Skip to content

Commit

Permalink
Merge pull request #3731 from clumens/glib-timer
Browse files Browse the repository at this point in the history
Improvements for glib timer functions
  • Loading branch information
kgaillot authored Nov 14, 2024
2 parents c2feeef + 577149b commit 32fca61
Show file tree
Hide file tree
Showing 38 changed files with 195 additions and 100 deletions.
3 changes: 2 additions & 1 deletion daemons/attrd/attrd_attributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ attrd_add_value_xml(xmlNode *parent, const attribute_t *a,
crm_xml_add_int(xml, PCMK__XA_ATTR_IS_REMOTE, 1);
}
crm_xml_add(xml, PCMK__XA_ATTR_VALUE, v->current);
crm_xml_add_int(xml, PCMK__XA_ATTR_DAMPENING, a->timeout_ms / 1000);
crm_xml_add_int(xml, PCMK__XA_ATTR_DAMPENING,
pcmk__timeout_ms2s(a->timeout_ms));
crm_xml_add_int(xml, PCMK__XA_ATTR_IS_PRIVATE,
pcmk_is_set(a->flags, attrd_attr_is_private));
crm_xml_add_int(xml, PCMK__XA_ATTRD_IS_FORCE_WRITE, force_write);
Expand Down
2 changes: 1 addition & 1 deletion daemons/based/based_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ initiate_exit(void)
pcmk__cluster_send_message(NULL, pcmk_ipc_based, leaving);
pcmk__xml_free(leaving);

g_timeout_add(EXIT_ESCALATION_MS, cib_force_exit, NULL);
pcmk__create_timer(EXIT_ESCALATION_MS, cib_force_exit, NULL);
}

void
Expand Down
12 changes: 6 additions & 6 deletions daemons/based/based_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@ cib_remote_listen(gpointer data)
}

// Require the client to authenticate within this time
new_client->remote->auth_timeout = g_timeout_add(REMOTE_AUTH_TIMEOUT,
remote_auth_timeout_cb,
new_client);
new_client->remote->auth_timeout = pcmk__create_timer(REMOTE_AUTH_TIMEOUT,
remote_auth_timeout_cb,
new_client);
crm_info("%s connection from %s pending authentication for client %s",
((ssock == remote_tls_fd)? "Encrypted" : "Clear-text"),
ipstr, new_client->id);
Expand Down Expand Up @@ -454,9 +454,9 @@ cib_remote_msg(gpointer data)
}

// Require the client to authenticate within this time
client->remote->auth_timeout = g_timeout_add(REMOTE_AUTH_TIMEOUT,
remote_auth_timeout_cb,
client);
client->remote->auth_timeout = pcmk__create_timer(REMOTE_AUTH_TIMEOUT,
remote_auth_timeout_cb,
client);
return 0;
}

