]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Revert "core/credential,mount: re-read /proc/self/mountinfo before invoking umount...
authorMike Yuan <me@yhndnzj.com>
Tue, 14 May 2024 10:47:42 +0000 (18:47 +0800)
committerLuca Boccassi <bluca@debian.org>
Tue, 11 Jun 2024 23:54:26 +0000 (00:54 +0100)
This reverts commit 1e1225614ca1106116dcad9fb37aaeb6106408ab.

This was an incomplete workaround of the race. Now that
we stop generating mount units for credential mounts,
the logic could be dropped.

src/core/exec-credential.c
src/core/exec-credential.h
src/core/mount.c
src/core/mount.h
src/core/unit.c

index f4cff57848b3614bfab890d2e4d0a1ee314fcec1..d58aa18b55653e6912b34298290a603a1acc276c 100644 (file)
@@ -13,7 +13,6 @@
 #include "label-util.h"
 #include "mkdir-label.h"
 #include "mount-util.h"
-#include "mount.h"
 #include "mountpoint-util.h"
 #include "process-util.h"
 #include "random-util.h"
@@ -145,21 +144,19 @@ int unit_add_default_credential_dependencies(Unit *u, const ExecContext *c) {
         return unit_add_dependency_by_name(u, UNIT_AFTER, m, /* add_reference= */ true, UNIT_DEPENDENCY_FILE);
 }
 
-int exec_context_destroy_credentials(Unit *u) {
+int exec_context_destroy_credentials(const ExecContext *c, const char *runtime_prefix, const char *unit) {
         _cleanup_free_ char *p = NULL;
         int r;
 
-        assert(u);
+        assert(c);
 
-        r = get_credential_directory(u->manager->prefix[EXEC_DIRECTORY_RUNTIME], u->id, &p);
+        r = get_credential_directory(runtime_prefix, unit, &p);
         if (r <= 0)
                 return r;
 
         /* This is either a tmpfs/ramfs of its own, or a plain directory. Either way, let's first try to
          * unmount it, and afterwards remove the mount point */
-        if (umount2(p, MNT_DETACH|UMOUNT_NOFOLLOW) >= 0)
-                (void) mount_invalidate_state_by_path(u->manager, p);
-
+        (void) umount2(p, MNT_DETACH|UMOUNT_NOFOLLOW);
         (void) rm_rf(p, REMOVE_ROOT|REMOVE_CHMOD);
 
         return 0;
index 70bb46bdde6847a20a8b37f01d6cb8ab05f438af..f02770cec58ff1676ec58689082147bcedfba250 100644 (file)
@@ -47,7 +47,7 @@ int exec_context_get_credential_directory(
 
 int unit_add_default_credential_dependencies(Unit *u, const ExecContext *c);
 
-int exec_context_destroy_credentials(Unit *u);
+int exec_context_destroy_credentials(const ExecContext *c, const char *runtime_root, const char *unit);
 int exec_setup_credentials(
                 const ExecContext *context,
                 const ExecParameters *params,
index 238e3eab501d72ceb324500b12fc4996267bd146..a6460287ced6bff251f7cf4cedc7290a408cd681 100644 (file)
@@ -1333,11 +1333,6 @@ static int mount_start(Unit *u) {
 static int mount_stop(Unit *u) {
         Mount *m = ASSERT_PTR(MOUNT(u));
 
-        /* When we directly call umount() for a path, then the state of the corresponding mount unit may be
-         * outdated. Let's re-read mountinfo now and update the state. */
-        if (m->invalidated_state)
-                (void) mount_process_proc_self_mountinfo(u->manager);
-
         switch (m->state) {
 
         case MOUNT_UNMOUNTING:
@@ -1372,11 +1367,6 @@ static int mount_stop(Unit *u) {
                 mount_enter_signal(m, MOUNT_UNMOUNTING_SIGKILL, MOUNT_SUCCESS);
                 return 0;
 
-        case MOUNT_DEAD:
-        case MOUNT_FAILED:
-                /* The mount has just been unmounted by somebody else. */
-                return 0;
-
         default:
                 assert_not_reached();
         }
@@ -2141,8 +2131,6 @@ static int mount_process_proc_self_mountinfo(Manager *m) {
         LIST_FOREACH(units_by_type, u, m->units_by_type[UNIT_MOUNT]) {
                 Mount *mount = MOUNT(u);
 
-                mount->invalidated_state = false;
-
                 if (!mount_is_mounted(mount)) {
 
                         /* A mount point is not around right now. It might be gone, or might never have
@@ -2239,26 +2227,6 @@ static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
         return mount_process_proc_self_mountinfo(m);
 }
 
-int mount_invalidate_state_by_path(Manager *manager, const char *path) {
-        _cleanup_free_ char *name = NULL;
-        Unit *u;
-        int r;
-
-        assert(manager);
-        assert(path);
-
-        r = unit_name_from_path(path, ".mount", &name);
-        if (r < 0)
-                return log_debug_errno(r, "Failed to generate unit name from path \"%s\", ignoring: %m", path);
-
-        u = manager_get_unit(manager, name);
-        if (!u)
-                return -ENOENT;
-
-        MOUNT(u)->invalidated_state = true;
-        return 0;
-}
-
 static void mount_reset_failed(Unit *u) {
         Mount *m = MOUNT(u);
 
index a029dc87aca36473aa84787aebfd79c9994c33da..9a8b6bb4c0a0271e43404fcd066cb7535b0ca178 100644 (file)
@@ -50,8 +50,6 @@ struct Mount {
         MountParameters parameters_proc_self_mountinfo;
         MountParameters parameters_fragment;
 
-        bool invalidated_state:1; /* Set when the 'state' of the mount unit may be outdated, and we need to
-                                   * re-read /proc/self/mountinfo. */
         bool from_proc_self_mountinfo:1;
         bool from_fragment:1;
 
@@ -96,8 +94,6 @@ extern const UnitVTable mount_vtable;
 
 void mount_fd_event(Manager *m, int events);
 
-int mount_invalidate_state_by_path(Manager *manager, const char *path);
-
 char* mount_get_what_escaped(const Mount *m);
 char* mount_get_options_escaped(const Mount *m);
 const char* mount_get_fstype(const Mount *m);
index 2d40618fcbb7ad201d33f65c6636e0165f58c9c5..a1e7b62b9afd64b5905cf3fff0f3a44b3df1a198 100644 (file)
@@ -6109,7 +6109,7 @@ void unit_destroy_runtime_data(Unit *u, const ExecContext *context) {
         if (context->runtime_directory_preserve_mode == EXEC_PRESERVE_NO)
                 exec_context_destroy_runtime_directory(context, u->manager->prefix[EXEC_DIRECTORY_RUNTIME]);
 
-        exec_context_destroy_credentials(u);
+        exec_context_destroy_credentials(context, u->manager->prefix[EXEC_DIRECTORY_RUNTIME], u->id);
         exec_context_destroy_mount_ns_dir(u);
 }