Commit 0bfaaace authored by Ziye Yang's avatar Ziye Yang Committed by Tomasz Zawadzki
Browse files

sock: Add impl_name parameter in spdk_sock_listen/connect.



Purpose: With this patch,

(1)We can support using different sock implementations in
one application together.

(2)For one IP address managed by kernel, we can use different method
to listen/connect, e.g., posix, or uring. With this patch, we can
designate the specified sock implementation if impl_name is not NULL
and valid. Otherwise, spdk_sock_listen/connect will try to use the sock
implementations in the list by order if impl_name is NULL.

Without this patch, the app will always use the same type of sock implementation
if the order is fixed. For example, if we have posix and uring together,
the first one will always be uring.

Signed-off-by: default avatarZiye Yang <ziye.yang@intel.com>
Change-Id: Ic49563f5025085471d356798e522ff7ab748f586
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478140


Community-CI: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
Community-CI: SPDK CI Jenkins <sys_sgci@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 738b9569
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -25,6 +25,10 @@ never return EAGAIN, instead queueing internally until the data has all been sen
simplify many code flows that create pollers to continue attempting to flush writes
on sockets.

Added `impl_name` parameter in spdk_sock_listen and spdk_sock_connect functions. Users may now
specify the sock layer implementation they'd prefer to use. Valid implementations are currently
"vpp" and "posix" and NULL, where NULL results in the previous behavior of the functions.

### isa-l

Updated ISA-L submodule to commit f3993f5c0b6911 which includes implementation and
+2 −2
Original line number Diff line number Diff line
@@ -213,7 +213,7 @@ hello_sock_connect(struct hello_context_t *ctx)

	SPDK_NOTICELOG("Connecting to the server on %s:%d\n", ctx->host, ctx->port);

	ctx->sock = spdk_sock_connect(ctx->host, ctx->port);
	ctx->sock = spdk_sock_connect(ctx->host, ctx->port, NULL);
	if (ctx->sock == NULL) {
		SPDK_ERRLOG("connect error(%d): %s\n", errno, spdk_strerror(errno));
		return -1;
@@ -340,7 +340,7 @@ hello_sock_group_poll(void *arg)
static int
hello_sock_listen(struct hello_context_t *ctx)
{
	ctx->sock = spdk_sock_listen(ctx->host, ctx->port);
	ctx->sock = spdk_sock_listen(ctx->host, ctx->port, NULL);
	if (ctx->sock == NULL) {
		SPDK_ERRLOG("Cannot create server socket\n");
		return -1;
+16 −6
Original line number Diff line number Diff line
@@ -96,26 +96,36 @@ int spdk_sock_getaddr(struct spdk_sock *sock, char *saddr, int slen, uint16_t *s
		      char *caddr, int clen, uint16_t *cport);

/**
 * Create a socket, connect the socket to the specified address and port (of the
 * server), and then return the socket. This function is used by client.
 * Create a socket using the specific sock implementation, connect the socket
 * to the specified address and port (of the server), and then return the socket.
 * This function is used by client.
 *
 * \param ip IP address of the server.
 * \param port Port number of the server.
 * \param impl_name The sock_implementation to use, such as "posix". If impl_name is
 * specified, it will *only* try to listen on that impl. If it is NULL, it will try
 * all the sock implementations in order and uses the first sock implementation which
 * can connect. For example, it will try vpp, posix as an example.
 *
 * \return a pointer to the connected socket on success, or NULL on failure.
 */
struct spdk_sock *spdk_sock_connect(const char *ip, int port);
struct spdk_sock *spdk_sock_connect(const char *ip, int port, char *impl_name);

/**
 * Create a socket, bind the socket to the specified address and port and listen
 * on the socket, and then return the socket. This function is used by server.
 * Create a socket using the specific sock implementation, bind the socket to
 * the specified address and port and listen on the socket, and then return the socket.
 * This function is used by server.
 *
 * \param ip IP address to listen on.
 * \param port Port number.
 * \param impl_name The sock_implementation to use, such as "posix". If impl_name is
 * specified, it will *only* try to listen on that impl. If it is NULL, it will try
 * all the sock implementations in order and uses the first sock implementation which
 * can listen. For example, it will try vpp, posix as an example.
 *
 * \return a pointer to the listened socket on success, or NULL on failure.
 */
struct spdk_sock *spdk_sock_listen(const char *ip, int port);
struct spdk_sock *spdk_sock_listen(const char *ip, int port, char *impl_name);

/**
 * Accept a new connection from a client on the specified socket and return a
+1 −1
Original line number Diff line number Diff line
@@ -207,7 +207,7 @@ iscsi_portal_open(struct spdk_iscsi_portal *p)
	}

	port = (int)strtol(p->port, NULL, 0);
	sock = spdk_sock_listen(p->host, port);
	sock = spdk_sock_listen(p->host, port, NULL);
	if (sock == NULL) {
		SPDK_ERRLOG("listen error %.64s.%d\n", p->host, port);
		return -1;
+1 −1
Original line number Diff line number Diff line
@@ -1574,7 +1574,7 @@ nvme_tcp_ctrlr_connect_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpa
		return -1;
	}

	tqpair->sock = spdk_sock_connect(ctrlr->trid.traddr, port);
	tqpair->sock = spdk_sock_connect(ctrlr->trid.traddr, port, NULL);
	if (!tqpair->sock) {
		SPDK_ERRLOG("sock connection error of tqpair=%p with addr=%s, port=%ld\n",
			    tqpair, ctrlr->trid.traddr, port);
Loading