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 <benjamin.walker@intel.com>
Change-Id: I7f11db558e38e940267fdf6eaacbe515334391c2
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7222
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>
This commit is contained in:
Ben Walker 2021-04-01 13:22:28 -07:00 committed by Tomasz Zawadzki
parent 5379aa95e7
commit 4e347038a8
7 changed files with 31 additions and 22 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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. */

View File

@ -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. */

View File

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

View File

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

View File

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