osaf/services/saf/amf/amfd/imm.cc | 79 +++++++++++++++++++++++++++----------- 1 files changed, 55 insertions(+), 24 deletions(-)
diff --git a/osaf/services/saf/amf/amfd/imm.cc b/osaf/services/saf/amf/amfd/imm.cc --- a/osaf/services/saf/amf/amfd/imm.cc +++ b/osaf/services/saf/amf/amfd/imm.cc @@ -49,7 +49,8 @@ #include <si_dep.h> #include "osaf_utility.h" - +#include "osaf_time.h" +#include <stdint.h> /* ======================================================================== * DEFINITIONS @@ -1643,6 +1644,10 @@ static void *avd_imm_reinit_bg_thread(vo AVD_EVT *evt; uint32_t status; + struct timespec time = {1, 0 }; + uint32_t no_of_retries = 0; + const uint32_t MAX_NO_RETRIES = 5; + TRACE_ENTER(); osaf_mutex_lock_ordie(&imm_reinit_mutex); /* Send signal that imm_reinit_mutex has been taken. */ @@ -1652,38 +1657,64 @@ static void *avd_imm_reinit_bg_thread(vo immutilWrapperProfile.errorsAreFatal = 0; - if ((rc = immutil_saImmOiInitialize_2(&cb->immOiHandle, &avd_callbacks, &immVersion)) != SA_AIS_OK) { - LOG_ER("saImmOiInitialize failed %u", rc); - osaf_mutex_unlock_ordie(&imm_reinit_mutex); - exit(EXIT_FAILURE); - } + while (++no_of_retries < MAX_NO_RETRIES) { + (void) saImmOiFinalize(avd_cb->immOiHandle); - if ((rc = immutil_saImmOiSelectionObjectGet(cb->immOiHandle, &cb->imm_sel_obj)) != SA_AIS_OK) { - LOG_ER("saImmOiSelectionObjectGet failed %u", rc); - osaf_mutex_unlock_ordie(&imm_reinit_mutex); - exit(EXIT_FAILURE); - } + avd_cb->immOiHandle = 0; + avd_cb->is_implementer = false; - /* If this is the active server, become implementer again. */ - if (cb->avail_state_avd == SA_AMF_HA_ACTIVE) { - if (avd_imm_impl_set() != SA_AIS_OK) { - LOG_ER("exiting since avd_imm_impl_set failed"); - osaf_mutex_unlock_ordie(&imm_reinit_mutex); - exit(EXIT_FAILURE); - } - } else { - /* become applier and re-read the config */ - if (avd_imm_applier_set() != SA_AIS_OK) { - LOG_ER("exiting since avd_imm_applier_set failed"); + if ((rc = immutil_saImmOiInitialize_2(&cb->immOiHandle, &avd_callbacks, &immVersion)) != SA_AIS_OK) { + LOG_ER("saImmOiInitialize failed %u", rc); osaf_mutex_unlock_ordie(&imm_reinit_mutex); exit(EXIT_FAILURE); } - if (avd_imm_config_get() != NCSCC_RC_SUCCESS) { - LOG_ER("avd_imm_config_get FAILED"); + rc = immutil_saImmOiSelectionObjectGet(cb->immOiHandle, &cb->imm_sel_obj); + if (rc == SA_AIS_ERR_BAD_HANDLE) { + osaf_nanosleep(&time); + continue; + } else if (rc != SA_AIS_OK) { + LOG_ER("saImmOiSelectionObjectGet failed %u", rc); osaf_mutex_unlock_ordie(&imm_reinit_mutex); exit(EXIT_FAILURE); } + + /* If this is the active server, become implementer again. */ + if (cb->avail_state_avd == SA_AMF_HA_ACTIVE) { + rc = avd_imm_impl_set(); + if (rc == SA_AIS_ERR_BAD_HANDLE) { + osaf_nanosleep(&time); + continue; + } else if (rc != SA_AIS_OK) { + LOG_ER("exiting since avd_imm_impl_set failed"); + osaf_mutex_unlock_ordie(&imm_reinit_mutex); + exit(EXIT_FAILURE); + } + } else { + /* become applier and re-read the config */ + rc = avd_imm_applier_set(); + if (rc == SA_AIS_ERR_BAD_HANDLE) { + osaf_nanosleep(&time); + continue; + } else if (rc != SA_AIS_OK) { + LOG_ER("exiting since avd_imm_applier_set failed"); + osaf_mutex_unlock_ordie(&imm_reinit_mutex); + exit(EXIT_FAILURE); + } + + if (avd_imm_config_get() != NCSCC_RC_SUCCESS) { + LOG_ER("avd_imm_config_get FAILED"); + osaf_mutex_unlock_ordie(&imm_reinit_mutex); + exit(EXIT_FAILURE); + } + } + break; + } + + if (no_of_retries >= MAX_NO_RETRIES) { + LOG_ER("Re-init with IMM FAILED"); + osaf_mutex_unlock_ordie(&imm_reinit_mutex); + exit(EXIT_FAILURE); } /* Wake up the main thread so it discovers the new IMM handle. */ ------------------------------------------------------------------------------ BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel