All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/6] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL
@ 2016-05-17 14:32 Anand Jain
  2016-05-17 14:32 ` [PATCH 2/6] fstests: btrfs: add functions to get and put a device for replace target Anand Jain
                   ` (6 more replies)
  0 siblings, 7 replies; 32+ messages in thread
From: Anand Jain @ 2016-05-17 14:32 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs, Anand Jain

This patch provides functions
 _scratch_dev_pool_get()
 _scratch_dev_pool_put()

Which will help to set/reset SCRATCH_DEV_POOL with the required
number of devices. SCRATCH_DEV_POOL_SAVED will hold all the devices.

Usage:
  _scratch_dev_pool_get() <ndevs>
  :: do stuff

  _scratch_dev_pool_put()

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 common/rc | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/common/rc b/common/rc
index 91e8f1c8e693..33632fd8e4a3 100644
--- a/common/rc
+++ b/common/rc
@@ -786,6 +786,53 @@ _scratch_mkfs()
     esac
 }
 
+#
+# $1 Number of the scratch devs required
+#
+_scratch_dev_pool_get()
+{
+	if [ $# != 1 ]; then
+		_fail "Usage: _scratch_dev_pool_get ndevs"
+	fi
+
+	local test_ndevs=$1
+	local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
+	local devs[]="( $SCRATCH_DEV_POOL )"
+
+	typeset -p config_ndevs >/dev/null 2>&1
+	if [ $? != 0 ]; then
+		_fail "Bug: unset val, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
+	fi
+
+	# _require_scratch_dev_pool $test_ndevs
+	# must have already checked the min required devices
+	# but just in case, trap here for any potential bugs
+	# perpetuating any further
+	if [ $config_ndevs -lt $test_ndevs ]; then
+		_notrun "Need at least test requested number of ndevs $test_ndevs"
+	fi
+
+	SCRATCH_DEV_POOL_SAVED=${SCRATCH_DEV_POOL}
+	export SCRATCH_DEV_POOL_SAVED
+	SCRATCH_DEV_POOL=${devs[@]:0:$test_ndevs}
+	export SCRATCH_DEV_POOL
+}
+
+_scratch_dev_pool_put()
+{
+	typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
+	if [ $? != 0 ]; then
+		_fail "Bug: unset val, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
+	fi
+
+	if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
+		_fail "Bug: str empty, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
+	fi
+
+	export SCRATCH_DEV_POOL=$SCRATCH_DEV_POOL_SAVED
+	export SCRATCH_DEV_POOL_SAVED=""
+}
+
 _scratch_pool_mkfs()
 {
     case $FSTYP in
-- 
2.7.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 2/6] fstests: btrfs: add functions to get and put a device for replace target
  2016-05-17 14:32 [PATCH 1/6] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL Anand Jain
@ 2016-05-17 14:32 ` Anand Jain
  2016-06-12  4:42   ` Eryu Guan
  2016-06-15  8:47   ` [PATCH v2 " Anand Jain
  2016-05-17 14:32 ` [PATCH 3/6] fstests: btrfs: 027 make use of new device get and put helper functions Anand Jain
                   ` (5 subsequent siblings)
  6 siblings, 2 replies; 32+ messages in thread
From: Anand Jain @ 2016-05-17 14:32 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs, Anand Jain

For the replace tests we need a device as a spare device,
here functions _spare_dev_get() and _spare_dev_put()
will get it from the SCRATCH_DEV_POOL_SAVED, which is set
when _scratch_dev_pool_get() is called, and is based on how
many has already been assigned to SCRATCH_DEV_POOL.

 usage:
   _scratch_dev_pool_get 3
   _spare_dev_get

      SPARE_DEV will have a device set which can be
      used as the replace target device.

   _spare_dev_put
   _scratch_dev_pool_put

_spare_dev_get() will pick the next device after SCRATCH_DEV_POOL
devices, from the SCRATCH_DEV_POOL_SAVED, and assigns it to
SPARE_DEV. _spare_dev_put() will set to SPARE_DEV to null.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 common/rc | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/common/rc b/common/rc
index 33632fd8e4a3..f2b39ddbee0c 100644
--- a/common/rc
+++ b/common/rc
@@ -786,6 +786,51 @@ _scratch_mkfs()
     esac
 }
 
+_spare_dev_get()
+{
+	typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
+	if [ $? != 0 ]; then
+		_fail "Bug: unset val, must call _scratch_dev_pool_get before _spare_dev_get"
+	fi
+
+	if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
+		_fail "Bug: str empty, must call _scratch_dev_pool_get before _spare_dev_get"
+	fi
+
+	# Check if the spare is already assigned
+	typeset -p SPARE_DEV >/dev/null 2>&1
+	if [ $? == 0 ]; then
+		if [ ! -z "$SPARE_DEV" ]; then
+			_fail "Bug: SPARE_DEV = $SPARE_DEV already assigned"
+		fi
+	fi
+
+	local ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
+	local config_ndevs=`echo $SCRATCH_DEV_POOL_SAVED| wc -w`
+
+	if [ $ndevs -eq $config_ndevs ]; then
+		_notrun "All devs used no spare"
+	fi
+	# Get a dev that is not used
+	local devs[]="( $SCRATCH_DEV_POOL_SAVED )"
+	SPARE_DEV=${devs[@]:$ndevs:1}
+	export SPARE_DEV
+}
+
+_spare_dev_put()
+{
+	typeset -p SPARE_DEV >/dev/null 2>&1
+	if [ $? != 0 ]; then
+		_fail "Bug: unset val, must call _spare_dev_get before its put"
+	fi
+
+	if [ -z "$SPARE_DEV" ]; then
+		_fail "Bug: str empty, must call _spare_dev_get before its put"
+	fi
+
+	export SPARE_DEV=""
+}
+
 #
 # $1 Number of the scratch devs required
 #
-- 
2.7.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 3/6] fstests: btrfs: 027 make use of new device get and put helper functions
  2016-05-17 14:32 [PATCH 1/6] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL Anand Jain
  2016-05-17 14:32 ` [PATCH 2/6] fstests: btrfs: add functions to get and put a device for replace target Anand Jain
@ 2016-05-17 14:32 ` Anand Jain
  2016-05-17 14:32 ` [PATCH 4/6] fstests: btrfs: add helper function to check if btrfs is module Anand Jain
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 32+ messages in thread
From: Anand Jain @ 2016-05-17 14:32 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs, Anand Jain

Below patches added helper function to get the requested
number of devices for scratch and spare device

fstest: btrfs: add functions to get and put a device for replace target
fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL

This patch makes use of them.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 tests/btrfs/027 | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/tests/btrfs/027 b/tests/btrfs/027
index f0844a14f8e6..905dc0ebaa27 100755
--- a/tests/btrfs/027
+++ b/tests/btrfs/027
@@ -57,17 +57,22 @@ _require_command "$WIPEFS_PROG" wipefs
 run_test()
 {
 	local mkfs_opts=$1
-	local saved_scratch_dev_pool=$SCRATCH_DEV_POOL
-	local replace_dev=`echo $SCRATCH_DEV_POOL | awk '{print $NF}'`
+	local ndevs=`echo $SCRATCH_DEV_POOL | wc -w`
+
+	# reserve one for replace target
+	((ndevs--))
+
+	_scratch_dev_pool_get $ndevs
+	_spare_dev_get
 
 	echo "Test $mkfs_opts" >>$seqres.full
 
-	SCRATCH_DEV_POOL=`echo $SCRATCH_DEV_POOL | sed -e "s# *$replace_dev *##"`
 	_scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
 	# make sure we created btrfs with desired options
 	if [ $? -ne 0 ]; then
 		echo "mkfs $mkfs_opts failed"
-		SCRATCH_DEV_POOL=$saved_scratch_dev_pool
+		_spare_dev_put
+		_scratch_dev_pool_put
 		return
 	fi
 	_scratch_mount >>$seqres.full 2>&1
@@ -89,17 +94,19 @@ run_test()
 	_scratch_mount -o degraded >>$seqres.full 2>&1
 
 	# replace $missing_dev with $replace_dev and scrub it to double-check
-	$BTRFS_UTIL_PROG replace start -B -r $missing_dev_id $replace_dev \
+	$BTRFS_UTIL_PROG replace start -B -r $missing_dev_id $SPARE_DEV \
 		$SCRATCH_MNT -f >>$seqres.full 2>&1
 	if [ $? -ne 0 ]; then
 		echo "btrfs replace failed"
-		SCRATCH_DEV_POOL=$saved_scratch_dev_pool
+		_spare_dev_put
+		_scratch_dev_pool_put
 		return
 	fi
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
 	if [ $? -ne 0 ]; then
 		echo "btrfs scrub failed"
-		SCRATCH_DEV_POOL=$saved_scratch_dev_pool
+		_spare_dev_put
+		_scratch_dev_pool_put
 		return
 	fi
 
@@ -107,7 +114,8 @@ run_test()
 	# we called _require_scratch_nocheck instead of _require_scratch
 	# do check after test for each profile config
 	_check_scratch_fs
-	SCRATCH_DEV_POOL=$saved_scratch_dev_pool
+	_spare_dev_put
+	_scratch_dev_pool_put
 }
 
 echo "Silence is golden"
-- 
2.7.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 4/6] fstests: btrfs: add helper function to check if btrfs is module
  2016-05-17 14:32 [PATCH 1/6] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL Anand Jain
  2016-05-17 14:32 ` [PATCH 2/6] fstests: btrfs: add functions to get and put a device for replace target Anand Jain
  2016-05-17 14:32 ` [PATCH 3/6] fstests: btrfs: 027 make use of new device get and put helper functions Anand Jain
@ 2016-05-17 14:32 ` Anand Jain
  2016-06-12  4:53   ` Eryu Guan
  2016-06-15  8:47   ` [PATCH v2 " Anand Jain
  2016-05-17 14:32 ` [PATCH 5/6] fstests: btrfs: test RAID1 device reappear and balanced Anand Jain
                   ` (3 subsequent siblings)
  6 siblings, 2 replies; 32+ messages in thread
From: Anand Jain @ 2016-05-17 14:32 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs, Anand Jain

We need btrfs to be a module so that it can unloaded and reloaded,
so that we can clean up the btrfs internal in memory device list.

This patch adds _require_btrfs_unloadable() and _reload_btrfs_ko()
to help with the same.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 common/rc | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/common/rc b/common/rc
index f2b39ddbee0c..a9391b4cbf57 100644
--- a/common/rc
+++ b/common/rc
@@ -1403,6 +1403,18 @@ _supported_os()
     _notrun "not suitable for this OS: $HOSTOS"
 }
 
+_require_btrfs_unloadable()
+{
+	modprobe -r btrfs || _notrun "btrfs unloadable"
+	modprobe btrfs || _notrun "Can't load btrfs"
+}
+
+_reload_btrfs_ko()
+{
+	modprobe -r btrfs || _fail "btrfs unload failed"
+	modprobe btrfs || _fail "btrfs load failed"
+}
+
 # this test needs a scratch partition - check we're ok & unmount it
 # No post-test check of the device is required. e.g. the test intentionally
 # finishes the test with the filesystem in a corrupt state
-- 
2.7.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 5/6] fstests: btrfs: test RAID1 device reappear and balanced
  2016-05-17 14:32 [PATCH 1/6] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL Anand Jain
                   ` (2 preceding siblings ...)
  2016-05-17 14:32 ` [PATCH 4/6] fstests: btrfs: add helper function to check if btrfs is module Anand Jain
@ 2016-05-17 14:32 ` Anand Jain
  2016-06-12  5:06   ` Eryu Guan
                     ` (2 more replies)
  2016-05-17 14:32 ` [PATCH 6/6] fstests: btrfs: test RAID5 device reappear and balance Anand Jain
                   ` (2 subsequent siblings)
  6 siblings, 3 replies; 32+ messages in thread
From: Anand Jain @ 2016-05-17 14:32 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs, Anand Jain

The test does the following:
  Initialize a RAID1 with some data

  Re-mount RAID1 degraded with _dev1_ and write up to
  half of the FS capacity
  Save md5sum checkpoint1

  Re-mount healthy RAID1

  Let balance re-silver.
  Save md5sum checkpoint2

  Re-mount RAID1 degraded with _dev2_
  Save md5sum checkpoint3

  Verify if all three md5sum match

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 tests/btrfs/121     | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/121.out |   8 +++
 tests/btrfs/group   |   1 +
 3 files changed, 172 insertions(+)
 create mode 100755 tests/btrfs/121
 create mode 100644 tests/btrfs/121.out

diff --git a/tests/btrfs/121 b/tests/btrfs/121
new file mode 100755
index 000000000000..81b7deb047af
--- /dev/null
+++ b/tests/btrfs/121
@@ -0,0 +1,163 @@
+#! /bin/bash
+# FS QA Test 121
+#
+# This test verify the RAID1 reconstruction on the reappeared
+# device. By using the following steps:
+# Initialize a RAID1 with some data
+#
+# Re-mount RAID1 degraded with dev2 missing and write up to
+# half of the FS capacity.
+# Save md5sum checkpoint1
+#
+# Re-mount healthy RAID1
+#
+# Let balance re-silver.
+# Save md5sum checkpoint2
+#
+# Re-mount RAID1 degraded with dev1 missing
+# Save md5sum checkpoint3
+#
+# Verify if all three checkpoints match
+#
+#---------------------------------------------------------------------
+# Copyright (c) 2016 Oracle.  All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#---------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	cd /
+}
+
+# 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
+
+_supported_fs btrfs
+_supported_os Linux
+_require_scratch_nocheck
+_require_scratch_dev_pool 2
+
+# the mounted test dir prevent btrfs unload, we need to unmount
+_test_unmount
+_require_btrfs_unloadable
+
+_scratch_dev_pool_get 2
+
+dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
+dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
+
+dev1_sz=`blockdev --getsize64 $dev1`
+dev2_sz=`blockdev --getsize64 $dev2`
+# get min of both
+max_fs_sz=`echo -e "$dev1_sz\n$dev2_sz" | sort | head -1`
+max_fs_sz=$(( max_fs_sz/2 ))
+if [ $max_fs_sz -gt 1000000 ]; then
+	bs="1M"
+	count=$(( max_fs_sz/1000000 ))
+else
+	max_fs_sz=$(( max_fs_sz*2 ))
+	_notrun "Smallest dev size $max_fs_sz, Need at least 2M"
+fi
+
+echo >> $seqres.full
+echo "max_fs_sz=$max_fs_sz count=$count" >> $seqres.full
+echo "-----Initialize -----" >> $seqres.full
+_scratch_pool_mkfs "-mraid1 -draid1" >> $seqres.full 2>&1
+_scratch_mount >> $seqres.full 2>&1
+_run_btrfs_util_prog filesystem show
+dd if=/dev/zero of="$SCRATCH_MNT"/tf1 bs=$bs count=1 \
+					>>$seqres.full 2>&1
+count=$(( count-- ))
+echo "unmount" >> $seqres.full
+echo "clean btrfs ko" >> $seqres.full
+_scratch_unmount
+_reload_btrfs_ko
+
+
+echo >> $seqres.full
+echo "-----Write degraded mount fill upto $max_fs_sz bytes-----" >> $seqres.full
+echo
+echo "Write data with degraded mount"
+# Since we didn't run dev scan, btrfs kernel does not know
+# about the dev2
+# don't use _scratch_mount as we want to control
+# the device used for mounting.
+
+_mount -o degraded $dev1 $SCRATCH_MNT >>$seqres.full 2>&1
+_run_btrfs_util_prog filesystem show
+dd if=/dev/zero of="$SCRATCH_MNT"/tf2 bs=$bs count=$count \
+					>>$seqres.full 2>&1
+checkpoint1=`md5sum $SCRATCH_MNT/tf2`
+echo $checkpoint1 >> $seqres.full 2>&1
+_scratch_unmount
+echo "unmount" >> $seqres.full
+
+echo >> $seqres.full
+echo "-----Mount normal-----" >> $seqres.full
+echo
+echo "Mount normal after balance"
+_run_btrfs_util_prog device scan
+_scratch_mount >> $seqres.full 2>&1
+_run_btrfs_util_prog filesystem show
+echo >> $seqres.full
+_run_btrfs_util_prog balance start ${SCRATCH_MNT}
+
+checkpoint2=`md5sum $SCRATCH_MNT/tf2`
+echo $checkpoint2 >> $seqres.full 2>&1
+
+echo >> $seqres.full
+echo "-----Mount degraded but with other dev -----" >> $seqres.full
+echo
+echo "Mount degraded but with other dev"
+_scratch_unmount
+_reload_btrfs_ko
+_mount -o degraded $dev2 $SCRATCH_MNT >>$seqres.full 2>&1
+_run_btrfs_util_prog filesystem show
+checkpoint3=`md5sum $SCRATCH_MNT/tf2`
+echo $checkpoint3 >> $seqres.full 2>&1
+
+if [ "$checkpoint1" != "$checkpoint2" ]; then
+	echo $checkpoint1
+	echo $checkpoint2
+	_fail "Inital sum does not match with after balance"
+fi
+
+if [ "$checkpoint1" != "$checkpoint3" ]; then
+	echo $checkpoint1
+	echo $checkpoint3
+	_fail "Inital sum does not match with data on dev2 written by balance"
+fi
+
+_scratch_dev_pool_put
+_test_mount
+
+echo "Silence is golden"
+status=0
+exit
diff --git a/tests/btrfs/121.out b/tests/btrfs/121.out
new file mode 100644
index 000000000000..0728787d17bc
--- /dev/null
+++ b/tests/btrfs/121.out
@@ -0,0 +1,8 @@
+QA output created by 121
+
+Write data with degraded mount
+
+Mount normal after balance
+
+Mount degraded but with other dev
+Silence is golden
diff --git a/tests/btrfs/group b/tests/btrfs/group
index 90af8fc2d106..5c28a3ca0687 100644
--- a/tests/btrfs/group
+++ b/tests/btrfs/group
@@ -122,3 +122,4 @@
 118 auto quick snapshot metadata
 119 auto quick snapshot metadata qgroup
 120 auto quick snapshot metadata
+121 auto replace
-- 
2.7.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 6/6] fstests: btrfs: test RAID5 device reappear and balance
  2016-05-17 14:32 [PATCH 1/6] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL Anand Jain
                   ` (3 preceding siblings ...)
  2016-05-17 14:32 ` [PATCH 5/6] fstests: btrfs: test RAID1 device reappear and balanced Anand Jain
