Hi Minh,

It is my mistake and sorry for that. Published patch V2 is correct one. While pushing I missed the delta patch and pushed without this case. I have raised #1744 ticket.Attached is 1744.patch and I will publish it officially today.

Thanks,
Praveen

On 08-Apr-16 7:00 AM, minh chau wrote:
Hi Praveen,

I see the latest ntfa_api.c code does not reserve SA_AIS_ERR_UNAVAILABLE
when recovery client/reader/subscriber failed due to non-SA_AIS_OK rc in
returned msg. Can you check whether this V2 was pushed?

Thanks,
Minh
On 29/03/16 20:02, praveen.malv...@oracle.com wrote:
  osaf/libs/agents/saf/ntfa/ntfa.h      |    2 +
  osaf/libs/agents/saf/ntfa/ntfa_api.c  |  226
++++++++++++++++++++++++++++++++-
  osaf/libs/agents/saf/ntfa/ntfa_mds.c  |   52 +++++++
  osaf/libs/agents/saf/ntfa/ntfa_util.c |    3 +
  4 files changed, 272 insertions(+), 11 deletions(-)


V2 changes:
-Rebased over #1180 (Cloud resilience patch).
-During headless state, OpenSAF may get stopped on payload with NTF
app running.
  Since OpenSAF is not running on the payload, any A.01.02 NTF client
should not be served on
  this node and this client should not be recovered. After first
controller comes up, A.01.02
  client will not be recovered and application will get
SA_AIS_ERR_UNAVAILABLE upon which an
  app can call saNtfFinalize() for freeing the resources.


Changes include:
-maintain SAF version.
-minor version is updated from 01 to 02.
-ntfa will get NTFSV_CLM_NODE_STATUS_CALLBACK from NTFS for membership
status of node.
-check is included in all apis, excluding saNTfFinalize(), to return
SA_AIS_ERR_UNAVAILABLE
  if node loses CLM membership.

diff --git a/osaf/libs/agents/saf/ntfa/ntfa.h
b/osaf/libs/agents/saf/ntfa/ntfa.h
--- a/osaf/libs/agents/saf/ntfa/ntfa.h
+++ b/osaf/libs/agents/saf/ntfa/ntfa.h
@@ -120,6 +120,7 @@ typedef struct ntfa_client_hdl_rec {
      SYSF_MBX mbx;        /* priority q mbx b/w MDS & Library */
      struct ntfa_client_hdl_rec *next;    /* next pointer for the
list in ntfa_cb_t */
      bool valid;        /* handle is valid if it's known by NTF
server, used for headless hydra */
+    bool is_stale_client;  /* Status of client based on the CLM
status of node.*/
      SaVersionT version; /* the API version is being used by client,
used for recover after headless */
  } ntfa_client_hdl_rec_t;
@@ -148,6 +149,7 @@ typedef struct {
      SaUint32T ntf_var_data_limit;    /* max allowed variableDataSize */
      /* NTF Server state */
      ntfa_ntfsv_state_t ntfa_ntfsv_state;
+    SaClmClusterChangesT clm_node_state; /*Reflects CLM status of
this node(for future use).*/
  } ntfa_cb_t;
  /* ntfa_saf_api.c */
diff --git a/osaf/libs/agents/saf/ntfa/ntfa_api.c
b/osaf/libs/agents/saf/ntfa/ntfa_api.c
--- a/osaf/libs/agents/saf/ntfa/ntfa_api.c
+++ b/osaf/libs/agents/saf/ntfa/ntfa_api.c
@@ -966,7 +966,8 @@ SaAisErrorT reinitializeClient(ntfa_clie
      }
      if ((rc = o_msg->info.api_resp_info.rc) != SA_AIS_OK) {
          TRACE("info.api_resp_info.rc:%u",
o_msg->info.api_resp_info.rc);
-        rc = SA_AIS_ERR_BAD_HANDLE;
+        if (rc != SA_AIS_ERR_UNAVAILABLE)
+            rc = SA_AIS_ERR_BAD_HANDLE;
          goto done;
      }
