xfs/007: fix regressions on V4 filesystems
[xfstests-dev.git] / tests / xfs / 341
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. 341
6 #
7 # Cross-link file block into rtrmapbt and see if repair fixes it.
8 #
9 . ./common/preamble
10 _begin_fstest auto quick rmap realtime
11
12 # Import common functions.
13 . ./common/filter
14
15 # real QA test starts here
16 _supported_fs xfs
17 _require_realtime
18 _require_xfs_scratch_rmapbt
19 _require_test_program "punch-alternating"
20 _disable_dmesg_check
21 _require_xfs_io_command "falloc"
22
23 rm -f "$seqres.full"
24
25 echo "Format and mount"
26 _scratch_mkfs | _filter_mkfs 2>$tmp.mkfs >/dev/null
27 . $tmp.mkfs
28 cat $tmp.mkfs > "$seqres.full" 2>&1
29 _scratch_mount
30 blksz="$(_get_block_size $SCRATCH_MNT)"
31
32 rtextsz_blks=$((rtextsz / blksz))
33
34 # inode core size is at least 176 bytes; btree header is 56 bytes;
35 # rtrmap record is 32 bytes; and rtrmap key/pointer are 56 bytes.
36 i_ptrs=$(( (isize - 176) / 56 ))
37 bt_recs=$(( (blksz - 56) / 32 ))
38
39 blocks=$((i_ptrs * bt_recs + 1))
40 len=$((blocks * rtextsz))
41
42 echo "Create some files"
43 $XFS_IO_PROG -f -R -c "falloc 0 $len" -c "pwrite -S 0x68 -b 1048576 0 $len" $SCRATCH_MNT/f1 >> $seqres.full
44 $XFS_IO_PROG -f -R -c "falloc 0 $len" -c "pwrite -S 0x68 -b 1048576 0 $len" $SCRATCH_MNT/f2 >> $seqres.full
45 $here/src/punch-alternating -i $((2 * rtextsz_blks)) -s $rtextsz_blks $SCRATCH_MNT/f1 >> "$seqres.full"
46 $here/src/punch-alternating -i $((2 * rtextsz_blks)) -s $rtextsz_blks $SCRATCH_MNT/f2 >> "$seqres.full"
47 echo garbage > $SCRATCH_MNT/f3
48 ino=$(stat -c '%i' $SCRATCH_MNT/f3)
49 _scratch_unmount
50
51 echo "Corrupt fs"
52 fsbno=$(_scratch_xfs_db -c "inode $ino" -c 'bmap' | grep 'flag 0' | head -n 1 | \
53         sed -e 's/^.*startblock \([0-9]*\) .*$/\1/g')
54
55 _scratch_xfs_db -x -c 'sb 0' -c 'addr rrmapino' \
56         -c "write u3.rtrmapbt.ptrs[1] $fsbno" -c 'p' >> $seqres.full
57 _scratch_mount
58
59 echo "Try to create more files"
60 $XFS_IO_PROG -f -R -c "pwrite -S 0x68 0 9999" $SCRATCH_MNT/f5 >> $seqres.full 2>&1
61 test -e $SCRATCH_MNT/f5 && echo "should not have been able to write f5"
62
63 echo "Repair fs"
64 _scratch_unmount 2>&1 | _filter_scratch
65 _repair_scratch_fs >> $seqres.full 2>&1
66
67 echo "Try to create more files (again)"
68 _scratch_mount
69 $XFS_IO_PROG -f -R -c "pwrite -S 0x68 0 9999" $SCRATCH_MNT/f4 >> $seqres.full
70
71 # success, all done
72 status=0
73 exit