xfs: test what happens when we reset the root dir and it has xattrs
[xfstests-dev.git] / tests / xfs / 299
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 299
6 #
7 # Exercises basic XFS quota functionality, with all 3 quotas together
8 #       uquota, gquota, pquota
9 #       uqnoenforce, gqnoenforce, pqnoenforce
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18
19 # get standard environment, filters and checks
20 . ./common/rc
21 . ./common/filter
22 . ./common/quota
23
24 _cleanup()
25 {
26         cd /
27         _scratch_unmount 2>/dev/null
28         rm -f $tmp.*
29 }
30 trap "_cleanup; exit \$status" 0 1 2 3 15
31
32 # real QA test starts here
33 _supported_fs xfs
34
35 cp /dev/null $seqres.full
36 chmod a+rwx $seqres.full        # arbitrary users will write here
37
38 _require_scratch
39 _require_xfs_quota
40 _require_xfs_mkfs_crc
41 _require_xfs_crc
42
43 # The actual point at which limit enforcement takes place for the
44 # hard block limit is variable depending on filesystem blocksize,
45 # and iosize.  What we want to test is that the limit is enforced
46 # (ie. blksize less than limit but not unduly less - ~85% is kind)
47 # nowadays we actually get much closer to the limit before EDQUOT.
48 #
49 _filter_and_check_blks()
50 {
51         perl -npe '
52                 if (/^\#'$id'\s+(\d+)/ && '$enforce') {
53                         $maximum = '$bhard';
54                         $minimum = '$bhard' * 85/100;
55                         $used = $1 * 1024;
56                         if (($used < $minimum || $used > $maximum) && '$noextsz') {
57                                 printf(" URK %d: %d is out of range! [%d,%d]\n",
58                                         '$id', $used, $minimum, $maximum);
59                         }
60                         s/^(\#'$id'\s+)(\d+)/\1 =OK=/g;
61                 }
62         ' | _filter_quota_report
63 }
64
65 _exercise()
66 {
67
68         # Figure out whether we're doing large allocations
69         # (bail out if they're so large they stuff the test up)
70         _test_inode_flag extsz-inherit $SCRATCH_MNT
71         noextsz=$?
72         extsize=`_test_inode_extsz $SCRATCH_MNT`
73         [ $extsize -ge 512000 ] && \
74                 _notrun "Extent size hint is too large ($extsize bytes)"
75
76         _qsetup $1
77
78         echo "Using type=$type id=$id" >>$seqres.full
79
80         $XFS_QUOTA_PROG -x -c "warn -$type 65535 -d" $SCRATCH_DEV
81
82         echo
83         echo "*** report no quota settings" | tee -a $seqres.full
84         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
85                 -c "repquota -birnN -$type" $SCRATCH_DEV |
86                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
87
88         echo
89         echo "*** report initial settings" | tee -a $seqres.full
90         _file_as_id $SCRATCH_MNT/initme $id $type 1024 0
91         echo "ls -l $SCRATCH_MNT" >>$seqres.full
92         ls -l $SCRATCH_MNT >>$seqres.full
93         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
94                 -c "limit -$type bsoft=${bsoft} bhard=${bhard} $id" \
95                 -c "limit -$type isoft=$isoft ihard=$ihard $id" \
96                 $SCRATCH_DEV
97         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
98                 -c "repquota -birnN -$type" $SCRATCH_DEV |
99                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
100
101         echo
102         echo "*** push past the soft inode limit" | tee -a $seqres.full
103         _file_as_id $SCRATCH_MNT/softie1 $id $type 1024 0
104         _file_as_id $SCRATCH_MNT/softie2 $id $type 1024 0
105         _file_as_id $SCRATCH_MNT/softie3 $id $type 1024 0
106         _file_as_id $SCRATCH_MNT/softie4 $id $type 1024 0
107         _qmount
108         $XFS_QUOTA_PROG -x -c "warn -i -$type 0 $id" $SCRATCH_DEV
109         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
110                 -c "repquota -birnN -$type" $SCRATCH_DEV |
111                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
112
113         echo
114         echo "*** push past the soft block limit" | tee -a $seqres.full
115         _file_as_id $SCRATCH_MNT/softie $id $type $bsize 200
116         _qmount
117         $XFS_QUOTA_PROG -x -c "warn -i -$type 0 $id" \
118                 -c "warn -b -$type 0 $id" $SCRATCH_DEV
119         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
120                 -c "repquota -birnN -$type" $SCRATCH_DEV |
121                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
122
123         echo
124         # Note: for quota accounting (not enforcement), EDQUOT is not expected
125         echo "*** push past the hard inode limit (expect EDQUOT)" | tee -a $seqres.full
126         for i in 1 2 3 4 5 6 7 8 9 10 11 12
127         do
128                 _file_as_id $SCRATCH_MNT/hard$i $id $type 1024 0
129         done
130         _qmount
131         $XFS_QUOTA_PROG -x  -c "warn -b -$type 0 $id" \
132                 -c "warn -i -$type 0 $id" $SCRATCH_DEV
133         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
134                 -c "repquota -birnN -$type" $SCRATCH_DEV |
135                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
136
137         echo
138         # Note: for quota accounting (not enforcement), EDQUOT is not expected
139         echo "*** push past the hard block limit (expect EDQUOT)" | tee -a $seqres.full
140         _file_as_id $SCRATCH_MNT/softie $id $type $bsize 600
141         echo "ls -l $SCRATCH_MNT" >>$seqres.full
142         ls -l $SCRATCH_MNT >>$seqres.full
143         _qmount
144         $XFS_QUOTA_PROG -x -c "warn -b -$type 0 $id" $SCRATCH_DEV
145         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
146                 -c "repquota -birnN -$type" $SCRATCH_DEV |
147                 _filter_and_check_blks | LC_COLLATE=POSIX sort -ru
148
149         echo
150
151         # clean up our files so we don't pollute the next run
152         rm -f $SCRATCH_MNT/*
153
154 }
155
156 _scratch_mkfs_xfs -m crc=1 2>/dev/null | _filter_mkfs 2>$tmp.mkfs
157 cat $tmp.mkfs >>$seqres.full
158 # keep the blocksize and data size for dd later
159 . $tmp.mkfs
160
161 cat >$tmp.projects <<EOF
162 1:$SCRATCH_MNT
163 EOF
164
165 cat >$tmp.projid <<EOF
166 root:0
167 scrach:1
168 EOF
169
170 projid_file="$tmp.projid"
171
172 echo "*** user, group, and project"
173 _qmount_option "uquota,gquota,pquota"
174 _qmount
175
176 bsize=$(_get_file_block_size $SCRATCH_MNT)
177
178 bsoft=$(( 100 * $bsize ))
179 bhard=$(( 500 * $bsize ))
180 isoft=4
181 ihard=10
182
183 # non-root users need to be able to write to this filesystem
184 chmod 777 $SCRATCH_MNT
185
186 _exercise p
187 _exercise g
188 _exercise u
189
190 echo "*** unmount"
191 _scratch_unmount
192
193
194 _scratch_mkfs_xfs -m crc=1 2>/dev/null | _filter_mkfs 2>$tmp.mkfs
195 cat $tmp.mkfs >>$seqres.full
196 # keep the blocksize and data size for dd later
197 . $tmp.mkfs
198
199 echo "*** uqnoenforce, gqnoenforce, and pqnoenforce"
200 _qmount_option "uqnoenforce,gqnoenforce,pqnoenforce"
201 _qmount
202 _exercise uno
203 _exercise gno
204 _exercise pno
205
206 echo "*** unmount"
207 _scratch_unmount
208
209 # success, all done
210 status=0
211 exit