btrfs: Verify falloc on multiple holes won't leak qgroup reserved data space
authorQu Wenruo <wqu@suse.com>
Sun, 15 Sep 2019 07:22:30 +0000 (15:22 +0800)
committerEryu Guan <guaneryu@gmail.com>
Sun, 15 Sep 2019 13:13:55 +0000 (21:13 +0800)
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"

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
tests/btrfs/193 [new file with mode: 0755]
tests/btrfs/193.out [new file with mode: 0644]
tests/btrfs/group

diff --git a/tests/btrfs/193 b/tests/btrfs/193
new file mode 100755 (executable)
index 0000000..16b7650
--- /dev/null
@@ -0,0 +1,69 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
+#
+# FS QA Test btrfs/193
+#
+# 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 -f "$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
diff --git a/tests/btrfs/193.out b/tests/btrfs/193.out
new file mode 100644 (file)
index 0000000..095c1fc
--- /dev/null
@@ -0,0 +1,8 @@
+QA output created by 193
+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)
index cab10d19501bf351a7863638ba0f1f0028f252c8..b92cb12ca66fb8e78a62249762a0c38244859126 100644 (file)
 190 auto quick replay balance qgroup
 191 auto quick send dedupe
 192 auto replay snapshot stress
 190 auto quick replay balance qgroup
 191 auto quick send dedupe
 192 auto replay snapshot stress
+193 auto quick qgroup enospc limit