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 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
25 # get standard environment, filters and checks
29 # real QA test starts here
34 _require_btrfs_qgroup_report
36 # Use big blocksize to ensure there is still enough space left for metadata
38 BLOCKSIZE=$(( 2 * 1024 * 1024 )) # 2M block size
39 FILESIZE=$(( 128 * 1024 * 1024 )) # 128M file size
43 _scratch_mkfs >> $seqres.full 2>&1
45 _require_fs_space $SCRATCH_MNT $(($FILESIZE * 2 / 1024))
47 _run_btrfs_util_prog quota enable $SCRATCH_MNT
48 _run_btrfs_util_prog qgroup limit $FILESIZE 5 $SCRATCH_MNT
50 # loop 5 times without sync to ensure reserved space leak will happen
51 for i in `seq 1 5`; do
52 # Use 1/4 of the file size, to ensure even commit is trigger by
53 # dirty page threshold or commit interval, we should still be
54 # able to continue write
55 $XFS_IO_PROG -f -c "pwrite -b $BLOCKSIZE 0 $(($FILESIZE / 4))" \
56 $SCRATCH_MNT/foo | _filter_xfs_io
59 # Sync to make sure all the dirty pages are written to disk, which should
60 # free all the reserved space
63 # remove the file and sync, to ensure all quota space freed
67 # We should be able to write $FILESIZE - $BLOCKSIZE data now
68 $XFS_IO_PROG -f -c "pwrite -b $BLOCKSIZE 0 $(($FILESIZE - $BLOCKSIZE))" \
69 $SCRATCH_MNT/foo | _filter_xfs_io