From b77db23ef93ec99e57a4449c593955f3bc4ad85c Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Tue, 30 Mar 2021 13:39:30 -0700 Subject: [PATCH] sock: Map operations are now part of the module API Individual modules will need to mantain their own placement maps for this to work correctly, especially if modules have different algorithms. This is a step toward allowing them to do that. Change-Id: Ie798baa50b94f1e99d6690adb606b936c7b30da0 Signed-off-by: Ben Walker Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7217 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Aleksey Marchuk --- include/spdk_internal/sock.h | 21 +++++++++++++++++++++ lib/sock/sock.c | 29 ++++++++++++----------------- lib/sock/spdk_sock.map | 3 +++ 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/include/spdk_internal/sock.h b/include/spdk_internal/sock.h index e172b2397..81b2bc528 100644 --- a/include/spdk_internal/sock.h +++ b/include/spdk_internal/sock.h @@ -299,6 +299,27 @@ spdk_sock_get_placement_id(int fd, enum spdk_placement_mode mode, int *placement } } +extern struct spdk_sock_map g_map; + +/** + * Insert a group into the placement map. + * 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); + +/** + * Release a reference for the given placement_id. If the reference count goes to 0, the + * entry will no longer be associated with a group. + */ +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); + #ifdef __cplusplus } #endif diff --git a/lib/sock/sock.c b/lib/sock/sock.c index 2e9c0b3ae..b9d965b27 100644 --- a/lib/sock/sock.c +++ b/lib/sock/sock.c @@ -57,16 +57,13 @@ struct spdk_sock_map { pthread_mutex_t mtx; }; -static struct spdk_sock_map g_map = { +struct spdk_sock_map g_map = { .entries = STAILQ_HEAD_INITIALIZER(g_map.entries), .mtx = PTHREAD_MUTEX_INITIALIZER }; -/* Insert a group into the placement map. - * If the group is already in the map, take a reference. - */ -static int -sock_map_insert(struct spdk_sock_map *map, int placement_id, struct spdk_sock_group *group) +int +spdk_sock_map_insert(struct spdk_sock_map *map, int placement_id, struct spdk_sock_group *group) { struct spdk_sock_placement_id_entry *entry; @@ -111,9 +108,8 @@ sock_map_insert(struct spdk_sock_map *map, int placement_id, struct spdk_sock_gr return 0; } -/* Release a reference to the group for a given placement_id */ -static void -sock_map_release(struct spdk_sock_map *map, int placement_id) +void +spdk_sock_map_release(struct spdk_sock_map *map, int placement_id) { struct spdk_sock_placement_id_entry *entry; @@ -133,9 +129,8 @@ sock_map_release(struct spdk_sock_map *map, int placement_id) pthread_mutex_unlock(&map->mtx); } -/* Look up the group for a placement_id. */ -static int -sock_map_lookup(struct spdk_sock_map *map, int placement_id, struct spdk_sock_group **group) +int +spdk_sock_map_lookup(struct spdk_sock_map *map, int placement_id, struct spdk_sock_group **group) { struct spdk_sock_placement_id_entry *entry; int rc = -EINVAL; @@ -189,7 +184,7 @@ spdk_sock_get_optimal_sock_group(struct spdk_sock *sock, struct spdk_sock_group placement_id = sock_get_placement_id(sock); if (placement_id != -1) { - sock_map_lookup(&g_map, placement_id, group); + spdk_sock_map_lookup(&g_map, placement_id, group); return 0; } else { return -1; @@ -526,7 +521,7 @@ spdk_sock_group_create(void *ctx) /* if any net_impl is configured to use SO_INCOMING_CPU, initialize the sock map */ if (enable_incoming_cpu) { - sock_map_insert(&g_map, spdk_env_get_current_core(), group); + spdk_sock_map_insert(&g_map, spdk_env_get_current_core(), group); } return group; @@ -585,7 +580,7 @@ spdk_sock_group_add_sock(struct spdk_sock_group *group, struct spdk_sock *sock, placement_id = sock_get_placement_id(sock); if (placement_id != -1) { - rc = sock_map_insert(&g_map, placement_id, group); + rc = spdk_sock_map_insert(&g_map, placement_id, group); 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. */ @@ -616,7 +611,7 @@ spdk_sock_group_remove_sock(struct spdk_sock_group *group, struct spdk_sock *soc placement_id = sock_get_placement_id(sock); if (placement_id != -1) { - sock_map_release(&g_map, placement_id); + spdk_sock_map_release(&g_map, placement_id); } rc = group_impl->net_impl->group_impl_remove_sock(group_impl, sock); @@ -726,7 +721,7 @@ spdk_sock_group_close(struct spdk_sock_group **group) } if (enable_incoming_cpu) { - sock_map_release(&g_map, spdk_env_get_current_core()); + spdk_sock_map_release(&g_map, spdk_env_get_current_core()); } STAILQ_FOREACH_SAFE(group_impl, &(*group)->group_impls, link, tmp) { diff --git a/lib/sock/spdk_sock.map b/lib/sock/spdk_sock.map index df90c35c3..14c743a46 100644 --- a/lib/sock/spdk_sock.map +++ b/lib/sock/spdk_sock.map @@ -43,6 +43,9 @@ # internal function in spdk_internal/sock.h spdk_net_impl_register; + spdk_sock_map_insert; + spdk_sock_map_release; + spdk_sock_map_lookup; local: *; };