From 275497b4f7ec14d49c51ecfdd2779a66bde3adc1 Mon Sep 17 00:00:00 2001 From: Naohiro Aota Date: Wed, 29 May 2024 16:13:23 +0900 Subject: [PATCH] btrfs-progs: tests: add mkfs test for zone resetting Add test for mkfs.btrfs zone reset behavior to check if - it resets all the zones without "-b" option - it detects an active zone outside of the FS range - it do not reset a zone outside of the range Signed-off-by: Naohiro Aota Reviewed-by: Qu Wenruo Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/mkfs-tests/032-zoned-reset/test.sh | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 tests/mkfs-tests/032-zoned-reset/test.sh diff --git a/tests/mkfs-tests/032-zoned-reset/test.sh b/tests/mkfs-tests/032-zoned-reset/test.sh new file mode 100755 index 00000000..2aedb14a --- /dev/null +++ b/tests/mkfs-tests/032-zoned-reset/test.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# Verify mkfs for zoned devices support block-group-tree feature + +source "$TEST_TOP/common" || exit + +check_global_prereq blkzone +setup_root_helper +# Create one 128M device with 4M zones, 32 of them +setup_nullbdevs 1 128 4 + +prepare_nullbdevs + +TEST_DEV="${nullb_devs[1]}" +last_zone_sector=$(( 4 * 31 * 1024 * 1024 / 512 )) +# Write some data to the last zone +run_check $SUDO_HELPER dd if=/dev/urandom of="${TEST_DEV}" bs=1M count=4 seek=$(( 4 * 31 )) +# Use single as it's supported on more kernels +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -m single -d single "${TEST_DEV}" +# Check if the lat zone is empty +run_check_stdout $SUDO_HELPER blkzone report -o ${last_zone_sector} -c 1 "${TEST_DEV}" | grep -Fq '(em)' +if [ $? != 0 ]; then + _fail "last zone is not empty" +fi + +# Write some data to the last zone +run_check $SUDO_HELPER dd if=/dev/urandom of="${TEST_DEV}" bs=1M count=1 seek=$(( 4 * 31 )) +# Create a FS excluding the last zone +run_mayfail $SUDO_HELPER "$TOP/mkfs.btrfs" -f -b $(( 4 * 31 ))M -m single -d single "${TEST_DEV}" +if [ $? == 0 ]; then + _fail "mkfs.btrfs should detect active zone outside of FS range" +fi + +# Fill the last zone to finish it +run_check $SUDO_HELPER dd if=/dev/urandom of="${TEST_DEV}" bs=1M count=3 seek=$(( 4 * 31 + 1 )) +# Create a FS excluding the last zone +run_mayfail $SUDO_HELPER "$TOP/mkfs.btrfs" -f -b $(( 4 * 31 ))M -m single -d single "${TEST_DEV}" +# Check if the lat zone is not empty +run_check_stdout $SUDO_HELPER blkzone report -o ${last_zone_sector} -c 1 "${TEST_DEV}" | grep -Fq '(em)' +if [ $? == 0 ]; then + _fail "last zone is empty" +fi + +cleanup_nullbdevs