]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: mgmtd: only clear pending for the in-progress command
authorChristian Hopps <chopps@labn.net>
Fri, 14 Jul 2023 20:13:54 +0000 (16:13 -0400)
committerChristian Hopps <chopps@labn.net>
Sun, 16 Jul 2023 17:18:37 +0000 (13:18 -0400)
The lock/unlocks are being done short-circuit so they are never pending;
however, the handling of the unlock notification was always resuming the command
if pending was set. In all cases pending is set for another command. For example
implicit commit locks then when notified its done unlocks which was clearing the
set-config pending flag and resuming that command incorrectly.

Signed-off-by: Christian Hopps <chopps@labn.net>
lib/mgmt_fe_client.c
lib/mgmt_fe_client.h
lib/vty.c
mgmtd/mgmt_fe_adapter.c
vtysh/vtysh.c

index da19db463f37453d6feadd866051e08f2cf14514..7e42e1c09e5e21964cfaafacff5f3ff467c9af89 100644 (file)
@@ -629,6 +629,11 @@ uint mgmt_fe_client_session_count(struct mgmt_fe_client *client)
        return mgmt_sessions_count(&client->sessions);
 }
 
+bool mgmt_fe_client_current_msg_short_circuit(struct mgmt_fe_client *client)
+{
+       return client->client.conn.is_short_circuit;
+}
+
 /*
  * Create a new Session for a Frontend Client connection.
  */
index 286141da443a94597c0706c1a2099b3ccfd464e9..349b7e4cf4154ebba9451c298f06894e3474b39e 100644 (file)
@@ -373,6 +373,12 @@ extern void mgmt_fe_client_destroy(struct mgmt_fe_client *client);
  */
 extern uint mgmt_fe_client_session_count(struct mgmt_fe_client *client);
 
+/*
+ * True if the current handled message is being short-circuited
+ */
+extern bool
+mgmt_fe_client_current_msg_short_circuit(struct mgmt_fe_client *client);
+
 #ifdef __cplusplus
 }
 #endif
index c9de00a2713dde69b0d3d64e23e94e51b4899485..23aa2d1f38d0bff3166bd49ad11fb165be2ce63a 100644 (file)
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -3524,6 +3524,7 @@ static void vty_mgmt_ds_lock_notified(struct mgmt_fe_client *client,
                                      char *errmsg_if_any)
 {
        struct vty *vty;
+       bool is_short_circuit = mgmt_fe_client_current_msg_short_circuit(client);
 
        vty = (struct vty *)session_ctx;
 
@@ -3540,8 +3541,10 @@ static void vty_mgmt_ds_lock_notified(struct mgmt_fe_client *client,
                        vty->mgmt_locked_running_ds = lock_ds;
        }
 
-       if (vty->mgmt_req_pending_cmd)
+       if (!is_short_circuit && vty->mgmt_req_pending_cmd) {
+               assert(!strcmp(vty->mgmt_req_pending_cmd, "MESSAGE_LOCKDS_REQ"));
                vty_mgmt_resume_response(vty, success);
+       }
 }
 
 static void vty_mgmt_set_config_result_notified(
@@ -3734,6 +3737,7 @@ int vty_mgmt_send_config_data(struct vty *vty, bool implicit_commit)
                } else if (vty_mgmt_lock_running_inline(vty)) {
                        vty_out(vty,
                                "%% command failed, could not lock running DS\n");
+                       vty_mgmt_unlock_candidate_inline(vty);
                        return -1;
                }
        }
index c12d8646b17c5b71043b66f86f43c6f58652a5be..98b0e8bfcdba9258ba0e745c5ec8d652237b25cc 100644 (file)
@@ -593,9 +593,8 @@ mgmt_fe_session_handle_lockds_req_msg(struct mgmt_fe_session_ctx *session,
        }
 
        if (lockds_req->lock) {
-               if (mgmt_fe_session_write_lock_ds(lockds_req->ds_id,
-                                                     ds_ctx, session)
-                   != 0) {
+               if (mgmt_fe_session_write_lock_ds(lockds_req->ds_id, ds_ctx,
+                                                 session)) {
                        fe_adapter_send_lockds_reply(
                                session, lockds_req->ds_id, lockds_req->req_id,
                                lockds_req->lock, false,
index ee52a98adb6c1bf36a3098a03d851454833e024f..6744bfe7283de5446a26bda658012b9dc1818744 100644 (file)
@@ -2356,6 +2356,7 @@ static int vtysh_exit(struct vty *vty)
        if (vty->node == CONFIG_NODE) {
                /* resync in case one of the daemons is somewhere else */
                vtysh_execute("end");
+               /* NOTE: a rather expensive thing to do, can we avoid it? */
                vtysh_execute("configure terminal file-lock");
        }
        return CMD_SUCCESS;