@@ -1033,7 +1034,8 @@ SaAisErrorT recoverReader(ntfa_client_hd
      osafassert(o_msg != NULL);
      if ((rc = o_msg->info.api_resp_info.rc) != SA_AIS_OK) {
          TRACE("o_msg->info.api_resp_info.rc:%u",
o_msg->info.api_resp_info.rc);
-        rc = SA_AIS_ERR_BAD_HANDLE;
+        if (rc != SA_AIS_ERR_UNAVAILABLE)
+            rc = SA_AIS_ERR_BAD_HANDLE;
          goto done;
      }
@@ -1108,7 +1110,8 @@ SaAisErrorT recoverSubscriber(ntfa_clien
      if ((rc = o_msg->info.api_resp_info.rc) != SA_AIS_OK) {
          TRACE("o_msg->info.api_resp_info.rc:%u",
o_msg->info.api_resp_info.rc);
-        rc = SA_AIS_ERR_BAD_HANDLE;
+        if (rc != SA_AIS_ERR_UNAVAILABLE)
+            rc = SA_AIS_ERR_BAD_HANDLE;
          goto done;
      }
@@ -1229,7 +1232,8 @@ SaAisErrorT saNtfInitialize(SaNtfHandleT
      if ((version->releaseCode == NTF_RELEASE_CODE) &&
(version->majorVersion <= NTF_MAJOR_VERSION) &&
          (0 < version->majorVersion)) {
          version->majorVersion = NTF_MAJOR_VERSION;
-        version->minorVersion = NTF_MINOR_VERSION;
+        if (version->minorVersion != NTF_MINOR_VERSION_0)
+            version->minorVersion = NTF_MINOR_VERSION;
      } else {
          TRACE("version FAILED, required: %c.%u.%u, supported:
%c.%u.%u\n",
                version->releaseCode, version->majorVersion,
version->minorVersion,
@@ -1276,6 +1280,10 @@ SaAisErrorT saNtfInitialize(SaNtfHandleT
      if (SA_AIS_OK != o_msg->info.api_resp_info.rc) {
          rc = o_msg->info.api_resp_info.rc;
          TRACE("NTFS return FAILED");
+        /*Check CLM membership of node.*/
+        if (rc == SA_AIS_ERR_UNAVAILABLE) {
+            TRACE("Node not CLM member or stale client");
+        }
          goto err;
      }
@@ -1357,7 +1365,13 @@ SaAisErrorT saNtfSelectionObjectGet(SaNt
          rc = SA_AIS_ERR_BAD_HANDLE;
          goto done;
      }
-
+    /*Check CLM membership of node.*/
+    if (hdl_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        ncshm_give_hdl(ntfHandle);
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done;
+    }
      /* Obtain the selection object from the IPC queue */
      sel_obj = m_NCS_IPC_GET_SEL_OBJ(&hdl_rec->mbx);
@@ -1434,8 +1448,22 @@ SaAisErrorT saNtfDispatch(SaNtfHandleT n
                  ntfa_shutdown(false);
                  goto done;
              }
+            if (rc == SA_AIS_ERR_UNAVAILABLE) {
+                TRACE("Node not CLM member or stale client");
+                ncshm_give_hdl(ntfHandle);
+                goto done;
+            }
          }
      }
+
+    /*Check CLM membership of node.*/
+    if (hdl_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        ncshm_give_hdl(ntfHandle);
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done;
+    }
+
      if ((rc = ntfa_hdl_cbk_dispatch(&ntfa_cb, hdl_rec,
dispatchFlags)) != SA_AIS_OK)
          TRACE("NTFA_DISPATCH_FAILURE");
@@ -1601,6 +1629,14 @@ SaAisErrorT saNtfAlarmNotificationAlloca
      /**                 Lock ntfa_CB                 **/
      osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) == 0);
+    /*Check CLM membership of node.*/
+    if (hdl_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done_give_hdl;
+    }
+
      /** Allocate an ntfa_LOG_STREAM_HDL_REC structure and insert this
       *  into the list of channel hdl record.
       **/
@@ -1683,6 +1719,13 @@ SaAisErrorT saNtfNotificationFree(SaNtfN
          rc = SA_AIS_ERR_BAD_HANDLE;
          goto done_give_hdl;
      }
+    /*Check CLM membership of node.*/
+    if (client_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        ncshm_give_hdl(client_handle);
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done_give_hdl;
+    }
      /* free the resources allocated by
saNtf<ntfType>NotificationAllocate */
      ntfa_notification_destructor(notification_hdl_rec);
@@ -1753,6 +1796,14 @@ SaAisErrorT saNtfNotificationSend(SaNtfN
          rc = SA_AIS_ERR_BAD_HANDLE;
          goto done_give_hdl;
      }
+    /*Check CLM membership of node.*/
+    if (client_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
+        ncshm_give_hdl(client_handle);
+        goto done_give_hdl;
+    }
      osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
      /* Check NTF server availability */
@@ -1862,6 +1913,10 @@ SaAisErrorT saNtfNotificationSend(SaNtfN
      if (SA_AIS_OK != o_msg->info.api_resp_info.rc) {
          rc = o_msg->info.api_resp_info.rc;
          TRACE("Bad return status!!! rc = %d", rc);
+        /*Check CLM membership of node.*/
+        if (rc == SA_AIS_ERR_UNAVAILABLE) {
+            TRACE("Node not CLM member or stale client");
+        }
          goto done_give_hdls;
      }
      /* Return the notificationId to client from right notification */
@@ -2037,7 +2092,12 @@ SaAisErrorT saNtfNotificationSubscribe(c
              goto done;
          }
      }
-
+    /*Check CLM membership of node.*/
+    if (client_hdl_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done;
+    }
      tmpHandle = ntfHandleGet(subscriptionId);
      if (tmpHandle != 0) {
          rc = SA_AIS_ERR_EXIST;
@@ -2079,6 +2139,10 @@ SaAisErrorT saNtfNotificationSubscribe(c
      if (rc != SA_AIS_OK) {
          subscriberListItemRemove(subscriptionId);
+        /*Check CLM membership of node.*/
+        if (rc == SA_AIS_ERR_UNAVAILABLE) {
+            TRACE("Node not CLM member or stale client");
+        }
      }
      if (o_msg)
          ntfa_msg_destroy(o_msg);
@@ -2097,13 +2161,12 @@ SaAisErrorT saNtfNotificationSubscribe(c
          if (notificationFilterHandles->alarmFilterHandle)

ncshm_give_hdl(notificationFilterHandles->alarmFilterHandle);
      }
-    if (recovery_failed && rc == SA_AIS_ERR_BAD_HANDLE) {
+    if (recovery_failed && (rc == SA_AIS_ERR_BAD_HANDLE)) {
          osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) == 0);
          ntfa_hdl_rec_force_del(&ntfa_cb.client_list, client_hdl_rec);
          osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
          ntfa_shutdown(false);
      }
-
      TRACE_LEAVE();
      return rc;
  }
@@ -2155,7 +2218,13 @@ saNtfObjectCreateDeleteNotificationAlloc
      /**                 Lock ntfa_CB                 **/
      osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) == 0);
