fstests: btrfs: Verify falloc on multiple holes won't cause qgroup reserved data space leak
PATCH v2 1/1 fstests: btrfs: Verify falloc on multiple holes won't cause qgroup reserved data space leak
Add a test case where falloc is called on multiple holes with qgroup enabled.
This can cause qgroup reserved data space leak and false EDQUOT error even we're not reaching the limit.
The fix is titled:
"btrfs: qgroup: Fix the wrong target io_tree when freeing
reserved data space"
---
changelog:
v2:
- Remove the unnecessary loop
The loop itself is just to ensure we leak as much space as possible. However even one loop is already enough to fail the final verification write, so remove the loop and modify the golden output.
--- tests/btrfs/192 | 70 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/192.out | 8 ++++++ tests/btrfs/group | 1 + 3 files changed, 79 insertions(+) create mode 100755 tests/btrfs/192 create mode 100644 tests/btrfs/192.out
tests/btrfs/192 new file +70 -0
@@ -0,0 +1,70 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved. +# +# FS QA Test 192 +# +# Test if btrfs is going to leak qgroup reserved data space when +# falloc on multiple holes fails. +# The fix is titled: +# "btrfs: qgroup: Fix the wrong target io_tree when freeing reserved data space" +# +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 + +# real QA test starts here + +# Modify as appropriate. +_supported_fs btrfs +_supported_os Linux +_require_scratch +_require_xfs_io_command falloc + +_scratch_mkfs > /dev/null +_scratch_mount + +$BTRFS_UTIL_PROG quota enable "$SCRATCH_MNT" > /dev/null +$BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null +$BTRFS_UTIL_PROG qgroup limit -e 256M "$SCRATCH_MNT" + +# Create a file with the following layout: +# 0 128M 256M 384M +# | Hole |4K| Hole |4K| Hole | +# The total hole size will be 384M - 8k +truncate -s 384m "$SCRATCH_MNT/file" +$XFS_IO_PROG -c "pwrite 128m 4k" -c "pwrite 256m 4k" \ + "$SCRATCH_MNT/file" | _filter_xfs_io + +# Falloc 0~384M range, it's going to fail due to the qgroup limit +$XFS_IO_PROG -c "falloc 0 384m" "$SCRATCH_MNT/file" |\ + _filter_xfs_io_error +rm "$SCRATCH_MNT/file" + +# Ensure above delete reaches disk and free some space +sync + +# We should be able to write at least 3/4 of the limit +$XFS_IO_PROG -f -c "pwrite 0 192m" "$SCRATCH_MNT/file" | _filter_xfs_io + +# success, all done +status=0 +exit
tests/btrfs/192.out new file +8 -0
@@ -0,0 +1,8 @@ +QA output created by 192 +wrote 4096/4096 bytes at offset 134217728 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 4096/4096 bytes at offset 268435456 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +fallocate: Disk quota exceeded +wrote 201326592/201326592 bytes at offset 0 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
tests/btrfs/group +1 -0
@@ -194,3 +194,4 @@ 189 auto quick send clone 190 auto quick replay balance qgroup 191 auto quick send dedupe +192 auto qgroup fast enospc limit
Signature · 1 line
2.22.0
Quoted 82 lines · Qu Wenruo
Add a test case where falloc is called on multiple holes with qgroup enabled.
This can cause qgroup reserved data space leak and false EDQUOT error even we're not reaching the limit.
The fix is titled:
"btrfs: qgroup: Fix the wrong targetio_treewhen freeing
reserved data space"Signed-off-by Qu Wenruo <[email protected]>---
changelog:
v2:
- Remove the unnecessary loop
The loop itself is just to ensure we leak as much space as possible. However even one loop is already enough to fail the final verification write, so remove the loop and modify the golden output.--- tests/btrfs/192 | 70 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/192.out | 8 ++++++ tests/btrfs/group | 1 + 3 files changed, 79 insertions(+) create mode 100755 tests/btrfs/192 create mode 100644 tests/btrfs/192.outtests/btrfs/192 new file +49
-0@@ -0,0 +1,70 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved. +# +# FS QA Test 192 +# +# Test if btrfs is going to leak qgroup reserved data space when +# falloc on multiple holes fails. +# The fix is titled: +# "btrfs: qgroup: Fix the wrong target io_tree when freeing reserved data space" +# +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 + +# real QA test starts here + +# Modify as appropriate. +_supported_fs btrfs +_supported_os Linux +_require_scratch +_require_xfs_io_command falloc + +_scratch_mkfs > /dev/null +_scratch_mount + +$BTRFS_UTIL_PROG quota enable "$SCRATCH_MNT" > /dev/null +$BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null +$BTRFS_UTIL_PROG qgroup limit -e 256M "$SCRATCH_MNT" + +# Create a file with the following layout:
tests/btrfs/192 line 59
Quoted 10 lines
tests/btrfs/192 new file +10
-0+# 0 128M 256M 384M +# | Hole |4K| Hole |4K| Hole | +# The total hole size will be 384M - 8k +truncate -s 384m "$SCRATCH_MNT/file" +$XFS_IO_PROG -c "pwrite 128m 4k" -c "pwrite 256m 4k" \ + "$SCRATCH_MNT/file" | _filter_xfs_io + +# Falloc 0~384M range, it's going to fail due to the qgroup limit +$XFS_IO_PROG -c "falloc 0 384m" "$SCRATCH_MNT/file" |\ + _filter_xfs_io_error
This can be in a single line, as it doesn't go beyond 80 characters. It doesn't hurt, but the use of the error filter isn't necessary here at the moment.
tests/btrfs/192 line 60
Quoted 1 line
tests/btrfs/192 new file +1
-0+rm "$SCRATCH_MNT/file"
rm -f, in case one has " alias rm='rm -i' " in its environment.
Quoted 29 lines
tests/btrfs/192 new file +10
-0+ +# Ensure above delete reaches disk and free some space +sync + +# We should be able to write at least 3/4 of the limit +$XFS_IO_PROG -f -c "pwrite 0 192m" "$SCRATCH_MNT/file" | _filter_xfs_io + +# success, all done +status=0 +exittests/btrfs/192.out new file +8
-0@@ -0,0 +1,8 @@ +QA output created by 192 +wrote 4096/4096 bytes at offset 134217728 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 4096/4096 bytes at offset 268435456 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +fallocate: Disk quota exceeded +wrote 201326592/201326592 bytes at offset 0 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)tests/btrfs/group +0
-0
tests/btrfs/group line 197
Quoted 4 lines
tests/btrfs/group +1
-0@@ -194,3 +194,4 @@ 189 auto quick send clone 190 auto quick replay balance qgroup 191 auto quick send dedupe +192 auto qgroup fast enospc limit
fast -> quick?
(we don't have a group named "fast" yet)
Anyway, small things that can be fixed at commit time.
Thanks
Quoted 3 lines
--
2.22.0
Signature · 3 lines
Filipe David Manana, “Whether you think you can, or you think you can't — you're right.”
Quoted 130 lines · Filipe Manana
Quoted 82 lines · Qu Wenruo
Add a test case where falloc is called on multiple holes with qgroup enabled.
This can cause qgroup reserved data space leak and false EDQUOT error even we're not reaching the limit.
The fix is titled:
"btrfs: qgroup: Fix the wrong targetio_treewhen freeing
reserved data space"Signed-off-by Qu Wenruo <[email protected]>---
changelog:
v2:
- Remove the unnecessary loop
The loop itself is just to ensure we leak as much space as possible. However even one loop is already enough to fail the final verification write, so remove the loop and modify the golden output.--- tests/btrfs/192 | 70 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/192.out | 8 ++++++ tests/btrfs/group | 1 + 3 files changed, 79 insertions(+) create mode 100755 tests/btrfs/192 create mode 100644 tests/btrfs/192.outtests/btrfs/192 new file +49
-0@@ -0,0 +1,70 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved. +# +# FS QA Test 192 +# +# Test if btrfs is going to leak qgroup reserved data space when +# falloc on multiple holes fails. +# The fix is titled: +# "btrfs: qgroup: Fix the wrong target io_tree when freeing reserved data space" +# +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 + +# real QA test starts here + +# Modify as appropriate. +_supported_fs btrfs +_supported_os Linux +_require_scratch +_require_xfs_io_command falloc + +_scratch_mkfs > /dev/null +_scratch_mount + +$BTRFS_UTIL_PROG quota enable "$SCRATCH_MNT" > /dev/null +$BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null +$BTRFS_UTIL_PROG qgroup limit -e 256M "$SCRATCH_MNT" + +# Create a file with the following layout:tests/btrfs/192 line 59
Quoted 10 lines
tests/btrfs/192 new file +10
-0+# 0 128M 256M 384M +# | Hole |4K| Hole |4K| Hole | +# The total hole size will be 384M - 8k +truncate -s 384m "$SCRATCH_MNT/file" +$XFS_IO_PROG -c "pwrite 128m 4k" -c "pwrite 256m 4k" \ + "$SCRATCH_MNT/file" | _filter_xfs_io + +# Falloc 0~384M range, it's going to fail due to the qgroup limit +$XFS_IO_PROG -c "falloc 0 384m" "$SCRATCH_MNT/file" |\ + _filter_xfs_io_errorThis can be in a single line, as it doesn't go beyond 80 characters. It doesn't hurt, but the use of the error filter isn't necessary here at the moment.
tests/btrfs/192 line 60
Quoted 1 line
tests/btrfs/192 new file +1
-0+rm "$SCRATCH_MNT/file"rm -f, in case one has " alias rm='rm -i' " in its environment.
Quoted 28 lines
tests/btrfs/192 new file +10
-0+ +# Ensure above delete reaches disk and free some space +sync + +# We should be able to write at least 3/4 of the limit +$XFS_IO_PROG -f -c "pwrite 0 192m" "$SCRATCH_MNT/file" | _filter_xfs_io + +# success, all done +status=0 +exittests/btrfs/192.out new file +8
-0@@ -0,0 +1,8 @@ +QA output created by 192 +wrote 4096/4096 bytes at offset 134217728 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 4096/4096 bytes at offset 268435456 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +fallocate: Disk quota exceeded +wrote 201326592/201326592 bytes at offset 0 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)tests/btrfs/group +0
-0
Quoted 8 lines
tests/btrfs/group line 197
Quoted 5 lines
tests/btrfs/group +1
-0@@ -194,3 +194,4 @@ 189 auto quick send clone 190 auto quick replay balance qgroup 191 auto quick send dedupe +192 auto qgroup fast enospc limitfast -> quick?
(we don't have a group named "fast" yet)
Yeah, I've changed it to 'quick' on commit. And I can fix your other comments on commit as well.
Quoted 4 lines
Anyway, small things that can be fixed at commit time.
Reviewed-by Filipe Manana <[email protected]>
Thanks for the review!
Eryu