summaryrefslogtreecommitdiff
path: root/tests/btrfs/196
blob: 9602c6f44cbc4e99fdb0b71764a24ce8ed2d0188 (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
95
96
97
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2019 Facebook.  All Rights Reserved.
#
# FS QA Test 196
#
# Test multi subvolume fsync to test a bug where we'd end up pointing at a block
# we haven't written.  This was fixed by the patch
#
# btrfs: fix incorrect updating of log root tree
#
# Will do log replay and check the filesystem.
#
. ./common/preamble
_begin_fstest auto metadata log volume

fio_config=$tmp.fio

# Override the default cleanup function.
_cleanup()
{
	cd /
	_log_writes_cleanup &> /dev/null
	_dmthin_cleanup
	rm -f $tmp.*
}

. ./common/filter
. ./common/dmthin
. ./common/dmlogwrites

_supported_fs btrfs

# Use thin device as replay device, which requires $SCRATCH_DEV
_require_scratch_nocheck
# and we need extra device as log device
_require_log_writes
_require_dm_target thin-pool

cat >$fio_config <<EOF
[global]
readwrite=write
fallocate=none
bs=4k
fsync=1
size=128k
EOF

for i in $(seq 0 49); do
	echo "[foo$i]" >> $fio_config
	echo "filename=$SCRATCH_MNT/$i/file" >> $fio_config
done

_require_fio $fio_config

cat $fio_config >> $seqres.full

# Use a thin device to provide deterministic discard behavior. Discards are used
# by the log replay tool for fast zeroing to prevent out-of-order replay issues.
_dmthin_init
_log_writes_init $DMTHIN_VOL_DEV
_log_writes_mkfs >> $seqres.full 2>&1
_log_writes_mark mkfs

_log_writes_mount

# First create all the subvolumes
for i in $(seq 0 49); do
	$BTRFS_UTIL_PROG subvolume create "$SCRATCH_MNT/$i" > /dev/null
done

$FIO_PROG $fio_config > /dev/null 2>&1
_log_writes_unmount

_log_writes_remove
prev=$(_log_writes_mark_to_entry_number mkfs)
[ -z "$prev" ] && _fail "failed to locate entry mark 'mkfs'"
cur=$(_log_writes_find_next_fua $prev)
[ -z "$cur" ] && _fail "failed to locate next FUA write"

while [ ! -z "$cur" ]; do
	_log_writes_replay_log_range $cur $DMTHIN_VOL_DEV >> $seqres.full

	# We need to mount the fs because btrfsck won't bother checking the log.
	_dmthin_mount
	_dmthin_check_fs

	prev=$cur
	cur=$(_log_writes_find_next_fua $(($cur + 1)))
	[ -z "$cur" ] && break
done

echo "Silence is golden"

# success, all done
status=0
exit