Compare commits

...

No commits in common. "imports/c8-beta/pacemaker-2.0.5-8.el8" and "c8" have entirely different histories.

52 changed files with 13908 additions and 62653 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
SOURCES/nagios-agents-metadata-105ab8a.tar.gz
SOURCES/pacemaker-ba59be7.tar.gz
SOURCES/pacemaker-0f7f88312.tar.gz

View File

@ -1,2 +1,2 @@
ea6c0a27fd0ae8ce02f84a11f08a0d79377041c3 SOURCES/nagios-agents-metadata-105ab8a.tar.gz
268769bcd0d6c2ea2d50db92aaea0f31637775d0 SOURCES/pacemaker-ba59be7.tar.gz
88946a460e3be18852861269f8837aaaf339328c SOURCES/pacemaker-0f7f88312.tar.gz

View File

@ -1,704 +0,0 @@
From d81282f1ac5e1226fbf6cfa1bd239d317e106def Mon Sep 17 00:00:00 2001
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
Date: Tue, 13 Oct 2020 10:08:21 +0200
Subject: [PATCH 1/3] Feature: crmadmin: implement formatted output
---
include/crm/crm.h | 2 +-
tools/crmadmin.c | 312 ++++++++++++++++++++++++++++++++++++++++--------------
2 files changed, 232 insertions(+), 82 deletions(-)
diff --git a/include/crm/crm.h b/include/crm/crm.h
index 389b6aa..4eca278 100644
--- a/include/crm/crm.h
+++ b/include/crm/crm.h
@@ -51,7 +51,7 @@ extern "C" {
* >=3.0.13: Fail counts include operation name and interval
* >=3.2.0: DC supports PCMK_LRM_OP_INVALID and PCMK_LRM_OP_NOT_CONNECTED
*/
-# define CRM_FEATURE_SET "3.6.1"
+# define CRM_FEATURE_SET "3.6.2"
# define EOS '\0'
# define DIMOF(a) ((int) (sizeof(a)/sizeof(a[0])) )
diff --git a/tools/crmadmin.c b/tools/crmadmin.c
index 0b87d01..14078e6 100644
--- a/tools/crmadmin.c
+++ b/tools/crmadmin.c
@@ -20,6 +20,7 @@
#include <crm/cib.h>
#include <crm/msg_xml.h>
#include <crm/common/cmdline_internal.h>
+#include <crm/common/output_internal.h>
#include <crm/common/xml.h>
#include <crm/common/iso8601.h>
#include <crm/common/ipc_controld.h>
@@ -38,7 +39,6 @@ bool need_controld_api = true;
bool need_pacemakerd_api = false;
bool do_work(pcmk_ipc_api_t *api);
-void do_find_node_list(xmlNode *xml_node);
static char *ipc_name = NULL;
gboolean admin_message_timeout(gpointer data);
@@ -55,13 +55,12 @@ static enum {
static gboolean BE_VERBOSE = FALSE;
static gboolean BASH_EXPORT = FALSE;
-static gboolean BE_SILENT = FALSE;
static char *dest_node = NULL;
static crm_exit_t exit_code = CRM_EX_OK;
+pcmk__output_t *out = NULL;
struct {
- gboolean quiet;
gboolean health;
gint timeout;
} options;
@@ -168,6 +167,191 @@ command_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError
return TRUE;
}
+PCMK__OUTPUT_ARGS("health", "char *", "char *", "char *", "char *")
+static int
+health_text(pcmk__output_t *out, va_list args)
+{
+ char *sys_from = va_arg(args, char *);
+ char *host_from = va_arg(args, char *);
+ char *fsa_state = va_arg(args, char *);
+ char *result = va_arg(args, char *);
+
+ if (!out->is_quiet(out)) {
+ out->info(out, "Status of %s@%s: %s (%s)", crm_str(sys_from),
+ crm_str(host_from), crm_str(fsa_state), crm_str(result));
+ } else if (fsa_state != NULL) {
+ out->info(out, "%s", fsa_state);
+ }
+
+ return pcmk_rc_ok;
+}
+
+PCMK__OUTPUT_ARGS("health", "char *", "char *", "char *", "char *")
+static int
+health_xml(pcmk__output_t *out, va_list args)
+{
+ char *sys_from = va_arg(args, char *);
+ char *host_from = va_arg(args, char *);
+ char *fsa_state = va_arg(args, char *);
+ char *result = va_arg(args, char *);
+
+ xmlNodePtr node = pcmk__output_create_xml_node(out, crm_str(sys_from));
+ xmlSetProp(node, (pcmkXmlStr) "node_name", (pcmkXmlStr) crm_str(host_from));
+ xmlSetProp(node, (pcmkXmlStr) "state", (pcmkXmlStr) crm_str(fsa_state));
+ xmlSetProp(node, (pcmkXmlStr) "result", (pcmkXmlStr) crm_str(result));
+
+ return pcmk_rc_ok;
+}
+
+PCMK__OUTPUT_ARGS("pacemakerd-health", "char *", "char *", "char *")
+static int
+pacemakerd_health_text(pcmk__output_t *out, va_list args)
+{
+ char *sys_from = va_arg(args, char *);
+ char *state = va_arg(args, char *);
+ char *last_updated = va_arg(args, char *);
+
+ if (!out->is_quiet(out)) {
+ out->info(out, "Status of %s: '%s' %s %s", crm_str(sys_from),
+ crm_str(state), (!pcmk__str_empty(last_updated))?
+ "last updated":"", crm_str(last_updated));
+ } else {
+ out->info(out, "%s", crm_str(state));
+ }
+
+ return pcmk_rc_ok;
+}
+
+PCMK__OUTPUT_ARGS("pacemakerd-health", "char *", "char *", "char *")
+static int
+pacemakerd_health_xml(pcmk__output_t *out, va_list args)
+{
+ char *sys_from = va_arg(args, char *);
+ char *state = va_arg(args, char *);
+ char *last_updated = va_arg(args, char *);
+
+
+ xmlNodePtr node = pcmk__output_create_xml_node(out, crm_str(sys_from));
+ xmlSetProp(node, (pcmkXmlStr) "state", (pcmkXmlStr) crm_str(state));
+ xmlSetProp(node, (pcmkXmlStr) "last_updated", (pcmkXmlStr) crm_str(last_updated));
+
+ return pcmk_rc_ok;
+}
+
+PCMK__OUTPUT_ARGS("dc", "char *")
+static int
+dc_text(pcmk__output_t *out, va_list args)
+{
+ char *dc = va_arg(args, char *);
+
+ if (!out->is_quiet(out)) {
+ out->info(out, "Designated Controller is: %s", crm_str(dc));
+ } else if (dc != NULL) {
+ out->info(out, "%s", dc);
+ }
+
+ return pcmk_rc_ok;
+}
+
+PCMK__OUTPUT_ARGS("dc", "char *")
+static int
+dc_xml(pcmk__output_t *out, va_list args)
+{
+ char *dc = va_arg(args, char *);
+
+ xmlNodePtr node = pcmk__output_create_xml_node(out, "dc");
+ xmlSetProp(node, (pcmkXmlStr) "node_name", (pcmkXmlStr) crm_str(dc));
+
+ return pcmk_rc_ok;
+}
+
+
+PCMK__OUTPUT_ARGS("crmadmin-node-list", "xmlNode *")
+static int
+crmadmin_node_list(pcmk__output_t *out, va_list args)
+{
+ xmlNode *xml_node = va_arg(args, xmlNode *);
+ int found = 0;
+ xmlNode *node = NULL;
+ xmlNode *nodes = get_object_root(XML_CIB_TAG_NODES, xml_node);
+
+ out->begin_list(out, NULL, NULL, "Nodes");
+
+ for (node = first_named_child(nodes, XML_CIB_TAG_NODE); node != NULL;
+ node = crm_next_same_xml(node)) {
+ const char *node_type = BASH_EXPORT ? NULL :
+ crm_element_value(node, XML_ATTR_TYPE);
+ out->message(out, "crmadmin-node", node_type,
+ crm_str(crm_element_value(node, XML_ATTR_UNAME)),
+ crm_str(crm_element_value(node, XML_ATTR_ID)));
+
+ found++;
+ }
+ // @TODO List Pacemaker Remote nodes that don't have a <node> entry
+
+ out->end_list(out);
+
+ if (found == 0) {
+ out->info(out, "No nodes configured");
+ }
+
+ return pcmk_rc_ok;
+}
+
+PCMK__OUTPUT_ARGS("crmadmin-node", "char *", "char *", "char *")
+static int
+crmadmin_node_text(pcmk__output_t *out, va_list args)
+{
+ char *type = va_arg(args, char *);
+ char *name = va_arg(args, char *);
+ char *id = va_arg(args, char *);
+
+ if (BASH_EXPORT) {
+ out->info(out, "export %s=%s", crm_str(name), crm_str(id));
+ } else {
+ out->info(out, "%s node: %s (%s)", type ? type : "member",
+ crm_str(name), crm_str(id));
+ }
+
+ return pcmk_rc_ok;
+}
+
+PCMK__OUTPUT_ARGS("crmadmin-node", "char *", "char *", "char *")
+static int
+crmadmin_node_xml(pcmk__output_t *out, va_list args)
+{
+ char *type = va_arg(args, char *);
+ char *name = va_arg(args, char *);
+ char *id = va_arg(args, char *);
+
+ xmlNodePtr node = pcmk__output_create_xml_node(out, "crmadmin-node");
+ xmlSetProp(node, (pcmkXmlStr) "type", (pcmkXmlStr) (type ? type : "member"));
+ xmlSetProp(node, (pcmkXmlStr) "name", (pcmkXmlStr) crm_str(name));
+ xmlSetProp(node, (pcmkXmlStr) "id", (pcmkXmlStr) crm_str(id));
+
+ return pcmk_rc_ok;
+}
+
+static pcmk__message_entry_t fmt_functions[] = {
+ {"health", "default", health_text },
+ {"health", "xml", health_xml },
+ {"pacemakerd-health", "default", pacemakerd_health_text },
+ {"pacemakerd-health", "xml", pacemakerd_health_xml },
+ {"dc", "default", dc_text },
+ {"dc", "xml", dc_xml },
+ {"crmadmin-node-list", "default", crmadmin_node_list },
+ {"crmadmin-node", "default", crmadmin_node_text },
+ {"crmadmin-node", "xml", crmadmin_node_xml },
+
+ { NULL, NULL, NULL }
+};
+
+static pcmk__supported_format_t formats[] = {
+ PCMK__SUPPORTED_FORMAT_TEXT,
+ PCMK__SUPPORTED_FORMAT_XML,
+ { NULL, NULL, NULL }
+};
+
static void
quit_main_loop(crm_exit_t ec)
{
@@ -191,7 +375,7 @@ controller_event_cb(pcmk_ipc_api_t *controld_api,
switch (event_type) {
case pcmk_ipc_event_disconnect:
if (exit_code == CRM_EX_DISCONNECT) { // Unexpected
- fprintf(stderr, "error: Lost connection to controller\n");
+ out->err(out, "error: Lost connection to controller");
}
goto done;
break;
@@ -209,14 +393,14 @@ controller_event_cb(pcmk_ipc_api_t *controld_api,
}
if (status != CRM_EX_OK) {
- fprintf(stderr, "error: Bad reply from controller: %s",
+ out->err(out, "error: Bad reply from controller: %s",
crm_exit_str(status));
exit_code = status;
goto done;
}
if (reply->reply_type != pcmk_controld_reply_ping) {
- fprintf(stderr, "error: Unknown reply type %d from controller\n",
+ out->err(out, "error: Unknown reply type %d from controller",
reply->reply_type);
goto done;
}
@@ -224,22 +408,16 @@ controller_event_cb(pcmk_ipc_api_t *controld_api,
// Parse desired information from reply
switch (command) {
case cmd_health:
- printf("Status of %s@%s: %s (%s)\n",
+ out->message(out, "health",
reply->data.ping.sys_from,
reply->host_from,
reply->data.ping.fsa_state,
reply->data.ping.result);
- if (BE_SILENT && (reply->data.ping.fsa_state != NULL)) {
- fprintf(stderr, "%s\n", reply->data.ping.fsa_state);
- }
exit_code = CRM_EX_OK;
break;
case cmd_whois_dc:
- printf("Designated Controller is: %s\n", reply->host_from);
- if (BE_SILENT && (reply->host_from != NULL)) {
- fprintf(stderr, "%s\n", reply->host_from);
- }
+ out->message(out, "dc", reply->host_from);
exit_code = CRM_EX_OK;
break;
@@ -263,7 +441,7 @@ pacemakerd_event_cb(pcmk_ipc_api_t *pacemakerd_api,
switch (event_type) {
case pcmk_ipc_event_disconnect:
if (exit_code == CRM_EX_DISCONNECT) { // Unexpected
- fprintf(stderr, "error: Lost connection to pacemakerd\n");
+ out->err(out, "error: Lost connection to pacemakerd");
}
goto done;
break;
@@ -281,14 +459,14 @@ pacemakerd_event_cb(pcmk_ipc_api_t *pacemakerd_api,
}
if (status != CRM_EX_OK) {
- fprintf(stderr, "error: Bad reply from pacemakerd: %s",
+ out->err(out, "error: Bad reply from pacemakerd: %s",
crm_exit_str(status));
exit_code = status;
goto done;
}
if (reply->reply_type != pcmk_pacemakerd_reply_ping) {
- fprintf(stderr, "error: Unknown reply type %d from pacemakerd\n",
+ out->err(out, "error: Unknown reply type %d from pacemakerd",
reply->reply_type);
goto done;
}
@@ -305,21 +483,12 @@ pacemakerd_event_cb(pcmk_ipc_api_t *pacemakerd_api,
crm_time_log_date | crm_time_log_timeofday |
crm_time_log_with_timezone);
- printf("Status of %s: '%s' %s %s\n",
+ out->message(out, "pacemakerd-health",
reply->data.ping.sys_from,
(reply->data.ping.status == pcmk_rc_ok)?
pcmk_pacemakerd_api_daemon_state_enum2text(
reply->data.ping.state):"query failed",
- (reply->data.ping.status == pcmk_rc_ok)?"last updated":"",
(reply->data.ping.status == pcmk_rc_ok)?pinged_buf:"");
- if (BE_SILENT &&
- (reply->data.ping.state != pcmk_pacemakerd_state_invalid)) {
- fprintf(stderr, "%s\n",
- (reply->data.ping.status == pcmk_rc_ok)?
- pcmk_pacemakerd_api_daemon_state_enum2text(
- reply->data.ping.state):
- "query failed");
- }
exit_code = CRM_EX_OK;
free(pinged_buf);
}
@@ -354,7 +523,7 @@ list_nodes()
rc = the_cib->cmds->query(the_cib, NULL, &output,
cib_scope_local | cib_sync_call);
if (rc == pcmk_ok) {
- do_find_node_list(output);
+ out->message(out, "crmadmin-node-list", output);
free_xml(output);
}
the_cib->cmds->signoff(the_cib);
@@ -362,20 +531,20 @@ list_nodes()
}
static GOptionContext *
-build_arg_context(pcmk__common_args_t *args) {
+build_arg_context(pcmk__common_args_t *args, GOptionGroup **group) {
GOptionContext *context = NULL;
const char *description = "Report bugs to users@clusterlabs.org";
GOptionEntry extra_prog_entries[] = {
- { "quiet", 'q', 0, G_OPTION_ARG_NONE, &options.quiet,
+ { "quiet", 'q', 0, G_OPTION_ARG_NONE, &(args->quiet),
"Display only the essential query information",
NULL },
{ NULL }
};
- context = pcmk__build_arg_context(args, NULL, NULL, NULL);
+ context = pcmk__build_arg_context(args, "text (default), xml", group, NULL);
g_option_context_set_description(context, description);
/* Add the -q option, which cannot be part of the globally supported options
@@ -402,9 +571,11 @@ main(int argc, char **argv)
GError *error = NULL;
GOptionContext *context = NULL;
+ GOptionGroup *output_group = NULL;
gchar **processed_args = NULL;
- context = build_arg_context(args);
+ context = build_arg_context(args, &output_group);
+ pcmk__register_formats(output_group, formats);
crm_log_cli_init("crmadmin");
@@ -421,9 +592,21 @@ main(int argc, char **argv)
crm_bump_log_level(argc, argv);
}
+ rc = pcmk__output_new(&out, args->output_ty, args->output_dest, argv);
+ if (rc != pcmk_rc_ok) {
+ fprintf(stderr, "Error creating output format %s: %s\n",
+ args->output_ty, pcmk_rc_str(rc));
+ exit_code = CRM_EX_ERROR;
+ goto done;
+ }
+
+ out->quiet = args->quiet;
+
+ pcmk__register_messages(out, fmt_functions);
+
if (args->version) {
- /* FIXME: When crmadmin is converted to use formatted output, this can go. */
- pcmk__cli_help('v', CRM_EX_USAGE);
+ out->version(out, false);
+ goto done;
}
if (options.timeout) {
@@ -433,12 +616,8 @@ main(int argc, char **argv)
}
}
- if (options.quiet) {
- BE_SILENT = TRUE;
- }
-
if (options.health) {
- fprintf(stderr, "Cluster-wide health option not supported\n");
+ out->err(out, "Cluster-wide health option not supported");
++argerr;
}
@@ -447,14 +626,14 @@ main(int argc, char **argv)
}
if (command == cmd_none) {
- fprintf(stderr, "error: Must specify a command option\n\n");
+ out->err(out, "error: Must specify a command option");
++argerr;
}
if (argerr) {
char *help = g_option_context_get_help(context, TRUE, NULL);
- fprintf(stderr, "%s", help);
+ out->err(out, "%s", help);
g_free(help);
exit_code = CRM_EX_USAGE;
goto done;
@@ -464,7 +643,7 @@ main(int argc, char **argv)
if (need_controld_api) {
rc = pcmk_new_ipc_api(&controld_api, pcmk_ipc_controld);
if (controld_api == NULL) {
- fprintf(stderr, "error: Could not connect to controller: %s\n",
+ out->err(out, "error: Could not connect to controller: %s",
pcmk_rc_str(rc));
exit_code = pcmk_rc2exitc(rc);
goto done;
@@ -472,7 +651,7 @@ main(int argc, char **argv)
pcmk_register_ipc_callback(controld_api, controller_event_cb, NULL);
rc = pcmk_connect_ipc(controld_api, pcmk_ipc_dispatch_main);
if (rc != pcmk_rc_ok) {
- fprintf(stderr, "error: Could not connect to controller: %s\n",
+ out->err(out, "error: Could not connect to controller: %s",
pcmk_rc_str(rc));
exit_code = pcmk_rc2exitc(rc);
goto done;
@@ -483,7 +662,7 @@ main(int argc, char **argv)
if (need_pacemakerd_api) {
rc = pcmk_new_ipc_api(&pacemakerd_api, pcmk_ipc_pacemakerd);
if (pacemakerd_api == NULL) {
- fprintf(stderr, "error: Could not connect to pacemakerd: %s\n",
+ out->err(out, "error: Could not connect to pacemakerd: %s",
pcmk_rc_str(rc));
exit_code = pcmk_rc2exitc(rc);
goto done;
@@ -491,7 +670,7 @@ main(int argc, char **argv)
pcmk_register_ipc_callback(pacemakerd_api, pacemakerd_event_cb, NULL);
rc = pcmk_connect_ipc(pacemakerd_api, pcmk_ipc_dispatch_main);
if (rc != pcmk_rc_ok) {
- fprintf(stderr, "error: Could not connect to pacemakerd: %s\n",
+ out->err(out, "error: Could not connect to pacemakerd: %s",
pcmk_rc_str(rc));
exit_code = pcmk_rc2exitc(rc);
goto done;
@@ -528,6 +707,10 @@ done:
g_strfreev(processed_args);
g_clear_error(&error);
pcmk__free_arg_context(context);
+ if (out != NULL) {
+ out->finish(out, exit_code, true, NULL);
+ pcmk__output_free(out);
+ }
return crm_exit(exit_code);
}
@@ -567,7 +750,7 @@ do_work(pcmk_ipc_api_t *api)
break;
}
if (rc != pcmk_rc_ok) {
- fprintf(stderr, "error: Command failed: %s", pcmk_rc_str(rc));
+ out->err(out, "error: Command failed: %s", pcmk_rc_str(rc));
exit_code = pcmk_rc2exitc(rc);
}
return need_reply;
@@ -576,43 +759,10 @@ do_work(pcmk_ipc_api_t *api)
gboolean
admin_message_timeout(gpointer data)
{
- fprintf(stderr,
- "error: No reply received from controller before timeout (%dms)\n",
+ out->err(out,
+ "error: No reply received from controller before timeout (%dms)",
message_timeout_ms);
message_timer_id = 0;
quit_main_loop(CRM_EX_TIMEOUT);
return FALSE; // Tells glib to remove source
}
-
-void
-do_find_node_list(xmlNode * xml_node)
-{
- int found = 0;
- xmlNode *node = NULL;
- xmlNode *nodes = get_object_root(XML_CIB_TAG_NODES, xml_node);
-
- for (node = first_named_child(nodes, XML_CIB_TAG_NODE); node != NULL;
- node = crm_next_same_xml(node)) {
-
- if (BASH_EXPORT) {
- printf("export %s=%s\n",
- crm_element_value(node, XML_ATTR_UNAME),
- crm_element_value(node, XML_ATTR_ID));
- } else {
- const char *node_type = crm_element_value(node, XML_ATTR_TYPE);
-
- if (node_type == NULL) {
- node_type = "member";
- }
- printf("%s node: %s (%s)\n", node_type,
- crm_element_value(node, XML_ATTR_UNAME),
- crm_element_value(node, XML_ATTR_ID));
- }
- found++;
- }
- // @TODO List Pacemaker Remote nodes that don't have a <node> entry
-
- if (found == 0) {
- printf("No nodes configured\n");
- }
-}
--
1.8.3.1
From 2b121066c8eead96e85dc3bf6ecc1c2674cbdf32 Mon Sep 17 00:00:00 2001
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
Date: Tue, 20 Oct 2020 16:19:03 +0200
Subject: [PATCH 2/3] Refactor: crmadmin: use simple XML lists
---
tools/crmadmin.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/tools/crmadmin.c b/tools/crmadmin.c
index 14078e6..b80a31a 100644
--- a/tools/crmadmin.c
+++ b/tools/crmadmin.c
@@ -275,7 +275,7 @@ crmadmin_node_list(pcmk__output_t *out, va_list args)
xmlNode *node = NULL;
xmlNode *nodes = get_object_root(XML_CIB_TAG_NODES, xml_node);
- out->begin_list(out, NULL, NULL, "Nodes");
+ out->begin_list(out, NULL, NULL, "nodes");
for (node = first_named_child(nodes, XML_CIB_TAG_NODE); node != NULL;
node = crm_next_same_xml(node)) {
@@ -324,7 +324,7 @@ crmadmin_node_xml(pcmk__output_t *out, va_list args)
char *name = va_arg(args, char *);
char *id = va_arg(args, char *);
- xmlNodePtr node = pcmk__output_create_xml_node(out, "crmadmin-node");
+ xmlNodePtr node = pcmk__output_create_xml_node(out, "node");
xmlSetProp(node, (pcmkXmlStr) "type", (pcmkXmlStr) (type ? type : "member"));
xmlSetProp(node, (pcmkXmlStr) "name", (pcmkXmlStr) crm_str(name));
xmlSetProp(node, (pcmkXmlStr) "id", (pcmkXmlStr) crm_str(id));
@@ -604,6 +604,10 @@ main(int argc, char **argv)
pcmk__register_messages(out, fmt_functions);
+ if (!pcmk__force_args(context, &error, "%s --xml-simple-list --xml-substitute", g_get_prgname())) {
+ goto done;
+ }
+
if (args->version) {
out->version(out, false);
goto done;
--
1.8.3.1
From 9b53a7eda078db736be5212aeb77daf8117e2f17 Mon Sep 17 00:00:00 2001
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
Date: Tue, 20 Oct 2020 16:21:12 +0200
Subject: [PATCH 3/3] Feature: xml: add schema for new crmadmin output
---
xml/Makefile.am | 2 +-
xml/api/crmadmin-2.4.rng | 68 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+), 1 deletion(-)
create mode 100644 xml/api/crmadmin-2.4.rng
diff --git a/xml/Makefile.am b/xml/Makefile.am
index c045522..892c811 100644
--- a/xml/Makefile.am
+++ b/xml/Makefile.am
@@ -45,7 +45,7 @@ version_pairs_last = $(wordlist \
)
# Names of API schemas that form the choices for pacemaker-result content
-API_request_base = command-output crm_mon stonith_admin version
+API_request_base = command-output crm_mon crmadmin stonith_admin version
# Names of CIB schemas that form the choices for cib/configuration content
CIB_cfg_base = options nodes resources constraints fencing acls tags alerts
diff --git a/xml/api/crmadmin-2.4.rng b/xml/api/crmadmin-2.4.rng
new file mode 100644
index 0000000..34c9ca4
--- /dev/null
+++ b/xml/api/crmadmin-2.4.rng
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<grammar xmlns="http://relaxng.org/ns/structure/1.0"
+ datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+
+ <start>
+ <ref name="element-crmadmin"/>
+ </start>
+
+ <define name="element-crmadmin">
+ <optional>
+ <ref name="element-status" />
+ </optional>
+ <optional>
+ <ref name="element-pacemakerd" />
+ </optional>
+ <optional>
+ <ref name="element-dc" />
+ </optional>
+ <optional>
+ <ref name="crmadmin-nodes-list" />
+ </optional>
+ </define>
+
+ <define name="element-status">
+ <element name="crmd">
+ <attribute name="node_name"> <text /> </attribute>
+ <attribute name="state"> <text /> </attribute>
+ <attribute name="result"> <text /> </attribute>
+ </element>
+ </define>
+
+ <define name="element-pacemakerd">
+ <element name="pacemakerd">
+ <attribute name="state"> <text /> </attribute>
+ <attribute name="last_updated"> <text /> </attribute>
+ </element>
+ </define>
+
+ <define name="element-dc">
+ <element name="dc">
+ <attribute name="node_name"> <text /> </attribute>
+ </element>
+ </define>
+
+ <define name="crmadmin-nodes-list">
+ <element name="nodes">
+ <zeroOrMore>
+ <ref name="element-crmadmin-node" />
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <define name="element-crmadmin-node">
+ <element name="node">
+ <attribute name="type">
+ <choice>
+ <value>unknown</value>
+ <value>member</value>
+ <value>remote</value>
+ <value>ping</value>
+ </choice>
+ </attribute>
+
+ <attribute name="name"> <text/> </attribute>
+ <attribute name="id"> <text/> </attribute>
+ </element>
+ </define>
+</grammar>
--
1.8.3.1

File diff suppressed because it is too large Load Diff

View File

@ -1,165 +0,0 @@
From 12e59f337f838d647deb8f84850324f785e58824 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Tue, 20 Oct 2020 10:53:26 -0400
Subject: [PATCH] Feature: libcrmcommon: Add a spacer formatted output message.
---
include/crm/common/output_internal.h | 10 +++++++++-
lib/common/output_html.c | 6 ++++++
lib/common/output_log.c | 6 ++++++
lib/common/output_text.c | 6 ++++++
lib/common/output_xml.c | 6 ++++++
tools/crm_mon_curses.c | 6 ++++++
6 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/include/crm/common/output_internal.h b/include/crm/common/output_internal.h
index 2874259..e1bd295 100644
--- a/include/crm/common/output_internal.h
+++ b/include/crm/common/output_internal.h
@@ -460,6 +460,14 @@ struct pcmk__output_s {
* \return true if output should be supressed, false otherwise.
*/
bool (*is_quiet) (pcmk__output_t *out);
+
+ /*!
+ * \internal
+ * \brief Output a spacer. Not all formatter will do this.
+ *
+ * \param[in] out The output functions structure.
+ */
+ void (*spacer) (pcmk__output_t *out);
};
/*!
@@ -745,7 +753,7 @@ G_GNUC_NULL_TERMINATED;
#define PCMK__OUTPUT_SPACER_IF(out_obj, cond) \
if (cond) { \
- out_obj->info(out_obj, "%s", ""); \
+ out->spacer(out); \
}
#define PCMK__OUTPUT_LIST_HEADER(out_obj, cond, retcode, title...) \
diff --git a/lib/common/output_html.c b/lib/common/output_html.c
index 156887d..e354b5d 100644
--- a/lib/common/output_html.c
+++ b/lib/common/output_html.c
@@ -368,6 +368,11 @@ html_is_quiet(pcmk__output_t *out) {
return false;
}
+static void
+html_spacer(pcmk__output_t *out) {
+ pcmk__output_create_xml_node(out, "br");
+}
+
pcmk__output_t *
pcmk__mk_html_output(char **argv) {
pcmk__output_t *retval = calloc(1, sizeof(pcmk__output_t));
@@ -399,6 +404,7 @@ pcmk__mk_html_output(char **argv) {
retval->end_list = html_end_list;
retval->is_quiet = html_is_quiet;
+ retval->spacer = html_spacer;
return retval;
}
diff --git a/lib/common/output_log.c b/lib/common/output_log.c
index fd13c89..6336fa2 100644
--- a/lib/common/output_log.c
+++ b/lib/common/output_log.c
@@ -226,6 +226,11 @@ log_is_quiet(pcmk__output_t *out) {
return false;
}
+static void
+log_spacer(pcmk__output_t *out) {
+ /* This function intentionally left blank */
+}
+
pcmk__output_t *
pcmk__mk_log_output(char **argv) {
pcmk__output_t *retval = calloc(1, sizeof(pcmk__output_t));
@@ -256,6 +261,7 @@ pcmk__mk_log_output(char **argv) {
retval->end_list = log_end_list;
retval->is_quiet = log_is_quiet;
+ retval->spacer = log_spacer;
return retval;
}
diff --git a/lib/common/output_text.c b/lib/common/output_text.c
index 9b3c09a..3432505 100644
--- a/lib/common/output_text.c
+++ b/lib/common/output_text.c
@@ -244,6 +244,11 @@ text_is_quiet(pcmk__output_t *out) {
return out->quiet;
}
+static void
+text_spacer(pcmk__output_t *out) {
+ fprintf(out->dest, "\n");
+}
+
pcmk__output_t *
pcmk__mk_text_output(char **argv) {
pcmk__output_t *retval = calloc(1, sizeof(pcmk__output_t));
@@ -275,6 +280,7 @@ pcmk__mk_text_output(char **argv) {
retval->end_list = text_end_list;
retval->is_quiet = text_is_quiet;
+ retval->spacer = text_spacer;
return retval;
}
diff --git a/lib/common/output_xml.c b/lib/common/output_xml.c
index 9a08d20..1710fac 100644
--- a/lib/common/output_xml.c
+++ b/lib/common/output_xml.c
@@ -376,6 +376,11 @@ xml_is_quiet(pcmk__output_t *out) {
return false;
}
+static void
+xml_spacer(pcmk__output_t *out) {
+ /* This function intentionally left blank */
+}
+
pcmk__output_t *
pcmk__mk_xml_output(char **argv) {
pcmk__output_t *retval = calloc(1, sizeof(pcmk__output_t));
@@ -407,6 +412,7 @@ pcmk__mk_xml_output(char **argv) {
retval->end_list = xml_end_list;
retval->is_quiet = xml_is_quiet;
+ retval->spacer = xml_spacer;
return retval;
}
diff --git a/tools/crm_mon_curses.c b/tools/crm_mon_curses.c
index 2c092df..8a08578 100644
--- a/tools/crm_mon_curses.c
+++ b/tools/crm_mon_curses.c
@@ -247,6 +247,11 @@ curses_is_quiet(pcmk__output_t *out) {
return out->quiet;
}
+static void
+curses_spacer(pcmk__output_t *out) {
+ addch('\n');
+}
+
pcmk__output_t *
crm_mon_mk_curses_output(char **argv) {
pcmk__output_t *retval = calloc(1, sizeof(pcmk__output_t));
@@ -278,6 +283,7 @@ crm_mon_mk_curses_output(char **argv) {
retval->end_list = curses_end_list;
retval->is_quiet = curses_is_quiet;
+ retval->spacer = curses_spacer;
return retval;
}
--
1.8.3.1

File diff suppressed because it is too large Load Diff

View File

@ -1,208 +0,0 @@
From 0deb5145c336bc4b32766c6f7af259d643af9143 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Wed, 28 Oct 2020 13:56:09 -0400
Subject: [PATCH 1/2] Fix: scheduler, tools: Update typing on maint-mode args.
---
lib/pengine/pe_output.c | 2 +-
tools/crm_mon_curses.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/pengine/pe_output.c b/lib/pengine/pe_output.c
index 186be33..d0f96f4 100644
--- a/lib/pengine/pe_output.c
+++ b/lib/pengine/pe_output.c
@@ -686,7 +686,7 @@ pe__cluster_dc_xml(pcmk__output_t *out, va_list args) {
return pcmk_rc_ok;
}
-PCMK__OUTPUT_ARGS("maint-mode", "unsigned long long")
+PCMK__OUTPUT_ARGS("maint-mode", "unsigned long long int")
int
pe__cluster_maint_mode_text(pcmk__output_t *out, va_list args) {
unsigned long long flags = va_arg(args, unsigned long long);
diff --git a/tools/crm_mon_curses.c b/tools/crm_mon_curses.c
index 8a08578..9cf28dc 100644
--- a/tools/crm_mon_curses.c
+++ b/tools/crm_mon_curses.c
@@ -365,7 +365,7 @@ stonith_event_console(pcmk__output_t *out, va_list args) {
return pcmk_rc_ok;
}
-PCMK__OUTPUT_ARGS("maint-mode", "unsigned long long")
+PCMK__OUTPUT_ARGS("maint-mode", "unsigned long long int")
static int
cluster_maint_mode_console(pcmk__output_t *out, va_list args) {
unsigned long long flags = va_arg(args, unsigned long long);
--
1.8.3.1
From 7a61ae2384b0a1653b4a06926b4ec23099ccf292 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Wed, 28 Oct 2020 13:57:51 -0400
Subject: [PATCH 2/2] Fix: tools: Update typing on formatted output args in
crmadmin.
A lot of these are actually taking const char * as an argument, not
regular char *.
---
tools/crmadmin.c | 62 ++++++++++++++++++++++++++++----------------------------
1 file changed, 31 insertions(+), 31 deletions(-)
diff --git a/tools/crmadmin.c b/tools/crmadmin.c
index b80a31a..e61dbf4 100644
--- a/tools/crmadmin.c
+++ b/tools/crmadmin.c
@@ -167,14 +167,14 @@ command_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError
return TRUE;
}
-PCMK__OUTPUT_ARGS("health", "char *", "char *", "char *", "char *")
+PCMK__OUTPUT_ARGS("health", "const char *", "const char *", "const char *", "const char *")
static int
health_text(pcmk__output_t *out, va_list args)
{
- char *sys_from = va_arg(args, char *);
- char *host_from = va_arg(args, char *);
- char *fsa_state = va_arg(args, char *);
- char *result = va_arg(args, char *);
+ const char *sys_from = va_arg(args, const char *);
+ const char *host_from = va_arg(args, const char *);
+ const char *fsa_state = va_arg(args, const char *);
+ const char *result = va_arg(args, const char *);
if (!out->is_quiet(out)) {
out->info(out, "Status of %s@%s: %s (%s)", crm_str(sys_from),
@@ -186,14 +186,14 @@ health_text(pcmk__output_t *out, va_list args)
return pcmk_rc_ok;
}
-PCMK__OUTPUT_ARGS("health", "char *", "char *", "char *", "char *")
+PCMK__OUTPUT_ARGS("health", "const char *", "const char *", "const char *", "const char *")
static int
health_xml(pcmk__output_t *out, va_list args)
{
- char *sys_from = va_arg(args, char *);
- char *host_from = va_arg(args, char *);
- char *fsa_state = va_arg(args, char *);
- char *result = va_arg(args, char *);
+ const char *sys_from = va_arg(args, const char *);
+ const char *host_from = va_arg(args, const char *);
+ const char *fsa_state = va_arg(args, const char *);
+ const char *result = va_arg(args, const char *);
xmlNodePtr node = pcmk__output_create_xml_node(out, crm_str(sys_from));
xmlSetProp(node, (pcmkXmlStr) "node_name", (pcmkXmlStr) crm_str(host_from));
@@ -203,13 +203,13 @@ health_xml(pcmk__output_t *out, va_list args)
return pcmk_rc_ok;
}
-PCMK__OUTPUT_ARGS("pacemakerd-health", "char *", "char *", "char *")
+PCMK__OUTPUT_ARGS("pacemakerd-health", "const char *", "const char *", "const char *")
static int
pacemakerd_health_text(pcmk__output_t *out, va_list args)
{
- char *sys_from = va_arg(args, char *);
- char *state = va_arg(args, char *);
- char *last_updated = va_arg(args, char *);
+ const char *sys_from = va_arg(args, const char *);
+ const char *state = va_arg(args, const char *);
+ const char *last_updated = va_arg(args, const char *);
if (!out->is_quiet(out)) {
out->info(out, "Status of %s: '%s' %s %s", crm_str(sys_from),
@@ -222,13 +222,13 @@ pacemakerd_health_text(pcmk__output_t *out, va_list args)
return pcmk_rc_ok;
}
-PCMK__OUTPUT_ARGS("pacemakerd-health", "char *", "char *", "char *")
+PCMK__OUTPUT_ARGS("pacemakerd-health", "const char *", "const char *", "const char *")
static int
pacemakerd_health_xml(pcmk__output_t *out, va_list args)
{
- char *sys_from = va_arg(args, char *);
- char *state = va_arg(args, char *);
- char *last_updated = va_arg(args, char *);
+ const char *sys_from = va_arg(args, const char *);
+ const char *state = va_arg(args, const char *);
+ const char *last_updated = va_arg(args, const char *);
xmlNodePtr node = pcmk__output_create_xml_node(out, crm_str(sys_from));
@@ -238,11 +238,11 @@ pacemakerd_health_xml(pcmk__output_t *out, va_list args)
return pcmk_rc_ok;
}
-PCMK__OUTPUT_ARGS("dc", "char *")
+PCMK__OUTPUT_ARGS("dc", "const char *")
static int
dc_text(pcmk__output_t *out, va_list args)
{
- char *dc = va_arg(args, char *);
+ const char *dc = va_arg(args, const char *);
if (!out->is_quiet(out)) {
out->info(out, "Designated Controller is: %s", crm_str(dc));
@@ -253,11 +253,11 @@ dc_text(pcmk__output_t *out, va_list args)
return pcmk_rc_ok;
}
-PCMK__OUTPUT_ARGS("dc", "char *")
+PCMK__OUTPUT_ARGS("dc", "const char *")
static int
dc_xml(pcmk__output_t *out, va_list args)
{
- char *dc = va_arg(args, char *);
+ const char *dc = va_arg(args, const char *);
xmlNodePtr node = pcmk__output_create_xml_node(out, "dc");
xmlSetProp(node, (pcmkXmlStr) "node_name", (pcmkXmlStr) crm_str(dc));
@@ -266,7 +266,7 @@ dc_xml(pcmk__output_t *out, va_list args)
}
-PCMK__OUTPUT_ARGS("crmadmin-node-list", "xmlNode *")
+PCMK__OUTPUT_ARGS("crmadmin-node-list", "struct xmlNode *")
static int
crmadmin_node_list(pcmk__output_t *out, va_list args)
{
@@ -298,13 +298,13 @@ crmadmin_node_list(pcmk__output_t *out, va_list args)
return pcmk_rc_ok;
}
-PCMK__OUTPUT_ARGS("crmadmin-node", "char *", "char *", "char *")
+PCMK__OUTPUT_ARGS("crmadmin-node", "const char *", "const char *", "const char *")
static int
crmadmin_node_text(pcmk__output_t *out, va_list args)
{
- char *type = va_arg(args, char *);
- char *name = va_arg(args, char *);
- char *id = va_arg(args, char *);
+ const char *type = va_arg(args, const char *);
+ const char *name = va_arg(args, const char *);
+ const char *id = va_arg(args, const char *);
if (BASH_EXPORT) {
out->info(out, "export %s=%s", crm_str(name), crm_str(id));
@@ -316,13 +316,13 @@ crmadmin_node_text(pcmk__output_t *out, va_list args)
return pcmk_rc_ok;
}
-PCMK__OUTPUT_ARGS("crmadmin-node", "char *", "char *", "char *")
+PCMK__OUTPUT_ARGS("crmadmin-node", "const char *", "const char *", "const char *")
static int
crmadmin_node_xml(pcmk__output_t *out, va_list args)
{
- char *type = va_arg(args, char *);
- char *name = va_arg(args, char *);
- char *id = va_arg(args, char *);
+ const char *type = va_arg(args, const char *);
+ const char *name = va_arg(args, const char *);
+ const char *id = va_arg(args, const char *);
xmlNodePtr node = pcmk__output_create_xml_node(out, "node");
xmlSetProp(node, (pcmkXmlStr) "type", (pcmkXmlStr) (type ? type : "member"));
--
1.8.3.1

View File

@ -0,0 +1,42 @@
From a3bffc7c66bf6f796f977cffd44f223635b008c5 Mon Sep 17 00:00:00 2001
From: Reid Wahl <nrwahl@protonmail.com>
Date: Wed, 20 Dec 2023 13:33:47 -0800
Subject: [PATCH] Doc: Pacemaker Explained: Add replace for
PCMK__REMOTE_SCHEMA_DIR
So that the existing use in local-options.rst expands correctly.
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
---
doc/sphinx/Makefile.am | 1 +
doc/sphinx/conf.py.in | 1 +
3 files changed, 2 insertions(+)
create mode 100644 doc/sphinx/conf.py.in.rej
diff --git a/doc/sphinx/Makefile.am b/doc/sphinx/Makefile.am
index e48e19a..d0309ff 100644
--- a/doc/sphinx/Makefile.am
+++ b/doc/sphinx/Makefile.am
@@ -134,6 +134,7 @@ $(BOOKS:%=%/conf.py): conf.py.in
-e 's#%CRM_SCHEMA_DIRECTORY%#@CRM_SCHEMA_DIRECTORY@#g' \
-e 's#%PACEMAKER_CONFIG_DIR%#@PACEMAKER_CONFIG_DIR@#g' \
-e 's#%PCMK_GNUTLS_PRIORITIES%#@PCMK_GNUTLS_PRIORITIES@#g' \
+ -e 's#%PCMK__REMOTE_SCHEMA_DIR%#@PCMK__REMOTE_SCHEMA_DIR@#g' \
$(<) > "$@"
$(BOOK)/_build: $(STATIC_FILES) $(BOOK)/conf.py $(DEPS_$(BOOK)) $(wildcard $(srcdir)/$(BOOK)/*.rst)
diff --git a/doc/sphinx/conf.py.in b/doc/sphinx/conf.py.in
index 556eb72..511f029 100644
--- a/doc/sphinx/conf.py.in
+++ b/doc/sphinx/conf.py.in
@@ -40,6 +40,7 @@ rst_prolog="""
.. |PCMK_INIT_ENV_FILE| replace:: ``%PACEMAKER_CONFIG_DIR%/pcmk-init.env``
.. |PCMK_LOG_FILE| replace:: %CRM_LOG_DIR%/pacemaker.log
.. |PCMK_GNUTLS_PRIORITIES| replace:: %PCMK_GNUTLS_PRIORITIES%
+.. |PCMK__REMOTE_SCHEMA_DIR| replace:: %PCMK__REMOTE_SCHEMA_DIR%
.. |REMOTE_DISTRO| replace:: AlmaLinux
.. |REMOTE_DISTRO_VER| replace:: 9
"""
--
2.31.1

File diff suppressed because it is too large Load Diff

View File

@ -1,771 +0,0 @@
From 9faa62f0701801f1d420462025e863d8ca3d6a06 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Mon, 21 Sep 2020 14:19:19 -0400
Subject: [PATCH 1/6] Fix: libcrmcommon: Automatically lower case XML list
names.
---
lib/common/output_xml.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/lib/common/output_xml.c b/lib/common/output_xml.c
index 1710fac..6a6ed6e 100644
--- a/lib/common/output_xml.c
+++ b/lib/common/output_xml.c
@@ -50,7 +50,6 @@ typedef struct subst_s {
} subst_t;
static subst_t substitutions[] = {
- { "Attributes", "attributes" },
{ "Active Resources", "resources" },
{ "Full List of Resources", "resources" },
{ "Inactive Resources", "resources" },
@@ -61,8 +60,6 @@ static subst_t substitutions[] = {
{ "Operations", "node_history" },
{ "Negative Location Constraints", "bans" },
{ "Node Attributes", "node_attributes" },
- { "Resources", "resources" },
- { "Tickets", "tickets" },
{ NULL, NULL }
};
@@ -288,7 +285,7 @@ static void
xml_begin_list(pcmk__output_t *out, const char *singular_noun, const char *plural_noun,
const char *format, ...) {
va_list ap;
- const char *name = NULL;
+ char *name = NULL;
char *buf = NULL;
int len;
@@ -300,14 +297,14 @@ xml_begin_list(pcmk__output_t *out, const char *singular_noun, const char *plura
if (substitute) {
for (subst_t *s = substitutions; s->from != NULL; s++) {
if (!strcmp(s->from, buf)) {
- name = s->to;
+ name = g_strdup(s->to);
break;
}
}
}
if (name == NULL) {
- name = buf;
+ name = g_ascii_strdown(buf, -1);
}
if (legacy_xml || simple_list) {
@@ -319,6 +316,7 @@ xml_begin_list(pcmk__output_t *out, const char *singular_noun, const char *plura
xmlSetProp(list_node, (pcmkXmlStr) "name", (pcmkXmlStr) name);
}
+ g_free(name);
free(buf);
}
--
1.8.3.1
From 7a77441ae8d3ab943dfafebfc06b63402be323e1 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Tue, 27 Oct 2020 12:49:45 -0400
Subject: [PATCH 2/6] Feature: xml: Move resource-related XML schema into its
own file.
This allows it to be shared between the crm_mon and crm_resource
schemas. Also, this adds support for resource XML to crm_mon given that
this is now technically possible as part of the library output.
---
xml/Makefile.am | 2 +-
xml/api/crm_mon-2.4.rng | 311 ++++++++++++++++++++++++++++++++++++++++++++++
xml/api/resources-2.4.rng | 109 ++++++++++++++++
3 files changed, 421 insertions(+), 1 deletion(-)
create mode 100644 xml/api/crm_mon-2.4.rng
create mode 100644 xml/api/resources-2.4.rng
diff --git a/xml/Makefile.am b/xml/Makefile.am
index 892c811..79ce900 100644
--- a/xml/Makefile.am
+++ b/xml/Makefile.am
@@ -51,7 +51,7 @@ API_request_base = command-output crm_mon crmadmin stonith_admin version
CIB_cfg_base = options nodes resources constraints fencing acls tags alerts
# Names of all schemas (including top level and those included by others)
-API_base = $(API_request_base) fence-event item status
+API_base = $(API_request_base) fence-event item resources status
CIB_base = cib $(CIB_cfg_base) status score rule nvset
# Static schema files and transforms (only CIB has transforms)
diff --git a/xml/api/crm_mon-2.4.rng b/xml/api/crm_mon-2.4.rng
new file mode 100644
index 0000000..88973a4
--- /dev/null
+++ b/xml/api/crm_mon-2.4.rng
@@ -0,0 +1,311 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<grammar xmlns="http://relaxng.org/ns/structure/1.0"
+ datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+
+ <start>
+ <ref name="element-crm-mon"/>
+ </start>
+
+ <define name="element-crm-mon">
+ <optional>
+ <ref name="element-summary" />
+ </optional>
+ <optional>
+ <ref name="nodes-list" />
+ </optional>
+ <optional>
+ <ref name="resources-list" />
+ </optional>
+ <optional>
+ <ref name="node-attributes-list" />
+ </optional>
+ <optional>
+ <ref name="node-history-list" />
+ </optional>
+ <optional>
+ <ref name="failures-list" />
+ </optional>
+ <optional>
+ <ref name="fence-event-list" />
+ </optional>
+ <optional>
+ <ref name="tickets-list" />
+ </optional>
+ <optional>
+ <ref name="bans-list" />
+ </optional>
+ </define>
+
+ <define name="element-summary">
+ <element name="summary">
+ <optional>
+ <element name="stack">
+ <attribute name="type"> <text /> </attribute>
+ </element>
+ </optional>
+ <optional>
+ <element name="current_dc">
+ <attribute name="present"> <data type="boolean" /> </attribute>
+ <optional>
+ <group>
+ <attribute name="version"> <text /> </attribute>
+ <attribute name="name"> <text /> </attribute>
+ <attribute name="id"> <text /> </attribute>
+ <attribute name="with_quorum"> <data type="boolean" /> </attribute>
+ </group>
+ </optional>
+ </element>
+ </optional>
+ <optional>
+ <element name="last_update">
+ <attribute name="time"> <text /> </attribute>
+ </element>
+ <element name="last_change">
+ <attribute name="time"> <text /> </attribute>
+ <attribute name="user"> <text /> </attribute>
+ <attribute name="client"> <text /> </attribute>
+ <attribute name="origin"> <text /> </attribute>
+ </element>
+ </optional>
+ <optional>
+ <element name="nodes_configured">
+ <attribute name="number"> <data type="nonNegativeInteger" /> </attribute>
+ </element>
+ <element name="resources_configured">
+ <attribute name="number"> <data type="nonNegativeInteger" /> </attribute>
+ <attribute name="disabled"> <data type="nonNegativeInteger" /> </attribute>
+ <attribute name="blocked"> <data type="nonNegativeInteger" /> </attribute>
+ </element>
+ </optional>
+ <optional>
+ <element name="cluster_options">
+ <attribute name="stonith-enabled"> <data type="boolean" /> </attribute>
+ <attribute name="symmetric-cluster"> <data type="boolean" /> </attribute>
+ <attribute name="no-quorum-policy"> <text /> </attribute>
+ <attribute name="maintenance-mode"> <data type="boolean" /> </attribute>
+ <attribute name="stop-all-resources"> <data type="boolean" /> </attribute>
+ </element>
+ </optional>
+ </element>
+ </define>
+
+ <define name="resources-list">
+ <element name="resources">
+ <zeroOrMore>
+ <externalRef href="resources-2.4.rng" />
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <define name="nodes-list">
+ <element name="nodes">
+ <zeroOrMore>
+ <ref name="element-full-node" />
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <define name="node-attributes-list">
+ <element name="node_attributes">
+ <zeroOrMore>
+ <ref name="element-node-with-attributes" />
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <define name="node-history-list">
+ <element name="node_history">
+ <zeroOrMore>
+ <ref name="element-node-history" />
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <define name="failures-list">
+ <element name="failures">
+ <zeroOrMore>
+ <ref name="element-failure" />
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <define name="fence-event-list">
+ <element name="fence_history">
+ <optional>
+ <attribute name="status"> <data type="integer" /> </attribute>
+ </optional>
+ <zeroOrMore>
+ <externalRef href="fence-event-2.0.rng" />
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <define name="tickets-list">
+ <element name="tickets">
+ <zeroOrMore>
+ <ref name="element-ticket" />
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <define name="bans-list">
+ <element name="bans">
+ <zeroOrMore>
+ <ref name="element-ban" />
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <define name="element-full-node">
+ <element name="node">
+ <attribute name="name"> <text/> </attribute>
+ <attribute name="id"> <text/> </attribute>
+ <attribute name="online"> <data type="boolean" /> </attribute>
+ <attribute name="standby"> <data type="boolean" /> </attribute>
+ <attribute name="standby_onfail"> <data type="boolean" /> </attribute>
+ <attribute name="maintenance"> <data type="boolean" /> </attribute>
+ <attribute name="pending"> <data type="boolean" /> </attribute>
+ <attribute name="unclean"> <data type="boolean" /> </attribute>
+ <attribute name="shutdown"> <data type="boolean" /> </attribute>
+ <attribute name="expected_up"> <data type="boolean" /> </attribute>
+ <attribute name="is_dc"> <data type="boolean" /> </attribute>
+ <attribute name="resources_running"> <data type="nonNegativeInteger" /> </attribute>
+ <attribute name="type">
+ <choice>
+ <value>unknown</value>
+ <value>member</value>
+ <value>remote</value>
+ <value>ping</value>
+ </choice>
+ </attribute>
+ <optional>
+ <!-- for virtualized pacemaker_remote nodes, crm_mon 1.1.13 uses
+ "container_id" while later versions use "id_as_resource" -->
+ <choice>
+ <attribute name="container_id"> <text/> </attribute>
+ <attribute name="id_as_resource"> <text/> </attribute>
+ </choice>
+ </optional>
+ <externalRef href="resources-2.4.rng" />
+ </element>
+ </define>
+
+ <define name="element-node-with-attributes">
+ <element name="node">
+ <attribute name="name"> <text /> </attribute>
+ <zeroOrMore>
+ <element name="attribute">
+ <attribute name="name"> <text /> </attribute>
+ <attribute name="value"> <text /> </attribute>
+ <optional>
+ <attribute name="expected"> <data type="nonNegativeInteger" /> </attribute>
+ </optional>
+ </element>
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <define name="element-node-history">
+ <element name="node">
+ <attribute name="name"> <text /> </attribute>
+ <zeroOrMore>
+ <ref name="element-resource-history" />
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <define name="element-resource-history">
+ <element name="resource_history">
+ <attribute name="id"> <text /> </attribute>
+ <attribute name="orphan"> <data type="boolean" /> </attribute>
+ <optional>
+ <group>
+ <attribute name="migration-threshold"> <data type="nonNegativeInteger" /> </attribute>
+ <optional>
+ <attribute name="fail-count"> <text /> </attribute>
+ </optional>
+ <optional>
+ <attribute name="last-failure"> <text /> </attribute>
+ </optional>
+ </group>
+ </optional>
+ <zeroOrMore>
+ <ref name="element-operation-history" />
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <define name="element-operation-history">
+ <element name="operation_history">
+ <attribute name="call"> <text /> </attribute>
+ <attribute name="task"> <text /> </attribute>
+ <optional>
+ <attribute name="interval"> <text /> </attribute>
+ </optional>
+ <optional>
+ <attribute name="last-rc-change"> <text /> </attribute>
+ </optional>
+ <optional>
+ <attribute name="last-run"> <text /> </attribute>
+ </optional>
+ <optional>
+ <attribute name="exec-time"> <text /> </attribute>
+ </optional>
+ <optional>
+ <attribute name="queue-time"> <text /> </attribute>
+ </optional>
+ <attribute name="rc"> <data type="integer" /> </attribute>
+ <attribute name="rc_text"> <text /> </attribute>
+ </element>
+ </define>
+
+ <define name="element-failure">
+ <element name="failure">
+ <choice>
+ <attribute name="op_key"> <text/> </attribute>
+ <attribute name="id"> <text/> </attribute>
+ </choice>
+ <attribute name="node"> <text /> </attribute>
+ <attribute name="exitstatus"> <text /> </attribute>
+ <attribute name="exitreason"> <text /> </attribute>
+ <attribute name="exitcode"> <data type="nonNegativeInteger" /> </attribute>
+ <attribute name="call"> <data type="nonNegativeInteger" /> </attribute>
+ <attribute name="status"> <text /> </attribute>
+ <optional>
+ <group>
+ <attribute name="last-rc-change"> <text /> </attribute>
+ <attribute name="queued"> <data type="nonNegativeInteger" /> </attribute>
+ <attribute name="exec"> <data type="nonNegativeInteger" /> </attribute>
+ <attribute name="interval"> <data type="nonNegativeInteger" /> </attribute>
+ <attribute name="task"> <text /> </attribute>
+ </group>
+ </optional>
+ </element>
+ </define>
+
+ <define name="element-ticket">
+ <element name="ticket">
+ <attribute name="id"> <text /> </attribute>
+ <attribute name="status">
+ <choice>
+ <value>granted</value>
+ <value>revoked</value>
+ </choice>
+ </attribute>
+ <attribute name="standby"> <data type="boolean" /> </attribute>
+ <optional>
+ <attribute name="last-granted"> <text /> </attribute>
+ </optional>
+ </element>
+ </define>
+
+ <define name="element-ban">
+ <element name="ban">
+ <attribute name="id"> <text /> </attribute>
+ <attribute name="resource"> <text /> </attribute>
+ <attribute name="node"> <text /> </attribute>
+ <attribute name="weight"> <data type="integer" /> </attribute>
+ <attribute name="master_only"> <data type="boolean" /> </attribute>
+ </element>
+ </define>
+</grammar>
diff --git a/xml/api/resources-2.4.rng b/xml/api/resources-2.4.rng
new file mode 100644
index 0000000..e279583
--- /dev/null
+++ b/xml/api/resources-2.4.rng
@@ -0,0 +1,109 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<grammar xmlns="http://relaxng.org/ns/structure/1.0"
+ datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+
+ <start>
+ <ref name="element-resource-list"/>
+ </start>
+
+ <define name="element-resource-list">
+ <interleave>
+ <zeroOrMore>
+ <ref name="element-bundle" />
+ </zeroOrMore>
+ <zeroOrMore>
+ <ref name="element-clone" />
+ </zeroOrMore>
+ <zeroOrMore>
+ <ref name="element-group" />
+ </zeroOrMore>
+ <zeroOrMore>
+ <ref name="element-resource" />
+ </zeroOrMore>
+ </interleave>
+ </define>
+
+ <define name="element-bundle">
+ <element name="bundle">
+ <attribute name="id"> <text/> </attribute>
+ <attribute name="type">
+ <choice>
+ <value>docker</value>
+ <value>rkt</value>
+ <value>podman</value>
+ </choice>
+ </attribute>
+ <attribute name="image"> <text/> </attribute>
+ <attribute name="unique"> <data type="boolean" /> </attribute>
+ <attribute name="managed"> <data type="boolean" /> </attribute>
+ <attribute name="failed"> <data type="boolean" /> </attribute>
+ <zeroOrMore>
+ <element name="replica">
+ <attribute name="id"> <data type="nonNegativeInteger" /> </attribute>
+ <zeroOrMore>
+ <ref name="element-resource" />
+ </zeroOrMore>
+ </element>
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <define name="element-clone">
+ <element name="clone">
+ <attribute name="id"> <text/> </attribute>
+ <attribute name="multi_state"> <data type="boolean" /> </attribute>
+ <attribute name="unique"> <data type="boolean" /> </attribute>
+ <attribute name="managed"> <data type="boolean" /> </attribute>
+ <attribute name="disabled"> <data type="boolean" /> </attribute>
+ <attribute name="failed"> <data type="boolean" /> </attribute>
+ <attribute name="failure_ignored"> <data type="boolean" /> </attribute>
+ <optional>
+ <attribute name="target_role"> <text/> </attribute>
+ </optional>
+ <ref name="element-resource-list" />
+ </element>
+ </define>
+
+ <define name="element-group">
+ <element name="group">
+ <attribute name="id"> <text/> </attribute>
+ <attribute name="number_resources"> <data type="nonNegativeInteger" /> </attribute>
+ <attribute name="managed"> <data type="boolean" /> </attribute>
+ <attribute name="disabled"> <data type="boolean" /> </attribute>
+ <ref name="element-resource-list" />
+ </element>
+ </define>
+
+ <define name="element-resource">
+ <element name="resource">
+ <attribute name="id"> <text/> </attribute>
+ <attribute name="resource_agent"> <text/> </attribute>
+ <attribute name="role"> <text/> </attribute>
+ <optional>
+ <attribute name="target_role"> <text/> </attribute>
+ </optional>
+ <attribute name="active"> <data type="boolean" /> </attribute>
+ <attribute name="orphaned"> <data type="boolean" /> </attribute>
+ <optional>
+ <attribute name="blocked"> <data type="boolean" /> </attribute>
+ </optional>
+ <attribute name="managed"> <data type="boolean" /> </attribute>
+ <attribute name="failed"> <data type="boolean" /> </attribute>
+ <attribute name="failure_ignored"> <data type="boolean" /> </attribute>
+ <attribute name="nodes_running_on"> <data type="nonNegativeInteger" /> </attribute>
+ <optional>
+ <attribute name="pending"> <text/> </attribute>
+ </optional>
+ <zeroOrMore>
+ <element name="node">
+ <attribute name="name"> <text/> </attribute>
+ <attribute name="id"> <text/> </attribute>
+ <attribute name="cached"> <data type="boolean" /> </attribute>
+ </element>
+ </zeroOrMore>
+ <optional>
+ <element name="xml"> <text/> </element>
+ </optional>
+ </element>
+ </define>
+</grammar>
--
1.8.3.1
From 814eb921cd429692220f33722c9bc061266bd838 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Thu, 29 Oct 2020 14:45:02 -0400
Subject: [PATCH 3/6] Feature: xml: Add a generic list XML schema file.
Formatted output supports a generic list structure that isn't used in
too many places at the moment, but it could be getting used more in the
future. It's also really easy to have a schema for this piece of XML.
---
xml/Makefile.am | 7 ++++++-
xml/api/generic-list-2.4.rng | 21 +++++++++++++++++++++
2 files changed, 27 insertions(+), 1 deletion(-)
create mode 100644 xml/api/generic-list-2.4.rng
diff --git a/xml/Makefile.am b/xml/Makefile.am
index 79ce900..2f99f1c 100644
--- a/xml/Makefile.am
+++ b/xml/Makefile.am
@@ -44,6 +44,11 @@ version_pairs_last = $(wordlist \
),$(1),$(2) \
)
+# NOTE: All files in API_request_base, CIB_cfg_base, API_base, and CIB_base
+# need to start with a unique prefix. These variables all get iterated over
+# and globbed, and two files starting with the same prefix will cause
+# problems.
+
# Names of API schemas that form the choices for pacemaker-result content
API_request_base = command-output crm_mon crmadmin stonith_admin version
@@ -51,7 +56,7 @@ API_request_base = command-output crm_mon crmadmin stonith_admin version
CIB_cfg_base = options nodes resources constraints fencing acls tags alerts
# Names of all schemas (including top level and those included by others)
-API_base = $(API_request_base) fence-event item resources status
+API_base = $(API_request_base) fence-event generic-list item resources status
CIB_base = cib $(CIB_cfg_base) status score rule nvset
# Static schema files and transforms (only CIB has transforms)
diff --git a/xml/api/generic-list-2.4.rng b/xml/api/generic-list-2.4.rng
new file mode 100644
index 0000000..fee93a9
--- /dev/null
+++ b/xml/api/generic-list-2.4.rng
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<grammar xmlns="http://relaxng.org/ns/structure/1.0"
+ datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+
+ <start>
+ <ref name="generic-list"/>
+ </start>
+
+ <define name="generic-list">
+ <element name="list">
+ <attribute name="name"> <text /> </attribute>
+ <attribute name="count"> <data type="nonNegativeInteger" /> </attribute>
+ <choice>
+ <empty/>
+ <oneOrMore>
+ <externalRef href="item-1.1.rng"/>
+ </oneOrMore>
+ </choice>
+ </element>
+ </define>
+</grammar>
--
1.8.3.1
From 316b6f66ca5425093503c51c2f8738922287ebca Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Wed, 16 Sep 2020 15:59:34 -0400
Subject: [PATCH 4/6] Fix: tools: Save the optarg parameter for
--list-ocf-alternatives.
We need this so it can be added to the XML output of crm_resource.
---
tools/crm_resource.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/tools/crm_resource.c b/tools/crm_resource.c
index 6573ad5..acaddc0 100644
--- a/tools/crm_resource.c
+++ b/tools/crm_resource.c
@@ -720,9 +720,7 @@ list_alternatives_cb(const gchar *option_name, const gchar *optarg,
gpointer data, GError **error)
{
SET_COMMAND(cmd_list_alternatives);
- options.require_cib = FALSE;
- options.require_dataset = FALSE;
- options.require_resource = FALSE;
+ get_agent_spec(optarg);
return TRUE;
}
--
1.8.3.1
From c063ce9b193f2022611e651c13afcb3ceb5969e3 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Wed, 2 Sep 2020 16:20:10 -0400
Subject: [PATCH 5/6] Fix: scheduler: Use the default format handler in a few
more places.
---
lib/pengine/pe_output.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/lib/pengine/pe_output.c b/lib/pengine/pe_output.c
index d0f96f4..9d43e5f 100644
--- a/lib/pengine/pe_output.c
+++ b/lib/pengine/pe_output.c
@@ -1847,9 +1847,7 @@ static pcmk__message_entry_t fmt_functions[] = {
{ "cluster-times", "log", pe__cluster_times_text },
{ "cluster-times", "text", pe__cluster_times_text },
{ "cluster-times", "xml", pe__cluster_times_xml },
- { "failed-action", "html", pe__failed_action_text },
- { "failed-action", "log", pe__failed_action_text },
- { "failed-action", "text", pe__failed_action_text },
+ { "failed-action", "default", pe__failed_action_text },
{ "failed-action", "xml", pe__failed_action_xml },
{ "group", "xml", pe__group_xml },
{ "group", "html", pe__group_html },
@@ -1868,9 +1866,7 @@ static pcmk__message_entry_t fmt_functions[] = {
{ "node-attribute", "log", pe__node_attribute_text },
{ "node-attribute", "text", pe__node_attribute_text },
{ "node-attribute", "xml", pe__node_attribute_xml },
- { "op-history", "html", pe__op_history_text },
- { "op-history", "log", pe__op_history_text },
- { "op-history", "text", pe__op_history_text },
+ { "op-history", "default", pe__op_history_text },
{ "op-history", "xml", pe__op_history_xml },
{ "primitive", "xml", pe__resource_xml },
{ "primitive", "html", pe__resource_html },
--
1.8.3.1
From a32b99f5fd09ec15dbba6785c5d8dc2e220417a3 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Thu, 3 Sep 2020 10:23:16 -0400
Subject: [PATCH 6/6] Refactor: scheduler: Expose native_output_string as
pcmk__native_output_string.
The plan is that this function can be used to help build the string that
is output for each line of "crm_resource -o" output. It appears that
output only happens for primitive resources. However, I've added a
check at the beginning just in case it's called for some other type of
resource.
---
include/crm/pengine/internal.h | 3 +++
lib/pengine/native.c | 24 ++++++++++++++----------
2 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/include/crm/pengine/internal.h b/include/crm/pengine/internal.h
index abe7a76..d658e86 100644
--- a/include/crm/pengine/internal.h
+++ b/include/crm/pengine/internal.h
@@ -243,6 +243,9 @@ void clone_print(pe_resource_t * rsc, const char *pre_text, long options, void *
void pe__print_bundle(pe_resource_t *rsc, const char *pre_text, long options,
void *print_data);
+gchar * pcmk__native_output_string(pe_resource_t *rsc, const char *name, pe_node_t *node,
+ long options, const char *target_role, bool show_nodes);
+
int pe__name_and_nvpairs_xml(pcmk__output_t *out, bool is_list, const char *tag_name
, size_t pairs_count, ...);
char *pe__node_display_name(pe_node_t *node, bool print_detail);
diff --git a/lib/pengine/native.c b/lib/pengine/native.c
index 8f0c5c9..bf1f5c0 100644
--- a/lib/pengine/native.c
+++ b/lib/pengine/native.c
@@ -570,17 +570,21 @@ add_output_node(GString *s, const char *node, bool have_nodes)
* \return Newly allocated string description of resource
* \note Caller must free the result with g_free().
*/
-static gchar *
-native_output_string(pe_resource_t *rsc, const char *name, pe_node_t *node,
- long options, const char *target_role, bool show_nodes)
+gchar *
+pcmk__native_output_string(pe_resource_t *rsc, const char *name, pe_node_t *node,
+ long options, const char *target_role, bool show_nodes)
{
const char *class = crm_element_value(rsc->xml, XML_AGENT_ATTR_CLASS);
const char *provider = NULL;
const char *kind = crm_element_value(rsc->xml, XML_ATTR_TYPE);
- char *retval = NULL;
+ gchar *retval = NULL;
GString *outstr = NULL;
bool have_flags = false;
+ if (rsc->variant != pe_native) {
+ return NULL;
+ }
+
CRM_CHECK(name != NULL, name = "unknown");
CRM_CHECK(kind != NULL, kind = "unknown");
CRM_CHECK(class != NULL, class = "unknown");
@@ -758,8 +762,8 @@ pe__common_output_html(pcmk__output_t *out, pe_resource_t * rsc,
}
{
- gchar *s = native_output_string(rsc, name, node, options, target_role,
- true);
+ gchar *s = pcmk__native_output_string(rsc, name, node, options,
+ target_role, true);
list_node = pcmk__output_create_html_node(out, "li", NULL, NULL, NULL);
pcmk_create_html_node(list_node, "span", NULL, cl, s);
@@ -826,8 +830,8 @@ pe__common_output_text(pcmk__output_t *out, pe_resource_t * rsc,
}
{
- gchar *s = native_output_string(rsc, name, node, options, target_role,
- true);
+ gchar *s = pcmk__native_output_string(rsc, name, node, options,
+ target_role, true);
out->list_item(out, NULL, "%s", s);
g_free(s);
@@ -923,8 +927,8 @@ common_print(pe_resource_t * rsc, const char *pre_text, const char *name, pe_nod
}
{
- gchar *resource_s = native_output_string(rsc, name, node, options,
- target_role, false);
+ gchar *resource_s = pcmk__native_output_string(rsc, name, node, options,
+ target_role, false);
status_print("%s%s", (pre_text? pre_text : ""), resource_s);
g_free(resource_s);
}
--
1.8.3.1

File diff suppressed because it is too large Load Diff

View File

@ -1,210 +0,0 @@
From 477b7b679d58455dc38c2594b29a1ecfbe88e80c Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Mon, 2 Nov 2020 14:55:27 -0500
Subject: [PATCH 1/2] Fix: libcrmcommon: Prevent a segfault in
pcmk__cmdline_preproc.
The list of special single-character args is optional. The function
currently handles it being an empty string, but it should handle a NULL
as well.
---
lib/common/cmdline.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/common/cmdline.c b/lib/common/cmdline.c
index d66ccc7..66f1976 100644
--- a/lib/common/cmdline.c
+++ b/lib/common/cmdline.c
@@ -203,7 +203,7 @@ pcmk__cmdline_preproc(char **argv, const char *special) {
* glib does not. Grab both the argument and its value and
* separate them into a new argument.
*/
- if (strchr(special, *ch) != NULL) {
+ if (special != NULL && strchr(special, *ch) != NULL) {
/* The argument does not occur at the end of this string of
* arguments. Take everything through the end as its value.
*/
--
1.8.3.1
From d1f4a975fa783045254521f415f1899b34ee96e3 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Mon, 2 Nov 2020 16:06:29 -0500
Subject: [PATCH 2/2] Test: libcrmcommon: Add unit tests for
pcmk__cmdline_preproc.
---
configure.ac | 1 +
lib/common/tests/Makefile.am | 2 +-
lib/common/tests/cmdline/Makefile.am | 29 ++++++
.../tests/cmdline/pcmk__cmdline_preproc_test.c | 102 +++++++++++++++++++++
4 files changed, 133 insertions(+), 1 deletion(-)
create mode 100644 lib/common/tests/cmdline/Makefile.am
create mode 100644 lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c
diff --git a/configure.ac b/configure.ac
index 7ed4a30..36e85a9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2006,6 +2006,7 @@ AC_CONFIG_FILES(Makefile \
lib/pacemaker-cluster.pc \
lib/common/Makefile \
lib/common/tests/Makefile \
+ lib/common/tests/cmdline/Makefile \
lib/common/tests/flags/Makefile \
lib/common/tests/operations/Makefile \
lib/common/tests/strings/Makefile \
diff --git a/lib/common/tests/Makefile.am b/lib/common/tests/Makefile.am
index 33c45cb..f3eaeec 100644
--- a/lib/common/tests/Makefile.am
+++ b/lib/common/tests/Makefile.am
@@ -1 +1 @@
-SUBDIRS = flags operations strings utils
+SUBDIRS = cmdline flags operations strings utils
diff --git a/lib/common/tests/cmdline/Makefile.am b/lib/common/tests/cmdline/Makefile.am
new file mode 100644
index 0000000..e69ef21
--- /dev/null
+++ b/lib/common/tests/cmdline/Makefile.am
@@ -0,0 +1,29 @@
+#
+# Copyright 2020 the Pacemaker project contributors
+#
+# The version control history for this file may have further details.
+#
+# This source code is licensed under the GNU General Public License version 2
+# or later (GPLv2+) WITHOUT ANY WARRANTY.
+#
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
+LDADD = $(top_builddir)/lib/common/libcrmcommon.la
+
+include $(top_srcdir)/mk/glib-tap.mk
+
+# Add each test program here. Each test should be written as a little standalone
+# program using the glib unit testing functions. See the documentation for more
+# information.
+#
+# https://developer.gnome.org/glib/unstable/glib-Testing.html
+#
+# Add "_test" to the end of all test program names to simplify .gitignore.
+test_programs = pcmk__cmdline_preproc_test
+
+# If any extra data needs to be added to the source distribution, add it to the
+# following list.
+dist_test_data =
+
+# If any extra data needs to be used by tests but should not be added to the
+# source distribution, add it to the following list.
+test_data =
diff --git a/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c b/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c
new file mode 100644
index 0000000..e13c983
--- /dev/null
+++ b/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2020 the Pacemaker project contributors
+ *
+ * The version control history for this file may have further details.
+ *
+ * This source code is licensed under the GNU Lesser General Public License
+ * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
+ */
+
+#include <crm_internal.h>
+#include <crm/common/cmdline_internal.h>
+
+#define LISTS_EQ(a, b) { \
+ g_assert_cmpint(g_strv_length((gchar **) (a)), ==, g_strv_length((gchar **) (b))); \
+ for (int i = 0; i < g_strv_length((a)); i++) { \
+ g_assert_cmpstr((a)[i], ==, (b)[i]); \
+ } \
+}
+
+static void
+empty_input(void) {
+ g_assert_cmpint(pcmk__cmdline_preproc(NULL, "") == NULL, ==, TRUE);
+}
+
+static void
+no_specials(void) {
+ const char *argv[] = { "-a", "-b", "-c", "-d", NULL };
+ const gchar *expected[] = { "-a", "-b", "-c", "-d", NULL };
+
+ gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL);
+ LISTS_EQ(processed, expected);
+ g_strfreev(processed);
+
+ processed = pcmk__cmdline_preproc((char **) argv, "");
+ LISTS_EQ(processed, expected);
+ g_strfreev(processed);
+}
+
+static void
+single_dash(void) {
+ const char *argv[] = { "-", NULL };
+ const gchar *expected[] = { "-", NULL };
+
+ gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL);
+ LISTS_EQ(processed, expected);
+ g_strfreev(processed);
+}
+
+static void
+double_dash(void) {
+ const char *argv[] = { "-a", "--", "-bc", NULL };
+ const gchar *expected[] = { "-a", "--", "-bc", NULL };
+
+ gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL);
+ LISTS_EQ(processed, expected);
+ g_strfreev(processed);
+}
+
+static void
+special_args(void) {
+ const char *argv[] = { "-aX", "-Fval", NULL };
+ const gchar *expected[] = { "-a", "X", "-F", "val", NULL };
+
+ gchar **processed = pcmk__cmdline_preproc((char **) argv, "aF");
+ LISTS_EQ(processed, expected);
+ g_strfreev(processed);
+}
+
+static void
+special_arg_at_end(void) {
+ const char *argv[] = { "-a", NULL };
+ const gchar *expected[] = { "-a", NULL };
+
+ gchar **processed = pcmk__cmdline_preproc((char **) argv, "a");
+ LISTS_EQ(processed, expected);
+ g_strfreev(processed);
+}
+
+static void
+long_arg(void) {
+ const char *argv[] = { "--blah=foo", NULL };
+ const gchar *expected[] = { "--blah=foo", NULL };
+
+ gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL);
+ LISTS_EQ(processed, expected);
+ g_strfreev(processed);
+}
+
+int
+main(int argc, char **argv)
+{
+ g_test_init(&argc, &argv, NULL);
+
+ g_test_add_func("/common/cmdline/preproc/empty_input", empty_input);
+ g_test_add_func("/common/cmdline/preproc/no_specials", no_specials);
+ g_test_add_func("/common/cmdline/preproc/single_dash", single_dash);
+ g_test_add_func("/common/cmdline/preproc/double_dash", double_dash);
+ g_test_add_func("/common/cmdline/preproc/special_args", special_args);
+ g_test_add_func("/common/cmdline/preproc/special_arg_at_end", special_arg_at_end);
+ g_test_add_func("/common/cmdline/preproc/long_arg", long_arg);
+ return g_test_run();
+}
--
1.8.3.1

View File

@ -0,0 +1,276 @@
From d50bbafc32428e873c0052a9defcf93d2e52667e Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Wed, 10 Jan 2024 11:35:11 -0500
Subject: [PATCH 1/3] Refactor: libcrmcommon: Split feature set check into its
own function.
---
include/crm/common/cib_internal.h | 4 +++-
lib/cib/cib_utils.c | 12 ++++++------
lib/common/cib.c | 18 +++++++++++++++++-
3 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/include/crm/common/cib_internal.h b/include/crm/common/cib_internal.h
index c41c12e..fa65e58 100644
--- a/include/crm/common/cib_internal.h
+++ b/include/crm/common/cib_internal.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2023 the Pacemaker project contributors
+ * Copyright 2023-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -16,6 +16,8 @@ extern "C" {
const char *pcmk__cib_abs_xpath_for(const char *element);
+int pcmk__check_feature_set(const char *cib_version);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/cib/cib_utils.c b/lib/cib/cib_utils.c
index 0082eef..bf2982c 100644
--- a/lib/cib/cib_utils.c
+++ b/lib/cib/cib_utils.c
@@ -353,7 +353,6 @@ cib_perform_op(const char *op, int call_options, cib__op_fn_t fn, bool is_query,
xmlNode *patchset_cib = NULL;
xmlNode *local_diff = NULL;
- const char *new_version = NULL;
const char *user = crm_element_value(req, F_CIB_USER);
bool with_digest = false;
@@ -470,12 +469,13 @@ cib_perform_op(const char *op, int call_options, cib__op_fn_t fn, bool is_query,
}
if (scratch) {
- new_version = crm_element_value(scratch, XML_ATTR_CRM_VERSION);
+ const char *new_version = crm_element_value(scratch, XML_ATTR_CRM_VERSION);
- if (new_version && compare_version(new_version, CRM_FEATURE_SET) > 0) {
- crm_err("Discarding update with feature set '%s' greater than our own '%s'",
- new_version, CRM_FEATURE_SET);
- rc = -EPROTONOSUPPORT;
+ rc = pcmk__check_feature_set(new_version);
+ if (rc != pcmk_rc_ok) {
+ pcmk__config_err("Discarding update with feature set '%s' greater than our own '%s'",
+ new_version, CRM_FEATURE_SET);
+ rc = pcmk_rc2legacy(rc);
goto done;
}
}
diff --git a/lib/common/cib.c b/lib/common/cib.c
index fee7881..cbebc2e 100644
--- a/lib/common/cib.c
+++ b/lib/common/cib.c
@@ -1,6 +1,6 @@
/*
* Original copyright 2004 International Business Machines
- * Later changes copyright 2008-2023 the Pacemaker project contributors
+ * Later changes copyright 2008-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -173,3 +173,19 @@ pcmk_find_cib_element(xmlNode *cib, const char *element_name)
{
return get_xpath_object(pcmk_cib_xpath_for(element_name), cib, LOG_TRACE);
}
+
+/*!
+ * \internal
+ * \brief Check that the feature set in the CIB is supported on this node
+ *
+ * \param[in] new_version XML_ATTR_CRM_VERSION attribute from the CIB
+ */
+int
+pcmk__check_feature_set(const char *cib_version)
+{
+ if (cib_version && compare_version(cib_version, CRM_FEATURE_SET) > 0) {
+ return EPROTONOSUPPORT;
+ }
+
+ return pcmk_rc_ok;
+}
--
2.31.1
From d89fd8336ae47d892201513c99773705d57f15f0 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Wed, 10 Jan 2024 13:46:42 -0500
Subject: [PATCH 2/3] Feature: scheduler: Check the CIB feature set in
cluster_status.
This adds the check that was previously only in cib_perform_op to the
scheduler code, ensuring that any daemon or tool that calls the
scheduler will check that the feature set in the CIB is supported.
---
lib/pengine/status.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/lib/pengine/status.c b/lib/pengine/status.c
index e6ec237..1294803 100644
--- a/lib/pengine/status.c
+++ b/lib/pengine/status.c
@@ -14,6 +14,7 @@
#include <crm/crm.h>
#include <crm/msg_xml.h>
#include <crm/common/xml.h>
+#include <crm/common/cib_internal.h>
#include <glib.h>
@@ -70,12 +71,21 @@ pe_free_working_set(pcmk_scheduler_t *scheduler)
gboolean
cluster_status(pcmk_scheduler_t * scheduler)
{
+ const char *new_version = NULL;
xmlNode *section = NULL;
if ((scheduler == NULL) || (scheduler->input == NULL)) {
return FALSE;
}
+ new_version = crm_element_value(scheduler->input, XML_ATTR_CRM_VERSION);
+
+ if (pcmk__check_feature_set(new_version) != pcmk_rc_ok) {
+ pcmk__config_err("Can't process CIB with feature set '%s' greater than our own '%s'",
+ new_version, CRM_FEATURE_SET);
+ return FALSE;
+ }
+
crm_trace("Beginning unpack");
if (scheduler->failed != NULL) {
--
2.31.1
From a3428926d37af506014a6b462d1308d8541c5932 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Wed, 10 Jan 2024 14:56:36 -0500
Subject: [PATCH 3/3] Low: libcib: Do not check CIB feature set for files in
cib_perform_op.
This is related to the previous feature for transferring schema files to
older remote nodes. In that case, the newer schema files may also have
a newer feature set than the node supports, so the transferred files are
still not usable.
However, the feature set only matters for the scheduler, not for most
command line tools (obviously, crm_simulate would still care). So in
those cases, we can just disable the feature set check if the CIB was
read in from a file. For the scheduler, the check is still performed as
part of cluster_status.
---
cts/cli/regression.tools.exp | 2 +-
daemons/based/based_callbacks.c | 4 ++--
include/crm/cib/internal.h | 4 ++--
lib/cib/cib_file.c | 2 +-
lib/cib/cib_utils.c | 15 +++++++++------
5 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/cts/cli/regression.tools.exp b/cts/cli/regression.tools.exp
index 417b5cd..c81c420 100644
--- a/cts/cli/regression.tools.exp
+++ b/cts/cli/regression.tools.exp
@@ -7939,7 +7939,7 @@ unpack_config warning: Blind faith: not fencing unseen nodes
=#=#=#= End test: Verbosely verify a file-specified invalid configuration, outputting as xml - Invalid configuration (78) =#=#=#=
* Passed: crm_verify - Verbosely verify a file-specified invalid configuration, outputting as xml
=#=#=#= Begin test: Verbosely verify another file-specified invalid configuration, outputting as xml =#=#=#=
-(cluster_status@status.c:113) warning: Fencing and resource management disabled due to lack of quorum
+(cluster_status@status.c:123) warning: Fencing and resource management disabled due to lack of quorum
<pacemaker-result api-version="X" request="crm_verify_invalid_no_stonith.xml --output-as=xml --verbose">
<status code="78" message="Invalid configuration">
<errors>
diff --git a/daemons/based/based_callbacks.c b/daemons/based/based_callbacks.c
index 5f3dc62..f16e4d9 100644
--- a/daemons/based/based_callbacks.c
+++ b/daemons/based/based_callbacks.c
@@ -1362,7 +1362,7 @@ cib_process_command(xmlNode *request, const cib__operation_t *operation,
input = prepare_input(request, operation->type, &section);
if (!pcmk_is_set(operation->flags, cib__op_attr_modifies)) {
- rc = cib_perform_op(op, call_options, op_function, true, section,
+ rc = cib_perform_op(NULL, op, call_options, op_function, true, section,
request, input, false, &config_changed, &the_cib,
&result_cib, NULL, &output);
@@ -1395,7 +1395,7 @@ cib_process_command(xmlNode *request, const cib__operation_t *operation,
}
// result_cib must not be modified after cib_perform_op() returns
- rc = cib_perform_op(op, call_options, op_function, false, section,
+ rc = cib_perform_op(NULL, op, call_options, op_function, false, section,
request, input, manage_counters, &config_changed,
&the_cib, &result_cib, cib_diff, &output);
diff --git a/include/crm/cib/internal.h b/include/crm/cib/internal.h
index 9d54d52..b6d6871 100644
--- a/include/crm/cib/internal.h
+++ b/include/crm/cib/internal.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2004-2023 the Pacemaker project contributors
+ * Copyright 2004-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -206,7 +206,7 @@ int cib__get_notify_patchset(const xmlNode *msg, const xmlNode **patchset);
bool cib__element_in_patchset(const xmlNode *patchset, const char *element);
-int cib_perform_op(const char *op, int call_options, cib__op_fn_t fn,
+int cib_perform_op(cib_t *cib, const char *op, int call_options, cib__op_fn_t fn,
bool is_query, const char *section, xmlNode *req,
xmlNode *input, bool manage_counters, bool *config_changed,
xmlNode **current_cib, xmlNode **result_cib, xmlNode **diff,
diff --git a/lib/cib/cib_file.c b/lib/cib/cib_file.c
index a279823..9dd952c 100644
--- a/lib/cib/cib_file.c
+++ b/lib/cib/cib_file.c
@@ -245,7 +245,7 @@ cib_file_process_request(cib_t *cib, xmlNode *request, xmlNode **output)
data = pcmk_find_cib_element(data, section);
}
- rc = cib_perform_op(op, call_options, op_function, read_only, section,
+ rc = cib_perform_op(cib, op, call_options, op_function, read_only, section,
request, data, true, &changed, &private->cib_xml,
&result_cib, &cib_diff, output);
diff --git a/lib/cib/cib_utils.c b/lib/cib/cib_utils.c
index bf2982c..9c3f9f1 100644
--- a/lib/cib/cib_utils.c
+++ b/lib/cib/cib_utils.c
@@ -339,11 +339,10 @@ should_copy_cib(const char *op, const char *section, int call_options)
}
int
-cib_perform_op(const char *op, int call_options, cib__op_fn_t fn, bool is_query,
- const char *section, xmlNode *req, xmlNode *input,
- bool manage_counters, bool *config_changed,
- xmlNode **current_cib, xmlNode **result_cib, xmlNode **diff,
- xmlNode **output)
+cib_perform_op(cib_t *cib, const char *op, int call_options, cib__op_fn_t fn,
+ bool is_query, const char *section, xmlNode *req, xmlNode *input,
+ bool manage_counters, bool *config_changed, xmlNode **current_cib,
+ xmlNode **result_cib, xmlNode **diff, xmlNode **output)
{
int rc = pcmk_ok;
bool check_schema = true;
@@ -468,7 +467,11 @@ cib_perform_op(const char *op, int call_options, cib__op_fn_t fn, bool is_query,
goto done;
}
- if (scratch) {
+ /* If the CIB is from a file, we don't need to check that the feature set is
+ * supported. All we care about in that case is the schema version, which
+ * is checked elsewhere.
+ */
+ if (scratch && (cib == NULL || cib->variant != cib_file)) {
const char *new_version = crm_element_value(scratch, XML_ATTR_CRM_VERSION);
rc = pcmk__check_feature_set(new_version);
--
2.31.1

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,373 @@
From 4823643bef8801b33688167b159bb531bcdf8911 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Thu, 4 Jan 2024 17:10:08 -0600
Subject: [PATCH 1/5] Refactor: pacemaker-attrd: drop redundant argument from
update_attr_on_host()
It can check for a force-write via its xml argument, to simplify the caller
---
daemons/attrd/attrd_corosync.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/daemons/attrd/attrd_corosync.c b/daemons/attrd/attrd_corosync.c
index 158d82f..1b56923 100644
--- a/daemons/attrd/attrd_corosync.c
+++ b/daemons/attrd/attrd_corosync.c
@@ -266,7 +266,7 @@ record_peer_nodeid(attribute_value_t *v, const char *host)
static void
update_attr_on_host(attribute_t *a, const crm_node_t *peer, const xmlNode *xml,
const char *attr, const char *value, const char *host,
- bool filter, int is_force_write)
+ bool filter)
{
attribute_value_t *v = NULL;
@@ -309,6 +309,10 @@ update_attr_on_host(attribute_t *a, const crm_node_t *peer, const xmlNode *xml,
}
} else {
+ int is_force_write = 0;
+
+ crm_element_value_int(xml, PCMK__XA_ATTR_FORCE, &is_force_write);
+
if (is_force_write == 1 && a->timeout_ms && a->timer) {
/* Save forced writing and set change flag. */
/* The actual attribute is written by Writer after election. */
@@ -338,15 +342,12 @@ attrd_peer_update_one(const crm_node_t *peer, xmlNode *xml, bool filter)
const char *attr = crm_element_value(xml, PCMK__XA_ATTR_NAME);
const char *value = crm_element_value(xml, PCMK__XA_ATTR_VALUE);
const char *host = crm_element_value(xml, PCMK__XA_ATTR_NODE_NAME);
- int is_force_write = 0;
if (attr == NULL) {
crm_warn("Could not update attribute: peer did not specify name");
return;
}
- crm_element_value_int(xml, PCMK__XA_ATTR_FORCE, &is_force_write);
-
a = attrd_populate_attribute(xml, attr);
if (a == NULL) {
return;
@@ -361,12 +362,12 @@ attrd_peer_update_one(const crm_node_t *peer, xmlNode *xml, bool filter)
g_hash_table_iter_init(&vIter, a->values);
while (g_hash_table_iter_next(&vIter, (gpointer *) & host, NULL)) {
- update_attr_on_host(a, peer, xml, attr, value, host, filter, is_force_write);
+ update_attr_on_host(a, peer, xml, attr, value, host, filter);
}
} else {
// Update attribute value for the given host
- update_attr_on_host(a, peer, xml, attr, value, host, filter, is_force_write);
+ update_attr_on_host(a, peer, xml, attr, value, host, filter);
}
/* If this is a message from some attrd instance broadcasting its protocol
--
2.31.1
From c7a1ab819b25e3225c185c1630a7139a96fb5c71 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Tue, 9 Jan 2024 16:48:37 -0600
Subject: [PATCH 2/5] Refactor: pacemaker-attrd: drop unused argument from
attrd_peer_sync()
---
daemons/attrd/attrd_corosync.c | 10 ++++++++--
daemons/attrd/attrd_elections.c | 2 +-
daemons/attrd/attrd_messages.c | 2 +-
daemons/attrd/pacemaker-attrd.h | 2 +-
4 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/daemons/attrd/attrd_corosync.c b/daemons/attrd/attrd_corosync.c
index 1b56923..088f00c 100644
--- a/daemons/attrd/attrd_corosync.c
+++ b/daemons/attrd/attrd_corosync.c
@@ -233,7 +233,7 @@ attrd_peer_change_cb(enum crm_status_type kind, crm_node_t *peer, const void *da
*/
if (attrd_election_won()
&& !pcmk_is_set(peer->flags, crm_remote_node)) {
- attrd_peer_sync(peer, NULL);
+ attrd_peer_sync(peer);
}
} else {
// Remove all attribute values associated with lost nodes
@@ -535,8 +535,14 @@ attrd_peer_remove(const char *host, bool uncache, const char *source)
}
}
+/*!
+ * \internal
+ * \brief Send all known attributes and values to a peer
+ *
+ * \param[in] peer Peer to send sync to (if NULL, broadcast to all peers)
+ */
void
-attrd_peer_sync(crm_node_t *peer, xmlNode *xml)
+attrd_peer_sync(crm_node_t *peer)
{
GHashTableIter aIter;
GHashTableIter vIter;
diff --git a/daemons/attrd/attrd_elections.c b/daemons/attrd/attrd_elections.c
index 82fbe8a..9dbf133 100644
--- a/daemons/attrd/attrd_elections.c
+++ b/daemons/attrd/attrd_elections.c
@@ -23,7 +23,7 @@ attrd_election_cb(gpointer user_data)
attrd_declare_winner();
/* Update the peers after an election */
- attrd_peer_sync(NULL, NULL);
+ attrd_peer_sync(NULL);
/* After winning an election, update the CIB with the values of all
* attributes as the winner knows them.
diff --git a/daemons/attrd/attrd_messages.c b/daemons/attrd/attrd_messages.c
index 5525d4b..13ac01f 100644
--- a/daemons/attrd/attrd_messages.c
+++ b/daemons/attrd/attrd_messages.c
@@ -180,7 +180,7 @@ handle_sync_request(pcmk__request_t *request)
crm_node_t *peer = pcmk__get_node(0, request->peer, NULL,
pcmk__node_search_cluster);
- attrd_peer_sync(peer, request->xml);
+ attrd_peer_sync(peer);
pcmk__set_result(&request->result, CRM_EX_OK, PCMK_EXEC_DONE, NULL);
return NULL;
} else {
diff --git a/daemons/attrd/pacemaker-attrd.h b/daemons/attrd/pacemaker-attrd.h
index 7384188..bacaad6 100644
--- a/daemons/attrd/pacemaker-attrd.h
+++ b/daemons/attrd/pacemaker-attrd.h
@@ -175,7 +175,7 @@ extern GHashTable *peer_protocol_vers;
int attrd_cluster_connect(void);
void attrd_peer_update(const crm_node_t *peer, xmlNode *xml, const char *host,
bool filter);
-void attrd_peer_sync(crm_node_t *peer, xmlNode *xml);
+void attrd_peer_sync(crm_node_t *peer);
void attrd_peer_remove(const char *host, bool uncache, const char *source);
void attrd_peer_clear_failure(pcmk__request_t *request);
void attrd_peer_sync_response(const crm_node_t *peer, bool peer_won,
--
2.31.1
From abafae0068e10abb135b0496086947728365299a Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Thu, 11 Jan 2024 17:31:17 -0600
Subject: [PATCH 3/5] Refactor: pacemaker-attrd: de-functionize
attrd_lookup_or_create_value()
... to make planned changes easier
---
daemons/attrd/attrd_corosync.c | 62 +++++++++++++---------------------
1 file changed, 24 insertions(+), 38 deletions(-)
diff --git a/daemons/attrd/attrd_corosync.c b/daemons/attrd/attrd_corosync.c
index 088f00c..59e6a26 100644
--- a/daemons/attrd/attrd_corosync.c
+++ b/daemons/attrd/attrd_corosync.c
@@ -168,40 +168,6 @@ broadcast_local_value(const attribute_t *a)
#define state_text(state) pcmk__s((state), "in unknown state")
-/*!
- * \internal
- * \brief Return a node's value from hash table (creating one if needed)
- *
- * \param[in,out] values Hash table of values
- * \param[in] node_name Name of node to look up
- * \param[in] xml XML describing the attribute
- *
- * \return Pointer to new or existing hash table entry
- */
-static attribute_value_t *
-attrd_lookup_or_create_value(GHashTable *values, const char *node_name,
- const xmlNode *xml)
-{
- attribute_value_t *v = g_hash_table_lookup(values, node_name);
- int is_remote = 0;
-
- if (v == NULL) {
- v = calloc(1, sizeof(attribute_value_t));
- CRM_ASSERT(v != NULL);
-
- pcmk__str_update(&v->nodename, node_name);
- g_hash_table_replace(values, v->nodename, v);
- }
-
- crm_element_value_int(xml, PCMK__XA_ATTR_IS_REMOTE, &is_remote);
- if (is_remote) {
- attrd_set_value_flags(v, attrd_value_remote);
- CRM_ASSERT(crm_remote_peer_get(node_name) != NULL);
- }
-
- return(v);
-}
-
static void
attrd_peer_change_cb(enum crm_status_type kind, crm_node_t *peer, const void *data)
{
@@ -268,18 +234,38 @@ update_attr_on_host(attribute_t *a, const crm_node_t *peer, const xmlNode *xml,
const char *attr, const char *value, const char *host,
bool filter)
{
+ int is_remote = 0;
+ bool changed = false;
attribute_value_t *v = NULL;
- v = attrd_lookup_or_create_value(a->values, host, xml);
+ // Create entry for value if not already existing
+ v = g_hash_table_lookup(a->values, host);
+ if (v == NULL) {
+ v = calloc(1, sizeof(attribute_value_t));
+ CRM_ASSERT(v != NULL);
+
+ pcmk__str_update(&v->nodename, host);
+ g_hash_table_replace(a->values, v->nodename, v);
+ }
+
+ // If value is for a Pacemaker Remote node, remember that
+ crm_element_value_int(xml, PCMK__XA_ATTR_IS_REMOTE, &is_remote);
+ if (is_remote) {
+ attrd_set_value_flags(v, attrd_value_remote);
+ CRM_ASSERT(crm_remote_peer_get(host) != NULL);
+ }
+
+ // Check whether the value changed
+ changed = !pcmk__str_eq(v->current, value, pcmk__str_casei);
- if (filter && !pcmk__str_eq(v->current, value, pcmk__str_casei)
- && pcmk__str_eq(host, attrd_cluster->uname, pcmk__str_casei)) {
+ if (changed && filter && pcmk__str_eq(host, attrd_cluster->uname,
+ pcmk__str_casei)) {
crm_notice("%s[%s]: local value '%s' takes priority over '%s' from %s",
attr, host, v->current, value, peer->uname);
v = broadcast_local_value(a);
- } else if (!pcmk__str_eq(v->current, value, pcmk__str_casei)) {
+ } else if (changed) {
crm_notice("Setting %s[%s]%s%s: %s -> %s "
CRM_XS " from %s with %s write delay",
attr, host, a->set_type ? " in " : "",
--
2.31.1
From 72529ec512fb4938bd8dbbd2caf44bbb1a616826 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Thu, 11 Jan 2024 18:04:33 -0600
Subject: [PATCH 4/5] Refactor: pacemaker-attrd: minor shuffling to make
planned changes easier
---
daemons/attrd/attrd_cib.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/daemons/attrd/attrd_cib.c b/daemons/attrd/attrd_cib.c
index bdc0a10..481fea7 100644
--- a/daemons/attrd/attrd_cib.c
+++ b/daemons/attrd/attrd_cib.c
@@ -51,6 +51,7 @@ attrd_cib_updated_cb(const char *event, xmlNode *msg)
{
const xmlNode *patchset = NULL;
const char *client_name = NULL;
+ bool status_changed = false;
if (attrd_shutting_down(true)) {
return;
@@ -64,20 +65,22 @@ attrd_cib_updated_cb(const char *event, xmlNode *msg)
mainloop_set_trigger(attrd_config_read);
}
- if (!attrd_election_won()) {
- // Don't write attributes if we're not the writer
- return;
- }
+ status_changed = cib__element_in_patchset(patchset, XML_CIB_TAG_STATUS);
client_name = crm_element_value(msg, F_CIB_CLIENTNAME);
if (!cib__client_triggers_refresh(client_name)) {
- // The CIB is still accurate
+ /* This change came from a source that ensured the CIB is consistent
+ * with our attributes table, so we don't need to write anything out.
+ */
return;
}
- if (cib__element_in_patchset(patchset, XML_CIB_TAG_NODES)
- || cib__element_in_patchset(patchset, XML_CIB_TAG_STATUS)) {
-
+ if (!attrd_election_won()) {
+ // Don't write attributes if we're not the writer
+ return;
+ }
+
+ if (status_changed || cib__element_in_patchset(patchset, XML_CIB_TAG_NODES)) {
/* An unsafe client modified the nodes or status section. Write
* transient attributes to ensure they're up-to-date in the CIB.
*/
--
2.31.1
From b83c2567fb450eec5b18882ded16403831d2c3c0 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Thu, 11 Jan 2024 17:53:55 -0600
Subject: [PATCH 5/5] Log: pacemaker-attrd: make sure we don't try to log NULL
---
daemons/attrd/attrd_corosync.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/daemons/attrd/attrd_corosync.c b/daemons/attrd/attrd_corosync.c
index 59e6a26..b348d52 100644
--- a/daemons/attrd/attrd_corosync.c
+++ b/daemons/attrd/attrd_corosync.c
@@ -229,6 +229,11 @@ record_peer_nodeid(attribute_value_t *v, const char *host)
}
}
+#define readable_value(rv_v) pcmk__s((rv_v)->current, "(unset)")
+
+#define readable_peer(p) \
+ (((p) == NULL)? "all peers" : pcmk__s((p)->uname, "unknown peer"))
+
static void
update_attr_on_host(attribute_t *a, const crm_node_t *peer, const xmlNode *xml,
const char *attr, const char *value, const char *host,
@@ -262,14 +267,14 @@ update_attr_on_host(attribute_t *a, const crm_node_t *peer, const xmlNode *xml,
pcmk__str_casei)) {
crm_notice("%s[%s]: local value '%s' takes priority over '%s' from %s",
- attr, host, v->current, value, peer->uname);
+ attr, host, readable_value(v), value, peer->uname);
v = broadcast_local_value(a);
} else if (changed) {
crm_notice("Setting %s[%s]%s%s: %s -> %s "
CRM_XS " from %s with %s write delay",
attr, host, a->set_type ? " in " : "",
- pcmk__s(a->set_type, ""), pcmk__s(v->current, "(unset)"),
+ pcmk__s(a->set_type, ""), readable_value(v),
pcmk__s(value, "(unset)"), peer->uname,
(a->timeout_ms == 0)? "no" : pcmk__readable_interval(a->timeout_ms));
pcmk__str_update(&v->current, value);
@@ -543,12 +548,14 @@ attrd_peer_sync(crm_node_t *peer)
while (g_hash_table_iter_next(&aIter, NULL, (gpointer *) & a)) {
g_hash_table_iter_init(&vIter, a->values);
while (g_hash_table_iter_next(&vIter, NULL, (gpointer *) & v)) {
- crm_debug("Syncing %s[%s] = %s to %s", a->id, v->nodename, v->current, peer?peer->uname:"everyone");
+ crm_debug("Syncing %s[%s]='%s' to %s",
+ a->id, v->nodename, readable_value(v),
+ readable_peer(peer));
attrd_add_value_xml(sync, a, v, false);
}
}
- crm_debug("Syncing values to %s", peer?peer->uname:"everyone");
+ crm_debug("Syncing values to %s", readable_peer(peer));
attrd_send_message(peer, sync, false);
free_xml(sync);
}
--
2.31.1

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,385 @@
From 84d4a0d5f562df91baa0fece45d06ad3732f941c Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Tue, 16 Jan 2024 11:20:53 -0600
Subject: [PATCH 1/5] Low: pacemaker-attrd: properly validate attribute set
type
The sense of the test was accidentally reversed in 26471a52689
---
daemons/attrd/attrd_attributes.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/daemons/attrd/attrd_attributes.c b/daemons/attrd/attrd_attributes.c
index 8f32988..f059059 100644
--- a/daemons/attrd/attrd_attributes.c
+++ b/daemons/attrd/attrd_attributes.c
@@ -40,9 +40,9 @@ attrd_create_attribute(xmlNode *xml)
* attributes are not written.
*/
crm_element_value_int(xml, PCMK__XA_ATTR_IS_PRIVATE, &is_private);
- if ((is_private != 0)
- && !pcmk__str_any_of(set_type, XML_TAG_ATTR_SETS, XML_TAG_UTILIZATION,
- NULL)) {
+ if (!is_private && !pcmk__str_any_of(set_type,
+ XML_TAG_ATTR_SETS,
+ XML_TAG_UTILIZATION, NULL)) {
crm_warn("Ignoring attribute %s with invalid set type %s",
pcmk__s(name, "(unidentified)"), set_type);
return NULL;
--
2.31.1
From d0d0511e71fe983a2d89589c39810b79fb48a8ca Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Tue, 16 Jan 2024 12:13:42 -0600
Subject: [PATCH 2/5] Fix: pacemaker-attrd: sync utilization attributes to
peers correctly
Include the set type with attribute syncs.
Previously, utilization attributes would have the correct set_type on the node
where they were set, but peers would store it as a regular node attribute. If
one of those peers became writer, the attribute would get written to the wrong
set.
---
daemons/attrd/attrd_attributes.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/daemons/attrd/attrd_attributes.c b/daemons/attrd/attrd_attributes.c
index f059059..0ad9630 100644
--- a/daemons/attrd/attrd_attributes.c
+++ b/daemons/attrd/attrd_attributes.c
@@ -139,6 +139,7 @@ attrd_add_value_xml(xmlNode *parent, const attribute_t *a,
xmlNode *xml = create_xml_node(parent, __func__);
crm_xml_add(xml, PCMK__XA_ATTR_NAME, a->id);
+ crm_xml_add(xml, PCMK__XA_ATTR_SET_TYPE, a->set_type);
crm_xml_add(xml, PCMK__XA_ATTR_SET, a->set_id);
crm_xml_add(xml, PCMK__XA_ATTR_UUID, a->uuid);
crm_xml_add(xml, PCMK__XA_ATTR_USER, a->user);
--
2.31.1
From 4479ff8507dd69f5946d31cf83c7e47fe15d3bdb Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Tue, 16 Jan 2024 12:18:40 -0600
Subject: [PATCH 3/5] Refactor: pacemaker-attrd: functionize getting attribute
set ID
... for future reuse
---
daemons/attrd/attrd_attributes.c | 38 ++++++++++++++++++++++++++++++++
daemons/attrd/attrd_cib.c | 9 +-------
daemons/attrd/pacemaker-attrd.h | 3 ++-
3 files changed, 41 insertions(+), 9 deletions(-)
diff --git a/daemons/attrd/attrd_attributes.c b/daemons/attrd/attrd_attributes.c
index 0ad9630..5727ab8 100644
--- a/daemons/attrd/attrd_attributes.c
+++ b/daemons/attrd/attrd_attributes.c
@@ -210,3 +210,41 @@ attrd_populate_attribute(xmlNode *xml, const char *attr)
return a;
}
+
+/*!
+ * \internal
+ * \brief Get the XML ID used to write out an attribute set
+ *
+ * \param[in] attr Attribute to get set ID for
+ * \param[in] node_state_id XML ID of node state that attribute value is for
+ *
+ * \return Newly allocated string with XML ID to use for \p attr set
+ */
+char *
+attrd_set_id(const attribute_t *attr, const char *node_state_id)
+{
+ char *set_id = NULL;
+
+ CRM_ASSERT((attr != NULL) && (node_state_id != NULL));
+
+ if (attr->set_id == NULL) {
+ /* @COMPAT This should really take the set type into account. Currently
+ * we use the same XML ID for transient attributes and utilization
+ * attributes. It doesn't cause problems because the status section is
+ * not limited by the schema in any way, but it's still unfortunate.
+ * For backward compatibility reasons, we can't change this.
+ */
+ set_id = crm_strdup_printf("%s-%s", XML_CIB_TAG_STATUS, node_state_id);
+ } else {
+ /* @COMPAT When the user specifies a set ID for an attribute, it is the
+ * same for every node. That is less than ideal, but again, the schema
+ * doesn't enforce anything for the status section. We couldn't change
+ * it without allowing the set ID to vary per value rather than per
+ * attribute, which would break backward compatibility, pose design
+ * challenges, and potentially cause problems in rolling upgrades.
+ */
+ pcmk__str_update(&set_id, attr->set_id);
+ }
+ crm_xml_sanitize_id(set_id);
+ return set_id;
+}
diff --git a/daemons/attrd/attrd_cib.c b/daemons/attrd/attrd_cib.c
index 481fea7..08d3425 100644
--- a/daemons/attrd/attrd_cib.c
+++ b/daemons/attrd/attrd_cib.c
@@ -423,17 +423,10 @@ add_unset_attr_update(const attribute_t *attr, const char *attr_id,
static int
add_attr_update(const attribute_t *attr, const char *value, const char *node_id)
{
- char *set_id = NULL;
+ char *set_id = attrd_set_id(attr, node_id);
char *attr_id = NULL;
int rc = pcmk_rc_ok;
- if (attr->set_id != NULL) {
- pcmk__str_update(&set_id, attr->set_id);
- } else {
- set_id = crm_strdup_printf("%s-%s", XML_CIB_TAG_STATUS, node_id);
- }
- crm_xml_sanitize_id(set_id);
-
if (attr->uuid != NULL) {
pcmk__str_update(&attr_id, attr->uuid);
} else {
diff --git a/daemons/attrd/pacemaker-attrd.h b/daemons/attrd/pacemaker-attrd.h
index bacaad6..3da7f8d 100644
--- a/daemons/attrd/pacemaker-attrd.h
+++ b/daemons/attrd/pacemaker-attrd.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2023 the Pacemaker project contributors
+ * Copyright 2013-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -195,6 +195,7 @@ void attrd_clear_value_seen(void);
void attrd_free_attribute(gpointer data);
void attrd_free_attribute_value(gpointer data);
attribute_t *attrd_populate_attribute(xmlNode *xml, const char *attr);
+char *attrd_set_id(const attribute_t *attr, const char *node_state_id);
enum attrd_write_options {
attrd_write_changed = 0,
--
2.31.1
From eee2169ac348b8ed26ac0b78cb11ddc5cef9384e Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Tue, 16 Jan 2024 12:25:59 -0600
Subject: [PATCH 4/5] Refactor: pacemaker-attrd: functionize getting attribute
nvpair ID
... for future reuse
---
daemons/attrd/attrd_attributes.c | 28 ++++++++++++++++++++++++++++
daemons/attrd/attrd_cib.c | 17 +++++------------
daemons/attrd/pacemaker-attrd.h | 1 +
3 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/daemons/attrd/attrd_attributes.c b/daemons/attrd/attrd_attributes.c
index 5727ab8..23de2e2 100644
--- a/daemons/attrd/attrd_attributes.c
+++ b/daemons/attrd/attrd_attributes.c
@@ -248,3 +248,31 @@ attrd_set_id(const attribute_t *attr, const char *node_state_id)
crm_xml_sanitize_id(set_id);
return set_id;
}
+
+/*!
+ * \internal
+ * \brief Get the XML ID used to write out an attribute value
+ *
+ * \param[in] attr Attribute to get value XML ID for
+ * \param[in] node_state_id UUID of node that attribute value is for
+ *
+ * \return Newly allocated string with XML ID of \p attr value
+ */
+char *
+attrd_nvpair_id(const attribute_t *attr, const char *node_state_id)
+{
+ char *nvpair_id = NULL;
+
+ if (attr->uuid != NULL) {
+ pcmk__str_update(&nvpair_id, attr->uuid);
+
+ } else if (attr->set_id != NULL) {
+ nvpair_id = crm_strdup_printf("%s-%s", attr->set_id, attr->id);
+
+ } else {
+ nvpair_id = crm_strdup_printf(XML_CIB_TAG_STATUS "-%s-%s",
+ node_state_id, attr->id);
+ }
+ crm_xml_sanitize_id(nvpair_id);
+ return nvpair_id;
+}
diff --git a/daemons/attrd/attrd_cib.c b/daemons/attrd/attrd_cib.c
index 08d3425..d42345f 100644
--- a/daemons/attrd/attrd_cib.c
+++ b/daemons/attrd/attrd_cib.c
@@ -424,23 +424,16 @@ static int
add_attr_update(const attribute_t *attr, const char *value, const char *node_id)
{
char *set_id = attrd_set_id(attr, node_id);
- char *attr_id = NULL;
+ char *nvpair_id = attrd_nvpair_id(attr, node_id);
int rc = pcmk_rc_ok;
- if (attr->uuid != NULL) {
- pcmk__str_update(&attr_id, attr->uuid);
+ if (value == NULL) {
+ rc = add_unset_attr_update(attr, nvpair_id, node_id, set_id);
} else {
- attr_id = crm_strdup_printf("%s-%s", set_id, attr->id);
- }
- crm_xml_sanitize_id(attr_id);
-
- if (value != NULL) {
- rc = add_set_attr_update(attr, attr_id, node_id, set_id, value);
- } else {
- rc = add_unset_attr_update(attr, attr_id, node_id, set_id);
+ rc = add_set_attr_update(attr, nvpair_id, node_id, set_id, value);
}
free(set_id);
- free(attr_id);
+ free(nvpair_id);
return rc;
}
diff --git a/daemons/attrd/pacemaker-attrd.h b/daemons/attrd/pacemaker-attrd.h
index 3da7f8d..deec790 100644
--- a/daemons/attrd/pacemaker-attrd.h
+++ b/daemons/attrd/pacemaker-attrd.h
@@ -196,6 +196,7 @@ void attrd_free_attribute(gpointer data);
void attrd_free_attribute_value(gpointer data);
attribute_t *attrd_populate_attribute(xmlNode *xml, const char *attr);
char *attrd_set_id(const attribute_t *attr, const char *node_state_id);
+char *attrd_nvpair_id(const attribute_t *attr, const char *node_state_id);
enum attrd_write_options {
attrd_write_changed = 0,
--
2.31.1
From 2abde6cb87d2e3d31a370c74656f6f7c0818c185 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Thu, 18 Jan 2024 10:01:56 -0600
Subject: [PATCH 5/5] Log: pacemaker-attrd: improve some messages for debugging
---
daemons/attrd/attrd_attributes.c | 8 +++++---
daemons/attrd/attrd_cib.c | 13 +++++++++----
daemons/attrd/attrd_corosync.c | 10 ++++++----
3 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/daemons/attrd/attrd_attributes.c b/daemons/attrd/attrd_attributes.c
index 23de2e2..68b9585 100644
--- a/daemons/attrd/attrd_attributes.c
+++ b/daemons/attrd/attrd_attributes.c
@@ -60,13 +60,10 @@ attrd_create_attribute(xmlNode *xml)
a->values = pcmk__strikey_table(NULL, attrd_free_attribute_value);
a->user = crm_element_value_copy(xml, PCMK__XA_ATTR_USER);
- crm_trace("Performing all %s operations as user '%s'", a->id, a->user);
if (dampen_s != NULL) {
dampen = crm_get_msec(dampen_s);
}
- crm_trace("Created attribute %s with %s write delay", a->id,
- (a->timeout_ms == 0)? "no" : pcmk__readable_interval(a->timeout_ms));
if(dampen > 0) {
a->timeout_ms = dampen;
@@ -75,6 +72,11 @@ attrd_create_attribute(xmlNode *xml)
crm_warn("Ignoring invalid delay %s for attribute %s", dampen_s, a->id);
}
+ crm_trace("Created attribute %s with %s write delay and %s CIB user",
+ a->id,
+ ((dampen > 0)? pcmk__readable_interval(a->timeout_ms) : "no"),
+ pcmk__s(a->user, "default"));
+
g_hash_table_replace(attributes, a->id, a);
return a;
}
diff --git a/daemons/attrd/attrd_cib.c b/daemons/attrd/attrd_cib.c
index d42345f..cae6846 100644
--- a/daemons/attrd/attrd_cib.c
+++ b/daemons/attrd/attrd_cib.c
@@ -54,6 +54,7 @@ attrd_cib_updated_cb(const char *event, xmlNode *msg)
bool status_changed = false;
if (attrd_shutting_down(true)) {
+ crm_debug("Ignoring CIB change during shutdown");
return;
}
@@ -278,11 +279,13 @@ attrd_cib_callback(xmlNode *msg, int call_id, int rc, xmlNode *output, void *use
g_hash_table_iter_init(&iter, a->values);
while (g_hash_table_iter_next(&iter, (gpointer *) & peer, (gpointer *) & v)) {
- do_crm_log(level, "* %s[%s]=%s",
- a->id, peer, pcmk__s(v->requested, "(null)"));
if (rc == pcmk_ok) {
+ crm_info("* Wrote %s[%s]=%s",
+ a->id, peer, pcmk__s(v->requested, "(unset)"));
pcmk__str_update(&(v->requested), NULL);
} else {
+ do_crm_log(level, "* Could not write %s[%s]=%s",
+ a->id, peer, pcmk__s(v->requested, "(unset)"));
a->changed = true; // Reattempt write below if we are still writer
}
}
@@ -292,6 +295,7 @@ attrd_cib_callback(xmlNode *msg, int call_id, int rc, xmlNode *output, void *use
/* We deferred a write of a new update because this update was in
* progress. Write out the new value without additional delay.
*/
+ crm_debug("Pending update for %s can be written now", a->id);
write_attribute(a, false);
/* We're re-attempting a write because the original failed; delay
@@ -593,8 +597,9 @@ write_attribute(attribute_t *a, bool ignore_delay)
continue;
}
- crm_debug("Updating %s[%s]=%s (node uuid=%s id=%" PRIu32 ")",
- a->id, v->nodename, v->current, uuid, v->nodeid);
+ crm_debug("Writing %s[%s]=%s (node-state-id=%s node-id=%" PRIu32 ")",
+ a->id, v->nodename, pcmk__s(v->current, "(unset)"),
+ uuid, v->nodeid);
cib_updates++;
/* Preservation of the attribute to transmit alert */
diff --git a/daemons/attrd/attrd_corosync.c b/daemons/attrd/attrd_corosync.c
index b348d52..6fb847b 100644
--- a/daemons/attrd/attrd_corosync.c
+++ b/daemons/attrd/attrd_corosync.c
@@ -293,7 +293,8 @@ update_attr_on_host(attribute_t *a, const crm_node_t *peer, const xmlNode *xml,
// Write out new value or start dampening timer
if (a->timeout_ms && a->timer) {
- crm_trace("Delayed write out (%dms) for %s", a->timeout_ms, attr);
+ crm_trace("Delaying write of %s %s for dampening",
+ attr, pcmk__readable_interval(a->timeout_ms));
mainloop_timer_start(a->timer);
} else {
attrd_write_or_elect_attribute(a);
@@ -307,11 +308,12 @@ update_attr_on_host(attribute_t *a, const crm_node_t *peer, const xmlNode *xml,
if (is_force_write == 1 && a->timeout_ms && a->timer) {
/* Save forced writing and set change flag. */
/* The actual attribute is written by Writer after election. */
- crm_trace("Unchanged %s[%s] from %s is %s(Set the forced write flag)",
- attr, host, peer->uname, value);
+ crm_trace("%s[%s] from %s is unchanged (%s), forcing write",
+ attr, host, peer->uname, pcmk__s(value, "unset"));
a->force_write = TRUE;
} else {
- crm_trace("Unchanged %s[%s] from %s is %s", attr, host, peer->uname, value);
+ crm_trace("%s[%s] from %s is unchanged (%s)",
+ attr, host, peer->uname, pcmk__s(value, "unset"));
}
}
--
2.31.1

View File

@ -1,846 +0,0 @@
From df587aaec07b4a08364d4024b3d0c73e6dede562 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Mon, 9 Nov 2020 14:55:42 -0600
Subject: [PATCH 1/9] Refactor: scheduler: simplify XML attribute filtering
function
---
lib/pengine/pe_digest.c | 52 ++++++++++++++++++++++++++-----------------------
1 file changed, 28 insertions(+), 24 deletions(-)
diff --git a/lib/pengine/pe_digest.c b/lib/pengine/pe_digest.c
index 5bcd22b..1e119f9 100644
--- a/lib/pengine/pe_digest.c
+++ b/lib/pengine/pe_digest.c
@@ -45,30 +45,38 @@ pe__free_digests(gpointer ptr)
}
}
+/*!
+ * \internal
+ * \brief Remove named attributes from an XML element
+ *
+ * \param[in,out] param_set XML to be filtered
+ * \param[in] param_string Space-separated list of attribute names
+ * \param[in] need_present Whether to remove attributes that match,
+ * or those that don't match
+ */
static void
-filter_parameters(xmlNode * param_set, const char *param_string, bool need_present)
+filter_parameters(xmlNode *param_set, const char *param_string,
+ bool need_present)
{
- if (param_set && param_string) {
- xmlAttrPtr xIter = param_set->properties;
-
- while (xIter) {
- const char *prop_name = (const char *)xIter->name;
- char *name = crm_strdup_printf(" %s ", prop_name);
- char *match = strstr(param_string, name);
+ if ((param_set == NULL) || (param_string == NULL)) {
+ return;
+ }
+ for (xmlAttrPtr xIter = param_set->properties; xIter; ) {
+ const char *prop_name = (const char *) xIter->name;
+ char *name = crm_strdup_printf(" %s ", prop_name);
+ char *match = strstr(param_string, name);
- free(name);
+ free(name);
- // Do now, because current entry might get removed below
- xIter = xIter->next;
+ // Do now, because current entry might get removed below
+ xIter = xIter->next;
- if (need_present && match == NULL) {
- crm_trace("%s not found in %s", prop_name, param_string);
- xml_remove_prop(param_set, prop_name);
+ if ((need_present && (match == NULL))
+ || (!need_present && (match != NULL))) {
- } else if (need_present == FALSE && match) {
- crm_trace("%s found in %s", prop_name, param_string);
- xml_remove_prop(param_set, prop_name);
- }
+ crm_trace("Filtering %s (%sfound in '%s')",
+ prop_name, (need_present? "not " : ""), param_string);
+ xml_remove_prop(param_set, prop_name);
}
}
}
@@ -203,9 +211,7 @@ calculate_secure_digest(op_digest_cache_t *data, pe_resource_t *rsc,
g_hash_table_foreach(overrides, hash2field, data->params_secure);
}
g_hash_table_foreach(rsc->parameters, hash2field, data->params_secure);
- if (secure_list != NULL) {
- filter_parameters(data->params_secure, secure_list, FALSE);
- }
+ filter_parameters(data->params_secure, secure_list, FALSE);
if (pcmk_is_set(pcmk_get_ra_caps(class),
pcmk_ra_cap_fence_params)) {
/* For stonith resources, Pacemaker adds special parameters,
@@ -259,9 +265,7 @@ calculate_restart_digest(op_digest_cache_t *data, xmlNode *xml_op,
// Then filter out reloadable parameters, if any
value = crm_element_value(xml_op, XML_LRM_ATTR_OP_RESTART);
- if (value != NULL) {
- filter_parameters(data->params_restart, value, TRUE);
- }
+ filter_parameters(data->params_restart, value, TRUE);
value = crm_element_value(xml_op, XML_ATTR_CRM_VERSION);
data->digest_restart_calc = calculate_operation_digest(data->params_restart,
--
1.8.3.1
From f030af8771601d46947ac9276538c46c6c296504 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Mon, 9 Nov 2020 18:37:37 -0600
Subject: [PATCH 2/9] Refactor: scheduler: remember whether action is probe
when unpacking
... to reduce code duplication and improve readability
---
lib/pengine/utils.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/pengine/utils.c b/lib/pengine/utils.c
index 04110be..b0922fa 100644
--- a/lib/pengine/utils.c
+++ b/lib/pengine/utils.c
@@ -995,6 +995,8 @@ unpack_operation(pe_action_t * action, xmlNode * xml_obj, pe_resource_t * contai
{
int timeout_ms = 0;
const char *value = NULL;
+ bool is_probe = pcmk__str_eq(action->task, RSC_STATUS, pcmk__str_casei)
+ && (interval_ms == 0);
#if ENABLE_VERSIONED_ATTRS
pe_rsc_action_details_t *rsc_details = NULL;
#endif
@@ -1026,8 +1028,7 @@ unpack_operation(pe_action_t * action, xmlNode * xml_obj, pe_resource_t * contai
action->meta, NULL, FALSE, data_set);
// Determine probe default timeout differently
- if (pcmk__str_eq(action->task, RSC_STATUS, pcmk__str_casei)
- && (interval_ms == 0)) {
+ if (is_probe) {
xmlNode *min_interval_mon = find_min_interval_mon(action->rsc, FALSE);
if (min_interval_mon) {
@@ -1099,8 +1100,7 @@ unpack_operation(pe_action_t * action, xmlNode * xml_obj, pe_resource_t * contai
if (pcmk_is_set(pcmk_get_ra_caps(rsc_rule_data.standard),
pcmk_ra_cap_fence_params)
&& (pcmk__str_eq(action->task, RSC_START, pcmk__str_casei)
- || (pcmk__str_eq(action->task, RSC_STATUS, pcmk__str_casei)
- && (interval_ms == 0)))
+ || is_probe)
&& action->rsc->parameters) {
value = g_hash_table_lookup(action->rsc->parameters,
--
1.8.3.1
From 9de547849697cd6a3581db3f83b04f68d0405d9d Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Tue, 10 Nov 2020 15:15:01 -0600
Subject: [PATCH 3/9] Refactor: scheduler: don't include originally unpacked
resource parameters in digest
Previously, when calculating an operation digest, calculate_main_digest() would
grab the following, in order of highest to lowest precedence:
* instance attributes evaluated for the appropriate node
* instance attributes specified with the operation
* instance attributes as originally unpacked (without evaluating for any node)
* resource meta-attributes
Adding the originally unpacked instance attributes was redundant, since
node-evaluated instance attributes would always be a superset of those and
would take precedence.
---
lib/pengine/pe_digest.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/lib/pengine/pe_digest.c b/lib/pengine/pe_digest.c
index 1e119f9..dd6b753 100644
--- a/lib/pengine/pe_digest.c
+++ b/lib/pengine/pe_digest.c
@@ -162,7 +162,6 @@ calculate_main_digest(op_digest_cache_t *data, pe_resource_t *rsc,
}
g_hash_table_foreach(local_rsc_params, hash2field, data->params_all);
g_hash_table_foreach(action->extra, hash2field, data->params_all);
- g_hash_table_foreach(rsc->parameters, hash2field, data->params_all);
g_hash_table_foreach(action->meta, hash2metafield, data->params_all);
#if ENABLE_VERSIONED_ATTRS
--
1.8.3.1
From e9921b2ab3e9eeab6227d97cc12b85fa04dfd187 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Fri, 13 Nov 2020 09:27:12 -0600
Subject: [PATCH 4/9] Refactor: scheduler: reuse existing function to check for
remote in XML
... to reduce code duplication and improve readability
---
lib/pengine/bundle.c | 21 +++------------------
1 file changed, 3 insertions(+), 18 deletions(-)
diff --git a/lib/pengine/bundle.c b/lib/pengine/bundle.c
index 76730c7..4f6eac3 100644
--- a/lib/pengine/bundle.c
+++ b/lib/pengine/bundle.c
@@ -959,28 +959,13 @@ pe__bundle_needs_remote_name(pe_resource_t *rsc)
const char *value;
if (rsc == NULL) {
- return FALSE;
+ return false;
}
value = g_hash_table_lookup(rsc->parameters, XML_RSC_ATTR_REMOTE_RA_ADDR);
- if (!pcmk__str_eq(value, "#uname", pcmk__str_casei)) {
- return FALSE;
- } else {
- const char *match[3][2] = {
- { XML_ATTR_TYPE, "remote" },
- { XML_AGENT_ATTR_CLASS, PCMK_RESOURCE_CLASS_OCF },
- { XML_AGENT_ATTR_PROVIDER, "pacemaker" },
- };
-
- for (int m = 0; m < 3; m++) {
- value = crm_element_value(rsc->xml, match[m][0]);
- if (!pcmk__str_eq(value, match[m][1], pcmk__str_casei)) {
- return FALSE;
- }
- }
- }
- return TRUE;
+ return pcmk__str_eq(value, "#uname", pcmk__str_casei)
+ && xml_contains_remote_node(rsc->xml);
}
const char *
--
1.8.3.1
From 0f220e1cd25ec095492ac4b346452520f4b71cf1 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Wed, 11 Nov 2020 15:29:46 -0600
Subject: [PATCH 5/9] Refactor: scheduler: remove dead code
Several internal expression-testing functions were unused. While they might
have had some potential future value, the abundance of similarly named
functions made debugging difficult. Comment blocks were added to the functions
they wrapped, which should add similar value.
Also, we had an internal wrapper for pe__eval_date_expr() that was used
only in crm_rule, so it was moved there.
---
include/crm/pengine/rules_internal.h | 10 +--
lib/pengine/rules.c | 130 +++++++++++------------------------
tools/crm_rule.c | 27 +++++++-
3 files changed, 66 insertions(+), 101 deletions(-)
diff --git a/include/crm/pengine/rules_internal.h b/include/crm/pengine/rules_internal.h
index f60263a..7380826 100644
--- a/include/crm/pengine/rules_internal.h
+++ b/include/crm/pengine/rules_internal.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-2019 the Pacemaker project contributors
+ * Copyright 2015-2020 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -28,14 +28,6 @@ gboolean pe__eval_op_expr(xmlNodePtr expr, pe_rule_eval_data_t *rule_data);
gboolean pe__eval_role_expr(xmlNode *expr, pe_rule_eval_data_t *rule_data);
gboolean pe__eval_rsc_expr(xmlNodePtr expr, pe_rule_eval_data_t *rule_data);
-int pe_eval_date_expression(xmlNode *time_expr,
- crm_time_t *now,
- crm_time_t *next_change);
-gboolean pe_test_date_expression(xmlNode *time_expr, crm_time_t *now,
- crm_time_t *next_change);
int pe_cron_range_satisfied(crm_time_t * now, xmlNode * cron_spec);
-gboolean pe_test_attr_expression(xmlNode *expr, GHashTable *hash, crm_time_t *now,
- pe_match_data_t *match_data);
-gboolean pe_test_role_expression(xmlNode * expr, enum rsc_role_e role, crm_time_t * now);
#endif
diff --git a/lib/pengine/rules.c b/lib/pengine/rules.c
index 28562aa..be30e67 100644
--- a/lib/pengine/rules.c
+++ b/lib/pengine/rules.c
@@ -140,37 +140,6 @@ find_expression_type(xmlNode * expr)
return attr_expr;
}
-gboolean
-pe_test_role_expression(xmlNode *expr, enum rsc_role_e role, crm_time_t *now)
-{
- pe_rule_eval_data_t rule_data = {
- .node_hash = NULL,
- .role = role,
- .now = now,
- .match_data = NULL,
- .rsc_data = NULL,
- .op_data = NULL
- };
-
- return pe__eval_role_expr(expr, &rule_data);
-}
-
-gboolean
-pe_test_attr_expression(xmlNode *expr, GHashTable *hash, crm_time_t *now,
- pe_match_data_t *match_data)
-{
- pe_rule_eval_data_t rule_data = {
- .node_hash = hash,
- .role = RSC_ROLE_UNKNOWN,
- .now = now,
- .match_data = match_data,
- .rsc_data = NULL,
- .op_data = NULL
- };
-
- return pe__eval_attr_expr(expr, &rule_data);
-}
-
/* As per the nethack rules:
*
* moon period = 29.53058 days ~= 30, year = 365.2422 days
@@ -331,38 +300,6 @@ pe_parse_xml_duration(crm_time_t * start, xmlNode * duration_spec)
return end;
}
-/*!
- * \internal
- * \brief Test a date expression (pass/fail) for a specific time
- *
- * \param[in] time_expr date_expression XML
- * \param[in] now Time for which to evaluate expression
- * \param[out] next_change If not NULL, set to when evaluation will change
- *
- * \return TRUE if date expression is in effect at given time, FALSE otherwise
- */
-gboolean
-pe_test_date_expression(xmlNode *expr, crm_time_t *now, crm_time_t *next_change)
-{
- pe_rule_eval_data_t rule_data = {
- .node_hash = NULL,
- .role = RSC_ROLE_UNKNOWN,
- .now = now,
- .match_data = NULL,
- .rsc_data = NULL,
- .op_data = NULL
- };
-
- switch (pe__eval_date_expr(expr, &rule_data, next_change)) {
- case pcmk_rc_within_range:
- case pcmk_rc_ok:
- return TRUE;
-
- default:
- return FALSE;
- }
-}
-
// Set next_change to t if t is earlier
static void
crm_time_set_if_earlier(crm_time_t *next_change, crm_time_t *t)
@@ -375,31 +312,6 @@ crm_time_set_if_earlier(crm_time_t *next_change, crm_time_t *t)
}
}
-/*!
- * \internal
- * \brief Evaluate a date expression for a specific time
- *
- * \param[in] time_expr date_expression XML
- * \param[in] now Time for which to evaluate expression
- * \param[out] next_change If not NULL, set to when evaluation will change
- *
- * \return Standard Pacemaker return code
- */
-int
-pe_eval_date_expression(xmlNode *expr, crm_time_t *now, crm_time_t *next_change)
-{
- pe_rule_eval_data_t rule_data = {
- .node_hash = NULL,
- .role = RSC_ROLE_UNKNOWN,
- .now = now,
- .match_data = NULL,
- .rsc_data = NULL,
- .op_data = NULL
- };
-
- return pe__eval_date_expr(expr, &rule_data, next_change);
-}
-
// Information about a block of nvpair elements
typedef struct sorted_set_s {
int score; // This block's score for sorting
@@ -908,7 +820,16 @@ pe_eval_subexpr(xmlNode *expr, pe_rule_eval_data_t *rule_data, crm_time_t *next_
break;
case time_expr:
- accept = pe_test_date_expression(expr, rule_data->now, next_change);
+ switch (pe__eval_date_expr(expr, rule_data, next_change)) {
+ case pcmk_rc_within_range:
+ case pcmk_rc_ok:
+ accept = TRUE;
+ break;
+
+ default:
+ accept = FALSE;
+ break;
+ }
break;
case role_expr:
@@ -1104,6 +1025,16 @@ accept_attr_expr(const char *l_val, const char *r_val, const char *type,
return false; // Should never reach this point
}
+/*!
+ * \internal
+ * \brief Evaluate a node attribute expression based on #uname, #id, #kind,
+ * or a generic node attribute
+ *
+ * \param[in] expr XML of rule expression
+ * \param[in] rule_data The match_data and node_hash members are used
+ *
+ * \return TRUE if rule_data satisfies the expression, FALSE otherwise
+ */
gboolean
pe__eval_attr_expr(xmlNodePtr expr, pe_rule_eval_data_t *rule_data)
{
@@ -1169,8 +1100,16 @@ pe__eval_attr_expr(xmlNodePtr expr, pe_rule_eval_data_t *rule_data)
return accept_attr_expr(h_val, value, type, op);
}
-
-
+/*!
+ * \internal
+ * \brief Evaluate a date_expression
+ *
+ * \param[in] expr XML of rule expression
+ * \param[in] rule_data Only the now member is used
+ * \param[out] next_change If not NULL, set to when evaluation will change
+ *
+ * \return Standard Pacemaker return code
+ */
int
pe__eval_date_expr(xmlNodePtr expr, pe_rule_eval_data_t *rule_data, crm_time_t *next_change)
{
@@ -1285,6 +1224,15 @@ pe__eval_op_expr(xmlNodePtr expr, pe_rule_eval_data_t *rule_data) {
return TRUE;
}
+/*!
+ * \internal
+ * \brief Evaluate a node attribute expression based on #role
+ *
+ * \param[in] expr XML of rule expression
+ * \param[in] rule_data Only the role member is used
+ *
+ * \return TRUE if rule_data->role satisfies the expression, FALSE otherwise
+ */
gboolean
pe__eval_role_expr(xmlNodePtr expr, pe_rule_eval_data_t *rule_data)
{
diff --git a/tools/crm_rule.c b/tools/crm_rule.c
index 0e44828..2871f3d 100644
--- a/tools/crm_rule.c
+++ b/tools/crm_rule.c
@@ -75,6 +75,31 @@ mode_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError **e
return TRUE;
}
+/*!
+ * \internal
+ * \brief Evaluate a date expression for a specific time
+ *
+ * \param[in] time_expr date_expression XML
+ * \param[in] now Time for which to evaluate expression
+ * \param[out] next_change If not NULL, set to when evaluation will change
+ *
+ * \return Standard Pacemaker return code
+ */
+static int
+eval_date_expression(xmlNode *expr, crm_time_t *now, crm_time_t *next_change)
+{
+ pe_rule_eval_data_t rule_data = {
+ .node_hash = NULL,
+ .role = RSC_ROLE_UNKNOWN,
+ .now = now,
+ .match_data = NULL,
+ .rsc_data = NULL,
+ .op_data = NULL
+ };
+
+ return pe__eval_date_expr(expr, &rule_data, next_change);
+}
+
static int
crm_rule_check(pe_working_set_t *data_set, const char *rule_id, crm_time_t *effective_date)
{
@@ -156,7 +181,7 @@ crm_rule_check(pe_working_set_t *data_set, const char *rule_id, crm_time_t *effe
CRM_ASSERT(match != NULL);
CRM_ASSERT(find_expression_type(match) == time_expr);
- rc = pe_eval_date_expression(match, effective_date, NULL);
+ rc = eval_date_expression(match, effective_date, NULL);
if (rc == pcmk_rc_within_range) {
printf("Rule %s is still in effect\n", rule_id);
--
1.8.3.1
From 91a6ec4bec86de7389fcd64cb27e315da760f0dd Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Wed, 11 Nov 2020 16:44:57 -0600
Subject: [PATCH 6/9] Refactor: scheduler: make constraint unpacking function
static
... for linker efficiency and readability. Also change the return type to void
since it was ignored (and the same for some related functions).
---
include/pcmki/pcmki_sched_allocate.h | 4 +--
lib/pacemaker/pcmk_sched_constraints.c | 46 ++++++++++++++++------------------
2 files changed, 23 insertions(+), 27 deletions(-)
diff --git a/include/pcmki/pcmki_sched_allocate.h b/include/pcmki/pcmki_sched_allocate.h
index efc0da6..a7f8c11 100644
--- a/include/pcmki/pcmki_sched_allocate.h
+++ b/include/pcmki/pcmki_sched_allocate.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2004-2019 the Pacemaker project contributors
+ * Copyright 2004-2020 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -143,8 +143,6 @@ extern gboolean unpack_rsc_order(xmlNode * xml_obj, pe_working_set_t * data_set)
extern gboolean unpack_rsc_colocation(xmlNode * xml_obj, pe_working_set_t * data_set);
-extern gboolean unpack_location(xmlNode * xml_obj, pe_working_set_t * data_set);
-
extern gboolean unpack_rsc_ticket(xmlNode * xml_obj, pe_working_set_t * data_set);
void LogNodeActions(pe_working_set_t * data_set, gboolean terminal);
diff --git a/lib/pacemaker/pcmk_sched_constraints.c b/lib/pacemaker/pcmk_sched_constraints.c
index 6ed2d8c..121754d 100644
--- a/lib/pacemaker/pcmk_sched_constraints.c
+++ b/lib/pacemaker/pcmk_sched_constraints.c
@@ -48,6 +48,7 @@ static pe__location_t *generate_location_rule(pe_resource_t *rsc,
crm_time_t *next_change,
pe_working_set_t *data_set,
pe_match_data_t *match_data);
+static void unpack_location(xmlNode *xml_obj, pe_working_set_t *data_set);
static bool
evaluate_lifetime(xmlNode *lifetime, pe_working_set_t *data_set)
@@ -709,11 +710,13 @@ tag_to_set(xmlNode * xml_obj, xmlNode ** rsc_set, const char * attr,
return TRUE;
}
-static gboolean unpack_rsc_location(xmlNode * xml_obj, pe_resource_t * rsc_lh, const char * role,
- const char * score, pe_working_set_t * data_set, pe_match_data_t * match_data);
+static void unpack_rsc_location(xmlNode *xml_obj, pe_resource_t *rsc_lh,
+ const char *role, const char *score,
+ pe_working_set_t *data_set,
+ pe_match_data_t *match_data);
-static gboolean
-unpack_simple_location(xmlNode * xml_obj, pe_working_set_t * data_set)
+static void
+unpack_simple_location(xmlNode *xml_obj, pe_working_set_t *data_set)
{
const char *id = crm_element_value(xml_obj, XML_ATTR_ID);
const char *value = crm_element_value(xml_obj, XML_LOC_ATTR_SOURCE);
@@ -721,7 +724,7 @@ unpack_simple_location(xmlNode * xml_obj, pe_working_set_t * data_set)
if(value) {
pe_resource_t *rsc_lh = pe_find_constraint_resource(data_set->resources, value);
- return unpack_rsc_location(xml_obj, rsc_lh, NULL, NULL, data_set, NULL);
+ unpack_rsc_location(xml_obj, rsc_lh, NULL, NULL, data_set, NULL);
}
value = crm_element_value(xml_obj, XML_LOC_ATTR_SOURCE_PATTERN);
@@ -741,7 +744,7 @@ unpack_simple_location(xmlNode * xml_obj, pe_working_set_t * data_set)
" has invalid value '%s'", id, value);
regfree(r_patt);
free(r_patt);
- return FALSE;
+ return;
}
for (rIter = data_set->resources; rIter; rIter = rIter->next) {
@@ -787,13 +790,12 @@ unpack_simple_location(xmlNode * xml_obj, pe_working_set_t * data_set)
regfree(r_patt);
free(r_patt);
}
-
- return FALSE;
}
-static gboolean
-unpack_rsc_location(xmlNode * xml_obj, pe_resource_t * rsc_lh, const char * role,
- const char * score, pe_working_set_t * data_set, pe_match_data_t * match_data)
+static void
+unpack_rsc_location(xmlNode *xml_obj, pe_resource_t *rsc_lh, const char *role,
+ const char *score, pe_working_set_t *data_set,
+ pe_match_data_t *match_data)
{
pe__location_t *location = NULL;
const char *id_lh = crm_element_value(xml_obj, XML_LOC_ATTR_SOURCE);
@@ -804,7 +806,7 @@ unpack_rsc_location(xmlNode * xml_obj, pe_resource_t * rsc_lh, const char * role
if (rsc_lh == NULL) {
pcmk__config_warn("Ignoring constraint '%s' because resource '%s' "
"does not exist", id, id_lh);
- return FALSE;
+ return;
}
if (score == NULL) {
@@ -816,7 +818,7 @@ unpack_rsc_location(xmlNode * xml_obj, pe_resource_t * rsc_lh, const char * role
pe_node_t *match = pe_find_node(data_set->nodes, node);
if (!match) {
- return FALSE;
+ return;
}
location = rsc2node_new(id, rsc_lh, score_i, discovery, match, data_set);
@@ -850,7 +852,7 @@ unpack_rsc_location(xmlNode * xml_obj, pe_resource_t * rsc_lh, const char * role
pe__update_recheck_time(t, data_set);
}
crm_time_free(next_change);
- return TRUE;
+ return;
}
if (role == NULL) {
@@ -860,7 +862,7 @@ unpack_rsc_location(xmlNode * xml_obj, pe_resource_t * rsc_lh, const char * role
if (location && role) {
if (text2role(role) == RSC_ROLE_UNKNOWN) {
pe_err("Invalid constraint %s: Bad role %s", id, role);
- return FALSE;
+ return;
} else {
enum rsc_role_e r = text2role(role);
@@ -877,8 +879,6 @@ unpack_rsc_location(xmlNode * xml_obj, pe_resource_t * rsc_lh, const char * role
}
}
}
-
- return TRUE;
}
static gboolean
@@ -992,8 +992,8 @@ unpack_location_set(xmlNode * location, xmlNode * set, pe_working_set_t * data_s
return TRUE;
}
-gboolean
-unpack_location(xmlNode * xml_obj, pe_working_set_t * data_set)
+static void
+unpack_location(xmlNode *xml_obj, pe_working_set_t *data_set)
{
xmlNode *set = NULL;
gboolean any_sets = FALSE;
@@ -1002,7 +1002,7 @@ unpack_location(xmlNode * xml_obj, pe_working_set_t * data_set)
xmlNode *expanded_xml = NULL;
if (unpack_location_tags(xml_obj, &expanded_xml, data_set) == FALSE) {
- return FALSE;
+ return;
}
if (expanded_xml) {
@@ -1020,7 +1020,7 @@ unpack_location(xmlNode * xml_obj, pe_working_set_t * data_set)
if (expanded_xml) {
free_xml(expanded_xml);
}
- return FALSE;
+ return;
}
}
}
@@ -1031,10 +1031,8 @@ unpack_location(xmlNode * xml_obj, pe_working_set_t * data_set)
}
if (any_sets == FALSE) {
- return unpack_simple_location(xml_obj, data_set);
+ unpack_simple_location(xml_obj, data_set);
}
-
- return TRUE;
}
static int
--
1.8.3.1
From df842adafca8ba56ddb5b448490ffef54ea785d4 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Fri, 13 Nov 2020 09:19:51 -0600
Subject: [PATCH 7/9] Refactor: scheduler: trivial refactoring of nvpair
evaluation
... for readability
---
lib/pengine/rules.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/lib/pengine/rules.c b/lib/pengine/rules.c
index be30e67..86e7899 100644
--- a/lib/pengine/rules.c
+++ b/lib/pengine/rules.c
@@ -529,20 +529,19 @@ static GList *
make_pairs(xmlNode *top, xmlNode *xml_obj, const char *set_name,
const char *always_first)
{
- GListPtr unsorted = NULL;
- const char *score = NULL;
- sorted_set_t *pair = NULL;
- xmlNode *attr_set = NULL;
+ GList *unsorted = NULL;
if (xml_obj == NULL) {
return NULL;
}
- for (attr_set = pcmk__xe_first_child(xml_obj); attr_set != NULL;
+ for (xmlNode *attr_set = pcmk__xe_first_child(xml_obj); attr_set != NULL;
attr_set = pcmk__xe_next(attr_set)) {
- /* Uncertain if set_name == NULL check is strictly necessary here */
- if (pcmk__str_eq(set_name, (const char *)attr_set->name, pcmk__str_null_matches)) {
- pair = NULL;
+ if (pcmk__str_eq(set_name, (const char *) attr_set->name,
+ pcmk__str_null_matches)) {
+ const char *score = NULL;
+ sorted_set_t *pair = NULL;
+
attr_set = expand_idref(attr_set, top);
if (attr_set == NULL) {
continue;
--
1.8.3.1
From 373c224ac1c41bd47a928a7523744c6c678a6543 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Fri, 13 Nov 2020 09:21:35 -0600
Subject: [PATCH 8/9] Low: scheduler: correctly skip dangling id-ref
When evaluating XML nvpair blocks, make_pairs() previously reused the
"for" loop variable when expanding id-ref's. However if the id-ref was dangling
(only possible if schema enforcement is turned off), this would make it NULL
and thus exiting the loop instead of continuing.
---
lib/pengine/rules.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/lib/pengine/rules.c b/lib/pengine/rules.c
index 86e7899..1bd807f 100644
--- a/lib/pengine/rules.c
+++ b/lib/pengine/rules.c
@@ -541,18 +541,19 @@ make_pairs(xmlNode *top, xmlNode *xml_obj, const char *set_name,
pcmk__str_null_matches)) {
const char *score = NULL;
sorted_set_t *pair = NULL;
+ xmlNode *expanded_attr_set = expand_idref(attr_set, top);
- attr_set = expand_idref(attr_set, top);
- if (attr_set == NULL) {
+ if (expanded_attr_set == NULL) {
+ // Schema (if not "none") prevents this
continue;
}
pair = calloc(1, sizeof(sorted_set_t));
- pair->name = ID(attr_set);
+ pair->name = ID(expanded_attr_set);
pair->special_name = always_first;
- pair->attr_set = attr_set;
+ pair->attr_set = expanded_attr_set;
- score = crm_element_value(attr_set, XML_RULE_ATTR_SCORE);
+ score = crm_element_value(expanded_attr_set, XML_RULE_ATTR_SCORE);
pair->score = char2score(score);
unsorted = g_list_prepend(unsorted, pair);
--
1.8.3.1
From b59717751c168ec745bedbcc5696bee11036d931 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Thu, 12 Nov 2020 14:37:27 -0600
Subject: [PATCH 9/9] Low: scheduler: treat missing parameter as NULL in rules
with value-source
Previously, if value-source were set to "param" or "meta", and an affected
resource did not have the specified parameter, the parameter name would wrongly
be used as the value to compare against. Now, use NULL as the value to compare
against.
---
lib/pengine/rules.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/lib/pengine/rules.c b/lib/pengine/rules.c
index 1bd807f..e5d452f 100644
--- a/lib/pengine/rules.c
+++ b/lib/pengine/rules.c
@@ -1041,6 +1041,7 @@ pe__eval_attr_expr(xmlNodePtr expr, pe_rule_eval_data_t *rule_data)
gboolean attr_allocated = FALSE;
const char *h_val = NULL;
GHashTable *table = NULL;
+ bool literal = true;
const char *op = NULL;
const char *type = NULL;
@@ -1071,18 +1072,22 @@ pe__eval_attr_expr(xmlNodePtr expr, pe_rule_eval_data_t *rule_data)
}
if (pcmk__str_eq(value_source, "param", pcmk__str_casei)) {
+ literal = false;
table = rule_data->match_data->params;
} else if (pcmk__str_eq(value_source, "meta", pcmk__str_casei)) {
+ literal = false;
table = rule_data->match_data->meta;
}
}
- if (table) {
+ if (!literal) {
const char *param_name = value;
const char *param_value = NULL;
- if (param_name && param_name[0]) {
- if ((param_value = (const char *)g_hash_table_lookup(table, param_name))) {
+ value = NULL;
+ if ((table != NULL) && !pcmk__str_empty(param_name)) {
+ param_value = (const char *)g_hash_table_lookup(table, param_name);
+ if (param_value != NULL) {
value = param_value;
}
}
--
1.8.3.1

View File

@ -0,0 +1,53 @@
From 9c13ce6fe95812308443c188ace8f897e6bce942 Mon Sep 17 00:00:00 2001
From: Reid Wahl <nrwahl@protonmail.com>
Date: Mon, 29 Jan 2024 11:14:25 -0800
Subject: [PATCH] Fix: tools: crm_attribute emits garbage for --node localhost
or auto
This happens because pcmk__node_attr_target() returns its argument if
its argument is NULL, "auto", or "localhost" and no relevant environment
variables are found. Then crm_attribute frees the return value, makes a
copy of it, and assigns it back to options.dest_uname.
The fix is to check whether the return value is equal to the argument.
Fixes RHEL-23065
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
---
tools/crm_attribute.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/tools/crm_attribute.c b/tools/crm_attribute.c
index d221ab85d..636d03dbd 100644
--- a/tools/crm_attribute.c
+++ b/tools/crm_attribute.c
@@ -766,8 +766,23 @@ main(int argc, char **argv)
const char *target = pcmk__node_attr_target(options.dest_uname);
if (target != NULL) {
- g_free(options.dest_uname);
- options.dest_uname = g_strdup(target);
+ /* If options.dest_uname is "auto" or "localhost", then
+ * pcmk__node_attr_target() may return it, depending on environment
+ * variables. In that case, attribute lookups will fail for "auto"
+ * (unless there's a node named "auto"). attrd maps "localhost" to
+ * the true local node name for queries.
+ *
+ * @TODO
+ * * Investigate whether "localhost" is mapped to a real node name
+ * for non-query commands. If not, possibly modify it so that it
+ * is.
+ * * Map "auto" to "localhost" (probably).
+ */
+ if (target != (const char *) options.dest_uname) {
+ g_free(options.dest_uname);
+ options.dest_uname = g_strdup(target);
+ }
+
} else if (getenv("CIB_file") != NULL && options.dest_uname == NULL) {
get_node_name_from_local();
}
--
2.41.0

View File

@ -1,26 +0,0 @@
From d1b6b6cb5151763888ac8bc55708d2e7cbbf590b Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Thu, 19 Nov 2020 13:35:31 -0500
Subject: [PATCH] Fix: scheduler: Fix output of failed actions without an
operation_key.
---
lib/pengine/pe_output.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/pengine/pe_output.c b/lib/pengine/pe_output.c
index 1a3f93d..b91348f 100644
--- a/lib/pengine/pe_output.c
+++ b/lib/pengine/pe_output.c
@@ -975,7 +975,7 @@ pe__failed_action_xml(pcmk__output_t *out, va_list args) {
xmlNodePtr node = pcmk__output_create_xml_node(out, "failure");
xmlSetProp(node, (pcmkXmlStr) (op_key ? "op_key" : "id"),
- (pcmkXmlStr) (op_key ? op_key : "id"));
+ (pcmkXmlStr) (op_key ? op_key : ID(xml_op)));
xmlSetProp(node, (pcmkXmlStr) "node",
(pcmkXmlStr) crm_element_value(xml_op, XML_ATTR_UNAME));
xmlSetProp(node, (pcmkXmlStr) "exitstatus",
--
1.8.3.1

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,285 +0,0 @@
From 0700a4814a598d0e2e9bd54f970c6d3ff66184df Mon Sep 17 00:00:00 2001
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
Date: Tue, 24 Nov 2020 16:17:34 +0100
Subject: [PATCH 1/2] Refactor: move stonith__register_messages() call from
pcmk__out_prologue() to the calling functions
---
lib/pacemaker/pcmk_fence.c | 14 ++++++++++++++
lib/pacemaker/pcmk_output.c | 1 -
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/lib/pacemaker/pcmk_fence.c b/lib/pacemaker/pcmk_fence.c
index 7beedff..d591379 100644
--- a/lib/pacemaker/pcmk_fence.c
+++ b/lib/pacemaker/pcmk_fence.c
@@ -247,6 +247,8 @@ pcmk_fence_history(xmlNodePtr *xml, stonith_t *st, char *target, unsigned int ti
return rc;
}
+ stonith__register_messages(out);
+
out->quiet = quiet;
rc = pcmk__fence_history(out, st, target, timeout, verbose, broadcast, cleanup);
@@ -287,6 +289,8 @@ pcmk_fence_installed(xmlNodePtr *xml, stonith_t *st, unsigned int timeout) {
return rc;
}
+ stonith__register_messages(out);
+
rc = pcmk__fence_installed(out, st, timeout);
pcmk__out_epilogue(out, xml, rc);
return rc;
@@ -321,6 +325,8 @@ pcmk_fence_last(xmlNodePtr *xml, const char *target, bool as_nodeid) {
return rc;
}
+ stonith__register_messages(out);
+
rc = pcmk__fence_last(out, target, as_nodeid);
pcmk__out_epilogue(out, xml, rc);
return rc;
@@ -364,6 +370,8 @@ pcmk_fence_list_targets(xmlNodePtr *xml, stonith_t *st, const char *device_id,
return rc;
}
+ stonith__register_messages(out);
+
rc = pcmk__fence_list_targets(out, st, device_id, timeout);
pcmk__out_epilogue(out, xml, rc);
return rc;
@@ -398,6 +406,8 @@ pcmk_fence_metadata(xmlNodePtr *xml, stonith_t *st, char *agent,
return rc;
}
+ stonith__register_messages(out);
+
rc = pcmk__fence_metadata(out, st, agent, timeout);
pcmk__out_epilogue(out, xml, rc);
return rc;
@@ -442,6 +452,8 @@ pcmk_fence_registered(xmlNodePtr *xml, stonith_t *st, char *target,
return rc;
}
+ stonith__register_messages(out);
+
rc = pcmk__fence_registered(out, st, target, timeout);
pcmk__out_epilogue(out, xml, rc);
return rc;
@@ -501,6 +513,8 @@ pcmk_fence_validate(xmlNodePtr *xml, stonith_t *st, const char *agent,
return rc;
}
+ stonith__register_messages(out);
+
rc = pcmk__fence_validate(out, st, agent, id, params, timeout);
pcmk__out_epilogue(out, xml, rc);
return rc;
diff --git a/lib/pacemaker/pcmk_output.c b/lib/pacemaker/pcmk_output.c
index 74a7c59..a637031 100644
--- a/lib/pacemaker/pcmk_output.c
+++ b/lib/pacemaker/pcmk_output.c
@@ -34,7 +34,6 @@ pcmk__out_prologue(pcmk__output_t **out, xmlNodePtr *xml) {
return rc;
}
- stonith__register_messages(*out);
return rc;
}
--
1.8.3.1
From 27677a6d03ba42aeb0d6a971df9d9b8861232903 Mon Sep 17 00:00:00 2001
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
Date: Tue, 24 Nov 2020 16:19:59 +0100
Subject: [PATCH 2/2] API: libpacemaker: add public API functions for cluster
queries
---
include/pacemaker.h | 45 +++++++++++++++++++++-
lib/pacemaker/pcmk_cluster_queries.c | 75 ++++++++++++++++++++++++++++++++++++
2 files changed, 118 insertions(+), 2 deletions(-)
diff --git a/include/pacemaker.h b/include/pacemaker.h
index a1e76d0..b2a73cd 100644
--- a/include/pacemaker.h
+++ b/include/pacemaker.h
@@ -14,8 +14,6 @@
extern "C" {
#endif
-#ifdef BUILD_PUBLIC_LIBPACEMAKER
-
/**
* \file
* \brief High Level API
@@ -26,6 +24,49 @@ extern "C" {
# include <libxml/tree.h>
/*!
+ * \brief Get controller status
+ *
+ * \param[in,out] xml The destination for the result, as an XML tree.
+ * \param[in] dest_node Destination node for request
+ * \param[in] message_timeout_ms Message timeout
+ *
+ * \return Standard Pacemaker return code
+ */
+int pcmk_controller_status(xmlNodePtr *xml, char *dest_node, unsigned int message_timeout_ms);
+
+/*!
+ * \brief Get designated controller
+ *
+ * \param[in,out] xml The destination for the result, as an XML tree.
+ * \param[in] message_timeout_ms Message timeout
+ *
+ * \return Standard Pacemaker return code
+ */
+int pcmk_designated_controller(xmlNodePtr *xml, unsigned int message_timeout_ms);
+
+/*!
+ * \brief Get pacemakerd status
+ *
+ * \param[in,out] xml The destination for the result, as an XML tree.
+ * \param[in] ipc_name IPC name for request
+ * \param[in] message_timeout_ms Message timeout
+ *
+ * \return Standard Pacemaker return code
+ */
+int pcmk_pacemakerd_status(xmlNodePtr *xml, char *ipc_name, unsigned int message_timeout_ms);
+
+#ifdef BUILD_PUBLIC_LIBPACEMAKER
+
+/*!
+ * \brief Get nodes list
+ *
+ * \param[in,out] xml The destination for the result, as an XML tree.
+ *
+ * \return Standard Pacemaker return code
+ */
+int pcmk_list_nodes(xmlNodePtr *xml);
+
+/*!
* \brief Perform a STONITH action.
*
* \param[in] st A connection to the STONITH API.
diff --git a/lib/pacemaker/pcmk_cluster_queries.c b/lib/pacemaker/pcmk_cluster_queries.c
index 8d729eb..c705b7f 100644
--- a/lib/pacemaker/pcmk_cluster_queries.c
+++ b/lib/pacemaker/pcmk_cluster_queries.c
@@ -1,6 +1,7 @@
#include <glib.h> // gboolean, GMainLoop, etc.
#include <libxml/tree.h> // xmlNode
+#include <pacemaker.h>
#include <pacemaker-internal.h>
#include <crm/crm.h>
@@ -282,6 +283,24 @@ pcmk__controller_status(pcmk__output_t *out, char *dest_node, guint message_time
}
int
+pcmk_controller_status(xmlNodePtr *xml, char *dest_node, unsigned int message_timeout_ms)
+{
+ pcmk__output_t *out = NULL;
+ int rc = pcmk_rc_ok;
+
+ rc = pcmk__out_prologue(&out, xml);
+ if (rc != pcmk_rc_ok) {
+ return rc;
+ }
+
+ pcmk__register_lib_messages(out);
+
+ rc = pcmk__controller_status(out, dest_node, (guint) message_timeout_ms);
+ pcmk__out_epilogue(out, xml, rc);
+ return rc;
+}
+
+int
pcmk__designated_controller(pcmk__output_t *out, guint message_timeout_ms)
{
data_t data = {
@@ -309,6 +328,24 @@ pcmk__designated_controller(pcmk__output_t *out, guint message_timeout_ms)
}
int
+pcmk_designated_controller(xmlNodePtr *xml, unsigned int message_timeout_ms)
+{
+ pcmk__output_t *out = NULL;
+ int rc = pcmk_rc_ok;
+
+ rc = pcmk__out_prologue(&out, xml);
+ if (rc != pcmk_rc_ok) {
+ return rc;
+ }
+
+ pcmk__register_lib_messages(out);
+
+ rc = pcmk__designated_controller(out, (guint) message_timeout_ms);
+ pcmk__out_epilogue(out, xml, rc);
+ return rc;
+}
+
+int
pcmk__pacemakerd_status(pcmk__output_t *out, char *ipc_name, guint message_timeout_ms)
{
data_t data = {
@@ -335,6 +372,24 @@ pcmk__pacemakerd_status(pcmk__output_t *out, char *ipc_name, guint message_timeo
return data.rc;
}
+int
+pcmk_pacemakerd_status(xmlNodePtr *xml, char *ipc_name, unsigned int message_timeout_ms)
+{
+ pcmk__output_t *out = NULL;
+ int rc = pcmk_rc_ok;
+
+ rc = pcmk__out_prologue(&out, xml);
+ if (rc != pcmk_rc_ok) {
+ return rc;
+ }
+
+ pcmk__register_lib_messages(out);
+
+ rc = pcmk__pacemakerd_status(out, ipc_name, (guint) message_timeout_ms);
+ pcmk__out_epilogue(out, xml, rc);
+ return rc;
+}
+
// \return Standard Pacemaker return code
int
pcmk__list_nodes(pcmk__output_t *out, gboolean BASH_EXPORT)
@@ -361,6 +416,26 @@ pcmk__list_nodes(pcmk__output_t *out, gboolean BASH_EXPORT)
return pcmk_legacy2rc(rc);
}
+#ifdef BUILD_PUBLIC_LIBPACEMAKER
+int
+pcmk_list_nodes(xmlNodePtr *xml)
+{
+ pcmk__output_t *out = NULL;
+ int rc = pcmk_rc_ok;
+
+ rc = pcmk__out_prologue(&out, xml);
+ if (rc != pcmk_rc_ok) {
+ return rc;
+ }
+
+ pcmk__register_lib_messages(out);
+
+ rc = pcmk__list_nodes(out, FALSE);
+ pcmk__out_epilogue(out, xml, rc);
+ return rc;
+}
+#endif
+
// remove when parameters removed from tools/crmadmin.c
int
pcmk__shutdown_controller(pcmk__output_t *out, char *dest_node)
--
1.8.3.1

View File

@ -1,114 +0,0 @@
From 12b30c920dd15287a7b295475ce1cc4a6cb1f43f Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Tue, 8 Dec 2020 15:48:38 -0500
Subject: [PATCH] Fix: scheduler: Don't output a resource header with no list.
If there's no resources to print, don't output just the header with
nothing under it. This potentially comes up if there are only inactive
resources, but inactive_resources is FALSE.
---
lib/pengine/pe_output.c | 48 ++++++++++++++++++++++++++++++++++++------------
1 file changed, 36 insertions(+), 12 deletions(-)
diff --git a/lib/pengine/pe_output.c b/lib/pengine/pe_output.c
index 5562eb6..f1a6b43 100644
--- a/lib/pengine/pe_output.c
+++ b/lib/pengine/pe_output.c
@@ -1761,6 +1761,21 @@ resource_history_xml(pcmk__output_t *out, va_list args) {
return pcmk_rc_ok;
}
+static void
+print_resource_header(pcmk__output_t *out, gboolean group_by_node,
+ gboolean inactive_resources)
+{
+ if (group_by_node) {
+ /* Active resources have already been printed by node */
+ out->begin_list(out, NULL, NULL, "Inactive Resources");
+ } else if (inactive_resources) {
+ out->begin_list(out, NULL, NULL, "Full List of Resources");
+ } else {
+ out->begin_list(out, NULL, NULL, "Active Resources");
+ }
+}
+
+
PCMK__OUTPUT_ARGS("resource-list", "pe_working_set_t *", "unsigned int", "gboolean",
"gboolean", "gboolean", "gboolean", "GList *", "GList *", "gboolean")
static int
@@ -1778,6 +1793,7 @@ resource_list(pcmk__output_t *out, va_list args)
GList *rsc_iter;
int rc = pcmk_rc_no_output;
+ bool printed_header = false;
/* If we already showed active resources by node, and
* we're not showing inactive resources, we have nothing to do
@@ -1786,22 +1802,15 @@ resource_list(pcmk__output_t *out, va_list args)
return rc;
}
- PCMK__OUTPUT_SPACER_IF(out, print_spacer);
-
- if (group_by_node) {
- /* Active resources have already been printed by node */
- out->begin_list(out, NULL, NULL, "Inactive Resources");
- } else if (inactive_resources) {
- out->begin_list(out, NULL, NULL, "Full List of Resources");
- } else {
- out->begin_list(out, NULL, NULL, "Active Resources");
- }
-
/* If we haven't already printed resources grouped by node,
* and brief output was requested, print resource summary */
if (brief_output && !group_by_node) {
GList *rscs = pe__filter_rsc_list(data_set->resources, only_rsc);
+ PCMK__OUTPUT_SPACER_IF(out, print_spacer);
+ print_resource_header(out, group_by_node, inactive_resources);
+ printed_header = true;
+
pe__rscs_brief_output(out, rscs, print_opts, inactive_resources);
g_list_free(rscs);
}
@@ -1839,6 +1848,12 @@ resource_list(pcmk__output_t *out, va_list args)
continue;
}
+ if (!printed_header) {
+ PCMK__OUTPUT_SPACER_IF(out, print_spacer);
+ print_resource_header(out, group_by_node, inactive_resources);
+ printed_header = true;
+ }
+
/* Print this resource */
x = out->message(out, crm_map_element_name(rsc->xml), print_opts, rsc,
only_node, only_rsc);
@@ -1848,6 +1863,12 @@ resource_list(pcmk__output_t *out, va_list args)
}
if (print_summary && rc != pcmk_rc_ok) {
+ if (!printed_header) {
+ PCMK__OUTPUT_SPACER_IF(out, print_spacer);
+ print_resource_header(out, group_by_node, inactive_resources);
+ printed_header = true;
+ }
+
if (group_by_node) {
out->list_item(out, NULL, "No inactive resources");
} else if (inactive_resources) {
@@ -1857,7 +1878,10 @@ resource_list(pcmk__output_t *out, va_list args)
}
}
- out->end_list(out);
+ if (printed_header) {
+ out->end_list(out);
+ }
+
return rc;
}
--
1.8.3.1

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +0,0 @@
From a66f63e1001c2c93e286978c0383b4256abfce6b Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Mon, 4 Jan 2021 16:46:52 -0500
Subject: [PATCH] Test: cts: Distribute the new constraints.xml file.
---
cts/Makefile.am | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/cts/Makefile.am b/cts/Makefile.am
index 6abb42f..5666a9f 100644
--- a/cts/Makefile.am
+++ b/cts/Makefile.am
@@ -60,7 +60,8 @@ cts_SCRIPTS = CTSlab.py \
pacemaker-cts-dummyd
clidir = $(testdir)/cli
-dist_cli_DATA = cli/crm_diff_new.xml \
+dist_cli_DATA = cli/constraints.xml \
+ cli/crm_diff_new.xml \
cli/crm_diff_old.xml \
cli/crm_mon.xml \
cli/crm_mon-partial.xml \
--
1.8.3.1

View File

@ -1,47 +0,0 @@
From c3e2edb78e6d0b6ffc8acbe8fc7caef058b35d76 Mon Sep 17 00:00:00 2001
From: Reid Wahl <nrwahl@protonmail.com>
Date: Tue, 22 Dec 2020 22:28:46 -0800
Subject: [PATCH] Fix: liblrmd: Limit node name addition to proxied attrd
update commands
remote_proxy_cb() currently adds the remote node's name as
PCMK__XA_ATTR_NODE_NAME if that attribute is not explicitly set. This is
necessary for attrd update commands. For those, lack of an explicit node
name means to use the local node. Since requests are proxied to full
nodes, the node hosting the remote resource would be incorrectly treated
as the "local node", causing the attribute to be updated for the wrong
node.
However, for other commands, this is not the case. Lack of an explicit
node name can mean "all nodes" (as for CLEAR_FAILURE and QUERY), or a
node name may be ignored (as for REFRESH). In these cases (the
non-update commands), we don't want to add a node name automatically if
it's not explicitly set.
Resolves: RHBZ#1907726
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
---
lib/lrmd/proxy_common.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/lrmd/proxy_common.c b/lib/lrmd/proxy_common.c
index b8d889e..0f1e76a 100644
--- a/lib/lrmd/proxy_common.c
+++ b/lib/lrmd/proxy_common.c
@@ -259,7 +259,11 @@ remote_proxy_cb(lrmd_t *lrmd, const char *node_name, xmlNode *msg)
if (pcmk__str_eq(type, T_ATTRD, pcmk__str_casei)
&& crm_element_value(request,
- PCMK__XA_ATTR_NODE_NAME) == NULL) {
+ PCMK__XA_ATTR_NODE_NAME) == NULL
+ && pcmk__str_any_of(crm_element_value(request, PCMK__XA_TASK),
+ PCMK__ATTRD_CMD_UPDATE,
+ PCMK__ATTRD_CMD_UPDATE_BOTH,
+ PCMK__ATTRD_CMD_UPDATE_DELAY, NULL)) {
crm_xml_add(request, PCMK__XA_ATTR_NODE_NAME, proxy->node_name);
}
--
1.8.3.1

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +0,0 @@
From b1241e5026a4fd9a8674ad4b867c7efa3d8ef466 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Tue, 12 Jan 2021 09:03:03 -0600
Subject: [PATCH] Feature: tools: bump feature set for crm_resource --digests
... so script and tools can check for support
---
include/crm/crm.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/crm/crm.h b/include/crm/crm.h
index b07152c..4bbf46a 100644
--- a/include/crm/crm.h
+++ b/include/crm/crm.h
@@ -51,7 +51,7 @@ extern "C" {
* >=3.0.13: Fail counts include operation name and interval
* >=3.2.0: DC supports PCMK_LRM_OP_INVALID and PCMK_LRM_OP_NOT_CONNECTED
*/
-# define CRM_FEATURE_SET "3.6.3"
+# define CRM_FEATURE_SET "3.6.4"
# define EOS '\0'
# define DIMOF(a) ((int) (sizeof(a)/sizeof(a[0])) )
--
1.8.3.1

File diff suppressed because it is too large Load Diff

View File

@ -1,505 +0,0 @@
From cf0eebd913855f9ceda2864cbcd9cbd647fca055 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Wed, 13 Jan 2021 12:10:07 -0600
Subject: [PATCH] Build: xml: rename crm_resource API file
5aadeaf added an API schema 2.5 for crm_resource, but API schema 2.5 was
released with 2.0.5, so rename it to 2.6 to indicate it is a later change.
---
xml/api/crm_resource-2.5.rng | 238 -------------------------------------------
xml/api/crm_resource-2.6.rng | 238 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 238 insertions(+), 238 deletions(-)
delete mode 100644 xml/api/crm_resource-2.5.rng
create mode 100644 xml/api/crm_resource-2.6.rng
diff --git a/xml/api/crm_resource-2.5.rng b/xml/api/crm_resource-2.5.rng
deleted file mode 100644
index b49e24c..0000000
--- a/xml/api/crm_resource-2.5.rng
+++ /dev/null
@@ -1,238 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<grammar xmlns="http://relaxng.org/ns/structure/1.0"
- datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
-
- <start>
- <ref name="element-crm-resource"/>
- </start>
-
- <define name="element-crm-resource">
- <choice>
- <ref name="agents-list" />
- <ref name="alternatives-list" />
- <ref name="constraints-list" />
- <externalRef href="generic-list-2.4.rng"/>
- <element name="metadata"> <text/> </element>
- <ref name="locate-list" />
- <ref name="operations-list" />
- <ref name="providers-list" />
- <ref name="reasons-list" />
- <ref name="resource-check" />
- <ref name="resource-config" />
- <ref name="resources-list" />
- </choice>
- </define>
-
- <define name="agents-list">
- <element name="agents">
- <attribute name="standard"> <text/> </attribute>
- <optional>
- <attribute name="provider"> <text/> </attribute>
- </optional>
- <zeroOrMore>
- <element name="agent"> <text/> </element>
- </zeroOrMore>
- </element>
- </define>
-
- <define name="alternatives-list">
- <element name="providers">
- <attribute name="for"> <text/> </attribute>
- <zeroOrMore>
- <element name="provider"> <text/> </element>
- </zeroOrMore>
- </element>
- </define>
-
- <define name="constraints-list">
- <element name="constraints">
- <interleave>
- <zeroOrMore>
- <ref name="rsc-location" />
- </zeroOrMore>
- <zeroOrMore>
- <ref name="rsc-colocation" />
- </zeroOrMore>
- </interleave>
- </element>
- </define>
-
- <define name="locate-list">
- <element name="nodes">
- <attribute name="resource"> <text/> </attribute>
- <zeroOrMore>
- <element name="node">
- <optional>
- <attribute name="state"><value>promoted</value></attribute>
- </optional>
- <text/>
- </element>
- </zeroOrMore>
- </element>
- </define>
-
- <define name="rsc-location">
- <element name="rsc_location">
- <attribute name="node"> <text/> </attribute>
- <attribute name="rsc"> <text/> </attribute>
- <attribute name="id"> <text/> </attribute>
- <externalRef href="../score.rng"/>
- </element>
- </define>
-
- <define name="operations-list">
- <element name="operations">
- <oneOrMore>
- <ref name="element-operation-list" />
- </oneOrMore>
- </element>
- </define>
-
- <define name="providers-list">
- <element name="providers">
- <attribute name="standard"> <value>ocf</value> </attribute>
- <optional>
- <attribute name="agent"> <text/> </attribute>
- </optional>
- <zeroOrMore>
- <element name="provider"> <text/> </element>
- </zeroOrMore>
- </element>
- </define>
-
- <define name="reasons-list">
- <choice>
- <ref name="no-resource-or-uname"/>
- <ref name="resource-and-uname"/>
- <ref name="no-resource-but-uname"/>
- <ref name="resource-but-no-uname"/>
- </choice>
- </define>
-
- <define name="no-resource-or-uname">
- <element name="reason">
- <element name="resources">
- <zeroOrMore>
- <element name="resource">
- <attribute name="id"> <text/> </attribute>
- <attribute name="running"> <data type="boolean"/> </attribute>
- <ref name="resource-check"/>
- </element>
- </zeroOrMore>
- </element>
- </element>
- </define>
-
- <define name="resource-and-uname">
- <element name="reason">
- <attribute name="running_on"> <text/> </attribute>
- <ref name="resource-check"/>
- </element>
- </define>
-
- <define name="no-resource-but-uname">
- <element name="reason">
- <element name="resources">
- <zeroOrMore>
- <element name="resource">
- <attribute name="id"> <text/> </attribute>
- <attribute name="running"> <data type="boolean"/> </attribute>
- <attribute name="host"> <text/> </attribute>
- <ref name="resource-check"/>
- </element>
- </zeroOrMore>
- </element>
- </element>
- </define>
-
- <define name="resource-but-no-uname">
- <element name="reason">
- <attribute name="running"> <data type="boolean"/> </attribute>
- <ref name="resource-check"/>
- </element>
- </define>
-
- <define name="resource-config">
- <element name="resource_config">
- <externalRef href="resources-2.4.rng" />
- <element name="xml"> <text/> </element>
- </element>
- </define>
-
- <define name="resource-check">
- <element name="check">
- <attribute name="id"> <text/> </attribute>
- <optional>
- <choice>
- <attribute name="remain_stopped"><value>true</value></attribute>
- <attribute name="promotable"><value>false</value></attribute>
- </choice>
- </optional>
- <optional>
- <attribute name="unmanaged"><value>true</value></attribute>
- </optional>
- <optional>
- <attribute name="locked-to"> <text/> </attribute>
- </optional>
- </element>
- </define>
-
- <define name="resources-list">
- <element name="resources">
- <zeroOrMore>
- <externalRef href="resources-2.4.rng" />
- </zeroOrMore>
- </element>
- </define>
-
- <define name="rsc-colocation">
- <element name="rsc_colocation">
- <attribute name="id"> <text/> </attribute>
- <attribute name="rsc"> <text/> </attribute>
- <attribute name="with-rsc"> <text/> </attribute>
- <externalRef href="../score.rng"/>
- <optional>
- <attribute name="node-attribute"> <text/> </attribute>
- </optional>
- <optional>
- <attribute name="rsc-role">
- <ref name="attribute-roles"/>
- </attribute>
- </optional>
- <optional>
- <attribute name="with-rsc-role">
- <ref name="attribute-roles"/>
- </attribute>
- </optional>
- </element>
- </define>
-
- <define name="element-operation-list">
- <element name="operation">
- <optional>
- <group>
- <attribute name="rsc"> <text/> </attribute>
- <attribute name="agent"> <text/> </attribute>
- </group>
- </optional>
- <attribute name="op"> <text/> </attribute>
- <attribute name="node"> <text/> </attribute>
- <attribute name="call"> <data type="nonNegativeInteger" /> </attribute>
- <attribute name="rc"> <data type="nonNegativeInteger" /> </attribute>
- <optional>
- <attribute name="last-rc-change"> <text/> </attribute>
- <attribute name="exec-time"> <data type="nonNegativeInteger" /> </attribute>
- </optional>
- <attribute name="status"> <text/> </attribute>
- </element>
- </define>
-
- <define name="attribute-roles">
- <choice>
- <value>Stopped</value>
- <value>Started</value>
- <value>Master</value>
- <value>Slave</value>
- </choice>
- </define>
-</grammar>
diff --git a/xml/api/crm_resource-2.6.rng b/xml/api/crm_resource-2.6.rng
new file mode 100644
index 0000000..b49e24c
--- /dev/null
+++ b/xml/api/crm_resource-2.6.rng
@@ -0,0 +1,238 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<grammar xmlns="http://relaxng.org/ns/structure/1.0"
+ datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+
+ <start>
+ <ref name="element-crm-resource"/>
+ </start>
+
+ <define name="element-crm-resource">
+ <choice>
+ <ref name="agents-list" />
+ <ref name="alternatives-list" />
+ <ref name="constraints-list" />
+ <externalRef href="generic-list-2.4.rng"/>
+ <element name="metadata"> <text/> </element>
+ <ref name="locate-list" />
+ <ref name="operations-list" />
+ <ref name="providers-list" />
+ <ref name="reasons-list" />
+ <ref name="resource-check" />
+ <ref name="resource-config" />
+ <ref name="resources-list" />
+ </choice>
+ </define>
+
+ <define name="agents-list">
+ <element name="agents">
+ <attribute name="standard"> <text/> </attribute>
+ <optional>
+ <attribute name="provider"> <text/> </attribute>
+ </optional>
+ <zeroOrMore>
+ <element name="agent"> <text/> </element>
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <define name="alternatives-list">
+ <element name="providers">
+ <attribute name="for"> <text/> </attribute>
+ <zeroOrMore>
+ <element name="provider"> <text/> </element>
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <define name="constraints-list">
+ <element name="constraints">
+ <interleave>
+ <zeroOrMore>
+ <ref name="rsc-location" />
+ </zeroOrMore>
+ <zeroOrMore>
+ <ref name="rsc-colocation" />
+ </zeroOrMore>
+ </interleave>
+ </element>
+ </define>
+
+ <define name="locate-list">
+ <element name="nodes">
+ <attribute name="resource"> <text/> </attribute>
+ <zeroOrMore>
+ <element name="node">
+ <optional>
+ <attribute name="state"><value>promoted</value></attribute>
+ </optional>
+ <text/>
+ </element>
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <define name="rsc-location">
+ <element name="rsc_location">
+ <attribute name="node"> <text/> </attribute>
+ <attribute name="rsc"> <text/> </attribute>
+ <attribute name="id"> <text/> </attribute>
+ <externalRef href="../score.rng"/>
+ </element>
+ </define>
+
+ <define name="operations-list">
+ <element name="operations">
+ <oneOrMore>
+ <ref name="element-operation-list" />
+ </oneOrMore>
+ </element>
+ </define>
+
+ <define name="providers-list">
+ <element name="providers">
+ <attribute name="standard"> <value>ocf</value> </attribute>
+ <optional>
+ <attribute name="agent"> <text/> </attribute>
+ </optional>
+ <zeroOrMore>
+ <element name="provider"> <text/> </element>
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <define name="reasons-list">
+ <choice>
+ <ref name="no-resource-or-uname"/>
+ <ref name="resource-and-uname"/>
+ <ref name="no-resource-but-uname"/>
+ <ref name="resource-but-no-uname"/>
+ </choice>
+ </define>
+
+ <define name="no-resource-or-uname">
+ <element name="reason">
+ <element name="resources">
+ <zeroOrMore>
+ <element name="resource">
+ <attribute name="id"> <text/> </attribute>
+ <attribute name="running"> <data type="boolean"/> </attribute>
+ <ref name="resource-check"/>
+ </element>
+ </zeroOrMore>
+ </element>
+ </element>
+ </define>
+
+ <define name="resource-and-uname">
+ <element name="reason">
+ <attribute name="running_on"> <text/> </attribute>
+ <ref name="resource-check"/>
+ </element>
+ </define>
+
+ <define name="no-resource-but-uname">
+ <element name="reason">
+ <element name="resources">
+ <zeroOrMore>
+ <element name="resource">
+ <attribute name="id"> <text/> </attribute>
+ <attribute name="running"> <data type="boolean"/> </attribute>
+ <attribute name="host"> <text/> </attribute>
+ <ref name="resource-check"/>
+ </element>
+ </zeroOrMore>
+ </element>
+ </element>
+ </define>
+
+ <define name="resource-but-no-uname">
+ <element name="reason">
+ <attribute name="running"> <data type="boolean"/> </attribute>
+ <ref name="resource-check"/>
+ </element>
+ </define>
+
+ <define name="resource-config">
+ <element name="resource_config">
+ <externalRef href="resources-2.4.rng" />
+ <element name="xml"> <text/> </element>
+ </element>
+ </define>
+
+ <define name="resource-check">
+ <element name="check">
+ <attribute name="id"> <text/> </attribute>
+ <optional>
+ <choice>
+ <attribute name="remain_stopped"><value>true</value></attribute>
+ <attribute name="promotable"><value>false</value></attribute>
+ </choice>
+ </optional>
+ <optional>
+ <attribute name="unmanaged"><value>true</value></attribute>
+ </optional>
+ <optional>
+ <attribute name="locked-to"> <text/> </attribute>
+ </optional>
+ </element>
+ </define>
+
+ <define name="resources-list">
+ <element name="resources">
+ <zeroOrMore>
+ <externalRef href="resources-2.4.rng" />
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <define name="rsc-colocation">
+ <element name="rsc_colocation">
+ <attribute name="id"> <text/> </attribute>
+ <attribute name="rsc"> <text/> </attribute>
+ <attribute name="with-rsc"> <text/> </attribute>
+ <externalRef href="../score.rng"/>
+ <optional>
+ <attribute name="node-attribute"> <text/> </attribute>
+ </optional>
+ <optional>
+ <attribute name="rsc-role">
+ <ref name="attribute-roles"/>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="with-rsc-role">
+ <ref name="attribute-roles"/>
+ </attribute>
+ </optional>
+ </element>
+ </define>
+
+ <define name="element-operation-list">
+ <element name="operation">
+ <optional>
+ <group>
+ <attribute name="rsc"> <text/> </attribute>
+ <attribute name="agent"> <text/> </attribute>
+ </group>
+ </optional>
+ <attribute name="op"> <text/> </attribute>
+ <attribute name="node"> <text/> </attribute>
+ <attribute name="call"> <data type="nonNegativeInteger" /> </attribute>
+ <attribute name="rc"> <data type="nonNegativeInteger" /> </attribute>
+ <optional>
+ <attribute name="last-rc-change"> <text/> </attribute>
+ <attribute name="exec-time"> <data type="nonNegativeInteger" /> </attribute>
+ </optional>
+ <attribute name="status"> <text/> </attribute>
+ </element>
+ </define>
+
+ <define name="attribute-roles">
+ <choice>
+ <value>Stopped</value>
+ <value>Started</value>
+ <value>Master</value>
+ <value>Slave</value>
+ </choice>
+ </define>
+</grammar>
--
1.8.3.1

View File

@ -1,26 +0,0 @@
From 610e54caf9a695d3d108c87c735a630f2ea5657f Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Wed, 2 Dec 2020 15:09:35 -0600
Subject: [PATCH] Test: cts-fencing: update expected output
b16b24ed changed the order of some XML attributes
---
cts/cts-fencing.in | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cts/cts-fencing.in b/cts/cts-fencing.in
index c901c6c..224b5d4 100644
--- a/cts/cts-fencing.in
+++ b/cts/cts-fencing.in
@@ -1102,7 +1102,7 @@ class Tests(object):
test.add_cmd("stonith_admin", "--output-as=xml -F node3 -t 5 -V")
- test.add_cmd_check_stdout("stonith_admin", "--output-as=xml -H node3", 'status="success" .* action="off" target="node3"')
+ test.add_cmd_check_stdout("stonith_admin", "--output-as=xml -H node3", 'action="off" target="node3" .* status="success"')
# simple test of dynamic list query
for test_type in test_types:
--
1.8.3.1

View File

@ -1,962 +0,0 @@
From a32b6e14ba51fefbda2d4a699cf1c48dd3a1bb5a Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Thu, 7 Jan 2021 11:37:51 -0500
Subject: [PATCH 01/10] Fix: tools: Don't pass stonith history to
print_simple_status.
It's not being used.
---
tools/crm_mon.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index 4555516..729f6a1 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2004-2020 the Pacemaker project contributors
+ * Copyright 2004-2021 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -1451,14 +1451,13 @@ main(int argc, char **argv)
* \brief Print one-line status suitable for use with monitoring software
*
* \param[in] data_set Working set of CIB state
- * \param[in] history List of stonith actions
*
* \note This function's output (and the return code when the program exits)
* should conform to https://www.monitoring-plugins.org/doc/guidelines.html
*/
static void
print_simple_status(pcmk__output_t *out, pe_working_set_t * data_set,
- stonith_history_t *history, unsigned int mon_ops)
+ unsigned int mon_ops)
{
GListPtr gIter = NULL;
int nodes_online = 0;
@@ -2012,7 +2011,7 @@ mon_refresh_display(gpointer user_data)
break;
case mon_output_monitor:
- print_simple_status(out, mon_data_set, stonith_history, options.mon_ops);
+ print_simple_status(out, mon_data_set, options.mon_ops);
if (pcmk_is_set(options.mon_ops, mon_op_has_warnings)) {
clean_up(MON_STATUS_WARN);
return FALSE;
--
1.8.3.1
From 8b9c47089c70295bc0529671ba5991c6d831e14b Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Thu, 7 Jan 2021 13:17:04 -0500
Subject: [PATCH 02/10] Refactor: tools: Don't pass output_format to
mon_refresh_display.
output_format is a global variable.
---
tools/crm_mon.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index 729f6a1..b801560 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -827,7 +827,7 @@ cib_connect(gboolean full)
rc = cib->cmds->query(cib, NULL, &current_cib, cib_scope_local | cib_sync_call);
if (rc == pcmk_ok) {
- mon_refresh_display(&output_format);
+ mon_refresh_display(NULL);
}
if (rc == pcmk_ok && full) {
--
1.8.3.1
From a1b14ad96f12746167da8588dc086b20e6f6d1d6 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Thu, 7 Jan 2021 13:20:14 -0500
Subject: [PATCH 03/10] Refactor: tools: Remove unnecessary checks for cib !=
NULL.
cib is guaranteed to not be NULL at these points, so there's no need to
do an additional check. This code was leftover from a previous
reorganization that changed when the cib variable gets initialized.
---
tools/crm_mon.c | 41 +++++++++++++++++++----------------------
1 file changed, 19 insertions(+), 22 deletions(-)
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index b801560..1eedd38 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -1346,7 +1346,7 @@ main(int argc, char **argv)
/* Extra sanity checks when in CGI mode */
if (output_format == mon_output_cgi) {
- if (cib && cib->variant == cib_file) {
+ if (cib->variant == cib_file) {
g_set_error(&error, PCMK__EXITC_ERROR, CRM_EX_USAGE, "CGI mode used with CIB file");
return clean_up(CRM_EX_USAGE);
} else if (options.external_agent != NULL) {
@@ -1370,33 +1370,30 @@ main(int argc, char **argv)
crm_info("Starting %s", crm_system_name);
- if (cib) {
-
- do {
- if (!pcmk_is_set(options.mon_ops, mon_op_one_shot)) {
- print_as(output_format ,"Waiting until cluster is available on this node ...\n");
- }
- rc = cib_connect(!pcmk_is_set(options.mon_ops, mon_op_one_shot));
+ do {
+ if (!pcmk_is_set(options.mon_ops, mon_op_one_shot)) {
+ print_as(output_format ,"Waiting until cluster is available on this node ...\n");
+ }
+ rc = cib_connect(!pcmk_is_set(options.mon_ops, mon_op_one_shot));
- if (pcmk_is_set(options.mon_ops, mon_op_one_shot)) {
- break;
+ if (pcmk_is_set(options.mon_ops, mon_op_one_shot)) {
+ break;
- } else if (rc != pcmk_ok) {
- sleep(options.reconnect_msec / 1000);
+ } else if (rc != pcmk_ok) {
+ sleep(options.reconnect_msec / 1000);
#if CURSES_ENABLED
- if (output_format == mon_output_console) {
- clear();
- refresh();
- }
+ if (output_format == mon_output_console) {
+ clear();
+ refresh();
+ }
#endif
- } else {
- if (output_format == mon_output_html && out->dest != stdout) {
- printf("Writing html to %s ...\n", args->output_dest);
- }
+ } else {
+ if (output_format == mon_output_html && out->dest != stdout) {
+ printf("Writing html to %s ...\n", args->output_dest);
}
+ }
- } while (rc == -ENOTCONN);
- }
+ } while (rc == -ENOTCONN);
if (rc != pcmk_ok) {
if (output_format == mon_output_monitor) {
--
1.8.3.1
From fe5284a12765e775905bdfe58711c5733a063132 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Thu, 7 Jan 2021 14:15:40 -0500
Subject: [PATCH 04/10] Fix: tools: mon_refresh_display should return an int.
While GSourceFunc is defined as returning a boolean, our public API
mainloop function expect the dispatch function to return an int. So
change mon_refresh_display to do so.
---
tools/crm_mon.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index 1eedd38..8657a89 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -125,7 +125,7 @@ struct {
static void clean_up_connections(void);
static crm_exit_t clean_up(crm_exit_t exit_code);
static void crm_diff_update(const char *event, xmlNode * msg);
-static gboolean mon_refresh_display(gpointer user_data);
+static int mon_refresh_display(gpointer user_data);
static int cib_connect(gboolean full);
static void mon_st_callback_event(stonith_t * st, stonith_event_t * e);
static void mon_st_callback_display(stonith_t * st, stonith_event_t * e);
@@ -1925,7 +1925,7 @@ crm_diff_update(const char *event, xmlNode * msg)
kick_refresh(cib_updated);
}
-static gboolean
+static int
mon_refresh_display(gpointer user_data)
{
xmlNode *cib_copy = copy_xml(current_cib);
@@ -1940,7 +1940,7 @@ mon_refresh_display(gpointer user_data)
}
out->err(out, "Upgrade failed: %s", pcmk_strerror(-pcmk_err_schema_validation));
clean_up(CRM_EX_CONFIG);
- return FALSE;
+ return 0;
}
/* get the stonith-history if there is evidence we need it
@@ -1966,7 +1966,7 @@ mon_refresh_display(gpointer user_data)
}
free_xml(cib_copy);
out->err(out, "Reading stonith-history failed");
- return FALSE;
+ return 0;
}
if (mon_data_set == NULL) {
@@ -1995,7 +1995,7 @@ mon_refresh_display(gpointer user_data)
options.only_node, options.only_rsc) != 0) {
g_set_error(&error, PCMK__EXITC_ERROR, CRM_EX_CANTCREAT, "Critical: Unable to output html file");
clean_up(CRM_EX_CANTCREAT);
- return FALSE;
+ return 0;
}
break;
@@ -2044,7 +2044,7 @@ mon_refresh_display(gpointer user_data)
stonith_history_free(stonith_history);
stonith_history = NULL;
pe_reset_working_set(mon_data_set);
- return TRUE;
+ return 1;
}
static void
--
1.8.3.1
From 7f88a5a428ed73fb5161096ece2517abe1119f06 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Thu, 7 Jan 2021 16:59:02 -0500
Subject: [PATCH 05/10] Refactor: tools: Change a conditional in cib_connect.
This allows unindenting everything that occurs inside that conditional,
which I think makes it a little bit easier to understand what is going
on.
---
tools/crm_mon.c | 86 +++++++++++++++++++++++++++++----------------------------
1 file changed, 44 insertions(+), 42 deletions(-)
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index 8657a89..b8ba56b 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -804,55 +804,57 @@ cib_connect(gboolean full)
}
}
- if (cib->state != cib_connected_query && cib->state != cib_connected_command) {
- crm_trace("Connecting to the CIB");
-
- /* Hack: the CIB signon will print the prompt for a password if needed,
- * but to stderr. If we're in curses, show it on the screen instead.
- *
- * @TODO Add a password prompt (maybe including input) function to
- * pcmk__output_t and use it in libcib.
- */
- if ((output_format == mon_output_console) && need_pass && (cib->variant == cib_remote)) {
- need_pass = FALSE;
- print_as(output_format, "Password:");
- }
+ if (cib->state == cib_connected_query || cib->state == cib_connected_command) {
+ return rc;
+ }
- rc = cib->cmds->signon(cib, crm_system_name, cib_query);
- if (rc != pcmk_ok) {
- out->err(out, "Could not connect to the CIB: %s",
- pcmk_strerror(rc));
- return rc;
- }
+ crm_trace("Connecting to the CIB");
- rc = cib->cmds->query(cib, NULL, &current_cib, cib_scope_local | cib_sync_call);
- if (rc == pcmk_ok) {
- mon_refresh_display(NULL);
- }
+ /* Hack: the CIB signon will print the prompt for a password if needed,
+ * but to stderr. If we're in curses, show it on the screen instead.
+ *
+ * @TODO Add a password prompt (maybe including input) function to
+ * pcmk__output_t and use it in libcib.
+ */
+ if ((output_format == mon_output_console) && need_pass && (cib->variant == cib_remote)) {
+ need_pass = FALSE;
+ print_as(output_format, "Password:");
+ }
- if (rc == pcmk_ok && full) {
- if (rc == pcmk_ok) {
- rc = cib->cmds->set_connection_dnotify(cib, mon_cib_connection_destroy_regular);
- if (rc == -EPROTONOSUPPORT) {
- print_as
- (output_format, "Notification setup not supported, won't be able to reconnect after failure");
- if (output_format == mon_output_console) {
- sleep(2);
- }
- rc = pcmk_ok;
- }
+ rc = cib->cmds->signon(cib, crm_system_name, cib_query);
+ if (rc != pcmk_ok) {
+ out->err(out, "Could not connect to the CIB: %s",
+ pcmk_strerror(rc));
+ return rc;
+ }
- }
+ rc = cib->cmds->query(cib, NULL, &current_cib, cib_scope_local | cib_sync_call);
+ if (rc == pcmk_ok) {
+ mon_refresh_display(NULL);
+ }
- if (rc == pcmk_ok) {
- cib->cmds->del_notify_callback(cib, T_CIB_DIFF_NOTIFY, crm_diff_update);
- rc = cib->cmds->add_notify_callback(cib, T_CIB_DIFF_NOTIFY, crm_diff_update);
+ if (rc == pcmk_ok && full) {
+ if (rc == pcmk_ok) {
+ rc = cib->cmds->set_connection_dnotify(cib, mon_cib_connection_destroy_regular);
+ if (rc == -EPROTONOSUPPORT) {
+ print_as
+ (output_format, "Notification setup not supported, won't be able to reconnect after failure");
+ if (output_format == mon_output_console) {
+ sleep(2);
+ }
+ rc = pcmk_ok;
}
- if (rc != pcmk_ok) {
- out->err(out, "Notification setup failed, could not monitor CIB actions");
- clean_up_connections();
- }
+ }
+
+ if (rc == pcmk_ok) {
+ cib->cmds->del_notify_callback(cib, T_CIB_DIFF_NOTIFY, crm_diff_update);
+ rc = cib->cmds->add_notify_callback(cib, T_CIB_DIFF_NOTIFY, crm_diff_update);
+ }
+
+ if (rc != pcmk_ok) {
+ out->err(out, "Notification setup failed, could not monitor CIB actions");
+ clean_up_connections();
}
}
return rc;
--
1.8.3.1
From 178ba17e4ee62bef28f8e71cad2c002f823661b5 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Thu, 7 Jan 2021 17:37:36 -0500
Subject: [PATCH 06/10] Refactor: tools: Remove an unnecessary conditional in
cib_connect.
---
tools/crm_mon.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index b8ba56b..36249e8 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -834,17 +834,14 @@ cib_connect(gboolean full)
}
if (rc == pcmk_ok && full) {
- if (rc == pcmk_ok) {
- rc = cib->cmds->set_connection_dnotify(cib, mon_cib_connection_destroy_regular);
- if (rc == -EPROTONOSUPPORT) {
- print_as
- (output_format, "Notification setup not supported, won't be able to reconnect after failure");
- if (output_format == mon_output_console) {
- sleep(2);
- }
- rc = pcmk_ok;
+ rc = cib->cmds->set_connection_dnotify(cib, mon_cib_connection_destroy_regular);
+ if (rc == -EPROTONOSUPPORT) {
+ print_as
+ (output_format, "Notification setup not supported, won't be able to reconnect after failure");
+ if (output_format == mon_output_console) {
+ sleep(2);
}
-
+ rc = pcmk_ok;
}
if (rc == pcmk_ok) {
--
1.8.3.1
From 33bac5886417afc5c7bbf56f4d31e0e36f8ae947 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Fri, 8 Jan 2021 10:00:50 -0500
Subject: [PATCH 07/10] Refactor: tools: Simplify another conditional in
crm_mon.
---
tools/crm_mon.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index 36249e8..8b47bbc 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -1386,10 +1386,8 @@ main(int argc, char **argv)
refresh();
}
#endif
- } else {
- if (output_format == mon_output_html && out->dest != stdout) {
- printf("Writing html to %s ...\n", args->output_dest);
- }
+ } else if (output_format == mon_output_html && out->dest != stdout) {
+ printf("Writing html to %s ...\n", args->output_dest);
}
} while (rc == -ENOTCONN);
--
1.8.3.1
From 40bc8b3147e7ebef4318211fa69973a8b5d32e79 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Fri, 8 Jan 2021 12:12:37 -0500
Subject: [PATCH 08/10] Refactor: libcrmcommon,tools,daemons: Put common xpath
code in one place.
---
configure.ac | 1 +
daemons/controld/controld_te_callbacks.c | 26 +++-----------
include/crm/common/xml_internal.h | 14 +++++++-
lib/common/tests/Makefile.am | 2 +-
lib/common/tests/xpath/Makefile.am | 29 +++++++++++++++
lib/common/tests/xpath/pcmk__xpath_node_id_test.c | 43 +++++++++++++++++++++++
lib/common/xpath.c | 34 +++++++++++++++++-
tools/crm_mon.c | 25 ++-----------
8 files changed, 127 insertions(+), 47 deletions(-)
create mode 100644 lib/common/tests/xpath/Makefile.am
create mode 100644 lib/common/tests/xpath/pcmk__xpath_node_id_test.c
diff --git a/configure.ac b/configure.ac
index 5959116..ce0f1fe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1920,6 +1920,7 @@ AC_CONFIG_FILES(Makefile \
lib/common/tests/operations/Makefile \
lib/common/tests/strings/Makefile \
lib/common/tests/utils/Makefile \
+ lib/common/tests/xpath/Makefile \
lib/cluster/Makefile \
lib/cib/Makefile \
lib/gnu/Makefile \
diff --git a/daemons/controld/controld_te_callbacks.c b/daemons/controld/controld_te_callbacks.c
index 66fc645..4e3e4e6 100644
--- a/daemons/controld/controld_te_callbacks.c
+++ b/daemons/controld/controld_te_callbacks.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2004-2020 the Pacemaker project contributors
+ * Copyright 2004-2021 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -276,24 +276,6 @@ process_resource_updates(const char *node, xmlNode *xml, xmlNode *change,
}
}
-#define NODE_PATT "/lrm[@id="
-static char *get_node_from_xpath(const char *xpath)
-{
- char *nodeid = NULL;
- char *tmp = strstr(xpath, NODE_PATT);
-
- if(tmp) {
- tmp += strlen(NODE_PATT);
- tmp += 1;
-
- nodeid = strdup(tmp);
- tmp = strstr(nodeid, "\'");
- CRM_ASSERT(tmp);
- tmp[0] = 0;
- }
- return nodeid;
-}
-
static char *extract_node_uuid(const char *xpath)
{
char *mutable_path = strdup(xpath);
@@ -522,19 +504,19 @@ te_update_diff_v2(xmlNode *diff)
process_resource_updates(ID(match), match, change, op, xpath);
} else if (strcmp(name, XML_LRM_TAG_RESOURCES) == 0) {
- char *local_node = get_node_from_xpath(xpath);
+ char *local_node = pcmk__xpath_node_id(xpath, "lrm");
process_resource_updates(local_node, match, change, op, xpath);
free(local_node);
} else if (strcmp(name, XML_LRM_TAG_RESOURCE) == 0) {
- char *local_node = get_node_from_xpath(xpath);
+ char *local_node = pcmk__xpath_node_id(xpath, "lrm");
process_lrm_resource_diff(match, local_node);
free(local_node);
} else if (strcmp(name, XML_LRM_TAG_RSC_OP) == 0) {
- char *local_node = get_node_from_xpath(xpath);
+ char *local_node = pcmk__xpath_node_id(xpath, "lrm");
process_graph_event(match, local_node);
free(local_node);
diff --git a/include/crm/common/xml_internal.h b/include/crm/common/xml_internal.h
index 1e80bc6..d8694ee 100644
--- a/include/crm/common/xml_internal.h
+++ b/include/crm/common/xml_internal.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2020 the Pacemaker project contributors
+ * Copyright 2017-2021 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -273,4 +273,16 @@ pcmk__xe_first_attr(const xmlNode *xe)
return (xe == NULL)? NULL : xe->properties;
}
+/*!
+ * \internal
+ * \brief Extract the ID attribute from an XML element
+ *
+ * \param[in] xpath String to search
+ * \param[in] node Node to get the ID for
+ *
+ * \return ID attribute of \p node in xpath string \p xpath
+ */
+char *
+pcmk__xpath_node_id(const char *xpath, const char *node);
+
#endif // PCMK__XML_INTERNAL__H
diff --git a/lib/common/tests/Makefile.am b/lib/common/tests/Makefile.am
index 2c33cc5..4c6e8b4 100644
--- a/lib/common/tests/Makefile.am
+++ b/lib/common/tests/Makefile.am
@@ -1 +1 @@
-SUBDIRS = agents cmdline flags operations strings utils
+SUBDIRS = agents cmdline flags operations strings utils xpath
diff --git a/lib/common/tests/xpath/Makefile.am b/lib/common/tests/xpath/Makefile.am
new file mode 100644
index 0000000..7a53683
--- /dev/null
+++ b/lib/common/tests/xpath/Makefile.am
@@ -0,0 +1,29 @@
+#
+# Copyright 2021 the Pacemaker project contributors
+#
+# The version control history for this file may have further details.
+#
+# This source code is licensed under the GNU General Public License version 2
+# or later (GPLv2+) WITHOUT ANY WARRANTY.
+#
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
+LDADD = $(top_builddir)/lib/common/libcrmcommon.la
+
+include $(top_srcdir)/mk/glib-tap.mk
+
+# Add each test program here. Each test should be written as a little standalone
+# program using the glib unit testing functions. See the documentation for more
+# information.
+#
+# https://developer.gnome.org/glib/unstable/glib-Testing.html
+#
+# Add "_test" to the end of all test program names to simplify .gitignore.
+test_programs = pcmk__xpath_node_id_test
+
+# If any extra data needs to be added to the source distribution, add it to the
+# following list.
+dist_test_data =
+
+# If any extra data needs to be used by tests but should not be added to the
+# source distribution, add it to the following list.
+test_data =
diff --git a/lib/common/tests/xpath/pcmk__xpath_node_id_test.c b/lib/common/tests/xpath/pcmk__xpath_node_id_test.c
new file mode 100644
index 0000000..f6b5c10
--- /dev/null
+++ b/lib/common/tests/xpath/pcmk__xpath_node_id_test.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2021 the Pacemaker project contributors
+ *
+ * The version control history for this file may have further details.
+ *
+ * This source code is licensed under the GNU Lesser General Public License
+ * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
+ */
+
+#include <crm_internal.h>
+#include <crm/common/xml_internal.h>
+
+static void
+empty_input(void) {
+ g_assert_null(pcmk__xpath_node_id(NULL, "lrm"));
+ g_assert_null(pcmk__xpath_node_id("", "lrm"));
+ g_assert_null(pcmk__xpath_node_id("/blah/blah", NULL));
+ g_assert_null(pcmk__xpath_node_id("/blah/blah", ""));
+ g_assert_null(pcmk__xpath_node_id(NULL, NULL));
+}
+
+static void
+not_present(void) {
+ g_assert_null(pcmk__xpath_node_id("/some/xpath/string[@id='xyz']", "lrm"));
+ g_assert_null(pcmk__xpath_node_id("/some/xpath/containing[@id='lrm']", "lrm"));
+}
+
+static void
+present(void) {
+ g_assert_cmpint(strcmp(pcmk__xpath_node_id("/some/xpath/containing/lrm[@id='xyz']", "lrm"), "xyz"), ==, 0);
+ g_assert_cmpint(strcmp(pcmk__xpath_node_id("/some/other/lrm[@id='xyz']/xpath", "lrm"), "xyz"), ==, 0);
+}
+
+int
+main(int argc, char **argv)
+{
+ g_test_init(&argc, &argv, NULL);
+
+ g_test_add_func("/common/xpath/node_id/empty_input", empty_input);
+ g_test_add_func("/common/xpath/node_id/not_present", not_present);
+ g_test_add_func("/common/xpath/node_id/present", present);
+ return g_test_run();
+}
diff --git a/lib/common/xpath.c b/lib/common/xpath.c
index 6fa4941..7851a7c 100644
--- a/lib/common/xpath.c
+++ b/lib/common/xpath.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2004-2020 the Pacemaker project contributors
+ * Copyright 2004-2021 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -11,6 +11,7 @@
#include <stdio.h>
#include <string.h>
#include <crm/msg_xml.h>
+#include <crm/common/xml_internal.h>
#include "crmcommon_private.h"
/*
@@ -297,3 +298,34 @@ xml_get_path(xmlNode *xml)
}
return NULL;
}
+
+char *
+pcmk__xpath_node_id(const char *xpath, const char *node)
+{
+ char *retval = NULL;
+ char *patt = NULL;
+ char *start = NULL;
+ char *end = NULL;
+
+ if (node == NULL || xpath == NULL) {
+ return retval;
+ }
+
+ patt = crm_strdup_printf("/%s[@id=", node);
+ start = strstr(xpath, patt);
+
+ if (!start) {
+ free(patt);
+ return retval;
+ }
+
+ start += strlen(patt);
+ start++;
+
+ end = strstr(start, "\'");
+ CRM_ASSERT(end);
+ retval = strndup(start, end-start);
+
+ free(patt);
+ return retval;
+}
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index 8b47bbc..ff1b86b 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -1719,25 +1719,6 @@ mon_trigger_refresh(gpointer user_data)
return FALSE;
}
-#define NODE_PATT "/lrm[@id="
-static char *
-get_node_from_xpath(const char *xpath)
-{
- char *nodeid = NULL;
- char *tmp = strstr(xpath, NODE_PATT);
-
- if(tmp) {
- tmp += strlen(NODE_PATT);
- tmp += 1;
-
- nodeid = strdup(tmp);
- tmp = strstr(nodeid, "\'");
- CRM_ASSERT(tmp);
- tmp[0] = 0;
- }
- return nodeid;
-}
-
static void
crm_diff_update_v2(const char *event, xmlNode * msg)
{
@@ -1822,19 +1803,19 @@ crm_diff_update_v2(const char *event, xmlNode * msg)
handle_rsc_op(match, node);
} else if(strcmp(name, XML_LRM_TAG_RESOURCES) == 0) {
- char *local_node = get_node_from_xpath(xpath);
+ char *local_node = pcmk__xpath_node_id(xpath, "lrm");
handle_rsc_op(match, local_node);
free(local_node);
} else if(strcmp(name, XML_LRM_TAG_RESOURCE) == 0) {
- char *local_node = get_node_from_xpath(xpath);
+ char *local_node = pcmk__xpath_node_id(xpath, "lrm");
handle_rsc_op(match, local_node);
free(local_node);
} else if(strcmp(name, XML_LRM_TAG_RSC_OP) == 0) {
- char *local_node = get_node_from_xpath(xpath);
+ char *local_node = pcmk__xpath_node_id(xpath, "lrm");
handle_rsc_op(match, local_node);
free(local_node);
--
1.8.3.1
From b0126373d8b2a739ec5b985a7e1f530e850618d3 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Mon, 11 Jan 2021 10:20:11 -0500
Subject: [PATCH 09/10] Refactor: libpacemaker: Move reduce_stonith_history
into the library.
And also rename it to pcmk__reduce_fence_history. I don't see anywhere
else that could use this function at the moment, but it seems too
generic to keep in crm_mon.
---
include/pcmki/pcmki_fence.h | 16 +++++++++++++-
lib/pacemaker/pcmk_fence.c | 45 ++++++++++++++++++++++++++++++++++++++-
tools/crm_mon.c | 52 +--------------------------------------------
3 files changed, 60 insertions(+), 53 deletions(-)
diff --git a/include/pcmki/pcmki_fence.h b/include/pcmki/pcmki_fence.h
index 241d030..d4cef68 100644
--- a/include/pcmki/pcmki_fence.h
+++ b/include/pcmki/pcmki_fence.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2019-2020 the Pacemaker project contributors
+ * Copyright 2019-2021 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -219,4 +219,18 @@ int pcmk__fence_validate(pcmk__output_t *out, stonith_t *st, const char *agent,
const char *id, stonith_key_value_t *params,
unsigned int timeout);
+/**
+ * \brief Reduce the STONITH history
+ *
+ * STONITH history is reduced as follows:
+ * - The last successful action of every action-type and target is kept
+ * - For failed actions, who failed is kept
+ * - All actions in progress are kept
+ *
+ * \param[in] history List of STONITH actions
+ *
+ * \return The reduced history
+ */
+stonith_history_t *
+pcmk__reduce_fence_history(stonith_history_t *history);
#endif
diff --git a/lib/pacemaker/pcmk_fence.c b/lib/pacemaker/pcmk_fence.c
index d591379..34540cc 100644
--- a/lib/pacemaker/pcmk_fence.c
+++ b/lib/pacemaker/pcmk_fence.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2009-2020 the Pacemaker project contributors
+ * Copyright 2009-2021 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -520,3 +520,46 @@ pcmk_fence_validate(xmlNodePtr *xml, stonith_t *st, const char *agent,
return rc;
}
#endif
+
+stonith_history_t *
+pcmk__reduce_fence_history(stonith_history_t *history)
+{
+ stonith_history_t *new, *hp, *np;
+
+ if (!history) {
+ return history;
+ }
+
+ new = history;
+ hp = new->next;
+ new->next = NULL;
+
+ while (hp) {
+ stonith_history_t *hp_next = hp->next;
+
+ hp->next = NULL;
+
+ for (np = new; ; np = np->next) {
+ if ((hp->state == st_done) || (hp->state == st_failed)) {
+ /* action not in progress */
+ if (pcmk__str_eq(hp->target, np->target, pcmk__str_casei) &&
+ pcmk__str_eq(hp->action, np->action, pcmk__str_casei) &&
+ (hp->state == np->state) &&
+ ((hp->state == st_done) ||
+ pcmk__str_eq(hp->delegate, np->delegate, pcmk__str_casei))) {
+ /* purge older hp */
+ stonith_history_free(hp);
+ break;
+ }
+ }
+
+ if (!np->next) {
+ np->next = hp;
+ break;
+ }
+ }
+ hp = hp_next;
+ }
+
+ return new;
+}
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index ff1b86b..2179f53 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -1520,56 +1520,6 @@ print_simple_status(pcmk__output_t *out, pe_working_set_t * data_set,
/* coverity[leaked_storage] False positive */
}
-/*!
- * \internal
- * \brief Reduce the stonith-history
- * for successful actions we keep the last of every action-type & target
- * for failed actions we record as well who had failed
- * for actions in progress we keep full track
- *
- * \param[in] history List of stonith actions
- *
- */
-static stonith_history_t *
-reduce_stonith_history(stonith_history_t *history)
-{
- stonith_history_t *new = history, *hp, *np;
-
- if (new) {
- hp = new->next;
- new->next = NULL;
-
- while (hp) {
- stonith_history_t *hp_next = hp->next;
-
- hp->next = NULL;
-
- for (np = new; ; np = np->next) {
- if ((hp->state == st_done) || (hp->state == st_failed)) {
- /* action not in progress */
- if (pcmk__str_eq(hp->target, np->target, pcmk__str_casei) &&
- pcmk__str_eq(hp->action, np->action, pcmk__str_casei) &&
- (hp->state == np->state) &&
- ((hp->state == st_done) ||
- pcmk__str_eq(hp->delegate, np->delegate, pcmk__str_casei))) {
- /* purge older hp */
- stonith_history_free(hp);
- break;
- }
- }
-
- if (!np->next) {
- np->next = hp;
- break;
- }
- }
- hp = hp_next;
- }
- }
-
- return new;
-}
-
static int
send_custom_trap(const char *node, const char *rsc, const char *task, int target_rc, int rc,
int status, const char *desc)
@@ -1935,7 +1885,7 @@ mon_refresh_display(gpointer user_data)
if (!pcmk_is_set(options.mon_ops, mon_op_fence_full_history)
&& (output_format != mon_output_xml)) {
- stonith_history = reduce_stonith_history(stonith_history);
+ stonith_history = pcmk__reduce_fence_history(stonith_history);
}
break; /* all other cases are errors */
}
--
1.8.3.1
From af3f1368bc76eb498c2c96b3eda9324b579c9380 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Tue, 12 Jan 2021 15:46:55 -0500
Subject: [PATCH 10/10] Low: tools: Adjust fencing shown indicator in crm_mon.
If any of the various fencing flags are set, but not all of them, no '*'
will be shown next to the fencing line in the interactive change screen.
This makes it seem like fencing should not be shown, and hitting 'm'
should toggle the fencing display on. However, that's not the case and
hitting 'm' will actually toggle fencing off. Hitting it again will
toggle it on and the '*' will appear.
This is confusing, so just display the '*' if any fencing flag is set.
---
tools/crm_mon.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index 2179f53..8ec97bb 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -984,7 +984,10 @@ detect_user_input(GIOChannel *channel, GIOCondition condition, gpointer user_dat
print_option_help(out, 'R', pcmk_is_set(options.mon_ops, mon_op_print_clone_detail));
print_option_help(out, 'b', pcmk_is_set(options.mon_ops, mon_op_print_brief));
print_option_help(out, 'j', pcmk_is_set(options.mon_ops, mon_op_print_pending));
- print_option_help(out, 'm', pcmk_is_set(show, mon_show_fencing_all));
+ print_option_help(out, 'm', pcmk_any_flags_set(show,
+ mon_show_fence_failed
+ |mon_show_fence_pending
+ |mon_show_fence_worked));
out->info(out, "%s", "\nToggle fields via field letter, type any other key to return");
}
--
1.8.3.1

File diff suppressed because it is too large Load Diff

View File

@ -1,202 +0,0 @@
From bc60f9c84bd6f0fa4d73db8d140030dfcdbf4f5e Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Tue, 19 Jan 2021 15:58:36 -0500
Subject: [PATCH 1/2] Fix: tools: Describe interactive crm_mon use in help and
man page.
---
tools/crm_mon.8.inc | 3 +++
tools/crm_mon.c | 4 ++++
tools/fix-manpages | 2 +-
3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/tools/crm_mon.8.inc b/tools/crm_mon.8.inc
index e4cd7e3..6b46d7b 100644
--- a/tools/crm_mon.8.inc
+++ b/tools/crm_mon.8.inc
@@ -12,3 +12,6 @@ crm_mon mode [options]
/command line arguments./
.SH TIME SPECIFICATION
+
+/or --exclude=list./
+.SH INTERACTIVE USE
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index 083b7ae..aafc80f 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -1062,6 +1062,10 @@ build_arg_context(pcmk__common_args_t *args, GOptionGroup **group) {
"times on the command line, and each can give a comma-separated list of sections.\n"
"The options are applied to the default set, from left to right as seen on the\n"
"command line. For a list of valid sections, pass --include=list or --exclude=list.\n\n"
+ "Interactive Use:\n\n"
+ "When run interactively, crm_mon can be told to hide and display various sections\n"
+ "of output. To see a help screen explaining the options, hit '?'. Any key stroke\n"
+ "aside from those listed will cause the screen to refresh.\n\n"
"Examples:\n\n"
"Display the cluster status on the console with updates as they occur:\n\n"
"\tcrm_mon\n\n"
diff --git a/tools/fix-manpages b/tools/fix-manpages
index 714ecce..f1f6f0d 100644
--- a/tools/fix-manpages
+++ b/tools/fix-manpages
@@ -26,7 +26,7 @@
# This leaves the --help-all output looking good and removes redundant
# stuff from the man page. Feel free to add additional headers here.
# Not all tools will have all headers.
-/.SH NOTES\|.SH OPERATION SPECIFICATION\|.SH OUTPUT CONTROL\|.SH TIME SPECIFICATION/{ n
+/.SH NOTES\|.SH INTERACTIVE USE\|.SH OPERATION SPECIFICATION\|.SH OUTPUT CONTROL\|.SH TIME SPECIFICATION/{ n
N
N
d
--
1.8.3.1
From ed4e4370dc97bc220878db89d69c71426b9458a3 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Tue, 19 Jan 2021 17:02:45 -0500
Subject: [PATCH 2/2] Fix: tools: The 'm' key in crm_mon is a cycle, not a
toggle.
Each time it's pressed, a different amount of fencing information should
be shown, cycling back to nothing after level 3.
---
tools/crm_mon.c | 76 +++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 55 insertions(+), 21 deletions(-)
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index aafc80f..0981634 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -83,6 +83,8 @@ static gchar **processed_args = NULL;
static time_t last_refresh = 0;
crm_trigger_t *refresh_trigger = NULL;
+int interactive_fence_level = 0;
+
static pcmk__supported_format_t formats[] = {
#if CURSES_ENABLED
CRM_MON_SUPPORTED_FORMAT_CURSES,
@@ -382,9 +384,9 @@ as_xml_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError *
static gboolean
fence_history_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError **err) {
- int rc = crm_atoi(optarg, "2");
+ interactive_fence_level = crm_atoi(optarg, "2");
- switch (rc) {
+ switch (interactive_fence_level) {
case 3:
options.mon_ops |= mon_op_fence_full_history | mon_op_fence_history | mon_op_fence_connect;
return include_exclude_cb("--include", "fencing", data, err);
@@ -862,6 +864,38 @@ cib_connect(gboolean full)
return rc;
}
+/* This is used to set up the fencing options after the interactive UI has been stared.
+ * fence_history_cb can't be used because it builds up a list of includes/excludes that
+ * then have to be processed with apply_include_exclude and that could affect other
+ * things.
+ */
+static void
+set_fencing_options(int level)
+{
+ switch (level) {
+ case 3:
+ options.mon_ops |= mon_op_fence_full_history | mon_op_fence_history | mon_op_fence_connect;
+ show |= mon_show_fencing_all;
+ break;
+
+ case 2:
+ options.mon_ops |= mon_op_fence_history | mon_op_fence_connect;
+ show |= mon_show_fencing_all;
+ break;
+
+ case 1:
+ options.mon_ops |= mon_op_fence_history | mon_op_fence_connect;
+ show |= mon_show_fence_failed | mon_show_fence_pending;
+ break;
+
+ default:
+ level = 0;
+ options.mon_ops &= ~(mon_op_fence_history | mon_op_fence_connect);
+ show &= ~mon_show_fencing_all;
+ break;
+ }
+}
+
#if CURSES_ENABLED
static const char *
get_option_desc(char c)
@@ -900,23 +934,12 @@ detect_user_input(GIOChannel *channel, GIOCondition condition, gpointer user_dat
switch (c) {
case 'm':
- if (!pcmk_is_set(show, mon_show_fencing_all)) {
- options.mon_ops |= mon_op_fence_history;
- options.mon_ops |= mon_op_fence_connect;
- if (st == NULL) {
- mon_cib_connection_destroy(NULL);
- }
- }
-
- if (pcmk_any_flags_set(show,
- mon_show_fence_failed
- |mon_show_fence_pending
- |mon_show_fence_worked)) {
- show &= ~mon_show_fencing_all;
- } else {
- show |= mon_show_fencing_all;
+ interactive_fence_level++;
+ if (interactive_fence_level > 3) {
+ interactive_fence_level = 0;
}
+ set_fencing_options(interactive_fence_level);
break;
case 'c':
show ^= mon_show_tickets;
@@ -997,10 +1020,7 @@ detect_user_input(GIOChannel *channel, GIOCondition condition, gpointer user_dat
print_option_help(out, 'R', pcmk_is_set(options.mon_ops, mon_op_print_clone_detail));
print_option_help(out, 'b', pcmk_is_set(options.mon_ops, mon_op_print_brief));
print_option_help(out, 'j', pcmk_is_set(options.mon_ops, mon_op_print_pending));
- print_option_help(out, 'm', pcmk_any_flags_set(show,
- mon_show_fence_failed
- |mon_show_fence_pending
- |mon_show_fence_worked));
+ out->info(out, "%d m: \t%s", interactive_fence_level, get_option_desc('m'));
out->info(out, "%s", "\nToggle fields via field letter, type any other key to return");
}
@@ -1400,6 +1420,19 @@ main(int argc, char **argv)
return clean_up(CRM_EX_USAGE);
}
+ /* Sync up the initial value of interactive_fence_level with whatever was set with
+ * --include/--exclude= options.
+ */
+ if (pcmk_is_set(show, mon_show_fencing_all)) {
+ interactive_fence_level = 3;
+ } else if (pcmk_is_set(show, mon_show_fence_worked)) {
+ interactive_fence_level = 2;
+ } else if (pcmk_any_flags_set(show, mon_show_fence_failed | mon_show_fence_pending)) {
+ interactive_fence_level = 1;
+ } else {
+ interactive_fence_level = 0;
+ }
+
crm_mon_register_messages(out);
pe__register_messages(out);
stonith__register_messages(out);
@@ -1460,6 +1493,7 @@ main(int argc, char **argv)
} while (rc == -ENOTCONN);
handle_connection_failures(rc);
+ set_fencing_options(interactive_fence_level);
mon_refresh_display(NULL);
mainloop = g_main_loop_new(NULL, FALSE);
--
1.8.3.1

File diff suppressed because it is too large Load Diff

View File

@ -1,29 +0,0 @@
From 240b9ec01e6a6e6554f0ae13d759c01339835a40 Mon Sep 17 00:00:00 2001
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
Date: Wed, 27 Jan 2021 10:10:03 +0100
Subject: [PATCH] Feature: cibsecret: use crmadmin -N (which also lists guest
and remote nodes) to get nodes to sync to
---
tools/cibsecret.in | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/cibsecret.in b/tools/cibsecret.in
index 8923a70..6326bf0 100644
--- a/tools/cibsecret.in
+++ b/tools/cibsecret.in
@@ -182,9 +182,9 @@ get_live_peers() {
[ $? -eq 0 ] || fatal $CRM_EX_UNAVAILABLE "couldn't get local node name"
# Get a list of all other cluster nodes
- GLP_ALL_PEERS="$(crm_node -l)"
+ GLP_ALL_PEERS="$(crmadmin -N -q)"
[ $? -eq 0 ] || fatal $CRM_EX_UNAVAILABLE "couldn't determine cluster nodes"
- GLP_ALL_PEERS="$(echo "$GLP_ALL_PEERS" | awk '{print $2}' | grep -v "^${GLP_LOCAL_NODE}$")"
+ GLP_ALL_PEERS="$(echo "$GLP_ALL_PEERS" | grep -v "^${GLP_LOCAL_NODE}$")"
# Make a list of those that respond to pings
if [ "$(id -u)" = "0" ] && which fping >/dev/null 2>&1; then
--
1.8.3.1

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +0,0 @@
From 494eebe33d56b24e1f3a13ebe6c0ec651c99a2af Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Wed, 3 Feb 2021 09:47:39 -0600
Subject: [PATCH] Fix: tools: get cibsecret stash working again
Broke with dfe636c4
---
tools/cibsecret.in | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/cibsecret.in b/tools/cibsecret.in
index 6326bf0..ce57a18 100644
--- a/tools/cibsecret.in
+++ b/tools/cibsecret.in
@@ -393,7 +393,7 @@ cibsecret_stash() {
fatal $CRM_EX_NOSUCH "nothing to stash for resource $rsc parameter $param"
is_secret "$CIBSTASH_CURRENT" &&
fatal $CRM_EX_EXISTS "resource $rsc parameter $param already set as secret, nothing to stash"
- cibsecret_set "$CIBSTASH_CURRENT"
+ cibsecret_set "$CIBSTASH_CURRENT" 4
}
cibsecret_unstash() {
--
1.8.3.1

View File

@ -1,709 +0,0 @@
From 68139dc8ff5efbfd81d3b5e868462e7eaefa2c74 Mon Sep 17 00:00:00 2001
From: Klaus Wenninger <klaus.wenninger@aon.at>
Date: Mon, 25 Jan 2021 15:35:33 +0100
Subject: [PATCH 1/7] Fix: crm_mon: add explicit void to one_shot prototype for
compat
---
tools/crm_mon.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index 0981634..1eca1b7 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -1226,7 +1226,7 @@ handle_connection_failures(int rc)
}
static void
-one_shot()
+one_shot(void)
{
int rc;
--
1.8.3.1
From 8c7a01f8880efff8457e8421c381082b250d4512 Mon Sep 17 00:00:00 2001
From: Klaus Wenninger <klaus.wenninger@aon.at>
Date: Mon, 25 Jan 2021 16:26:30 +0100
Subject: [PATCH 2/7] Refactor: crm_mon: cib_connect &
handle_connection_failures -> new rc
---
tools/crm_mon.c | 62 ++++++++++++++++++++++++++++++++-------------------------
1 file changed, 35 insertions(+), 27 deletions(-)
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index 1eca1b7..3fbac5f 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -690,7 +690,7 @@ reconnect_after_timeout(gpointer data)
print_as(output_format, "Reconnecting...\n");
fencing_connect();
- if (cib_connect(TRUE) == pcmk_ok) {
+ if (cib_connect(TRUE) == pcmk_rc_ok) {
/* Redraw the screen and reinstall ourselves to get called after another reconnect_msec. */
mon_refresh_display(NULL);
return FALSE;
@@ -804,16 +804,17 @@ fencing_connect(void)
static int
cib_connect(gboolean full)
{
- int rc = pcmk_ok;
+ int rc = pcmk_rc_ok;
static gboolean need_pass = TRUE;
- CRM_CHECK(cib != NULL, return -EINVAL);
+ CRM_CHECK(cib != NULL, return EINVAL);
if (getenv("CIB_passwd") != NULL) {
need_pass = FALSE;
}
- if (cib->state == cib_connected_query || cib->state == cib_connected_command) {
+ if (cib->state == cib_connected_query ||
+ cib->state == cib_connected_command) {
return rc;
}
@@ -825,37 +826,44 @@ cib_connect(gboolean full)
* @TODO Add a password prompt (maybe including input) function to
* pcmk__output_t and use it in libcib.
*/
- if ((output_format == mon_output_console) && need_pass && (cib->variant == cib_remote)) {
+ if ((output_format == mon_output_console) &&
+ need_pass &&
+ (cib->variant == cib_remote)) {
need_pass = FALSE;
print_as(output_format, "Password:");
}
- rc = cib->cmds->signon(cib, crm_system_name, cib_query);
- if (rc != pcmk_ok) {
+ rc = pcmk_legacy2rc(cib->cmds->signon(cib, crm_system_name, cib_query));
+ if (rc != pcmk_rc_ok) {
out->err(out, "Could not connect to the CIB: %s",
- pcmk_strerror(rc));
+ pcmk_rc_str(rc));
return rc;
}
- rc = cib->cmds->query(cib, NULL, &current_cib, cib_scope_local | cib_sync_call);
+ rc = pcmk_legacy2rc(cib->cmds->query(cib, NULL, &current_cib,
+ cib_scope_local | cib_sync_call));
- if (rc == pcmk_ok && full) {
- rc = cib->cmds->set_connection_dnotify(cib, mon_cib_connection_destroy);
- if (rc == -EPROTONOSUPPORT) {
- print_as
- (output_format, "Notification setup not supported, won't be able to reconnect after failure");
+ if (rc == pcmk_rc_ok && full) {
+ rc = pcmk_legacy2rc(cib->cmds->set_connection_dnotify(cib,
+ mon_cib_connection_destroy));
+ if (rc == EPROTONOSUPPORT) {
+ print_as(output_format,
+ "Notification setup not supported, won't be "
+ "able to reconnect after failure");
if (output_format == mon_output_console) {
sleep(2);
}
- rc = pcmk_ok;
+ rc = pcmk_rc_ok;
}
- if (rc == pcmk_ok) {
- cib->cmds->del_notify_callback(cib, T_CIB_DIFF_NOTIFY, crm_diff_update);
- rc = cib->cmds->add_notify_callback(cib, T_CIB_DIFF_NOTIFY, crm_diff_update);
+ if (rc == pcmk_rc_ok) {
+ cib->cmds->del_notify_callback(cib, T_CIB_DIFF_NOTIFY,
+ crm_diff_update);
+ rc = pcmk_legacy2rc(cib->cmds->add_notify_callback(cib,
+ T_CIB_DIFF_NOTIFY, crm_diff_update));
}
- if (rc != pcmk_ok) {
+ if (rc != pcmk_rc_ok) {
out->err(out, "Notification setup failed, could not monitor CIB actions");
clean_up_cib_connection();
clean_up_fencing_connection();
@@ -1206,20 +1214,20 @@ reconcile_output_format(pcmk__common_args_t *args) {
static void
handle_connection_failures(int rc)
{
- if (rc == pcmk_ok) {
+ if (rc == pcmk_rc_ok) {
return;
}
if (output_format == mon_output_monitor) {
g_set_error(&error, PCMK__EXITC_ERROR, CRM_EX_ERROR, "CLUSTER CRIT: Connection to cluster failed: %s",
- pcmk_strerror(rc));
+ pcmk_rc_str(rc));
rc = MON_STATUS_CRIT;
- } else if (rc == -ENOTCONN) {
+ } else if (rc == ENOTCONN) {
g_set_error(&error, PCMK__EXITC_ERROR, CRM_EX_ERROR, "Error: cluster is not available on this node");
- rc = crm_errno2exit(rc);
+ rc = pcmk_rc2exitc(rc);
} else {
- g_set_error(&error, PCMK__EXITC_ERROR, CRM_EX_ERROR, "Connection to cluster failed: %s", pcmk_strerror(rc));
- rc = crm_errno2exit(rc);
+ g_set_error(&error, PCMK__EXITC_ERROR, CRM_EX_ERROR, "Connection to cluster failed: %s", pcmk_rc_str(rc));
+ rc = pcmk_rc2exitc(rc);
}
clean_up(rc);
@@ -1478,7 +1486,7 @@ main(int argc, char **argv)
fencing_connect();
rc = cib_connect(TRUE);
- if (rc != pcmk_ok) {
+ if (rc != pcmk_rc_ok) {
sleep(options.reconnect_msec / 1000);
#if CURSES_ENABLED
if (output_format == mon_output_console) {
@@ -1490,7 +1498,7 @@ main(int argc, char **argv)
printf("Writing html to %s ...\n", args->output_dest);
}
- } while (rc == -ENOTCONN);
+ } while (rc == ENOTCONN);
handle_connection_failures(rc);
set_fencing_options(interactive_fence_level);
--
1.8.3.1
From 9b8fb7b608280f65a3b76d66a99b575a4da70944 Mon Sep 17 00:00:00 2001
From: Klaus Wenninger <klaus.wenninger@aon.at>
Date: Mon, 25 Jan 2021 18:26:04 +0100
Subject: [PATCH 3/7] Fix: tools: Report pacemakerd in state waiting for sbd
Waiting for pacemakerd to report that all subdaemons are started
before trying to connect to cib and fencer should remove the
potential race introduced by making fencer connection failure
non fatal when cib is faster to come up.
---
tools/crm_mon.c | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
tools/crm_mon.h | 1 +
2 files changed, 148 insertions(+), 11 deletions(-)
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index 3fbac5f..61f070d 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -132,6 +132,7 @@ static void handle_connection_failures(int rc);
static int mon_refresh_display(gpointer user_data);
static int cib_connect(gboolean full);
static int fencing_connect(void);
+static int pacemakerd_status(void);
static void mon_st_callback_event(stonith_t * st, stonith_event_t * e);
static void mon_st_callback_display(stonith_t * st, stonith_event_t * e);
static void refresh_after_event(gboolean data_updated);
@@ -689,11 +690,13 @@ reconnect_after_timeout(gpointer data)
}
print_as(output_format, "Reconnecting...\n");
- fencing_connect();
- if (cib_connect(TRUE) == pcmk_rc_ok) {
- /* Redraw the screen and reinstall ourselves to get called after another reconnect_msec. */
- mon_refresh_display(NULL);
- return FALSE;
+ if (pacemakerd_status() == pcmk_rc_ok) {
+ fencing_connect();
+ if (cib_connect(TRUE) == pcmk_rc_ok) {
+ /* Redraw the screen and reinstall ourselves to get called after another reconnect_msec. */
+ mon_refresh_display(NULL);
+ return FALSE;
+ }
}
reconnect_timer = g_timeout_add(options.reconnect_msec, reconnect_after_timeout, NULL);
@@ -840,6 +843,13 @@ cib_connect(gboolean full)
return rc;
}
+#if CURSES_ENABLED
+ /* just show this if refresh is gonna remove all traces */
+ if (output_format == mon_output_console) {
+ print_as(output_format ,"Waiting for CIB ...\n");
+ }
+#endif
+
rc = pcmk_legacy2rc(cib->cmds->query(cib, NULL, &current_cib,
cib_scope_local | cib_sync_call));
@@ -904,6 +914,121 @@ set_fencing_options(int level)
}
}
+/* Before trying to connect to fencer or cib check for state of
+ pacemakerd - just no sense in trying till pacemakerd has
+ taken care of starting all the sub-processes
+
+ Only noteworthy thing to show here is when pacemakerd is
+ waiting for startup-trigger from SBD.
+ */
+static void
+pacemakerd_event_cb(pcmk_ipc_api_t *pacemakerd_api,
+ enum pcmk_ipc_event event_type, crm_exit_t status,
+ void *event_data, void *user_data)
+{
+ pcmk_pacemakerd_api_reply_t *reply = event_data;
+ enum pcmk_pacemakerd_state *state =
+ (enum pcmk_pacemakerd_state *) user_data;
+
+ /* we are just interested in the latest reply */
+ *state = pcmk_pacemakerd_state_invalid;
+
+ switch (event_type) {
+ case pcmk_ipc_event_reply:
+ break;
+
+ default:
+ return;
+ }
+
+ if (status != CRM_EX_OK) {
+ out->err(out, "Bad reply from pacemakerd: %s",
+ crm_exit_str(status));
+ return;
+ }
+
+ if (reply->reply_type != pcmk_pacemakerd_reply_ping) {
+ out->err(out, "Unknown reply type %d from pacemakerd",
+ reply->reply_type);
+ } else {
+ if ((reply->data.ping.last_good != (time_t) 0) &&
+ (reply->data.ping.status == pcmk_rc_ok)) {
+ *state = reply->data.ping.state;
+ }
+ }
+}
+
+static int
+pacemakerd_status(void)
+{
+ int rc = pcmk_rc_ok;
+ pcmk_ipc_api_t *pacemakerd_api = NULL;
+ enum pcmk_pacemakerd_state state = pcmk_pacemakerd_state_invalid;
+
+ if (!pcmk_is_set(options.mon_ops, mon_op_cib_native)) {
+ /* we don't need fully functional pacemakerd otherwise */
+ return rc;
+ }
+ if (cib != NULL &&
+ (cib->state == cib_connected_query ||
+ cib->state == cib_connected_command)) {
+ /* As long as we have a cib-connection let's go with
+ * that to fetch further cluster-status and avoid
+ * unnecessary pings to pacemakerd.
+ * If cluster is going down and fencer is down already
+ * this will lead to a silently failing fencer reconnect.
+ * On cluster startup we shouldn't see this situation
+ * as first we do is wait for pacemakerd to report all
+ * daemons running.
+ */
+ return rc;
+ }
+ rc = pcmk_new_ipc_api(&pacemakerd_api, pcmk_ipc_pacemakerd);
+ if (pacemakerd_api == NULL) {
+ out->err(out, "Could not connect to pacemakerd: %s",
+ pcmk_rc_str(rc));
+ /* this is unrecoverable so return with rc we have */
+ return rc;
+ }
+ pcmk_register_ipc_callback(pacemakerd_api, pacemakerd_event_cb, (void *) &state);
+ rc = pcmk_connect_ipc(pacemakerd_api, pcmk_ipc_dispatch_poll);
+ if (rc == pcmk_rc_ok) {
+ rc = pcmk_pacemakerd_api_ping(pacemakerd_api, crm_system_name);
+ if (rc == pcmk_rc_ok) {
+ rc = pcmk_poll_ipc(pacemakerd_api, options.reconnect_msec/2);
+ if (rc == pcmk_rc_ok) {
+ pcmk_dispatch_ipc(pacemakerd_api);
+ rc = ENOTCONN;
+ switch (state) {
+ case pcmk_pacemakerd_state_running:
+ rc = pcmk_rc_ok;
+ break;
+ case pcmk_pacemakerd_state_starting_daemons:
+ print_as(output_format ,"Pacemaker daemons starting ...\n");
+ break;
+ case pcmk_pacemakerd_state_wait_for_ping:
+ print_as(output_format ,"Waiting for startup-trigger from SBD ...\n");
+ break;
+ case pcmk_pacemakerd_state_shutting_down:
+ print_as(output_format ,"Pacemaker daemons shutting down ...\n");
+ break;
+ case pcmk_pacemakerd_state_shutdown_complete:
+ /* assuming pacemakerd doesn't dispatch any pings after entering
+ * that state unless it is waiting for SBD
+ */
+ print_as(output_format ,"Pacemaker daemons shut down - reporting to SBD ...\n");
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ }
+ pcmk_free_ipc_api(pacemakerd_api);
+ /* returning with ENOTCONN triggers a retry */
+ return (rc == pcmk_rc_ok)?rc:ENOTCONN;
+}
+
#if CURSES_ENABLED
static const char *
get_option_desc(char c)
@@ -1033,8 +1158,11 @@ detect_user_input(GIOChannel *channel, GIOCondition condition, gpointer user_dat
}
refresh:
- fencing_connect();
- rc = cib_connect(FALSE);
+ rc = pacemakerd_status();
+ if (rc == pcmk_rc_ok) {
+ fencing_connect();
+ rc = cib_connect(FALSE);
+ }
if (rc == pcmk_rc_ok) {
mon_refresh_display(NULL);
} else {
@@ -1238,9 +1366,13 @@ one_shot(void)
{
int rc;
- fencing_connect();
+ rc = pacemakerd_status();
+
+ if (rc == pcmk_rc_ok) {
+ fencing_connect();
+ rc = cib_connect(FALSE);
+ }
- rc = cib_connect(FALSE);
if (rc == pcmk_rc_ok) {
mon_refresh_display(NULL);
} else {
@@ -1316,6 +1448,7 @@ main(int argc, char **argv)
case cib_native:
/* cib & fencing - everything available */
+ options.mon_ops |= mon_op_cib_native;
break;
case cib_file:
@@ -1483,8 +1616,11 @@ main(int argc, char **argv)
do {
print_as(output_format ,"Waiting until cluster is available on this node ...\n");
- fencing_connect();
- rc = cib_connect(TRUE);
+ rc = pacemakerd_status();
+ if (rc == pcmk_rc_ok) {
+ fencing_connect();
+ rc = cib_connect(TRUE);
+ }
if (rc != pcmk_rc_ok) {
sleep(options.reconnect_msec / 1000);
diff --git a/tools/crm_mon.h b/tools/crm_mon.h
index 73c926d..b556913 100644
--- a/tools/crm_mon.h
+++ b/tools/crm_mon.h
@@ -91,6 +91,7 @@ typedef enum mon_output_format_e {
#define mon_op_print_brief (0x0200U)
#define mon_op_print_pending (0x0400U)
#define mon_op_print_clone_detail (0x0800U)
+#define mon_op_cib_native (0x1000U)
#define mon_op_default (mon_op_print_pending | mon_op_fence_history | mon_op_fence_connect)
--
1.8.3.1
From 046516dbe66fb2c52b90f36215cf60c5ad3c269b Mon Sep 17 00:00:00 2001
From: Klaus Wenninger <klaus.wenninger@aon.at>
Date: Thu, 28 Jan 2021 16:38:22 +0100
Subject: [PATCH 4/7] Refactor: crm_mon: do refreshes rather via
refresh_after_event
---
tools/crm_mon.c | 35 ++++++++++++++---------------------
1 file changed, 14 insertions(+), 21 deletions(-)
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index 61f070d..195e7b5 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -135,7 +135,7 @@ static int fencing_connect(void);
static int pacemakerd_status(void);
static void mon_st_callback_event(stonith_t * st, stonith_event_t * e);
static void mon_st_callback_display(stonith_t * st, stonith_event_t * e);
-static void refresh_after_event(gboolean data_updated);
+static void refresh_after_event(gboolean data_updated, gboolean enforce);
static unsigned int
all_includes(mon_output_format_t fmt) {
@@ -694,13 +694,13 @@ reconnect_after_timeout(gpointer data)
fencing_connect();
if (cib_connect(TRUE) == pcmk_rc_ok) {
/* Redraw the screen and reinstall ourselves to get called after another reconnect_msec. */
- mon_refresh_display(NULL);
+ refresh_after_event(FALSE, TRUE);
return FALSE;
}
}
reconnect_timer = g_timeout_add(options.reconnect_msec, reconnect_after_timeout, NULL);
- return TRUE;
+ return FALSE;
}
/* Called from various places when we are disconnected from the CIB or from the
@@ -1057,7 +1057,6 @@ static gboolean
detect_user_input(GIOChannel *channel, GIOCondition condition, gpointer user_data)
{
int c;
- int rc;
gboolean config_mode = FALSE;
while (1) {
@@ -1158,16 +1157,7 @@ detect_user_input(GIOChannel *channel, GIOCondition condition, gpointer user_dat
}
refresh:
- rc = pacemakerd_status();
- if (rc == pcmk_rc_ok) {
- fencing_connect();
- rc = cib_connect(FALSE);
- }
- if (rc == pcmk_rc_ok) {
- mon_refresh_display(NULL);
- } else {
- handle_connection_failures(rc);
- }
+ refresh_after_event(FALSE, TRUE);
return TRUE;
}
@@ -2087,7 +2077,7 @@ crm_diff_update(const char *event, xmlNode * msg)
}
stale = FALSE;
- refresh_after_event(cib_updated);
+ refresh_after_event(cib_updated, FALSE);
}
static int
@@ -2246,7 +2236,7 @@ mon_st_callback_event(stonith_t * st, stonith_event_t * e)
* fencing event is received or a CIB diff occurrs.
*/
static void
-refresh_after_event(gboolean data_updated)
+refresh_after_event(gboolean data_updated, gboolean enforce)
{
static int updates = 0;
time_t now = time(NULL);
@@ -2259,12 +2249,15 @@ refresh_after_event(gboolean data_updated)
refresh_timer = mainloop_timer_add("refresh", 2000, FALSE, mon_trigger_refresh, NULL);
}
- if ((now - last_refresh) > (options.reconnect_msec / 1000)) {
- mainloop_set_trigger(refresh_trigger);
+ if (reconnect_timer > 0) {
+ /* we will receive a refresh request after successful reconnect */
mainloop_timer_stop(refresh_timer);
- updates = 0;
+ return;
+ }
- } else if(updates >= 10) {
+ if (enforce ||
+ now - last_refresh > options.reconnect_msec / 1000 ||
+ updates >= 10) {
mainloop_set_trigger(refresh_trigger);
mainloop_timer_stop(refresh_timer);
updates = 0;
@@ -2285,7 +2278,7 @@ mon_st_callback_display(stonith_t * st, stonith_event_t * e)
mon_cib_connection_destroy(NULL);
} else {
print_dot(output_format);
- refresh_after_event(TRUE);
+ refresh_after_event(TRUE, FALSE);
}
}
--
1.8.3.1
From a63af2713f96719fc1d5ef594eb033d0f251187f Mon Sep 17 00:00:00 2001
From: Klaus Wenninger <klaus.wenninger@aon.at>
Date: Thu, 28 Jan 2021 16:52:57 +0100
Subject: [PATCH 5/7] Fix: crm_mon: retry fencer connection as not fatal
initially
and cleanup fencer api to not leak memory on multiple reconnects
---
tools/crm_mon.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index 195e7b5..a768ca9 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -798,7 +798,7 @@ fencing_connect(void)
st->cmds->register_notification(st, T_STONITH_NOTIFY_HISTORY, mon_st_callback_display);
}
} else {
- st = NULL;
+ clean_up_fencing_connection();
}
return rc;
@@ -2255,6 +2255,12 @@ refresh_after_event(gboolean data_updated, gboolean enforce)
return;
}
+ /* as we're not handling initial failure of fencer-connection as
+ * fatal give it a retry here
+ * not getting here if cib-reconnection is already on the way
+ */
+ fencing_connect();
+
if (enforce ||
now - last_refresh > options.reconnect_msec / 1000 ||
updates >= 10) {
--
1.8.3.1
From b6f4b5dfc0b5fec8cdc029409fc61252de019415 Mon Sep 17 00:00:00 2001
From: Klaus Wenninger <klaus.wenninger@aon.at>
Date: Thu, 28 Jan 2021 18:08:43 +0100
Subject: [PATCH 6/7] Refactor: crm_mon: have reconnect-timer removed
implicitly
---
tools/crm_mon.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index a768ca9..4f73379 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -684,23 +684,19 @@ reconnect_after_timeout(gpointer data)
}
#endif
- if (reconnect_timer > 0) {
- g_source_remove(reconnect_timer);
- reconnect_timer = 0;
- }
-
print_as(output_format, "Reconnecting...\n");
if (pacemakerd_status() == pcmk_rc_ok) {
fencing_connect();
if (cib_connect(TRUE) == pcmk_rc_ok) {
- /* Redraw the screen and reinstall ourselves to get called after another reconnect_msec. */
+ /* trigger redrawing the screen (needs reconnect_timer == 0) */
+ reconnect_timer = 0;
refresh_after_event(FALSE, TRUE);
- return FALSE;
+ return G_SOURCE_REMOVE;
}
}
reconnect_timer = g_timeout_add(options.reconnect_msec, reconnect_after_timeout, NULL);
- return FALSE;
+ return G_SOURCE_REMOVE;
}
/* Called from various places when we are disconnected from the CIB or from the
--
1.8.3.1
From 586e69ec38d5273b348c42a61b9bc7bbcc2b93b3 Mon Sep 17 00:00:00 2001
From: Klaus Wenninger <klaus.wenninger@aon.at>
Date: Thu, 28 Jan 2021 21:08:16 +0100
Subject: [PATCH 7/7] Fix: crm_mon: suppress pacemakerd-status for non-text
output
---
tools/crm_mon.c | 53 ++++++++++++++++++++++++++++++++---------------------
1 file changed, 32 insertions(+), 21 deletions(-)
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index 4f73379..d4d4ac3 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -995,27 +995,38 @@ pacemakerd_status(void)
if (rc == pcmk_rc_ok) {
pcmk_dispatch_ipc(pacemakerd_api);
rc = ENOTCONN;
- switch (state) {
- case pcmk_pacemakerd_state_running:
- rc = pcmk_rc_ok;
- break;
- case pcmk_pacemakerd_state_starting_daemons:
- print_as(output_format ,"Pacemaker daemons starting ...\n");
- break;
- case pcmk_pacemakerd_state_wait_for_ping:
- print_as(output_format ,"Waiting for startup-trigger from SBD ...\n");
- break;
- case pcmk_pacemakerd_state_shutting_down:
- print_as(output_format ,"Pacemaker daemons shutting down ...\n");
- break;
- case pcmk_pacemakerd_state_shutdown_complete:
- /* assuming pacemakerd doesn't dispatch any pings after entering
- * that state unless it is waiting for SBD
- */
- print_as(output_format ,"Pacemaker daemons shut down - reporting to SBD ...\n");
- break;
- default:
- break;
+ if ((output_format == mon_output_console) ||
+ (output_format == mon_output_plain)) {
+ switch (state) {
+ case pcmk_pacemakerd_state_running:
+ rc = pcmk_rc_ok;
+ break;
+ case pcmk_pacemakerd_state_starting_daemons:
+ print_as(output_format ,"Pacemaker daemons starting ...\n");
+ break;
+ case pcmk_pacemakerd_state_wait_for_ping:
+ print_as(output_format ,"Waiting for startup-trigger from SBD ...\n");
+ break;
+ case pcmk_pacemakerd_state_shutting_down:
+ print_as(output_format ,"Pacemaker daemons shutting down ...\n");
+ break;
+ case pcmk_pacemakerd_state_shutdown_complete:
+ /* assuming pacemakerd doesn't dispatch any pings after entering
+ * that state unless it is waiting for SBD
+ */
+ print_as(output_format ,"Pacemaker daemons shut down - reporting to SBD ...\n");
+ break;
+ default:
+ break;
+ }
+ } else {
+ switch (state) {
+ case pcmk_pacemakerd_state_running:
+ rc = pcmk_rc_ok;
+ break;
+ default:
+ break;
+ }
}
}
}
--
1.8.3.1

View File

@ -1,267 +0,0 @@
From f4e3d77c94906a062641c7bf34243049de521a87 Mon Sep 17 00:00:00 2001
From: Klaus Wenninger <klaus.wenninger@aon.at>
Date: Wed, 3 Feb 2021 13:25:22 +0100
Subject: [PATCH] Fix: crm_mon: detect when run on remote-node
---
daemons/execd/remoted_proxy.c | 17 +++++++
daemons/pacemakerd/pacemakerd.c | 6 +--
include/crm/common/ipc_internal.h | 2 +
lib/common/ipc_server.c | 26 ++++++++++
tools/crm_mon.c | 99 ++++++++++++++++++++++++---------------
5 files changed, 106 insertions(+), 44 deletions(-)
diff --git a/daemons/execd/remoted_proxy.c b/daemons/execd/remoted_proxy.c
index 9329fa6..0fe39bf 100644
--- a/daemons/execd/remoted_proxy.c
+++ b/daemons/execd/remoted_proxy.c
@@ -29,6 +29,7 @@ static qb_ipcs_service_t *cib_shm = NULL;
static qb_ipcs_service_t *attrd_ipcs = NULL;
static qb_ipcs_service_t *crmd_ipcs = NULL;
static qb_ipcs_service_t *stonith_ipcs = NULL;
+static qb_ipcs_service_t *pacemakerd_ipcs = NULL;
// An IPC provider is a cluster node controller connecting as a client
static GList *ipc_providers = NULL;
@@ -126,6 +127,12 @@ stonith_proxy_accept(qb_ipcs_connection_t * c, uid_t uid, gid_t gid)
}
static int32_t
+pacemakerd_proxy_accept(qb_ipcs_connection_t * c, uid_t uid, gid_t gid)
+{
+ return -EREMOTEIO;
+}
+
+static int32_t
cib_proxy_accept_rw(qb_ipcs_connection_t * c, uid_t uid, gid_t gid)
{
return ipc_proxy_accept(c, uid, gid, PCMK__SERVER_BASED_RW);
@@ -356,6 +363,14 @@ static struct qb_ipcs_service_handlers stonith_proxy_callbacks = {
.connection_destroyed = ipc_proxy_destroy
};
+static struct qb_ipcs_service_handlers pacemakerd_proxy_callbacks = {
+ .connection_accept = pacemakerd_proxy_accept,
+ .connection_created = NULL,
+ .msg_process = NULL,
+ .connection_closed = NULL,
+ .connection_destroyed = NULL
+};
+
static struct qb_ipcs_service_handlers cib_proxy_callbacks_ro = {
.connection_accept = cib_proxy_accept_ro,
.connection_created = NULL,
@@ -422,6 +437,7 @@ ipc_proxy_init(void)
&cib_proxy_callbacks_rw);
pcmk__serve_attrd_ipc(&attrd_ipcs, &attrd_proxy_callbacks);
pcmk__serve_fenced_ipc(&stonith_ipcs, &stonith_proxy_callbacks);
+ pcmk__serve_pacemakerd_ipc(&pacemakerd_ipcs, &pacemakerd_proxy_callbacks);
crmd_ipcs = pcmk__serve_controld_ipc(&crmd_proxy_callbacks);
if (crmd_ipcs == NULL) {
crm_err("Failed to create controller: exiting and inhibiting respawn");
@@ -444,6 +460,7 @@ ipc_proxy_cleanup(void)
pcmk__stop_based_ipc(cib_ro, cib_rw, cib_shm);
qb_ipcs_destroy(attrd_ipcs);
qb_ipcs_destroy(stonith_ipcs);
+ qb_ipcs_destroy(pacemakerd_ipcs);
qb_ipcs_destroy(crmd_ipcs);
cib_ro = NULL;
cib_rw = NULL;
diff --git a/daemons/pacemakerd/pacemakerd.c b/daemons/pacemakerd/pacemakerd.c
index 509b0f8..4572b70 100644
--- a/daemons/pacemakerd/pacemakerd.c
+++ b/daemons/pacemakerd/pacemakerd.c
@@ -1287,11 +1287,7 @@ main(int argc, char **argv)
// Don't build CRM_RSCTMP_DIR, pacemaker-execd will do it
- ipcs = mainloop_add_ipc_server(CRM_SYSTEM_MCP, QB_IPC_NATIVE, &mcp_ipc_callbacks);
- if (ipcs == NULL) {
- crm_err("Couldn't start IPC server");
- crm_exit(CRM_EX_OSERR);
- }
+ pcmk__serve_pacemakerd_ipc(&ipcs, &mcp_ipc_callbacks);
#ifdef SUPPORT_COROSYNC
/* Allows us to block shutdown */
diff --git a/include/crm/common/ipc_internal.h b/include/crm/common/ipc_internal.h
index cf935f3..fb82ce1 100644
--- a/include/crm/common/ipc_internal.h
+++ b/include/crm/common/ipc_internal.h
@@ -221,6 +221,8 @@ void pcmk__serve_attrd_ipc(qb_ipcs_service_t **ipcs,
struct qb_ipcs_service_handlers *cb);
void pcmk__serve_fenced_ipc(qb_ipcs_service_t **ipcs,
struct qb_ipcs_service_handlers *cb);
+void pcmk__serve_pacemakerd_ipc(qb_ipcs_service_t **ipcs,
+ struct qb_ipcs_service_handlers *cb);
qb_ipcs_service_t *pcmk__serve_controld_ipc(struct qb_ipcs_service_handlers *cb);
void pcmk__serve_based_ipc(qb_ipcs_service_t **ipcs_ro,
diff --git a/lib/common/ipc_server.c b/lib/common/ipc_server.c
index 4d3e954..b3aaf8e 100644
--- a/lib/common/ipc_server.c
+++ b/lib/common/ipc_server.c
@@ -922,6 +922,32 @@ pcmk__serve_fenced_ipc(qb_ipcs_service_t **ipcs,
}
/*!
+ * \internal
+ * \brief Add an IPC server to the main loop for the pacemakerd API
+ *
+ * \param[in] cb IPC callbacks
+ *
+ * \note This function exits with CRM_EX_OSERR if unable to create the servers.
+ */
+void
+pcmk__serve_pacemakerd_ipc(qb_ipcs_service_t **ipcs,
+ struct qb_ipcs_service_handlers *cb)
+{
+ *ipcs = mainloop_add_ipc_server(CRM_SYSTEM_MCP, QB_IPC_NATIVE, cb);
+
+ if (*ipcs == NULL) {
+ crm_err("Couldn't start pacemakerd IPC server");
+ crm_warn("Verify pacemaker and pacemaker_remote are not both enabled.");
+ /* sub-daemons are observed by pacemakerd. Thus we exit CRM_EX_FATAL
+ * if we want to prevent pacemakerd from restarting them.
+ * With pacemakerd we leave the exit-code shown to e.g. systemd
+ * to what it was prior to moving the code here from pacemakerd.c
+ */
+ crm_exit(CRM_EX_OSERR);
+ }
+}
+
+/*!
* \brief Check whether string represents a client name used by cluster daemons
*
* \param[in] name String to check
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index d4d4ac3..e58fed2 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -83,6 +83,8 @@ static gchar **processed_args = NULL;
static time_t last_refresh = 0;
crm_trigger_t *refresh_trigger = NULL;
+static gboolean on_remote_node = FALSE;
+
int interactive_fence_level = 0;
static pcmk__supported_format_t formats[] = {
@@ -988,48 +990,63 @@ pacemakerd_status(void)
}
pcmk_register_ipc_callback(pacemakerd_api, pacemakerd_event_cb, (void *) &state);
rc = pcmk_connect_ipc(pacemakerd_api, pcmk_ipc_dispatch_poll);
- if (rc == pcmk_rc_ok) {
- rc = pcmk_pacemakerd_api_ping(pacemakerd_api, crm_system_name);
- if (rc == pcmk_rc_ok) {
- rc = pcmk_poll_ipc(pacemakerd_api, options.reconnect_msec/2);
+ switch (rc) {
+ case pcmk_rc_ok:
+ rc = pcmk_pacemakerd_api_ping(pacemakerd_api, crm_system_name);
if (rc == pcmk_rc_ok) {
- pcmk_dispatch_ipc(pacemakerd_api);
- rc = ENOTCONN;
- if ((output_format == mon_output_console) ||
- (output_format == mon_output_plain)) {
- switch (state) {
- case pcmk_pacemakerd_state_running:
- rc = pcmk_rc_ok;
- break;
- case pcmk_pacemakerd_state_starting_daemons:
- print_as(output_format ,"Pacemaker daemons starting ...\n");
- break;
- case pcmk_pacemakerd_state_wait_for_ping:
- print_as(output_format ,"Waiting for startup-trigger from SBD ...\n");
- break;
- case pcmk_pacemakerd_state_shutting_down:
- print_as(output_format ,"Pacemaker daemons shutting down ...\n");
- break;
- case pcmk_pacemakerd_state_shutdown_complete:
- /* assuming pacemakerd doesn't dispatch any pings after entering
- * that state unless it is waiting for SBD
- */
- print_as(output_format ,"Pacemaker daemons shut down - reporting to SBD ...\n");
- break;
- default:
- break;
- }
- } else {
- switch (state) {
- case pcmk_pacemakerd_state_running:
- rc = pcmk_rc_ok;
- break;
- default:
- break;
+ rc = pcmk_poll_ipc(pacemakerd_api, options.reconnect_msec/2);
+ if (rc == pcmk_rc_ok) {
+ pcmk_dispatch_ipc(pacemakerd_api);
+ rc = ENOTCONN;
+ if ((output_format == mon_output_console) ||
+ (output_format == mon_output_plain)) {
+ switch (state) {
+ case pcmk_pacemakerd_state_running:
+ rc = pcmk_rc_ok;
+ break;
+ case pcmk_pacemakerd_state_starting_daemons:
+ print_as(output_format ,"Pacemaker daemons starting ...\n");
+ break;
+ case pcmk_pacemakerd_state_wait_for_ping:
+ print_as(output_format ,"Waiting for startup-trigger from SBD ...\n");
+ break;
+ case pcmk_pacemakerd_state_shutting_down:
+ print_as(output_format ,"Pacemaker daemons shutting down ...\n");
+ break;
+ case pcmk_pacemakerd_state_shutdown_complete:
+ /* assuming pacemakerd doesn't dispatch any pings after entering
+ * that state unless it is waiting for SBD
+ */
+ print_as(output_format ,"Pacemaker daemons shut down - reporting to SBD ...\n");
+ break;
+ default:
+ break;
+ }
+ } else {
+ switch (state) {
+ case pcmk_pacemakerd_state_running:
+ rc = pcmk_rc_ok;
+ break;
+ default:
+ break;
+ }
}
}
}
- }
+ break;
+ case EREMOTEIO:
+ rc = pcmk_rc_ok;
+ on_remote_node = TRUE;
+#if CURSES_ENABLED
+ /* just show this if refresh is gonna remove all traces */
+ if (output_format == mon_output_console) {
+ print_as(output_format ,
+ "Running on remote-node waiting to be connected by cluster ...\n");
+ }
+#endif
+ break;
+ default:
+ break;
}
pcmk_free_ipc_api(pacemakerd_api);
/* returning with ENOTCONN triggers a retry */
@@ -1348,7 +1365,11 @@ handle_connection_failures(int rc)
pcmk_rc_str(rc));
rc = MON_STATUS_CRIT;
} else if (rc == ENOTCONN) {
- g_set_error(&error, PCMK__EXITC_ERROR, CRM_EX_ERROR, "Error: cluster is not available on this node");
+ if (on_remote_node) {
+ g_set_error(&error, PCMK__EXITC_ERROR, CRM_EX_ERROR, "Error: remote-node not connected to cluster");
+ } else {
+ g_set_error(&error, PCMK__EXITC_ERROR, CRM_EX_ERROR, "Error: cluster is not available on this node");
+ }
rc = pcmk_rc2exitc(rc);
} else {
g_set_error(&error, PCMK__EXITC_ERROR, CRM_EX_ERROR, "Connection to cluster failed: %s", pcmk_rc_str(rc));
--
1.8.3.1

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,62 +0,0 @@
From 98589d8e1ef9b57d806702b9968ff7e5560e9c8f Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Fri, 12 Feb 2021 11:51:16 -0500
Subject: [PATCH] Low: Fix a problem with crm_resource exit code handling.
If no output is produced but an error message is printed (like, when an
inactive resource is provided on the command line), don't print the
error message for the pcmk_rc_no_output error code. It's weird to see
output and a message about no output at the same time.
Similarly, don't print an "Error: OK" message when usage is printed.
---
tools/crm_resource.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/tools/crm_resource.c b/tools/crm_resource.c
index 7d2f0f6..29b0a04 100644
--- a/tools/crm_resource.c
+++ b/tools/crm_resource.c
@@ -1534,9 +1534,9 @@ main(int argc, char **argv)
rc = pcmk__output_new(&out, args->output_ty, args->output_dest, argv);
if (rc != pcmk_rc_ok) {
- fprintf(stderr, "Error creating output format %s: %s\n",
- args->output_ty, pcmk_rc_str(rc));
exit_code = CRM_EX_ERROR;
+ g_set_error(&error, PCMK__EXITC_ERROR, exit_code, "Error creating output format %s: %s",
+ args->output_ty, pcmk_rc_str(rc));
goto done;
}
@@ -2039,7 +2039,12 @@ main(int argc, char **argv)
*/
done:
- if (rc != pcmk_rc_ok) {
+ /* Don't do any of this for pcmk_rc_no_output (doesn't make sense to show an
+ * error message for no output) or for CRM_EX_USAGE (we don't want to show
+ * an "error: OK" message from pcmk_rc_str).
+ */
+ if ((rc != pcmk_rc_ok && rc != pcmk_rc_no_output) ||
+ (exit_code != CRM_EX_OK && exit_code != CRM_EX_USAGE)) {
if (rc == pcmk_rc_no_quorum) {
g_prefix_error(&error, "To ignore quorum, use the force option.\n");
}
@@ -2054,10 +2059,10 @@ done:
g_set_error(&error, PCMK__RC_ERROR, rc,
"Error performing operation: %s", pcmk_rc_str(rc));
}
+ }
- if (exit_code == CRM_EX_OK) {
- exit_code = pcmk_rc2exitc(rc);
- }
+ if (exit_code == CRM_EX_OK) {
+ exit_code = pcmk_rc2exitc(rc);
}
g_free(options.host_uname);
--
1.8.3.1

View File

@ -1,36 +0,0 @@
From 34b2d8ab82dcdf49535c74e6a580240455498759 Mon Sep 17 00:00:00 2001
From: Klaus Wenninger <klaus.wenninger@aon.at>
Date: Wed, 2 Dec 2020 22:51:33 +0100
Subject: [PATCH] default to syncing with sbd
---
lib/common/watchdog.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/lib/common/watchdog.c b/lib/common/watchdog.c
index 03ee7f1..bf5df18 100644
--- a/lib/common/watchdog.c
+++ b/lib/common/watchdog.c
@@ -244,12 +244,16 @@ pcmk__get_sbd_timeout(void)
bool
pcmk__get_sbd_sync_resource_startup(void)
{
- static bool sync_resource_startup = false;
+ static bool sync_resource_startup = true; // default overruled by env
static bool checked_sync_resource_startup = false;
if (!checked_sync_resource_startup) {
- sync_resource_startup =
- crm_is_true(getenv("SBD_SYNC_RESOURCE_STARTUP"));
+ gboolean ret = FALSE;
+ const char *s = getenv("SBD_SYNC_RESOURCE_STARTUP");
+
+ if ((s != NULL) && (crm_str_to_boolean(s, &ret) > 0)) {
+ sync_resource_startup = ret;
+ }
checked_sync_resource_startup = true;
}
--
1.8.3.1

File diff suppressed because it is too large Load Diff