From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v2 5/5] btrfs-progs: mkfs-tests: verify cross mount point behavior for rootdir
Date: Thu, 1 Aug 2024 15:42:40 +0930 [thread overview]
Message-ID: <c8a14aa2b640d79fd60a14883a4f4c705292c1e6.1722492491.git.wqu@suse.com> (raw)
In-Reply-To: <cover.1722492491.git.wqu@suse.com>
The new test case creates a special layout like this:
rootdir/ (fs1 ino=256)
|- dir1/ (fs1 ino=257)
| |- dir1/ (fs2 ino=257)
| |- dir2/ (fs2 ino=258)
| |- file1 (fs2 ino=259)
| |- file2 (fs2 ino=260)
|- dir2/ (fs1 ino=258)
|- file1 (fs1 ino=259)
|- file2 (fs2 ino=259)
This layout intentionally creates inode number conflicts, which will
make the old "mkfs.btrfs --rootdir" to fail.
But newer reworked one will successfully handle them, just leave a test
case to avoid to hit the old bugs.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
.../035-rootdir-cross-mount/test.sh | 46 +++++++++++++++++++
1 file changed, 46 insertions(+)
create mode 100755 tests/mkfs-tests/035-rootdir-cross-mount/test.sh
diff --git a/tests/mkfs-tests/035-rootdir-cross-mount/test.sh b/tests/mkfs-tests/035-rootdir-cross-mount/test.sh
new file mode 100755
index 000000000000..0215f7223356
--- /dev/null
+++ b/tests/mkfs-tests/035-rootdir-cross-mount/test.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+#
+# Test if "mkfs.btrfs --rootdir" would handle a rootdir with subdirectories
+# on another fs.
+
+source "$TEST_TOP/common" || exit
+
+setup_root_helper
+
+# Here we need 3 devices, one for the rootdir, one for a subdirectory of
+# rootdir. This is to ensure we have conflicting inode numbers among the
+# two filesystems.
+# The last device is the for the mkfs.
+setup_loopdevs 3
+prepare_loopdevs
+
+dev1=${loopdevs[1]}
+dev2=${loopdevs[2]}
+dev3=${loopdevs[3]}
+tmpdir=$(_mktemp_dir mkfs-rootdir-cross-mount)
+
+run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$dev1"
+run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$dev2"
+
+# Populate both fs with the same contents. So that we're ensured
+# to have conflicting inode numbers.
+for i in "$dev1" "$dev2"; do
+ run_check $SUDO_HELPER mount -t btrfs "$i" "$tmpdir"
+ mkdir "$tmpdir/dir1" "$tmpdir/dir2"
+ touch "$tmpdir/file1" "$tmpdir/file2"
+ run_check $SUDO_HELPER umount "$tmpdir"
+done
+
+
+run_check $SUDO_HELPER mount -t btrfs "$dev1" "$tmpdir"
+run_check $SUDO_HELPER mount -t btrfs "$dev2" "$tmpdir/dir1"
+
+# The old rootdir implementation relies on the st_ino from the host fs, but
+# doesn't do any cross-mount check, it would result conflicting inode numbers
+# and fail.
+run_check "$TOP/mkfs.btrfs" --rootdir "$tmpdir" -f "$dev3"
+run_check $SUDO_HELPER umount "$tmpdir/dir1"
+run_check $SUDO_HELPER umount "$tmpdir"
+run_check "$TOP/btrfs" check "$dev3"
+rm -rf -- "$tmpdir"
+cleanup_loopdevs
--
2.45.2
prev parent reply other threads:[~2024-08-01 6:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-01 6:12 [PATCH v2 0/5] btrfs-progs: rework how we traverse rootdir Qu Wenruo
2024-08-01 6:12 ` [PATCH v2 1/5] btrfs-progs: constify the name parameter of btrfs_add_link() Qu Wenruo
2024-08-01 6:12 ` [PATCH v2 2/5] btrfs-progs: mkfs: rework how we traverse rootdir Qu Wenruo
2024-08-01 6:12 ` [PATCH v2 3/5] btrfs-progs: rootdir: warn about hard links Qu Wenruo
2024-08-01 6:12 ` [PATCH v2 4/5] btrfs-progs: mkfs-tests: a new test case to verify handling of " Qu Wenruo
2024-08-01 6:12 ` Qu Wenruo [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=c8a14aa2b640d79fd60a14883a4f4c705292c1e6.1722492491.git.wqu@suse.com \
--to=wqu@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/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