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 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
22 kill -q $pid1 &> /dev/null
23 kill -q $pid2 &> /dev/null
24 "$KILLALL_PROG" -q $FSSTRESS_PROG &> /dev/null
26 _log_writes_cleanup &> /dev/null
30 # get standard environment, filters and checks
34 . ./common/dmlogwrites
36 # remove previous $seqres.full before test
39 # real QA test starts here
41 # Modify as appropriate.
45 _require_command "$KILLALL_PROG" killall
46 _require_command "$BLKDISCARD_PROG" blkdiscard
47 _require_btrfs_fs_feature "no_holes"
48 _require_btrfs_mkfs_feature "no-holes"
53 # We require a 4K nodesize to ensure the test isn't too slow
54 if [ $(get_page_size) -ne 4096 ]; then
55 _notrun "This test doesn't support non-4K page size yet"
59 nr_cpus=$("$here/src/feature" -o)
60 # cap nr_cpus to 8 to avoid spending too much time on hosts with many cpus
61 if [ $nr_cpus -gt 8 ]; then
64 fsstress_args=$(_scale_fsstress_args -w -d $SCRATCH_MNT -n 99999 -p $nr_cpus \
66 _log_writes_init $SCRATCH_DEV
68 # Discard the whole devices so when some tree pointer is wrong, it won't point
69 # to some older valid tree blocks, so we can detect it.
70 $BLKDISCARD_PROG $LOGWRITES_DMDEV > /dev/null 2>&1
72 # Use no-holes to avoid warnings of missing file extent items (expected
73 # for holes due to mix of buffered and direct IO writes).
74 # And use 4K nodesize to bump tree height.
75 _log_writes_mkfs -O no-holes -n 4k >> $seqres.full
78 $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/src > /dev/null
79 mkdir -p $SCRATCH_MNT/snapshots
80 mkdir -p $SCRATCH_MNT/src/padding
85 echo "$basedir/$(ls $basedir | sort -R | tail -1)"
90 trap "wait; exit" SIGTERM
94 $BTRFS_UTIL_PROG subvolume snapshot \
95 $SCRATCH_MNT/src $SCRATCH_MNT/snapshots/$i \
97 # Do something small to make snapshots different
98 rm -f "$(random_file $SCRATCH_MNT/src/padding)"
99 rm -f "$(random_file $SCRATCH_MNT/src/padding)"
100 touch "$(random_file $SCRATCH_MNT/src/padding)"
101 touch "$SCRATCH_MNT/src/padding/random_$RANDOM"
110 trap "wait; exit" SIGTERM
114 $BTRFS_UTIL_PROG subvolume delete \
115 "$(random_file $SCRATCH_MNT/snapshots)" \
120 # Replay and check each fua/flush (specified by $2) point.
122 # Since dm-log-writes records bio sequentially, even just replaying a range
123 # still needs to iterate all records before the end point.
124 # When number of records grows, it will be unacceptably slow, thus we need
125 # to use relay-log itself to trigger fsck, avoid unnecessary seek.
126 log_writes_fast_replay_check()
130 local fsck_command="$BTRFS_UTIL_PROG check $blkdev"
133 [ -z "$check_point" -o -z "$blkdev" ] && _fail \
134 "check_point and blkdev must be specified for log_writes_fast_replay_check"
136 $here/src/log-writes/replay-log --log $LOGWRITES_DEV \
137 --replay $blkdev --check $check_point --fsck "$fsck_command" \
140 tail -n 150 $tmp.full_fsck > $seqres.full
141 [ $ret -ne 0 ] && _fail "fsck failed during replay"
144 xattr_value=$(printf '%0.sX' $(seq 1 3800))
146 # Bumping tree height to level 2.
147 for ((i = 0; i < 64; i++)); do
148 touch "$SCRATCH_MNT/src/padding/$i"
149 $SETFATTR_PROG -n 'user.x1' -v $xattr_value "$SCRATCH_MNT/src/padding/$i"
152 _log_writes_mark prepare
159 "$FSSTRESS_PROG" $fsstress_args > /dev/null &
162 "$KILLALL_PROG" -q "$FSSTRESS_PROG" &> /dev/null
163 kill $pid1 &> /dev/null
164 kill $pid2 &> /dev/null
169 log_writes_fast_replay_check fua "$SCRATCH_DEV"
171 echo "Silence is golden"