2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
7 # Cross-link file block into rtrmapbt and see if repair fixes it.
10 seqres="$RESULT_DIR/$seq"
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
24 # get standard environment, filters and checks
28 # real QA test starts here
31 _require_xfs_scratch_rmapbt
32 _require_test_program "punch-alternating"
34 _require_xfs_io_command "falloc"
38 echo "Format and mount"
39 _scratch_mkfs | _filter_mkfs 2>$tmp.mkfs >/dev/null
41 cat $tmp.mkfs > "$seqres.full" 2>&1
43 blksz="$(_get_block_size $SCRATCH_MNT)"
45 rtextsz_blks=$((rtextsz / blksz))
47 # inode core size is at least 176 bytes; btree header is 56 bytes;
48 # rtrmap record is 32 bytes; and rtrmap key/pointer are 56 bytes.
49 i_ptrs=$(( (isize - 176) / 56 ))
50 bt_recs=$(( (blksz - 56) / 32 ))
52 blocks=$((i_ptrs * bt_recs + 1))
53 len=$((blocks * rtextsz))
55 echo "Create some files"
56 $XFS_IO_PROG -f -R -c "falloc 0 $len" -c "pwrite -S 0x68 -b 1048576 0 $len" $SCRATCH_MNT/f1 >> $seqres.full
57 $XFS_IO_PROG -f -R -c "falloc 0 $len" -c "pwrite -S 0x68 -b 1048576 0 $len" $SCRATCH_MNT/f2 >> $seqres.full
58 $here/src/punch-alternating -i $((2 * rtextsz_blks)) -s $rtextsz_blks $SCRATCH_MNT/f1 >> "$seqres.full"
59 $here/src/punch-alternating -i $((2 * rtextsz_blks)) -s $rtextsz_blks $SCRATCH_MNT/f2 >> "$seqres.full"
60 echo garbage > $SCRATCH_MNT/f3
61 ino=$(stat -c '%i' $SCRATCH_MNT/f3)
65 fsbno=$(_scratch_xfs_db -c "inode $ino" -c 'bmap' | grep 'flag 0' | head -n 1 | \
66 sed -e 's/^.*startblock \([0-9]*\) .*$/\1/g')
68 _scratch_xfs_db -x -c 'sb 0' -c 'addr rrmapino' \
69 -c "write u3.rtrmapbt.ptrs[1] $fsbno" -c 'p' >> $seqres.full
72 echo "Try to create more files"
73 $XFS_IO_PROG -f -R -c "pwrite -S 0x68 0 9999" $SCRATCH_MNT/f5 >> $seqres.full 2>&1
74 test -e $SCRATCH_MNT/f5 && echo "should not have been able to write f5"
77 _scratch_unmount 2>&1 | _filter_scratch
78 _repair_scratch_fs >> $seqres.full 2>&1
80 echo "Try to create more files (again)"
82 $XFS_IO_PROG -f -R -c "pwrite -S 0x68 0 9999" $SCRATCH_MNT/f4 >> $seqres.full