From 367fc7a9cf83b36f202cc54c23f95e76aca4d1e9 Mon Sep 17 00:00:00 2001 From: Michal Berger Date: Fri, 14 Oct 2022 23:24:32 +0200 Subject: [PATCH] test/bdev: Refactor nbd_function_test() This function was a bit cluttered so simplify it. Also, it was assuming nbd module was loaded into the kernel prior running it - this could silently fail the nbd_all[@] setup in case it wasn't. Always attempt to load nbd driver before the setup and fail hard if the driver is not in place. Signed-off-by: Michal Berger Change-Id: I5884973944eae3e827eaafec16ba72e2cb4f70e7 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14994 Tested-by: SPDK CI Jenkins Reviewed-by: Karol Latecki Reviewed-by: Tomasz Zawadzki Reviewed-by: Pawel Piatek Reviewed-by: Jim Harris --- test/bdev/blockdev.sh | 56 +++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/test/bdev/blockdev.sh b/test/bdev/blockdev.sh index f1b9b63ec..7b4bd1c14 100755 --- a/test/bdev/blockdev.sh +++ b/test/bdev/blockdev.sh @@ -5,6 +5,8 @@ rootdir=$(readlink -f $testdir/../..) source $rootdir/test/common/autotest_common.sh source $testdir/nbd_common.sh +shopt -s nullglob extglob + rpc_py=rpc_cmd conf_file="$testdir/bdev.json" nonenclosed_conf_file="$testdir/nonenclosed.json" @@ -208,42 +210,34 @@ function bdev_bounds() { } function nbd_function_test() { - if [ $(uname -s) = Linux ] && modprobe -n nbd; then - local rpc_server=/var/tmp/spdk-nbd.sock - local conf=$1 - local nbd_all=($(ls /dev/nbd* | grep -v p)) - local bdev_all=($bdevs_name) - local nbd_num=${#bdev_all[@]} - if ((nbd_num < 1)); then - # There should be at least one bdev and one valid nbd device - return 1 - fi - if [ ${#nbd_all[@]} -le $nbd_num ]; then - nbd_num=${#nbd_all[@]} - fi - local nbd_list=(${nbd_all[@]:0:$nbd_num}) - local bdev_list=(${bdev_all[@]:0:$nbd_num}) + [[ $(uname -s) == Linux ]] || return 0 - if [ ! -e $conf ]; then - return 1 - fi + local rpc_server=/var/tmp/spdk-nbd.sock + local conf=$1 + local bdev_all=($2) + local bdev_num=${#bdev_all[@]} - modprobe nbd - $rootdir/test/app/bdev_svc/bdev_svc -r $rpc_server -i 0 --json "$conf" "$env_ctx" & - nbd_pid=$! - trap 'cleanup; killprocess $nbd_pid; exit 1' SIGINT SIGTERM EXIT - echo "Process nbd pid: $nbd_pid" - waitforlisten $nbd_pid $rpc_server + # FIXME: Centos7 in the CI is not shipped with a kernel supporting BLK_DEV_NBD + # so don't fail here for now. + [[ -e /sys/module/nbd ]] || modprobe -q nbd nbds_max=$bdev_num || return 0 - nbd_rpc_start_stop_verify $rpc_server "${bdev_list[*]}" - nbd_rpc_data_verify $rpc_server "${bdev_list[*]}" "${nbd_list[*]}" - nbd_with_lvol_verify $rpc_server "${nbd_list[*]}" + local nbd_all=(/dev/nbd+([0-9])) + bdev_num=$((${#nbd_all[@]} < bdev_num ? ${#nbd_all[@]} : bdev_num)) - killprocess $nbd_pid - trap - SIGINT SIGTERM EXIT - fi + local nbd_list=(${nbd_all[@]::bdev_num}) + local bdev_list=(${bdev_all[@]::bdev_num}) - return 0 + $rootdir/test/app/bdev_svc/bdev_svc -r $rpc_server -i 0 --json "$conf" "$env_ctx" & + nbd_pid=$! + trap 'cleanup; killprocess $nbd_pid' SIGINT SIGTERM EXIT + waitforlisten $nbd_pid $rpc_server + + nbd_rpc_start_stop_verify $rpc_server "${bdev_list[*]}" + nbd_rpc_data_verify $rpc_server "${bdev_list[*]}" "${nbd_list[*]}" + nbd_with_lvol_verify $rpc_server "${nbd_list[*]}" + + killprocess $nbd_pid + trap - SIGINT SIGTERM EXIT } function fio_test_suite() {