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 <benjamin.walker@intel.com> Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7217 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:
parent
b18fdef111
commit
b77db23ef9
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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: *;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user