Commit 33c14a14 authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

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: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I38cfb9073f343a7bf3966754008065c7ab89e609
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12626


Community-CI: Mellanox Build Bot
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
parent 90aba31a
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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;
+12 −0
Original line number Diff line number Diff line
@@ -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