Skip to content

Commit 1c0ff39

Browse files
committed
Feature: stonith_admin: add --delay option to support enforced fencing delay
It can be specified with --fence, --reboot or --unfence commands. The default value -1 disables enforced fencing delay.
1 parent 1e6cfb8 commit 1c0ff39

3 files changed

Lines changed: 28 additions & 14 deletions

File tree

include/pcmki/pcmki_fence.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
* \param[in] tolerance If a successful action for \p target happened within
2727
* this many ms, return 0 without performing the action
2828
* again.
29+
* \param[in] delay Enforce a fencing delay. Value -1 means disabled.
2930
*
3031
* \return Standard Pacemaker return code
3132
*/
3233
int pcmk__fence_action(stonith_t *st, const char *target, const char *action,
33-
const char *name, unsigned int timeout, unsigned int tolerance);
34+
const char *name, unsigned int timeout, unsigned int tolerance,
35+
int delay);
3436

3537
/*!
3638
* \brief List the fencing operations that have occurred for a specific node.

lib/pacemaker/pcmk_fence.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ static struct {
3030
char *name;
3131
unsigned int timeout;
3232
unsigned int tolerance;
33+
int delay;
3334
int rc;
3435
} async_fence_data;
3536

@@ -109,12 +110,13 @@ async_fence_helper(gpointer user_data)
109110

110111
st->cmds->register_notification(st, T_STONITH_NOTIFY_FENCE, notify_callback);
111112

112-
call_id = st->cmds->fence(st,
113-
st_opt_allow_suicide,
114-
async_fence_data.target,
115-
async_fence_data.action,
116-
async_fence_data.timeout/1000,
117-
async_fence_data.tolerance/1000);
113+
call_id = st->cmds->fence_with_delay(st,
114+
st_opt_allow_suicide,
115+
async_fence_data.target,
116+
async_fence_data.action,
117+
async_fence_data.timeout/1000,
118+
async_fence_data.tolerance/1000,
119+
async_fence_data.delay);
118120

119121
if (call_id < 0) {
120122
g_main_loop_quit(mainloop);
@@ -131,7 +133,8 @@ async_fence_helper(gpointer user_data)
131133

132134
int
133135
pcmk__fence_action(stonith_t *st, const char *target, const char *action,
134-
const char *name, unsigned int timeout, unsigned int tolerance)
136+
const char *name, unsigned int timeout, unsigned int tolerance,
137+
int delay)
135138
{
136139
crm_trigger_t *trig;
137140

@@ -141,6 +144,7 @@ pcmk__fence_action(stonith_t *st, const char *target, const char *action,
141144
async_fence_data.action = action;
142145
async_fence_data.timeout = timeout;
143146
async_fence_data.tolerance = tolerance;
147+
async_fence_data.delay = delay;
144148
async_fence_data.rc = pcmk_err_generic;
145149

146150
trig = mainloop_add_trigger(G_PRIORITY_HIGH, async_fence_helper, NULL);
@@ -157,8 +161,10 @@ pcmk__fence_action(stonith_t *st, const char *target, const char *action,
157161
#ifdef BUILD_PUBLIC_LIBPACEMAKER
158162
int
159163
pcmk_fence_action(stonith_t *st, const char *target, const char *action,
160-
const char *name, unsigned int timeout, unsigned int tolerance) {
161-
return pcmk__fence_action(st, target, action, name, timeout, tolerance);
164+
const char *name, unsigned int timeout, unsigned int tolerance,
165+
int delay)
166+
{
167+
return pcmk__fence_action(st, target, action, name, timeout, tolerancei, delay);
162168
}
163169
#endif
164170

tools/stonith_admin.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct {
5454
int fence_level;
5555
int timeout ;
5656
int tolerance;
57+
int delay;
5758
char *agent;
5859
char *confirm_host;
5960
char *fence_host;
@@ -69,7 +70,8 @@ struct {
6970
char *unregister_dev;
7071
char *unregister_level;
7172
} options = {
72-
.timeout = 120
73+
.timeout = 120,
74+
.delay = -1
7375
};
7476

7577
gboolean add_env_params(const gchar *option_name, const gchar *optarg, gpointer data, GError **error);
@@ -205,6 +207,10 @@ static GOptionEntry addl_entries[] = {
205207
"Operation timeout in seconds (default 120;\n"
206208
INDENT "used with most commands).",
207209
"SECONDS" },
210+
{ "delay", 'y', 0, G_OPTION_ARG_INT, &options.delay,
211+
"Enforced fencing delay in seconds (default -1 (disabled);\n"
212+
INDENT "with --fence, --reboot, --unfence).",
213+
"SECONDS" },
208214
{ "as-node-id", 'n', 0, G_OPTION_ARG_NONE, &options.as_nodeid,
209215
"(Advanced) The supplied node is the corosync node ID\n"
210216
INDENT "(with --last).",
@@ -560,17 +566,17 @@ main(int argc, char **argv)
560566

561567
case 'B':
562568
rc = pcmk__fence_action(st, target, "reboot", name, options.timeout*1000,
563-
options.tolerance*1000);
569+
options.tolerance*1000, options.delay);
564570
break;
565571

566572
case 'F':
567573
rc = pcmk__fence_action(st, target, "off", name, options.timeout*1000,
568-
options.tolerance*1000);
574+
options.tolerance*1000, options.delay);
569575
break;
570576

571577
case 'U':
572578
rc = pcmk__fence_action(st, target, "on", name, options.timeout*1000,
573-
options.tolerance*1000);
579+
options.tolerance*1000, options.delay);
574580
break;
575581

576582
case 'h':

0 commit comments

Comments
 (0)