diff mbox series

[ndctl,rebased,1/3] ndctl/namespace: Skip seed namespaces when processing all namespaces.

Message ID e55ae2c17b8b9c3288491efe6214338118e8c5ae.1609938610.git.msuchanek@suse.de (mailing list archive)
State New, archived
Headers show
Series [ndctl,rebased,1/3] ndctl/namespace: Skip seed namespaces when processing all namespaces. | expand

Commit Message

Michal Suchanek Jan. 6, 2021, 1:17 p.m. UTC
The seed namespaces are exposed by the kernel but most operations are
not valid on seed namespaces.

When processing all namespaces the user gets confusing errors from ndctl
trying to process seed namespaces. The kernel does not provide any way
to tell that a namspace is seed namespace but skipping namespaces with
zero size and UUID is a good heuristic.

The user can still specify the namespace by name directly in case
processing it is desirable.

Fixes: #41
Link: https://patchwork.kernel.org/patch/11473645/
Reviewed-by: Santosh S <santosh@fossix.org>
Tested-by: Harish Sriram <harish@linux.ibm.com>
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
---
 ndctl/namespace.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index 0c8df9fa8b47..b9ffd21fe7bf 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -2207,9 +2207,19 @@  static int do_xaction_namespace(const char *namespace,
 			ndctl_namespace_foreach_safe(region, ndns, _n) {
 				ndns_name = ndctl_namespace_get_devname(ndns);
 
-				if (strcmp(namespace, "all") != 0
-						&& strcmp(namespace, ndns_name) != 0)
-					continue;
+				if (strcmp(namespace, "all") == 0) {
+					static const uuid_t zero_uuid;
+					uuid_t uuid;
+
+					ndctl_namespace_get_uuid(ndns, uuid);
+					if (!ndctl_namespace_get_size(ndns) &&
+					    !memcmp(uuid, zero_uuid, sizeof(uuid_t)))
+						continue;
+				} else {
+					if (strcmp(namespace, ndns_name) != 0)
+						continue;
+				}
+
 				switch (action) {
 				case ACTION_DISABLE:
 					rc = ndctl_namespace_disable_safe(ndns);