summaryrefslogtreecommitdiff
path: root/tests/generic/682
blob: b4cd0cd9dd2ed3e20c7424f304940306c9a9b76c (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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2022 Oracle.  All Rights Reserved.
#
# FS QA Test No. 682
#
# Ensure that unprivileged userspace hits EDQUOT while moving files into a
# directory when the directory's quota limits have been exceeded.
#
# Regression test for commit:
#
# 41667260bc84 ("xfs: reserve quota for target dir expansion when renaming files")
#
. ./common/preamble
_begin_fstest auto quick quota

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

# real QA test starts here

# Modify as appropriate.
_supported_fs generic
_require_quota
_require_user
_require_scratch

_scratch_mkfs > "$seqres.full" 2>&1
_qmount_option usrquota
_qmount

blocksize=$(_get_block_size $SCRATCH_MNT)
scratchdir=$SCRATCH_MNT/dir
scratchfile=$SCRATCH_MNT/file
stagedir=$SCRATCH_MNT/staging
mkdir $scratchdir $stagedir
touch $scratchfile

# Create a 2-block directory for our 1-block quota limit
total_size=$((blocksize * 2))
dirents=$((total_size / 255))

for ((i = 0; i < dirents; i++)); do
	name=$(printf "x%0254d" $i)
	ln $scratchfile $scratchdir/$name
done

# Set a low quota hardlimit for an unprivileged uid and chown the files to it
echo "set up quota" >> $seqres.full
setquota -u $qa_user 0 "$((blocksize / 1024))" 0 0 $SCRATCH_MNT
chown $qa_user $scratchdir $scratchfile
repquota -upn $SCRATCH_MNT >> $seqres.full
echo $(ls $scratchdir | wc -l) files in $scratchdir  >> $seqres.full
ls -sld $scratchdir  >> $seqres.full

# Fail at renaming into the directory as qa_user to ensure quota enforcement
# works
chmod a+rwx $stagedir
echo "fail quota" >> $seqres.full
for ((i = 0; i < dirents; i++)); do
	name=$(printf "y%0254d" $i)
	ln $scratchfile $stagedir/$name
	su - "$qa_user" -c "mv $stagedir/$name $scratchdir/$name" 2>&1 | \
		_filter_scratch | sed -e 's/y[0-9]*/yXXX/g'
	test "${PIPESTATUS[0]}" -ne 0 && break
done
repquota -upn $SCRATCH_MNT >> $seqres.full
echo $(ls $scratchdir | wc -l) files in $scratchdir  >> $seqres.full
ls -sld $scratchdir  >> $seqres.full

# success, all done
echo Silence is golden
status=0
exit