Commit f176436b authored by Jim Harris's avatar Jim Harris Committed by Daniel Verkamp
Browse files

test/bdev: wait for nbd device to become ready



Previously, we were waiting to find the target bdev as
registered before proceeding with nbd operations.  But
there can be a delay between when the bdev is registered
and when the nbd device becomes ready for block I/O
operations.  This delay has recently become longer as
lvol now performs I/O on registered bdevs to check for
an existing logical volume store.

So instead, check for the existence of the nbd device
in /proc/partitions output.

While here, also fix a bug in the nbd.c code - it needs
to wait for the poller to be unregistered before calling
spdk_nbd_stop().  Normally I would fix this in a separate
patch but because these issues are causing a lot of
failures in the test pool, I'm expediting this by putting
both fixes in one patch (so we can avoid a bunch of
re-runs).

Signed-off-by: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: Ia297337338f7eeee9b4c56b80e941d373c1a965d

Reviewed-on: https://review.gerrithub.io/385687


Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarDariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
parent fed26671
Loading
Loading
Loading
Loading
+19 −17
Original line number Diff line number Diff line
@@ -202,12 +202,11 @@ function waitforlisten() {
	set -x
}

function waitforbdev() {
	bdev_name=$1
	rpc_py=$2
function waitfornbd() {
	nbd_name=$1

	for ((i=1; i<=10; i++)); do
		if $rpc_py get_bdevs -b "$bdev_name" &>/dev/null; then
	for ((i=1; i<=20; i++)); do
		if grep -q -w $nbd_name /proc/partitions; then
			return 0
		else
			sleep 0.1
@@ -326,6 +325,10 @@ function part_dev_by_gpt () {
			return 1
		fi

		if [ ! -e /dev/nbd0 ]; then
			return 1
		fi

		if [ -z "$operation" ]; then
			operation="create"
		fi
@@ -339,9 +342,8 @@ function part_dev_by_gpt () {
		nbd_pid=$!
		echo "Process nbd pid: $nbd_pid"
		waitforlisten $nbd_pid 5260
		waitforbdev $devname "python $rootdir/scripts/rpc.py"
		waitfornbd nbd0

		if [ -e /dev/nbd0 ]; then
		if [ "$operation" = create ]; then
			parted -s /dev/nbd0 mklabel gpt mkpart first '0%' '50%' mkpart second '50%' '100%'
			# change the GUID to SPDK GUID value
@@ -351,7 +353,7 @@ function part_dev_by_gpt () {
			# clear the partition table
			dd if=/dev/zero of=/dev/nbd0 bs=4096 count=8 oflag=direct
		fi
		fi

		killprocess $nbd_pid
		rm -f ${conf}.gpt
	fi
+10 −2
Original line number Diff line number Diff line
@@ -50,13 +50,21 @@ static char *g_nbd_name = "/dev/nbd0";
#include "../common.c"

static void
nbd_shutdown(void)
nbd_stop(void *arg1, void *arg2)
{
	spdk_poller_unregister(&g_nbd_poller, NULL);
	spdk_nbd_stop(g_nbd_disk);
	spdk_app_stop(0);
}

static void
nbd_shutdown(void)
{
	struct spdk_event *stop_event;

	stop_event = spdk_event_allocate(spdk_env_get_current_core(), nbd_stop, NULL, NULL);
	spdk_poller_unregister(&g_nbd_poller, stop_event);
}

static void
nbd_poll(void *arg)
{