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: Jim Harris <james.r.harris@intel.com>
Change-Id: Ia297337338f7eeee9b4c56b80e941d373c1a965d

Reviewed-on: https://review.gerrithub.io/385687
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Jim Harris 2017-11-03 11:22:05 -07:00 committed by Daniel Verkamp
parent fed2667127
commit f176436b69
2 changed files with 28 additions and 18 deletions

View File

@ -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,19 +342,18 @@ 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
sgdisk -t 1:$SPDK_GPT_GUID /dev/nbd0
sgdisk -t 2:$SPDK_GPT_GUID /dev/nbd0
elif [ "$operation" = reset ]; then
# clear the partition table
dd if=/dev/zero of=/dev/nbd0 bs=4096 count=8 oflag=direct
fi
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
sgdisk -t 1:$SPDK_GPT_GUID /dev/nbd0
sgdisk -t 2:$SPDK_GPT_GUID /dev/nbd0
elif [ "$operation" = reset ]; then
# clear the partition table
dd if=/dev/zero of=/dev/nbd0 bs=4096 count=8 oflag=direct
fi
killprocess $nbd_pid
rm -f ${conf}.gpt
fi

View File

@ -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)
{