From fa563858fac7a108517c4bc7d7c5b04124be3e49 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Tue, 4 Jun 2019 13:55:21 -0700 Subject: [PATCH] test/vhost: Allow string names for vhost targets Don't require these to be numbered. Change-Id: I385f579b41d24eea02e157e53c4fc1530864bb5b Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/461389 Tested-by: SPDK CI Jenkins Reviewed-by: Darek Stojaczyk Reviewed-by: Jim Harris --- test/lvol/lvol.sh | 2 +- test/nvmf/target/nvmf_vhost.sh | 2 +- test/pmem/common.sh | 2 +- test/pmem/pmem.sh | 2 +- test/vhost/common.sh | 68 +++++++++---------- test/vhost/fiotest/fio.sh | 4 +- test/vhost/hotplug/common.sh | 4 +- test/vhost/initiator/blockdev.sh | 5 +- test/vhost/integrity/integrity_start.sh | 4 +- test/vhost/lvol/lvol_test.sh | 4 +- test/vhost/migration/migration-tc1.sh | 4 +- test/vhost/migration/migration-tc2.sh | 4 +- test/vhost/migration/migration-tc3b.sh | 2 +- test/vhost/other/negative.sh | 4 +- test/vhost/perf_bench/vhost_perf.sh | 4 +- test/vhost/readonly/readonly.sh | 4 +- test/vhost/shared/shared.sh | 4 +- test/vhost/vhost_boot/vhost_boot.sh | 12 ++-- test/vhost/windows/windows.sh | 4 +- test/vhost/windows/windows_scsi_compliance.sh | 4 +- 20 files changed, 69 insertions(+), 74 deletions(-) diff --git a/test/lvol/lvol.sh b/test/lvol/lvol.sh index 27fdb566d..7999405ef 100755 --- a/test/lvol/lvol.sh +++ b/test/lvol/lvol.sh @@ -133,6 +133,6 @@ truncate -s 400M $testdir/aio_bdev_0 $testdir/aio_bdev_1 vhost_start $testdir/lvol_test.py $rpc_py $total_size $block_size $testdir $rootdir/app/vhost "${test_cases[@]}" -vhost_kill +vhost_kill 0 rm -rf $testdir/aio_bdev_0 $testdir/aio_bdev_1 trap - SIGINT SIGTERM EXIT diff --git a/test/nvmf/target/nvmf_vhost.sh b/test/nvmf/target/nvmf_vhost.sh index e95907911..5abd6d241 100755 --- a/test/nvmf/target/nvmf_vhost.sh +++ b/test/nvmf/target/nvmf_vhost.sh @@ -53,7 +53,7 @@ $VHOST_RPC construct_vhost_scsi_controller naa.VhostScsi0.3 $VHOST_RPC add_vhost_scsi_lun naa.VhostScsi0.3 0 "Nvme0n1" # start qemu based VM. -vm_setup --os="$VM_IMAGE" --disk-type=spdk_vhost_scsi --disks="VhostScsi0" --force=3 --vhost-num=3 +vm_setup --os="$VM_IMAGE" --disk-type=spdk_vhost_scsi --disks="VhostScsi0" --force=3 --vhost-name=3 vm_run 3 diff --git a/test/pmem/common.sh b/test/pmem/common.sh index 26ad3590a..ba1cae7e6 100644 --- a/test/pmem/common.sh +++ b/test/pmem/common.sh @@ -8,7 +8,7 @@ function error() echo -e "ERROR: $1" echo "error code: $error_code" echo "===========" - vhost_kill + vhost_kill 0 pmem_clean_pool_file return $error_code } diff --git a/test/pmem/pmem.sh b/test/pmem/pmem.sh index d3b48bd71..5eed0e6c3 100755 --- a/test/pmem/pmem.sh +++ b/test/pmem/pmem.sh @@ -698,5 +698,5 @@ fi pmem_clean_pool_file report_test_completion "pmem" -vhost_kill +vhost_kill 0 timing_exit pmem diff --git a/test/vhost/common.sh b/test/vhost/common.sh index e5d605066..d9be8cbe9 100644 --- a/test/vhost/common.sh +++ b/test/vhost/common.sh @@ -96,42 +96,34 @@ function notice() function get_vhost_dir() { - if [[ ! -z "$1" ]]; then - assert_number "$1" - local vhost_num=$1 - else - local vhost_num=0 + local vhost_name="$1" + + if [[ -z "$vhost_name" ]]; then + error "vhost name must be provided to get_vhost_dir" + return 1 fi - echo "$TARGET_DIR/${vhost_num}" -} - -function vhost_list_all() -{ - shopt -s nullglob - local vhost_list="$(echo $TARGET_DIR/[0-9]*)" - shopt -u nullglob - - if [[ ! -z "$vhost_list" ]]; then - vhost_list="$(basename --multiple $vhost_list)" - echo "${vhost_list//vhost/}" - fi + echo "$TARGET_DIR/${vhost_name}" } function vhost_run() { - local vhost_num="$1" + local vhost_name="$1" - assert_number "$vhost_num" shift - local vhost_dir="$(get_vhost_dir $vhost_num)" + if [[ -z "$vhost_name" ]]; then + error "vhost name must be provided to vhost_run" + return 1 + fi + + local vhost_dir="$(get_vhost_dir $vhost_name)" local vhost_app="$rootdir/app/vhost/vhost" local vhost_log_file="$vhost_dir/vhost.log" local vhost_pid_file="$vhost_dir/vhost.pid" local vhost_socket="$vhost_dir/usvhost" notice "starting vhost app in background" - [[ -r "$vhost_pid_file" ]] && vhost_kill $vhost_num + [[ -r "$vhost_pid_file" ]] && vhost_kill 0 $vhost_name [[ -d $vhost_dir ]] && rm -f $vhost_dir/* mkdir -p $vhost_dir @@ -175,13 +167,14 @@ function vhost_load_config() function vhost_kill() { local rc=0 - local vhost_num=0 - if [[ ! -z "$1" ]]; then - vhost_num=$1 - assert_number "$vhost_num" + local vhost_name="$1" + + if [[ -z "$vhost_name" ]]; then + error "Must provide vhost name to vhost_kill" + return 0 fi - local vhost_pid_file="$(get_vhost_dir $vhost_num)/vhost.pid" + local vhost_pid_file="$(get_vhost_dir $vhost_name)/vhost.pid" if [[ ! -r $vhost_pid_file ]]; then warning "no vhost pid file found" @@ -229,14 +222,15 @@ function vhost_kill() function vhost_rpc { - local vhost_num=0 - if [[ ! -z "$1" ]]; then - vhost_num=$1 - assert_number "$vhost_num" + local vhost_name="$1" + + if [[ -z "$vhost_name" ]]; then + error "vhost name must be provided to vhost_rpc" + return 1 fi shift - $rootdir/scripts/rpc.py -s $(get_vhost_dir $vhost_num)/rpc.sock $@ + $rootdir/scripts/rpc.py -s $(get_vhost_dir $vhost_name)/rpc.sock $@ } ### @@ -521,7 +515,7 @@ function vm_setup() local force_vm="" local guest_memory=1024 local queue_number="" - local vhost_dir="$(get_vhost_dir)" + local vhost_dir="$(get_vhost_dir 0)" while getopts ':-:' optchar; do case "$optchar" in -) @@ -538,7 +532,7 @@ function vm_setup() queue_num=*) local queue_number=${OPTARG#*=} ;; incoming=*) local vm_incoming="${OPTARG#*=}" ;; migrate-to=*) local vm_migrate_to="${OPTARG#*=}" ;; - vhost-num=*) local vhost_dir="$(get_vhost_dir ${OPTARG#*=})" ;; + vhost-name=*) local vhost_dir="$(get_vhost_dir ${OPTARG#*=})" ;; spdk-boot=*) local boot_from="${OPTARG#*=}" ;; *) error "unknown argument $OPTARG" @@ -1097,7 +1091,7 @@ function run_fio() # function at_app_exit() { - local vhost_num + local vhost_name notice "APP EXITING" notice "killing all VMs" @@ -1105,8 +1099,8 @@ function at_app_exit() # Kill vhost application notice "killing vhost app" - for vhost_num in $(vhost_list_all); do - vhost_kill $vhost_num + for vhost_name in $(ls $TARGET_DIR); do + vhost_kill $vhost_name done notice "EXIT DONE" diff --git a/test/vhost/fiotest/fio.sh b/test/vhost/fiotest/fio.sh index 908a35968..f68c00077 100755 --- a/test/vhost/fiotest/fio.sh +++ b/test/vhost/fiotest/fio.sh @@ -91,7 +91,7 @@ notice "" notice "Setting up VM" notice "" -rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir)/rpc.sock" +rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock" for vm_conf in ${vms[@]}; do IFS=',' read -ra conf <<< "$vm_conf" @@ -254,7 +254,7 @@ if ! $no_shutdown; then fi notice "Testing done -> shutting down" notice "killing vhost app" - vhost_kill + vhost_kill 0 notice "EXIT DONE" notice "===============" diff --git a/test/vhost/hotplug/common.sh b/test/vhost/hotplug/common.sh index d3d308617..634c53426 100644 --- a/test/vhost/hotplug/common.sh +++ b/test/vhost/hotplug/common.sh @@ -65,7 +65,7 @@ fio_job=$testdir/fio_jobs/default_integrity.job tmp_attach_job=$testdir/fio_jobs/fio_attach.job.tmp tmp_detach_job=$testdir/fio_jobs/fio_detach.job.tmp -rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir)/rpc.sock" +rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock" function print_test_fio_header() { notice "===============" @@ -181,7 +181,7 @@ function reboot_all_and_prepare() { function post_test_case() { vm_shutdown_all - vhost_kill + vhost_kill 0 } function on_error_exit() { diff --git a/test/vhost/initiator/blockdev.sh b/test/vhost/initiator/blockdev.sh index c49d5a243..682ff0c15 100755 --- a/test/vhost/initiator/blockdev.sh +++ b/test/vhost/initiator/blockdev.sh @@ -37,7 +37,7 @@ vhosttestinit source $testdir/autotest.config PLUGIN_DIR=$rootdir/examples/bdev/fio_plugin -RPC_PY="$rootdir/scripts/rpc.py -s $(get_vhost_dir)/rpc.sock" +RPC_PY="$rootdir/scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock" if [ ! -x $FIO_PATH ]; then error "Invalid path of fio binary" @@ -50,6 +50,7 @@ fi trap 'rm -f *.state $rootdir/spdk.tar.gz $rootdir/fio.tar.gz $(get_vhost_dir)/Virtio0;\ error_exit "${FUNCNAME}""${LINENO}"' ERR SIGTERM SIGABRT + function run_spdk_fio() { fio_bdev --ioengine=spdk_bdev "$@" --spdk_mem=1024 --spdk_single_seg=1 } @@ -109,7 +110,7 @@ timing_exit run_spdk_fio_unmap $RPC_PY delete_nvme_controller Nvme0 timing_enter vhost_kill -vhost_kill +vhost_kill 0 timing_exit vhost_kill vhosttestfini diff --git a/test/vhost/integrity/integrity_start.sh b/test/vhost/integrity/integrity_start.sh index 103f21e66..0f60ccdeb 100755 --- a/test/vhost/integrity/integrity_start.sh +++ b/test/vhost/integrity/integrity_start.sh @@ -52,7 +52,7 @@ done vhosttestinit . $(readlink -e "$(dirname $0)/../common.sh") || exit 1 -rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir)/rpc.sock" +rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock" trap 'error_exit "${FUNCNAME}" "${LINENO}"' SIGTERM SIGABRT ERR @@ -98,6 +98,6 @@ clean_lvol_cfg $rpc_py delete_nvme_controller Nvme0 notice "Shutting down SPDK vhost app..." -vhost_kill +vhost_kill 0 vhosttestfini diff --git a/test/vhost/lvol/lvol_test.sh b/test/vhost/lvol/lvol_test.sh index 4e5116387..f896b9f2d 100755 --- a/test/vhost/lvol/lvol_test.sh +++ b/test/vhost/lvol/lvol_test.sh @@ -6,7 +6,7 @@ source $rootdir/test/common/autotest_common.sh source $rootdir/test/vhost/common.sh source $rootdir/scripts/common.sh -rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir)/rpc.sock" +rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock" vm_count=1 max_disks="" @@ -282,6 +282,6 @@ $rpc_py get_bdevs $rpc_py get_vhost_controllers notice "Shutting down SPDK vhost app..." -vhost_kill +vhost_kill 0 vhosttestfini diff --git a/test/vhost/migration/migration-tc1.sh b/test/vhost/migration/migration-tc1.sh index 7a5ddc288..c5a9f2b31 100644 --- a/test/vhost/migration/migration-tc1.sh +++ b/test/vhost/migration/migration-tc1.sh @@ -21,7 +21,7 @@ function migration_tc1_configure_vhost() target_vm=1 incoming_vm_ctrlr=naa.Malloc0.$incoming_vm target_vm_ctrlr=naa.Malloc0.$target_vm - rpc="$rootdir/scripts/rpc.py -s $(get_vhost_dir)/rpc.sock" + rpc="$rootdir/scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock" trap 'migration_tc1_error_handler; error_exit "${FUNCNAME}" "${LINENO}"' INT ERR EXIT @@ -115,7 +115,7 @@ function migration_tc1() migration_tc1_clean_vhost_config notice "killing vhost app" - vhost_kill + vhost_kill 0 notice "Migration TC1 SUCCESS" } diff --git a/test/vhost/migration/migration-tc2.sh b/test/vhost/migration/migration-tc2.sh index 18a9da8b5..dba71efa4 100644 --- a/test/vhost/migration/migration-tc2.sh +++ b/test/vhost/migration/migration-tc2.sh @@ -129,9 +129,9 @@ function migration_tc2_configure_vhost() notice "Setting up VMs" vm_setup --os="$os_image" --force=$incoming_vm --disk-type=spdk_vhost_scsi --disks=VhostScsi0 \ - --migrate-to=$target_vm --memory=1024 --vhost-num=0 + --migrate-to=$target_vm --memory=1024 --vhost-name=0 vm_setup --force=$target_vm --disk-type=spdk_vhost_scsi --disks=VhostScsi0 --incoming=$incoming_vm --memory=1024 \ - --vhost-num=1 + --vhost-name=1 # Run everything vm_run $incoming_vm $target_vm diff --git a/test/vhost/migration/migration-tc3b.sh b/test/vhost/migration/migration-tc3b.sh index a94a6af77..a10bfb29a 100644 --- a/test/vhost/migration/migration-tc3b.sh +++ b/test/vhost/migration/migration-tc3b.sh @@ -40,7 +40,7 @@ function host_2_start_vhost() $rpc add_vhost_scsi_lun $target_vm_ctrl 0 Nvme0n1 vm_setup --os="$os_image" --force=$target_vm --disk-type=spdk_vhost_scsi --disks=VhostScsi0 \ - --memory=512 --vhost-num=1 --incoming=$incoming_vm + --memory=512 --vhost-name=1 --incoming=$incoming_vm vm_run $target_vm sleep 1 diff --git a/test/vhost/other/negative.sh b/test/vhost/other/negative.sh index b2e0d2dde..cbd121755 100755 --- a/test/vhost/other/negative.sh +++ b/test/vhost/other/negative.sh @@ -73,7 +73,7 @@ if [[ $RUN_NIGHTLY -eq 1 ]]; then vhost_json_config 0 $testdir/conf.json notice "" - rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir)/rpc.sock" + rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock" # General commands notice "Trying to remove nonexistent controller" @@ -142,7 +142,7 @@ if [[ $RUN_NIGHTLY -eq 1 ]]; then notice "Testing done -> shutting down" notice "killing vhost app" - vhost_kill + vhost_kill 0 notice "EXIT DONE" notice "===============" diff --git a/test/vhost/perf_bench/vhost_perf.sh b/test/vhost/perf_bench/vhost_perf.sh index 62ecd4e5a..a5e0c949d 100755 --- a/test/vhost/perf_bench/vhost_perf.sh +++ b/test/vhost/perf_bench/vhost_perf.sh @@ -139,7 +139,7 @@ while getopts 'xh-:' optchar; do esac done -rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir)/rpc.sock" +rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock" if [[ -n $custom_cpu_cfg ]]; then source $custom_cpu_cfg @@ -386,7 +386,7 @@ else else cleanup_lvol_cfg fi - vhost_kill + vhost_kill 0 fi if [[ -n "$kernel_cpus" ]]; then diff --git a/test/vhost/readonly/readonly.sh b/test/vhost/readonly/readonly.sh index 7ef130540..ab6135ffd 100755 --- a/test/vhost/readonly/readonly.sh +++ b/test/vhost/readonly/readonly.sh @@ -5,7 +5,7 @@ rootdir=$(readlink -f $testdir/../../..) source $rootdir/test/common/autotest_common.sh source $rootdir/test/vhost/common.sh -rpc_py="$testdir/../../../scripts/rpc.py -s $(get_vhost_dir)/rpc.sock" +rpc_py="$testdir/../../../scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock" vm_img="" disk="Nvme0n1" @@ -130,6 +130,6 @@ blk_ro_tc1 $rpc_py delete_nvme_controller Nvme0 -vhost_kill +vhost_kill 0 vhosttestfini diff --git a/test/vhost/shared/shared.sh b/test/vhost/shared/shared.sh index 6198aadff..16da72b92 100755 --- a/test/vhost/shared/shared.sh +++ b/test/vhost/shared/shared.sh @@ -5,7 +5,7 @@ rootdir=$(readlink -f $testdir/../../..) source $rootdir/test/common/autotest_common.sh source $rootdir/test/vhost/common.sh -rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir)/rpc.sock" +rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock" function run_spdk_fio() { fio_bdev --ioengine=spdk_bdev \ @@ -27,6 +27,6 @@ run_fio_pid=$! sleep 1 run_spdk_fio --size=50% --offset=50% --filename=VirtioBlk0 wait $run_fio_pid -vhost_kill +vhost_kill 0 vhosttestfini diff --git a/test/vhost/vhost_boot/vhost_boot.sh b/test/vhost/vhost_boot/vhost_boot.sh index 6ac0de06a..bf25d74a4 100755 --- a/test/vhost/vhost_boot/vhost_boot.sh +++ b/test/vhost/vhost_boot/vhost_boot.sh @@ -7,7 +7,7 @@ source $rootdir/test/common/autotest_common.sh source $rootdir/test/vhost/common.sh source $rootdir/test/bdev/nbd_common.sh -rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir)/rpc.sock" +rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock" vm_no="0" function err_clean @@ -21,7 +21,7 @@ function err_clean $rpc_py remove_vhost_controller naa.vhost_vm.$vm_no $rpc_py destroy_lvol_bdev $lvb_u $rpc_py destroy_lvol_store -u $lvs_u - vhost_kill + vhost_kill 0 exit 1 } @@ -80,11 +80,11 @@ timing_exit create_lvol timing_enter convert_vm_image modprobe nbd -trap 'nbd_stop_disks $(get_vhost_dir)/rpc.sock /dev/nbd0; err_clean "${FUNCNAME}" "${LINENO}"' ERR -nbd_start_disks "$(get_vhost_dir)/rpc.sock" $lvb_u /dev/nbd0 +trap 'nbd_stop_disks $(get_vhost_dir 0)/rpc.sock /dev/nbd0; err_clean "${FUNCNAME}" "${LINENO}"' ERR +nbd_start_disks "$(get_vhost_dir 0)/rpc.sock" $lvb_u /dev/nbd0 qemu-img convert $os_image -O raw /dev/nbd0 sync -nbd_stop_disks $(get_vhost_dir)/rpc.sock /dev/nbd0 +nbd_stop_disks $(get_vhost_dir 0)/rpc.sock /dev/nbd0 sleep 1 timing_exit convert_vm_image @@ -119,7 +119,7 @@ $rpc_py remove_vhost_scsi_target naa.vhost_vm.$vm_no 0 $rpc_py remove_vhost_controller naa.vhost_vm.$vm_no $rpc_py destroy_lvol_bdev $lvb_u $rpc_py destroy_lvol_store -u $lvs_u -vhost_kill +vhost_kill 0 timing_exit clean_vhost timing_exit vhost_boot diff --git a/test/vhost/windows/windows.sh b/test/vhost/windows/windows.sh index a3cec79be..3a9ded80a 100755 --- a/test/vhost/windows/windows.sh +++ b/test/vhost/windows/windows.sh @@ -5,7 +5,7 @@ rootdir=$(readlink -f $testdir/../../..) source $rootdir/test/common/autotest_common.sh source $rootdir/test/vhost/common.sh -rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir)/rpc.sock" +rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock" ctrl_type="spdk_vhost_scsi" ssh_pass="" vm_num="0" @@ -132,6 +132,6 @@ notice "Shutting down Windows VM..." vm_kill $vm_num notice "Shutting down SPDK vhost app..." -vhost_kill +vhost_kill 0 rm -f $aio_file diff --git a/test/vhost/windows/windows_scsi_compliance.sh b/test/vhost/windows/windows_scsi_compliance.sh index b82a94756..c13973bd4 100755 --- a/test/vhost/windows/windows_scsi_compliance.sh +++ b/test/vhost/windows/windows_scsi_compliance.sh @@ -14,7 +14,7 @@ aio_file="$testdir/aio_disk" ssh_pass="" vm_num=1 keep_results_dir=false -rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir)/rpc.sock" +rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock" function usage() { @@ -76,7 +76,7 @@ dos2unix $testdir/results/WIN_SCSI_*.log notice "Kill vm 1" vm_kill "$vm_num" notice "Kill spdk" -vhost_kill +vhost_kill 0 notice "Remove $aio_file" rm -f $aio_file