]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: server/event_hdl: add SERVER_ADMIN event
authorAurelien DARRAGON <adarragon@haproxy.com>
Fri, 21 Apr 2023 16:06:58 +0000 (18:06 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 5 May 2023 14:28:32 +0000 (16:28 +0200)
Adding a new SERVER event in the event_hdl API.

SERVER_ADMIN is implemented as an advanced server event.
It is published each time the administrative state changes.
(when s->cur_admin changes)

SERVER_ADMIN data is an event_hdl_cb_data_server_admin struct that
provides additional info related to the admin state change, but can
be casted as a regular event_hdl_cb_data_server struct if additional
info is not needed.

include/haproxy/event_hdl-t.h
include/haproxy/server-t.h
src/event_hdl.c
src/server.c

index 55d4da8a7d08daef9c19380976cbff634ab41533..249cfeda2ef7dd6964ba722cdfef1f2b58200f5d 100644 (file)
@@ -270,6 +270,8 @@ struct event_hdl_sub {
 #define EVENT_HDL_SUB_SERVER_DOWN                       EVENT_HDL_SUB_TYPE(1,4)
 /* server state change */
 #define EVENT_HDL_SUB_SERVER_STATE                      EVENT_HDL_SUB_TYPE(1,5)
+/* server admin change */
+#define EVENT_HDL_SUB_SERVER_ADMIN                      EVENT_HDL_SUB_TYPE(1,6)
 
 /*     ---------------------------------------        */
 
index c9986dbd77c78edec7396e3a3f914e076cecc35d..60eb92555f00588106f4a4ec50740e754ac73881 100644 (file)
@@ -442,6 +442,7 @@ struct event_hdl_cb_data_server {
         *   EVENT_HDL_SUB_SERVER_UP
         *   EVENT_HDL_SUB_SERVER_DOWN
         *   EVENT_HDL_SUB_SERVER_STATE
+        *   EVENT_HDL_SUB_SERVER_ADMIN
         */
        struct {
                /* safe data can be safely used from both
@@ -522,6 +523,26 @@ struct event_hdl_cb_data_server_state {
        /* no unsafe data */
 };
 
+/* data provided to EVENT_HDL_SUB_SERVER_ADMIN handlers through
+ * event_hdl facility
+ *
+ * Note that this may be casted to regular event_hdl_cb_data_server if
+ * you don't care about admin related optional info
+ */
+struct event_hdl_cb_data_server_admin {
+       /* provided by:
+        *   EVENT_HDL_SUB_SERVER_ADMIN
+        */
+       struct event_hdl_cb_data_server server; /* must be at the beginning */
+       struct {
+               enum srv_admin old_admin, new_admin;
+               uint32_t requeued; /* requeued connections due to server admin change */
+               /* admin change cause */
+               enum srv_adm_st_chg_cause cause;
+       } safe;
+       /* no unsafe data */
+};
+
 /* Storage structure to load server-state lines from a flat file into
  * an ebtree, for faster processing
  */
index 87b77ebfc3198d1f739cd9d7fe052f49a413f50e..5fc1935ecd70e4e16fbffdbc9914f44ff5d1ad01 100644 (file)
@@ -30,6 +30,7 @@ static struct event_hdl_sub_type_map event_hdl_sub_type_map[] = {
        {"SERVER_UP",           EVENT_HDL_SUB_SERVER_UP},
        {"SERVER_DOWN",         EVENT_HDL_SUB_SERVER_DOWN},
        {"SERVER_STATE",        EVENT_HDL_SUB_SERVER_STATE},
+       {"SERVER_ADMIN",        EVENT_HDL_SUB_SERVER_ADMIN},
 };
 
 /* internal types (only used in this file) */
index 83faf6b3014762b0854e971a15c069f511d24ccd..272e4e9c79132595228f552fbf0fd0bf2779c338 100644 (file)
@@ -5776,6 +5776,7 @@ static void srv_update_status(struct server *s, int type, int cause)
        enum srv_state srv_prev_state = s->cur_state;
        union {
                struct event_hdl_cb_data_server_state state;
+               struct event_hdl_cb_data_server_admin admin;
                struct event_hdl_cb_data_server common;
        } cb_data;
        int requeued;
@@ -5783,8 +5784,15 @@ static void srv_update_status(struct server *s, int type, int cause)
        /* prepare common server event data */
        _srv_event_hdl_prepare(&cb_data.common, s, 0);
 
-       if (type)
+       if (type) {
+               cb_data.admin.safe.cause = cause;
+               cb_data.admin.safe.old_admin = s->cur_admin;
+               cb_data.admin.safe.new_admin = s->next_admin;
                requeued = _srv_update_status_adm(s, cause);
+               cb_data.admin.safe.requeued = requeued;
+               /* publish admin change */
+               _srv_event_hdl_publish(EVENT_HDL_SUB_SERVER_ADMIN, cb_data.admin, s);
+       }
        else
                requeued = _srv_update_status_op(s, cause);