* [PATCH 1/3] [RFC] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL
@ 2016-05-13 11:21 Anand Jain
2016-05-13 11:21 ` [PATCH 2/3] [RFC] fstests: btrfs: add functions to get and put a device for replace target Anand Jain
2016-05-13 11:21 ` [PATCH 3/3] fstests: btrfs: 027 make use of new device get and put helper functions Anand Jain
0 siblings, 2 replies; 3+ messages in thread
From: Anand Jain @ 2016-05-13 11:21 UTC (permalink / raw)
To: fstests; +Cc: linux-btrfs
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] 3+ messages in thread
* [PATCH 2/3] [RFC] fstests: btrfs: add functions to get and put a device for replace target
2016-05-13 11:21 [PATCH 1/3] [RFC] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL Anand Jain
@ 2016-05-13 11:21 ` Anand Jain
2016-05-13 11:21 ` [PATCH 3/3] fstests: btrfs: 027 make use of new device get and put helper functions Anand Jain
1 sibling, 0 replies; 3+ messages in thread
From: Anand Jain @ 2016-05-13 11:21 UTC (permalink / raw)
To: fstests; +Cc: linux-btrfs
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] 3+ messages in thread
* [PATCH 3/3] fstests: btrfs: 027 make use of new device get and put helper functions
2016-05-13 11:21 [PATCH 1/3] [RFC] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL Anand Jain
2016-05-13 11:21 ` [PATCH 2/3] [RFC] fstests: btrfs: add functions to get and put a device for replace target Anand Jain
@ 2016-05-13 11:21 ` Anand Jain
1 sibling, 0 replies; 3+ messages in thread
From: Anand Jain @ 2016-05-13 11:21 UTC (permalink / raw)
To: fstests; +Cc: linux-btrfs
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] 3+ messages in thread
end of thread, other threads:[~2016-05-13 11:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-13 11:21 [PATCH 1/3] [RFC] fstests: btrfs: add functions to set and reset required number of SCRATCH_DEV_POOL Anand Jain
2016-05-13 11:21 ` [PATCH 2/3] [RFC] fstests: btrfs: add functions to get and put a device for replace target Anand Jain
2016-05-13 11:21 ` [PATCH 3/3] fstests: btrfs: 027 make use of new device get and put helper functions Anand Jain
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).