From f176436b697d0f865eb8f4d788140766780c1868 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Fri, 3 Nov 2017 11:22:05 -0700 Subject: [PATCH] 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 Change-Id: Ia297337338f7eeee9b4c56b80e941d373c1a965d Reviewed-on: https://review.gerrithub.io/385687 Reviewed-by: Ben Walker Tested-by: SPDK Automated Test System Reviewed-by: Dariusz Stojaczyk Reviewed-by: Daniel Verkamp --- scripts/autotest_common.sh | 34 ++++++++++++++++++---------------- test/lib/bdev/nbd/nbd.c | 12 ++++++++++-- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/scripts/autotest_common.sh b/scripts/autotest_common.sh index 028fd9d790..4af7f9be7f 100755 --- a/scripts/autotest_common.sh +++ b/scripts/autotest_common.sh @@ -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 diff --git a/test/lib/bdev/nbd/nbd.c b/test/lib/bdev/nbd/nbd.c index 730819b4b4..3b67812f95 100644 --- a/test/lib/bdev/nbd/nbd.c +++ b/test/lib/bdev/nbd/nbd.c @@ -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) {