diff mbox series

[v2,7/8] btrfs-progs: add test for zone resetting

Message ID 20240514182227.1197664-8-naohiro.aota@wdc.com (mailing list archive)
State New
Headers show
Series btrfs-progs: zoned: proper "mkfs.btrfs -b" support | expand

Commit Message

Naohiro Aota May 14, 2024, 6:22 p.m. UTC
Add test for mkfs.btrfs's 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 <naohiro.aota@wdc.com>
---
 tests/mkfs-tests/032-zoned-reset/test.sh | 62 ++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
 create mode 100755 tests/mkfs-tests/032-zoned-reset/test.sh

Comments

Qu Wenruo May 14, 2024, 11:04 p.m. UTC | #1
在 2024/5/15 03:52, Naohiro Aota 写道:
> Add test for mkfs.btrfs's 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 <naohiro.aota@wdc.com>
> ---
>   tests/mkfs-tests/032-zoned-reset/test.sh | 62 ++++++++++++++++++++++++
>   1 file changed, 62 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 000000000000..6a599dd2874f
> --- /dev/null
> +++ b/tests/mkfs-tests/032-zoned-reset/test.sh
> @@ -0,0 +1,62 @@
> +#!/bin/bash
> +# Verify mkfs for zoned devices support block-group-tree feature
> +
> +source "$TEST_TOP/common" || exit
> +
> +setup_root_helper
> +prepare_test_dev
> +
> +nullb="$TEST_TOP/nullb"
> +# Create one 128M device with 4M zones, 32 of them
> +size=128
> +zone=4
> +
> +run_mayfail $SUDO_HELPER "$nullb" setup
> +if [ $? != 0 ]; then
> +	_not_run "cannot setup nullb environment for zoned devices"
> +fi
> +
> +# Record any other pre-existing devices in case creation fails
> +run_check $SUDO_HELPER "$nullb" ls
> +
> +# Last line has the name of the device node path
> +out=$(run_check_stdout $SUDO_HELPER "$nullb" create -s "$size" -z "$zone")
> +if [ $? != 0 ]; then
> +	_fail "cannot create nullb zoned device $i"
> +fi
> +dev=$(echo "$out" | tail -n 1)
> +name=$(basename "${dev}")

Can we wrap all the zoned devices setup in a common function?

I believe zoned tests would only increase in the future.

> +
> +run_check $SUDO_HELPER "$nullb" ls
> +
> +TEST_DEV="${dev}"
> +last_zone_sector=$(( 4 * 31 * 1024 * 1024 / 512 ))
> +# Write some data to the last zone
> +run_check $SUDO_HELPER dd if=/dev/urandom of="${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 "${dev}"
> +# Check if the lat zone is empty
> +$SUDO_HELPER blkzone report -o ${last_zone_sector} -c 1 "${dev}" | grep -Fq '(em)'

You may want to use `run_check_stdout`, as that would dump the command
and its output into the log for easier debug.

And since the test is relying on external program `blkzone` you may want
to put all those requirement into a zoned specific helper like
`check_zoned_preqreq()`.

Thanks,
Qu

