anitazha / rpms / ndctl

Forked from rpms/ndctl 2 years ago
Clone

Blame SOURCES/9bd2994-ndctl-namespace-Skip-seed-namespaces-when-processing-all-namespaces.patch

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