anitazha / rpms / ndctl

Forked from rpms/ndctl a year ago
Clone

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

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