2016-12-07 02:21:23 +00:00
|
|
|
#!/usr/bin/env bash
|
2022-11-02 15:49:40 +00:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
# Copyright (C) 2022 Intel Corporation
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
2016-12-07 02:21:23 +00:00
|
|
|
testdir=$(readlink -f $(dirname $0))
|
2018-03-22 22:18:32 +00:00
|
|
|
rootdir=$(readlink -f $testdir/../..)
|
2022-01-19 09:31:52 +00:00
|
|
|
source $rootdir/scripts/common.sh
|
2018-02-27 22:14:08 +00:00
|
|
|
source $rootdir/test/common/autotest_common.sh
|
2016-12-07 02:21:23 +00:00
|
|
|
|
2022-01-19 09:31:52 +00:00
|
|
|
# Pci bus hotplug
|
2022-02-09 12:22:58 +00:00
|
|
|
# Helper function to remove/attach cotrollers
|
2021-09-09 14:50:10 +00:00
|
|
|
remove_attach_helper() {
|
|
|
|
local hotplug_events=$1
|
|
|
|
local hotplug_wait=$2
|
2022-02-09 12:22:58 +00:00
|
|
|
local use_bdev=$3
|
2021-09-09 14:50:10 +00:00
|
|
|
local dev
|
|
|
|
|
2023-01-25 16:20:22 +00:00
|
|
|
# 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"
|
|
|
|
|
2021-09-09 14:50:10 +00:00
|
|
|
while ((hotplug_events--)); do
|
|
|
|
for dev in "${nvmes[@]}"; do
|
|
|
|
echo 1 > "/sys/bus/pci/devices/$dev/remove"
|
2022-02-09 12:22:58 +00:00
|
|
|
if $use_bdev; then
|
|
|
|
sleep "$hotplug_wait"
|
|
|
|
rpc_cmd bdev_get_bdevs \
|
|
|
|
| jq '.[] | .driver_specific | .nvme | .[] | .pci_address' \
|
|
|
|
| NOT grep $dev
|
|
|
|
fi
|
2021-09-09 14:50:10 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
echo 1 > "/sys/bus/pci/rescan"
|
|
|
|
|
2022-02-09 12:22:58 +00:00
|
|
|
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
|
|
|
|
|
2022-07-28 14:30:26 +00:00
|
|
|
# Avoid setup.sh as it does some extra work which is not relevant for this test.
|
2021-09-09 14:50:10 +00:00
|
|
|
for dev in "${nvmes[@]}"; do
|
2022-07-28 14:30:26 +00:00
|
|
|
echo "${pci_bus_driver["$dev"]}" > "/sys/bus/pci/devices/$dev/driver_override"
|
2021-09-09 14:50:10 +00:00
|
|
|
echo "$dev" > "/sys/bus/pci/devices/$dev/driver/unbind"
|
2022-07-28 14:30:26 +00:00
|
|
|
echo "$dev" > "/sys/bus/pci/drivers_probe"
|
|
|
|
echo "" > "/sys/bus/pci/devices/$dev/driver_override"
|
2021-09-09 14:50:10 +00:00
|
|
|
done
|
2022-02-09 12:22:58 +00:00
|
|
|
|
2021-09-09 14:50:10 +00:00
|
|
|
# Wait now for hotplug to reattach to the devices
|
|
|
|
sleep "$hotplug_wait"
|
2017-06-16 02:36:26 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2022-01-19 09:31:52 +00:00
|
|
|
run_hotplug() {
|
2022-06-22 09:26:24 +00:00
|
|
|
trap 'killprocess $hotplug_pid; exit 1' SIGINT SIGTERM EXIT
|
2016-12-07 02:21:23 +00:00
|
|
|
|
2023-01-25 16:20:22 +00:00
|
|
|
"$SPDK_EXAMPLE_DIR/hotplug" \
|
2021-09-09 14:50:10 +00:00
|
|
|
-i 0 \
|
2023-01-25 16:20:22 +00:00
|
|
|
-t $((hotplug_events * hotplug_wait + hotplug_wait * 3)) \
|
2021-09-09 14:50:10 +00:00
|
|
|
-n $((hotplug_events * nvme_count)) \
|
2021-11-19 09:50:08 +00:00
|
|
|
-r $((hotplug_events * nvme_count)) \
|
2023-01-25 16:20:22 +00:00
|
|
|
-l warning &
|
|
|
|
hotplug_pid=$!
|
2022-06-22 09:26:24 +00:00
|
|
|
|
2023-01-25 16:20:22 +00:00
|
|
|
remove_attach_helper "$hotplug_events" "$hotplug_wait" false
|
2022-06-22 09:26:24 +00:00
|
|
|
|
2023-01-25 16:20:22 +00:00
|
|
|
# Wait in case hotplug app is lagging behind
|
|
|
|
# and kill it, if it hung.
|
|
|
|
sleep $hotplug_wait
|
2022-06-22 09:26:24 +00:00
|
|
|
|
2023-01-25 16:20:22 +00:00
|
|
|
if ! kill -0 "$hotplug_pid"; then
|
|
|
|
# hotplug already finished, check for the error code.
|
|
|
|
wait "$hotplug_pid"
|
|
|
|
else
|
|
|
|
echo "Killing hotplug application"
|
|
|
|
killprocess $hotplug_pid
|
|
|
|
return 1
|
|
|
|
fi
|
2022-06-22 09:26:24 +00:00
|
|
|
|
|
|
|
trap - SIGINT SIGTERM EXIT
|
2016-12-07 02:21:23 +00:00
|
|
|
}
|
|
|
|
|
2022-02-09 12:22:58 +00:00
|
|
|
# SPDK target hotplug
|
|
|
|
tgt_run_hotplug() {
|
|
|
|
local i=0
|
|
|
|
local dev
|
|
|
|
|
|
|
|
$SPDK_BIN_DIR/spdk_tgt &
|
|
|
|
spdk_tgt_pid=$!
|
|
|
|
|
|
|
|
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))
|
|
|
|
done
|
|
|
|
|
|
|
|
rpc_cmd bdev_nvme_set_hotplug -e
|
|
|
|
|
|
|
|
remove_attach_helper "$hotplug_events" "$hotplug_wait" true
|
|
|
|
# Verify reregistering hotplug poller
|
|
|
|
rpc_cmd bdev_nvme_set_hotplug -d
|
|
|
|
rpc_cmd bdev_nvme_set_hotplug -e
|
|
|
|
|
|
|
|
remove_attach_helper "$hotplug_events" "$hotplug_wait" true
|
|
|
|
|
|
|
|
trap - SIGINT SIGTERM EXIT
|
|
|
|
killprocess $spdk_tgt_pid
|
|
|
|
}
|
|
|
|
|
|
|
|
# Preparation
|
|
|
|
"$rootdir/scripts/setup.sh"
|
|
|
|
|
|
|
|
hotplug_wait=6
|
|
|
|
hotplug_events=3
|
|
|
|
nvmes=($(nvme_in_userspace))
|
|
|
|
nvme_count=${#nvmes[@]}
|
|
|
|
|
|
|
|
xtrace_disable
|
|
|
|
cache_pci_bus_sysfs
|
|
|
|
xtrace_restore
|
|
|
|
|
2022-01-19 09:31:52 +00:00
|
|
|
# Run pci bus hotplug test
|
|
|
|
run_hotplug
|
2022-02-09 12:22:58 +00:00
|
|
|
|
|
|
|
# Run SPDK target based hotplug
|
|
|
|
tgt_run_hotplug
|