btrfs: cleanup tests 004, 007, 022 and 025
[xfstests-dev.git] / tests / btrfs / 022
1 #! /bin/bash
2 # FS QA Test No. 022
3 #
4 # Test the basic functionality of qgroups
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2013 Fusion IO.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #-----------------------------------------------------------------------
22 #
23
24 seq=`basename $0`
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
27
28 here=`pwd`
29 tmp=/tmp/$$
30 status=1        # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
32
33 _cleanup()
34 {
35     cd /
36     rm -f $tmp.*
37 }
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42
43 _supported_fs btrfs
44 _supported_os Linux
45 _require_scratch
46
47 rm -f $seqres.full
48
49 # Test to make sure we can actually turn it on and it makes sense
50 _basic_test()
51 {
52         _run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
53         _run_btrfs_util_prog quota enable $SCRATCH_MNT/a
54         subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
55         $BTRFS_UTIL_PROG qgroup show $SCRATCH_MNT | grep $subvolid >> \
56                 $seqres.full 2>&1
57         [ $? -eq 0 ] || _fail "couldn't find our subvols quota group"
58         run_check $FSSTRESS_PROG -d $SCRATCH_MNT/a -w -p 1 -n 2000 \
59                 $FSSTRESS_AVOID
60         _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT/a \
61                 $SCRATCH_MNT/b
62
63         # the shared values of both the original subvol and snapshot should
64         # match
65         a_shared=$($BTRFS_UTIL_PROG qgroup show $SCRATCH_MNT | grep $subvolid)
66         a_shared=$(echo $a_shared | awk '{ print $2 }')
67         subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)
68         b_shared=$($BTRFS_UTIL_PROG qgroup show $SCRATCH_MNT | grep $subvolid)
69         b_shared=$(echo $b_shared | awk '{ print $2 }')
70         [ $b_shared -eq $a_shared ] || _fail "shared values don't match"
71 }
72
73 #enable quotas, do some work, check our values and then rescan and make sure we
74 #come up with the same answer
75 _rescan_test()
76 {
77         # first with a blank subvol
78         _run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
79         _run_btrfs_util_prog quota enable $SCRATCH_MNT/a
80         subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
81         run_check $FSSTRESS_PROG -d $SCRATCH_MNT/a -w -p 1 -n 2000 \
82                 $FSSTRESS_AVOID
83         sync
84         output=$($BTRFS_UTIL_PROG qgroup show $SCRATCH_MNT | grep $subvolid)
85         echo $output >> $seqres.full
86         refer=$(echo $output | awk '{ print $2 }')
87         excl=$(echo $output | awk '{ print $3 }')
88         _run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
89         output=$($BTRFS_UTIL_PROG qgroup show $SCRATCH_MNT | grep $subvolid)
90         echo $output >> $seqres.full
91         [ $refer -eq $(echo $output | awk '{ print $2 }') ] || \
92                 _fail "reference values don't match after rescan"
93         [ $excl -eq $(echo $output | awk '{ print $3 }') ] || \
94                 _fail "exclusive values don't match after rescan"
95 }
96
97 #basic exceed limit testing
98 _limit_test_exceed()
99 {
100         _run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
101         _run_btrfs_util_prog quota enable $SCRATCH_MNT
102         subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
103         _run_btrfs_util_prog qgroup limit 5M 0/$subvolid $SCRATCH_MNT
104         dd if=/dev/urandom of=$SCRATCH_MNT/a/file bs=10M count=1 >> \
105                 $seqres.full 2>&1
106         [ $? -ne 0 ] || _fail "quota should have limited us"
107 }
108
109 #basic noexceed limit testing
110 _limit_test_noexceed()
111 {
112         _run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
113         _run_btrfs_util_prog quota enable $SCRATCH_MNT
114         subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
115         _run_btrfs_util_prog qgroup limit 5M 0/$subvolid $SCRATCH_MNT
116         dd if=/dev/urandom of=$SCRATCH_MNT/a/file bs=4M count=1 >> \
117                 $seqres.full 2>&1
118         [ $? -eq 0 ] || _fail "should have been allowed to write"
119 }
120
121 _scratch_mkfs > /dev/null 2>&1
122 _scratch_mount
123 _basic_test
124 _scratch_unmount
125
126 _scratch_mkfs > /dev/null 2>&1
127 _scratch_mount
128 _rescan_test
129 _scratch_unmount
130
131 _scratch_mkfs > /dev/null 2>&1
132 _scratch_mount
133 _limit_test_exceed
134 _scratch_unmount
135
136 _scratch_mkfs > /dev/null 2>&1
137 _scratch_mount
138 _limit_test_noexceed
139
140 # success, all done
141 echo "Silence is golden"
142 status=0
143 exit