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

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