xref: /spdk/test/vhost/hotplug/blk_hotremove.sh (revision eb53c23236cccb6b698b7ca70ee783da1c574b5f)
1*eb53c232Spaul luse#  SPDX-License-Identifier: BSD-3-Clause
2*eb53c232Spaul luse#  Copyright (C) 2017 Intel Corporation
3*eb53c232Spaul luse#  All rights reserved.
4*eb53c232Spaul luse#
5*eb53c232Spaul luse
662556204SPawel Kaminski# Vhost blk hot remove tests
762556204SPawel Kaminski#
862556204SPawel Kaminski# Objective
962556204SPawel Kaminski# The purpose of these tests is to verify that SPDK vhost remains stable during
1062556204SPawel Kaminski# hot-remove operations performed on SCSI and BLK controllers devices.
1162556204SPawel Kaminski# Hot-remove is a scenario where a NVMe device is removed when already in use.
1262556204SPawel Kaminski#
1362556204SPawel Kaminski# Test cases description
1462556204SPawel Kaminski# 1. FIO I/O traffic is run during hot-remove operations.
1562556204SPawel Kaminski#    By default FIO uses default_integrity*.job config files located in
1662556204SPawel Kaminski#    test/vhost/hotplug/fio_jobs directory.
1762556204SPawel Kaminski# 2. FIO mode of operation is random write (randwrite) with verification enabled
1862556204SPawel Kaminski#    which results in also performing read operations.
1962556204SPawel Kaminski# 3. In test cases fio status is checked after every run if any errors occurred.
2062556204SPawel Kaminski
2121140193SPawel Kaminskifunction prepare_fio_cmd_tc1() {
2221140193SPawel Kaminski	print_test_fio_header
2321140193SPawel Kaminski
2421140193SPawel Kaminski	run_fio="$fio_bin --eta=never "
2521140193SPawel Kaminski	for vm_num in $1; do
2621140193SPawel Kaminski		cp $fio_job $tmp_detach_job
2721140193SPawel Kaminski		vm_check_blk_location $vm_num
2821140193SPawel Kaminski		for disk in $SCSI_DISK; do
2921140193SPawel Kaminski			echo "[nvme-host$disk]" >> $tmp_detach_job
3021140193SPawel Kaminski			echo "filename=/dev/$disk" >> $tmp_detach_job
3121140193SPawel Kaminski		done
3221140193SPawel Kaminski		vm_scp "$vm_num" $tmp_detach_job 127.0.0.1:/root/default_integrity_2discs.job
3321140193SPawel Kaminski		run_fio+="--client=127.0.0.1,$(vm_fio_socket $vm_num) --remote-config /root/default_integrity_2discs.job "
3421140193SPawel Kaminski		rm $tmp_detach_job
3521140193SPawel Kaminski	done
3621140193SPawel Kaminski}
3721140193SPawel Kaminski
38edb18971SPawel Kaminskifunction vhost_delete_controllers() {
39edb18971SPawel Kaminski	$rpc_py vhost_delete_controller naa.Nvme0n1p0.0
40edb18971SPawel Kaminski	$rpc_py vhost_delete_controller naa.Nvme0n1p1.0
41edb18971SPawel Kaminski	$rpc_py vhost_delete_controller naa.Nvme0n1p2.1
42edb18971SPawel Kaminski	$rpc_py vhost_delete_controller naa.Nvme0n1p3.1
4321140193SPawel Kaminski}
4421140193SPawel Kaminski
4562556204SPawel Kaminski# Vhost blk hot remove test cases
4662556204SPawel Kaminski#
4762556204SPawel Kaminski# Test Case 1
4821140193SPawel Kaminskifunction blk_hotremove_tc1() {
4921140193SPawel Kaminski	echo "Blk hotremove test case 1"
5021140193SPawel Kaminski	traddr=""
5162556204SPawel Kaminski	# 1. Run the command to hot remove NVMe disk.
5249de02ecSTomasz Zawadzki	get_traddr "Nvme0"
5349de02ecSTomasz Zawadzki	delete_nvme "Nvme0"
5462556204SPawel Kaminski	# 2. If vhost had crashed then tests would stop running
5521140193SPawel Kaminski	sleep 1
5649de02ecSTomasz Zawadzki	add_nvme "HotInNvme0" "$traddr"
5721140193SPawel Kaminski	sleep 1
5821140193SPawel Kaminski}
5921140193SPawel Kaminski
6062556204SPawel Kaminski# Test Case 2
6121140193SPawel Kaminskifunction blk_hotremove_tc2() {
6221140193SPawel Kaminski	echo "Blk hotremove test case 2"
6362556204SPawel Kaminski	# 1. Use rpc command to create blk controllers.
6449de02ecSTomasz Zawadzki	$rpc_py vhost_create_blk_controller naa.Nvme0n1p0.0 HotInNvme0n1p0
65d7c00c17SPawel Kaminski	$rpc_py vhost_create_blk_controller naa.Nvme0n1p1.0 Mallocp0
66d7c00c17SPawel Kaminski	$rpc_py vhost_create_blk_controller naa.Nvme0n1p2.1 Mallocp1
67d7c00c17SPawel Kaminski	$rpc_py vhost_create_blk_controller naa.Nvme0n1p3.1 Mallocp2
6862556204SPawel Kaminski	# 2. Run two VMs and attach every VM to two blk controllers.
6921140193SPawel Kaminski	vm_run_with_arg "0 1"
7021140193SPawel Kaminski	vms_prepare "0"
7121140193SPawel Kaminski
7221140193SPawel Kaminski	traddr=""
7321140193SPawel Kaminski	get_traddr "Nvme0"
7421140193SPawel Kaminski	prepare_fio_cmd_tc1 "0"
7562556204SPawel Kaminski	# 3. Run FIO I/O traffic with verification enabled on NVMe disk.
7621140193SPawel Kaminski	$run_fio &
7721140193SPawel Kaminski	local last_pid=$!
7821140193SPawel Kaminski	sleep 3
7962556204SPawel Kaminski	# 4. Run the command to hot remove NVMe disk.
8049de02ecSTomasz Zawadzki	delete_nvme "HotInNvme0"
8121140193SPawel Kaminski	local retcode=0
8221140193SPawel Kaminski	wait_for_finish $last_pid || retcode=$?
8362556204SPawel Kaminski	# 5. Check that fio job run on hot-removed device stopped.
8462556204SPawel Kaminski	#    Expected: Fio should return error message and return code != 0.
8521140193SPawel Kaminski	check_fio_retcode "Blk hotremove test case 2: Iteration 1." 1 $retcode
8621140193SPawel Kaminski
8762556204SPawel Kaminski	# 6. Reboot VM
8821140193SPawel Kaminski	reboot_all_and_prepare "0"
8962556204SPawel Kaminski	# 7. Run FIO I/O traffic with verification enabled on NVMe disk.
9021140193SPawel Kaminski	$run_fio &
9121140193SPawel Kaminski	local retcode=0
9221140193SPawel Kaminski	wait_for_finish $! || retcode=$?
9362556204SPawel Kaminski	# 8. Check that fio job run on hot-removed device stopped.
9462556204SPawel Kaminski	#    Expected: Fio should return error message and return code != 0.
9521140193SPawel Kaminski	check_fio_retcode "Blk hotremove test case 2: Iteration 2." 1 $retcode
9621140193SPawel Kaminski	vm_shutdown_all
97edb18971SPawel Kaminski	vhost_delete_controllers
9849de02ecSTomasz Zawadzki	add_nvme "HotInNvme1" "$traddr"
9921140193SPawel Kaminski	sleep 1
10021140193SPawel Kaminski}
10121140193SPawel Kaminski
10262556204SPawel Kaminski# ## Test Case 3
10321140193SPawel Kaminskifunction blk_hotremove_tc3() {
10421140193SPawel Kaminski	echo "Blk hotremove test case 3"
10562556204SPawel Kaminski	# 1. Use rpc command to create blk controllers.
10649de02ecSTomasz Zawadzki	$rpc_py vhost_create_blk_controller naa.Nvme0n1p0.0 HotInNvme1n1p0
107d7c00c17SPawel Kaminski	$rpc_py vhost_create_blk_controller naa.Nvme0n1p1.0 Mallocp0
10849de02ecSTomasz Zawadzki	$rpc_py vhost_create_blk_controller naa.Nvme0n1p2.1 HotInNvme1n1p1
109d7c00c17SPawel Kaminski	$rpc_py vhost_create_blk_controller naa.Nvme0n1p3.1 Mallocp1
11062556204SPawel Kaminski	# 2. Run two VMs and attach every VM to two blk controllers.
11121140193SPawel Kaminski	vm_run_with_arg "0 1"
11221140193SPawel Kaminski	vms_prepare "0 1"
11321140193SPawel Kaminski
11421140193SPawel Kaminski	traddr=""
11521140193SPawel Kaminski	get_traddr "Nvme0"
11621140193SPawel Kaminski	prepare_fio_cmd_tc1 "0"
11762556204SPawel Kaminski	# 3. Run FIO I/O traffic with verification enabled on first NVMe disk.
11821140193SPawel Kaminski	$run_fio &
11921140193SPawel Kaminski	local last_pid=$!
12021140193SPawel Kaminski	sleep 3
12162556204SPawel Kaminski	# 4. Run the command to hot remove of first NVMe disk.
12249de02ecSTomasz Zawadzki	delete_nvme "HotInNvme1"
12321140193SPawel Kaminski	local retcode=0
12421140193SPawel Kaminski	wait_for_finish $last_pid || retcode=$?
12562556204SPawel Kaminski	# 6. Check that fio job run on hot-removed device stopped.
12662556204SPawel Kaminski	#    Expected: Fio should return error message and return code != 0.
12721140193SPawel Kaminski	check_fio_retcode "Blk hotremove test case 3: Iteration 1." 1 $retcode
12821140193SPawel Kaminski
12962556204SPawel Kaminski	# 7. Reboot VM
13021140193SPawel Kaminski	reboot_all_and_prepare "0"
13121140193SPawel Kaminski	local retcode=0
13262556204SPawel Kaminski	# 8. Run FIO I/O traffic with verification enabled on removed NVMe disk.
13321140193SPawel Kaminski	$run_fio &
13421140193SPawel Kaminski	wait_for_finish $! || retcode=$?
13562556204SPawel Kaminski	# 9. Check that fio job run on hot-removed device stopped.
13662556204SPawel Kaminski	#    Expected: Fio should return error message and return code != 0.
13721140193SPawel Kaminski	check_fio_retcode "Blk hotremove test case 3: Iteration 2." 1 $retcode
13821140193SPawel Kaminski	vm_shutdown_all
139edb18971SPawel Kaminski	vhost_delete_controllers
14049de02ecSTomasz Zawadzki	add_nvme "HotInNvme2" "$traddr"
14121140193SPawel Kaminski	sleep 1
14221140193SPawel Kaminski}
14321140193SPawel Kaminski
14462556204SPawel Kaminski# Test Case 4
14521140193SPawel Kaminskifunction blk_hotremove_tc4() {
14621140193SPawel Kaminski	echo "Blk hotremove test case 4"
14762556204SPawel Kaminski	# 1. Use rpc command to create blk controllers.
14849de02ecSTomasz Zawadzki	$rpc_py vhost_create_blk_controller naa.Nvme0n1p0.0 HotInNvme2n1p0
149d7c00c17SPawel Kaminski	$rpc_py vhost_create_blk_controller naa.Nvme0n1p1.0 Mallocp0
15049de02ecSTomasz Zawadzki	$rpc_py vhost_create_blk_controller naa.Nvme0n1p2.1 HotInNvme2n1p1
151d7c00c17SPawel Kaminski	$rpc_py vhost_create_blk_controller naa.Nvme0n1p3.1 Mallocp1
15262556204SPawel Kaminski	# 2. Run two VM, attached to blk controllers.
15321140193SPawel Kaminski	vm_run_with_arg "0 1"
15421140193SPawel Kaminski	vms_prepare "0 1"
15521140193SPawel Kaminski
15621140193SPawel Kaminski	prepare_fio_cmd_tc1 "0"
15762556204SPawel Kaminski	# 3. Run FIO I/O traffic on first VM with verification enabled on both NVMe disks.
15821140193SPawel Kaminski	$run_fio &
15921140193SPawel Kaminski	local last_pid_vm0=$!
16021140193SPawel Kaminski
16121140193SPawel Kaminski	prepare_fio_cmd_tc1 "1"
16262556204SPawel Kaminski	# 4. Run FIO I/O traffic on second VM with verification enabled on both NVMe disks.
16321140193SPawel Kaminski	$run_fio &
16421140193SPawel Kaminski	local last_pid_vm1=$!
16521140193SPawel Kaminski
16621140193SPawel Kaminski	sleep 3
16721140193SPawel Kaminski	prepare_fio_cmd_tc1 "0 1"
16862556204SPawel Kaminski	# 5. Run the command to hot remove of first NVMe disk.
16949de02ecSTomasz Zawadzki	delete_nvme "HotInNvme2"
17021140193SPawel Kaminski	local retcode_vm0=0
17121140193SPawel Kaminski	local retcode_vm1=0
17221140193SPawel Kaminski	wait_for_finish $last_pid_vm0 || retcode_vm0=$?
17321140193SPawel Kaminski	wait_for_finish $last_pid_vm1 || retcode_vm1=$?
17462556204SPawel Kaminski	# 6. Check that fio job run on hot-removed device stopped.
17562556204SPawel Kaminski	#    Expected: Fio should return error message and return code != 0.
17621140193SPawel Kaminski	check_fio_retcode "Blk hotremove test case 4: Iteration 1." 1 $retcode_vm0
17721140193SPawel Kaminski	check_fio_retcode "Blk hotremove test case 4: Iteration 2." 1 $retcode_vm1
17821140193SPawel Kaminski
17962556204SPawel Kaminski	# 7. Reboot all VMs.
18021140193SPawel Kaminski	reboot_all_and_prepare "0 1"
18162556204SPawel Kaminski	# 8. Run FIO I/O traffic with verification enabled on removed NVMe disk.
18221140193SPawel Kaminski	$run_fio &
18321140193SPawel Kaminski	local retcode=0
18421140193SPawel Kaminski	wait_for_finish $! || retcode=$?
18562556204SPawel Kaminski	# 9. Check that fio job run on hot-removed device stopped.
18662556204SPawel Kaminski	#    Expected: Fio should return error message and return code != 0.
18721140193SPawel Kaminski	check_fio_retcode "Blk hotremove test case 4: Iteration 3." 1 $retcode
18821140193SPawel Kaminski
18921140193SPawel Kaminski	vm_shutdown_all
190edb18971SPawel Kaminski	vhost_delete_controllers
19149de02ecSTomasz Zawadzki	add_nvme "HotInNvme3" "$traddr"
19221140193SPawel Kaminski	sleep 1
19321140193SPawel Kaminski}
19421140193SPawel Kaminski
19562556204SPawel Kaminski# Test Case 5
19621140193SPawel Kaminskifunction blk_hotremove_tc5() {
19721140193SPawel Kaminski	echo "Blk hotremove test case 5"
19862556204SPawel Kaminski	# 1. Use rpc command to create blk controllers.
19949de02ecSTomasz Zawadzki	$rpc_py vhost_create_blk_controller naa.Nvme0n1p0.0 HotInNvme3n1p0
200d7c00c17SPawel Kaminski	$rpc_py vhost_create_blk_controller naa.Nvme0n1p1.0 Mallocp0
201d7c00c17SPawel Kaminski	$rpc_py vhost_create_blk_controller naa.Nvme0n1p2.1 Mallocp1
202d7c00c17SPawel Kaminski	$rpc_py vhost_create_blk_controller naa.Nvme0n1p3.1 Mallocp2
20362556204SPawel Kaminski	# 2. Run two VM, attached to blk controllers.
20421140193SPawel Kaminski	vm_run_with_arg "0 1"
20521140193SPawel Kaminski	vms_prepare "0 1"
20621140193SPawel Kaminski
20721140193SPawel Kaminski	prepare_fio_cmd_tc1 "0"
20862556204SPawel Kaminski	# 3. Run FIO I/O traffic on first VM with verification enabled on both NVMe disks.
20921140193SPawel Kaminski	$run_fio &
21021140193SPawel Kaminski	local last_pid=$!
21121140193SPawel Kaminski	sleep 3
21262556204SPawel Kaminski	# 4. Run the command to hot remove of first NVMe disk.
21349de02ecSTomasz Zawadzki	delete_nvme "HotInNvme3"
21421140193SPawel Kaminski	local retcode=0
21521140193SPawel Kaminski	wait_for_finish $last_pid || retcode=$?
21662556204SPawel Kaminski	# 5. Check that fio job run on hot-removed device stopped.
21762556204SPawel Kaminski	#    Expected: Fio should return error message and return code != 0.
21821140193SPawel Kaminski	check_fio_retcode "Blk hotremove test case 5: Iteration 1." 1 $retcode
21921140193SPawel Kaminski
22062556204SPawel Kaminski	# 6. Reboot VM.
22121140193SPawel Kaminski	reboot_all_and_prepare "0"
22221140193SPawel Kaminski	local retcode=0
22362556204SPawel Kaminski	# 7. Run FIO I/O traffic with verification enabled on removed NVMe disk.
22421140193SPawel Kaminski	$run_fio &
22521140193SPawel Kaminski	wait_for_finish $! || retcode=$?
22662556204SPawel Kaminski	# 8. Check that fio job run on hot-removed device stopped.
22762556204SPawel Kaminski	#    Expected: Fio should return error message and return code != 0.
22821140193SPawel Kaminski	check_fio_retcode "Blk hotremove test case 5: Iteration 2." 1 $retcode
22921140193SPawel Kaminski	vm_shutdown_all
230edb18971SPawel Kaminski	vhost_delete_controllers
23149de02ecSTomasz Zawadzki	add_nvme "HotInNvme4" "$traddr"
23221140193SPawel Kaminski	sleep 1
23321140193SPawel Kaminski}
23421140193SPawel Kaminski
23521140193SPawel Kaminskivms_setup
23621140193SPawel Kaminskiblk_hotremove_tc1
23721140193SPawel Kaminskiblk_hotremove_tc2
23821140193SPawel Kaminskiblk_hotremove_tc3
23921140193SPawel Kaminskiblk_hotremove_tc4
24021140193SPawel Kaminskiblk_hotremove_tc5
241