btrfs-progs/tests/fsck-tests/059-shrunk-device/test.sh
David Sterba 3e7cc11ecb btrfs-progs: tests: add missing protection against running out of test suite
Executing the script inside the directories as './test.sh' is not
supposed to work but could happen accidentally. With an exit after
attempting to source the we can fix that. Not all cases have been fixed
in f6bbe06c08 ("btrfs-progs: tests: add protection against running
out of test suite").

Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-03 22:37:53 +02:00

30 lines
774 B
Bash
Executable file

#!/bin/bash
#
# Make sure "btrfs check" can detect device smaller than its total_bytes
# in device item
#
source "$TEST_TOP/common" || exit
setup_root_helper
file="img"
# Allocate an initial 1G file for testing.
_mktemp_local "$file" 1g
dev=$(run_check_stdout $SUDO_HELPER losetup --find --show "$file")
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$dev"
# The original device size from prepare_loopdevs is 2G.
# Since the fs is empty, shrinking it to 996m will not cause any
# lose of metadata.
run_check $SUDO_HELPER losetup -d "$dev"
truncate -s 996m "$file"
dev=$(run_check_stdout $SUDO_HELPER losetup --find --show "$file")
run_mustfail "btrfs check should detect errors in device size" \
"$TOP/btrfs" check "$dev"
$SUDO_HELPER losetup -d "$dev"
rm -- "$file"