Skip to content

Commit 949368d

Browse files
author
Ken Gaillot
authored
Merge pull request #2001 from clumens/no-stonith-history
Add an indication to XML output if we failed to get stonith history
2 parents 54af6db + a279354 commit 949368d

10 files changed

Lines changed: 691 additions & 235 deletions

File tree

include/crm/common/output.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extern "C" {
2727
# include <glib.h>
2828
# include <crm/common/results.h>
2929

30-
# define PCMK__API_VERSION "2.0"
30+
# define PCMK__API_VERSION "2.2"
3131

3232
typedef struct pcmk__output_s pcmk__output_t;
3333

include/crm/fencing/internal.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,19 @@ int stonith__rhcs_validate(stonith_t *st, int call_options, const char *target,
154154
const char *agent, GHashTable *params,
155155
int timeout, char **output, char **error_output);
156156

157+
int stonith__failed_history(pcmk__output_t *out, va_list args);
158+
int stonith__history(pcmk__output_t *out, va_list args);
159+
int stonith__full_history(pcmk__output_t *out, va_list args);
160+
int stonith__full_history_xml(pcmk__output_t *out, va_list args);
161+
int stonith__last_fenced_html(pcmk__output_t *out, va_list args);
162+
int stonith__last_fenced_text(pcmk__output_t *out, va_list args);
163+
int stonith__last_fenced_xml(pcmk__output_t *out, va_list args);
164+
int stonith__pending_actions(pcmk__output_t *out, va_list args);
165+
int stonith__event_html(pcmk__output_t *out, va_list args);
166+
int stonith__event_text(pcmk__output_t *out, va_list args);
167+
int stonith__event_xml(pcmk__output_t *out, va_list args);
168+
int stonith__validate_agent_html(pcmk__output_t *out, va_list args);
169+
int stonith__validate_agent_text(pcmk__output_t *out, va_list args);
170+
int stonith__validate_agent_xml(pcmk__output_t *out, va_list args);
171+
157172
#endif

lib/fencing/st_output.c

Lines changed: 206 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,134 @@ time_t_string(time_t when) {
2727
return buf;
2828
}
2929

30-
static int
31-
last_fenced_html(pcmk__output_t *out, va_list args) {
30+
int
31+
stonith__failed_history(pcmk__output_t *out, va_list args) {
32+
stonith_history_t *history = va_arg(args, stonith_history_t *);
33+
gboolean full_history = va_arg(args, gboolean);
34+
gboolean print_spacer = va_arg(args, gboolean);
35+
36+
int rc = pcmk_rc_no_output;
37+
38+
for (stonith_history_t *hp = history; hp; hp = hp->next) {
39+
if (hp->state != st_failed) {
40+
continue;
41+
}
42+
43+
if (rc == pcmk_rc_no_output) {
44+
if (print_spacer) {
45+
out->info(out, "%s", "");
46+
}
47+
48+
rc = pcmk_rc_ok;
49+
out->begin_list(out, NULL, NULL, "Failed Fencing Actions");
50+
}
51+
52+
out->message(out, "stonith-event", hp, full_history, stonith__later_succeeded(hp, history));
53+
out->increment_list(out);
54+
}
55+
56+
if (rc == pcmk_rc_ok) {
57+
out->end_list(out);
58+
}
59+
60+
return rc;
61+
}
62+
63+
int
64+
stonith__history(pcmk__output_t *out, va_list args) {
65+
stonith_history_t *history = va_arg(args, stonith_history_t *);
66+
gboolean full_history = va_arg(args, gboolean);
67+
gboolean print_spacer = va_arg(args, gboolean);
68+
69+
int rc = pcmk_rc_no_output;
70+
71+
for (stonith_history_t *hp = history; hp; hp = hp->next) {
72+
if (hp->state != st_failed) {
73+
/* Print the header the first time we have an event to print out to
74+
* prevent printing headers with empty sections underneath.
75+
*/
76+
if (rc == pcmk_rc_no_output) {
77+
/* Add a blank line between this section and the one before it. */
78+
if (print_spacer) {
79+
out->info(out, "%s", "");
80+
}
81+
82+
rc = pcmk_rc_ok;
83+
out->begin_list(out, NULL, NULL, "Fencing History");
84+
}
85+
86+
out->message(out, "stonith-event", hp, full_history, stonith__later_succeeded(hp, history));
87+
out->increment_list(out);
88+
}
89+
}
90+
91+
if (rc == pcmk_rc_ok) {
92+
out->end_list(out);
93+
}
94+
95+
return rc;
96+
}
97+
98+
int
99+
stonith__full_history(pcmk__output_t *out, va_list args) {
100+
crm_exit_t history_rc G_GNUC_UNUSED = va_arg(args, crm_exit_t);
101+
stonith_history_t *history = va_arg(args, stonith_history_t *);
102+
gboolean full_history = va_arg(args, gboolean);
103+
gboolean print_spacer = va_arg(args, gboolean);
104+
105+
int rc = pcmk_rc_no_output;
106+
107+
for (stonith_history_t *hp = history; hp; hp = hp->next) {
108+
if (rc == pcmk_rc_no_output) {
109+
/* Add a blank line between this section and the one before it. */
110+
if (print_spacer) {
111+
out->info(out, "%s", "");
112+
}
113+
114+
rc = pcmk_rc_ok;
115+
out->begin_list(out, NULL, NULL, "Fencing History");
116+
}
117+
118+
out->message(out, "stonith-event", hp, full_history, stonith__later_succeeded(hp, history));
119+
out->increment_list(out);
120+
}
121+
122+
if (rc == pcmk_rc_ok) {
123+
out->end_list(out);
124+
}
125+
126+
return rc;
127+
}
128+
129+
int
130+
stonith__full_history_xml(pcmk__output_t *out, va_list args) {
131+
crm_exit_t history_rc = va_arg(args, crm_exit_t);
132+
stonith_history_t *history = va_arg(args, stonith_history_t *);
133+
gboolean full_history = va_arg(args, gboolean);
134+
gboolean print_spacer G_GNUC_UNUSED = va_arg(args, gboolean);
135+
136+
if (history_rc == 0) {
137+
out->begin_list(out, NULL, NULL, "Fencing History");
138+
139+
for (stonith_history_t *hp = history; hp; hp = hp->next) {
140+
out->message(out, "stonith-event", hp, full_history, stonith__later_succeeded(hp, history));
141+
out->increment_list(out);
142+
}
143+
144+
out->end_list(out);
145+
} else {
146+
xmlNodePtr node = pcmk__output_create_xml_node(out, "fence_history");
147+
char *rc_s = crm_itoa(history_rc);
148+
149+
xmlSetProp(node, (pcmkXmlStr) "status", (pcmkXmlStr) rc_s);
150+
free(rc_s);
151+
}
152+
153+
return pcmk_rc_ok;
154+
}
155+
156+
int
157+
stonith__last_fenced_html(pcmk__output_t *out, va_list args) {
32158
const char *target = va_arg(args, const char *);
33159
time_t when = va_arg(args, time_t);
34160

@@ -42,8 +168,8 @@ last_fenced_html(pcmk__output_t *out, va_list args) {
42168
}
43169
}
44170

45-
static int
46-
last_fenced_text(pcmk__output_t *out, va_list args) {
171+
int
172+
stonith__last_fenced_text(pcmk__output_t *out, va_list args) {
47173
const char *target = va_arg(args, const char *);
48174
time_t when = va_arg(args, time_t);
49175

@@ -56,8 +182,8 @@ last_fenced_text(pcmk__output_t *out, va_list args) {
56182
return pcmk_rc_ok;
57183
}
58184

59-
static int
60-
last_fenced_xml(pcmk__output_t *out, va_list args) {
185+
int
186+
stonith__last_fenced_xml(pcmk__output_t *out, va_list args) {
61187
const char *target = va_arg(args, const char *);
62188
time_t when = va_arg(args, time_t);
63189

@@ -75,8 +201,42 @@ last_fenced_xml(pcmk__output_t *out, va_list args) {
75201
}
76202
}
77203

78-
static int
79-
stonith_event_html(pcmk__output_t *out, va_list args) {
204+
int
205+
stonith__pending_actions(pcmk__output_t *out, va_list args) {
206+
stonith_history_t *history = va_arg(args, stonith_history_t *);
207+
gboolean full_history = va_arg(args, gboolean);
208+
gboolean print_spacer = va_arg(args, gboolean);
209+
210+
int rc = pcmk_rc_no_output;
211+
212+
for (stonith_history_t *hp = history; hp; hp = hp->next) {
213+
/* Skip the rest of the history after we see a failed/done action */
214+
if ((hp->state == st_failed) || (hp->state == st_done)) {
215+
break;
216+
}
217+
218+
if (rc == pcmk_rc_no_output) {
219+
if (print_spacer) {
220+
out->info(out, "%s", "");
221+
}
222+
223+
rc = pcmk_rc_ok;
224+
out->begin_list(out, NULL, NULL, "Pending Fencing Actions");
225+
}
226+
227+
out->message(out, "stonith-event", hp, full_history, stonith__later_succeeded(hp, history));
228+
out->increment_list(out);
229+
}
230+
231+
if (rc == pcmk_rc_ok) {
232+
out->end_list(out);
233+
}
234+
235+
return rc;
236+
}
237+
238+
int
239+
stonith__event_html(pcmk__output_t *out, va_list args) {
80240
stonith_history_t *event = va_arg(args, stonith_history_t *);
81241
gboolean full_history = va_arg(args, gboolean);
82242
gboolean later_succeeded = va_arg(args, gboolean);
@@ -122,8 +282,8 @@ stonith_event_html(pcmk__output_t *out, va_list args) {
122282
return pcmk_rc_ok;
123283
}
124284

125-
static int
126-
stonith_event_text(pcmk__output_t *out, va_list args) {
285+
int
286+
stonith__event_text(pcmk__output_t *out, va_list args) {
127287
stonith_history_t *event = va_arg(args, stonith_history_t *);
128288
gboolean full_history = va_arg(args, gboolean);
129289
gboolean later_succeeded = va_arg(args, gboolean);
@@ -159,8 +319,8 @@ stonith_event_text(pcmk__output_t *out, va_list args) {
159319
return pcmk_rc_ok;
160320
}
161321

162-
static int
163-
stonith_event_xml(pcmk__output_t *out, va_list args) {
322+
int
323+
stonith__event_xml(pcmk__output_t *out, va_list args) {
164324
xmlNodePtr node = pcmk__output_create_xml_node(out, "fence_event");
165325
stonith_history_t *event = va_arg(args, stonith_history_t *);
166326
gboolean full_history G_GNUC_UNUSED = va_arg(args, gboolean);
@@ -204,8 +364,8 @@ stonith_event_xml(pcmk__output_t *out, va_list args) {
204364
return pcmk_rc_ok;
205365
}
206366

207-
static int
208-
validate_agent_html(pcmk__output_t *out, va_list args) {
367+
int
368+
stonith__validate_agent_html(pcmk__output_t *out, va_list args) {
209369
const char *agent = va_arg(args, const char *);
210370
const char *device = va_arg(args, const char *);
211371
char *output = va_arg(args, char *);
@@ -228,8 +388,8 @@ validate_agent_html(pcmk__output_t *out, va_list args) {
228388
return rc;
229389
}
230390

231-
static int
232-
validate_agent_text(pcmk__output_t *out, va_list args) {
391+
int
392+
stonith__validate_agent_text(pcmk__output_t *out, va_list args) {
233393
const char *agent = va_arg(args, const char *);
234394
const char *device = va_arg(args, const char *);
235395
char *output = va_arg(args, char *);
@@ -255,8 +415,8 @@ validate_agent_text(pcmk__output_t *out, va_list args) {
255415
return rc;
256416
}
257417

258-
static int
259-
validate_agent_xml(pcmk__output_t *out, va_list args) {
418+
int
419+
stonith__validate_agent_xml(pcmk__output_t *out, va_list args) {
260420
xmlNodePtr node = pcmk__output_create_xml_node(out, "validate");
261421

262422
const char *agent = va_arg(args, const char *);
@@ -279,15 +439,34 @@ validate_agent_xml(pcmk__output_t *out, va_list args) {
279439
}
280440

281441
static pcmk__message_entry_t fmt_functions[] = {
282-
{ "last-fenced", "html", last_fenced_html },
283-
{ "last-fenced", "text", last_fenced_text },
284-
{ "last-fenced", "xml", last_fenced_xml },
285-
{ "stonith-event", "html", stonith_event_html },
286-
{ "stonith-event", "text", stonith_event_text },
287-
{ "stonith-event", "xml", stonith_event_xml },
288-
{ "validate", "html", validate_agent_html },
289-
{ "validate", "text", validate_agent_text },
290-
{ "validate", "xml", validate_agent_xml },
442+
{ "failed-fencing-history", "html", stonith__failed_history },
443+
{ "failed-fencing-history", "log", stonith__failed_history },
444+
{ "failed-fencing-history", "text", stonith__failed_history },
445+
{ "failed-fencing-history", "xml", stonith__failed_history },
446+
{ "fencing-history", "html", stonith__history },
447+
{ "fencing-history", "log", stonith__history },
448+
{ "fencing-history", "text", stonith__history },
449+
{ "fencing-history", "xml", stonith__history },
450+
{ "full-fencing-history", "html", stonith__full_history },
451+
{ "full-fencing-history", "log", stonith__full_history },
452+
{ "full-fencing-history", "text", stonith__full_history },
453+
{ "full-fencing-history", "xml", stonith__full_history_xml },
454+
{ "last-fenced", "html", stonith__last_fenced_html },
455+
{ "last-fenced", "log", stonith__last_fenced_text },
456+
{ "last-fenced", "text", stonith__last_fenced_text },
457+
{ "last-fenced", "xml", stonith__last_fenced_xml },
458+
{ "pending-fencing-actions", "html", stonith__pending_actions },
459+
{ "pending-fencing-actions", "log", stonith__pending_actions },
460+
{ "pending-fencing-actions", "text", stonith__pending_actions },
461+
{ "pending-fencing-actions", "xml", stonith__pending_actions },
462+
{ "stonith-event", "html", stonith__event_html },
463+
{ "stonith-event", "log", stonith__event_text },
464+
{ "stonith-event", "text", stonith__event_text },
465+
{ "stonith-event", "xml", stonith__event_xml },
466+
{ "validate", "html", stonith__validate_agent_html },
467+
{ "validate", "log", stonith__validate_agent_text },
468+
{ "validate", "text", stonith__validate_agent_text },
469+
{ "validate", "xml", stonith__validate_agent_xml },
291470

292471
{ NULL, NULL, NULL }
293472
};

lib/pengine/pe_output.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,7 @@ static pcmk__message_entry_t fmt_functions[] = {
14901490
{ "resource-history", "text", pe__resource_history_text },
14911491
{ "resource-history", "xml", pe__resource_history_xml },
14921492
{ "ticket", "html", pe__ticket_html },
1493+
{ "ticket", "log", pe__ticket_text },
14931494
{ "ticket", "text", pe__ticket_text },
14941495
{ "ticket", "xml", pe__ticket_xml },
14951496

tools/crm_mon.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,7 @@ mon_refresh_display(gpointer user_data)
18741874
{
18751875
xmlNode *cib_copy = copy_xml(current_cib);
18761876
stonith_history_t *stonith_history = NULL;
1877+
int history_rc = 0;
18771878

18781879
last_refresh = time(NULL);
18791880

@@ -1893,7 +1894,9 @@ mon_refresh_display(gpointer user_data)
18931894
*/
18941895
while (is_set(options.mon_ops, mon_op_fence_history)) {
18951896
if (st != NULL) {
1896-
if (st->cmds->history(st, st_opt_sync_call, NULL, &stonith_history, 120)) {
1897+
history_rc = st->cmds->history(st, st_opt_sync_call, NULL, &stonith_history, 120);
1898+
1899+
if (history_rc != 0) {
18971900
out->err(out, "Critical: Unable to get stonith-history");
18981901
mon_cib_connection_destroy(NULL);
18991902
} else {
@@ -1945,8 +1948,9 @@ mon_refresh_display(gpointer user_data)
19451948

19461949
case mon_output_legacy_xml:
19471950
case mon_output_xml:
1948-
print_xml_status(out, mon_data_set, stonith_history, options.mon_ops,
1949-
show, options.neg_location_prefix);
1951+
print_xml_status(out, mon_data_set, crm_errno2exit(history_rc),
1952+
stonith_history, options.mon_ops, show,
1953+
options.neg_location_prefix);
19501954
break;
19511955

19521956
case mon_output_monitor:

tools/crm_mon.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ void print_status(pcmk__output_t *out, pe_working_set_t *data_set,
9898
stonith_history_t *stonith_history, unsigned int mon_ops,
9999
unsigned int show, char *prefix);
100100
void print_xml_status(pcmk__output_t *out, pe_working_set_t *data_set,
101-
stonith_history_t *stonith_history, unsigned int mon_ops,
102-
unsigned int show, char *prefix);
101+
crm_exit_t history_rc, stonith_history_t *stonith_history,
102+
unsigned int mon_ops, unsigned int show, char *prefix);
103103
int print_html_status(pcmk__output_t *out, pe_working_set_t *data_set,
104104
stonith_history_t *stonith_history, unsigned int mon_ops,
105105
unsigned int show, char *prefix);

0 commit comments

Comments
 (0)