summaryrefslogtreecommitdiff
path: root/tests/generic/244
blob: 504150777b3282e6a287ea39c3a9cff4c605efe6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2016 Red Hat, Inc.  All Rights Reserved.
#
# FS QA Test 244
#
# test out "sparse" quota ids retrieved by Q_GETNEXTQUOTA
#
# Designed to use the new Q_GETNEXTQUOTA quotactl
#
. ./common/preamble
_begin_fstest auto quick quota

# Override the default cleanup function.
_cleanup()
{
	cat $tmp.IDs >> $seqres.full
	cd /
	rm -f $tmp.*
}

# Import common functions.
. ./common/filter
. ./common/quota

# real QA test starts here

_supported_fs generic
_require_quota
_require_scratch

_scratch_mkfs >> $seqres.full 2>&1

TYPES="u g"
MOUNT_OPTIONS="-o usrquota,grpquota"
_qmount
_require_getnextquota

echo "Launch all quotas"

# Ideally we'd carefully test edge conditions of "sparse"
# quota ids at beginnings and ends of otherwise empty disk
# blocks, etc, but that's pretty fs-specific.
# So just spray a bunch of random IDs into quota, and make
# sure we get them all back.

ITERATIONS=100

# A few extra on the off chance we get dups
for I in `seq 1 $(($ITERATIONS+10))`; do
	ID=`od -N 4 -t uI -An /dev/urandom | tr -d " "`
	echo $ID >> $tmp.1
done

# sort & uniq to remove dups & facilitate reading them back
# On the off chance we got ID 0, remove it.
sort -n $tmp.1 | uniq | head -n ${ITERATIONS} | grep -vw 0 > $tmp.IDs

# Populate a bunch of random quotas on the filesystem:
for TYPE in u g; do
	for ID in `cat $tmp.IDs`; do
		setquota -${TYPE} $ID $ID $ID $ID $ID $SCRATCH_MNT
		touch ${SCRATCH_MNT}/${ID}
		chown ${ID} ${SCRATCH_MNT}/${ID}
	done
done

# remount just for kicks, make sure we get it off disk
_scratch_unmount
_qmount
quotaon $SCRATCH_MNT 2>/dev/null

# Read them back by iterating based on quotas returned.
# This should match what we set, even if we don't directly
# ask for each exact id, but just ask for "next" id after
# each one we got back last.
for TYPE in u g; do
	# root is always there but not in our random IDs; start at 1
	NEXT=1
	for ID in `cat $tmp.IDs`; do
		echo "Trying ID $NEXT expecting $ID" >> $seqres.full
		Q=`$here/src/test-nextquota -i $NEXT -${TYPE} -d $SCRATCH_DEV` \
			 || _fail "test-nextquota failed: $Q"
		echo $Q >> $seqres.full
		# ID and its inode limits should match
		echo "$Q" | grep -qw ${ID} || _fail "Didn't get id $ID"
		# Get the ID returned from the test
		NEXT=`echo "$Q" | grep ^id | awk '{print $NF}' | head -n 1`
		# Advance that ID by one, and ask for another search
		let NEXT=NEXT+1
	done
done

# success, all done
status=0
exit