[ndctl,2/2] ndctl/namespace: For enable-namespace all, don't count no-op namespaces
diff mbox series

Message ID 20191104230857.28172-2-vishal.l.verma@intel.com
State New
Headers show
Series
  • [ndctl,1/2] ndctl/namespace: skip seed namespaces for 'enable-namespace'
Related show

Commit Message

Verma, Vishal L Nov. 4, 2019, 11:08 p.m. UTC
When ndctl-enable-namespace is called for namespaces that are already
enabled, it shouldn't report that a positive number of namespaces were
enabled. Check whether the namespace is enabled, and if so, omit it from
the 'processed' count.

Since the indentation-heavy section for ACTION_ENABLE is getting larger
than a simgle libndctl call, break it out into its own namespace_enable()
helper.

Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 ndctl/namespace.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

Patch
diff mbox series

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index ed0421b..cebc312 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -961,6 +961,20 @@  out:
 	return rc;
 }
 
+static int namespace_enable(struct ndctl_namespace *ndns)
+{
+	if (ndctl_namespace_is_enabled(ndns))
+		return 1;
+
+	if (ndctl_namespace_is_configuration_idle(ndns)) {
+		debug("%s: skip seed namespace\n",
+			ndctl_namespace_get_devname(ndns));
+		return 1;
+	}
+
+	return ndctl_namespace_enable(ndns);
+}
+
 static int enable_labels(struct ndctl_region *region)
 {
 	int mappings = ndctl_region_get_mappings(region);
@@ -1401,16 +1415,12 @@  static int do_xaction_namespace(const char *namespace,
 						(*processed)++;
 					break;
 				case ACTION_ENABLE:
-					if (ndctl_namespace_is_configuration_idle(ndns)) {
-						debug("%s: skip seed namespace\n",
-							ndctl_namespace_get_devname(ndns));
-						continue;
-					}
-					rc = ndctl_namespace_enable(ndns);
-					if (rc >= 0) {
+					rc = namespace_enable(ndns);
+					if (rc == 0)
 						(*processed)++;
+					/* return success if skipped */
+					if (rc > 0)
 						rc = 0;
-					}
 					break;
 				case ACTION_DESTROY:
 					rc = namespace_destroy(region, ndns);