diff options
author | Darrick J. Wong <djwong@kernel.org> | 2022-04-11 15:54:54 -0700 |
---|---|---|
committer | Eryu Guan <guaneryu@gmail.com> | 2022-04-17 23:04:25 +0800 |
commit | fbc6486be09c93a68d3863ebf7e3ed851fc4721c (patch) | |
tree | ef55b51e3442715b3e5b1e3699f0f24ed8f856e6 | |
parent | 48029933892b96c183603d94a1f3acc179988d99 (diff) | |
download | xfstests-dev-fbc6486be09c93a68d3863ebf7e3ed851fc4721c.tar.gz |
generic: test that renaming into a directory fails with EDQUOT
Add a regression test to make sure that unprivileged userspace renaming
within a directory fails with EDQUOT when the directory quota limits have
been exceeded.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Zorro Lang <zlang@redhat.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
-rwxr-xr-x | tests/generic/682 | 71 | ||||
-rw-r--r-- | tests/generic/682.out | 3 |
2 files changed, 74 insertions, 0 deletions
diff --git a/tests/generic/682 b/tests/generic/682 new file mode 100755 index 0000000000..31629a56a5 --- /dev/null +++ b/tests/generic/682 @@ -0,0 +1,71 @@ +#! /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 + +# 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 + +# success, all done +echo Silence is golden +status=0 +exit diff --git a/tests/generic/682.out b/tests/generic/682.out new file mode 100644 index 0000000000..b747081172 --- /dev/null +++ b/tests/generic/682.out @@ -0,0 +1,3 @@ +QA output created by 682 +mv: cannot move 'SCRATCH_MNT/staging/yXXX' to 'SCRATCH_MNT/dir/yXXX': Disk quota exceeded +Silence is golden |