sock: Use an enum for placement modes

Easier to read than integers.

Signed-off-by: Ben Walker <benjamin.walker@intel.com>
Change-Id: Ie9b8b16e1916b393a257e9ed0180ef9837f20cd2
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7205
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Community-CI: Mellanox Build Bot
This commit is contained in:
Ben Walker 2021-03-29 12:34:51 -07:00 committed by Jim Harris
parent 0254ef6d2b
commit 28b3889c8e
4 changed files with 18 additions and 11 deletions

View File

@ -80,6 +80,12 @@ 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)))
enum spdk_placement_mode {
PLACEMENT_NONE,
PLACEMENT_NAPI,
PLACEMENT_CPU,
};
/**
* SPDK socket implementation options.
*
@ -115,6 +121,7 @@ struct spdk_sock_impl_opts {
/**
* Enable or disable placement_id. Used by posix and uring socket modules.
* Valid values in the enum spdk_placement_mode.
*/
uint32_t enable_placement_id;

View File

@ -489,7 +489,7 @@ spdk_sock_group_create(void *ctx)
struct spdk_sock_group_impl *group_impl;
struct spdk_sock_impl_opts sock_opts = {};
size_t sock_len;
bool enable_incoming_cpu = 0;
bool enable_incoming_cpu = false;
group = calloc(1, sizeof(*group));
if (group == NULL) {
@ -507,8 +507,8 @@ spdk_sock_group_create(void *ctx)
sock_len = sizeof(sock_opts);
spdk_sock_impl_get_opts(impl->name, &sock_opts, &sock_len);
if (sock_opts.enable_placement_id == 2) {
enable_incoming_cpu = 1;
if (sock_opts.enable_placement_id == PLACEMENT_CPU) {
enable_incoming_cpu = true;
}
}
}

View File

@ -86,7 +86,7 @@ static struct spdk_sock_impl_opts g_spdk_posix_sock_impl_opts = {
.enable_recv_pipe = true,
.enable_zerocopy_send = true,
.enable_quickack = false,
.enable_placement_id = 0,
.enable_placement_id = PLACEMENT_NONE,
};
static int
@ -1115,9 +1115,9 @@ posix_sock_get_placement_id(struct spdk_sock *_sock, int *placement_id)
return rc;
}
if (g_spdk_posix_sock_impl_opts.enable_placement_id != 0) {
if (g_spdk_posix_sock_impl_opts.enable_placement_id != PLACEMENT_NONE) {
switch (g_spdk_posix_sock_impl_opts.enable_placement_id) {
case 1: {
case PLACEMENT_NAPI: {
#if defined(SO_INCOMING_NAPI_ID)
struct spdk_posix_sock *sock = __posix_sock(_sock);
socklen_t len = sizeof(int);
@ -1126,7 +1126,7 @@ posix_sock_get_placement_id(struct spdk_sock *_sock, int *placement_id)
#endif
break;
}
case 2: {
case PLACEMENT_CPU: {
#if defined(SO_INCOMING_CPU)
struct spdk_posix_sock *sock = __posix_sock(_sock);
socklen_t len = sizeof(int);

View File

@ -102,7 +102,7 @@ static struct spdk_sock_impl_opts g_spdk_uring_sock_impl_opts = {
.send_buf_size = MIN_SO_SNDBUF_SIZE,
.enable_recv_pipe = true,
.enable_quickack = false,
.enable_placement_id = 0,
.enable_placement_id = PLACEMENT_NONE,
};
#define SPDK_URING_SOCK_REQUEST_IOV(req) ((struct iovec *)((uint8_t *)req + sizeof(struct spdk_sock_request)))
@ -1098,9 +1098,9 @@ uring_sock_get_placement_id(struct spdk_sock *_sock, int *placement_id)
return rc;
}
if (g_spdk_uring_sock_impl_opts.enable_placement_id != 0) {
if (g_spdk_uring_sock_impl_opts.enable_placement_id != PLACEMENT_NONE) {
switch (g_spdk_uring_sock_impl_opts.enable_placement_id) {
case 1: {
case PLACEMENT_NAPI: {
#if defined(SO_INCOMING_NAPI_ID)
struct spdk_uring_sock *sock = __uring_sock(_sock);
socklen_t len = sizeof(int);
@ -1109,7 +1109,7 @@ uring_sock_get_placement_id(struct spdk_sock *_sock, int *placement_id)
#endif
break;
}
case 2: {
case PLACEMENT_CPU: {
#if defined(SO_INCOMING_CPU)
struct spdk_uring_sock *sock = __uring_sock(_sock);
socklen_t len = sizeof(int);