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_mkfs >> $seqres.full 2>&1
60 MOUNT_OPTIONS="-o usrquota,grpquota"
64 echo "Launch all quotas"
66 # Ideally we'd carefully test edge conditions of "sparse"
67 # quota ids at beginnings and ends of otherwise empty disk
68 # blocks, etc, but that's pretty fs-specific.
69 # So just spray a bunch of random IDs into quota, and make
70 # sure we get them all back.
74 # A few extra on the off chance we get dups
75 for I in `seq 1 $(($ITERATIONS+10))`; do
76 ID=`od -N 4 -t uI -An /dev/urandom | tr -d " "`
80 # sort & uniq to remove dups & facilitate reading them back
81 # On the off chance we got ID 0, remove it.
82 sort -n $tmp.1 | uniq | head -n ${ITERATIONS} | grep -vw 0 > $tmp.IDs
84 # Populate a bunch of random quotas on the filesystem:
86 for ID in `cat $tmp.IDs`; do
87 setquota -${TYPE} $ID $ID $ID $ID $ID $SCRATCH_MNT
88 touch ${SCRATCH_MNT}/${ID}
89 chown ${ID} ${SCRATCH_MNT}/${ID}
93 # remount just for kicks, make sure we get it off disk
96 quotaon $SCRATCH_MNT 2>/dev/null
98 # Read them back by iterating based on quotas returned.
99 # This should match what we set, even if we don't directly
100 # ask for each exact id, but just ask for "next" id after
101 # each one we got back last.
103 # root is always there but not in our random IDs; start at 1
105 for ID in `cat $tmp.IDs`; do
106 echo "Trying ID $NEXT expecting $ID" >> $seqres.full
107 Q=`$here/src/test-nextquota -i $NEXT -${TYPE} -d $SCRATCH_DEV` \
108 || _fail "test-nextquota failed: $Q"
109 echo $Q >> $seqres.full
110 # ID and its inode limits should match
111 echo "$Q" | grep -qw ${ID} || _fail "Didn't get id $ID"
112 # Get the ID returned from the test
113 NEXT=`echo "$Q" | grep ^id | awk '{print $NF}' | head -n 1`
114 # Advance that ID by one, and ask for another search