btrfs: check qgroup doesn't crash when beyond limit
[xfstests-dev.git] / tests / btrfs / 042
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Fujitsu.  All Rights Reserved.
4 #
5 # FS QA Test No. 042
6 #
7 # Test the basic functionality of Quota groups
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27
28 _supported_fs btrfs
29 _require_scratch
30 _require_btrfs_qgroup_report
31
32 rm -f $seqres.full
33
34 run_check _scratch_mkfs
35 _scratch_mount
36
37 LIMIT_SIZE=$((10 * 1024 * 1024))
38
39 _run_btrfs_util_prog quota enable $SCRATCH_MNT
40 _run_btrfs_util_prog qgroup create 1/1 $SCRATCH_MNT
41 _run_btrfs_util_prog qgroup limit $LIMIT_SIZE 1/1 $SCRATCH_MNT
42
43 for i in `seq 10 -1 1`; do
44         #add newly created subvolume qgroup to it's parent qgroup
45         _run_btrfs_util_prog subvolume create -i 1/1 \
46                 $SCRATCH_MNT/subv_$i
47 done
48
49 #try to write data into every subvolume
50 for i in `seq 10 -1 1`; do
51         $XFS_IO_PROG -f -d -c 'pwrite -b 4k 0 10m' $SCRATCH_MNT/subv_$i/data \
52                 >> /dev/null 2>&1 &
53 done
54
55 wait
56 _run_btrfs_util_prog filesystem sync $SCRATCH_MNT \
57         >>$seqres.full 2>&1
58
59 total_written=0
60 #calculate every subvolume's data.
61 for i in `seq 10 -1 1`; do
62         #we may fail to create the file, skip this subvolume
63         test -f $SCRATCH_MNT/subv_$i || continue
64
65         filesize=`du -b $SCRATCH_MNT/subv_$i/data | $AWK_PROG '{print $1}'`
66         if [ $filesize -gt $LIMIT_SIZE ];then
67                 _fail "subv_$i/data size should be less than $LIMIT_SIZE"
68         fi
69         total_written=$(($total_written+$filesize))
70 done
71
72 #check if total written exceeds limit
73 if [ $total_written -gt $LIMIT_SIZE ];then
74         _fail "total written should be less than $LIMIT_SIZE"
75 fi
76
77 # success, all done
78 echo "Silence is golden"
79 status=0
80 exit