Linux sysfs change broke fio disk lookup
authorJens Axboe <jens.axboe@oracle.com>
Fri, 6 Jun 2008 10:08:04 +0000 (12:08 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Fri, 6 Jun 2008 10:08:04 +0000 (12:08 +0200)
/sys/block/<dev> is now a sym link to the real path, which
broke our disk lookup. Fix it.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diskutil.c

index a38f4fa3f73970a798cc4a2ed838b232256a5490..9fb31bf2be44f6c6e9f997e204a10fb6b7574aa1 100644 (file)
@@ -170,7 +170,7 @@ static int check_dev_match(int majdev, int mindev, char *path)
        return 1;
 }
 
        return 1;
 }
 
-static int find_block_dir(int majdev, int mindev, char *path)
+static int find_block_dir(int majdev, int mindev, char *path, int link_ok)
 {
        struct dirent *dir;
        struct stat st;
 {
        struct dirent *dir;
        struct stat st;
@@ -196,15 +196,22 @@ static int find_block_dir(int majdev, int mindev, char *path)
                        }
                }
 
                        }
                }
 
-               if (lstat(full_path, &st) == -1) {
-                       perror("stat");
-                       break;
+               if (link_ok) {
+                       if (stat(full_path, &st) == -1) {
+                               perror("stat");
+                               break;
+                       }
+               } else {
+                       if (lstat(full_path, &st) == -1) {
+                               perror("stat");
+                               break;
+                       }
                }
 
                if (!S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode))
                        continue;
 
                }
 
                if (!S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode))
                        continue;
 
-               found = find_block_dir(majdev, mindev, full_path);
+               found = find_block_dir(majdev, mindev, full_path, 0);
                if (found) {
                        strcpy(path, full_path);
                        break;
                if (found) {
                        strcpy(path, full_path);
                        break;
@@ -277,7 +284,7 @@ static void __init_disk_util(struct thread_data *td, struct fio_file *f)
        last_majdev = majdev;
 
        sprintf(foo, "/sys/block");
        last_majdev = majdev;
 
        sprintf(foo, "/sys/block");
-       if (!find_block_dir(majdev, mindev, foo))
+       if (!find_block_dir(majdev, mindev, foo, 1))
                return;
 
        /*
                return;
 
        /*