From: mwilck@suse.com
To: Keith Busch <kbusch@kernel.org>, Sagi Grimberg <sagi@grimberg.me>,
Chaitanya Kulkarni <Chaitanya.Kulkarni@wdc.com>,
Hannes Reinecke <hare@suse.de>
Cc: linux-nvme@lists.infradead.org, Enzo Matsumiya <ematsumiya@suse.de>
Subject: [PATCH v2 1/9] nvme-discover: lookup existing persistent controllers
Date: Tue, 30 Mar 2021 17:57:03 +0200 [thread overview]
Message-ID: <20210330155711.8436-2-mwilck@suse.com> (raw)
In-Reply-To: <20210330155711.8436-1-mwilck@suse.com>
From: Hannes Reinecke <hare@suse.de>
If persistent controller connections are present they should be
preferred even if no --device option is given on the commandline.
To avoid selecting a temporary non-persistent controller the
'kato' attribute is checked; any controller for which the
attribute is '0' will be skipped. This logic is not applied on
older kernels that don't support the 'kato' attribute. On these
kernels, we just have to assume that the encountered discovery
controller is persistent.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin Wilck <mwilck@suse.de>
Signed-off-by: Martin Wilck <mwilck@suse.com>
---
fabrics.c | 55 ++++++++++++++++++++++++++++++++-----------------------
1 file changed, 32 insertions(+), 23 deletions(-)
diff --git a/fabrics.c b/fabrics.c
index 227773d..bdd0679 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -303,6 +303,7 @@ static bool ctrl_matches_connectargs(char *name, struct connect_args *args)
bool found = false;
char *path, *addr;
int ret;
+ bool persistent = true;
ret = asprintf(&path, "%s/%s", SYS_NVME, name);
if (ret < 0)
@@ -320,7 +321,30 @@ static bool ctrl_matches_connectargs(char *name, struct connect_args *args)
cargs.trsvcid = parse_conn_arg(addr, ' ', conarg_trsvcid);
cargs.host_traddr = parse_conn_arg(addr, ' ', conarg_host_traddr);
- if (!strcmp(cargs.subsysnqn, args->subsysnqn) &&
+ if (!strcmp(cargs.subsysnqn, NVME_DISC_SUBSYS_NAME)) {
+ char *kato_str = nvme_get_ctrl_attr(path, "kato"), *p;
+ unsigned int kato = 0;
+
+ /*
+ * When looking up discovery controllers we have to skip
+ * any non-persistent controllers (ie those with a zero
+ * kato value). Otherwise the controller will vanish from
+ * underneath us as they are owned by another program.
+ *
+ * On older kernels, the 'kato' attribute isn't present.
+ * Assume a persistent controller for these installations.
+ */
+ if (kato_str) {
+ kato = strtoul(kato_str, &p, 0);
+ if (p == kato_str)
+ kato = 0;
+ free(kato_str);
+ persistent = (kato != 0);
+ }
+ }
+
+ if (persistent &&
+ !strcmp(cargs.subsysnqn, args->subsysnqn) &&
!strcmp(cargs.transport, args->transport) &&
(!strcmp(cargs.traddr, args->traddr) ||
!strcmp(args->traddr, "none")) &&
@@ -1346,30 +1370,15 @@ static int do_discover(char *argstr, bool connect, enum nvme_print_flags flags)
char *dev_name;
int instance, numrec = 0, ret, err;
int status = 0;
+ struct connect_args *cargs;
- if (cfg.device) {
- struct connect_args *cargs;
+ cargs = extract_connect_args(argstr);
+ if (!cargs)
+ return -ENOMEM;
- cargs = extract_connect_args(argstr);
- if (!cargs)
- return -ENOMEM;
-
- /*
- * if the cfg.device passed in matches the connect args
- * cfg.device is left as-is
- * else if there exists a controller that matches the
- * connect args
- * cfg.device is the matching ctrl name
- * else if no ctrl matches the connect args
- * cfg.device is set to null. This will attempt to
- * create a new ctrl.
- * endif
- */
- if (!ctrl_matches_connectargs(cfg.device, cargs))
- cfg.device = find_ctrl_with_connectargs(cargs);
-
- free_connect_args(cargs);
- }
+ if (!cfg.device || !ctrl_matches_connectargs(cfg.device, cargs))
+ cfg.device = find_ctrl_with_connectargs(cargs);
+ free_connect_args(cargs);
if (!cfg.device) {
instance = add_ctrl(argstr);
--
2.30.1
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
next prev parent reply other threads:[~2021-03-30 15:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-30 15:57 [PATCH v2 0/9] Some minor fixes/additions for nvme-cli mwilck
2021-03-30 15:57 ` mwilck [this message]
2021-03-30 15:57 ` [PATCH v2 2/9] do_discover: free cfg.device when resetting it mwilck
2021-03-30 15:57 ` [PATCH v2 3/9] nvme-connect-all(1): fix documentation for --quiet/-S mwilck
2021-03-30 15:57 ` [PATCH v2 4/9] nvme: add some simplifying macros for __attribute__((cleanup())) mwilck
2021-03-30 15:57 ` [PATCH v2 5/9] nvme-cli: add generic logging functionality mwilck
2021-03-30 15:57 ` [PATCH v2 6/9] nvme: convert some function arguments from "char *" to "const char *" mwilck
2021-03-30 15:57 ` [PATCH v2 7/9] fabrics: use "const char *" in struct config mwilck
2021-03-30 15:57 ` [PATCH v2 8/9] fabrics: fix some memory leaks mwilck
2021-03-30 15:57 ` [PATCH v2 9/9] 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=20210330155711.8436-2-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