MINOR: server/event_hdl: add SERVER_ADMIN event

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.
This commit is contained in:
Aurelien DARRAGON 2023-04-21 18:06:58 +02:00 committed by Christopher Faulet
parent c99f3adf10
commit a163d65254
4 changed files with 33 additions and 1 deletions

View 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)
/* --------------------------------------- */

View 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
*/

View 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) */

View 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);