misc: move exit status into trap handler
[xfstests-dev.git] / tests / xfs / 137
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Red Hat, Inc. All Rights Reserved.
4 #
5 # FS QA Test No. 137
6 #
7 # XFS v5 supers carry an LSN in various on-disk structures to track when
8 # associated metadata was last written to disk. These metadata LSNs must always
9 # be behind the current LSN as dictated by the log to ensure log recovery
10 # correctness after a potential crash. This test uses xfs_db to intentionally
11 # put the current LSN behind metadata LSNs and verifies that the kernel and
12 # xfs_repair detect the problem.
13 #
14 seq=`basename $0`
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
17
18 here=`pwd`
19 tmp=/tmp/$$
20 status=1        # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
22
23 _cleanup()
24 {
25         cd /
26         rm -f $tmp.*
27 }
28
29 rm -f $seqres.full
30
31 # get standard environment, filters and checks
32 . ./common/rc
33
34 # real QA test starts here
35
36 # Modify as appropriate.
37 _supported_fs xfs
38 _require_scratch
39 _require_scratch_xfs_crc
40 _require_xfs_db_command "logformat"
41
42 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
43
44 # push the log cycle ahead so we have room to move it backwards later
45 _scratch_xfs_db -x -c "logformat -c 3" >> $seqres.full 2>&1
46
47 # do some work on the fs to update metadata LSNs
48 _scratch_mount
49 $FSSTRESS_PROG -d $SCRATCH_MNT -n 999 -p 4 -w >> $seqres.full 2>&1
50 _scratch_unmount
51
52 # Reformat to the current cycle and try to mount. This fails in most cases
53 # because the sb LSN is ahead of the current LSN. If it doesn't fail, push the
54 # cycle back further and try again.
55 _scratch_xfs_db -x -c "logformat" >> $seqres.full 2>&1
56 _try_scratch_mount >> $seqres.full 2>&1
57 if [ $? != 0 ]; then
58         echo mount failure detected
59 else
60         _scratch_unmount
61         _scratch_xfs_db -x -c "logformat -c 2" >> $seqres.full 2>&1
62         _try_scratch_mount >> $seqres.full 2>&1 || echo mount failure detected
63 fi
64
65 # verify that repair detects invalid LSNs as well
66 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
67         echo repair failure detected
68
69 # repair for real so the post-test check can verify repair fixed things up
70 _scratch_xfs_repair >> $seqres.full 2>&1
71
72 # success, all done
73 status=0
74 exit