btrfs/099: use the qgroupid for qgroup limit
[xfstests-dev.git] / tests / btrfs / 099
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Fujitsu. All Rights Reserved.
4 #
5 # FS QA Test 099
6 #
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
9 #
10 . ./common/preamble
11 _begin_fstest auto quick qgroup limit
12
13 # Import common functions.
14 . ./common/filter
15
16 # real QA test starts here
17
18 _supported_fs btrfs
19 _require_scratch
20 _require_btrfs_qgroup_report
21
22 # Use big blocksize to ensure there is still enough space left for metadata
23 # space reserve.
24 BLOCKSIZE=$(( 2 * 1024 * 1024 )) # 2M block size
25 FILESIZE=$(( 128 * 1024 * 1024 )) # 128M file size
26
27 _scratch_mkfs >> $seqres.full 2>&1
28 _scratch_mount
29 _require_fs_space $SCRATCH_MNT $(($FILESIZE * 2 / 1024))
30
31 _run_btrfs_util_prog quota enable $SCRATCH_MNT
32 _run_btrfs_util_prog qgroup limit $FILESIZE 0/5 $SCRATCH_MNT
33
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
41 done
42
43 # Sync to make sure all the dirty pages are written to disk, which should
44 # free all the reserved space
45 sync
46
47 # remove the file and sync, to ensure all quota space freed
48 rm $SCRATCH_MNT/foo
49 sync
50
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
54
55 # success, all done
56 status=0
57 exit