-
+    /*Check CLM membership of node.*/
+    if (hdl_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done_give_hdl;
+    }
      notification_hdl_rec = ntfa_notification_hdl_rec_add(&hdl_rec,
variableDataSize, &rc);
      if (notification_hdl_rec == NULL) {
          osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
@@ -2229,7 +2298,13 @@ saNtfAttributeChangeNotificationAllocate
      }
      /**                 Lock ntfa_CB                 **/
      osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) == 0);
-
+    /*Check CLM membership of node.*/
+    if (hdl_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done_give_hdl;
+    }
      notification_hdl_rec = ntfa_notification_hdl_rec_add(&hdl_rec,
variableDataSize, &rc);
      if (notification_hdl_rec == NULL) {
          osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
@@ -2302,6 +2377,13 @@ saNtfStateChangeNotificationAllocate(SaN
      /**                 Lock ntfa_CB                 **/
      osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) == 0);
+    /*Check CLM membership of node.*/
+    if (hdl_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done_give_hdl;
+    }
      notification_hdl_rec = ntfa_notification_hdl_rec_add(&hdl_rec,
variableDataSize, &rc);
      if (notification_hdl_rec == NULL) {
          osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
@@ -2372,6 +2454,13 @@ SaAisErrorT saNtfSecurityAlarmNotificati
      }
      /**                 Lock ntfa_CB                 **/
      osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) == 0);
