linux-dev-lookup.c: Put the check for replay_redirect in the beginning
authorLukas Straub <lukasstraub2@web.de>
Wed, 19 Jan 2022 21:14:26 +0000 (21:14 +0000)
committerJens Axboe <axboe@kernel.dk>
Thu, 20 Jan 2022 18:40:42 +0000 (11:40 -0700)
The machine may not have any block device nodes (like my dev container)
which makes this function fail despite replay_redirect being set.

Move the check to the beginning to fix this.

Signed-off-by: Lukas Straub <lukasstraub2@web.de>
Link: https://lore.kernel.org/r/0dd4b6407f7b7f5f15f1fcad409554ff339ffca1.1642626314.git.lukasstraub2@web.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
oslib/linux-dev-lookup.c

index 1dda93f2a0ef3fa0e537a9ccdf202a9a624ecb35..4335faf99b91b1c1876afd836673f1d4cb658472 100644 (file)
@@ -16,6 +16,16 @@ int blktrace_lookup_device(const char *redirect, char *path, unsigned int maj,
        int found = 0;
        DIR *D;
 
        int found = 0;
        DIR *D;
 
+       /*
+        * If replay_redirect is set then always return this device
+        * upon lookup which overrides the device lookup based on
+        * major minor in the actual blktrace
+        */
+       if (redirect) {
+               strcpy(path, redirect);
+               return 1;
+       }
+
        D = opendir(path);
        if (!D)
                return 0;
        D = opendir(path);
        if (!D)
                return 0;
@@ -44,17 +54,6 @@ int blktrace_lookup_device(const char *redirect, char *path, unsigned int maj,
                if (!S_ISBLK(st.st_mode))
                        continue;
 
                if (!S_ISBLK(st.st_mode))
                        continue;
 
-               /*
-                * If replay_redirect is set then always return this device
-                * upon lookup which overrides the device lookup based on
-                * major minor in the actual blktrace
-                */
-               if (redirect) {
-                       strcpy(path, redirect);
-                       found = 1;
-                       break;
-               }
-
                if (maj == major(st.st_rdev) && min == minor(st.st_rdev)) {
                        strcpy(path, full_path);
                        found = 1;
                if (maj == major(st.st_rdev) && min == minor(st.st_rdev)) {
                        strcpy(path, full_path);
                        found = 1;