diff --git a/module/sock/posix/posix.c b/module/sock/posix/posix.c index fbc8c9ebd..a673a385d 100644 --- a/module/sock/posix/posix.c +++ b/module/sock/posix/posix.c @@ -93,6 +93,72 @@ posix_sock_map_cleanup(void) #define __posix_sock(sock) (struct spdk_posix_sock *)sock #define __posix_group_impl(group) (struct spdk_posix_sock_group_impl *)group +static int +posix_sock_impl_get_opts(struct spdk_sock_impl_opts *opts, size_t *len) +{ + if (!opts || !len) { + errno = EINVAL; + return -1; + } + memset(opts, 0, *len); + +#define FIELD_OK(field) \ + offsetof(struct spdk_sock_impl_opts, field) + sizeof(opts->field) <= *len + +#define GET_FIELD(field) \ + if (FIELD_OK(field)) { \ + opts->field = g_spdk_posix_sock_impl_opts.field; \ + } + + GET_FIELD(recv_buf_size); + GET_FIELD(send_buf_size); + GET_FIELD(enable_recv_pipe); + GET_FIELD(enable_zerocopy_send); + GET_FIELD(enable_quickack); + GET_FIELD(enable_placement_id); + GET_FIELD(enable_zerocopy_send_server); + GET_FIELD(enable_zerocopy_send_client); + GET_FIELD(zerocopy_threshold); + +#undef GET_FIELD +#undef FIELD_OK + + *len = spdk_min(*len, sizeof(g_spdk_posix_sock_impl_opts)); + return 0; +} + +static int +posix_sock_impl_set_opts(const struct spdk_sock_impl_opts *opts, size_t len) +{ + if (!opts) { + errno = EINVAL; + return -1; + } + +#define FIELD_OK(field) \ + offsetof(struct spdk_sock_impl_opts, field) + sizeof(opts->field) <= len + +#define SET_FIELD(field) \ + if (FIELD_OK(field)) { \ + g_spdk_posix_sock_impl_opts.field = opts->field; \ + } + + SET_FIELD(recv_buf_size); + SET_FIELD(send_buf_size); + SET_FIELD(enable_recv_pipe); + SET_FIELD(enable_zerocopy_send); + SET_FIELD(enable_quickack); + SET_FIELD(enable_placement_id); + SET_FIELD(enable_zerocopy_send_server); + SET_FIELD(enable_zerocopy_send_client); + SET_FIELD(zerocopy_threshold); + +#undef SET_FIELD +#undef FIELD_OK + + return 0; +} + static int posix_sock_getaddr(struct spdk_sock *_sock, char *saddr, int slen, uint16_t *sport, char *caddr, int clen, uint16_t *cport) @@ -1887,73 +1953,6 @@ posix_sock_group_impl_close(struct spdk_sock_group_impl *_group) return rc; } -static int -posix_sock_impl_get_opts(struct spdk_sock_impl_opts *opts, size_t *len) -{ - if (!opts || !len) { - errno = EINVAL; - return -1; - } - memset(opts, 0, *len); - -#define FIELD_OK(field) \ - offsetof(struct spdk_sock_impl_opts, field) + sizeof(opts->field) <= *len - -#define GET_FIELD(field) \ - if (FIELD_OK(field)) { \ - opts->field = g_spdk_posix_sock_impl_opts.field; \ - } - - GET_FIELD(recv_buf_size); - GET_FIELD(send_buf_size); - GET_FIELD(enable_recv_pipe); - GET_FIELD(enable_zerocopy_send); - GET_FIELD(enable_quickack); - GET_FIELD(enable_placement_id); - GET_FIELD(enable_zerocopy_send_server); - GET_FIELD(enable_zerocopy_send_client); - GET_FIELD(zerocopy_threshold); - -#undef GET_FIELD -#undef FIELD_OK - - *len = spdk_min(*len, sizeof(g_spdk_posix_sock_impl_opts)); - return 0; -} - -static int -posix_sock_impl_set_opts(const struct spdk_sock_impl_opts *opts, size_t len) -{ - if (!opts) { - errno = EINVAL; - return -1; - } - -#define FIELD_OK(field) \ - offsetof(struct spdk_sock_impl_opts, field) + sizeof(opts->field) <= len - -#define SET_FIELD(field) \ - if (FIELD_OK(field)) { \ - g_spdk_posix_sock_impl_opts.field = opts->field; \ - } - - SET_FIELD(recv_buf_size); - SET_FIELD(send_buf_size); - SET_FIELD(enable_recv_pipe); - SET_FIELD(enable_zerocopy_send); - SET_FIELD(enable_quickack); - SET_FIELD(enable_placement_id); - SET_FIELD(enable_zerocopy_send_server); - SET_FIELD(enable_zerocopy_send_client); - SET_FIELD(zerocopy_threshold); - -#undef SET_FIELD -#undef FIELD_OK - - return 0; -} - - static struct spdk_net_impl g_posix_net_impl = { .name = "posix", .getaddr = posix_sock_getaddr, diff --git a/module/sock/uring/uring.c b/module/sock/uring/uring.c index 6e6e0ff43..61af09aed 100644 --- a/module/sock/uring/uring.c +++ b/module/sock/uring/uring.c @@ -114,6 +114,70 @@ uring_sock_map_cleanup(void) #define __uring_sock(sock) (struct spdk_uring_sock *)sock #define __uring_group_impl(group) (struct spdk_uring_sock_group_impl *)group +static int +uring_sock_impl_get_opts(struct spdk_sock_impl_opts *opts, size_t *len) +{ + if (!opts || !len) { + errno = EINVAL; + return -1; + } + memset(opts, 0, *len); + +#define FIELD_OK(field) \ + offsetof(struct spdk_sock_impl_opts, field) + sizeof(opts->field) <= *len + +#define GET_FIELD(field) \ + if (FIELD_OK(field)) { \ + opts->field = g_spdk_uring_sock_impl_opts.field; \ + } + + GET_FIELD(recv_buf_size); + GET_FIELD(send_buf_size); + GET_FIELD(enable_recv_pipe); + GET_FIELD(enable_quickack); + GET_FIELD(enable_placement_id); + GET_FIELD(enable_zerocopy_send_server); + GET_FIELD(enable_zerocopy_send_client); + GET_FIELD(zerocopy_threshold); + +#undef GET_FIELD +#undef FIELD_OK + + *len = spdk_min(*len, sizeof(g_spdk_uring_sock_impl_opts)); + return 0; +} + +static int +uring_sock_impl_set_opts(const struct spdk_sock_impl_opts *opts, size_t len) +{ + if (!opts) { + errno = EINVAL; + return -1; + } + +#define FIELD_OK(field) \ + offsetof(struct spdk_sock_impl_opts, field) + sizeof(opts->field) <= len + +#define SET_FIELD(field) \ + if (FIELD_OK(field)) { \ + g_spdk_uring_sock_impl_opts.field = opts->field; \ + } + + SET_FIELD(recv_buf_size); + SET_FIELD(send_buf_size); + SET_FIELD(enable_recv_pipe); + SET_FIELD(enable_quickack); + SET_FIELD(enable_placement_id); + SET_FIELD(enable_zerocopy_send_server); + SET_FIELD(enable_zerocopy_send_client); + SET_FIELD(zerocopy_threshold); + +#undef SET_FIELD +#undef FIELD_OK + + return 0; +} + static int uring_sock_getaddr(struct spdk_sock *_sock, char *saddr, int slen, uint16_t *sport, char *caddr, int clen, uint16_t *cport) @@ -1546,70 +1610,6 @@ uring_sock_group_impl_close(struct spdk_sock_group_impl *_group) return 0; } -static int -uring_sock_impl_get_opts(struct spdk_sock_impl_opts *opts, size_t *len) -{ - if (!opts || !len) { - errno = EINVAL; - return -1; - } - memset(opts, 0, *len); - -#define FIELD_OK(field) \ - offsetof(struct spdk_sock_impl_opts, field) + sizeof(opts->field) <= *len - -#define GET_FIELD(field) \ - if (FIELD_OK(field)) { \ - opts->field = g_spdk_uring_sock_impl_opts.field; \ - } - - GET_FIELD(recv_buf_size); - GET_FIELD(send_buf_size); - GET_FIELD(enable_recv_pipe); - GET_FIELD(enable_quickack); - GET_FIELD(enable_placement_id); - GET_FIELD(enable_zerocopy_send_server); - GET_FIELD(enable_zerocopy_send_client); - GET_FIELD(zerocopy_threshold); - -#undef GET_FIELD -#undef FIELD_OK - - *len = spdk_min(*len, sizeof(g_spdk_uring_sock_impl_opts)); - return 0; -} - -static int -uring_sock_impl_set_opts(const struct spdk_sock_impl_opts *opts, size_t len) -{ - if (!opts) { - errno = EINVAL; - return -1; - } - -#define FIELD_OK(field) \ - offsetof(struct spdk_sock_impl_opts, field) + sizeof(opts->field) <= len - -#define SET_FIELD(field) \ - if (FIELD_OK(field)) { \ - g_spdk_uring_sock_impl_opts.field = opts->field; \ - } - - SET_FIELD(recv_buf_size); - SET_FIELD(send_buf_size); - SET_FIELD(enable_recv_pipe); - SET_FIELD(enable_quickack); - SET_FIELD(enable_placement_id); - SET_FIELD(enable_zerocopy_send_server); - SET_FIELD(enable_zerocopy_send_client); - SET_FIELD(zerocopy_threshold); - -#undef SET_FIELD -#undef FIELD_OK - - return 0; -} - static int uring_sock_flush(struct spdk_sock *_sock) {