diff mbox series

[v2] fstests: btrfs test read from disks of different generation

Message ID 1586174426-6016-1-git-send-email-anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series [v2] fstests: btrfs test read from disks of different generation | expand

Commit Message

Anand Jain April 6, 2020, noon UTC
Verify file read from disks assembled with different generations.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
(Not yet for the integration, prerequisites are not yet integrated)

v2: rebase.
    use the sysfs interface to set the read_policy instead of mount

 tests/btrfs/210     | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/210.out |  12 +++++
 tests/btrfs/group   |   1 +
 3 files changed, 160 insertions(+)
 create mode 100755 tests/btrfs/210
 create mode 100644 tests/btrfs/210.out
diff mbox series

Patch

diff --git a/tests/btrfs/210 b/tests/btrfs/210
new file mode 100755
index 000000000000..df51ab584688
--- /dev/null
+++ b/tests/btrfs/210
@@ -0,0 +1,147 @@ 
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2019 Oracle.  All Rights Reserved.
+#
+# FS QA Test ?
+#
+# Test read on raid1 assembled with disks of different generations.
+#  Steps:
+#   . Use btrfs snapshot on the test_dir to create disk images of
+#     different generations (lets say generation a and generation b).
+#   . Mount one disk from generation a and another disk from generation
+#     b, and verify the file md5sum.
+#  Note: readmirror feature (in the btrfs ml) helps to reproduce the
+#     problem consistently.
+#  Fix-by: kernel patch
+#   NA
+#  Temp workaroud fix for two disk raid1:
+#   [PATCH] btrfs: fix read corrpution on disks of different generation
+#  Needs read_policy patch-set to test:
+#   [PATCH v7 0/5] readmirror feature (sysfs and in-memory only approach; with new read_policy device)
+
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+	_scratch_unmount > /dev/null 2>&1
+	_destroy_loop_device $dev1
+	_destroy_loop_device $dev2
+	btrfs subvolume delete $img_subvol > /dev/null 2>&1
+	btrfs subvolume delete $img_subvol_at_gen_a > /dev/null 2>&1
+	[[ -z $scratch_dev_pool_saved ]] || \
+			SCRATCH_DEV_POOL="$scratch_dev_pool_saved"
+	_scratch_dev_pool_put
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs generic
+_supported_os Linux
+_require_test
+_require_scratch_dev_pool 2
+_require_btrfs_forget_or_module_loadable
+
+_btrfs_forget_or_module_reload
+
+_scratch_dev_pool_get 2
+scratch_dev_pool_saved=""
+
+img_subvol=$TEST_DIR/img_subvol
+img_subvol_at_gen_a=$TEST_DIR/img_subvol_at_gen_a
+dev1_img=$img_subvol/d1
+dev2_img=$img_subvol/d2
+dev1_img_at_gen_a=$img_subvol_at_gen_a/d1
+dev2_img_at_gen_a=$img_subvol_at_gen_a/d2
+
+$BTRFS_UTIL_PROG subvolume create $img_subvol >> /dev/null 2>&1 || \
+					_fail "subvol create failed"
+
+$XFS_IO_PROG -f -c "pwrite -S 0xdd 0 256m" $dev1_img >> /dev/null 2>&1
+$XFS_IO_PROG -f -c "pwrite -S 0xdd 0 256m" $dev2_img >> /dev/null 2>&1
+
+dev1=$(_create_loop_device $dev1_img)
+dev2=$(_create_loop_device $dev2_img)
+
+scratch_dev_pool_saved="$SCRATCH_DEV_POOL"
+SCRATCH_DEV_POOL="$dev1 $dev2"
+_scratch_pool_mkfs -U 12345678-1234-1234-1234-123456789abc -d raid1 -m raid1 >>\
+		$seqres.full 2>&1 || _fail  "mkfs failed on $SCRATCH_DEV_POOL"
+
+
+_mount "-o max_inline=0,nodatacow,device=$dev1" $dev2 $SCRATCH_MNT || \
+					_fail "mount for gen a failed"
+
+$XFS_IO_PROG -f -c "pwrite -S 0xaa 0 4K" $SCRATCH_MNT/foobar >> /dev/null 2>&1
+
+echo md5sum at generation aa
+md5sum $SCRATCH_MNT/foobar | _filter_scratch
+echo
+_scratch_unmount
+
+$BTRFS_UTIL_PROG subvolume snapshot $img_subvol $img_subvol_at_gen_a \
+		>> /dev/null 2>&1 || _fail "subvol create failed"
+
+_mount "-o max_inline=0,nodatacow,device=$dev1" $dev2 $SCRATCH_MNT || \
+					_fail "mount for gen b failed"
+
+$XFS_IO_PROG -f -c "pwrite -S 0xbb 0 4K" $SCRATCH_MNT/foobar >> /dev/null 2>&1
+
+echo md5sum at generation bb
+md5sum $SCRATCH_MNT/foobar | _filter_scratch
+echo
+
+_scratch_unmount
+
+_destroy_loop_device $dev1
+_destroy_loop_device $dev2
+
+_test_unmount
+_btrfs_forget_or_module_reload
+_test_mount
+
+dev1=$(_create_loop_device $dev1_img_at_gen_a)
+dev2=$(_create_loop_device $dev2_img)
+
+_mount "-o ro,device=$dev1" $dev2 $SCRATCH_MNT || _fail "mount at gen ab failed"
+
+SCRATCH_SYSFS_PATH="/sys/fs/btrfs/12345678-1234-1234-1234-123456789abc"
+
+devid_for_read=$($BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT| grep $dev1 |\
+							awk '{print $2}')
+echo 1 > $SCRATCH_SYSFS_PATH/devinfo/$devid_for_read/read_preferred
+echo "device" > $SCRATCH_SYSFS_PATH/read_policy
+
+echo md5sum at generation ab read from devid=$devid_for_read
+md5sum $SCRATCH_MNT/foobar | _filter_scratch
+
+echo 1 > /proc/sys/vm/drop_caches
+echo 0 > $SCRATCH_SYSFS_PATH/devinfo/$devid_for_read/read_preferred
+devid_for_read=$($BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT| grep $dev2 |\
+							awk '{print $2}')
+echo 1 > $SCRATCH_SYSFS_PATH/devinfo/$devid_for_read/read_preferred
+
+echo
+echo md5sum at generation ab read from devid=$devid_for_read
+md5sum $SCRATCH_MNT/foobar | _filter_scratch
+
+# success, all done
+status=0
+exit
diff --git a/tests/btrfs/210.out b/tests/btrfs/210.out
new file mode 100644
index 000000000000..b55030fea1fa
--- /dev/null
+++ b/tests/btrfs/210.out
@@ -0,0 +1,12 @@ 
+QA output created by 210
+md5sum at generation aa
+3e4309c7cc81f23d45e260a8f13ca860  SCRATCH_MNT/foobar
+
+md5sum at generation bb
+055a2a7342c0528969e1b6e32aadeee3  SCRATCH_MNT/foobar
+
+md5sum at generation ab read from devid=1
+055a2a7342c0528969e1b6e32aadeee3  SCRATCH_MNT/foobar
+
+md5sum at generation ab read from devid=2
+055a2a7342c0528969e1b6e32aadeee3  SCRATCH_MNT/foobar
diff --git a/tests/btrfs/group b/tests/btrfs/group
index 657ec548159b..3f71ce235d96 100644
--- a/tests/btrfs/group
+++ b/tests/btrfs/group
@@ -212,3 +212,4 @@ 
 207 auto rw raid
 208 auto quick subvol
 209 auto quick log
+210 auto quick volume