Skip to content

Commit b560fc5

Browse files
authored
Merge pull request #7505 from hkuno/john.l.byrne/btl_ofi
Fix btl ofi clean-up logic
2 parents 758c3f8 + ab4875d commit b560fc5

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

opal/mca/btl/ofi/btl_ofi_component.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,21 +581,29 @@ static int mca_btl_ofi_init_device(struct fi_info *info)
581581
fail:
582582
/* clean up */
583583

584+
/* close basic ep before closing av */
585+
if (NULL != ep && !module->is_scalable_ep) {
586+
fi_close(&ep->fid);
587+
ep = NULL;
588+
}
589+
584590
/* if the contexts have not been initiated, num_contexts should
585591
* be zero and we skip this. */
586592
for (int i=0; i < module->num_contexts; i++) {
587593
mca_btl_ofi_context_finalize(&module->contexts[i], module->is_scalable_ep);
588594
}
589595
free(module->contexts);
590596

591-
if (NULL != av) {
592-
fi_close(&av->fid);
593-
}
594-
597+
/* check for NULL ep to avoid double-close */
595598
if (NULL != ep) {
596599
fi_close(&ep->fid);
597600
}
598601

602+
/* close av after closing basic ep */
603+
if (NULL != av) {
604+
fi_close(&av->fid);
605+
}
606+
599607
if (NULL != domain) {
600608
fi_close(&domain->fid);
601609
}

opal/mca/btl/ofi/btl_ofi_module.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,20 +277,33 @@ int mca_btl_ofi_finalize (mca_btl_base_module_t* btl)
277277

278278
assert(btl);
279279

280+
/* clear the rcache */
281+
if (ofi_btl->rcache) {
282+
mca_rcache_base_module_destroy (ofi_btl->rcache);
283+
ofi_btl->rcache = NULL;
284+
}
285+
286+
/* Close basic ep before closing its attached resources. */
287+
if (NULL != ofi_btl->ofi_endpoint && !ofi_btl->is_scalable_ep) {
288+
fi_close(&ofi_btl->ofi_endpoint->fid);
289+
ofi_btl->ofi_endpoint = NULL;
290+
}
291+
280292
/* loop over all the contexts */
281293
for (i=0; i < ofi_btl->num_contexts; i++) {
282294
mca_btl_ofi_context_finalize(&ofi_btl->contexts[i], ofi_btl->is_scalable_ep);
283295
}
284296
free(ofi_btl->contexts);
285297

286-
if (NULL != ofi_btl->av) {
287-
fi_close(&ofi_btl->av->fid);
288-
}
289-
290298
if (NULL != ofi_btl->ofi_endpoint) {
291299
fi_close(&ofi_btl->ofi_endpoint->fid);
292300
}
293301

302+
/* close ep before closing av */
303+
if (NULL != ofi_btl->av) {
304+
fi_close(&ofi_btl->av->fid);
305+
}
306+
294307
if (NULL != ofi_btl->domain) {
295308
fi_close(&ofi_btl->domain->fid);
296309
}
@@ -313,11 +326,6 @@ int mca_btl_ofi_finalize (mca_btl_base_module_t* btl)
313326
OBJ_DESTRUCT(&ofi_btl->id_to_endpoint);
314327
OBJ_DESTRUCT(&ofi_btl->module_lock);
315328

316-
if (ofi_btl->rcache) {
317-
mca_rcache_base_module_destroy (ofi_btl->rcache);
318-
ofi_btl->rcache = NULL;
319-
}
320-
321329
free (btl);
322330

323331
return OPAL_SUCCESS;

0 commit comments

Comments
 (0)