diff --git a/src/urma/lib/urma/bond/bondp_api.c b/src/urma/lib/urma/bond/bondp_api.c index d37652b0b8eccce83acfd6c6c4dd02f960b70c02..38f31ddd524d13509b0862eda9db697426f41056 100644 --- a/src/urma/lib/urma/bond/bondp_api.c +++ b/src/urma/lib/urma/bond/bondp_api.c @@ -178,11 +178,11 @@ static int bondp_add_jfs_p_vjetty_id_info(bondp_context_t *bdp_ctx, bondp_comp_t if (bdp_jfs->p_jfs[i] == NULL) { continue; } - int ret = bdp_p_vjetty_id_table_add_without_lock(&bdp_ctx->p_vjetty_id_table, - bdp_jfs->p_jfs[i]->jfs_id.id, JFS, jetty_id, bdp_jfs); + urma_jfr_id_t pjfs_id = bdp_jfs->p_jfs[i]->jfs_id; + int ret = bdp_p_vjetty_id_table_add_without_lock(&bdp_ctx->p_vjetty_id_table, pjfs_id, JFS, jetty_id, bdp_jfs); if (ret) { - URMA_LOG_ERR("Failed to add p_vjfs_id[%d]: ret: %d, p_jfs_id: %u, v_jfs_id: %u\n", - i, ret, bdp_jfs->p_jfs[i]->jfs_id.id, jetty_id); + URMA_LOG_ERR("Failed to add p_vjfs_id[%d]: ret: %d, p_jfs_id: %u, v_jfs_id: %u\n", i, ret, pjfs_id.id, + jetty_id); goto DEL_P_VJFS_ID; } } @@ -193,7 +193,8 @@ DEL_P_VJFS_ID: if (bdp_jfs->p_jfs[j] == NULL) { continue; } - (void)bdp_p_vjetty_id_table_del_without_lock(&bdp_ctx->p_vjetty_id_table, bdp_jfs->p_jfs[j]->jfs_id.id, JFS); + urma_jfr_id_t pjfs_id = bdp_jfs->p_jfs[i]->jfs_id; + (void)bdp_p_vjetty_id_table_del_without_lock(&bdp_ctx->p_vjetty_id_table, pjfs_id, JFS); } pthread_rwlock_unlock(&bdp_ctx->p_vjetty_id_table.lock); return -1; @@ -206,11 +207,10 @@ static void bondp_del_jfs_p_vjetty_info_without_lock(bondp_comp_t *bdp_jfs) if (bdp_jfs->p_jfs[i] == NULL) { continue; } - int ret = bdp_p_vjetty_id_table_del_without_lock(&bdp_ctx->p_vjetty_id_table, - bdp_jfs->p_jfs[i]->jfs_id.id, JFS); + urma_jfr_id_t pjfs_id = bdp_jfs->p_jfs[i]->jfs_id; + int ret = bdp_p_vjetty_id_table_del_without_lock(&bdp_ctx->p_vjetty_id_table, pjfs_id, JFS); if (ret) { - URMA_LOG_ERR("Failed to delete p_vjfs_id node[%d]: ret: %d pjfs_id: %u\n", - i, ret, bdp_jfs->p_jfs[i]->jfs_id.id); + URMA_LOG_ERR("Failed to delete p_vjfs_id node[%d]: ret: %d pjfs_id: %u\n", i, ret, pjfs_id.id); } } } @@ -378,11 +378,11 @@ static int bondp_add_jfr_p_vjetty_id_info(bondp_context_t *bdp_ctx, bondp_comp_t if (bdp_jfr->p_jfr[i] == NULL) { continue; } - int ret = bdp_p_vjetty_id_table_add_without_lock(&bdp_ctx->p_vjetty_id_table, - bdp_jfr->p_jfr[i]->jfr_id.id, JFR, jetty_id, bdp_jfr); + urma_jfr_id_t pjfr_id = bdp_jfr->p_jfr[i]->jfr_id; + int ret = bdp_p_vjetty_id_table_add_without_lock(&bdp_ctx->p_vjetty_id_table, pjfr_id, JFR, jetty_id, bdp_jfr); if (ret) { - URMA_LOG_ERR("Failed to add p_vjfr_id[%d]: ret: %d, p_jfr_id: %u, v_jfr_id: %u\n", - i, ret, bdp_jfr->p_jfr[i]->jfr_id.id, jetty_id); + URMA_LOG_ERR("Failed to add p_vjfr_id[%d]: ret: %d, p_jfr_id: %u, v_jfr_id: %u\n", i, ret, pjfr_id.id, + jetty_id); goto DEL_P_VJFR_ID; } } @@ -393,7 +393,8 @@ DEL_P_VJFR_ID: if (bdp_jfr->p_jfr[j] == NULL) { continue; } - (void)bdp_p_vjetty_id_table_del_without_lock(&bdp_ctx->p_vjetty_id_table, bdp_jfr->p_jfr[j]->jfr_id.id, JFR); + urma_jfr_id_t pjfr_id = bdp_jfr->p_jfr[i]->jfr_id; + (void)bdp_p_vjetty_id_table_del_without_lock(&bdp_ctx->p_vjetty_id_table, pjfr_id, JFR); } pthread_rwlock_unlock(&bdp_ctx->p_vjetty_id_table.lock); return -1; @@ -406,11 +407,10 @@ static void bondp_del_jfr_p_vjetty_info_without_lock(bondp_comp_t *bdp_jfr) if (bdp_jfr->p_jfr[i] == NULL) { continue; } - int ret = bdp_p_vjetty_id_table_del_without_lock(&bdp_ctx->p_vjetty_id_table, - bdp_jfr->p_jfr[i]->jfr_id.id, JFR); + urma_jfr_id_t pjfr_id = bdp_jfr->p_jfr[i]->jfr_id; + int ret = bdp_p_vjetty_id_table_del_without_lock(&bdp_ctx->p_vjetty_id_table, pjfr_id, JFR); if (ret) { - URMA_LOG_ERR("Failed to delete p_vjfr_id node[%d]: ret %d pjfr_id: %u\n", - i, ret, bdp_jfr->p_jfr[i]->jfr_id.id); + URMA_LOG_ERR("Failed to delete p_vjfr_id node[%d]: ret %d pjfr_id: %u\n", i, ret, pjfr_id.id); } } } @@ -633,16 +633,16 @@ static int bondp_add_jetty_p_vjetty_id_info(bondp_context_t *bdp_ctx, bondp_comp if (!bdp_jetty->p_jetty[i]) { continue; } - uint32_t pjetty_id = bdp_jetty->p_jetty[i]->jetty_id.id; + urma_jetty_id_t pjetty_id = bdp_jetty->p_jetty[i]->jetty_id; int ret = bdp_p_vjetty_id_table_add_without_lock(&bdp_ctx->p_vjetty_id_table, pjetty_id, JETTY, jetty_id, bdp_jetty); if (ret == BONDP_HASH_MAP_COLLIDE_ERROR && jetty_id > 0 && jetty_id < BONDP_MAX_WELL_KNOWN_JETTY_ID) { URMA_LOG_INFO("Add repeated wk-jetty id[%d]: ret: %d, p_jetty_id: %u, v_jetty_id: %u\n", - i, ret, pjetty_id, jetty_id); + i, ret, pjetty_id.id, jetty_id); } else if (ret != 0) { URMA_LOG_ERR("Failed to add p_vjetty_id[%d]: ret: %d, p_jetty_id: %u, v_jetty_id: %u\n", - i, ret, pjetty_id, jetty_id); + i, ret, pjetty_id.id, jetty_id); goto DEL_P_VJETTY_ID; } } @@ -653,8 +653,8 @@ DEL_P_VJETTY_ID: if (!bdp_jetty->p_jetty[i]) { continue; } - (void)bdp_p_vjetty_id_table_del_without_lock(&bdp_ctx->p_vjetty_id_table, - bdp_jetty->p_jetty[i]->jetty_id.id, JETTY); + urma_jetty_id_t pjetty_id = bdp_jetty->p_jetty[i]->jetty_id; + (void)bdp_p_vjetty_id_table_del_without_lock(&bdp_ctx->p_vjetty_id_table, pjetty_id, JETTY); } pthread_rwlock_unlock(&bdp_ctx->p_vjetty_id_table.lock); return -1; @@ -667,8 +667,8 @@ static void bondp_del_jetty_p_vjetty_info_without_lock(bondp_comp_t *bdp_jetty) if (bdp_jetty->p_jetty[i] == NULL) { continue; } - int ret = bdp_p_vjetty_id_table_del_without_lock(&bdp_ctx->p_vjetty_id_table, - bdp_jetty->p_jetty[i]->jetty_id.id, JETTY); + urma_jetty_id_t pjetty_id = bdp_jetty->p_jetty[i]->jetty_id; + int ret = bdp_p_vjetty_id_table_del_without_lock(&bdp_ctx->p_vjetty_id_table, pjetty_id, JETTY); if (ret) { URMA_LOG_ERR("Failed to delete p_vjetty_id node: ret: %d pjetty_id: %u\n", ret, bdp_jetty->p_jetty[i]->jetty_id.id); diff --git a/src/urma/lib/urma/bond/bondp_context_table.c b/src/urma/lib/urma/bond/bondp_context_table.c index 92a79678ba8fd2154fbaeec19b51dcef94b7d7e9..8de8cc9ebef34a877da66b84f0c0f99d7ecc576f 100644 --- a/src/urma/lib/urma/bond/bondp_context_table.c +++ b/src/urma/lib/urma/bond/bondp_context_table.c @@ -20,8 +20,9 @@ static bool bdp_p_vjetty_id_comp(struct ub_hmap_node *node, void *key) { bdp_p_vjetty_id_t *item = CONTAINER_OF_FIELD(node, bdp_p_vjetty_id_t, hmap_node); - bdp_p_vjetty_id_key_t *tmp = key; - return item->key.pjetty_id == tmp->pjetty_id && item->key.type == tmp->type; + bdp_p_vjetty_id_key_t *key_item = key; + return memcmp(&item->key.pjetty_id, &key_item->pjetty_id, sizeof(urma_jetty_id_t)) == 0 && + item->key.type == key_item->type; } static void bdp_p_vjetty_id_free(struct ub_hmap_node *node) @@ -32,7 +33,8 @@ static void bdp_p_vjetty_id_free(struct ub_hmap_node *node) static uint32_t bdp_p_vjetty_id_hash(void *key) { - return ub_hash_bytes(key, sizeof(bdp_p_vjetty_id_key_t), BDP_P_VJETTY_ID_HASH_BASIS); + bdp_p_vjetty_id_key_t *item = key; + return ub_hash_bytes(&item->pjetty_id, sizeof(urma_jetty_id_t), BDP_P_VJETTY_ID_HASH_BASIS) + item->type; } int bdp_p_vjetty_id_table_create(bondp_hash_table_t *tbl, uint32_t size) @@ -46,7 +48,7 @@ int bdp_p_vjetty_id_table_destroy(bondp_hash_table_t *tbl) return 0; } -int bdp_p_vjetty_id_table_add(bondp_hash_table_t *tbl, uint32_t pjetty_id, bdp_p_vjetty_type_t type, +int bdp_p_vjetty_id_table_add_without_lock(bondp_hash_table_t *tbl, urma_jetty_id_t pjetty_id, bdp_p_vjetty_type_t type, uint32_t vjetty_id, bondp_comp_t *comp) { bdp_p_vjetty_id_t *tmp = NULL; @@ -59,26 +61,22 @@ int bdp_p_vjetty_id_table_add(bondp_hash_table_t *tbl, uint32_t pjetty_id, bdp_p return BONDP_HASH_MAP_INVALID_PARAM_ERROR; } uint32_t hash = bdp_p_vjetty_id_hash(&key); - (void)pthread_rwlock_wrlock(&tbl->lock); node = bondp_hash_table_lookup_without_lock(tbl, &key, hash); if (node) { - (void)pthread_rwlock_unlock(&tbl->lock); return BONDP_HASH_MAP_COLLIDE_ERROR; } tmp = calloc(1, sizeof(bdp_p_vjetty_id_t)); if (!tmp) { - (void)pthread_rwlock_unlock(&tbl->lock); return BONDP_HASH_MAP_ALLOC_ERROR; } tmp->key = key; tmp->vjetty_id = vjetty_id; tmp->comp = comp; bondp_hash_table_add_with_hash_without_lock(tbl, &tmp->hmap_node, hash); - (void)pthread_rwlock_unlock(&tbl->lock); return 0; } -int bdp_p_vjetty_id_table_del(bondp_hash_table_t *tbl, uint32_t pjetty_id, bdp_p_vjetty_type_t type) +int bdp_p_vjetty_id_table_del_without_lock(bondp_hash_table_t *tbl, urma_jetty_id_t pjetty_id, bdp_p_vjetty_type_t type) { hmap_node_t *node = NULL; bdp_p_vjetty_id_key_t key = { @@ -87,65 +85,16 @@ int bdp_p_vjetty_id_table_del(bondp_hash_table_t *tbl, uint32_t pjetty_id, bdp_p }; uint32_t hash = bdp_p_vjetty_id_hash(&key); - (void)pthread_rwlock_wrlock(&tbl->lock); node = bondp_hash_table_lookup_without_lock(tbl, &key, hash); if (!node) { - (void)pthread_rwlock_unlock(&tbl->lock); return BONDP_HASH_MAP_NOT_FOUND_ERROR; } bondp_hash_table_remove_without_lock(tbl, node); bdp_p_vjetty_id_free(node); - (void)pthread_rwlock_unlock(&tbl->lock); - return 0; -} - -int bdp_p_vjetty_id_table_add_without_lock(bondp_hash_table_t *tbl, uint32_t pjetty_id, bdp_p_vjetty_type_t type, - uint32_t vjetty_id, bondp_comp_t *comp) -{ - bdp_p_vjetty_id_t *tmp = NULL; - hmap_node_t *node = NULL; - bdp_p_vjetty_id_key_t key = { - .pjetty_id = pjetty_id, - .type = type - }; - if (comp == NULL) { - return BONDP_HASH_MAP_INVALID_PARAM_ERROR; - } - uint32_t hash = bdp_p_vjetty_id_hash(&key); - node = bondp_hash_table_lookup_without_lock(tbl, &key, hash); - if (node) { - return BONDP_HASH_MAP_COLLIDE_ERROR; - } - tmp = calloc(1, sizeof(bdp_p_vjetty_id_t)); - if (!tmp) { - return BONDP_HASH_MAP_ALLOC_ERROR; - } - tmp->key = key; - tmp->vjetty_id = vjetty_id; - tmp->comp = comp; - bondp_hash_table_add_with_hash_without_lock(tbl, &tmp->hmap_node, hash); return 0; } -int bdp_p_vjetty_id_table_del_without_lock(bondp_hash_table_t *tbl, uint32_t pjetty_id, bdp_p_vjetty_type_t type) -{ - hmap_node_t *node = NULL; - bdp_p_vjetty_id_key_t key = { - .pjetty_id = pjetty_id, - .type = type - }; - uint32_t hash = bdp_p_vjetty_id_hash(&key); - - node = bondp_hash_table_lookup_without_lock(tbl, &key, hash); - if (!node) { - return BONDP_HASH_MAP_NOT_FOUND_ERROR; - } - bondp_hash_table_remove_without_lock(tbl, node); - bdp_p_vjetty_id_free(node); - return 0; -} - -int bdp_p_vjetty_id_table_lookup(bondp_hash_table_t *tbl, uint32_t pjetty_id, bdp_p_vjetty_type_t type, +int bdp_p_vjetty_id_table_lookup(bondp_hash_table_t *tbl, urma_jetty_id_t pjetty_id, bdp_p_vjetty_type_t type, uint32_t *vjetty_id) { hmap_node_t *node = NULL; @@ -166,7 +115,7 @@ int bdp_p_vjetty_id_table_lookup(bondp_hash_table_t *tbl, uint32_t pjetty_id, bd } struct bondp_comp *bdp_p_vjetty_id_table_lookup_comp_without_lock(bondp_hash_table_t *tbl, - uint32_t pjetty_id, bdp_p_vjetty_type_t type) + urma_jetty_id_t pjetty_id, bdp_p_vjetty_type_t type) { hmap_node_t *node = NULL; bdp_p_vjetty_id_key_t key = { @@ -290,39 +239,39 @@ int bdp_r_p2v_jetty_id_table_lookup(bondp_hash_table_t *tbl, urma_jetty_id_t *rp } /* == bdp_r_v2p_token_id_table == */ - + static bool bdp_r_v2p_token_id_comp(struct ub_hmap_node *node, void *key) { bondp_v2p_token_id_t *item = CONTAINER_OF_FIELD(node, bondp_v2p_token_id_t, hmap_node); bondp_v2p_token_id_key_t *key_item = key; - + return (item->key.v_token_id == key_item->v_token_id) && (memcmp(&item->key.v_remote_eid, &key_item->v_remote_eid, sizeof(urma_eid_t)) == 0); } - + static void bdp_r_v2p_token_id_free(struct ub_hmap_node *node) { bondp_v2p_token_id_t *item = CONTAINER_OF_FIELD(node, bondp_v2p_token_id_t, hmap_node); free(item); } - + static uint32_t bdp_r_v2p_token_id_hash(void *key) { return ((bondp_v2p_token_id_key_t *)key)->v_token_id; } - + int bdp_r_v2p_token_id_table_create(bondp_hash_table_t *tbl, uint32_t size) { return bondp_hash_table_create(tbl, size, bdp_r_v2p_token_id_comp, bdp_r_v2p_token_id_free, bdp_r_v2p_token_id_hash); } - + int bdp_r_v2p_token_id_table_destroy(bondp_hash_table_t *tbl) { bondp_hash_table_destroy(tbl); return 0; } - + int bdp_r_v2p_token_id_tabl_lookup(bondp_hash_table_t *tbl, uint32_t v_token_id, urma_eid_t *v_remote_eid, bondp_v2p_token_id_t *item) { @@ -341,15 +290,15 @@ int bdp_r_v2p_token_id_tabl_lookup(bondp_hash_table_t *tbl, uint32_t v_token_id, bondp_v2p_token_id_t *tmp = CONTAINER_OF_FIELD(node, bondp_v2p_token_id_t, hmap_node); (void)memcpy(item, tmp, sizeof(bondp_v2p_token_id_t)); (void)pthread_rwlock_unlock(&tbl->lock); - + return 0; } - + int bdp_r_v2p_token_id_del_idx_lockless(bondp_hash_table_t *tbl, uint32_t index) { bondp_v2p_token_id_t *item = NULL; struct ub_hmap_node *node, *next; - + node = ub_hmap_first(&tbl->hmap); while (node != NULL) { item = CONTAINER_OF_FIELD(node, bondp_v2p_token_id_t, hmap_node); @@ -363,11 +312,11 @@ int bdp_r_v2p_token_id_del_idx_lockless(bondp_hash_table_t *tbl, uint32_t index) } node = next; } - + URMA_LOG_ERR("Failed to find node, index: %u.\n", index); return -1; } - + int bdp_r_v2p_token_id_table_add_lockless(bondp_hash_table_t *tbl, bondp_v2p_token_id_t *item) { bondp_v2p_token_id_key_t key = item->key; @@ -377,18 +326,18 @@ int bdp_r_v2p_token_id_table_add_lockless(bondp_hash_table_t *tbl, bondp_v2p_tok URMA_LOG_DEBUG("Node already added into hash table, hash: %u, index: %u.\n", hash, item->index); return 0; } - + bondp_v2p_token_id_t *new_item = calloc(1, sizeof(bondp_v2p_token_id_t)); if (new_item == NULL) { return BONDP_HASH_MAP_ALLOC_ERROR; } - + (void)memcpy(new_item->peer_p_seg, item->peer_p_seg, URMA_UBAGG_DEV_MAX_NUM * sizeof(item->peer_p_seg[0])); new_item->v_handle = item->v_handle; new_item->key = key; new_item->index = item->index; - + bondp_hash_table_add_with_hash_without_lock(tbl, &new_item->hmap_node, hash); - + return 0; -} \ No newline at end of file +} diff --git a/src/urma/lib/urma/bond/bondp_context_table.h b/src/urma/lib/urma/bond/bondp_context_table.h index 24cf30190b6ac6ce6b0931dd48ac0e4c6da0958c..733fec61981b7b6d03e406ccc4dfdf3a57429196 100644 --- a/src/urma/lib/urma/bond/bondp_context_table.h +++ b/src/urma/lib/urma/bond/bondp_context_table.h @@ -25,7 +25,7 @@ typedef enum bdp_p_vjetty_type { } bdp_p_vjetty_type_t; typedef struct bdp_p_vjetty_id_key { - uint32_t pjetty_id; + urma_jetty_id_t pjetty_id; bdp_p_vjetty_type_t type; } bdp_p_vjetty_id_key_t; /** @@ -43,29 +43,12 @@ typedef struct bdp_p_vjetty_id { int bdp_p_vjetty_id_table_create(bondp_hash_table_t *tbl, uint32_t size); int bdp_p_vjetty_id_table_destroy(bondp_hash_table_t *tbl); -/** - * This function does not increase the reference count of the comp. - * The lifecycle of the comp pointer needs to be confirmed by the caller. - * As long as the comp pointer is protected from being released when accessed externally, - * there will be no UAF (Use-After-Free) issues. - */ -int bdp_p_vjetty_id_table_add(bondp_hash_table_t *tbl, uint32_t pjetty_id, bdp_p_vjetty_type_t type, - uint32_t vjetty_id, struct bondp_comp *comp); -/** - * This function is not recommended for use except in scenarios where the entire hash table is being released. - * This is because the reference count and lifecycle of the comp pointer within the nodes may require structures beyond - * the current hash table to manage. - * This function only guarantees the deletion of one node mapped by a pjetty_id at a time; - * it does not ensure that the same comp pointer will not be found by other nodes through lookup after deletion. - * This function does not manage the lifecycle of the comp, - * so it will not release the comp or access any resources associated with it. - */ -int bdp_p_vjetty_id_table_del(bondp_hash_table_t *tbl, uint32_t pjetty_id, bdp_p_vjetty_type_t type); -int bdp_p_vjetty_id_table_add_without_lock(bondp_hash_table_t *tbl, uint32_t pjetty_id, bdp_p_vjetty_type_t type, - uint32_t vjetty_id, struct bondp_comp *comp); +int bdp_p_vjetty_id_table_add_without_lock(bondp_hash_table_t *tbl, urma_jetty_id_t pjetty_id, bdp_p_vjetty_type_t type, + uint32_t vjetty_id, struct bondp_comp *comp); -int bdp_p_vjetty_id_table_del_without_lock(bondp_hash_table_t *tbl, uint32_t pjetty_id, bdp_p_vjetty_type_t type); +int bdp_p_vjetty_id_table_del_without_lock(bondp_hash_table_t *tbl, urma_jetty_id_t pjetty_id, + bdp_p_vjetty_type_t type); /** * After querying the table, only the vjetty_id is returned. * This function does not consider the reference count corresponding to comp. @@ -79,15 +62,15 @@ int bdp_p_vjetty_id_table_del_without_lock(bondp_hash_table_t *tbl, uint32_t pje * @param vjetty_id: output * @return: 0 for success, other for error */ -int bdp_p_vjetty_id_table_lookup(bondp_hash_table_t *tbl, uint32_t pjetty_id, bdp_p_vjetty_type_t type, - uint32_t *vjetty_id); +int bdp_p_vjetty_id_table_lookup(bondp_hash_table_t *tbl, urma_jetty_id_t pjetty_id, bdp_p_vjetty_type_t type, + uint32_t *vjetty_id); /** * Return the bondp_comp corresponding to pjetty_id * Only perform table lookup operations, do not manage reference counts, external locking is required for use. * @return: The pointer of `comp` field in the lookup result. NULL means error or not found. */ -struct bondp_comp *bdp_p_vjetty_id_table_lookup_comp_without_lock(bondp_hash_table_t *tbl, - uint32_t pjetty_id, bdp_p_vjetty_type_t type); +struct bondp_comp *bdp_p_vjetty_id_table_lookup_comp_without_lock(bondp_hash_table_t *tbl, urma_jetty_id_t pjetty_id, + bdp_p_vjetty_type_t type); typedef enum bdp_remote_p_to_v_jetty_id_type { REMOTE_JETTY, @@ -145,7 +128,7 @@ typedef struct bondp_v2p_token_id_key { uint32_t v_token_id; urma_eid_t v_remote_eid; } bondp_v2p_token_id_key_t; - + typedef struct bondp_v2p_token_id { hmap_node_t hmap_node; bondp_v2p_token_id_key_t key; @@ -153,13 +136,13 @@ typedef struct bondp_v2p_token_id { uint64_t v_handle; uint32_t index; } bondp_v2p_token_id_t; - + int bdp_r_v2p_token_id_table_create(bondp_hash_table_t *tbl, uint32_t size); int bdp_r_v2p_token_id_table_destroy(bondp_hash_table_t *tbl); - + int bdp_r_v2p_token_id_tabl_lookup(bondp_hash_table_t *tbl, uint32_t v_token_id, urma_eid_t *v_remote_eid, bondp_v2p_token_id_t *item); int bdp_r_v2p_token_id_del_idx_lockless(bondp_hash_table_t *tbl, uint32_t index); int bdp_r_v2p_token_id_table_add_lockless(bondp_hash_table_t *tbl, bondp_v2p_token_id_t *item); -#endif // BONDP_CONTEXT_TABLE \ No newline at end of file +#endif // BONDP_CONTEXT_TABLE diff --git a/src/urma/lib/urma/bond/bondp_datapath.c b/src/urma/lib/urma/bond/bondp_datapath.c index 18532824382b3a32969ec6f6ecf7d14f654e628b..bf3939a6f34b1d84be07cd835a12983df85e5da8 100644 --- a/src/urma/lib/urma/bond/bondp_datapath.c +++ b/src/urma/lib/urma/bond/bondp_datapath.c @@ -1830,14 +1830,18 @@ static inline bdp_p_vjetty_type_t get_p_vjetty_type_by_cr(urma_cr_t *cr) * The caller needs to decrement the reference count when bjetty_ctx is about to go out of scope. * @return Return bjetty_ctx on success, return NULL on failure. */ -static bjetty_ctx_t *get_bjetty_ctx_by_cr(bondp_context_t *bdp_ctx, urma_cr_t *cr) +static bjetty_ctx_t *get_bjetty_ctx_by_cr(bondp_context_t *bdp_ctx, int dev_idx, urma_cr_t *cr) { + urma_jetty_id_t pjetty_id = { + .eid = bdp_ctx->p_ctxs[dev_idx]->eid, + .id = cr->local_id, + }; pthread_rwlock_rdlock(&bdp_ctx->p_vjetty_id_table.lock); - bondp_comp_t *comp = bdp_p_vjetty_id_table_lookup_comp_without_lock(&bdp_ctx->p_vjetty_id_table, - cr->local_id, get_p_vjetty_type_by_cr(cr)); + bondp_comp_t *comp = bdp_p_vjetty_id_table_lookup_comp_without_lock(&bdp_ctx->p_vjetty_id_table, pjetty_id, + get_p_vjetty_type_by_cr(cr)); if (comp == NULL) { pthread_rwlock_unlock(&bdp_ctx->p_vjetty_id_table.lock); - URMA_LOG_ERR("Failed to get comp, local_id: %d\n", cr->local_id); + URMA_LOG_ERR("Failed to get comp, local_id: %d\n", pjetty_id.id); return NULL; } if (comp->comp_ctx == NULL) { @@ -1884,7 +1888,7 @@ static urma_status_t update_device_valid_state(bondp_context_t *bdp_ctx, int dev if (!is_cr_user_ctx_valid(&cr_buf[cr_id])) { continue; } - bjetty_ctx_t *bjetty_ctx = get_bjetty_ctx_by_cr(bdp_ctx, &cr_buf[cr_id]); + bjetty_ctx_t *bjetty_ctx = get_bjetty_ctx_by_cr(bdp_ctx, dev_id, &cr_buf[cr_id]); if (bjetty_ctx == NULL) { URMA_LOG_ERR("Failed to get bjetty_ctx\n"); return URMA_FAIL; @@ -1948,13 +1952,17 @@ static int bondp_poll_pjfc(bondp_context_t *bdp_ctx, bondp_comp_t *bdp_jfc, int * Convert the local_id field of a CR from pjetty.id to vjetty.id if possible. * @return: If conversion is possible, perform the conversion and return 0; otherwise, do not replace and return -1. */ -static int restore_cr_local_id(bondp_context_t *bdp_ctx, urma_cr_t *cr) +static int restore_cr_local_id(bondp_context_t *bdp_ctx, int dev_idx, urma_cr_t *cr) { uint32_t vjetty_id; - int ret = bdp_p_vjetty_id_table_lookup(&bdp_ctx->p_vjetty_id_table, cr->local_id, get_p_vjetty_type_by_cr(cr), + urma_jetty_id_t pjetty_id = { + .eid = bdp_ctx->p_ctxs[dev_idx]->eid, + .id = cr->local_id, + }; + int ret = bdp_p_vjetty_id_table_lookup(&bdp_ctx->p_vjetty_id_table, pjetty_id, get_p_vjetty_type_by_cr(cr), &vjetty_id); if (ret) { - URMA_LOG_ERR("Failed to get vjetty.id of local_id: %u, ret: %d\n", cr->local_id, ret); + URMA_LOG_ERR("Failed to get vjetty.id of local_id: %u, ret: %d\n", pjetty_id.id, ret); return -1; } cr->local_id = vjetty_id; @@ -2001,13 +2009,13 @@ static void restore_cr_remote_id_fallback(bondp_context_t *bdp_ctx, urma_cr_t *c * Considering that the binding relationship between pjfc and pjetty keeps their indices consistent, * we use the index of pjfc as the index for pjetty. */ -static int bondp_handle_cr_no_store(bondp_context_t *bdp_ctx, int dev_idx, - urma_cr_t *cr, urma_cr_t *cr_output_array, int *total_cnt) +static int bondp_handle_cr_no_store(bondp_context_t *bdp_ctx, int dev_idx, urma_cr_t *cr, urma_cr_t *cr_output_array, + int *total_cnt) { // Special handling is applied to the CRs constructed by the hardware of SUSPEND_DONE and FLUSH_ERROR_DONE. if (!is_cr_user_ctx_valid(cr)) { // find out the bjetty_ctx - bjetty_ctx_t *bjetty_ctx = get_bjetty_ctx_by_cr(bdp_ctx, cr); + bjetty_ctx_t *bjetty_ctx = get_bjetty_ctx_by_cr(bdp_ctx, dev_idx, cr); if (bjetty_ctx == NULL) { return -1; } @@ -2046,7 +2054,7 @@ static int bondp_handle_cr_no_store(bondp_context_t *bdp_ctx, int dev_idx, put_bjetty_ctx(bjetty_ctx); return 0; } - if (restore_cr_local_id(bdp_ctx, cr)) { + if (restore_cr_local_id(bdp_ctx, dev_idx, cr)) { cr->local_id = 0; /* Replace with invalid value under exceptional circumstances */ } /* Perform remote_id restoration on both the sending and receiving ends. @@ -2069,13 +2077,13 @@ static inline bool is_cr_handler_ret_skip(bondp_cr_handler_ret_t ret) return ret == CR_HANDLER_SUCCESS_AND_SKIP || ret == CR_HANDLER_ERR_AND_SKIP; } -static int bondp_handle_cr_with_store(bondp_context_t *bdp_ctx, int total_cqe_cnt, int cr_cnt_limit, urma_cr_t *cr, - urma_cr_t *cr_output_array, int *total_cnt) +static int bondp_handle_cr_with_store(bondp_context_t *bdp_ctx, int dev_idx, int total_cqe_cnt, int cr_cnt_limit, + urma_cr_t *cr, urma_cr_t *cr_output_array, int *total_cnt) { /* Handle CR with status URMA_CR_WR_SUSPEND_DONE or URMA_CR_WR_FLUSH_ERR_DONE */ if (!is_cr_user_ctx_valid(cr)) { /* For these CRs where the user_ctx does not exist, simply restore the necessary values and then skip them. */ - if (restore_cr_local_id(bdp_ctx, cr)) { + if (restore_cr_local_id(bdp_ctx, dev_idx, cr)) { cr->local_id = 0; /* Replace with invalid value under exceptional circumstances */ } /* @@ -2090,7 +2098,7 @@ static int bondp_handle_cr_with_store(bondp_context_t *bdp_ctx, int total_cqe_cn cr_output_array[(*total_cnt)++] = *cr; return 0; } - bjetty_ctx_t *bjetty_ctx = get_bjetty_ctx_by_cr(bdp_ctx, cr); + bjetty_ctx_t *bjetty_ctx = get_bjetty_ctx_by_cr(bdp_ctx, dev_idx, cr); if (bjetty_ctx == NULL) { return -1; } @@ -2164,7 +2172,7 @@ int bondp_poll_jfc(urma_jfc_t *jfc, int cr_cnt, urma_cr_t *cr_output_array) ret = bondp_handle_cr_no_store(bdp_ctx, dev_id, &bdp_cr_buf[dev_id][cr_id], cr_output_array, &total_cnt); } else { - ret = bondp_handle_cr_with_store(bdp_ctx, total_cqe_cnt, cr_cnt, + ret = bondp_handle_cr_with_store(bdp_ctx, dev_id, total_cqe_cnt, cr_cnt, &bdp_cr_buf[dev_id][cr_id], cr_output_array, &total_cnt); } if (ret < 0) {