All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org, fstests@vger.kernel.org
Subject: [PATCH] btrfs: add test case for NODATASUM dev-replace
Date: Thu, 23 Feb 2023 13:10:49 +0800	[thread overview]
Message-ID: <20230223051049.30086-1-wqu@suse.com> (raw)

During my development on dev-replace, I made a mistake in RAID56
dev-replace code where it can lead to NODATASUM corruption.
Thankfully such corruption didn't reach upstream.

Inspired by such incident, here comes a new test case for btrfs
dev-replace, the new case would:

- Populate the filesystem with nodatasum mount option

- Run fssum to record the contents
  Since the test case only cares about data contents, here we don't
  include metadata like uid/gid/timestamp.

- Wipe one device

- Mount the fs with the missing device

- Verify the contents is still correct

- Replace the missing device

- Verify the contents is still correct again
  Before the verification, drop all cache to make sure the 2nd
  verification is reading from the disks.

For current kernels, the test case should pass as expected.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 tests/btrfs/286     | 78 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/286.out |  2 ++
 2 files changed, 80 insertions(+)
 create mode 100755 tests/btrfs/286
 create mode 100644 tests/btrfs/286.out

diff --git a/tests/btrfs/286 b/tests/btrfs/286
new file mode 100755
index 00000000..fb805256
--- /dev/null
+++ b/tests/btrfs/286
@@ -0,0 +1,78 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2023 SUSE Linux Products GmbH. All Rights Reserved.
+#
+# FS QA Test 286
+#
+# Make sure btrfs dev-replace on missing device won't cause data corruption
+# for NODATASUM data.
+#
+. ./common/preamble
+_begin_fstest auto replace
+
+# Import common functions.
+. ./common/filter
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs btrfs
+_require_command "$WIPEFS_PROG" wipefs
+_btrfs_get_profile_configs replace-missing
+_require_fssum
+_require_scratch_dev_pool 5
+_scratch_dev_pool_get 4
+_spare_dev_get
+
+workload()
+{
+	local profile=$1
+	local victim="$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')"
+
+	echo "=== Profile: $profile ===" >> $seqres.full
+	rm -f $tmp.fssum
+	_scratch_pool_mkfs "$profile" >> $seqres.full 2>&1
+
+	# Use nodatasum mount option, so all data won't have checksum.
+	_scratch_mount -o nodatasum
+
+	$FSSTRESS_PROG -p 10 -n 200 -d $SCRATCH_MNT > /dev/null 2>&1
+	sync
+
+	# Generate fssum for later verification, here we only care
+	# about the file contents, thus we don't bother metadata at all.
+	$FSSUM_PROG -n -d -f -w $tmp.fssum $SCRATCH_MNT
+	_scratch_unmount
+
+	# Wipe devid 2
+	$WIPEFS_PROG -a $victim >> $seqres.full 2>&1
+
+	# Mount the fs with the victim device missing
+	_scratch_mount -o degraded,nodatasum
+
+	# Verify no data corruption first.
+	echo "=== Verify the contents before replace ===" >> $seqres.full
+	$FSSUM_PROG -r $tmp.fssum $SCRATCH_MNT >> $seqres.full 2>&1
+
+	# Replace the missing device
+	$BTRFS_UTIL_PROG replace start -Bf 2 $SPARE_DEV $SCRATCH_MNT >> $seqres.full
+
+	# Drop all cache to make sure later read are all from the disks
+	echo 3 > /proc/sys/vm/drop_caches
+
+	# Re-check the file contents
+	echo "=== Verify the contents after replace ===" >> $seqres.full
+	$FSSUM_PROG -r $tmp.fssum $SCRATCH_MNT >> $seqres.full 2>&1
+
+	_scratch_unmount
+}
+
+for t in "${_btrfs_profile_configs[@]}"; do
+	workload "$t"
+done
+
+echo "Silence is golden"
+
+# success, all done
+status=0
+exit
diff --git a/tests/btrfs/286.out b/tests/btrfs/286.out
new file mode 100644
index 00000000..35c48006
--- /dev/null
+++ b/tests/btrfs/286.out
@@ -0,0 +1,2 @@
+QA output created by 286
+Silence is golden
-- 
2.39.0


             reply	other threads:[~2023-02-23  5:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-23  5:10 Qu Wenruo [this message]
2023-02-25 14:04 ` [PATCH] btrfs: add test case for NODATASUM dev-replace Zorro Lang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230223051049.30086-1-wqu@suse.com \
    --to=wqu@suse.com \
    --cc=fstests@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.