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
33 _require_btrfs_qgroup_report
35 # Use big blocksize to ensure there is still enough space left for metadata
37 BLOCKSIZE=$(( 2 * 1024 * 1024 )) # 2M block size
38 FILESIZE=$(( 128 * 1024 * 1024 )) # 128M file size
42 _scratch_mkfs >> $seqres.full 2>&1
44 _require_fs_space $SCRATCH_MNT $(($FILESIZE * 2 / 1024))
46 _run_btrfs_util_prog quota enable $SCRATCH_MNT
47 _run_btrfs_util_prog qgroup limit $FILESIZE 5 $SCRATCH_MNT
49 # loop 5 times without sync to ensure reserved space leak will happen
50 for i in `seq 1 5`; do
51 # Use 1/4 of the file size, to ensure even commit is trigger by
52 # dirty page threshold or commit interval, we should still be
53 # able to continue write
54 $XFS_IO_PROG -f -c "pwrite -b $BLOCKSIZE 0 $(($FILESIZE / 4))" \
55 $SCRATCH_MNT/foo | _filter_xfs_io
58 # Sync to make sure all the dirty pages are written to disk, which should
59 # free all the reserved space
62 # remove the file and sync, to ensure all quota space freed
66 # We should be able to write $FILESIZE - $BLOCKSIZE data now
67 $XFS_IO_PROG -f -c "pwrite -b $BLOCKSIZE 0 $(($FILESIZE - $BLOCKSIZE))" \
68 $SCRATCH_MNT/foo | _filter_xfs_io