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 _begin_fstest auto quick quota
14 # Override the default cleanup function.
17 cat $tmp.IDs >> $seqres.full
22 # Import common functions.
26 # real QA test starts here
32 _scratch_mkfs >> $seqres.full 2>&1
35 MOUNT_OPTIONS="-o usrquota,grpquota"
39 echo "Launch all quotas"
41 # Ideally we'd carefully test edge conditions of "sparse"
42 # quota ids at beginnings and ends of otherwise empty disk
43 # blocks, etc, but that's pretty fs-specific.
44 # So just spray a bunch of random IDs into quota, and make
45 # sure we get them all back.
49 # A few extra on the off chance we get dups
50 for I in `seq 1 $(($ITERATIONS+10))`; do
51 ID=`od -N 4 -t uI -An /dev/urandom | tr -d " "`
55 # sort & uniq to remove dups & facilitate reading them back
56 # On the off chance we got ID 0, remove it.
57 sort -n $tmp.1 | uniq | head -n ${ITERATIONS} | grep -vw 0 > $tmp.IDs
59 # Populate a bunch of random quotas on the filesystem:
61 for ID in `cat $tmp.IDs`; do
62 setquota -${TYPE} $ID $ID $ID $ID $ID $SCRATCH_MNT
63 touch ${SCRATCH_MNT}/${ID}
64 chown ${ID} ${SCRATCH_MNT}/${ID}
68 # remount just for kicks, make sure we get it off disk
71 quotaon $SCRATCH_MNT 2>/dev/null
73 # Read them back by iterating based on quotas returned.
74 # This should match what we set, even if we don't directly
75 # ask for each exact id, but just ask for "next" id after
76 # each one we got back last.
78 # root is always there but not in our random IDs; start at 1
80 for ID in `cat $tmp.IDs`; do
81 echo "Trying ID $NEXT expecting $ID" >> $seqres.full
82 Q=`$here/src/test-nextquota -i $NEXT -${TYPE} -d $SCRATCH_DEV` \
83 || _fail "test-nextquota failed: $Q"
84 echo $Q >> $seqres.full
85 # ID and its inode limits should match
86 echo "$Q" | grep -qw ${ID} || _fail "Didn't get id $ID"
87 # Get the ID returned from the test
88 NEXT=`echo "$Q" | grep ^id | awk '{print $NF}' | head -n 1`
89 # Advance that ID by one, and ask for another search