]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/mount: drop unnecessary dependency generations
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 10 May 2025 18:22:04 +0000 (03:22 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 10 May 2025 18:33:02 +0000 (03:33 +0900)
When the unit is new, then mount_setup_new_unit() adds the unit to the
load queue, and the same dependencies will be anyway added.

When the unit already exists but previously failed to be loaded, then
mount_setup_existing_unit() also adds the unit to the load queue.
Hence it is not necessary to regenerate dependencies here now.

So, we need to regenerate dependencies only when things changed and
the unit has been already loaded.

No functional changes, just optimization.

src/core/mount.c

index 2541a4888c1a4eb024e1503d8de9c55fd344b678..d7211de024962e12d429608b4a05fcb3c88f490a 100644 (file)
@@ -1795,10 +1795,6 @@ static int mount_setup_new_unit(
          * attributes the deps to. */
         mnt->from_proc_self_mountinfo = true;
 
-        r = mount_add_non_exec_dependencies(mnt);
-        if (r < 0)
-                return r;
-
         /* We have only allocated the stub now, let's enqueue this unit for loading now, so that everything
          * else is loaded in now. */
         unit_add_to_load_queue(u);
@@ -1864,9 +1860,9 @@ static int mount_setup_existing_unit(
                 flags |= MOUNT_PROC_JUST_CHANGED;
         }
 
-        if (FLAGS_SET(flags, MOUNT_PROC_JUST_CHANGED)) {
-                /* If things changed, then make sure that all deps are regenerated. Let's
-                 * first remove all automatic deps, and then add in the new ones. */
+        if (FLAGS_SET(flags, MOUNT_PROC_JUST_CHANGED) && u->load_state == UNIT_LOADED) {
+                /* If things changed, and we have successfully loaded the unit, then make sure that all deps
+                 * are regenerated. Let's first remove all automatic deps, and then add in the new ones. */
                 r = mount_add_non_exec_dependencies(m);
                 if (r < 0)
                         return r;