6a19311860c30144c7f99e1a3d133613998600a7
[xfstests-dev.git] / tests / xfs / 137
1 #! /bin/bash
2 # FS QA Test No. 137
3 #
4 # XFS v5 supers carry an LSN in various on-disk structures to track when
5 # associated metadata was last written to disk. These metadata LSNs must always
6 # be behind the current LSN as dictated by the log to ensure log recovery
7 # correctness after a potential crash. This test uses xfs_db to intentionally
8 # put the current LSN behind metadata LSNs and verifies that the kernel and
9 # xfs_repair detect the problem.
10 #
11 #-----------------------------------------------------------------------
12 # Copyright (c) 2015 Red Hat, Inc. All Rights Reserved.
13 #
14 # This program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License as
16 # published by the Free Software Foundation.
17 #
18 # This program is distributed in the hope that it would be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write the Free Software Foundation,
25 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
26 #-----------------------------------------------------------------------
27 #
28
29 seq=`basename $0`
30 seqres=$RESULT_DIR/$seq
31 echo "QA output created by $seq"
32
33 here=`pwd`
34 tmp=/tmp/$$
35 status=1        # failure is the default!
36 trap "_cleanup; exit \$status" 0 1 2 3 15
37
38 _cleanup()
39 {
40         cd /
41         rm -f $tmp.*
42 }
43
44 rm -f $seqres.full
45
46 # get standard environment, filters and checks
47 . ./common/rc
48
49 # real QA test starts here
50
51 # Modify as appropriate.
52 _supported_fs xfs
53 _supported_os Linux
54 _require_scratch
55 _require_scratch_xfs_crc
56 _require_xfs_db_command "logformat"
57
58 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
59
60 # push the log cycle ahead so we have room to move it backwards later
61 _scratch_xfs_db -x -c "logformat -c 3" >> $seqres.full 2>&1
62
63 # do some work on the fs to update metadata LSNs
64 _scratch_mount
65 $FSSTRESS_PROG -d $SCRATCH_MNT -n 999 -p 4 -w >> $seqres.full 2>&1
66 _scratch_unmount
67
68 # Reformat to the current cycle and try to mount. This fails in most cases
69 # because the sb LSN is ahead of the current LSN. If it doesn't fail, push the
70 # cycle back further and try again.
71 _scratch_xfs_db -x -c "logformat" >> $seqres.full 2>&1
72 _try_scratch_mount >> $seqres.full 2>&1
73 if [ $? != 0 ]; then
74         echo mount failure detected
75 else
76         _scratch_unmount
77         _scratch_xfs_db -x -c "logformat -c 2" >> $seqres.full 2>&1
78         _try_scratch_mount >> $seqres.full 2>&1 || echo mount failure detected
79 fi
80
81 # verify that repair detects invalid LSNs as well
82 $XFS_REPAIR_PROG -n $SCRATCH_DEV >> $seqres.full 2>&1 || \
83         echo repair failure detected
84
85 # repair for real so the post-test check can verify repair fixed things up
86 $XFS_REPAIR_PROG $SCRATCH_DEV >> $seqres.full 2>&1
87
88 # success, all done
89 status=0
90 exit