2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test btrfs consistency after each FUA for a workload with snapshot creation
11 _begin_fstest auto replay snapshot stress recoveryloop
13 # Override the default cleanup function.
17 kill -q $pid1 &> /dev/null
18 kill -q $pid2 &> /dev/null
19 "$KILLALL_PROG" -q $FSSTRESS_PROG &> /dev/null
21 _log_writes_cleanup &> /dev/null
25 # Import common functions.
28 . ./common/dmlogwrites
30 # real QA test starts here
32 # Modify as appropriate.
35 _require_command "$KILLALL_PROG" killall
36 _require_command "$BLKDISCARD_PROG" blkdiscard
37 _require_btrfs_fs_feature "no_holes"
38 _require_btrfs_mkfs_feature "no-holes"
43 # We require a 4K nodesize to ensure the test isn't too slow
44 if [ $(_get_page_size) -ne 4096 ]; then
45 _notrun "This test doesn't support non-4K page size yet"
49 nr_cpus=$("$here/src/feature" -o)
50 # cap nr_cpus to 8 to avoid spending too much time on hosts with many cpus
51 if [ $nr_cpus -gt 8 ]; then
54 fsstress_args=$(_scale_fsstress_args -w -d $SCRATCH_MNT -n 99999 -p $nr_cpus \
56 _log_writes_init $SCRATCH_DEV
58 # Discard the whole devices so when some tree pointer is wrong, it won't point
59 # to some older valid tree blocks, so we can detect it.
60 $BLKDISCARD_PROG $LOGWRITES_DMDEV > /dev/null 2>&1
62 # Use no-holes to avoid warnings of missing file extent items (expected
63 # for holes due to mix of buffered and direct IO writes).
64 # And use 4K nodesize to bump tree height.
65 _log_writes_mkfs -O no-holes -n 4k >> $seqres.full
68 $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/src > /dev/null
69 mkdir -p $SCRATCH_MNT/snapshots
70 mkdir -p $SCRATCH_MNT/src/padding
74 trap "wait; exit" SIGTERM
78 $BTRFS_UTIL_PROG subvolume snapshot \
79 $SCRATCH_MNT/src $SCRATCH_MNT/snapshots/$i \
81 # Do something small to make snapshots different
82 rm -f "$(_random_file $SCRATCH_MNT/src/padding)"
83 rm -f "$(_random_file $SCRATCH_MNT/src/padding)"
84 touch "$(_random_file $SCRATCH_MNT/src/padding)"
85 touch "$SCRATCH_MNT/src/padding/random_$RANDOM"
94 trap "wait; exit" SIGTERM
98 $BTRFS_UTIL_PROG subvolume delete \
99 "$(_random_file $SCRATCH_MNT/snapshots)" \
104 # Replay and check each fua/flush (specified by $2) point.
106 # Since dm-log-writes records bio sequentially, even just replaying a range
107 # still needs to iterate all records before the end point.
108 # When number of records grows, it will be unacceptably slow, thus we need
109 # to use relay-log itself to trigger fsck, avoid unnecessary seek.
110 log_writes_fast_replay_check()
114 local fsck_command="$BTRFS_UTIL_PROG check $blkdev"
117 [ -z "$check_point" -o -z "$blkdev" ] && _fail \
118 "check_point and blkdev must be specified for log_writes_fast_replay_check"
120 $here/src/log-writes/replay-log --log $LOGWRITES_DEV \
121 --replay $blkdev --check $check_point --fsck "$fsck_command" \
124 tail -n 150 $tmp.full_fsck >> $seqres.full
125 [ $ret -ne 0 ] && _fail "fsck failed during replay"
128 xattr_value=$(printf '%0.sX' $(seq 1 3800))
130 # Bumping tree height to level 2.
131 for ((i = 0; i < 64; i++)); do
132 touch "$SCRATCH_MNT/src/padding/$i"
133 $SETFATTR_PROG -n 'user.x1' -v $xattr_value "$SCRATCH_MNT/src/padding/$i"
136 _log_writes_mark prepare
143 "$FSSTRESS_PROG" $fsstress_args >> $seqres.full &
146 "$KILLALL_PROG" -q "$FSSTRESS_PROG" &> /dev/null
147 kill $pid1 &> /dev/null
148 kill $pid2 &> /dev/null
153 log_writes_fast_replay_check fua "$SCRATCH_DEV"
155 echo "Silence is golden"