1# SPDX-License-Identifier: BSD-3-Clause 2# Copyright (C) 2018 Intel Corporation 3# All rights reserved. 4# 5 6function migration_tc1_clean_vhost_config() { 7 # Restore trap 8 trap 'error_exit "${FUNCNAME}" "${LINENO}"' INT ERR EXIT 9 10 notice "Removing vhost devices & controllers via RPC ..." 11 # Delete bdev first to remove all LUNs and SCSI targets 12 $rpc bdev_malloc_delete Malloc0 13 14 # Delete controllers 15 $rpc vhost_delete_controller $incoming_vm_ctrlr 16 $rpc vhost_delete_controller $target_vm_ctrlr 17 18 unset -v incoming_vm target_vm incoming_vm_ctrlr target_vm_ctrlr rpc 19} 20 21function migration_tc1_configure_vhost() { 22 # Those are global intentionally - they will be unset in cleanup handler 23 incoming_vm=0 24 target_vm=1 25 incoming_vm_ctrlr=naa.Malloc0.$incoming_vm 26 target_vm_ctrlr=naa.Malloc0.$target_vm 27 rpc="$rootdir/scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock" 28 29 trap 'migration_tc1_error_handler; error_exit "${FUNCNAME}" "${LINENO}"' INT ERR EXIT 30 31 # Construct shared Malloc Bdev 32 $rpc bdev_malloc_create -b Malloc0 128 4096 33 34 # And two controllers - one for each VM. Both are using the same Malloc Bdev as LUN 0 35 $rpc vhost_create_scsi_controller $incoming_vm_ctrlr 36 $rpc vhost_scsi_controller_add_target $incoming_vm_ctrlr 0 Malloc0 37 38 $rpc vhost_create_scsi_controller $target_vm_ctrlr 39 $rpc vhost_scsi_controller_add_target $target_vm_ctrlr 0 Malloc0 40} 41 42function migration_tc1_error_handler() { 43 trap - SIGINT ERR EXIT 44 warning "Migration TC1 ERROR HANDLER" 45 print_backtrace 46 set -x 47 48 vm_kill_all 49 migration_tc1_clean_vhost_config 50 51 warning "Migration TC1 FAILED" 52} 53 54function migration_tc1() { 55 # Use 2 VMs: 56 # incoming VM - the one we want to migrate 57 # targe VM - the one which will accept migration 58 # VM uses 1 GiB memory, here we use light IO workload to keep number of dirty pages 59 # is in low rate of VM's memory, see https://github.com/spdk/spdk/issues/2805. 60 local job_file="$testdir/migration-tc1.job" 61 local log_file 62 log_file="/root/$(basename ${job_file%%.*}).log" 63 64 # Run vhost 65 vhost_run -n 0 66 migration_tc1_configure_vhost 67 68 notice "Setting up VMs" 69 vm_setup --os="$os_image" --force=$incoming_vm --disk-type=spdk_vhost_scsi --disks=Malloc0 --migrate-to=$target_vm 70 vm_setup --force=$target_vm --disk-type=spdk_vhost_scsi --disks=Malloc0 --incoming=$incoming_vm 71 72 # Run everything 73 vm_run $incoming_vm $target_vm 74 75 # Wait only for incoming VM, as target is waiting for migration 76 vm_wait_for_boot 300 $incoming_vm 77 78 # Run fio before migration 79 notice "Starting FIO" 80 81 vm_check_scsi_location $incoming_vm 82 run_fio $fio_bin --job-file="$job_file" --no-wait-for-fio --local --vm="${incoming_vm}$(printf ':/dev/%s' $SCSI_DISK)" 83 84 # Wait a while to let the FIO time to issue some IO 85 sleep 5 86 87 # Check if fio is still running before migration 88 if ! is_fio_running $incoming_vm; then 89 vm_exec $incoming_vm "cat $log_file" 90 error "FIO is not running before migration: process crashed or finished too early" 91 fi 92 93 vm_migrate $incoming_vm 94 sleep 3 95 96 # Check if fio is still running after migration 97 if ! is_fio_running $target_vm; then 98 vm_exec $target_vm "cat $log_file" 99 error "FIO is not running after migration: process crashed or finished too early" 100 fi 101 102 notice "Waiting for fio to finish" 103 local timeout=20 104 while is_fio_running $target_vm; do 105 sleep 1 106 echo -n "." 107 if ((timeout-- == 0)); then 108 error "timeout while waiting for FIO!" 109 fi 110 done 111 112 notice "Fio result is:" 113 vm_exec $target_vm "cat $log_file" 114 115 notice "Migration DONE" 116 117 notice "Shutting down all VMs" 118 vm_shutdown_all 119 120 migration_tc1_clean_vhost_config 121 122 notice "killing vhost app" 123 vhost_kill 0 124 125 notice "Migration TC1 SUCCESS" 126} 127