Skip to content

Commit 1768f9b

Browse files
committed
selftests: fourth 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 4fd0aea commit 1768f9b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tools/testing/selftests/mount_setattr/mount_setattr_test.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,4 +1909,34 @@ TEST_F(mount_setattr, move_mount_detached_fail)
19091909
EXPECT_EQ(close(fd_tree_subdir), 0);
19101910
}
19111911

1912+
TEST_F(mount_setattr, attach_detached_mount_then_umount_then_close)
1913+
{
1914+
int fd_tree = -EBADF;
1915+
struct statx stx;
1916+
1917+
fd_tree = sys_open_tree(-EBADF, "/mnt",
1918+
AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW |
1919+
AT_RECURSIVE | OPEN_TREE_CLOEXEC |
1920+
OPEN_TREE_CLONE);
1921+
ASSERT_GE(fd_tree, 0);
1922+
1923+
ASSERT_EQ(statx(fd_tree, "A", 0, 0, &stx), 0);
1924+
/* We copied with AT_RECURSIVE so /mnt/A must be a mountpoint. */
1925+
ASSERT_TRUE(stx.stx_attributes & STATX_ATTR_MOUNT_ROOT);
1926+
1927+
/* Attach the mount to the caller's mount namespace. */
1928+
ASSERT_EQ(move_mount(fd_tree, "", -EBADF, "/tmp/target1", MOVE_MOUNT_F_EMPTY_PATH), 0);
1929+
1930+
ASSERT_EQ(statx(-EBADF, "/tmp/target1", 0, 0, &stx), 0);
1931+
ASSERT_TRUE(stx.stx_attributes & STATX_ATTR_MOUNT_ROOT);
1932+
1933+
ASSERT_EQ(umount2("/tmp/target1", MNT_DETACH), 0);
1934+
1935+
/*
1936+
* This tests whether dissolve_on_fput() handles a NULL mount
1937+
* namespace correctly, i.e., that it doesn't splat.
1938+
*/
1939+
EXPECT_EQ(close(fd_tree), 0);
1940+
}
1941+
19121942
TEST_HARNESS_MAIN

0 commit comments

Comments
 (0)