+    /*Check CLM membership of node.*/
+    if (hdl_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done_give_hdl;
+    }
      notification_hdl_rec = ntfa_notification_hdl_rec_add(&hdl_rec,
variableDataSize, &rc);
      if (notification_hdl_rec == NULL) {
          osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
@@ -2444,6 +2533,14 @@ SaAisErrorT saNtfPtrValAllocate(SaNtfNot
      }
      osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) == 0);
+    /*Check CLM membership of node.*/
+    if (client_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
+        ncshm_give_hdl(client_handle);
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done_give_hdl;
+    }
      rc = ntfsv_ptr_val_alloc(&notification_hdl_rec->variable_data,
value, dataSize, dataPtr);
      osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
      ncshm_give_hdl(client_handle);
@@ -2484,6 +2581,14 @@ SaAisErrorT saNtfArrayValAllocate(SaNtfN
          goto done_give_hdl;
      }
      osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) == 0);
+    /*Check CLM membership of node.*/
+    if (client_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
+        ncshm_give_hdl(client_handle);
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done_give_hdl;
+    }
      rc = ntfsv_array_val_alloc(&notification_hdl_rec->variable_data,
value, numElements, elementSize, arrayPtr);
      osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
      ncshm_give_hdl(client_handle);
@@ -2569,6 +2674,14 @@ SaAisErrorT saNtfPtrValGet(SaNtfNotifica
      }
      osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) == 0);
+    /*Check CLM membership of node.*/
+    if (client_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
+        ncshm_give_hdl(client_handle);
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done_give_hdl;
+    }
      rc = ntfsv_ptr_val_get(&notification_hdl_rec->variable_data,
value, dataPtr, dataSize);
      osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
      ncshm_give_hdl(client_handle);
@@ -2616,6 +2729,14 @@ SaAisErrorT saNtfArrayValGet(SaNtfNotifi
      }
      osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) == 0);
+    /*Check CLM membership of node.*/
+    if (client_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
+        ncshm_give_hdl(client_handle);
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done_give_hdl;
+    }
      rc = ntfsv_array_val_get(&notification_hdl_rec->variable_data,
value, arrayPtr, numElements, elementSize);
      ncshm_give_hdl(client_handle);
      osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
@@ -2656,6 +2777,13 @@ SaAisErrorT saNtfObjectCreateDeleteNotif
       /**                 Lock ntfa_CB                 **/
      osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) == 0);
+    /*Check CLM membership of node.*/
+    if (client_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done_give_hdl;
+    }
      filter_hdl_rec = ntfa_filter_hdl_rec_add(&client_rec);
      if (filter_hdl_rec == NULL) {
@@ -2736,6 +2864,13 @@ SaAisErrorT saNtfAttributeChangeNotifica
       /**                 Lock ntfa_CB                 **/
      osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) == 0);
+    /*Check CLM membership of node.*/
+    if (client_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done_give_hdl;
+    }
      filter_hdl_rec = ntfa_filter_hdl_rec_add(&client_rec);
      if (filter_hdl_rec == NULL) {
@@ -2818,6 +2953,13 @@ SaAisErrorT saNtfStateChangeNotification
       /**                 Lock ntfa_CB                 **/
      osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) == 0);
+    /*Check CLM membership of node.*/
+    if (client_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done_give_hdl;
+    }
      filter_hdl_rec = ntfa_filter_hdl_rec_add(&client_rec);
      if (filter_hdl_rec == NULL) {
@@ -2899,6 +3041,13 @@ SaAisErrorT saNtfAlarmNotificationFilter
      /**                 Lock ntfa_CB                 **/
      osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) == 0);
+    /*Check CLM membership of node.*/
+    if (client_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done_give_hdl;
+    }
      filter_hdl_rec = ntfa_filter_hdl_rec_add(&client_rec);
      if (filter_hdl_rec == NULL) {
@@ -2983,6 +3132,13 @@ SaAisErrorT saNtfSecurityAlarmNotificati
       /**                 Lock ntfa_CB                 **/
      osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) == 0);
