summaryrefslogtreecommitdiffstats
path: root/mgmtd/mgmt_fe_adapter.c
diff options
context:
space:
mode:
authorYash Ranjan <ranjany@vmware.com>2021-10-28 09:07:11 +0200
committerChristian Hopps <chopps@labn.net>2023-03-22 03:08:32 +0100
commit74335ceb2753cc73afe2854b20640018431acc19 (patch)
tree0ff2afc2aacd7078131086fd6051321725b5cd94 /mgmtd/mgmt_fe_adapter.c
parentmgmtd: Add MGMT Backend Interface Framework (diff)
downloadfrr-74335ceb2753cc73afe2854b20640018431acc19.tar.xz
frr-74335ceb2753cc73afe2854b20640018431acc19.zip
mgmtd: Add MGMT Transaction Framework
This commit introduces the MGMT Transaction framework that takes management requests from one (or more) frontend client sessions, translates them into transactions and drives them to completion in co-oridination with one (or more) backend client daemons involved in the request. This commit includes the following functionalities in the changeset: 1. Introduces the actual Transaction module. Commands added related to transaction are: a. show mgmt transaction all 2. Adds support for commit rollback feature which stores upto the 10 commit buffers. Each commit has a commit-id which can be used to rollback to the exact configuration state. Commands supported for this feature are: a. show mgmt commit-history b. mgmt rollback commit-id COMMIT_ID 3. Add hidden commands to enable record various performance metrics: a. mgmt performance-measurement b. mgmt reset-statistic Co-authored-by: Pushpasis Sarkar <pushpasis@gmail.com> Co-authored-by: Abhinay Ramesh <rabhinay@vmware.com> Co-authored-by: Ujwal P <ujwalp@vmware.com> Signed-off-by: Yash Ranjan <ranjany@vmware.com>
Diffstat (limited to 'mgmtd/mgmt_fe_adapter.c')
-rw-r--r--mgmtd/mgmt_fe_adapter.c289
1 files changed, 126 insertions, 163 deletions
diff --git a/mgmtd/mgmt_fe_adapter.c b/mgmtd/mgmt_fe_adapter.c
index fa1e0826d..1ea812c1a 100644
--- a/mgmtd/mgmt_fe_adapter.c
+++ b/mgmtd/mgmt_fe_adapter.c
@@ -180,10 +180,11 @@ mgmt_fe_session_cfg_txn_cleanup(struct mgmt_fe_session_ctx *session)
}
}
- /* TODO: Destroy the actual transaction created earlier.
- * if (session->cfg_txn_id != MGMTD_TXN_ID_NONE)
- * mgmt_destroy_txn(&session->cfg_txn_id);
+ /*
+ * Destroy the actual transaction created earlier.
*/
+ if (session->cfg_txn_id != MGMTD_TXN_ID_NONE)
+ mgmt_destroy_txn(&session->cfg_txn_id);
}
static void
@@ -200,10 +201,11 @@ mgmt_fe_session_show_txn_cleanup(struct mgmt_fe_session_ctx *session)
}
}
- /* TODO: Destroy the transaction created recently.
- * if (session->txn_id != MGMTD_TXN_ID_NONE)
- * mgmt_destroy_txn(&session->txn_id);
+ /*
+ * Destroy the transaction created recently.
*/
+ if (session->txn_id != MGMTD_TXN_ID_NONE)
+ mgmt_destroy_txn(&session->txn_id);
}
static void
@@ -687,9 +689,6 @@ mgmt_fe_session_register_event(struct mgmt_fe_session_ctx *session,
&tv, &session->proc_show_txn_clnp);
assert(session->proc_show_txn_clnp);
break;
- default:
- assert(!"mgmt_fe_adapter_post_event() called incorrectly");
- break;
}
}
@@ -834,7 +833,7 @@ static int
mgmt_fe_session_handle_setcfg_req_msg(struct mgmt_fe_session_ctx *session,
Mgmtd__FeSetConfigReq *setcfg_req)
{
- /* uint64_t cfg_session_id; */
+ uint64_t cfg_session_id;
struct mgmt_ds_ctx *ds_ctx, *dst_ds_ctx;
if (mm->perf_stats_en)
@@ -867,20 +866,20 @@ mgmt_fe_session_handle_setcfg_req_msg(struct mgmt_fe_session_ctx *session,
if (session->cfg_txn_id == MGMTD_TXN_ID_NONE) {
/*
- * TODO: Check first if the current session can run a CONFIG
+ * Check first if the current session can run a CONFIG
* transaction or not. Report failure if a CONFIG transaction
* from another session is already in progress.
- * cfg_session_id = mgmt_config_txn_in_progress();
- * if (cfg_session_id != MGMTD_SESSION_ID_NONE
- * && cfg_session_id != session->session_id) {
- * mgmt_fe_send_setcfg_reply(
- * session, setcfg_req->ds_id, setcfg_req->req_id,
- * false,
- * "Configuration already in-progress through a
- *different user session!", setcfg_req->implicit_commit); goto
- *mgmt_fe_sess_handle_setcfg_req_failed;
- *}
*/
+ cfg_session_id = mgmt_config_txn_in_progress();
+ if (cfg_session_id != MGMTD_SESSION_ID_NONE
+ && cfg_session_id != session->session_id) {
+ mgmt_fe_send_setcfg_reply(
+ session, setcfg_req->ds_id, setcfg_req->req_id,
+ false,
+ "Configuration already in-progress through a different user session!",
+ setcfg_req->implicit_commit);
+ goto mgmt_fe_sess_handle_setcfg_req_failed;
+ }
/*
@@ -902,18 +901,18 @@ mgmt_fe_session_handle_setcfg_req_msg(struct mgmt_fe_session_ctx *session,
}
/*
- * TODO: Start a CONFIG Transaction (if not started already)
- * session->cfg_txn_id = mgmt_create_txn(session->session_id,
- * MGMTD_TXN_TYPE_CONFIG);
- * if (session->cfg_txn_id == MGMTD_SESSION_ID_NONE) {
- * mgmt_fe_send_setcfg_reply(
- * session, setcfg_req->ds_id, setcfg_req->req_id,
- * false,
- * "Failed to create a Configuration session!",
- * setcfg_req->implicit_commit);
- * goto mgmt_fe_sess_handle_setcfg_req_failed;
- * }
+ * Start a CONFIG Transaction (if not started already)
*/
+ session->cfg_txn_id = mgmt_create_txn(session->session_id,
+ MGMTD_TXN_TYPE_CONFIG);
+ if (session->cfg_txn_id == MGMTD_SESSION_ID_NONE) {
+ mgmt_fe_send_setcfg_reply(
+ session, setcfg_req->ds_id, setcfg_req->req_id,
+ false,
+ "Failed to create a Configuration session!",
+ setcfg_req->implicit_commit);
+ goto mgmt_fe_sess_handle_setcfg_req_failed;
+ }
MGMTD_FE_ADAPTER_DBG(
"Created new Config Txn 0x%llx for session %p",
@@ -950,36 +949,31 @@ mgmt_fe_session_handle_setcfg_req_msg(struct mgmt_fe_session_ctx *session,
}
}
- /* TODO: Create the SETConfig request under the transaction.
- * if (mgmt_txn_send_set_config_req(
- * session->cfg_txn_id, setcfg_req->req_id, setcfg_req->ds_id,
- * ds_ctx, setcfg_req->data, setcfg_req->n_data,
- * setcfg_req->implicit_commit, setcfg_req->commit_ds_id,
- * dst_ds_ctx)
- * != 0) {
- * mgmt_fe_send_setcfg_reply(
- * session, setcfg_req->ds_id, setcfg_req->req_id, false,
- * "Request processing for SET-CONFIG failed!",
- * setcfg_req->implicit_commit);
- * goto mgmt_fe_sess_handle_setcfg_req_failed;
- * }
- *
- * For now send a failure reply.
+ /*
+ * Create the SETConfig request under the transaction.
*/
- mgmt_fe_send_setcfg_reply(
- session, setcfg_req->ds_id, setcfg_req->req_id, false,
- "Request processing for SET-CONFIG failed!",
- setcfg_req->implicit_commit);
- goto mgmt_fe_sess_handle_setcfg_req_failed;
+ if (mgmt_txn_send_set_config_req(
+ session->cfg_txn_id, setcfg_req->req_id, setcfg_req->ds_id,
+ ds_ctx, setcfg_req->data, setcfg_req->n_data,
+ setcfg_req->implicit_commit, setcfg_req->commit_ds_id,
+ dst_ds_ctx)
+ != 0) {
+ mgmt_fe_send_setcfg_reply(
+ session, setcfg_req->ds_id, setcfg_req->req_id, false,
+ "Request processing for SET-CONFIG failed!",
+ setcfg_req->implicit_commit);
+ goto mgmt_fe_sess_handle_setcfg_req_failed;
+ }
return 0;
mgmt_fe_sess_handle_setcfg_req_failed:
- /* TODO: Delete transaction created recently.
- * if (session->cfg_txn_id != MGMTD_TXN_ID_NONE)
- * mgmt_destroy_txn(&session->cfg_txn_id);
+ /*
+ * Delete transaction created recently.
*/
+ if (session->cfg_txn_id != MGMTD_TXN_ID_NONE)
+ mgmt_destroy_txn(&session->cfg_txn_id);
if (ds_ctx && session->ds_write_locked[setcfg_req->ds_id])
mgmt_fe_session_unlock_ds(setcfg_req->ds_id, ds_ctx, session,
true, false);
@@ -1042,22 +1036,17 @@ mgmt_fe_session_handle_getcfg_req_msg(struct mgmt_fe_session_ctx *session,
}
/*
- * TODO: Start a SHOW Transaction (if not started already)
- * session->txn_id = mgmt_create_txn(session->session_id,
- * MGMTD_TXN_TYPE_SHOW);
- * if (session->txn_id == MGMTD_SESSION_ID_NONE) {
- * mgmt_fe_send_getcfg_reply(
- * session, getcfg_req->ds_id, getcfg_req->req_id,
- * false, NULL,
- * "Failed to create a Show transaction!");
- * goto mgmt_fe_sess_handle_getcfg_req_failed;
- * }
+ * Start a SHOW Transaction (if not started already)
*/
- mgmt_fe_send_getcfg_reply(
- session, getcfg_req->ds_id, getcfg_req->req_id, false,
- NULL, "Failed to create a Show transaction!");
- goto mgmt_fe_sess_handle_getcfg_req_failed;
-
+ session->txn_id = mgmt_create_txn(session->session_id,
+ MGMTD_TXN_TYPE_SHOW);
+ if (session->txn_id == MGMTD_SESSION_ID_NONE) {
+ mgmt_fe_send_getcfg_reply(
+ session, getcfg_req->ds_id, getcfg_req->req_id,
+ false, NULL,
+ "Failed to create a Show transaction!");
+ goto mgmt_fe_sess_handle_getcfg_req_failed;
+ }
MGMTD_FE_ADAPTER_DBG(
"Created new Show Txn 0x%llx for session %p",
@@ -1068,32 +1057,28 @@ mgmt_fe_session_handle_getcfg_req_msg(struct mgmt_fe_session_ctx *session,
(unsigned long long)session->txn_id, session);
}
- /* TODO: Create a GETConfig request under the transaction.
- * if (mgmt_txn_send_get_config_req(session->txn_id, getcfg_req->req_id,
- * getcfg_req->ds_id, ds_ctx,
- * getcfg_req->data, getcfg_req->n_data)
- * != 0) {
- * mgmt_fe_send_getcfg_reply(
- * session, getcfg_req->ds_id, getcfg_req->req_id, false,
- * NULL, "Request processing for GET-CONFIG failed!");
- * goto mgmt_fe_sess_handle_getcfg_req_failed;
- * }
- *
- * For now send back a failure reply.
+ /*
+ * Create a GETConfig request under the transaction.
*/
- mgmt_fe_send_getcfg_reply(
- session, getcfg_req->ds_id, getcfg_req->req_id, false, NULL,
- "Request processing for GET-CONFIG failed!");
- goto mgmt_fe_sess_handle_getcfg_req_failed;
+ if (mgmt_txn_send_get_config_req(session->txn_id, getcfg_req->req_id,
+ getcfg_req->ds_id, ds_ctx,
+ getcfg_req->data, getcfg_req->n_data)
+ != 0) {
+ mgmt_fe_send_getcfg_reply(
+ session, getcfg_req->ds_id, getcfg_req->req_id, false,
+ NULL, "Request processing for GET-CONFIG failed!");
+ goto mgmt_fe_sess_handle_getcfg_req_failed;
+ }
return 0;
mgmt_fe_sess_handle_getcfg_req_failed:
- /* TODO: Destroy the transaction created recently.
- * if (session->txn_id != MGMTD_TXN_ID_NONE)
- * mgmt_destroy_txn(&session->txn_id);
+ /*
+ * Destroy the transaction created recently.
*/
+ if (session->txn_id != MGMTD_TXN_ID_NONE)
+ mgmt_destroy_txn(&session->txn_id);
if (ds_ctx && session->ds_read_locked[getcfg_req->ds_id])
mgmt_fe_session_unlock_ds(getcfg_req->ds_id, ds_ctx, session,
false, true);
@@ -1142,23 +1127,17 @@ mgmt_fe_session_handle_getdata_req_msg(struct mgmt_fe_session_ctx *session,
}
/*
- * TODO: Start a SHOW Transaction (if not started already)
- * session->txn_id =
- * mgmt_create_txn(session->session_id,
- * MGMTD_TXN_TYPE_SHOW);
- * if (session->txn_id == MGMTD_SESSION_ID_NONE) {
- * mgmt_fe_send_getdata_reply(
- * session, getdata_req->ds_id, getdata_req->req_id,
- * false, NULL,
- * "Failed to create a Show transaction!");
- * goto mgmt_fe_sess_handle_getdata_req_failed;
- * }
+ * Start a SHOW Transaction (if not started already)
*/
- mgmt_fe_send_getdata_reply(
- session, getdata_req->ds_id, getdata_req->req_id, false,
- NULL, "Failed to create a Show transaction!");
- goto mgmt_fe_sess_handle_getdata_req_failed;
-
+ session->txn_id = mgmt_create_txn(session->session_id,
+ MGMTD_TXN_TYPE_SHOW);
+ if (session->txn_id == MGMTD_SESSION_ID_NONE) {
+ mgmt_fe_send_getdata_reply(
+ session, getdata_req->ds_id, getdata_req->req_id,
+ false, NULL,
+ "Failed to create a Show transaction!");
+ goto mgmt_fe_sess_handle_getdata_req_failed;
+ }
MGMTD_FE_ADAPTER_DBG(
"Created new Show Txn 0x%llx for session %p",
@@ -1169,32 +1148,28 @@ mgmt_fe_session_handle_getdata_req_msg(struct mgmt_fe_session_ctx *session,
(unsigned long long)session->txn_id, session);
}
- /* TODO: Create a GETData request under the transaction.
- * if (mgmt_txn_send_get_data_req(session->txn_id, getdata_req->req_id,
- * getdata_req->ds_id, ds_ctx,
- * getdata_req->data, getdata_req->n_data)
- * != 0) {
- * mgmt_fe_send_getdata_reply(
- * session, getdata_req->ds_id, getdata_req->req_id, false,
- * NULL, "Request processing for GET-CONFIG failed!");
- * goto mgmt_fe_sess_handle_getdata_req_failed;
- * }
- *
- * For now send back a failure reply.
+ /*
+ * Create a GETData request under the transaction.
*/
- mgmt_fe_send_getdata_reply(
- session, getdata_req->ds_id, getdata_req->req_id, false, NULL,
- "Request processing for GET-CONFIG failed!");
- goto mgmt_fe_sess_handle_getdata_req_failed;
+ if (mgmt_txn_send_get_data_req(session->txn_id, getdata_req->req_id,
+ getdata_req->ds_id, ds_ctx,
+ getdata_req->data, getdata_req->n_data)
+ != 0) {
+ mgmt_fe_send_getdata_reply(
+ session, getdata_req->ds_id, getdata_req->req_id, false,
+ NULL, "Request processing for GET-CONFIG failed!");
+ goto mgmt_fe_sess_handle_getdata_req_failed;
+ }
return 0;
mgmt_fe_sess_handle_getdata_req_failed:
- /* TODO: Destroy the transaction created recently.
- * if (session->txn_id != MGMTD_TXN_ID_NONE)
- * mgmt_destroy_txn(&session->txn_id);
+ /*
+ * Destroy the transaction created recently.
*/
+ if (session->txn_id != MGMTD_TXN_ID_NONE)
+ mgmt_destroy_txn(&session->txn_id);
if (ds_ctx && session->ds_read_locked[getdata_req->ds_id])
mgmt_fe_session_unlock_ds(getdata_req->ds_id, ds_ctx,
@@ -1256,25 +1231,19 @@ static int mgmt_fe_session_handle_commit_config_req_msg(
if (session->cfg_txn_id == MGMTD_TXN_ID_NONE) {
/*
- * TODO: Start a CONFIG Transaction (if not started already)
- * session->cfg_txn_id = mgmt_create_txn(session->session_id,
- * MGMTD_TXN_TYPE_CONFIG);
- * if (session->cfg_txn_id == MGMTD_SESSION_ID_NONE) {
- * mgmt_fe_send_commitcfg_reply(
- * session, commcfg_req->src_ds_id,
- * commcfg_req->dst_ds_id, commcfg_req->req_id,
- * MGMTD_INTERNAL_ERROR,
- * commcfg_req->validate_only,
- * "Failed to create a Configuration session!");
- * return 0;
- * }
+ * Start a CONFIG Transaction (if not started already)
*/
- mgmt_fe_send_commitcfg_reply(
- session, commcfg_req->src_ds_id, commcfg_req->dst_ds_id,
- commcfg_req->req_id, MGMTD_INTERNAL_ERROR,
- commcfg_req->validate_only,
- "Failed to create a Configuration session!");
- return 0;
+ session->cfg_txn_id = mgmt_create_txn(session->session_id,
+ MGMTD_TXN_TYPE_CONFIG);
+ if (session->cfg_txn_id == MGMTD_SESSION_ID_NONE) {
+ mgmt_fe_send_commitcfg_reply(
+ session, commcfg_req->src_ds_id,
+ commcfg_req->dst_ds_id, commcfg_req->req_id,
+ MGMTD_INTERNAL_ERROR,
+ commcfg_req->validate_only,
+ "Failed to create a Configuration session!");
+ return 0;
+ }
}
@@ -1297,28 +1266,22 @@ static int mgmt_fe_session_handle_commit_config_req_msg(
session->ds_locked_implict[commcfg_req->dst_ds_id] = true;
}
- /* TODO: Create COMMITConfig request under the transaction
- * if (mgmt_txn_send_commit_config_req(
- * session->cfg_txn_id, commcfg_req->req_id,
- * commcfg_req->src_ds_id, src_ds_ctx, commcfg_req->dst_ds_id,
- * dst_ds_ctx, commcfg_req->validate_only, commcfg_req->abort,
- * false)
- * != 0) {
- * mgmt_fe_send_commitcfg_reply(
- * session, commcfg_req->src_ds_id, commcfg_req->dst_ds_id,
- * commcfg_req->req_id, MGMTD_INTERNAL_ERROR,
- * commcfg_req->validate_only,
- * "Request processing for COMMIT-CONFIG failed!");
- * return 0;
- * }
- *
- * For now due to lack of txn modules send a unsuccessfull reply.
+ /*
+ * Create COMMITConfig request under the transaction
*/
- mgmt_fe_send_commitcfg_reply(
- session, commcfg_req->src_ds_id, commcfg_req->dst_ds_id,
- commcfg_req->req_id, MGMTD_INTERNAL_ERROR,
- commcfg_req->validate_only,
- "Request processing for COMMIT-CONFIG failed!");
+ if (mgmt_txn_send_commit_config_req(
+ session->cfg_txn_id, commcfg_req->req_id,
+ commcfg_req->src_ds_id, src_ds_ctx, commcfg_req->dst_ds_id,
+ dst_ds_ctx, commcfg_req->validate_only, commcfg_req->abort,
+ false)
+ != 0) {
+ mgmt_fe_send_commitcfg_reply(
+ session, commcfg_req->src_ds_id, commcfg_req->dst_ds_id,
+ commcfg_req->req_id, MGMTD_INTERNAL_ERROR,
+ commcfg_req->validate_only,
+ "Request processing for COMMIT-CONFIG failed!");
+ return 0;
+ }
return 0;
}