btrfs: fsync after hole punching with no-holes mode
[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 _require_btrfs_qgroup_report
47
48 rm -f $seqres.full
49
50 # Test to make sure we can actually turn it on and it makes sense
51 _basic_test()
52 {
53         _run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
54         _run_btrfs_util_prog quota enable $SCRATCH_MNT/a
55         _run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
56         subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
57         $BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep $subvolid >> \
58                 $seqres.full 2>&1
59         [ $? -eq 0 ] || _fail "couldn't find our subvols quota group"
60         run_check $FSSTRESS_PROG -d $SCRATCH_MNT/a -w -p 1 -n 2000 \
61                 $FSSTRESS_AVOID
62         _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT/a \
63                 $SCRATCH_MNT/b
64
65         # the shared values of both the original subvol and snapshot should
66         # match
67         a_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep $subvolid)
68         a_shared=$(echo $a_shared | awk '{ print $2 }')
69         subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)
70         b_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep $subvolid)
71         b_shared=$(echo $b_shared | awk '{ print $2 }')
72         [ $b_shared -eq $a_shared ] || _fail "shared values don't match"
73 }
74
75 #enable quotas, do some work, check our values and then rescan and make sure we
76 #come up with the same answer
77 _rescan_test()
78 {
79         # first with a blank subvol
80         _run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
81         _run_btrfs_util_prog quota enable $SCRATCH_MNT/a
82         subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
83         run_check $FSSTRESS_PROG -d $SCRATCH_MNT/a -w -p 1 -n 2000 \
84                 $FSSTRESS_AVOID
85         sync
86         output=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep $subvolid)
87         echo $output >> $seqres.full
88         refer=$(echo $output | awk '{ print $2 }')
89         excl=$(echo $output | awk '{ print $3 }')
90         _run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
91         output=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep $subvolid)
92         echo $output >> $seqres.full
93         [ $refer -eq $(echo $output | awk '{ print $2 }') ] || \
94                 _fail "reference values don't match after rescan"
95         [ $excl -eq $(echo $output | awk '{ print $3 }') ] || \
96                 _fail "exclusive values don't match after rescan"
97 }
98
99 #basic exceed limit testing
100 _limit_test_exceed()
101 {
102         _run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
103         _run_btrfs_util_prog quota enable $SCRATCH_MNT
104         subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
105         _run_btrfs_util_prog qgroup limit 5M 0/$subvolid $SCRATCH_MNT
106         _ddt of=$SCRATCH_MNT/a/file bs=10M count=1 >> $seqres.full 2>&1
107         [ $? -ne 0 ] || _fail "quota should have limited us"
108 }
109
110 #basic noexceed limit testing
111 _limit_test_noexceed()
112 {
113         _run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
114         _run_btrfs_util_prog quota enable $SCRATCH_MNT
115         subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
116         _run_btrfs_util_prog qgroup limit 5M 0/$subvolid $SCRATCH_MNT
117         _ddt of=$SCRATCH_MNT/a/file bs=4M count=1 >> $seqres.full 2>&1
118         [ $? -eq 0 ] || _fail "should have been allowed to write"
119 }
120
121 units=`_btrfs_qgroup_units`
122
123 _scratch_mkfs > /dev/null 2>&1
124 _scratch_mount
125 _basic_test
126 _scratch_unmount
127 _check_scratch_fs
128
129 _scratch_mkfs > /dev/null 2>&1
130 _scratch_mount
131 _rescan_test
132 _scratch_unmount
133 _check_scratch_fs
134
135 _scratch_mkfs > /dev/null 2>&1
136 _scratch_mount
137 _limit_test_exceed
138 _scratch_unmount
139 _check_scratch_fs
140
141 _scratch_mkfs > /dev/null 2>&1
142 _scratch_mount
143 _limit_test_noexceed
144
145 # success, all done
146 echo "Silence is golden"
147 status=0
148 exit