+    /*Check CLM membership of node.*/
+    if (client_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done_give_hdl;
+    }
      filter_hdl_rec = ntfa_filter_hdl_rec_add(&client_rec);
      if (filter_hdl_rec == NULL) {
@@ -3065,6 +3221,14 @@ SaAisErrorT saNtfNotificationFilterFree(
          goto done_give_hdl;
      }
+    /*Check CLM membership of node.*/
+    if (client_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        ncshm_give_hdl(client_handle);
+        goto done_give_hdl;
+    }
      /* free the resources allocated by saNtf<ntfType>FilterAllocate */
      ntfa_filter_destructor(filter_hdl_rec);
@@ -3128,6 +3292,12 @@ SaAisErrorT saNtfNotificationUnsubscribe
          rc = SA_AIS_ERR_BAD_HANDLE;
          goto done;
      }
+    /*Check CLM membership of node.*/
+    if (client_hdl_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done_give_hdl;
+    }
      if (client_hdl_rec->valid) {
          /**
@@ -3153,6 +3323,10 @@ SaAisErrorT saNtfNotificationUnsubscribe
          if (SA_AIS_OK != o_msg->info.api_resp_info.rc) {
              rc = o_msg->info.api_resp_info.rc;
              TRACE_1("Bad return status! rc = %d", rc);
+            /*Check CLM membership of node.*/
+            if (rc == SA_AIS_ERR_UNAVAILABLE) {
+                TRACE("Node not CLM member or stale client");
+            }
              goto done_give_hdl;
          }
      }
@@ -3256,6 +3430,12 @@ SaAisErrorT saNtfNotificationReadInitial
          TRACE("getFilters failed");
          goto done_give_client_hdl;
      }
+    /*Check CLM membership of node.*/
+    if (client_hdl_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done_give_client_hdl;
+    }

      /* Check NTF server availability */
      if ((rc = checkNtfServerState()) != SA_AIS_OK)
@@ -3292,6 +3472,10 @@ SaAisErrorT saNtfNotificationReadInitial
      if (SA_AIS_OK != o_msg->info.api_resp_info.rc) {
          rc = o_msg->info.api_resp_info.rc;
          TRACE("Bad return status!!! rc = %d", rc);
+        /*Check CLM membership of node.*/
+        if (rc == SA_AIS_ERR_UNAVAILABLE) {
+            TRACE("Node not CLM member or stale client");
+        }
          goto done_give_client_hdl;
      }
@@ -3341,7 +3525,7 @@ done_give_client_hdl:
      }
      ncshm_give_hdl(notificationFilterHandles->alarmFilterHandle);
-    if (recovery_failed && rc == SA_AIS_ERR_BAD_HANDLE) {
+    if (recovery_failed && (rc == SA_AIS_ERR_BAD_HANDLE)) {
          osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) == 0);
          ntfa_hdl_rec_force_del(&ntfa_cb.client_list, client_hdl_rec);
          osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
@@ -3387,6 +3571,12 @@ SaAisErrorT saNtfNotificationReadFinaliz
          rc = SA_AIS_ERR_BAD_HANDLE;
          goto done_give_read_hdl;
      }