Expand Down
6 changes: 2 additions & 4 deletions daemons/controld/controld_fencing.c
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,7 @@ static int
fence_with_delay(const char *target, const char *type, int delay)
{
uint32_t options = st_opt_none; // Group of enum stonith_call_options
int timeout_sec = (int) (controld_globals.transition_graph->stonith_timeout
/ 1000);
int timeout_sec = pcmk__timeout_ms2s(controld_globals.transition_graph->stonith_timeout);

if (crmd_join_phase_count(controld_join_confirmed) == 1) {
stonith__set_call_options(options, target, st_opt_allow_self_fencing);
Expand Down Expand Up @@ -975,8 +974,7 @@ controld_execute_fence_action(pcmk__graph_t *graph,
const char *priority_delay = NULL;
int delay_i = 0;
gboolean invalid_action = FALSE;
int stonith_timeout = (int) (controld_globals.transition_graph->stonith_timeout
/ 1000);
int stonith_timeout = pcmk__timeout_ms2s(controld_globals.transition_graph->stonith_timeout);

CRM_CHECK(id != NULL, invalid_action = TRUE);
CRM_CHECK(uuid != NULL, invalid_action = TRUE);
Expand Down
14 changes: 8 additions & 6 deletions daemons/controld/controld_remote_ra.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ remote_lrm_op_callback(lrmd_event_data_t * op)

} else if (cmd->remaining_timeout > 3000) {
crm_trace("rescheduling start, remaining timeout %d", cmd->remaining_timeout);
g_timeout_add(1000, retry_start_cmd_cb, lrm_state);
pcmk__create_timer(1000, retry_start_cmd_cb, lrm_state);
return;

} else {
Expand Down Expand Up @@ -779,8 +779,8 @@ remote_lrm_op_callback(lrmd_event_data_t * op)
/* success, keep rescheduling if interval is present. */
if (cmd->interval_ms && !pcmk_is_set(cmd->status, cmd_cancel)) {
ra_data->recurring_cmds = g_list_append(ra_data->recurring_cmds, cmd);
cmd->interval_id = g_timeout_add(cmd->interval_ms,
recurring_helper, cmd);
cmd->interval_id = pcmk__create_timer(cmd->interval_ms,
recurring_helper, cmd);
cmd = NULL; /* prevent free */
}
cmd_handled = TRUE;
Expand Down Expand Up @@ -942,7 +942,7 @@ handle_remote_ra_exec(gpointer user_data)
crm_debug("Poked Pacemaker Remote at node %s, waiting for async response",
cmd->rsc_id);
ra_data->cur_cmd = cmd;
cmd->monitor_timeout_id = g_timeout_add(cmd->timeout, monitor_timeout_cb, cmd);
cmd->monitor_timeout_id = pcmk__create_timer(cmd->timeout, monitor_timeout_cb, cmd);
return TRUE;
}
report_remote_ra_result(cmd);
Expand All @@ -956,7 +956,9 @@ handle_remote_ra_exec(gpointer user_data)
* cleared which will require all the resources running in the remote-node
* to be explicitly re-detected via probe actions. If the takeover does occur
* successfully, then we can leave the status section intact. */
cmd->takeover_timeout_id = g_timeout_add((cmd->timeout/2), connection_takeover_timeout_cb, cmd);
cmd->takeover_timeout_id = pcmk__create_timer((cmd->timeout/2),
connection_takeover_timeout_cb,
cmd);
ra_data->cur_cmd = cmd;
return TRUE;
}
Expand Down Expand Up @@ -1299,7 +1301,7 @@ controld_execute_remote_agent(const lrm_state_t *lrm_state, const char *rsc_id,
cmd->call_id = generate_callid();

if (cmd->start_delay) {
cmd->delay_id = g_timeout_add(cmd->start_delay, start_delay_helper, cmd);
cmd->delay_id = pcmk__create_timer(cmd->start_delay, start_delay_helper, cmd);
}

ra_data->cmds = g_list_append(ra_data->cmds, cmd);
Expand Down
4 changes: 2 additions & 2 deletions daemons/controld/controld_te_actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ static void te_update_job_count(pcmk__graph_action_t *action, int offset);
static void
te_start_action_timer(const pcmk__graph_t *graph, pcmk__graph_action_t *action)
{
action->timer = g_timeout_add(action->timeout + graph->network_delay,
action_timer_callback, (void *) action);
action->timer = pcmk__create_timer(action->timeout + graph->network_delay,
action_timer_callback, action);
pcmk__assert(action->timer != 0);
}

Expand Down
8 changes: 4 additions & 4 deletions daemons/controld/controld_te_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ abort_after_delay(int abort_priority, enum pcmk__graph_next abort_action,
abort_timer.priority = abort_priority;
abort_timer.action = abort_action;
abort_timer.text = abort_text;
abort_timer.id = g_timeout_add(delay_ms, abort_timer_popped, &abort_timer);
abort_timer.id = pcmk__create_timer(delay_ms, abort_timer_popped, &abort_timer);
}

static void
Expand Down Expand Up @@ -238,9 +238,9 @@ init_node_pending_timer(const pcmk__node_status_t *node, guint timeout)

g_hash_table_replace(node_pending_timers, key, node_pending_timer);

node_pending_timer->id = g_timeout_add_seconds(timeout,
node_pending_timer_popped,
key);
node_pending_timer->id = pcmk__create_timer(timeout * 1000,
node_pending_timer_popped,
key);
pcmk__assert(node_pending_timer->id != 0);
}

Expand Down
2 changes: 1 addition & 1 deletion daemons/controld/controld_timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static void
controld_start_timer(fsa_timer_t *timer)
{
if (timer->source_id == 0 && timer->period_ms > 0) {
timer->source_id = g_timeout_add(timer->period_ms, timer->callback, (void *)timer);
timer->source_id = pcmk__create_timer(timer->period_ms, timer->callback, timer);
pcmk__assert(timer->source_id != 0);
crm_debug("Started %s (inject %s if pops after %ums, source=%d)",
get_timer_desc(timer), fsa_input2string(timer->fsa_input),
Expand Down
2 changes: 1 addition & 1 deletion daemons/execd/cts-exec-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ start_test(gpointer user_data)
lrmd_conn->cmds->set_callback(lrmd_conn, read_events);

if (options.timeout) {
g_timeout_add(options.timeout, timeout_err, NULL);
pcmk__create_timer(options.timeout, timeout_err, NULL);
}

if (!options.api_call) {
Expand Down
14 changes: 8 additions & 6 deletions daemons/execd/execd_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,13 @@ stonith_recurring_op_helper(gpointer data)
static inline void
start_recurring_timer(lrmd_cmd_t *cmd)
{
if (cmd && (cmd->interval_ms > 0)) {
cmd->stonith_recurring_id = g_timeout_add(cmd->interval_ms,
stonith_recurring_op_helper,
cmd);
if (!cmd || (cmd->interval_ms <= 0)) {
return;
}

cmd->stonith_recurring_id = pcmk__create_timer(cmd->interval_ms,
stonith_recurring_op_helper,
cmd);
}

static gboolean
Expand Down Expand Up @@ -532,7 +534,7 @@ schedule_lrmd_cmd(lrmd_rsc_t * rsc, lrmd_cmd_t * cmd)
mainloop_set_trigger(rsc->work);

if (cmd->start_delay) {
cmd->delay_id = g_timeout_add(cmd->start_delay, start_delay_helper, cmd);
cmd->delay_id = pcmk__create_timer(cmd->start_delay, start_delay_helper, cmd);
}
}

Expand Down Expand Up @@ -1216,7 +1218,7 @@ static inline int
execd_stonith_monitor(stonith_t *stonith_api, lrmd_rsc_t *rsc, lrmd_cmd_t *cmd)
{
int rc = stonith_api->cmds->monitor(stonith_api, 0, cmd->rsc_id,
cmd->timeout / 1000);
pcmk__timeout_ms2s(cmd->timeout));

rc = stonith_api->cmds->register_callback(stonith_api, rc, 0, 0, cmd,
"lrmd_stonith_callback",
Expand Down
6 changes: 3 additions & 3 deletions daemons/execd/remoted_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ lrmd_remote_listen(gpointer data)
new_client->remote->tls_session = session;

// Require the client to authenticate within this time
new_client->remote->auth_timeout = g_timeout_add(LRMD_REMOTE_AUTH_TIMEOUT,
lrmd_auth_timeout_cb,
new_client);
new_client->remote->auth_timeout = pcmk__create_timer(LRMD_REMOTE_AUTH_TIMEOUT,
lrmd_auth_timeout_cb,
new_client);
crm_info("Remote client pending authentication "
QB_XS " %p id: %s", new_client, new_client->id);

Expand Down
4 changes: 2 additions & 2 deletions daemons/fenced/fenced_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ get_action_timeout(const stonith_device_t *device, const char *action,
value = g_hash_table_lookup(device->params, buffer);
if (value) {
long long timeout_ms = crm_get_msec(value);
return (int) QB_MIN(timeout_ms / 1000, INT_MAX);
return (int) QB_MIN(pcmk__timeout_ms2s(timeout_ms), INT_MAX);
}
}
return default_timeout;
Expand Down Expand Up @@ -711,7 +711,7 @@ schedule_stonith_command(async_command_t * cmd, stonith_device_t * device)
device->id, cmd->start_delay, cmd->timeout,
requested_delay, delay_base, delay_max);
cmd->delay_id =
g_timeout_add_seconds(cmd->start_delay, start_delay_helper, cmd);
pcmk__create_timer(cmd->start_delay * 1000, start_delay_helper, cmd);
}
}

Expand Down
15 changes: 8 additions & 7 deletions daemons/fenced/fenced_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ initiate_remote_stonith_op(const pcmk__client_t *client, xmlNode *request,
pcmk__xml_free(query);

query_timeout = op->base_timeout * TIMEOUT_MULTIPLY_FACTOR;
op->query_timer = g_timeout_add((1000 * query_timeout), remote_op_query_timeout, op);
op->query_timer = pcmk__create_timer((1000 * query_timeout), remote_op_query_timeout, op);

return op;
}
Expand Down Expand Up @@ -1505,7 +1505,8 @@ valid_fencing_timeout(int specified_timeout, bool action_specific,
}

timeout = (int) QB_MIN(QB_MAX(specified_timeout,
stonith_watchdog_timeout_ms / 1000), INT_MAX);
pcmk__timeout_ms2s(stonith_watchdog_timeout_ms)),
INT_MAX);

if (timeout > specified_timeout) {
if (action_specific) {
Expand Down Expand Up @@ -1659,7 +1660,7 @@ get_op_total_timeout(const remote_fencing_op_t *op,
if didn't get a reply
*/
if (!found && is_watchdog_fencing(op, device_list->data)) {
total_timeout += stonith_watchdog_timeout_ms / 1000;
total_timeout += pcmk__timeout_ms2s(stonith_watchdog_timeout_ms);
}
} /* End Loop2: iterate through devices at a specific level */
} /*End Loop1: iterate through fencing levels */
Expand Down Expand Up @@ -1834,8 +1835,8 @@ check_watchdog_fencing_and_wait(remote_fencing_op_t * op)
if (op->op_timer_one) {
g_source_remove(op->op_timer_one);
}
op->op_timer_one = g_timeout_add(timeout_ms, remote_op_watchdog_done,
op);
op->op_timer_one = pcmk__create_timer(timeout_ms, remote_op_watchdog_done,
op);
return TRUE;
} else {
crm_debug("Skipping fallback to watchdog-fencing as %s is "
Expand Down Expand Up @@ -1900,7 +1901,7 @@ request_peer_fencing(remote_fencing_op_t *op, peer_device_info_t *peer)

if (!op->op_timer_total) {
op->total_timeout = TIMEOUT_MULTIPLY_FACTOR * get_op_total_timeout(op, peer);
op->op_timer_total = g_timeout_add(1000 * op->total_timeout, remote_op_timeout, op);
op->op_timer_total = pcmk__create_timer(1000 * op->total_timeout, remote_op_timeout, op);
report_timeout_period(op, op->total_timeout);
crm_info("Total timeout set to %ds for peer's fencing targeting %s for %s "
QB_XS " id=%.8s",
Expand Down Expand Up @@ -1997,7 +1998,7 @@ request_peer_fencing(remote_fencing_op_t *op, peer_device_info_t *peer)

/* coming here we're not waiting for watchdog timeout -
thus engage timer with timout evaluated before */
op->op_timer_one = g_timeout_add((1000 * timeout_one), remote_op_timeout_one, op);
op->op_timer_one = pcmk__create_timer((1000 * timeout_one), remote_op_timeout_one, op);
}

pcmk__cluster_send_message(peer_node, pcmk_ipc_fenced, remote_op);
Expand Down
10 changes: 5 additions & 5 deletions daemons/pacemakerd/pcmkd_subdaemons.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ typedef struct pcmk_child_s {
uint32_t flags;
} pcmk_child_t;

#define PCMK_PROCESS_CHECK_INTERVAL 1
#define PCMK_PROCESS_CHECK_INTERVAL 1000 /* 1s */
#define PCMK_PROCESS_CHECK_RETRIES 5
#define SHUTDOWN_ESCALATION_PERIOD 180000 /* 3m */

Expand Down Expand Up @@ -372,8 +372,8 @@ pcmk_shutdown_worker(gpointer user_data)
child->flags &= ~child_respawn;
stop_child(child, SIGTERM);
if (phase < PCMK_CHILD_CONTROLD) {
g_timeout_add(SHUTDOWN_ESCALATION_PERIOD,
escalate_shutdown, child);
pcmk__create_timer(SHUTDOWN_ESCALATION_PERIOD,
escalate_shutdown, child);
}

} else if (now >= next_log) {
Expand Down Expand Up @@ -793,8 +793,8 @@ find_and_track_existing_processes(void)
pcmk_children[i].respawn_count = 0; /* restore pristine state */
}

g_timeout_add_seconds(PCMK_PROCESS_CHECK_INTERVAL, check_next_subdaemon,
NULL);
pcmk__create_timer(PCMK_PROCESS_CHECK_INTERVAL, check_next_subdaemon,
NULL);
return pcmk_rc_ok;
}

Expand Down
2 changes: 2 additions & 0 deletions include/crm/common/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ void pcmk__daemonize(const char *name, const char *pidfile);
void pcmk__panic(const char *reason);
pid_t pcmk__locate_sbd(void);
void pcmk__sleep_ms(unsigned int ms);
guint pcmk__create_timer(guint interval_ms, GSourceFunc fn, gpointer data);
guint pcmk__timeout_ms2s(guint timeout_ms);

extern int pcmk__score_red;
extern int pcmk__score_green;
Expand Down
2 changes: 1 addition & 1 deletion include/pcmki/pcmki_fence.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ enum pcmk__fence_history {
* \return Standard Pacemaker return code
* \note If \p reason is not NULL, the caller is responsible for freeing its
* returned value.
* \todo delay is eventually used with g_timeout_add() and should be guint
* \todo delay is eventually used with pcmk__create_timer() and should be guint
*/
int pcmk__request_fencing(stonith_t *st, const char *target, const char *action,
const char *name, unsigned int timeout,
Expand Down
6 changes: 3 additions & 3 deletions lib/cib/cib_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ cib_client_register_callback_full(cib_t *cib, int call_id, int timeout,
async_timer->cib = cib;
async_timer->call_id = call_id;
async_timer->timeout = timeout * 1000;
async_timer->ref = g_timeout_add(async_timer->timeout,
cib_async_timeout_handler,
async_timer);
async_timer->ref = pcmk__create_timer(async_timer->timeout,
cib_async_timeout_handler,
async_timer);
}

crm_trace("Adding callback %s for call %d", callback_name, call_id);
Expand Down
2 changes: 1 addition & 1 deletion lib/cluster/cpg.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ crm_cs_flush(gpointer data)
/* Proportionally more if sending failed but cap at 1s */
delay_ms = QB_MIN(1000, CS_SEND_MAX + (10 * queue_len));
}
cs_message_timer = g_timeout_add(delay_ms, crm_cs_flush_cb, data);
cs_message_timer = pcmk__create_timer(delay_ms, crm_cs_flush_cb, data);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/common/ipc_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ static int
internal_ipc_get_reply(crm_ipc_t *client, int request_id, int ms_timeout,
ssize_t *bytes)
{
time_t timeout = time(NULL) + 1 + (ms_timeout / 1000);
time_t timeout = time(NULL) + 1 + pcmk__timeout_ms2s(ms_timeout);
int rc = pcmk_rc_ok;

/* get the reply */
Expand Down Expand Up @@ -1330,7 +1330,7 @@ crm_ipc_send(crm_ipc_t *client, const xmlNode *message,

if ((ms_timeout > 0) || !pcmk_is_set(flags, crm_ipc_client_response)) {

time_t timeout = time(NULL) + 1 + (ms_timeout / 1000);
time_t timeout = time(NULL) + 1 + pcmk__timeout_ms2s(ms_timeout);

do {
/* @TODO Is this check really needed? Won't qb_ipcc_sendv() return
Expand Down
2 changes: 1 addition & 1 deletion lib/common/ipc_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ delay_next_flush(pcmk__client_t *c, unsigned int queue_len)
/* Delay a maximum of 1.5 seconds */
guint delay = (queue_len < 5)? (1000 + 100 * queue_len) : 1500;

c->event_timer = g_timeout_add(delay, crm_ipcs_flush_events_cb, c);
c->event_timer = pcmk__create_timer(delay, crm_ipcs_flush_events_cb, c);
}

/*!
Expand Down
Loading

0 comments on commit 32fca61

Please sign in to comment.