From 1819d49e4f9405d0f8c75fd621f3b8ae58e2f45c Mon Sep 17 00:00:00 2001 From: Krzysztof Karas Date: Wed, 22 Jun 2022 09:26:24 +0000 Subject: [PATCH] sw_hotplug: run the hotplug in the background Currently we run the remove_attach_helper() function in the background and hotplug application in the foreground - if hotplug hangs unexpectedly, the whole script will freeze. This patch pushes hotplug to run in background to ensure the control over the whole test is on sw_hotplug.sh script's side. This way we can enforce a timeout and stop the execution. Change-Id: I5ae5e4e029f65faf5d41e2f7e1d576823d30ac33 Signed-off-by: Krzysztof Karas Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13407 Tested-by: SPDK CI Jenkins Reviewed-by: Konrad Sztyber Reviewed-by: Tomasz Zawadzki --- test/nvme/sw_hotplug.sh | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/test/nvme/sw_hotplug.sh b/test/nvme/sw_hotplug.sh index 49193f33f..c351d6c58 100755 --- a/test/nvme/sw_hotplug.sh +++ b/test/nvme/sw_hotplug.sh @@ -6,11 +6,6 @@ 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" -} - # Helper function to remove/attach cotrollers remove_attach_helper() { local hotplug_events=$1 @@ -72,17 +67,32 @@ remove_attach_helper() { } run_hotplug() { - trap "cleanup" EXIT - - remove_attach_helper "$hotplug_events" "$hotplug_wait" false & - hotplug_pid=$! + trap 'killprocess $hotplug_pid; exit 1' SIGINT SIGTERM EXIT "$SPDK_EXAMPLE_DIR/hotplug" \ -i 0 \ -t $((hotplug_events * hotplug_wait + hotplug_wait * 3)) \ -n $((hotplug_events * nvme_count)) \ -r $((hotplug_events * nvme_count)) \ - -l warning + -l warning & + hotplug_pid=$! + + remove_attach_helper "$hotplug_events" "$hotplug_wait" false + + # Wait in case hotplug app is lagging behind + # and kill it, if it hung. + sleep $hotplug_wait + + 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 + + trap - SIGINT SIGTERM EXIT } # SPDK target hotplug