xref: /spdk/test/vhost/hotplug/scsi_hotattach.sh (revision 12fd2b05939d34c64c02aba56243e55ce636b734)
1#!/usr/bin/env bash
2#  SPDX-License-Identifier: BSD-3-Clause
3#  Copyright (C) 2017 Intel Corporation
4#  All rights reserved.
5#
6testdir=$(readlink -f $(dirname $0))
7rootdir=$(readlink -f $testdir/../../..)
8source "$rootdir/test/vhost/hotplug/common.sh"
9
10function prepare_fio_cmd_tc1() {
11	print_test_fio_header
12
13	run_fio="$fio_bin --eta=never "
14	for vm_num in $1; do
15		cp $fio_job $tmp_attach_job
16		vm_check_scsi_location $vm_num
17		for disk in $SCSI_DISK; do
18			echo "[nvme-host$disk]" >> $tmp_attach_job
19			echo "filename=/dev/$disk" >> $tmp_attach_job
20		done
21		vm_scp $vm_num $tmp_attach_job 127.0.0.1:/root/default_integrity_discs.job
22		run_fio+="--client=127.0.0.1,$(vm_fio_socket ${vm_num}) --remote-config /root/default_integrity_discs.job "
23		rm $tmp_attach_job
24	done
25}
26
27# Check if fio test passes on device attached to first controller.
28function hotattach_tc1() {
29	notice "Hotattach test case 1"
30
31	$rpc_py vhost_scsi_controller_add_target naa.Nvme0n1p0.0 0 Nvme0n1p0
32
33	sleep 3
34	prepare_fio_cmd_tc1 "0"
35	$run_fio
36	check_fio_retcode "Hotattach test case 1: Iteration 1." 0 $?
37}
38
39# Run fio test for previously attached device.
40# During test attach another device to first controller and check fio status.
41function hotattach_tc2() {
42	notice "Hotattach test case 2"
43	prepare_fio_cmd_tc1 "0"
44
45	$run_fio &
46	last_pid=$!
47	sleep 3
48	$rpc_py vhost_scsi_controller_add_target naa.Nvme0n1p0.0 1 Nvme0n1p1
49	wait $last_pid
50	check_fio_retcode "Hotattach test case 2: Iteration 1." 0 $?
51}
52
53# Run fio test for previously attached devices.
54# During test attach another device to second controller and check fio status.
55function hotattach_tc3() {
56	notice "Hotattach test case 3"
57	prepare_fio_cmd_tc1 "0"
58
59	$run_fio &
60	last_pid=$!
61	sleep 3
62	$rpc_py vhost_scsi_controller_add_target naa.Nvme0n1p1.0 0 Nvme0n1p2
63	wait $last_pid
64	check_fio_retcode "Hotattach test case 3: Iteration 1." 0 $?
65}
66
67# Run fio test for previously attached devices.
68# During test attach another device to third controller(VM2) and check fio status.
69# At the end after rebooting VMs run fio test for all devices and check fio status.
70function hotattach_tc4() {
71	notice "Hotattach test case 4"
72
73	prepare_fio_cmd_tc1 "0"
74
75	$run_fio &
76	last_pid=$!
77	sleep 3
78	$rpc_py vhost_scsi_controller_add_target naa.Nvme0n1p2.1 0 Nvme0n1p3
79	wait $last_pid
80	check_fio_retcode "Hotattach test case 4: Iteration 1." 0 $?
81
82	prepare_fio_cmd_tc1 "0 1"
83	$run_fio
84	check_fio_retcode "Hotattach test case 4: Iteration 2." 0 $?
85
86	reboot_all_and_prepare "0 1"
87
88	prepare_fio_cmd_tc1 "0 1"
89	$run_fio
90	check_fio_retcode "Hotattach test case 4: Iteration 3." 0 $?
91}
92
93function cleanup_after_tests() {
94	$rpc_py vhost_scsi_controller_remove_target naa.Nvme0n1p0.0 0
95	$rpc_py vhost_scsi_controller_remove_target naa.Nvme0n1p0.0 1
96	$rpc_py vhost_scsi_controller_remove_target naa.Nvme0n1p1.0 0
97	$rpc_py vhost_scsi_controller_remove_target naa.Nvme0n1p2.1 0
98}
99
100hotattach_tc1
101hotattach_tc2
102hotattach_tc3
103hotattach_tc4
104cleanup_after_tests
105