2022-11-02 15:49:40 +00:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
# Copyright (C) 2018 Intel Corporation
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function migration_tc1_clean_vhost_config() {
|
2018-01-31 14:50:16 +00:00
|
|
|
# Restore trap
|
|
|
|
trap 'error_exit "${FUNCNAME}" "${LINENO}"' INT ERR EXIT
|
|
|
|
|
|
|
|
notice "Removing vhost devices & controllers via RPC ..."
|
|
|
|
# Delete bdev first to remove all LUNs and SCSI targets
|
2019-08-19 08:19:29 +00:00
|
|
|
$rpc bdev_malloc_delete Malloc0
|
2018-01-31 14:50:16 +00:00
|
|
|
|
|
|
|
# Delete controllers
|
2019-09-30 11:01:44 +00:00
|
|
|
$rpc vhost_delete_controller $incoming_vm_ctrlr
|
|
|
|
$rpc vhost_delete_controller $target_vm_ctrlr
|
2018-01-31 14:50:16 +00:00
|
|
|
|
|
|
|
unset -v incoming_vm target_vm incoming_vm_ctrlr target_vm_ctrlr rpc
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function migration_tc1_configure_vhost() {
|
2018-08-22 03:03:03 +00:00
|
|
|
# Those are global intentionally - they will be unset in cleanup handler
|
2018-01-31 14:50:16 +00:00
|
|
|
incoming_vm=0
|
|
|
|
target_vm=1
|
|
|
|
incoming_vm_ctrlr=naa.Malloc0.$incoming_vm
|
|
|
|
target_vm_ctrlr=naa.Malloc0.$target_vm
|
2019-06-04 20:55:21 +00:00
|
|
|
rpc="$rootdir/scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock"
|
2018-01-31 14:50:16 +00:00
|
|
|
|
|
|
|
trap 'migration_tc1_error_handler; error_exit "${FUNCNAME}" "${LINENO}"' INT ERR EXIT
|
|
|
|
|
|
|
|
# Construct shared Malloc Bdev
|
2019-08-09 11:15:35 +00:00
|
|
|
$rpc bdev_malloc_create -b Malloc0 128 4096
|
2018-01-31 14:50:16 +00:00
|
|
|
|
|
|
|
# And two controllers - one for each VM. Both are using the same Malloc Bdev as LUN 0
|
2019-09-24 14:29:10 +00:00
|
|
|
$rpc vhost_create_scsi_controller $incoming_vm_ctrlr
|
2019-09-27 20:53:41 +00:00
|
|
|
$rpc vhost_scsi_controller_add_target $incoming_vm_ctrlr 0 Malloc0
|
2018-01-31 14:50:16 +00:00
|
|
|
|
2019-09-24 14:29:10 +00:00
|
|
|
$rpc vhost_create_scsi_controller $target_vm_ctrlr
|
2019-09-27 20:53:41 +00:00
|
|
|
$rpc vhost_scsi_controller_add_target $target_vm_ctrlr 0 Malloc0
|
2018-01-31 14:50:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function migration_tc1_error_handler() {
|
2018-01-31 14:50:16 +00:00
|
|
|
trap - SIGINT ERR EXIT
|
2018-03-05 14:21:21 +00:00
|
|
|
warning "Migration TC1 ERROR HANDLER"
|
|
|
|
print_backtrace
|
2018-01-31 14:50:16 +00:00
|
|
|
set -x
|
|
|
|
|
|
|
|
vm_kill_all
|
|
|
|
migration_tc1_clean_vhost_config
|
|
|
|
|
|
|
|
warning "Migration TC1 FAILED"
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function migration_tc1() {
|
2018-01-31 14:50:16 +00:00
|
|
|
# Use 2 VMs:
|
|
|
|
# incoming VM - the one we want to migrate
|
|
|
|
# targe VM - the one which will accept migration
|
2019-06-10 21:13:44 +00:00
|
|
|
local job_file="$testdir/migration-tc1.job"
|
2020-04-20 09:26:55 +00:00
|
|
|
local log_file
|
|
|
|
log_file="/root/$(basename ${job_file%%.*}).log"
|
2018-01-31 14:50:16 +00:00
|
|
|
|
|
|
|
# Run vhost
|
2021-03-03 17:34:59 +00:00
|
|
|
vhost_run -n 0
|
2018-01-31 14:50:16 +00:00
|
|
|
migration_tc1_configure_vhost
|
|
|
|
|
|
|
|
notice "Setting up VMs"
|
|
|
|
vm_setup --os="$os_image" --force=$incoming_vm --disk-type=spdk_vhost_scsi --disks=Malloc0 --migrate-to=$target_vm
|
|
|
|
vm_setup --force=$target_vm --disk-type=spdk_vhost_scsi --disks=Malloc0 --incoming=$incoming_vm
|
|
|
|
|
|
|
|
# Run everything
|
|
|
|
vm_run $incoming_vm $target_vm
|
|
|
|
|
|
|
|
# Wait only for incoming VM, as target is waiting for migration
|
2019-03-25 13:14:55 +00:00
|
|
|
vm_wait_for_boot 300 $incoming_vm
|
2018-01-31 14:50:16 +00:00
|
|
|
|
|
|
|
# Run fio before migration
|
|
|
|
notice "Starting FIO"
|
|
|
|
|
|
|
|
vm_check_scsi_location $incoming_vm
|
2020-04-20 09:26:55 +00:00
|
|
|
run_fio $fio_bin --job-file="$job_file" --no-wait-for-fio --local --vm="${incoming_vm}$(printf ':/dev/%s' $SCSI_DISK)"
|
2018-01-31 14:50:16 +00:00
|
|
|
|
|
|
|
# Wait a while to let the FIO time to issue some IO
|
|
|
|
sleep 5
|
|
|
|
|
|
|
|
# Check if fio is still running before migration
|
|
|
|
if ! is_fio_running $incoming_vm; then
|
2020-04-20 09:26:55 +00:00
|
|
|
vm_exec $incoming_vm "cat $log_file"
|
2018-01-31 14:50:16 +00:00
|
|
|
error "FIO is not running before migration: process crashed or finished too early"
|
|
|
|
fi
|
|
|
|
|
|
|
|
vm_migrate $incoming_vm
|
|
|
|
sleep 3
|
|
|
|
|
|
|
|
# Check if fio is still running after migration
|
|
|
|
if ! is_fio_running $target_vm; then
|
2020-04-20 09:26:55 +00:00
|
|
|
vm_exec $target_vm "cat $log_file"
|
2018-01-31 14:50:16 +00:00
|
|
|
error "FIO is not running after migration: process crashed or finished too early"
|
|
|
|
fi
|
|
|
|
|
|
|
|
notice "Waiting for fio to finish"
|
2021-04-01 12:38:12 +00:00
|
|
|
local timeout=20
|
2018-01-31 14:50:16 +00:00
|
|
|
while is_fio_running $target_vm; do
|
|
|
|
sleep 1
|
|
|
|
echo -n "."
|
2020-05-07 11:27:06 +00:00
|
|
|
if ((timeout-- == 0)); then
|
2018-01-31 14:50:16 +00:00
|
|
|
error "timeout while waiting for FIO!"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
notice "Fio result is:"
|
2020-04-20 09:26:55 +00:00
|
|
|
vm_exec $target_vm "cat $log_file"
|
2018-01-31 14:50:16 +00:00
|
|
|
|
|
|
|
notice "Migration DONE"
|
|
|
|
|
|
|
|
notice "Shutting down all VMs"
|
|
|
|
vm_shutdown_all
|
|
|
|
|
|
|
|
migration_tc1_clean_vhost_config
|
|
|
|
|
|
|
|
notice "killing vhost app"
|
2019-06-04 20:55:21 +00:00
|
|
|
vhost_kill 0
|
2018-01-31 14:50:16 +00:00
|
|
|
|
|
|
|
notice "Migration TC1 SUCCESS"
|
|
|
|
}
|