lib/sock: fix lookup on placement_id with NULL sock_group

spdk_sock_map_insert() allows for allocating a sock_map
entry, without assigning any sock_group.
This is useful for cases where placement_id determined
by the component using spdk_sock_map_*. See PLACEMENT_MARK mode.
Placement_id's are allocated first, then an empty one is found
using spdk_sock_map_find_free().

Since the above is a valid use case, then entry in sock_map
can exist without a group assigned. spdk_sock_map_lookup() has
to handle such cases, rather than trigger an assert.

Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: Ia717c38fef5e71fe44471ea12f61a5548463f0cf
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10725
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: wanghailiang <hailiangx.e.wang@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Dong Yi <dongx.yi@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
Tomasz Zawadzki 2021-12-16 09:15:31 +01:00
parent dfeab17ef6
commit 91f2725291
2 changed files with 30 additions and 2 deletions

View File

@ -145,9 +145,10 @@ spdk_sock_map_lookup(struct spdk_sock_map *map, int placement_id,
pthread_mutex_lock(&map->mtx);
STAILQ_FOREACH(entry, &map->entries, link) {
if (placement_id == entry->placement_id) {
assert(entry->group != NULL);
*group = entry->group;
rc = 0;
if (*group != NULL) {
rc = 0;
}
break;
}
}

View File

@ -1019,6 +1019,10 @@ ut_sock_map(void)
/* Release entry second and final time. */
spdk_sock_map_release(&map, 1);
test_group = NULL;
rc = spdk_sock_map_lookup(&map, 1, &test_group);
CU_ASSERT(rc == -EINVAL);
CU_ASSERT(test_group == NULL);
spdk_sock_map_cleanup(&map);
@ -1062,6 +1066,29 @@ ut_sock_map(void)
spdk_sock_map_cleanup(&map);
/* Test 6
* Insert single entry without a sock_group */
rc = spdk_sock_map_insert(&map, 1, NULL);
CU_ASSERT(rc == 0);
test_group = NULL;
rc = spdk_sock_map_lookup(&map, 1, &test_group);
CU_ASSERT(rc == -EINVAL);
CU_ASSERT(test_group == NULL);
test_id = spdk_sock_map_find_free(&map);
CU_ASSERT(test_id == 1);
rc = spdk_sock_map_insert(&map, test_id, group_1);
CU_ASSERT(rc == 0);
test_group = NULL;
rc = spdk_sock_map_lookup(&map, test_id, &test_group);
CU_ASSERT(rc == 0);
CU_ASSERT(test_group == group_1);
spdk_sock_map_cleanup(&map);
spdk_ut_sock_group_impl_close(group_2);
spdk_ut_sock_group_impl_close(group_1);
}