Skip to content

Commit 7bece69

Browse files
committed
selftests: seventh test for mounting detached mounts onto detached mounts
Add a test to verify that detached mounts behave correctly. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 0e6eef9 commit 7bece69

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tools/testing/selftests/mount_setattr/mount_setattr_test.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,4 +2061,40 @@ TEST_F(mount_setattr, two_detached_mounts_referring_to_same_anonymous_mount_name
20612061
ASSERT_NE(move_mount(fd_tree1, "", -EBADF, "/tmp/target1", MOVE_MOUNT_F_EMPTY_PATH), 0);
20622062
}
20632063

2064+
TEST_F(mount_setattr, two_detached_subtrees_of_same_anonymous_mount_namespace)
2065+
{
2066+
int fd_tree1 = -EBADF, fd_tree2 = -EBADF;
2067+
2068+
/*
2069+
* Copy the following mount tree:
2070+
*
2071+
* |-/mnt/A testing tmpfs
2072+
* `-/mnt/A/AA testing tmpfs
2073+
* `-/mnt/A/AA/B testing tmpfs
2074+
* `-/mnt/A/AA/B/BB testing tmpfs
2075+
*/
2076+
fd_tree1 = sys_open_tree(-EBADF, "/mnt/A",
2077+
AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW |
2078+
AT_RECURSIVE | OPEN_TREE_CLOEXEC |
2079+
OPEN_TREE_CLONE);
2080+
ASSERT_GE(fd_tree1, 0);
2081+
2082+
/*
2083+
* Create an O_PATH file descriptors with a separate struct file that
2084+
* refers to a subtree of the same detached mount tree as @fd_tree1
2085+
*/
2086+
fd_tree2 = sys_open_tree(fd_tree1, "AA",
2087+
AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW |
2088+
AT_EMPTY_PATH | OPEN_TREE_CLOEXEC);
2089+
ASSERT_GE(fd_tree2, 0);
2090+
2091+
/*
2092+
* This must fail as it is only possible to attach the root of a
2093+
* detached mount tree.
2094+
*/
2095+
ASSERT_NE(move_mount(fd_tree2, "", -EBADF, "/tmp/target1", MOVE_MOUNT_F_EMPTY_PATH), 0);
2096+
2097+
ASSERT_EQ(move_mount(fd_tree1, "", -EBADF, "/tmp/target1", MOVE_MOUNT_F_EMPTY_PATH), 0);
2098+
}
2099+
20642100
TEST_HARNESS_MAIN

0 commit comments

Comments
 (0)