anitazha / rpms / ndctl

Forked from rpms/ndctl 2 years ago
Clone
Blob Blame History Raw
ndctl/namespace: Skip seed namespaces when processing all namespaces.

BZ: 
Brew: 

commit 9bd2994f91bb77604521cbe09a76a51d092c2cfd
Author: Michal Suchanek <msuchanek@suse.de>
Date:   Wed Jan 6 14:17:40 2021 +0100

    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>

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);