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