Blob Blame History Raw
From 9bd2994f91bb77604521cbe09a76a51d092c2cfd Mon Sep 17 00:00:00 2001
From: Michal Suchanek <msuchanek@suse.de>
Date: Wed, 6 Jan 2021 14:17:40 +0100
Subject: [PATCH 028/217] ndctl/namespace: Skip seed namespaces when processing
 all namespaces.

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.

Link: https://patchwork.kernel.org/patch/11473645/
Link: https://lore.kernel.org/r/e55ae2c17b8b9c3288491efe6214338118e8c5ae.1609938610.git.msuchanek@suse.de
Fixes: #41
Tested-by: Harish Sriram <harish@linux.ibm.com>
Reviewed-by: Santosh S <santosh@fossix.org>
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 ndctl/namespace.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index 1e8a2cd..5e65ed5 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -2210,9 +2210,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);
-- 
2.27.0