All of lore.kernel.org
 help / color / mirror / Atom feed
* [ndctl PATCH] ndctl/namespace: Fix destroy-namespace accounting relative to seed devices
@ 2020-01-09  4:17 Dan Williams
  2020-01-10  8:20 ` [PATCH ndctl] ndctl/namespace: Fix enable-namespace error for seed namespaces Santosh Sivaraj
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Williams @ 2020-01-09  4:17 UTC (permalink / raw)
  To: linux-nvdimm

Seed namespaces are included in "ndctl destroy-namespace all". However
since the user never "creates" them it is surprising to see
"destroy-namespace" report 1 more namespace relative to the number that
have been created. Catch attempts to destroy a zero-sized namespace:

Before:
# ndctl create-namespace -s 500M
{
  "dev":"namespace1.0",
  "size":"492.00 MiB (515.90 MB)",
  "blockdev":"pmem1"
}
# ndctl create-namespace -s 500M
{
  "dev":"namespace1.1",
  "size":"492.00 MiB (515.90 MB)",
  "blockdev":"pmem1.1"
}
# ndctl create-namespace -s 500M
{
  "dev":"namespace1.2",
  "size":"492.00 MiB (515.90 MB)",
  "blockdev":"pmem1.2"
}
# ndctl destroy-namespace -r 1 all -f
destroyed 4 namespaces

After:
# ndctl create-namespace -s 500M
{
  "dev":"namespace1.0",
  "size":"492.00 MiB (515.90 MB)",
  "blockdev":"pmem1"
}
# ndctl create-namespace -s 500M
{
  "dev":"namespace1.3",
  "size":"492.00 MiB (515.90 MB)",
  "blockdev":"pmem1.3"
}
# ndctl create-namespace -s 500M
{
  "dev":"namespace1.1",
  "size":"492.00 MiB (515.90 MB)",
  "blockdev":"pmem1.1"
}
# ndctl destroy-namespace -r 1 all -f
destroyed 3 namespaces

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 ndctl/namespace.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index 2f463509f8ca..994b4e8791ea 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -907,6 +907,7 @@ static int namespace_destroy(struct ndctl_region *region,
 	struct ndctl_pfn *pfn = ndctl_namespace_get_pfn(ndns);
 	struct ndctl_dax *dax = ndctl_namespace_get_dax(ndns);
 	struct ndctl_btt *btt = ndctl_namespace_get_btt(ndns);
+	unsigned long long size;
 	bool did_zero = false;
 	int rc;
 
@@ -953,10 +954,19 @@ 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;
 }
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

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

* [PATCH ndctl] ndctl/namespace: Fix enable-namespace error for seed namespaces
  2020-01-09  4:17 [ndctl PATCH] ndctl/namespace: Fix destroy-namespace accounting relative to seed devices Dan Williams
@ 2020-01-10  8:20 ` Santosh Sivaraj
  2020-01-10 17:56   ` Dan Williams
  0 siblings, 1 reply; 3+ messages in thread
From: Santosh Sivaraj @ 2020-01-10  8:20 UTC (permalink / raw)
  To: linux-nvdimm, Dan Williams; +Cc: harish

'ndctl enable-namespace all' tries to enable seed namespaces too, which results
in a error like

libndctl: ndctl_namespace_enable: namespace1.0: failed to enable

Signed-off-by: Santosh Sivaraj <santosh@fossix.org>
---
 ndctl/lib/libndctl.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 6596f94..4839214 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -4010,11 +4010,16 @@ 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 -1;
+
 	rc = ndctl_bind(ctx, ndns->module, devname);
 
 	/*
-- 
2.24.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 related	[flat|nested] 3+ messages in thread

* Re: [PATCH ndctl] ndctl/namespace: Fix enable-namespace error for seed namespaces
  2020-01-10  8:20 ` [PATCH ndctl] ndctl/namespace: Fix enable-namespace error for seed namespaces Santosh Sivaraj
@ 2020-01-10 17:56   ` Dan Williams
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Williams @ 2020-01-10 17:56 UTC (permalink / raw)
  To: Santosh Sivaraj; +Cc: linux-nvdimm, harish

On Fri, Jan 10, 2020 at 12:21 AM Santosh Sivaraj <santosh@fossix.org> wrote:
>
> 'ndctl enable-namespace all' tries to enable seed namespaces too, which results
> in a error like
>
> libndctl: ndctl_namespace_enable: namespace1.0: failed to enable
>
> Signed-off-by: Santosh Sivaraj <santosh@fossix.org>
> ---
>  ndctl/lib/libndctl.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
> index 6596f94..4839214 100644
> --- a/ndctl/lib/libndctl.c
> +++ b/ndctl/lib/libndctl.c
> @@ -4010,11 +4010,16 @@ 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 -1;

Concept looks good to me, just resend with that -1 changed to a named
error code (-ENXIO).
_______________________________________________
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, other threads:[~2020-01-10 17:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-09  4:17 [ndctl PATCH] ndctl/namespace: Fix destroy-namespace accounting relative to seed devices Dan Williams
2020-01-10  8:20 ` [PATCH ndctl] ndctl/namespace: Fix enable-namespace error for seed namespaces Santosh Sivaraj
2020-01-10 17:56   ` Dan Williams

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.