Hi Thien,

I think you just need create a new function
SearchAndGetClientsDownFlag(MDS_DEST  mds_dest)
Then in client_added_res_lib(), you will call SearchAndGetClientsDownFlag()
to decide send response or skip.

Best Regards,
ThuanTr

-----Original Message-----
From: thien.m.huynh <thien.m.hu...@dektech.com.au> 
Sent: Monday, October 7, 2019 10:41 AM
To: vu.m.ngu...@dektech.com.au; minh.c...@dektech.com.au
Cc: opensaf-devel@lists.sourceforge.net
Subject: [devel] [PATCH 1/1] ntfd: Do not send response to client if client
down [#3084]

Ntfd will not send response to a client when client already down.
This will avoid timeout when ntfd send via mds.
---
 src/ntf/ntfd/NtfAdmin.cc | 61
++++++++++++++++++++++++++++++++++++++++++++++++
 src/ntf/ntfd/NtfAdmin.h  |  1 +
 src/ntf/ntfd/ntfs_cb.h   |  6 +++++
 src/ntf/ntfd/ntfs_com.c  |  4 ++++
 src/ntf/ntfd/ntfs_com.h  |  1 +
 src/ntf/ntfd/ntfs_evt.c  |  1 +
 src/ntf/ntfd/ntfs_mds.c  |  2 +-
 7 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/src/ntf/ntfd/NtfAdmin.cc b/src/ntf/ntfd/NtfAdmin.cc index
8bbee69..3a0e9f6 100644
--- a/src/ntf/ntfd/NtfAdmin.cc
+++ b/src/ntf/ntfd/NtfAdmin.cc
@@ -555,6 +555,28 @@ void NtfAdmin::SearchAndSetClientsDownFlag(MDS_DEST
mds_dest) {
       client->SetClientDownFlag();
     }
   }
+
+  CLIENT_DOWN_LIST *client_down_rec = NULL;  if ((client_down_rec = 
+ reinterpret_cast<CLIENT_DOWN_LIST *>(
+           malloc(sizeof(CLIENT_DOWN_LIST)))) == NULL) {
+    LOG_ER("memory allocation for the CLIENT_DOWN_LIST failed");
+    return;
+  }
+  memset(client_down_rec, 0, sizeof(CLIENT_DOWN_LIST));  
+ client_down_rec->mds_dest = mds_dest;  client_down_rec->next = NULL;
+
+  if (ntfs_cb->client_down_list_head == NULL) {
+    ntfs_cb->client_down_list_head = client_down_rec;  } else {
+    CLIENT_DOWN_LIST *p = ntfs_cb->client_down_list_head;
+    while (p->next != NULL) {
+      p = p->next;
+    }
+    p->next = client_down_rec;
+  }
+  TRACE_1("MDS dest added: %" PRIx64, client_down_rec->mds_dest);
+
   osaf_mutex_unlock_ordie(&client_map_mutex);
   TRACE_LEAVE();
 }
@@ -1096,6 +1118,41 @@ bool NtfAdmin::is_stale_client(unsigned int
client_id) {
     return false;
 }
 
+/**
+ * @brief  Checks client added to CLIENT_DOWN_LIST.
+ *         Remove client out of list if existed.
+ * @param  mds_dest
+ * @return true/false.
+ */
+bool NtfAdmin::checkAddedAndRemove(MDS_DEST mds_dest) {
+  bool found = false;
+  CLIENT_DOWN_LIST *client_down_rec = ntfs_cb->client_down_list_head;
+  CLIENT_DOWN_LIST *prev = NULL;
+  TRACE_ENTER();
+  while (client_down_rec != NULL) {
+    if (mds_dest == client_down_rec->mds_dest) {
+      if (client_down_rec == ntfs_cb->client_down_list_head) {
+        if (client_down_rec->next == NULL) {
+          ntfs_cb->client_down_list_head = NULL;
+        } else {
+          ntfs_cb->client_down_list_head = client_down_rec->next;
+        }
+      } else if (prev) {
+        prev->next = client_down_rec->next;
+      }
+      TRACE("MDS dest %" PRIx64 " already delete",
client_down_rec->mds_dest);
+      free(client_down_rec);
+      client_down_rec = NULL;
+      found = true;
+      break;
+    }
+    prev = client_down_rec;
+    client_down_rec = client_down_rec->next;
+  }
+  TRACE_LEAVE();
+  return found;
+}
+
 // C wrapper funcions start here
 
 /**
@@ -1300,6 +1357,10 @@ uint32_t
send_clm_node_status_change(SaClmClusterChangesT cluster_change,
       cluster_change, node_id));
 }
 
+bool checkAddedAndRemove(MDS_DEST mds_dest) {
+  return (NtfAdmin::theNtfAdmin->checkAddedAndRemove(mds_dest));
+}
+
 /**
  * @brief  Checks CLM membership status of a client.
  *         A0101 clients are always CLM member.
diff --git a/src/ntf/ntfd/NtfAdmin.h b/src/ntf/ntfd/NtfAdmin.h index
4808ca9..d0c5528 100644
--- a/src/ntf/ntfd/NtfAdmin.h
+++ b/src/ntf/ntfd/NtfAdmin.h
@@ -109,6 +109,7 @@ class NtfAdmin {
   uint32_t send_cluster_membership_msg_to_clients(
       SaClmClusterChangesT cluster_change, NODE_ID node_id);
   bool is_stale_client(unsigned int clientId);
+  bool checkAddedAndRemove(MDS_DEST mds_dest);
 
  private:
   void processNotification(unsigned int clientId, diff --git
a/src/ntf/ntfd/ntfs_cb.h b/src/ntf/ntfd/ntfs_cb.h index 96eedc1..e09f8fb
100644
--- a/src/ntf/ntfd/ntfs_cb.h
+++ b/src/ntf/ntfd/ntfs_cb.h
@@ -38,6 +38,11 @@ typedef struct {
   MDS_DEST mds_dest;
 } ntf_client_t;
 
+typedef struct client_down_list {
+  MDS_DEST mds_dest;
+  struct client_down_list *next;
+} CLIENT_DOWN_LIST;
+
 typedef struct ntfs_cb {
   SYSF_MBX mbx;           /* NTFS's mailbox                             */
   MDS_HDL mds_hdl;        /* PWE Handle for interacting with NTFAs      */