+    /*Check CLM membership of node.*/
+    if (client_hdl_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done_give_hdls;
+    }
      TRACE_1("reader_hdl_rec = %u", reader_hdl_rec->reader_hdl);
      if (client_hdl_rec->valid) {
@@ -3412,6 +3602,10 @@ SaAisErrorT saNtfNotificationReadFinaliz
          if (SA_AIS_OK != o_msg->info.api_resp_info.rc) {
              rc = o_msg->info.api_resp_info.rc;
              TRACE("Bad return status!!! rc = %d", rc);
+            /*Check CLM membership of node.*/
+            if (rc == SA_AIS_ERR_UNAVAILABLE) {
+                TRACE("Node not CLM member or stale client");
+            }
              goto done_give_hdls;
          }
@@ -3497,6 +3691,12 @@ SaAisErrorT saNtfNotificationReadNext(Sa
          rc = SA_AIS_ERR_BAD_HANDLE;
          goto done_give_read_hdl;
      }
+    /*Check CLM membership of node.*/
+    if (client_hdl_rec->is_stale_client == true) {
+        TRACE("Node not CLM member or stale client");
+        rc = SA_AIS_ERR_UNAVAILABLE;
+        goto done_give_hdls;
+    }
      TRACE_1("reader_hdl_rec = %u", reader_hdl_rec->reader_hdl);
      /* Check NTF server availability */
@@ -3539,6 +3739,10 @@ SaAisErrorT saNtfNotificationReadNext(Sa
          if (SA_AIS_OK != o_msg->info.api_resp_info.rc) {
              rc = o_msg->info.api_resp_info.rc;
              TRACE("error: response msg rc = %d", rc);
+            /*Check CLM membership of node.*/
+            if (rc == SA_AIS_ERR_UNAVAILABLE) {
+                TRACE("Node not CLM member or stale client");
+            }
              goto done_give_hdls;
          }
          if (o_msg->info.api_resp_info.type != NTFSV_READ_NEXT_RSP) {
diff --git a/osaf/libs/agents/saf/ntfa/ntfa_mds.c
b/osaf/libs/agents/saf/ntfa/ntfa_mds.c
--- a/osaf/libs/agents/saf/ntfa/ntfa_mds.c
+++ b/osaf/libs/agents/saf/ntfa/ntfa_mds.c
@@ -270,6 +270,33 @@ uint32_t ntfa_ntfs_msg_proc(ntfa_cb_t *c
      switch (ntfsv_msg->type) {
      case NTFSV_NTFS_CBK_MSG:
          switch (ntfsv_msg->info.cbk_info.type) {
+        case NTFSV_CLM_NODE_STATUS_CALLBACK:
+            {
+                ntfa_client_hdl_rec_t *ntfa_hdl_rec;
+                ntfsv_ntfa_clm_status_cbk_t *param =
&ntfsv_msg->info.cbk_info.param.clm_node_status_cbk;
+                TRACE_2("NTFSV_CLM_NODE_STATUS_CALLBACK: "
+                        "subscriptionId = %d,"
+                        " client_id = %d",
+                        (int)ntfsv_msg->info.cbk_info.subscriptionId,
+                        (int)ntfsv_msg->info.cbk_info.ntfs_client_id);
+                cb->clm_node_state = (SaClmClusterChangesT)
param->clm_node_status;
+                TRACE_2("CLM Membership of local node changed to : %u",
+                        cb->clm_node_state);
+                //Search client.
+                if (NULL == (ntfa_hdl_rec =
+                            ntfa_find_hdl_rec_by_client_id(cb,
+
ntfsv_msg->info.cbk_info.ntfs_client_id))) {
+                    TRACE("client_id not found");
+                    ntfa_msg_destroy(ntfsv_msg);
+                                        TRACE_LEAVE();
+                                        return NCSCC_RC_FAILURE;
+                                }
+                //A client becomes stale if Node loses CLM Membership.
+                if (cb->clm_node_state != SA_CLM_NODE_JOINED)
+                    ntfa_hdl_rec->is_stale_client = true;
+                ntfa_msg_destroy(ntfsv_msg);
+            }
+            break;
          case NTFSV_NOTIFICATION_CALLBACK:
              {
                  ntfa_client_hdl_rec_t *ntfa_hdl_rec;
@@ -620,6 +647,27 @@ static uint32_t ntfa_dec_not_discard_cbk
      return ntfsv_dec_discard_msg(uba, param);
  }
+/**
+ * @brief  Decodes CLM node status callback msg.
+ *
+ * @param  ptr to NCS_UBAID.
+ * @param  ptr to ntfsv_msg_t.
+ *
+ * @return NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE.
+ */
+static uint32_t ntfa_dec_clm_node_status_cbk_msg(NCS_UBAID *uba,
ntfsv_msg_t *msg)
+{
+    uint8_t *p8;
+    ntfsv_ntfa_clm_status_cbk_t *param =
&msg->info.cbk_info.param.clm_node_status_cbk;
+    uint8_t local_data[2];
+
+    osafassert(uba != NULL);
+
+    p8 = ncs_dec_flatten_space(uba, local_data, 2);
+    param->clm_node_status = ncs_decode_16bit(&p8);
+    ncs_dec_skip_space(uba, 2);
+    return NCSCC_RC_SUCCESS;
+}

/****************************************************************************

    Name          : ntfa_dec_subscribe_rsp_msg
@@ -862,6 +910,10 @@ static uint32_t ntfa_mds_dec(struct ncsm
                  TRACE_2("decode discarded cbk message");
                  rc = ntfa_dec_not_discard_cbk_msg(uba, msg);
                  break;
+            case NTFSV_CLM_NODE_STATUS_CALLBACK:
+                TRACE_2("decode clm node status cbk message");
+                rc = ntfa_dec_clm_node_status_cbk_msg(uba, msg);
+                break;
              default:
                  TRACE_2("Unknown callback type = %d!",
msg->info.cbk_info.type);
                  rc = NCSCC_RC_FAILURE;
diff --git a/osaf/libs/agents/saf/ntfa/ntfa_util.c
b/osaf/libs/agents/saf/ntfa/ntfa_util.c
--- a/osaf/libs/agents/saf/ntfa/ntfa_util.c
+++ b/osaf/libs/agents/saf/ntfa/ntfa_util.c
@@ -53,6 +53,8 @@ static unsigned int ntfa_create(void)
      pthread_mutex_lock(&ntfa_cb.cb_lock);
      ntfa_cb.ntfs_sync_awaited = 0;
+    ntfa_cb.clm_node_state = SA_CLM_NODE_JOINED;
+
      pthread_mutex_unlock(&ntfa_cb.cb_lock);
      /* No longer needed */
@@ -1149,6 +1151,7 @@ ntfa_client_hdl_rec_t *ntfa_hdl_rec_add(
       **/
      rec->ntfs_client_id = client_id;
      rec->valid = true;
+    rec->is_stale_client = false;
      /** Initialize and attach the IPC/Priority queue
       **/


diff --git a/osaf/libs/agents/saf/ntfa/ntfa_api.c 
b/osaf/libs/agents/saf/ntfa/ntfa_api.c
--- a/osaf/libs/agents/saf/ntfa/ntfa_api.c
+++ b/osaf/libs/agents/saf/ntfa/ntfa_api.c
@@ -966,7 +966,8 @@ SaAisErrorT reinitializeClient(ntfa_clie
        }
        if ((rc = o_msg->info.api_resp_info.rc) != SA_AIS_OK) {
                TRACE("info.api_resp_info.rc:%u", o_msg->info.api_resp_info.rc);
-               rc = SA_AIS_ERR_BAD_HANDLE;
+               if (rc != SA_AIS_ERR_UNAVAILABLE)
+                       rc = SA_AIS_ERR_BAD_HANDLE;
                goto done;
        }
 
@@ -1033,7 +1034,8 @@ SaAisErrorT recoverReader(ntfa_client_hd
        osafassert(o_msg != NULL);
        if ((rc = o_msg->info.api_resp_info.rc) != SA_AIS_OK) {
                TRACE("o_msg->info.api_resp_info.rc:%u", 
o_msg->info.api_resp_info.rc);
-               rc = SA_AIS_ERR_BAD_HANDLE;
+               if (rc != SA_AIS_ERR_UNAVAILABLE)
+                       rc = SA_AIS_ERR_BAD_HANDLE;
                goto done;
        }
 
@@ -1108,7 +1110,8 @@ SaAisErrorT recoverSubscriber(ntfa_clien
 
        if ((rc = o_msg->info.api_resp_info.rc) != SA_AIS_OK) {
                TRACE("o_msg->info.api_resp_info.rc:%u", 
o_msg->info.api_resp_info.rc);
-               rc = SA_AIS_ERR_BAD_HANDLE;
+               if (rc != SA_AIS_ERR_UNAVAILABLE)
+                       rc = SA_AIS_ERR_BAD_HANDLE;
                goto done;
        }
 
@@ -1437,7 +1440,7 @@ SaAisErrorT saNtfDispatch(SaNtfHandleT n
        if (!hdl_rec->valid) {
                /* recovery */
                if ((rc = recoverClient(hdl_rec)) != SA_AIS_OK) {
-                       if ((rc == SA_AIS_ERR_BAD_HANDLE) || (rc == 
SA_AIS_ERR_UNAVAILABLE)) {
+                       if (rc == SA_AIS_ERR_BAD_HANDLE) {
                                ncshm_give_hdl(ntfHandle);
                                osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) 
== 0);
                                ntfa_hdl_rec_force_del(&ntfa_cb.client_list, 
hdl_rec);
@@ -1445,6 +1448,11 @@ SaAisErrorT saNtfDispatch(SaNtfHandleT n
                                ntfa_shutdown(false);
                                goto done;
                        }
+                       if (rc == SA_AIS_ERR_UNAVAILABLE) {
+                               TRACE("Node not CLM member or stale client");
+                               ncshm_give_hdl(ntfHandle);
+                               goto done;
+                       }
                }
        }
 
@@ -1807,7 +1815,7 @@ SaAisErrorT saNtfNotificationSend(SaNtfN
                if ((rc = recoverClient(client_rec)) != SA_AIS_OK) {
                        ncshm_give_hdl(client_handle);
                        ncshm_give_hdl(notificationHandle);
-                       if ((rc == SA_AIS_ERR_BAD_HANDLE) || (rc == 
SA_AIS_ERR_UNAVAILABLE)) {
+                       if (rc == SA_AIS_ERR_BAD_HANDLE) {
                                osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) 
== 0);
                                ntfa_hdl_rec_force_del(&ntfa_cb.client_list, 
client_rec);
                                
osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
@@ -2153,7 +2161,7 @@ SaAisErrorT saNtfNotificationSubscribe(c
                if (notificationFilterHandles->alarmFilterHandle)
                        
ncshm_give_hdl(notificationFilterHandles->alarmFilterHandle);
        }
-       if (recovery_failed && ((rc == SA_AIS_ERR_BAD_HANDLE) || (rc == 
SA_AIS_ERR_UNAVAILABLE))) {
+       if (recovery_failed && (rc == SA_AIS_ERR_BAD_HANDLE)) {
                osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) == 0);
                ntfa_hdl_rec_force_del(&ntfa_cb.client_list, client_hdl_rec);
                osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
@@ -3355,7 +3363,7 @@ SaAisErrorT saNtfNotificationUnsubscribe
 
        if (!client_hdl_rec->valid && getServerState() == NTFA_NTFSV_UP) {
                if ((rc = recoverClient(client_hdl_rec)) != SA_AIS_OK) {
-                       if ((rc == SA_AIS_ERR_BAD_HANDLE) || (rc == 
SA_AIS_ERR_UNAVAILABLE)) {
+                       if (rc == SA_AIS_ERR_BAD_HANDLE) {
                                ncshm_give_hdl(ntfHandle);
                                osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) 
== 0);
                                ntfa_hdl_rec_force_del(&ntfa_cb.client_list, 
client_hdl_rec);
@@ -3517,7 +3525,7 @@ done_give_client_hdl:
        }
 
        ncshm_give_hdl(notificationFilterHandles->alarmFilterHandle);
-       if (recovery_failed && ((rc == SA_AIS_ERR_BAD_HANDLE) || (rc == 
SA_AIS_ERR_UNAVAILABLE))) {
+       if (recovery_failed && (rc == SA_AIS_ERR_BAD_HANDLE)) {
                osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) == 0);
                ntfa_hdl_rec_force_del(&ntfa_cb.client_list, client_hdl_rec);
                osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
@@ -3621,7 +3629,7 @@ SaAisErrorT saNtfNotificationReadFinaliz
 
        if (!client_hdl_rec->valid && getServerState() == NTFA_NTFSV_UP) {
                if ((rc = recoverClient(client_hdl_rec)) != SA_AIS_OK) {
-                       if ((rc == SA_AIS_ERR_BAD_HANDLE) || (rc == 
SA_AIS_ERR_UNAVAILABLE)) {
+                       if (rc == SA_AIS_ERR_BAD_HANDLE) {
                                ncshm_give_hdl(client_hdl_rec->local_hdl);
                                ncshm_give_hdl(readhandle);
                                osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) 
== 0);
@@ -3699,7 +3707,7 @@ SaAisErrorT saNtfNotificationReadNext(Sa
                if ((rc = recoverClient(client_hdl_rec)) != SA_AIS_OK) {
                        ncshm_give_hdl(client_hdl_rec->local_hdl);
                        ncshm_give_hdl(readHandle);
-                       if ((rc == SA_AIS_ERR_BAD_HANDLE) || (rc == 
SA_AIS_ERR_UNAVAILABLE)) {
+                       if (rc == SA_AIS_ERR_BAD_HANDLE) {
                                osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) 
== 0);
                                ntfa_hdl_rec_force_del(&ntfa_cb.client_list, 
client_hdl_rec);
                                
osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial! http://pubads.g.doubleclick.net/
gampad/clk?id=1444514301&iu=/ca-pub-7940484522588532
_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to