@ 2016-05-17 14:32 ` Anand Jain
  2016-06-12  5:08   ` Eryu Guan
                     ` (2 more replies)
  2016-06-12  4:40 ` [PATCH 1/6] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL Eryu Guan
  2016-06-15  8:46 ` [PATCH v2 " Anand Jain
  6 siblings, 3 replies; 32+ messages in thread
From: Anand Jain @ 2016-05-17 14:32 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs, Anand Jain

The test does the following:
Initialize a RAID5 with some data

Re-mount RAID5 degraded with _dev3_ missing and write data.
Save md5sum checkpoint1

Re-mount healthy RAID5

Let balance fix degraded blocks.
Save md5sum checkpoint2

Re-mount RAID1 degraded now with _dev1_ missing.
Save md5sum checkpoint3

Verify if all three md5sum matches

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 tests/btrfs/122     | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/122.out |   8 +++
 tests/btrfs/group   |   1 +
 3 files changed, 187 insertions(+)
 create mode 100755 tests/btrfs/122
 create mode 100644 tests/btrfs/122.out

diff --git a/tests/btrfs/122 b/tests/btrfs/122
new file mode 100755
index 000000000000..89c0103fef08
--- /dev/null
+++ b/tests/btrfs/122
@@ -0,0 +1,178 @@
+#! /bin/bash
+# FS QA Test 122
+#
+# This test verify if the reconstructed data on the RAID5 is good.
+# Steps:
+# Initialize RAID5 with some data
+#
+# Re-mount RAID5 degraded with dev3 missing and write data
+# Save md5sum checkpoint1
+#
+# Re-mount healthy RAID5
+#
+# Let balance fix the RAID5.
+# Save md5sum checkpoint2
+#
+# Re-mount RAID5 degraded with dev1 as missing.
+# Save md5sum checkpoint3
+#
+# Verify if all three checkpoints match
+#
+#---------------------------------------------------------------------
+# Copyright (c) 2016 Oracle.  All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#---------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	cd /
+}
+
+# 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
+
+_supported_fs btrfs
+_supported_os Linux
+_require_scratch_nocheck
+_require_scratch_dev_pool 3
+
+# we need btrfs to unload, need test dir unmounted
+_test_unmount
+_require_btrfs_unloadable
+
+_scratch_dev_pool_get 3
+
+dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
+dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
+dev3=`echo $SCRATCH_DEV_POOL | awk '{print $3}'`
+
+echo dev1=$dev1 >> $seqres.full
+echo dev2=$dev2 >> $seqres.full
+echo dev3=$dev3 >> $seqres.full
+
+# Balance won't be successful if filled too much
+dev1_sz=`blockdev --getsize64 $dev1`
+dev2_sz=`blockdev --getsize64 $dev2`
+dev3_sz=`blockdev --getsize64 $dev3`
+
+# get min of both
+max_fs_sz=`echo -e "$dev1_sz\n$dev2_sz\n$dev3_sz" | sort | head -1`
+if [ $max_fs_sz -gt 1000000 ]; then
+	bs="1M"
+	count=$(( max_fs_sz/1000000 ))
+	count=$(( count/100 ))
+else
+	_notrun "Smallest dev size $max_fs_sz, Need at least 2M"
+fi
+
+#-------------init-------------------
+echo >> $seqres.full
+echo "max_fs_sz=$max_fs_sz count=$count" >> $seqres.full
+echo "-----Initialize -----" >> $seqres.full
+_scratch_pool_mkfs "-mraid5 -draid5" >> $seqres.full 2>&1
+_scratch_mount >> $seqres.full 2>&1
+dd if=/dev/zero of="$SCRATCH_MNT"/tf1 bs=$bs count=1 \
+					>>$seqres.full 2>&1
+_run_btrfs_util_prog filesystem show
+_run_btrfs_util_prog filesystem df $SCRATCH_MNT
+count=$(( count-- ))
+
+
+#-------------degraded-init-------------------
+echo >> $seqres.full
+echo "-----Write degraded mount fill upto $max_fs_sz bytes-----" >> $seqres.full
+echo
+echo "Write data with degraded mount"
+
+echo "unmount" >> $seqres.full
+_scratch_unmount
+echo "clean btrfs ko" >> $seqres.full
+_reload_btrfs_ko
+_mount -o degraded,device=$dev2 $dev1 $SCRATCH_MNT >>$seqres.full 2>&1
+dd if=/dev/zero of="$SCRATCH_MNT"/tf2 bs=$bs count=$count \
+					>>$seqres.full 2>&1
+_run_btrfs_util_prog filesystem show
+_run_btrfs_util_prog filesystem df $SCRATCH_MNT
+checkpoint1=`md5sum $SCRATCH_MNT/tf2`
+echo $checkpoint1 >> $seqres.full 2>&1
+
+#-------------balance-------------------
+echo >> $seqres.full
+echo "-----Mount normal-----" >> $seqres.full
+echo
+echo "Mount normal after balance"
+
+_scratch_unmount
+_run_btrfs_util_prog device scan
+_scratch_mount >> $seqres.full 2>&1
+
+echo >> $seqres.full
+_run_btrfs_util_prog balance start ${SCRATCH_MNT}
+
+_run_btrfs_util_prog filesystem show
+_run_btrfs_util_prog filesystem df ${SCRATCH_MNT}
+
+checkpoint2=`md5sum $SCRATCH_MNT/tf2`
+echo $checkpoint2 >> $seqres.full 2>&1
+
+#-------------degraded-mount-------------------
+echo >> $seqres.full
+echo "-----Mount degraded with dev1 missing-----" >> $seqres.full
+echo
+echo "Mount degraded but with other dev"
+
+_scratch_unmount
+_reload_btrfs_ko
+
+_mount -o degraded,device=${dev2} $dev3 $SCRATCH_MNT >>$seqres.full 2>&1
+
+_run_btrfs_util_prog filesystem show
+_run_btrfs_util_prog filesystem df $SCRATCH_MNT
+checkpoint3=`md5sum $SCRATCH_MNT/tf2`
+echo $checkpoint3 >> $seqres.full 2>&1
+
+if [ "$checkpoint1" != "$checkpoint2" ]; then
+	echo $checkpoint1
+	echo $checkpoint2
+	_fail "Inital sum does not match with after balance"
+fi
+
+if [ "$checkpoint1" != "$checkpoint3" ]; then
+	echo $checkpoint1
+	echo $checkpoint3
+	_fail "Inital sum does not match with data on dev2 written by balance"
+fi
+
+_scratch_dev_pool_put
+_test_mount
+
+echo "Silence is golden"
+status=0
+exit
diff --git a/tests/btrfs/122.out b/tests/btrfs/122.out
new file mode 100644
index 000000000000..5bac6be9bec2
--- /dev/null
+++ b/tests/btrfs/122.out
@@ -0,0 +1,8 @@
+QA output created by 122
+
+Write data with degraded mount
+
+Mount normal after balance
+
+Mount degraded but with other dev
+Silence is golden
diff --git a/tests/btrfs/group b/tests/btrfs/group
index 5c28a3ca0687..848037bbacd8 100644
--- a/tests/btrfs/group
+++ b/tests/btrfs/group
@@ -123,3 +123,4 @@
 119 auto quick snapshot metadata qgroup
 120 auto quick snapshot metadata
 121 auto replace
+122 auto replace
-- 
2.7.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* Re: [PATCH 1/6] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL
  2016-05-17 14:32 [PATCH 1/6] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL Anand Jain
                   ` (4 preceding siblings ...)
  2016-05-17 14:32 ` [PATCH 6/6] fstests: btrfs: test RAID5 device reappear and balance Anand Jain
@ 2016-06-12  4:40 ` Eryu Guan
  2016-06-15  8:44   ` Anand Jain
  2016-06-15  8:46 ` [PATCH v2 " Anand Jain
  6 siblings, 1 reply; 32+ messages in thread
From: Eryu Guan @ 2016-06-12  4:40 UTC (permalink / raw)
  To: Anand Jain; +Cc: fstests, linux-btrfs

On Tue, May 17, 2016 at 10:32:05PM +0800, Anand Jain wrote:
> This patch provides functions
>  _scratch_dev_pool_get()
>  _scratch_dev_pool_put()
> 
> Which will help to set/reset SCRATCH_DEV_POOL with the required
> number of devices. SCRATCH_DEV_POOL_SAVED will hold all the devices.
> 
> Usage:
>   _scratch_dev_pool_get() <ndevs>
>   :: do stuff
> 
>   _scratch_dev_pool_put()
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>

I'm not sure about the usefulness and the implementation of these
helpers (include the _spare_dev_get|_put helpers), but they look good to
me. It'd better to have btrfs developers review them as well.

> ---
>  common/rc | 47 +++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 47 insertions(+)
> 
> diff --git a/common/rc b/common/rc
> index 91e8f1c8e693..33632fd8e4a3 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -786,6 +786,53 @@ _scratch_mkfs()
>      esac
>  }
>  
> +#
> +# $1 Number of the scratch devs required
> +#

Some comments about its usage/purpose would be good, otherwise one has
to search for the commit log and look into it to understand its purpose

> +_scratch_dev_pool_get()
> +{
> +	if [ $# != 1 ]; then
> +		_fail "Usage: _scratch_dev_pool_get ndevs"
> +	fi
> +
> +	local test_ndevs=$1
> +	local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
> +	local devs[]="( $SCRATCH_DEV_POOL )"
> +
> +	typeset -p config_ndevs >/dev/null 2>&1
> +	if [ $? != 0 ]; then
> +		_fail "Bug: unset val, must call _scratch_dev_pool_get before _scratch_dev_pool_put"

This error message seems confusing, it's _scratch_dev_pool_get being
called here, not _put.

> +	fi
> +
> +	# _require_scratch_dev_pool $test_ndevs
> +	# must have already checked the min required devices
> +	# but just in case, trap here for any potential bugs
> +	# perpetuating any further
> +	if [ $config_ndevs -lt $test_ndevs ]; then
> +		_notrun "Need at least test requested number of ndevs $test_ndevs"

This message is not clear to me either.

Thanks,
Eryu

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 2/6] fstests: btrfs: add functions to get and put a device for replace target
  2016-05-17 14:32 ` [PATCH 2/6] fstests: btrfs: add functions to get and put a device for replace target Anand Jain
@ 2016-06-12  4:42   ` Eryu Guan
  2016-06-15  8:45     ` Anand Jain
  2016-06-15  8:47   ` [PATCH v2 " Anand Jain
  1 sibling, 1 reply; 32+ messages in thread
From: Eryu Guan @ 2016-06-12  4:42 UTC (permalink / raw)
  To: Anand Jain; +Cc: fstests, linux-btrfs

On Tue, May 17, 2016 at 10:32:06PM +0800, Anand Jain wrote:
> For the replace tests we need a device as a spare device,
> here functions _spare_dev_get() and _spare_dev_put()
> will get it from the SCRATCH_DEV_POOL_SAVED, which is set
> when _scratch_dev_pool_get() is called, and is based on how
> many has already been assigned to SCRATCH_DEV_POOL.
> 
>  usage:
>    _scratch_dev_pool_get 3
>    _spare_dev_get
> 
>       SPARE_DEV will have a device set which can be
>       used as the replace target device.
> 
>    _spare_dev_put
>    _scratch_dev_pool_put
> 
> _spare_dev_get() will pick the next device after SCRATCH_DEV_POOL
> devices, from the SCRATCH_DEV_POOL_SAVED, and assigns it to
> SPARE_DEV. _spare_dev_put() will set to SPARE_DEV to null.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>  common/rc | 45 +++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 45 insertions(+)
> 
> diff --git a/common/rc b/common/rc
> index 33632fd8e4a3..f2b39ddbee0c 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -786,6 +786,51 @@ _scratch_mkfs()
>      esac
>  }
>  
> +_spare_dev_get()

I'd like to see some comments about these helpers in the code. Otherwise
look good to me.

Thanks,
Eryu

> +{
> +	typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
> +	if [ $? != 0 ]; then
> +		_fail "Bug: unset val, must call _scratch_dev_pool_get before _spare_dev_get"
> +	fi
> +
> +	if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
> +		_fail "Bug: str empty, must call _scratch_dev_pool_get before _spare_dev_get"
> +	fi
> +
> +	# Check if the spare is already assigned
> +	typeset -p SPARE_DEV >/dev/null 2>&1
> +	if [ $? == 0 ]; then
> +		if [ ! -z "$SPARE_DEV" ]; then
> +			_fail "Bug: SPARE_DEV = $SPARE_DEV already assigned"
> +		fi
> +	fi
> +
> +	local ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
> +	local config_ndevs=`echo $SCRATCH_DEV_POOL_SAVED| wc -w`
> +
> +	if [ $ndevs -eq $config_ndevs ]; then
> +		_notrun "All devs used no spare"
> +	fi
> +	# Get a dev that is not used
> +	local devs[]="( $SCRATCH_DEV_POOL_SAVED )"
> +	SPARE_DEV=${devs[@]:$ndevs:1}
> +	export SPARE_DEV
> +}
> +
> +_spare_dev_put()
> +{
> +	typeset -p SPARE_DEV >/dev/null 2>&1
> +	if [ $? != 0 ]; then
> +		_fail "Bug: unset val, must call _spare_dev_get before its put"
> +	fi
> +
> +	if [ -z "$SPARE_DEV" ]; then
> +		_fail "Bug: str empty, must call _spare_dev_get before its put"
> +	fi
> +
> +	export SPARE_DEV=""
> +}
> +
>  #
>  # $1 Number of the scratch devs required
>  #
> -- 
> 2.7.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 4/6] fstests: btrfs: add helper function to check if btrfs is module
  2016-05-17 14:32 ` [PATCH 4/6] fstests: btrfs: add helper function to check if btrfs is module Anand Jain
@ 2016-06-12  4:53   ` Eryu Guan
  2016-06-15  8:45     ` Anand Jain
  2016-06-15  8:47   ` [PATCH v2 " Anand Jain
  1 sibling, 1 reply; 32+ messages in thread
From: Eryu Guan @ 2016-06-12  4:53 UTC (permalink / raw)
  To: Anand Jain; +Cc: fstests, linux-btrfs

On Tue, May 17, 2016 at 10:32:08PM +0800, Anand Jain wrote:
> We need btrfs to be a module so that it can unloaded and reloaded,
> so that we can clean up the btrfs internal in memory device list.

It looks like a bug to me if btrfs needs to reload module to clean up
the device list. If a user builds btrfs in kernel then he cannot replace
btrfs device properly? Or it's not totally clear to me why a test needs
to reload btrfs module.

> 
> This patch adds _require_btrfs_unloadable() and _reload_btrfs_ko()
> to help with the same.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>  common/rc | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/common/rc b/common/rc
> index f2b39ddbee0c..a9391b4cbf57 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -1403,6 +1403,18 @@ _supported_os()
>      _notrun "not suitable for this OS: $HOSTOS"
>  }
>  
> +_require_btrfs_unloadable()

The name seems misleading, the name indicates that it requires btrfs to
be unloadable, but in the code it _notrun if btrfs is unloadable.

Thanks,
Eryu

> +{
> +	modprobe -r btrfs || _notrun "btrfs unloadable"
> +	modprobe btrfs || _notrun "Can't load btrfs"
> +}
> +
> +_reload_btrfs_ko()
> +{
> +	modprobe -r btrfs || _fail "btrfs unload failed"
> +	modprobe btrfs || _fail "btrfs load failed"
> +}
> +
>  # this test needs a scratch partition - check we're ok & unmount it
>  # No post-test check of the device is required. e.g. the test intentionally
>  # finishes the test with the filesystem in a corrupt state
> -- 
> 2.7.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 5/6] fstests: btrfs: test RAID1 device reappear and balanced
  2016-05-17 14:32 ` [PATCH 5/6] fstests: btrfs: test RAID1 device reappear and balanced Anand Jain
@ 2016-06-12  5:06   ` Eryu Guan
  2016-06-15  8:45     ` Anand Jain
  2016-06-15  8:48   ` [PATCH v2 " Anand Jain
  2016-06-30 10:58   ` [PATCH v3 5/6] fstests: btrfs: test RAID1 device reappear and balanced Anand Jain
  2 siblings, 1 reply; 32+ messages in thread
From: Eryu Guan @ 2016-06-12  5:06 UTC (permalink / raw)
  To: Anand Jain; +Cc: fstests, linux-btrfs

On Tue, May 17, 2016 at 10:32:09PM +0800, Anand Jain wrote:
> The test does the following:
>   Initialize a RAID1 with some data
> 
>   Re-mount RAID1 degraded with _dev1_ and write up to
>   half of the FS capacity
>   Save md5sum checkpoint1
> 
>   Re-mount healthy RAID1
> 
>   Let balance re-silver.
>   Save md5sum checkpoint2
> 
>   Re-mount RAID1 degraded with _dev2_
>   Save md5sum checkpoint3
> 
>   Verify if all three md5sum match
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>  tests/btrfs/121     | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  tests/btrfs/121.out |   8 +++
>  tests/btrfs/group   |   1 +
>  3 files changed, 172 insertions(+)
>  create mode 100755 tests/btrfs/121
>  create mode 100644 tests/btrfs/121.out
> 
> diff --git a/tests/btrfs/121 b/tests/btrfs/121
> new file mode 100755
> index 000000000000..81b7deb047af
> --- /dev/null
> +++ b/tests/btrfs/121
> @@ -0,0 +1,163 @@
> +#! /bin/bash
> +# FS QA Test 121
> +#
> +# This test verify the RAID1 reconstruction on the reappeared
> +# device. By using the following steps:
> +# Initialize a RAID1 with some data
> +#
> +# Re-mount RAID1 degraded with dev2 missing and write up to
> +# half of the FS capacity.
> +# Save md5sum checkpoint1
> +#
> +# Re-mount healthy RAID1
> +#
> +# Let balance re-silver.
> +# Save md5sum checkpoint2
> +#
> +# Re-mount RAID1 degraded with dev1 missing
> +# Save md5sum checkpoint3
> +#
> +# Verify if all three checkpoints match
> +#
> +#---------------------------------------------------------------------
> +# Copyright (c) 2016 Oracle.  All Rights Reserved.
> +#
> +# This program is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU General Public License as
> +# published by the Free Software Foundation.
> +#
> +# This program is distributed in the hope that it would be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, write the Free Software Foundation,
> +# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
> +#---------------------------------------------------------------------
> +#
> +
> +seq=`basename $0`
> +seqres=$RESULT_DIR/$seq
> +echo "QA output created by $seq"
> +
> +here=`pwd`
> +status=1	# failure is the default!
> +trap "_cleanup; exit \$status" 0 1 2 3 15
> +
> +_cleanup()
> +{
> +	cd /

The "rm -f $tmp.*" is still needed even $tmp.* is not used in the test
itself, it's still possible to be used by some helper functions.

> +}
> +
> +# 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
> +
> +_supported_fs btrfs
> +_supported_os Linux
> +_require_scratch_nocheck
> +_require_scratch_dev_pool 2
> +
> +# the mounted test dir prevent btrfs unload, we need to unmount
> +_test_unmount
> +_require_btrfs_unloadable
> +
> +_scratch_dev_pool_get 2
> +
> +dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
> +dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
> +
> +dev1_sz=`blockdev --getsize64 $dev1`
> +dev2_sz=`blockdev --getsize64 $dev2`
> +# get min of both
> +max_fs_sz=`echo -e "$dev1_sz\n$dev2_sz" | sort | head -1`
> +max_fs_sz=$(( max_fs_sz/2 ))
> +if [ $max_fs_sz -gt 1000000 ]; then
> +	bs="1M"
> +	count=$(( max_fs_sz/1000000 ))
> +else
> +	max_fs_sz=$(( max_fs_sz*2 ))
> +	_notrun "Smallest dev size $max_fs_sz, Need at least 2M"
> +fi
> +
> +echo >> $seqres.full
> +echo "max_fs_sz=$max_fs_sz count=$count" >> $seqres.full
> +echo "-----Initialize -----" >> $seqres.full
> +_scratch_pool_mkfs "-mraid1 -draid1" >> $seqres.full 2>&1
> +_scratch_mount >> $seqres.full 2>&1
> +_run_btrfs_util_prog filesystem show
> +dd if=/dev/zero of="$SCRATCH_MNT"/tf1 bs=$bs count=1 \
> +					>>$seqres.full 2>&1
> +count=$(( count-- ))
> +echo "unmount" >> $seqres.full
> +echo "clean btrfs ko" >> $seqres.full
> +_scratch_unmount
> +_reload_btrfs_ko

A comment to explain the reason to reload btrfs.ko would be good.

> +
> +
> +echo >> $seqres.full
> +echo "-----Write degraded mount fill upto $max_fs_sz bytes-----" >> $seqres.full
> +echo
> +echo "Write data with degraded mount"
> +# Since we didn't run dev scan, btrfs kernel does not know
> +# about the dev2
> +# don't use _scratch_mount as we want to control
> +# the device used for mounting.
> +
> +_mount -o degraded $dev1 $SCRATCH_MNT >>$seqres.full 2>&1
> +_run_btrfs_util_prog filesystem show
> +dd if=/dev/zero of="$SCRATCH_MNT"/tf2 bs=$bs count=$count \
> +					>>$seqres.full 2>&1
> +checkpoint1=`md5sum $SCRATCH_MNT/tf2`
> +echo $checkpoint1 >> $seqres.full 2>&1
> +_scratch_unmount
> +echo "unmount" >> $seqres.full
> +
> +echo >> $seqres.full
> +echo "-----Mount normal-----" >> $seqres.full
> +echo
> +echo "Mount normal after balance"
> +_run_btrfs_util_prog device scan
> +_scratch_mount >> $seqres.full 2>&1
> +_run_btrfs_util_prog filesystem show
> +echo >> $seqres.full
> +_run_btrfs_util_prog balance start ${SCRATCH_MNT}
> +
> +checkpoint2=`md5sum $SCRATCH_MNT/tf2`
> +echo $checkpoint2 >> $seqres.full 2>&1
> +
> +echo >> $seqres.full
> +echo "-----Mount degraded but with other dev -----" >> $seqres.full
> +echo
> +echo "Mount degraded but with other dev"
> +_scratch_unmount
> +_reload_btrfs_ko
> +_mount -o degraded $dev2 $SCRATCH_MNT >>$seqres.full 2>&1
> +_run_btrfs_util_prog filesystem show
> +checkpoint3=`md5sum $SCRATCH_MNT/tf2`
> +echo $checkpoint3 >> $seqres.full 2>&1
> +
> +if [ "$checkpoint1" != "$checkpoint2" ]; then
> +	echo $checkpoint1
> +	echo $checkpoint2
> +	_fail "Inital sum does not match with after balance"
> +fi
> +
> +if [ "$checkpoint1" != "$checkpoint3" ]; then
> +	echo $checkpoint1
> +	echo $checkpoint3
> +	_fail "Inital sum does not match with data on dev2 written by balance"

Just "echo" error message, not _fail. _fail causes the test to exit,
leaves the following "_scratch_dev_pool_put; _test_mount" not run.

> +fi
> +
> +_scratch_dev_pool_put
> +_test_mount
> +
> +echo "Silence is golden"

There're outputs in golden image, then this line is not needed.

Thanks,
Eryu

> +status=0
> +exit
> diff --git a/tests/btrfs/121.out b/tests/btrfs/121.out
> new file mode 100644
> index 000000000000..0728787d17bc
> --- /dev/null
> +++ b/tests/btrfs/121.out
> @@ -0,0 +1,8 @@
> +QA output created by 121
> +
> +Write data with degraded mount
> +
> +Mount normal after balance
> +
> +Mount degraded but with other dev
> +Silence is golden
> diff --git a/tests/btrfs/group b/tests/btrfs/group
> index 90af8fc2d106..5c28a3ca0687 100644
> --- a/tests/btrfs/group
> +++ b/tests/btrfs/group
> @@ -122,3 +122,4 @@
>  118 auto quick snapshot metadata
>  119 auto quick snapshot metadata qgroup
>  120 auto quick snapshot metadata
> +121 auto replace
> -- 
> 2.7.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 6/6] fstests: btrfs: test RAID5 device reappear and balance
  2016-05-17 14:32 ` [PATCH 6/6] fstests: btrfs: test RAID5 device reappear and balance Anand Jain
@ 2016-06-12  5:08   ` Eryu Guan
  2016-06-15  8:51     ` Anand Jain
  2016-06-15  8:49   ` [PATCH v2 " Anand Jain
  2016-06-30 10:59   ` [PATCH v3 " Anand Jain
  2 siblings, 1 reply; 32+ messages in thread
From: Eryu Guan @ 2016-06-12  5:08 UTC (permalink / raw)
  To: Anand Jain; +Cc: fstests, linux-btrfs

On Tue, May 17, 2016 at 10:32:10PM +0800, Anand Jain wrote:
> The test does the following:
> Initialize a RAID5 with some data
> 
> Re-mount RAID5 degraded with _dev3_ missing and write data.
> Save md5sum checkpoint1
> 
> Re-mount healthy RAID5
> 
> Let balance fix degraded blocks.
> Save md5sum checkpoint2
> 
> Re-mount RAID1 degraded now with _dev1_ missing.
> Save md5sum checkpoint3
> 
> Verify if all three md5sum matches
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>

All comments for 5/6 apply here for 6/6 :)

Thanks,
Eryu

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 1/6] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL
  2016-06-12  4:40 ` [PATCH 1/6] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL Eryu Guan
@ 2016-06-15  8:44   ` Anand Jain
  0 siblings, 0 replies; 32+ messages in thread
