diff --git a/include/spdk/sock.h b/include/spdk/sock.h index a51ba8706..389fea904 100644 --- a/include/spdk/sock.h +++ b/include/spdk/sock.h @@ -138,6 +138,11 @@ struct spdk_sock_opts { * The priority on the socket and default value is zero. */ int priority; + + /** + * Used to enable or disable zero copy on socket layer. + */ + bool zcopy; }; /** diff --git a/lib/sock/sock.c b/lib/sock/sock.c index 6c407c71e..cfa324628 100644 --- a/lib/sock/sock.c +++ b/lib/sock/sock.c @@ -39,6 +39,7 @@ #include "spdk/queue.h" #define SPDK_SOCK_DEFAULT_PRIORITY 0 +#define SPDK_SOCK_DEFAULT_ZCOPY true #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); @@ -191,6 +192,10 @@ spdk_sock_get_default_opts(struct spdk_sock_opts *opts) if (SPDK_SOCK_OPTS_FIELD_OK(opts, priority)) { opts->priority = SPDK_SOCK_DEFAULT_PRIORITY; } + + if (SPDK_SOCK_OPTS_FIELD_OK(opts, zcopy)) { + opts->zcopy = SPDK_SOCK_DEFAULT_ZCOPY; + } } /* @@ -211,6 +216,10 @@ sock_init_opts(struct spdk_sock_opts *opts, struct spdk_sock_opts *opts_user) if (SPDK_SOCK_OPTS_FIELD_OK(opts, priority)) { opts->priority = opts_user->priority; } + + if (SPDK_SOCK_OPTS_FIELD_OK(opts, zcopy)) { + opts->zcopy = opts_user->zcopy; + } } struct spdk_sock * diff --git a/module/sock/posix/posix.c b/module/sock/posix/posix.c index 78a146cc7..5c4cfa095 100644 --- a/module/sock/posix/posix.c +++ b/module/sock/posix/posix.c @@ -556,7 +556,7 @@ retry: if (type == SPDK_SOCK_CREATE_LISTEN) { /* Only enable zero copy for non-loopback sockets. */ - enable_zero_copy = !sock_is_loopback(fd); + enable_zero_copy = opts->zcopy && !sock_is_loopback(fd); } else if (type == SPDK_SOCK_CREATE_CONNECT) { /* Disable zero copy for client sockets until support is added */ enable_zero_copy = false;