Blame SOURCES/0008-ndctl-namespace-Fix-disable-namespace-accounting-rel.patch

26ccd9
From fe626a8a8a1b1bc94ea95c693ec672109909e3dc Mon Sep 17 00:00:00 2001
26ccd9
From: Redhairer Li <redhairer.li@intel.com>
26ccd9
Date: Thu, 28 Jan 2021 22:03:39 +0800
26ccd9
Subject: [PATCH 008/217] ndctl/namespace: Fix disable-namespace accounting
26ccd9
 relative to seed devices
26ccd9
26ccd9
Seed namespaces are included in "ndctl disable-namespace all". However
26ccd9
since the user never "creates" them it is surprising to see
26ccd9
"disable-namespace" report 1 more namespace relative to the number that
26ccd9
have been created. Catch attempts to disable a zero-sized namespace:
26ccd9
26ccd9
Before:
26ccd9
{
26ccd9
  "dev":"namespace1.0",
26ccd9
  "size":"492.00 MiB (515.90 MB)",
26ccd9
  "blockdev":"pmem1"
26ccd9
}
26ccd9
{
26ccd9
  "dev":"namespace1.1",
26ccd9
  "size":"492.00 MiB (515.90 MB)",
26ccd9
  "blockdev":"pmem1.1"
26ccd9
}
26ccd9
{
26ccd9
  "dev":"namespace1.2",
26ccd9
  "size":"492.00 MiB (515.90 MB)",
26ccd9
  "blockdev":"pmem1.2"
26ccd9
}
26ccd9
disabled 4 namespaces
26ccd9
26ccd9
After:
26ccd9
{
26ccd9
  "dev":"namespace1.0",
26ccd9
  "size":"492.00 MiB (515.90 MB)",
26ccd9
  "blockdev":"pmem1"
26ccd9
}
26ccd9
{
26ccd9
  "dev":"namespace1.3",
26ccd9
  "size":"492.00 MiB (515.90 MB)",
26ccd9
  "blockdev":"pmem1.3"
26ccd9
}
26ccd9
{
26ccd9
  "dev":"namespace1.1",
26ccd9
  "size":"492.00 MiB (515.90 MB)",
26ccd9
  "blockdev":"pmem1.1"
26ccd9
}
26ccd9
disabled 3 namespaces
26ccd9
26ccd9
Signed-off-by: Redhairer Li <redhairer.li@intel.com>
26ccd9
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
26ccd9
Link: https://lore.kernel.org/linux-nvdimm/20210128140339.3080-1-redhairer.li@intel.com/
26ccd9
---
26ccd9
 ndctl/lib/libndctl.c | 10 ++++++++--
26ccd9
 ndctl/namespace.c    |  8 ++++----
26ccd9
 ndctl/region.c       |  2 +-
26ccd9
 3 files changed, 13 insertions(+), 7 deletions(-)
26ccd9
26ccd9
diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
26ccd9
index 36fb6fe..2f6d806 100644
26ccd9
--- a/ndctl/lib/libndctl.c
26ccd9
+++ b/ndctl/lib/libndctl.c
26ccd9
@@ -4602,6 +4602,7 @@ NDCTL_EXPORT int ndctl_namespace_disable_safe(struct ndctl_namespace *ndns)
26ccd9
 	const char *bdev = NULL;
26ccd9
 	char path[50];
26ccd9
 	int fd;
26ccd9
+	unsigned long long size = ndctl_namespace_get_size(ndns);
26ccd9
 
26ccd9
 	if (pfn && ndctl_pfn_is_enabled(pfn))
26ccd9
 		bdev = ndctl_pfn_get_block_device(pfn);
26ccd9
@@ -4631,8 +4632,13 @@ NDCTL_EXPORT int ndctl_namespace_disable_safe(struct ndctl_namespace *ndns)
26ccd9
 					devname, bdev, strerror(errno));
26ccd9
 			return -errno;
26ccd9
 		}
26ccd9
-	} else
26ccd9
-		ndctl_namespace_disable_invalidate(ndns);
26ccd9
+	} else {
26ccd9
+		if (size == 0)
26ccd9
+			/* No disable necessary due to no capacity allocated */
26ccd9
+			return 1;
26ccd9
+		else
26ccd9
+			ndctl_namespace_disable_invalidate(ndns);
26ccd9
+	}
26ccd9
 
26ccd9
 	return 0;
26ccd9
 }
26ccd9
diff --git a/ndctl/namespace.c b/ndctl/namespace.c
26ccd9
index 0c8df9f..1feb74d 100644
26ccd9
--- a/ndctl/namespace.c
26ccd9
+++ b/ndctl/namespace.c
26ccd9
@@ -1125,7 +1125,7 @@ static int namespace_prep_reconfig(struct ndctl_region *region,
26ccd9
 	}
26ccd9
 
26ccd9
 	rc = ndctl_namespace_disable_safe(ndns);
26ccd9
-	if (rc)
26ccd9
+	if (rc < 0)
26ccd9
 		return rc;
26ccd9
 
26ccd9
 	ndctl_namespace_set_enforce_mode(ndns, NDCTL_NS_MODE_RAW);
26ccd9
@@ -1431,7 +1431,7 @@ static int dax_clear_badblocks(struct ndctl_dax *dax)
26ccd9
 		return -ENXIO;
26ccd9
 
26ccd9
 	rc = ndctl_namespace_disable_safe(ndns);
26ccd9
-	if (rc) {
26ccd9
+	if (rc < 0) {
26ccd9
 		error("%s: unable to disable namespace: %s\n", devname,
26ccd9
 			strerror(-rc));
26ccd9
 		return rc;
26ccd9
@@ -1455,7 +1455,7 @@ static int pfn_clear_badblocks(struct ndctl_pfn *pfn)
26ccd9
 		return -ENXIO;
26ccd9
 
26ccd9
 	rc = ndctl_namespace_disable_safe(ndns);
26ccd9
-	if (rc) {
26ccd9
+	if (rc < 0) {
26ccd9
 		error("%s: unable to disable namespace: %s\n", devname,
26ccd9
 			strerror(-rc));
26ccd9
 		return rc;
26ccd9
@@ -1478,7 +1478,7 @@ static int raw_clear_badblocks(struct ndctl_namespace *ndns)
26ccd9
 		return -ENXIO;
26ccd9
 
26ccd9
 	rc = ndctl_namespace_disable_safe(ndns);
26ccd9
-	if (rc) {
26ccd9
+	if (rc < 0) {
26ccd9
 		error("%s: unable to disable namespace: %s\n", devname,
26ccd9
 			strerror(-rc));
26ccd9
 		return rc;
26ccd9
diff --git a/ndctl/region.c b/ndctl/region.c
26ccd9
index 3edb9b3..4552c4a 100644
26ccd9
--- a/ndctl/region.c
26ccd9
+++ b/ndctl/region.c
26ccd9
@@ -70,7 +70,7 @@ static int region_action(struct ndctl_region *region, enum device_action mode)
26ccd9
 	case ACTION_DISABLE:
26ccd9
 		ndctl_namespace_foreach(region, ndns) {
26ccd9
 			rc = ndctl_namespace_disable_safe(ndns);
26ccd9
-			if (rc)
26ccd9
+			if (rc < 0)
26ccd9
 				return rc;
26ccd9
 		}
26ccd9
 		rc = ndctl_region_disable_invalidate(region);
26ccd9
-- 
26ccd9
2.27.0
26ccd9