Skip to content

Commit d83a55b

Browse files
committed
selftests: first test for mounting detached mounts onto detached mounts
Add a test to verify that detached mounts behave correctly. Link: https://lore.kernel.org/r/20250221-brauner-open_tree-v1-10-dbcfcb98c676@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 2110772 commit d83a55b

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

tools/testing/selftests/mount_setattr/mount_setattr_test.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,4 +1789,44 @@ TEST_F(mount_setattr, open_tree_detached_fail3)
17891789
ASSERT_EQ(errno, EINVAL);
17901790
}
17911791

1792+
TEST_F(mount_setattr, mount_detached_mount_on_detached_mount_then_close)
1793+
{
1794+
int fd_tree_base = -EBADF, fd_tree_subdir = -EBADF;
1795+
struct statx stx;
1796+
1797+
fd_tree_base = sys_open_tree(-EBADF, "/mnt",
1798+
AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW |
1799+
OPEN_TREE_CLOEXEC | OPEN_TREE_CLONE);
1800+
ASSERT_GE(fd_tree_base, 0);
1801+
/*
1802+
* /mnt testing tmpfs
1803+
*/
1804+
ASSERT_EQ(statx(fd_tree_base, "A", 0, 0, &stx), 0);
1805+
ASSERT_FALSE(stx.stx_attributes & STATX_ATTR_MOUNT_ROOT);
1806+
1807+
fd_tree_subdir = sys_open_tree(fd_tree_base, "",
1808+
AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW |
1809+
AT_EMPTY_PATH | OPEN_TREE_CLOEXEC |
1810+
OPEN_TREE_CLONE);
1811+
ASSERT_GE(fd_tree_subdir, 0);
1812+
/*
1813+
* /mnt testing tmpfs
1814+
*/
1815+
ASSERT_EQ(statx(fd_tree_subdir, "A", 0, 0, &stx), 0);
1816+
ASSERT_FALSE(stx.stx_attributes & STATX_ATTR_MOUNT_ROOT);
1817+
1818+
/*
1819+
* /mnt testing tmpfs
1820+
* `-/mnt testing tmpfs
1821+
*/
1822+
ASSERT_EQ(move_mount(fd_tree_subdir, "", fd_tree_base, "", MOVE_MOUNT_F_EMPTY_PATH | MOVE_MOUNT_T_EMPTY_PATH), 0);
1823+
ASSERT_EQ(statx(fd_tree_subdir, "", AT_EMPTY_PATH, 0, &stx), 0);
1824+
ASSERT_TRUE(stx.stx_attributes & STATX_ATTR_MOUNT_ROOT);
1825+
1826+
ASSERT_NE(move_mount(fd_tree_subdir, "", fd_tree_base, "", MOVE_MOUNT_F_EMPTY_PATH | MOVE_MOUNT_T_EMPTY_PATH), 0);
1827+
1828+
EXPECT_EQ(close(fd_tree_base), 0);
1829+
EXPECT_EQ(close(fd_tree_subdir), 0);
1830+
}
1831+
17921832
TEST_HARNESS_MAIN

0 commit comments

Comments
 (0)