File ndctl-namespace-skip-zero-namespaces-when-processing.patch of Package ndctl.15916

From ff4e8668a5edd2eaa38f08deb9b357778019e2ea Mon Sep 17 00:00:00 2001
From: Michal Suchanek <msuchanek@suse.de>
Date: Fri, 3 Apr 2020 19:38:33 +0200
Subject: [PATCH] ndctl/namespace: skip zero namespaces when processing all
 namespaces.

The kernel always creates zero length namespace with uuid 0 in each
region.

When processing all namespaces the user gets confusing errors from ndctl
trying to process this namespace. Skip it.

The user can still specify the namespace by name directly in case
processing it is desirable.

Fixes: #41

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
---
 ndctl/namespace.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index 0550580707e8..6f4a4b5b8883 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -2128,9 +2128,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);
-- 
2.23.0

openSUSE Build Service is sponsored by