]> sourceware.org Git - lvm2.git/commitdiff
filters: drop extra slash from sysfs path
authorZdenek Kabelac <zkabelac@redhat.com>
Thu, 21 Nov 2013 16:50:12 +0000 (17:50 +0100)
committerZdenek Kabelac <zkabelac@redhat.com>
Fri, 22 Nov 2013 19:53:31 +0000 (20:53 +0100)
Sysfs filter was using '/sys//class/block' with double '//' inside.
Remove this extra '/'.
Also simplify code around and use loop to try those paths.

WHATS_NEW
lib/filters/filter-sysfs.c

index 647c81036215aba3a6ab4ed8b4ef35728d943a0e..b7a1e84a490b61c137f9f2d92afa6e73bbc0933b 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 2.02.105 -
 =====================================
+  Drop extra unneeded '/' when scanning sysfs directory.
   Fix undef value if skipped clustered VG ignored for toollib PV seg. (2.02.103)
   liblvm/python API Add ability to validate VG/LV names.
   liblvm/python API Add ability to create PV with arguments.
index af3ed078daf363b16314323feda3e00af6d86ec0..ff948108e2848fa8826a7acf8ffe7e15e957a4ce 100644 (file)
@@ -23,64 +23,61 @@ static int _locate_sysfs_blocks(const char *sysfs_dir, char *path, size_t len,
                                unsigned *sysfs_depth)
 {
        struct stat info;
-
-       /*
-        * unified classification directory for all kernel subsystems
-        *
-        * /sys/subsystem/block/devices
-        * |-- sda -> ../../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda
-        * |-- sda1 -> ../../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1
-        *  `-- sr0 -> ../../../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0
-        *
-        */
-       if (dm_snprintf(path, len, "%s/%s", sysfs_dir,
-                       "subsystem/block/devices") >= 0) {
-               if (!stat(path, &info)) {
-                       *sysfs_depth = 0;
-                       return 1;
-               }
-       }
-
-       /*
-        * block subsystem as a class
-        *
-        * /sys/class/block
-        * |-- sda -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda
-        * |-- sda1 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1
-        *  `-- sr0 -> ../../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0
-        *
-        */
-       if (dm_snprintf(path, len, "%s/%s", sysfs_dir, "class/block") >= 0) {
-               if (!stat(path, &info)) {
-                       *sysfs_depth = 0;
+       unsigned i;
+       static const struct dir_class {
+               const char path[32];
+               int depth;
+       } classes[] = {
+               /*
+                * unified classification directory for all kernel subsystems
+                *
+                * /sys/subsystem/block/devices
+                * |-- sda -> ../../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda
+                * |-- sda1 -> ../../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1
+                *  `-- sr0 -> ../../../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0
+                *
+                */
+               { "subsystem/block/devices", 0 },
+
+               /*
+                * block subsystem as a class
+                *
+                * /sys/class/block
+                * |-- sda -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda
+                * |-- sda1 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1
+                *  `-- sr0 -> ../../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0
+                *
+                */
+               { "class/block", 0 },
+
+               /*
+                * old block subsystem layout with nested directories
+                *
+                * /sys/block/
+                * |-- sda
+                * |   |-- capability
+                * |   |-- dev
+                * ...
+                * |   |-- sda1
+                * |   |   |-- dev
+                * ...
+                * |
+                * `-- sr0
+                *     |-- capability
+                *     |-- dev
+                * ...
+                *
+                */
+
+               { "block", 1 }
+       };
+
+       for (i = 0; i < DM_ARRAY_SIZE(classes); ++i)
+               if ((dm_snprintf(path, len, "%s%s", sysfs_dir, classes[i].path) >= 0) &&
+                   (stat(path, &info) == 0)) {
+                       *sysfs_depth = classes[i].depth;
                        return 1;
                }
-       }
-
-       /*
-        * old block subsystem layout with nested directories
-        *
-        * /sys/block/
-        * |-- sda
-        * |   |-- capability
-        * |   |-- dev
-        * ...
-        * |   |-- sda1
-        * |   |   |-- dev
-        * ...
-        * |
-        * `-- sr0
-        *     |-- capability
-        *     |-- dev
-        * ...
-        *
-        */
-       if (dm_snprintf(path, len, "%s/%s", sysfs_dir, "block") >= 0) {
-               if (!stat(path, &info)) {
-                       *sysfs_depth = 1;
-                       return 1;
-               }
-       }
 
        return 0;
 }
This page took 0.055253 seconds and 5 git commands to generate.