diff mbox series

[4/4] btrfs-progs: convert-tests: add a test case to verify large symbol link handling

Message ID 715a310387bb3138bd0e41809e21bfef3825df1d.1725348299.git.wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: convert: fix the invalid regular extents for symbol links | expand

Commit Message

Qu Wenruo Sept. 3, 2024, 7:29 a.m. UTC
The new test case will:

- Create a symbol which contains a 4095 bytes sized target on ext4

- Convert the ext4 to btrfs

- Make sure we can still read the symbol link
  For unpatched btrfs-convert, the resulted symbol link will be rejected
  by kernel and fail.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 .../027-large-symbol-link/test.sh             | 33 +++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100755 tests/convert-tests/027-large-symbol-link/test.sh
diff mbox series

Patch

diff --git a/tests/convert-tests/027-large-symbol-link/test.sh b/tests/convert-tests/027-large-symbol-link/test.sh
new file mode 100755
index 000000000000..85f7329a86d2
--- /dev/null
+++ b/tests/convert-tests/027-large-symbol-link/test.sh
@@ -0,0 +1,33 @@ 
+#!/bin/bash
+# Make sure btrfs-convert can handle a symbol link which is 4095 bytes large
+
+source "$TEST_TOP/common" || exit
+source "$TEST_TOP/common.convert" || exit
+
+setup_root_helper
+prepare_test_dev 1G
+check_global_prereq mkfs.ext4
+
+link_target=""
+
+# Soft link in btrfs can only have inlined data extent.
+# So here we create a symbol link whose target is 4095 bytes length.
+for ((i = 0; i < 4095; i++)); do
+	link_target+="b"
+done
+
+convert_test_prep_fs ext4 mke2fs -t ext4 -b 4096
+run_check $SUDO_HELPER ln -s "$link_target" "$TEST_MNT/symbol_link"
+run_check_umount_test_dev
+
+# For unpatched btrfs-convert, it will always append one byte to the
+# link target, causing above 4095 target to be 4096, exactly one sector,
+# resulting a regular file extent.
+convert_test_do_convert
+
+run_check_mount_test_dev
+# If the unpatched btrfs-convert created a regular extent, and the kernel is
+# newer enough, such readlink will be rejected by kernel.
+run_check $SUDO_HELPER readlink "$TEST_MNT/symbol_link"
+run_check_umount_test_dev
+