xfs: Check for extent overflow when trivally adding a new extent
[xfstests-dev.git] / tests / xfs / 145
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2021 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 145
6 #
7 # Regression test for failing to undo delalloc quota reservations when changing
8 # project id but we fail some other part of FSSETXATTR validation.  If we fail
9 # the test, we trip debugging assertions in dmesg.  This is a regression test
10 # for commit 1aecf3734a95 ("xfs: fix chown leaking delalloc quota blocks when
11 # fssetxattr fails").
12
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1    # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         cd /
25         rm -f $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/quota
31
32 # real QA test starts here
33 _supported_fs xfs
34 _require_command "$FILEFRAG_PROG" filefrag
35 _require_test_program "chprojid_fail"
36 _require_quota
37 _require_scratch
38
39 rm -f $seqres.full
40
41 echo "Format filesystem" | tee -a $seqres.full
42 _scratch_mkfs > $seqres.full
43 _qmount_option 'prjquota'
44 _qmount
45 _require_prjquota $SCRATCH_DEV
46
47 # Make sure that a regular buffered write produces delalloc reservations.
48 $XFS_IO_PROG -f -c 'pwrite 0 64k' $SCRATCH_MNT/testy &> /dev/null
49 $FILEFRAG_PROG -v $SCRATCH_MNT/testy 2>&1 | grep -q delalloc || \
50         _notrun "test requires delayed allocation writes"
51 rm -f $SCRATCH_MNT/testy
52
53 echo "Run test program"
54 $XFS_QUOTA_PROG -f -x -c 'report -ap' $SCRATCH_MNT >> $seqres.full
55 $here/src/chprojid_fail $SCRATCH_MNT/blah
56
57 # The regression we're testing for is an accounting bug involving delalloc
58 # reservations.  FSSETXATTR does not itself cause dirty data writeback, so we
59 # assume that if the file still has delalloc extents, then it must have had
60 # them when chprojid_fail was running, and therefore the test was set up
61 # correctly.  There's a slight chance that background writeback can sneak in
62 # and flush the file, but this should be a small enough gap.
63 $FILEFRAG_PROG -v $SCRATCH_MNT/blah 2>&1 | grep -q delalloc || \
64         echo "file didn't get delalloc extents, test invalid?"
65
66 # Make a note of current quota status for diagnostic purposes
67 $XFS_QUOTA_PROG -f -x -c 'report -ap' $SCRATCH_MNT >> $seqres.full
68
69 # success, all done
70 status=0
71 exit