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

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