]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
loop-util: add debug logging about O_RDWR vs. O_RDONLY + O_DIRECT mode
authorLennart Poettering <lennart@poettering.net>
Wed, 20 Oct 2021 07:56:20 +0000 (09:56 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 20 Oct 2021 07:56:20 +0000 (09:56 +0200)
Once we managed to open the file let's log what we wanted and what we
got.

src/shared/loop-util.c

index 52c47e208e513ef6a2a0df230d094e9f2eb2e09e..f2f4ab481d4957669b3891d816f333fdde67d751 100644 (file)
@@ -646,6 +646,7 @@ int loop_device_make_by_path(
 
         int r, basic_flags, direct_flags, rdwr_flags;
         _cleanup_close_ int fd = -1;
+        bool direct = false;
 
         assert(path);
         assert(ret);
@@ -666,6 +667,8 @@ int loop_device_make_by_path(
         fd = open(path, basic_flags|direct_flags|rdwr_flags);
         if (fd < 0 && direct_flags != 0) /* If we had O_DIRECT on, and things failed with that, let's immediately try again without */
                 fd = open(path, basic_flags|rdwr_flags);
+        else
+                direct = direct_flags != 0;
         if (fd < 0) {
                 r = -errno;
 
@@ -676,6 +679,8 @@ int loop_device_make_by_path(
                 fd = open(path, basic_flags|direct_flags|O_RDONLY);
                 if (fd < 0 && direct_flags != 0) /* as above */
                         fd = open(path, basic_flags|O_RDONLY);
+                else
+                        direct = direct_flags != 0;
                 if (fd < 0)
                         return r; /* Propagate original error */
 
@@ -683,6 +688,13 @@ int loop_device_make_by_path(
         } else if (open_flags < 0)
                 open_flags = O_RDWR;
 
+        log_debug("Opened '%s' in %s access mode%s, with O_DIRECT %s%s.",
+                  path,
+                  open_flags == O_RDWR ? "O_RDWR" : "O_RDONLY",
+                  open_flags != rdwr_flags ? " (O_RDWR was requested but not allowed)" : "",
+                  direct ? "enabled" : "disabled",
+                  direct != (direct_flags != 0) ? " (O_DIRECT was requested but not supported)" : "");
+
         return loop_device_make(fd, open_flags, 0, 0, loop_flags, ret);
 }