2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2022 Oracle. All Rights Reserved.
7 # Ensure that unprivileged userspace hits EDQUOT while moving files into a
8 # directory when the directory's quota limits have been exceeded.
10 # Regression test for commit:
12 # 41667260bc84 ("xfs: reserve quota for target dir expansion when renaming files")
15 _begin_fstest auto quick quota
17 # Import common functions.
21 # real QA test starts here
23 # Modify as appropriate.
29 _scratch_mkfs > "$seqres.full" 2>&1
30 _qmount_option usrquota
33 blocksize=$(_get_block_size $SCRATCH_MNT)
34 scratchdir=$SCRATCH_MNT/dir
35 scratchfile=$SCRATCH_MNT/file
36 stagedir=$SCRATCH_MNT/staging
37 mkdir $scratchdir $stagedir
40 # Create a 2-block directory for our 1-block quota limit
41 total_size=$((blocksize * 2))
42 dirents=$((total_size / 255))
44 for ((i = 0; i < dirents; i++)); do
45 name=$(printf "x%0254d" $i)
46 ln $scratchfile $scratchdir/$name
49 # Set a low quota hardlimit for an unprivileged uid and chown the files to it
50 echo "set up quota" >> $seqres.full
51 setquota -u $qa_user 0 "$((blocksize / 1024))" 0 0 $SCRATCH_MNT
52 chown $qa_user $scratchdir $scratchfile
53 repquota -upn $SCRATCH_MNT >> $seqres.full
54 echo $(ls $scratchdir | wc -l) files in $scratchdir >> $seqres.full
55 ls -sld $scratchdir >> $seqres.full
57 # Fail at renaming into the directory as qa_user to ensure quota enforcement
60 echo "fail quota" >> $seqres.full
61 for ((i = 0; i < dirents; i++)); do
62 name=$(printf "y%0254d" $i)
63 ln $scratchfile $stagedir/$name
64 su - "$qa_user" -c "mv $stagedir/$name $scratchdir/$name" 2>&1 | \
65 _filter_scratch | sed -e 's/y[0-9]*/yXXX/g'
66 test "${PIPESTATUS[0]}" -ne 0 && break
68 repquota -upn $SCRATCH_MNT >> $seqres.full
69 echo $(ls $scratchdir | wc -l) files in $scratchdir >> $seqres.full
70 ls -sld $scratchdir >> $seqres.full
73 echo Silence is golden