Skip to content

Commit

Permalink
Merge pull request #2868 from nrwahl2/nrwahl2-T15
Browse files Browse the repository at this point in the history
Fix: tools: crm_mon --daemonize should update when disconnected
  • Loading branch information
kgaillot authored Nov 8, 2022
2 parents c10931c + 3cd3984 commit d1110dd
Show file tree
Hide file tree
Showing 11 changed files with 511 additions and 252 deletions.
2 changes: 1 addition & 1 deletion include/crm/common/output_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern "C" {
*/


# define PCMK__API_VERSION "2.25"
# define PCMK__API_VERSION "2.26"

#if defined(PCMK__WITH_ATTRIBUTE_OUTPUT_ARGS)
# define PCMK__OUTPUT_ARGS(ARGS...) __attribute__((output_args(ARGS)))
Expand Down
1 change: 1 addition & 0 deletions include/pcmki/pcmki_status.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ int pcmk__output_simple_status(pcmk__output_t *out, pe_working_set_t *data_set);

int pcmk__output_cluster_status(pcmk__output_t *out, stonith_t *stonith,
cib_t *cib, xmlNode *current_cib,
enum pcmk_pacemakerd_state pcmkd_state,
enum pcmk__fence_history fence_history,
uint32_t show, uint32_t show_opts,
const char *only_node, const char *only_rsc,
Expand Down
2 changes: 1 addition & 1 deletion lib/cib/cib_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ cib__signon_query(pcmk__output_t *out, cib_t **cib, xmlNode **cib_object)
cib__clean_up_connection(&cib_conn);
}

if (*cib_object == NULL) {
if ((rc == pcmk_rc_ok) && (*cib_object == NULL)) {
return pcmk_rc_no_input;
}
return rc;
Expand Down
53 changes: 32 additions & 21 deletions lib/pacemaker/pcmk_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,8 @@ health_xml(pcmk__output_t *out, va_list args)
return pcmk_rc_ok;
}

PCMK__OUTPUT_ARGS("pacemakerd-health", "const char *", "int", "const char *",
"long long")
PCMK__OUTPUT_ARGS("pacemakerd-health", "const char *",
"enum pcmk_pacemakerd_state", "const char *", "long long")
static int
pacemakerd_health(pcmk__output_t *out, va_list args)
{
Expand Down Expand Up @@ -688,8 +688,8 @@ pacemakerd_health(pcmk__output_t *out, va_list args)
return rc;
}

PCMK__OUTPUT_ARGS("pacemakerd-health", "const char *", "int", "const char *",
"long long")
PCMK__OUTPUT_ARGS("pacemakerd-health", "const char *",
"enum pcmk_pacemakerd_state", "const char *", "long long")
static int
pacemakerd_health_html(pcmk__output_t *out, va_list args)
{
Expand Down Expand Up @@ -731,8 +731,8 @@ pacemakerd_health_html(pcmk__output_t *out, va_list args)
return pcmk_rc_ok;
}

PCMK__OUTPUT_ARGS("pacemakerd-health", "const char *", "int", "const char *",
"long long")
PCMK__OUTPUT_ARGS("pacemakerd-health", "const char *",
"enum pcmk_pacemakerd_state", "const char *", "long long")
static int
pacemakerd_health_text(pcmk__output_t *out, va_list args)
{
Expand All @@ -753,8 +753,8 @@ pacemakerd_health_text(pcmk__output_t *out, va_list args)
}
}

PCMK__OUTPUT_ARGS("pacemakerd-health", "const char *", "int", "const char *",
"long long")
PCMK__OUTPUT_ARGS("pacemakerd-health", "const char *",
"enum pcmk_pacemakerd_state", "const char *", "long long")
static int
pacemakerd_health_xml(pcmk__output_t *out, va_list args)
{
Expand All @@ -775,7 +775,7 @@ pacemakerd_health_xml(pcmk__output_t *out, va_list args)
}

