diff --git a/CHANGELOG.md b/CHANGELOG.md index f1a54aa21d..fb03866adb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,11 @@ Two providers are available - verbs (used by default when RDMA is enabled or ena using --with-rdma=verbs) and mlx5 Direct Verbs aka DV (enabled by --with-rdma=mlx5_dv). Using mlx5_dv requires libmlx5 installed on the system. +### sock + +Added `spdk_sock_impl_get_opts` and `spdk_sock_impl_set_opts` functions to set/get socket layer configuration +options. Options can be set independently for each implementation. + ## v20.04: IDXD engine support for compare has been added. diff --git a/include/spdk/sock.h b/include/spdk/sock.h index 65299f62e6..a95743d382 100644 --- a/include/spdk/sock.h +++ b/include/spdk/sock.h @@ -1,8 +1,8 @@ /*- * BSD LICENSE * - * Copyright (c) Intel Corporation. - * All rights reserved. + * Copyright (c) Intel Corporation. All rights reserved. + * Copyright (c) 2020 Mellanox Technologies LTD. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -79,6 +79,15 @@ struct spdk_sock_request { #define SPDK_SOCK_REQUEST_IOV(req, i) ((struct iovec *)(((uint8_t *)req + sizeof(struct spdk_sock_request)) + (sizeof(struct iovec) * i))) +/** + * SPDK socket implementation options. + * + * A pointer to this structure is used by spdk_sock_impl_get_opts() and spdk_sock_impl_set_opts() + * to allow the user to request options for the socket module implementation. + * Each socket module defines which options from this structure are applicable to the module. + */ +struct spdk_sock_impl_opts; + /** * Spdk socket initialization options. * @@ -408,6 +417,29 @@ int spdk_sock_group_close(struct spdk_sock_group **group); */ int spdk_sock_get_optimal_sock_group(struct spdk_sock *sock, struct spdk_sock_group **group); +/** + * Get current socket implementation options. + * + * \param impl_name The socket implementation to use, such as "posix". + * \param opts Pointer to allocated spdk_sock_impl_opts structure that will be filled with actual values. + * \param len On input specifies size of passed opts structure. On return it is set to actual size that was filled with values. + * + * \return 0 on success, -1 on failure. errno is set to indicate the reason of failure. + */ +int spdk_sock_impl_get_opts(const char *impl_name, struct spdk_sock_impl_opts *opts, size_t *len); + +/** + * Set socket implementation options. + * + * \param impl_name The socket implementation to use, such as "posix". + * \param opts Pointer to allocated spdk_sock_impl_opts structure with new options values. + * \param len Size of passed opts structure. + * + * \return 0 on success, -1 on failure. errno is set to indicate the reason of failure. + */ +int spdk_sock_impl_set_opts(const char *impl_name, const struct spdk_sock_impl_opts *opts, + size_t len); + #ifdef __cplusplus } #endif diff --git a/include/spdk_internal/sock.h b/include/spdk_internal/sock.h index 498f2840fe..c3effdd7d3 100644 --- a/include/spdk_internal/sock.h +++ b/include/spdk_internal/sock.h @@ -1,8 +1,8 @@ /*- * BSD LICENSE * - * Copyright (c) Intel Corporation. - * All rights reserved. + * Copyright (c) Intel Corporation. All rights reserved. + * Copyright (c) 2020 Mellanox Technologies LTD. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -119,6 +119,9 @@ struct spdk_net_impl { struct spdk_sock **socks); int (*group_impl_close)(struct spdk_sock_group_impl *group); + int (*get_opts)(struct spdk_sock_impl_opts *opts, size_t *len); + int (*set_opts)(const struct spdk_sock_impl_opts *opts, size_t len); + STAILQ_ENTRY(spdk_net_impl) link; }; diff --git a/lib/sock/Makefile b/lib/sock/Makefile index 553665f73d..38bf801753 100644 --- a/lib/sock/Makefile +++ b/lib/sock/Makefile @@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk SO_VER := 3 -SO_MINOR := 0 +SO_MINOR := 1 C_SRCS = sock.c net_framework.c diff --git a/lib/sock/sock.c b/lib/sock/sock.c index bdc9dc7841..096cefd9ae 100644 --- a/lib/sock/sock.c +++ b/lib/sock/sock.c @@ -1,8 +1,8 @@ /*- * BSD LICENSE * - * Copyright (c) Intel Corporation. - * All rights reserved. + * Copyright (c) Intel Corporation. All rights reserved. + * Copyright (c) 2020 Mellanox Technologies LTD. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -688,6 +688,69 @@ spdk_sock_group_close(struct spdk_sock_group **group) return 0; } +static inline struct spdk_net_impl * +sock_get_impl_by_name(const char *impl_name) +{ + struct spdk_net_impl *impl; + + assert(impl_name != NULL); + STAILQ_FOREACH(impl, &g_net_impls, link) { + if (0 == strcmp(impl_name, impl->name)) { + return impl; + } + } + + return NULL; +} + +int +spdk_sock_impl_get_opts(const char *impl_name, struct spdk_sock_impl_opts *opts, size_t *len) +{ + struct spdk_net_impl *impl; + + if (!impl_name || !opts || !len) { + errno = EINVAL; + return -1; + } + + impl = sock_get_impl_by_name(impl_name); + if (!impl) { + errno = EINVAL; + return -1; + } + + if (!impl->get_opts) { + errno = ENOTSUP; + return -1; + } + + return impl->get_opts(opts, len); +} + +int +spdk_sock_impl_set_opts(const char *impl_name, const struct spdk_sock_impl_opts *opts, size_t len) +{ + struct spdk_net_impl *impl; + + if (!impl_name || !opts) { + errno = EINVAL; + return -1; + } + + impl = sock_get_impl_by_name(impl_name); + if (!impl) { + errno = EINVAL; + return -1; + } + + if (!impl->set_opts) { + errno = ENOTSUP; + return -1; + } + + return impl->set_opts(opts, len); +} + void spdk_net_impl_register(struct spdk_net_impl *impl, int priority) { diff --git a/lib/sock/spdk_sock.map b/lib/sock/spdk_sock.map index 29d18c27fc..20d6fd93b7 100644 --- a/lib/sock/spdk_sock.map +++ b/lib/sock/spdk_sock.map @@ -29,6 +29,8 @@ spdk_sock_group_poll_count; spdk_sock_group_close; spdk_sock_get_optimal_sock_group; + spdk_sock_impl_get_opts; + spdk_sock_impl_set_opts; # public functions in spdk/net.h spdk_net_framework_register;