anitazha / rpms / ndctl

Forked from rpms/ndctl a year ago
Clone

Blame SOURCES/0028-ndctl-namespace-Skip-seed-namespaces-when-processing.patch

e0018b
From 9bd2994f91bb77604521cbe09a76a51d092c2cfd Mon Sep 17 00:00:00 2001
e0018b
From: Michal Suchanek <msuchanek@suse.de>
e0018b
Date: Wed, 6 Jan 2021 14:17:40 +0100
e0018b
Subject: [PATCH 028/217] ndctl/namespace: Skip seed namespaces when processing
e0018b
 all namespaces.
e0018b
e0018b
The seed namespaces are exposed by the kernel but most operations are
e0018b
not valid on seed namespaces.
e0018b
e0018b
When processing all namespaces the user gets confusing errors from ndctl
e0018b
trying to process seed namespaces. The kernel does not provide any way
e0018b
to tell that a namspace is seed namespace but skipping namespaces with
e0018b
zero size and UUID is a good heuristic.
e0018b
e0018b
The user can still specify the namespace by name directly in case
e0018b
processing it is desirable.
e0018b
e0018b
Link: https://patchwork.kernel.org/patch/11473645/
e0018b
Link: https://lore.kernel.org/r/e55ae2c17b8b9c3288491efe6214338118e8c5ae.1609938610.git.msuchanek@suse.de
e0018b
Fixes: #41
e0018b
Tested-by: Harish Sriram <harish@linux.ibm.com>
e0018b
Reviewed-by: Santosh S <santosh@fossix.org>
e0018b
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
e0018b
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
e0018b
---
e0018b
 ndctl/namespace.c | 16 +++++++++++++---
e0018b
 1 file changed, 13 insertions(+), 3 deletions(-)
e0018b
e0018b
diff --git a/ndctl/namespace.c b/ndctl/namespace.c
e0018b
index 1e8a2cd..5e65ed5 100644
e0018b
--- a/ndctl/namespace.c
e0018b
+++ b/ndctl/namespace.c
e0018b
@@ -2210,9 +2210,19 @@ static int do_xaction_namespace(const char *namespace,
e0018b
 			ndctl_namespace_foreach_safe(region, ndns, _n) {
e0018b
 				ndns_name = ndctl_namespace_get_devname(ndns);
e0018b
 
e0018b
-				if (strcmp(namespace, "all") != 0
e0018b
-						&& strcmp(namespace, ndns_name) != 0)
e0018b
-					continue;
e0018b
+				if (strcmp(namespace, "all") == 0) {
e0018b
+					static const uuid_t zero_uuid;
e0018b
+					uuid_t uuid;
e0018b
+
e0018b
+					ndctl_namespace_get_uuid(ndns, uuid);
e0018b
+					if (!ndctl_namespace_get_size(ndns) &&
e0018b
+					    !memcmp(uuid, zero_uuid, sizeof(uuid_t)))
e0018b
+						continue;
e0018b
+				} else {
e0018b
+					if (strcmp(namespace, ndns_name) != 0)
e0018b
+						continue;
e0018b
+				}
e0018b
+
e0018b
 				switch (action) {
e0018b
 				case ACTION_DISABLE:
e0018b
 					rc = ndctl_namespace_disable_safe(ndns);
e0018b
-- 
e0018b
2.27.0
e0018b