From 33c14a1445c21e18c71206df82d705d0d3b61cab Mon Sep 17 00:00:00 2001 From: Konrad Sztyber Date: Wed, 11 May 2022 11:45:08 +0200 Subject: [PATCH] bdev/nvme: don't allow duplicate discovery service names Otherwise, we'll try to use the same name to create the bdevs. Signed-off-by: Konrad Sztyber Change-Id: I38cfb9073f343a7bf3966754008065c7ab89e609 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12626 Community-CI: Mellanox Build Bot Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Aleksey Marchuk --- module/bdev/nvme/bdev_nvme.c | 6 ++++++ test/nvmf/host/discovery.sh | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/module/bdev/nvme/bdev_nvme.c b/module/bdev/nvme/bdev_nvme.c index ed3bf0276..b89215a8b 100644 --- a/module/bdev/nvme/bdev_nvme.c +++ b/module/bdev/nvme/bdev_nvme.c @@ -5170,6 +5170,12 @@ bdev_nvme_start_discovery(struct spdk_nvme_transport_id *trid, struct discovery_ctx *ctx; struct discovery_entry_ctx *discovery_entry_ctx; + TAILQ_FOREACH(ctx, &g_discovery_ctxs, tailq) { + if (strcmp(ctx->name, base_name) == 0) { + return -EEXIST; + } + } + ctx = calloc(1, sizeof(*ctx)); if (ctx == NULL) { return -ENOMEM; diff --git a/test/nvmf/host/discovery.sh b/test/nvmf/host/discovery.sh index 75e4d053f..6a9ecb4ba 100755 --- a/test/nvmf/host/discovery.sh +++ b/test/nvmf/host/discovery.sh @@ -62,6 +62,10 @@ function get_subsystem_paths() { $rpc_py -s $HOST_SOCK bdev_nvme_get_controllers -n $1 | jq -r '.[].ctrlrs[].trid.trsvcid' | sort -n | xargs } +function get_discovery_ctrlrs() { + $rpc_py -s $HOST_SOCK bdev_nvme_get_discovery_info | jq -r '.[].name' | sort | 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 @@ -133,6 +137,14 @@ sleep 1 # Wait a bit to make sure the discovery service has a chance to detect t get_notification_count [[ $notification_count == 2 ]] +# Make sure that it's not possible to start two discovery services with the same name +$rpc_py -s $HOST_SOCK bdev_nvme_start_discovery -b nvme -t $TEST_TRANSPORT \ + -a $NVMF_FIRST_TARGET_IP -s $DISCOVERY_PORT -f ipv4 -q $HOST_NQN -w +NOT $rpc_py -s $HOST_SOCK bdev_nvme_start_discovery -b nvme -t $TEST_TRANSPORT \ + -a $NVMF_FIRST_TARGET_IP -s $DISCOVERY_PORT -f ipv4 -q $HOST_NQN -w +[[ $(get_discovery_ctrlrs) == "nvme" ]] +[[ $(get_bdev_list) == "nvme0n1 nvme0n2" ]] + trap - SIGINT SIGTERM EXIT kill $hostpid