From: Anand Jain @ 2016-06-15  8:44 UTC (permalink / raw)
  To: Eryu Guan; +Cc: fstests, linux-btrfs


Thanks for reviewing.

On 06/12/2016 12:40 PM, Eryu Guan wrote:
> On Tue, May 17, 2016 at 10:32:05PM +0800, Anand Jain wrote:
>> This patch provides functions
>>  _scratch_dev_pool_get()
>>  _scratch_dev_pool_put()
>>
>> Which will help to set/reset SCRATCH_DEV_POOL with the required
>> number of devices. SCRATCH_DEV_POOL_SAVED will hold all the devices.
>>
>> Usage:
>>   _scratch_dev_pool_get() <ndevs>
>>   :: do stuff
>>
>>   _scratch_dev_pool_put()
>>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>
> I'm not sure about the usefulness and the implementation of these
> helpers (include the _spare_dev_get|_put helpers), but they look good to
> me. It'd better to have btrfs developers review them as well.
>
>> ---
>>  common/rc | 47 +++++++++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 47 insertions(+)
>>
>> diff --git a/common/rc b/common/rc
>> index 91e8f1c8e693..33632fd8e4a3 100644
>> --- a/common/rc
>> +++ b/common/rc
>> @@ -786,6 +786,53 @@ _scratch_mkfs()
>>      esac
>>  }
>>
>> +#
>> +# $1 Number of the scratch devs required
>> +#
>
> Some comments about its usage/purpose would be good, otherwise one has
> to search for the commit log and look into it to understand its purpose

added in v2.

>> +_scratch_dev_pool_get()
>> +{
>> +	if [ $# != 1 ]; then
>> +		_fail "Usage: _scratch_dev_pool_get ndevs"
>> +	fi
>> +
>> +	local test_ndevs=$1
>> +	local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
>> +	local devs[]="( $SCRATCH_DEV_POOL )"
>> +
>> +	typeset -p config_ndevs >/dev/null 2>&1
>> +	if [ $? != 0 ]; then
>> +		_fail "Bug: unset val, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
>
> This error message seems confusing, it's _scratch_dev_pool_get being
> called here, not _put.

ah, copy paste typo. fixed it in v2.

>> +	fi
>> +
>> +	# _require_scratch_dev_pool $test_ndevs
>> +	# must have already checked the min required devices
>> +	# but just in case, trap here for any potential bugs
>> +	# perpetuating any further
>> +	if [ $config_ndevs -lt $test_ndevs ]; then
>> +		_notrun "Need at least test requested number of ndevs $test_ndevs"
>
> This message is not clear to me either.

  ok, updated.

Thanks, Anand


> Thanks,
> Eryu
>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 2/6] fstests: btrfs: add functions to get and put a device for replace target
  2016-06-12  4:42   ` Eryu Guan
@ 2016-06-15  8:45     ` Anand Jain
  0 siblings, 0 replies; 32+ messages in thread
From: Anand Jain @ 2016-06-15  8:45 UTC (permalink / raw)
  To: Eryu Guan; +Cc: fstests, linux-btrfs



On 06/12/2016 12:42 PM, Eryu Guan wrote:
> On Tue, May 17, 2016 at 10:32:06PM +0800, Anand Jain wrote:
>> For the replace tests we need a device as a spare device,
>> here functions _spare_dev_get() and _spare_dev_put()
>> will get it from the SCRATCH_DEV_POOL_SAVED, which is set
>> when _scratch_dev_pool_get() is called, and is based on how
>> many has already been assigned to SCRATCH_DEV_POOL.
>>
>>  usage:
>>    _scratch_dev_pool_get 3
>>    _spare_dev_get
>>
>>       SPARE_DEV will have a device set which can be
>>       used as the replace target device.
>>
>>    _spare_dev_put
>>    _scratch_dev_pool_put
>>
>> _spare_dev_get() will pick the next device after SCRATCH_DEV_POOL
>> devices, from the SCRATCH_DEV_POOL_SAVED, and assigns it to
>> SPARE_DEV. _spare_dev_put() will set to SPARE_DEV to null.
>>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>> ---
>>  common/rc | 45 +++++++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 45 insertions(+)
>>
>> diff --git a/common/rc b/common/rc
>> index 33632fd8e4a3..f2b39ddbee0c 100644
>> --- a/common/rc
>> +++ b/common/rc
>> @@ -786,6 +786,51 @@ _scratch_mkfs()
>>      esac
>>  }
>>
>> +_spare_dev_get()
>
> I'd like to see some comments about these helpers in the code. Otherwise
> look good to me.

  Added in v2. Thanks Anand


> Thanks,
> Eryu
>
>> +{
>> +	typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
>> +	if [ $? != 0 ]; then
>> +		_fail "Bug: unset val, must call _scratch_dev_pool_get before _spare_dev_get"
>> +	fi
>> +
>> +	if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
>> +		_fail "Bug: str empty, must call _scratch_dev_pool_get before _spare_dev_get"
>> +	fi
>> +
>> +	# Check if the spare is already assigned
>> +	typeset -p SPARE_DEV >/dev/null 2>&1
>> +	if [ $? == 0 ]; then
>> +		if [ ! -z "$SPARE_DEV" ]; then
>> +			_fail "Bug: SPARE_DEV = $SPARE_DEV already assigned"
>> +		fi
>> +	fi
>> +
>> +	local ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
>> +	local config_ndevs=`echo $SCRATCH_DEV_POOL_SAVED| wc -w`
>> +
>> +	if [ $ndevs -eq $config_ndevs ]; then
>> +		_notrun "All devs used no spare"
>> +	fi
>> +	# Get a dev that is not used
>> +	local devs[]="( $SCRATCH_DEV_POOL_SAVED )"
>> +	SPARE_DEV=${devs[@]:$ndevs:1}
>> +	export SPARE_DEV
>> +}
>> +
>> +_spare_dev_put()
>> +{
>> +	typeset -p SPARE_DEV >/dev/null 2>&1
>> +	if [ $? != 0 ]; then
>> +		_fail "Bug: unset val, must call _spare_dev_get before its put"
>> +	fi
>> +
>> +	if [ -z "$SPARE_DEV" ]; then
>> +		_fail "Bug: str empty, must call _spare_dev_get before its put"
>> +	fi
>> +
>> +	export SPARE_DEV=""
>> +}
>> +
>>  #
>>  # $1 Number of the scratch devs required
>>  #
>> --
>> 2.7.0
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe fstests" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 4/6] fstests: btrfs: add helper function to check if btrfs is module
  2016-06-12  4:53   ` Eryu Guan
@ 2016-06-15  8:45     ` Anand Jain
  0 siblings, 0 replies; 32+ messages in thread
From: Anand Jain @ 2016-06-15  8:45 UTC (permalink / raw)
  To: Eryu Guan; +Cc: fstests, linux-btrfs



On 06/12/2016 12:53 PM, Eryu Guan wrote:
> On Tue, May 17, 2016 at 10:32:08PM +0800, Anand Jain wrote:
>> We need btrfs to be a module so that it can unloaded and reloaded,
>> so that we can clean up the btrfs internal in memory device list.
>
> It looks like a bug to me if btrfs needs to reload module to clean up
> the device list.
  Definitely not a bug, but a pending enhancement.

> If a user builds btrfs in kernel then he cannot replace
> btrfs device properly?
  No. That's not true.

> Or it's not totally clear to me why a test needs
> to reload btrfs module.

  Sure.
  Test cases such 5/6 and 6/6 needs devices to be un-scanned.
  But as said, as of now we don't have such a feature and
  in a way _reload_btrfs_ko() will help to achieve the device
  un-scan.

  Further we have seen situations where previous test cases
  affects the next test case results. These are bugs,
  but are unintentional at that test case point of viwe, and
  is disturbingly deviating, so these helpers will help to
  start with a clean btrfs memory, so that test results are
  consistent to what is being tested.

>>
>> This patch adds _require_btrfs_unloadable() and _reload_btrfs_ko()
>> to help with the same.
>>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>> ---
>>  common/rc | 12 ++++++++++++
>>  1 file changed, 12 insertions(+)
>>
>> diff --git a/common/rc b/common/rc
>> index f2b39ddbee0c..a9391b4cbf57 100644
>> --- a/common/rc
>> +++ b/common/rc
>> @@ -1403,6 +1403,18 @@ _supported_os()
>>      _notrun "not suitable for this OS: $HOSTOS"
>>  }
>>
>> +_require_btrfs_unloadable()
>
> The name seems misleading, the name indicates that it requires btrfs to
> be unloadable, but in the code it _notrun if btrfs is unloadable.

  ok. Will rename it.

Thanks, Anand


> Thanks,
> Eryu
>
>> +{
>> +	modprobe -r btrfs || _notrun "btrfs unloadable"
>> +	modprobe btrfs || _notrun "Can't load btrfs"
>> +}
>> +
>> +_reload_btrfs_ko()
>> +{
>> +	modprobe -r btrfs || _fail "btrfs unload failed"
>> +	modprobe btrfs || _fail "btrfs load failed"
>> +}
>> +
>>  # this test needs a scratch partition - check we're ok & unmount it
>>  # No post-test check of the device is required. e.g. the test intentionally
>>  # finishes the test with the filesystem in a corrupt state
>> --
>> 2.7.0
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe fstests" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 5/6] fstests: btrfs: test RAID1 device reappear and balanced
  2016-06-12  5:06   ` Eryu Guan
@ 2016-06-15  8:45     ` Anand Jain
  0 siblings, 0 replies; 32+ messages in thread
From: Anand Jain @ 2016-06-15  8:45 UTC (permalink / raw)
  To: Eryu Guan; +Cc: fstests, linux-btrfs



On 06/12/2016 01:06 PM, Eryu Guan wrote:
> On Tue, May 17, 2016 at 10:32:09PM +0800, Anand Jain wrote:
>> The test does the following:
>>   Initialize a RAID1 with some data
>>
>>   Re-mount RAID1 degraded with _dev1_ and write up to
>>   half of the FS capacity
>>   Save md5sum checkpoint1
>>
>>   Re-mount healthy RAID1
>>
>>   Let balance re-silver.
>>   Save md5sum checkpoint2
>>
>>   Re-mount RAID1 degraded with _dev2_
>>   Save md5sum checkpoint3
>>
>>   Verify if all three md5sum match
>>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>> ---
>>  tests/btrfs/121     | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>>  tests/btrfs/121.out |   8 +++
>>  tests/btrfs/group   |   1 +
>>  3 files changed, 172 insertions(+)
>>  create mode 100755 tests/btrfs/121
>>  create mode 100644 tests/btrfs/121.out
>>
>> diff --git a/tests/btrfs/121 b/tests/btrfs/121
>> new file mode 100755
>> index 000000000000..81b7deb047af
>> --- /dev/null
>> +++ b/tests/btrfs/121
>> @@ -0,0 +1,163 @@
>> +#! /bin/bash
>> +# FS QA Test 121
>> +#
>> +# This test verify the RAID1 reconstruction on the reappeared
>> +# device. By using the following steps:
>> +# Initialize a RAID1 with some data
>> +#
>> +# Re-mount RAID1 degraded with dev2 missing and write up to
>> +# half of the FS capacity.
>> +# Save md5sum checkpoint1
>> +#
>> +# Re-mount healthy RAID1
>> +#
>> +# Let balance re-silver.
>> +# Save md5sum checkpoint2
>> +#
>> +# Re-mount RAID1 degraded with dev1 missing
>> +# Save md5sum checkpoint3
>> +#
>> +# Verify if all three checkpoints match
>> +#
>> +#---------------------------------------------------------------------
>> +# Copyright (c) 2016 Oracle.  All Rights Reserved.
>> +#
>> +# This program is free software; you can redistribute it and/or
>> +# modify it under the terms of the GNU General Public License as
>> +# published by the Free Software Foundation.
>> +#
>> +# This program is distributed in the hope that it would be useful,
>> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
>> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> +# GNU General Public License for more details.
>> +#
>> +# You should have received a copy of the GNU General Public License
>> +# along with this program; if not, write the Free Software Foundation,
>> +# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
>> +#---------------------------------------------------------------------
>> +#
>> +
>> +seq=`basename $0`
>> +seqres=$RESULT_DIR/$seq
>> +echo "QA output created by $seq"
>> +
>> +here=`pwd`
>> +status=1	# failure is the default!
>> +trap "_cleanup; exit \$status" 0 1 2 3 15
>> +
>> +_cleanup()
>> +{
>> +	cd /
>
> The "rm -f $tmp.*" is still needed even $tmp.* is not used in the test
> itself, it's still possible to be used by some helper functions.

  I didn't set the tmp= either, so is it mandatory to set tmp=?
  Anyway have done it in v2.

>> +}
>> +
>> +# 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
>> +
>> +_supported_fs btrfs
>> +_supported_os Linux
>> +_require_scratch_nocheck
>> +_require_scratch_dev_pool 2
>> +
>> +# the mounted test dir prevent btrfs unload, we need to unmount
>> +_test_unmount
>> +_require_btrfs_unloadable
>> +
>> +_scratch_dev_pool_get 2
>> +
>> +dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
>> +dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
>> +
>> +dev1_sz=`blockdev --getsize64 $dev1`
>> +dev2_sz=`blockdev --getsize64 $dev2`
>> +# get min of both
>> +max_fs_sz=`echo -e "$dev1_sz\n$dev2_sz" | sort | head -1`
>> +max_fs_sz=$(( max_fs_sz/2 ))
>> +if [ $max_fs_sz -gt 1000000 ]; then
>> +	bs="1M"
>> +	count=$(( max_fs_sz/1000000 ))
>> +else
>> +	max_fs_sz=$(( max_fs_sz*2 ))
>> +	_notrun "Smallest dev size $max_fs_sz, Need at least 2M"
>> +fi
>> +
>> +echo >> $seqres.full
>> +echo "max_fs_sz=$max_fs_sz count=$count" >> $seqres.full
>> +echo "-----Initialize -----" >> $seqres.full
>> +_scratch_pool_mkfs "-mraid1 -draid1" >> $seqres.full 2>&1
>> +_scratch_mount >> $seqres.full 2>&1
>> +_run_btrfs_util_prog filesystem show
>> +dd if=/dev/zero of="$SCRATCH_MNT"/tf1 bs=$bs count=1 \
>> +					>>$seqres.full 2>&1
>> +count=$(( count-- ))
>> +echo "unmount" >> $seqres.full
>> +echo "clean btrfs ko" >> $seqres.full
>> +_scratch_unmount
>> +_reload_btrfs_ko
>
> A comment to explain the reason to reload btrfs.ko would be good.

yes. added.

>> +
>> +
>> +echo >> $seqres.full
>> +echo "-----Write degraded mount fill upto $max_fs_sz bytes-----" >> $seqres.full
>> +echo
>> +echo "Write data with degraded mount"
>> +# Since we didn't run dev scan, btrfs kernel does not know
>> +# about the dev2
>> +# don't use _scratch_mount as we want to control
>> +# the device used for mounting.
>> +
>> +_mount -o degraded $dev1 $SCRATCH_MNT >>$seqres.full 2>&1
>> +_run_btrfs_util_prog filesystem show
>> +dd if=/dev/zero of="$SCRATCH_MNT"/tf2 bs=$bs count=$count \
>> +					>>$seqres.full 2>&1
>> +checkpoint1=`md5sum $SCRATCH_MNT/tf2`
>> +echo $checkpoint1 >> $seqres.full 2>&1
>> +_scratch_unmount
>> +echo "unmount" >> $seqres.full
>> +
>> +echo >> $seqres.full
>> +echo "-----Mount normal-----" >> $seqres.full
>> +echo
>> +echo "Mount normal after balance"
>> +_run_btrfs_util_prog device scan
>> +_scratch_mount >> $seqres.full 2>&1
>> +_run_btrfs_util_prog filesystem show
>> +echo >> $seqres.full
>> +_run_btrfs_util_prog balance start ${SCRATCH_MNT}
>> +
>> +checkpoint2=`md5sum $SCRATCH_MNT/tf2`
>> +echo $checkpoint2 >> $seqres.full 2>&1
>> +
>> +echo >> $seqres.full
>> +echo "-----Mount degraded but with other dev -----" >> $seqres.full
>> +echo
>> +echo "Mount degraded but with other dev"
>> +_scratch_unmount
>> +_reload_btrfs_ko
>> +_mount -o degraded $dev2 $SCRATCH_MNT >>$seqres.full 2>&1
>> +_run_btrfs_util_prog filesystem show
>> +checkpoint3=`md5sum $SCRATCH_MNT/tf2`
>> +echo $checkpoint3 >> $seqres.full 2>&1
>> +
>> +if [ "$checkpoint1" != "$checkpoint2" ]; then
>> +	echo $checkpoint1
>> +	echo $checkpoint2
>> +	_fail "Inital sum does not match with after balance"
>> +fi
>> +
>> +if [ "$checkpoint1" != "$checkpoint3" ]; then
>> +	echo $checkpoint1
>> +	echo $checkpoint3
>> +	_fail "Inital sum does not match with data on dev2 written by balance"
>
> Just "echo" error message, not _fail. _fail causes the test to exit,
> leaves the following "_scratch_dev_pool_put; _test_mount" not run.

