summaryrefslogtreecommitdiff
path: root/tests/generic/709
blob: 4bd591b873d8edad0612c049938ac6ba79accb2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /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 swapext to make the quota accounting incorrect?

. ./common/preamble
_begin_fstest auto quick fiexchange swapext quota

# Import common functions.
. ./common/filter
. ./common/quota

# real QA test starts here
_require_xfs_io_command swapext '-v exchrange'
_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 swapext >> $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 "swapext $SCRATCH_MNT/b" $SCRATCH_MNT/a &> $tmp.swap
cat $tmp.swap >> $seqres.full
grep -v 'Invalid argument' $tmp.swap

echo after swapext >> $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