From: "Darrick J. Wong" <djwong@kernel.org>
To: xfs <linux-xfs@vger.kernel.org>
Subject: [PATCH] generic: test that linking into a directory fails with EDQUOT
Date: Mon, 28 Feb 2022 20:59:49 -0800 [thread overview]
Message-ID: <20220301045949.GH117732@magnolia> (raw)
In-Reply-To: <20220301025118.GG117732@magnolia>
From: Darrick J. Wong <djwong@kernel.org>
Add a regression test to make sure that unprivileged userspace linking
into a directory fails with EDQUOT when the directory quota limits have
been exceeded.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
tests/generic/732 | 67 +++++++++++++++++++++++++++++++++++++++++++++++++
tests/generic/732.out | 3 ++
2 files changed, 70 insertions(+)
create mode 100755 tests/generic/732
create mode 100644 tests/generic/732.out
diff --git a/tests/generic/732 b/tests/generic/732
new file mode 100755
index 00000000..c4a3dcb6
--- /dev/null
+++ b/tests/generic/732
@@ -0,0 +1,67 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2022 Oracle. All Rights Reserved.
+#
+# FS QA Test No. 732
+#
+# Ensure that unprivileged userspace hits EDQUOT while linking files into a
+# directory when the directory's quota limits have been exceeded.
+#
+# Regression test for commit:
+#
+# XXXXXXXXXXXX ("xfs: reserve quota for directory expansion when hardlinking 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
+mkdir $scratchdir
+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 appending the directory as qa_user to ensure quota enforcement works
+echo "fail quota" >> $seqres.full
+for ((i = 0; i < dirents; i++)); do
+ name=$(printf "y%0254d" $i)
+ su - "$qa_user" -c "ln $scratchfile $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/732.out b/tests/generic/732.out
new file mode 100644
index 00000000..15d2cb61
--- /dev/null
+++ b/tests/generic/732.out
@@ -0,0 +1,3 @@
+QA output created by 732
+ln: failed to create hard link 'SCRATCH_MNT/dir/yXXX': Disk quota exceeded
+Silence is golden
next prev parent reply other threads:[~2022-03-01 5:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-01 2:51 [PATCH] xfs: reserve quota for directory expansion when hardlinking files Darrick J. Wong
2022-03-01 4:59 ` Darrick J. Wong [this message]
2022-03-08 17:25 ` Darrick J. Wong
2022-03-08 22:18 ` Dave Chinner
2022-03-08 23:17 ` Darrick J. Wong
2022-03-09 1:12 ` Dave Chinner
2022-03-09 16:44 ` Darrick J. Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220301045949.GH117732@magnolia \
--to=djwong@kernel.org \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox