fstests: convert remaining tests to SPDX license tags
[xfstests-dev.git] / tests / xfs / 337
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 337
6 #
7 # Corrupt the realtime rmapbt and see how the kernel and xfs_repair deal.
8 #
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 -rf "$tmp".*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27
28 # real QA test starts here
29 _supported_os Linux
30 _supported_fs xfs
31 _require_realtime
32 _require_xfs_scratch_rmapbt
33 _require_test_program "punch-alternating"
34 _require_xfs_io_command "falloc"
35 _disable_dmesg_check
36
37 rm -f "$seqres.full"
38
39 echo "+ create scratch fs"
40 _scratch_mkfs | _filter_mkfs 2>$tmp.mkfs >/dev/null
41 . $tmp.mkfs
42 cat $tmp.mkfs > "$seqres.full" 2>&1
43
44 echo "+ mount fs image"
45 _scratch_mount
46 blksz="$(_get_block_size $SCRATCH_MNT)"
47
48 # inode core size is at least 176 bytes; btree header is 56 bytes;
49 # rtrmap record is 32 bytes; and rtrmap key/pointer are 56 bytes.
50 i_ptrs=$(( (isize - 176) / 56 ))
51 bt_ptrs=$(( (blksz - 56) / 56 ))
52 bt_recs=$(( (blksz - 56) / 32 ))
53
54 blocks=$((i_ptrs * bt_ptrs * bt_recs + 1))
55 _require_fs_space $SCRATCH_MNT $(( (2 * blocks * blksz) * 5 / 4096 ))
56 len=$((blocks * blksz))
57
58 echo "+ make some files"
59 $XFS_IO_PROG -f -R -c "falloc 0 $len" -c "pwrite -S 0x68 -b 1048576 0 $len" $SCRATCH_MNT/f1 >> $seqres.full
60 $XFS_IO_PROG -f -R -c "falloc 0 $len" -c "pwrite -S 0x68 -b 1048576 0 $len" $SCRATCH_MNT/f2 >> $seqres.full
61 ./src/punch-alternating $SCRATCH_MNT/f1 >> "$seqres.full"
62 ./src/punch-alternating $SCRATCH_MNT/f2 >> "$seqres.full"
63 _scratch_unmount
64
65 echo "+ check fs"
66 _scratch_xfs_repair -n >> $seqres.full 2>&1 || echo "xfs_repair should not fail"
67
68 echo "+ corrupt image"
69 _scratch_xfs_db -x -c "sb" -c "addr rrmapino" -c "addr u3.rtrmapbt.ptrs[1]" \
70         -c "stack" -c "blocktrash -x 4096 -y 4096 -n 8 -3 -z" \
71         >> $seqres.full 2>&1
72
73 echo "+ mount image"
74 if _try_scratch_mount >> $seqres.full 2>&1; then
75
76         echo "+ copy more"
77         $XFS_IO_PROG -f -R -c "pwrite -S 0x68 0 1" $SCRATCH_MNT/e3 >> $seqres.full 2>&1
78         test -s ${SCRATCH_MNT}/f3 && echo "should not be able to copy with busted rtrmap btree"
79         _scratch_unmount
80 fi
81
82 echo "+ repair fs"
83 _repair_scratch_fs >> $seqres.full 2>&1
84
85 echo "+ mount image (2)"
86 _scratch_mount
87
88 echo "+ copy more (2)"
89 $XFS_IO_PROG -f -R -c "pwrite -S 0x68 0 1" $SCRATCH_MNT/e4 >> $seqres.full
90
91 # success, all done
92 status=0
93 exit