[PATCH 01/10] nvme-discover: lookup existing persistent controllers
From: <hidden>
Date: 2021-03-06 00:37:27
Subsystem:
the rest · Maintainer:
Linus Torvalds
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 which does not have this attribute or for which the attribute is '0' will be skipped. Signed-off-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Martin Wilck <redacted> --- fabrics.c | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-)
diff --git a/fabrics.c b/fabrics.c
index f84c45b..14899cc 100644
--- a/fabrics.c
+++ b/fabrics.c@@ -320,6 +320,27 @@ 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, 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. + * + * The 'kato' attribute might not be present; assume a + * non-persistent controller for these installations. + */ + if (kato_str) { + kato = strtoul(kato_str, &p, 0); + if (p == kato_str) + kato = 0; + } + if (kato == 0) + return found; + } if (!strcmp(cargs.subsysnqn, args->subsysnqn) && !strcmp(cargs.transport, args->transport) && (!strcmp(cargs.traddr, args->traddr) ||
@@ -1345,30 +1366,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.29.2
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme