]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: Add trace logging to mount_add_device_dependencies() 23354/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 11 May 2022 21:48:07 +0000 (23:48 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 12 May 2022 12:56:16 +0000 (14:56 +0200)
To help debug missing implicit device deps in
https://github.com/systemd/systemd/issues/13775#issuecomment-1122969810.

src/core/mount.c
src/core/unit.h

index 20b4bb6d2b8116c60df3e9ae189ab3d4f2e8b60b..dcfbf970d7009a6a3f22a98b906d057ead2857d4 100644 (file)
@@ -354,26 +354,40 @@ static int mount_add_device_dependencies(Mount *m) {
 
         assert(m);
 
+        log_unit_trace(UNIT(m), "Processing implicit device dependencies");
+
         p = get_mount_parameters(m);
-        if (!p)
+        if (!p) {
+                log_unit_trace(UNIT(m), "Missing mount parameters, skipping implicit device dependencies");
                 return 0;
+        }
 
-        if (!p->what)
+        if (!p->what) {
+                log_unit_trace(UNIT(m), "Missing mount source, skipping implicit device dependencies");
                 return 0;
+        }
 
-        if (mount_is_bind(p))
+        if (mount_is_bind(p)) {
+                log_unit_trace(UNIT(m), "Mount unit is a bind mount, skipping implicit device dependencies");
                 return 0;
+        }
 
-        if (!is_device_path(p->what))
+        if (!is_device_path(p->what)) {
+                log_unit_trace(UNIT(m), "Mount source is not a device path, skipping implicit device dependencies");
                 return 0;
+        }
 
         /* /dev/root is a really weird thing, it's not a real device, but just a path the kernel exports for
          * the root file system specified on the kernel command line. Ignore it here. */
-        if (PATH_IN_SET(p->what, "/dev/root", "/dev/nfs"))
+        if (PATH_IN_SET(p->what, "/dev/root", "/dev/nfs")) {
+                log_unit_trace(UNIT(m), "Mount source is in /dev/root or /dev/nfs, skipping implicit device dependencies");
                 return 0;
+        }
 
-        if (path_equal(m->where, "/"))
+        if (path_equal(m->where, "/")) {
+                log_unit_trace(UNIT(m), "Mount destination is '/', skipping implicit device dependencies");
                 return 0;
+        }
 
         /* Mount units from /proc/self/mountinfo are not bound to devices by default since they're subject to
          * races when mounts are established by other tools with different backing devices than what we
@@ -388,13 +402,23 @@ static int mount_add_device_dependencies(Mount *m) {
         r = unit_add_node_dependency(UNIT(m), p->what, dep, mask);
         if (r < 0)
                 return r;
+        if (r > 0)
+                log_unit_trace(UNIT(m), "Added %s dependency on %s", unit_dependency_to_string(dep), p->what);
+
         if (mount_propagate_stop(m)) {
                 r = unit_add_node_dependency(UNIT(m), p->what, UNIT_STOP_PROPAGATED_FROM, mask);
                 if (r < 0)
                         return r;
+                if (r > 0)
+                        log_unit_trace(UNIT(m), "Added %s dependency on %s",
+                                       unit_dependency_to_string(UNIT_STOP_PROPAGATED_FROM), p->what);
         }
 
-        return unit_add_blockdev_dependency(UNIT(m), p->what, mask);
+        r = unit_add_blockdev_dependency(UNIT(m), p->what, mask);
+        if (r > 0)
+                log_unit_trace(UNIT(m), "Added %s dependency on %s", unit_dependency_to_string(UNIT_AFTER), p->what);
+
+        return r;
 }
 
 static int mount_add_quota_dependencies(Mount *m) {
index 20c511c108c49e424cb44d406bb1713b7be1d4c0..c6a2fadf528024c31c8a7a90010f65ef4e4f0ce6 100644 (file)
@@ -1025,6 +1025,14 @@ Condition *unit_find_failed_condition(Unit *u);
 #define log_unit_warning_errno(unit, error, ...) log_unit_full_errno(unit, LOG_WARNING, error, __VA_ARGS__)
 #define log_unit_error_errno(unit, error, ...)   log_unit_full_errno(unit, LOG_ERR, error, __VA_ARGS__)
 
+#if LOG_TRACE
+#  define log_unit_trace(...)          log_unit_debug(__VA_ARGS__)
+#  define log_unit_trace_errno(...)    log_unit_debug_errno(__VA_ARGS__)
+#else
+#  define log_unit_trace(...)          do {} while (0)
+#  define log_unit_trace_errno(e, ...) (-ERRNO_VALUE(e))
+#endif
+
 #define log_unit_struct_errno(unit, level, error, ...)                  \
         ({                                                              \
                 const Unit *_u = (unit);                                \