]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
fabrics: show number of controllers disconnected
authorKeith Busch <keith.busch@intel.com>
Fri, 16 Dec 2016 23:35:15 +0000 (18:35 -0500)
committerKeith Busch <keith.busch@intel.com>
Fri, 16 Dec 2016 23:40:05 +0000 (18:40 -0500)
Multiple controllers may have the same nqn, so we iterate multiple
times and don't want to return the status of just the last one to try to
disconnect. This patch has the status show the number of controllers that
were disconnected based on that nqn as that should be more informative.

Signed-off-by: Keith Busch <keith.busch@intel.com>
fabrics.c

index d62373fd30156305c51b7d3f57e29b3598bdbd0f..a9898d15a71280f25c0532874273c236da758cf3 100644 (file)
--- a/fabrics.c
+++ b/fabrics.c
@@ -808,6 +808,9 @@ static int scan_sys_nvme_filter(const struct dirent *d)
        return 1;
 }
 
+/*
+ * Returns 1 if disconnect occurred, 0 otherwise.
+ */
 static int disconnect_subsys(char *nqn, char *ctrl)
 {
        char *sysfs_nqn_path, *sysfs_del_path;;
@@ -828,7 +831,8 @@ static int disconnect_subsys(char *nqn, char *ctrl)
        if (strcmp(subsysnqn, nqn))
                goto close;
 
-       ret = remove_ctrl_by_path(sysfs_del_path);
+       if (!remove_ctrl_by_path(sysfs_del_path))
+               ret = 1;
  close:
        close(fd);
  free:
@@ -837,6 +841,9 @@ static int disconnect_subsys(char *nqn, char *ctrl)
        return ret;
 }
 
+/*
+ * Returns the number of controllers successfully disconnected.
+ */
 static int disconnect_by_nqn(char *nqn)
 {
        struct dirent **devices = NULL;
@@ -850,11 +857,12 @@ static int disconnect_by_nqn(char *nqn)
                return n;
 
        for (i = 0; i < n; i++)
-               ret = disconnect_subsys(nqn, devices[i]->d_name);
+               ret += disconnect_subsys(nqn, devices[i]->d_name);
 
        for (i = 0; i < n; i++)
                free(devices[i]);
        free(devices);
+
        return ret;
 }
 
@@ -891,9 +899,11 @@ int disconnect(const char *desc, int argc, char **argv)
 
        if (cfg.nqn) {
                ret = disconnect_by_nqn(cfg.nqn);
-               if (ret)
+               if (ret < 0)
                        fprintf(stderr, "Failed to disconnect by NQN: %s\n",
                                cfg.nqn);
+               else
+                       printf("NQN:%s disconnected %d controller(s)\n", cfg.nqn, ret);
        }
 
        if (cfg.device) {