From: Mike Yuan Date: Mon, 10 Jun 2024 15:43:52 +0000 (+0200) Subject: mount-util: clean up mount_exchange_graceful a bit, don't duplicate move_mount when... X-Git-Tag: v257-rc1~831^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=706302897acdcbe442de6e5c66023938675cee8d;p=thirdparty%2Fsystemd.git mount-util: clean up mount_exchange_graceful a bit, don't duplicate move_mount when fallback --- diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c index 7e18d12df45..0b3154fbd90 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;