fstests: move test group info to test files
[xfstests-dev.git] / tests / xfs / 342
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. 342
6 #
7 # Cross-link rtrmapbt block into a file 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 _require_xfs_io_command "falloc"
21
22 rm -f "$seqres.full"
23
24 echo "Format and mount"
25 _scratch_mkfs | _filter_mkfs 2>$tmp.mkfs >/dev/null
26 . $tmp.mkfs
27 cat $tmp.mkfs > "$seqres.full" 2>&1
28 _scratch_mount
29 blksz="$(_get_block_size $SCRATCH_MNT)"
30
31 # inode core size is at least 176 bytes; btree header is 56 bytes;
32 # rtrmap record is 32 bytes; and rtrmap key/pointer are 56 bytes.
33 i_ptrs=$(( (isize - 176) / 56 ))
34 bt_recs=$(( (blksz - 56) / 32 ))
35
36 blocks=$((i_ptrs * bt_recs + 1))
37 len=$((blocks * rtextsz))
38
39 echo "Create some files"
40 $XFS_IO_PROG -f -R -c "falloc 0 $len" -c "pwrite -S 0x68 -b 1048576 0 $len" $SCRATCH_MNT/f1 >> $seqres.full
41 $XFS_IO_PROG -f -R -c "falloc 0 $len" -c "pwrite -S 0x68 -b 1048576 0 $len" $SCRATCH_MNT/f2 >> $seqres.full
42 $here/src/punch-alternating $SCRATCH_MNT/f1 >> "$seqres.full"
43 $here/src/punch-alternating $SCRATCH_MNT/f2 >> "$seqres.full"
44 echo garbage > $SCRATCH_MNT/f3
45 ino=$(stat -c '%i' $SCRATCH_MNT/f3)
46 _scratch_unmount
47
48 echo "Corrupt fs"
49 _scratch_xfs_db -c 'sb 0' -c 'addr rrmapino' -c 'p u3.rtrmapbt.ptrs[1]' >> $seqres.full
50
51 fsbno=$(_scratch_xfs_db -c 'sb 0' -c 'addr rrmapino' \
52         -c 'p u3.rtrmapbt.ptrs[1]' | sed -e 's/^.*://g')
53 _scratch_xfs_db -x -c "inode $ino" -c "write u3.bmx[0].startblock $fsbno" >> $seqres.full
54 _scratch_mount
55
56 od -tx1 -Ad -c $SCRATCH_MNT/f3 >> $seqres.full
57
58 echo "Try to create more files"
59 $XFS_IO_PROG -f -R -c "pwrite -S 0x68 0 9999" $SCRATCH_MNT/f5 >> $seqres.full 2>&1
60 test ! -e $SCRATCH_MNT/f5 && echo "should have been able to write f5"
61
62 echo "Repair fs"
63 _scratch_unmount 2>&1 | _filter_scratch
64 _repair_scratch_fs >> $seqres.full 2>&1
65
66 echo "Try to create more files (again)"
67 _scratch_mount
68 $XFS_IO_PROG -f -R -c "pwrite -S 0x68 0 9999" $SCRATCH_MNT/f4 >> $seqres.full
69
70 # success, all done
71 status=0
72 exit