diff mbox series

[ndctl,2/2] ndctl/scrub: Reread scrub-engine status at start

Message ID 162207199057.3715490.2469820075085914776.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State Accepted
Commit 4e646fa490ba4b782afa188dd8818b94c419924e
Headers show
Series ndctl/scrub: Fix start-scrub vs exponential backoff | expand

Commit Message

Dan Williams May 26, 2021, 11:33 p.m. UTC
Given that the kernel has exponential backoff to cover the lack of
interrupts for scrub completion status there is a reasonable likelihood
that 'ndctl start-scrub' is issued while the hardware/platform scrub-state
is idle, but the kernel engine poll timer has not fired.

Trigger at least one poll cycle for the kernel to re-read the scrub-state
before reporting that ARS is busy.

Reported-by: Krzysztof Rusocki <krzysztof.rusocki@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 ndctl/lib/libndctl.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index e5641feec23d..536e142cf6af 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -1354,8 +1354,18 @@  static int __ndctl_bus_get_scrub_state(struct ndctl_bus *bus,
 NDCTL_EXPORT int ndctl_bus_start_scrub(struct ndctl_bus *bus)
 {
 	struct ndctl_ctx *ctx = ndctl_bus_get_ctx(bus);
+	int rc;
+
+	rc = sysfs_write_attr(ctx, bus->scrub_path, "1\n");
 
-	return sysfs_write_attr(ctx, bus->scrub_path, "1\n");
+	/*
+	 * Try at least 1 poll cycle before reporting busy in case this
+	 * request hits the kernel's exponential backoff while the
+	 * hardware/platform scrub state is idle.
+	 */
+	if (rc == -EBUSY && ndctl_bus_poll_scrub_completion(bus, 1, 1) == 0)
+		return sysfs_write_attr(ctx, bus->scrub_path, "1\n");
+	return rc;
 }
 
 NDCTL_EXPORT int ndctl_bus_get_scrub_state(struct ndctl_bus *bus)