diff --git a/include/spdk_internal/sock.h b/include/spdk_internal/sock.h index b074366fc..138805ac4 100644 --- a/include/spdk_internal/sock.h +++ b/include/spdk_internal/sock.h @@ -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, 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 */ diff --git a/lib/sock/sock.c b/lib/sock/sock.c index e72330410..1438f12d8 100644 --- a/lib/sock/sock.c +++ b/lib/sock/sock.c @@ -155,6 +155,25 @@ spdk_sock_map_cleanup(struct spdk_sock_map *map) 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 spdk_sock_get_optimal_sock_group(struct spdk_sock *sock, struct spdk_sock_group **group) { diff --git a/lib/sock/spdk_sock.map b/lib/sock/spdk_sock.map index 64fa372c9..65b98eb4f 100644 --- a/lib/sock/spdk_sock.map +++ b/lib/sock/spdk_sock.map @@ -46,6 +46,7 @@ spdk_sock_map_insert; spdk_sock_map_release; spdk_sock_map_lookup; + spdk_sock_map_find_free; spdk_sock_map_cleanup; local: *; diff --git a/test/unit/lib/sock/posix.c/posix_ut.c b/test/unit/lib/sock/posix.c/posix_ut.c index d83482795..da20cdbd8 100644 --- a/test/unit/lib/sock/posix.c/posix_ut.c +++ b/test/unit/lib/sock/posix.c/posix_ut.c @@ -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(spdk_sock_map_lookup, int, (struct spdk_sock_map *map, int placement_id, 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_net_impl_register, (struct spdk_net_impl *impl, int priority)); diff --git a/test/unit/lib/sock/uring.c/uring_ut.c b/test/unit/lib/sock/uring.c/uring_ut.c index 6454eb91d..c8d43459e 100644 --- a/test/unit/lib/sock/uring.c/uring_ut.c +++ b/test/unit/lib/sock/uring.c/uring_ut.c @@ -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(spdk_sock_map_lookup, int, (struct spdk_sock_map *map, int placement_id, 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_net_impl_register, (struct spdk_net_impl *impl, int priority));