btrfs: Test proper interaction between skip_balance and paused balance
PATCH v3 1/1 btrfs: Test proper interaction between skip_balance and paused balance
Ensure a device can be added to a filesystem that has a paused balance operation and has been mounted with the 'skip_balance' mount option
---
V3:
* Added swapon to the list of exclusive ops
* Use _spare_dev_get
* Test balance resume via progs while balance is paused. I hit an assertion failure outside of xfstest while doing this sequence of steps so let's add it to ensure that's not regressed.
tests/btrfs/049 | 92 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/049.out | 1 + 2 files changed, 93 insertions(+) create mode 100755 tests/btrfs/049
tests/btrfs/049 new file +92 -0
@@ -0,0 +1,92 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2021 SUSE Linux Products GmbH. All Rights Reserved. +# +# FS QA Test 049 +# +# Ensure that it's possible to add a device when we have a paused balance +# and the filesystem is mounted with skip_balance. The issue is fixed by a patch +# titled "btrfs: allow device add if balance is paused" +# +. ./common/preamble +_begin_fstest quick balance auto + +# real QA test starts here + +_supported_fs btrfs +_require_scratch_swapfile +_require_scratch_dev_pool 3 + +_scratch_dev_pool_get 2 +_spare_dev_get + +swapfile="$SCRATCH_MNT/swap" +_scratch_pool_mkfs >/dev/null +_scratch_mount +_format_swapfile "$swapfile" $(($(get_page_size) * 10)) + +check_exclusive_ops() +{ + $BTRFS_UTIL_PROG device remove 2 $SCRATCH_MNT &>/dev/null + [ $? -ne 0 ] || _fail "Successfully removed device" + $BTRFS_UTIL_PROG filesystem resize -5m $SCRATCH_MNT &> /dev/null + [ $? -ne 0 ] || _fail "Successfully resized filesystem" + $BTRFS_UTIL_PROG replace start -B 2 $SPARE_DEV $SCRATCH_MNT &> /dev/null + [ $? -ne 0 ] || _fail "Successfully replaced device" + swapon "$swapfile" &> /dev/null + [ $? -ne 0 ] || _fail "Successfully enabled a swap file" +} + +uuid=$(findmnt -n -o UUID $SCRATCH_MNT) + +# Create some files on the so that balance doesn't complete instantly +args=`_scale_fsstress_args -z \ + -f write=10 -f creat=10 \ + -n 1000 -p 2 -d $SCRATCH_MNT/stress_dir` +echo "Run fsstress $args" >>$seqres.full +$FSSTRESS_PROG $args >/dev/null 2>&1 + +# Start and pause balance to ensure it will be restored on remount +echo "Start balance" >>$seqres.full +_run_btrfs_balance_start --bg "$SCRATCH_MNT" +$BTRFS_UTIL_PROG balance pause "$SCRATCH_MNT" +$BTRFS_UTIL_PROG balance status "$SCRATCH_MNT" | grep -q paused +[ $? -eq 0 ] || _fail "Balance not paused" + +# Exclusive ops should be blocked on manual pause of balance +check_exclusive_ops + +# Balance is now placed in paused state during mount +_scratch_cycle_mount "skip_balance" + +# Exclusive ops should be blocked on balance pause due to 'skip_balance' +check_exclusive_ops + +# Device add is the only allowed operation +$BTRFS_UTIL_PROG device add -K -f $SPARE_DEV "$SCRATCH_MNT" + +# Exclusive ops should still be blocked on account that balance is still paused +check_exclusive_ops + +# Should be possible to resume balance after device add +$BTRFS_UTIL_PROG balance resume "$SCRATCH_MNT" &>/dev/null +[ $? -eq 0 ] || _fail "Couldn't resume balance after device add" + +# Add more files so that new balance won't fish immediately +$FSSTRESS_PROG $args >/dev/null 2>&1 + +# Now pause->resume balance. This ensures balance paused is properly set in +# the kernel and won't trigger an assertion failure. +echo "Start balance" >>$seqres.full +_run_btrfs_balance_start --bg "$SCRATCH_MNT" +$BTRFS_UTIL_PROG balance pause "$SCRATCH_MNT" +$BTRFS_UTIL_PROG balance status "$SCRATCH_MNT" | grep -q paused +[ $? -eq 0 ] || _fail "Balance not paused" +$BTRFS_UTIL_PROG balance resume "$SCRATCH_MNT" &>/dev/null +[ $? -eq 0 ] || _fail "Balance can't be resumed via IOCTL" + +_spare_dev_put +_scratch_dev_pool_put +echo "Silence is golden" +status=0 +exit
tests/btrfs/049.out +1 -0
@@ -1 +1,2 @@ QA output created by 049 +Silence is golden
--
2.17.1
Quoted 25 lines · Nikolay Borisov
Ensure a device can be added to a filesystem that has a paused balance operation and has been mounted with the '
skip_balance' mount optionSigned-off-by Nikolay Borisov <[email protected]>---
V3:
* Added swapon to the list of exclusive ops
* Use_spare_dev_get
* Test balance resume via progs while balance is paused. I hit an assertion failure outside of xfstest while doing this sequence of steps so let's add it to ensure that's not regressed.tests/btrfs/049 | 92 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/049.out | 1 + 2 files changed, 93 insertions(+)create mode 100755 tests/btrfs/049
tests/btrfs/049 new file +1
-0@@ -0,0 +1,92 @@ +#! /bin/bash
tests/btrfs/049 line 9
Quoted 10 lines
tests/btrfs/049 new file +8
-0+# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2021 SUSE Linux Products GmbH. All Rights Reserved. +# +# FS QA Test 049 +# +# Ensure that it's possible to add a device when we have a paused balance +# and the filesystem is mounted with skip_balance. The issue is fixed by a patch +# titled "btrfs: allow device add if balance is paused"
It is a new feature, not a bug fix? The kernel patch won't backport to the stable kernels. Then on older kernels, this test has to exit with _notrun().
Is there any way to achieve this? There isn't any sysfs interface that will help and, so far we haven't used the kernel version to achieve something like this.
Quoted 93 lines
tests/btrfs/049 new file +83
-0+# +. ./common/preamble +_begin_fstest quick balance auto + +# real QA test starts here + +_supported_fs btrfs +_require_scratch_swapfile +_require_scratch_dev_pool 3 + +_scratch_dev_pool_get 2 +_spare_dev_get + +swapfile="$SCRATCH_MNT/swap" +_scratch_pool_mkfs >/dev/null +_scratch_mount +_format_swapfile "$swapfile" $(($(get_page_size) * 10)) + +check_exclusive_ops() +{ + $BTRFS_UTIL_PROG device remove 2 $SCRATCH_MNT &>/dev/null + [ $? -ne 0 ] || _fail "Successfully removed device" + $BTRFS_UTIL_PROG filesystem resize -5m $SCRATCH_MNT &> /dev/null + [ $? -ne 0 ] || _fail "Successfully resized filesystem" + $BTRFS_UTIL_PROG replace start -B 2 $SPARE_DEV $SCRATCH_MNT &> /dev/null + [ $? -ne 0 ] || _fail "Successfully replaced device" + swapon "$swapfile" &> /dev/null + [ $? -ne 0 ] || _fail "Successfully enabled a swap file" +} + +uuid=$(findmnt -n -o UUID $SCRATCH_MNT) + +# Create some files on the so that balance doesn't complete instantly +args=`_scale_fsstress_args -z \ + -f write=10 -f creat=10 \ + -n 1000 -p 2 -d $SCRATCH_MNT/stress_dir` +echo "Run fsstress $args" >>$seqres.full +$FSSTRESS_PROG $args >/dev/null 2>&1 + +# Start and pause balance to ensure it will be restored on remount +echo "Start balance" >>$seqres.full +_run_btrfs_balance_start --bg "$SCRATCH_MNT" +$BTRFS_UTIL_PROG balance pause "$SCRATCH_MNT" +$BTRFS_UTIL_PROG balance status "$SCRATCH_MNT" | grep -q paused +[ $? -eq 0 ] || _fail "Balance not paused" + +# Exclusive ops should be blocked on manual pause of balance +check_exclusive_ops + +# Balance is now placed in paused state during mount +_scratch_cycle_mount "skip_balance" + +# Exclusive ops should be blocked on balance pause due to 'skip_balance' +check_exclusive_ops + +# Device add is the only allowed operation +$BTRFS_UTIL_PROG device add -K -f $SPARE_DEV "$SCRATCH_MNT" + +# Exclusive ops should still be blocked on account that balance is still paused +check_exclusive_ops + +# Should be possible to resume balance after device add +$BTRFS_UTIL_PROG balance resume "$SCRATCH_MNT" &>/dev/null +[ $? -eq 0 ] || _fail "Couldn't resume balance after device add" + +# Add more files so that new balance won't fish immediately +$FSSTRESS_PROG $args >/dev/null 2>&1 + +# Now pause->resume balance. This ensures balance paused is properly set in +# the kernel and won't trigger an assertion failure. +echo "Start balance" >>$seqres.full +_run_btrfs_balance_start --bg "$SCRATCH_MNT" +$BTRFS_UTIL_PROG balance pause "$SCRATCH_MNT" +$BTRFS_UTIL_PROG balance status "$SCRATCH_MNT" | grep -q paused +[ $? -eq 0 ] || _fail "Balance not paused" +$BTRFS_UTIL_PROG balance resume "$SCRATCH_MNT" &>/dev/null +[ $? -eq 0 ] || _fail "Balance can't be resumed via IOCTL" + +_spare_dev_put +_scratch_dev_pool_put +echo "Silence is golden" +status=0 +exittests/btrfs/049.out +1
-1@@ -1 +1,2 @@ QA output created by 049 +Silence is golden --2.17.1
<snip>
Quoted 9 lines
Quoted 1 line
+# titled "btrfs: allow device add if balance is paused"
It is a new feature, not a bug fix? The kernel patch won't backport to the stable kernels. Then on older kernels, this test has to exit with
_notrun().
Is there any way to achieve this? There isn't any sysfs interface that will help and, so far we haven't used the kernel version to achieve something like this.
No, and this is outside the remit of xfstest. Anyone who is running xfstest should ensure incompatible tests are excluded.
<snip>
Quoted 13 lines · Nikolay Borisov
<snip>
Quoted 9 lines
Quoted 1 line
+# titled "btrfs: allow device add if balance is paused"
It is a new feature, not a bug fix? The kernel patch won't backport to the stable kernels. Then on older kernels, this test has to exit with
_notrun().
Is there any way to achieve this? There isn't any sysfs interface that will help and, so far we haven't used the kernel version to achieve something like this.
Quoted 2 lines
No, and this is outside the remit of xfstest. Anyone who is running xfstest should ensure incompatible tests are excluded.
I don't think that's the case, we perfer test case detect required env to run the test and _notrun if any condition not met. For regression test for bug fix, we want the test to fail on old/un-patched kernel, but for new features we need a way to tell if the kernel in test has the feature or not.
Thanks,
Eryu
Quoted 14 lines · Eryu Guan
Quoted 13 lines · Nikolay Borisov
<snip>
Quoted 9 lines
Quoted 1 line
+# titled "btrfs: allow device add if balance is paused"
It is a new feature, not a bug fix? The kernel patch won't backport to the stable kernels. Then on older kernels, this test has to exit with
_notrun().
Is there any way to achieve this? There isn't any sysfs interface that will help and, so far we haven't used the kernel version to achieve something like this.
Quoted 8 lines
Quoted 2 lines
No, and this is outside the remit of xfstest. Anyone who is running xfstest should ensure incompatible tests are excluded.
I don't think that's the case, we perfer test case detect required env to run the test and
_notrunif any condition not met. For regression test for bug fix, we want the test to fail on old/un-patched kernel, but for new features we need a way to tell if the kernel in test has the feature or not.
There isn't really an easy way to test for the presence of this feature. The closest I could think of is modify btrfs' exclusive_operation sysfs to show "balance paused" and in the test simply run a dummy balance and pause it and check whether "balance" or "balance paused" is the state of the exclusive op. However this means for this test to also rely on the presence of the exclusive_operation sysfs file. However, I don't like this because adding a device to balance is independent of the exclusive_operation sysfs i.e it only has an informative role.
Quoted 4 lines
Thanks,
Eryu
Quoted 24 lines · Nikolay Borisov
Ensure a device can be added to a filesystem that has a paused balance operation and has been mounted with the '
skip_balance' mount optionSigned-off-by Nikolay Borisov <[email protected]>---
V3:
* Added swapon to the list of exclusive ops
* Use_spare_dev_get
* Test balance resume via progs while balance is paused. I hit an assertion failure outside of xfstest while doing this sequence of steps so let's add it to ensure that's not regressed.tests/btrfs/049 | 92 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/049.out | 1 + 2 files changed, 93 insertions(+) create mode 100755 tests/btrfs/049tests/btrfs/049 new file +0
-0
tests/btrfs/049 line 9
Quoted 9 lines
tests/btrfs/049 new file +9
-0@@ -0,0 +1,92 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2021 SUSE Linux Products GmbH. All Rights Reserved. +# +# FS QA Test 049 +# +# Ensure that it's possible to add a device when we have a paused balance +# and the filesystem is mounted with skip_balance. The issue is fixed by a patch +# titled "btrfs: allow device add if balance is paused"
After looking at the kernel patch, it looks more like a bug fix not a new feature, as adding device to a ENOSPC-but-paused balance seems to be the only reasonable way to finish the balance. If that's the case, there's no problem add this case that will fail on old kernels.
Quoted 21 lines
tests/btrfs/049 new file +21
-0+# +. ./common/preamble +_begin_fstest quick balance auto + +# real QA test starts here + +_supported_fs btrfs +_require_scratch_swapfile +_require_scratch_dev_pool 3 + +_scratch_dev_pool_get 2 +_spare_dev_get + +swapfile="$SCRATCH_MNT/swap" +_scratch_pool_mkfs >/dev/null +_scratch_mount +_format_swapfile "$swapfile" $(($(get_page_size) * 10)) + +check_exclusive_ops() +{ + $BTRFS_UTIL_PROG device remove 2 $SCRATCH_MNT &>/dev/null
tests/btrfs/049 line 40
Quoted 10 lines
tests/btrfs/049 new file +10
-0+ [ $? -ne 0 ] || _fail "Successfully removed device" + $BTRFS_UTIL_PROG filesystem resize -5m $SCRATCH_MNT &> /dev/null + [ $? -ne 0 ] || _fail "Successfully resized filesystem" + $BTRFS_UTIL_PROG replace start -B 2 $SPARE_DEV $SCRATCH_MNT &> /dev/null + [ $? -ne 0 ] || _fail "Successfully replaced device" + swapon "$swapfile" &> /dev/null + [ $? -ne 0 ] || _fail "Successfully enabled a swap file" +} + +uuid=$(findmnt -n -o UUID $SCRATCH_MNT)
$uuid is not used anywhere, can be removed?
tests/btrfs/049 line 42
Quoted 2 lines
tests/btrfs/049 new file +2
-0+ +# Create some files on the so that balance doesn't complete instantly
You mean "on the device"?
Quoted 23 lines
tests/btrfs/049 new file +23
-0+args=`_scale_fsstress_args -z \ + -f write=10 -f creat=10 \ + -n 1000 -p 2 -d $SCRATCH_MNT/stress_dir` +echo "Run fsstress $args" >>$seqres.full +$FSSTRESS_PROG $args >/dev/null 2>&1 + +# Start and pause balance to ensure it will be restored on remount +echo "Start balance" >>$seqres.full +_run_btrfs_balance_start --bg "$SCRATCH_MNT" +$BTRFS_UTIL_PROG balance pause "$SCRATCH_MNT" +$BTRFS_UTIL_PROG balance status "$SCRATCH_MNT" | grep -q paused +[ $? -eq 0 ] || _fail "Balance not paused" + +# Exclusive ops should be blocked on manual pause of balance +check_exclusive_ops + +# Balance is now placed in paused state during mount +_scratch_cycle_mount "skip_balance" + +# Exclusive ops should be blocked on balance pause due to 'skip_balance' +check_exclusive_ops + +# Device add is the only allowed operation
tests/btrfs/049 line 75
Quoted 10 lines
tests/btrfs/049 new file +10
-0+$BTRFS_UTIL_PROG device add -K -f $SPARE_DEV "$SCRATCH_MNT" + +# Exclusive ops should still be blocked on account that balance is still paused +check_exclusive_ops + +# Should be possible to resume balance after device add +$BTRFS_UTIL_PROG balance resume "$SCRATCH_MNT" &>/dev/null +[ $? -eq 0 ] || _fail "Couldn't resume balance after device add" + +# Add more files so that new balance won't fish immediately
^^^^ finish ?
Quoted 22 lines
tests/btrfs/049 new file +17
-0+$FSSTRESS_PROG $args >/dev/null 2>&1 + +# Now pause->resume balance. This ensures balance paused is properly set in +# the kernel and won't trigger an assertion failure. +echo "Start balance" >>$seqres.full +_run_btrfs_balance_start --bg "$SCRATCH_MNT" +$BTRFS_UTIL_PROG balance pause "$SCRATCH_MNT" +$BTRFS_UTIL_PROG balance status "$SCRATCH_MNT" | grep -q paused +[ $? -eq 0 ] || _fail "Balance not paused" +$BTRFS_UTIL_PROG balance resume "$SCRATCH_MNT" &>/dev/null +[ $? -eq 0 ] || _fail "Balance can't be resumed via IOCTL" + +_spare_dev_put +_scratch_dev_pool_put +echo "Silence is golden" +status=0 +exittests/btrfs/049.out +0
-0
tests/btrfs/049.out line 2
Quoted 2 lines
tests/btrfs/049.out +1
-0@@ -1 +1,2 @@ QA output created by 049 +Silence is golden
Ah, 049.out was forgotten to be removed by commit 668c859d37f2 ("btrfs/049: remove the test"), so it's reused here.
Thanks,
Eryu
Quoted 31 lines · Eryu Guan
Quoted 30 lines · Nikolay Borisov
Ensure a device can be added to a filesystem that has a paused balance operation and has been mounted with the '
skip_balance' mount optionSigned-off-by Nikolay Borisov <[email protected]>---
V3:
* Added swapon to the list of exclusive ops
* Use_spare_dev_get
* Test balance resume via progs while balance is paused. I hit an assertion failure outside of xfstest while doing this sequence of steps so let's add it to ensure that's not regressed.tests/btrfs/049 | 92 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/049.out | 1 + 2 files changed, 93 insertions(+) create mode 100755 tests/btrfs/049tests/btrfs/049 new file +6
-0@@ -0,0 +1,92 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2021 SUSE Linux Products GmbH. All Rights Reserved. +# +# FS QA Test 049 +#
Quoted 8 lines
tests/btrfs/049 line 9
Quoted 3 lines
tests/btrfs/049 new file +3
-0+# Ensure that it's possible to add a device when we have a paused balance +# and the filesystem is mounted with skip_balance. The issue is fixed by a patch +# titled "btrfs: allow device add if balance is paused"After looking at the kernel patch, it looks more like a bug fix not a new feature, as adding device to a ENOSPC-but-paused balance seems to be the only reasonable way to finish the balance. If that's the case, there's no problem add this case that will fail on old kernels.
*nod*
Quoted 26 lines
Quoted 26 lines
tests/btrfs/049 new file +25
-0+# +. ./common/preamble +_begin_fstest quick balance auto + +# real QA test starts here + +_supported_fs btrfs +_require_scratch_swapfile +_require_scratch_dev_pool 3 + +_scratch_dev_pool_get 2 +_spare_dev_get + +swapfile="$SCRATCH_MNT/swap" +_scratch_pool_mkfs >/dev/null +_scratch_mount +_format_swapfile "$swapfile" $(($(get_page_size) * 10)) + +check_exclusive_ops() +{ + $BTRFS_UTIL_PROG device remove 2 $SCRATCH_MNT &>/dev/null + [ $? -ne 0 ] || _fail "Successfully removed device" + $BTRFS_UTIL_PROG filesystem resize -5m $SCRATCH_MNT &> /dev/null + [ $? -ne 0 ] || _fail "Successfully resized filesystem" + $BTRFS_UTIL_PROG replace start -B 2 $SPARE_DEV $SCRATCH_MNT &> /dev/null
Quoted 8 lines
tests/btrfs/049 line 40
Quoted 6 lines
tests/btrfs/049 new file +6
-0+ [ $? -ne 0 ] || _fail "Successfully replaced device" + swapon "$swapfile" &> /dev/null + [ $? -ne 0 ] || _fail "Successfully enabled a swap file" +} + +uuid=$(findmnt -n -o UUID $SCRATCH_MNT)$uuid is not used anywhere, can be removed?
Sure, I'm sure I did but I guess fucked up during rebase.
Quoted 5 lines
tests/btrfs/049 line 42
Quoted 3 lines
tests/btrfs/049 new file +2
-0+ +# Create some files on the so that balance doesn't complete instantlyYou mean "on the device"?
Yep.
Quoted 27 lines
Quoted 27 lines
tests/btrfs/049 new file +26
-0+args=`_scale_fsstress_args -z \ + -f write=10 -f creat=10 \ + -n 1000 -p 2 -d $SCRATCH_MNT/stress_dir` +echo "Run fsstress $args" >>$seqres.full +$FSSTRESS_PROG $args >/dev/null 2>&1 + +# Start and pause balance to ensure it will be restored on remount +echo "Start balance" >>$seqres.full +_run_btrfs_balance_start --bg "$SCRATCH_MNT" +$BTRFS_UTIL_PROG balance pause "$SCRATCH_MNT" +$BTRFS_UTIL_PROG balance status "$SCRATCH_MNT" | grep -q paused +[ $? -eq 0 ] || _fail "Balance not paused" + +# Exclusive ops should be blocked on manual pause of balance +check_exclusive_ops + +# Balance is now placed in paused state during mount +_scratch_cycle_mount "skip_balance" + +# Exclusive ops should be blocked on balance pause due to 'skip_balance' +check_exclusive_ops + +# Device add is the only allowed operation +$BTRFS_UTIL_PROG device add -K -f $SPARE_DEV "$SCRATCH_MNT" + +# Exclusive ops should still be blocked on account that balance is still paused
Quoted 8 lines
tests/btrfs/049 line 75
Quoted 7 lines
tests/btrfs/049 new file +7
-0+check_exclusive_ops + +# Should be possible to resume balance after device add +$BTRFS_UTIL_PROG balance resume "$SCRATCH_MNT" &>/dev/null +[ $? -eq 0 ] || _fail "Couldn't resume balance after device add" + +# Add more files so that new balance won't fish immediately^^^^ finish ?
Yes,
Quoted 31 lines
Quoted 22 lines
tests/btrfs/049 new file +17
-0+$FSSTRESS_PROG $args >/dev/null 2>&1 + +# Now pause->resume balance. This ensures balance paused is properly set in +# the kernel and won't trigger an assertion failure. +echo "Start balance" >>$seqres.full +_run_btrfs_balance_start --bg "$SCRATCH_MNT" +$BTRFS_UTIL_PROG balance pause "$SCRATCH_MNT" +$BTRFS_UTIL_PROG balance status "$SCRATCH_MNT" | grep -q paused +[ $? -eq 0 ] || _fail "Balance not paused" +$BTRFS_UTIL_PROG balance resume "$SCRATCH_MNT" &>/dev/null +[ $? -eq 0 ] || _fail "Balance can't be resumed via IOCTL" + +_spare_dev_put +_scratch_dev_pool_put +echo "Silence is golden" +status=0 +exittests/btrfs/049.out +0
-0tests/btrfs/049.out line 2
Quoted 2 lines
tests/btrfs/049.out +1
-0@@ -1 +1,2 @@ QA output created by 049 +Silence is goldenAh, 049.out was forgotten to be removed by commit
668c859d37f2("btrfs/049: remove the test"), so it's reused here.Thanks,
Eryu