@@ -4130,16 +4130,11 @@ NDCTL_EXPORT int ndctl_namespace_enable(struct ndctl_namespace *ndns)
const char *devname = ndctl_namespace_get_devname(ndns);
struct ndctl_ctx *ctx = ndctl_namespace_get_ctx(ndns);
struct ndctl_region *region = ndns->region;
- unsigned long long size = ndctl_namespace_get_size(ndns);
int rc;
if (ndctl_namespace_is_enabled(ndns))
return 0;
- /* Don't try to enable idle namespace (no capacity allocated) */
- if (size == 0)
- return -ENXIO;
-
rc = ndctl_bind(ctx, ndns->module, devname);
/*
@@ -1102,7 +1102,6 @@ static int namespace_destroy(struct ndctl_region *region,
struct ndctl_namespace *ndns)
{
const char *devname = ndctl_namespace_get_devname(ndns);
- unsigned long long size;
bool did_zero = false;
int rc;
@@ -1147,19 +1146,9 @@ static int namespace_destroy(struct ndctl_region *region,
goto out;
}
- size = ndctl_namespace_get_size(ndns);
-
rc = ndctl_namespace_delete(ndns);
if (rc)
debug("%s: failed to reclaim\n", devname);
-
- /*
- * Don't report a destroyed namespace when no capacity was
- * allocated.
- */
- if (size == 0 && rc == 0)
- rc = 1;
-
out:
return rc;
}
@@ -2128,8 +2117,9 @@ 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
+ if ((strcmp(namespace, "all") != 0
&& strcmp(namespace, ndns_name) != 0)
+ || ndctl_namespace_get_size(ndns) == 0)
continue;
switch (action) {
case ACTION_DISABLE:
@@ -2148,9 +2138,6 @@ static int do_xaction_namespace(const char *namespace,
rc = namespace_destroy(region, ndns);
if (rc == 0)
(*processed)++;
- /* return success if skipped */
- if (rc > 0)
- rc = 0;
break;
case ACTION_CHECK:
rc = namespace_check(ndns, verbose,
@@ -2195,22 +2182,32 @@ static int do_xaction_namespace(const char *namespace,
if (ri_ctx.f_out && ri_ctx.f_out != stdout)
fclose(ri_ctx.f_out);
- if (action == ACTION_CREATE && rc == -EAGAIN) {
- /*
- * Namespace creation searched through all candidate
- * regions and all of them said "nope, I don't have
- * enough capacity", so report -ENOSPC. Except during
- * greedy namespace creation using --continue as we
- * may have created some namespaces already, and the
- * last one in the region search may preexist.
- */
- if (param.greedy && (*processed) > 0)
- rc = 0;
- else
- rc = -ENOSPC;
+ if (action == ACTION_CREATE) {
+ if (rc == -EAGAIN) {
+ /*
+ * Namespace creation searched through all candidate
+ * regions and all of them said "nope, I don't have
+ * enough capacity", so report -ENOSPC. Except during
+ * greedy namespace creation using --continue as we
+ * may have created some namespaces already, and the
+ * last one in the region search may preexist.
+ */
+ if (param.greedy && (*processed) > 0)
+ rc = 0;
+ else
+ rc = -ENOSPC;
+ }
+
+ if (saved_rc)
+ rc = saved_rc;
+
+ return rc;
}
- if (saved_rc)
- rc = saved_rc;
+
+ /* If there is nothing processed, and if we have only skipped idle
+ * namespaces, there shouldn't be any error */
+ if (rc == -ENXIO && !*processed)
+ rc = 0;
return rc;
}
Catch seed namespaces early on. This will prevent checking for sizes in enable, disable and destroy namespace code path, which in turn prevents the inconsistent reporting in count of enabled/disabled namespaces. Signed-off-by: Santosh Sivaraj <santosh@fossix.org> --- ndctl/lib/libndctl.c | 5 ---- ndctl/namespace.c | 57 +++++++++++++++++++++----------------------- 2 files changed, 27 insertions(+), 35 deletions(-) Changes from v2: Updated patch to return the proper error code. In V1, we return the default -ENXIO even if we had skipped all the namespaces (when there are only idle namespaces). In cases like that, we need to return zero, except when creating namespaces, which may fail due to insufficient space.