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