2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Red Hat, Inc. All Rights Reserved.
7 # test out "sparse" quota ids retrieved by Q_GETNEXTQUOTA
9 # Designed to use the new Q_GETNEXTQUOTA quotactl
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
17 status=1 # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
22 cat $tmp.IDs >> $seqres.full
27 # get standard environment, filters and checks
32 # remove previous $seqres.full before test
35 # real QA test starts here
41 _scratch_mkfs >> $seqres.full 2>&1
44 MOUNT_OPTIONS="-o usrquota,grpquota"
48 echo "Launch all quotas"
50 # Ideally we'd carefully test edge conditions of "sparse"
51 # quota ids at beginnings and ends of otherwise empty disk
52 # blocks, etc, but that's pretty fs-specific.
53 # So just spray a bunch of random IDs into quota, and make
54 # sure we get them all back.
58 # A few extra on the off chance we get dups
59 for I in `seq 1 $(($ITERATIONS+10))`; do
60 ID=`od -N 4 -t uI -An /dev/urandom | tr -d " "`
64 # sort & uniq to remove dups & facilitate reading them back
65 # On the off chance we got ID 0, remove it.
66 sort -n $tmp.1 | uniq | head -n ${ITERATIONS} | grep -vw 0 > $tmp.IDs
68 # Populate a bunch of random quotas on the filesystem:
70 for ID in `cat $tmp.IDs`; do
71 setquota -${TYPE} $ID $ID $ID $ID $ID $SCRATCH_MNT
72 touch ${SCRATCH_MNT}/${ID}
73 chown ${ID} ${SCRATCH_MNT}/${ID}
77 # remount just for kicks, make sure we get it off disk
80 quotaon $SCRATCH_MNT 2>/dev/null
82 # Read them back by iterating based on quotas returned.
83 # This should match what we set, even if we don't directly
84 # ask for each exact id, but just ask for "next" id after
85 # each one we got back last.
87 # root is always there but not in our random IDs; start at 1
89 for ID in `cat $tmp.IDs`; do
90 echo "Trying ID $NEXT expecting $ID" >> $seqres.full
91 Q=`$here/src/test-nextquota -i $NEXT -${TYPE} -d $SCRATCH_DEV` \
92 || _fail "test-nextquota failed: $Q"
93 echo $Q >> $seqres.full
94 # ID and its inode limits should match
95 echo "$Q" | grep -qw ${ID} || _fail "Didn't get id $ID"
96 # Get the ID returned from the test
97 NEXT=`echo "$Q" | grep ^id | awk '{print $NF}' | head -n 1`
98 # Advance that ID by one, and ask for another search