From e61b0904a839791c9190c6934be28470ec8f8d86 Mon Sep 17 00:00:00 2001 From: Or Gerlitz Date: Thu, 21 Nov 2019 17:16:18 +0200 Subject: [PATCH] sock/posix: Add flush Initiator drivers (e.g nvme/tcp) don't use poll groups but rather directly poll the qpair. In this case we want to allow the polling function (e.g _qpair_process_completions()) to flush async writes pending on the socket. Signed-off-by: Or Gerlitz Change-Id: Ibd8c73691213d58e287b7110d0f5a381a89a64d0 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/475419 Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Tested-by: SPDK CI Jenkins --- include/spdk/sock.h | 9 +++++++++ include/spdk_internal/sock.h | 1 + lib/sock/sock.c | 6 ++++++ module/sock/posix/posix.c | 7 +++++++ test/common/lib/test_sock.c | 1 + 5 files changed, 24 insertions(+) diff --git a/include/spdk/sock.h b/include/spdk/sock.h index 4d36f35f4..2ef68449e 100644 --- a/include/spdk/sock.h +++ b/include/spdk/sock.h @@ -146,6 +146,15 @@ struct spdk_sock *spdk_sock_accept(struct spdk_sock *sock); */ int spdk_sock_close(struct spdk_sock **sock); +/** + * Flush a socket from data gathered in previous writev_async calls. + * + * \param sock Socket to flush. + * + * \return 0 on success, -1 on failure. + */ +int spdk_sock_flush(struct spdk_sock *sock); + /** * Receive a message from the given socket. * diff --git a/include/spdk_internal/sock.h b/include/spdk_internal/sock.h index 2087ea789..5693a6ebc 100644 --- a/include/spdk_internal/sock.h +++ b/include/spdk_internal/sock.h @@ -94,6 +94,7 @@ struct spdk_net_impl { ssize_t (*writev)(struct spdk_sock *sock, struct iovec *iov, int iovcnt); void (*writev_async)(struct spdk_sock *sock, struct spdk_sock_request *req); + int (*flush)(struct spdk_sock *sock); int (*set_recvlowat)(struct spdk_sock *sock, int nbytes); int (*set_recvbuf)(struct spdk_sock *sock, int sz); diff --git a/lib/sock/sock.c b/lib/sock/sock.c index dcb1d2bd9..0f913d7d4 100644 --- a/lib/sock/sock.c +++ b/lib/sock/sock.c @@ -329,6 +329,12 @@ spdk_sock_writev_async(struct spdk_sock *sock, struct spdk_sock_request *req) sock->net_impl->writev_async(sock, req); } +int +spdk_sock_flush(struct spdk_sock *sock) +{ + return sock->net_impl->flush(sock); +} + int spdk_sock_set_recvlowat(struct spdk_sock *sock, int nbytes) { diff --git a/module/sock/posix/posix.c b/module/sock/posix/posix.c index bb3805867..5366b48d5 100644 --- a/module/sock/posix/posix.c +++ b/module/sock/posix/posix.c @@ -545,6 +545,12 @@ _sock_flush(struct spdk_sock *sock) return 0; } +static int +spdk_posix_sock_flush(struct spdk_sock *_sock) +{ + return _sock_flush(_sock); +} + static ssize_t spdk_posix_sock_recv(struct spdk_sock *_sock, void *buf, size_t len) { @@ -870,6 +876,7 @@ static struct spdk_net_impl g_posix_net_impl = { .readv = spdk_posix_sock_readv, .writev = spdk_posix_sock_writev, .writev_async = spdk_posix_sock_writev_async, + .flush = spdk_posix_sock_flush, .set_recvlowat = spdk_posix_sock_set_recvlowat, .set_recvbuf = spdk_posix_sock_set_recvbuf, .set_sendbuf = spdk_posix_sock_set_sendbuf, diff --git a/test/common/lib/test_sock.c b/test/common/lib/test_sock.c index 3a67fd08d..8b0b35818 100644 --- a/test/common/lib/test_sock.c +++ b/test/common/lib/test_sock.c @@ -51,6 +51,7 @@ DEFINE_STUB(spdk_sock_set_recvlowat, int, (struct spdk_sock *sock, int nbytes), DEFINE_STUB(spdk_sock_set_recvbuf, int, (struct spdk_sock *sock, int sz), 0); DEFINE_STUB(spdk_sock_set_sendbuf, int, (struct spdk_sock *sock, int sz), 0); DEFINE_STUB_V(spdk_sock_writev_async, (struct spdk_sock *sock, struct spdk_sock_request *req)); +DEFINE_STUB(spdk_sock_flush, int, (struct spdk_sock *sock), 0); DEFINE_STUB(spdk_sock_is_ipv6, bool, (struct spdk_sock *sock), false); DEFINE_STUB(spdk_sock_is_ipv4, bool, (struct spdk_sock *sock), true); DEFINE_STUB(spdk_sock_is_connected, bool, (struct spdk_sock *sock), true);