Commit 7db1ed8b authored by Ben Walker's avatar Ben Walker Committed by Tomasz Zawadzki
Browse files

sock/posix: Use sendmsg instead of writev when flushing



This is preparation to add flags to the call.

Change-Id: I36109c069b42bd3ec22e023079c62d41a435f44c
Signed-off-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/471771


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Community-CI: SPDK CI Jenkins <sys_sgci@intel.com>
parent ab22d249
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -438,6 +438,8 @@ static int
_sock_flush(struct spdk_sock *sock)
{
	struct spdk_posix_sock *psock = __posix_sock(sock);
	struct msghdr msg = {};
	int flags;
	struct iovec iovs[IOV_BATCH_SIZE];
	int iovcnt;
	int retval;
@@ -488,7 +490,10 @@ _sock_flush(struct spdk_sock *sock)
	}

	/* Perform the vectored write */
	rc = writev(psock->fd, iovs, iovcnt);
	msg.msg_iov = iovs;
	msg.msg_iovlen = iovcnt;
	flags = 0;
	rc = sendmsg(psock->fd, &msg, flags);
	if (rc <= 0) {
		if (errno == EAGAIN || errno == EWOULDBLOCK) {
			return 0;
@@ -526,7 +531,7 @@ _sock_flush(struct spdk_sock *sock)
		req->internal.offset = 0;
		spdk_sock_request_pend(sock, req);

		/* The writev syscall above isn't currently asynchronous,
		/* The sendmsg syscall above isn't currently asynchronous,
		 * so it's already done. */
		retval = spdk_sock_request_put(sock, req, 0);

+7 −7
Original line number Diff line number Diff line
@@ -86,9 +86,9 @@ flush(void)
	req2->cb_arg = &cb_arg2;

	/* Simple test - a request with a 2 element iovec
	 * that gets submitted in a single writev. */
	 * that gets submitted in a single sendmsg. */
	spdk_sock_request_queue(sock, req1);
	MOCK_SET(writev, 64);
	MOCK_SET(sendmsg, 64);
	cb_arg1 = false;
	rc = _sock_flush(sock);
	CU_ASSERT(rc == 0);
@@ -98,7 +98,7 @@ flush(void)
	/* Two requests, where both can fully send. */
	spdk_sock_request_queue(sock, req1);
	spdk_sock_request_queue(sock, req2);
	MOCK_SET(writev, 128);
	MOCK_SET(sendmsg, 128);
	cb_arg1 = false;
	cb_arg2 = false;
	rc = _sock_flush(sock);
@@ -110,7 +110,7 @@ flush(void)
	/* Two requests. Only first one can send */
	spdk_sock_request_queue(sock, req1);
	spdk_sock_request_queue(sock, req2);
	MOCK_SET(writev, 64);
	MOCK_SET(sendmsg, 64);
	cb_arg1 = false;
	cb_arg2 = false;
	rc = _sock_flush(sock);
@@ -123,7 +123,7 @@ flush(void)

	/* One request. Partial send. */
	spdk_sock_request_queue(sock, req1);
	MOCK_SET(writev, 10);
	MOCK_SET(sendmsg, 10);
	cb_arg1 = false;
	rc = _sock_flush(sock);
	CU_ASSERT(rc == 0);
@@ -131,7 +131,7 @@ flush(void)
	CU_ASSERT(TAILQ_FIRST(&sock->queued_reqs) == req1);

	/* Do a second flush that partial sends again. */
	MOCK_SET(writev, 24);
	MOCK_SET(sendmsg, 24);
	cb_arg1 = false;
	rc = _sock_flush(sock);
	CU_ASSERT(rc == 0);
@@ -139,7 +139,7 @@ flush(void)
	CU_ASSERT(TAILQ_FIRST(&sock->queued_reqs) == req1);

	/* Flush the rest of the data */
	MOCK_SET(writev, 30);
	MOCK_SET(sendmsg, 30);
	cb_arg1 = false;
	rc = _sock_flush(sock);
	CU_ASSERT(rc == 0);