From: Sagi Grimberg Date: Tue, 24 Mar 2020 08:53:28 +0000 (-0700) Subject: nvmf: use discovery controller host identifiers for persistent controllers X-Git-Tag: v1.11~15 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=4ec74f0a9985d7680618ab02e0541ca294704f1e;p=users%2Fhch%2Fnvme-cli.git nvmf: use discovery controller host identifiers for persistent controllers It is possible that the user will create a persistent discovery controller with a specific host identifiers (hostnqn and/or hostid). If we get a discovery change log event on this discovery controller we need to use the same host identifiers that otherwise we will may not see what the discovery change log event intended us to see (as we connect with a different hostnqn for example). Note that we take these identifiers only if they exist in sysfs which gives us backward compatibility (as hostnqn and hostid are still new). Reported-by: Yogev Cohen Signed-off-by: Sagi Grimberg Signed-off-by: Keith Busch --- diff --git a/fabrics.c b/fabrics.c index a112f76..e2c9bfb 100644 --- a/fabrics.c +++ b/fabrics.c @@ -1079,6 +1079,16 @@ static int connect_ctrls(struct nvmf_disc_rsp_page_hdr *log, int numrec) return ret; } +static void nvmf_get_host_identifiers(int ctrl_instance) +{ + char *path; + + if (asprintf(&path, "%s/nvme%d", SYS_NVME, ctrl_instance) < 0) + return; + cfg.hostnqn = nvme_get_ctrl_attr(path, "hostnqn"); + cfg.hostid = nvme_get_ctrl_attr(path, "hostid"); +} + static int do_discover(char *argstr, bool connect) { struct nvmf_disc_rsp_page_hdr *log = NULL; @@ -1117,10 +1127,12 @@ static int do_discover(char *argstr, bool connect) free(cargs.host_traddr); } - if (!cfg.device) + if (!cfg.device) { instance = add_ctrl(argstr); - else + } else { instance = ctrl_instance(cfg.device); + nvmf_get_host_identifiers(instance); + } if (instance < 0) return instance;