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