From 9325bd3d69dd9d04a2dfe4f7d06758bb71c511ac Mon Sep 17 00:00:00 2001 From: Artem Polyakov Date: Mon, 21 Dec 2015 09:53:26 +0600 Subject: [PATCH] Protect device initialization --- opal/mca/btl/openib/btl_openib.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/opal/mca/btl/openib/btl_openib.c b/opal/mca/btl/openib/btl_openib.c index 76b43037f6..1f048408c2 100644 --- a/opal/mca/btl/openib/btl_openib.c +++ b/opal/mca/btl/openib/btl_openib.c @@ -984,17 +984,22 @@ int mca_btl_openib_add_procs( } #endif + /* protect the device */ + OPAL_THREAD_LOCK(&mca_btl_openib_component.ib_lock); rc = prepare_device_for_use (openib_btl->device); if (OPAL_SUCCESS != rc) { BTL_ERROR(("could not prepare openib device for use")); + OPAL_THREAD_UNLOCK(&mca_btl_openib_component.ib_lock); return rc; } rc = mca_btl_openib_size_queues(openib_btl, nprocs); if (OPAL_SUCCESS != rc) { BTL_ERROR(("error creating cqs")); + OPAL_THREAD_UNLOCK(&mca_btl_openib_component.ib_lock); return rc; } + OPAL_THREAD_UNLOCK(&mca_btl_openib_component.ib_lock); for (i = 0, local_procs = 0 ; i < (int) nprocs; i++) { struct opal_proc_t* proc = procs[i]; @@ -1067,10 +1072,29 @@ struct mca_btl_base_endpoint_t *mca_btl_openib_get_ep (struct mca_btl_base_modul mca_btl_openib_module_t *openib_btl = (mca_btl_openib_module_t *) btl; mca_btl_base_endpoint_t *endpoint; mca_btl_openib_proc_t *ib_proc; - int j; + int j, rc; int local_port_cnt = 0, btl_rank; bool is_reachable; + // TODO: shift to the separate function + /* protect the device */ + OPAL_THREAD_LOCK(&mca_btl_openib_component.ib_lock); + rc = prepare_device_for_use (openib_btl->device); + if (OPAL_SUCCESS != rc) { + BTL_ERROR(("could not prepare openib device for use")); + OPAL_THREAD_UNLOCK(&mca_btl_openib_component.ib_lock); + return rc; + } + + rc = mca_btl_openib_size_queues(openib_btl, 1); + if (OPAL_SUCCESS != rc) { + BTL_ERROR(("error creating cqs")); + OPAL_THREAD_UNLOCK(&mca_btl_openib_component.ib_lock); + return rc; + } + OPAL_THREAD_UNLOCK(&mca_btl_openib_component.ib_lock); + + if (NULL == (ib_proc = mca_btl_openib_proc_get_locked(proc))) { /* if we don't have connection info for this process, it's * okay because some other method might be able to reach it,