sock: Allow null entries in sock_map
Allow the map to have entries with a valid placement_id, but no group. This will be useful later when the order of placement_id discovery and group assignment may be reversed. Signed-off-by: Ben Walker <benjamin.walker@intel.com> Change-Id: Ia39adb3a030135940aeb9eeadf9df78056e59c0d Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7209 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: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
b997e957d8
commit
4ce63b9877
@ -67,10 +67,19 @@ sock_map_insert(int placement_id, struct spdk_sock_group *group)
|
||||
pthread_mutex_lock(&g_map_table_mutex);
|
||||
STAILQ_FOREACH(entry, &g_placement_id_map, link) {
|
||||
if (placement_id == entry->placement_id) {
|
||||
if (entry->group != group) {
|
||||
/* Can't set group to NULL if it is already not-NULL */
|
||||
if (group == NULL) {
|
||||
pthread_mutex_unlock(&g_map_table_mutex);
|
||||
return (entry->group == NULL) ? 0 : -EINVAL;
|
||||
}
|
||||
|
||||
if (entry->group == NULL) {
|
||||
entry->group = group;
|
||||
} else if (entry->group != group) {
|
||||
pthread_mutex_unlock(&g_map_table_mutex);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
entry->ref++;
|
||||
pthread_mutex_unlock(&g_map_table_mutex);
|
||||
return 0;
|
||||
@ -85,8 +94,10 @@ sock_map_insert(int placement_id, struct spdk_sock_group *group)
|
||||
}
|
||||
|
||||
entry->placement_id = placement_id;
|
||||
entry->group = group;
|
||||
entry->ref++;
|
||||
if (group) {
|
||||
entry->group = group;
|
||||
entry->ref++;
|
||||
}
|
||||
|
||||
STAILQ_INSERT_TAIL(&g_placement_id_map, entry, link);
|
||||
pthread_mutex_unlock(&g_map_table_mutex);
|
||||
@ -105,6 +116,10 @@ sock_map_release(int placement_id)
|
||||
if (placement_id == entry->placement_id) {
|
||||
assert(entry->ref > 0);
|
||||
entry->ref--;
|
||||
|
||||
if (entry->ref == 0) {
|
||||
entry->group = NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -113,10 +128,11 @@ sock_map_release(int placement_id)
|
||||
}
|
||||
|
||||
/* Look up the group for a placement_id. */
|
||||
static void
|
||||
static int
|
||||
sock_map_lookup(int placement_id, struct spdk_sock_group **group)
|
||||
{
|
||||
struct spdk_sock_placement_id_entry *entry;
|
||||
int rc = -EINVAL;
|
||||
|
||||
*group = NULL;
|
||||
pthread_mutex_lock(&g_map_table_mutex);
|
||||
@ -124,10 +140,13 @@ sock_map_lookup(int placement_id, struct spdk_sock_group **group)
|
||||
if (placement_id == entry->placement_id) {
|
||||
assert(entry->group != NULL);
|
||||
*group = entry->group;
|
||||
rc = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_map_table_mutex);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Remove the socket group from the map table */
|
||||
|
Loading…
x
Reference in New Issue
Block a user