From 4e347038a8e800f0abc1c0042806605f2ae58df9 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Thu, 1 Apr 2021 13:22:28 -0700 Subject: [PATCH] sock: Maps hold group_impls instead of groups Since the maps are unique to modules, they can store the group_impls directly. Signed-off-by: Ben Walker Change-Id: I7f11db558e38e940267fdf6eaacbe515334391c2 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7222 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Aleksey Marchuk --- include/spdk_internal/sock.h | 6 +++--- lib/sock/sock.c | 17 +++++++++++++---- module/sock/posix/posix.c | 12 ++++++------ module/sock/uring/uring.c | 8 ++++---- test/unit/lib/sock/posix.c/posix_ut.c | 4 ++-- test/unit/lib/sock/sock.c/sock_ut.c | 2 +- test/unit/lib/sock/uring.c/uring_ut.c | 4 ++-- 7 files changed, 31 insertions(+), 22 deletions(-) diff --git a/include/spdk_internal/sock.h b/include/spdk_internal/sock.h index d32ed0baba..b074366fc8 100644 --- a/include/spdk_internal/sock.h +++ b/include/spdk_internal/sock.h @@ -114,7 +114,7 @@ struct spdk_net_impl { bool (*is_ipv4)(struct spdk_sock *sock); bool (*is_connected)(struct spdk_sock *sock); - struct spdk_sock_group *(*group_impl_get_optimal)(struct spdk_sock *sock); + struct spdk_sock_group_impl *(*group_impl_get_optimal)(struct spdk_sock *sock); struct spdk_sock_group_impl *(*group_impl_create)(void); int (*group_impl_add_sock)(struct spdk_sock_group_impl *group, struct spdk_sock *sock); int (*group_impl_remove_sock)(struct spdk_sock_group_impl *group, struct spdk_sock *sock); @@ -310,7 +310,7 @@ spdk_sock_get_placement_id(int fd, enum spdk_placement_mode mode, int *placement * If the group is already in the map, take a reference. */ int spdk_sock_map_insert(struct spdk_sock_map *map, int placement_id, - struct spdk_sock_group *group); + struct spdk_sock_group_impl *group_impl); /** * Release a reference for the given placement_id. If the reference count goes to 0, the @@ -322,7 +322,7 @@ void spdk_sock_map_release(struct spdk_sock_map *map, int placement_id); * Look up the group for the given placement_id. */ int spdk_sock_map_lookup(struct spdk_sock_map *map, int placement_id, - struct spdk_sock_group **group); + struct spdk_sock_group_impl **group_impl); /** * Clean up all memory associated with the given map diff --git a/lib/sock/sock.c b/lib/sock/sock.c index 2d0ecc3951..e72330410e 100644 --- a/lib/sock/sock.c +++ b/lib/sock/sock.c @@ -48,12 +48,13 @@ static struct spdk_net_impl *g_default_impl; struct spdk_sock_placement_id_entry { int placement_id; uint32_t ref; - struct spdk_sock_group *group; + struct spdk_sock_group_impl *group; STAILQ_ENTRY(spdk_sock_placement_id_entry) link; }; int -spdk_sock_map_insert(struct spdk_sock_map *map, int placement_id, struct spdk_sock_group *group) +spdk_sock_map_insert(struct spdk_sock_map *map, int placement_id, + struct spdk_sock_group_impl *group) { struct spdk_sock_placement_id_entry *entry; @@ -120,7 +121,8 @@ spdk_sock_map_release(struct spdk_sock_map *map, int placement_id) } int -spdk_sock_map_lookup(struct spdk_sock_map *map, int placement_id, struct spdk_sock_group **group) +spdk_sock_map_lookup(struct spdk_sock_map *map, int placement_id, + struct spdk_sock_group_impl **group) { struct spdk_sock_placement_id_entry *entry; int rc = -EINVAL; @@ -156,9 +158,16 @@ spdk_sock_map_cleanup(struct spdk_sock_map *map) int spdk_sock_get_optimal_sock_group(struct spdk_sock *sock, struct spdk_sock_group **group) { + struct spdk_sock_group_impl *group_impl; + assert(group != NULL); - *group = sock->net_impl->group_impl_get_optimal(sock); + group_impl = sock->net_impl->group_impl_get_optimal(sock); + + if (group_impl) { + *group = group_impl->group; + } + return 0; } diff --git a/module/sock/posix/posix.c b/module/sock/posix/posix.c index e013d4211f..57b25e781b 100644 --- a/module/sock/posix/posix.c +++ b/module/sock/posix/posix.c @@ -1110,15 +1110,15 @@ posix_sock_is_connected(struct spdk_sock *_sock) return true; } -static struct spdk_sock_group * +static struct spdk_sock_group_impl * posix_sock_group_impl_get_optimal(struct spdk_sock *_sock) { struct spdk_posix_sock *sock = __posix_sock(_sock); - struct spdk_sock_group *group; + struct spdk_sock_group_impl *group_impl; if (sock->placement_id != -1) { - spdk_sock_map_lookup(&g_map, sock->placement_id, &group); - return group; + spdk_sock_map_lookup(&g_map, sock->placement_id, &group_impl); + return group_impl; } return NULL; @@ -1150,7 +1150,7 @@ posix_sock_group_impl_create(void) TAILQ_INIT(&group_impl->pending_events); if (g_spdk_posix_sock_impl_opts.enable_placement_id == PLACEMENT_CPU) { - spdk_sock_map_insert(&g_map, spdk_env_get_current_core(), group_impl->base.group); + spdk_sock_map_insert(&g_map, spdk_env_get_current_core(), &group_impl->base); } return &group_impl->base; @@ -1190,7 +1190,7 @@ posix_sock_group_impl_add_sock(struct spdk_sock_group_impl *_group, struct spdk_ } if (sock->placement_id != -1) { - rc = spdk_sock_map_insert(&g_map, sock->placement_id, group->base.group); + rc = spdk_sock_map_insert(&g_map, sock->placement_id, &group->base); if (rc != 0) { SPDK_ERRLOG("Failed to insert sock group into map: %d", rc); /* Do not treat this as an error. The system will continue running. */ diff --git a/module/sock/uring/uring.c b/module/sock/uring/uring.c index d088d1a9c7..3f4b547622 100644 --- a/module/sock/uring/uring.c +++ b/module/sock/uring/uring.c @@ -1106,11 +1106,11 @@ uring_sock_is_connected(struct spdk_sock *_sock) return true; } -static struct spdk_sock_group * +static struct spdk_sock_group_impl * uring_sock_group_impl_get_optimal(struct spdk_sock *_sock) { struct spdk_uring_sock *sock = __uring_sock(_sock); - struct spdk_sock_group *group; + struct spdk_sock_group_impl *group; if (sock->placement_id != -1) { spdk_sock_map_lookup(&g_map, sock->placement_id, &group); @@ -1142,7 +1142,7 @@ uring_sock_group_impl_create(void) TAILQ_INIT(&group_impl->pending_recv); if (g_spdk_uring_sock_impl_opts.enable_placement_id == PLACEMENT_CPU) { - spdk_sock_map_insert(&g_map, spdk_env_get_current_core(), group_impl->base.group); + spdk_sock_map_insert(&g_map, spdk_env_get_current_core(), &group_impl->base); } return &group_impl->base; @@ -1175,7 +1175,7 @@ uring_sock_group_impl_add_sock(struct spdk_sock_group_impl *_group, } if (sock->placement_id != -1) { - rc = spdk_sock_map_insert(&g_map, sock->placement_id, group->base.group); + rc = spdk_sock_map_insert(&g_map, sock->placement_id, &group->base); if (rc != 0) { SPDK_ERRLOG("Failed to insert sock group into map: %d", rc); /* Do not treat this as an error. The system will continue running. */ diff --git a/test/unit/lib/sock/posix.c/posix_ut.c b/test/unit/lib/sock/posix.c/posix_ut.c index 5fe715cb78..d83482795b 100644 --- a/test/unit/lib/sock/posix.c/posix_ut.c +++ b/test/unit/lib/sock/posix.c/posix_ut.c @@ -42,10 +42,10 @@ #include "sock/posix/posix.c" DEFINE_STUB(spdk_sock_map_insert, int, (struct spdk_sock_map *map, int placement_id, - struct spdk_sock_group *group), 0); + struct spdk_sock_group_impl *group), 0); DEFINE_STUB_V(spdk_sock_map_release, (struct spdk_sock_map *map, int placement_id)); DEFINE_STUB(spdk_sock_map_lookup, int, (struct spdk_sock_map *map, int placement_id, - struct spdk_sock_group **group), 0); + struct spdk_sock_group_impl **group), 0); DEFINE_STUB_V(spdk_sock_map_cleanup, (struct spdk_sock_map *map)); DEFINE_STUB_V(spdk_net_impl_register, (struct spdk_net_impl *impl, int priority)); diff --git a/test/unit/lib/sock/sock.c/sock_ut.c b/test/unit/lib/sock/sock.c/sock_ut.c index e3968074b6..b023f6379a 100644 --- a/test/unit/lib/sock/sock.c/sock_ut.c +++ b/test/unit/lib/sock/sock.c/sock_ut.c @@ -290,7 +290,7 @@ spdk_ut_sock_is_connected(struct spdk_sock *_sock) return (sock->peer != NULL); } -static struct spdk_sock_group * +static struct spdk_sock_group_impl * spdk_ut_sock_group_impl_get_optimal(struct spdk_sock *_sock) { return NULL; diff --git a/test/unit/lib/sock/uring.c/uring_ut.c b/test/unit/lib/sock/uring.c/uring_ut.c index d4cc893a3e..6454eb91dc 100644 --- a/test/unit/lib/sock/uring.c/uring_ut.c +++ b/test/unit/lib/sock/uring.c/uring_ut.c @@ -42,10 +42,10 @@ #include "sock/uring/uring.c" DEFINE_STUB(spdk_sock_map_insert, int, (struct spdk_sock_map *map, int placement_id, - struct spdk_sock_group *group), 0); + struct spdk_sock_group_impl *group), 0); DEFINE_STUB_V(spdk_sock_map_release, (struct spdk_sock_map *map, int placement_id)); DEFINE_STUB(spdk_sock_map_lookup, int, (struct spdk_sock_map *map, int placement_id, - struct spdk_sock_group **group), 0); + struct spdk_sock_group_impl **group), 0); DEFINE_STUB_V(spdk_sock_map_cleanup, (struct spdk_sock_map *map)); DEFINE_STUB_V(spdk_net_impl_register, (struct spdk_net_impl *impl, int priority));