From 70ff6bb80bf43e55171f328c96f0e45c634a4e1f Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Fri, 9 Jun 2023 16:52:56 -0400 Subject: [PATCH] lib: mgmtd: simplify implicit commit code Signed-off-by: Christian Hopps --- lib/northbound_cli.c | 13 ++++++++++--- lib/vty.c | 4 +--- lib/vty.h | 9 ++------- mgmtd/mgmt_vty.c | 8 ++------ 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c index e9c89d2029..9d6ec66689 100644 --- a/lib/northbound_cli.c +++ b/lib/northbound_cli.c @@ -202,7 +202,7 @@ int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt, ...) return CMD_SUCCESS; implicit_commit = vty_needs_implicit_commit(vty); - ret = vty_mgmt_send_config_data(vty); + ret = vty_mgmt_send_config_data(vty, implicit_commit); if (ret >= 0 && !implicit_commit) vty->mgmt_num_pending_setcfg++; return ret; @@ -229,9 +229,16 @@ int nb_cli_apply_changes_clear_pending(struct vty *vty, if (vty_mgmt_should_process_cli_apply_changes(vty)) { VTY_CHECK_XPATH; - + /* + * The legacy user wanted to clear pending (i.e., perform a + * commit immediately) due to some non-yang compatible + * functionality. This new mgmtd code however, continues to send + * changes putting off the commit until XFRR_end is received + * (i.e., end-of-config-file). This should be fine b/c all + * conversions to mgmtd require full proper implementations. + */ implicit_commit = vty_needs_implicit_commit(vty); - ret = vty_mgmt_send_config_data(vty); + ret = vty_mgmt_send_config_data(vty, implicit_commit); if (ret >= 0 && !implicit_commit) vty->mgmt_num_pending_setcfg++; return ret; diff --git a/lib/vty.c b/lib/vty.c index fedbdbb813..c2eb78852e 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -3620,7 +3620,7 @@ int vty_mgmt_send_lockds_req(struct vty *vty, Mgmtd__DatastoreId ds_id, return 0; } -int vty_mgmt_send_config_data(struct vty *vty) +int vty_mgmt_send_config_data(struct vty *vty, bool implicit_commit) { Mgmtd__YangDataValue value[VTY_MAXCFGCHANGES]; Mgmtd__YangData cfg_data[VTY_MAXCFGCHANGES]; @@ -3628,7 +3628,6 @@ int vty_mgmt_send_config_data(struct vty *vty) Mgmtd__YangCfgDataReq *cfgreq[VTY_MAXCFGCHANGES] = {0}; size_t indx; int cnt; - bool implicit_commit = false; if (vty->type == VTY_FILE) { /* @@ -3702,7 +3701,6 @@ int vty_mgmt_send_config_data(struct vty *vty) } vty->mgmt_req_id++; - implicit_commit = vty_needs_implicit_commit(vty); if (cnt && mgmt_fe_send_setcfg_req( mgmt_fe_client, vty->mgmt_session_id, vty->mgmt_req_id, MGMTD_DS_CANDIDATE, cfgreq, diff --git a/lib/vty.h b/lib/vty.h index 28f27d0d47..3ad5c16365 100644 --- a/lib/vty.h +++ b/lib/vty.h @@ -147,7 +147,6 @@ struct vty { /* Dynamic transaction information. */ bool pending_allowed; bool pending_commit; - bool no_implicit_commit; char *pending_cmds_buf; size_t pending_cmds_buflen; size_t pending_cmds_bufpos; @@ -408,7 +407,7 @@ extern bool vty_mgmt_fe_enabled(void); extern bool vty_mgmt_should_process_cli_apply_changes(struct vty *vty); extern bool mgmt_vty_read_configs(void); -extern int vty_mgmt_send_config_data(struct vty *vty); +extern int vty_mgmt_send_config_data(struct vty *vty, bool implicit_commit); extern int vty_mgmt_send_commit_config(struct vty *vty, bool validate_only, bool abort); extern int vty_mgmt_send_get_config(struct vty *vty, @@ -422,11 +421,7 @@ extern void vty_mgmt_resume_response(struct vty *vty, bool success); static inline bool vty_needs_implicit_commit(struct vty *vty) { - return (frr_get_cli_mode() == FRR_CLI_CLASSIC - ? ((vty->pending_allowed || vty->no_implicit_commit) - ? false - : true) - : false); + return frr_get_cli_mode() == FRR_CLI_CLASSIC && !vty->pending_allowed; } #ifdef __cplusplus diff --git a/mgmtd/mgmt_vty.c b/mgmtd/mgmt_vty.c index 93c5145d71..6a6f32353d 100644 --- a/mgmtd/mgmt_vty.c +++ b/mgmtd/mgmt_vty.c @@ -157,9 +157,7 @@ DEFPY(mgmt_set_config_data, mgmt_set_config_data_cmd, vty->cfg_changes[0].operation = NB_OP_CREATE; vty->num_cfg_changes = 1; - vty->no_implicit_commit = true; - vty_mgmt_send_config_data(vty); - vty->no_implicit_commit = false; + vty_mgmt_send_config_data(vty, false); return CMD_SUCCESS; } @@ -176,9 +174,7 @@ DEFPY(mgmt_delete_config_data, mgmt_delete_config_data_cmd, vty->cfg_changes[0].operation = NB_OP_DESTROY; vty->num_cfg_changes = 1; - vty->no_implicit_commit = true; - vty_mgmt_send_config_data(vty); - vty->no_implicit_commit = false; + vty_mgmt_send_config_data(vty, false); return CMD_SUCCESS; } -- 2.39.5