4 # test out "sparse" quota ids retrieved by Q_GETNEXTQUOTA
6 # Designed to use the new Q_GETNEXTQUOTA quotactl
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2016 Red Hat, Inc. All Rights Reserved.
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.
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.
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 #-----------------------------------------------------------------------
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
32 status=1 # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
37 cat $tmp.IDs >> $seqres.full
42 # get standard environment, filters and checks
47 # remove previous $seqres.full before test
50 # real QA test starts here
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
65 MOUNT_OPTIONS="-o usrquota,grpquota"
68 quotaon $SCRATCH_MNT 2>/dev/null
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"
74 echo "Launch all quotas"
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.
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 " "`
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
94 # Populate a bunch of random quotas on the filesystem:
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}
103 # remount just for kicks, make sure we get it off disk
106 quotaon $SCRATCH_MNT 2>/dev/null
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.
113 # root is always there but not in our random IDs; start at 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