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

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