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>
This commit is contained in:
Christian Brauner 2025-02-21 14:13:12 +01:00
parent 4fd0aea1ea
commit 1768f9bd53
No known key found for this signature in database
GPG Key ID: 91C61BC06578DCA2

View File

@ -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