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

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