btrfs: Add a test for dead looping balance after balance cancel
PATCH v3 1/1 btrfs: Add a test for dead looping balance after balance cancel
Test if canceling a running balance can cause later balance to dead loop.
The ifx is titled "btrfs: relocation: Clear the DEAD_RELOC_TREE bit for
orphan roots to prevent runaway balance".
---
Changelog:
v2:
- Remove lsof debug output
v3:
- Remove ps debug output
--- tests/btrfs/213 | 64 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/213.out | 2 ++ tests/btrfs/group | 1 + 3 files changed, 67 insertions(+) create mode 100755 tests/btrfs/213 create mode 100644 tests/btrfs/213.out
tests/btrfs/213 new file +64 -0
@@ -0,0 +1,64 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved. +# +# FS QA Test 213 +# +# Test if canceling a running balance can lead to dead looping balance +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# Modify as appropriate. +_supported_fs btrfs +_supported_os Linux +_require_scratch +_require_command "$KILLALL_PROG" killall + +_scratch_mkfs >> $seqres.full +_scratch_mount + +runtime=4 + +# Create enough IO so that we need around $runtime seconds to relocate it +dd if=/dev/zero bs=1M of="$SCRATCH_MNT/file" oflag=sync status=none \ + &> /dev/null & +dd_pid=$! +sleep $runtime +"$KILLALL_PROG" -q dd &> /dev/null +wait $dd_pid + +# Now balance should take at least $runtime seconds, we can cancel it at +# $runtime/2 to ensure a success cancel. +$BTRFS_UTIL_PROG balance start -d --bg "$SCRATCH_MNT" +sleep $(($runtime / 2)) +$BTRFS_UTIL_PROG balance cancel "$SCRATCH_MNT" + +# Now check if we can finish relocating metadata, which should finish very +# quickly +$BTRFS_UTIL_PROG balance start -m "$SCRATCH_MNT" >> $seqres.full + +echo "Silence is golden" + +# success, all done +status=0 +exit
tests/btrfs/213.out new file +2 -0
@@ -0,0 +1,2 @@ +QA output created by 213 +Silence is golden
tests/btrfs/group +1 -0
@@ -215,3 +215,4 @@ 210 auto quick qgroup snapshot 211 auto quick log prealloc 212 auto balance dangerous +213 auto fast balance dangerous
Signature · 1 line
2.26.2
Quoted 1 line · Qu Wenruo
The ifx is titled "btrfs: relocation: Clear the
DEAD_RELOC_TREEbit for
Nit: s/ifx/fix/
Quoted 65 lines · Qu Wenruo
Test if canceling a running balance can cause later balance to dead loop.
The ifx is titled "btrfs: relocation: Clear the
DEAD_RELOC_TREEbit for
orphan roots to prevent runaway balance".Signed-off-by Qu Wenruo <[email protected]>---
Changelog:
v2:
- Remove lsof debug output
v3:
- Remove ps debug output--- tests/btrfs/213 | 64 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/213.out | 2 ++ tests/btrfs/group | 1 + 3 files changed, 67 insertions(+) create mode 100755 tests/btrfs/213 create mode 100644 tests/btrfs/213.outtests/btrfs/213 new file +37
-0@@ -0,0 +1,64 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved. +# +# FS QA Test 213 +# +# Test if canceling a running balance can lead to dead looping balance +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# Modify as appropriate. +_supported_fs btrfs +_supported_os Linux +_require_scratch +_require_command "$KILLALL_PROG" killall + +_scratch_mkfs >> $seqres.full
tests/btrfs/213 line 47
Quoted 10 lines
tests/btrfs/213 new file +10
-0+_scratch_mount + +runtime=4 + +# Create enough IO so that we need around $runtime seconds to relocate it +dd if=/dev/zero bs=1M of="$SCRATCH_MNT/file" oflag=sync status=none \ + &> /dev/null & +dd_pid=$! +sleep $runtime +"$KILLALL_PROG" -q dd &> /dev/null
Do we really need the killall program? There's only one dd process.
We should also kill the dd process at _cleanup(), as killing the test during the sleep above will result in the dd process not being killed.
tests/btrfs/213 line 58
Quoted 11 lines
tests/btrfs/213 new file +11
-0+wait $dd_pid + +# Now balance should take at least $runtime seconds, we can cancel it at +# $runtime/2 to ensure a success cancel. +$BTRFS_UTIL_PROG balance start -d --bg "$SCRATCH_MNT" +sleep $(($runtime / 2)) +$BTRFS_UTIL_PROG balance cancel "$SCRATCH_MNT" + +# Now check if we can finish relocating metadata, which should finish very +# quickly +$BTRFS_UTIL_PROG balance start -m "$SCRATCH_MNT" >> $seqres.full
Why redirect this one to $seqres.full and not the other balance? What kind of useful information it provides?
Quoted 19 lines
tests/btrfs/213 new file +6
-0+ +echo "Silence is golden" + +# success, all done +status=0 +exittests/btrfs/213.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 213 +Silence is goldentests/btrfs/group +0
-0
tests/btrfs/group line 218
Quoted 4 lines
tests/btrfs/group +1
-0@@ -215,3 +215,4 @@ 210 auto quick qgroup snapshot 211 auto quick log prealloc 212 auto balance dangerous +213 auto fast balance dangerous
fast -> quick
Thanks.
Quoted 3 lines
--
2.26.2
Signature · 3 lines
Filipe David Manana, “Whether you think you can, or you think you can't — you're right.”
Quoted 79 lines · Filipe Manana
Quoted 65 lines · Qu Wenruo
Test if canceling a running balance can cause later balance to dead loop.
The ifx is titled "btrfs: relocation: Clear the
DEAD_RELOC_TREEbit for
orphan roots to prevent runaway balance".Signed-off-by Qu Wenruo <[email protected]>---
Changelog:
v2:
- Remove lsof debug output
v3:
- Remove ps debug output--- tests/btrfs/213 | 64 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/213.out | 2 ++ tests/btrfs/group | 1 + 3 files changed, 67 insertions(+) create mode 100755 tests/btrfs/213 create mode 100644 tests/btrfs/213.outtests/btrfs/213 new file +37
-0@@ -0,0 +1,64 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved. +# +# FS QA Test 213 +# +# Test if canceling a running balance can lead to dead looping balance +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# Modify as appropriate. +_supported_fs btrfs +_supported_os Linux +_require_scratch +_require_command "$KILLALL_PROG" killall + +_scratch_mkfs >> $seqres.fulltests/btrfs/213 line 47
Quoted 10 lines
tests/btrfs/213 new file +10
-0+_scratch_mount + +runtime=4 + +# Create enough IO so that we need around $runtime seconds to relocate it +dd if=/dev/zero bs=1M of="$SCRATCH_MNT/file" oflag=sync status=none \ + &> /dev/null & +dd_pid=$! +sleep $runtime +"$KILLALL_PROG" -q dd &> /dev/nullDo we really need the killall program? There's only one dd process.
Quoted 2 lines
We should also kill the dd process at
_cleanup(), as killing the test during the sleep above will result in the dd process not being killed.
The main problem here is, I can't find a good way to kill dd. plain 'kill $dd_pid' doesn't seem to kill it properly, as my debug lsof/ps still shows dd running and failed to unmount the fs.
'kill -KILL $dd_pid' kills it well, but causes extra output for the terminated dd.
Only 'killall -q dd' works as expected.
Any good advice on this?
Quoted 15 lines
tests/btrfs/213 line 58
Quoted 12 lines
tests/btrfs/213 new file +11
-0+wait $dd_pid + +# Now balance should take at least $runtime seconds, we can cancel it at +# $runtime/2 to ensure a success cancel. +$BTRFS_UTIL_PROG balance start -d --bg "$SCRATCH_MNT" +sleep $(($runtime / 2)) +$BTRFS_UTIL_PROG balance cancel "$SCRATCH_MNT" + +# Now check if we can finish relocating metadata, which should finish very +# quickly +$BTRFS_UTIL_PROG balance start -m "$SCRATCH_MNT" >> $seqres.fullWhy redirect this one to $seqres.full and not the other balance? What kind of useful information it provides?
Not really much, just an indicator to show that the balance finishes as expected.
And we don't want to output it golden output, as mkfs change may create more metadata chunks and cause difference.
For other ones, like the one to be canceled, we don't really care that much.
Thanks,
Qu
Quoted 34 lines
Quoted 20 lines
tests/btrfs/213 new file +6
-0+ +echo "Silence is golden" + +# success, all done +status=0 +exittests/btrfs/213.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 213 +Silence is goldentests/btrfs/group +0
-0tests/btrfs/group line 218
Quoted 4 lines
tests/btrfs/group +1
-0@@ -215,3 +215,4 @@ 210 auto quick qgroup snapshot 211 auto quick log prealloc 212 auto balance dangerous +213 auto fast balance dangerousfast -> quick
Thanks.
Quoted 3 lines
--
2.26.2
Quoted 89 lines · Qu Wenruo
Quoted 79 lines · Filipe Manana
Quoted 65 lines · Qu Wenruo
Test if canceling a running balance can cause later balance to dead loop.
The ifx is titled "btrfs: relocation: Clear the
DEAD_RELOC_TREEbit for
orphan roots to prevent runaway balance".Signed-off-by Qu Wenruo <[email protected]>---
Changelog:
v2:
- Remove lsof debug output
v3:
- Remove ps debug output--- tests/btrfs/213 | 64 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/213.out | 2 ++ tests/btrfs/group | 1 + 3 files changed, 67 insertions(+) create mode 100755 tests/btrfs/213 create mode 100644 tests/btrfs/213.outtests/btrfs/213 new file +37
-0@@ -0,0 +1,64 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved. +# +# FS QA Test 213 +# +# Test if canceling a running balance can lead to dead looping balance +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# Modify as appropriate. +_supported_fs btrfs +_supported_os Linux +_require_scratch +_require_command "$KILLALL_PROG" killall + +_scratch_mkfs >> $seqres.fulltests/btrfs/213 line 47
Quoted 10 lines
tests/btrfs/213 new file +10
-0+_scratch_mount + +runtime=4 + +# Create enough IO so that we need around $runtime seconds to relocate it +dd if=/dev/zero bs=1M of="$SCRATCH_MNT/file" oflag=sync status=none \ + &> /dev/null & +dd_pid=$! +sleep $runtime +"$KILLALL_PROG" -q dd &> /dev/nullDo we really need the killall program? There's only one dd process.
Quoted 2 lines
We should also kill the dd process at
_cleanup(), as killing the test during the sleep above will result in the dd process not being killed.The main problem here is, I can't find a good way to kill dd. plain 'kill $dd_pid' doesn't seem to kill it properly, as my debug lsof/ps still shows dd running and failed to unmount the fs.
Quoted 6 lines
'kill -KILL $dd_pid' kills it well, but causes extra output for the terminated dd.
Only 'killall -q dd' works as expected.
Any good advice on this?
Oh, the fstests "kindly" overrides dd, "kill $dd_pid" only kills the child bash running that dd function, not the real dd command. I'll use xfs_io to ensure we get no extra wrapper.
Thanks,
Qu
Quoted 61 lines
Quoted 16 lines
tests/btrfs/213 line 58
Quoted 13 lines
tests/btrfs/213 new file +11
-0+wait $dd_pid + +# Now balance should take at least $runtime seconds, we can cancel it at +# $runtime/2 to ensure a success cancel. +$BTRFS_UTIL_PROG balance start -d --bg "$SCRATCH_MNT" +sleep $(($runtime / 2)) +$BTRFS_UTIL_PROG balance cancel "$SCRATCH_MNT" + +# Now check if we can finish relocating metadata, which should finish very +# quickly +$BTRFS_UTIL_PROG balance start -m "$SCRATCH_MNT" >> $seqres.fullWhy redirect this one to $seqres.full and not the other balance? What kind of useful information it provides?
Not really much, just an indicator to show that the balance finishes as expected.
And we don't want to output it golden output, as mkfs change may create more metadata chunks and cause difference.For other ones, like the one to be canceled, we don't really care that much.
Thanks,
QuQuoted 34 lines
Quoted 20 lines
tests/btrfs/213 new file +6
-0+ +echo "Silence is golden" + +# success, all done +status=0 +exittests/btrfs/213.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 213 +Silence is goldentests/btrfs/group +0
-0tests/btrfs/group line 218
Quoted 4 lines
tests/btrfs/group +1
-0@@ -215,3 +215,4 @@ 210 auto quick qgroup snapshot 211 auto quick log prealloc 212 auto balance dangerous +213 auto fast balance dangerousfast -> quick
Thanks.
Quoted 3 lines
--
2.26.2
Quoted 96 lines · Qu Wenruo
Quoted 92 lines · Qu Wenruo
Quoted 79 lines · Filipe Manana
Quoted 65 lines · Qu Wenruo
Test if canceling a running balance can cause later balance to dead loop.
The ifx is titled "btrfs: relocation: Clear the
DEAD_RELOC_TREEbit for
orphan roots to prevent runaway balance".Signed-off-by Qu Wenruo <[email protected]>---
Changelog:
v2:
- Remove lsof debug output
v3:
- Remove ps debug output--- tests/btrfs/213 | 64 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/213.out | 2 ++ tests/btrfs/group | 1 + 3 files changed, 67 insertions(+) create mode 100755 tests/btrfs/213 create mode 100644 tests/btrfs/213.outtests/btrfs/213 new file +37
-0@@ -0,0 +1,64 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved. +# +# FS QA Test 213 +# +# Test if canceling a running balance can lead to dead looping balance +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# Modify as appropriate. +_supported_fs btrfs +_supported_os Linux +_require_scratch +_require_command "$KILLALL_PROG" killall + +_scratch_mkfs >> $seqres.fulltests/btrfs/213 line 47
Quoted 10 lines
tests/btrfs/213 new file +10
-0+_scratch_mount + +runtime=4 + +# Create enough IO so that we need around $runtime seconds to relocate it +dd if=/dev/zero bs=1M of="$SCRATCH_MNT/file" oflag=sync status=none \ + &> /dev/null & +dd_pid=$! +sleep $runtime +"$KILLALL_PROG" -q dd &> /dev/nullDo we really need the killall program? There's only one dd process.
Quoted 2 lines
We should also kill the dd process at
_cleanup(), as killing the test during the sleep above will result in the dd process not being killed.The main problem here is, I can't find a good way to kill dd. plain 'kill $dd_pid' doesn't seem to kill it properly, as my debug lsof/ps still shows dd running and failed to unmount the fs.
'kill -KILL $dd_pid' kills it well, but causes extra output for the terminated dd.
Quoted 7 lines
Quoted 3 lines
Only 'killall -q dd' works as expected.
Any good advice on this?
Oh, the fstests "kindly" overrides dd, "kill $dd_pid" only kills the child bash running that dd function, not the real dd command. I'll use
xfs_ioto ensure we get no extra wrapper.
Indeed, I was doing this in the test:
ps -eo pid,ppid,pgid,comm > /tmp/ps.txt my_pid=$$
echo "dd_pid = $dd_pid mypid = $my_pid" >> /tmp/ps.txt kill -9 $dd_pid
wait $dd_pid
And was noticing that the ps.txt file had:
23467 937 23467 check
...
23840 23467 23467 213
...
24034 23840 23467 213
24039 24034 23467 dd
...dd_pid = 24034 mypid = 23840
So dd_pid matched a bash process running the test, which is a child of the bash process that invoked dd.
Before digging further I saw your reply and checked that common/rc provides a function named dd() which is a wrapper to dd and it invokes dd twice, whence you needed killall.
Interesting, wasn't aware of that wrapper.
Thanks.
Quoted 66 lines
Thanks,
QuQuoted 61 lines
Quoted 16 lines
tests/btrfs/213 line 58
Quoted 13 lines
tests/btrfs/213 new file +11
-0+wait $dd_pid + +# Now balance should take at least $runtime seconds, we can cancel it at +# $runtime/2 to ensure a success cancel. +$BTRFS_UTIL_PROG balance start -d --bg "$SCRATCH_MNT" +sleep $(($runtime / 2)) +$BTRFS_UTIL_PROG balance cancel "$SCRATCH_MNT" + +# Now check if we can finish relocating metadata, which should finish very +# quickly +$BTRFS_UTIL_PROG balance start -m "$SCRATCH_MNT" >> $seqres.fullWhy redirect this one to $seqres.full and not the other balance? What kind of useful information it provides?
Not really much, just an indicator to show that the balance finishes as expected.
And we don't want to output it golden output, as mkfs change may create more metadata chunks and cause difference.For other ones, like the one to be canceled, we don't really care that much.
Thanks,
QuQuoted 34 lines
Quoted 20 lines
tests/btrfs/213 new file +6
-0+ +echo "Silence is golden" + +# success, all done +status=0 +exittests/btrfs/213.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 213 +Silence is goldentests/btrfs/group +0
-0tests/btrfs/group line 218
Quoted 4 lines
tests/btrfs/group +1
-0@@ -215,3 +215,4 @@ 210 auto quick qgroup snapshot 211 auto quick log prealloc 212 auto balance dangerous +213 auto fast balance dangerousfast -> quick
Thanks.
Quoted 3 lines
--
2.26.2
Signature · 3 lines
Filipe David Manana, “Whether you think you can, or you think you can't — you're right.”