sock: Add sock_map_find_free

This function finds a placement_id that does not have a group
associated with it.

Change-Id: I1306690e980fd4661f46dba9fb283f048a962eba
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7223
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Ben Walker 2021-04-01 15:03:08 -07:00 committed by Tomasz Zawadzki
parent d88ccda689
commit 2f9271b818
5 changed files with 27 additions and 0 deletions

View File

@ -324,6 +324,11 @@ void 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, int spdk_sock_map_lookup(struct spdk_sock_map *map, int placement_id,
struct spdk_sock_group_impl **group_impl); struct spdk_sock_group_impl **group_impl);
/**
* Find a placement id with no associated group
*/
int spdk_sock_map_find_free(struct spdk_sock_map *map);
/** /**
* Clean up all memory associated with the given map * Clean up all memory associated with the given map
*/ */

View File

@ -155,6 +155,25 @@ spdk_sock_map_cleanup(struct spdk_sock_map *map)
pthread_mutex_unlock(&map->mtx); pthread_mutex_unlock(&map->mtx);
} }
int
spdk_sock_map_find_free(struct spdk_sock_map *map)
{
struct spdk_sock_placement_id_entry *entry;
int placement_id = -1;
pthread_mutex_lock(&map->mtx);
STAILQ_FOREACH(entry, &map->entries, link) {
if (entry->group == NULL) {
placement_id = entry->placement_id;
break;
}
}
pthread_mutex_unlock(&map->mtx);
return placement_id;
}
int int
spdk_sock_get_optimal_sock_group(struct spdk_sock *sock, struct spdk_sock_group **group) spdk_sock_get_optimal_sock_group(struct spdk_sock *sock, struct spdk_sock_group **group)
{ {

View File

@ -46,6 +46,7 @@
spdk_sock_map_insert; spdk_sock_map_insert;
spdk_sock_map_release; spdk_sock_map_release;
spdk_sock_map_lookup; spdk_sock_map_lookup;
spdk_sock_map_find_free;
spdk_sock_map_cleanup; spdk_sock_map_cleanup;
local: *; local: *;

View File

@ -46,6 +46,7 @@ DEFINE_STUB(spdk_sock_map_insert, int, (struct spdk_sock_map *map, int placement
DEFINE_STUB_V(spdk_sock_map_release, (struct spdk_sock_map *map, int placement_id)); 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, DEFINE_STUB(spdk_sock_map_lookup, int, (struct spdk_sock_map *map, int placement_id,
struct spdk_sock_group_impl **group), 0); struct spdk_sock_group_impl **group), 0);
DEFINE_STUB(spdk_sock_map_find_free, int, (struct spdk_sock_map *map), -1);
DEFINE_STUB_V(spdk_sock_map_cleanup, (struct spdk_sock_map *map)); 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)); DEFINE_STUB_V(spdk_net_impl_register, (struct spdk_net_impl *impl, int priority));

View File

@ -46,6 +46,7 @@ DEFINE_STUB(spdk_sock_map_insert, int, (struct spdk_sock_map *map, int placement
DEFINE_STUB_V(spdk_sock_map_release, (struct spdk_sock_map *map, int placement_id)); 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, DEFINE_STUB(spdk_sock_map_lookup, int, (struct spdk_sock_map *map, int placement_id,
struct spdk_sock_group_impl **group), 0); struct spdk_sock_group_impl **group), 0);
DEFINE_STUB(spdk_sock_map_find_free, int, (struct spdk_sock_map *map), -1);
DEFINE_STUB_V(spdk_sock_map_cleanup, (struct spdk_sock_map *map)); 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)); DEFINE_STUB_V(spdk_net_impl_register, (struct spdk_net_impl *impl, int priority));