common/rc: add _scratch_{u}mount_idmapped() helpers
[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 _require_quota
39 _require_scratch
40
41 _scratch_mkfs >> $seqres.full 2>&1
42
43 TYPES="u g"
44 MOUNT_OPTIONS="-o usrquota,grpquota"
45 _qmount
46 _require_getnextquota
47
48 echo "Launch all quotas"
49
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.
55
56 ITERATIONS=100
57
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 " "`
61         echo $ID >> $tmp.1
62 done
63
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
67
68 # Populate a bunch of random quotas on the filesystem:
69 for TYPE in u g; do
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}
74         done
75 done
76
77 # remount just for kicks, make sure we get it off disk
78 _scratch_unmount
79 _qmount
80 quotaon $SCRATCH_MNT 2>/dev/null
81
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.
86 for TYPE in u g; do
87         # root is always there but not in our random IDs; start at 1
88         NEXT=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
99                 let NEXT=NEXT+1
100         done
101 done
102
103 # success, all done
104 status=0
105 exit