From 249f5a78d3094477c8615cb62fb49ef3aec4f785 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Fri, 30 Dec 2022 14:19:57 -0800 Subject: [PATCH] xfs: ensure that online directory repairs don't hit EDQUOT Add a test to ensure that the sysadmin doesn't get EDQUOT if they try to repair directory metadata when we've already exceeded a quota limit somewhere. Signed-off-by: Darrick J. Wong Reviewed-by: Zorro Lang Signed-off-by: Zorro Lang --- tests/xfs/795 | 77 +++++++++++++++++++++++++++++++++++++++++++++++ tests/xfs/795.out | 3 ++ 2 files changed, 80 insertions(+) create mode 100755 tests/xfs/795 create mode 100644 tests/xfs/795.out diff --git a/tests/xfs/795 b/tests/xfs/795 new file mode 100755 index 00000000..a381db32 --- /dev/null +++ b/tests/xfs/795 @@ -0,0 +1,77 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Oracle. All Rights Reserved. +# +# FS QA Test No. 795 +# +# Ensure that the sysadmin won't hit EDQUOT while repairing file data contents +# even if the file's quota limits have been exceeded. This tests the quota +# reservation handling inside the swapext code used by repair. +# +. ./common/preamble +_begin_fstest online_repair + +# Import common functions. +. ./common/filter +. ./common/fuzzy +. ./common/inject +. ./common/quota + +# real QA test starts here + +# Modify as appropriate. +_supported_fs xfs +_require_quota +_require_user +_require_scratch +_require_xfs_stress_online_repair + +_scratch_mkfs > "$seqres.full" 2>&1 +_qmount_option usrquota +_qmount + +blocksize=$(_get_block_size $SCRATCH_MNT) +alloc_unit=$(_xfs_get_dir_blocksize $SCRATCH_MNT) + +# Make sure we can actually repair a directory +scratchdir=$SCRATCH_MNT/dir +scratchfile=$SCRATCH_MNT/file +mkdir $scratchdir +touch $scratchfile +$XFS_IO_PROG -x -c 'inject force_repair' $SCRATCH_MNT +__stress_scrub_check_commands "$scratchdir" "" 'repair directory' + +# Create a 2-dirblock directory +total_size=$((alloc_unit * 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 +$XFS_QUOTA_PROG -x -c "limit -u bhard=$alloc_unit $qa_user" $SCRATCH_MNT +chown $qa_user $scratchdir $scratchfile +$XFS_QUOTA_PROG -x -c 'report -u' $SCRATCH_MNT >> $seqres.full + +# Rebuild the directory +echo "repairs" >> $seqres.full +$XFS_IO_PROG -x -c 'inject force_repair' -c 'repair directory' $scratchdir +$XFS_QUOTA_PROG -x -c 'report -u' $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 +$XFS_QUOTA_PROG -x -c 'report -u' $SCRATCH_MNT >> $seqres.full + +# success, all done +echo Silence is golden +status=0 +exit diff --git a/tests/xfs/795.out b/tests/xfs/795.out new file mode 100644 index 00000000..91819956 --- /dev/null +++ b/tests/xfs/795.out @@ -0,0 +1,3 @@ +QA output created by 795 +ln: failed to create hard link 'SCRATCH_MNT/dir/yXXX': Disk quota exceeded +Silence is golden -- 2.39.5