diff options
author | Anand Jain <anand.jain@oracle.com> | 2024-02-20 03:48:41 +0800 |
---|---|---|
committer | Zorro Lang <zlang@kernel.org> | 2024-03-01 19:22:35 +0800 |
commit | c5c8a22238816ce68148f02ddfaf4a3f3104aaaf (patch) | |
tree | 875cf279bbd4142e4f692ab3cd46d122758dc08d | |
parent | faabc4852ad91ce406288048ed067cf814c68e22 (diff) | |
download | xfstests-dev-c5c8a22238816ce68148f02ddfaf4a3f3104aaaf.tar.gz |
common/rc: assign SCRATCH_DEV_POOL to an array
Many test cases use local variables to manage the names of each device in
SCRATCH_DEV_POOL. Let _scratch_dev_pool_get set an array, SCRATCH_DEV_NAME,
for it.
Usage:
_scratch_dev_pool_get <n>
# device names are in the array SCRATCH_DEV_NAME.
${SCRATCH_DEV_NAME[0]} ${SCRATCH_DEV_NAME[1]} ...
_scratch_dev_pool_put
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
-rw-r--r-- | common/rc | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -835,8 +835,9 @@ _spare_dev_put() # 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. +# the replace-target and spare device. So, this function sets +# SCRATCH_DEV_POOL to the specified number of devices and also +# sets a SCRATCH_DEV_NAME array with the names of the devices. # # Usage: # _scratch_dev_pool_get() <ndevs> @@ -867,19 +868,28 @@ _scratch_dev_pool_get() export SCRATCH_DEV_POOL_SAVED SCRATCH_DEV_POOL=${devs[@]:0:$test_ndevs} export SCRATCH_DEV_POOL + SCRATCH_DEV_NAME=( $SCRATCH_DEV_POOL ) + export SCRATCH_DEV_NAME } _scratch_dev_pool_put() { + local ret1 + local ret2 + typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1 - if [ $? -ne 0 ]; then + ret1=$? + typeset -p SCRATCH_DEV_NAME >/dev/null 2>&1 + ret2=$? + if [[ $ret1 -ne 0 || $ret2 -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 + if [[ -z "$SCRATCH_DEV_POOL_SAVED" || -z "${SCRATCH_DEV_NAME[@]}" ]]; then _fail "Bug: str empty, must call _scratch_dev_pool_get before _scratch_dev_pool_put" fi + export SCRATCH_DEV_NAME=() export SCRATCH_DEV_POOL=$SCRATCH_DEV_POOL_SAVED export SCRATCH_DEV_POOL_SAVED="" } |