btrfs: add a test for multi-subvolume fsyncing
authorJosef Bacik <josef@toxicpanda.com>
Mon, 7 Oct 2019 19:33:39 +0000 (15:33 -0400)
committerEryu Guan <guaneryu@gmail.com>
Sun, 13 Oct 2019 13:01:41 +0000 (21:01 +0800)
I discovered a problem in btrfs where we'd end up pointing at a block we
hadn't written out yet.  This is triggered by a race when two different
files on two different subvolumes fsync.  This test exercises this path
with dm-log-writes, and then replays the log at every FUA to verify the
file system is still mountable and the log is replayable.

This test is to verify the fix

btrfs: fix incorrect updating of log root tree

actually fixed the problem.

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
tests/btrfs/196 [new file with mode: 0755]
tests/btrfs/196.out [new file with mode: 0644]
tests/btrfs/group

diff --git a/tests/btrfs/196 b/tests/btrfs/196
new file mode 100755 (executable)
index 0000000..9a3435d
--- /dev/null
@@ -0,0 +1,110 @@
+#! /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.
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+fio_config=$tmp.fio
+status=1       # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+       cd /
+       _log_writes_cleanup &> /dev/null
+       _dmthin_cleanup
+       rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/dmthin
+. ./common/dmlogwrites
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs btrfs
+_supported_os Linux
+
+# 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
diff --git a/tests/btrfs/196.out b/tests/btrfs/196.out
new file mode 100644 (file)
index 0000000..477dcf0
--- /dev/null
@@ -0,0 +1,2 @@
+QA output created by 196
+Silence is golden
index 3ce6fa4628d8a3a1307d602a9e4fdd0a095471af..c2ab3e7de9b683b1b7141c498a4c04fae08f81a0 100644 (file)
 193 auto quick qgroup enospc limit
 194 auto volume
 195 auto volume
+196 auto metadata log volume