Commit acc3c993 authored by Kaiqi Chen's avatar Kaiqi Chen Committed by Tomasz Zawadzki
Browse files

nvmf/tcp: refactor nvmf_tcp_qpair_get_trid() to return void



Currently, nvmf_tcp_listen() only supports SPDK_NVMF_ADRFAM_IPV4 and
SPDK_NVMF_ADRFAM_IPV6, and will fail early if the socket type is
unsupported. Therefore, nvmf_tcp_qpair_get_trid() should never
encounter a socket type that is not SPDK_NVMF_ADRFAM_IPV4 or
SPDK_NVMF_ADRFAM_IPV6.

This patch changes the return type to void and replaces the default
case with an SPDK_ERRLOG and assert(false) to catch unreachable code
paths.

Change-Id: Ib673373fb2b60152cf44d95507671999c669498a
Signed-off-by: default avatarKaiqi Chen <kaiqi.chen@smartx.com>
Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/26353


Tested-by: default avatarSPDK Automated Test System <spdkbot@gmail.com>
Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarVasuki Manikarnike <vasuki.manikarnike@hpe.com>
Reviewed-by: default avatarGangCao <gang.cao@intel.com>
Reviewed-by: default avatarKonrad Sztyber <ksztyber@nvidia.com>
parent e9d28d48
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -3564,7 +3564,7 @@ nvmf_tcp_poll_group_poll(struct spdk_nvmf_transport_poll_group *group)
	return num_events;
}

static int
static void
nvmf_tcp_qpair_get_trid(struct spdk_nvmf_qpair *qpair,
			struct spdk_nvme_transport_id *trid, bool peer)
{
@@ -3587,32 +3587,38 @@ nvmf_tcp_qpair_get_trid(struct spdk_nvmf_qpair *qpair,
	} else if (spdk_sock_is_ipv6(tqpair->sock)) {
		trid->adrfam = SPDK_NVMF_ADRFAM_IPV6;
	} else {
		return -1;
		SPDK_ERRLOG("Unsupported socket type for qpair: %p\n", qpair);
		assert(false);
	}

	snprintf(trid->trsvcid, sizeof(trid->trsvcid), "%d", port);
	return 0;
}

static int
nvmf_tcp_qpair_get_local_trid(struct spdk_nvmf_qpair *qpair,
			      struct spdk_nvme_transport_id *trid)
{
	return nvmf_tcp_qpair_get_trid(qpair, trid, 0);
	nvmf_tcp_qpair_get_trid(qpair, trid, 0);

	return 0;
}

static int
nvmf_tcp_qpair_get_peer_trid(struct spdk_nvmf_qpair *qpair,
			     struct spdk_nvme_transport_id *trid)
{
	return nvmf_tcp_qpair_get_trid(qpair, trid, 1);
	nvmf_tcp_qpair_get_trid(qpair, trid, 1);

	return 0;
}

static int
nvmf_tcp_qpair_get_listen_trid(struct spdk_nvmf_qpair *qpair,
			       struct spdk_nvme_transport_id *trid)
{
	return nvmf_tcp_qpair_get_trid(qpair, trid, 0);
	nvmf_tcp_qpair_get_trid(qpair, trid, 0);

	return 0;
}

static void