sock/posix: Use sendmsg instead of writev when flushing
This is preparation to add flags to the call. Change-Id: I36109c069b42bd3ec22e023079c62d41a435f44c Signed-off-by: Ben Walker <benjamin.walker@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/471771 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Community-CI: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
ab22d249e2
commit
7db1ed8b67
@ -438,6 +438,8 @@ static int
|
|||||||
_sock_flush(struct spdk_sock *sock)
|
_sock_flush(struct spdk_sock *sock)
|
||||||
{
|
{
|
||||||
struct spdk_posix_sock *psock = __posix_sock(sock);
|
struct spdk_posix_sock *psock = __posix_sock(sock);
|
||||||
|
struct msghdr msg = {};
|
||||||
|
int flags;
|
||||||
struct iovec iovs[IOV_BATCH_SIZE];
|
struct iovec iovs[IOV_BATCH_SIZE];
|
||||||
int iovcnt;
|
int iovcnt;
|
||||||
int retval;
|
int retval;
|
||||||
@ -488,7 +490,10 @@ _sock_flush(struct spdk_sock *sock)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Perform the vectored write */
|
/* 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 (rc <= 0) {
|
||||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -526,7 +531,7 @@ _sock_flush(struct spdk_sock *sock)
|
|||||||
req->internal.offset = 0;
|
req->internal.offset = 0;
|
||||||
spdk_sock_request_pend(sock, req);
|
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. */
|
* so it's already done. */
|
||||||
retval = spdk_sock_request_put(sock, req, 0);
|
retval = spdk_sock_request_put(sock, req, 0);
|
||||||
|
|
||||||
|
@ -86,9 +86,9 @@ flush(void)
|
|||||||
req2->cb_arg = &cb_arg2;
|
req2->cb_arg = &cb_arg2;
|
||||||
|
|
||||||
/* Simple test - a request with a 2 element iovec
|
/* 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);
|
spdk_sock_request_queue(sock, req1);
|
||||||
MOCK_SET(writev, 64);
|
MOCK_SET(sendmsg, 64);
|
||||||
cb_arg1 = false;
|
cb_arg1 = false;
|
||||||
rc = _sock_flush(sock);
|
rc = _sock_flush(sock);
|
||||||
CU_ASSERT(rc == 0);
|
CU_ASSERT(rc == 0);
|
||||||
@ -98,7 +98,7 @@ flush(void)
|
|||||||
/* Two requests, where both can fully send. */
|
/* Two requests, where both can fully send. */
|
||||||
spdk_sock_request_queue(sock, req1);
|
spdk_sock_request_queue(sock, req1);
|
||||||
spdk_sock_request_queue(sock, req2);
|
spdk_sock_request_queue(sock, req2);
|
||||||
MOCK_SET(writev, 128);
|
MOCK_SET(sendmsg, 128);
|
||||||
cb_arg1 = false;
|
cb_arg1 = false;
|
||||||
cb_arg2 = false;
|
cb_arg2 = false;
|
||||||
rc = _sock_flush(sock);
|
rc = _sock_flush(sock);
|
||||||
@ -110,7 +110,7 @@ flush(void)
|
|||||||
/* Two requests. Only first one can send */
|
/* Two requests. Only first one can send */
|
||||||
spdk_sock_request_queue(sock, req1);
|
spdk_sock_request_queue(sock, req1);
|
||||||
spdk_sock_request_queue(sock, req2);
|
spdk_sock_request_queue(sock, req2);
|
||||||
MOCK_SET(writev, 64);
|
MOCK_SET(sendmsg, 64);
|
||||||
cb_arg1 = false;
|
cb_arg1 = false;
|
||||||
cb_arg2 = false;
|
cb_arg2 = false;
|
||||||
rc = _sock_flush(sock);
|
rc = _sock_flush(sock);
|
||||||
@ -123,7 +123,7 @@ flush(void)
|
|||||||
|
|
||||||
/* One request. Partial send. */
|
/* One request. Partial send. */
|
||||||
spdk_sock_request_queue(sock, req1);
|
spdk_sock_request_queue(sock, req1);
|
||||||
MOCK_SET(writev, 10);
|
MOCK_SET(sendmsg, 10);
|
||||||
cb_arg1 = false;
|
cb_arg1 = false;
|
||||||
rc = _sock_flush(sock);
|
rc = _sock_flush(sock);
|
||||||
CU_ASSERT(rc == 0);
|
CU_ASSERT(rc == 0);
|
||||||
@ -131,7 +131,7 @@ flush(void)
|
|||||||
CU_ASSERT(TAILQ_FIRST(&sock->queued_reqs) == req1);
|
CU_ASSERT(TAILQ_FIRST(&sock->queued_reqs) == req1);
|
||||||
|
|
||||||
/* Do a second flush that partial sends again. */
|
/* Do a second flush that partial sends again. */
|
||||||
MOCK_SET(writev, 24);
|
MOCK_SET(sendmsg, 24);
|
||||||
cb_arg1 = false;
|
cb_arg1 = false;
|
||||||
rc = _sock_flush(sock);
|
rc = _sock_flush(sock);
|
||||||
CU_ASSERT(rc == 0);
|
CU_ASSERT(rc == 0);
|
||||||
@ -139,7 +139,7 @@ flush(void)
|
|||||||
CU_ASSERT(TAILQ_FIRST(&sock->queued_reqs) == req1);
|
CU_ASSERT(TAILQ_FIRST(&sock->queued_reqs) == req1);
|
||||||
|
|
||||||
/* Flush the rest of the data */
|
/* Flush the rest of the data */
|
||||||
MOCK_SET(writev, 30);
|
MOCK_SET(sendmsg, 30);
|
||||||
cb_arg1 = false;
|
cb_arg1 = false;
|
||||||
rc = _sock_flush(sock);
|
rc = _sock_flush(sock);
|
||||||
CU_ASSERT(rc == 0);
|
CU_ASSERT(rc == 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user