]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
nvmf: use discovery controller host identifiers for persistent controllers
authorSagi Grimberg <sagi@grimberg.me>
Tue, 24 Mar 2020 08:53:28 +0000 (01:53 -0700)
committerKeith Busch <kbusch@kernel.org>
Wed, 1 Apr 2020 19:40:50 +0000 (12:40 -0700)
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 <yogev@lightbitslabs.com>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Keith Busch <kbusch@kernel.org>
fabrics.c

index a112f76c146cfe70798c998a73e67664ad876328..e2c9bfb37177aca0281f5664db470c1732736a20 100644 (file)
--- 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;