xfs: fix old fuzz test invocations of xfs_repair
[xfstests-dev.git] / tests / xfs / 535
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2021 Chandan Babu R.  All Rights Reserved.
4 #
5 # FS QA Test 535
6 #
7 # Verify that XFS does not cause inode fork's extent count to overflow when
8 # writing to a shared extent.
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/reflink
28 . ./common/inject
29
30 # remove previous $seqres.full before test
31 rm -f $seqres.full
32
33 # real QA test starts here
34
35 _supported_fs xfs
36 _require_scratch
37 _require_scratch_reflink
38 _require_xfs_debug
39 _require_xfs_io_command "reflink"
40 _require_xfs_io_command "funshare"
41 _require_xfs_io_error_injection "reduce_max_iextents"
42
43 echo "Format and mount fs"
44 _scratch_mkfs_sized $((512 * 1024 * 1024)) >> $seqres.full
45 _scratch_mount >> $seqres.full
46
47 bsize=$(_get_block_size $SCRATCH_MNT)
48
49 nr_blks=15
50
51 srcfile=${SCRATCH_MNT}/srcfile
52 dstfile=${SCRATCH_MNT}/dstfile
53
54 touch $srcfile
55 touch $dstfile
56
57 echo "Inject reduce_max_iextents error tag"
58 _scratch_inject_error reduce_max_iextents 1
59
60 echo "Create a \$srcfile having an extent of length $nr_blks blocks"
61 $XFS_IO_PROG -f -c "pwrite -b $((nr_blks * bsize))  0 $((nr_blks * bsize))" \
62        -c fsync $srcfile  >> $seqres.full
63
64 echo "* Write to shared extent"
65
66 echo "Share the extent with \$dstfile"
67 _reflink $srcfile $dstfile >> $seqres.full
68
69 echo "Buffered write to every other block of \$dstfile's shared extent"
70 for i in $(seq 1 2 $((nr_blks - 1))); do
71         $XFS_IO_PROG -f -s -c "pwrite $((i * bsize)) $bsize" $dstfile \
72                >> $seqres.full 2>&1
73         [[ $? != 0 ]] && break
74 done
75
76 echo "Verify \$dstfile's extent count"
77 nextents=$(_xfs_get_fsxattr nextents $dstfile)
78 if (( $nextents > 10 )); then
79         echo "Extent count overflow check failed: nextents = $nextents"
80         exit 1
81 fi
82
83 echo "Disable reduce_max_iextents error tag"
84 _scratch_inject_error reduce_max_iextents 0
85
86 rm $dstfile
87
88 echo "* Funshare shared extent"
89
90 touch $dstfile
91
92 echo "Inject reduce_max_iextents error tag"
93 _scratch_inject_error reduce_max_iextents 1
94
95 echo "Share the extent with \$dstfile"
96 _reflink $srcfile $dstfile >> $seqres.full
97
98 echo "Funshare every other block of \$dstfile's shared extent"
99 for i in $(seq 1 2 $((nr_blks - 1))); do
100         $XFS_IO_PROG -f -s -c "funshare $((i * bsize)) $bsize" $dstfile \
101                >> $seqres.full 2>&1
102         [[ $? != 0 ]] && break
103 done
104
105 echo "Verify \$dstfile's extent count"
106 nextents=$(_xfs_get_fsxattr nextents $dstfile)
107 if (( $nextents > 10 )); then
108         echo "Extent count overflow check failed: nextents = $nextents"
109         exit 1
110 fi
111
112 # success, all done
113 status=0
114 exit
115