Ah. yes. Thanks fixed it.

>> +fi
>> +
>> +_scratch_dev_pool_put
>> +_test_mount
>> +
>> +echo "Silence is golden"
>
> There're outputs in golden image, then this line is not needed.

fixed it in v2.

Thanks, Anand


> Thanks,
> Eryu
>
>> +status=0
>> +exit
>> diff --git a/tests/btrfs/121.out b/tests/btrfs/121.out
>> new file mode 100644
>> index 000000000000..0728787d17bc
>> --- /dev/null
>> +++ b/tests/btrfs/121.out
>> @@ -0,0 +1,8 @@
>> +QA output created by 121
>> +
>> +Write data with degraded mount
>> +
>> +Mount normal after balance
>> +
>> +Mount degraded but with other dev
>> +Silence is golden
>> diff --git a/tests/btrfs/group b/tests/btrfs/group
>> index 90af8fc2d106..5c28a3ca0687 100644
>> --- a/tests/btrfs/group
>> +++ b/tests/btrfs/group
>> @@ -122,3 +122,4 @@
>>  118 auto quick snapshot metadata
>>  119 auto quick snapshot metadata qgroup
>>  120 auto quick snapshot metadata
>> +121 auto replace
>> --
>> 2.7.0
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe fstests" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v2 1/6] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL
  2016-05-17 14:32 [PATCH 1/6] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL Anand Jain
                   ` (5 preceding siblings ...)
  2016-06-12  4:40 ` [PATCH 1/6] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL Eryu Guan
@ 2016-06-15  8:46 ` Anand Jain
  2016-06-21 13:20   ` Eryu Guan
  2016-06-23 13:25   ` [PATCH v3 " Anand Jain
  6 siblings, 2 replies; 32+ messages in thread
From: Anand Jain @ 2016-06-15  8:46 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs

From: Anand Jain <Anand.Jain@oracle.com>

This patch provides functions
 _scratch_dev_pool_get()
 _scratch_dev_pool_put()

Which will help to set/reset SCRATCH_DEV_POOL with the required
number of devices. SCRATCH_DEV_POOL_SAVED will hold all the devices.

Usage:
  _scratch_dev_pool_get() <ndevs>
  :: do stuff

  _scratch_dev_pool_put()

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 v2: Error message and comment section updates.

 common/rc | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/common/rc b/common/rc
index 51092a0644f0..31c46ba1226e 100644
--- a/common/rc
+++ b/common/rc
@@ -802,6 +802,61 @@ _scratch_mkfs()
     esac
 }
 
+#
+# Generally test cases will have..
+#   _require_scratch_dev_pool X
+# to make sure it has the enough scratch devices including
+# replace-target and spare device. Now arg1 here is the
+# required number of scratch devices by a-test-case excluding
+# the replace-target and spare device. So this function will
+# set SCRATCH_DEV_POOL to the specified number of devices.
+#
+# Usage:
+#  _scratch_dev_pool_get() <ndevs>
+#     :: do stuff
+#
+#  _scratch_dev_pool_put()
+#
+_scratch_dev_pool_get()
+{
+	if [ $# != 1 ]; then
+		_fail "Usage: _scratch_dev_pool_get ndevs"
+	fi
+
+	local test_ndevs=$1
+	local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
+	local devs[]="( $SCRATCH_DEV_POOL )"
+
+	typeset -p config_ndevs >/dev/null 2>&1
+	if [ $? != 0 ]; then
+		_fail "Bug: cant find SCRATCH_DEV_POOL ndevs"
+	fi
+
+	if [ $config_ndevs -lt $test_ndevs ]; then
+		_notrun "Need at least test requested number of ndevs $test_ndevs"
+	fi
+
+	SCRATCH_DEV_POOL_SAVED=${SCRATCH_DEV_POOL}
+	export SCRATCH_DEV_POOL_SAVED
+	SCRATCH_DEV_POOL=${devs[@]:0:$test_ndevs}
+	export SCRATCH_DEV_POOL
+}
+
+_scratch_dev_pool_put()
+{
+	typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
+	if [ $? != 0 ]; then
+		_fail "Bug: unset val, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
+	fi
+
+	if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
+		_fail "Bug: str empty, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
+	fi
+
+	export SCRATCH_DEV_POOL=$SCRATCH_DEV_POOL_SAVED
+	export SCRATCH_DEV_POOL_SAVED=""
+}
+
 _scratch_pool_mkfs()
 {
     case $FSTYP in
-- 
2.7.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH v2 2/6] fstests: btrfs: add functions to get and put a device for replace target
  2016-05-17 14:32 ` [PATCH 2/6] fstests: btrfs: add functions to get and put a device for replace target Anand Jain
  2016-06-12  4:42   ` Eryu Guan
@ 2016-06-15  8:47   ` Anand Jain
  1 sibling, 0 replies; 32+ messages in thread
From: Anand Jain @ 2016-06-15  8:47 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs

From: Anand Jain <Anand.Jain@oracle.com>

For the replace tests we need a device as a spare device,
here functions _spare_dev_get() and _spare_dev_put()
will get it from the SCRATCH_DEV_POOL_SAVED, which is set
when _scratch_dev_pool_get() is called, and is based on how
many has already been assigned to SCRATCH_DEV_POOL.

 usage:
   _scratch_dev_pool_get 3
   _spare_dev_get

      SPARE_DEV will have a device set which can be
      used as the replace target device.

   _spare_dev_put
   _scratch_dev_pool_put

_spare_dev_get() will pick the next device after SCRATCH_DEV_POOL
devices, from the SCRATCH_DEV_POOL_SAVED, and assigns it to
SPARE_DEV. _spare_dev_put() will set to SPARE_DEV to null.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 v2: Added comments

 common/rc | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/common/rc b/common/rc
index 31c46ba1226e..ffdbfcdae68d 100644
--- a/common/rc
+++ b/common/rc
@@ -802,6 +802,65 @@ _scratch_mkfs()
     esac
 }
 
+# Helper function to get a spare or replace-target device from
+# configured SCRATCH_DEV_POLL, must call _scratch_dev_pool_get()
+# before _spare_dev_get(). Replace-target-device/Spare-device will
+# be assigned to SPARE_DEV.
+# As of now only one replace-target-device/spare-device can be
+# assigned.
+#
+# Usage:
+#  _scratch_dev_pool_get() <ndevs>
+#     _spare_dev_get()
+#     :: do stuff
+#     _spare_dev_put()
+#  _scratch_dev_pool_put()
+#
+_spare_dev_get()
+{
+	typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
+	if [ $? != 0 ]; then
+		_fail "Bug: unset val, must call _scratch_dev_pool_get before _spare_dev_get"
+	fi
+
+	if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
+		_fail "Bug: str empty, must call _scratch_dev_pool_get before _spare_dev_get"
+	fi
+
+	# Check if the spare is already assigned
+	typeset -p SPARE_DEV >/dev/null 2>&1
+	if [ $? == 0 ]; then
+		if [ ! -z "$SPARE_DEV" ]; then
+			_fail "Bug: SPARE_DEV = $SPARE_DEV already assigned"
+		fi
+	fi
+
+	local ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
+	local config_ndevs=`echo $SCRATCH_DEV_POOL_SAVED| wc -w`
+
+	if [ $ndevs -eq $config_ndevs ]; then
+		_notrun "All devs used no spare"
+	fi
+	# Get a dev that is not used
+	local devs[]="( $SCRATCH_DEV_POOL_SAVED )"
+	SPARE_DEV=${devs[@]:$ndevs:1}
+	export SPARE_DEV
+}
+
+_spare_dev_put()
+{
+	typeset -p SPARE_DEV >/dev/null 2>&1
+	if [ $? != 0 ]; then
+		_fail "Bug: unset val, must call _spare_dev_get before its put"
+	fi
+
+	if [ -z "$SPARE_DEV" ]; then
+		_fail "Bug: str empty, must call _spare_dev_get before its put"
+	fi
+
+	export SPARE_DEV=""
+}
+
 #
 # Generally test cases will have..
 #   _require_scratch_dev_pool X
-- 
2.7.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH v2 4/6] fstests: btrfs: add helper function to check if btrfs is module
  2016-05-17 14:32 ` [PATCH 4/6] fstests: btrfs: add helper function to check if btrfs is module Anand Jain
  2016-06-12  4:53   ` Eryu Guan
@ 2016-06-15  8:47   ` Anand Jain
  1 sibling, 0 replies; 32+ messages in thread
From: Anand Jain @ 2016-06-15  8:47 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs

From: Anand Jain <Anand.Jain@oracle.com>

We need btrfs to be a module so that it can unloaded and reloaded,
so that we can clean up the btrfs internal in memory device list.

This patch adds _require_btrfs_unloadable() and _reload_btrfs_ko()
to help with the same.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: rename _require_btrfs_unloadable to _require_btrfs_loadable

 common/rc | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/common/rc b/common/rc
index ffdbfcdae68d..89281171365f 100644
--- a/common/rc
+++ b/common/rc
@@ -1441,6 +1441,18 @@ _supported_os()
     _notrun "not suitable for this OS: $HOSTOS"
 }
 
+_require_btrfs_loadable()
+{
+	modprobe -r btrfs || _notrun "btrfs unloadable"
+	modprobe btrfs || _notrun "Can't load btrfs"
+}
+
+_reload_btrfs_ko()
+{
+	modprobe -r btrfs || _fail "btrfs unload failed"
+	modprobe btrfs || _fail "btrfs load failed"
+}
+
 # this test needs a scratch partition - check we're ok & unmount it
 # No post-test check of the device is required. e.g. the test intentionally
 # finishes the test with the filesystem in a corrupt state
-- 
2.7.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH v2 5/6] fstests: btrfs: test RAID1 device reappear and balanced
  2016-05-17 14:32 ` [PATCH 5/6] fstests: btrfs: test RAID1 device reappear and balanced Anand Jain
  2016-06-12  5:06   ` Eryu Guan
@ 2016-06-15  8:48   ` Anand Jain
  2016-06-21 13:31     ` Eryu Guan
  2016-06-23 13:28     ` [PATCH v3 2/6] fstests: btrfs: add functions to get and put a device for replace target Anand Jain
  2016-06-30 10:58   ` [PATCH v3 5/6] fstests: btrfs: test RAID1 device reappear and balanced Anand Jain
  2 siblings, 2 replies; 32+ messages in thread
From: Anand Jain @ 2016-06-15  8:48 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs

From: Anand Jain <Anand.Jain@oracle.com>

The test does the following:
  Initialize a RAID1 with some data

  Re-mount RAID1 degraded with _dev1_ and write up to
  half of the FS capacity
  Save md5sum checkpoint1

  Re-mount healthy RAID1

  Let balance re-silver.
  Save md5sum checkpoint2

  Re-mount RAID1 degraded with _dev2_
  Save md5sum checkpoint3

  Verify if all three md5sum match

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2:
  add tmp= and its rm
  add comments to why _reload_btrfs_ko is used
  add missing put and test_mount at notrun exit
  use echo instead of _fail when checkpoints are checked
  .out updated to remove Silence..

 tests/btrfs/123     | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/123.out |   7 +++
 tests/btrfs/group   |   1 +
 3 files changed, 177 insertions(+)
 create mode 100755 tests/btrfs/123
 create mode 100644 tests/btrfs/123.out

diff --git a/tests/btrfs/123 b/tests/btrfs/123
new file mode 100755
index 000000000000..33decfd1c434
--- /dev/null
+++ b/tests/btrfs/123
@@ -0,0 +1,169 @@
+#! /bin/bash
+# FS QA Test 123
+#
+# This test verify the RAID1 reconstruction on the reappeared
+# device. By using the following steps:
+# Initialize a RAID1 with some data
+#
+# Re-mount RAID1 degraded with dev2 missing and write up to
+# half of the FS capacity.
+# Save md5sum checkpoint1
+#
+# Re-mount healthy RAID1
+#
+# Let balance re-silver.
+# Save md5sum checkpoint2
+#
+# Re-mount RAID1 degraded with dev1 missing
+# Save md5sum checkpoint3
+#
+# Verify if all three checkpoints match
+#
+#---------------------------------------------------------------------
+# Copyright (c) 2016 Oracle.  All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#---------------------------------------------------------------------
+#
+
+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.*
+}
+
+# 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
+
+_supported_fs btrfs
+_supported_os Linux
+_require_scratch_nocheck
+_require_scratch_dev_pool 2
+
+# the mounted test dir prevent btrfs unload, we need to unmount
+_test_unmount
+_require_btrfs_loadable
+
+_scratch_dev_pool_get 2
+
+dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
+dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
+
+dev1_sz=`blockdev --getsize64 $dev1`
+dev2_sz=`blockdev --getsize64 $dev2`
+# get min of both
+max_fs_sz=`echo -e "$dev1_sz\n$dev2_sz" | sort | head -1`
+max_fs_sz=$(( max_fs_sz/2 ))
+if [ $max_fs_sz -gt 1000000 ]; then
+	bs="1M"
+	count=$(( max_fs_sz/1000000 ))
+else
+	max_fs_sz=$(( max_fs_sz*2 ))
+	_scratch_dev_pool_put
+	_test_mount
+	_notrun "Smallest dev size $max_fs_sz, Need at least 2M"
+fi
+
+echo >> $seqres.full
+echo "max_fs_sz=$max_fs_sz count=$count" >> $seqres.full
+echo "-----Initialize -----" >> $seqres.full
+_scratch_pool_mkfs "-mraid1 -draid1" >> $seqres.full 2>&1
+_scratch_mount >> $seqres.full 2>&1
+_run_btrfs_util_prog filesystem show
+dd if=/dev/zero of="$SCRATCH_MNT"/tf1 bs=$bs count=1 \
+					>>$seqres.full 2>&1
+count=$(( count-- ))
+echo "unmount" >> $seqres.full
+echo "clean btrfs ko" >> $seqres.full
+_scratch_unmount
+
+# un-scan the btrfs devices
+_reload_btrfs_ko
+
+
+echo >> $seqres.full
+echo "-----Write degraded mount fill upto $max_fs_sz bytes-----" >> $seqres.full
+echo
+echo "Write data with degraded mount"
+# Since we didn't run dev scan, btrfs kernel does not know
+# about the dev2
+# don't use _scratch_mount as we want to control
+# the device used for mounting.
+
+_mount -o degraded $dev1 $SCRATCH_MNT >>$seqres.full 2>&1
+_run_btrfs_util_prog filesystem show
+dd if=/dev/zero of="$SCRATCH_MNT"/tf2 bs=$bs count=$count \
+					>>$seqres.full 2>&1
+checkpoint1=`md5sum $SCRATCH_MNT/tf2`
+echo $checkpoint1 >> $seqres.full 2>&1
+_scratch_unmount
+echo "unmount" >> $seqres.full
+
+echo >> $seqres.full
+echo "-----Mount normal-----" >> $seqres.full
+echo
+echo "Mount normal after balance"
+_run_btrfs_util_prog device scan
+_scratch_mount >> $seqres.full 2>&1
+_run_btrfs_util_prog filesystem show
+echo >> $seqres.full
+_run_btrfs_util_prog balance start ${SCRATCH_MNT}
+
+checkpoint2=`md5sum $SCRATCH_MNT/tf2`
+echo $checkpoint2 >> $seqres.full 2>&1
+
+echo >> $seqres.full
+echo "-----Mount degraded but with other dev -----" >> $seqres.full
+echo
+echo "Mount degraded but with other dev"
+_scratch_unmount
+# un-scan the btrfs devices
+_reload_btrfs_ko
+_mount -o degraded $dev2 $SCRATCH_MNT >>$seqres.full 2>&1
+_run_btrfs_util_prog filesystem show
+checkpoint3=`md5sum $SCRATCH_MNT/tf2`
+echo $checkpoint3 >> $seqres.full 2>&1
+
+if [ "$checkpoint1" != "$checkpoint2" ]; then
+	echo $checkpoint1
+	echo $checkpoint2
+	echo "Inital sum does not match with after balance"
+fi
+
+if [ "$checkpoint1" != "$checkpoint3" ]; then
+	echo $checkpoint1
+	echo $checkpoint3
+	echo "Inital sum does not match with data on dev2 written by balance"
+fi
+
+_scratch_dev_pool_put
+_test_mount
+
+status=0
+exit
diff --git a/tests/btrfs/123.out b/tests/btrfs/123.out
new file mode 100644
index 000000000000..1aa77036b55b
--- /dev/null
+++ b/tests/btrfs/123.out
@@ -0,0 +1,7 @@
+QA output created by 123
+
+Write data with degraded mount
+
+Mount normal after balance
+
+Mount degraded but with other dev
diff --git a/tests/btrfs/group b/tests/btrfs/group
index da0e27fa308d..1c4bfa8dbc96 100644
--- a/tests/btrfs/group
+++ b/tests/btrfs/group
@@ -124,3 +124,4 @@
 120 auto quick snapshot metadata
 121 auto quick snapshot qgroup
 122 auto quick snapshot qgroup
+123 auto replace
-- 
2.7.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH v2 6/6] fstests: btrfs: test RAID5 device reappear and balance
  2016-05-17 14:32 ` [PATCH 6/6] fstests: btrfs: test RAID5 device reappear and balance Anand Jain
  2016-06-12  5:08   ` Eryu Guan
@ 2016-06-15  8:49   ` Anand Jain
  2016-06-30 10:59   ` [PATCH v3 " Anand Jain
  2 siblings, 0 replies; 32+ messages in thread
From: Anand Jain @ 2016-06-15  8:49 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs

From: Anand Jain <Anand.Jain@oracle.com>

The test does the following:
Initialize a RAID5 with some data

Re-mount RAID5 degraded with _dev3_ missing and write data.
Save md5sum checkpoint1

Re-mount healthy RAID5

Let balance fix degraded blocks.
Save md5sum checkpoint2

Re-mount RAID1 degraded now with _dev1_ missing.
Save md5sum checkpoint3

Verify if all three md5sum matches

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2:
  add tmp= and its rm
  add comments to why _reload_btrfs_ko is used
  add missing put and test_mount at notrun exit
  use echo instead of _fail when checkpoints are checked
  .out updated to remove Silence..
 tests/btrfs/124     | 183 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/124.out |   7 ++
 tests/btrfs/group   |   1 +
 3 files changed, 191 insertions(+)
 create mode 100755 tests/btrfs/124
 create mode 100644 tests/btrfs/124.out

diff --git a/tests/btrfs/124 b/tests/btrfs/124
new file mode 100755
index 000000000000..8ef7c62c4380
--- /dev/null
+++ b/tests/btrfs/124
@@ -0,0 +1,183 @@
+#! /bin/bash
+# FS QA Test 124
+#
+# This test verify if the reconstructed data on the RAID5 is good.
+# Steps:
+# Initialize RAID5 with some data
+#
+# Re-mount RAID5 degraded with dev3 missing and write data
+# Save md5sum checkpoint1
+#
+# Re-mount healthy RAID5
+#
+# Let balance fix the RAID5.
+# Save md5sum checkpoint2
+#
+# Re-mount RAID5 degraded with dev1 as missing.
+# Save md5sum checkpoint3
+#
+# Verify if all three checkpoints match
+#
+#---------------------------------------------------------------------
+# Copyright (c) 2016 Oracle.  All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#---------------------------------------------------------------------
+#
+
+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.*
+}
+
+# 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
+
+_supported_fs btrfs
+_supported_os Linux
+_require_scratch_nocheck
+_require_scratch_dev_pool 3
+
+# we need btrfs to unload, need test dir unmounted
+_test_unmount
+_require_btrfs_loadable
+
+_scratch_dev_pool_get 3
+
+dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
+dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
+dev3=`echo $SCRATCH_DEV_POOL | awk '{print $3}'`
+
+echo dev1=$dev1 >> $seqres.full
+echo dev2=$dev2 >> $seqres.full
+echo dev3=$dev3 >> $seqres.full
+
+# Balance won't be successful if filled too much
+dev1_sz=`blockdev --getsize64 $dev1`
+dev2_sz=`blockdev --getsize64 $dev2`
+dev3_sz=`blockdev --getsize64 $dev3`
+
+# get min of both
+max_fs_sz=`echo -e "$dev1_sz\n$dev2_sz\n$dev3_sz" | sort | head -1`
+if [ $max_fs_sz -gt 1000000 ]; then
+	bs="1M"
+	count=$(( max_fs_sz/1000000 ))
+	count=$(( count/100 ))
+else
+	_scratch_dev_pool_put
+	_test_mount
+	_notrun "Smallest dev size $max_fs_sz, Need at least 2M"
+fi
+
+#-------------init-------------------
+echo >> $seqres.full
+echo "max_fs_sz=$max_fs_sz count=$count" >> $seqres.full
+echo "-----Initialize -----" >> $seqres.full
+_scratch_pool_mkfs "-mraid5 -draid5" >> $seqres.full 2>&1
+_scratch_mount >> $seqres.full 2>&1
+dd if=/dev/zero of="$SCRATCH_MNT"/tf1 bs=$bs count=1 \
+					>>$seqres.full 2>&1
+_run_btrfs_util_prog filesystem show
+_run_btrfs_util_prog filesystem df $SCRATCH_MNT
+count=$(( count-- ))
+
+
+#-------------degraded-init-------------------
+echo >> $seqres.full
+echo "-----Write degraded mount fill upto $max_fs_sz bytes-----" >> $seqres.full
+echo
+echo "Write data with degraded mount"
+
+echo "unmount" >> $seqres.full
+_scratch_unmount
+echo "clean btrfs ko" >> $seqres.full
+# un-scan the btrfs devices
+_reload_btrfs_ko
+_mount -o degraded,device=$dev2 $dev1 $SCRATCH_MNT >>$seqres.full 2>&1
+dd if=/dev/zero of="$SCRATCH_MNT"/tf2 bs=$bs count=$count \
+					>>$seqres.full 2>&1
+_run_btrfs_util_prog filesystem show
+_run_btrfs_util_prog filesystem df $SCRATCH_MNT
+checkpoint1=`md5sum $SCRATCH_MNT/tf2`
+echo $checkpoint1 >> $seqres.full 2>&1
+
+#-------------balance-------------------
+echo >> $seqres.full
+echo "-----Mount normal-----" >> $seqres.full
+echo
+echo "Mount normal after balance"
+
+_scratch_unmount
+_run_btrfs_util_prog device scan
+_scratch_mount >> $seqres.full 2>&1
+
+echo >> $seqres.full
+_run_btrfs_util_prog balance start ${SCRATCH_MNT}
+
+_run_btrfs_util_prog filesystem show
+_run_btrfs_util_prog filesystem df ${SCRATCH_MNT}
+
+checkpoint2=`md5sum $SCRATCH_MNT/tf2`
+echo $checkpoint2 >> $seqres.full 2>&1
+
+#-------------degraded-mount-------------------
+echo >> $seqres.full
+echo "-----Mount degraded with dev1 missing-----" >> $seqres.full
+echo
+echo "Mount degraded but with other dev"
+
+_scratch_unmount
+# un-scan the btrfs devices
+_reload_btrfs_ko
+
+_mount -o degraded,device=${dev2} $dev3 $SCRATCH_MNT >>$seqres.full 2>&1
+
+_run_btrfs_util_prog filesystem show
+_run_btrfs_util_prog filesystem df $SCRATCH_MNT
+checkpoint3=`md5sum $SCRATCH_MNT/tf2`
+echo $checkpoint3 >> $seqres.full 2>&1
+
+if [ "$checkpoint1" != "$checkpoint2" ]; then
+	echo $checkpoint1
+	echo $checkpoint2
+	echo "Inital sum does not match with after balance"
+fi
+
+if [ "$checkpoint1" != "$checkpoint3" ]; then
+	echo $checkpoint1
+	echo $checkpoint3
+	echo "Inital sum does not match with data on dev2 written by balance"
+fi
+
+_scratch_dev_pool_put
+_test_mount
+
+status=0
+exit
diff --git a/tests/btrfs/124.out b/tests/btrfs/124.out
new file mode 100644
index 000000000000..60426e4ea3f8
--- /dev/null
+++ b/tests/btrfs/124.out
@@ -0,0 +1,7 @@
+QA output created by 124
+
+Write data with degraded mount
+
+Mount normal after balance
+
+Mount degraded but with other dev
diff --git a/tests/btrfs/group b/tests/btrfs/group
index 1c4bfa8dbc96..1866b17aa6df 100644
--- a/tests/btrfs/group
+++ b/tests/btrfs/group
@@ -125,3 +125,4 @@
 121 auto quick snapshot qgroup
 122 auto quick snapshot qgroup
 123 auto replace
+124 auto replace
-- 
2.7.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* Re: [PATCH 6/6] fstests: btrfs: test RAID5 device reappear and balance
  2016-06-12  5:08   ` Eryu Guan
