From e65549fc3441f842d4d3db351fe6fcc26d7d11f5 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 24 Feb 2022 21:57:23 +0000 Subject: [PATCH] test/nvmf/discovery: add get_notification_count This will be helpful to ensure we do not unregister and then reregister a bdev during a discovery failover event. We will want to make sure that if a path gets replaced, that we register the new path before removing the old one, if the old one is removed from the discovery log. Signed-off-by: Jim Harris Change-Id: I9a65f7b8e462ed262e615f2680742db309640e79 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11748 Community-CI: Broadcom CI Reviewed-by: Paul Luse Reviewed-by: Ben Walker Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto Tested-by: SPDK CI Jenkins --- test/nvmf/host/discovery.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/nvmf/host/discovery.sh b/test/nvmf/host/discovery.sh index d060893da..0d9e2b7ac 100755 --- a/test/nvmf/host/discovery.sh +++ b/test/nvmf/host/discovery.sh @@ -61,6 +61,14 @@ function get_subsystem_paths() { $rpc_py -s $HOST_SOCK bdev_nvme_get_controllers -n $1 | jq -r '.[].ctrlrs[].trid.trsvcid' | sort -n | xargs } +# Note that tests need to call get_notification_count and then check $notification_count, +# because if we use $(get_notification_count), the notify_id gets updated in the subshell. +notify_id=0 +function get_notification_count() { + notification_count=$($rpc_py -s $HOST_SOCK notify_get_notifications -i $notify_id | jq '. | length') + notify_id=$((notify_id + notification_count)) +} + [[ "$(get_subsystem_names)" == "" ]] [[ "$(get_bdev_list)" == "" ]] @@ -77,6 +85,8 @@ $rpc_py nvmf_subsystem_add_ns ${NQN}0 null0 $rpc_py nvmf_subsystem_add_listener ${NQN}0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT [[ "$(get_subsystem_names)" == "" ]] [[ "$(get_bdev_list)" == "" ]] +get_notification_count +[[ $notification_count == 0 ]] # Discovery hostnqn is added, so now the host should see the subsystem, with a single path for the # port of the single listener on the target. @@ -84,10 +94,14 @@ $rpc_py nvmf_subsystem_add_host ${NQN}0 $HOST_NQN [[ "$(get_subsystem_names)" == "nvme0" ]] [[ "$(get_bdev_list)" == "nvme0n1" ]] [[ "$(get_subsystem_paths nvme0)" == "$NVMF_PORT" ]] +get_notification_count +[[ $notification_count == 1 ]] # Adding a namespace isn't a discovery function, but do it here anyways just to confirm we see a new bdev. $rpc_py nvmf_subsystem_add_ns ${NQN}0 null1 [[ "$(get_bdev_list)" == "nvme0n1 nvme0n2" ]] +get_notification_count +[[ $notification_count == 1 ]] # Add a second path to the same subsystem. This shouldn't change the list of subsystems or bdevs, but # we should see a second path on the nvme0 subsystem now. @@ -95,6 +109,8 @@ $rpc_py nvmf_subsystem_add_listener ${NQN}0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TA [[ "$(get_subsystem_names)" == "nvme0" ]] [[ "$(get_bdev_list)" == "nvme0n1 nvme0n2" ]] [[ "$(get_subsystem_paths nvme0)" == "$NVMF_PORT $NVMF_SECOND_PORT" ]] +get_notification_count +[[ $notification_count == 0 ]] # Remove the listener for the first port. The subsystem and bdevs should stay, but we should see # the path to that first port disappear. @@ -102,10 +118,14 @@ $rpc_py nvmf_subsystem_remove_listener ${NQN}0 -t $TEST_TRANSPORT -a $NVMF_FIRST [[ "$(get_subsystem_names)" == "nvme0" ]] [[ "$(get_bdev_list)" == "nvme0n1 nvme0n2" ]] [[ "$(get_subsystem_paths nvme0)" == "$NVMF_SECOND_PORT" ]] +get_notification_count +[[ $notification_count == 0 ]] $rpc_py -s $HOST_SOCK bdev_nvme_stop_discovery -b nvme [[ "$(get_subsystem_names)" == "" ]] [[ "$(get_bdev_list)" == "" ]] +get_notification_count +[[ $notification_count == 2 ]] trap - SIGINT SIGTERM EXIT