xref: /spdk/test/vhost/migration/migration-tc1.sh (revision f5d1a924a1dcfac15289d1d9705f8ead23d1114b)
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	local job_file="$testdir/migration-tc1.job"
59	local log_file
60	log_file="/root/$(basename ${job_file%%.*}).log"
61
62	# Run vhost
63	vhost_run -n 0
64	migration_tc1_configure_vhost
65
66	notice "Setting up VMs"
67	vm_setup --os="$os_image" --force=$incoming_vm --disk-type=spdk_vhost_scsi --disks=Malloc0 --migrate-to=$target_vm
68	vm_setup --force=$target_vm --disk-type=spdk_vhost_scsi --disks=Malloc0 --incoming=$incoming_vm
69
70	# Run everything
71	vm_run $incoming_vm $target_vm
72
73	# Wait only for incoming VM, as target is waiting for migration
74	vm_wait_for_boot 300 $incoming_vm
75
76	# Run fio before migration
77	notice "Starting FIO"
78
79	vm_check_scsi_location $incoming_vm
80	run_fio $fio_bin --job-file="$job_file" --no-wait-for-fio --local --vm="${incoming_vm}$(printf ':/dev/%s' $SCSI_DISK)"
81
82	# Wait a while to let the FIO time to issue some IO
83	sleep 5
84
85	# Check if fio is still running before migration
86	if ! is_fio_running $incoming_vm; then
87		vm_exec $incoming_vm "cat $log_file"
88		error "FIO is not running before migration: process crashed or finished too early"
89	fi
90
91	vm_migrate $incoming_vm
92	sleep 3
93
94	# Check if fio is still running after migration
95	if ! is_fio_running $target_vm; then
96		vm_exec $target_vm "cat $log_file"
97		error "FIO is not running after migration: process crashed or finished too early"
98	fi
99
100	notice "Waiting for fio to finish"
101	local timeout=20
102	while is_fio_running $target_vm; do
103		sleep 1
104		echo -n "."
105		if ((timeout-- == 0)); then
106			error "timeout while waiting for FIO!"
107		fi
108	done
109
110	notice "Fio result is:"
111	vm_exec $target_vm "cat $log_file"
112
113	notice "Migration DONE"
114
115	notice "Shutting down all VMs"
116	vm_shutdown_all
117
118	migration_tc1_clean_vhost_config
119
120	notice "killing vhost app"
121	vhost_kill 0
122
123	notice "Migration TC1 SUCCESS"
124}
125