[libmultipath] fix "show devices" CLI command
authorChristophe Varoqui <christophe.varoqui@free.fr>
Sun, 18 Nov 2007 18:01:15 +0000 (19:01 +0100)
committerChristophe Varoqui <christophe.varoqui@free.fr>
Sun, 18 Nov 2007 18:01:15 +0000 (19:01 +0100)
Whatever this command was intented to do, it did not.
I still don't see the usefulness, but now it displays :

    ...
    sdf devnode whitelisted, monitored
    sdb devnode whitelisted, unmonitored
    sda devnode whitelisted, unmonitored
    ram15 devnode blacklisted, unmonitored
    ...

libmultipath/print.c

index 01a157a..9ac5cc0 100644 (file)
@@ -1118,15 +1118,16 @@ snprint_devices (char * buff, int len, struct vectors *vecs)
                return len;
        fwd += snprintf(buff + fwd, len - fwd, "available block devices:\n");
 
-       strcpy(devpath,"/sys/block");
-       devptr = devpath + 10;
+       strcpy(devpath,"/sys/block/");
        while ((blkdev = readdir(blkdir)) != NULL) {
                if ((strcmp(blkdev->d_name,".") == 0) ||
                    (strcmp(blkdev->d_name,"..") == 0))
                        continue;
 
-               strcat(devptr,blkdev->d_name);
-               if (stat(devptr, &statbuf) < 0)
+               devptr = devpath + 11;
+               *devptr = '\0';
+               strncat(devptr, blkdev->d_name, PATH_MAX-12);
+               if (stat(devpath, &statbuf) < 0)
                        continue;
 
                if (S_ISDIR(statbuf.st_mode) == 0)
@@ -1135,18 +1136,20 @@ snprint_devices (char * buff, int len, struct vectors *vecs)
                if ((len - fwd - threshold)  <= 0)
                        return len;
 
-               fwd += snprintf(buff + fwd, len - fwd, "    %s", devpath);
-               pp = find_path_by_dev(vecs->pathvec, devpath);
+               fwd += snprintf(buff + fwd, len - fwd, "    %s", devptr);
+               pp = find_path_by_dev(vecs->pathvec, devptr);
                if (!pp) {
                        r = filter_devnode(conf->blist_devnode,
-                                          conf->elist_devnode, devpath);
+                                          conf->elist_devnode, devptr);
                        if (r > 0)
                                fwd += snprintf(buff + fwd, len - fwd,
-                                               " (blacklisted)");
+                                               " devnode blacklisted, unmonitored");
                        else if (r < 0)
                                fwd += snprintf(buff + fwd, len - fwd,
-                                               " (whitelisted)");
-               }
+                                               " devnode whitelisted, unmonitored");
+               } else
+                       fwd += snprintf(buff + fwd, len - fwd,
+                                       " devnode whitelisted, monitored");
                fwd += snprintf(buff + fwd, len - fwd, "\n");
        }
        closedir(blkdir);