]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: server/event_hdl: prepare for server event data wrapper
authorAurelien DARRAGON <adarragon@haproxy.com>
Fri, 24 Mar 2023 16:02:53 +0000 (17:02 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 21 Apr 2023 12:36:45 +0000 (14:36 +0200)
Adding the possibility to publish an event using a struct wrapper
around existing SERVER events to provide additional contextual info.

Using the specific struct wrapper is not required: it is supported
to cast event data as a regular server event data struct so
that we don't break the existing API.

However, casting event data with a more explicit data type allows
to fetch event-only relevant hints.

src/server.c

index c24f527706c5a6097d06ae342fa81a78c44a274a..8172f8f5306f943590314b4906948fd0ee81848d 100644 (file)
@@ -166,7 +166,30 @@ int srv_getinter(const struct check *check)
        return (check->fastinter)?(check->fastinter):(check->inter);
 }
 
-/*
+/* fill common server event data members struct
+ * must be called with server lock or under thread isolate
+ */
+static inline void _srv_event_hdl_prepare(struct event_hdl_cb_data_server *cb_data,
+                                          struct server *srv, uint8_t thread_isolate)
+{
+       /* safe data assignments */
+       cb_data->safe.puid = srv->puid;
+       cb_data->safe.rid = srv->rid;
+       cb_data->safe.flags = srv->flags;
+       snprintf(cb_data->safe.name, sizeof(cb_data->safe.name), "%s", srv->id);
+       cb_data->safe.proxy_name[0] = '\0';
+       cb_data->safe.proxy_uuid = -1; /* default value */
+       if (srv->proxy) {
+               cb_data->safe.proxy_uuid = srv->proxy->uuid;
+               snprintf(cb_data->safe.proxy_name, sizeof(cb_data->safe.proxy_name), "%s", srv->proxy->id);
+       }
+       /* unsafe data assignments */
+       cb_data->unsafe.ptr = srv;
+       cb_data->unsafe.thread_isolate = thread_isolate;
+       cb_data->unsafe.srv_lock = !thread_isolate;
+}
+
+/* general server event publishing:
  * Use this to publish EVENT_HDL_SUB_SERVER family type event
  * from srv facility
  * Event will be published in both global subscription list and
@@ -174,25 +197,13 @@ int srv_getinter(const struct check *check)
  * server ptr must be valid
  * must be called with srv lock or under thread_isolate
  */
-static inline void srv_event_hdl_publish(struct event_hdl_sub_type event, struct server *srv, uint8_t thread_isolate)
+static void srv_event_hdl_publish(struct event_hdl_sub_type event,
+                                  struct server *srv, uint8_t thread_isolate)
 {
        struct event_hdl_cb_data_server cb_data;
 
-       /* safe data assignments */
-       cb_data.safe.puid = srv->puid;
-       cb_data.safe.rid = srv->rid;
-       cb_data.safe.flags = srv->flags;
-       snprintf(cb_data.safe.name, sizeof(cb_data.safe.name), "%s", srv->id);
-       cb_data.safe.proxy_name[0] = '\0';
-       cb_data.safe.proxy_uuid = -1; /* default value */
-       if (srv->proxy) {
-               cb_data.safe.proxy_uuid = srv->proxy->uuid;
-               snprintf(cb_data.safe.proxy_name, sizeof(cb_data.safe.proxy_name), "%s", srv->proxy->id);
-       }
-       /* unsafe data assignments */
-       cb_data.unsafe.ptr = srv;
-       cb_data.unsafe.thread_isolate = thread_isolate;
-       cb_data.unsafe.srv_lock = !thread_isolate;
+       /* prepare event data */
+       _srv_event_hdl_prepare(&cb_data, srv, thread_isolate);
        /* publish in server dedicated sub list */
        event_hdl_publish(&srv->e_subs, event, EVENT_HDL_CB_DATA(&cb_data));
        /* publish in global subscription list */