2022-11-02 15:49:40 +00:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
# Copyright (C) 2017 Intel Corporation
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
|
2019-05-10 17:54:24 +00:00
|
|
|
testdir=$(readlink -f $(dirname $0))
|
|
|
|
rootdir=$(readlink -f $testdir/../../..)
|
|
|
|
source $rootdir/test/common/autotest_common.sh
|
|
|
|
source $rootdir/test/vhost/common.sh
|
|
|
|
|
2017-08-02 17:13:48 +00:00
|
|
|
dry_run=false
|
|
|
|
no_shutdown=false
|
|
|
|
fio_bin="fio"
|
2019-05-10 17:54:24 +00:00
|
|
|
fio_jobs="$testdir/fio_jobs/"
|
2017-08-02 17:13:48 +00:00
|
|
|
test_type=spdk_vhost_scsi
|
|
|
|
reuse_vms=false
|
|
|
|
vms=()
|
|
|
|
used_vms=""
|
|
|
|
disk_split=""
|
|
|
|
x=""
|
2017-12-18 15:02:24 +00:00
|
|
|
scsi_hot_remove_test=0
|
2017-12-20 13:26:59 +00:00
|
|
|
blk_hot_remove_test=0
|
2019-10-25 08:49:18 +00:00
|
|
|
readonly=""
|
2017-08-02 17:13:48 +00:00
|
|
|
|
|
|
|
function usage() {
|
2020-05-07 11:27:06 +00:00
|
|
|
[[ -n $2 ]] && (
|
|
|
|
echo "$2"
|
|
|
|
echo ""
|
|
|
|
)
|
|
|
|
echo "Shortcut script for doing automated hotattach/hotdetach test"
|
|
|
|
echo "Usage: $(basename $1) [OPTIONS]"
|
|
|
|
echo
|
|
|
|
echo "-h, --help print help and exit"
|
|
|
|
echo " --test-type=TYPE Perform specified test:"
|
|
|
|
echo " virtio - test host virtio-scsi-pci using file as disk image"
|
|
|
|
echo " kernel_vhost - use kernel driver vhost-scsi"
|
|
|
|
echo " spdk_vhost_scsi - use spdk vhost scsi"
|
|
|
|
echo " spdk_vhost_blk - use spdk vhost block"
|
|
|
|
echo "-x set -x for script debug"
|
|
|
|
echo " --fio-bin=FIO Use specific fio binary (will be uploaded to VM)"
|
|
|
|
echo " --fio-jobs= Fio configs to use for tests. Can point to a directory or"
|
|
|
|
echo " --vm=NUM[,OS][,DISKS] VM configuration. This parameter might be used more than once:"
|
|
|
|
echo " NUM - VM number (mandatory)"
|
|
|
|
echo " OS - VM os disk path (optional)"
|
|
|
|
echo " DISKS - VM os test disks/devices path (virtio - optional, kernel_vhost - mandatory)"
|
|
|
|
echo " --scsi-hotremove-test Run scsi hotremove tests"
|
|
|
|
echo " --readonly Use readonly for fio"
|
|
|
|
exit 0
|
2017-08-02 17:13:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while getopts 'xh-:' optchar; do
|
2020-05-07 11:27:06 +00:00
|
|
|
case "$optchar" in
|
|
|
|
-)
|
|
|
|
case "$OPTARG" in
|
|
|
|
help) usage $0 ;;
|
|
|
|
fio-bin=*) fio_bin="${OPTARG#*=}" ;;
|
|
|
|
fio-jobs=*) fio_jobs="${OPTARG#*=}" ;;
|
|
|
|
test-type=*) test_type="${OPTARG#*=}" ;;
|
|
|
|
vm=*) vms+=("${OPTARG#*=}") ;;
|
|
|
|
scsi-hotremove-test) scsi_hot_remove_test=1 ;;
|
|
|
|
blk-hotremove-test) blk_hot_remove_test=1 ;;
|
|
|
|
readonly) readonly="--readonly" ;;
|
|
|
|
*) usage $0 "Invalid argument '$OPTARG'" ;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
h) usage $0 ;;
|
|
|
|
x)
|
|
|
|
set -x
|
|
|
|
x="-x"
|
|
|
|
;;
|
|
|
|
*) usage $0 "Invalid argument '$OPTARG'" ;;
|
|
|
|
esac
|
2017-08-02 17:13:48 +00:00
|
|
|
done
|
2020-05-07 11:27:06 +00:00
|
|
|
shift $((OPTIND - 1))
|
2017-08-02 17:13:48 +00:00
|
|
|
|
2019-05-10 17:54:24 +00:00
|
|
|
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
|
2017-08-02 17:13:48 +00:00
|
|
|
|
2019-06-04 20:55:21 +00:00
|
|
|
rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock"
|
2017-08-02 17:13:48 +00:00
|
|
|
|
|
|
|
function print_test_fio_header() {
|
2020-05-07 11:27:06 +00:00
|
|
|
notice "==============="
|
|
|
|
notice ""
|
|
|
|
notice "Testing..."
|
2017-08-02 17:13:48 +00:00
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
notice "Running fio jobs ..."
|
|
|
|
if [ $# -gt 0 ]; then
|
|
|
|
echo $1
|
|
|
|
fi
|
2017-08-02 17:13:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function vms_setup() {
|
2020-05-07 11:27:06 +00:00
|
|
|
for vm_conf in "${vms[@]}"; do
|
|
|
|
IFS=',' read -ra conf <<< "$vm_conf"
|
2021-06-24 15:09:14 +00:00
|
|
|
if [[ -z ${conf[0]} ]] || ! assert_number ${conf[0]}; then
|
2020-05-07 11:27:06 +00:00
|
|
|
fail "invalid VM configuration syntax $vm_conf"
|
|
|
|
fi
|
2017-08-02 17:13:48 +00:00
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
# Sanity check if VM is not defined twice
|
|
|
|
for vm_num in $used_vms; do
|
|
|
|
if [[ $vm_num -eq ${conf[0]} ]]; then
|
|
|
|
fail "VM$vm_num defined more than twice ( $(printf "'%s' " "${vms[@]}"))!"
|
|
|
|
fi
|
|
|
|
done
|
2017-08-02 17:13:48 +00:00
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
used_vms+=" ${conf[0]}"
|
2017-08-02 17:13:48 +00:00
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
setup_cmd="vm_setup --disk-type=$test_type --force=${conf[0]}"
|
|
|
|
[[ x"${conf[1]}" != x"" ]] && setup_cmd+=" --os=${conf[1]}"
|
|
|
|
[[ x"${conf[2]}" != x"" ]] && setup_cmd+=" --disks=${conf[2]}"
|
|
|
|
$setup_cmd
|
|
|
|
done
|
2017-08-02 17:13:48 +00:00
|
|
|
}
|
|
|
|
|
2017-12-18 15:02:24 +00:00
|
|
|
function vm_run_with_arg() {
|
2020-05-07 11:27:06 +00:00
|
|
|
local vms_to_run="$*"
|
|
|
|
vm_run $vms_to_run
|
|
|
|
vm_wait_for_boot 300 $vms_to_run
|
2017-12-18 15:02:24 +00:00
|
|
|
}
|
|
|
|
|
2017-08-02 17:13:48 +00:00
|
|
|
function vms_setup_and_run() {
|
2020-05-07 11:27:06 +00:00
|
|
|
local vms_to_run="$*"
|
|
|
|
vms_setup
|
|
|
|
vm_run_with_arg $vms_to_run
|
2017-08-02 17:13:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function vms_prepare() {
|
2020-05-07 11:27:06 +00:00
|
|
|
for vm_num in $1; do
|
|
|
|
qemu_mask_param="VM_${vm_num}_qemu_mask"
|
2017-08-02 17:13:48 +00:00
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
host_name="VM-${vm_num}-${!qemu_mask_param}"
|
|
|
|
notice "Setting up hostname: $host_name"
|
|
|
|
vm_exec $vm_num "hostname $host_name"
|
|
|
|
vm_start_fio_server --fio-bin=$fio_bin $readonly $vm_num
|
|
|
|
done
|
2017-08-02 17:13:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function vms_reboot_all() {
|
2020-05-07 11:27:06 +00:00
|
|
|
notice "Rebooting all vms "
|
|
|
|
for vm_num in $1; do
|
|
|
|
vm_exec $vm_num "reboot" || true
|
|
|
|
while vm_os_booted $vm_num; do
|
|
|
|
sleep 0.5
|
|
|
|
done
|
|
|
|
done
|
2017-08-02 17:13:48 +00:00
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
vm_wait_for_boot 300 $1
|
2017-08-02 17:13:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function check_fio_retcode() {
|
2020-05-07 11:27:06 +00:00
|
|
|
local fio_retcode=$3
|
|
|
|
echo $1
|
|
|
|
local retcode_expected=$2
|
|
|
|
if [ $retcode_expected == 0 ]; then
|
|
|
|
if [ $fio_retcode != 0 ]; then
|
|
|
|
error " Fio test ended with error."
|
|
|
|
else
|
|
|
|
notice " Fio test ended with success."
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ $fio_retcode != 0 ]; then
|
|
|
|
notice " Fio test ended with expected error."
|
|
|
|
else
|
|
|
|
error " Fio test ended with unexpected success."
|
|
|
|
fi
|
|
|
|
fi
|
2017-08-02 17:13:48 +00:00
|
|
|
}
|
|
|
|
|
2017-12-20 13:26:59 +00:00
|
|
|
function wait_for_finish() {
|
2020-05-07 11:27:06 +00:00
|
|
|
local wait_for_pid=$1
|
|
|
|
local sequence=${2:-30}
|
|
|
|
for i in $(seq 1 $sequence); do
|
|
|
|
if kill -0 $wait_for_pid; then
|
|
|
|
sleep 0.5
|
|
|
|
continue
|
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if kill -0 $wait_for_pid; then
|
|
|
|
error "Timeout for fio command"
|
|
|
|
fi
|
|
|
|
|
|
|
|
wait $wait_for_pid
|
2017-12-20 13:26:59 +00:00
|
|
|
}
|
|
|
|
|
2017-08-02 17:13:48 +00:00
|
|
|
function reboot_all_and_prepare() {
|
2020-05-07 11:27:06 +00:00
|
|
|
vms_reboot_all "$1"
|
|
|
|
vms_prepare "$1"
|
2017-12-18 15:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function post_test_case() {
|
2020-05-07 11:27:06 +00:00
|
|
|
vm_shutdown_all
|
|
|
|
vhost_kill 0
|
2017-12-18 15:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function on_error_exit() {
|
2020-05-07 11:27:06 +00:00
|
|
|
set +e
|
|
|
|
echo "Error on $1 - $2"
|
|
|
|
post_test_case
|
|
|
|
print_backtrace
|
|
|
|
exit 1
|
2017-12-18 15:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function check_disks() {
|
2020-05-07 11:27:06 +00:00
|
|
|
if [ "$1" == "$2" ]; then
|
|
|
|
echo "Disk has not been deleted"
|
|
|
|
exit 1
|
|
|
|
fi
|
2017-12-18 15:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_traddr() {
|
2020-05-07 11:27:06 +00:00
|
|
|
local nvme_name=$1
|
|
|
|
local nvme
|
2020-12-15 13:09:02 +00:00
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
nvme="$($rootdir/scripts/gen_nvme.sh)"
|
2021-11-17 14:45:13 +00:00
|
|
|
traddr=$(jq -r ".config[] | select(.params.name == \"$nvme_name\") | .params.traddr" <<< "$nvme")
|
2020-12-15 13:09:02 +00:00
|
|
|
[[ -n $traddr ]] || return 1
|
2017-12-18 15:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function delete_nvme() {
|
2020-05-07 11:27:06 +00:00
|
|
|
$rpc_py bdev_nvme_detach_controller $1
|
2017-12-18 15:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function add_nvme() {
|
2020-05-07 11:27:06 +00:00
|
|
|
$rpc_py bdev_nvme_attach_controller -b $1 -t PCIe -a $2
|
2017-08-02 17:13:48 +00:00
|
|
|
}
|