blob: e3994d003e23bce3f7c51415f2d48f7a23aa4c2a [file] [log] [blame]
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (c) 2022 Oracle. All Rights Reserved.
#
# FS QA Test No. 709
#
# Can we use exchangerange to make the quota accounting incorrect?
. ./common/preamble
_begin_fstest auto quick fiexchange quota
# Import common functions.
. ./common/filter
. ./common/quota
_require_xfs_io_command exchangerange
_require_user
_require_nobody
_require_quota
_require_xfs_quota
_require_scratch
# Format filesystem and set up quota limits
_scratch_mkfs > $seqres.full
_qmount_option "usrquota,grpquota"
_qmount >> $seqres.full
# Set up initial files
$XFS_IO_PROG -f -c 'pwrite -S 0x58 0 256k -b 1m' $SCRATCH_MNT/a >> $seqres.full
chown $qa_user $SCRATCH_MNT/a
$XFS_IO_PROG -f -c 'pwrite -S 0x59 0 64k -b 64k' -c 'truncate 256k' $SCRATCH_MNT/b >> $seqres.full
chown nobody $SCRATCH_MNT/b
echo before exchangerange >> $seqres.full
$XFS_QUOTA_PROG -x -c 'report -a' $SCRATCH_MNT >> $seqres.full
stat $SCRATCH_MNT/* >> $seqres.full
# Now try to swap the extents of the two files. The command is allowed to
# fail with -EINVAL (since that's what the first kernel fix does) or succeed
# (because subsequent rewrites can handle quota). Whatever the outcome, the
# quota usage check at the end should never show a discrepancy.
$XFS_IO_PROG -c "exchangerange $SCRATCH_MNT/b" $SCRATCH_MNT/a &> $tmp.swap
cat $tmp.swap >> $seqres.full
grep -v 'Invalid argument' $tmp.swap
echo after exchangerange >> $seqres.full
$XFS_QUOTA_PROG -x -c 'report -a' $SCRATCH_MNT >> $seqres.full
stat $SCRATCH_MNT/* >> $seqres.full
_check_quota_usage
# success, all done
status=0
exit