generic: add _require_odirect to generic/113 and generic/214
[xfstests-dev.git] / tests / generic / 244
1 #! /bin/bash
2 # FS QA Test 244
3 #
4 # test out "sparse" quota ids retrieved by Q_GETNEXTQUOTA
5 #
6 # Designed to use the new Q_GETNEXTQUOTA quotactl
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2016 Red Hat, Inc.  All Rights Reserved.
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
14 #
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 #-----------------------------------------------------------------------
24 #
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37         cat $tmp.IDs >> $seqres.full
38         cd /
39         rm -f $tmp.*
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45 . ./common/quota
46
47 # remove previous $seqres.full before test
48 rm -f $seqres.full
49
50 # real QA test starts here
51
52 _supported_fs generic
53 _supported_os Linux
54 _require_quota
55 _require_scratch
56
57 scratch_unmount 2>/dev/null
58 _scratch_mkfs >> $seqres.full 2>&1
59 _scratch_mount "-o usrquota,grpquota"
60 quotacheck -u -g $SCRATCH_MNT 2>/dev/null
61 quotaon $SCRATCH_MNT 2>/dev/null
62 _scratch_unmount
63
64 TYPES="u g"
65 MOUNT_OPTIONS="-o usrquota,grpquota"
66
67 _qmount
68 quotaon $SCRATCH_MNT 2>/dev/null
69
70 # Ok, do we even have GETNEXTQUOTA?  Querying ID 0 should work.
71 $here/src/test-nextquota -i 0 -u -d $SCRATCH_DEV &> $seqres.full || \
72         _notrun "No GETNEXTQUOTA support"
73
74 echo "Launch all quotas"
75
76 # Ideally we'd carefully test edge conditions of "sparse"
77 # quota ids at beginnings and ends of otherwise empty disk
78 # blocks, etc, but that's pretty fs-specific.
79 # So just spray a bunch of random IDs into quota, and make
80 # sure we get them all back.
81
82 ITERATIONS=100
83
84 # A few extra on the off chance we get dups
85 for I in `seq 1 $(($ITERATIONS+10))`; do
86         ID=`od -N 4 -t uL -An /dev/urandom | tr -d " "`
87         echo $ID >> $tmp.1
88 done
89
90 # sort & uniq to remove dups & facilitate reading them back
91 # On the off chance we got ID 0, remove it.
92 sort -n $tmp.1 | uniq | head -n ${ITERATIONS} | grep -vw 0 > $tmp.IDs
93
94 # Populate a bunch of random quotas on the filesystem:
95 for TYPE in u g; do
96         for ID in `cat $tmp.IDs`; do
97                 setquota -${TYPE} $ID $ID $ID $ID $ID $SCRATCH_MNT
98                 touch ${SCRATCH_MNT}/${ID}
99                 chown ${ID} ${SCRATCH_MNT}/${ID}
100         done
101 done
102
103 # remount just for kicks, make sure we get it off disk
104 _scratch_unmount
105 _qmount
106 quotaon $SCRATCH_MNT 2>/dev/null
107
108 # Read them back by iterating based on quotas returned.
109 # This should match what we set, even if we don't directly
110 # ask for each exact id, but just ask for "next" id after
111 # each one we got back last.
112 for TYPE in u g; do
113         # root is always there but not in our random IDs; start at 1
114         NEXT=1
115         for ID in `cat $tmp.IDs`; do
116                 echo "Trying ID $NEXT expecting $ID" >> $seqres.full
117                 Q=`$here/src/test-nextquota -i $NEXT -${TYPE} -d $SCRATCH_DEV` \
118                          || _fail "test-nextquota failed: $Q"
119                 echo $Q >> $seqres.full
120                 # ID and its inode limits should match
121                 echo "$Q" | grep -qw ${ID} || _fail "Didn't get id $ID"
122                 # Get the ID returned from the test
123                 NEXT=`echo "$Q" | grep ^id | awk '{print $NF}' | head -n 1`
124                 # Advance that ID by one, and ask for another search
125                 let NEXT=NEXT+1
126         done
127 done
128
129 # success, all done
130 status=0
131 exit