anitazha / rpms / ndctl

Forked from rpms/ndctl 2 years ago
Clone

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

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