xfs/007: fix regressions on V4 filesystems
[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 . ./common/preamble
15 _begin_fstest auto metadata v2log
16
17 # Import common functions.
18
19 # real QA test starts here
20
21 # Modify as appropriate.
22 _supported_fs xfs
23 _require_scratch
24 _require_scratch_xfs_crc
25 _require_xfs_db_command "logformat"
26
27 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
28
29 # push the log cycle ahead so we have room to move it backwards later
30 _scratch_xfs_db -x -c "logformat -c 3" >> $seqres.full 2>&1
31
32 # do some work on the fs to update metadata LSNs
33 _scratch_mount
34 $FSSTRESS_PROG -d $SCRATCH_MNT -n 999 -p 4 -w >> $seqres.full 2>&1
35 _scratch_unmount
36
37 # Reformat to the current cycle and try to mount. This fails in most cases
38 # because the sb LSN is ahead of the current LSN. If it doesn't fail, push the
39 # cycle back further and try again.
40 _scratch_xfs_db -x -c "logformat" >> $seqres.full 2>&1
41 _try_scratch_mount >> $seqres.full 2>&1
42 if [ $? != 0 ]; then
43         echo mount failure detected
44 else
45         _scratch_unmount
46         _scratch_xfs_db -x -c "logformat -c 2" >> $seqres.full 2>&1
47         _try_scratch_mount >> $seqres.full 2>&1 || echo mount failure detected
48 fi
49
50 # verify that repair detects invalid LSNs as well
51 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
52         echo repair failure detected
53
54 # repair for real so the post-test check can verify repair fixed things up
55 _scratch_xfs_repair >> $seqres.full 2>&1
56
57 # success, all done
58 status=0
59 exit