xfs/{263,106}: erase max warnings printout
[xfstests-dev.git] / tests / generic / 244
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test 244
6 #
7 # test out "sparse" quota ids retrieved by Q_GETNEXTQUOTA
8 #
9 # Designed to use the new Q_GETNEXTQUOTA quotactl
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         cat $tmp.IDs >> $seqres.full
23         cd /
24         rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30 . ./common/quota
31
32 # remove previous $seqres.full before test
33 rm -f $seqres.full
34
35 # real QA test starts here
36
37 _supported_fs generic
38 _supported_os Linux
39 _require_quota
40 _require_scratch
41
42 _scratch_mkfs >> $seqres.full 2>&1
43
44 TYPES="u g"
45 MOUNT_OPTIONS="-o usrquota,grpquota"
46 _qmount
47 _require_getnextquota
48
49 echo "Launch all quotas"
50
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.
56
57 ITERATIONS=100
58
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 " "`
62         echo $ID >> $tmp.1
63 done
64
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
68
69 # Populate a bunch of random quotas on the filesystem:
70 for TYPE in u g; do
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}
75         done
76 done
77
78 # remount just for kicks, make sure we get it off disk
79 _scratch_unmount
80 _qmount
81 quotaon $SCRATCH_MNT 2>/dev/null
82
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.
87 for TYPE in u g; do
88         # root is always there but not in our random IDs; start at 1
89         NEXT=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
100                 let NEXT=NEXT+1
101         done
102 done
103
104 # success, all done
105 status=0
106 exit