From bf9dbae56b9cc0a070c652be215b20de3e0fe3f8 Mon Sep 17 00:00:00 2001 From: Pawel Wodkowski Date: Tue, 20 Nov 2018 12:20:35 +0100 Subject: [PATCH] tests: wait for each start and stop nbd disk RPC This workaround is needed to stop EBUSY errors from NBD ioctls(). This can be fixed in NBD bdev code but till that point lets merge this workaround. Change-Id: Ic1546963538beda4d4409cef93062103e2a23e34 Signed-off-by: Pawel Wodkowski Reviewed-on: https://review.gerrithub.io/434040 Tested-by: SPDK CI Jenkins Reviewed-by: Darek Stojaczyk Reviewed-by: Ben Walker Chandler-Test-Pool: SPDK Automated Test System --- test/bdev/nbd_common.sh | 17 +++++++---------- test/bdev/nbdjson/json_config.sh | 2 ++ test/common/autotest_common.sh | 7 ++++--- test/vhost/vhost_boot/vhost_boot.sh | 13 ++++++++----- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/test/bdev/nbd_common.sh b/test/bdev/nbd_common.sh index df8caac65..2fa258b6c 100644 --- a/test/bdev/nbd_common.sh +++ b/test/bdev/nbd_common.sh @@ -4,19 +4,17 @@ function nbd_start_disks() { local rpc_server=$1 local bdev_list=($2) local nbd_list=($3) + local i for (( i=0; i<${#nbd_list[@]}; i++ )); do - $rootdir/scripts/rpc.py -s $rpc_server start_nbd_disk \ - ${bdev_list[$i]} ${nbd_list[$i]} - done - # Wait for nbd devices ready - for i in ${nbd_list[@]}; do - waitfornbd ${i:5} + $rootdir/scripts/rpc.py -s $rpc_server start_nbd_disk ${bdev_list[$i]} ${nbd_list[$i]} + # Wait for nbd device ready + waitfornbd $(basename ${nbd_list[$i]}) done } function waitfornbd_exit() { - nbd_name=$1 + local nbd_name=$1 for ((i=1; i<=20; i++)); do if grep -q -w $nbd_name /proc/partitions; then @@ -32,12 +30,11 @@ function waitfornbd_exit() { function nbd_stop_disks() { local rpc_server=$1 local nbd_list=($2) + local i for i in ${nbd_list[@]}; do $rootdir/scripts/rpc.py -s $rpc_server stop_nbd_disk $i - done - for i in ${nbd_list[@]}; do - waitfornbd_exit ${i:5} + waitfornbd_exit $(basename $i) done } diff --git a/test/bdev/nbdjson/json_config.sh b/test/bdev/nbdjson/json_config.sh index ccd7006c7..ed4a06e89 100755 --- a/test/bdev/nbdjson/json_config.sh +++ b/test/bdev/nbdjson/json_config.sh @@ -14,7 +14,9 @@ modprobe nbd timing_enter nbd_json_config_create_setup $rpc_py construct_malloc_bdev 128 512 --name Malloc0 $rpc_py start_nbd_disk Malloc0 /dev/nbd0 +waitfornbd nbd0 $rpc_py start_nbd_disk Nvme0n1 /dev/nbd1 +waitfornbd nbd1 timing_exit nbd_json_config_create_setup timing_enter nbd_json_config_test diff --git a/test/common/autotest_common.sh b/test/common/autotest_common.sh index cb7220d3c..1b6d7d7b3 100644 --- a/test/common/autotest_common.sh +++ b/test/common/autotest_common.sh @@ -337,7 +337,8 @@ function waitforlisten() { } function waitfornbd() { - nbd_name=$1 + local nbd_name=$1 + local i for ((i=1; i<=20; i++)); do if grep -q -w $nbd_name /proc/partitions; then @@ -527,7 +528,7 @@ function part_dev_by_gpt () { waitforlisten $nbd_pid $rpc_server # Start bdev as a nbd device - $rootdir/scripts/rpc.py -s "$rpc_server" start_nbd_disk $devname $nbd_path + nbd_start_disks "$rpc_server" $devname $nbd_path waitfornbd ${nbd_path:5} @@ -545,7 +546,7 @@ function part_dev_by_gpt () { dd if=/dev/zero of=$nbd_path bs=4096 count=8 oflag=direct fi - $rootdir/scripts/rpc.py -s "$rpc_server" stop_nbd_disk $nbd_path + nbd_stop_disks "$rpc_server" $nbd_path killprocess $nbd_pid rm -f ${conf}.gpt diff --git a/test/vhost/vhost_boot/vhost_boot.sh b/test/vhost/vhost_boot/vhost_boot.sh index 42bd7f229..79bfd81df 100755 --- a/test/vhost/vhost_boot/vhost_boot.sh +++ b/test/vhost/vhost_boot/vhost_boot.sh @@ -1,8 +1,11 @@ #!/usr/bin/env bash set -xe -basedir=$(readlink -f $(dirname $0)) -. $basedir/../common/common.sh +testdir=$(readlink -f $(dirname $0)) +rootdir=$(readlink -f $testdir/../../..) +. $testdir/../common/common.sh +. $rootdir/test/bdev/nbd_common.sh + rpc_py="python $SPDK_BUILD_DIR/scripts/rpc.py -s $(get_vhost_dir)/rpc.sock" vm_no="0" @@ -65,11 +68,11 @@ timing_exit create_lvol timing_enter convert_vm_image modprobe nbd -trap '$rpc_py stop_nbd_disk /dev/nbd0; rmmod nbd; err_clean "${FUNCNAME}" "${LINENO}"' ERR -$rpc_py start_nbd_disk $lvb_u /dev/nbd0 +trap 'nbd_stop_disks $(get_vhost_dir)/rpc.sock /dev/nbd0; rmmod nbd; err_clean "${FUNCNAME}" "${LINENO}"' ERR +nbd_start_disks "$(get_vhost_dir)/rpc.sock" $lvb_u /dev/nbd0 $QEMU_PREFIX/bin/qemu-img convert $os_image -O raw /dev/nbd0 sync -$rpc_py stop_nbd_disk /dev/nbd0 +nbd_stop_disks $(get_vhost_dir)/rpc.sock /dev/nbd0 sleep 1 rmmod nbd timing_exit convert_vm_image