> +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="${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 "${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="${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 "${dev}"
> +# Check if the lat zone is not empty
> +$SUDO_HELPER blkzone report -o ${last_zone_sector} -c 1 "${dev}" | grep -Fq '(em)'
> +if [ $? == 0 ]; then
> +	_fail "last zone is empty"
> +fi
> +
> +run_check $SUDO_HELPER "$nullb" rm "${name}"
Naohiro Aota May 15, 2024, 4:14 p.m. UTC | #2
On Wed, May 15, 2024 at 08:34:57AM +0930, Qu Wenruo wrote:
> 
> 
> 在 2024/5/15 03:52, Naohiro Aota 写道:
> > Add test for mkfs.btrfs's 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 <naohiro.aota@wdc.com>
> > ---
> >   tests/mkfs-tests/032-zoned-reset/test.sh | 62 ++++++++++++++++++++++++
> >   1 file changed, 62 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 000000000000..6a599dd2874f
> > --- /dev/null
> > +++ b/tests/mkfs-tests/032-zoned-reset/test.sh
> > @@ -0,0 +1,62 @@
> > +#!/bin/bash
> > +# Verify mkfs for zoned devices support block-group-tree feature
> > +
> > +source "$TEST_TOP/common" || exit
> > +
> > +setup_root_helper
> > +prepare_test_dev
> > +
> > +nullb="$TEST_TOP/nullb"
> > +# Create one 128M device with 4M zones, 32 of them
> > +size=128
> > +zone=4
> > +
> > +run_mayfail $SUDO_HELPER "$nullb" setup
> > +if [ $? != 0 ]; then
> > +	_not_run "cannot setup nullb environment for zoned devices"
> > +fi
> > +
> > +# Record any other pre-existing devices in case creation fails
> > +run_check $SUDO_HELPER "$nullb" ls
> > +
> > +# Last line has the name of the device node path
> > +out=$(run_check_stdout $SUDO_HELPER "$nullb" create -s "$size" -z "$zone")
> > +if [ $? != 0 ]; then
> > +	_fail "cannot create nullb zoned device $i"
> > +fi
> > +dev=$(echo "$out" | tail -n 1)
> > +name=$(basename "${dev}")
> 
> Can we wrap all the zoned devices setup in a common function?
> 
> I believe zoned tests would only increase in the future.

Sounds good. Then, we can migrate 030-zoned-rst to use it too as there is
no reason using a loop device there.

> 
> > +
> > +run_check $SUDO_HELPER "$nullb" ls
> > +
> > +TEST_DEV="${dev}"
> > +last_zone_sector=$(( 4 * 31 * 1024 * 1024 / 512 ))
> > +# Write some data to the last zone
> > +run_check $SUDO_HELPER dd if=/dev/urandom of="${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 "${dev}"
> > +# Check if the lat zone is empty
> > +$SUDO_HELPER blkzone report -o ${last_zone_sector} -c 1 "${dev}" | grep -Fq '(em)'
> 
> You may want to use `run_check_stdout`, as that would dump the command
> and its output into the log for easier debug.
> 
> And since the test is relying on external program `blkzone` you may want
> to put all those requirement into a zoned specific helper like
> `check_zoned_preqreq()`.

Will do. Thank you.

> Thanks,
> Qu
> 
> > +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="${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 "${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="${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 "${dev}"
> > +# Check if the lat zone is not empty
> > +$SUDO_HELPER blkzone report -o ${last_zone_sector} -c 1 "${dev}" | grep -Fq '(em)'
> > +if [ $? == 0 ]; then
> > +	_fail "last zone is empty"
> > +fi
> > +
> > +run_check $SUDO_HELPER "$nullb" rm "${name}"
diff mbox series

Patch

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 000000000000..6a599dd2874f
--- /dev/null
+++ b/tests/mkfs-tests/032-zoned-reset/test.sh
@@ -0,0 +1,62 @@ 
+#!/bin/bash
+# Verify mkfs for zoned devices support block-group-tree feature
+
+source "$TEST_TOP/common" || exit
+
+setup_root_helper
+prepare_test_dev
+
+nullb="$TEST_TOP/nullb"
+# Create one 128M device with 4M zones, 32 of them
+size=128
+zone=4
+
+run_mayfail $SUDO_HELPER "$nullb" setup
+if [ $? != 0 ]; then
+	_not_run "cannot setup nullb environment for zoned devices"
+fi
+
+# Record any other pre-existing devices in case creation fails
+run_check $SUDO_HELPER "$nullb" ls
+
+# Last line has the name of the device node path
+out=$(run_check_stdout $SUDO_HELPER "$nullb" create -s "$size" -z "$zone")
+if [ $? != 0 ]; then
+	_fail "cannot create nullb zoned device $i"
+fi
+dev=$(echo "$out" | tail -n 1)
+name=$(basename "${dev}")
+
+run_check $SUDO_HELPER "$nullb" ls
+
+TEST_DEV="${dev}"
+last_zone_sector=$(( 4 * 31 * 1024 * 1024 / 512 ))
+# Write some data to the last zone
+run_check $SUDO_HELPER dd if=/dev/urandom of="${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 "${dev}"
+# Check if the lat zone is empty
+$SUDO_HELPER blkzone report -o ${last_zone_sector} -c 1 "${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="${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 "${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="${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 "${dev}"
+# Check if the lat zone is not empty
+$SUDO_HELPER blkzone report -o ${last_zone_sector} -c 1 "${dev}" | grep -Fq '(em)'
+if [ $? == 0 ]; then
+	_fail "last zone is empty"
+fi
+
+run_check $SUDO_HELPER "$nullb" rm "${name}"