sock: store impl_opts in socket structure
It'll make it possible to change some of the impl_opts options on a per-socket basis, as well as make it easier to use fields common to all implementations in the generic layer. Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com> Change-Id: Id3b5e0a0b302fdecc2387d07fb87b75b487dc5c5 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13659 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Community-CI: Mellanox Build Bot Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
36589e1e44
commit
50afaf1ee8
@ -44,6 +44,7 @@ struct spdk_sock {
|
|||||||
uint8_t closed : 1;
|
uint8_t closed : 1;
|
||||||
uint8_t reserved : 7;
|
uint8_t reserved : 7;
|
||||||
} flags;
|
} flags;
|
||||||
|
struct spdk_sock_impl_opts impl_opts;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct spdk_sock_group {
|
struct spdk_sock_group {
|
||||||
|
@ -298,7 +298,7 @@ posix_sock_set_recvbuf(struct spdk_sock *_sock, int sz)
|
|||||||
|
|
||||||
assert(sock != NULL);
|
assert(sock != NULL);
|
||||||
|
|
||||||
if (g_spdk_posix_sock_impl_opts.enable_recv_pipe) {
|
if (_sock->impl_opts.enable_recv_pipe) {
|
||||||
rc = posix_sock_alloc_pipe(sock, sz);
|
rc = posix_sock_alloc_pipe(sock, sz);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
return rc;
|
return rc;
|
||||||
@ -315,6 +315,8 @@ posix_sock_set_recvbuf(struct spdk_sock *_sock, int sz)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_sock->impl_opts.recv_buf_size = sz;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,6 +337,8 @@ posix_sock_set_sendbuf(struct spdk_sock *_sock, int sz)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_sock->impl_opts.send_buf_size = sz;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,17 +365,17 @@ posix_sock_init(struct spdk_posix_sock *sock, bool enable_zero_copy)
|
|||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
flag = 1;
|
flag = 1;
|
||||||
|
|
||||||
if (g_spdk_posix_sock_impl_opts.enable_quickack) {
|
if (sock->base.impl_opts.enable_quickack) {
|
||||||
rc = setsockopt(sock->fd, IPPROTO_TCP, TCP_QUICKACK, &flag, sizeof(flag));
|
rc = setsockopt(sock->fd, IPPROTO_TCP, TCP_QUICKACK, &flag, sizeof(flag));
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
SPDK_ERRLOG("quickack was failed to set\n");
|
SPDK_ERRLOG("quickack was failed to set\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spdk_sock_get_placement_id(sock->fd, g_spdk_posix_sock_impl_opts.enable_placement_id,
|
spdk_sock_get_placement_id(sock->fd, sock->base.impl_opts.enable_placement_id,
|
||||||
&sock->placement_id);
|
&sock->placement_id);
|
||||||
|
|
||||||
if (g_spdk_posix_sock_impl_opts.enable_placement_id == PLACEMENT_MARK) {
|
if (sock->base.impl_opts.enable_placement_id == PLACEMENT_MARK) {
|
||||||
/* Save placement_id */
|
/* Save placement_id */
|
||||||
spdk_sock_map_insert(&g_map, sock->placement_id, NULL);
|
spdk_sock_map_insert(&g_map, sock->placement_id, NULL);
|
||||||
}
|
}
|
||||||
@ -379,7 +383,7 @@ posix_sock_init(struct spdk_posix_sock *sock, bool enable_zero_copy)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct spdk_posix_sock *
|
static struct spdk_posix_sock *
|
||||||
posix_sock_alloc(int fd, bool enable_zero_copy)
|
posix_sock_alloc(int fd, struct spdk_sock_impl_opts *impl_opts, bool enable_zero_copy)
|
||||||
{
|
{
|
||||||
struct spdk_posix_sock *sock;
|
struct spdk_posix_sock *sock;
|
||||||
|
|
||||||
@ -390,6 +394,7 @@ posix_sock_alloc(int fd, bool enable_zero_copy)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sock->fd = fd;
|
sock->fd = fd;
|
||||||
|
memcpy(&sock->base.impl_opts, impl_opts, sizeof(*impl_opts));
|
||||||
posix_sock_init(sock, enable_zero_copy);
|
posix_sock_init(sock, enable_zero_copy);
|
||||||
|
|
||||||
return sock;
|
return sock;
|
||||||
@ -934,7 +939,8 @@ retry:
|
|||||||
/* Only enable zero copy for non-loopback and non-ssl sockets. */
|
/* Only enable zero copy for non-loopback and non-ssl sockets. */
|
||||||
enable_zcopy_user_opts = opts->zcopy && !sock_is_loopback(fd) && !enable_ssl;
|
enable_zcopy_user_opts = opts->zcopy && !sock_is_loopback(fd) && !enable_ssl;
|
||||||
|
|
||||||
sock = posix_sock_alloc(fd, enable_zcopy_user_opts && enable_zcopy_impl_opts);
|
sock = posix_sock_alloc(fd, &g_spdk_posix_sock_impl_opts,
|
||||||
|
enable_zcopy_user_opts && enable_zcopy_impl_opts);
|
||||||
if (sock == NULL) {
|
if (sock == NULL) {
|
||||||
SPDK_ERRLOG("sock allocation failed\n");
|
SPDK_ERRLOG("sock allocation failed\n");
|
||||||
close(fd);
|
close(fd);
|
||||||
@ -1018,7 +1024,7 @@ posix_sock_accept(struct spdk_sock *_sock)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Inherit the zero copy feature from the listen socket */
|
/* Inherit the zero copy feature from the listen socket */
|
||||||
new_sock = posix_sock_alloc(fd, sock->zcopy);
|
new_sock = posix_sock_alloc(fd, &sock->base.impl_opts, sock->zcopy);
|
||||||
if (new_sock == NULL) {
|
if (new_sock == NULL) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -318,7 +318,7 @@ uring_sock_set_recvbuf(struct spdk_sock *_sock, int sz)
|
|||||||
|
|
||||||
assert(sock != NULL);
|
assert(sock != NULL);
|
||||||
|
|
||||||
if (g_spdk_uring_sock_impl_opts.enable_recv_pipe) {
|
if (_sock->impl_opts.enable_recv_pipe) {
|
||||||
rc = uring_sock_alloc_pipe(sock, sz);
|
rc = uring_sock_alloc_pipe(sock, sz);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
SPDK_ERRLOG("unable to allocate sufficient recvbuf with sz=%d on sock=%p\n", sz, _sock);
|
SPDK_ERRLOG("unable to allocate sufficient recvbuf with sz=%d on sock=%p\n", sz, _sock);
|
||||||
@ -335,6 +335,8 @@ uring_sock_set_recvbuf(struct spdk_sock *_sock, int sz)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_sock->impl_opts.recv_buf_size = sz;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,11 +357,13 @@ uring_sock_set_sendbuf(struct spdk_sock *_sock, int sz)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_sock->impl_opts.send_buf_size = sz;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct spdk_uring_sock *
|
static struct spdk_uring_sock *
|
||||||
uring_sock_alloc(int fd, bool enable_zero_copy)
|
uring_sock_alloc(int fd, struct spdk_sock_impl_opts *impl_opts, bool enable_zero_copy)
|
||||||
{
|
{
|
||||||
struct spdk_uring_sock *sock;
|
struct spdk_uring_sock *sock;
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
@ -374,18 +378,19 @@ uring_sock_alloc(int fd, bool enable_zero_copy)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sock->fd = fd;
|
sock->fd = fd;
|
||||||
|
memcpy(&sock->base.impl_opts, impl_opts, sizeof(*impl_opts));
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
flag = 1;
|
flag = 1;
|
||||||
|
|
||||||
if (g_spdk_uring_sock_impl_opts.enable_quickack) {
|
if (sock->base.impl_opts.enable_quickack) {
|
||||||
rc = setsockopt(sock->fd, IPPROTO_TCP, TCP_QUICKACK, &flag, sizeof(flag));
|
rc = setsockopt(sock->fd, IPPROTO_TCP, TCP_QUICKACK, &flag, sizeof(flag));
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
SPDK_ERRLOG("quickack was failed to set\n");
|
SPDK_ERRLOG("quickack was failed to set\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spdk_sock_get_placement_id(sock->fd, g_spdk_uring_sock_impl_opts.enable_placement_id,
|
spdk_sock_get_placement_id(sock->fd, sock->base.impl_opts.enable_placement_id,
|
||||||
&sock->placement_id);
|
&sock->placement_id);
|
||||||
#ifdef SPDK_ZEROCOPY
|
#ifdef SPDK_ZEROCOPY
|
||||||
/* Try to turn on zero copy sends */
|
/* Try to turn on zero copy sends */
|
||||||
@ -591,7 +596,8 @@ retry:
|
|||||||
}
|
}
|
||||||
|
|
||||||
enable_zcopy_user_opts = opts->zcopy && !sock_is_loopback(fd);
|
enable_zcopy_user_opts = opts->zcopy && !sock_is_loopback(fd);
|
||||||
sock = uring_sock_alloc(fd, enable_zcopy_user_opts && enable_zcopy_impl_opts);
|
sock = uring_sock_alloc(fd, &g_spdk_uring_sock_impl_opts,
|
||||||
|
enable_zcopy_user_opts && enable_zcopy_impl_opts);
|
||||||
if (sock == NULL) {
|
if (sock == NULL) {
|
||||||
SPDK_ERRLOG("sock allocation failed\n");
|
SPDK_ERRLOG("sock allocation failed\n");
|
||||||
close(fd);
|
close(fd);
|
||||||
@ -654,7 +660,7 @@ uring_sock_accept(struct spdk_sock *_sock)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
new_sock = uring_sock_alloc(fd, sock->zcopy);
|
new_sock = uring_sock_alloc(fd, &sock->base.impl_opts, sock->zcopy);
|
||||||
if (new_sock == NULL) {
|
if (new_sock == NULL) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user