summaryrefslogtreecommitdiff
path: root/tests/xfs/605
blob: 78458c76657f298845d51c9d90cc0597dd5a0f9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2024 Oracle, Inc.  All Rights Reserved.
#
# FS QA Test No. 605
#
# Test metadump/mdrestore's ability to dump a dirty log and restore it
# correctly.
#
. ./common/preamble
_begin_fstest auto quick metadump log logprint punch

# Override the default cleanup function.
_cleanup()
{
	cd /
	rm -r -f $tmp.*
	_xfs_cleanup_verify_metadump
}

# Import common functions.
. ./common/dmflakey
. ./common/inject
. ./common/metadump

# real QA test starts here
_supported_fs xfs
_require_scratch
_require_test
_require_loop
_require_xfs_debug
_require_xfs_io_error_injection log_item_pin
_require_dm_target flakey
_require_xfs_io_command "pwrite"
_require_test_program "punch-alternating"
_xfs_setup_verify_metadump

testfile=${SCRATCH_MNT}/testfile

echo "Format filesystem on scratch device"
_scratch_mkfs >> $seqres.full 2>&1

echo "Initialize and mount filesystem on flakey device"
_init_flakey
_load_flakey_table $FLAKEY_ALLOW_WRITES
_mount_flakey

echo "Create test file"
$XFS_IO_PROG -s -f -c "pwrite 0 5M" $testfile >> $seqres.full

echo "Punch alternative blocks of test file"
$here/src/punch-alternating $testfile

echo "Mount cycle the filesystem on flakey device"
_unmount_flakey
_mount_flakey

device=$(readlink -f $FLAKEY_DEV)
device=$(_short_dev $device)

echo "Pin log items in the AIL"
echo 1 > /sys/fs/xfs/${device}/errortag/log_item_pin

echo "Create two checkpoint transactions on ondisk log"
for ct in $(seq 1 2); do
	offset=$($XFS_IO_PROG -c 'fiemap' $testfile | tac |  grep -v hole | \
			 head -n 1 | awk -F '[\\[.]' '{ print $2 * 512; }')
	$XFS_IO_PROG -c "truncate $offset" -c fsync $testfile
done

echo "Drop writes to filesystem from here onwards"
_load_flakey_table $FLAKEY_DROP_WRITES

echo "Unpin log items in AIL"
echo 0 > /sys/fs/xfs/${device}/errortag/log_item_pin

echo "Unmount filesystem on flakey device"
_unmount_flakey

echo "Clean up flakey device"
_cleanup_flakey

echo -n "Filesystem has a "
_print_logstate

echo "Create metadump file, restore it and check restored fs"
_xfs_verify_metadumps '-a -o'

# Mount the fs to replay the contents from the dirty log.
_scratch_mount

# success, all done
status=0
exit