From: Daniel Wagner Date: Tue, 19 Jul 2022 09:53:12 +0000 (+0200) Subject: fabrics: Avoid nvme_scan_ctrl when disconnecting X-Git-Tag: v2.1~7^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=40d7cc0050d0c0dd06ac76880c2a81ecf25eb796;p=users%2Fsagi%2Fnvme-cli.git fabrics: Avoid nvme_scan_ctrl when disconnecting In certain corner cases, the kernel will not populate a nvme subsystem but only create a nvme controller. nvme_scan_ctrl will fail in such scenarios to find the controller object. Let's do the lookup based on the ctrl name only. Signed-off-by: Daniel Wagner --- diff --git a/fabrics.c b/fabrics.c index 58a7c31d..ad1668c0 100644 --- a/fabrics.c +++ b/fabrics.c @@ -903,6 +903,23 @@ out_free: return errno; } +static nvme_ctrl_t lookup_nvme_ctrl(nvme_root_t r, const char *name) +{ + nvme_host_t h; + nvme_subsystem_t s; + nvme_ctrl_t c; + + nvme_for_each_host(r, h) { + nvme_for_each_subsystem(h, s) { + nvme_subsystem_for_each_ctrl(s, c) { + if (!strcmp(nvme_ctrl_get_name(c), name)) + return c; + } + } + } + return NULL; +} + int nvmf_disconnect(const char *desc, int argc, char **argv) { const char *device = "nvme device handle"; @@ -980,11 +997,10 @@ int nvmf_disconnect(const char *desc, int argc, char **argv) while ((p = strsep(&d, ",")) != NULL) { if (!strncmp(p, "/dev/", 5)) p += 5; - c = nvme_scan_ctrl(r, p); + c = lookup_nvme_ctrl(r, p); if (!c) { fprintf(stderr, - "Did not find device %s: %s\n", - p, nvme_strerror(errno)); + "Did not find device %s\n", p); nvme_free_tree(r); return errno; }