if (state_s == NULL) {
state_s = pcmk__pcmkd_state_enum2friendly(state);
state_s = pcmk_pacemakerd_api_daemon_state_enum2text(state);
}

if (last_updated != 0) {
Expand Down Expand Up @@ -1655,13 +1655,16 @@ inject_rsc_action_xml(pcmk__output_t *out, va_list args)
retcode = pcmk_rc_ok; \
}

PCMK__OUTPUT_ARGS("cluster-status", "pe_working_set_t *", "crm_exit_t", "stonith_history_t *",
"enum pcmk__fence_history", "uint32_t", "uint32_t", "const char *", "GList *",
"GList *")
PCMK__OUTPUT_ARGS("cluster-status", "pe_working_set_t *",
"enum pcmk_pacemakerd_state", "crm_exit_t",
"stonith_history_t *", "enum pcmk__fence_history", "uint32_t",
"uint32_t", "const char *", "GList *", "GList *")
int
pcmk__cluster_status_text(pcmk__output_t *out, va_list args)
{
pe_working_set_t *data_set = va_arg(args, pe_working_set_t *);
enum pcmk_pacemakerd_state pcmkd_state =
(enum pcmk_pacemakerd_state) va_arg(args, int);
crm_exit_t history_rc = va_arg(args, crm_exit_t);
stonith_history_t *stonith_history = va_arg(args, stonith_history_t *);
enum pcmk__fence_history fence_history = va_arg(args, int);
Expand All @@ -1674,7 +1677,7 @@ pcmk__cluster_status_text(pcmk__output_t *out, va_list args)
int rc = pcmk_rc_no_output;
bool already_printed_failure = false;

CHECK_RC(rc, out->message(out, "cluster-summary", data_set,
CHECK_RC(rc, out->message(out, "cluster-summary", data_set, pcmkd_state,
section_opts, show_opts));

if (pcmk_is_set(section_opts, pcmk_section_nodes) && unames) {
Expand Down Expand Up @@ -1778,13 +1781,16 @@ pcmk__cluster_status_text(pcmk__output_t *out, va_list args)
return rc;
}

PCMK__OUTPUT_ARGS("cluster-status", "pe_working_set_t *", "crm_exit_t", "stonith_history_t *",
"enum pcmk__fence_history", "uint32_t", "uint32_t", "const char *", "GList *",
"GList *")
PCMK__OUTPUT_ARGS("cluster-status", "pe_working_set_t *",
"enum pcmk_pacemakerd_state", "crm_exit_t",
"stonith_history_t *", "enum pcmk__fence_history", "uint32_t",
"uint32_t", "const char *", "GList *", "GList *")
static int
cluster_status_xml(pcmk__output_t *out, va_list args)
{
pe_working_set_t *data_set = va_arg(args, pe_working_set_t *);
enum pcmk_pacemakerd_state pcmkd_state =
(enum pcmk_pacemakerd_state) va_arg(args, int);
crm_exit_t history_rc = va_arg(args, crm_exit_t);
stonith_history_t *stonith_history = va_arg(args, stonith_history_t *);
enum pcmk__fence_history fence_history = va_arg(args, int);
Expand All @@ -1794,7 +1800,8 @@ cluster_status_xml(pcmk__output_t *out, va_list args)
GList *unames = va_arg(args, GList *);
GList *resources = va_arg(args, GList *);

out->message(out, "cluster-summary", data_set, section_opts, show_opts);
out->message(out, "cluster-summary", data_set, pcmkd_state, section_opts,
show_opts);

/*** NODES ***/
if (pcmk_is_set(section_opts, pcmk_section_nodes)) {
Expand Down Expand Up @@ -1854,13 +1861,16 @@ cluster_status_xml(pcmk__output_t *out, va_list args)
return pcmk_rc_ok;
}

PCMK__OUTPUT_ARGS("cluster-status", "pe_working_set_t *", "crm_exit_t", "stonith_history_t *",
"enum pcmk__fence_history", "uint32_t", "uint32_t", "const char *", "GList *",
"GList *")
PCMK__OUTPUT_ARGS("cluster-status", "pe_working_set_t *",
"enum pcmk_pacemakerd_state", "crm_exit_t",
"stonith_history_t *", "enum pcmk__fence_history", "uint32_t",
"uint32_t", "const char *", "GList *", "GList *")
static int
cluster_status_html(pcmk__output_t *out, va_list args)
{
pe_working_set_t *data_set = va_arg(args, pe_working_set_t *);
enum pcmk_pacemakerd_state pcmkd_state =
(enum pcmk_pacemakerd_state) va_arg(args, int);
crm_exit_t history_rc = va_arg(args, crm_exit_t);
stonith_history_t *stonith_history = va_arg(args, stonith_history_t *);
enum pcmk__fence_history fence_history = va_arg(args, int);
Expand All @@ -1871,7 +1881,8 @@ cluster_status_html(pcmk__output_t *out, va_list args)
GList *resources = va_arg(args, GList *);
bool already_printed_failure = false;

out->message(out, "cluster-summary", data_set, section_opts, show_opts);
out->message(out, "cluster-summary", data_set, pcmkd_state, section_opts,
show_opts);

/*** NODE LIST ***/
if (pcmk_is_set(section_opts, pcmk_section_nodes) && unames) {
Expand Down
5 changes: 3 additions & 2 deletions lib/pacemaker/pcmk_simulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ print_cluster_status(pe_working_set_t *data_set, uint32_t show_opts,

PCMK__OUTPUT_SPACER_IF(out, print_spacer);
out->begin_list(out, NULL, NULL, "%s", title);
out->message(out, "cluster-status", data_set, stonith_rc, NULL, false,
section_opts, show_opts, NULL, all, all);
out->message(out, "cluster-status",
data_set, pcmk_pacemakerd_state_invalid, stonith_rc, NULL,
false, section_opts, show_opts, NULL, all, all);
out->end_list(out);

g_list_free(all);
Expand Down
31 changes: 19 additions & 12 deletions lib/pacemaker/pcmk_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fencing_connect(void)
* \param[in,out] stonith Fencer connection
* \param[in,out] cib CIB connection
* \param[in] current_cib Current CIB XML
* \param[in] pcmkd_state \p pacemakerd state
* \param[in] fence_history How much of the fencing history to output
* \param[in] show Group of \p pcmk_section_e flags
* \param[in] show_opts Group of \p pcmk_show_opt_e flags
Expand All @@ -68,7 +69,9 @@ fencing_connect(void)
*/
int
pcmk__output_cluster_status(pcmk__output_t *out, stonith_t *stonith, cib_t *cib,
xmlNode *current_cib, enum pcmk__fence_history fence_history,
xmlNode *current_cib,
enum pcmk_pacemakerd_state pcmkd_state,
enum pcmk__fence_history fence_history,
uint32_t show, uint32_t show_opts,
const char *only_node, const char *only_rsc,
const char *neg_location_prefix, bool simple_output)
Expand Down Expand Up @@ -122,7 +125,8 @@ pcmk__output_cluster_status(pcmk__output_t *out, stonith_t *stonith, cib_t *cib,
if (simple_output) {
rc = pcmk__output_simple_status(out, data_set);
} else {
out->message(out, "cluster-status", data_set, pcmk_rc2exitc(history_rc),
out->message(out, "cluster-status",
data_set, pcmkd_state, pcmk_rc2exitc(history_rc),
stonith_history, fence_history, show, show_opts,
neg_location_prefix, unames, resources);
}
Expand Down Expand Up @@ -214,20 +218,23 @@ pcmk__status(pcmk__output_t *out, cib_t *cib,
xmlNode *current_cib = NULL;
int rc = pcmk_rc_ok;
stonith_t *stonith = NULL;
enum pcmk_pacemakerd_state state = pcmk_pacemakerd_state_invalid;
enum pcmk_pacemakerd_state pcmkd_state = pcmk_pacemakerd_state_invalid;
time_t last_updated = 0;

if (cib == NULL) {
return ENOTCONN;
}

if (cib->variant == cib_native) {
rc = pcmk__pacemakerd_status(out, crm_system_name, timeout_ms, false,
&state);
&pcmkd_state);
if (rc != pcmk_rc_ok) {
return rc;
}

switch (state) {
last_updated = time(NULL);

switch (pcmkd_state) {
case pcmk_pacemakerd_state_running:
case pcmk_pacemakerd_state_shutting_down:
case pcmk_pacemakerd_state_remote:
Expand All @@ -238,7 +245,7 @@ pcmk__status(pcmk__output_t *out, cib_t *cib,
default:
// Fencer and CIB are definitely unavailable
out->message(out, "pacemakerd-health",
NULL, state, NULL, time(NULL));
NULL, pcmkd_state, NULL, last_updated);
return rc;
}

Expand All @@ -249,18 +256,18 @@ pcmk__status(pcmk__output_t *out, cib_t *cib,

rc = cib__signon_query(out, &cib, &current_cib);
if (rc != pcmk_rc_ok) {
if (state != pcmk_pacemakerd_state_invalid) {
// If we got this far, invalid means we didn't query the pcmkd state
if (pcmkd_state != pcmk_pacemakerd_state_invalid) {
// Invalid at this point means we didn't query the pcmkd state
out->message(out, "pacemakerd-health",
NULL, state, NULL, time(NULL));
NULL, pcmkd_state, NULL, last_updated);
}
goto done;
}

rc = pcmk__output_cluster_status(out, stonith, cib, current_cib,
fence_history, show, show_opts, only_node,
only_rsc, neg_location_prefix,
simple_output);
pcmkd_state, fence_history, show,
show_opts, only_node, only_rsc,
neg_location_prefix, simple_output);
if (rc != pcmk_rc_ok) {
out->err(out, "Error outputting status info from the fencer or CIB");
}
Expand Down
47 changes: 39 additions & 8 deletions lib/pengine/pe_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,13 @@ formatted_xml_buf(pe_resource_t *rsc, bool raw)
}
}

PCMK__OUTPUT_ARGS("cluster-summary", "pe_working_set_t *", "uint32_t", "uint32_t")
PCMK__OUTPUT_ARGS("cluster-summary", "pe_working_set_t *",
"enum pcmk_pacemakerd_state", "uint32_t", "uint32_t")
static int
cluster_summary(pcmk__output_t *out, va_list args) {
pe_working_set_t *data_set = va_arg(args, pe_working_set_t *);
enum pcmk_pacemakerd_state pcmkd_state =
(enum pcmk_pacemakerd_state) va_arg(args, int);
uint32_t section_opts = va_arg(args, uint32_t);
uint32_t show_opts = va_arg(args, uint32_t);

Expand All @@ -365,7 +368,7 @@ cluster_summary(pcmk__output_t *out, va_list args) {

if (pcmk_is_set(section_opts, pcmk_section_stack)) {
PCMK__OUTPUT_LIST_HEADER(out, false, rc, "Cluster Summary");
out->message(out, "cluster-stack", stack_s);
out->message(out, "cluster-stack", stack_s, pcmkd_state);
}

if (pcmk_is_set(section_opts, pcmk_section_dc)) {
Expand Down Expand Up @@ -417,10 +420,13 @@ cluster_summary(pcmk__output_t *out, va_list args) {
return rc;
}

PCMK__OUTPUT_ARGS("cluster-summary", "pe_working_set_t *", "uint32_t", "uint32_t")
PCMK__OUTPUT_ARGS("cluster-summary", "pe_working_set_t *",
"enum pcmk_pacemakerd_state", "uint32_t", "uint32_t")
static int
cluster_summary_html(pcmk__output_t *out, va_list args) {
pe_working_set_t *data_set = va_arg(args, pe_working_set_t *);
enum pcmk_pacemakerd_state pcmkd_state =
(enum pcmk_pacemakerd_state) va_arg(args, int);
uint32_t section_opts = va_arg(args, uint32_t);
uint32_t show_opts = va_arg(args, uint32_t);

Expand All @@ -429,7 +435,7 @@ cluster_summary_html(pcmk__output_t *out, va_list args) {

if (pcmk_is_set(section_opts, pcmk_section_stack)) {
PCMK__OUTPUT_LIST_HEADER(out, false, rc, "Cluster Summary");
out->message(out, "cluster-stack", stack_s);
out->message(out, "cluster-stack", stack_s, pcmkd_state);
}

/* Always print DC if none, even if not requested */
Expand Down Expand Up @@ -1076,35 +1082,60 @@ cluster_options_xml(pcmk__output_t *out, va_list args) {
return pcmk_rc_ok;
}

PCMK__OUTPUT_ARGS("cluster-stack", "const char *")
PCMK__OUTPUT_ARGS("cluster-stack", "const char *", "enum pcmk_pacemakerd_state")
static int
cluster_stack_html(pcmk__output_t *out, va_list args) {
const char *stack_s = va_arg(args, const char *);
enum pcmk_pacemakerd_state pcmkd_state =
(enum pcmk_pacemakerd_state) va_arg(args, int);

xmlNodePtr node = pcmk__output_create_xml_node(out, "li", NULL);

pcmk_create_html_node(node, "span", NULL, "bold", "Stack: ");
pcmk_create_html_node(node, "span", NULL, NULL, stack_s);

if (pcmkd_state != pcmk_pacemakerd_state_invalid) {
pcmk_create_html_node(node, "span", NULL, NULL, " (");
pcmk_create_html_node(node, "span", NULL, NULL,
pcmk__pcmkd_state_enum2friendly(pcmkd_state));
pcmk_create_html_node(node, "span", NULL, NULL, ")");
}
return pcmk_rc_ok;
}

PCMK__OUTPUT_ARGS("cluster-stack", "const char *")
PCMK__OUTPUT_ARGS("cluster-stack", "const char *", "enum pcmk_pacemakerd_state")
static int
cluster_stack_text(pcmk__output_t *out, va_list args) {
const char *stack_s = va_arg(args, const char *);
enum pcmk_pacemakerd_state pcmkd_state =
(enum pcmk_pacemakerd_state) va_arg(args, int);

if (pcmkd_state != pcmk_pacemakerd_state_invalid) {
out->list_item(out, "Stack", "%s (%s)",
stack_s, pcmk__pcmkd_state_enum2friendly(pcmkd_state));
} else {
out->list_item(out, "Stack", "%s", stack_s);
}

out->list_item(out, "Stack", "%s", stack_s);
return pcmk_rc_ok;
}

PCMK__OUTPUT_ARGS("cluster-stack", "const char *")
PCMK__OUTPUT_ARGS("cluster-stack", "const char *", "enum pcmk_pacemakerd_state")
static int
cluster_stack_xml(pcmk__output_t *out, va_list args) {
const char *stack_s = va_arg(args, const char *);
enum pcmk_pacemakerd_state pcmkd_state =
(enum pcmk_pacemakerd_state) va_arg(args, int);

const char *state_s = NULL;

if (pcmkd_state != pcmk_pacemakerd_state_invalid) {
state_s = pcmk_pacemakerd_api_daemon_state_enum2text(pcmkd_state);
}

pcmk__output_create_xml_node(out, "stack",
"type", stack_s,
"pacemakerd-state", state_s,
NULL);

return pcmk_rc_ok;
Expand Down
Loading

0 comments on commit d1110dd

Please sign in to comment.