Blame SOURCES/0172-ndctl-bus-Handle-missing-scrub-commands-more-gracefu.patch

26ccd9
From 3e17210345482ec9795f1046c766564d3b8a0795 Mon Sep 17 00:00:00 2001
26ccd9
From: Tarun Sahu <tsahu@linux.ibm.com>
26ccd9
Date: Mon, 2 May 2022 12:34:54 +0530
26ccd9
Subject: [PATCH 172/217] ndctl/bus: Handle missing scrub commands more
26ccd9
 gracefully
26ccd9
26ccd9
Buses that don't have nfit support return "No such file or directory"
26ccd9
for start-scrub/wait-scrub command.
26ccd9
26ccd9
Presently, non-nfit support buses do not support start-scrub/ wait-scrub
26ccd9
operation. This patch is to handle these commands more gracefully by
26ccd9
returning" Operation not supported".
26ccd9
26ccd9
This has been tested on PPC64le lpar with nvdimm that does not support
26ccd9
scrub.
26ccd9
26ccd9
Previously:
26ccd9
  $ ./ndctl start-scrub ndbus0
26ccd9
  error starting scrub: No such file or directory
26ccd9
26ccd9
Now:
26ccd9
  $ ./ndctl start-scrub ndbus0
26ccd9
  error starting scrub: Operation not supported
26ccd9
26ccd9
- Invalid ndbus
26ccd9
  $ sudo ./ndctl start-scrub ndbus5
26ccd9
  error starting scrub: No such device or address
26ccd9
26ccd9
Link: https://lore.kernel.org/r/20220502070454.179153-1-tsahu@linux.ibm.com
26ccd9
Tested-by: Vaibhav Jain <vaibhav@linux.ibm.com>
26ccd9
Reviewed-by: Vaibhav Jain <vaibhav@linux.ibm.com>
26ccd9
Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
26ccd9
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
26ccd9
---
26ccd9
 ndctl/lib/libndctl.c | 18 ++++++++++++++----
26ccd9
 1 file changed, 14 insertions(+), 4 deletions(-)
26ccd9
26ccd9
diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
26ccd9
index 110d8a5..ad54f06 100644
26ccd9
--- a/ndctl/lib/libndctl.c
26ccd9
+++ b/ndctl/lib/libndctl.c
26ccd9
@@ -938,10 +938,14 @@ static void *add_bus(void *parent, int id, const char *ctl_base)
26ccd9
 	if (!bus->wait_probe_path)
26ccd9
 		goto err_read;
26ccd9
 
26ccd9
-	sprintf(path, "%s/device/nfit/scrub", ctl_base);
26ccd9
-	bus->scrub_path = strdup(path);
26ccd9
-	if (!bus->scrub_path)
26ccd9
-		goto err_read;
26ccd9
+	if (ndctl_bus_has_nfit(bus)) {
26ccd9
+		sprintf(path, "%s/device/nfit/scrub", ctl_base);
26ccd9
+		bus->scrub_path = strdup(path);
26ccd9
+		if (!bus->scrub_path)
26ccd9
+			goto err_read;
26ccd9
+	} else {
26ccd9
+		bus->scrub_path = NULL;
26ccd9
+	}
26ccd9
 
26ccd9
 	sprintf(path, "%s/device/firmware/activate", ctl_base);
26ccd9
 	if (sysfs_read_attr(ctx, path, buf) < 0)
26ccd9
@@ -1377,6 +1381,9 @@ NDCTL_EXPORT int ndctl_bus_start_scrub(struct ndctl_bus *bus)
26ccd9
 	struct ndctl_ctx *ctx = ndctl_bus_get_ctx(bus);
26ccd9
 	int rc;
26ccd9
 
26ccd9
+	if (bus->scrub_path == NULL)
26ccd9
+		return -EOPNOTSUPP;
26ccd9
+
26ccd9
 	rc = sysfs_write_attr(ctx, bus->scrub_path, "1\n");
26ccd9
 
26ccd9
 	/*
26ccd9
@@ -1447,6 +1454,9 @@ NDCTL_EXPORT int ndctl_bus_poll_scrub_completion(struct ndctl_bus *bus,
26ccd9
 	char in_progress;
26ccd9
 	int fd = 0, rc;
26ccd9
 
26ccd9
+	if (bus->scrub_path == NULL)
26ccd9
+		return -EOPNOTSUPP;
26ccd9
+
26ccd9
 	fd = open(bus->scrub_path, O_RDONLY|O_CLOEXEC);
26ccd9
 	if (fd < 0)
26ccd9
 		return -errno;
26ccd9
-- 
26ccd9
2.27.0
26ccd9