libmultipath: do not fallback to search /proc/partitions
authorHannes Reinecke <hare@suse.de>
Fri, 28 Jan 2011 08:21:15 +0000 (09:21 +0100)
committerHannes Reinecke <hare@suse.de>
Tue, 17 May 2011 10:02:33 +0000 (12:02 +0200)
devt2devname() reverse-maps the device number to the
device name. However, when a device is not found in
/sys/block/dev it's pointless to retry searching for
it in /proc/partitions, as both carry the same information.
And the search in /proc/partitions is only meant for
systems not providing /sys/block.

Signed-off-by: Hannes Reinecke <hare@suse.de>
libmultipath/util.c

index f2ad630..62b1aa1 100644 (file)
@@ -169,22 +169,25 @@ devt2devname (char *devname, int devname_len, char *devt)
        if (devname_len > FILE_NAME_SIZE)
                devname_len = FILE_NAME_SIZE;
 
-       sprintf(block_path,"/sys/dev/block/%u:%u", major, minor);
-       if (stat(block_path, &statbuf) == 0) {
+       if (stat("/sys/dev/block", &statbuf) == 0) {
                /* Newer kernels have /sys/dev/block */
-               if (S_ISLNK(statbuf.st_mode) &&
-                   readlink(block_path, dev, FILE_NAME_SIZE) > 0) {
-                       char *p = strrchr(dev, '/');
-
-                       if (!p) {
-                               condlog(0, "No sysfs entry for %s\n",
-                                       block_path);
-                               return 1;
+               sprintf(block_path,"/sys/dev/block/%u:%u", major, minor);
+               if (stat(block_path, &statbuf) == 0) {
+                       if (S_ISLNK(statbuf.st_mode) &&
+                           readlink(block_path, dev, FILE_NAME_SIZE) > 0) {
+                               char *p = strrchr(dev, '/');
+
+                               if (!p) {
+                                       condlog(0, "No sysfs entry for %s\n",
+                                               block_path);
+                                       return 1;
+                               }
+                               p++;
+                               strncpy(devname, p, devname_len);
+                               return 0;
                        }
-                       p++;
-                       strncpy(devname, p, devname_len);
-                       return 0;
                }
+               goto skip_proc;
        }
        memset(block_path, 0, sizeof(block_path));
 
@@ -213,9 +216,9 @@ devt2devname (char *devname, int devname_len, char *devt)
                }
        }
        fclose(fd);
-
+skip_proc:
        if (strncmp(block_path,"/sys/block", 10)) {
-               condlog(3, "device %s not found\n", dev);
+               condlog(3, "No device found for %u:%u\n", major, minor);
                return 1;
        }