2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Fujitsu. All Rights Reserved.
7 # Check for qgroup reserved space leaks caused by re-writing dirty ranges
8 # This bug has been present in btrfs qgroup for a long time
11 _begin_fstest auto quick qgroup limit
13 # Import common functions.
16 # real QA test starts here
20 _require_btrfs_qgroup_report
22 # Use big blocksize to ensure there is still enough space left for metadata
24 BLOCKSIZE=$(( 2 * 1024 * 1024 )) # 2M block size
25 FILESIZE=$(( 128 * 1024 * 1024 )) # 128M file size
27 _scratch_mkfs >> $seqres.full 2>&1
29 _require_fs_space $SCRATCH_MNT $(($FILESIZE * 2 / 1024))
31 _run_btrfs_util_prog quota enable $SCRATCH_MNT
32 _run_btrfs_util_prog qgroup limit $FILESIZE 5 $SCRATCH_MNT
34 # loop 5 times without sync to ensure reserved space leak will happen
35 for i in `seq 1 5`; do
36 # Use 1/4 of the file size, to ensure even commit is trigger by
37 # dirty page threshold or commit interval, we should still be
38 # able to continue write
39 $XFS_IO_PROG -f -c "pwrite -b $BLOCKSIZE 0 $(($FILESIZE / 4))" \
40 $SCRATCH_MNT/foo | _filter_xfs_io
43 # Sync to make sure all the dirty pages are written to disk, which should
44 # free all the reserved space
47 # remove the file and sync, to ensure all quota space freed
51 # We should be able to write $FILESIZE - $BLOCKSIZE data now
52 $XFS_IO_PROG -f -c "pwrite -b $BLOCKSIZE 0 $(($FILESIZE - $BLOCKSIZE))" \
53 $SCRATCH_MNT/foo | _filter_xfs_io