public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: linux-fsdevel@vger.kernel.org
Cc: Al Viro <viro@zeniv.linux.org.uk>,
	Miklos Szeredi <miklos@szeredi.hu>,
	 Jeff Layton <jlayton@kernel.org>,
	Josef Bacik <josef@toxicpanda.com>,
	 Seth Forshee <sforshee@kernel.org>,
	Christian Brauner <brauner@kernel.org>
Subject: [PATCH RFC 16/16] selftests: seventh test for mounting detached mounts onto detached mounts
Date: Fri, 21 Feb 2025 14:13:15 +0100	[thread overview]
Message-ID: <20250221-brauner-open_tree-v1-16-dbcfcb98c676@kernel.org> (raw)
In-Reply-To: <20250221-brauner-open_tree-v1-0-dbcfcb98c676@kernel.org>

Add a test to verify that detached mounts behave correctly.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 .../selftests/mount_setattr/mount_setattr_test.c   | 36 ++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/tools/testing/selftests/mount_setattr/mount_setattr_test.c b/tools/testing/selftests/mount_setattr/mount_setattr_test.c
index d2bf8b77df3f..1e0508cb5c2d 100644
--- a/tools/testing/selftests/mount_setattr/mount_setattr_test.c
+++ b/tools/testing/selftests/mount_setattr/mount_setattr_test.c
@@ -2061,4 +2061,40 @@ TEST_F(mount_setattr, two_detached_mounts_referring_to_same_anonymous_mount_name
 	ASSERT_NE(move_mount(fd_tree1, "", -EBADF, "/tmp/target1", MOVE_MOUNT_F_EMPTY_PATH), 0);
 }
 
+TEST_F(mount_setattr, two_detached_subtrees_of_same_anonymous_mount_namespace)
+{
+	int fd_tree1 = -EBADF, fd_tree2 = -EBADF;
+
+	/*
+	 * Copy the following mount tree:
+	 *
+	 * |-/mnt/A               testing tmpfs
+	 *   `-/mnt/A/AA          testing tmpfs
+	 *     `-/mnt/A/AA/B      testing tmpfs
+	 *       `-/mnt/A/AA/B/BB testing tmpfs
+	 */
+	fd_tree1 = sys_open_tree(-EBADF, "/mnt/A",
+				 AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW |
+				 AT_RECURSIVE | OPEN_TREE_CLOEXEC |
+				 OPEN_TREE_CLONE);
+	ASSERT_GE(fd_tree1, 0);
+
+	/*
+	 * Create an O_PATH file descriptors with a separate struct file that
+	 * refers to a subtree of the same detached mount tree as @fd_tree1
+	 */
+	fd_tree2 = sys_open_tree(fd_tree1, "AA",
+				 AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW |
+				 AT_EMPTY_PATH | OPEN_TREE_CLOEXEC);
+	ASSERT_GE(fd_tree2, 0);
+
+	/*
+	 * This must fail as it is only possible to attach the root of a
+	 * detached mount tree.
+	 */
+	ASSERT_NE(move_mount(fd_tree2, "", -EBADF, "/tmp/target1", MOVE_MOUNT_F_EMPTY_PATH), 0);
+
+	ASSERT_EQ(move_mount(fd_tree1, "", -EBADF, "/tmp/target1", MOVE_MOUNT_F_EMPTY_PATH), 0);
+}
+
 TEST_HARNESS_MAIN

-- 
2.47.2


      parent reply	other threads:[~2025-02-21 13:14 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-21 13:12 [PATCH RFC 00/16] fs: expand abilities of anonymous mount namespaces Christian Brauner
2025-02-21 13:13 ` [PATCH RFC 01/16] fs: record sequence number of origin mount namespace Christian Brauner
2025-02-21 13:13 ` [PATCH RFC 02/16] fs: add mnt_ns_empty() helper Christian Brauner
2025-02-21 13:13 ` [PATCH RFC 03/16] fs: add assert for move_mount() Christian Brauner
2025-02-21 13:13 ` [PATCH RFC 04/16] fs: add fastpath for dissolve_on_fput() Christian Brauner
2025-02-21 13:13 ` [PATCH RFC 05/16] fs: add may_copy_tree() Christian Brauner
2025-02-21 13:13 ` [PATCH RFC 06/16] fs: create detached mounts from detached mounts Christian Brauner
2025-02-21 13:13 ` [PATCH RFC 07/16] selftests: " Christian Brauner
2025-02-21 13:13 ` [PATCH RFC 08/16] fs: support getname_maybe_null() in move_mount() Christian Brauner
2025-02-21 13:13 ` [PATCH RFC 09/16] fs: mount detached mounts onto detached mounts Christian Brauner
2025-02-21 13:13 ` [PATCH RFC 10/16] selftests: first test for mounting " Christian Brauner
2025-02-21 13:13 ` [PATCH RFC 11/16] selftests: second " Christian Brauner
2025-02-21 13:13 ` [PATCH RFC 12/16] selftests: third " Christian Brauner
2025-02-21 13:13 ` [PATCH RFC 13/16] selftests: fourth " Christian Brauner
2025-02-21 13:13 ` [PATCH RFC 14/16] selftests: fifth " Christian Brauner
2025-02-21 13:13 ` [PATCH RFC 15/16] selftests: sixth " Christian Brauner
2025-02-21 13:13 ` Christian Brauner [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250221-brauner-open_tree-v1-16-dbcfcb98c676@kernel.org \
    --to=brauner@kernel.org \
    --cc=jlayton@kernel.org \
    --cc=josef@toxicpanda.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=sforshee@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox