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

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