diff mbox series

[v2,5/5] btrfs-progs: mkfs-tests: verify cross mount point behavior for rootdir

Message ID c8a14aa2b640d79fd60a14883a4f4c705292c1e6.1722492491.git.wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: rework how we traverse rootdir | expand

Commit Message

Qu Wenruo Aug. 1, 2024, 6:12 a.m. UTC
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 mbox series

Patch

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