anitazha / rpms / ndctl

Forked from rpms/ndctl 2 years ago
Clone

Blame 4e646fa-ndctl-scrub-Reread-scrub-engine-status-at-start.patch

Bryan Gurney bc084d
ndctl/scrub: Reread scrub-engine status at start
Bryan Gurney bc084d
Bryan Gurney bc084d
BZ: 
Bryan Gurney bc084d
Brew: 
Bryan Gurney bc084d
Bryan Gurney bc084d
commit 4e646fa490ba4b782afa188dd8818b94c419924e
Bryan Gurney bc084d
Author: Dan Williams <dan.j.williams@intel.com>
Bryan Gurney bc084d
Date:   Wed May 26 16:33:10 2021 -0700
Bryan Gurney bc084d
Bryan Gurney bc084d
    ndctl/scrub: Reread scrub-engine status at start
Bryan Gurney bc084d
    
Bryan Gurney bc084d
    Given that the kernel has exponential backoff to cover the lack of
Bryan Gurney bc084d
    interrupts for scrub completion status there is a reasonable likelihood
Bryan Gurney bc084d
    that 'ndctl start-scrub' is issued while the hardware/platform scrub-state
Bryan Gurney bc084d
    is idle, but the kernel engine poll timer has not fired.
Bryan Gurney bc084d
    
Bryan Gurney bc084d
    Trigger at least one poll cycle for the kernel to re-read the scrub-state
Bryan Gurney bc084d
    before reporting that ARS is busy.
Bryan Gurney bc084d
    
Bryan Gurney bc084d
    Link: https://lore.kernel.org/r/162207199057.3715490.2469820075085914776.stgit@dwillia2-desk3.amr.corp.intel.com
Bryan Gurney bc084d
    Reported-by: Krzysztof Rusocki <krzysztof.rusocki@intel.com>
Bryan Gurney bc084d
    Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Bryan Gurney bc084d
    Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Bryan Gurney bc084d
Bryan Gurney bc084d
diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
Bryan Gurney bc084d
index e5641fe..536e142 100644
Bryan Gurney bc084d
--- a/ndctl/lib/libndctl.c
Bryan Gurney bc084d
+++ b/ndctl/lib/libndctl.c
Bryan Gurney bc084d
@@ -1354,8 +1354,18 @@ static int __ndctl_bus_get_scrub_state(struct ndctl_bus *bus,
Bryan Gurney bc084d
 NDCTL_EXPORT int ndctl_bus_start_scrub(struct ndctl_bus *bus)
Bryan Gurney bc084d
 {
Bryan Gurney bc084d
 	struct ndctl_ctx *ctx = ndctl_bus_get_ctx(bus);
Bryan Gurney bc084d
+	int rc;
Bryan Gurney bc084d
+
Bryan Gurney bc084d
+	rc = sysfs_write_attr(ctx, bus->scrub_path, "1\n");
Bryan Gurney bc084d
 
Bryan Gurney bc084d
-	return sysfs_write_attr(ctx, bus->scrub_path, "1\n");
Bryan Gurney bc084d
+	/*
Bryan Gurney bc084d
+	 * Try at least 1 poll cycle before reporting busy in case this
Bryan Gurney bc084d
+	 * request hits the kernel's exponential backoff while the
Bryan Gurney bc084d
+	 * hardware/platform scrub state is idle.
Bryan Gurney bc084d
+	 */
Bryan Gurney bc084d
+	if (rc == -EBUSY && ndctl_bus_poll_scrub_completion(bus, 1, 1) == 0)
Bryan Gurney bc084d
+		return sysfs_write_attr(ctx, bus->scrub_path, "1\n");
Bryan Gurney bc084d
+	return rc;
Bryan Gurney bc084d
 }
Bryan Gurney bc084d
 
Bryan Gurney bc084d
 NDCTL_EXPORT int ndctl_bus_get_scrub_state(struct ndctl_bus *bus)