Linux-NVDIMM Archive on lore.kernel.org
 help / color / Atom feed
* [ndctl PATCH v2 1/2] ndctl/namespace: Rework counts reported by enable-namespace
@ 2019-11-05 17:27 Vishal Verma
  2019-11-05 17:27 ` [ndctl PATCH v2 2/2] ndctl/namespace: fix reported count for disable-namespace Vishal Verma
  2019-11-12 19:23 ` [ndctl PATCH v2 1/2] ndctl/namespace: Rework counts reported by enable-namespace Verma, Vishal L
  0 siblings, 2 replies; 3+ messages in thread
From: Vishal Verma @ 2019-11-05 17:27 UTC (permalink / raw)
  To: linux-nvdimm; +Cc: Aneesh Kumar K.V

Add detection of 'seed' namespaces
(ndctl_namespace_is_configuration_idle()) to the enable-namespace
operatiuon and libndctl API. In libndctl, return a '1' for seed
namespaces. In namespace.c, reinterpret a '1' based on a check for a
seed namespace, and decide on skip vs success accordingly. Collect this
into a new namespace_enable helper, and make the reported count
consistent by also skipping namespaces that were already enabled.

Link: https://github.com/pmem/ndctl/issues/119
Reported-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---

Changes in v2:
- The kernel is the ultimate authority on enabling namespaces, so we
  should let it make the decision of how to handle seed namespaces
  instead of preemptively skipping them. Let the kernel make that
  decision, and fix up error reporting after the fact.

 ndctl/lib/libndctl.c |  9 +++++++--
 ndctl/namespace.c    | 37 ++++++++++++++++++++++++++++++++++---
 2 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index d6a2800..cde58ff 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -4045,8 +4045,13 @@ NDCTL_EXPORT int ndctl_namespace_enable(struct ndctl_namespace *ndns)
 			return 1;
 		}
 
-		err(ctx, "%s: failed to enable\n", devname);
-		return rc ? rc : -ENXIO;
+		if (ndctl_namespace_is_configuration_idle(ndns)) {
+			dbg(ctx, "%s: skip seed namespace\n", devname);
+			return 1;
+		} else {
+			err(ctx, "%s: failed to enable\n", devname);
+			return rc ? rc : -ENXIO;
+		}
 	}
 	rc = 0;
 	dbg(ctx, "%s: enabled\n", devname);
diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index a07d7e2..f2987ca 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -961,6 +961,36 @@ out:
 	return rc;
 }
 
+/*
+ * Adjust the return convention slightly differently from
+ * ndctl_namespace_enable(). We don't care as much if the enable resulted in
+ * a different namespace personality being attached. We care more about success,
+ * failure, or skipped.
+ * return 0 for success
+ * return < 0 for failure
+ * return > 0 for skipped
+ */
+static int namespace_enable(struct ndctl_namespace *ndns)
+{
+	int rc;
+
+	if (ndctl_namespace_is_enabled(ndns))
+		return 1;
+
+	rc = ndctl_namespace_enable(ndns);
+	if (rc < 0)
+		return rc;
+
+	/*
+	 * ndctl_namespace_enable() returns 'success' even for seed namespaces.
+	 * Reinterpret it to determine success vs. skipped.
+	 */
+	if (ndctl_namespace_is_configuration_idle(ndns))
+		return 1;
+
+	return 0;
+}
+
 static int enable_labels(struct ndctl_region *region)
 {
 	int mappings = ndctl_region_get_mappings(region);
@@ -1401,11 +1431,12 @@ static int do_xaction_namespace(const char *namespace,
 						(*processed)++;
 					break;
 				case ACTION_ENABLE:
-					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);
-- 
2.20.1
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ndctl PATCH v2 2/2] ndctl/namespace: fix reported count for disable-namespace
  2019-11-05 17:27 [ndctl PATCH v2 1/2] ndctl/namespace: Rework counts reported by enable-namespace Vishal Verma
@ 2019-11-05 17:27 ` Vishal Verma
  2019-11-12 19:23 ` [ndctl PATCH v2 1/2] ndctl/namespace: Rework counts reported by enable-namespace Verma, Vishal L
  1 sibling, 0 replies; 3+ messages in thread
From: Vishal Verma @ 2019-11-05 17:27 UTC (permalink / raw)
  To: linux-nvdimm; +Cc: Aneesh Kumar K.V

Make the count reported disable-namespace consistent with
enable-namespace by skipping namespaces that were already disabled.

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

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index f2987ca..57998ce 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -1426,6 +1426,10 @@ static int do_xaction_namespace(const char *namespace,
 					continue;
 				switch (action) {
 				case ACTION_DISABLE:
+					if (!ndctl_namespace_is_enabled(ndns)) {
+						rc = 0;
+						continue;
+					}
 					rc = ndctl_namespace_disable_safe(ndns);
 					if (rc == 0)
 						(*processed)++;
-- 
2.20.1
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [ndctl PATCH v2 1/2] ndctl/namespace: Rework counts reported by enable-namespace
  2019-11-05 17:27 [ndctl PATCH v2 1/2] ndctl/namespace: Rework counts reported by enable-namespace Vishal Verma
  2019-11-05 17:27 ` [ndctl PATCH v2 2/2] ndctl/namespace: fix reported count for disable-namespace Vishal Verma
@ 2019-11-12 19:23 ` Verma, Vishal L
  1 sibling, 0 replies; 3+ messages in thread
From: Verma, Vishal L @ 2019-11-12 19:23 UTC (permalink / raw)
  To: linux-nvdimm; +Cc: aneesh.kumar


On Tue, 2019-11-05 at 10:27 -0700, Vishal Verma wrote:
> Add detection of 'seed' namespaces
> (ndctl_namespace_is_configuration_idle()) to the enable-namespace
> operatiuon and libndctl API. In libndctl, return a '1' for seed
> namespaces. In namespace.c, reinterpret a '1' based on a check for a
> seed namespace, and decide on skip vs success accordingly. Collect this
> into a new namespace_enable helper, and make the reported count
> consistent by also skipping namespaces that were already enabled.
> 
> Link: https://github.com/pmem/ndctl/issues/119
> Reported-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
> ---
> 
> Changes in v2:
> - The kernel is the ultimate authority on enabling namespaces, so we
>   should let it make the decision of how to handle seed namespaces
>   instead of preemptively skipping them. Let the kernel make that
>   decision, and fix up error reporting after the fact.

These break the unit tests, so I'll have to take another look at this.
I suspect the added complexity is probably not worth the few extra
prints from seed namespaces for operations using the 'all' keyword.

_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-05 17:27 [ndctl PATCH v2 1/2] ndctl/namespace: Rework counts reported by enable-namespace Vishal Verma
2019-11-05 17:27 ` [ndctl PATCH v2 2/2] ndctl/namespace: fix reported count for disable-namespace Vishal Verma
2019-11-12 19:23 ` [ndctl PATCH v2 1/2] ndctl/namespace: Rework counts reported by enable-namespace Verma, Vishal L

Linux-NVDIMM Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-nvdimm/0 linux-nvdimm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-nvdimm linux-nvdimm/ https://lore.kernel.org/linux-nvdimm \
		linux-nvdimm@lists.01.org
	public-inbox-index linux-nvdimm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.01.lists.linux-nvdimm


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git