mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-04-27 05:18:00 +00:00
MINOR: server/event_hdl: prepare for server event data wrapper
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.
This commit is contained in:
parent
f71e0645c1
commit
23f352f7d0
45
src/server.c
45
src/server.c
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user