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