btrfs-progs: tests: check that convert does not create extents beyond device boundary

Add a test case to check if the converted fs has device extent beyond
boundary.

The disk layout of source ext4 fs needs some extents to make them
allocated at the very end of the fs.  The script is from the original
reporter.

Also, since the existing convert tests always uses 512M as device size,
which is not suitable for this test case, make it to grab the existing
device size to co-operate with this test case.

Reported-by: Jiachen YANG <farseerfc@gmail.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Qu Wenruo 2020-06-24 19:55:27 +08:00 committed by David Sterba
parent 0ff7a9b521
commit 761add2622
2 changed files with 38 additions and 1 deletions

View File

@ -61,14 +61,20 @@ convert_test_prep_fs() {
local fstype
local force
local mountopts
local oldsize
fstype="$1"
shift
# Use device size that was set before, or the default 512M
oldsize=$(stat --format=%s "$TEST_DEV")
if [ -z "$oldsize" ]; then
oldssize=512M
fi
# TEST_DEV not removed as the file might have special permissions, eg.
# when test image is on NFS and would not be writable for root
run_check truncate -s 0 "$TEST_DEV"
# 256MB is the smallest acceptable btrfs image.
run_check truncate -s 512M "$TEST_DEV"
run_check truncate -s "$oldsize" "$TEST_DEV"
force=
mountopts=
case "$fstype" in

View File

@ -0,0 +1,31 @@
#!/bin/bash
# Check if btrfs-convert creates filesystem with device extents beyond the
# device boundary
source "$TEST_TOP/common"
source "$TEST_TOP/common.convert"
setup_root_helper
prepare_test_dev 1G
check_prereq btrfs-convert
check_global_prereq mke2fs
check_global_prereq fallocate
convert_test_prep_fs ext4 mke2fs -t ext4 -b 4096
# Use up 800MiB first
for i in $(seq 1 4); do
run_check $SUDO_HELPER fallocate -l 200M "$TEST_MNT/file$i"
done
# Then add 5MiB for above files. These 5 MiB will be allocated near the very
# end of the fs, to confuse btrfs-convert
for i in $(seq 1 4); do
run_check $SUDO_HELPER fallocate -l 205M "$TEST_MNT/file$i"
done
run_check_umount_test_dev
# convert_test_do_convert() will call btrfs check, which should expose any
# invalid inline extent with too large size
convert_test_do_convert