When there are no more log client in log agent, unregister mds and shutdown log
agent.
---
src/log/agent/lga_agent.cc | 18 +++++++++++++++
src/log/agent/lga_agent.h | 3 +++
src/log/agent/lga_mds.cc | 28 +++++++++++++++++++++++
src/log/agent/lga_mds.h | 1 +
src/log/agent/lga_util.cc | 47 ++++++++++++++++++++++++++++++++++++++
src/log/agent/lga_util.h | 1 +
6 files changed, 98 insertions(+)
diff --git a/src/log/agent/lga_agent.cc b/src/log/agent/lga_agent.cc
index b61d82a03..bbff2b0ad 100644
--- a/src/log/agent/lga_agent.cc
+++ b/src/log/agent/lga_agent.cc
@@ -625,6 +625,11 @@ SaAisErrorT LogAgent::saLogDispatch(SaLogHandleT logHandle,
return ais_rc;
}
+size_t LogAgent::CountClient() {
+ ScopeLock scopeLock(mutex_);
+ return client_list_.size();
+}
+
SaAisErrorT LogAgent::SendFinalizeMsg(uint32_t client_id) {
uint32_t mds_rc;
lgsv_msg_t msg, *o_msg = nullptr;
@@ -671,6 +676,7 @@ SaAisErrorT LogAgent::saLogFinalize(SaLogHandleT logHandle)
{
bool updated = false;
bool is_locked = false;
SaAisErrorT ais_rc = SA_AIS_OK;
+ int rc;
TRACE_ENTER();
@@ -751,6 +757,18 @@ SaAisErrorT LogAgent::saLogFinalize(SaLogHandleT
logHandle) {
}
}
+ if (CountClient() == 0) {
+ // Shutdown the agent if there are no clients
+ rc = lga_shutdown();
+ if (rc != NCSCC_RC_SUCCESS) {
+ TRACE("lga_shutdown FAILED");
+ ais_rc = SA_AIS_ERR_LIBRARY;
+ }
+ m_NCS_SEL_OBJ_RMV_IND(&init_clm_status_sel_, true, false);
+ m_NCS_SEL_OBJ_RMV_IND(&log_server_up_sel_, true, false);
+ atomic_data_.waiting_log_server_up = true;
+ }
+
TRACE_LEAVE2("ais_rc = %s", saf_error(ais_rc));
return ais_rc;
}
diff --git a/src/log/agent/lga_agent.h b/src/log/agent/lga_agent.h
index 957adc716..55632684a 100644
--- a/src/log/agent/lga_agent.h
+++ b/src/log/agent/lga_agent.h
@@ -198,6 +198,9 @@ class LogAgent {
// True if there is no LOG server at all (headless)
bool is_no_log_server() const;
+ // Count number of clients in agent
+ size_t CountClient();
+
// Form finalize Msg and send to MDS
SaAisErrorT SendFinalizeMsg(uint32_t client_id);
diff --git a/src/log/agent/lga_mds.cc b/src/log/agent/lga_mds.cc
index 838eca5e1..2836ce2ed 100644
--- a/src/log/agent/lga_mds.cc
+++ b/src/log/agent/lga_mds.cc
@@ -1329,6 +1329,34 @@ uint32_t lga_mds_init() {
return rc;
}
+/****************************************************************************
+ Name : lga_mds_deinit
+
+ Description : This routine unregisters the LGA Service in MDS.
+
+ Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE
+
+ Notes : None.
+******************************************************************************/
+uint32_t lga_mds_deinit() {
+ NCSMDS_INFO mds_info;
+ uint32_t rc = NCSCC_RC_SUCCESS;
+ std::atomic<MDS_HDL> &mds_hdl = LogAgent::instance()->atomic_get_mds_hdl();
+ TRACE_ENTER();
+
+ memset(&mds_info, 0, sizeof(NCSMDS_INFO));
+ mds_info.i_mds_hdl = mds_hdl.load();
+ mds_info.i_svc_id = NCSMDS_SVC_ID_LGA;
+ mds_info.i_op = MDS_UNINSTALL;
+ if ((rc = ncsmds_api(&mds_info)) != NCSCC_RC_SUCCESS) {
+ TRACE("mds api call failed");
+ return NCSCC_RC_FAILURE;
+ }
+
+ TRACE_LEAVE();
+ return rc;
+}
+
/****************************************************************************
Name : lga_mds_msg_sync_send
diff --git a/src/log/agent/lga_mds.h b/src/log/agent/lga_mds.h
index 2fbe906e3..af5608849 100644
--- a/src/log/agent/lga_mds.h
+++ b/src/log/agent/lga_mds.h
@@ -25,6 +25,7 @@ struct lga_cb_t;
struct lgsv_msg_t;
uint32_t lga_mds_init();
+uint32_t lga_mds_deinit();
void lga_msg_destroy(lgsv_msg_t *msg);
uint32_t lga_mds_msg_sync_send(lgsv_msg_t *i_msg, lgsv_msg_t **o_msg,
diff --git a/src/log/agent/lga_util.cc b/src/log/agent/lga_util.cc
index d64496839..c1a50f5ae 100644
--- a/src/log/agent/lga_util.cc
+++ b/src/log/agent/lga_util.cc
@@ -54,12 +54,32 @@ static unsigned int lga_create() {
TRACE("WaitLogServerUp FAILED");
// Delete the lga init instances
LogAgent::instance()->RemoveAllLogClients();
+ // Unregister MDS
+ lga_mds_deinit();
return rc;
}
return rc;
}
+/**
+ * Delete log agent
+ *
+ * @return unsigned int
+ */
+static unsigned int lga_delete() {
+ unsigned int rc = NCSCC_RC_SUCCESS;
+
+ // Unregister in MDS
+ rc = lga_mds_deinit();
+ if (rc != NCSCC_RC_SUCCESS) {
+ TRACE("lga_mds_deinit FAILED");
+ rc = NCSCC_RC_FAILURE;
+ }
+
+ return rc;
+}
+
/**
* Initiate the agent when first used.
* Start NCS service
@@ -92,6 +112,33 @@ done:
return rc;
}
+/**
+ * Shutdown the agent when not in use
+ * Stop NCS service and unregister MDS
+ *
+ * @return unsigned int
+ */
+unsigned int lga_shutdown() {
+ unsigned int rc = NCSCC_RC_SUCCESS;
+ ScopeLock lock(init_lock);
+ std::atomic<MDS_HDL>& mds_hdl = LogAgent::instance()->atomic_get_mds_hdl();
+ TRACE_ENTER();
+
+ if (mds_hdl) {
+ rc = lga_delete();
+ if (rc != NCSCC_RC_SUCCESS) {
+ TRACE("lga_delete FAILED");
+ goto done;
+ }
+ ncs_agents_shutdown();
+ mds_hdl = 0;
+ }
+
+done:
+ TRACE_LEAVE2("rc: %u", rc);
+ return rc;
+}
+
/**
* Increase user counter
* The function help to trace number of clients
diff --git a/src/log/agent/lga_util.h b/src/log/agent/lga_util.h
index 81175dd22..179c6ae9d 100644
--- a/src/log/agent/lga_util.h
+++ b/src/log/agent/lga_util.h
@@ -23,6 +23,7 @@
#include <saLog.h>
unsigned int lga_startup();
+unsigned int lga_shutdown();
void lga_increase_user_counter(void);
void lga_decrease_user_counter(void);
--
2.17.1
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel