59ac0433ec188546cf78b865ed0e815a3f4e4d95
[xfstests-dev.git] / tests / xfs / 120
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 120
6 #
7 # Create and populate an XFS filesystem, corrupt the bmbt, then see how
8 # 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 . ./common/populate
30
31 # real QA test starts here
32 _supported_fs xfs
33
34 _require_scratch
35 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
36 _require_attrs
37 _require_populate_commands
38 _require_xfs_db_blocktrash_z_command
39 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
40
41 rm -f $seqres.full
42
43 echo "+ create scratch fs"
44 _scratch_mkfs_xfs > /dev/null
45
46 echo "+ mount fs image"
47 _scratch_mount
48 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
49 nr="$((blksz * 2 / 16))"
50
51 echo "+ make some files"
52 $XFS_IO_PROG -f -c "pwrite -S 0x62 0 $((blksz * nr))" -c 'fsync' "${SCRATCH_MNT}/bigfile" >> $seqres.full
53 for i in $(seq 1 2 ${nr}); do
54         $XFS_IO_PROG -f -c "fpunch $((i * blksz)) ${blksz}" "${SCRATCH_MNT}/bigfile" >> $seqres.full
55 done
56 inode="$(stat -c '%i' "${SCRATCH_MNT}/bigfile")"
57 umount "${SCRATCH_MNT}"
58
59 echo "+ check fs"
60 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
61
62 echo "+ corrupt image"
63 _scratch_xfs_db -x -c "inode ${inode}" -c "addr u.bmbt.ptrs[1]" -c "addr u3.bmbt.ptrs[1]" -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full
64
65 echo "+ mount image && modify files"
66 if _try_scratch_mount >> $seqres.full 2>&1; then
67
68         before="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")"
69         $XFS_IO_PROG -f -c "pwrite -S 0x62 ${blksz} ${blksz}" -c 'fsync' "${SCRATCH_MNT}/bigfile" >> $seqres.full 2> /dev/null
70         after="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")"
71         test "${before}" -eq "${after}" || _fail "pwrite should fail on corrupt bmbt"
72         umount "${SCRATCH_MNT}"
73 fi
74
75 echo "+ repair fs"
76 _scratch_xfs_repair >> $seqres.full 2>&1
77
78 echo "+ mount image (2)"
79 _scratch_mount
80
81 echo "+ chattr -R -i"
82 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
83
84 echo "+ modify files (2)"
85 touch "${SCRATCH_MNT}/bigfile"
86 before="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")"
87 $XFS_IO_PROG -f -c "pwrite -S 0x62 ${blksz} ${blksz}" -c 'fsync' "${SCRATCH_MNT}/bigfile" >> $seqres.full 2> /dev/null
88 after="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")"
89 test "${before}" -ne "${after}" || _fail "pwrite failed after fixing corrupt bmbt"
90 umount "${SCRATCH_MNT}"
91
92 echo "+ check fs (2)"
93 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
94
95 status=0
96 exit