@@ -71,6 +76,7 @@ typedef struct ntfs_cb {
   NCS_SEL_OBJ usr2_sel_obj; /* Selection object for CLM initialization.*/
   uint16_t peer_mbcsv_version; /*Remeber peer NTFS MBCSV version.*/
   bool clm_initialized;        // For CLM init status;
+  CLIENT_DOWN_LIST *client_down_list_head; /* client down reccords */
 } ntfs_cb_t;
 
 extern uint32_t ntfs_cb_init(ntfs_cb_t *); diff --git
a/src/ntf/ntfd/ntfs_com.c b/src/ntf/ntfd/ntfs_com.c index 35435bb..ee282dc
100644
--- a/src/ntf/ntfd/ntfs_com.c
+++ b/src/ntf/ntfd/ntfs_com.c
@@ -44,6 +44,10 @@ void client_added_res_lib(SaAisErrorT error, unsigned int
clientId,
        ntfsv_msg_t msg;
        ntfsv_ckpt_msg_t ckpt;
        TRACE_ENTER2("clientId: %u, rv: %u", clientId, error);
+       // Not respond when client already down
+       if (checkAddedAndRemove(mdsDest))
+               return;
+
        msg.type = NTFSV_NTFA_API_RESP_MSG;
        msg.info.api_resp_info.type = NTFSV_INITIALIZE_RSP;
        msg.info.api_resp_info.rc = error;
diff --git a/src/ntf/ntfd/ntfs_com.h b/src/ntf/ntfd/ntfs_com.h index
b9e37da..a570d95 100644
--- a/src/ntf/ntfd/ntfs_com.h
+++ b/src/ntf/ntfd/ntfs_com.h
@@ -204,6 +204,7 @@ uint32_t count_member_nodes();  bool
is_client_clm_member(NODE_ID node_id, SaVersionT *client_ver);  bool
is_clm_init();  bool is_stale_client(unsigned int clientId);
+bool checkAddedAndRemove(MDS_DEST mds_dest);
 
 #ifdef __cplusplus
 }
diff --git a/src/ntf/ntfd/ntfs_evt.c b/src/ntf/ntfd/ntfs_evt.c index
19b2f60..136302e 100644
--- a/src/ntf/ntfd/ntfs_evt.c
+++ b/src/ntf/ntfd/ntfs_evt.c
@@ -110,6 +110,7 @@ static uint32_t proc_ntfa_updn_mds_msg(ntfsv_ntfs_evt_t
*evt)
                } else {
                        clientRemoveMDS(evt->fr_dest);
                }
+               checkAddedAndRemove(evt->fr_dest);
                break;
        default:
                TRACE("Unknown evt type!!!");
diff --git a/src/ntf/ntfd/ntfs_mds.c b/src/ntf/ntfd/ntfs_mds.c index
5f40c6e..3d2d9f0 100644
--- a/src/ntf/ntfd/ntfs_mds.c
+++ b/src/ntf/ntfd/ntfs_mds.c
@@ -953,7 +953,7 @@ static uint32_t mds_svc_event(struct
ncsmds_callback_info *info)
 
                        /* Push the event and we are done */
                        if (m_NCS_IPC_SEND(&ntfs_cb->mbx, evt,
-                                          NCS_IPC_PRIORITY_HIGH) !=
+                                          NCS_IPC_PRIORITY_NORMAL) !=
                            NCSCC_RC_SUCCESS) {
                                TRACE("ipc send failed");
                                ntfs_evt_destroy(evt);
--
2.7.4



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



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

Reply via email to