Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util/av: Fix handling of double insertion of the same address #3931

Merged
merged 1 commit into from
Mar 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions prov/util/src/util_av.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,30 @@ static int util_av_hash_insert(struct util_av_hash *hash, int slot, int index)
return 0;
}

/* Caller must hold `av::lock` */
static inline
int util_av_lookup_index(struct util_av *av, const void *addr, int slot)
{
int i, ret = -FI_ENODATA;

if (av->hash.table[slot].index == UTIL_NO_ENTRY) {
FI_DBG(av->prov, FI_LOG_AV, "no entry at slot (%d)\n", slot);
goto out;
}

for (i = slot; i != UTIL_NO_ENTRY; i = av->hash.table[i].next) {
if (!memcmp(ofi_av_get_addr(av, av->hash.table[i].index), addr,
av->addrlen)) {
ret = av->hash.table[i].index;
FI_DBG(av->prov, FI_LOG_AV, "entry at index (%d)\n", ret);
break;
}
}
out:
FI_DBG(av->prov, FI_LOG_AV, "%d\n", ret);
return ret;
}

/*
* Must hold AV lock
*/
Expand All @@ -304,6 +328,11 @@ int ofi_av_insert_addr(struct util_av *av, const void *addr, int slot, int *inde
}

if (av->flags & OFI_AV_HASH) {
ret = util_av_lookup_index(av, addr, slot);
if (ret != -FI_ENODATA) {
*index = ret;
return 0;
}
ret = util_av_hash_insert(&av->hash, slot, av->free_list);
if (ret) {
FI_WARN(av->prov, FI_LOG_AV,
Expand Down Expand Up @@ -405,29 +434,15 @@ int ofi_av_remove_addr(struct util_av *av, int slot, int index)

int ofi_av_lookup_index(struct util_av *av, const void *addr, int slot)
{
int i, ret = -FI_ENODATA;
int ret;

if (slot < 0 || slot >= av->hash.slots) {
FI_WARN(av->prov, FI_LOG_AV, "invalid slot (%d)\n", slot);
return -FI_EINVAL;
}

fastlock_acquire(&av->lock);
if (av->hash.table[slot].index == UTIL_NO_ENTRY) {
FI_DBG(av->prov, FI_LOG_AV, "no entry at slot (%d)\n", slot);
goto out;
}

for (i = slot; i != UTIL_NO_ENTRY; i = av->hash.table[i].next) {
if (!memcmp(ofi_av_get_addr(av, av->hash.table[i].index), addr,
av->addrlen)) {
ret = av->hash.table[i].index;
FI_DBG(av->prov, FI_LOG_AV, "entry at index (%d)\n", ret);
break;
}
}
out:
FI_DBG(av->prov, FI_LOG_AV, "%d\n", ret);
ret = util_av_lookup_index(av, addr, slot);
fastlock_release(&av->lock);
return ret;
}
Expand Down