Skip to content

Commit

Permalink
Merge pull request ofiwg#5184 from shefty/master
Browse files Browse the repository at this point in the history
mr/cache: Ensure that we remove the correct entry from the rbtree
  • Loading branch information
shefty authored Jul 29, 2019
2 parents 37a511c + 0334bd7 commit 90c4198
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
3 changes: 2 additions & 1 deletion include/ofi_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ void ofi_rbmap_cleanup(struct ofi_rbmap *map);
struct ofi_rbnode *ofi_rbmap_find(struct ofi_rbmap *map, void *key);
struct ofi_rbnode *ofi_rbmap_search(struct ofi_rbmap *map, void *key,
int (*compare)(struct ofi_rbmap *map, void *key, void *data));
int ofi_rbmap_insert(struct ofi_rbmap *map, void *key, void *data);
int ofi_rbmap_insert(struct ofi_rbmap *map, void *key, void *data,
struct ofi_rbnode **node);
void ofi_rbmap_delete(struct ofi_rbmap *map, struct ofi_rbnode *node);
int ofi_rbmap_empty(struct ofi_rbmap *map);

Expand Down
9 changes: 5 additions & 4 deletions prov/rxd/src/rxd_av.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,14 @@ int rxd_av_insert_dg_addr(struct rxd_av *av, const void *addr,

*rxd_addr = rxd_set_rxd_addr(av, dg_addr);

ret = ofi_rbmap_insert(&av->rbmap, (void *) addr, (void *) (*rxd_addr));
if (ret && ret != -FI_EALREADY) {
ret = ofi_rbmap_insert(&av->rbmap, (void *) addr, (void *) (*rxd_addr),
NULL);
if (ret) {
assert(ret != -FI_EALREADY);
fi_av_remove(av->dg_av, &dg_addr, 1, flags);
return ret;
}

return 0;
return ret;
}

static int rxd_av_insert(struct fid_av *av_fid, const void *addr, size_t count,
Expand Down
3 changes: 2 additions & 1 deletion prov/util/src/util_mr_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ static int ofi_mr_rbt_insert(struct ofi_mr_storage *storage,
struct ofi_mr_info *key,
struct ofi_mr_entry *entry)
{
return ofi_rbmap_insert(storage->storage, (void *) key, (void *) entry);
return ofi_rbmap_insert(storage->storage, (void *) key, (void *) entry,
NULL);
}

static int ofi_mr_rbt_erase(struct ofi_mr_storage *storage,
Expand Down
19 changes: 11 additions & 8 deletions prov/util/src/util_mr_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ int ofi_mr_map_insert(struct ofi_mr_map *map, const struct fi_mr_attr *attr,
uint64_t *key, void *context)
{
struct fi_mr_attr *item;
int ret;

item = dup_mr_attr(attr);
if (!item)
Expand All @@ -67,20 +68,22 @@ int ofi_mr_map_insert(struct ofi_mr_map *map, const struct fi_mr_attr *attr,
if (!(map->mode & FI_MR_VIRT_ADDR))
item->offset = (uintptr_t) attr->mr_iov[0].iov_base;

if (!(map->mode & FI_MR_PROV_KEY)) {
if (ofi_rbmap_find(map->rbtree, &item->requested_key)) {
free(item);
return -FI_ENOKEY;
}
} else {
if (map->mode & FI_MR_PROV_KEY)
item->requested_key = map->key++;
}

ofi_rbmap_insert(map->rbtree, &item->requested_key, item);
ret = ofi_rbmap_insert(map->rbtree, &item->requested_key, item, NULL);
if (ret) {
if (ret == -FI_EALREADY)
ret = -FI_ENOKEY;
goto err;
}
*key = item->requested_key;
item->context = context;

return 0;
err:
free(item);
return ret;
}

void *ofi_mr_map_get(struct ofi_mr_map *map, uint64_t key)
Expand Down
2 changes: 1 addition & 1 deletion prov/verbs/src/verbs_domain_xrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ int fi_ibv_get_shared_ini_conn(struct fi_ibv_xrc_ep *ep,
ofi_atomic_initialize32(&conn->ref_cnt, 1);

ret = ofi_rbmap_insert(domain->xrc.ini_conn_rbmap,
(void *) &key, (void *) conn);
(void *) &key, (void *) conn, NULL);
assert(ret != -FI_EALREADY);
if (ret) {
VERBS_WARN(FI_LOG_EP_CTRL, "INI QP RBTree insert failed %d\n",
Expand Down
5 changes: 4 additions & 1 deletion src/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ ofi_insert_rebalance(struct ofi_rbmap *map, struct ofi_rbnode *x)
map->root->color = BLACK;
}

int ofi_rbmap_insert(struct ofi_rbmap *map, void *key, void *data)
int ofi_rbmap_insert(struct ofi_rbmap *map, void *key, void *data,
struct ofi_rbnode **ret_node)
{
struct ofi_rbnode *current, *parent, *node;
int ret;
Expand Down Expand Up @@ -229,6 +230,8 @@ int ofi_rbmap_insert(struct ofi_rbmap *map, void *key, void *data)
}

ofi_insert_rebalance(map, node);
if (ret_node)
*ret_node = node;
return 0;
}

Expand Down

0 comments on commit 90c4198

Please sign in to comment.