ack, code review only. Minor comments inlined.

/Thanks HansN

On 09/10/2015 04:03 PM, praveen.malv...@oracle.com wrote:
>   osaf/services/saf/amf/amfd/comp.cc             |    5 +-
>   osaf/services/saf/amf/amfd/include/su.h        |    1 +
>   osaf/services/saf/amf/amfd/sgproc.cc           |   18 +
>   osaf/services/saf/amf/amfd/su.cc               |   10 +-
>   osaf/services/saf/amf/amfnd/clc.cc             |  223 +++++-
>   osaf/services/saf/amf/amfnd/comp.cc            |   58 +-
>   osaf/services/saf/amf/amfnd/compdb.cc          |    1 +
>   osaf/services/saf/amf/amfnd/err.cc             |  148 +++-
>   osaf/services/saf/amf/amfnd/include/avnd_err.h |    1 +
>   osaf/services/saf/amf/amfnd/include/avnd_su.h  |    8 +-
>   osaf/services/saf/amf/amfnd/su.cc              |   58 +-
>   osaf/services/saf/amf/amfnd/susm.cc            |  915 
> ++++++++++++++++++++----
>   12 files changed, 1192 insertions(+), 254 deletions(-)
>
>
> During surestart recovery, currently AMF is not spec compliant in two
> ways:
> 1)Individual component is terminated/cleaned up and then instantiated.
>    Iinstead all componenets should be abruplty terminated and then 
> instantiated
>    honoring the instantiation level.
> 2)During termination/cleanup of individual component, saAmfDisableRestart 
> flag is
>    not honoured.
> Ticket is updated with relevent spec sections for reference.
>
> Patch solves the problem by cleaning up the component in the reverse order of
> instantiation level and instantiation of compoment in the forward order. Also
> before terminating a non-restartable component (saAmfDisableRestart=true),
> assignments are switchover to another SU.
>
> This patch contains the common code to be used by #334 and #1455.
>
> diff --git a/osaf/services/saf/amf/amfd/comp.cc 
> b/osaf/services/saf/amf/amfd/comp.cc
> --- a/osaf/services/saf/amf/amfd/comp.cc
> +++ b/osaf/services/saf/amf/amfd/comp.cc
> @@ -189,8 +189,9 @@ void avd_comp_readiness_state_set(AVD_CO
>               comp->comp_info.name.value,
>               avd_readiness_state_name[comp->saAmfCompReadinessState], 
> avd_readiness_state_name[readiness_state]);
>       comp->saAmfCompReadinessState = readiness_state;
> -     avd_saImmOiRtObjectUpdate(&comp->comp_info.name, 
> "saAmfCompReadinessState",
> -             SA_IMM_ATTR_SAUINT32T, &comp->saAmfCompReadinessState);
> +     if (comp->su->surestart == false)
> +             avd_saImmOiRtObjectUpdate(&comp->comp_info.name, 
> "saAmfCompReadinessState",
> +                             SA_IMM_ATTR_SAUINT32T, 
> &comp->saAmfCompReadinessState);
>       m_AVSV_SEND_CKPT_UPDT_ASYNC_UPDT(avd_cb, comp, 
> AVSV_CKPT_COMP_READINESS_STATE);
>       TRACE_LEAVE();
>   }
> diff --git a/osaf/services/saf/amf/amfd/include/su.h 
> b/osaf/services/saf/amf/amfd/include/su.h
> --- a/osaf/services/saf/amf/amfd/include/su.h
> +++ b/osaf/services/saf/amf/amfd/include/su.h
> @@ -87,6 +87,7 @@ class AVD_SU {
>       int su_act_state; // not used, kept for EDU, remove later
>   
>       AVD_SG *sg_of_su;       /* the service group of this SU */
> +     bool surestart; /* used during surestart recovery and restart op on non 
> restartable comp*/
[HansN] surestart can be private, and functions to set, void 
set_surestart(bool restart) and to check bool surestart() void.
>       AVD_AVND *su_on_node;   /*  the node on which this SU resides */
>       struct avd_su_si_rel_tag *list_of_susi; /* the list of su si 
> relationship elements */
>   
> diff --git a/osaf/services/saf/amf/amfd/sgproc.cc 
> b/osaf/services/saf/amf/amfd/sgproc.cc
> --- a/osaf/services/saf/amf/amfd/sgproc.cc
> +++ b/osaf/services/saf/amf/amfd/sgproc.cc
> @@ -689,6 +689,24 @@ void avd_su_oper_state_evh(AVD_CL_CB *cb
>               cluster_startup_expiry_event_generate(cb);
>       }
>   
> +     /* Atleast one non-restartable healthy comp is assigned and recovery got
> +        escalated to surestart. Before cleaning up any healthy 
> non-restartable comp,
> +        gracefully reassigned their assignments to comp in other SU. At 
> present
> +        assignment of whole SU will be gracefully reassigned instead of only 
> this comp.
> +        Thus PI applications modeled on  NWay and Nway Active modelthis is 
> spec deviation.
> +      */
> +     if (n2d_msg->msg_info.n2d_opr_state.rec_rcvr.raw == 
> AVSV_ERR_RCVR_SU_RESTART) {
> +             TRACE("surestart recovery request for '%s'", su->name.value);
> +             su->surestart = true;
> +             TRACE("surestart flag is set true");
> +             /*Readiness is temporarliy kept OOS so as to reuse sg_fsm.
> +               It will not be updated to IMM and thus not visible to user.
> +              */
> +             su->set_readiness_state(SA_AMF_READINESS_OUT_OF_SERVICE);
> +             /*Initiate graceful removal of assignment from this su.*/
> +             su->sg_of_su->su_fault(cb, su);
> +             goto done;
> +     }
>       /* Verify that the SU operation state is disable and do the processing. 
> */
>       if (n2d_msg->msg_info.n2d_opr_state.su_oper_state == 
> SA_AMF_OPERATIONAL_DISABLED) {
>               /* if the SU is NCS SU, call the node FSM routine to handle the 
> failure.
> diff --git a/osaf/services/saf/amf/amfd/su.cc 
> b/osaf/services/saf/amf/amfd/su.cc
> --- a/osaf/services/saf/amf/amfd/su.cc
> +++ b/osaf/services/saf/amf/amfd/su.cc
> @@ -64,6 +64,7 @@ void AVD_SU::initialize() {
>       saAmfSUHostedByNode.length = 0;
>       pend_cbk.invocation = 0;
>       pend_cbk.admin_oper = (SaAmfAdminOperationIdT)0;
> +     surestart = false;
>   }
>   
>   AVD_SU::AVD_SU() {
> @@ -766,6 +767,10 @@ void AVD_SU::set_pres_state(SaAmfPresenc
>       avd_saImmOiRtObjectUpdate(&name, "saAmfSUPresenceState",
>               SA_IMM_ATTR_SAUINT32T, &saAmfSUPresenceState);
>       m_AVSV_SEND_CKPT_UPDT_ASYNC_UPDT(avd_cb, this, AVSV_CKPT_SU_PRES_STATE);
> +     if ((saAmfSUPresenceState == SA_AMF_PRESENCE_UNINSTANTIATED) && 
> (surestart == true)) {
> +             TRACE("setting surestart flag to false");
> +             surestart = false;
> +     }
>       TRACE_LEAVE();
>   }
>   
> @@ -814,8 +819,9 @@ void AVD_SU::set_readiness_state(SaAmfRe
>               avd_readiness_state_name[saAmfSuReadinessState],
>               avd_readiness_state_name[readiness_state]);
>       saAmfSuReadinessState = readiness_state;
> -     avd_saImmOiRtObjectUpdate(&name, "saAmfSUReadinessState",
> -             SA_IMM_ATTR_SAUINT32T, &saAmfSuReadinessState);
> +     if (surestart == false)
> +             avd_saImmOiRtObjectUpdate(&name, "saAmfSUReadinessState",
> +                             SA_IMM_ATTR_SAUINT32T, &saAmfSuReadinessState);
>       m_AVSV_SEND_CKPT_UPDT_ASYNC_UPDT(avd_cb, this, 
> AVSV_CKPT_SU_READINESS_STATE);
>   
>       /* Since Su readiness state has changed, we need to change it for all 
> the
> diff --git a/osaf/services/saf/amf/amfnd/clc.cc 
> b/osaf/services/saf/amf/amfnd/clc.cc
> --- a/osaf/services/saf/amf/amfnd/clc.cc
> +++ b/osaf/services/saf/amf/amfnd/clc.cc
> @@ -57,6 +57,7 @@ static uint32_t avnd_comp_clc_terming_te
>   static uint32_t avnd_comp_clc_terming_termfail_hdler(AVND_CB *, AVND_COMP 
> *);
>   static uint32_t avnd_comp_clc_terming_cleansucc_hdler(AVND_CB *, AVND_COMP 
> *);
>   static uint32_t avnd_comp_clc_terming_cleanfail_hdler(AVND_CB *, AVND_COMP 
> *);
> +static uint32_t avnd_comp_clc_restart_inst_hdler(AVND_CB *, AVND_COMP *);
>   static uint32_t avnd_comp_clc_restart_instsucc_hdler(AVND_CB *, AVND_COMP 
> *);
>   static uint32_t avnd_comp_clc_restart_term_hdler(AVND_CB *, AVND_COMP *);
>   static uint32_t avnd_comp_clc_restart_termsucc_hdler(AVND_CB *, AVND_COMP 
> *);
> @@ -141,7 +142,7 @@ static AVND_COMP_CLC_FSM_FN avnd_comp_cl
>   
>       /* SA_AMF_PRESENCE_RESTARTING */
>       {
> -      0,                     /* INST EV */
> +      avnd_comp_clc_restart_inst_hdler,      /* INST EV */
>        avnd_comp_clc_restart_instsucc_hdler,  /* INST_SUCC EV */
>        avnd_comp_clc_xxxing_instfail_hdler,   /* INST_FAIL EV */
>        avnd_comp_clc_restart_term_hdler,      /* TERM EV */
> @@ -877,15 +878,25 @@ uint32_t avnd_comp_clc_fsm_run(AVND_CB *
>       TRACE_1("'%s':FSM Enter presence state: '%s':FSM Exit presence 
> state:%s",
>                                       
> comp->name.value,pres_state[prv_st],pres_state[final_st]);
>   
> -     /* process state change */
> -     if (prv_st != final_st)
> +     /*
> +         A restartable component will trigger SU FSM in the context of:
> +            1.su restart recovery or
> +            2.restart admin op on su.
> +         In these cases comp will be instantiated only when all the 
> components
> +            are cleaned up. So after successful cleanup/termination of 
> restarting comp,
> +         trigger SU FSM to terminate/cleanup more components or instantiat 
> the SU.
> +      */
> +     if ((prv_st != final_st) || (((prv_st == SA_AMF_PRESENCE_RESTARTING) &&
> +                             (final_st == SA_AMF_PRESENCE_RESTARTING)) &&
> +                             ((ev == AVND_COMP_CLC_PRES_FSM_EV_INST_SUCC) ||
> +                              (ev == AVND_COMP_CLC_PRES_FSM_EV_TERM_SUCC) ||
> +                              (ev == 
> AVND_COMP_CLC_PRES_FSM_EV_CLEANUP_SUCC))))
>               rc = avnd_comp_clc_st_chng_prc(cb, comp, prv_st, final_st);
>   
>    done:
>       TRACE_LEAVE2("%u", rc);
>       return rc;
>   }
> -
>   
> /****************************************************************************
>     Name          : avnd_comp_clc_st_chng_prc
>    
> @@ -907,7 +918,8 @@ uint32_t avnd_comp_clc_st_chng_prc(AVND_
>       AVND_COMP_CSI_REC *csi = 0;
>       bool is_en;
>       uint32_t rc = NCSCC_RC_SUCCESS;
> -     TRACE_ENTER2("Comp '%s', Prv_state '%u', Final_state '%u'", 
> comp->name.value, prv_st, final_st);
> +     TRACE_ENTER2("Comp '%s', Prv_state '%s', Final_state '%s'", 
> comp->name.value,
> +                     presence_state[prv_st],presence_state[final_st]);
>   
>       /*
>        * Process state change
> @@ -925,7 +937,7 @@ uint32_t avnd_comp_clc_st_chng_prc(AVND_
>                               &comp->name, comp->err_info.restart_cnt);
>       }
>       /* reset the admin-oper flag to false */
> -     if (comp->admin_oper == true) {
> +     if ((comp->admin_oper == true) && (final_st == 
> SA_AMF_PRESENCE_INSTANTIATED)) {
>               TRACE_1("Component restart is through admin opration, admin 
> oper flag reset");
>               comp->admin_oper = false;
>       }
> @@ -1003,8 +1015,16 @@ uint32_t avnd_comp_clc_st_chng_prc(AVND_
>                               clear_error_report_alarm(comp);
>                       }
>   
> -                     /* reassign the comp-csis.. if su-restart recovery is 
> not active */
> -                     if (!m_AVND_SU_IS_RESTART(comp->su)) {
> +                     /* reassign the comp-csis..
> +                        1)if su-restart recovery is not active which means 
> comp was admin restarted
> +                          or faulted with restart recovery.
> +                        2)if comp with restartable recovery faulted during 
> the reassignment phase of
> +                          of surestart recovery. This can happen when 
> surestart prob timer expires   
> +                          in the surestart recovery phase.
> +                      */
> +                     if ((!m_AVND_SU_IS_RESTART(comp->su)) || 
> (((m_AVND_SU_IS_RESTART(comp->su))
> +                                                     && 
> (!m_AVND_SU_IS_FAILED(comp->su)) &&
> +                                        (comp->su->admin_op_Id != 
> SA_AMF_ADMIN_RESTART)))) {

[HansN] Having a comment explaining the if statement indicates that the 
if stmt can be clearer, instead:
                                       if ((comp->admin_restarted()) || 
((!comp->admin_restarted()) &&
(comp->su->state() !=  AVND_SU_FLAG_FAILED) &&
(comp->su->admin_op_Id() != SA_AMF_ADMIN_RESTART)))) {

>                               rc = avnd_comp_csi_reassign(cb, comp);
>                               if (NCSCC_RC_SUCCESS != rc)
>                                       goto done;
> @@ -1044,8 +1064,12 @@ uint32_t avnd_comp_clc_st_chng_prc(AVND_
>                       if (m_AVND_COMP_IS_FAILED(comp) && 
> !comp->csi_list.n_nodes &&
>                           !m_AVND_SU_IS_ADMN_TERM(comp->su) &&
>                           (cb->oper_state == SA_AMF_OPERATIONAL_ENABLED)) {
> -                             /* No need to restart component during shutdown 
> and during sufailover*/
> -                             if (!m_AVND_IS_SHUTTING_DOWN(cb) && 
> !sufailover_in_progress(comp->su))
> +                             /* No need to restart component during 
> shutdown, during surestart
> +                                and during sufailover.It will be 
> instantiated as part of repair.
> +                                For surestart recovery, SU FSM will 
> instantiate all comps after successful
> +                                clean up of all of them.*/
> +                             if (!m_AVND_IS_SHUTTING_DOWN(cb) && 
> !sufailover_in_progress(comp->su) &&
> +                                             
> (!m_AVND_SU_IS_RESTART(comp->su)))
>                                       rc = avnd_comp_clc_fsm_trigger(cb, 
> comp, AVND_COMP_CLC_PRES_FSM_EV_INST);
>                       } else if (m_AVND_COMP_IS_FAILED(comp) && 
> !comp->csi_list.n_nodes) {
>                               m_AVND_COMP_FAILED_RESET(comp); /*if we moved 
> from restart -> term
> @@ -1087,6 +1111,7 @@ uint32_t avnd_comp_clc_st_chng_prc(AVND_
>                       }
>                       else {
>                               if (!m_AVND_COMP_IS_FAILED(comp)) {
> +                                     TRACE("Not a failed comp");
>                                       /* csi-set / csi-rem succeeded.. 
> generate csi-done indication */
>                                       csi = 
> m_AVND_CSI_REC_FROM_COMP_DLL_NODE_GET(m_NCS_DBLIST_FIND_FIRST(&comp->csi_list));
>                                       osafassert(csi);
> @@ -1101,6 +1126,7 @@ uint32_t avnd_comp_clc_st_chng_prc(AVND_
>                               } else {
>                                       /* failed su is ready to take on si 
> assignment.. inform avd */
>                                       if (!comp->csi_list.n_nodes) {
> +                                             TRACE("Comp has no CSIs 
> assigned");
>                                               m_AVND_SU_IS_ENABLED(comp->su, 
> is_en);
>                                               if (true == is_en) {
>                                                       
> m_AVND_SU_OPER_STATE_SET(comp->su,SA_AMF_OPERATIONAL_ENABLED);
> @@ -1111,8 +1137,10 @@ uint32_t avnd_comp_clc_st_chng_prc(AVND_
>                                               }
>                                               m_AVND_COMP_FAILED_RESET(comp);
>                                               
> m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, comp, AVND_CKPT_COMP_FLAG_CHANGE);
> +                                     } else if 
> ((m_AVND_SU_IS_RESTART(comp->su)) && (m_AVND_SU_IS_FAILED(comp->su))) {
> +                                             TRACE("suRestart escalation 
> context");
> +                                             m_AVND_COMP_FAILED_RESET(comp);
>                                       }
> -
>                               }
>                       }
>               }
> @@ -1275,11 +1303,7 @@ uint32_t avnd_comp_clc_st_chng_prc(AVND_
>               }
>       }
>   
> -     /*
> -      * Trigger the SU FSM.
> -      * Only PI comps in a PI SU send event to the SU FSM.
> -      * All NPI comps in an NPI SU send event to the SU FSM.
> -      */
> +      /*Trigger the SU FSM from a NPI component in PI SU.*/
>       if (m_AVND_SU_IS_PREINSTANTIABLE(comp->su) && 
> !m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(comp)) {
>   
>               if (SA_AMF_PRESENCE_INSTANTIATION_FAILED == final_st)
> @@ -1288,16 +1312,24 @@ uint32_t avnd_comp_clc_st_chng_prc(AVND_
>                       ev = AVND_SU_PRES_FSM_EV_COMP_TERM_FAIL;
>               else if ((SA_AMF_PRESENCE_TERMINATING == final_st) && 
> (comp->su->pres == SA_AMF_PRESENCE_RESTARTING))
>                       ev = AVND_SU_PRES_FSM_EV_COMP_TERMINATING;
> -             else if ((sufailover_in_progress(comp->su) ||
> +             else if ((sufailover_in_progress(comp->su) || 
> (m_AVND_SU_IS_RESTART(comp->su)) ||
>                                       (avnd_cb->term_state == 
> AVND_TERM_STATE_NODE_SWITCHOVER_STARTED) ||
>                                       (all_comps_terminated_in_su(comp->su) 
> == true)) &&
>                               (SA_AMF_PRESENCE_UNINSTANTIATED == final_st))
> -                     /* If sufailover flag is enabled, then SU FSM needs to 
> be triggered in both sufailover
> -                        and nodeswitchover escalation.
> +                     /* If sufailover flag is enabled, then SU FSM needs to 
> be triggered in
> +                        sufailover, surestart and nodeswitchover escalation. 
> Also in case of
> +                        restart admin operation on a non restartable 
> component or SU trigger SU FSM.
>                        */
>                       ev = AVND_SU_PRES_FSM_EV_COMP_UNINSTANTIATED;
> +             else if ((final_st == SA_AMF_PRESENCE_RESTARTING) && (prv_st == 
> SA_AMF_PRESENCE_RESTARTING) &&
> +                                (comp->su->admin_op_Id == 
> SA_AMF_ADMIN_RESTART))
> +                     /* If a restartable PI SU consists of NPI comp, then 
> trigger SU FSM to terminate
> +                       other components or start instnatiation.*/
> +                     ev = AVND_SU_PRES_FSM_EV_COMP_RESTARTING;
>       }
>   
> +      /* Trigger the SU FSM from a PI component in PI SU or
> +         from a NPI component in any SU.*/
>       if ((m_AVND_SU_IS_PREINSTANTIABLE(comp->su) &&
>            m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(comp)) || 
> !m_AVND_SU_IS_PREINSTANTIABLE(comp->su)) {
>               if (SA_AMF_PRESENCE_UNINSTANTIATED == final_st)
> @@ -1308,7 +1340,14 @@ uint32_t avnd_comp_clc_st_chng_prc(AVND_
>                       ev = AVND_SU_PRES_FSM_EV_COMP_INST_FAIL;
>               else if (SA_AMF_PRESENCE_TERMINATION_FAILED == final_st)
>                       ev = AVND_SU_PRES_FSM_EV_COMP_TERM_FAIL;
> -             else if (SA_AMF_PRESENCE_RESTARTING == final_st)
> +             else if ((SA_AMF_PRESENCE_RESTARTING == final_st) &&
> +                             (prv_st == SA_AMF_PRESENCE_RESTARTING) && 
> (comp->admin_oper == false) &&
> +                             (comp->su->admin_op_Id == SA_AMF_ADMIN_RESTART))
> +                     /* A restartable component is restarting state will not 
> trigger SU FSM:
> +                        - when it has faulted with comprestart recovery or
> +                        - when it is admin restarted.
> +                        But in the context of restart admin operatin on SU, 
> trigger SU FSM
> +                        to make way for furter termination or instantiation. 
> */
>                       ev = AVND_SU_PRES_FSM_EV_COMP_RESTARTING;
>               else if (SA_AMF_PRESENCE_TERMINATING == final_st)
>                       ev = AVND_SU_PRES_FSM_EV_COMP_TERMINATING;
> @@ -1655,6 +1694,31 @@ uint32_t avnd_comp_clc_xxxing_cleansucc_
>        */
>       avnd_comp_cmplete_all_assignment(cb, comp);
>   
> +     /* If su is restarting then, instantiation of the all the PI components 
> will be done after
> +        termination of all of them. But for a NPI comp in PI su, restart is 
> done at the time of
> +        assignment. Such a component never triggers SU FSM. So instantiate 
> it in comp FSM.
> +      */
> +     //TODO: Reframe these blockes to make them more illustrative.
> +     if (!(m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(comp)) && 
> m_AVND_SU_IS_PREINSTANTIABLE(comp->su) &&
> +                     (!m_AVND_SU_IS_RESTART(comp->su)) && 
> (!m_AVND_SU_IS_FAILED(comp->su)))
> +             /* Instantiate this NPI comp of PI SU if context is not:
> +               -surestart recovery.
> +                  -restart admin op on SU.*/
> +             ;//Goahead and instantiate a NPI comp in PI SU.
> +     else if ((m_AVND_SU_IS_RESTART(comp->su)) && 
> (!m_AVND_SU_IS_FAILED(comp->su)) &&
> +                                     (comp->su->admin_op_Id != 
> SA_AMF_ADMIN_RESTART))
> +             /* Restart the component if it fails with restart reocvery
> +                during the repair phase of surestart recovery.*/
> +             ;
> +     else if (m_AVND_SU_IS_RESTART(comp->su))  {
> +             if ((comp->pres == SA_AMF_PRESENCE_RESTARTING) &&  
> m_AVND_SU_IS_FAILED(comp->su))       
> +                     /* Cleanup was already initiated when comp faulted with 
> comprestart recovery.
> +                        If further escalation reached to surestart, same 
> cleanup can be used and thus
> +                           comp can be marked uninstantiated.*/
> +                     avnd_comp_pres_state_set(comp, 
> SA_AMF_PRESENCE_UNINSTANTIATED);
> +             goto done;
> +     }
> +
>       if ((clc_info->inst_retry_cnt < clc_info->inst_retry_max) &&
>           (AVND_COMP_INST_EXIT_CODE_NO_RETRY != clc_info->inst_code_rcvd)) {
>               /* => keep retrying */
> @@ -1848,9 +1912,27 @@ uint32_t avnd_comp_clc_inst_clean_hdler(
>       } else if (m_AVND_COMP_TYPE_IS_PROXY(comp) && comp->pxied_list.n_nodes) 
> {
>               /* if there are still outstanding proxied components we can't 
> terminate right now */
>               return rc;
> -     } else
> -             /* cleanup the comp */
> -             rc = avnd_comp_clc_cmd_execute(cb, comp, 
> AVND_COMP_CLC_CMD_TYPE_CLEANUP);
> +     } else {
> +             if (m_AVND_SU_IS_RESTART(comp->su) && 
> m_AVND_COMP_IS_RESTART_DIS(comp) &&
> +                             (comp->csi_list.n_nodes > 0) &&
> +                             (m_AVND_SU_IS_PREINSTANTIABLE(comp->su) &&
> +                              (comp->su->su_err_esc_level != 
> AVND_ERR_ESC_LEVEL_2))) {
> +                     /* A non-restartable assigned healthy 
> component(DisableRestart=1) and
> +                        context is surestart recovery, first perform 
> reassignment for this
> +                        component to other SU then clean it up.
> +                        At present assignment of whole SU will be gracefully 
> reassigned
> +                        instead of only this comp. Thus for PI applications 
> modeled on NWay and
> +                        Nway Active model this is spec deviation.
> +                        So as of now clean up of components due to surestart 
> recovery policy
> +                        is halted to remove assignment from a healthy non 
> restartable comp.
> +                        Further cleanup will be resumed after removal of 
> assignments.
> +                      */
> +                     /*Send amfd to gracefully remove assignments for thus 
> SU.*/
> +                     su_send_suRestart_recovery_msg(comp->su);
> +                     goto done;
> +             } else
> +                     rc = avnd_comp_clc_cmd_execute(cb, comp, 
> AVND_COMP_CLC_CMD_TYPE_CLEANUP);
> +     }
>       if (NCSCC_RC_SUCCESS == rc) {
>               /* reset the comp-reg & instantiate params */
>               if (!m_AVND_COMP_TYPE_IS_PROXIED(comp))
> @@ -1864,6 +1946,7 @@ uint32_t avnd_comp_clc_inst_clean_hdler(
>               m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, comp, 
> AVND_CKPT_COMP_CONFIG);
>       }
>   
> +done:
>       TRACE_LEAVE();
>       return rc;
>   }
> @@ -1913,10 +1996,21 @@ uint32_t avnd_comp_clc_inst_restart_hdle
>                       avnd_comp_pm_rec_del_all(cb, comp);     /*if at all 
> anythnig is left behind */
>               } else if (m_AVND_COMP_TYPE_IS_SAAWARE(comp) ||
>                          (m_AVND_COMP_TYPE_IS_PROXIED(comp) && 
> m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(comp)))
> -                     /* invoke terminate callback */
> -                     rc = avnd_comp_cbk_send(cb, comp, AVSV_AMF_COMP_TERM, 
> 0, 0);
> +                     if (m_AVND_COMP_IS_RESTART_DIS(comp) && 
> (comp->csi_list.n_nodes > 0)) {
> +                             /* A non-restartable assigned healthy 
> component(DisableRestart=1) and
> +                                context is restart admin op on su or this 
> comp itself,
> +                                first perform reassignment for this 
> component to other SU then term it.
> +                                At present assignment of whole SU will be 
> gracefully reassigned
> +                                instead of only this comp. Thus for PI 
> applications modeled on NWay and
> +                                Nway Active model this is spec deviation.
> +                              */
> +                             /*Send amfd to gracefully remove assignments 
> for thus SU.*/
> +                             su_send_suRestart_recovery_msg(comp->su);
> +                             goto done;
> +                     } else
> +                             /* invoke terminate callback */
> +                             rc = avnd_comp_cbk_send(cb, comp, 
> AVSV_AMF_COMP_TERM, 0, 0);
>               else {
> -                     /* invoke terminate command */
>                       rc = avnd_comp_clc_cmd_execute(cb, comp, 
> AVND_COMP_CLC_CMD_TYPE_TERMINATE);
>                       m_AVND_COMP_REG_PARAM_RESET(cb, comp);
>                       m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, comp, 
> AVND_CKPT_COMP_CONFIG);
> @@ -1933,11 +2027,15 @@ uint32_t avnd_comp_clc_inst_restart_hdle
>   
>               m_AVND_COMP_CLC_INST_PARAM_RESET(comp);
>   
> -             /* transition to 'restarting' state */
> -             avnd_comp_pres_state_set(comp, SA_AMF_PRESENCE_RESTARTING);
> +             /* If DisableRestart=0 then transition to 'restarting' state and
> +                DisableRestart=1 then  transition to 'terminating' state */
> +             if (!m_AVND_COMP_IS_RESTART_DIS(comp))
> +                     avnd_comp_pres_state_set(comp, 
> SA_AMF_PRESENCE_RESTARTING);
> +             else
> +                     avnd_comp_pres_state_set(comp, 
> SA_AMF_PRESENCE_TERMINATING);
>               m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, comp, 
> AVND_CKPT_COMP_CONFIG);
>       }
> -
> +done:
>       TRACE_LEAVE();
>       return rc;
>   }
> @@ -2113,7 +2211,8 @@ uint32_t avnd_comp_clc_terming_cleansucc
>        */
>       if (m_AVND_COMP_IS_FAILED(comp) && m_AVND_SU_IS_FAILED(su) &&
>                       m_AVND_SU_IS_PREINSTANTIABLE(su) && (su->sufailover == 
> false) &&
> -                     (avnd_cb->oper_state != SA_AMF_OPERATIONAL_DISABLED)) {
> +                     (avnd_cb->oper_state != SA_AMF_OPERATIONAL_DISABLED) &&
> +                     (su->su_err_esc_level == AVND_ERR_ESC_LEVEL_2)) {
>               /* yes, request director to orchestrate component failover */
>               rc = avnd_di_oper_send(cb, su, SA_AMF_COMPONENT_FAILOVER);
>       }
> @@ -2169,6 +2268,63 @@ uint32_t avnd_comp_clc_terming_cleanfail
>       return rc;
>   }
>   
> +/**
> + * @brief  handler for instantiating a component in restarting state.
> + *      It will be used during restart admin operation on su.
> + * @param  ptr to avnd_cb.
> + * @param  ptr to comp.
> + * @return NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE.
> + */
> +
> +uint32_t avnd_comp_clc_restart_inst_hdler (AVND_CB *cb, AVND_COMP *comp)
> +{
> +     uint32_t rc = NCSCC_RC_SUCCESS;
> +
> +     TRACE_ENTER2("'%s' : Instantiate event in the restart state", 
> comp->name.value);
> +
> +     /* Refresh the component configuration, it may have changed */
> +     if (!m_AVND_IS_SHUTTING_DOWN(cb) && (avnd_comp_config_reinit(comp) != 
> 0)) {
> +             rc = NCSCC_RC_FAILURE;
> +             goto done;
> +     }
> +     /*if proxied component check whether the proxy exists, if so continue
> +        instantiating by calling the proxied callback. else start timer and
> +        wait for inst timeout duration */
> +     if (m_AVND_COMP_TYPE_IS_PROXIED(comp)) {
> +             if (comp->pxy_comp != NULL) {
> +                     if (m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(comp))
> +                             /* call the proxied instantiate callback   */
> +                             rc = avnd_comp_cbk_send(cb, comp, 
> AVSV_AMF_PXIED_COMP_INST, 0, 0);
> +                     else
> +                             /* do a csi set with active ha state */
> +                             rc = avnd_comp_cbk_send(cb, comp, 
> AVSV_AMF_CSI_SET, 0, 0);
> +                     if (NCSCC_RC_SUCCESS == rc) {
> +                             /* increment the retry count */
> +                             comp->clc_info.inst_retry_cnt++;
> +                             m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, comp, 
> AVND_CKPT_COMP_INST_RETRY_CNT);
> +                     }
> +             } else {
> +                     /* start a timer for proxied instantiating timeout 
> duration */
> +                     m_AVND_TMR_PXIED_COMP_INST_START(cb, *comp, rc);
> +                     m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, comp, 
> AVND_CKPT_COMP_CLC_REG_TMR);
> +             }
> +             goto done;
> +     }
> +
> +     rc = avnd_comp_clc_cmd_execute(cb, comp, 
> AVND_COMP_CLC_CMD_TYPE_INSTANTIATE);
> +     if (NCSCC_RC_SUCCESS == rc) {
> +             /* timestamp the start of this instantiation phase */
> +             m_GET_TIME_STAMP(comp->clc_info.inst_cmd_ts);
> +             m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, comp, 
> AVND_CKPT_COMP_INST_CMD_TS);
> +             /* increment the retry count */
> +             comp->clc_info.inst_retry_cnt++;
> +             m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, comp, 
> AVND_CKPT_COMP_INST_RETRY_CNT);
> +     }
> +done:
> +     TRACE_LEAVE2("%u", rc);
> +     return rc;
> +}
> +
>   
> /****************************************************************************
>     Name          : avnd_comp_clc_restart_instsucc_hdler
>    
> @@ -2277,6 +2433,13 @@ uint32_t avnd_comp_clc_restart_termsucc_
>               m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, comp, 
> AVND_CKPT_COMP_CONFIG);
>       }
>   
> +     if (!(m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(comp)) && 
> m_AVND_SU_IS_PREINSTANTIABLE(comp->su) &&
> +                     (comp->admin_oper == true))
> +             ;
> +     else if (m_AVND_SU_IS_RESTART(comp->su))  {
> +             goto done;
> +     }
> +
>       /* re-instantiate the comp */
>       if (m_AVND_COMP_TYPE_IS_PROXIED(comp) && comp->pxy_comp != 0 && 
> m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(comp))
>               /* proxied pre-instantiable comp */
> diff --git a/osaf/services/saf/amf/amfnd/comp.cc 
> b/osaf/services/saf/amf/amfnd/comp.cc
> --- a/osaf/services/saf/amf/amfnd/comp.cc
> +++ b/osaf/services/saf/amf/amfnd/comp.cc
> @@ -919,18 +919,13 @@ uint32_t avnd_comp_csi_assign(AVND_CB *c
>   
>       /* skip assignments to failed / unregistered comp */
>       if (!m_AVND_SU_IS_RESTART(comp->su) &&
> -         (m_AVND_COMP_IS_FAILED(comp) || 
> (m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(comp) && ((!m_AVND_COMP_IS_REG(comp)
> -                                                                             
>             &&
> -                                                                             
>             !m_AVND_COMP_PRES_STATE_IS_ORPHANED
> -                                                                             
>             (comp))
> -                                                                             
>            ||
> -                                                                             
>            (!m_AVND_COMP_PRES_STATE_IS_INSTANTIATED
> -                                                                             
>             (comp)
> -                                                                             
>             && (comp->su->pres ==
> -                                                                             
>                 SA_AMF_PRESENCE_INSTANTIATION_FAILED)
> -                                                                             
>             &&
> -                                                                             
>             !m_AVND_COMP_PRES_STATE_IS_ORPHANED
> -                                                                             
>             (comp)))))) {
> +         (m_AVND_COMP_IS_FAILED(comp) ||
> +          (m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(comp) &&
> +           ((!m_AVND_COMP_IS_REG(comp) && 
> !m_AVND_COMP_PRES_STATE_IS_ORPHANED (comp)) ||
> +            (!m_AVND_COMP_PRES_STATE_IS_INSTANTIATED(comp) &&
> +             (comp->su->pres == SA_AMF_PRESENCE_INSTANTIATION_FAILED) &&
> +             !m_AVND_COMP_PRES_STATE_IS_ORPHANED (comp)))))) {
> +             TRACE("Not suRestart context and comp is failed or 
> unregistered");
>               /* dont skip restarting components. wait till restart is 
> complete */
>               if ((comp->pres == SA_AMF_PRESENCE_RESTARTING) && 
> m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(comp)) {  /* mark the csi(s) assigned */
>                       if (csi) {
> @@ -967,6 +962,32 @@ uint32_t avnd_comp_csi_assign(AVND_CB *c
>                       rc = avnd_comp_csi_assign_done(cb, comp, csi);
>                       goto done;
>               }
> +     } else if (m_AVND_SU_IS_RESTART(comp->su) && 
> (su_all_comps_restartable(*comp->su) == false) &&
> +                     (m_AVND_COMP_IS_FAILED(comp) || (comp->pres == 
> SA_AMF_PRESENCE_UNINSTANTIATED))) {
> +             /* In surestart recovery of non restartable su, assignment 
> (quiesced) done indication
> +                   will be done for a failed component or for the component 
> which is already cleaned up.
> +              */
> +             TRACE("In suRestart recovery or admin op context");
> +             if (csi) {
> +                     TRACE("'%s'", csi->name.value);
> +                     m_AVND_COMP_CSI_CURR_ASSIGN_STATE_SET(csi, 
> AVND_COMP_CSI_ASSIGN_STATE_ASSIGNING);
> +                     m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, csi, 
> AVND_CKPT_COMP_CSI_CURR_ASSIGN_STATE);
> +             } else {
> +                     m_AVND_COMP_ALL_CSI_SET(comp);
> +                     m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, comp, 
> AVND_CKPT_COMP_FLAG_CHANGE);
> +                     for (curr_csi =
> +                             
> m_AVND_CSI_REC_FROM_COMP_DLL_NODE_GET(m_NCS_DBLIST_FIND_FIRST(&comp->csi_list));
> +                             curr_csi;
> +                             curr_csi = 
> m_AVND_CSI_REC_FROM_COMP_DLL_NODE_GET(m_NCS_DBLIST_FIND_NEXT
> +                                             (&curr_csi->comp_dll_node))) {
> +                             m_AVND_COMP_CSI_CURR_ASSIGN_STATE_SET(curr_csi,
> +                                             
> AVND_COMP_CSI_ASSIGN_STATE_ASSIGNING);
> +                             m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, curr_csi,
> +                                             
> AVND_CKPT_COMP_CSI_CURR_ASSIGN_STATE);
> +                     }
> +             }
> +             rc = avnd_comp_csi_assign_done(cb, comp, csi);
> +             goto done;
>       }
>   
>       /* skip standby assignment to x_active or 1_active capable comp */
> @@ -1108,19 +1129,28 @@ uint32_t avnd_comp_csi_assign(AVND_CB *c
>                  other way of doing it is to change the csi to assign state 
> in failover error
>                  processing after restart.
>                */
> -
> +             
> TRACE("npi_prv_inst:%d,npi_curr_inst:%d",npi_prv_inst,npi_curr_inst);
>               /* Active Assigning --> quiesced,  quiescing --> quiesced */
>               if (!m_AVND_COMP_CSI_PRV_ASSIGN_STATE_IS_ASSIGNED(curr_csi) &&
>                   ((comp->pres == SA_AMF_PRESENCE_INSTANTIATED) || 
> (comp->pres == SA_AMF_PRESENCE_INSTANTIATING) ||
>                    (comp->pres == SA_AMF_PRESENCE_TERMINATING) || (comp->pres 
> == SA_AMF_PRESENCE_RESTARTING)))
>                       npi_prv_inst = true;
> +             
> TRACE("npi_prv_inst:%d,npi_curr_inst:%d",npi_prv_inst,npi_curr_inst);
>   
>               /* determine the event for comp fsm */
>               if (m_AVND_SU_IS_RESTART(comp->su) && (true == npi_curr_inst))
> -                     comp_ev = AVND_COMP_CLC_PRES_FSM_EV_RESTART;
> +                     comp_ev = AVND_COMP_CLC_PRES_FSM_EV_INST;
>               else if (!m_AVND_SU_IS_RESTART(comp->su) && (npi_prv_inst != 
> npi_curr_inst))
>                       comp_ev = (true == npi_curr_inst) ? 
> AVND_COMP_CLC_PRES_FSM_EV_INST :
>                           AVND_COMP_CLC_PRES_FSM_EV_TERM;
> +             else if (m_AVND_SU_IS_RESTART(comp->su) && 
> (su_all_comps_restartable(*comp->su) == false) &&
> +                                (npi_curr_inst == false)) {
> +                        /*suRestart is going on and SU has atleast one 
> component non-restartable.*/
> +                        TRACE("suRestart is going on for a non-restartable 
> SU,"
> +                                        "  terminate this component for 
> quiesced state.");
> +                        comp_ev = AVND_COMP_CLC_PRES_FSM_EV_TERM;
> +                }
> +
>   
>               /* mark the csi state assigning */
>               m_AVND_COMP_CSI_CURR_ASSIGN_STATE_SET(curr_csi, 
> AVND_COMP_CSI_ASSIGN_STATE_ASSIGNING);
> diff --git a/osaf/services/saf/amf/amfnd/compdb.cc 
> b/osaf/services/saf/amf/amfnd/compdb.cc
> --- a/osaf/services/saf/amf/amfnd/compdb.cc
> +++ b/osaf/services/saf/amf/amfnd/compdb.cc
> @@ -1781,6 +1781,7 @@ static AVND_COMP *avnd_comp_create(const
>   
>       comp->su = su;
>       comp->error_report_sent = false;
> +     comp->admin_oper = false;
>   
>       if (true == su->su_is_external) {
>               m_AVND_COMP_TYPE_SET_EXT_CLUSTER(comp);
> diff --git a/osaf/services/saf/amf/amfnd/err.cc 
> b/osaf/services/saf/amf/amfnd/err.cc
> --- a/osaf/services/saf/amf/amfnd/err.cc
> +++ b/osaf/services/saf/amf/amfnd/err.cc
> @@ -548,7 +548,8 @@ uint32_t avnd_err_recover(AVND_CB *cb, A
>          other than these, then clean the component and don't process any 
> recovery for that
>          component. */
>       if ((su->pres == SA_AMF_PRESENCE_TERMINATING) && (rcvr != 
> SA_AMF_NODE_FAILOVER)
> -         && (rcvr != SA_AMF_NODE_FAILFAST) && (rcvr != 
> SA_AMF_NODE_SWITCHOVER)) {
> +         && (rcvr != SA_AMF_NODE_FAILFAST) && (rcvr != 
> SA_AMF_NODE_SWITCHOVER) &&
> +         (rcvr != AVSV_ERR_RCVR_SU_FAILOVER)) {
>               /* mark the comp failed */
>               m_AVND_COMP_FAILED_SET(comp);
>               m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, comp, 
> AVND_CKPT_COMP_FLAG_CHANGE);
> @@ -663,22 +664,6 @@ uint32_t avnd_err_rcvr_su_restart(AVND_C
>       m_AVND_COMP_FAILED_SET(failed_comp);
>       m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, failed_comp, 
> AVND_CKPT_COMP_FLAG_CHANGE);
>   
> -     /* delete su current info */
> -     rc = avnd_su_curr_info_del(cb, su);
> -     if (NCSCC_RC_SUCCESS != rc)
> -             goto done;
> -
> -     /* prepare su-sis for fresh assignment */
> -     rc = avnd_su_si_unmark(cb, su);
> -     if (NCSCC_RC_SUCCESS != rc)
> -             goto done;
> -
> -     /*
> -      * Trigger su-fsm with restart event.
> -      */
> -     rc = avnd_su_pres_fsm_run(cb, su, 0, AVND_SU_PRES_FSM_EV_RESTART);
> -     if (NCSCC_RC_SUCCESS != rc)
> -             goto done;
>   
>       /* change the comp & su oper state to disabled */
>       m_AVND_SU_OPER_STATE_SET(su, SA_AMF_OPERATIONAL_DISABLED);
> @@ -687,12 +672,70 @@ uint32_t avnd_err_rcvr_su_restart(AVND_C
>       m_AVND_COMP_OPER_STATE_AVD_SYNC(cb, failed_comp, rc);
>       if (NCSCC_RC_SUCCESS != rc)
>               goto done;
> +
>       m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, failed_comp, 
> AVND_CKPT_COMP_OPER_STATE);
> -
> -     /* finally... set su-restart flag */
> -     m_AVND_SU_RESTART_SET(su);
> +     set_suRestart_flag(su);
>       m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, su, AVND_CKPT_SU_FLAG_CHANGE);
>   
> +     if (su_all_comps_restartable(*su) == true) {
> +             /* Case 1: All components in SU are restartable
> +                        (saAmfCompDisableRestart is false for all).
> +                In this case surestart recovery involves two steps:
> +                a) First, all components in the SU are abruptly terminated 
> in the
> +                   reverse order of their instantiation-levels.
> +                b) In a second step, all components in the SU are 
> instantiated
> +                   in the order dictated by their instantiation-levels.
> +             
> +                Also if the components have assignments, same assignments 
> will be
> +                reassigned to respective components after successful restart 
> of SU.
> +                In this case, only restarting state of the component will be 
> observed.
> +                     
> +             */
> +             //So prepare su-sis for fresh assignment.
> +             rc = avnd_su_curr_info_del(cb, su);
> +             if (NCSCC_RC_SUCCESS != rc)
> +                     goto done;
> +             rc = avnd_su_si_unmark(cb, su);
> +             if (NCSCC_RC_SUCCESS != rc)
> +                     goto done;
> +             rc = avnd_su_pres_fsm_run(cb, su, 0, 
> AVND_SU_PRES_FSM_EV_RESTART);
> +             if (NCSCC_RC_SUCCESS != rc)
> +                     goto done;
> +     } else {
> +             /* Case 2: Atleast one component in SU is non restartable
> +                        (saAmfCompDisableRestart is true for atleast one 
> comp in SU).
> +             In this case, all components in the SU are abruptly terminated 
> in the
> +             reverse order of their instantiation-levels. Since aleast one 
> of the
> +             components is non restartable, first reassign the CSIs 
> currently assigned
> +             to non restartable component to another component before 
> terminating/instantiating
> +             the components. Since a component may be serving any redundancy 
> model, the
> +             process of reassignment depends upon the redundancy model 
> characteristics.
> +     
> +             At the same time, reassignment of CSIs from this 
> non-restartable component
> +             may lead to reassignment of CSIs from other components 
> (non-restartable and
> +             restartable) in this SU as the same SI may have assignments in 
> those components.
> +             In current OpenSAF implementation, such a case of comp-failover 
> is implemented
> +             as switchover of all the assignments from the whole SU 
> irrespective of redundancy
> +             model. As of now, this case will work like OpenSAF 
> comp-failover only.
> +
> +             TODO:In future when AMF supports comp-failover in spec 
> compliance then this
> +                     case should be alligned with that.
> +             */
> +             if (m_AVND_SU_IS_PREINSTANTIABLE(su)) {
> +                     if (m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(failed_comp))
> +                             rc = avnd_comp_clc_fsm_run(cb, failed_comp, 
> AVND_COMP_CLC_PRES_FSM_EV_CLEANUP);
> +                     else
> +                             rc = avnd_su_pres_fsm_run(cb, su, 0, 
> AVND_SU_PRES_FSM_EV_RESTART);
> +                     if (NCSCC_RC_SUCCESS != rc)
> +                             goto done;
> +             } else {
> +                     /*In NPI SU only one SI is assigned to the whole SU. 
> Since SU has atleast
> +                       one component non-restartable then request AMFD to 
> start switchover of this SU.
> +                       As a part of quieced assignment, clean up will be 
> done.
> +                      */
> +                     su_send_suRestart_recovery_msg(su);
> +             }
> +     }
>    done:
>       TRACE_LEAVE2("%u", rc);
>       return rc;
> @@ -734,11 +777,9 @@ uint32_t avnd_err_rcvr_comp_failover(AVN
>       m_AVND_SU_OPER_STATE_SET(su, SA_AMF_OPERATIONAL_DISABLED);
>       m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, su, AVND_CKPT_SU_OPER_STATE);
>   
> -     /* We are now in the context of failover, forget the restart */
> -     if (su->pres == SA_AMF_PRESENCE_RESTARTING || m_AVND_SU_IS_RESTART(su)) 
> {
> -             m_AVND_SU_RESTART_RESET(su);
> -             m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, su, 
> AVND_CKPT_SU_FLAG_CHANGE);
> -     }
> +     /* We are now in the context of failover, forget the reset restart 
> admin op id*/
> +     if (m_AVND_SU_IS_RESTART(su))
> +             su->admin_op_Id = static_cast<SaAmfAdminOperationIdT>(0);
>   
>       // TODO: there should be no difference between PI/NPI comps
>       if (m_AVND_SU_IS_PREINSTANTIABLE(su)) {
> @@ -777,6 +818,12 @@ uint32_t avnd_err_rcvr_su_failover(AVND_
>       m_AVND_SU_FAILED_SET(su);
>       m_AVND_SU_OPER_STATE_SET(su, SA_AMF_OPERATIONAL_DISABLED);
>   
> +     /* We are now in the context of failover, forget the restart */
> +     if (m_AVND_SU_IS_RESTART(su)) {
> +             reset_suRestart_flag(su);
> +             su->admin_op_Id = static_cast<SaAmfAdminOperationIdT>(0);
> +             m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, su, 
> AVND_CKPT_SU_FLAG_CHANGE);
> +     }
>       LOG_NO("Terminating components of '%s'(abruptly & 
> unordered)",su->name.value);
>       /* Unordered cleanup of components of failed SU */
>       for (comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_FIRST(&su->comp_list));
> @@ -790,6 +837,7 @@ uint32_t avnd_err_rcvr_su_failover(AVND_
>                       LOG_ER("'%s' termination failed", comp->name.value);
>                       goto done;
>               }
> +             avnd_su_pres_state_set(comp->su, SA_AMF_PRESENCE_TERMINATING);
>       }
>   done:
>   
> @@ -850,11 +898,9 @@ uint32_t avnd_err_rcvr_node_switchover(A
>               cb->oper_state = SA_AMF_OPERATIONAL_DISABLED;
>       }
>   
> -     /* We are now in the context of failover, forget the restart */
> -     if (failed_su->pres == SA_AMF_PRESENCE_RESTARTING || 
> m_AVND_SU_IS_RESTART(failed_su)) {
> -             m_AVND_SU_RESTART_RESET(failed_su);
> -             m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, failed_su, 
> AVND_CKPT_SU_FLAG_CHANGE);
> -     }
> +     /* We are now in the context of failover, forget the reset restart 
> admin op id*/
> +     if (m_AVND_SU_IS_RESTART(failed_su))
> +             failed_su->admin_op_Id = static_cast<SaAmfAdminOperationIdT>(0);
>   
>       /* In nodeswitchover context:
>          a)If saAmfSUFailover is set for the faulted SU then this SU will be 
> failed-over
> @@ -869,6 +915,10 @@ uint32_t avnd_err_rcvr_node_switchover(A
>        */
>       if (m_AVND_SU_IS_FAILED(failed_comp->su) && 
> (failed_comp->su->sufailover))
>       {
> +             reset_suRestart_flag(failed_su);
> +             failed_su->admin_op_Id = static_cast<SaAmfAdminOperationIdT>(0);
> +             m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, failed_su, 
> AVND_CKPT_SU_FLAG_CHANGE);
> +
>               LOG_NO("Terminating components of '%s'(abruptly & 
> unordered)",failed_su->name.value);
>               /* Unordered cleanup of components of failed SU */
>               for (comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_FIRST(&failed_su->comp_list));
> @@ -882,6 +932,7 @@ uint32_t avnd_err_rcvr_node_switchover(A
>                               LOG_ER("'%s' termination failed", 
> comp->name.value);
>                               goto done;
>                       }
> +                     avnd_su_pres_state_set(failed_comp->su, 
> SA_AMF_PRESENCE_TERMINATING);
>               }
>       }
>       else {
> @@ -933,6 +984,12 @@ uint32_t avnd_err_rcvr_node_failover(AVN
>       m_AVND_SU_FAILED_SET(failed_su);
>       m_AVND_SU_OPER_STATE_SET(failed_su, SA_AMF_OPERATIONAL_DISABLED);
>   
> +     /* We are now in the context of failover, forget the restart */
> +     if (m_AVND_SU_IS_RESTART(failed_su)) {
> +             reset_suRestart_flag(failed_su);
> +             failed_su->admin_op_Id = static_cast<SaAmfAdminOperationIdT>(0);
> +             m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, failed_su, 
> AVND_CKPT_SU_FLAG_CHANGE);
> +     }
>       /* Unordered cleanup of all local application components */
>       for (comp = (AVND_COMP *)ncs_patricia_tree_getnext(&cb->compdb, 
> (uint8_t *)NULL);
>                 comp != NULL;
> @@ -950,6 +1007,7 @@ uint32_t avnd_err_rcvr_node_failover(AVN
>                       LOG_ER("Exiting (due to comp term failed) to aid fast 
> node reboot");
>                       exit(1);
>               }
> +             avnd_su_pres_state_set(comp->su, SA_AMF_PRESENCE_TERMINATING);
>       }
>   
>       TRACE_LEAVE2("%u", rc);
> @@ -1189,6 +1247,7 @@ uint32_t avnd_err_restart_esc_level_1(AV
>       /* If the SU is still instantiating, do jump to next level */
>       if (su->pres == SA_AMF_PRESENCE_INSTANTIATING || su->pres == 
> SA_AMF_PRESENCE_RESTARTING
>           || m_AVND_SU_IS_ASSIGN_PEND(su)) {
> +             TRACE("Further escalating surestart recovery");
>               /* go to the next possible level, get escalated recovery and 
> modify count */
>               if ((cb->su_failover_max != 0) || (true == su->su_is_external)) 
> {
>                       /* External component should not contribute to NODE 
> FAILOVER of cluster
> @@ -1494,3 +1553,32 @@ uint32_t avnd_err_rcvr_node_failfast(AVN
>       TRACE_LEAVE2("%u", rc);
>       return rc;
>   }
> +
> +/**
> + * @brief  In escalation of level 2 (sufailover), level 3(nodefailover) and
> + *         nodeswitchover when failed su is sufailover capable, cleanup of
> + *         all components of su or node will be done.
> + *      A a exception, assignments are responded when a SU enters in
> + *         inst_failed state.
> + *         This function return true if such a escalation exists or failed su
> + *         is in inst_failed state.
> + * @param  ptr to su.
> + * @return true/false.
> + */
> +bool is_no_assignment_due_to_escalations(AVND_SU *su)
> +{
> +     TRACE_ENTER();
> +     if (((sufailover_in_progress(su) == true) && (su->su_err_esc_level == 
> AVND_ERR_ESC_LEVEL_2)) ||
> +                     (sufailover_during_nodeswitchover(su) == true) ||
> +                     (avnd_cb->term_state == 
> AVND_TERM_STATE_NODE_FAILOVER_TERMINATING) ||
> +                     (avnd_cb->term_state == 
> AVND_TERM_STATE_NODE_FAILOVER_TERMINATED))  {
> +             TRACE_LEAVE2("true");
> +             return true;
> +     }
> +     if (su->pres == SA_AMF_PRESENCE_INSTANTIATION_FAILED) {
> +             TRACE_LEAVE2("false");
> +             return false;
> +     }
> +     TRACE_LEAVE2("false");
> +     return false;
> +}
> diff --git a/osaf/services/saf/amf/amfnd/include/avnd_err.h 
> b/osaf/services/saf/amf/amfnd/include/avnd_err.h
> --- a/osaf/services/saf/amf/amfnd/include/avnd_err.h
> +++ b/osaf/services/saf/amf/amfnd/include/avnd_err.h
> @@ -115,5 +115,6 @@ struct avnd_su_tag;
>   
>   extern uint32_t avnd_err_process(struct avnd_cb_tag *, struct avnd_comp_tag 
> *, AVND_ERR_INFO *);
>   extern uint32_t avnd_err_su_repair(struct avnd_cb_tag *, struct avnd_su_tag 
> *);
> +extern bool is_no_assignment_due_to_escalations( struct avnd_su_tag *);
>   
>   #endif   /* !AVND_ERR_H */
> diff --git a/osaf/services/saf/amf/amfnd/include/avnd_su.h 
> b/osaf/services/saf/amf/amfnd/include/avnd_su.h
> --- a/osaf/services/saf/amf/amfnd/include/avnd_su.h
> +++ b/osaf/services/saf/amf/amfnd/include/avnd_su.h
> @@ -160,6 +160,7 @@ typedef struct avnd_su_tag {
>   
>       /* To maintain saAmfSUFailover attribute of SU classs at Amfnd. */
>       bool sufailover; /* sufailover is enabled or not for the SU. */
> +     SaAmfAdminOperationIdT admin_op_Id; //flag to track admin operation on 
> su.
>   
>   } AVND_SU;
>   
> @@ -411,5 +412,10 @@ extern bool all_comps_terminated_in_su(c
>   
>   void su_increment_su_restart_count(AVND_SU& su);
>   void su_increment_comp_restart_count(AVND_SU& su);
> -
> +void set_suRestart_flag(AVND_SU *su);
> +void reset_suRestart_flag(AVND_SU *su);
> +bool su_all_comps_restartable(const AVND_SU& su);
> +void su_send_suRestart_recovery_msg(AVND_SU *su);
> +bool pi_su_all_comps_uninstantiated (const AVND_SU& su);
> +bool is_any_non_restartable_comp_assigned(const AVND_SU& su);
>   #endif
> diff --git a/osaf/services/saf/amf/amfnd/su.cc 
> b/osaf/services/saf/amf/amfnd/su.cc
> --- a/osaf/services/saf/amf/amfnd/su.cc
> +++ b/osaf/services/saf/amf/amfnd/su.cc
> @@ -580,7 +580,7 @@ uint32_t avnd_su_curr_info_del(AVND_CB *
>               /* stop su_err_esc_tmr TBD Later */
>   
>               /* disable the oper state (if pi su) */
> -             if (m_AVND_SU_IS_PREINSTANTIABLE(su)) {
> +             if (m_AVND_SU_IS_PREINSTANTIABLE(su) && (su->admin_op_Id != 
> SA_AMF_ADMIN_RESTART)) {
>                       m_AVND_SU_OPER_STATE_SET(su, 
> SA_AMF_OPERATIONAL_DISABLED);
>                       m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, su, 
> AVND_CKPT_SU_OPER_STATE);
>               }
> @@ -646,6 +646,7 @@ uint32_t avnd_evt_su_admin_op_req(AVND_C
>                     comp;
>                     comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_NEXT(&comp->su_dll_node))) 
> {
>   
> +                     comp->admin_oper = false;
>                       m_AVND_COMP_STATE_RESET(comp);
>                       avnd_comp_pres_state_set(comp, 
> SA_AMF_PRESENCE_UNINSTANTIATED);
>                       
> @@ -657,6 +658,8 @@ uint32_t avnd_evt_su_admin_op_req(AVND_C
>                               (comp_in_term_failed_state() == false))
>                       avnd_failed_state_file_delete();
>   
> +             su->admin_op_Id = static_cast<SaAmfAdminOperationIdT>(0);
> +             reset_suRestart_flag(su);
>               m_AVND_SU_STATE_RESET(su);
>               m_AVND_SU_OPER_STATE_SET(su, SA_AMF_OPERATIONAL_ENABLED);
>               avnd_di_uns32_upd_send(AVSV_SA_AMF_SU, saAmfSUOperState_ID, 
> &su->name, su->oper);
> @@ -726,3 +729,56 @@ void cb_increment_su_failover_count(AVND
>       LOG_NO("Performing failover of '%s' (SU failover count: %u)",
>               su.name.value, cb.su_failover_cnt);     
>   }
> +void set_suRestart_flag(AVND_SU *su)
> +{
> +     TRACE("suRestart flag set for '%s'",su->name.value);
> +     m_AVND_SU_RESTART_SET(su);
> +     
> +}
> +void reset_suRestart_flag(AVND_SU *su)
> +{
> +     TRACE("suRestart flag reset for '%s'",su->name.value);
> +     m_AVND_SU_RESTART_RESET(su);
> +}
> +bool su_all_comps_restartable(const AVND_SU& su)
> +{
> +     for (AVND_COMP *comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_FIRST(&su.comp_list));
> +             comp;
> +             comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_NEXT(&comp->su_dll_node))) 
> {
> +             if (m_AVND_COMP_IS_RESTART_DIS(comp))
> +                     return false;
> +     }
> +     return true;
> +}
> +void su_send_suRestart_recovery_msg(AVND_SU *su)
> +{
> +     su->oper = SA_AMF_OPERATIONAL_ENABLED;  
> +     //Keep the su enabled for sending the message.
> +     avnd_di_oper_send(avnd_cb, su, AVSV_ERR_RCVR_SU_RESTART);
> +     su->oper = SA_AMF_OPERATIONAL_DISABLED; 
> +}
> +
> +bool pi_su_all_comps_uninstantiated (const AVND_SU& su)
> +{
> +     for (AVND_COMP *comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_FIRST(&su.comp_list));
> +                     comp;
> +                     comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_NEXT(&comp->su_dll_node))) 
> {
> +             if ((comp->pres != SA_AMF_PRESENCE_UNINSTANTIATED) &&
> +                             (m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(comp)))
> +                     return false;
> +     }
> +     return true;
> +}
> +
> +bool is_any_non_restartable_comp_assigned(const AVND_SU& su)
> +{
> +     for (AVND_COMP *comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_FIRST(&su.comp_list));
> +                     comp;
> +                     comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_NEXT(&comp->su_dll_node))) 
> {
> +                if ((m_AVND_COMP_IS_RESTART_DIS(comp)) &&
> +                                (comp->csi_list.n_nodes > 0))
> +                        return true;
> +        }
> +        return false;
> +}
> +
> diff --git a/osaf/services/saf/amf/amfnd/susm.cc 
> b/osaf/services/saf/amf/amfnd/susm.cc
> --- a/osaf/services/saf/amf/amfnd/susm.cc
> +++ b/osaf/services/saf/amf/amfnd/susm.cc
> @@ -48,7 +48,11 @@ static uint32_t avnd_su_pres_inst_compte
>   static uint32_t avnd_su_pres_terming_compinst_hdler(AVND_CB *, AVND_SU *, 
> AVND_COMP *);
>   static uint32_t avnd_su_pres_terming_comptermfail_hdler(AVND_CB *, AVND_SU 
> *, AVND_COMP *);
>   static uint32_t avnd_su_pres_terming_compuninst_hdler(AVND_CB *, AVND_SU *, 
> AVND_COMP *);
> +static uint32_t avnd_su_pres_terming_comprestart_hdler(AVND_CB *cb, AVND_SU 
> *su, AVND_COMP *comp);
> +static uint32_t avnd_su_pres_terming_suinst_hdler(AVND_CB *cb, AVND_SU *su, 
> AVND_COMP *comp);
> +static uint32_t avnd_su_pres_terming_surestart_hdler (AVND_CB *cb, AVND_SU 
> *su, AVND_COMP *comp);
>   static uint32_t avnd_su_pres_restart_suterm_hdler(AVND_CB *, AVND_SU *, 
> AVND_COMP *);
> +static uint32_t avnd_su_pres_restart_comprestart_hdler(AVND_CB *, AVND_SU *, 
> AVND_COMP *);
>   static uint32_t avnd_su_pres_restart_compinst_hdler(AVND_CB *, AVND_SU *, 
> AVND_COMP *);
>   static uint32_t avnd_su_pres_restart_compterming_hdler(AVND_CB *, AVND_SU 
> *, AVND_COMP *);
>   static uint32_t avnd_su_pres_inst_compinstfail_hdler(AVND_CB *, AVND_SU *, 
> AVND_COMP *);
> @@ -102,12 +106,12 @@ static AVND_SU_PRES_FSM_FN avnd_su_pres_
>   
>       /* SA_AMF_PRESENCE_TERMINATING */
>       {
> -      0,                     /* SU INST */
> +      avnd_su_pres_terming_suinst_hdler,                     /* SU INST */
>        avnd_su_pres_restart_suterm_hdler,     /* SU TERM */
> -      0,                     /* SU RESTART */
> +      avnd_su_pres_terming_surestart_hdler,  /* SU RESTART */
>        avnd_su_pres_terming_compinst_hdler,   /* COMP INSTANTIATED */
>        avnd_su_pres_inst_compinstfail_hdler,  /* COMP INST_FAIL */
> -      0,                     /* COMP RESTARTING */
> +      avnd_su_pres_terming_comprestart_hdler, /* COMP RESTARTING */
>        avnd_su_pres_terming_comptermfail_hdler,       /* COMP TERM_FAIL */
>        avnd_su_pres_terming_compuninst_hdler, /* COMP UNINSTANTIATED */
>        0,                     /* COMP TERMINATING */
> @@ -120,7 +124,7 @@ static AVND_SU_PRES_FSM_FN avnd_su_pres_
>        0,                     /* SU RESTART */
>        avnd_su_pres_restart_compinst_hdler,   /* COMP INSTANTIATED */
>        avnd_su_pres_inst_compinstfail_hdler,  /* COMP INST_FAIL */
> -      0,                     /* COMP RESTARTING */
> +      avnd_su_pres_restart_comprestart_hdler,/* COMP RESTARTING */
>        avnd_su_pres_terming_comptermfail_hdler,       /* COMP TERM_FAIL */
>        0,                     /* COMP UNINSTANTIATED */
>        avnd_su_pres_restart_compterming_hdler,        /* COMP TERMINATING */
> @@ -184,7 +188,7 @@ AVND_SU_SIQ_REC *avnd_su_siq_rec_buf(AVN
>   
>       /* buffer the msg, if SU is inst-failed and all comps are not 
> terminated */
>       if (((su->pres == SA_AMF_PRESENCE_INSTANTIATION_FAILED) && 
> (!m_AVND_SU_IS_ALL_TERM(su))) ||
> -         m_AVND_IS_SHUTTING_DOWN(cb) || (m_AVND_SU_IS_RESTART(su))) {
> +         m_AVND_IS_SHUTTING_DOWN(cb)) {
>               siq = avnd_su_siq_rec_add(cb, su, param, &rc);
>               TRACE_LEAVE();
>               return siq;
> @@ -580,19 +584,38 @@ static uint32_t assign_si_to_su(AVND_SU_
>   
>               /* determine the instantiation state of npi su */
>               if (SA_AMF_HA_ACTIVE != si->prv_state)
> +                     //If previous state was not active, it means SU was not 
> instantiated.
>                       npi_prv_inst = false;
>               if (SA_AMF_HA_ACTIVE != si->curr_state)
> +                     /*If current state, that has come from AMFD, is not 
> active, then also this NPI SU
> +                       is not going to be instantiated.*/
>                       npi_curr_inst = false;
>   
>               /* Quiesced while Quiescing */
> -             if (m_AVND_SU_SI_PRV_ASSIGN_STATE_IS_ASSIGNING(si) && 
> (SA_AMF_HA_QUIESCING == si->prv_state))
> +             if (m_AVND_SU_SI_PRV_ASSIGN_STATE_IS_ASSIGNING(si) && 
> (SA_AMF_HA_QUIESCING == si->prv_state))
> +                     /*I guess this condition is for the situation when 
> shutdown operation is going
> +                        on and lock is issued over it.*/
>                       npi_prv_inst = true;
>   
>               /* determine the event for the su fsm */
> -             if (m_AVND_SU_IS_RESTART(su) && (true == npi_curr_inst))
> +             if (m_AVND_SU_IS_RESTART(su) && (true == npi_curr_inst))
> +                     /* This seems to be a doubtful if block.
> +                           Active state has come when su restart is going on.
> +                        This can never happen as NPI su gets only one SI.
> +                      */
>                       su_ev = AVND_SU_PRES_FSM_EV_RESTART;
>               else if (!m_AVND_SU_IS_RESTART(su) && (npi_prv_inst != 
> npi_curr_inst))
> +                     /* When surestart is not going on and quiesced 
> assignments or active
> +                        state has come. */
>                       su_ev = (true == npi_curr_inst) ? 
> AVND_SU_PRES_FSM_EV_INST : AVND_SU_PRES_FSM_EV_TERM;
> +             else if (m_AVND_SU_IS_RESTART(su) && 
> (su_all_comps_restartable(*su) == false) &&
> +                             (npi_curr_inst == false)) {
> +                     /*suRestart is going on and SU has atleast one 
> component non-restartable.*/
> +                     TRACE("suRestart is going on for a non-restartable SU,"
> +                                     "  terminate all the components for 
> quiesced state.");
> +                     su_ev = AVND_SU_PRES_FSM_EV_RESTART;
> +             }
> +                     
>   
>               /* we cant do anything on inst-failed SU or term-failed SU, so 
> just resp success for quiesced */
>               if (su->pres == SA_AMF_PRESENCE_INSTANTIATION_FAILED || 
> su->pres == SA_AMF_PRESENCE_TERMINATION_FAILED)
> @@ -937,6 +960,58 @@ static bool all_sis_atrank_removed(const
>       return true;
>   }
>   
> +/**
> + * @brief  This function resets surestart escalation or restart admin op 
> params
> + *         for a restartable su. For a non restartable SU, it will resume 
> surestart
> + *         escalation or recovery when assignments are gracefully removed.
> + * @param  ptr to su.
> + */
> +static void su_finish_suRestart_escalation_or_admin_op(AVND_SU *su)
> +{
> +     bool are_si_assigned;
> +     TRACE_ENTER2("'%s'",su->name.value);
> +     if ((su_all_comps_restartable(*su) == true) || 
> ((is_any_non_restartable_comp_assigned(*su) == false)
> +                             && (!m_AVND_SU_IS_FAILED(su)))) {
> +             TRACE("All the components restartable or non restartable comps 
> are not assigned.");
> +             m_AVND_SU_ARE_ALL_SI_ASSIGNED(su, are_si_assigned);
> +             if (true == are_si_assigned) {
> +                     TRACE("All SIs are reassigned after suRestart 
> escalation or admin op,"
> +                                     " so resetting the suRestart flag.");
> +                     reset_suRestart_flag(su);
> +                     m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, su, 
> AVND_CKPT_SU_FLAG_CHANGE);
> +             }
> +     } else {
> +             TRACE("SU has atleast one non-restartable (DisbaleRestart = 1) 
> assigned component");
> +             if (su->si_list.n_nodes > 0) {
> +                     TRACE("Can't resume termination/clean up of components 
> as some of them"
> +                                     " still have assignments.");
> +             } else {
> +                     TRACE("Graceful removal of assignments from components 
> of this"
> +                                     " SU completed.");
> +                     if (m_AVND_SU_IS_PREINSTANTIABLE(su)) {
> +                             TRACE("PI SU");
> +                             if (su->pres == SA_AMF_PRESENCE_TERMINATING) {
> +                                     TRACE("PI SU: Resume termination/clean 
> up of component honoring"
> +                                                     " their instantiation 
> level in reverse order.");
> +                                     avnd_su_pres_fsm_run(avnd_cb, su, 0, 
> AVND_SU_PRES_FSM_EV_RESTART);
> +                             }
> +                             if (su->pres == SA_AMF_PRESENCE_UNINSTANTIATED) 
> {
> +                                     TRACE("PI SU: Instantiate SU honoring 
> instantiation level");
> +                                     m_AVND_SU_FAILED_RESET(su);
> +                                     reset_suRestart_flag(su);
> +                                     avnd_su_pres_fsm_run(avnd_cb, su, 0, 
> AVND_SU_PRES_FSM_EV_INST);
> +                             }
> +                     } else {
> +                             TRACE("NPI SU");
> +                             m_AVND_SU_FAILED_RESET(su);
> +                             reset_suRestart_flag(su);
> +                             if (su->pres == SA_AMF_PRESENCE_UNINSTANTIATED)
> +                                     avnd_di_oper_send(avnd_cb, su, 0);
> +                     }
> +             }
> +     }
> +     TRACE_LEAVE();
> +}
>   
> /****************************************************************************
>     Name          : avnd_su_si_oper_done
>    
> @@ -961,7 +1036,6 @@ uint32_t avnd_su_si_oper_done(AVND_CB *c
>   {
>       AVND_SU_SI_REC *curr_si = 0;
>       AVND_COMP_CSI_REC *curr_csi = 0, *t_csi = 0;
> -     bool are_si_assigned;
>       uint32_t rc = NCSCC_RC_SUCCESS;
>       bool opr_done;
>   
> @@ -1015,8 +1089,13 @@ uint32_t avnd_su_si_oper_done(AVND_CB *c
>               }
>       } /* for */
>   
> -     /* inform AvD */
> -     if (opr_done && !m_AVND_SU_IS_RESTART(su)) {
> +     /* Inform AMFD when assign are over. During surestart only for non 
> restartable SU we
> +        need to inform AMFD.*/
> +     if (opr_done && ((!(m_AVND_SU_IS_RESTART(su))) ||
> +                             (m_AVND_SU_IS_RESTART(su) &&
> +                              (su_all_comps_restartable(*su) == false) &&
> +                              (is_any_non_restartable_comp_assigned(*su) == 
> true))) &&
> +                     (is_no_assignment_due_to_escalations(su) == false)) {
>               rc = avnd_di_susi_resp_send(cb, su, m_AVND_SU_IS_ALL_SI(su) ? 
> NULL : si);
>               if (NCSCC_RC_SUCCESS != rc)
>                       goto done;
> @@ -1089,7 +1168,7 @@ uint32_t avnd_su_si_oper_done(AVND_CB *c
>                * unless a NODE level recovery action is in progress.
>                */
>               if (m_AVND_SU_IS_FAILED(su) && !su->si_list.n_nodes &&
> -                 (cb->oper_state == SA_AMF_OPERATIONAL_ENABLED))
> +                 (cb->oper_state == SA_AMF_OPERATIONAL_ENABLED) && 
> (!m_AVND_SU_IS_RESTART(su)))
>                       rc = avnd_err_su_repair(cb, su);
>       }
>   
> @@ -1116,14 +1195,10 @@ uint32_t avnd_su_si_oper_done(AVND_CB *c
>        * reset the su-restart flag if all the sis are in assigned
>        * state (signifying the end of su-restart phase)
>        */
> -     if (m_AVND_SU_IS_RESTART(su)) {
> -             m_AVND_SU_ARE_ALL_SI_ASSIGNED(su, are_si_assigned);
> -             if (true == are_si_assigned) {
> -                     m_AVND_SU_RESTART_RESET(su);
> -                     m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, su, 
> AVND_CKPT_SU_FLAG_CHANGE);
> -             }
> +     if (m_AVND_SU_IS_RESTART(su))  {
> +             TRACE("SU restart due to escalation or admin op going on.");
> +             su_finish_suRestart_escalation_or_admin_op(su);
>       }
> -
>       /* finally initiate buffered assignments, if any */
>       rc = avnd_su_siq_prc(cb, su);
>   
> @@ -1487,46 +1562,58 @@ uint32_t avnd_su_pres_fsm_run(AVND_CB *c
>   
>   
>   /**
> - * @brief  Reset flags when a NPI SU moves from RESTARTING to INSTANTIATED 
> state.
> + * @brief  Reset flags when a NPI SU moves from INSTANTIATING to 
> INSTANTIATED state.
>    * @param  su
>    * @return NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE
>    */
>   
> -static uint32_t npi_su_restarting_to_instantiated(AVND_SU *su)
> +static uint32_t npi_su_instantiating_to_instantiated(AVND_SU *su)
>   {
>       uint32_t rc = NCSCC_RC_SUCCESS;
> +     TRACE_ENTER();
>   
>       if (m_AVND_SU_IS_RESTART(su)) {
>               m_AVND_SU_FAILED_RESET(su);
> -             m_AVND_SU_RESTART_RESET(su);
> +             reset_suRestart_flag(su);
>               m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(avnd_cb, su, 
> AVND_CKPT_SU_FLAG_CHANGE);
> +     } else {
> +             AVND_SU_SI_REC *si = 0;
> +             si = (AVND_SU_SI_REC *)m_NCS_DBLIST_FIND_FIRST(&su->si_list);
> +                osafassert(si);
> +             rc = avnd_su_si_oper_done(avnd_cb, su, m_AVND_SU_IS_ALL_SI(su) 
> ? 0 : si);
> +             m_AVND_SU_ALL_SI_RESET(su);
> +             m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(avnd_cb, su, 
> AVND_CKPT_SU_FLAG_CHANGE);
> +             TRACE("SI Assignment succeeded, generating si-oper done 
> indication");
>       }
> -
> +     TRACE_LEAVE2("rc:%d", rc);
>       return rc;
>   }
>   
>   
>   /**
> - * @brief  Reset flags when a PI SU moves from RESTARTING to INSTANTIATED 
> state.
> + * @brief  Reset flags when a PI SU moves from Instantiating to INSTANTIATED 
> state.
>    * @param  su
>    * @return NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE
>    */
> -static uint32_t pi_su_restarting_to_instantiated(AVND_SU *su)
> +static uint32_t pi_su_instantiating_to_instantiated(AVND_SU *su)
>   {
>       uint32_t rc = NCSCC_RC_SUCCESS;
> +     bool is_en;
> +     TRACE_ENTER();
>   
>       /* A SU can be restarted because all components faulted with component
>          restart recovery policy or because of surestart escalation. */       
> +     
> +     /* reset the su failed flag */
> +     if (m_AVND_SU_IS_FAILED(su)) {
> +             m_AVND_SU_FAILED_RESET(su);
> +             m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, su, 
> AVND_CKPT_SU_FLAG_CHANGE);
> +     }
>       if (m_AVND_SU_IS_RESTART(su)) {
>               /* reset the su failed flag & set the oper state to enabled */
> -             if (m_AVND_SU_IS_FAILED(su)) {
> -                     m_AVND_SU_FAILED_RESET(su);
> -                     m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(avnd_cb, su, 
> AVND_CKPT_SU_FLAG_CHANGE);
> -                     m_AVND_SU_OPER_STATE_SET(su, 
> SA_AMF_OPERATIONAL_ENABLED);
> -                     m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(avnd_cb, su, 
> AVND_CKPT_SU_OPER_STATE);
> -                     TRACE("Setting the Oper state to Enabled");
> -             }
> -
> +             m_AVND_SU_OPER_STATE_SET(su, SA_AMF_OPERATIONAL_ENABLED);
> +             m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(avnd_cb, su, 
> AVND_CKPT_SU_OPER_STATE);
> +             TRACE("Setting the Oper state to Enabled");
>               /*
>                * reassign all the sis...
>                * it's possible that the si was never assigned. send su-oper
> @@ -1534,10 +1621,25 @@ static uint32_t pi_su_restarting_to_inst
>                */
>               if (su->si_list.n_nodes)
>                       rc = avnd_su_si_reassign(avnd_cb, su);
> +             else {
> +                     rc = avnd_di_oper_send(avnd_cb, su, 0);
> +                     reset_suRestart_flag(su);
> +             }
> +             su->admin_op_Id = static_cast<SaAmfAdminOperationIdT>(0);
> +     } else {
> +
> +             /* determine the su oper state. if enabled, inform avd. */
> +             m_AVND_SU_IS_ENABLED(su, is_en);
> +             if (true == is_en) {
> +                     TRACE("SU oper state is enabled");
> +                     m_AVND_SU_OPER_STATE_SET(su, 
> SA_AMF_OPERATIONAL_ENABLED);
> +                     m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(anvd_cb, su, 
> AVND_CKPT_SU_OPER_STATE);
> +                     rc = avnd_di_oper_send(avnd_cb, su, 0);
> +             }
>               else
> -                     rc = avnd_di_oper_send(avnd_cb, su, 0);
> +                     TRACE("SU oper state is disabled");
>       }
> -     
> +     TRACE_LEAVE();
>       return rc;
>   }
>   
> /****************************************************************************
> @@ -1566,34 +1668,13 @@ uint32_t avnd_su_pres_st_chng_prc(AVND_C
>       /* pi su */
>       if (m_AVND_SU_IS_PREINSTANTIABLE(su)) {
>               TRACE("PI SU :'%s'",su->name.value);
> -             /* instantiating -> instantiated */
> -             if ((SA_AMF_PRESENCE_INSTANTIATING == prv_st) && 
> (SA_AMF_PRESENCE_INSTANTIATED == final_st)) {
> -                     TRACE("SU Instantiating -> Instantiated");
> -                     /* reset the su failed flag */
> -                     if (m_AVND_SU_IS_FAILED(su)) {
> -                             m_AVND_SU_FAILED_RESET(su);
> -                             m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, su, 
> AVND_CKPT_SU_FLAG_CHANGE);
> -                     }
> -
> -                     /* determine the su oper state. if enabled, inform avd. 
> */
> -                     m_AVND_SU_IS_ENABLED(su, is_en);
> -                     if (true == is_en) {
> -                             TRACE("SU oper state is enabled");
> -                             m_AVND_SU_OPER_STATE_SET(su, 
> SA_AMF_OPERATIONAL_ENABLED);
> -                             m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, su, 
> AVND_CKPT_SU_OPER_STATE);
> -                             rc = avnd_di_oper_send(cb, su, 0);
> -                             if (NCSCC_RC_SUCCESS != rc)
> -                                     goto done;
> -                     }
> -                     else
> -                             TRACE("SU oper state is disabled");
> +             /* instantiating/restarting -> instantiated */
> +             if (((SA_AMF_PRESENCE_INSTANTIATING == prv_st) || 
> (SA_AMF_PRESENCE_RESTARTING == prv_st))
> +                             && (SA_AMF_PRESENCE_INSTANTIATED == final_st)) {
> +                     rc = pi_su_instantiating_to_instantiated(su);
> +                     if (NCSCC_RC_SUCCESS != rc)
> +                             goto done;
>               }
> -
> -             /* restarting -> instantiated */
> -             if ((SA_AMF_PRESENCE_RESTARTING == prv_st) && 
> (SA_AMF_PRESENCE_INSTANTIATED == final_st))
> -                     rc = pi_su_restarting_to_instantiated(su);
> -     
> -
>               /* terminating -> instantiated */
>               if ((SA_AMF_PRESENCE_TERMINATING == prv_st) && 
> (SA_AMF_PRESENCE_INSTANTIATED == final_st)) {
>                       TRACE("SU Terminating -> Instantiated");
> @@ -1622,22 +1703,31 @@ uint32_t avnd_su_pres_st_chng_prc(AVND_C
>                       TRACE("SU Terminating -> Uninstantiated");
>                       if (sufailover_in_progress(su)) {
>                               /*Do not reset any flag, this will be done as a 
> part of repair.*/
> -                     }
> -                     else
> -                     {
> -                             if (m_AVND_SU_IS_FAILED(su) && 
> (su->si_list.n_nodes == 0)) {
> +                     } else {
> +                             if (!m_AVND_SU_IS_RESTART(su) && 
> m_AVND_SU_IS_FAILED(su) &&
> +                                             (su->si_list.n_nodes == 0)) {
>                                       m_AVND_SU_FAILED_RESET(su);
>                                       m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, 
> su, AVND_CKPT_SU_FLAG_CHANGE);
>                               }
> -
> -                             if (m_AVND_SU_IS_RESTART(su)) {
> -                                     m_AVND_SU_RESTART_RESET(su);
> -                                     m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, 
> su, AVND_CKPT_SU_FLAG_CHANGE);
> +                             if (m_AVND_SU_IS_RESTART(su) &&
> +                                     ((su_all_comps_restartable(*su) == 
> true) ||
> +                                      ((su_all_comps_restartable(*su) == 
> false)
> +                                       && 
> (is_any_non_restartable_comp_assigned(*su) == false)) ||
> +                                      ((su->su_err_esc_level == 
> AVND_ERR_ESC_LEVEL_2) &&
> +                                       (su->si_list.n_nodes == 0)))) {
> +                                     /*
> +                                        It means all comps are terminated in 
> surestart recovery or
> +                                        admin op. For non restartable SU 
> with no non restartable comp
> +                                        assigned, instantiation of SU will 
> started from here.
> +                                        Now instantiate SU honoring 
> instantiation level.
> +                                      */
> +                                     rc = avnd_su_pres_fsm_run(cb, su, 0, 
> AVND_SU_PRES_FSM_EV_INST);
> +                                     if (NCSCC_RC_SUCCESS != rc)
> +                                             goto done;
>                               }
>                       }
>                       goto done;
>               }
> -
>               /* instantiating -> inst-failed */
>               if ((SA_AMF_PRESENCE_INSTANTIATING == prv_st) && 
> (SA_AMF_PRESENCE_INSTANTIATION_FAILED == final_st)) {
>                       TRACE("SU Instantiating -> Instantiation Failed");
> @@ -1708,16 +1798,11 @@ uint32_t avnd_su_pres_st_chng_prc(AVND_C
>               si = (AVND_SU_SI_REC *)m_NCS_DBLIST_FIND_FIRST(&su->si_list);
>               osafassert(si);
>   
> -             /* instantiating -> instantiated */
> -             if ((SA_AMF_PRESENCE_INSTANTIATING == prv_st) && 
> (SA_AMF_PRESENCE_INSTANTIATED == final_st)) {
> -                     TRACE("SU Instantiating -> Instantiated");
> -                     /* si assignment success.. generate si-oper done 
> indication */
> -                     rc = avnd_su_si_oper_done(cb, su, 
> m_AVND_SU_IS_ALL_SI(su) ? 0 : si);
> -                     m_AVND_SU_ALL_SI_RESET(su);
> -                     m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, su, 
> AVND_CKPT_SU_FLAG_CHANGE);
> -                     TRACE("SI Assignment succeeded, generating si-oper done 
> indication");
> +             /* instantiating/restarting -> instantiated */
> +             if (((SA_AMF_PRESENCE_INSTANTIATING == prv_st) || 
> (SA_AMF_PRESENCE_RESTARTING == prv_st))
> +                             && (SA_AMF_PRESENCE_INSTANTIATED == final_st)) {
> +                     rc = npi_su_instantiating_to_instantiated(su);
>               }
> -
>               /* instantiating/instantiated/restarting -> inst-failed */
>               if (((SA_AMF_PRESENCE_INSTANTIATING == prv_st) ||
>                    (SA_AMF_PRESENCE_INSTANTIATED == prv_st)) && 
> (SA_AMF_PRESENCE_INSTANTIATION_FAILED == final_st)) {
> @@ -1750,8 +1835,6 @@ uint32_t avnd_su_pres_st_chng_prc(AVND_C
>                       }
>               }
>   
> -             if ((SA_AMF_PRESENCE_RESTARTING == prv_st) && 
> (SA_AMF_PRESENCE_INSTANTIATED == final_st))
> -                     rc = npi_su_restarting_to_instantiated(su);
>   
>               /* terminating -> uninstantiated */
>               if ((SA_AMF_PRESENCE_TERMINATING == prv_st) && 
> (SA_AMF_PRESENCE_UNINSTANTIATED == final_st)) {
> @@ -1761,15 +1844,36 @@ uint32_t avnd_su_pres_st_chng_prc(AVND_C
>                       }
>                       else
>                       {
> -                             /* si assignment/removal success.. generate 
> si-oper done indication */
> -                             rc = avnd_su_si_oper_done(cb, su, 
> m_AVND_SU_IS_ALL_SI(su) ? 0 : si);
> -                             m_AVND_SU_ALL_SI_RESET(su);
> -                             m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, su, 
> AVND_CKPT_SU_FLAG_CHANGE);
> -
> -                             /* npi su is enabled in uninstantiated state */
> -                             m_AVND_SU_OPER_STATE_SET(su, 
> SA_AMF_OPERATIONAL_ENABLED);
> -                             m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, su, 
> AVND_CKPT_SU_OPER_STATE);
> -                             rc = avnd_di_oper_send(cb, su, 0);
> +                             if (m_AVND_SU_IS_RESTART(su) && 
> (su_all_comps_restartable(*su) == true)) {
> +                                     /* npi su is enabled in uninstantiated 
> state */
> +                                     m_AVND_SU_OPER_STATE_SET(su, 
> SA_AMF_OPERATIONAL_ENABLED);
> +                                     m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, 
> su, AVND_CKPT_SU_OPER_STATE);
> +                                     /*
> +                                        It means all comps are terminated in 
> surestart recovery or admin op.
> +                                        Now instantiate SU honoring 
> instantiation level.
> +                                      */
> +                                     rc = avnd_su_pres_fsm_run(cb, su, 0, 
> AVND_SU_PRES_FSM_EV_INST);
> +                                     if (NCSCC_RC_SUCCESS != rc)
> +                                             goto done;
> +                             } else {
> +                                     if (m_AVND_SU_IS_FAILED(su))
> +                                             m_AVND_SU_FAILED_RESET(su);
> +
> +                                     /* si assignment/removal success.. 
> generate si-oper done indication */
> +                                     rc = avnd_su_si_oper_done(cb, su, 
> m_AVND_SU_IS_ALL_SI(su) ? 0 : si);
> +                                     m_AVND_SU_ALL_SI_RESET(su);
> +                                     m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, 
> su, AVND_CKPT_SU_FLAG_CHANGE);
> +
> +                                     /* npi su is enabled in uninstantiated 
> state */
> +                                     m_AVND_SU_OPER_STATE_SET(su, 
> SA_AMF_OPERATIONAL_ENABLED);
> +                                     m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, 
> su, AVND_CKPT_SU_OPER_STATE);
> +                             }
> +
> +                             /* A NPI SU becomes uninstantiated, send SU 
> oper state enabled event
> +                                to AMFD if removal of assignments is also 
> done.*/
> +                             if (su->si_list.n_nodes == 0) {
> +                                     rc = avnd_di_oper_send(cb, su, 0);
> +                             }
>                       }
>               }
>   
> @@ -2048,7 +2152,8 @@ uint32_t avnd_su_pres_insting_compinst_h
>               curr_csi = (AVND_COMP_CSI_REC 
> *)m_NCS_DBLIST_FIND_NEXT(&curr_csi->si_dll_node);
>               if (curr_csi) {
>                       /* we have another csi. trigger the comp fsm with 
> InstEv */
> -                     TRACE("There's another CSI, Running the component clc 
> FSM");
> +                     TRACE("There's another CSI:'%s', Running the component 
> clc FSM for comp:'%s'",
> +                                     
> curr_csi->name.value,curr_csi->comp->name.value);
>                       rc = avnd_comp_clc_fsm_trigger(cb, curr_csi->comp, 
> AVND_COMP_CLC_PRES_FSM_EV_INST);
>                       if (NCSCC_RC_SUCCESS != rc)
>                               goto done;
> @@ -2226,13 +2331,56 @@ uint32_t avnd_su_pres_inst_suterm_hdler(
>       }
>   
>       /* transition to terminating state */
> -     avnd_su_pres_state_set(su, SA_AMF_PRESENCE_TERMINATING);
> +     if (su->pres != SA_AMF_PRESENCE_TERMINATING)
> +             avnd_su_pres_state_set(su, SA_AMF_PRESENCE_TERMINATING);
>   
>    done:
>       TRACE_LEAVE2("%u", rc);
>       return rc;
>   }
>   
> +/**
> + * @brief  Return true if all pi comps of SU are in restarting state.
> + *      It will be used during restart admin operation on su.
> + * @param  ptr to su.
> + * @return  true/false.
> + */
> +static bool su_evaluate_restarting_state(AVND_SU *su)
> +{
> +     for (AVND_COMP *comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_FIRST(&su->comp_list));
> +             comp;
> +             comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_NEXT(&comp->su_dll_node))) 
> {
> +             if (!m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(comp))
> +                     continue;
> +             if (comp->pres !=SA_AMF_PRESENCE_RESTARTING) {
> +                     return false;
> +             }       
> +     }
> +
> +     return true;
> +}
> +/**
> + * @brief       Checks if all csis of all the sis in this su are in 
> restarting state
> + * @param [in]  cmp
> + * @returns     true/false
> + **/
> +static bool all_csis_in_restarting_state(const AVND_SU *su)
> +{
> +        AVND_COMP_CSI_REC *curr_csi;
> +        AVND_SU_SI_REC *curr_si;
> +
> +        for (curr_si = (AVND_SU_SI_REC 
> *)m_NCS_DBLIST_FIND_FIRST(&su->si_list);
> +                        curr_si;
> +                        curr_si = (AVND_SU_SI_REC 
> *)m_NCS_DBLIST_FIND_NEXT(&curr_si->su_dll_node)) {
> +                for (curr_csi = (AVND_COMP_CSI_REC 
> *)m_NCS_DBLIST_FIND_FIRST(&curr_si->csi_list);
> +                                curr_csi; curr_csi = (AVND_COMP_CSI_REC 
> *)m_NCS_DBLIST_FIND_NEXT(&curr_csi->si_dll_node)) {
> +                        if 
> (!m_AVND_COMP_CSI_CURR_ASSIGN_STATE_IS_RESTARTING(curr_csi)) {
> +                                return false;
> +                        }
> +                }
> +        }
> +        return true;
> +}
>   
> /****************************************************************************
>     Name          : avnd_su_pres_inst_surestart_hdler
>    
> @@ -2260,18 +2408,48 @@ uint32_t avnd_su_pres_inst_surestart_hdl
>        */
>       if (m_AVND_SU_IS_PREINSTANTIABLE(su)) {
>               TRACE("PI SU:'%s'",su->name.value);
> -             for (curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_FIRST(&su->comp_list));
> +             for (curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_LAST(&su->comp_list));
>                    curr_comp;
> -                  curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_NEXT(&curr_comp->su_dll_node)))
>  {
> -                     /* restart the pi comp */
> +                  curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_PREV(&curr_comp->su_dll_node)))
>  {
> +                     if ((curr_comp->pres == SA_AMF_PRESENCE_RESTARTING) ||
> +                                     (curr_comp->pres == 
> SA_AMF_PRESENCE_UNINSTANTIATED))
> +                                continue;
>                       if (m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(curr_comp)) {
>                               TRACE("Running the component clc FSM, restart 
> the component");
> -                             rc = avnd_comp_clc_fsm_run(cb, curr_comp, 
> AVND_COMP_CLC_PRES_FSM_EV_RESTART);
> +                             if (m_AVND_SU_IS_RESTART(su) && 
> m_AVND_SU_IS_FAILED(su))
> +                                     rc = avnd_comp_clc_fsm_run(cb, 
> curr_comp, AVND_COMP_CLC_PRES_FSM_EV_CLEANUP);
> +                             else
> +                                     rc = avnd_comp_clc_fsm_run(cb, 
> curr_comp, AVND_COMP_CLC_PRES_FSM_EV_RESTART);
>                               if (NCSCC_RC_SUCCESS != rc)
>                                       goto done;
>                               break;
> +                     } else {
> +                             /*
> +                                For a NPI comp in PI SU, component FSM is 
> always triggered at the time of
> +                                assignments. If this component is 
> non-restartable then start
> +                                reassginment from the whole SU now, it will 
> take care if its termination/clean
> +                                up.
> +                             */
> +                             if (m_AVND_COMP_IS_RESTART_DIS(curr_comp) && 
> (curr_comp->csi_list.n_nodes > 0)) {
> +                                     TRACE("Start reassignment to different 
> SU as '%s' is"
> +                                                     " not 
> restartable",curr_comp->name.value);
> +                                     su_send_suRestart_recovery_msg(su);
> +                                     goto done;
> +                             } else {
> +                                     if (m_AVND_SU_IS_RESTART(su) && 
> m_AVND_SU_IS_FAILED(su))
> +                                             rc = avnd_comp_clc_fsm_run(cb, 
> curr_comp, AVND_COMP_CLC_PRES_FSM_EV_CLEANUP);
> +                                     else
> +                                             rc = avnd_comp_clc_fsm_run(cb, 
> curr_comp, AVND_COMP_CLC_PRES_FSM_EV_RESTART);
> +                                     if (curr_comp->pres == 
> SA_AMF_PRESENCE_TERMINATING)
> +                                             avnd_su_pres_state_set(su, 
> SA_AMF_PRESENCE_TERMINATING);
> +                                     break;
> +                             }
>                       }
>               }               /* for */
> +             if ((su_evaluate_restarting_state(su) == true) && 
> (!m_AVND_SU_IS_FAILED(su))) {
> +                     TRACE("Mark su restarting");
> +                     avnd_su_pres_state_set(su, SA_AMF_PRESENCE_RESTARTING);
> +             }
>       }
>   
>       /*
> @@ -2284,40 +2462,36 @@ uint32_t avnd_su_pres_inst_surestart_hdl
>               si = (AVND_SU_SI_REC *)m_NCS_DBLIST_FIND_FIRST(&su->si_list);
>               osafassert(si);
>   
> -             csi = (AVND_COMP_CSI_REC 
> *)m_NCS_DBLIST_FIND_FIRST(&si->csi_list);
> +             csi = (AVND_COMP_CSI_REC 
> *)m_NCS_DBLIST_FIND_LAST(&si->csi_list);
>               if (csi) {
> -                     /* mark the csi state assigning */
> -                     m_AVND_COMP_CSI_CURR_ASSIGN_STATE_SET(csi, 
> AVND_COMP_CSI_ASSIGN_STATE_ASSIGNING);
> +                        TRACE("Running the component clc FSM for csi:'%s', 
> comp:%s",
> +                                     csi->name.value, csi->comp->name.value);
> +                     if (m_AVND_SU_IS_RESTART(su) && 
> m_AVND_SU_IS_FAILED(su)) {
> +                             if 
> (m_AVND_SU_SI_CURR_ASSIGN_STATE_IS_REMOVING(si))
> +                                     
> m_AVND_COMP_CSI_CURR_ASSIGN_STATE_SET(csi, 
> AVND_COMP_CSI_ASSIGN_STATE_REMOVING);
> +                             else
> +                                     
> m_AVND_COMP_CSI_CURR_ASSIGN_STATE_SET(csi, 
> AVND_COMP_CSI_ASSIGN_STATE_ASSIGNING);
> +                             rc = avnd_comp_clc_fsm_run(cb, csi->comp, 
> AVND_COMP_CLC_PRES_FSM_EV_CLEANUP);
> +                     } else {
> +                             m_AVND_COMP_CSI_CURR_ASSIGN_STATE_SET(csi, 
> AVND_COMP_CSI_ASSIGN_STATE_RESTARTING);
> +                             rc = avnd_comp_clc_fsm_run(cb, csi->comp, 
> AVND_COMP_CLC_PRES_FSM_EV_RESTART);
> +                     }
>                       m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, csi, 
> AVND_CKPT_COMP_CSI_CURR_ASSIGN_STATE);
> -
> -                     TRACE("Running the component clc FSM, restart the 
> component");
> -                     /* restart the comp */
> -                     rc = avnd_comp_clc_fsm_run(cb, csi->comp, 
> AVND_COMP_CLC_PRES_FSM_EV_RESTART);
>                       if (NCSCC_RC_SUCCESS != rc)
>                               goto done;
>               }
> +                if ((all_csis_in_restarting_state(su) == true) && 
> (!m_AVND_SU_IS_FAILED(su))) {
> +                        TRACE("All CSIs are in restarting state, so marking 
> SU restarting");
> +                        avnd_su_pres_state_set(su, 
> SA_AMF_PRESENCE_RESTARTING);
> +                }
>       }
>   
> -     /* transition to restarting state */
> -     avnd_su_pres_state_set(su, SA_AMF_PRESENCE_RESTARTING);
>   
>    done:
>       TRACE_LEAVE2("%u", rc);
>       return rc;
>   }
>   
> -static bool su_evaluate_restarting_state(AVND_SU *su)
> -{
> -     for (AVND_COMP *comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_FIRST(&su->comp_list));
> -             comp;
> -             comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_NEXT(&comp->su_dll_node))) 
> {
> -             if (comp->pres !=SA_AMF_PRESENCE_RESTARTING) {
> -                     return false;
> -             }       
> -     }
> -
> -     return true;
> -}
>   
>   
> /****************************************************************************
>     Name          : avnd_su_pres_inst_comprestart_hdler
> @@ -2336,13 +2510,55 @@ static bool su_evaluate_restarting_state
>   uint32_t avnd_su_pres_inst_comprestart_hdler(AVND_CB *cb, AVND_SU *su, 
> AVND_COMP *comp)
>   {                           /* TBD */
>       uint32_t rc = NCSCC_RC_SUCCESS;
> +     AVND_COMP_CSI_REC *curr_csi = 0;
>       const char *compname = comp ? (char*)comp->name.value : "none";
> -     TRACE_1("Component restart event in the Instantiated state, '%s' : 
> '%s'",
> +     TRACE_ENTER2("Component restart event in the Instantiated state, '%s' : 
> '%s'",
>                       su->name.value, compname);
> -
> -     if (su_evaluate_restarting_state(su) == true)
> -             avnd_su_pres_state_set(su, SA_AMF_PRESENCE_RESTARTING);
> -
> +        if (m_AVND_SU_IS_PREINSTANTIABLE(su)) {
> +             TRACE("PI SU");
> +             for (AVND_COMP *curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_PREV(&comp->su_dll_node));
> +                     curr_comp;
> +                     curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_PREV(&curr_comp->su_dll_node)))
>  {
> +                     if (curr_comp->pres == SA_AMF_PRESENCE_RESTARTING)
> +                                continue;
> +                        if (m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(curr_comp)) {
> +                                TRACE("Running the component clc FSM");
> +                                rc = avnd_comp_clc_fsm_run(cb, curr_comp, 
> AVND_COMP_CLC_PRES_FSM_EV_RESTART);
> +                                if (NCSCC_RC_SUCCESS != rc)
> +                                        goto done;
> +                                break;
> +                        }
> +             }
> +             if (su_evaluate_restarting_state(su) == true)
> +                     avnd_su_pres_state_set(su, SA_AMF_PRESENCE_RESTARTING);
> +        }
> +     
> +        if (!m_AVND_SU_IS_PREINSTANTIABLE(su)) {
> +                TRACE_1("NPI SU");
> +                /* get the only csi rec */
> +                curr_csi = 
> m_AVND_CSI_REC_FROM_COMP_DLL_NODE_GET(m_NCS_DBLIST_FIND_FIRST(&comp->csi_list));
> +                osafassert(curr_csi);
> +             /* Typically we mark the CSI state here. But initially we had 
> marked
> +                CSI state Restarting. It will be marked 
> AVND_COMP_CSI_ASSIGN_STATE_ASSIGNED
> +                when component will be instantiated.
> +              */
> +                curr_csi = (AVND_COMP_CSI_REC 
> *)m_NCS_DBLIST_FIND_PREV(&curr_csi->si_dll_node);
> +             if (curr_csi) {
> +                     m_AVND_COMP_CSI_CURR_ASSIGN_STATE_SET(curr_csi, 
> AVND_COMP_CSI_ASSIGN_STATE_RESTARTING);
> +                     m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, curr_csi, 
> AVND_CKPT_COMP_CSI_CURR_ASSIGN_STATE);
> +                     TRACE_2("Running the component clc FSM for csi:'%s', 
> comp:%s",
> +                                     curr_csi->name.value, 
> curr_csi->comp->name.value);
> +                     rc = avnd_comp_clc_fsm_run(cb, curr_csi->comp, 
> AVND_COMP_CLC_PRES_FSM_EV_RESTART);
> +                     if (NCSCC_RC_SUCCESS != rc)
> +                             goto done;
> +                }
> +                if (all_csis_in_restarting_state(su) == true) {
> +                        TRACE_2("All CSIs are in restarting state, so 
> marking SU restarting");
> +                        avnd_su_pres_state_set(su, 
> SA_AMF_PRESENCE_RESTARTING);
> +                }
> +        }
> +done:
> +     TRACE_LEAVE();
>       return rc;
>   }
>   
> @@ -2366,8 +2582,9 @@ uint32_t avnd_su_pres_inst_compterming_h
>       const char *compname = comp ? (char*)comp->name.value : "none";
>       TRACE_ENTER2("CompTerminating event in the Instantiated state:'%s' : 
> '%s'",
>                                su->name.value, compname);
> -
> -     if (m_AVND_SU_IS_FAILED(su)) {
> +     //A SU enters in TERMINATING state when any component is terminating.
> +     if (((comp != NULL) && (comp->admin_oper == true)) ||
> +                     m_AVND_SU_IS_FAILED(su) || (su->admin_op_Id == 
> SA_AMF_ADMIN_RESTART)) {
>               avnd_su_pres_state_set(su, SA_AMF_PRESENCE_TERMINATING);
>       }
>   
> @@ -2408,8 +2625,18 @@ uint32_t avnd_su_pres_terming_compinst_h
>               if (true == is) {
>                       avnd_su_pres_state_set(su, 
> SA_AMF_PRESENCE_INSTANTIATED);
>               }
> -     }
> -
> +                if (m_AVND_SU_IS_RESTART(su)) {
> +                     if (su->admin_op_Id == SA_AMF_ADMIN_RESTART)
> +                             /*This can happen when SU has both restartable 
> and non restartable
> +                                   comps.Go for further instantiation.*/
> +                             rc = avnd_su_pres_fsm_run(cb, su, 0, 
> AVND_SU_PRES_FSM_EV_INST);
> +                     else if (m_AVND_SU_IS_FAILED(su)) {
> +                             /*Before going for surestart recovery from comp 
> restart recovery, a
> +                               comp was in instantiating state, cleanup it 
> now.*/
> +                             rc = avnd_comp_clc_fsm_run(cb, comp, 
> AVND_COMP_CLC_PRES_FSM_EV_CLEANUP);
> +                     }
> +             }
> +        }
>       TRACE_LEAVE2("%u", rc);
>       return rc;
>   }
> @@ -2513,6 +2740,8 @@ uint32_t avnd_su_pres_terming_comptermfa
>       return rc;
>   }
>   
> +
> +
>   /**
>    * @brief       Checks if all csis of all the sis in this su are in removed 
> state
>    *
> @@ -2559,66 +2788,109 @@ uint32_t avnd_su_pres_terming_compuninst
>   {
>       AVND_COMP *curr_comp = 0;
>       AVND_COMP_CSI_REC *curr_csi = 0;
> -     bool all_uninst = true;
>       uint32_t rc = NCSCC_RC_SUCCESS;
>       const char *compname = comp ? (char*)comp->name.value : "none";
>       TRACE_ENTER2("Component Uninstantiated event in the Terminating 
> state:'%s' : '%s'",
>                                su->name.value, compname);
> -
> -     /* Mark failed PI SU uninstantiated whenever all components are 
> uninstantiated. */
> -     if (m_AVND_SU_IS_PREINSTANTIABLE(su) && m_AVND_SU_IS_FAILED(su))
> +     //TODO: write whole if block into a separate function for PI SUand call 
> it here.
> +     if (m_AVND_SU_IS_PREINSTANTIABLE(su))
>       {
>               TRACE("PI SU");
> -             for (curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_FIRST(&su->comp_list));
> -                  curr_comp;
> -                  curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_NEXT(&curr_comp->su_dll_node)))
>  {
> -                     if ((curr_comp->pres != SA_AMF_PRESENCE_UNINSTANTIATED) 
> &&
> -                         (m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(curr_comp)))
> -                             all_uninst = false;
> -             }
> -
> -             if (all_uninst == true) {
> -                     avnd_su_pres_state_set(su, 
> SA_AMF_PRESENCE_UNINSTANTIATED);
> -
> -             }
> -     }
> -
> -     
> -     /*
> -      * If pi su, pick the prv pi comp & trigger it's FSM with TermEv.
> -      */
> -     if (m_AVND_SU_IS_PREINSTANTIABLE(su) && !m_AVND_SU_IS_FAILED(su)) {
> -             TRACE("PI SU");
> -             for (curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_PREV(&comp->su_dll_node));
> -                  curr_comp;
> -                  curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_PREV(&curr_comp->su_dll_node)))
>  {
> -
> -                     if (curr_comp->pres == SA_AMF_PRESENCE_UNINSTANTIATED)
> -                             continue;
> -
> -                     /* terminate the pi comp */
> -                     if (m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(curr_comp)) {
> -                             TRACE("Running the component clc FSM");
> -                             rc = avnd_comp_clc_fsm_run(cb, curr_comp, 
> AVND_COMP_CLC_PRES_FSM_EV_TERM);
> +             if (m_AVND_SU_IS_FAILED(su)) {
> +                     TRACE("SU is in Failed state");
> +                     if (pi_su_all_comps_uninstantiated(*su) == true)
> +                             avnd_su_pres_state_set(su, 
> SA_AMF_PRESENCE_UNINSTANTIATED);
> +
> +                     if (m_AVND_SU_IS_RESTART(su)) {
> +                             for (curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_LAST(&su->comp_list));
> +                                     curr_comp;
> +                                     curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_PREV(&curr_comp->su_dll_node)))
>  {
> +                                     if (curr_comp->pres == 
> SA_AMF_PRESENCE_UNINSTANTIATED)
> +                                             continue;
> +                                     //Will pick up when terminating comp 
> will move to uninstantiated state.
> +                                     if ((curr_comp->pres == 
> SA_AMF_PRESENCE_TERMINATING) ||
> +                                                     (curr_comp->pres == 
> SA_AMF_PRESENCE_RESTARTING))
> +                                             break;
> +                                     if 
> (m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(curr_comp)) {
> +                                             rc = avnd_comp_clc_fsm_run(cb, 
> curr_comp,
> +                                                             
> AVND_COMP_CLC_PRES_FSM_EV_CLEANUP);
> +                                             if (NCSCC_RC_SUCCESS != rc)
> +                                                     goto done;
> +                                             break;
> +                                     } else {
> +                                             /*
> +                                                For a NPI comp in SU, 
> component FSM is always triggered
> +                                                at the time of assignments. 
> If this component is
> +                                                non-restartable then start 
> reassginment from the
> +                                                whole SU now.
> +                                              */
> +                                             if 
> (m_AVND_COMP_IS_RESTART_DIS(curr_comp) &&
> +                                                             
> (curr_comp->csi_list.n_nodes > 0)) {
> +                                                     TRACE("Start 
> reassignment to different SU as '%s' is"
> +                                                                     " not 
> restartable",curr_comp->name.value);
> +                                                     
> su_send_suRestart_recovery_msg(su);
> +                                                     goto done;
> +                                             } else {
> +                                                     if 
> (m_AVND_SU_IS_RESTART(su) && m_AVND_SU_IS_FAILED(su))
> +                                                             rc = 
> avnd_comp_clc_fsm_run(cb, curr_comp, AVND_COMP_CLC_PRES_FSM_EV_CLEANUP);
> +                                                     else
> +                                                             rc = 
> avnd_comp_clc_fsm_run(cb, curr_comp, AVND_COMP_CLC_PRES_FSM_EV_RESTART);
> +                                                     if (curr_comp->pres == 
> SA_AMF_PRESENCE_TERMINATING)
> +                                                             
> avnd_su_pres_state_set(su, SA_AMF_PRESENCE_TERMINATING);
> +                                                     break;
> +                                             }
> +                                     }
> +                             }
> +                     }
> +             } else if ((comp != NULL) && (comp->admin_oper == true) &&
> +                             (cb->term_state != 
> AVND_TERM_STATE_OPENSAF_SHUTDOWN_STARTED) &&
> +                             (m_AVND_COMP_IS_RESTART_DIS(comp))) {
> +                     TRACE("Admin operation on component");
> +                     if (pi_su_all_comps_uninstantiated(*su) == true)
> +                             avnd_su_pres_state_set(su, 
> SA_AMF_PRESENCE_UNINSTANTIATED);
> +                     avnd_comp_clc_fsm_run(cb, comp, 
> AVND_COMP_CLC_PRES_FSM_EV_INST);
> +                     avnd_su_pres_state_set(su, 
> SA_AMF_PRESENCE_INSTANTIATING);
> +             } else {
> +                     TRACE("Admin operation on SU");
> +                     for (curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_PREV(&comp->su_dll_node));
> +                             curr_comp;
> +                             curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_PREV(&curr_comp->su_dll_node)))
>  {
> +                             TRACE_1("comp:'%s', Pres 
> state:%u",curr_comp->name.value, curr_comp->pres);
> +                             if ((curr_comp->pres == 
> SA_AMF_PRESENCE_RESTARTING) ||
> +                                             (curr_comp->pres == 
> SA_AMF_PRESENCE_UNINSTANTIATED))
> +                                     continue;
> +
> +                             if 
> (m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(curr_comp)) {
> +                                     TRACE("Running the component clc FSM");
> +                                     if (su->admin_op_Id == 
> SA_AMF_ADMIN_RESTART)
> +                                             rc = avnd_comp_clc_fsm_run(cb, 
> curr_comp, AVND_COMP_CLC_PRES_FSM_EV_RESTART);
> +                                     else
> +                                             rc = avnd_comp_clc_fsm_run(cb, 
> curr_comp, AVND_COMP_CLC_PRES_FSM_EV_TERM);
> +                                     if (NCSCC_RC_SUCCESS != rc)
> +                                             goto done;
> +                                     break;
> +                             }
> +                     }               
> +                     if (pi_su_all_comps_uninstantiated(*su) == true)
> +                             avnd_su_pres_state_set(su, 
> SA_AMF_PRESENCE_UNINSTANTIATED);
> +                     else if ((curr_comp == NULL) && (su->admin_op_Id == 
> SA_AMF_ADMIN_RESTART)) {
> +                             /*
> +                                It means it is a SU comprising of assigned 
> non restartable comps and
> +                                   restartable comps and it is restart admin 
> op on su.
> +                                Now instantiate SU honoring instantiation 
> level.
> +                              */
> +                             rc = avnd_su_pres_fsm_run(cb, su, 0, 
> AVND_SU_PRES_FSM_EV_INST);
>                               if (NCSCC_RC_SUCCESS != rc)
>                                       goto done;
> -                             break;
>                       }
> -             }               /* for */
> -
> -             /*
> -              * if curr-comp is null, => all the pi comps are terminated.
> -              * transition to terminate state.
> -              */
> -             if (!curr_comp) {
> -                     avnd_su_pres_state_set(su, 
> SA_AMF_PRESENCE_UNINSTANTIATED);
>               }
>       }
>   
>       /*
>        * If npi su, pick the prv csi & trigger it's comp fsm with TermEv.
>        */
> -     if (!m_AVND_SU_IS_PREINSTANTIABLE(su) &&  !m_AVND_SU_IS_FAILED(su)) {
> +     if (!m_AVND_SU_IS_PREINSTANTIABLE(su) &&  (!m_AVND_SU_IS_FAILED(su) ||
> +                             m_AVND_SU_IS_RESTART(su))) {
>               TRACE("NPI SU");
>               /* get the only csi rec */
>               curr_csi = 
> m_AVND_CSI_REC_FROM_COMP_DLL_NODE_GET(m_NCS_DBLIST_FIND_FIRST(&comp->csi_list));
> @@ -2645,7 +2917,10 @@ uint32_t avnd_su_pres_terming_compuninst
>               if (curr_csi) {
>                       /* we have another csi. trigger the comp fsm with 
> TermEv */
>                       TRACE("There's another CSI, Running the component clc 
> FSM");
> -                     rc = avnd_comp_clc_fsm_trigger(cb, curr_csi->comp, 
> (m_AVND_COMP_IS_FAILED(curr_csi->comp)) ?
> +                     if (m_AVND_SU_IS_RESTART(su) && m_AVND_SU_IS_FAILED(su))
> +                             rc = avnd_comp_clc_fsm_trigger(cb, 
> curr_csi->comp, AVND_COMP_CLC_PRES_FSM_EV_CLEANUP);
> +                     else
> +                             rc = avnd_comp_clc_fsm_trigger(cb, 
> curr_csi->comp, (m_AVND_COMP_IS_FAILED(curr_csi->comp)) ?
>                                                      
> AVND_COMP_CLC_PRES_FSM_EV_CLEANUP :
>                                                      
> AVND_COMP_CLC_PRES_FSM_EV_TERM);
>                       if (NCSCC_RC_SUCCESS != rc)
> @@ -2721,6 +2996,86 @@ uint32_t avnd_su_pres_restart_suterm_hdl
>       return rc;
>   }
>   
> +/**
> + * @brief  handler for a component restart event when SU is in restarting 
> state.
> + *         This will be invoked when  either a comp is instantiated or 
> terminated restarting state.
> + *      It will be used during restart admin operation on su.
> + * @param  ptr to avnd_cb.
> + * @param  ptr to su.
> + * @param  ptr to comp.
> + * @return  NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE.
> + */
> +uint32_t avnd_su_pres_restart_comprestart_hdler(AVND_CB *cb, AVND_SU *su, 
> AVND_COMP *comp)
> +{
> +        AVND_COMP *curr_comp = 0;
> +     AVND_SU_SI_REC *si = 0;
> +     AVND_COMP_CSI_REC *csi = 0;
> +        uint32_t rc = NCSCC_RC_SUCCESS;
> +        TRACE_ENTER2("Comp restart event while su is restarting: '%s'", 
> su->name.value);
> +
> +     /* This event comes when a component in restarting state  is 
> successfully terminated
> +        or instantiated.
> +      */
> +        if (m_AVND_SU_IS_PREINSTANTIABLE(su)) {
> +                TRACE("PI SU:'%s'",su->name.value);
> +             /*All restartable PI comps are terminated when SU remains in 
> instantiated state.
> +               After restarting all the PI comps in restarting state, su 
> will be marked restarting.
> +                  Some NPI comps may remain instantiated, terminate them now.
> +                 */
> +             for (curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_LAST(&su->comp_list));
> +                     curr_comp;
> +                     curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_PREV(&curr_comp->su_dll_node)))
>  {
> +                     TRACE("%s", curr_comp->name.value);
> +                        if (m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(curr_comp))
> +                             continue;
> +                        if((!m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(curr_comp)) 
> &&
> +                                        (curr_comp->pres == 
> SA_AMF_PRESENCE_INSTANTIATED)) {
> +                                rc = avnd_comp_clc_fsm_run(cb, curr_comp, 
> AVND_COMP_CLC_PRES_FSM_EV_RESTART);
> +                                goto done;
> +                        }
> +             }
> +             /* It means last pi component got terminated,now instantiate 
> the first comp.*/
> +                for (curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_FIRST(&su->comp_list));
> +                     curr_comp;
> +                     curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_NEXT(&curr_comp->su_dll_node)))
>  {
> +                        TRACE("%s", curr_comp->name.value);
> +                        if (m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(curr_comp) &&
> +                                        (curr_comp->pres == 
> SA_AMF_PRESENCE_RESTARTING)) {
> +                                rc = avnd_comp_clc_fsm_run(cb, curr_comp, 
> AVND_COMP_CLC_PRES_FSM_EV_INST);
> +                                if (NCSCC_RC_SUCCESS != rc)
> +                                        goto done;
> +                                break;
> +                     }
> +             }
> +        }
> +
> +      /*
> +         * If npi su, it'll have only one si-rec in the si-list. Pick the
> +         * lowest ranked csi belonging to this si & trigger it's comp fsm.
> +         */
> +        if (!m_AVND_SU_IS_PREINSTANTIABLE(su)) {
> +                TRACE("NPI SU:'%s'",su->name.value);
> +                /* get the only si rec */
> +                si = (AVND_SU_SI_REC *)m_NCS_DBLIST_FIND_FIRST(&su->si_list);
> +                osafassert(si);
> +                csi = (AVND_COMP_CSI_REC 
> *)m_NCS_DBLIST_FIND_FIRST(&si->csi_list);
> +                if (csi) {
> +                     /* This CSI must be in restarting state. We will mark it
> +                        AVND_COMP_CSI_ASSIGN_STATE_ASSIGNED after the 
> instantiation
> +                        of associated component.
> +                      */
> +                        TRACE("Running the component CLC FSM for csi:%s, 
> comp:%s",
> +                                     csi->name.value, comp->name.value);
> +                        rc = avnd_comp_clc_fsm_run(cb, csi->comp, 
> AVND_COMP_CLC_PRES_FSM_EV_INST);
> +                        if (NCSCC_RC_SUCCESS != rc)
> +                                goto done;
> +                }
> +        }
> +     avnd_su_pres_state_set(su, SA_AMF_PRESENCE_INSTANTIATING);
> +done:
> +     TRACE_LEAVE();
> +     return rc;
> +}
>   
> /****************************************************************************
>     Name          : avnd_su_pres_restart_compinst_hdler
>    
> @@ -3074,7 +3429,7 @@ uint32_t avnd_su_pres_instfailed_compuni
>    */
>   bool sufailover_in_progress(const AVND_SU *su)
>   {
> -     if (m_AVND_SU_IS_FAILED(su) && (su->sufailover) &&
> +     if (m_AVND_SU_IS_FAILED(su) && (su->sufailover) && 
> (!m_AVND_SU_IS_RESTART(su)) &&
>                        (avnd_cb->oper_state != SA_AMF_OPERATIONAL_DISABLED) 
> && (!su->is_ncs))
>                               return true;
>       return false;
> @@ -3088,7 +3443,7 @@ bool sufailover_in_progress(const AVND_S
>    */
>   bool sufailover_during_nodeswitchover(const AVND_SU *su)
>   {
> -     if ((m_AVND_SU_IS_FAILED(su) && (su->sufailover) &&
> +     if ((m_AVND_SU_IS_FAILED(su) && (su->sufailover) && 
> (!m_AVND_SU_IS_RESTART(su)) &&
>                               (avnd_cb->term_state == 
> AVND_TERM_STATE_NODE_SWITCHOVER_STARTED) &&
>                               (!su->is_ncs)))
>               return true;
> @@ -3096,3 +3451,215 @@ bool sufailover_during_nodeswitchover(co
>       return false;
>   }
>   
> +/**
> + * @brief  handler for for restart recovery or admin op on su
> + *         when a SU is in terminating state.
> + * @param  ptr to avnd_cb.
> + * @param  ptr to su.
> + * @param  ptr to comp.
> + * @return  NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE.
> + */
> +uint32_t avnd_su_pres_terming_surestart_hdler (AVND_CB *cb, AVND_SU *su, 
> AVND_COMP *comp)
> +{
> +     AVND_COMP *curr_comp = 0;
> +     AVND_SU_SI_REC *si = 0;
> +     AVND_COMP_CSI_REC *csi = 0;
> +     uint32_t rc = NCSCC_RC_SUCCESS;
> +     TRACE_ENTER2("SURestart event in SU terminating state: '%s'", 
> su->name.value);
> +
> +     if (m_AVND_SU_IS_PREINSTANTIABLE(su)) {
> +             TRACE("PI SU:'%s'",su->name.value);
> +             for (curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_LAST(&su->comp_list));
> +                  curr_comp;
> +                  curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_PREV(&curr_comp->su_dll_node)))
>  {
> +                     if ((curr_comp->pres == SA_AMF_PRESENCE_RESTARTING) ||
> +                                     (curr_comp->pres == 
> SA_AMF_PRESENCE_UNINSTANTIATED))
> +                             continue;
> +                     if (m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(curr_comp)) {
> +                             if (m_AVND_SU_IS_RESTART(su) && 
> m_AVND_SU_IS_FAILED(su))
> +                                     rc = avnd_comp_clc_fsm_run(cb, 
> curr_comp, AVND_COMP_CLC_PRES_FSM_EV_CLEANUP);
> +                             else
> +                                     rc = avnd_comp_clc_fsm_run(cb, 
> curr_comp, AVND_COMP_CLC_PRES_FSM_EV_RESTART);
> +                             if (NCSCC_RC_SUCCESS != rc)
> +                                     goto done;
> +                             break;
> +                     } else {
> +                             /*
> +                                For a NPI comp in SU, component FSM is 
> always triggered at the time of
> +                                assignments. If this component is 
> non-restartable then start
> +                                reassginment from the whole SU now.
> +                              */
> +                             if (m_AVND_COMP_IS_RESTART_DIS(curr_comp) && 
> (curr_comp->csi_list.n_nodes > 0)) {
> +                                     TRACE("Start reassignment to different 
> SU as '%s' is"
> +                                                     " not 
> restartable",curr_comp->name.value);
> +                                     su_send_suRestart_recovery_msg(su);
> +                                     goto done;
> +                             } else {
> +                                     //NPI comp in PI SU, clean it up now.
> +                                     rc = avnd_comp_clc_fsm_run(cb, 
> curr_comp, AVND_COMP_CLC_PRES_FSM_EV_CLEANUP);
> +                                     break;
> +                             }
> +                     }
> +
> +             }               /* for */
> +     }
> +
> +     /*TODO_SURESTART:Will relook for NPI SU as there seems a rare 
> possbility for surestart
> +       for NPI SU in terminating state .*/
> +     /*
> +      * If npi su, it'll have only one si-rec in the si-list. Pick the
> +      * lowest ranked csi belonging to this si & trigger it's comp fsm.
> +      */
> +     if (!m_AVND_SU_IS_PREINSTANTIABLE(su)) {
> +             TRACE("NPI SU:'%s'",su->name.value);
> +             /* get the only si rec */
> +             si = (AVND_SU_SI_REC *)m_NCS_DBLIST_FIND_FIRST(&su->si_list);
> +             osafassert(si);
> +
> +             csi = (AVND_COMP_CSI_REC 
> *)m_NCS_DBLIST_FIND_LAST(&si->csi_list);
> +             if (csi) {
> +                     m_AVND_COMP_CSI_CURR_ASSIGN_STATE_SET(csi, 
> AVND_COMP_CSI_ASSIGN_STATE_RESTARTING);
> +                     m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, csi, 
> AVND_CKPT_COMP_CSI_CURR_ASSIGN_STATE);
> +
> +                        TRACE("Running the component clc FSM for csi:'%s', 
> comp:%s",
> +                                     csi->name.value, csi->comp->name.value);
> +                     /* restart the comp */
> +                     rc = avnd_comp_clc_fsm_run(cb, csi->comp, 
> AVND_COMP_CLC_PRES_FSM_EV_RESTART);
> +                     if (NCSCC_RC_SUCCESS != rc)
> +                             goto done;
> +             }
> +                if (all_csis_in_restarting_state(su) == true) {
> +                        TRACE("All CSIs are in restarting state, so marking 
> SU restarting");
> +                        avnd_su_pres_state_set(su, 
> SA_AMF_PRESENCE_RESTARTING);
> +                }
> +     }
> + done:
> +     TRACE_LEAVE2("%u", rc);
> +     return rc;
> +}
> +
> +/**
> + * @brief  handler for for restart admin op on su
> + *         when a SU is in terminating state. Comp FSM will
> + *         invoke this event when a restartable component is terminated
> + *      during restart admin op on su.
> + * @param  ptr to avnd_cb.
> + * @param  ptr to su.
> + * @param  ptr to comp.
> + * @return  NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE.
> + */
> +uint32_t avnd_su_pres_terming_comprestart_hdler(AVND_CB *cb, AVND_SU *su, 
> AVND_COMP *comp)
> +{
> +     uint32_t rc = NCSCC_RC_SUCCESS;
> +     const char *compname = comp ? (char*)comp->name.value : "none";
> +     TRACE_ENTER2("Component restart event in the Instantiated state, '%s' : 
> '%s'",
> +                     su->name.value, compname);
> +     if (m_AVND_SU_IS_PREINSTANTIABLE(su)) {
> +             TRACE("PI SU");
> +             AVND_COMP * curr_comp = NULL;
> +             for (curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_PREV(&comp->su_dll_node));
> +                     curr_comp;
> +                     curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_PREV(&curr_comp->su_dll_node)))
>  {
> +                     if ((curr_comp->pres == SA_AMF_PRESENCE_RESTARTING) ||
> +                                     (curr_comp->pres == 
> SA_AMF_PRESENCE_UNINSTANTIATED))
> +                             continue;
> +                     if (m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(curr_comp)) {
> +                             TRACE("Running the component clc FSM");
> +                             rc = avnd_comp_clc_fsm_run(cb, curr_comp, 
> AVND_COMP_CLC_PRES_FSM_EV_RESTART);
> +                             if (NCSCC_RC_SUCCESS != rc)
> +                                     goto done;
> +                             break;
> +                     }
> +             }
> +             if (!curr_comp) {
> +                     /*
> +                        It means all comps are terminated in surestart admin 
> op.
> +                        Now instantiate SU honoring instantiation level.
> +                     */
> +                     rc = avnd_su_pres_fsm_run(cb, su, 0, 
> AVND_SU_PRES_FSM_EV_INST);
> +                     if (NCSCC_RC_SUCCESS != rc)
> +                             goto done;
> +             }
> +     }
> +done:
> +     TRACE_LEAVE();
> +     return rc;
> +}
> +
> +/**
> + * @brief  handler for instantiating a SU when it is in terminating state.
> + *         SU FSM will invoke this handler when all components are 
> terminated.
> + *      It will start instantiating comps in SU.
> + * @param  ptr to avnd_cb.
> + * @param  ptr to su.
> + * @param  ptr to comp.
> + * @return  NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE.
> + */
> +uint32_t avnd_su_pres_terming_suinst_hdler(AVND_CB *cb, AVND_SU *su, 
> AVND_COMP *comp)
> +{
> +     AVND_COMP *curr_comp = 0;
> +     AVND_SU_SI_REC *si = 0;
> +     AVND_COMP_CSI_REC *csi = 0;
> +     uint32_t rc = NCSCC_RC_SUCCESS;
> +     TRACE_ENTER2("SU Instantiate event in Terminating state: '%s'", 
> su->name.value);
> +
> +     /*
> +      * If pi su, pick the first pi comp & trigger it's FSM with InstEv.
> +      */
> +     if (m_AVND_SU_IS_PREINSTANTIABLE(su)) {
> +             TRACE("PI SU:'%s'",su->name.value);
> +             for (curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_FIRST(&su->comp_list));
> +                  curr_comp;
> +                  curr_comp = 
> m_AVND_COMP_FROM_SU_DLL_NODE_GET(m_NCS_DBLIST_FIND_NEXT(&curr_comp->su_dll_node)))
>  {
> +                     /* instantiate the pi comp */
> +                     TRACE("%s", curr_comp->name.value);
> +                     if (m_AVND_COMP_TYPE_IS_PREINSTANTIABLE(curr_comp) &&
> +                                     ((curr_comp->pres == 
> SA_AMF_PRESENCE_RESTARTING) ||
> +                                      (curr_comp->pres == 
> SA_AMF_PRESENCE_UNINSTANTIATED)) &&
> +                                      (curr_comp->pres != 
> SA_AMF_PRESENCE_INSTANTIATED)) {
> +                             TRACE("Running the component CLC FSM ");
> +                             rc = avnd_comp_clc_fsm_run(cb, curr_comp, 
> AVND_COMP_CLC_PRES_FSM_EV_INST);
> +                             if (NCSCC_RC_SUCCESS != rc)
> +                                     goto done;
> +                             break;
> +                     }
> +             }               /* for */
> +             if ((curr_comp) && (curr_comp->pres == 
> SA_AMF_PRESENCE_INSTANTIATING) &&
> +                             (su->pres == SA_AMF_PRESENCE_TERMINATING))
> +                     avnd_su_pres_state_set(su, 
> SA_AMF_PRESENCE_INSTANTIATING);
> +     }
> +
> +     /*TODO_SURESTART:Will relook for NPI SU as there seems a rare 
> possbility for su instantiate
> +       event for NPI SU in terminating state .*/
> +     /*
> +      * If npi su, it'll have only one si-rec in the si-list. Pick the
> +      * lowest ranked csi belonging to this si & trigger it's comp fsm.
> +      */
> +     if (!m_AVND_SU_IS_PREINSTANTIABLE(su)) {
> +             TRACE("NPI SU:'%s'",su->name.value);
> +             si = (AVND_SU_SI_REC *)m_NCS_DBLIST_FIND_FIRST(&su->si_list);
> +             osafassert(si);
> +
> +             csi = (AVND_COMP_CSI_REC 
> *)m_NCS_DBLIST_FIND_FIRST(&si->csi_list);
> +             if (csi) {
> +                     /* mark the csi state assigning */
> +                     m_AVND_COMP_CSI_CURR_ASSIGN_STATE_SET(csi, 
> AVND_COMP_CSI_ASSIGN_STATE_ASSIGNING);
> +                     m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, csi, 
> AVND_CKPT_COMP_CSI_CURR_ASSIGN_STATE);
> +
> +                     TRACE("Running the component CLC FSM ");
> +                     /* instantiate the comp */
> +                     rc = avnd_comp_clc_fsm_run(cb, csi->comp, 
> AVND_COMP_CLC_PRES_FSM_EV_INST);
> +                     if (NCSCC_RC_SUCCESS != rc)
> +                             goto done;
> +             }
> +             if ((csi->comp) && (csi->comp->pres == 
> SA_AMF_PRESENCE_INSTANTIATING) &&
> +                             (su->pres == SA_AMF_PRESENCE_TERMINATING))
> +                     avnd_su_pres_state_set(su, 
> SA_AMF_PRESENCE_INSTANTIATING);
> +     }
> +
> + done:
> +     if (rc == NCSCC_RC_FAILURE)
> +             avnd_su_pres_state_set(su, 
> SA_AMF_PRESENCE_INSTANTIATION_FAILED);
> +     TRACE_LEAVE2("%u", rc);
> +     return rc;
> +}


------------------------------------------------------------------------------
_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to