]> git.ipfire.org Git - thirdparty/util-linux.git/commit
libmount: (subdir) support detached open_tree() (>=6.15)
authorKarel Zak <kzak@redhat.com>
Tue, 15 Apr 2025 10:29:37 +0000 (12:29 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 16 Apr 2025 08:21:23 +0000 (10:21 +0200)
commitae19f7546ccb038966fc121e287e1a1385ba94bb
treecce99cfbd56cd7be002f5c2d201c173fc2fe4216
parent437a271f7108f689d350f1b3d837490d3d283c3c
libmount: (subdir) support detached open_tree() (>=6.15)

The latest kernel can open a directory as a tree (open_tree()) on a
detached mount tree. This means we do not need to unshare and
attach the root of the filesystem to a private temporary directory. All
this machinery can be replaced by one open_tree() call.

Old version:
fsopen("ext4", FSOPEN_CLOEXEC)          = 3
unshare(CLONE_NEWNS)                    = 0
fsconfig(3, FSCONFIG_SET_STRING, "source", "/dev/sdc", 0) = 0
fsconfig(3, FSCONFIG_CMD_CREATE, NULL, NULL, 0) = 0
fsmount(3, FSMOUNT_CLOEXEC, 0)          = 6
move_mount(6, "", AT_FDCWD, "/run/mount/tmptgt", MOVE_MOUNT_F_EMPTY_PATH) = 0
open_tree(6, "subdir", OPEN_TREE_CLONE|OPEN_TREE_CLOEXEC) = 7
setns(4, CLONE_NEWNS)                   = 0
move_mount(7, "", AT_FDCWD, "/mnt/test", MOVE_MOUNT_F_EMPTY_PATH) = 0
setns(5, CLONE_NEWNS)                   = 0
umount2("/run/mount/tmptgt", 0)         = 0
setns(4, CLONE_NEWNS)                   = 0

New version:
fsopen("ext4", FSOPEN_CLOEXEC)          = 3
fsconfig(3, FSCONFIG_SET_STRING, "source", "/dev/sda", 0) = 0
fsconfig(3, FSCONFIG_CMD_CREATE, NULL, NULL, 0) = 0
fsmount(3, FSMOUNT_CLOEXEC, 0)          = 4
open_tree(4, "subdir", OPEN_TREE_CLONE|OPEN_TREE_CLOEXEC|AT_SYMLINK_NOFOLLOW|AT_NO_AUTOMOUNT|AT_RECURSIVE
move_mount(5, "", AT_FDCWD, "/mnt/test", MOVE_MOUNT_F_EMPTY_PATH) = 0

Note that this commit does not completely deactivate hook_subdir.c
because it is better to keep things in one place. It only adds a "subdir"
to the struct libmnt_sysapi to force hook_mount.c to call open_tree(subdir),
but all the logic and checks are still in hook_subdir.c.

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/hook_mount.c
libmount/src/hook_subdir.c
libmount/src/mountP.h