@@ -4602,6 +4602,7 @@ NDCTL_EXPORT int ndctl_namespace_disable_safe(struct ndctl_namespace *ndns)
const char *bdev = NULL;
char path[50];
int fd;
+ unsigned long long size = ndctl_namespace_get_size(ndns);
if (pfn && ndctl_pfn_is_enabled(pfn))
bdev = ndctl_pfn_get_block_device(pfn);
@@ -4631,8 +4632,13 @@ NDCTL_EXPORT int ndctl_namespace_disable_safe(struct ndctl_namespace *ndns)
devname, bdev, strerror(errno));
return -errno;
}
- } else
- ndctl_namespace_disable_invalidate(ndns);
+ } else {
+ if (size == 0)
+ /* No disable necessary due to no capacity allocated */
+ return 1;
+ else
+ ndctl_namespace_disable_invalidate(ndns);
+ }
return 0;
}
@@ -1125,7 +1125,7 @@ static int namespace_prep_reconfig(struct ndctl_region *region,
}
rc = ndctl_namespace_disable_safe(ndns);
- if (rc)
+ if (rc < 0)
return rc;
ndctl_namespace_set_enforce_mode(ndns, NDCTL_NS_MODE_RAW);
@@ -1431,7 +1431,7 @@ static int dax_clear_badblocks(struct ndctl_dax *dax)
return -ENXIO;
rc = ndctl_namespace_disable_safe(ndns);
- if (rc) {
+ if (rc < 0) {
error("%s: unable to disable namespace: %s\n", devname,
strerror(-rc));
return rc;
@@ -1455,7 +1455,7 @@ static int pfn_clear_badblocks(struct ndctl_pfn *pfn)
return -ENXIO;
rc = ndctl_namespace_disable_safe(ndns);
- if (rc) {
+ if (rc < 0) {
error("%s: unable to disable namespace: %s\n", devname,
strerror(-rc));
return rc;
@@ -1478,7 +1478,7 @@ static int raw_clear_badblocks(struct ndctl_namespace *ndns)
return -ENXIO;
rc = ndctl_namespace_disable_safe(ndns);
- if (rc) {
+ if (rc < 0) {
error("%s: unable to disable namespace: %s\n", devname,
strerror(-rc));
return rc;
@@ -70,7 +70,7 @@ static int region_action(struct ndctl_region *region, enum device_action mode)
case ACTION_DISABLE:
ndctl_namespace_foreach(region, ndns) {
rc = ndctl_namespace_disable_safe(ndns);
- if (rc)
+ if (rc < 0)
return rc;
}
rc = ndctl_region_disable_invalidate(region);