Looks ok to me(code review only) except 
1.      sleep of 1 sec may be more, we can go in micro sleep and 
2.      MAX_NO_RETRIES could match with 10 as max no of retries for immnd 
within 60 seconds.

Thanks
-Nagu

> -----Original Message-----
> From: Hans Nordeback [mailto:hans.nordeb...@ericsson.com]
> Sent: 21 April 2015 20:24
> To: Praveen Malviya; Nagendra Kumar
> Cc: opensaf-devel@lists.sourceforge.net
> Subject: [PATCH 1 of 1] amfd: node rebooted when immnd is killed twice in
> succession [#1290]
> 
>  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. */

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to