diff options
author | Mike Yuan <me@yhndnzj.com> | 2024-06-10 17:43:52 +0200 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2024-07-23 19:30:55 +0200 |
commit | 706302897acdcbe442de6e5c66023938675cee8d (patch) | |
tree | 44fb84c3a9ca9f5a55aca283ffd218cbe597944b /src/shared | |
parent | machine-dbus: use pidref_namespace_open() where appropriate (diff) | |
download | systemd-706302897acdcbe442de6e5c66023938675cee8d.tar.xz systemd-706302897acdcbe442de6e5c66023938675cee8d.zip |
mount-util: clean up mount_exchange_graceful a bit, don't duplicate move_mount when fallback
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/mount-util.c | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c index 7e18d12df4..0b3154fbd9 100644 --- a/src/shared/mount-util.c +++ b/src/shared/mount-util.c @@ -759,27 +759,19 @@ int mount_exchange_graceful(int fsmount_fd, const char *dest, bool mount_beneath * this is not supported (minimum kernel v6.5), or if there is no mount on the mountpoint, we get * -EINVAL and then we fallback to normal mounting. */ - r = RET_NERRNO(move_mount( - fsmount_fd, - /* from_path= */ "", - /* to_fd= */ -EBADF, - dest, - MOVE_MOUNT_F_EMPTY_PATH | (mount_beneath ? MOVE_MOUNT_BENEATH : 0))); + r = RET_NERRNO(move_mount(fsmount_fd, /* from_path = */ "", + /* to_fd = */ -EBADF, dest, + MOVE_MOUNT_F_EMPTY_PATH | (mount_beneath ? MOVE_MOUNT_BENEATH : 0))); if (mount_beneath) { + if (r >= 0) /* Mounting beneath worked! Now unmount the upper mount. */ + return umount_verbose(LOG_DEBUG, dest, UMOUNT_NOFOLLOW|MNT_DETACH); + if (r == -EINVAL) { /* Fallback if mount_beneath is not supported */ log_debug_errno(r, - "Failed to mount beneath '%s', falling back to overmount", + "Cannot mount beneath '%s', falling back to overmount: %m", dest); - return RET_NERRNO(move_mount( - fsmount_fd, - /* from_path= */ "", - /* to_fd= */ -EBADF, - dest, - MOVE_MOUNT_F_EMPTY_PATH)); + return mount_exchange_graceful(fsmount_fd, dest, /* mount_beneath = */ false); } - - if (r >= 0) /* If it is, now remove the old mount */ - return umount_verbose(LOG_DEBUG, dest, UMOUNT_NOFOLLOW|MNT_DETACH); } return r; |