diff options
author | 2025-02-21 14:13:12 +0100 | |
---|---|---|
committer | 2025-03-04 09:29:53 +0100 | |
commit | 1768f9bd53c97a47a3a8ece94ab5436833d71007 (patch) | |
tree | 138e90a8ea5e82b671c589e6f18960cca50f5115 | |
parent | selftests: third test for mounting detached mounts onto detached mounts (diff) | |
download | wireguard-linux-1768f9bd53c97a47a3a8ece94ab5436833d71007.tar.xz wireguard-linux-1768f9bd53c97a47a3a8ece94ab5436833d71007.zip |
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/20250221-brauner-open_tree-v1-13-dbcfcb98c676@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
-rw-r--r-- | tools/testing/selftests/mount_setattr/mount_setattr_test.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tools/testing/selftests/mount_setattr/mount_setattr_test.c b/tools/testing/selftests/mount_setattr/mount_setattr_test.c index 66eed84c6a01..0ee4e5b27c68 100644 --- a/tools/testing/selftests/mount_setattr/mount_setattr_test.c +++ b/tools/testing/selftests/mount_setattr/mount_setattr_test.c @@ -1909,4 +1909,34 @@ TEST_F(mount_setattr, move_mount_detached_fail) EXPECT_EQ(close(fd_tree_subdir), 0); } +TEST_F(mount_setattr, attach_detached_mount_then_umount_then_close) +{ + int fd_tree = -EBADF; + struct statx stx; + + fd_tree = sys_open_tree(-EBADF, "/mnt", + AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW | + AT_RECURSIVE | OPEN_TREE_CLOEXEC | + OPEN_TREE_CLONE); + ASSERT_GE(fd_tree, 0); + + ASSERT_EQ(statx(fd_tree, "A", 0, 0, &stx), 0); + /* We copied with AT_RECURSIVE so /mnt/A must be a mountpoint. */ + ASSERT_TRUE(stx.stx_attributes & STATX_ATTR_MOUNT_ROOT); + + /* Attach the mount to the caller's mount namespace. */ + ASSERT_EQ(move_mount(fd_tree, "", -EBADF, "/tmp/target1", MOVE_MOUNT_F_EMPTY_PATH), 0); + + ASSERT_EQ(statx(-EBADF, "/tmp/target1", 0, 0, &stx), 0); + ASSERT_TRUE(stx.stx_attributes & STATX_ATTR_MOUNT_ROOT); + + ASSERT_EQ(umount2("/tmp/target1", MNT_DETACH), 0); + + /* + * This tests whether dissolve_on_fput() handles a NULL mount + * namespace correctly, i.e., that it doesn't splat. + */ + EXPECT_EQ(close(fd_tree), 0); +} + TEST_HARNESS_MAIN |