linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: mwilck@suse.com
To: Sagi Grimberg <sagi@grimberg.me>, Hannes Reinecke <hare@suse.de>,
	Keith Busch <kbusch@kernel.org>
Cc: Chaitanya Kulkarni <Chaitanya.Kulkarni@wdc.com>,
	linux-nvme@lists.infradead.org,
	Enzo Matsumiya <ematsumiya@suse.de>,
	Martin Wilck <mwilck@suse.com>
Subject: [PATCH 02/10] nvme-discover: assume device given on command line is persistent
Date: Sat,  6 Mar 2021 01:36:16 +0100	[thread overview]
Message-ID: <20210306003624.21102-3-mwilck@suse.com> (raw)
In-Reply-To: <20210306003624.21102-1-mwilck@suse.com>

From: Martin Wilck <mwilck@suse.com>

After commit "nvme-discover: lookup existing persistent controllers",
controllers without the "kato" sysfs attribute will never be used by
do_discover(). This makes sense for controllers found while traversing
sysfs in find_ctrl_with_connectargs(), but if the user passed a
device explicitly, it should be used, even on older kernels that
don't support the "kato" attribute.

Furthermore, make sure allocated memory in ctrl_matches_connectargs()
is freed.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 fabrics.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/fabrics.c b/fabrics.c
index 14899cc..dcee0c4 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -297,12 +297,14 @@ static int ctrl_instance(char *device)
  * given.
  * Return true/false based on whether it matches
  */
-static bool ctrl_matches_connectargs(char *name, struct connect_args *args)
+static bool ctrl_matches_connectargs(char *name, struct connect_args *args,
+				     bool assume_persistent)
 {
 	struct connect_args cargs;
 	bool found = false;
 	char *path, *addr;
 	int ret;
+	bool persistent = true;
 
 	ret = asprintf(&path, "%s/%s", SYS_NVME, name);
 	if (ret < 0)
@@ -331,17 +333,21 @@ static bool ctrl_matches_connectargs(char *name, struct connect_args *args)
 		 * underneath us as they are owned by another program.
 		 *
 		 * The 'kato' attribute might not be present; assume a
-		 * non-persistent controller for these installations.
+		 * non-persistent controller for these installations,
+		 * unless assume_persistent is set.
 		 */
 		if (kato_str) {
 			kato = strtoul(kato_str, &p, 0);
 			if (p == kato_str)
 				kato = 0;
-		}
-		if (kato == 0)
-			return found;
+			free(kato_str);
+			persistent = (kato != 0);
+		} else if (!assume_persistent)
+			persistent = false;
 	}
-	if (!strcmp(cargs.subsysnqn, args->subsysnqn) &&
+
+	if (persistent &&
+	    !strcmp(cargs.subsysnqn, args->subsysnqn) &&
 	    !strcmp(cargs.transport, args->transport) &&
 	    (!strcmp(cargs.traddr, args->traddr) ||
 	     !strcmp(args->traddr, "none")) &&
@@ -380,7 +386,7 @@ static char *find_ctrl_with_connectargs(struct connect_args *args)
 	}
 
 	for (i = 0; i < n; i++) {
-		if (ctrl_matches_connectargs(devices[i]->d_name, args)) {
+		if (ctrl_matches_connectargs(devices[i]->d_name, args, false)) {
 			devname = strdup(devices[i]->d_name);
 			if (devname == NULL)
 				fprintf(stderr, "no memory for ctrl name %s\n",
@@ -1372,7 +1378,7 @@ static int do_discover(char *argstr, bool connect, enum nvme_print_flags flags)
 	if (!cargs)
 		return -ENOMEM;
 
-	if (!cfg.device || !ctrl_matches_connectargs(cfg.device, cargs))
+	if (!cfg.device || !ctrl_matches_connectargs(cfg.device, cargs, true))
 		cfg.device = find_ctrl_with_connectargs(cargs);
 	free_connect_args(cargs);
 
-- 
2.29.2


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

  parent reply	other threads:[~2021-03-06  0:37 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-06  0:36 [PATCH 00/10] Some minor fixes/additions for nvme-cli mwilck
2021-03-06  0:36 ` [PATCH 01/10] nvme-discover: lookup existing persistent controllers mwilck
2021-03-15 17:38   ` Sagi Grimberg
2021-03-15 17:43     ` Martin Wilck
2021-03-16  9:36     ` Hannes Reinecke
2021-03-06  0:36 ` mwilck [this message]
2021-03-15 17:41   ` [PATCH 02/10] nvme-discover: assume device given on command line is persistent Sagi Grimberg
2021-03-15 17:51     ` Martin Wilck
2021-03-06  0:36 ` [PATCH 03/10] do_discover: free cfg.device when resetting it mwilck
2021-03-06  0:36 ` [PATCH 04/10] nvme-connect-all(1): fix documentation for --quiet/-S mwilck
2021-03-08  7:12   ` Chaitanya Kulkarni
2021-03-15 17:44   ` Sagi Grimberg
2021-03-06  0:36 ` [PATCH 05/10] nvme: add some simplifying macros for __attribute__((cleanup())) mwilck
2021-03-08  7:10   ` Chaitanya Kulkarni
2021-03-15 17:44   ` Sagi Grimberg
2021-03-06  0:36 ` [PATCH 06/10] nvme-cli: add generic logging functionality mwilck
2021-03-08  7:15   ` Chaitanya Kulkarni
2021-03-08  7:17   ` Chaitanya Kulkarni
2021-03-15 17:45   ` Sagi Grimberg
2021-03-16  8:14     ` Martin Wilck
2021-03-06  0:36 ` [PATCH 07/10] nvme: convert some function arguments from "char *" to "const char *" mwilck
2021-03-08  7:13   ` Chaitanya Kulkarni
2021-03-15 17:46   ` Sagi Grimberg
2021-03-06  0:36 ` [PATCH 08/10] fabrics: use "const char *" in struct config mwilck
2021-03-08  7:08   ` Chaitanya Kulkarni
2021-03-15 17:46   ` Sagi Grimberg
2021-03-06  0:36 ` [PATCH 09/10] fabrics: fix some memory leaks mwilck
2021-03-08  7:13   ` Chaitanya Kulkarni
2021-03-15 17:46   ` Sagi Grimberg
2021-03-06  0:36 ` [PATCH 10/10] fabrics: fix invalid memory access in discover_from_conf_file() mwilck

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=20210306003624.21102-3-mwilck@suse.com \
    --to=mwilck@suse.com \
    --cc=Chaitanya.Kulkarni@wdc.com \
    --cc=ematsumiya@suse.de \
    --cc=hare@suse.de \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /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).