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

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