Commit 6c1f8e80 authored by Michal Berger's avatar Michal Berger Committed by Tomasz Zawadzki
Browse files

test/nvme/sw_hotplug: Simplify the code



Remove stuff that's not needed and squash common parts together. This
should speed up both tests a bit as instead of operating on a single
device, we verify the entire list at once. and we drop the extra use
of setup.sh.

Change-Id: Idb1464ceb558b7c874dd3bc9ea9d61d46b09e9c4
Signed-off-by: default avatarMichal Berger <michal.berger@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17998


Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
parent 08be9c66
Loading
Loading
Loading
Loading
+17 −36
Original line number Diff line number Diff line
@@ -13,9 +13,8 @@ source $rootdir/test/common/autotest_common.sh
remove_attach_helper() {
	local hotplug_events=$1
	local hotplug_wait=$2
	local use_bdev=$3
	local nvme_count=${#nvmes[@]}
	local dev
	local use_bdev=${3:-false}
	local dev bdfs

	# We need to make sure we wait long enough for hotplug to initialize the devices
	# and start IO - if we start removing devices before that happens we will end up
@@ -26,38 +25,16 @@ remove_attach_helper() {
	while ((hotplug_events--)); do
		for dev in "${nvmes[@]}"; do
			echo 1 > "/sys/bus/pci/devices/$dev/remove"
			if $use_bdev; then
				sleep "$hotplug_wait"
				rpc_cmd bdev_get_bdevs \
					| jq '.[] | .driver_specific | .nvme | .[] | .pci_address' \
					| NOT grep $dev
			fi
		done

		echo 1 > "/sys/bus/pci/rescan"

		if $use_bdev; then
			local retries_left=10

			"$rootdir/scripts/setup.sh"

			while [ "$(rpc_cmd bdev_get_bdevs \
				| jq '.[] | .driver_specific | .nvme | .[] | .pci_address' \
				| wc -l)" -lt "$nvme_count" ]; do
				[ $retries_left -gt 0 ] || break
				retries_left=$((retries_left - 1))
				sleep 1
		done

			# Bdev name has already changed, search for the bdev's PCI addresses
			for dev in "${nvmes[@]}"; do
				rpc_cmd bdev_get_bdevs \
					| jq '.[] | .driver_specific | .nvme | .[] | .pci_address' \
					| grep $dev
			done
		fi
		if "$use_bdev"; then
			# Since we removed all the devices, when the sleep settles, we expect to find no bdevs
			sleep "$hotplug_wait" && (($(rpc_cmd bdev_get_bdevs | jq 'length') == 0))
		fi || return 1

		# Avoid setup.sh as it does some extra work which is not relevant for this test.
		echo 1 > "/sys/bus/pci/rescan"

		for dev in "${nvmes[@]}"; do
			echo "${pci_bus_driver["$dev"]}" > "/sys/bus/pci/devices/$dev/driver_override"
			echo "$dev" > "/sys/bus/pci/devices/$dev/driver/unbind"
@@ -67,6 +44,12 @@ remove_attach_helper() {

		# Wait now for hotplug to reattach to the devices
		sleep "$((hotplug_wait * nvme_count))"

		if "$use_bdev"; then
			# See if we get all the bdevs back in one bulk
			bdfs=($(rpc_cmd bdev_get_bdevs | jq -r '.[].driver_specific.nvme[].pci_address' | sort))
			[[ ${bdfs[*]} == "${nvmes[*]}" ]]
		fi
	done
}

@@ -101,7 +84,6 @@ run_hotplug() {

# SPDK target hotplug
tgt_run_hotplug() {
	local i=0
	local dev

	$SPDK_BIN_DIR/spdk_tgt &
@@ -110,10 +92,9 @@ tgt_run_hotplug() {
	trap 'killprocess ${spdk_tgt_pid}; echo 1 > /sys/bus/pci/rescan; exit 1' SIGINT SIGTERM EXIT
	waitforlisten $spdk_tgt_pid

	for dev in "${nvmes[@]}"; do
		rpc_cmd bdev_nvme_attach_controller -b "Nvme0$i" -t PCIe -a $dev
		waitforbdev "Nvme0${i}n1" "$hotplug_wait"
		((i = i + 1))
	for dev in "${!nvmes[@]}"; do
		rpc_cmd bdev_nvme_attach_controller -b "Nvme0$dev" -t PCIe -a "${nvmes[dev]}"
		waitforbdev "Nvme0${dev}n1" "$hotplug_wait"
	done

	rpc_cmd bdev_nvme_set_hotplug -e