Commit 367fc7a9 authored by Michal Berger's avatar Michal Berger Committed by Tomasz Zawadzki
Browse files

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: default avatarMichal Berger <michal.berger@intel.com>
Change-Id: I5884973944eae3e827eaafec16ba72e2cb4f70e7
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14994


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarKarol Latecki <karol.latecki@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarPawel Piatek <pawelx.piatek@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent f17fe629
Loading
Loading
Loading
Loading
+25 −31
Original line number Diff line number Diff line
@@ -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,31 +210,26 @@ function bdev_bounds() {
}

function nbd_function_test() {
	if [ $(uname -s) = Linux ] && modprobe -n nbd; then
	[[ $(uname -s) == Linux ]] || return 0

	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})
	local bdev_all=($2)
	local bdev_num=${#bdev_all[@]}

		if [ ! -e $conf ]; then
			return 1
		fi
	# 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

	local nbd_all=(/dev/nbd+([0-9]))
	bdev_num=$((${#nbd_all[@]} < bdev_num ? ${#nbd_all[@]} : bdev_num))

	local nbd_list=(${nbd_all[@]::bdev_num})
	local bdev_list=(${bdev_all[@]::bdev_num})

		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"
	trap 'cleanup; killprocess $nbd_pid' SIGINT SIGTERM EXIT
	waitforlisten $nbd_pid $rpc_server

	nbd_rpc_start_stop_verify $rpc_server "${bdev_list[*]}"
@@ -241,9 +238,6 @@ function nbd_function_test() {

	killprocess $nbd_pid
	trap - SIGINT SIGTERM EXIT
	fi

	return 0
}

function fio_test_suite() {