From 87cfed8442c4097af35a0368cd040784a5d2ba68 Mon Sep 17 00:00:00 2001 From: zhangduan Date: Mon, 11 Apr 2022 14:35:45 +0800 Subject: [PATCH] sock: Add ack_timeout to spdk_sock_opts Due to the same reason as transport_ack_timeout for RDMA transport, TCP transport also needs ack timeout. This timeout in msec will make TCP socket to wait for ack util closes connection. Signed-off-by: zhangduan Change-Id: I81c0089ac0d4afe4afdd2f2c7e5bff1790f59199 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12214 Community-CI: Mellanox Build Bot Community-CI: Broadcom CI Reviewed-by: Shuhei Matsumoto Reviewed-by: Aleksey Marchuk Tested-by: SPDK CI Jenkins --- CHANGELOG.md | 4 ++++ include/spdk/sock.h | 5 +++++ lib/sock/sock.c | 10 ++++++++++ module/sock/posix/posix.c | 18 ++++++++++++++++++ module/sock/uring/uring.c | 17 +++++++++++++++++ 5 files changed, 54 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92da743d1..c1414d7aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## v22.05: (Upcoming Release) +### sock + +A new option `ack_timeout` was added to the `spdk_sock_opts` structure. + ### util A new parameter `bounce_iovcnt` was added to `spdk_dif_generate_copy` and `spdk_dif_verify_copy`. diff --git a/include/spdk/sock.h b/include/spdk/sock.h index 776bb792e..231bb2d5b 100644 --- a/include/spdk/sock.h +++ b/include/spdk/sock.h @@ -164,6 +164,11 @@ struct spdk_sock_opts { * Used to enable or disable zero copy on socket layer. */ bool zcopy; + + /** + * Time in msec to wait ack until connection is closed forcefully. + */ + uint32_t ack_timeout; }; /** diff --git a/lib/sock/sock.c b/lib/sock/sock.c index 3b8d6d34d..b61c8bd50 100644 --- a/lib/sock/sock.c +++ b/lib/sock/sock.c @@ -42,6 +42,8 @@ #define SPDK_SOCK_DEFAULT_PRIORITY 0 #define SPDK_SOCK_DEFAULT_ZCOPY true +#define SPDK_SOCK_DEFAULT_ACK_TIMEOUT 0 + #define SPDK_SOCK_OPTS_FIELD_OK(opts, field) (offsetof(struct spdk_sock_opts, field) + sizeof(opts->field) <= (opts->opts_size)) static STAILQ_HEAD(, spdk_net_impl) g_net_impls = STAILQ_HEAD_INITIALIZER(g_net_impls); @@ -267,6 +269,10 @@ spdk_sock_get_default_opts(struct spdk_sock_opts *opts) if (SPDK_SOCK_OPTS_FIELD_OK(opts, zcopy)) { opts->zcopy = SPDK_SOCK_DEFAULT_ZCOPY; } + + if (SPDK_SOCK_OPTS_FIELD_OK(opts, ack_timeout)) { + opts->ack_timeout = SPDK_SOCK_DEFAULT_ACK_TIMEOUT; + } } /* @@ -291,6 +297,10 @@ sock_init_opts(struct spdk_sock_opts *opts, struct spdk_sock_opts *opts_user) if (SPDK_SOCK_OPTS_FIELD_OK(opts, zcopy)) { opts->zcopy = opts_user->zcopy; } + + if (SPDK_SOCK_OPTS_FIELD_OK(opts, ack_timeout)) { + opts->ack_timeout = opts_user->ack_timeout; + } } struct spdk_sock * diff --git a/module/sock/posix/posix.c b/module/sock/posix/posix.c index a432dea03..8f06f5337 100644 --- a/module/sock/posix/posix.c +++ b/module/sock/posix/posix.c @@ -366,6 +366,9 @@ posix_fd_create(struct addrinfo *res, struct spdk_sock_opts *opts) int fd; int val = 1; int rc, sz; +#if defined(__linux__) + int to; +#endif fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (fd < 0) { @@ -417,6 +420,21 @@ posix_fd_create(struct addrinfo *res, struct spdk_sock_opts *opts) return -1; } } + + if (opts->ack_timeout) { +#if defined(__linux__) + to = opts->ack_timeout; + rc = setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &to, sizeof(to)); + if (rc != 0) { + close(fd); + /* error */ + return -1; + } +#else + SPDK_WARNLOG("TCP_USER_TIMEOUT is not supported.\n"); +#endif + } + return fd; } diff --git a/module/sock/uring/uring.c b/module/sock/uring/uring.c index 972095006..1237163d9 100644 --- a/module/sock/uring/uring.c +++ b/module/sock/uring/uring.c @@ -457,6 +457,23 @@ retry: continue; } + if (opts->ack_timeout) { +#if defined(__linux__) + val = opts->ack_timeout; + rc = setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &val, sizeof val); + if (rc != 0) { + close(fd); + fd = -1; + /* error */ + continue; + } +#else + SPDK_WARNLOG("TCP_USER_TIMEOUT is not supported.\n"); +#endif + } + + + #if defined(SO_PRIORITY) if (opts != NULL && opts->priority) { rc = setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &opts->priority, sizeof val);