xfs: Check for extent overflow when trivally adding a new extent
[xfstests-dev.git] / tests / xfs / 235
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 235
6 #
7 # Create and populate an XFS filesystem, corrupt the rmap btree,
8 # then see how the kernel and xfs_repair deal with it.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21     cd /
22     rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/attr
29
30 # real QA test starts here
31 _supported_fs xfs
32 _require_xfs_scratch_rmapbt
33 test -n ${FORCE_FUZZ} || _require_scratch_xfs_crc
34
35 rm -f $seqres.full
36
37 echo "+ create scratch fs"
38 _scratch_mkfs_xfs > /dev/null
39
40 echo "+ mount fs image"
41 _scratch_mount
42 blksz=$(stat -f -c '%s' ${SCRATCH_MNT})
43 agcount=$(_xfs_mount_agcount $SCRATCH_MNT)
44
45 echo "+ make some files"
46 _pwrite_byte 0x62 0 $((blksz * 64)) ${SCRATCH_MNT}/file0 >> $seqres.full
47 _pwrite_byte 0x61 0 $((blksz * 64)) ${SCRATCH_MNT}/file1 >> $seqres.full
48 cp -p ${SCRATCH_MNT}/file0 ${SCRATCH_MNT}/file2
49 cp -p ${SCRATCH_MNT}/file1 ${SCRATCH_MNT}/file3
50 umount ${SCRATCH_MNT}
51
52 echo "+ check fs"
53 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
54         _fail "xfs_repair should not fail"
55
56 echo "+ corrupt image"
57 seq 0 $((agcount - 1)) | while read ag; do
58         _scratch_xfs_db -x -c "agf ${ag}" -c "agf ${ag}" -c "addr rmaproot" \
59                 -c "stack" -c "blocktrash -x 4096 -y 4096 -z -n 8 -3" \
60                 >> $seqres.full 2>&1
61 done
62
63 echo "+ mount image && copy more"
64 if _try_scratch_mount >> $seqres.full 2>&1; then
65
66         $XFS_IO_PROG -f -c "pwrite -S 0x63 0 $((blksz * 64))" -c "fsync" ${SCRATCH_MNT}/file4 >> $seqres.full 2>&1
67         test -s ${SCRATCH_MNT}/file4 && _fail "should not be able to copy with busted rmap btree"
68         umount ${SCRATCH_MNT}
69 fi
70
71 echo "+ repair fs"
72 _disable_dmesg_check
73 _repair_scratch_fs >> "$seqres.full" 2>&1
74 _scratch_xfs_repair >> $seqres.full 2>&1
75
76 echo "+ mount image (2)"
77 _scratch_mount
78
79 echo "+ chattr -R -i"
80 $CHATTR_PROG -R -f -i ${SCRATCH_MNT}/
81
82 echo "+ copy more (2)"
83 cp -p ${SCRATCH_MNT}/file1 ${SCRATCH_MNT}/file5 || \
84         _fail "modified rmap tree"
85 umount ${SCRATCH_MNT}
86
87 echo "+ check fs (2)"
88 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
89         _fail "xfs_repair should not fail"
90
91 status=0
92 exit