Spdk/test/nvme/sw_hotplug.sh
Krzysztof Karas c8802892ab hotplug: rename and refactor hotplug.sh
Rename hotplug.sh to sw_hotplug.sh (software hotplug)
and refactor its code in preparation for new software
based hotplug test.

Signed-off-by: Maciej Szwed <maciej.szwed@intel.com>
Change-Id: I751fc60ee013de341e064c83f0be3a9b404008e7
Signed-off-by: Krzysztof Karas <krzysztof.karas@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8834
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
2022-04-05 07:42:43 +00:00

71 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
testdir=$(readlink -f $(dirname $0))
rootdir=$(readlink -f $testdir/../..)
source $rootdir/scripts/common.sh
source $rootdir/test/common/autotest_common.sh
# Pci bus hotplug
cleanup() {
[[ -e /proc/$hotplug_pid/status ]] || return 0
kill "$hotplug_pid"
}
remove_attach_helper() {
local hotplug_events=$1
local hotplug_wait=$2
local dev
# 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
# stepping on hotplug's toes forcing it to fail to report proper count of given
# events.
sleep "$hotplug_wait"
while ((hotplug_events--)); do
for dev in "${nvmes[@]}"; do
echo 1 > "/sys/bus/pci/devices/$dev/remove"
done
echo 1 > "/sys/bus/pci/rescan"
# setup.sh masks failures while writing to sysfs interfaces so let's do
# this on our own to make sure there's anything for the hotplug to reattach
# to.
for dev in "${nvmes[@]}"; do
echo "$dev" > "/sys/bus/pci/devices/$dev/driver/unbind"
echo "$dev" > "/sys/bus/pci/drivers/${pci_bus_driver["$dev"]}/bind"
done
# Wait now for hotplug to reattach to the devices
sleep "$hotplug_wait"
done
}
run_hotplug() {
"$rootdir/scripts/setup.sh"
local hotplug_events=3
local hotplug_wait=6 # This should be enough for more stubborn nvmes in the CI
local nvmes=($(nvme_in_userspace))
local nvme_count=${#nvmes[@]}
xtrace_disable
cache_pci_bus_sysfs
xtrace_restore
trap "cleanup" EXIT
remove_attach_helper "$hotplug_events" "$hotplug_wait" &
hotplug_pid=$!
"$SPDK_EXAMPLE_DIR/hotplug" \
-i 0 \
-t $((hotplug_events * hotplug_wait + hotplug_wait)) \
-n $((hotplug_events * nvme_count)) \
-r $((hotplug_events * nvme_count)) \
-l warning
}
# Run pci bus hotplug test
run_hotplug