@ 2016-06-15  8:51     ` Anand Jain
  0 siblings, 0 replies; 32+ messages in thread
From: Anand Jain @ 2016-06-15  8:51 UTC (permalink / raw)
  To: Eryu Guan; +Cc: fstests, linux-btrfs



On 06/12/2016 01:08 PM, Eryu Guan wrote:
> On Tue, May 17, 2016 at 10:32:10PM +0800, Anand Jain wrote:
>> The test does the following:
>> Initialize a RAID5 with some data
>>
>> Re-mount RAID5 degraded with _dev3_ missing and write data.
>> Save md5sum checkpoint1
>>
>> Re-mount healthy RAID5
>>
>> Let balance fix degraded blocks.
>> Save md5sum checkpoint2
>>
>> Re-mount RAID1 degraded now with _dev1_ missing.
>> Save md5sum checkpoint3
>>
>> Verify if all three md5sum matches
>>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>
> All comments for 5/6 apply here for 6/6 :)

yep. Taken care in v2. Thanks for all the review comments.

Anand

>
> Thanks,
> Eryu
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v2 1/6] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL
  2016-06-15  8:46 ` [PATCH v2 " Anand Jain
@ 2016-06-21 13:20   ` Eryu Guan
  2016-06-22 11:01     ` Anand Jain
  2016-06-23 13:25   ` [PATCH v3 " Anand Jain
  1 sibling, 1 reply; 32+ messages in thread
From: Eryu Guan @ 2016-06-21 13:20 UTC (permalink / raw)
  To: Anand Jain; +Cc: fstests, linux-btrfs

On Wed, Jun 15, 2016 at 04:46:03PM +0800, Anand Jain wrote:
> From: Anand Jain <Anand.Jain@oracle.com>
> 
> This patch provides functions
>  _scratch_dev_pool_get()
>  _scratch_dev_pool_put()
> 
> Which will help to set/reset SCRATCH_DEV_POOL with the required
> number of devices. SCRATCH_DEV_POOL_SAVED will hold all the devices.
> 
> Usage:
>   _scratch_dev_pool_get() <ndevs>
>   :: do stuff
> 
>   _scratch_dev_pool_put()
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>

I think the helpers should be introduced when they are first used, so
that we know why they're introduced, and know how they're used with
clear examples.

So patch 1, 2 and 4 can be merged as one patch, patch 3 updates
btrfs/027, patch 4 and patch 5 can be merged as one patch, then comes
patch 6.

What do you think?

> ---
>  v2: Error message and comment section updates.
> 
>  common/rc | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 55 insertions(+)
> 
> diff --git a/common/rc b/common/rc
> index 51092a0644f0..31c46ba1226e 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -802,6 +802,61 @@ _scratch_mkfs()
>      esac
>  }
>  
> +#
> +# Generally test cases will have..
> +#   _require_scratch_dev_pool X
> +# to make sure it has the enough scratch devices including
> +# replace-target and spare device. Now arg1 here is the
> +# required number of scratch devices by a-test-case excluding
> +# the replace-target and spare device. So this function will
> +# set SCRATCH_DEV_POOL to the specified number of devices.
> +#
> +# Usage:
> +#  _scratch_dev_pool_get() <ndevs>
> +#     :: do stuff
> +#
> +#  _scratch_dev_pool_put()
> +#
> +_scratch_dev_pool_get()
> +{
> +	if [ $# != 1 ]; then

"-ne" "-eq" etc. are used for comparing integers, "=!" "==" are for
strings. And I think $#, $? are integers here, "-ne" would be better.

Thanks,
Eryu

> +		_fail "Usage: _scratch_dev_pool_get ndevs"
> +	fi
> +
> +	local test_ndevs=$1
> +	local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
> +	local devs[]="( $SCRATCH_DEV_POOL )"
> +
> +	typeset -p config_ndevs >/dev/null 2>&1
> +	if [ $? != 0 ]; then
> +		_fail "Bug: cant find SCRATCH_DEV_POOL ndevs"
> +	fi
> +
> +	if [ $config_ndevs -lt $test_ndevs ]; then
> +		_notrun "Need at least test requested number of ndevs $test_ndevs"
> +	fi
> +
> +	SCRATCH_DEV_POOL_SAVED=${SCRATCH_DEV_POOL}
> +	export SCRATCH_DEV_POOL_SAVED
> +	SCRATCH_DEV_POOL=${devs[@]:0:$test_ndevs}
> +	export SCRATCH_DEV_POOL
> +}
> +
> +_scratch_dev_pool_put()
> +{
> +	typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
> +	if [ $? != 0 ]; then
> +		_fail "Bug: unset val, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
> +	fi
> +
> +	if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
> +		_fail "Bug: str empty, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
> +	fi
> +
> +	export SCRATCH_DEV_POOL=$SCRATCH_DEV_POOL_SAVED
> +	export SCRATCH_DEV_POOL_SAVED=""
> +}
> +
>  _scratch_pool_mkfs()
>  {
>      case $FSTYP in
> -- 
> 2.7.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v2 5/6] fstests: btrfs: test RAID1 device reappear and balanced
  2016-06-15  8:48   ` [PATCH v2 " Anand Jain
@ 2016-06-21 13:31     ` Eryu Guan
  2016-06-22 11:01       ` Anand Jain
  2016-06-23 13:28     ` [PATCH v3 2/6] fstests: btrfs: add functions to get and put a device for replace target Anand Jain
  1 sibling, 1 reply; 32+ messages in thread
From: Eryu Guan @ 2016-06-21 13:31 UTC (permalink / raw)
  To: Anand Jain; +Cc: fstests, linux-btrfs

On Wed, Jun 15, 2016 at 04:48:47PM +0800, Anand Jain wrote:
> From: Anand Jain <Anand.Jain@oracle.com>
> 
> The test does the following:
>   Initialize a RAID1 with some data
> 
>   Re-mount RAID1 degraded with _dev1_ and write up to
>   half of the FS capacity

If test devices are big enough, this test consumes much longer test
time. I tested with 15G scratch dev pool and this test ran ~200s on my
4vcpu 8G memory test vm.

Is it possible to limit the file size or the device size used? So it
won't grow with device size. I'm thinking about something like
_scratch_mkfs_sized, but that doesn't work for dev pool.

>   Save md5sum checkpoint1
> 
>   Re-mount healthy RAID1
> 
>   Let balance re-silver.
>   Save md5sum checkpoint2
> 
>   Re-mount RAID1 degraded with _dev2_
>   Save md5sum checkpoint3
> 
>   Verify if all three md5sum match
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
> v2:
>   add tmp= and its rm
>   add comments to why _reload_btrfs_ko is used
>   add missing put and test_mount at notrun exit
>   use echo instead of _fail when checkpoints are checked
>   .out updated to remove Silence..
> 
>  tests/btrfs/123     | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  tests/btrfs/123.out |   7 +++
>  tests/btrfs/group   |   1 +
>  3 files changed, 177 insertions(+)
>  create mode 100755 tests/btrfs/123
>  create mode 100644 tests/btrfs/123.out
> 
> diff --git a/tests/btrfs/123 b/tests/btrfs/123
> new file mode 100755
> index 000000000000..33decfd1c434
> --- /dev/null
> +++ b/tests/btrfs/123
> @@ -0,0 +1,169 @@
> +#! /bin/bash
> +# FS QA Test 123
> +#
> +# This test verify the RAID1 reconstruction on the reappeared
> +# device. By using the following steps:
> +# Initialize a RAID1 with some data
> +#
> +# Re-mount RAID1 degraded with dev2 missing and write up to
> +# half of the FS capacity.
> +# Save md5sum checkpoint1
> +#
> +# Re-mount healthy RAID1
> +#
> +# Let balance re-silver.
> +# Save md5sum checkpoint2
> +#
> +# Re-mount RAID1 degraded with dev1 missing
> +# Save md5sum checkpoint3
> +#
> +# Verify if all three checkpoints match
> +#
> +#---------------------------------------------------------------------
> +# Copyright (c) 2016 Oracle.  All Rights Reserved.
> +#
> +# This program is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU General Public License as
> +# published by the Free Software Foundation.
> +#
> +# This program is distributed in the hope that it would be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, write the Free Software Foundation,
> +# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
> +#---------------------------------------------------------------------
> +#
> +
> +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.*
> +}
> +
> +# 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
> +
> +_supported_fs btrfs
> +_supported_os Linux
> +_require_scratch_nocheck

Why don't check filesystem after test? A comment would be good if
there's a good reason. Patch 6 needs it as well :)

Thanks,
Eryu

> +_require_scratch_dev_pool 2
> +
> +# the mounted test dir prevent btrfs unload, we need to unmount
> +_test_unmount
> +_require_btrfs_loadable
> +
> +_scratch_dev_pool_get 2
> +
> +dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
> +dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
> +
> +dev1_sz=`blockdev --getsize64 $dev1`
> +dev2_sz=`blockdev --getsize64 $dev2`
> +# get min of both
> +max_fs_sz=`echo -e "$dev1_sz\n$dev2_sz" | sort | head -1`
> +max_fs_sz=$(( max_fs_sz/2 ))
> +if [ $max_fs_sz -gt 1000000 ]; then
> +	bs="1M"
> +	count=$(( max_fs_sz/1000000 ))
> +else
> +	max_fs_sz=$(( max_fs_sz*2 ))
> +	_scratch_dev_pool_put
> +	_test_mount
> +	_notrun "Smallest dev size $max_fs_sz, Need at least 2M"
> +fi
> +
> +echo >> $seqres.full
> +echo "max_fs_sz=$max_fs_sz count=$count" >> $seqres.full
> +echo "-----Initialize -----" >> $seqres.full
> +_scratch_pool_mkfs "-mraid1 -draid1" >> $seqres.full 2>&1
> +_scratch_mount >> $seqres.full 2>&1
> +_run_btrfs_util_prog filesystem show
> +dd if=/dev/zero of="$SCRATCH_MNT"/tf1 bs=$bs count=1 \
> +					>>$seqres.full 2>&1
> +count=$(( count-- ))
> +echo "unmount" >> $seqres.full
> +echo "clean btrfs ko" >> $seqres.full
> +_scratch_unmount
> +
> +# un-scan the btrfs devices
> +_reload_btrfs_ko
> +
> +
> +echo >> $seqres.full
> +echo "-----Write degraded mount fill upto $max_fs_sz bytes-----" >> $seqres.full
> +echo
> +echo "Write data with degraded mount"
> +# Since we didn't run dev scan, btrfs kernel does not know
> +# about the dev2
> +# don't use _scratch_mount as we want to control
> +# the device used for mounting.
> +
> +_mount -o degraded $dev1 $SCRATCH_MNT >>$seqres.full 2>&1
> +_run_btrfs_util_prog filesystem show
> +dd if=/dev/zero of="$SCRATCH_MNT"/tf2 bs=$bs count=$count \
> +					>>$seqres.full 2>&1
> +checkpoint1=`md5sum $SCRATCH_MNT/tf2`
> +echo $checkpoint1 >> $seqres.full 2>&1
> +_scratch_unmount
> +echo "unmount" >> $seqres.full
> +
> +echo >> $seqres.full
> +echo "-----Mount normal-----" >> $seqres.full
> +echo
> +echo "Mount normal after balance"
> +_run_btrfs_util_prog device scan
> +_scratch_mount >> $seqres.full 2>&1
> +_run_btrfs_util_prog filesystem show
> +echo >> $seqres.full
> +_run_btrfs_util_prog balance start ${SCRATCH_MNT}
> +
> +checkpoint2=`md5sum $SCRATCH_MNT/tf2`
> +echo $checkpoint2 >> $seqres.full 2>&1
> +
> +echo >> $seqres.full
> +echo "-----Mount degraded but with other dev -----" >> $seqres.full
> +echo
> +echo "Mount degraded but with other dev"
> +_scratch_unmount
> +# un-scan the btrfs devices
> +_reload_btrfs_ko
> +_mount -o degraded $dev2 $SCRATCH_MNT >>$seqres.full 2>&1
> +_run_btrfs_util_prog filesystem show
> +checkpoint3=`md5sum $SCRATCH_MNT/tf2`
> +echo $checkpoint3 >> $seqres.full 2>&1
> +
> +if [ "$checkpoint1" != "$checkpoint2" ]; then
> +	echo $checkpoint1
> +	echo $checkpoint2
> +	echo "Inital sum does not match with after balance"
> +fi
> +
> +if [ "$checkpoint1" != "$checkpoint3" ]; then
> +	echo $checkpoint1
> +	echo $checkpoint3
> +	echo "Inital sum does not match with data on dev2 written by balance"
> +fi
> +
> +_scratch_dev_pool_put
> +_test_mount
> +
> +status=0
> +exit
> diff --git a/tests/btrfs/123.out b/tests/btrfs/123.out
> new file mode 100644
> index 000000000000..1aa77036b55b
> --- /dev/null
> +++ b/tests/btrfs/123.out
> @@ -0,0 +1,7 @@
> +QA output created by 123
> +
> +Write data with degraded mount
> +
> +Mount normal after balance
> +
> +Mount degraded but with other dev
> diff --git a/tests/btrfs/group b/tests/btrfs/group
> index da0e27fa308d..1c4bfa8dbc96 100644
> --- a/tests/btrfs/group
> +++ b/tests/btrfs/group
> @@ -124,3 +124,4 @@
>  120 auto quick snapshot metadata
>  121 auto quick snapshot qgroup
>  122 auto quick snapshot qgroup
> +123 auto replace
> -- 
> 2.7.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v2 1/6] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL
  2016-06-21 13:20   ` Eryu Guan
@ 2016-06-22 11:01     ` Anand Jain
  0 siblings, 0 replies; 32+ messages in thread
From: Anand Jain @ 2016-06-22 11:01 UTC (permalink / raw)
  To: Eryu Guan; +Cc: fstests, linux-btrfs



On 06/21/2016 09:20 PM, Eryu Guan wrote:
> On Wed, Jun 15, 2016 at 04:46:03PM +0800, Anand Jain wrote:
>> From: Anand Jain <Anand.Jain@oracle.com>
>>
>> This patch provides functions
>>  _scratch_dev_pool_get()
>>  _scratch_dev_pool_put()
>>
>> Which will help to set/reset SCRATCH_DEV_POOL with the required
>> number of devices. SCRATCH_DEV_POOL_SAVED will hold all the devices.
>>
>> Usage:
>>   _scratch_dev_pool_get() <ndevs>
>>   :: do stuff
>>
>>   _scratch_dev_pool_put()
>>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>
> I think the helpers should be introduced when they are first used, so
> that we know why they're introduced, and know how they're used with
> clear examples.
>
> So patch 1, 2 and 4 can be merged as one patch, patch 3 updates
> btrfs/027, patch 4 and patch 5 can be merged as one patch, then comes
> patch 6.
>
> What do you think?

  Hm. I won't bother much on that. will do if needed.
  (just a note- On the other hand it gets noticed about the
  new helper function if its a separate patch for helper
  function).

>> ---
>>  v2: Error message and comment section updates.
>>
>>  common/rc | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 55 insertions(+)
>>
>> diff --git a/common/rc b/common/rc
>> index 51092a0644f0..31c46ba1226e 100644
>> --- a/common/rc
>> +++ b/common/rc
>> @@ -802,6 +802,61 @@ _scratch_mkfs()
>>      esac
>>  }
>>
>> +#
>> +# Generally test cases will have..
>> +#   _require_scratch_dev_pool X
>> +# to make sure it has the enough scratch devices including
>> +# replace-target and spare device. Now arg1 here is the
>> +# required number of scratch devices by a-test-case excluding
>> +# the replace-target and spare device. So this function will
>> +# set SCRATCH_DEV_POOL to the specified number of devices.
>> +#
>> +# Usage:
>> +#  _scratch_dev_pool_get() <ndevs>
>> +#     :: do stuff
>> +#
>> +#  _scratch_dev_pool_put()
>> +#
>> +_scratch_dev_pool_get()
>> +{
>> +	if [ $# != 1 ]; then
>
> "-ne" "-eq" etc. are used for comparing integers, "=!" "==" are for
> strings. And I think $#, $? are integers here, "-ne" would be better.

  Thanks for the catch. fixed in next rev.

- Anand


> Thanks,
> Eryu
>
>> +		_fail "Usage: _scratch_dev_pool_get ndevs"
>> +	fi
>> +
>> +	local test_ndevs=$1
>> +	local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
>> +	local devs[]="( $SCRATCH_DEV_POOL )"
>> +
>> +	typeset -p config_ndevs >/dev/null 2>&1
>> +	if [ $? != 0 ]; then
>> +		_fail "Bug: cant find SCRATCH_DEV_POOL ndevs"
>> +	fi
>> +
>> +	if [ $config_ndevs -lt $test_ndevs ]; then
>> +		_notrun "Need at least test requested number of ndevs $test_ndevs"
>> +	fi
>> +
>> +	SCRATCH_DEV_POOL_SAVED=${SCRATCH_DEV_POOL}
>> +	export SCRATCH_DEV_POOL_SAVED
>> +	SCRATCH_DEV_POOL=${devs[@]:0:$test_ndevs}
>> +	export SCRATCH_DEV_POOL
>> +}
>> +
>> +_scratch_dev_pool_put()
>> +{
>> +	typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
>> +	if [ $? != 0 ]; then
>> +		_fail "Bug: unset val, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
>> +	fi
>> +
>> +	if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
>> +		_fail "Bug: str empty, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
>> +	fi
>> +
>> +	export SCRATCH_DEV_POOL=$SCRATCH_DEV_POOL_SAVED
>> +	export SCRATCH_DEV_POOL_SAVED=""
>> +}
>> +
>>  _scratch_pool_mkfs()
>>  {
>>      case $FSTYP in
>> --
>> 2.7.0
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe fstests" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v2 5/6] fstests: btrfs: test RAID1 device reappear and balanced
  2016-06-21 13:31     ` Eryu Guan
@ 2016-06-22 11:01       ` Anand Jain
  2016-06-27  9:29         ` Eryu Guan
  0 siblings, 1 reply; 32+ messages in thread
From: Anand Jain @ 2016-06-22 11:01 UTC (permalink / raw)
  To: Eryu Guan; +Cc: fstests, linux-btrfs



On 06/21/2016 09:31 PM, Eryu Guan wrote:
> On Wed, Jun 15, 2016 at 04:48:47PM +0800, Anand Jain wrote:
>> From: Anand Jain <Anand.Jain@oracle.com>
>>
>> The test does the following:
>>   Initialize a RAID1 with some data
>>
>>   Re-mount RAID1 degraded with _dev1_ and write up to
>>   half of the FS capacity
>
> If test devices are big enough, this test consumes much longer test
> time. I tested with 15G scratch dev pool and this test ran ~200s on my
> 4vcpu 8G memory test vm.

  Right. Isn't that a good design? So that it gets tested differently
  on different HW config. ?
  However the test time can be reduced by using smaller vdisk.

Thanks, Anand


> Is it possible to limit the file size or the device size used? So it
> won't grow with device size. I'm thinking about something like
> _scratch_mkfs_sized, but that doesn't work for dev pool.
>
>>   Save md5sum checkpoint1
>>
>>   Re-mount healthy RAID1
>>
>>   Let balance re-silver.
>>   Save md5sum checkpoint2
>>
>>   Re-mount RAID1 degraded with _dev2_
>>   Save md5sum checkpoint3
>>
>>   Verify if all three md5sum match
>>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>> ---
>> v2:
>>   add tmp= and its rm
>>   add comments to why _reload_btrfs_ko is used
>>   add missing put and test_mount at notrun exit
>>   use echo instead of _fail when checkpoints are checked
>>   .out updated to remove Silence..
>>
>>  tests/btrfs/123     | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>>  tests/btrfs/123.out |   7 +++
>>  tests/btrfs/group   |   1 +
>>  3 files changed, 177 insertions(+)
>>  create mode 100755 tests/btrfs/123
>>  create mode 100644 tests/btrfs/123.out
>>
>> diff --git a/tests/btrfs/123 b/tests/btrfs/123
>> new file mode 100755
>> index 000000000000..33decfd1c434
>> --- /dev/null
>> +++ b/tests/btrfs/123
>> @@ -0,0 +1,169 @@
>> +#! /bin/bash
>> +# FS QA Test 123
>> +#
>> +# This test verify the RAID1 reconstruction on the reappeared
>> +# device. By using the following steps:
>> +# Initialize a RAID1 with some data
>> +#
>> +# Re-mount RAID1 degraded with dev2 missing and write up to
>> +# half of the FS capacity.
>> +# Save md5sum checkpoint1
>> +#
>> +# Re-mount healthy RAID1
>> +#
>> +# Let balance re-silver.
>> +# Save md5sum checkpoint2
>> +#
>> +# Re-mount RAID1 degraded with dev1 missing
>> +# Save md5sum checkpoint3
>> +#
>> +# Verify if all three checkpoints match
>> +#
>> +#---------------------------------------------------------------------
>> +# Copyright (c) 2016 Oracle.  All Rights Reserved.
>> +#
>> +# This program is free software; you can redistribute it and/or
>> +# modify it under the terms of the GNU General Public License as
>> +# published by the Free Software Foundation.
>> +#
>> +# This program is distributed in the hope that it would be useful,
>> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
>> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> +# GNU General Public License for more details.
>> +#
>> +# You should have received a copy of the GNU General Public License
>> +# along with this program; if not, write the Free Software Foundation,
>> +# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
>> +#---------------------------------------------------------------------
>> +#
>> +
>> +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.*
>> +}
>> +
>> +# 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
>> +
>> +_supported_fs btrfs
>> +_supported_os Linux
>> +_require_scratch_nocheck
>
> Why don't check filesystem after test? A comment would be good if
> there's a good reason. Patch 6 needs it as well :)
>
> Thanks,
> Eryu
>
>> +_require_scratch_dev_pool 2
>> +
>> +# the mounted test dir prevent btrfs unload, we need to unmount
>> +_test_unmount
>> +_require_btrfs_loadable
>> +
>> +_scratch_dev_pool_get 2
>> +
>> +dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
>> +dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
>> +
>> +dev1_sz=`blockdev --getsize64 $dev1`
>> +dev2_sz=`blockdev --getsize64 $dev2`
>> +# get min of both
>> +max_fs_sz=`echo -e "$dev1_sz\n$dev2_sz" | sort | head -1`
>> +max_fs_sz=$(( max_fs_sz/2 ))
>> +if [ $max_fs_sz -gt 1000000 ]; then
>> +	bs="1M"
>> +	count=$(( max_fs_sz/1000000 ))
>> +else
>> +	max_fs_sz=$(( max_fs_sz*2 ))
>> +	_scratch_dev_pool_put
>> +	_test_mount
>> +	_notrun "Smallest dev size $max_fs_sz, Need at least 2M"
>> +fi
>> +
>> +echo >> $seqres.full
>> +echo "max_fs_sz=$max_fs_sz count=$count" >> $seqres.full
>> +echo "-----Initialize -----" >> $seqres.full
>> +_scratch_pool_mkfs "-mraid1 -draid1" >> $seqres.full 2>&1
>> +_scratch_mount >> $seqres.full 2>&1
>> +_run_btrfs_util_prog filesystem show
>> +dd if=/dev/zero of="$SCRATCH_MNT"/tf1 bs=$bs count=1 \
>> +					>>$seqres.full 2>&1
>> +count=$(( count-- ))
>> +echo "unmount" >> $seqres.full
>> +echo "clean btrfs ko" >> $seqres.full
>> +_scratch_unmount
>> +
>> +# un-scan the btrfs devices
>> +_reload_btrfs_ko
>> +
>> +
>> +echo >> $seqres.full
>> +echo "-----Write degraded mount fill upto $max_fs_sz bytes-----" >> $seqres.full
>> +echo
>> +echo "Write data with degraded mount"
>> +# Since we didn't run dev scan, btrfs kernel does not know
>> +# about the dev2
>> +# don't use _scratch_mount as we want to control
>> +# the device used for mounting.
>> +
>> +_mount -o degraded $dev1 $SCRATCH_MNT >>$seqres.full 2>&1
>> +_run_btrfs_util_prog filesystem show
>> +dd if=/dev/zero of="$SCRATCH_MNT"/tf2 bs=$bs count=$count \
>> +					>>$seqres.full 2>&1
>> +checkpoint1=`md5sum $SCRATCH_MNT/tf2`
>> +echo $checkpoint1 >> $seqres.full 2>&1
>> +_scratch_unmount
>> +echo "unmount" >> $seqres.full
>> +
>> +echo >> $seqres.full
>> +echo "-----Mount normal-----" >> $seqres.full
>> +echo
>> +echo "Mount normal after balance"
>> +_run_btrfs_util_prog device scan
>> +_scratch_mount >> $seqres.full 2>&1
>> +_run_btrfs_util_prog filesystem show
>> +echo >> $seqres.full
>> +_run_btrfs_util_prog balance start ${SCRATCH_MNT}
>> +
>> +checkpoint2=`md5sum $SCRATCH_MNT/tf2`
>> +echo $checkpoint2 >> $seqres.full 2>&1
>> +
>> +echo >> $seqres.full
>> +echo "-----Mount degraded but with other dev -----" >> $seqres.full
>> +echo
>> +echo "Mount degraded but with other dev"
>> +_scratch_unmount
>> +# un-scan the btrfs devices
>> +_reload_btrfs_ko
>> +_mount -o degraded $dev2 $SCRATCH_MNT >>$seqres.full 2>&1
>> +_run_btrfs_util_prog filesystem show
>> +checkpoint3=`md5sum $SCRATCH_MNT/tf2`
>> +echo $checkpoint3 >> $seqres.full 2>&1
>> +
>> +if [ "$checkpoint1" != "$checkpoint2" ]; then
>> +	echo $checkpoint1
>> +	echo $checkpoint2
>> +	echo "Inital sum does not match with after balance"
>> +fi
>> +
>> +if [ "$checkpoint1" != "$checkpoint3" ]; then
>> +	echo $checkpoint1
>> +	echo $checkpoint3
>> +	echo "Inital sum does not match with data on dev2 written by balance"
>> +fi
>> +
>> +_scratch_dev_pool_put
>> +_test_mount
>> +
>> +status=0
>> +exit
>> diff --git a/tests/btrfs/123.out b/tests/btrfs/123.out
>> new file mode 100644
>> index 000000000000..1aa77036b55b
>> --- /dev/null
>> +++ b/tests/btrfs/123.out
>> @@ -0,0 +1,7 @@
>> +QA output created by 123
>> +
>> +Write data with degraded mount
>> +
>> +Mount normal after balance
>> +
>> +Mount degraded but with other dev
>> diff --git a/tests/btrfs/group b/tests/btrfs/group
>> index da0e27fa308d..1c4bfa8dbc96 100644
>> --- a/tests/btrfs/group
>> +++ b/tests/btrfs/group
>> @@ -124,3 +124,4 @@
>>  120 auto quick snapshot metadata
>>  121 auto quick snapshot qgroup
>>  122 auto quick snapshot qgroup
>> +123 auto replace
>> --
>> 2.7.0
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe fstests" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v3 1/6] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL
  2016-06-15  8:46 ` [PATCH v2 " Anand Jain
  2016-06-21 13:20   ` Eryu Guan
@ 2016-06-23 13:25   ` Anand Jain
  1 sibling, 0 replies; 32+ messages in thread
From: Anand Jain @ 2016-06-23 13:25 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs, eguan, Anand Jain, Anand Jain

From: Anand Jain <Anand.Jain@oracle.com>

This patch provides functions
 _scratch_dev_pool_get()
 _scratch_dev_pool_put()

Which will help to set/reset SCRATCH_DEV_POOL with the required
number of devices. SCRATCH_DEV_POOL_SAVED will hold all the devices.

Usage:
  _scratch_dev_pool_get() <ndevs>
  :: do stuff

  _scratch_dev_pool_put()

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 v2: Error message and comment section updates.
 v3: fix to -ne for integer check

 common/rc | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/common/rc b/common/rc
index 51092a0644f0..2c3891e4b2c9 100644
--- a/common/rc
+++ b/common/rc
@@ -802,6 +802,61 @@ _scratch_mkfs()
     esac
 }
 
+#
+# Generally test cases will have..
+#   _require_scratch_dev_pool X
+# to make sure it has the enough scratch devices including
+# replace-target and spare device. Now arg1 here is the
+# required number of scratch devices by a-test-case excluding
+# the replace-target and spare device. So this function will
+# set SCRATCH_DEV_POOL to the specified number of devices.
+#
+# Usage:
+#  _scratch_dev_pool_get() <ndevs>
+#     :: do stuff
+#
+#  _scratch_dev_pool_put()
+#
+_scratch_dev_pool_get()
+{
+	if [ $# -ne 1 ]; then
+		_fail "Usage: _scratch_dev_pool_get ndevs"
+	fi
+
+	local test_ndevs=$1
+	local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
+	local devs[]="( $SCRATCH_DEV_POOL )"
+
+	typeset -p config_ndevs >/dev/null 2>&1
+	if [ $? -ne 0 ]; then
+		_fail "Bug: cant find SCRATCH_DEV_POOL ndevs"
+	fi
+
+	if [ $config_ndevs -lt $test_ndevs ]; then
+		_notrun "Need at least test requested number of ndevs $test_ndevs"
+	fi
+
+	SCRATCH_DEV_POOL_SAVED=${SCRATCH_DEV_POOL}
+	export SCRATCH_DEV_POOL_SAVED
+	SCRATCH_DEV_POOL=${devs[@]:0:$test_ndevs}
+	export SCRATCH_DEV_POOL
+}
+
+_scratch_dev_pool_put()
+{
+	typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
+	if [ $? -ne 0 ]; then
+		_fail "Bug: unset val, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
+	fi
+
+	if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
+		_fail "Bug: str empty, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
+	fi
+
+	export SCRATCH_DEV_POOL=$SCRATCH_DEV_POOL_SAVED
+	export SCRATCH_DEV_POOL_SAVED=""
+}
+
 _scratch_pool_mkfs()
 {
     case $FSTYP in
-- 
2.7.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH v3 2/6] fstests: btrfs: add functions to get and put a device for replace target
  2016-06-15  8:48   ` [PATCH v2 " Anand Jain
  2016-06-21 13:31     ` Eryu Guan
@ 2016-06-23 13:28     ` Anand Jain
  1 sibling, 0 replies; 32+ messages in thread
From: Anand Jain @ 2016-06-23 13:28 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs, eguan, Anand Jain, Anand Jain

From: Anand Jain <Anand.Jain@oracle.com>

For the replace tests we need a device as a spare device,
here functions _spare_dev_get() and _spare_dev_put()
will get it from the SCRATCH_DEV_POOL_SAVED, which is set
when _scratch_dev_pool_get() is called, and is based on how
many has already been assigned to SCRATCH_DEV_POOL.

 usage:
   _scratch_dev_pool_get 3
   _spare_dev_get

      SPARE_DEV will have a device set which can be
      used as the replace target device.

   _spare_dev_put
   _scratch_dev_pool_put

_spare_dev_get() will pick the next device after SCRATCH_DEV_POOL
devices, from the SCRATCH_DEV_POOL_SAVED, and assigns it to
SPARE_DEV. _spare_dev_put() will set to SPARE_DEV to null.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2:
  add tmp= and its rm
  add comments to why _reload_btrfs_ko is used
  add missing put and test_mount at notrun exit
  use echo instead of _fail when checkpoints are checked
  .out updated to remove Silence..
v3:
  fix to -ne for integer check

 common/rc | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/common/rc b/common/rc
index 2c3891e4b2c9..2a2079a90e6a 100644
--- a/common/rc
+++ b/common/rc
@@ -802,6 +802,65 @@ _scratch_mkfs()
     esac
 }
 
+# Helper function to get a spare or replace-target device from
+# configured SCRATCH_DEV_POLL, must call _scratch_dev_pool_get()
+# before _spare_dev_get(). Replace-target-device/Spare-device will
+# be assigned to SPARE_DEV.
+# As of now only one replace-target-device/spare-device can be
+# assigned.
+#
+# Usage:
+#  _scratch_dev_pool_get() <ndevs>
+#     _spare_dev_get()
+#     :: do stuff
+#     _spare_dev_put()
+#  _scratch_dev_pool_put()
+#
+_spare_dev_get()
+{
+	typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
+	if [ $? -ne 0 ]; then
+		_fail "Bug: unset val, must call _scratch_dev_pool_get before _spare_dev_get"
+	fi
+
+	if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
+		_fail "Bug: str empty, must call _scratch_dev_pool_get before _spare_dev_get"
+	fi
+
+	# Check if the spare is already assigned
+	typeset -p SPARE_DEV >/dev/null 2>&1
+	if [ $? -eq 0 ]; then
+		if [ ! -z "$SPARE_DEV" ]; then
+			_fail "Bug: SPARE_DEV = $SPARE_DEV already assigned"
+		fi
+	fi
+
+	local ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
+	local config_ndevs=`echo $SCRATCH_DEV_POOL_SAVED| wc -w`
+
+	if [ $ndevs -eq $config_ndevs ]; then
+		_notrun "All devs used no spare"
+	fi
+	# Get a dev that is not used
+	local devs[]="( $SCRATCH_DEV_POOL_SAVED )"
+	SPARE_DEV=${devs[@]:$ndevs:1}
+	export SPARE_DEV
+}
+
+_spare_dev_put()
+{
+	typeset -p SPARE_DEV >/dev/null 2>&1
+	if [ $? -ne 0 ]; then
+		_fail "Bug: unset val, must call _spare_dev_get before its put"
+	fi
+
+	if [ -z "$SPARE_DEV" ]; then
+		_fail "Bug: str empty, must call _spare_dev_get before its put"
+	fi
+
+	export SPARE_DEV=""
+}
+
 #
 # Generally test cases will have..
 #   _require_scratch_dev_pool X
-- 
2.7.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* Re: [PATCH v2 5/6] fstests: btrfs: test RAID1 device reappear and balanced
  2016-06-22 11:01       ` Anand Jain
@ 2016-06-27  9:29         ` Eryu Guan
  2016-06-30 11:04           ` Anand Jain
  0 siblings, 1 reply; 32+ messages in thread
From: Eryu Guan @ 2016-06-27  9:29 UTC (permalink / raw)
  To: Anand Jain; +Cc: fstests, linux-btrfs

On Wed, Jun 22, 2016 at 07:01:54PM +0800, Anand Jain wrote:
> 
> 
> On 06/21/2016 09:31 PM, Eryu Guan wrote:
> > On Wed, Jun 15, 2016 at 04:48:47PM +0800, Anand Jain wrote:
> > > From: Anand Jain <Anand.Jain@oracle.com>
> > > 
> > > The test does the following:
> > >   Initialize a RAID1 with some data
> > > 
> > >   Re-mount RAID1 degraded with _dev1_ and write up to
> > >   half of the FS capacity
> > 
> > If test devices are big enough, this test consumes much longer test
> > time. I tested with 15G scratch dev pool and this test ran ~200s on my
> > 4vcpu 8G memory test vm.
> 
>  Right. Isn't that a good design? So that it gets tested differently
>  on different HW config. ?

Not in fstests. We should limit the run time of tests to an acceptable
amount, for auto group it's within 5 minutes.

>  However the test time can be reduced by using smaller vdisk.

I think either limit the write size or _notrun if the $max_fs_size is
too big (say 30G).

More comments below.

> 
> Thanks, Anand
> 
> 
> > Is it possible to limit the file size or the device size used? So it
> > won't grow with device size. I'm thinking about something like
> > _scratch_mkfs_sized, but that doesn't work for dev pool.
> > 
> > >   Save md5sum checkpoint1
> > > 
> > >   Re-mount healthy RAID1
> > > 
> > >   Let balance re-silver.
> > >   Save md5sum checkpoint2
> > > 
> > >   Re-mount RAID1 degraded with _dev2_
> > >   Save md5sum checkpoint3
> > > 
> > >   Verify if all three md5sum match
> > > 
> > > Signed-off-by: Anand Jain <anand.jain@oracle.com>
> > > ---
> > > v2:
> > >   add tmp= and its rm
> > >   add comments to why _reload_btrfs_ko is used
> > >   add missing put and test_mount at notrun exit
> > >   use echo instead of _fail when checkpoints are checked
> > >   .out updated to remove Silence..
> > > 
> > >  tests/btrfs/123     | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> > >  tests/btrfs/123.out |   7 +++
> > >  tests/btrfs/group   |   1 +
> > >  3 files changed, 177 insertions(+)
> > >  create mode 100755 tests/btrfs/123
> > >  create mode 100644 tests/btrfs/123.out
> > > 
> > > diff --git a/tests/btrfs/123 b/tests/btrfs/123
> > > new file mode 100755
> > > index 000000000000..33decfd1c434
> > > --- /dev/null
> > > +++ b/tests/btrfs/123
> > > @@ -0,0 +1,169 @@
> > > +#! /bin/bash
> > > +# FS QA Test 123
> > > +#
> > > +# This test verify the RAID1 reconstruction on the reappeared
> > > +# device. By using the following steps:
> > > +# Initialize a RAID1 with some data
> > > +#
> > > +# Re-mount RAID1 degraded with dev2 missing and write up to
> > > +# half of the FS capacity.
> > > +# Save md5sum checkpoint1
> > > +#
> > > +# Re-mount healthy RAID1
> > > +#
> > > +# Let balance re-silver.
> > > +# Save md5sum checkpoint2
> > > +#
> > > +# Re-mount RAID1 degraded with dev1 missing
> > > +# Save md5sum checkpoint3
> > > +#
> > > +# Verify if all three checkpoints match
> > > +#
> > > +#---------------------------------------------------------------------
> > > +# Copyright (c) 2016 Oracle.  All Rights Reserved.
> > > +#
> > > +# This program is free software; you can redistribute it and/or
> > > +# modify it under the terms of the GNU General Public License as
> > > +# published by the Free Software Foundation.
> > > +#
> > > +# This program is distributed in the hope that it would be useful,
> > > +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > > +# GNU General Public License for more details.
> > > +#
> > > +# You should have received a copy of the GNU General Public License
> > > +# along with this program; if not, write the Free Software Foundation,
> > > +# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
> > > +#---------------------------------------------------------------------
> > > +#
> > > +
> > > +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.*
> > > +}
> > > +
> > > +# 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
> > > +
> > > +_supported_fs btrfs
> > > +_supported_os Linux
> > > +_require_scratch_nocheck
> > 
> > Why don't check filesystem after test? A comment would be good if
> > there's a good reason. Patch 6 needs it as well :)

And can you please add comments on _require_scratch_nocheck in this
patch and patch 6, and rebase the whole series after Dave pushed my
pull request(on 06-25) to upstream, and resend?

Thanks,
Eryu

> > 
> > > +_require_scratch_dev_pool 2
> > > +
> > > +# the mounted test dir prevent btrfs unload, we need to unmount
> > > +_test_unmount
> > > +_require_btrfs_loadable
> > > +
> > > +_scratch_dev_pool_get 2
> > > +
> > > +dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
> > > +dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
> > > +
> > > +dev1_sz=`blockdev --getsize64 $dev1`
> > > +dev2_sz=`blockdev --getsize64 $dev2`
> > > +# get min of both
> > > +max_fs_sz=`echo -e "$dev1_sz\n$dev2_sz" | sort | head -1`
> > > +max_fs_sz=$(( max_fs_sz/2 ))
> > > +if [ $max_fs_sz -gt 1000000 ]; then
> > > +	bs="1M"
> > > +	count=$(( max_fs_sz/1000000 ))
> > > +else
> > > +	max_fs_sz=$(( max_fs_sz*2 ))
> > > +	_scratch_dev_pool_put
> > > +	_test_mount
> > > +	_notrun "Smallest dev size $max_fs_sz, Need at least 2M"
> > > +fi
> > > +
> > > +echo >> $seqres.full
> > > +echo "max_fs_sz=$max_fs_sz count=$count" >> $seqres.full
> > > +echo "-----Initialize -----" >> $seqres.full
> > > +_scratch_pool_mkfs "-mraid1 -draid1" >> $seqres.full 2>&1
> > > +_scratch_mount >> $seqres.full 2>&1
> > > +_run_btrfs_util_prog filesystem show
> > > +dd if=/dev/zero of="$SCRATCH_MNT"/tf1 bs=$bs count=1 \
> > > +					>>$seqres.full 2>&1
> > > +count=$(( count-- ))
> > > +echo "unmount" >> $seqres.full
> > > +echo "clean btrfs ko" >> $seqres.full
> > > +_scratch_unmount
> > > +
> > > +# un-scan the btrfs devices
> > > +_reload_btrfs_ko
> > > +
> > > +
> > > +echo >> $seqres.full
> > > +echo "-----Write degraded mount fill upto $max_fs_sz bytes-----" >> $seqres.full
> > > +echo
> > > +echo "Write data with degraded mount"
> > > +# Since we didn't run dev scan, btrfs kernel does not know
> > > +# about the dev2
> > > +# don't use _scratch_mount as we want to control
> > > +# the device used for mounting.
> > > +
> > > +_mount -o degraded $dev1 $SCRATCH_MNT >>$seqres.full 2>&1
> > > +_run_btrfs_util_prog filesystem show
> > > +dd if=/dev/zero of="$SCRATCH_MNT"/tf2 bs=$bs count=$count \
> > > +					>>$seqres.full 2>&1
> > > +checkpoint1=`md5sum $SCRATCH_MNT/tf2`
> > > +echo $checkpoint1 >> $seqres.full 2>&1
> > > +_scratch_unmount
> > > +echo "unmount" >> $seqres.full
> > > +
> > > +echo >> $seqres.full
> > > +echo "-----Mount normal-----" >> $seqres.full
> > > +echo
> > > +echo "Mount normal after balance"
> > > +_run_btrfs_util_prog device scan
> > > +_scratch_mount >> $seqres.full 2>&1
> > > +_run_btrfs_util_prog filesystem show
> > > +echo >> $seqres.full
> > > +_run_btrfs_util_prog balance start ${SCRATCH_MNT}
> > > +
> > > +checkpoint2=`md5sum $SCRATCH_MNT/tf2`
> > > +echo $checkpoint2 >> $seqres.full 2>&1
> > > +
> > > +echo >> $seqres.full
> > > +echo "-----Mount degraded but with other dev -----" >> $seqres.full
> > > +echo
> > > +echo "Mount degraded but with other dev"
> > > +_scratch_unmount
> > > +# un-scan the btrfs devices
> > > +_reload_btrfs_ko
> > > +_mount -o degraded $dev2 $SCRATCH_MNT >>$seqres.full 2>&1
> > > +_run_btrfs_util_prog filesystem show
> > > +checkpoint3=`md5sum $SCRATCH_MNT/tf2`
> > > +echo $checkpoint3 >> $seqres.full 2>&1
> > > +
> > > +if [ "$checkpoint1" != "$checkpoint2" ]; then
> > > +	echo $checkpoint1
> > > +	echo $checkpoint2
> > > +	echo "Inital sum does not match with after balance"
> > > +fi
> > > +
> > > +if [ "$checkpoint1" != "$checkpoint3" ]; then
> > > +	echo $checkpoint1
> > > +	echo $checkpoint3
> > > +	echo "Inital sum does not match with data on dev2 written by balance"
> > > +fi
> > > +
> > > +_scratch_dev_pool_put
> > > +_test_mount
> > > +
> > > +status=0
> > > +exit
> > > diff --git a/tests/btrfs/123.out b/tests/btrfs/123.out
> > > new file mode 100644
> > > index 000000000000..1aa77036b55b
> > > --- /dev/null
> > > +++ b/tests/btrfs/123.out
> > > @@ -0,0 +1,7 @@
> > > +QA output created by 123
> > > +
> > > +Write data with degraded mount
> > > +
> > > +Mount normal after balance
> > > +
> > > +Mount degraded but with other dev
> > > diff --git a/tests/btrfs/group b/tests/btrfs/group
> > > index da0e27fa308d..1c4bfa8dbc96 100644
> > > --- a/tests/btrfs/group
> > > +++ b/tests/btrfs/group
> > > @@ -124,3 +124,4 @@
> > >  120 auto quick snapshot metadata
> > >  121 auto quick snapshot qgroup
> > >  122 auto quick snapshot qgroup
> > > +123 auto replace
> > > --
> > > 2.7.0
> > > 
> > > --
> > > To unsubscribe from this list: send the line "unsubscribe fstests" in
> > > the body of a message to majordomo@vger.kernel.org
> > > More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v3 5/6] fstests: btrfs: test RAID1 device reappear and balanced
  2016-05-17 14:32 ` [PATCH 5/6] fstests: btrfs: test RAID1 device reappear and balanced Anand Jain
  2016-06-12  5:06   ` Eryu Guan
  2016-06-15  8:48   ` [PATCH v2 " Anand Jain
@ 2016-06-30 10:58   ` Anand Jain
  2 siblings, 0 replies; 32+ messages in thread
From: Anand Jain @ 2016-06-30 10:58 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs

From: Anand Jain <Anand.Jain@oracle.com>

The test does the following:
  Initialize a RAID1 with some data

  Re-mount RAID1 degraded with _dev1_ and write up to
  half of the FS capacity
  Save md5sum checkpoint1

  Re-mount healthy RAID1

  Let balance re-silver.
  Save md5sum checkpoint2

  Re-mount RAID1 degraded with _dev2_
  Save md5sum checkpoint3

  Verify if all three md5sum match

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v3:
  Removed _require_scratch_nocheck
  Fix fs fill size, 1.2g took 1xxsec, looks reasonable
  Log and .out typo fix
  Rebase on latest fstests
v2:
  add tmp= and its rm
  add comments to why _reload_btrfs_ko is used
  add missing put and test_mount at notrun exit
  use echo instead of _fail when checkpoints are checked
  .out updated to remove Silence..

 tests/btrfs/124     | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/124.out |   7 +++
 tests/btrfs/group   |   1 +
 3 files changed, 174 insertions(+)
 create mode 100755 tests/btrfs/124
 create mode 100644 tests/btrfs/124.out

diff --git a/tests/btrfs/124 b/tests/btrfs/124
new file mode 100755
index 000000000000..731614431e78
--- /dev/null
+++ b/tests/btrfs/124
@@ -0,0 +1,166 @@
+#! /bin/bash
+# FS QA Test 124
+#
+# This test verify the RAID1 reconstruction on the reappeared
+# device. By using the following steps:
+# Initialize a RAID1 with some data
+#
+# Re-mount RAID1 degraded with dev2 missing and write up to
+# half of the FS capacity.
+# Save md5sum checkpoint1
+#
+# Re-mount healthy RAID1
+#
+# Let balance re-silver.
+# Save md5sum checkpoint2
+#
+# Re-mount RAID1 degraded with dev1 missing
+# Save md5sum checkpoint3
+#
+# Verify if all three checkpoints match
+#
+#---------------------------------------------------------------------
+# Copyright (c) 2016 Oracle.  All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#---------------------------------------------------------------------
+#
+
+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.*
+}
+
+# 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
+
+_supported_fs btrfs
+_supported_os Linux
+_require_scratch_dev_pool 2
+
+# the mounted test dir prevent btrfs unload, we need to unmount
+_test_unmount
+_require_btrfs_loadable
+
+_scratch_dev_pool_get 2
+
+dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
+dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
+
+dev1_sz=`blockdev --getsize64 $dev1`
+dev2_sz=`blockdev --getsize64 $dev2`
+# get min of both
+max_fs_sz=`echo -e "$dev1_sz\n$dev2_sz" | sort | head -1`
+# Need disks with more than 2G.
+if [ $max_fs_sz -lt 2000000000 ]; then
+	_scratch_dev_pool_put
+	_test_mount
+	_notrun "Smallest dev size $max_fs_sz, Need at least 2G"
+fi
+max_fs_sz=1200000000
+bs="1M"
+count=$(($max_fs_sz / 1000000))
+
+echo >> $seqres.full
+echo "max_fs_sz=$max_fs_sz count=$count" >> $seqres.full
+echo "-----Initialize -----" >> $seqres.full
+_scratch_pool_mkfs "-mraid1 -draid1" >> $seqres.full 2>&1
+_scratch_mount >> $seqres.full 2>&1
+_run_btrfs_util_prog filesystem show
+dd if=/dev/zero of="$SCRATCH_MNT"/tf1 bs=$bs count=1 \
+					>>$seqres.full 2>&1
+count=$(( count-- ))
+echo "unmount" >> $seqres.full
+echo "clean btrfs ko" >> $seqres.full
+_scratch_unmount
+
+# un-scan the btrfs devices
+_reload_btrfs_ko
+
+echo >> $seqres.full
+echo "-----Write degraded mount fill upto $max_fs_sz bytes-----" >> $seqres.full
+echo
+echo "Write data with degraded mount"
+# Since we didn't run dev scan, btrfs kernel does not know
+# about the dev2
+# don't use _scratch_mount as we want to control
+# the device used for mounting.
+
+_mount -o degraded $dev1 $SCRATCH_MNT >>$seqres.full 2>&1
+_run_btrfs_util_prog filesystem show
+dd if=/dev/zero of="$SCRATCH_MNT"/tf2 bs=$bs count=$count \
+					>>$seqres.full 2>&1
+checkpoint1=`md5sum $SCRATCH_MNT/tf2`
+echo $checkpoint1 >> $seqres.full 2>&1
+_scratch_unmount
+echo "unmount" >> $seqres.full
+
+echo >> $seqres.full
+echo "-----Mount normal-----" >> $seqres.full
+echo
+echo "Mount normal and balance"
+_run_btrfs_util_prog device scan
+_scratch_mount >> $seqres.full 2>&1
+_run_btrfs_util_prog filesystem show
+echo >> $seqres.full
+_run_btrfs_util_prog balance start ${SCRATCH_MNT}
+
+checkpoint2=`md5sum $SCRATCH_MNT/tf2`
+echo $checkpoint2 >> $seqres.full 2>&1
+
+echo >> $seqres.full
+echo "-----Mount degraded with the other dev -----" >> $seqres.full
+echo
+echo "Mount degraded with the other dev"
+_scratch_unmount
+# un-scan the btrfs devices
+_reload_btrfs_ko
+_mount -o degraded $dev2 $SCRATCH_MNT >>$seqres.full 2>&1
+_run_btrfs_util_prog filesystem show
+checkpoint3=`md5sum $SCRATCH_MNT/tf2`
+echo $checkpoint3 >> $seqres.full 2>&1
+
+if [ "$checkpoint1" != "$checkpoint2" ]; then
+	echo $checkpoint1
+	echo $checkpoint2
+	echo "Inital sum does not match with after balance"
+fi
+
+if [ "$checkpoint1" != "$checkpoint3" ]; then
+	echo $checkpoint1
+	echo $checkpoint3
+	echo "Inital sum does not match with data on dev2 written by balance"
+fi
+
+_scratch_dev_pool_put
+_test_mount
+
+status=0
+exit
diff --git a/tests/btrfs/124.out b/tests/btrfs/124.out
new file mode 100644
index 000000000000..cc3bb34efccb
--- /dev/null
+++ b/tests/btrfs/124.out
@@ -0,0 +1,7 @@
+QA output created by 124
+
+Write data with degraded mount
+
+Mount normal and balance
+
+Mount degraded with the other dev
diff --git a/tests/btrfs/group b/tests/btrfs/group
index 5a26ed737496..ba13e128b173 100644
--- a/tests/btrfs/group
+++ b/tests/btrfs/group
@@ -126,3 +126,4 @@
 121 auto quick snapshot qgroup
 122 auto quick snapshot qgroup
 123 auto quick qgroup
+124 auto replace
-- 
2.7.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH v3 6/6] fstests: btrfs: test RAID5 device reappear and balance
  2016-05-17 14:32 ` [PATCH 6/6] fstests: btrfs: test RAID5 device reappear and balance Anand Jain
  2016-06-12  5:08   ` Eryu Guan
  2016-06-15  8:49   ` [PATCH v2 " Anand Jain
@ 2016-06-30 10:59   ` Anand Jain
  2 siblings, 0 replies; 32+ messages in thread
From: Anand Jain @ 2016-06-30 10:59 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs

From: Anand Jain <Anand.Jain@oracle.com>

The test does the following:
Initialize a RAID5 with some data

Re-mount RAID5 degraded with _dev3_ missing and write data.
Save md5sum checkpoint1

Re-mount healthy RAID5

Let balance fix degraded blocks.
Save md5sum checkpoint2

Re-mount RAID1 degraded now with _dev1_ missing.
Save md5sum checkpoint3

Verify if all three md5sum matches

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v3:
  Removed _require_scratch_nocheck
  Fixed the FS fill size to be at 100m
  Typo fixes in the log and .out file
  Rebase on latest fstests
  
v2:
  add tmp= and its rm
  add comments to why _reload_btrfs_ko is used
  add missing put and test_mount at notrun exit
  use echo instead of _fail when checkpoints are checked
  .out updated to remove Silence..

 tests/btrfs/125     | 182 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/125.out |   7 ++
 tests/btrfs/group   |   1 +
 3 files changed, 190 insertions(+)
 create mode 100755 tests/btrfs/125
 create mode 100644 tests/btrfs/125.out

diff --git a/tests/btrfs/125 b/tests/btrfs/125
new file mode 100755
index 000000000000..1062b87b3eb9
--- /dev/null
+++ b/tests/btrfs/125
@@ -0,0 +1,182 @@
+#! /bin/bash
+# FS QA Test 125
+#
+# This test verify if the reconstructed data on the RAID5 is good.
+# Steps:
+# Initialize RAID5 with some data
+#
+# Re-mount RAID5 degraded with dev3 missing and write data
+# Save md5sum checkpoint1
+#
+# Re-mount healthy RAID5
+#
+# Let balance fix the RAID5.
+# Save md5sum checkpoint2
+#
+# Re-mount RAID5 degraded with dev1 as missing.
+# Save md5sum checkpoint3
+#
+# Verify if all three checkpoints match
+#
+#---------------------------------------------------------------------
+# Copyright (c) 2016 Oracle.  All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#---------------------------------------------------------------------
+#
+
+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.*
+}
+
+# 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
+
+_supported_fs btrfs
+_supported_os Linux
+_require_scratch_dev_pool 3
+
+# we need btrfs to unload, need test dir unmounted
+_test_unmount
+_require_btrfs_loadable
+
+_scratch_dev_pool_get 3
+
+dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
+dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
+dev3=`echo $SCRATCH_DEV_POOL | awk '{print $3}'`
+
+echo dev1=$dev1 >> $seqres.full
+echo dev2=$dev2 >> $seqres.full
+echo dev3=$dev3 >> $seqres.full
+
+# Balance won't be successful if filled too much
+dev1_sz=`blockdev --getsize64 $dev1`
+dev2_sz=`blockdev --getsize64 $dev2`
+dev3_sz=`blockdev --getsize64 $dev3`
+
+# get min of both.
+max_fs_sz=`echo -e "$dev1_sz\n$dev2_sz\n$dev3_sz" | sort | head -1`
+# Need disks with more than 2G
+if [ $max_fs_sz -lt 2000000000 ]; then
+	_scratch_dev_pool_put
+	_test_mount
+	_notrun "Smallest dev size $max_fs_sz, Need at least 2G"
+fi
+max_fs_sz=100000000
+bs="1M"
+count=$(($max_fs_sz / 1000000))
+
+#-------------normal init-------------------
+echo >> $seqres.full
+echo "max_fs_sz=$max_fs_sz count=$count" >> $seqres.full
+echo "-----Initialize -----" >> $seqres.full
+_scratch_pool_mkfs "-mraid5 -draid5" >> $seqres.full 2>&1
+_scratch_mount >> $seqres.full 2>&1
+dd if=/dev/zero of="$SCRATCH_MNT"/tf1 bs=$bs count=1 \
+					>>$seqres.full 2>&1
+_run_btrfs_util_prog filesystem show
+_run_btrfs_util_prog filesystem df $SCRATCH_MNT
+count=$(( count-- ))
+
+
+#-------------degraded-init-------------------
+echo >> $seqres.full
+echo "-----Write degraded mount fill upto $max_fs_sz bytes-----" >> $seqres.full
+echo
+echo "Write data with degraded mount"
+
+echo "unmount" >> $seqres.full
+_scratch_unmount
+echo "clean btrfs ko" >> $seqres.full
+# un-scan the btrfs devices
+_reload_btrfs_ko
+_mount -o degraded,device=$dev2 $dev1 $SCRATCH_MNT >>$seqres.full 2>&1
+dd if=/dev/zero of="$SCRATCH_MNT"/tf2 bs=$bs count=$count \
+					>>$seqres.full 2>&1
+_run_btrfs_util_prog filesystem show
+_run_btrfs_util_prog filesystem df $SCRATCH_MNT
+checkpoint1=`md5sum $SCRATCH_MNT/tf2`
+echo $checkpoint1 >> $seqres.full 2>&1
+
+#-------------balance-------------------
+echo >> $seqres.full
+echo "-----Mount normal-----" >> $seqres.full
+echo
+echo "Mount normal and balance"
+
+_scratch_unmount
+_run_btrfs_util_prog device scan
+_scratch_mount >> $seqres.full 2>&1
+
+echo >> $seqres.full
+_run_btrfs_util_prog balance start ${SCRATCH_MNT}
+
+_run_btrfs_util_prog filesystem show
+_run_btrfs_util_prog filesystem df ${SCRATCH_MNT}
+
+checkpoint2=`md5sum $SCRATCH_MNT/tf2`
+echo $checkpoint2 >> $seqres.full 2>&1
+
+#-------------degraded-mount-------------------
+echo >> $seqres.full
+echo "-----Mount degraded with dev1 missing-----" >> $seqres.full
+echo
+echo "Mount degraded but with other dev"
+
+_scratch_unmount
+# un-scan the btrfs devices
+_reload_btrfs_ko
+
+_mount -o degraded,device=${dev2} $dev3 $SCRATCH_MNT >>$seqres.full 2>&1
+
+_run_btrfs_util_prog filesystem show
+_run_btrfs_util_prog filesystem df $SCRATCH_MNT
+checkpoint3=`md5sum $SCRATCH_MNT/tf2`
+echo $checkpoint3 >> $seqres.full 2>&1
+
+if [ "$checkpoint1" != "$checkpoint2" ]; then
+	echo $checkpoint1
+	echo $checkpoint2
+	echo "Inital sum does not match with after balance"
+fi
+
+if [ "$checkpoint1" != "$checkpoint3" ]; then
+	echo $checkpoint1
+	echo $checkpoint3
+	echo "Inital sum does not match with data on dev2 written by balance"
+fi
+
+_scratch_dev_pool_put
+_test_mount
+
+status=0
+exit
diff --git a/tests/btrfs/125.out b/tests/btrfs/125.out
new file mode 100644
index 000000000000..d795f7d8e8a0
--- /dev/null
+++ b/tests/btrfs/125.out
@@ -0,0 +1,7 @@
+QA output created by 125
+
+Write data with degraded mount
+
+Mount normal and balance
+
+Mount degraded but with other dev
diff --git a/tests/btrfs/group b/tests/btrfs/group
index ba13e128b173..d959b1d38f6d 100644
--- a/tests/btrfs/group
+++ b/tests/btrfs/group
@@ -127,3 +127,4 @@
 122 auto quick snapshot qgroup
 123 auto quick qgroup
 124 auto replace
+125 auto replace
-- 
2.7.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* Re: [PATCH v2 5/6] fstests: btrfs: test RAID1 device reappear and balanced
  2016-06-27  9:29         ` Eryu Guan
@ 2016-06-30 11:04           ` Anand Jain
  2016-06-30 14:58             ` Eryu Guan
  0 siblings, 1 reply; 32+ messages in thread
From: Anand Jain @ 2016-06-30 11:04 UTC (permalink / raw)
  To: Eryu Guan; +Cc: fstests, linux-btrfs



Thanks for review comments.
more below..

On 06/27/2016 05:29 PM, Eryu Guan wrote:
> On Wed, Jun 22, 2016 at 07:01:54PM +0800, Anand Jain wrote:
>>
>>
>> On 06/21/2016 09:31 PM, Eryu Guan wrote:
>>> On Wed, Jun 15, 2016 at 04:48:47PM +0800, Anand Jain wrote:
>>>> From: Anand Jain <Anand.Jain@oracle.com>
>>>>
>>>> The test does the following:
>>>>   Initialize a RAID1 with some data
>>>>
>>>>   Re-mount RAID1 degraded with _dev1_ and write up to
>>>>   half of the FS capacity
>>>
>>> If test devices are big enough, this test consumes much longer test
>>> time. I tested with 15G scratch dev pool and this test ran ~200s on my
>>> 4vcpu 8G memory test vm.
>>
>>  Right. Isn't that a good design? So that it gets tested differently
>>  on different HW config. ?
>
> Not in fstests. We should limit the run time of tests to an acceptable
> amount, for auto group it's within 5 minutes.

>>  However the test time can be reduced by using smaller vdisk.
>
> I think either limit the write size or _notrun if the $max_fs_size is
> too big (say 30G).

Fixed in v3 to have a fixed scratch data.

> More comments below.
>
>>
>> Thanks, Anand
>>
>>
>>> Is it possible to limit the file size or the device size used? So it
>>> won't grow with device size. I'm thinking about something like
>>> _scratch_mkfs_sized, but that doesn't work for dev pool.
>>>
>>>>   Save md5sum checkpoint1
>>>>
>>>>   Re-mount healthy RAID1
>>>>
>>>>   Let balance re-silver.
>>>>   Save md5sum checkpoint2
>>>>
>>>>   Re-mount RAID1 degraded with _dev2_
>>>>   Save md5sum checkpoint3
>>>>
>>>>   Verify if all three md5sum match
>>>>
>>>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>>>> ---
>>>> v2:
>>>>   add tmp= and its rm
>>>>   add comments to why _reload_btrfs_ko is used
>>>>   add missing put and test_mount at notrun exit
>>>>   use echo instead of _fail when checkpoints are checked
>>>>   .out updated to remove Silence..
>>>>
>>>>  tests/btrfs/123     | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>>>>  tests/btrfs/123.out |   7 +++
>>>>  tests/btrfs/group   |   1 +
>>>>  3 files changed, 177 insertions(+)
>>>>  create mode 100755 tests/btrfs/123
>>>>  create mode 100644 tests/btrfs/123.out
>>>>
>>>> diff --git a/tests/btrfs/123 b/tests/btrfs/123
>>>> new file mode 100755
>>>> index 000000000000..33decfd1c434
>>>> --- /dev/null
>>>> +++ b/tests/btrfs/123
>>>> @@ -0,0 +1,169 @@
>>>> +#! /bin/bash
>>>> +# FS QA Test 123
>>>> +#
>>>> +# This test verify the RAID1 reconstruction on the reappeared
>>>> +# device. By using the following steps:
>>>> +# Initialize a RAID1 with some data
>>>> +#
>>>> +# Re-mount RAID1 degraded with dev2 missing and write up to
>>>> +# half of the FS capacity.
>>>> +# Save md5sum checkpoint1
>>>> +#
>>>> +# Re-mount healthy RAID1
>>>> +#
>>>> +# Let balance re-silver.
>>>> +# Save md5sum checkpoint2
>>>> +#
>>>> +# Re-mount RAID1 degraded with dev1 missing
>>>> +# Save md5sum checkpoint3
>>>> +#
>>>> +# Verify if all three checkpoints match
>>>> +#
>>>> +#---------------------------------------------------------------------
>>>> +# Copyright (c) 2016 Oracle.  All Rights Reserved.
>>>> +#
>>>> +# This program is free software; you can redistribute it and/or
>>>> +# modify it under the terms of the GNU General Public License as
>>>> +# published by the Free Software Foundation.
>>>> +#
>>>> +# This program is distributed in the hope that it would be useful,
>>>> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
>>>> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>>>> +# GNU General Public License for more details.
>>>> +#
>>>> +# You should have received a copy of the GNU General Public License
>>>> +# along with this program; if not, write the Free Software Foundation,
>>>> +# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
>>>> +#---------------------------------------------------------------------
>>>> +#
>>>> +
>>>> +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.*
>>>> +}
>>>> +
>>>> +# 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
>>>> +
>>>> +_supported_fs btrfs
>>>> +_supported_os Linux
>>>> +_require_scratch_nocheck
>>>
>>> Why don't check filesystem after test? A comment would be good if
>>> there's a good reason. Patch 6 needs it as well :)
>
> And can you please add comments on _require_scratch_nocheck in this
> patch and patch 6,

typo, ok to have fsck.

> and rebase the whole series after Dave pushed my
> pull request(on 06-25) to upstream, and resend?

yep.

Thanks, Anand

>
> Thanks,
> Eryu
>
>>>
>>>> +_require_scratch_dev_pool 2
>>>> +
>>>> +# the mounted test dir prevent btrfs unload, we need to unmount
>>>> +_test_unmount
>>>> +_require_btrfs_loadable
>>>> +
>>>> +_scratch_dev_pool_get 2
>>>> +
>>>> +dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
>>>> +dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
>>>> +
>>>> +dev1_sz=`blockdev --getsize64 $dev1`
>>>> +dev2_sz=`blockdev --getsize64 $dev2`
>>>> +# get min of both
>>>> +max_fs_sz=`echo -e "$dev1_sz\n$dev2_sz" | sort | head -1`
>>>> +max_fs_sz=$(( max_fs_sz/2 ))
>>>> +if [ $max_fs_sz -gt 1000000 ]; then
>>>> +	bs="1M"
>>>> +	count=$(( max_fs_sz/1000000 ))
>>>> +else
>>>> +	max_fs_sz=$(( max_fs_sz*2 ))
>>>> +	_scratch_dev_pool_put
>>>> +	_test_mount
>>>> +	_notrun "Smallest dev size $max_fs_sz, Need at least 2M"
>>>> +fi
>>>> +
>>>> +echo >> $seqres.full
>>>> +echo "max_fs_sz=$max_fs_sz count=$count" >> $seqres.full
>>>> +echo "-----Initialize -----" >> $seqres.full
>>>> +_scratch_pool_mkfs "-mraid1 -draid1" >> $seqres.full 2>&1
>>>> +_scratch_mount >> $seqres.full 2>&1
>>>> +_run_btrfs_util_prog filesystem show
>>>> +dd if=/dev/zero of="$SCRATCH_MNT"/tf1 bs=$bs count=1 \
>>>> +					>>$seqres.full 2>&1
>>>> +count=$(( count-- ))
>>>> +echo "unmount" >> $seqres.full
>>>> +echo "clean btrfs ko" >> $seqres.full
>>>> +_scratch_unmount
>>>> +
>>>> +# un-scan the btrfs devices
>>>> +_reload_btrfs_ko
>>>> +
>>>> +
>>>> +echo >> $seqres.full
>>>> +echo "-----Write degraded mount fill upto $max_fs_sz bytes-----" >> $seqres.full
>>>> +echo
>>>> +echo "Write data with degraded mount"
>>>> +# Since we didn't run dev scan, btrfs kernel does not know
>>>> +# about the dev2
>>>> +# don't use _scratch_mount as we want to control
>>>> +# the device used for mounting.
>>>> +
>>>> +_mount -o degraded $dev1 $SCRATCH_MNT >>$seqres.full 2>&1
>>>> +_run_btrfs_util_prog filesystem show
>>>> +dd if=/dev/zero of="$SCRATCH_MNT"/tf2 bs=$bs count=$count \
>>>> +					>>$seqres.full 2>&1
>>>> +checkpoint1=`md5sum $SCRATCH_MNT/tf2`
>>>> +echo $checkpoint1 >> $seqres.full 2>&1
>>>> +_scratch_unmount
>>>> +echo "unmount" >> $seqres.full
>>>> +
>>>> +echo >> $seqres.full
>>>> +echo "-----Mount normal-----" >> $seqres.full
>>>> +echo
>>>> +echo "Mount normal after balance"
>>>> +_run_btrfs_util_prog device scan
>>>> +_scratch_mount >> $seqres.full 2>&1
>>>> +_run_btrfs_util_prog filesystem show
>>>> +echo >> $seqres.full
>>>> +_run_btrfs_util_prog balance start ${SCRATCH_MNT}
>>>> +
>>>> +checkpoint2=`md5sum $SCRATCH_MNT/tf2`
>>>> +echo $checkpoint2 >> $seqres.full 2>&1
>>>> +
>>>> +echo >> $seqres.full
>>>> +echo "-----Mount degraded but with other dev -----" >> $seqres.full
>>>> +echo
>>>> +echo "Mount degraded but with other dev"
>>>> +_scratch_unmount
>>>> +# un-scan the btrfs devices
>>>> +_reload_btrfs_ko
>>>> +_mount -o degraded $dev2 $SCRATCH_MNT >>$seqres.full 2>&1
>>>> +_run_btrfs_util_prog filesystem show
>>>> +checkpoint3=`md5sum $SCRATCH_MNT/tf2`
>>>> +echo $checkpoint3 >> $seqres.full 2>&1
>>>> +
>>>> +if [ "$checkpoint1" != "$checkpoint2" ]; then
>>>> +	echo $checkpoint1
>>>> +	echo $checkpoint2
>>>> +	echo "Inital sum does not match with after balance"
>>>> +fi
>>>> +
>>>> +if [ "$checkpoint1" != "$checkpoint3" ]; then
>>>> +	echo $checkpoint1
>>>> +	echo $checkpoint3
>>>> +	echo "Inital sum does not match with data on dev2 written by balance"
>>>> +fi
>>>> +
>>>> +_scratch_dev_pool_put
>>>> +_test_mount
>>>> +
>>>> +status=0
>>>> +exit
>>>> diff --git a/tests/btrfs/123.out b/tests/btrfs/123.out
>>>> new file mode 100644
>>>> index 000000000000..1aa77036b55b
>>>> --- /dev/null
>>>> +++ b/tests/btrfs/123.out
>>>> @@ -0,0 +1,7 @@
>>>> +QA output created by 123
>>>> +
>>>> +Write data with degraded mount
>>>> +
>>>> +Mount normal after balance
>>>> +
>>>> +Mount degraded but with other dev
>>>> diff --git a/tests/btrfs/group b/tests/btrfs/group
>>>> index da0e27fa308d..1c4bfa8dbc96 100644
>>>> --- a/tests/btrfs/group
>>>> +++ b/tests/btrfs/group
>>>> @@ -124,3 +124,4 @@
>>>>  120 auto quick snapshot metadata
>>>>  121 auto quick snapshot qgroup
>>>>  122 auto quick snapshot qgroup
>>>> +123 auto replace
>>>> --
>>>> 2.7.0
>>>>
>>>> --
>>>> To unsubscribe from this list: send the line "unsubscribe fstests" in
>>>> the body of a message to majordomo@vger.kernel.org
>>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v2 5/6] fstests: btrfs: test RAID1 device reappear and balanced
  2016-06-30 11:04           ` Anand Jain
@ 2016-06-30 14:58             ` Eryu Guan
  0 siblings, 0 replies; 32+ messages in thread
From: Eryu Guan @ 2016-06-30 14:58 UTC (permalink / raw)
  To: Anand Jain; +Cc: fstests, linux-btrfs

On Thu, Jun 30, 2016 at 07:04:06PM +0800, Anand Jain wrote:
> 
> 
> Thanks for review comments.
> more below..
> 
> On 06/27/2016 05:29 PM, Eryu Guan wrote:
> > On Wed, Jun 22, 2016 at 07:01:54PM +0800, Anand Jain wrote:
> > > 
> > > 
> > > On 06/21/2016 09:31 PM, Eryu Guan wrote:
> > > > On Wed, Jun 15, 2016 at 04:48:47PM +0800, Anand Jain wrote:
> > > > > From: Anand Jain <Anand.Jain@oracle.com>
> > > > > 
> > > > > The test does the following:
> > > > >   Initialize a RAID1 with some data
> > > > > 
> > > > >   Re-mount RAID1 degraded with _dev1_ and write up to
> > > > >   half of the FS capacity
> > > > 
> > > > If test devices are big enough, this test consumes much longer test
> > > > time. I tested with 15G scratch dev pool and this test ran ~200s on my
> > > > 4vcpu 8G memory test vm.
> > > 
> > >  Right. Isn't that a good design? So that it gets tested differently
> > >  on different HW config. ?
> > 
> > Not in fstests. We should limit the run time of tests to an acceptable
> > amount, for auto group it's within 5 minutes.
> 
> > >  However the test time can be reduced by using smaller vdisk.
> > 
> > I think either limit the write size or _notrun if the $max_fs_size is
> > too big (say 30G).
> 
> Fixed in v3 to have a fixed scratch data.

Thanks! I've queued this patchset up, will let them go through some
testings.

Thanks,
Eryu

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2016-06-30 14:59 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-17 14:32 [PATCH 1/6] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL Anand Jain
2016-05-17 14:32 ` [PATCH 2/6] fstests: btrfs: add functions to get and put a device for replace target Anand Jain
2016-06-12  4:42   ` Eryu Guan
2016-06-15  8:45     ` Anand Jain
2016-06-15  8:47   ` [PATCH v2 " Anand Jain
2016-05-17 14:32 ` [PATCH 3/6] fstests: btrfs: 027 make use of new device get and put helper functions Anand Jain
2016-05-17 14:32 ` [PATCH 4/6] fstests: btrfs: add helper function to check if btrfs is module Anand Jain
2016-06-12  4:53   ` Eryu Guan
2016-06-15  8:45     ` Anand Jain
2016-06-15  8:47   ` [PATCH v2 " Anand Jain
2016-05-17 14:32 ` [PATCH 5/6] fstests: btrfs: test RAID1 device reappear and balanced Anand Jain
2016-06-12  5:06   ` Eryu Guan
2016-06-15  8:45     ` Anand Jain
2016-06-15  8:48   ` [PATCH v2 " Anand Jain
2016-06-21 13:31     ` Eryu Guan
2016-06-22 11:01       ` Anand Jain
2016-06-27  9:29         ` Eryu Guan
2016-06-30 11:04           ` Anand Jain
2016-06-30 14:58             ` Eryu Guan
2016-06-23 13:28     ` [PATCH v3 2/6] fstests: btrfs: add functions to get and put a device for replace target Anand Jain
2016-06-30 10:58   ` [PATCH v3 5/6] fstests: btrfs: test RAID1 device reappear and balanced Anand Jain
2016-05-17 14:32 ` [PATCH 6/6] fstests: btrfs: test RAID5 device reappear and balance Anand Jain
2016-06-12  5:08   ` Eryu Guan
2016-06-15  8:51     ` Anand Jain
2016-06-15  8:49   ` [PATCH v2 " Anand Jain
2016-06-30 10:59   ` [PATCH v3 " Anand Jain
2016-06-12  4:40 ` [PATCH 1/6] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL Eryu Guan
2016-06-15  8:44   ` Anand Jain
2016-06-15  8:46 ` [PATCH v2 " Anand Jain
2016-06-21 13:20   ` Eryu Guan
2016-06-22 11:01     ` Anand Jain
2016-06-23 13:25   ` [PATCH v3 " Anand Jain

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.