Commit 030bbebe authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

sock: extract copying impl_opts to a function



Both get_opts and set_opts use very similar macros to achieve almost the
same thing, so it makes sense to extract it to a separate function.
Additionally, it'll be also useful in subsequent patches introducing
per-sock impl_opts, as there will be more places when we want to copy
impl_opts.

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I8ab27298d62ea0118463ee945c708acd91aa5104
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13658


Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
parent 38f82ecf
Loading
Loading
Loading
Loading
+29 −41
Original line number Diff line number Diff line
@@ -93,37 +93,44 @@ 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)
static void
posix_sock_copy_impl_opts(struct spdk_sock_impl_opts *dest, const struct spdk_sock_impl_opts *src,
			  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
	offsetof(struct spdk_sock_impl_opts, field) + sizeof(src->field) <= len

#define GET_FIELD(field) \
#define SET_FIELD(field) \
	if (FIELD_OK(field)) { \
		opts->field = g_spdk_posix_sock_impl_opts.field; \
		dest->field = src->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);
	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 GET_FIELD
#undef SET_FIELD
#undef FIELD_OK
}

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);

	posix_sock_copy_impl_opts(opts, &g_spdk_posix_sock_impl_opts, *len);
	*len = spdk_min(*len, sizeof(g_spdk_posix_sock_impl_opts));

	return 0;
}

@@ -135,26 +142,7 @@ posix_sock_impl_set_opts(const struct spdk_sock_impl_opts *opts, size_t len)
		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
	posix_sock_copy_impl_opts(&g_spdk_posix_sock_impl_opts, opts, len);

	return 0;
}
+28 −39
Original line number Diff line number Diff line
@@ -114,36 +114,43 @@ 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)
static void
uring_sock_copy_impl_opts(struct spdk_sock_impl_opts *dest, const struct spdk_sock_impl_opts *src,
			  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
	offsetof(struct spdk_sock_impl_opts, field) + sizeof(src->field) <= len

#define GET_FIELD(field) \
#define SET_FIELD(field) \
	if (FIELD_OK(field)) { \
		opts->field = g_spdk_uring_sock_impl_opts.field; \
		dest->field = src->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);
	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 GET_FIELD
#undef SET_FIELD
#undef FIELD_OK
}

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);

	uring_sock_copy_impl_opts(opts, &g_spdk_uring_sock_impl_opts, *len);
	*len = spdk_min(*len, sizeof(g_spdk_uring_sock_impl_opts));

	return 0;
}

@@ -155,25 +162,7 @@ uring_sock_impl_set_opts(const struct spdk_sock_impl_opts *opts, size_t len)
		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
	uring_sock_copy_impl_opts(&g_spdk_uring_sock_impl_opts, opts, len);

	return 0;
}