misc: move exit status into trap handler
[xfstests-dev.git] / tests / xfs / 097
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. 097
6 #
7 # Create and populate an XFS filesystem, corrupt the finobt, 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 _require_xfs_mkfs_finobt
36 _require_xfs_finobt
37 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
38 _require_attrs
39 _require_populate_commands
40 _require_xfs_db_blocktrash_z_command
41 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
42
43 rm -f $seqres.full
44 TESTDIR="${SCRATCH_MNT}/scratchdir"
45 TESTFILE="${TESTDIR}/testfile"
46
47 echo "+ create scratch fs"
48 _scratch_mkfs_xfs -m crc=1,finobt=1 > /dev/null
49
50 echo "+ mount fs image"
51 _scratch_mount
52 $XFS_INFO_PROG "${SCRATCH_MNT}" | grep -q "finobt=1" || _notrun "finobt not enabled"
53 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
54
55 echo "+ make some files"
56 mkdir -p "${TESTDIR}"
57 for x in `seq 1 1024`; do
58         touch "${SCRATCH_MNT}/junk.${x}"
59         inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
60         if [ "$x" -gt 512 ] && [ "$((inode % 64))" -eq 0 ]; then
61                 mv "${SCRATCH_MNT}/junk.${x}" "${TESTFILE}.1"
62                 break
63         fi
64 done
65 for x in `seq 2 64`; do
66         touch "${TESTFILE}.${x}"
67 done
68 inode="$(stat -c '%i' "${TESTFILE}.1")"
69 agcount="$(_xfs_mount_agcount $SCRATCH_MNT)"
70 umount "${SCRATCH_MNT}"
71
72 echo "+ check fs"
73 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
74
75 echo "+ corrupt image"
76 for ag in $(seq 1 $((agcount - 1))) 0; do
77         _scratch_xfs_db -x -c "agi ${ag}" -c "agi ${ag}" -c "addr free_root" -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full 2>&1
78 done
79
80 echo "+ mount image && modify files"
81 broken=1
82 if _try_scratch_mount >> $seqres.full 2>&1; then
83         for x in `seq 65 70`; do
84                 touch "${TESTFILE}.${x}" 2> /dev/null && broken=0
85         done
86         umount "${SCRATCH_MNT}"
87 fi
88 echo "broken: ${broken}"
89
90 echo "+ repair fs"
91 _repair_scratch_fs >> $seqres.full 2>&1
92
93 echo "+ mount image (2)"
94 _scratch_mount
95
96 echo "+ chattr -R -i"
97 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
98
99 echo "+ modify files (2)"
100 broken=0
101 for x in `seq 65 70`; do
102         touch "${TESTFILE}.${x}" || broken=1
103 done
104 echo "broken: ${broken}"
105 umount "${SCRATCH_MNT}"
106
107 echo "+ check fs (2)"
108 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
109
110 status=0
111 exit