btrfs: convert tests to SPDX license tags
[xfstests-dev.git] / tests / btrfs / 022
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2013 Fusion IO.  All Rights Reserved.
4 #
5 # FS QA Test No. 022
6 #
7 # Test the basic functionality of qgroups
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 # Test to make sure we can actually turn it on and it makes sense
36 _basic_test()
37 {
38         _run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
39         _run_btrfs_util_prog quota enable $SCRATCH_MNT/a
40         _run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
41         subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
42         $BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep $subvolid >> \
43                 $seqres.full 2>&1
44         [ $? -eq 0 ] || _fail "couldn't find our subvols quota group"
45         run_check $FSSTRESS_PROG -d $SCRATCH_MNT/a -w -p 1 -n 2000 \
46                 $FSSTRESS_AVOID
47         _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT/a \
48                 $SCRATCH_MNT/b
49
50         # the shared values of both the original subvol and snapshot should
51         # match
52         a_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep $subvolid)
53         a_shared=$(echo $a_shared | awk '{ print $2 }')
54         subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)
55         b_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep $subvolid)
56         b_shared=$(echo $b_shared | awk '{ print $2 }')
57         [ $b_shared -eq $a_shared ] || _fail "shared values don't match"
58 }
59
60 #enable quotas, do some work, check our values and then rescan and make sure we
61 #come up with the same answer
62 _rescan_test()
63 {
64         # first with a blank subvol
65         _run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
66         _run_btrfs_util_prog quota enable $SCRATCH_MNT/a
67         subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
68         run_check $FSSTRESS_PROG -d $SCRATCH_MNT/a -w -p 1 -n 2000 \
69                 $FSSTRESS_AVOID
70         sync
71         output=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep $subvolid)
72         echo $output >> $seqres.full
73         refer=$(echo $output | awk '{ print $2 }')
74         excl=$(echo $output | awk '{ print $3 }')
75         _run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
76         output=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep $subvolid)
77         echo $output >> $seqres.full
78         [ $refer -eq $(echo $output | awk '{ print $2 }') ] || \
79                 _fail "reference values don't match after rescan"
80         [ $excl -eq $(echo $output | awk '{ print $3 }') ] || \
81                 _fail "exclusive values don't match after rescan"
82 }
83
84 #basic exceed limit testing
85 _limit_test_exceed()
86 {
87         _run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
88         _run_btrfs_util_prog quota enable $SCRATCH_MNT
89         subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
90         _run_btrfs_util_prog qgroup limit 5M 0/$subvolid $SCRATCH_MNT
91         _ddt of=$SCRATCH_MNT/a/file bs=10M count=1 >> $seqres.full 2>&1
92         [ $? -ne 0 ] || _fail "quota should have limited us"
93 }
94
95 #basic noexceed limit testing
96 _limit_test_noexceed()
97 {
98         _run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
99         _run_btrfs_util_prog quota enable $SCRATCH_MNT
100         subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
101         _run_btrfs_util_prog qgroup limit 5M 0/$subvolid $SCRATCH_MNT
102         _ddt of=$SCRATCH_MNT/a/file bs=4M count=1 >> $seqres.full 2>&1
103         [ $? -eq 0 ] || _fail "should have been allowed to write"
104 }
105
106 units=`_btrfs_qgroup_units`
107
108 _scratch_mkfs > /dev/null 2>&1
109 _scratch_mount
110 _basic_test
111 _scratch_unmount
112 _check_scratch_fs
113
114 _scratch_mkfs > /dev/null 2>&1
115 _scratch_mount
116 _rescan_test
117 _scratch_unmount
118 _check_scratch_fs
119
120 _scratch_mkfs > /dev/null 2>&1
121 _scratch_mount
122 _limit_test_exceed
123 _scratch_unmount
124 _check_scratch_fs
125
126 _scratch_mkfs > /dev/null 2>&1
127 _scratch_mount
128 _limit_test_noexceed
129
130 # success, all done
131 echo "Silence is golden"
132 status=0
133 exit