linux-nvdimm.lists.01.org archive mirror
 help / color / mirror / Atom feed
From: Vishal Verma <vishal.l.verma@intel.com>
To: "Williams, Dan J" <dan.j.williams@intel.com>
Cc: "Scargall, Steve" <steve.scargall@intel.com>,
	"linux-nvdimm@lists.01.org" <linux-nvdimm@lists.01.org>
Subject: Re: [ndctl PATCH 3/3] ndctl/namespace: add a --continue option to create namespaces greedily
Date: Thu, 29 Aug 2019 13:08:52 -0600	[thread overview]
Message-ID: <20190829190852.GA14129@vverma7-desk1.lm.intel.com> (raw)
In-Reply-To: <44b020035e3245084b2310cfdfe496853e2cf18d.camel@intel.com>

On 08/29, Verma, Vishal L wrote:
> On Wed, 2019-08-28 at 19:34 -0700, Dan Williams wrote:
> > 
> > Hmm, should "--continue --force" override that policy?
> 
> Yep that's a good idea, with a big note in the man page that errors
> could be lost/meaningless in that case.
> 
> > 
> > Otherwise this looks good to me.
> 
> Thanks, I'll send a new version with the above.
> _______________________________________________

Here is v2 with the --force change:

3<----


>From a91425beabae750227931594f77fe3db72b4cfff Mon Sep 17 00:00:00 2001
From: Vishal Verma <vishal.l.verma@intel.com>
Date: Wed, 28 Aug 2019 18:01:38 -0600
Subject: [ndctl PATCH v2] ndctl/namespace: add a --continue option to create
 namespaces greedily

Add a --continue option to ndctl-create-namespaces to allow the creation
of as many namespaces as possible, that meet the given filter
restrictions.

The creation loop will be aborted if a failure is encountered at any
point, unless --force is also specified.

Link: https://github.com/pmem/ndctl/issues/106
Reported-by: Steve Scargal <steve.scargall@intel.com>
Cc: Jeff Moyer <jmoyer@redhat.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---

v2: Allow --force to continue in spite of errors (Dan)

 .../ndctl/ndctl-create-namespace.txt          | 11 +++++-
 ndctl/namespace.c                             | 34 +++++++++++++++----
 2 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/Documentation/ndctl/ndctl-create-namespace.txt b/Documentation/ndctl/ndctl-create-namespace.txt
index c9ae27c..e29a5e7 100644
--- a/Documentation/ndctl/ndctl-create-namespace.txt
+++ b/Documentation/ndctl/ndctl-create-namespace.txt
@@ -152,6 +152,13 @@ OPTIONS
 	namespace directly ("--map=dev"). The overhead is 64-bytes per
 	4K (16GB per 1TB) on x86.
 
+-c::
+--continue::
+	Do not stop after creating one namespace. Instead, greedily create as
+	many namespaces as possible within the given --bus and --region filter
+	restrictions. This will abort if any creation attempt results in an
+	error unless --force is also supplied.
+
 -f::
 --force::
 	Unless this option is specified the 'reconfigure namespace'
@@ -160,7 +167,9 @@ OPTIONS
 	the operation is attempted. However, if the namespace is
 	mounted then the 'disable namespace' and 'reconfigure
 	namespace' operations will be aborted.  The namespace must be
-	unmounted before being reconfigured.
+	unmounted before being reconfigured. When used in conjunction
+	with --continue, continue the namespace creation loop even
+	if an error is encountered for intermediate namespaces.
 
 -L::
 --autolabel::
diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index af20a42..67768f3 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -41,6 +41,7 @@ static struct parameters {
 	bool do_scan;
 	bool mode_default;
 	bool autolabel;
+	bool greedy;
 	const char *bus;
 	const char *map;
 	const char *type;
@@ -114,7 +115,9 @@ OPT_STRING('t', "type", &param.type, "type", \
 OPT_STRING('a', "align", &param.align, "align", \
 	"specify the namespace alignment in bytes (default: 2M)"), \
 OPT_BOOLEAN('f', "force", &force, "reconfigure namespace even if currently active"), \
-OPT_BOOLEAN('L', "autolabel", &param.autolabel, "automatically initialize labels")
+OPT_BOOLEAN('L', "autolabel", &param.autolabel, "automatically initialize labels"), \
+OPT_BOOLEAN('c', "continue", &param.greedy, \
+	"continue creating namespaces as long as the filter criteria are met")
 
 #define CHECK_OPTIONS() \
 OPT_BOOLEAN('R', "repair", &repair, "perform metadata repairs"), \
@@ -1322,10 +1325,10 @@ static int do_xaction_namespace(const char *namespace,
 		int *processed)
 {
 	struct ndctl_namespace *ndns, *_n;
+	int rc = -ENXIO, saved_rc = 0;
 	struct ndctl_region *region;
 	const char *ndns_name;
 	struct ndctl_bus *bus;
-	int rc = -ENXIO;
 
 	*processed = 0;
 
@@ -1365,8 +1368,16 @@ static int do_xaction_namespace(const char *namespace,
 				rc = namespace_create(region);
 				if (rc == -EAGAIN)
 					continue;
-				if (rc == 0)
-					*processed = 1;
+				if (rc == 0) {
+					(*processed)++;
+					if (param.greedy)
+						continue;
+				}
+				if (force) {
+					if (rc)
+						saved_rc = rc;
+					continue;
+				}
 				return rc;
 			}
 			ndctl_namespace_foreach_safe(region, ndns, _n) {
@@ -1427,10 +1438,18 @@ static int do_xaction_namespace(const char *namespace,
 		/*
 		 * Namespace creation searched through all candidate
 		 * regions and all of them said "nope, I don't have
-		 * enough capacity", so report -ENOSPC
+		 * enough capacity", so report -ENOSPC. Except during
+		 * greedy namespace creation using --continue as we
+		 * may have created some namespaces already, and the
+		 * last one in the region search may preexist.
 		 */
-		rc = -ENOSPC;
+		if (param.greedy && (*processed) > 0)
+			rc = 0;
+		else
+			rc = -ENOSPC;
 	}
+	if (saved_rc)
+		rc = saved_rc;
 
 	return rc;
 }
@@ -1487,6 +1506,9 @@ int cmd_create_namespace(int argc, const char **argv, struct ndctl_ctx *ctx)
 		rc = do_xaction_namespace(NULL, ACTION_CREATE, ctx, &created);
 	}
 
+	if (param.greedy)
+		fprintf(stderr, "created %d namespace%s\n", created,
+			created == 1 ? "" : "s");
 	if (rc < 0 || (!namespace && created < 1)) {
 		fprintf(stderr, "failed to %s namespace: %s\n", namespace
 				? "reconfigure" : "create", strerror(-rc));
-- 
2.20.1

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

  reply	other threads:[~2019-08-29 19:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-29  0:17 [ndctl PATCH 0/3] greedy namespace creation Vishal Verma
2019-08-29  0:17 ` [ndctl PATCH 1/3] Documentation: refactor 'bus options' into its own include Vishal Verma
2019-08-29  0:17 ` [ndctl PATCH 2/3] Documentation: clarify bus/dimm/region filtering Vishal Verma
2019-08-29  0:17 ` [ndctl PATCH 3/3] ndctl/namespace: add a --continue option to create namespaces greedily Vishal Verma
2019-08-29  2:34   ` Dan Williams
2019-08-29 18:05     ` Verma, Vishal L
2019-08-29 19:08       ` Vishal Verma [this message]
2019-08-29 17:38   ` jane.chu
2019-08-29 18:08     ` Verma, Vishal L
2019-08-29 18:28       ` Dan Williams
2019-08-29 19:16         ` jane.chu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190829190852.GA14129@vverma7-desk1.lm.intel.com \
    --to=vishal.l.verma@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=linux-nvdimm@lists.01.org \
    --cc=steve.scargall@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).