btrfs/057: Fix false alerts due to orphan files
[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 _supported_os Linux
30 _require_scratch
31 _require_btrfs_qgroup_report
32
33 rm -f $seqres.full
34
35 run_check _scratch_mkfs
36 _scratch_mount
37
38 LIMIT_SIZE=$((10 * 1024 * 1024))
39
40 _run_btrfs_util_prog quota enable $SCRATCH_MNT
41 _run_btrfs_util_prog qgroup create 1/1 $SCRATCH_MNT
42 _run_btrfs_util_prog qgroup limit $LIMIT_SIZE 1/1 $SCRATCH_MNT
43
44 for i in `seq 10 -1 1`; do
45         #add newly created subvolume qgroup to it's parent qgroup
46         _run_btrfs_util_prog subvolume create -i 1/1 \
47                 $SCRATCH_MNT/subv_$i
48 done
49
50 #try to write data into every subvolume
51 for i in `seq 10 -1 1`; do
52         $XFS_IO_PROG -f -d -c 'pwrite -b 4k 0 10m' $SCRATCH_MNT/subv_$i/data \
53                 >> /dev/null 2>&1 &
54 done
55
56 wait
57 _run_btrfs_util_prog filesystem sync $SCRATCH_MNT \
58         >>$seqres.full 2>&1
59
60 total_written=0
61 #calculate every subvolume's data.
62 for i in `seq 10 -1 1`; do
63         #we may fail to create the file, skip this subvolume
64         test -f $SCRATCH_MNT/subv_$i || continue
65
66         filesize=`du -b $SCRATCH_MNT/subv_$i/data | $AWK_PROG '{print $1}'`
67         if [ $filesize -gt $LIMIT_SIZE ];then
68                 _fail "subv_$i/data size should be less than $LIMIT_SIZE"
69         fi
70         total_written=$(($total_written+$filesize))
71 done
72
73 #check if total written exceeds limit
74 if [ $total_written -gt $LIMIT_SIZE ];then
75         _fail "total written should be less than $LIMIT_SIZE"
76 fi
77
78 # success, all done
79 echo "Silence is golden"
80 status=0
81 exit