diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-03 13:39:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-03 13:39:28 +0000 |
commit | 7332b914bff2786ff70ccace103fc9ebdfb61a23 (patch) | |
tree | 3a8a60c4edba014c7e350be41839e3edbf2a315f /daemons/controld | |
parent | Adding debian version 2.1.7-1. (diff) | |
download | pacemaker-7332b914bff2786ff70ccace103fc9ebdfb61a23.tar.xz pacemaker-7332b914bff2786ff70ccace103fc9ebdfb61a23.zip |
Merging upstream version 2.1.8~rc1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'daemons/controld')
29 files changed, 1332 insertions, 1408 deletions
diff --git a/daemons/controld/controld_attrd.c b/daemons/controld/controld_attrd.c index 923abb9..f728bef 100644 --- a/daemons/controld/controld_attrd.c +++ b/daemons/controld/controld_attrd.c @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the Pacemaker project contributors + * Copyright 2006-2024 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -10,10 +10,10 @@ #include <crm_internal.h> #include <crm/crm.h> -#include <crm/common/attrd_internal.h> +#include <crm/common/attrs_internal.h> #include <crm/common/ipc.h> #include <crm/common/ipc_attrd_internal.h> -#include <crm/msg_xml.h> +#include <crm/common/xml.h> #include <pacemaker-controld.h> @@ -117,7 +117,7 @@ update_attrd_remote_node_removed(const char *host, const char *user_name) if (rc == pcmk_rc_ok) { crm_trace("Asking attribute manager to purge Pacemaker Remote node %s", host); - rc = pcmk__attrd_api_purge(attrd_api, host); + rc = pcmk__attrd_api_purge(attrd_api, host, true); } if (rc != pcmk_rc_ok) { crm_err("Could not purge Pacemaker Remote node %s " @@ -136,25 +136,23 @@ update_attrd_clear_failures(const char *host, const char *rsc, const char *op, rc = pcmk_new_ipc_api(&attrd_api, pcmk_ipc_attrd); } if (rc == pcmk_rc_ok) { - const char *op_desc = pcmk__s(op, "operations"); - const char *interval_desc = "all"; uint32_t attrd_opts = pcmk__node_attr_none; - if (op != NULL) { - interval_desc = pcmk__s(interval_spec, "nonrecurring"); - } if (is_remote_node) { pcmk__set_node_attr_flags(attrd_opts, pcmk__node_attr_remote); } - crm_info("Asking attribute manager to clear failure of %s %s for %s " - "on %s node %s", interval_desc, op_desc, rsc, - node_type(is_remote_node), host); rc = pcmk__attrd_api_clear_failures(attrd_api, host, rsc, op, interval_spec, NULL, attrd_opts); } if (rc != pcmk_rc_ok) { - crm_err("Could not clear failure attributes for %s on %s node %s%s: %s " - CRM_XS " rc=%d", pcmk__s(rsc, "all resources"), - node_type(is_remote_node), host, when(), pcmk_rc_str(rc), rc); + const char *interval_desc = "all"; + + if (op != NULL) { + interval_desc = pcmk__s(interval_spec, "nonrecurring"); + } + crm_err("Could not clear failure of %s %s for %s on %s node %s%s: %s " + CRM_XS " rc=%d", interval_desc, pcmk__s(op, "operations"), + pcmk__s(rsc, "all resources"), node_type(is_remote_node), host, + when(), pcmk_rc_str(rc), rc); } } diff --git a/daemons/controld/controld_callbacks.c b/daemons/controld/controld_callbacks.c index 7078739..16e6424 100644 --- a/daemons/controld/controld_callbacks.c +++ b/daemons/controld/controld_callbacks.c @@ -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. * @@ -13,7 +13,6 @@ #include <string.h> #include <crm/crm.h> -#include <crm/msg_xml.h> #include <crm/common/xml.h> #include <crm/cluster.h> #include <crm/cib.h> @@ -27,15 +26,15 @@ void crmd_ha_msg_filter(xmlNode * msg) { if (AM_I_DC) { - const char *sys_from = crm_element_value(msg, F_CRM_SYS_FROM); + const char *sys_from = crm_element_value(msg, PCMK__XA_CRM_SYS_FROM); if (pcmk__str_eq(sys_from, CRM_SYSTEM_DC, pcmk__str_casei)) { - const char *from = crm_element_value(msg, F_ORIG); + const char *from = crm_element_value(msg, PCMK__XA_SRC); if (!pcmk__str_eq(from, controld_globals.our_nodename, pcmk__str_casei)) { int level = LOG_INFO; - const char *op = crm_element_value(msg, F_CRM_TASK); + const char *op = crm_element_value(msg, PCMK__XA_CRM_TASK); /* make sure the election happens NOW */ if (controld_globals.fsa_state != S_ELECTION) { @@ -53,7 +52,7 @@ crmd_ha_msg_filter(xmlNode * msg) } } else { - const char *sys_to = crm_element_value(msg, F_CRM_SYS_TO); + const char *sys_to = crm_element_value(msg, PCMK__XA_CRM_SYS_TO); if (pcmk__str_eq(sys_to, CRM_SYSTEM_DC, pcmk__str_casei)) { return; @@ -84,7 +83,7 @@ node_alive(const crm_node_t *node) // Pacemaker Remote nodes can't be partially alive return pcmk__str_eq(node->state, CRM_NODE_MEMBER, pcmk__str_casei) ? 1: -1; - } else if (crm_is_peer_active(node)) { + } else if (pcmk__cluster_is_node_active(node)) { // Completely up cluster node: both cluster member and peer return 1; @@ -128,7 +127,7 @@ peer_update_callback(enum crm_status_type type, crm_node_t * node, const void *d xmlNode *query = create_request(CRM_OP_HELLO, NULL, NULL, CRM_SYSTEM_CRMD, CRM_SYSTEM_CRMD, NULL); crm_debug("Sending hello to node %u so that it learns our node name", node->id); - send_cluster_message(node, crm_msg_crmd, query, FALSE); + pcmk__cluster_send_message(node, crm_msg_crmd, query); free_xml(query); } @@ -178,7 +177,7 @@ peer_update_callback(enum crm_status_type type, crm_node_t * node, const void *d const char *dc_s = controld_globals.dc_name; if ((dc_s == NULL) && AM_I_DC) { - dc_s = "true"; + dc_s = PCMK_VALUE_TRUE; } crm_info("Node %s is %s a peer " CRM_XS @@ -222,7 +221,7 @@ peer_update_callback(enum crm_status_type type, crm_node_t * node, const void *d } else if (pcmk__str_eq(node->uname, controld_globals.dc_name, pcmk__str_casei) - && !crm_is_peer_active(node)) { + && !pcmk__cluster_is_node_active(node)) { /* Did the DC leave us? */ crm_notice("Our peer on the DC (%s) is dead", controld_globals.dc_name); @@ -274,7 +273,7 @@ peer_update_callback(enum crm_status_type type, crm_node_t * node, const void *d } if (down) { - const char *task = crm_element_value(down->xml, XML_LRM_ATTR_TASK); + const char *task = crm_element_value(down->xml, PCMK_XA_OPERATION); if (pcmk__str_eq(task, PCMK_ACTION_STONITH, pcmk__str_casei)) { @@ -322,8 +321,8 @@ peer_update_callback(enum crm_status_type type, crm_node_t * node, const void *d crm_update_peer_join(__func__, node, crm_join_none); check_join_state(controld_globals.fsa_state, __func__); } - abort_transition(INFINITY, pcmk__graph_restart, "Node failure", - NULL); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, + "Node failure", NULL); fail_incompletable_actions(controld_globals.transition_graph, node->uuid); @@ -340,7 +339,7 @@ peer_update_callback(enum crm_status_type type, crm_node_t * node, const void *d /* Trigger resource placement on newly integrated nodes */ if (appeared) { - abort_transition(INFINITY, pcmk__graph_restart, + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, "Pacemaker Remote node integrated", NULL); } } @@ -349,7 +348,8 @@ peer_update_callback(enum crm_status_type type, crm_node_t * node, const void *d && (node->when_member > 1)) { /* The node left CPG but is still a cluster member. Set its * membership time to 1 to record it in the cluster state as a - * boolean, so we don't fence it due to node-pending-timeout. + * boolean, so we don't fence it due to + * PCMK_OPT_NODE_PENDING_TIMEOUT. */ node->when_member = 1; flags |= node_update_cluster; @@ -361,7 +361,7 @@ peer_update_callback(enum crm_status_type type, crm_node_t * node, const void *d if (update == NULL) { crm_debug("Node state update not yet possible for %s", node->uname); } else { - fsa_cib_anon_update(XML_CIB_TAG_STATUS, update); + fsa_cib_anon_update(PCMK_XE_STATUS, update); } free_xml(update); } diff --git a/daemons/controld/controld_cib.c b/daemons/controld/controld_cib.c index 865e41f..7acff30 100644 --- a/daemons/controld/controld_cib.c +++ b/daemons/controld/controld_cib.c @@ -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. * @@ -14,7 +14,6 @@ #include <crm/common/alerts_internal.h> #include <crm/common/xml.h> #include <crm/crm.h> -#include <crm/msg_xml.h> #include <crm/lrmd_internal.h> #include <pacemaker-controld.h> @@ -59,8 +58,8 @@ do_cib_updated(const char *event, xmlNode * msg) return; } - if (cib__element_in_patchset(patchset, XML_CIB_TAG_ALERTS) - || cib__element_in_patchset(patchset, XML_CIB_TAG_CRMCONFIG)) { + if (cib__element_in_patchset(patchset, PCMK_XE_ALERTS) + || cib__element_in_patchset(patchset, PCMK_XE_CRM_CONFIG)) { controld_trigger_config(); } @@ -70,21 +69,21 @@ do_cib_updated(const char *event, xmlNode * msg) return; } - client_name = crm_element_value(msg, F_CIB_CLIENTNAME); + client_name = crm_element_value(msg, PCMK__XA_CIB_CLIENTNAME); if (!cib__client_triggers_refresh(client_name)) { // The CIB is still accurate return; } - if (cib__element_in_patchset(patchset, XML_CIB_TAG_NODES) - || cib__element_in_patchset(patchset, XML_CIB_TAG_STATUS)) { + if (cib__element_in_patchset(patchset, PCMK_XE_NODES) + || cib__element_in_patchset(patchset, PCMK_XE_STATUS)) { - /* An unsafe client modified the nodes or status section. Ensure the - * node list is up-to-date, and start the join process again so we get - * everyone's current resource history. + /* An unsafe client modified the PCMK_XE_NODES or PCMK_XE_STATUS + * section. Ensure the node list is up-to-date, and start the join + * process again so we get everyone's current resource history. */ if (client_name == NULL) { - client_name = crm_element_value(msg, F_CIB_CLIENTID); + client_name = crm_element_value(msg, PCMK__XA_CIB_CLIENTID); } crm_notice("Populating nodes and starting an election after %s event " "triggered by %s", @@ -106,7 +105,7 @@ controld_disconnect_cib_manager(void) controld_clear_fsa_input_flags(R_CIB_CONNECTED); - cib_conn->cmds->del_notify_callback(cib_conn, T_CIB_DIFF_NOTIFY, + cib_conn->cmds->del_notify_callback(cib_conn, PCMK__VALUE_CIB_DIFF_NOTIFY, do_cib_updated); cib_free_callbacks(cib_conn); @@ -175,7 +174,7 @@ do_cib_control(long long action, crm_err("Could not set dnotify callback"); } else if (cib_conn->cmds->add_notify_callback(cib_conn, - T_CIB_DIFF_NOTIFY, + PCMK__VALUE_CIB_DIFF_NOTIFY, update_cb) != pcmk_ok) { crm_err("Could not set CIB notification callback (update)"); @@ -226,12 +225,9 @@ cib_op_timeout(void) env_timeout, (env? env : "none")); } - calculated_timeout = 1 + crm_active_peers(); - if (crm_remote_peer_cache) { - calculated_timeout += g_hash_table_size(crm_remote_peer_cache); - } - calculated_timeout *= 10; - + calculated_timeout = 10U * (1U + + pcmk__cluster_num_active_nodes() + + pcmk__cluster_num_remote_nodes()); calculated_timeout = QB_MAX(calculated_timeout, env_timeout); crm_trace("Calculated timeout: %us", calculated_timeout); @@ -275,32 +271,32 @@ cib_delete_callback(xmlNode *msg, int call_id, int rc, xmlNode *output, } } -// Searches for various portions of node_state to delete +// Searches for various portions of PCMK__XE_NODE_STATE to delete -// Match a particular node's node_state (takes node name 1x) -#define XPATH_NODE_STATE "//" XML_CIB_TAG_STATE "[@" XML_ATTR_UNAME "='%s']" +// Match a particular node's PCMK__XE_NODE_STATE (takes node name 1x) +#define XPATH_NODE_STATE "//" PCMK__XE_NODE_STATE "[@" PCMK_XA_UNAME "='%s']" // Node's lrm section (name 1x) -#define XPATH_NODE_LRM XPATH_NODE_STATE "/" XML_CIB_TAG_LRM +#define XPATH_NODE_LRM XPATH_NODE_STATE "/" PCMK__XE_LRM -/* Node's lrm_rsc_op entries and lrm_resource entries without unexpired lock - * (name 2x, (seconds_since_epoch - XML_CONFIG_ATTR_SHUTDOWN_LOCK_LIMIT) 1x) +/* Node's PCMK__XE_LRM_RSC_OP entries and PCMK__XE_LRM_RESOURCE entries without + * unexpired lock + * (name 2x, (seconds_since_epoch - PCMK_OPT_SHUTDOWN_LOCK_LIMIT) 1x) */ -#define XPATH_NODE_LRM_UNLOCKED XPATH_NODE_STATE "//" XML_LRM_TAG_RSC_OP \ +#define XPATH_NODE_LRM_UNLOCKED XPATH_NODE_STATE "//" PCMK__XE_LRM_RSC_OP \ "|" XPATH_NODE_STATE \ - "//" XML_LRM_TAG_RESOURCE \ - "[not(@" XML_CONFIG_ATTR_SHUTDOWN_LOCK ") " \ - "or " XML_CONFIG_ATTR_SHUTDOWN_LOCK "<%lld]" + "//" PCMK__XE_LRM_RESOURCE \ + "[not(@" PCMK_OPT_SHUTDOWN_LOCK ") " \ + "or " PCMK_OPT_SHUTDOWN_LOCK "<%lld]" -// Node's transient_attributes section (name 1x) -#define XPATH_NODE_ATTRS XPATH_NODE_STATE "/" XML_TAG_TRANSIENT_NODEATTRS +// Node's PCMK__XE_TRANSIENT_ATTRIBUTES section (name 1x) +#define XPATH_NODE_ATTRS XPATH_NODE_STATE "/" PCMK__XE_TRANSIENT_ATTRIBUTES -// Everything under node_state (name 1x) +// Everything under PCMK__XE_NODE_STATE (name 1x) #define XPATH_NODE_ALL XPATH_NODE_STATE "/*" /* Unlocked history + transient attributes - * (name 2x, (seconds_since_epoch - XML_CONFIG_ATTR_SHUTDOWN_LOCK_LIMIT) 1x, - * name 1x) + * (name 2x, (seconds_since_epoch - PCMK_OPT_SHUTDOWN_LOCK_LIMIT) 1x, name 1x) */ #define XPATH_NODE_ALL_UNLOCKED XPATH_NODE_LRM_UNLOCKED "|" XPATH_NODE_ATTRS @@ -309,7 +305,7 @@ cib_delete_callback(xmlNode *msg, int call_id, int rc, xmlNode *output, * \brief Get the XPath and description of a node state section to be deleted * * \param[in] uname Desired node - * \param[in] section Subsection of node_state to be deleted + * \param[in] section Subsection of \c PCMK__XE_NODE_STATE to be deleted * \param[out] xpath Where to store XPath of \p section * \param[out] desc If not \c NULL, where to store description of \p section */ @@ -360,10 +356,10 @@ controld_node_state_deletion_strings(const char *uname, /*! * \internal - * \brief Delete subsection of a node's CIB node_state + * \brief Delete subsection of a node's CIB \c PCMK__XE_NODE_STATE * * \param[in] uname Desired node - * \param[in] section Subsection of node_state to delete + * \param[in] section Subsection of \c PCMK__XE_NODE_STATE to delete * \param[in] options CIB call options to use */ void @@ -391,12 +387,12 @@ controld_delete_node_state(const char *uname, enum controld_section_e section, } // Takes node name and resource ID -#define XPATH_RESOURCE_HISTORY "//" XML_CIB_TAG_STATE \ - "[@" XML_ATTR_UNAME "='%s']/" \ - XML_CIB_TAG_LRM "/" XML_LRM_TAG_RESOURCES \ - "/" XML_LRM_TAG_RESOURCE \ - "[@" XML_ATTR_ID "='%s']" -// @TODO could add "and @XML_CONFIG_ATTR_SHUTDOWN_LOCK" to limit to locks +#define XPATH_RESOURCE_HISTORY "//" PCMK__XE_NODE_STATE \ + "[@" PCMK_XA_UNAME "='%s']/" \ + PCMK__XE_LRM "/" PCMK__XE_LRM_RESOURCES \ + "/" PCMK__XE_LRM_RESOURCE \ + "[@" PCMK_XA_ID "='%s']" +// @TODO could add "and @PCMK_OPT_SHUTDOWN_LOCK" to limit to locks /*! * \internal @@ -490,7 +486,7 @@ build_parameter_list(const lrmd_event_data_t *op, { GString *list = NULL; - *result = create_xml_node(NULL, XML_TAG_PARAMS); + *result = pcmk__xe_create(NULL, PCMK_XE_PARAMETERS); /* Consider all parameters only except private ones to be consistent with * what scheduler does with calculate_secure_digest(). @@ -547,7 +543,7 @@ build_parameter_list(const lrmd_event_data_t *op, } else { crm_trace("Removing attr %s from the xml result", param->rap_name); - xml_remove_prop(*result, param->rap_name); + pcmk__xe_remove_attr(*result, param->rap_name); } } @@ -574,7 +570,9 @@ append_restart_list(lrmd_event_data_t *op, struct ra_metadata_s *metadata, } if (pcmk_is_set(metadata->ra_flags, ra_supports_reload_agent)) { - // Add parameters not marked reloadable to the "op-force-restart" list + /* Add parameters not marked reloadable to the PCMK__XA_OP_FORCE_RESTART + * list + */ list = build_parameter_list(op, metadata, ra_param_reloadable, &restart); @@ -583,7 +581,7 @@ append_restart_list(lrmd_event_data_t *op, struct ra_metadata_s *metadata, * * Before OCF 1.1, Pacemaker abused "unique=0" to indicate * reloadability. Add any parameters with unique="1" to the - * "op-force-restart" list. + * PCMK__XA_OP_FORCE_RESTART list. */ list = build_parameter_list(op, metadata, ra_param_unique, &restart); @@ -593,11 +591,13 @@ append_restart_list(lrmd_event_data_t *op, struct ra_metadata_s *metadata, } digest = calculate_operation_digest(restart, version); - /* Add "op-force-restart" and "op-restart-digest" to indicate the resource supports reload, - * no matter if it actually supports any parameters with unique="1"). */ - crm_xml_add(update, XML_LRM_ATTR_OP_RESTART, + /* Add PCMK__XA_OP_FORCE_RESTART and PCMK__XA_OP_RESTART_DIGEST to indicate + * the resource supports reload, no matter if it actually supports any + * reloadable parameters + */ + crm_xml_add(update, PCMK__XA_OP_FORCE_RESTART, (list == NULL)? "" : (const char *) list->str); - crm_xml_add(update, XML_LRM_ATTR_RESTART_DIGEST, digest); + crm_xml_add(update, PCMK__XA_OP_RESTART_DIGEST, digest); if ((list != NULL) && (list->len > 0)) { crm_trace("%s: %s, %s", op->rsc_id, digest, (const char *) list->str); @@ -622,17 +622,16 @@ append_secure_list(lrmd_event_data_t *op, struct ra_metadata_s *metadata, CRM_LOG_ASSERT(op->params != NULL); - /* - * To keep XML_LRM_ATTR_OP_SECURE short, we want it to contain the - * secure parameters but XML_LRM_ATTR_SECURE_DIGEST to be based on - * the insecure ones + /* To keep PCMK__XA_OP_SECURE_PARAMS short, we want it to contain the secure + * parameters but PCMK__XA_OP_SECURE_DIGEST to be based on the insecure ones */ list = build_parameter_list(op, metadata, ra_param_private, &secure); if (list != NULL) { digest = calculate_operation_digest(secure, version); - crm_xml_add(update, XML_LRM_ATTR_OP_SECURE, (const char *) list->str); - crm_xml_add(update, XML_LRM_ATTR_SECURE_DIGEST, digest); + crm_xml_add(update, PCMK__XA_OP_SECURE_PARAMS, + (const char *) list->str); + crm_xml_add(update, PCMK__XA_OP_SECURE_DIGEST, digest); crm_trace("%s: %s, %s", op->rsc_id, digest, (const char *) list->str); g_string_free(list, TRUE); @@ -672,7 +671,7 @@ controld_add_resource_history_xml_as(const char *func, xmlNode *parent, target_rc = rsc_op_expected_rc(op); - caller_version = g_hash_table_lookup(op->params, XML_ATTR_CRM_VERSION); + caller_version = g_hash_table_lookup(op->params, PCMK_XA_CRM_FEATURE_SET); CRM_CHECK(caller_version != NULL, caller_version = CRM_FEATURE_SET); xml_op = pcmk__create_history_xml(parent, op, caller_version, target_rc, @@ -742,8 +741,8 @@ controld_record_pending_op(const char *node_name, const lrmd_rsc_info_t *rsc, return false; } - // Check action's record-pending meta-attribute (defaults to true) - record_pending = crm_meta_value(op->params, XML_OP_ATTR_PENDING); + // Check action's PCMK_META_RECORD_PENDING meta-attribute (defaults to true) + record_pending = crm_meta_value(op->params, PCMK_META_RECORD_PENDING); if ((record_pending != NULL) && !crm_is_true(record_pending)) { return false; } @@ -890,34 +889,34 @@ controld_update_resource_history(const char *node_name, } // <status> - update = create_xml_node(NULL, XML_CIB_TAG_STATUS); + update = pcmk__xe_create(NULL, PCMK_XE_STATUS); // <node_state ...> - xml = create_xml_node(update, XML_CIB_TAG_STATE); + xml = pcmk__xe_create(update, PCMK__XE_NODE_STATE); if (pcmk__str_eq(node_name, controld_globals.our_nodename, pcmk__str_casei)) { node_id = controld_globals.our_uuid; } else { node_id = node_name; - pcmk__xe_set_bool_attr(xml, XML_NODE_IS_REMOTE, true); + pcmk__xe_set_bool_attr(xml, PCMK_XA_REMOTE_NODE, true); } - crm_xml_add(xml, XML_ATTR_ID, node_id); - crm_xml_add(xml, XML_ATTR_UNAME, node_name); - crm_xml_add(xml, XML_ATTR_ORIGIN, __func__); + crm_xml_add(xml, PCMK_XA_ID, node_id); + crm_xml_add(xml, PCMK_XA_UNAME, node_name); + crm_xml_add(xml, PCMK_XA_CRM_DEBUG_ORIGIN, __func__); // <lrm ...> - xml = create_xml_node(xml, XML_CIB_TAG_LRM); - crm_xml_add(xml, XML_ATTR_ID, node_id); + xml = pcmk__xe_create(xml, PCMK__XE_LRM); + crm_xml_add(xml, PCMK_XA_ID, node_id); // <lrm_resources> - xml = create_xml_node(xml, XML_LRM_TAG_RESOURCES); + xml = pcmk__xe_create(xml, PCMK__XE_LRM_RESOURCES); // <lrm_resource ...> - xml = create_xml_node(xml, XML_LRM_TAG_RESOURCE); - crm_xml_add(xml, XML_ATTR_ID, op->rsc_id); - crm_xml_add(xml, XML_AGENT_ATTR_CLASS, rsc->standard); - crm_xml_add(xml, XML_AGENT_ATTR_PROVIDER, rsc->provider); - crm_xml_add(xml, XML_ATTR_TYPE, rsc->type); + xml = pcmk__xe_create(xml, PCMK__XE_LRM_RESOURCE); + crm_xml_add(xml, PCMK_XA_ID, op->rsc_id); + crm_xml_add(xml, PCMK_XA_CLASS, rsc->standard); + crm_xml_add(xml, PCMK_XA_PROVIDER, rsc->provider); + crm_xml_add(xml, PCMK_XA_TYPE, rsc->type); if (lock_time != 0) { /* Actions on a locked resource should either preserve the lock by * recording it with the action result, or clear it. @@ -925,16 +924,15 @@ controld_update_resource_history(const char *node_name, if (!should_preserve_lock(op)) { lock_time = 0; } - crm_xml_add_ll(xml, XML_CONFIG_ATTR_SHUTDOWN_LOCK, - (long long) lock_time); + crm_xml_add_ll(xml, PCMK_OPT_SHUTDOWN_LOCK, (long long) lock_time); } if (op->params != NULL) { container = g_hash_table_lookup(op->params, - CRM_META "_" XML_RSC_ATTR_CONTAINER); + CRM_META "_" PCMK__META_CONTAINER); if (container != NULL) { crm_trace("Resource %s is a part of container resource %s", op->rsc_id, container); - crm_xml_add(xml, XML_RSC_ATTR_CONTAINER, container); + crm_xml_add(xml, PCMK__META_CONTAINER, container); } } @@ -946,7 +944,7 @@ controld_update_resource_history(const char *node_name, * fenced for running a resource it isn't. */ crm_log_xml_trace(update, __func__); - controld_update_cib(XML_CIB_TAG_STATUS, update, call_opt, cib_rsc_callback); + controld_update_cib(PCMK_XE_STATUS, update, call_opt, cib_rsc_callback); free_xml(update); } @@ -963,15 +961,15 @@ controld_delete_action_history(const lrmd_event_data_t *op) CRM_CHECK(op != NULL, return); - xml_top = create_xml_node(NULL, XML_LRM_TAG_RSC_OP); - crm_xml_add_int(xml_top, XML_LRM_ATTR_CALLID, op->call_id); - crm_xml_add(xml_top, XML_ATTR_TRANSITION_KEY, op->user_data); + xml_top = pcmk__xe_create(NULL, PCMK__XE_LRM_RSC_OP); + crm_xml_add_int(xml_top, PCMK__XA_CALL_ID, op->call_id); + crm_xml_add(xml_top, PCMK__XA_TRANSITION_KEY, op->user_data); if (op->interval_ms > 0) { char *op_id = pcmk__op_key(op->rsc_id, op->op_type, op->interval_ms); /* Avoid deleting last_failure too (if it was a result of this recurring op failing) */ - crm_xml_add(xml_top, XML_ATTR_ID, op_id); + crm_xml_add(xml_top, PCMK_XA_ID, op_id); free(op_id); } @@ -979,31 +977,29 @@ controld_delete_action_history(const lrmd_event_data_t *op) op->rsc_id, op->op_type, op->interval_ms, op->call_id); controld_globals.cib_conn->cmds->remove(controld_globals.cib_conn, - XML_CIB_TAG_STATUS, xml_top, - cib_none); + PCMK_XE_STATUS, xml_top, cib_none); crm_log_xml_trace(xml_top, "op:cancel"); free_xml(xml_top); } /* Define xpath to find LRM resource history entry by node and resource */ #define XPATH_HISTORY \ - "/" XML_TAG_CIB "/" XML_CIB_TAG_STATUS \ - "/" XML_CIB_TAG_STATE "[@" XML_ATTR_UNAME "='%s']" \ - "/" XML_CIB_TAG_LRM "/" XML_LRM_TAG_RESOURCES \ - "/" XML_LRM_TAG_RESOURCE "[@" XML_ATTR_ID "='%s']" \ - "/" XML_LRM_TAG_RSC_OP + "/" PCMK_XE_CIB "/" PCMK_XE_STATUS \ + "/" PCMK__XE_NODE_STATE "[@" PCMK_XA_UNAME "='%s']" \ + "/" PCMK__XE_LRM "/" PCMK__XE_LRM_RESOURCES \ + "/" PCMK__XE_LRM_RESOURCE "[@" PCMK_XA_ID "='%s']" \ + "/" PCMK__XE_LRM_RSC_OP /* ... and also by operation key */ -#define XPATH_HISTORY_ID XPATH_HISTORY \ - "[@" XML_ATTR_ID "='%s']" +#define XPATH_HISTORY_ID XPATH_HISTORY "[@" PCMK_XA_ID "='%s']" /* ... and also by operation key and operation call ID */ #define XPATH_HISTORY_CALL XPATH_HISTORY \ - "[@" XML_ATTR_ID "='%s' and @" XML_LRM_ATTR_CALLID "='%d']" + "[@" PCMK_XA_ID "='%s' and @" PCMK__XA_CALL_ID "='%d']" /* ... and also by operation key and original operation key */ #define XPATH_HISTORY_ORIG XPATH_HISTORY \ - "[@" XML_ATTR_ID "='%s' and @" XML_LRM_ATTR_TASK_KEY "='%s']" + "[@" PCMK_XA_ID "='%s' and @" PCMK__XA_OPERATION_KEY "='%s']" /*! * \internal diff --git a/daemons/controld/controld_cib.h b/daemons/controld/controld_cib.h index dcc5a48..9a8d6ac 100644 --- a/daemons/controld/controld_cib.h +++ b/daemons/controld/controld_cib.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. * @@ -16,7 +16,7 @@ #include <crm/crm.h> #include <crm/common/xml.h> -#include <crm/cib/internal.h> // PCMK__CIB_REQUEST_MODIFY +#include <crm/cib/internal.h> // cib__* #include "controld_globals.h" // controld_globals.cib_conn static inline void @@ -48,7 +48,7 @@ int controld_update_cib(const char *section, xmlNode *data, int options, void *)); unsigned int cib_op_timeout(void); -// Subsections of node_state +// Subsections of PCMK__XE_NODE_STATE enum controld_section_e { controld_section_lrm, controld_section_lrm_unlocked, diff --git a/daemons/controld/controld_control.c b/daemons/controld/controld_control.c index 644d686..368659b 100644 --- a/daemons/controld/controld_control.c +++ b/daemons/controld/controld_control.c @@ -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. * @@ -14,7 +14,7 @@ #include <sys/stat.h> #include <crm/crm.h> -#include <crm/msg_xml.h> +#include <crm/common/xml.h> #include <crm/pengine/rules.h> #include <crm/cluster/internal.h> #include <crm/cluster/election_internal.h> @@ -27,10 +27,10 @@ static qb_ipcs_service_t *ipcs = NULL; static crm_trigger_t *config_read_trigger = NULL; #if SUPPORT_COROSYNC -extern gboolean crm_connect_corosync(crm_cluster_t * cluster); +extern gboolean crm_connect_corosync(pcmk_cluster_t *cluster); #endif -void crm_shutdown(int nsig); +static void crm_shutdown(int nsig); static gboolean crm_read_options(gpointer user_data); /* A_HA_CONNECT */ @@ -41,25 +41,25 @@ do_ha_control(long long action, enum crmd_fsa_input current_input, fsa_data_t * msg_data) { gboolean registered = FALSE; - static crm_cluster_t *cluster = NULL; + static pcmk_cluster_t *cluster = NULL; if (cluster == NULL) { cluster = pcmk_cluster_new(); } if (action & A_HA_DISCONNECT) { - crm_cluster_disconnect(cluster); + pcmk_cluster_disconnect(cluster); crm_info("Disconnected from the cluster"); controld_set_fsa_input_flags(R_HA_DISCONNECTED); } if (action & A_HA_CONNECT) { - crm_set_status_callback(&peer_update_callback); - crm_set_autoreap(FALSE); + pcmk__cluster_set_status_callback(&peer_update_callback); + pcmk__cluster_set_autoreap(false); #if SUPPORT_COROSYNC - if (is_corosync_cluster()) { + if (pcmk_get_cluster_layer() == pcmk_cluster_layer_corosync) { registered = crm_connect_corosync(cluster); } #endif // SUPPORT_COROSYNC @@ -117,7 +117,7 @@ do_shutdown_req(long long action, pcmk__s(controld_globals.dc_name, "not set")); msg = create_request(CRM_OP_SHUTDOWN_REQ, NULL, NULL, CRM_SYSTEM_CRMD, CRM_SYSTEM_CRMD, NULL); - if (send_cluster_message(NULL, crm_msg_crmd, msg, TRUE) == FALSE) { + if (!pcmk__cluster_send_message(NULL, crm_msg_crmd, msg)) { register_fsa_error(C_FSA_INTERNAL, I_ERROR, NULL); } free_xml(msg); @@ -241,7 +241,7 @@ crmd_exit(crm_exit_t exit_code) controld_destroy_transition_trigger(); pcmk__client_cleanup(); - crm_peer_destroy(); + pcmk__cluster_destroy_node_caches(); controld_free_fsa_timers(); te_cleanup_stonith_history_sync(NULL, TRUE); @@ -365,7 +365,7 @@ accept_controller_client(qb_ipcs_connection_t *c, uid_t uid, gid_t gid) { crm_trace("Accepting new IPC client connection"); if (pcmk__new_client(c, uid, gid) == NULL) { - return -EIO; + return -ENOMEM; } return 0; } @@ -381,15 +381,17 @@ dispatch_controller_ipc(qb_ipcs_connection_t * c, void *data, size_t size) xmlNode *msg = pcmk__client_data2xml(client, data, &id, &flags); if (msg == NULL) { - pcmk__ipc_send_ack(client, id, flags, "ack", NULL, CRM_EX_PROTOCOL); + pcmk__ipc_send_ack(client, id, flags, PCMK__XE_ACK, NULL, + CRM_EX_PROTOCOL); return 0; } - pcmk__ipc_send_ack(client, id, flags, "ack", NULL, CRM_EX_INDETERMINATE); + pcmk__ipc_send_ack(client, id, flags, PCMK__XE_ACK, NULL, + CRM_EX_INDETERMINATE); CRM_ASSERT(client->user != NULL); - pcmk__update_acl_user(msg, F_CRM_USER, client->user); + pcmk__update_acl_user(msg, PCMK__XA_CRM_USER, client->user); - crm_xml_add(msg, F_CRM_SYS_FROM, client->id); + crm_xml_add(msg, PCMK__XA_CRM_SYS_FROM, client->id); if (controld_authorize_ipc_message(msg, client, NULL)) { crm_trace("Processing IPC message from client %s", pcmk__client_name(client)); @@ -515,194 +517,6 @@ do_recover(long long action, register_fsa_input(C_FSA_INTERNAL, I_TERMINATE, NULL); } -static pcmk__cluster_option_t controller_options[] = { - /* name, old name, type, allowed values, - * default value, validator, - * short description, - * long description - */ - { - "dc-version", NULL, "string", NULL, PCMK__VALUE_NONE, NULL, - N_("Pacemaker version on cluster node elected Designated Controller (DC)"), - N_("Includes a hash which identifies the exact changeset the code was " - "built from. Used for diagnostic purposes.") - }, - { - "cluster-infrastructure", NULL, "string", NULL, "corosync", NULL, - N_("The messaging stack on which Pacemaker is currently running"), - N_("Used for informational and diagnostic purposes.") - }, - { - "cluster-name", NULL, "string", NULL, NULL, NULL, - N_("An arbitrary name for the cluster"), - N_("This optional value is mostly for users' convenience as desired " - "in administration, but may also be used in Pacemaker " - "configuration rules via the #cluster-name node attribute, and " - "by higher-level tools and resource agents.") - }, - { - XML_CONFIG_ATTR_DC_DEADTIME, NULL, "time", - NULL, "20s", pcmk__valid_interval_spec, - N_("How long to wait for a response from other nodes during start-up"), - N_("The optimal value will depend on the speed and load of your network " - "and the type of switches used.") - }, - { - XML_CONFIG_ATTR_RECHECK, NULL, "time", - N_("Zero disables polling, while positive values are an interval in seconds" - "(unless other units are specified, for example \"5min\")"), - "15min", pcmk__valid_interval_spec, - N_("Polling interval to recheck cluster state and evaluate rules " - "with date specifications"), - N_("Pacemaker is primarily event-driven, and looks ahead to know when to " - "recheck cluster state for failure timeouts and most time-based " - "rules. However, it will also recheck the cluster after this " - "amount of inactivity, to evaluate rules with date specifications " - "and serve as a fail-safe for certain types of scheduler bugs.") - }, - { - "load-threshold", NULL, "percentage", NULL, - "80%", pcmk__valid_percentage, - N_("Maximum amount of system load that should be used by cluster nodes"), - N_("The cluster will slow down its recovery process when the amount of " - "system resources used (currently CPU) approaches this limit"), - }, - { - "node-action-limit", NULL, "integer", NULL, - "0", pcmk__valid_number, - N_("Maximum number of jobs that can be scheduled per node " - "(defaults to 2x cores)") - }, - { XML_CONFIG_ATTR_FENCE_REACTION, NULL, "string", NULL, "stop", NULL, - N_("How a cluster node should react if notified of its own fencing"), - N_("A cluster node may receive notification of its own fencing if fencing " - "is misconfigured, or if fabric fencing is in use that doesn't cut " - "cluster communication. Allowed values are \"stop\" to attempt to " - "immediately stop Pacemaker and stay stopped, or \"panic\" to attempt " - "to immediately reboot the local node, falling back to stop on failure.") - }, - { - XML_CONFIG_ATTR_ELECTION_FAIL, NULL, "time", NULL, - "2min", pcmk__valid_interval_spec, - "*** Advanced Use Only ***", - N_("Declare an election failed if it is not decided within this much " - "time. If you need to adjust this value, it probably indicates " - "the presence of a bug.") - }, - { - XML_CONFIG_ATTR_FORCE_QUIT, NULL, "time", NULL, - "20min", pcmk__valid_interval_spec, - "*** Advanced Use Only ***", - N_("Exit immediately if shutdown does not complete within this much " - "time. If you need to adjust this value, it probably indicates " - "the presence of a bug.") - }, - { - "join-integration-timeout", "crmd-integration-timeout", "time", NULL, - "3min", pcmk__valid_interval_spec, - "*** Advanced Use Only ***", - N_("If you need to adjust this value, it probably indicates " - "the presence of a bug.") - }, - { - "join-finalization-timeout", "crmd-finalization-timeout", "time", NULL, - "30min", pcmk__valid_interval_spec, - "*** Advanced Use Only ***", - N_("If you need to adjust this value, it probably indicates " - "the presence of a bug.") - }, - { - "transition-delay", "crmd-transition-delay", "time", NULL, - "0s", pcmk__valid_interval_spec, - N_("*** Advanced Use Only *** Enabling this option will slow down " - "cluster recovery under all conditions"), - N_("Delay cluster recovery for this much time to allow for additional " - "events to occur. Useful if your configuration is sensitive to " - "the order in which ping updates arrive.") - }, - { - "stonith-watchdog-timeout", NULL, "time", NULL, - "0", controld_verify_stonith_watchdog_timeout, - N_("How long before nodes can be assumed to be safely down when " - "watchdog-based self-fencing via SBD is in use"), - N_("If this is set to a positive value, lost nodes are assumed to " - "self-fence using watchdog-based SBD within this much time. This " - "does not require a fencing resource to be explicitly configured, " - "though a fence_watchdog resource can be configured, to limit use " - "to specific nodes. If this is set to 0 (the default), the cluster " - "will never assume watchdog-based self-fencing. If this is set to a " - "negative value, the cluster will use twice the local value of the " - "`SBD_WATCHDOG_TIMEOUT` environment variable if that is positive, " - "or otherwise treat this as 0. WARNING: When used, this timeout " - "must be larger than `SBD_WATCHDOG_TIMEOUT` on all nodes that use " - "watchdog-based SBD, and Pacemaker will refuse to start on any of " - "those nodes where this is not true for the local value or SBD is " - "not active. When this is set to a negative value, " - "`SBD_WATCHDOG_TIMEOUT` must be set to the same value on all nodes " - "that use SBD, otherwise data corruption or loss could occur.") - }, - { - "stonith-max-attempts", NULL, "integer", NULL, - "10", pcmk__valid_positive_number, - N_("How many times fencing can fail before it will no longer be " - "immediately re-attempted on a target") - }, - - // Already documented in libpe_status (other values must be kept identical) - { - "no-quorum-policy", NULL, "select", - "stop, freeze, ignore, demote, suicide", "stop", pcmk__valid_quorum, - N_("What to do when the cluster does not have quorum"), NULL - }, - { - XML_CONFIG_ATTR_SHUTDOWN_LOCK, NULL, "boolean", NULL, - "false", pcmk__valid_boolean, - N_("Whether to lock resources to a cleanly shut down node"), - N_("When true, resources active on a node when it is cleanly shut down " - "are kept \"locked\" to that node (not allowed to run elsewhere) " - "until they start again on that node after it rejoins (or for at " - "most shutdown-lock-limit, if set). Stonith resources and " - "Pacemaker Remote connections are never locked. Clone and bundle " - "instances and the promoted role of promotable clones are " - "currently never locked, though support could be added in a future " - "release.") - }, - { - XML_CONFIG_ATTR_SHUTDOWN_LOCK_LIMIT, NULL, "time", NULL, - "0", pcmk__valid_interval_spec, - N_("Do not lock resources to a cleanly shut down node longer than " - "this"), - N_("If shutdown-lock is true and this is set to a nonzero time " - "duration, shutdown locks will expire after this much time has " - "passed since the shutdown was initiated, even if the node has not " - "rejoined.") - }, - { - XML_CONFIG_ATTR_NODE_PENDING_TIMEOUT, NULL, "time", NULL, - "0", pcmk__valid_interval_spec, - N_("How long to wait for a node that has joined the cluster to join " - "the controller process group"), - N_("Fence nodes that do not join the controller process group within " - "this much time after joining the cluster, to allow the cluster " - "to continue managing resources. A value of 0 means never fence " - "pending nodes. Setting the value to 2h means fence nodes after " - "2 hours.") - }, -}; - -void -crmd_metadata(void) -{ - const char *desc_short = "Pacemaker controller options"; - const char *desc_long = "Cluster options used by Pacemaker's controller"; - - gchar *s = pcmk__format_option_metadata("pacemaker-controld", desc_short, - desc_long, controller_options, - PCMK__NELEM(controller_options)); - printf("%s", s); - g_free(s); -} - static void config_query_callback(xmlNode * msg, int call_id, int rc, xmlNode * output, void *user_data) { @@ -726,49 +540,62 @@ config_query_callback(xmlNode * msg, int call_id, int rc, xmlNode * output, void } crmconfig = output; - if ((crmconfig != NULL) - && !pcmk__xe_is(crmconfig, XML_CIB_TAG_CRMCONFIG)) { - crmconfig = first_named_child(crmconfig, XML_CIB_TAG_CRMCONFIG); + if ((crmconfig != NULL) && !pcmk__xe_is(crmconfig, PCMK_XE_CRM_CONFIG)) { + crmconfig = pcmk__xe_first_child(crmconfig, PCMK_XE_CRM_CONFIG, NULL, + NULL); } if (!crmconfig) { fsa_data_t *msg_data = NULL; - crm_err("Local CIB query for " XML_CIB_TAG_CRMCONFIG " section failed"); + crm_err("Local CIB query for " PCMK_XE_CRM_CONFIG " section failed"); register_fsa_error(C_FSA_INTERNAL, I_ERROR, NULL); goto bail; } crm_debug("Call %d : Parsing CIB options", call_id); config_hash = pcmk__strkey_table(free, free); - pe_unpack_nvpairs(crmconfig, crmconfig, XML_CIB_TAG_PROPSET, NULL, - config_hash, CIB_OPTIONS_FIRST, FALSE, now, NULL); + pe_unpack_nvpairs(crmconfig, crmconfig, PCMK_XE_CLUSTER_PROPERTY_SET, NULL, + config_hash, PCMK_VALUE_CIB_BOOTSTRAP_OPTIONS, FALSE, now, + NULL); // Validate all options, and use defaults if not already present in hash - pcmk__validate_cluster_options(config_hash, controller_options, - PCMK__NELEM(controller_options)); + pcmk__validate_cluster_options(config_hash); - value = g_hash_table_lookup(config_hash, "no-quorum-policy"); - if (pcmk__str_eq(value, "suicide", pcmk__str_casei) && pcmk__locate_sbd()) { + /* Validate the watchdog timeout in the context of the local node + * environment. If invalid, the controller will exit with a fatal error. + * + * We do this via a wrapper in the controller, so that we call + * pcmk__valid_stonith_watchdog_timeout() only if watchdog fencing is + * enabled for the local node. Otherwise, we may exit unnecessarily. + * + * A validator function in libcrmcommon can't act as such a wrapper, because + * it doesn't have a stonith API connection or the local node name. + */ + value = g_hash_table_lookup(config_hash, PCMK_OPT_STONITH_WATCHDOG_TIMEOUT); + controld_verify_stonith_watchdog_timeout(value); + + value = g_hash_table_lookup(config_hash, PCMK_OPT_NO_QUORUM_POLICY); + if (pcmk__str_eq(value, PCMK_VALUE_FENCE_LEGACY, pcmk__str_casei) + && (pcmk__locate_sbd() != 0)) { controld_set_global_flags(controld_no_quorum_suicide); } - value = g_hash_table_lookup(config_hash, XML_CONFIG_ATTR_SHUTDOWN_LOCK); + value = g_hash_table_lookup(config_hash, PCMK_OPT_SHUTDOWN_LOCK); if (crm_is_true(value)) { controld_set_global_flags(controld_shutdown_lock_enabled); } else { controld_clear_global_flags(controld_shutdown_lock_enabled); } - value = g_hash_table_lookup(config_hash, - XML_CONFIG_ATTR_SHUTDOWN_LOCK_LIMIT); - controld_globals.shutdown_lock_limit = crm_parse_interval_spec(value) - / 1000; + value = g_hash_table_lookup(config_hash, PCMK_OPT_SHUTDOWN_LOCK_LIMIT); + pcmk_parse_interval_spec(value, &controld_globals.shutdown_lock_limit); + controld_globals.shutdown_lock_limit /= 1000; - value = g_hash_table_lookup(config_hash, - XML_CONFIG_ATTR_NODE_PENDING_TIMEOUT); - controld_globals.node_pending_timeout = crm_parse_interval_spec(value) / 1000; + value = g_hash_table_lookup(config_hash, PCMK_OPT_NODE_PENDING_TIMEOUT); + pcmk_parse_interval_spec(value, &controld_globals.node_pending_timeout); + controld_globals.node_pending_timeout /= 1000; - value = g_hash_table_lookup(config_hash, "cluster-name"); + value = g_hash_table_lookup(config_hash, PCMK_OPT_CLUSTER_NAME); pcmk__str_update(&(controld_globals.cluster_name), value); // Let subcomponents initialize their own static variables @@ -777,7 +604,7 @@ config_query_callback(xmlNode * msg, int call_id, int rc, xmlNode * output, void controld_configure_fsa_timers(config_hash); controld_configure_throttle(config_hash); - alerts = first_named_child(output, XML_CIB_TAG_ALERTS); + alerts = pcmk__xe_first_child(output, PCMK_XE_ALERTS, NULL, NULL); crmd_unpack_alerts(alerts); controld_set_fsa_input_flags(R_READ_CONFIG); @@ -809,8 +636,8 @@ crm_read_options(gpointer user_data) { cib_t *cib_conn = controld_globals.cib_conn; int call_id = cib_conn->cmds->query(cib_conn, - "//" XML_CIB_TAG_CRMCONFIG - " | //" XML_CIB_TAG_ALERTS, + "//" PCMK_XE_CRM_CONFIG + " | //" PCMK_XE_ALERTS, NULL, cib_xpath|cib_scope_local); fsa_register_cib_callback(call_id, NULL, config_query_callback); @@ -829,7 +656,7 @@ do_read_config(long long action, controld_trigger_config(); } -void +static void crm_shutdown(int nsig) { const char *value = NULL; @@ -856,9 +683,7 @@ crm_shutdown(int nsig) * config_query_callback() has been run at least once, it doesn't look like * anything could have changed the timer period since then. */ - value = pcmk__cluster_option(NULL, controller_options, - PCMK__NELEM(controller_options), - XML_CONFIG_ATTR_FORCE_QUIT); - default_period_ms = crm_parse_interval_spec(value); + value = pcmk__cluster_option(NULL, PCMK_OPT_SHUTDOWN_ESCALATION); + pcmk_parse_interval_spec(value, &default_period_ms); controld_shutdown_start_countdown(default_period_ms); } diff --git a/daemons/controld/controld_corosync.c b/daemons/controld/controld_corosync.c index b69e821..d0652e4 100644 --- a/daemons/controld/controld_corosync.c +++ b/daemons/controld/controld_corosync.c @@ -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. * @@ -31,14 +31,14 @@ crmd_cs_dispatch(cpg_handle_t handle, const struct cpg_name *groupName, { uint32_t kind = 0; const char *from = NULL; - char *data = pcmk_message_common_cs(handle, nodeid, pid, msg, &kind, &from); + char *data = pcmk__cpg_message_data(handle, nodeid, pid, msg, &kind, &from); if(data == NULL) { return; } if (kind == crm_class_cluster) { crm_node_t *peer = NULL; - xmlNode *xml = string2xml(data); + xmlNode *xml = pcmk__xml_parse(data); if (xml == NULL) { crm_err("Could not parse message content (%d): %.100s", kind, data); @@ -46,10 +46,9 @@ crmd_cs_dispatch(cpg_handle_t handle, const struct cpg_name *groupName, return; } - crm_xml_add(xml, F_ORIG, from); - /* crm_xml_add_int(xml, F_SEQ, wrapper->id); Fake? */ + crm_xml_add(xml, PCMK__XA_SRC, from); - peer = crm_get_peer(0, from); + peer = pcmk__get_node(0, from, NULL, pcmk__node_search_cluster_member); if (!pcmk_is_set(peer->processes, crm_proc_cpg)) { /* If we can still talk to our peer process on that node, * then it must be part of the corosync membership @@ -57,7 +56,7 @@ crmd_cs_dispatch(cpg_handle_t handle, const struct cpg_name *groupName, crm_warn("Receiving messages from a node we think is dead: %s[%d]", peer->uname, peer->id); crm_update_peer_proc(__func__, peer, crm_proc_cpg, - ONLINESTATUS); + PCMK_VALUE_ONLINE); } crmd_ha_msg_filter(xml); free_xml(xml); @@ -119,8 +118,8 @@ cpg_membership_callback(cpg_handle_t handle, const struct cpg_name *cpg_name, if (controld_globals.dc_name != NULL) { crm_node_t *peer = NULL; - peer = pcmk__search_cluster_node_cache(0, controld_globals.dc_name, - NULL); + peer = pcmk__search_node_caches(0, controld_globals.dc_name, + pcmk__node_search_cluster_member); if (peer != NULL) { for (int i = 0; i < left_list_entries; ++i) { if (left_list[i].nodeid == peer->id) { @@ -132,25 +131,26 @@ cpg_membership_callback(cpg_handle_t handle, const struct cpg_name *cpg_name, } // Process the change normally, which will call the peer callback as needed - pcmk_cpg_membership(handle, cpg_name, member_list, member_list_entries, - left_list, left_list_entries, - joined_list, joined_list_entries); + pcmk__cpg_confchg_cb(handle, cpg_name, member_list, member_list_entries, + left_list, left_list_entries, + joined_list, joined_list_entries); controld_clear_global_flags(controld_dc_left); } -extern gboolean crm_connect_corosync(crm_cluster_t * cluster); +extern gboolean crm_connect_corosync(pcmk_cluster_t *cluster); gboolean -crm_connect_corosync(crm_cluster_t * cluster) +crm_connect_corosync(pcmk_cluster_t *cluster) { - if (is_corosync_cluster()) { - crm_set_status_callback(&peer_update_callback); - cluster->cpg.cpg_deliver_fn = crmd_cs_dispatch; - cluster->cpg.cpg_confchg_fn = cpg_membership_callback; - cluster->destroy = crmd_cs_destroy; + if (pcmk_get_cluster_layer() == pcmk_cluster_layer_corosync) { + pcmk__cluster_set_status_callback(&peer_update_callback); - if (crm_cluster_connect(cluster)) { + pcmk_cluster_set_destroy_fn(cluster, crmd_cs_destroy); + pcmk_cpg_set_deliver_fn(cluster, crmd_cs_dispatch); + pcmk_cpg_set_confchg_fn(cluster, cpg_membership_callback); + + if (pcmk_cluster_connect(cluster) == pcmk_rc_ok) { pcmk__corosync_quorum_connect(crmd_quorum_callback, crmd_cs_destroy); return TRUE; diff --git a/daemons/controld/controld_election.c b/daemons/controld/controld_election.c index 70ffecc..1d4ff25 100644 --- a/daemons/controld/controld_election.c +++ b/daemons/controld/controld_election.c @@ -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. * @@ -12,7 +12,6 @@ #include <sys/time.h> #include <sys/resource.h> -#include <crm/msg_xml.h> #include <crm/common/xml.h> #include <crm/cluster/internal.h> #include <crm/cluster/election_internal.h> @@ -44,10 +43,11 @@ controld_election_init(const char *uname) void controld_configure_election(GHashTable *options) { - const char *value = NULL; + const char *value = g_hash_table_lookup(options, PCMK_OPT_ELECTION_TIMEOUT); + guint interval_ms = 0U; - value = g_hash_table_lookup(options, XML_CONFIG_ATTR_ELECTION_FAIL); - election_timeout_set_period(fsa_election, crm_parse_interval_spec(value)); + pcmk_parse_interval_spec(value, &interval_ms); + election_timeout_set_period(fsa_election, interval_ms); } void @@ -201,7 +201,7 @@ feature_update_callback(xmlNode * msg, int call_id, int rc, xmlNode * output, vo #define dc_takeover_update_attr(name, value) do { \ cib__update_node_attr(controld_globals.logger_out, \ controld_globals.cib_conn, cib_none, \ - XML_CIB_TAG_CRMCONFIG, NULL, NULL, NULL, NULL, \ + PCMK_XE_CRM_CONFIG, NULL, NULL, NULL, NULL, \ name, value, NULL, NULL); \ } while (0) @@ -213,7 +213,8 @@ do_dc_takeover(long long action, enum crmd_fsa_input current_input, fsa_data_t * msg_data) { xmlNode *cib = NULL; - const char *cluster_type = name_for_cluster_type(get_cluster_type()); + const enum pcmk_cluster_layer cluster_layer = pcmk_get_cluster_layer(); + const char *cluster_layer_s = pcmk_cluster_layer_text(cluster_layer); pid_t watchdog = pcmk__locate_sbd(); crm_info("Taking over DC status for this partition"); @@ -226,20 +227,23 @@ do_dc_takeover(long long action, controld_globals.cib_conn->cmds->set_primary(controld_globals.cib_conn, cib_scope_local); - cib = create_xml_node(NULL, XML_TAG_CIB); - crm_xml_add(cib, XML_ATTR_CRM_VERSION, CRM_FEATURE_SET); - controld_update_cib(XML_TAG_CIB, cib, cib_none, feature_update_callback); + cib = pcmk__xe_create(NULL, PCMK_XE_CIB); + crm_xml_add(cib, PCMK_XA_CRM_FEATURE_SET, CRM_FEATURE_SET); + controld_update_cib(PCMK_XE_CIB, cib, cib_none, feature_update_callback); - dc_takeover_update_attr(XML_ATTR_HAVE_WATCHDOG, pcmk__btoa(watchdog)); - dc_takeover_update_attr("dc-version", PACEMAKER_VERSION "-" BUILD_VERSION); - dc_takeover_update_attr("cluster-infrastructure", cluster_type); + dc_takeover_update_attr(PCMK_OPT_HAVE_WATCHDOG, pcmk__btoa(watchdog)); + dc_takeover_update_attr(PCMK_OPT_DC_VERSION, + PACEMAKER_VERSION "-" BUILD_VERSION); + dc_takeover_update_attr(PCMK_OPT_CLUSTER_INFRASTRUCTURE, cluster_layer_s); #if SUPPORT_COROSYNC - if ((controld_globals.cluster_name == NULL) && is_corosync_cluster()) { + if ((controld_globals.cluster_name == NULL) + && (pcmk_get_cluster_layer() == pcmk_cluster_layer_corosync)) { + char *cluster_name = pcmk__corosync_cluster_name(); if (cluster_name != NULL) { - dc_takeover_update_attr("cluster-name", cluster_name); + dc_takeover_update_attr(PCMK_OPT_CLUSTER_NAME, cluster_name); } free(cluster_name); } @@ -265,13 +269,15 @@ do_dc_release(long long action, crm_info("DC role released"); if (pcmk_is_set(controld_globals.fsa_input_register, R_SHUTDOWN)) { xmlNode *update = NULL; - crm_node_t *node = crm_get_peer(0, controld_globals.our_nodename); + crm_node_t *node = + pcmk__get_node(0, controld_globals.our_nodename, + NULL, pcmk__node_search_cluster_member); pcmk__update_peer_expected(__func__, node, CRMD_JOINSTATE_DOWN); update = create_node_state_update(node, node_update_expected, NULL, __func__); /* Don't need a based response because controld will stop. */ - fsa_cib_anon_update_discard_reply(XML_CIB_TAG_STATUS, update); + fsa_cib_anon_update_discard_reply(PCMK_XE_STATUS, update); free_xml(update); } register_fsa_input(C_FSA_INTERNAL, I_RELEASE_SUCCESS, NULL); @@ -280,6 +286,5 @@ do_dc_release(long long action, crm_err("Unknown DC action %s", fsa_action2string(action)); } - crm_trace("Am I still the DC? %s", AM_I_DC ? XML_BOOLEAN_YES : XML_BOOLEAN_NO); - + crm_trace("Am I still the DC? %s", pcmk__btoa(AM_I_DC)); } diff --git a/daemons/controld/controld_execd.c b/daemons/controld/controld_execd.c index 480d37d..917c8c0 100644 --- a/daemons/controld/controld_execd.c +++ b/daemons/controld/controld_execd.c @@ -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. * @@ -17,7 +17,6 @@ #include <crm/crm.h> #include <crm/lrmd.h> // lrmd_event_data_t, lrmd_rsc_info_t, etc. #include <crm/services.h> -#include <crm/msg_xml.h> #include <crm/common/xml.h> #include <crm/pengine/rules.h> #include <crm/lrmd_internal.h> @@ -68,7 +67,7 @@ static void copy_instance_keys(gpointer key, gpointer value, gpointer user_data) { if (strstr(key, CRM_META "_") == NULL) { - g_hash_table_replace(user_data, strdup((const char *)key), strdup((const char *)value)); + pcmk__insert_dup(user_data, (const char *) key, (const char *) value); } } @@ -76,7 +75,7 @@ static void copy_meta_keys(gpointer key, gpointer value, gpointer user_data) { if (strstr(key, CRM_META "_") != NULL) { - g_hash_table_replace(user_data, strdup((const char *)key), strdup((const char *)value)); + pcmk__insert_dup(user_data, (const char *) key, (const char *) value); } } @@ -175,14 +174,14 @@ update_history_cache(lrm_state_t * lrm_state, lrmd_rsc_info_t * rsc, lrmd_event_ entry = g_hash_table_lookup(lrm_state->resource_history, op->rsc_id); if (entry == NULL && rsc) { - entry = calloc(1, sizeof(rsc_history_t)); - entry->id = strdup(op->rsc_id); + entry = pcmk__assert_alloc(1, sizeof(rsc_history_t)); + entry->id = pcmk__str_copy(op->rsc_id); g_hash_table_insert(lrm_state->resource_history, entry->id, entry); entry->rsc.id = entry->id; - entry->rsc.type = strdup(rsc->type); - entry->rsc.standard = strdup(rsc->standard); - pcmk__str_update(&entry->rsc.provider, rsc->provider); + entry->rsc.type = pcmk__str_copy(rsc->type); + entry->rsc.standard = pcmk__str_copy(rsc->standard); + entry->rsc.provider = pcmk__str_copy(rsc->provider); } else if (entry == NULL) { crm_info("Resource %s no longer exists, not updating cache", op->rsc_id); @@ -539,18 +538,21 @@ build_active_RAs(lrm_state_t * lrm_state, xmlNode * rsc_list) while (g_hash_table_iter_next(&iter, NULL, (void **)&entry)) { GList *gIter = NULL; - xmlNode *xml_rsc = create_xml_node(rsc_list, XML_LRM_TAG_RESOURCE); + xmlNode *xml_rsc = pcmk__xe_create(rsc_list, PCMK__XE_LRM_RESOURCE); - crm_xml_add(xml_rsc, XML_ATTR_ID, entry->id); - crm_xml_add(xml_rsc, XML_ATTR_TYPE, entry->rsc.type); - crm_xml_add(xml_rsc, XML_AGENT_ATTR_CLASS, entry->rsc.standard); - crm_xml_add(xml_rsc, XML_AGENT_ATTR_PROVIDER, entry->rsc.provider); + crm_xml_add(xml_rsc, PCMK_XA_ID, entry->id); + crm_xml_add(xml_rsc, PCMK_XA_TYPE, entry->rsc.type); + crm_xml_add(xml_rsc, PCMK_XA_CLASS, entry->rsc.standard); + crm_xml_add(xml_rsc, PCMK_XA_PROVIDER, entry->rsc.provider); if (entry->last && entry->last->params) { - const char *container = g_hash_table_lookup(entry->last->params, CRM_META"_"XML_RSC_ATTR_CONTAINER); + static const char *name = CRM_META "_" PCMK__META_CONTAINER; + const char *container = g_hash_table_lookup(entry->last->params, + name); + if (container) { crm_trace("Resource %s is a part of container resource %s", entry->id, container); - crm_xml_add(xml_rsc, XML_RSC_ATTR_CONTAINER, container); + crm_xml_add(xml_rsc, PCMK__META_CONTAINER, container); } } controld_add_resource_history_xml(xml_rsc, &(entry->rsc), entry->failed, @@ -581,7 +583,7 @@ controld_query_executor_state(void) return NULL; } - peer = crm_get_peer_full(0, lrm_state->node_name, CRM_GET_PEER_ANY); + peer = pcmk__get_node(0, lrm_state->node_name, NULL, pcmk__node_search_any); CRM_CHECK(peer != NULL, return NULL); xml_state = create_node_state_update(peer, @@ -591,9 +593,9 @@ controld_query_executor_state(void) return NULL; } - xml_data = create_xml_node(xml_state, XML_CIB_TAG_LRM); - crm_xml_add(xml_data, XML_ATTR_ID, peer->uuid); - rsc_list = create_xml_node(xml_data, XML_LRM_TAG_RESOURCES); + xml_data = pcmk__xe_create(xml_state, PCMK__XE_LRM); + crm_xml_add(xml_data, PCMK_XA_ID, peer->uuid); + rsc_list = pcmk__xe_create(xml_data, PCMK__XE_LRM_RESOURCES); /* Build a list of active (not always running) resources */ build_active_RAs(lrm_state, rsc_list); @@ -651,7 +653,7 @@ controld_trigger_delete_refresh(const char *from_sys, const char *rsc_id) crm_debug("Triggering a refresh after %s cleaned %s", from_sys, rsc_id); cib__update_node_attr(controld_globals.logger_out, controld_globals.cib_conn, cib_none, - XML_CIB_TAG_CRMCONFIG, NULL, NULL, NULL, NULL, + PCMK_XE_CRM_CONFIG, NULL, NULL, NULL, NULL, "last-lrm-refresh", now_s, NULL, NULL); free(now_s); } @@ -661,8 +663,8 @@ static void notify_deleted(lrm_state_t * lrm_state, ha_msg_input_t * input, const char *rsc_id, int rc) { lrmd_event_data_t *op = NULL; - const char *from_sys = crm_element_value(input->msg, F_CRM_SYS_FROM); - const char *from_host = crm_element_value(input->msg, F_CRM_HOST_FROM); + const char *from_sys = crm_element_value(input->msg, PCMK__XA_CRM_SYS_FROM); + const char *from_host = crm_element_value(input->msg, PCMK__XA_SRC); crm_info("Notifying %s on %s that %s was%s deleted", from_sys, (from_host? from_host : "localhost"), rsc_id, @@ -711,7 +713,7 @@ delete_rsc_entry(lrm_state_t *lrm_state, ha_msg_input_t *input, CRM_CHECK(rsc_id != NULL, return); if (rc == pcmk_ok) { - char *rsc_id_copy = strdup(rsc_id); + char *rsc_id_copy = pcmk__str_copy(rsc_id); if (rsc_iter) { g_hash_table_iter_remove(rsc_iter); @@ -907,7 +909,7 @@ static int get_lrm_resource(lrm_state_t *lrm_state, const xmlNode *rsc_xml, gboolean do_create, lrmd_rsc_info_t **rsc_info) { - const char *id = ID(rsc_xml); + const char *id = pcmk__xe_id(rsc_xml); CRM_CHECK(lrm_state && rsc_xml && rsc_info, return -EINVAL); CRM_CHECK(id, return -EINVAL); @@ -921,7 +923,7 @@ get_lrm_resource(lrm_state_t *lrm_state, const xmlNode *rsc_xml, // If resource isn't known by ID, try clone name, if provided if (!*rsc_info) { - const char *long_id = crm_element_value(rsc_xml, XML_ATTR_ID_LONG); + const char *long_id = crm_element_value(rsc_xml, PCMK__XA_LONG_ID); if (long_id) { *rsc_info = lrm_state_get_rsc_info(lrm_state, long_id, 0); @@ -929,9 +931,9 @@ get_lrm_resource(lrm_state_t *lrm_state, const xmlNode *rsc_xml, } if ((*rsc_info == NULL) && do_create) { - const char *class = crm_element_value(rsc_xml, XML_AGENT_ATTR_CLASS); - const char *provider = crm_element_value(rsc_xml, XML_AGENT_ATTR_PROVIDER); - const char *type = crm_element_value(rsc_xml, XML_ATTR_TYPE); + const char *class = crm_element_value(rsc_xml, PCMK_XA_CLASS); + const char *provider = crm_element_value(rsc_xml, PCMK_XA_PROVIDER); + const char *type = crm_element_value(rsc_xml, PCMK_XA_TYPE); int rc; crm_trace("Registering resource %s with the executor", id); @@ -979,10 +981,10 @@ delete_resource(lrm_state_t *lrm_state, const char *id, lrmd_rsc_info_t *rsc, crm_info("Deletion of resource '%s' from executor is pending", id); if (request) { struct pending_deletion_op_s *op = NULL; - char *ref = crm_element_value_copy(request->msg, XML_ATTR_REFERENCE); + char *ref = crm_element_value_copy(request->msg, PCMK_XA_REFERENCE); - op = calloc(1, sizeof(struct pending_deletion_op_s)); - op->rsc = strdup(rsc->id); + op = pcmk__assert_alloc(1, sizeof(struct pending_deletion_op_s)); + op->rsc = pcmk__str_copy(rsc->id); op->input = copy_ha_msg_input(request); g_hash_table_insert(lrm_state->deletion_ops, ref, op); } @@ -1096,25 +1098,26 @@ synthesize_lrmd_failure(lrm_state_t *lrm_state, const xmlNode *action, const char *exit_reason) { lrmd_event_data_t *op = NULL; - const char *operation = crm_element_value(action, XML_LRM_ATTR_TASK); - const char *target_node = crm_element_value(action, XML_LRM_ATTR_TARGET); - xmlNode *xml_rsc = find_xml_node(action, XML_CIB_TAG_RESOURCE, TRUE); + const char *operation = crm_element_value(action, PCMK_XA_OPERATION); + const char *target_node = crm_element_value(action, PCMK__META_ON_NODE); + xmlNode *xml_rsc = pcmk__xe_first_child(action, PCMK_XE_PRIMITIVE, NULL, + NULL); - if ((xml_rsc == NULL) || (ID(xml_rsc) == NULL)) { + if ((xml_rsc == NULL) || (pcmk__xe_id(xml_rsc) == NULL)) { /* @TODO Should we do something else, like direct ack? */ crm_info("Can't fake %s failure (%d) on %s without resource configuration", - crm_element_value(action, XML_LRM_ATTR_TASK_KEY), rc, + crm_element_value(action, PCMK__XA_OPERATION_KEY), rc, target_node); return; } else if(operation == NULL) { /* This probably came from crm_resource -C, nothing to do */ crm_info("Can't fake %s failure (%d) on %s without operation", - ID(xml_rsc), rc, target_node); + pcmk__xe_id(xml_rsc), rc, target_node); return; } - op = construct_op(lrm_state, action, ID(xml_rsc), operation); + op = construct_op(lrm_state, action, pcmk__xe_id(xml_rsc), operation); if (pcmk__str_eq(operation, PCMK_ACTION_NOTIFY, pcmk__str_casei)) { // Notifications can't fail @@ -1146,7 +1149,7 @@ lrm_op_target(const xmlNode *xml) const char *target = NULL; if (xml) { - target = crm_element_value(xml, XML_LRM_ATTR_TARGET); + target = crm_element_value(xml, PCMK__META_ON_NODE); } if (target == NULL) { target = controld_globals.our_nodename; @@ -1160,7 +1163,7 @@ fail_lrm_resource(xmlNode *xml, lrm_state_t *lrm_state, const char *user_name, { lrmd_event_data_t *op = NULL; lrmd_rsc_info_t *rsc = NULL; - xmlNode *xml_rsc = find_xml_node(xml, XML_CIB_TAG_RESOURCE, TRUE); + xmlNode *xml_rsc = pcmk__xe_first_child(xml, PCMK_XE_PRIMITIVE, NULL, NULL); CRM_CHECK(xml_rsc != NULL, return); @@ -1172,18 +1175,20 @@ fail_lrm_resource(xmlNode *xml, lrm_state_t *lrm_state, const char *user_name, * and pass that event to the executor client callback so it will be * processed as if it came from the executor. */ - op = construct_op(lrm_state, xml, ID(xml_rsc), "asyncmon"); + op = construct_op(lrm_state, xml, pcmk__xe_id(xml_rsc), "asyncmon"); free((char*) op->user_data); op->user_data = NULL; op->interval_ms = 0; if (user_name && !pcmk__is_privileged(user_name)) { - crm_err("%s does not have permission to fail %s", user_name, ID(xml_rsc)); + crm_err("%s does not have permission to fail %s", + user_name, pcmk__xe_id(xml_rsc)); fake_op_status(lrm_state, op, PCMK_EXEC_ERROR, PCMK_OCF_INSUFFICIENT_PRIV, "Unprivileged user cannot fail resources"); - controld_ack_event_directly(from_host, from_sys, NULL, op, ID(xml_rsc)); + controld_ack_event_directly(from_host, from_sys, NULL, op, + pcmk__xe_id(xml_rsc)); lrmd_free_event(op); return; } @@ -1204,7 +1209,8 @@ fail_lrm_resource(xmlNode *xml, lrm_state_t *lrm_state, const char *user_name, "Cannot fail unknown resource"); } - controld_ack_event_directly(from_host, from_sys, NULL, op, ID(xml_rsc)); + controld_ack_event_directly(from_host, from_sys, NULL, op, + pcmk__xe_id(xml_rsc)); lrmd_free_event(op); } @@ -1242,16 +1248,17 @@ static bool do_lrm_cancel(ha_msg_input_t *input, lrm_state_t *lrm_state, const char *op_task = NULL; guint interval_ms = 0; gboolean in_progress = FALSE; - xmlNode *params = find_xml_node(input->xml, XML_TAG_ATTRS, TRUE); + xmlNode *params = pcmk__xe_first_child(input->xml, PCMK__XE_ATTRIBUTES, + NULL, NULL); CRM_CHECK(params != NULL, return FALSE); - meta_key = crm_meta_name(XML_LRM_ATTR_TASK); + meta_key = crm_meta_name(PCMK_XA_OPERATION); op_task = crm_element_value(params, meta_key); free(meta_key); CRM_CHECK(op_task != NULL, return FALSE); - meta_key = crm_meta_name(XML_LRM_ATTR_INTERVAL_MS); + meta_key = crm_meta_name(PCMK_META_INTERVAL); if (crm_element_value_ms(params, meta_key, &interval_ms) != pcmk_ok) { free(meta_key); return FALSE; @@ -1260,7 +1267,7 @@ static bool do_lrm_cancel(ha_msg_input_t *input, lrm_state_t *lrm_state, op_key = pcmk__op_key(rsc->id, op_task, interval_ms); - meta_key = crm_meta_name(XML_LRM_ATTR_CALLID); + meta_key = crm_meta_name(PCMK__XA_CALL_ID); call_id = crm_element_value(params, meta_key); free(meta_key); @@ -1302,7 +1309,8 @@ static bool do_lrm_cancel(ha_msg_input_t *input, lrm_state_t *lrm_state, * not abcdaa8, they will time out waiting for the ack (no * released versions of Pacemaker are affected). */ - const char *peer_version = crm_element_value(params, XML_ATTR_CRM_VERSION); + const char *peer_version = crm_element_value(params, + PCMK_XA_CRM_FEATURE_SET); if (compare_version(peer_version, "3.0.8") <= 0) { crm_info("Sending compatibility ack for %s cancellation to %s (CRM version %s)", @@ -1359,9 +1367,8 @@ new_metadata_cb_data(lrmd_rsc_info_t *rsc, xmlNode *input_xml) { struct metadata_cb_data *data = NULL; - data = calloc(1, sizeof(struct metadata_cb_data)); - CRM_ASSERT(data != NULL); - data->input_xml = copy_xml(input_xml); + data = pcmk__assert_alloc(1, sizeof(struct metadata_cb_data)); + data->input_xml = pcmk__xml_copy(NULL, input_xml); data->rsc = lrmd_copy_rsc_info(rsc); return data; } @@ -1433,11 +1440,11 @@ do_lrm_invoke(long long action, } CRM_ASSERT(lrm_state != NULL); - user_name = pcmk__update_acl_user(input->msg, F_CRM_USER, NULL); - crm_op = crm_element_value(input->msg, F_CRM_TASK); - from_sys = crm_element_value(input->msg, F_CRM_SYS_FROM); + user_name = pcmk__update_acl_user(input->msg, PCMK__XA_CRM_USER, NULL); + crm_op = crm_element_value(input->msg, PCMK__XA_CRM_TASK); + from_sys = crm_element_value(input->msg, PCMK__XA_CRM_SYS_FROM); if (!pcmk__str_eq(from_sys, CRM_SYSTEM_TENGINE, pcmk__str_none)) { - from_host = crm_element_value(input->msg, F_CRM_HOST_FROM); + from_host = crm_element_value(input->msg, PCMK__XA_SRC); } if (pcmk__str_eq(crm_op, PCMK_ACTION_LRM_DELETE, pcmk__str_none)) { @@ -1447,7 +1454,7 @@ do_lrm_invoke(long long action, operation = PCMK_ACTION_DELETE; } else if (input->xml != NULL) { - operation = crm_element_value(input->xml, XML_LRM_ATTR_TASK); + operation = crm_element_value(input->xml, PCMK_XA_OPERATION); } CRM_CHECK(!pcmk__str_empty(crm_op) || !pcmk__str_empty(operation), return); @@ -1471,7 +1478,7 @@ do_lrm_invoke(long long action, // @COMPAT DCs <1.1.14 in a rolling upgrade might schedule this op } else if (pcmk__str_eq(operation, CRM_OP_PROBED, pcmk__str_none)) { - update_attrd(lrm_state->node_name, CRM_OP_PROBED, XML_BOOLEAN_TRUE, + update_attrd(lrm_state->node_name, CRM_OP_PROBED, PCMK_VALUE_TRUE, user_name, is_remote_node); } else if (pcmk__str_eq(crm_op, CRM_OP_REPROBE, pcmk__str_none) @@ -1480,20 +1487,21 @@ do_lrm_invoke(long long action, if (input->xml != NULL) { // For CRM_OP_REPROBE, a NULL target means we're targeting all nodes - raw_target = crm_element_value(input->xml, XML_LRM_ATTR_TARGET); + raw_target = crm_element_value(input->xml, PCMK__META_ON_NODE); } handle_reprobe_op(lrm_state, from_sys, from_host, user_name, is_remote_node, (raw_target == NULL)); } else if (operation != NULL) { lrmd_rsc_info_t *rsc = NULL; - xmlNode *xml_rsc = find_xml_node(input->xml, XML_CIB_TAG_RESOURCE, TRUE); + xmlNode *xml_rsc = pcmk__xe_first_child(input->xml, PCMK_XE_PRIMITIVE, + NULL, NULL); gboolean create_rsc = !pcmk__str_eq(operation, PCMK_ACTION_DELETE, pcmk__str_none); int rc; // We can't return anything meaningful without a resource ID - CRM_CHECK(xml_rsc && ID(xml_rsc), return); + CRM_CHECK((xml_rsc != NULL) && (pcmk__xe_id(xml_rsc) != NULL), return); rc = get_lrm_resource(lrm_state, xml_rsc, create_rsc, &rsc); if (rc == -ENOTCONN) { @@ -1509,15 +1517,15 @@ do_lrm_invoke(long long action, */ crm_notice("Not registering resource '%s' for a %s event " CRM_XS " get-rc=%d (%s) transition-key=%s", - ID(xml_rsc), operation, - rc, pcmk_strerror(rc), ID(input->xml)); - delete_rsc_entry(lrm_state, input, ID(xml_rsc), NULL, pcmk_ok, - user_name, true); + pcmk__xe_id(xml_rsc), operation, + rc, pcmk_strerror(rc), pcmk__xe_id(input->xml)); + delete_rsc_entry(lrm_state, input, pcmk__xe_id(xml_rsc), NULL, + pcmk_ok, user_name, true); return; } else if (rc == -EINVAL) { // Resource operation on malformed resource - crm_err("Invalid resource definition for %s", ID(xml_rsc)); + crm_err("Invalid resource definition for %s", pcmk__xe_id(xml_rsc)); crm_log_xml_warn(input->msg, "invalid resource"); synthesize_lrmd_failure(lrm_state, input->xml, PCMK_EXEC_ERROR, PCMK_OCF_NOT_CONFIGURED, // fatal error @@ -1528,7 +1536,7 @@ do_lrm_invoke(long long action, // Error communicating with the executor crm_err("Could not register resource '%s' with executor: %s " CRM_XS " rc=%d", - ID(xml_rsc), pcmk_strerror(rc), rc); + pcmk__xe_id(xml_rsc), pcmk_strerror(rc), rc); crm_log_xml_warn(input->msg, "failed registration"); synthesize_lrmd_failure(lrm_state, input->xml, PCMK_EXEC_ERROR, PCMK_OCF_INVALID_PARAM, // hard error @@ -1632,30 +1640,30 @@ construct_op(const lrm_state_t *lrm_state, const xmlNode *rsc_op, */ op->params = pcmk__strkey_table(free, free); - g_hash_table_insert(op->params, strdup(XML_ATTR_CRM_VERSION), strdup(CRM_FEATURE_SET)); + pcmk__insert_dup(op->params, PCMK_XA_CRM_FEATURE_SET, CRM_FEATURE_SET); crm_trace("Constructed %s op for %s", operation, rsc_id); return op; } params = xml2list(rsc_op); - g_hash_table_remove(params, CRM_META "_op_target_rc"); + g_hash_table_remove(params, CRM_META "_" PCMK__META_OP_TARGET_RC); - op_delay = crm_meta_value(params, XML_OP_ATTR_START_DELAY); + op_delay = crm_meta_value(params, PCMK_META_START_DELAY); pcmk__scan_min_int(op_delay, &op->start_delay, 0); - op_timeout = crm_meta_value(params, XML_ATTR_TIMEOUT); + op_timeout = crm_meta_value(params, PCMK_META_TIMEOUT); pcmk__scan_min_int(op_timeout, &op->timeout, 0); - if (pcmk__guint_from_hash(params, CRM_META "_" XML_LRM_ATTR_INTERVAL_MS, 0, + if (pcmk__guint_from_hash(params, CRM_META "_" PCMK_META_INTERVAL, 0, &(op->interval_ms)) != pcmk_rc_ok) { op->interval_ms = 0; } /* Use pcmk_monitor_timeout instead of meta timeout for stonith recurring monitor, if set */ - primitive = find_xml_node(rsc_op, XML_CIB_TAG_RESOURCE, FALSE); - class = crm_element_value(primitive, XML_AGENT_ATTR_CLASS); + primitive = pcmk__xe_first_child(rsc_op, PCMK_XE_PRIMITIVE, NULL, NULL); + class = crm_element_value(primitive, PCMK_XA_CLASS); if (pcmk_is_set(pcmk_get_ra_caps(class), pcmk_ra_cap_fence_params) && pcmk__str_eq(operation, PCMK_ACTION_MONITOR, pcmk__str_casei) @@ -1663,7 +1671,9 @@ construct_op(const lrm_state_t *lrm_state, const xmlNode *rsc_op, op_timeout = g_hash_table_lookup(params, "pcmk_monitor_timeout"); if (op_timeout != NULL) { - op->timeout = crm_get_msec(op_timeout); + long long timeout_ms = crm_get_msec(op_timeout); + + op->timeout = (int) QB_MIN(timeout_ms, INT_MAX); } } @@ -1701,10 +1711,10 @@ construct_op(const lrm_state_t *lrm_state, const xmlNode *rsc_op, op->start_delay = 0; } - transition = crm_element_value(rsc_op, XML_ATTR_TRANSITION_KEY); + transition = crm_element_value(rsc_op, PCMK__XA_TRANSITION_KEY); CRM_CHECK(transition != NULL, return op); - op->user_data = strdup(transition); + op->user_data = pcmk__str_copy(transition); if (op->interval_ms != 0) { if (pcmk__strcase_any_of(operation, PCMK_ACTION_START, PCMK_ACTION_STOP, @@ -1745,23 +1755,25 @@ controld_ack_event_directly(const char *to_host, const char *to_sys, CRM_CHECK(op != NULL, return); if (op->rsc_id == NULL) { + // op->rsc_id is a (const char *) but lrmd_free_event() frees it CRM_ASSERT(rsc_id != NULL); - op->rsc_id = strdup(rsc_id); + op->rsc_id = pcmk__str_copy(rsc_id); } if (to_sys == NULL) { to_sys = CRM_SYSTEM_TENGINE; } - peer = crm_get_peer(0, controld_globals.our_nodename); + peer = pcmk__get_node(0, controld_globals.our_nodename, NULL, + pcmk__node_search_cluster_member); update = create_node_state_update(peer, node_update_none, NULL, __func__); - iter = create_xml_node(update, XML_CIB_TAG_LRM); - crm_xml_add(iter, XML_ATTR_ID, controld_globals.our_uuid); - iter = create_xml_node(iter, XML_LRM_TAG_RESOURCES); - iter = create_xml_node(iter, XML_LRM_TAG_RESOURCE); + iter = pcmk__xe_create(update, PCMK__XE_LRM); + crm_xml_add(iter, PCMK_XA_ID, controld_globals.our_uuid); + iter = pcmk__xe_create(iter, PCMK__XE_LRM_RESOURCES); + iter = pcmk__xe_create(iter, PCMK__XE_LRM_RESOURCE); - crm_xml_add(iter, XML_ATTR_ID, op->rsc_id); + crm_xml_add(iter, PCMK_XA_ID, op->rsc_id); controld_add_resource_history_xml(iter, rsc, op, controld_globals.our_nodename); @@ -1771,7 +1783,7 @@ controld_ack_event_directly(const char *to_host, const char *to_sys, crm_debug("ACK'ing resource op " PCMK__OP_FMT " from %s: %s", op->rsc_id, op->op_type, op->interval_ms, op->user_data, - crm_element_value(reply, XML_ATTR_REFERENCE)); + crm_element_value(reply, PCMK_XA_REFERENCE)); if (relay_message(reply, TRUE) == FALSE) { crm_log_xml_err(reply, "Unable to route reply"); @@ -1916,10 +1928,10 @@ do_lrm_rsc_op(lrm_state_t *lrm_state, lrmd_rsc_info_t *rsc, xmlNode *msg, CRM_CHECK((rsc != NULL) && (msg != NULL), return); - operation = crm_element_value(msg, XML_LRM_ATTR_TASK); + operation = crm_element_value(msg, PCMK_XA_OPERATION); CRM_CHECK(!pcmk__str_empty(operation), return); - transition = crm_element_value(msg, XML_ATTR_TRANSITION_KEY); + transition = crm_element_value(msg, PCMK__XA_TRANSITION_KEY); if (pcmk__str_empty(transition)) { crm_log_xml_err(msg, "Missing transition number"); } @@ -1982,8 +1994,8 @@ do_lrm_rsc_op(lrm_state_t *lrm_state, lrmd_rsc_info_t *rsc, xmlNode *msg, crm_notice("Discarding attempt to perform action %s on %s in state %s " "(shutdown=%s)", operation, rsc->id, fsa_state2string(controld_globals.fsa_state), - pcmk__btoa(pcmk_is_set(controld_globals.fsa_input_register, - R_SHUTDOWN))); + pcmk__flag_text(controld_globals.fsa_input_register, + R_SHUTDOWN)); lrmd__set_result(op, PCMK_OCF_UNKNOWN_ERROR, PCMK_EXEC_INVALID, nack_reason); @@ -2013,17 +2025,17 @@ do_lrm_rsc_op(lrm_state_t *lrm_state, lrmd_rsc_info_t *rsc, xmlNode *msg, char *call_id_s = make_stop_id(rsc->id, call_id); active_op_t *pending = NULL; - pending = calloc(1, sizeof(active_op_t)); + pending = pcmk__assert_alloc(1, sizeof(active_op_t)); crm_trace("Recording pending op: %d - %s %s", call_id, op_id, call_id_s); pending->call_id = call_id; pending->interval_ms = op->interval_ms; - pending->op_type = strdup(operation); - pending->op_key = strdup(op_id); - pending->rsc_id = strdup(rsc->id); + pending->op_type = pcmk__str_copy(operation); + pending->op_key = pcmk__str_copy(op_id); + pending->rsc_id = pcmk__str_copy(rsc->id); pending->start_time = time(NULL); - pcmk__str_update(&pending->user_data, op->user_data); - if (crm_element_value_epoch(msg, XML_CONFIG_ATTR_SHUTDOWN_LOCK, + pending->user_data = pcmk__str_copy(op->user_data); + if (crm_element_value_epoch(msg, PCMK_OPT_SHUTDOWN_LOCK, &(pending->lock_time)) != pcmk_ok) { pending->lock_time = 0; } @@ -2082,7 +2094,7 @@ unescape_newlines(const char *string) return NULL; } - ret = strdup(string); + ret = pcmk__str_copy(string); pch = strstr(ret, escaped_newline); while (pch != NULL) { /* Replace newline escape pattern with actual newline (and a space so we @@ -2249,11 +2261,12 @@ process_lrm_event(lrm_state_t *lrm_state, lrmd_event_data_t *op, rsc = lrm_state_get_rsc_info(lrm_state, op->rsc_id, 0); } if ((rsc == NULL) && action_xml) { - xmlNode *xml = find_xml_node(action_xml, XML_CIB_TAG_RESOURCE, TRUE); + xmlNode *xml = pcmk__xe_first_child(action_xml, PCMK_XE_PRIMITIVE, NULL, + NULL); - const char *standard = crm_element_value(xml, XML_AGENT_ATTR_CLASS); - const char *provider = crm_element_value(xml, XML_AGENT_ATTR_PROVIDER); - const char *type = crm_element_value(xml, XML_ATTR_TYPE); + const char *standard = crm_element_value(xml, PCMK_XA_CLASS); + const char *provider = crm_element_value(xml, PCMK_XA_PROVIDER); + const char *type = crm_element_value(xml, PCMK_XA_TYPE); if (standard && type) { crm_info("%s agent information not cached, using %s%s%s:%s from action XML", @@ -2270,7 +2283,7 @@ process_lrm_event(lrm_state_t *lrm_state, lrmd_event_data_t *op, if (lrm_state) { node_name = lrm_state->node_name; } else if (action_xml) { - node_name = crm_element_value(action_xml, XML_LRM_ATTR_TARGET); + node_name = crm_element_value(action_xml, PCMK__META_ON_NODE); } if(pending == NULL) { diff --git a/daemons/controld/controld_execd_state.c b/daemons/controld/controld_execd_state.c index b90cc5e..1919684 100644 --- a/daemons/controld/controld_execd_state.c +++ b/daemons/controld/controld_execd_state.c @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the Pacemaker project contributors + * Copyright 2012-2024 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -12,8 +12,8 @@ #include <errno.h> #include <crm/crm.h> -#include <crm/msg_xml.h> #include <crm/common/iso8601.h> +#include <crm/common/xml.h> #include <crm/pengine/rules.h> #include <crm/pengine/rules_internal.h> #include <crm/lrmd_internal.h> @@ -116,12 +116,9 @@ lrm_state_create(const char *node_name) return NULL; } - state = calloc(1, sizeof(lrm_state_t)); - if (!state) { - return NULL; - } + state = pcmk__assert_alloc(1, sizeof(lrm_state_t)); - state->node_name = strdup(node_name); + state->node_name = pcmk__str_copy(node_name); state->rsc_info_cache = pcmk__strkey_table(NULL, free_rsc_info); state->deletion_ops = pcmk__strkey_table(free, free_deletion_op); state->active_ops = pcmk__strkey_table(free, free_recurring_op); @@ -453,7 +450,7 @@ crmd_proxy_dispatch(const char *session, xmlNode *msg) { crm_trace("Processing proxied IPC message from session %s", session); crm_log_xml_trace(msg, "controller[inbound]"); - crm_xml_add(msg, F_CRM_SYS_FROM, session); + crm_xml_add(msg, PCMK__XA_CRM_SYS_FROM, session); if (controld_authorize_ipc_message(msg, NULL, session)) { route_message(C_IPC_MESSAGE, msg); } @@ -477,8 +474,9 @@ remote_config_check(xmlNode * msg, int call_id, int rc, xmlNode * output, void * crm_debug("Call %d : Parsing CIB options", call_id); - pe_unpack_nvpairs(output, output, XML_CIB_TAG_PROPSET, NULL, - config_hash, CIB_OPTIONS_FIRST, FALSE, now, NULL); + pe_unpack_nvpairs(output, output, PCMK_XE_CLUSTER_PROPERTY_SET, NULL, + config_hash, PCMK_VALUE_CIB_BOOTSTRAP_OPTIONS, FALSE, + now, NULL); /* Now send it to the remote peer */ lrmd__validate_remote_settings(lrmd, config_hash); @@ -492,20 +490,22 @@ static void crmd_remote_proxy_cb(lrmd_t *lrmd, void *userdata, xmlNode *msg) { lrm_state_t *lrm_state = userdata; - const char *session = crm_element_value(msg, F_LRMD_IPC_SESSION); + const char *session = crm_element_value(msg, PCMK__XA_LRMD_IPC_SESSION); remote_proxy_t *proxy = g_hash_table_lookup(proxy_table, session); - const char *op = crm_element_value(msg, F_LRMD_IPC_OP); + const char *op = crm_element_value(msg, PCMK__XA_LRMD_IPC_OP); if (pcmk__str_eq(op, LRMD_IPC_OP_NEW, pcmk__str_casei)) { - const char *channel = crm_element_value(msg, F_LRMD_IPC_IPC_SERVER); + const char *channel = crm_element_value(msg, PCMK__XA_LRMD_IPC_SERVER); proxy = crmd_remote_proxy_new(lrmd, lrm_state->node_name, session, channel); if (!remote_ra_controlling_guest(lrm_state)) { if (proxy != NULL) { cib_t *cib_conn = controld_globals.cib_conn; - /* Look up stonith-watchdog-timeout and send to the remote peer for validation */ - int rc = cib_conn->cmds->query(cib_conn, XML_CIB_TAG_CRMCONFIG, + /* Look up PCMK_OPT_STONITH_WATCHDOG_TIMEOUT and send to the + * remote peer for validation + */ + int rc = cib_conn->cmds->query(cib_conn, PCMK_XE_CRM_CONFIG, NULL, cib_scope_local); cib_conn->cmds->register_callback_full(cib_conn, rc, 10, FALSE, lrmd, @@ -525,7 +525,8 @@ crmd_remote_proxy_cb(lrmd_t *lrmd, void *userdata, xmlNode *msg) if (!remote_ra_is_in_maintenance(lrm_state)) { now_s = pcmk__ttoa(time(NULL)); - update_attrd(lrm_state->node_name, XML_CIB_ATTR_SHUTDOWN, now_s, NULL, TRUE); + update_attrd(lrm_state->node_name, PCMK__NODE_ATTR_SHUTDOWN, now_s, + NULL, TRUE); free(now_s); remote_proxy_ack_shutdown(lrmd); @@ -545,39 +546,43 @@ crmd_remote_proxy_cb(lrmd_t *lrmd, void *userdata, xmlNode *msg) * to send to ourselves over IPC -- do it directly. */ int flags = 0; - xmlNode *request = get_message_xml(msg, F_LRMD_IPC_MSG); + xmlNode *wrapper = pcmk__xe_first_child(msg, PCMK__XE_LRMD_IPC_MSG, + NULL, NULL); + xmlNode *request = pcmk__xe_first_child(wrapper, NULL, NULL, NULL); CRM_CHECK(request != NULL, return); CRM_CHECK(lrm_state->node_name, return); - crm_xml_add(request, XML_ACL_TAG_ROLE, "pacemaker-remote"); - pcmk__update_acl_user(request, F_LRMD_IPC_USER, lrm_state->node_name); + crm_xml_add(request, PCMK_XE_ACL_ROLE, "pacemaker-remote"); + pcmk__update_acl_user(request, PCMK__XA_LRMD_IPC_USER, + lrm_state->node_name); /* Pacemaker Remote nodes don't know their own names (as known to the * cluster). When getting a node info request with no name or ID, add * the name, so we don't return info for ourselves instead of the * Pacemaker Remote node. */ - if (pcmk__str_eq(crm_element_value(request, F_CRM_TASK), CRM_OP_NODE_INFO, pcmk__str_casei)) { + if (pcmk__str_eq(crm_element_value(request, PCMK__XA_CRM_TASK), + CRM_OP_NODE_INFO, pcmk__str_none)) { int node_id = 0; - crm_element_value_int(request, XML_ATTR_ID, &node_id); + crm_element_value_int(request, PCMK_XA_ID, &node_id); if ((node_id <= 0) - && (crm_element_value(request, XML_ATTR_UNAME) == NULL)) { - crm_xml_add(request, XML_ATTR_UNAME, lrm_state->node_name); + && (crm_element_value(request, PCMK_XA_UNAME) == NULL)) { + crm_xml_add(request, PCMK_XA_UNAME, lrm_state->node_name); } } crmd_proxy_dispatch(session, request); - crm_element_value_int(msg, F_LRMD_IPC_MSG_FLAGS, &flags); + crm_element_value_int(msg, PCMK__XA_LRMD_IPC_MSG_FLAGS, &flags); if (flags & crm_ipc_client_response) { int msg_id = 0; - xmlNode *op_reply = create_xml_node(NULL, "ack"); + xmlNode *op_reply = pcmk__xe_create(NULL, PCMK__XE_ACK); - crm_xml_add(op_reply, "function", __func__); - crm_xml_add_int(op_reply, "line", __LINE__); + crm_xml_add(op_reply, PCMK_XA_FUNCTION, __func__); + crm_xml_add_int(op_reply, PCMK__XA_LINE, __LINE__); - crm_element_value_int(msg, F_LRMD_IPC_MSG_ID, &msg_id); + crm_element_value_int(msg, PCMK__XA_LRMD_IPC_MSG_ID, &msg_id); remote_proxy_relay_response(proxy, op_reply, msg_id); free_xml(op_reply); @@ -650,7 +655,7 @@ lrm_state_get_metadata(lrm_state_t * lrm_state, * @TODO Make meta-data calls asynchronous. (This will be part of a larger * project to make meta-data calls via the executor rather than directly.) */ - params = lrmd_key_value_add(params, CRM_META "_" XML_LRM_ATTR_TARGET, + params = lrmd_key_value_add(params, CRM_META "_" PCMK__META_ON_NODE, lrm_state->node_name); return ((lrmd_t *) lrm_state->conn)->cmds->get_metadata_params(lrm_state->conn, diff --git a/daemons/controld/controld_fencing.c b/daemons/controld/controld_fencing.c index 9557d9e..dcffc8e 100644 --- a/daemons/controld/controld_fencing.c +++ b/daemons/controld/controld_fencing.c @@ -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. * @@ -9,7 +9,6 @@ #include <crm_internal.h> #include <crm/crm.h> -#include <crm/msg_xml.h> #include <crm/common/xml.h> #include <crm/stonith-ng.h> #include <crm/fencing/internal.h> @@ -63,9 +62,9 @@ set_fence_reaction(const char *reaction_s) fence_reaction_panic = true; } else { - if (!pcmk__str_eq(reaction_s, "stop", pcmk__str_casei)) { + if (!pcmk__str_eq(reaction_s, PCMK_VALUE_STOP, pcmk__str_casei)) { crm_warn("Invalid value '%s' for %s, using 'stop'", - reaction_s, XML_CONFIG_ATTR_FENCE_REACTION); + reaction_s, PCMK_OPT_FENCE_REACTION); } fence_reaction_panic = false; } @@ -82,10 +81,10 @@ controld_configure_fencing(GHashTable *options) { const char *value = NULL; - value = g_hash_table_lookup(options, XML_CONFIG_ATTR_FENCE_REACTION); + value = g_hash_table_lookup(options, PCMK_OPT_FENCE_REACTION); set_fence_reaction(value); - value = g_hash_table_lookup(options, "stonith-max-attempts"); + value = g_hash_table_lookup(options, PCMK_OPT_STONITH_MAX_ATTEMPTS); update_stonith_max_attempts(value); } @@ -176,7 +175,7 @@ st_fail_count_increment(const char *target) } rec->count = 1; - g_hash_table_insert(stonith_failures, strdup(target), rec); + g_hash_table_insert(stonith_failures, pcmk__str_copy(target), rec); } } @@ -191,8 +190,8 @@ cib_fencing_updated(xmlNode *msg, int call_id, int rc, xmlNode *output, crm_err("Fencing update %d for %s: failed - %s (%d)", call_id, (char *)user_data, pcmk_strerror(rc), rc); crm_log_xml_warn(msg, "Failed update"); - abort_transition(INFINITY, pcmk__graph_shutdown, "CIB update failed", - NULL); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_shutdown, + "CIB update failed", NULL); } else { crm_info("Fencing update %d for %s: complete", call_id, (char *)user_data); @@ -222,7 +221,7 @@ send_stonith_update(pcmk__graph_action_t *action, const char *target, * Try getting any existing node cache entry also by node uuid in case it * doesn't have an uname yet. */ - peer = pcmk__get_peer_full(0, target, uuid, CRM_GET_PEER_ANY); + peer = pcmk__get_node(0, target, uuid, pcmk__node_search_any); CRM_CHECK(peer != NULL, return); @@ -236,7 +235,7 @@ send_stonith_update(pcmk__graph_action_t *action, const char *target, if (peer->uuid == NULL) { crm_info("Recording uuid '%s' for node '%s'", uuid, target); - peer->uuid = strdup(uuid); + peer->uuid = pcmk__str_copy(uuid); } crmd_peer_down(peer, TRUE); @@ -248,21 +247,21 @@ send_stonith_update(pcmk__graph_action_t *action, const char *target, if (peer->flags & crm_remote_node) { char *now_s = pcmk__ttoa(time(NULL)); - crm_xml_add(node_state, XML_NODE_IS_FENCED, now_s); + crm_xml_add(node_state, PCMK__XA_NODE_FENCED, now_s); free(now_s); } /* Force our known ID */ - crm_xml_add(node_state, XML_ATTR_ID, uuid); + crm_xml_add(node_state, PCMK_XA_ID, uuid); rc = controld_globals.cib_conn->cmds->modify(controld_globals.cib_conn, - XML_CIB_TAG_STATUS, node_state, + PCMK_XE_STATUS, node_state, cib_scope_local |cib_can_create); /* Delay processing the trigger until the update completes */ crm_debug("Sending fencing update %d for %s", rc, target); - fsa_register_cib_callback(rc, strdup(target), cib_fencing_updated); + fsa_register_cib_callback(rc, pcmk__str_copy(target), cib_fencing_updated); // Make sure it sticks /* controld_globals.cib_conn->cmds->bump_epoch(controld_globals.cib_conn, @@ -293,7 +292,8 @@ abort_for_stonith_failure(enum pcmk__graph_next abort_action, if ((abort_action != pcmk__graph_wait) && too_many_st_failures(target)) { abort_action = pcmk__graph_wait; } - abort_transition(INFINITY, abort_action, "Stonith failed", reason); + abort_transition(PCMK_SCORE_INFINITY, abort_action, "Stonith failed", + reason); } @@ -315,7 +315,8 @@ static GList *stonith_cleanup_list = NULL; */ void add_stonith_cleanup(const char *target) { - stonith_cleanup_list = g_list_append(stonith_cleanup_list, strdup(target)); + stonith_cleanup_list = g_list_append(stonith_cleanup_list, + pcmk__str_copy(target)); } /*! @@ -374,8 +375,9 @@ execute_stonith_cleanup(void) for (iter = stonith_cleanup_list; iter != NULL; iter = iter->next) { char *target = iter->data; - crm_node_t *target_node = crm_get_peer(0, target); - const char *uuid = crm_peer_uuid(target_node); + crm_node_t *target_node = + pcmk__get_node(0, target, NULL, pcmk__node_search_cluster_member); + const char *uuid = pcmk__cluster_node_uuid(target_node); crm_notice("Marking %s, target of a previous stonith action, as clean", target); send_stonith_update(NULL, target, uuid); @@ -424,13 +426,13 @@ fail_incompletable_stonith(pcmk__graph_t *graph) continue; } - task = crm_element_value(action->xml, XML_LRM_ATTR_TASK); + task = crm_element_value(action->xml, PCMK_XA_OPERATION); if (pcmk__str_eq(task, PCMK_ACTION_STONITH, pcmk__str_casei)) { pcmk__set_graph_action_flags(action, pcmk__graph_action_failed); last_action = action->xml; pcmk__update_graph(graph, action); crm_notice("Failing action %d (%s): fencer terminated", - action->id, ID(action->xml)); + action->id, pcmk__xe_id(action->xml)); } } } @@ -580,15 +582,17 @@ handle_fence_notification(stonith_t *st, stonith_event_t *event) event->id); if (succeeded) { - crm_node_t *peer = pcmk__search_known_node_cache(0, event->target, - CRM_GET_PEER_ANY); + const uint32_t flags = pcmk__node_search_any + |pcmk__node_search_cluster_cib; + + crm_node_t *peer = pcmk__search_node_caches(0, event->target, flags); const char *uuid = NULL; if (peer == NULL) { return; } - uuid = crm_peer_uuid(peer); + uuid = pcmk__cluster_node_uuid(peer); if (AM_I_DC) { /* The DC always sends updates */ @@ -598,8 +602,8 @@ handle_fence_notification(stonith_t *st, stonith_event_t *event) * hosted any guest nodes, and call remote_node_down() for them. * Unfortunately, the controller doesn't have a simple, reliable way * to map hosts to guests. It might be possible to track this in the - * peer cache via crm_remote_peer_cache_refresh(). For now, we rely - * on the scheduler creating fence pseudo-events for the guests. + * peer cache via refresh_remote_nodes(). For now, we rely on the + * scheduler creating fence pseudo-events for the guests. */ if (!pcmk__str_eq(client, te_client_id, pcmk__str_casei)) { @@ -608,7 +612,7 @@ handle_fence_notification(stonith_t *st, stonith_event_t *event) */ crm_info("External fencing operation from %s fenced %s", client, event->target); - abort_transition(INFINITY, pcmk__graph_restart, + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, "External Fencing Operation", NULL); } @@ -713,15 +717,16 @@ controld_timer_fencer_connect(gpointer user_data) } if (rc == pcmk_ok) { - stonith_api->cmds->register_notification(stonith_api, - T_STONITH_NOTIFY_DISCONNECT, - tengine_stonith_connection_destroy); - stonith_api->cmds->register_notification(stonith_api, - T_STONITH_NOTIFY_FENCE, - handle_fence_notification); - stonith_api->cmds->register_notification(stonith_api, - T_STONITH_NOTIFY_HISTORY_SYNCED, - tengine_stonith_history_synced); + stonith_api_operations_t *cmds = stonith_api->cmds; + + cmds->register_notification(stonith_api, + PCMK__VALUE_ST_NOTIFY_DISCONNECT, + tengine_stonith_connection_destroy); + cmds->register_notification(stonith_api, PCMK__VALUE_ST_NOTIFY_FENCE, + handle_fence_notification); + cmds->register_notification(stonith_api, + PCMK__VALUE_ST_NOTIFY_HISTORY_SYNCED, + tengine_stonith_history_synced); te_trigger_stonith_history_sync(TRUE); crm_notice("Fencer successfully connected"); } @@ -829,7 +834,7 @@ tengine_stonith_callback(stonith_t *stonith, stonith_callback_data_t *data) goto bail; } - target = crm_element_value(action->xml, XML_LRM_ATTR_TARGET); + target = crm_element_value(action->xml, PCMK__META_ON_NODE); if (target == NULL) { crm_err("Ignoring fence operation %d result: No target given (bug?)", data->call_id); @@ -838,8 +843,10 @@ tengine_stonith_callback(stonith_t *stonith, stonith_callback_data_t *data) stop_te_timer(action); if (stonith__exit_status(data) == CRM_EX_OK) { - const char *uuid = crm_element_value(action->xml, XML_LRM_ATTR_TARGET_UUID); - const char *op = crm_meta_value(action->params, "stonith_action"); + const char *uuid = crm_element_value(action->xml, + PCMK__META_ON_NODE_UUID); + const char *op = crm_meta_value(action->params, + PCMK__META_STONITH_ACTION); crm_info("Fence operation %d for %s succeeded", data->call_id, target); if (!(pcmk_is_set(action->flags, pcmk__graph_action_confirmed))) { @@ -864,11 +871,12 @@ tengine_stonith_callback(stonith_t *stonith, stonith_callback_data_t *data) is_remote_node); free(now); - value = crm_meta_value(action->params, XML_OP_ATTR_DIGESTS_ALL); + value = crm_meta_value(action->params, PCMK__META_DIGESTS_ALL); update_attrd(target, CRM_ATTR_DIGESTS_ALL, value, NULL, is_remote_node); - value = crm_meta_value(action->params, XML_OP_ATTR_DIGESTS_SECURE); + value = crm_meta_value(action->params, + PCMK__META_DIGESTS_SECURE); update_attrd(target, CRM_ATTR_DIGESTS_SECURE, value, NULL, is_remote_node); @@ -952,10 +960,11 @@ controld_execute_fence_action(pcmk__graph_t *graph, pcmk__graph_action_t *action) { int rc = 0; - const char *id = ID(action->xml); - const char *uuid = crm_element_value(action->xml, XML_LRM_ATTR_TARGET_UUID); - const char *target = crm_element_value(action->xml, XML_LRM_ATTR_TARGET); - const char *type = crm_meta_value(action->params, "stonith_action"); + const char *id = pcmk__xe_id(action->xml); + const char *uuid = crm_element_value(action->xml, PCMK__META_ON_NODE_UUID); + const char *target = crm_element_value(action->xml, PCMK__META_ON_NODE); + const char *type = crm_meta_value(action->params, + PCMK__META_STONITH_ACTION); char *transition_key = NULL; const char *priority_delay = NULL; int delay_i = 0; @@ -973,7 +982,8 @@ controld_execute_fence_action(pcmk__graph_t *graph, return EPROTO; } - priority_delay = crm_meta_value(action->params, XML_CONFIG_ATTR_PRIORITY_FENCING_DELAY); + priority_delay = crm_meta_value(action->params, + PCMK_OPT_PRIORITY_FENCING_DELAY); crm_notice("Requesting fencing (%s) targeting node %s " CRM_XS " action=%s timeout=%i%s%s", @@ -1001,17 +1011,16 @@ controld_execute_fence_action(pcmk__graph_t *graph, bool controld_verify_stonith_watchdog_timeout(const char *value) { - long st_timeout = value? crm_get_msec(value) : 0; + long long st_timeout = (value != NULL)? crm_get_msec(value) : 0; const char *our_nodename = controld_globals.our_nodename; - gboolean rv = TRUE; if (st_timeout == 0 || (stonith_api && (stonith_api->state != stonith_disconnected) && stonith__watchdog_fencing_enabled_for_node_api(stonith_api, our_nodename))) { - rv = pcmk__valid_sbd_timeout(value); + return pcmk__valid_stonith_watchdog_timeout(value); } - return rv; + return true; } /* end stonith API client functions */ @@ -1042,7 +1051,7 @@ te_cleanup_stonith_history_sync(stonith_t *st, bool free_timers) } if (st) { - st->cmds->remove_notification(st, T_STONITH_NOTIFY_HISTORY_SYNCED); + st->cmds->remove_notification(st, PCMK__VALUE_ST_NOTIFY_HISTORY_SYNCED); } } diff --git a/daemons/controld/controld_fsa.c b/daemons/controld/controld_fsa.c index 06559b8..79b3507 100644 --- a/daemons/controld/controld_fsa.c +++ b/daemons/controld/controld_fsa.c @@ -1,5 +1,5 @@ /* - * Copyright 2004-2022 the Pacemaker project contributors + * Copyright 2004-2024 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -18,7 +18,6 @@ #include <crm/crm.h> #include <crm/lrmd.h> #include <crm/cib.h> -#include <crm/msg_xml.h> #include <crm/common/xml.h> #include <crm/cluster/election_internal.h> #include <crm/cluster.h> @@ -198,7 +197,7 @@ s_crmd_fsa(enum crmd_fsa_cause cause) if ((controld_globals.fsa_message_queue == NULL) && (controld_globals.fsa_actions != A_NOTHING)) { /* fake the first message so we can get into the loop */ - fsa_data = calloc(1, sizeof(fsa_data_t)); + fsa_data = pcmk__assert_alloc(1, sizeof(fsa_data_t)); fsa_data->fsa_input = I_NULL; fsa_data->fsa_cause = C_FSA_INTERNAL; fsa_data->origin = __func__; @@ -283,8 +282,8 @@ s_crmd_fsa(enum crmd_fsa_cause cause) crm_debug("Exiting the FSA: queue=%d, fsa_actions=%#llx, stalled=%s", g_list_length(controld_globals.fsa_message_queue), (unsigned long long) controld_globals.fsa_actions, - pcmk__btoa(pcmk_is_set(controld_globals.flags, - controld_fsa_is_stalled))); + pcmk__flag_text(controld_globals.flags, + controld_fsa_is_stalled)); } else { crm_trace("Exiting the FSA"); } @@ -549,7 +548,7 @@ check_join_counts(fsa_data_t *msg_data) return; } - npeers = crm_active_peers(); + npeers = pcmk__cluster_num_active_nodes(); count = crmd_join_phase_count(crm_join_confirmed); if (count == npeers) { if (npeers == 1) { diff --git a/daemons/controld/controld_fsa.h b/daemons/controld/controld_fsa.h index 2b79f07..ad1c4fa 100644 --- a/daemons/controld/controld_fsa.h +++ b/daemons/controld/controld_fsa.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. * @@ -401,7 +401,9 @@ enum crmd_fsa_input { # define R_HAVE_CIB 0x00020000ULL /* Do we have an up-to-date CIB */ # define R_MEMBERSHIP 0x00100000ULL /* Have we got cluster layer data yet */ -# define R_PEER_DATA 0x00200000ULL /* Have we got T_CL_STATUS data yet */ + +// Ever received membership-layer data +# define R_PEER_DATA 0x00200000ULL # define R_HA_DISCONNECTED 0x00400000ULL /* did we sign out of our own accord */ diff --git a/daemons/controld/controld_join_client.c b/daemons/controld/controld_join_client.c index 805ecbd..8faf58b 100644 --- a/daemons/controld/controld_join_client.c +++ b/daemons/controld/controld_join_client.c @@ -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. * @@ -11,7 +11,6 @@ #include <crm/crm.h> #include <crm/cib.h> -#include <crm/msg_xml.h> #include <crm/common/xml.h> #include <pacemaker-controld.h> @@ -34,8 +33,9 @@ static void update_dc_expected(const xmlNode *msg) { if ((controld_globals.dc_name != NULL) - && pcmk__xe_attr_is_true(msg, F_CRM_DC_LEAVING)) { - crm_node_t *dc_node = crm_get_peer(0, controld_globals.dc_name); + && pcmk__xe_attr_is_true(msg, PCMK__XA_DC_LEAVING)) { + crm_node_t *dc_node = pcmk__get_node(0, controld_globals.dc_name, NULL, + pcmk__node_search_cluster_member); pcmk__update_peer_expected(__func__, dc_node, CRMD_JOINSTATE_DOWN); } @@ -55,7 +55,7 @@ do_cl_join_query(long long action, sleep(1); // Give the cluster layer time to propagate to the DC update_dc(NULL); /* Unset any existing value so that the result is not discarded */ crm_debug("Querying for a DC"); - send_cluster_message(NULL, crm_msg_crmd, req, FALSE); + pcmk__cluster_send_message(NULL, crm_msg_crmd, req); free_xml(req); } @@ -84,7 +84,7 @@ do_cl_join_announce(long long action, crm_debug("Announcing availability"); update_dc(NULL); - send_cluster_message(NULL, crm_msg_crmd, req, FALSE); + pcmk__cluster_send_message(NULL, crm_msg_crmd, req); free_xml(req); } else { @@ -112,10 +112,10 @@ do_cl_join_offer_respond(long long action, CRM_CHECK(input != NULL, return); - welcome_from = crm_element_value(input->msg, F_CRM_HOST_FROM); - join_id = crm_element_value(input->msg, F_CRM_JOIN_ID); + welcome_from = crm_element_value(input->msg, PCMK__XA_SRC); + join_id = crm_element_value(input->msg, PCMK__XA_JOIN_ID); crm_trace("Accepting cluster join offer from node %s "CRM_XS" join-%s", - welcome_from, crm_element_value(input->msg, F_CRM_JOIN_ID)); + welcome_from, crm_element_value(input->msg, PCMK__XA_JOIN_ID)); /* we only ever want the last one */ if (query_call_id > 0) { @@ -134,7 +134,7 @@ do_cl_join_offer_respond(long long action, query_call_id = cib_conn->cmds->query(cib_conn, NULL, NULL, cib_scope_local|cib_no_children); - fsa_register_cib_callback(query_call_id, strdup(join_id), + fsa_register_cib_callback(query_call_id, pcmk__str_copy(join_id), join_query_callback); crm_trace("Registered join query callback: %d", query_call_id); @@ -146,7 +146,7 @@ void join_query_callback(xmlNode * msg, int call_id, int rc, xmlNode * output, void *user_data) { char *join_id = user_data; - xmlNode *generation = create_xml_node(NULL, XML_CIB_TAG_GENERATION_TUPPLE); + xmlNode *generation = pcmk__xe_create(NULL, PCMK__XE_GENERATION_TUPLE); CRM_LOG_ASSERT(join_id != NULL); @@ -166,19 +166,21 @@ join_query_callback(xmlNode * msg, int call_id, int rc, xmlNode * output, void * } else { xmlNode *reply = NULL; + const crm_node_t *dc_node = + pcmk__get_node(0, controld_globals.dc_name, NULL, + pcmk__node_search_cluster_member); crm_debug("Respond to join offer join-%s from %s", join_id, controld_globals.dc_name); - copy_in_properties(generation, output); + pcmk__xe_copy_attrs(generation, output, pcmk__xaf_none); reply = create_request(CRM_OP_JOIN_REQUEST, generation, controld_globals.dc_name, CRM_SYSTEM_DC, CRM_SYSTEM_CRMD, NULL); - crm_xml_add(reply, F_CRM_JOIN_ID, join_id); - crm_xml_add(reply, XML_ATTR_CRM_VERSION, CRM_FEATURE_SET); - send_cluster_message(crm_get_peer(0, controld_globals.dc_name), - crm_msg_crmd, reply, TRUE); + crm_xml_add(reply, PCMK__XA_JOIN_ID, join_id); + crm_xml_add(reply, PCMK_XA_CRM_FEATURE_SET, CRM_FEATURE_SET); + pcmk__cluster_send_message(dc_node, crm_msg_crmd, reply); free_xml(reply); } @@ -190,29 +192,32 @@ void set_join_state(const char *start_state, const char *node_name, const char *node_uuid, bool remote) { - if (pcmk__str_eq(start_state, "standby", pcmk__str_casei)) { + if (pcmk__str_eq(start_state, PCMK_VALUE_STANDBY, pcmk__str_casei)) { crm_notice("Forcing node %s to join in %s state per configured " "environment", node_name, start_state); cib__update_node_attr(controld_globals.logger_out, controld_globals.cib_conn, cib_sync_call, - XML_CIB_TAG_NODES, node_uuid, - NULL, NULL, NULL, "standby", "on", NULL, - remote ? "remote" : NULL); + PCMK_XE_NODES, node_uuid, + NULL, NULL, NULL, PCMK_NODE_ATTR_STANDBY, + PCMK_VALUE_TRUE, NULL, + (remote? PCMK_VALUE_REMOTE : NULL)); - } else if (pcmk__str_eq(start_state, "online", pcmk__str_casei)) { + } else if (pcmk__str_eq(start_state, PCMK_VALUE_ONLINE, pcmk__str_casei)) { crm_notice("Forcing node %s to join in %s state per configured " "environment", node_name, start_state); cib__update_node_attr(controld_globals.logger_out, controld_globals.cib_conn, cib_sync_call, - XML_CIB_TAG_NODES, node_uuid, - NULL, NULL, NULL, "standby", "off", NULL, - remote ? "remote" : NULL); + PCMK_XE_NODES, node_uuid, + NULL, NULL, NULL, PCMK_NODE_ATTR_STANDBY, + PCMK_VALUE_FALSE, NULL, + (remote? PCMK_VALUE_REMOTE : NULL)); - } else if (pcmk__str_eq(start_state, "default", pcmk__str_casei)) { + } else if (pcmk__str_eq(start_state, PCMK_VALUE_DEFAULT, pcmk__str_casei)) { crm_debug("Not forcing a starting state on node %s", node_name); } else { - crm_warn("Unrecognized start state '%s', using 'default' (%s)", + crm_warn("Unrecognized start state '%s', using " + "'" PCMK_VALUE_DEFAULT "' (%s)", start_state, node_name); } } @@ -220,11 +225,11 @@ set_join_state(const char *start_state, const char *node_name, const char *node_ static int update_conn_host_cache(xmlNode *node, void *userdata) { - const char *remote = crm_element_value(node, XML_ATTR_ID); - const char *conn_host = crm_element_value(node, PCMK__XA_CONN_HOST); - const char *state = crm_element_value(node, XML_CIB_TAG_STATE); + const char *remote = crm_element_value(node, PCMK_XA_ID); + const char *conn_host = crm_element_value(node, PCMK__XA_CONNECTION_HOST); + const char *state = crm_element_value(node, PCMK__XA_NODE_STATE); - crm_node_t *remote_peer = crm_remote_peer_get(remote); + crm_node_t *remote_peer = pcmk__cluster_lookup_remote_node(remote); if (remote_peer == NULL) { return pcmk_rc_ok; @@ -256,8 +261,8 @@ do_cl_join_finalize_respond(long long action, const char *start_state = pcmk__env_option(PCMK__ENV_NODE_START_STATE); int join_id = -1; - const char *op = crm_element_value(input->msg, F_CRM_TASK); - const char *welcome_from = crm_element_value(input->msg, F_CRM_HOST_FROM); + const char *op = crm_element_value(input->msg, PCMK__XA_CRM_TASK); + const char *welcome_from = crm_element_value(input->msg, PCMK__XA_SRC); if (!pcmk__str_eq(op, CRM_OP_JOIN_ACKNAK, pcmk__str_casei)) { crm_trace("Ignoring op=%s message", op); @@ -269,7 +274,7 @@ do_cl_join_finalize_respond(long long action, was_nack = FALSE; } - crm_element_value_int(input->msg, F_CRM_JOIN_ID, &join_id); + crm_element_value_int(input->msg, PCMK__XA_JOIN_ID, &join_id); if (was_nack) { crm_err("Shutting down because cluster join with leader %s failed " @@ -305,8 +310,11 @@ do_cl_join_finalize_respond(long long action, xmlNode *reply = create_request(CRM_OP_JOIN_CONFIRM, tmp1, controld_globals.dc_name, CRM_SYSTEM_DC, CRM_SYSTEM_CRMD, NULL); + const crm_node_t *dc_node = + pcmk__get_node(0, controld_globals.dc_name, NULL, + pcmk__node_search_cluster_member); - crm_xml_add_int(reply, F_CRM_JOIN_ID, join_id); + crm_xml_add_int(reply, PCMK__XA_JOIN_ID, join_id); crm_debug("Confirming join-%d: sending local operation history to %s", join_id, controld_globals.dc_name); @@ -333,8 +341,7 @@ do_cl_join_finalize_respond(long long action, } } - send_cluster_message(crm_get_peer(0, controld_globals.dc_name), - crm_msg_crmd, reply, TRUE); + pcmk__cluster_send_message(dc_node, crm_msg_crmd, reply); free_xml(reply); if (AM_I_DC == FALSE) { @@ -347,9 +354,10 @@ do_cl_join_finalize_respond(long long action, /* Update the remote node cache with information about which node * is hosting the connection. */ - remotes = pcmk__xe_match(input->msg, XML_CIB_TAG_NODES, NULL, NULL); + remotes = pcmk__xe_first_child(input->msg, PCMK_XE_NODES, NULL, NULL); if (remotes != NULL) { - pcmk__xe_foreach_child(remotes, XML_CIB_TAG_NODE, update_conn_host_cache, NULL); + pcmk__xe_foreach_child(remotes, PCMK_XE_NODE, + update_conn_host_cache, NULL); } } else { diff --git a/daemons/controld/controld_join_dc.c b/daemons/controld/controld_join_dc.c index 2fe6710..e943e65 100644 --- a/daemons/controld/controld_join_dc.c +++ b/daemons/controld/controld_join_dc.c @@ -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. * @@ -11,7 +11,6 @@ #include <crm/crm.h> -#include <crm/msg_xml.h> #include <crm/common/xml.h> #include <crm/cluster.h> @@ -188,12 +187,12 @@ create_dc_message(const char *join_op, const char *host_to) CRM_SYSTEM_DC, NULL); /* Identify which election this is a part of */ - crm_xml_add_int(msg, F_CRM_JOIN_ID, current_join_id); + crm_xml_add_int(msg, PCMK__XA_JOIN_ID, current_join_id); /* Add a field specifying whether the DC is shutting down. This keeps the * joining node from fencing the old DC if it becomes the new DC. */ - pcmk__xe_set_bool_attr(msg, F_CRM_DC_LEAVING, + pcmk__xe_set_bool_attr(msg, PCMK__XA_DC_LEAVING, pcmk_is_set(controld_globals.fsa_input_register, R_SHUTDOWN)); return msg; @@ -206,7 +205,7 @@ join_make_offer(gpointer key, gpointer value, gpointer user_data) crm_node_t *member = (crm_node_t *)value; CRM_ASSERT(member != NULL); - if (crm_is_peer_active(member) == FALSE) { + if (!pcmk__cluster_is_node_active(member)) { crm_info("Not making join-%d offer to inactive node %s", current_join_id, (member->uname? member->uname : "with unknown name")); @@ -249,10 +248,10 @@ join_make_offer(gpointer key, gpointer value, gpointer user_data) offer = create_dc_message(CRM_OP_JOIN_OFFER, member->uname); // Advertise our feature set so the joining node can bail if not compatible - crm_xml_add(offer, XML_ATTR_CRM_VERSION, CRM_FEATURE_SET); + crm_xml_add(offer, PCMK_XA_CRM_FEATURE_SET, CRM_FEATURE_SET); crm_info("Sending join-%d offer to %s", current_join_id, member->uname); - send_cluster_message(member, crm_msg_crmd, offer, TRUE); + pcmk__cluster_send_message(member, crm_msg_crmd, offer); free_xml(offer); crm_update_peer_join(__func__, member, crm_join_welcomed); @@ -313,12 +312,12 @@ do_dc_join_offer_one(long long action, return; } - join_to = crm_element_value(welcome->msg, F_CRM_HOST_FROM); + join_to = crm_element_value(welcome->msg, PCMK__XA_SRC); if (join_to == NULL) { crm_err("Can't make join-%d offer to unknown node", current_join_id); return; } - member = crm_get_peer(0, join_to); + member = pcmk__get_node(0, join_to, NULL, pcmk__node_search_cluster_member); /* It is possible that a node will have been sick or starting up when the * original offer was made. However, it will either re-announce itself in @@ -332,14 +331,16 @@ do_dc_join_offer_one(long long action, * well, to ensure the correct value for max_generation_from. */ if (strcasecmp(join_to, controld_globals.our_nodename) != 0) { - member = crm_get_peer(0, controld_globals.our_nodename); + member = pcmk__get_node(0, controld_globals.our_nodename, NULL, + pcmk__node_search_cluster_member); join_make_offer(NULL, member, NULL); } /* This was a genuine join request; cancel any existing transition and * invoke the scheduler. */ - abort_transition(INFINITY, pcmk__graph_restart, "Node join", NULL); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, "Node join", + NULL); count = crmd_join_phase_count(crm_join_welcomed); crm_info("Waiting on join-%d requests from %d outstanding node%s", @@ -386,19 +387,20 @@ do_dc_join_filter_offer(long long action, gboolean ack_nack_bool = TRUE; ha_msg_input_t *join_ack = fsa_typed_data(fsa_dt_ha_msg); - const char *join_from = crm_element_value(join_ack->msg, F_CRM_HOST_FROM); - const char *ref = crm_element_value(join_ack->msg, F_CRM_REFERENCE); + const char *join_from = crm_element_value(join_ack->msg, PCMK__XA_SRC); + const char *ref = crm_element_value(join_ack->msg, PCMK_XA_REFERENCE); const char *join_version = crm_element_value(join_ack->msg, - XML_ATTR_CRM_VERSION); + PCMK_XA_CRM_FEATURE_SET); crm_node_t *join_node = NULL; if (join_from == NULL) { crm_err("Ignoring invalid join request without node name"); return; } - join_node = crm_get_peer(0, join_from); + join_node = pcmk__get_node(0, join_from, NULL, + pcmk__node_search_cluster_member); - crm_element_value_int(join_ack->msg, F_CRM_JOIN_ID, &join_id); + crm_element_value_int(join_ack->msg, PCMK__XA_JOIN_ID, &join_id); if (join_id != current_join_id) { crm_debug("Ignoring join-%d request from %s because we are on join-%d", join_id, join_from, current_join_id); @@ -411,13 +413,22 @@ do_dc_join_filter_offer(long long action, int lpc = 0; const char *attributes[] = { - XML_ATTR_GENERATION_ADMIN, - XML_ATTR_GENERATION, - XML_ATTR_NUMUPDATES, + PCMK_XA_ADMIN_EPOCH, + PCMK_XA_EPOCH, + PCMK_XA_NUM_UPDATES, }; - for (lpc = 0; cmp == 0 && lpc < PCMK__NELEM(attributes); lpc++) { - cmp = compare_int_fields(max_generation_xml, generation, attributes[lpc]); + /* It's not obvious that join_ack->xml is the PCMK__XE_GENERATION_TUPLE + * element from the join client. The "if" guard is for clarity. + */ + if (pcmk__xe_is(generation, PCMK__XE_GENERATION_TUPLE)) { + for (lpc = 0; cmp == 0 && lpc < PCMK__NELEM(attributes); lpc++) { + cmp = compare_int_fields(max_generation_xml, generation, + attributes[lpc]); + } + + } else { // Should always be PCMK__XE_GENERATION_TUPLE + CRM_LOG_ASSERT(false); } } @@ -431,7 +442,7 @@ do_dc_join_filter_offer(long long action, join_id, join_from, value, ref); ack_nack_bool = FALSE; - } else if (!crm_is_peer_active(join_node)) { + } else if (!pcmk__cluster_is_node_active(join_node)) { if (match_down_event(join_from) != NULL) { /* The join request was received after the node was fenced or * otherwise shutdown in a way that we're aware of. No need to log @@ -463,20 +474,20 @@ do_dc_join_filter_offer(long long action, } else if (max_generation_xml == NULL) { const char *validation = crm_element_value(generation, - XML_ATTR_VALIDATION); + PCMK_XA_VALIDATE_WITH); - if (get_schema_version(validation) < 0) { + if (pcmk__get_schema(validation) == NULL) { crm_err("Rejecting join-%d request from %s (with first CIB " "generation) due to unknown schema version %s " CRM_XS " ref=%s", - join_id, join_from, validation, ref); + join_id, join_from, pcmk__s(validation, "(missing)"), ref); ack_nack_bool = FALSE; } else { crm_debug("Accepting join-%d request from %s (with first CIB " "generation) " CRM_XS " ref=%s", join_id, join_from, ref); - max_generation_xml = copy_xml(generation); + max_generation_xml = pcmk__xml_copy(NULL, generation); pcmk__str_update(&max_generation_from, join_from); } @@ -485,13 +496,14 @@ do_dc_join_filter_offer(long long action, && pcmk__str_eq(join_from, controld_globals.our_nodename, pcmk__str_casei))) { const char *validation = crm_element_value(generation, - XML_ATTR_VALIDATION); + PCMK_XA_VALIDATE_WITH); - if (get_schema_version(validation) < 0) { + if (pcmk__get_schema(validation) == NULL) { crm_err("Rejecting join-%d request from %s (with better CIB " "generation than current best from %s) due to unknown " "schema version %s " CRM_XS " ref=%s", - join_id, join_from, max_generation_from, validation, ref); + join_id, join_from, max_generation_from, + pcmk__s(validation, "(missing)"), ref); ack_nack_bool = FALSE; } else { @@ -502,7 +514,7 @@ do_dc_join_filter_offer(long long action, crm_log_xml_debug(generation, "New max generation"); free_xml(max_generation_xml); - max_generation_xml = copy_xml(join_ack->xml); + max_generation_xml = pcmk__xml_copy(NULL, join_ack->xml); pcmk__str_update(&max_generation_from, join_from); } @@ -588,7 +600,7 @@ do_dc_join_finalize(long long action, if (pcmk_is_set(controld_globals.fsa_input_register, R_HAVE_CIB)) { // Send our CIB out to everyone - pcmk__str_update(&sync_from, controld_globals.our_nodename); + sync_from = pcmk__str_copy(controld_globals.our_nodename); crm_debug("Finalizing join-%d for %d node%s (sync'ing from local CIB)", current_join_id, count_finalizable, pcmk__plural_s(count_finalizable)); @@ -596,7 +608,7 @@ do_dc_join_finalize(long long action, } else { // Ask for the agreed best CIB - pcmk__str_update(&sync_from, max_generation_from); + sync_from = pcmk__str_copy(max_generation_from); crm_notice("Finalizing join-%d for %d node%s (sync'ing CIB from %s)", current_join_id, count_finalizable, pcmk__plural_s(count_finalizable), sync_from); @@ -698,8 +710,8 @@ do_dc_join_ack(long long action, int join_id = -1; ha_msg_input_t *join_ack = fsa_typed_data(fsa_dt_ha_msg); - const char *op = crm_element_value(join_ack->msg, F_CRM_TASK); - char *join_from = crm_element_value_copy(join_ack->msg, F_CRM_HOST_FROM); + const char *op = crm_element_value(join_ack->msg, PCMK__XA_CRM_TASK); + char *join_from = crm_element_value_copy(join_ack->msg, PCMK__XA_SRC); crm_node_t *peer = NULL; enum controld_section_e section = controld_section_lrm; @@ -726,13 +738,13 @@ do_dc_join_ack(long long action, goto done; } - if (crm_element_value_int(join_ack->msg, F_CRM_JOIN_ID, &join_id) != 0) { + if (crm_element_value_int(join_ack->msg, PCMK__XA_JOIN_ID, &join_id) != 0) { crm_warn("Ignoring join confirmation from %s without valid join ID", join_from); goto done; } - peer = crm_get_peer(0, join_from); + peer = pcmk__get_node(0, join_from, NULL, pcmk__node_search_cluster_member); if (peer->join != crm_join_finalized) { crm_info("Ignoring out-of-sequence join-%d confirmation from %s " "(currently %s not %s)", @@ -800,7 +812,7 @@ do_dc_join_ack(long long action, join_from, current_join_id); } - rc = cib->cmds->modify(cib, XML_CIB_TAG_STATUS, state, + rc = cib->cmds->modify(cib, PCMK_XE_STATUS, state, cib_scope_local|cib_can_create|cib_transaction); free_xml(execd_state); if (rc != pcmk_ok) { @@ -854,10 +866,10 @@ finalize_join_for(gpointer key, gpointer value, gpointer user_data) * weren't known before */ crm_trace("Updating node name and UUID in CIB for %s", join_to); - tmp1 = create_xml_node(NULL, XML_CIB_TAG_NODE); - crm_xml_add(tmp1, XML_ATTR_ID, crm_peer_uuid(join_node)); - crm_xml_add(tmp1, XML_ATTR_UNAME, join_to); - fsa_cib_anon_update(XML_CIB_TAG_NODES, tmp1); + tmp1 = pcmk__xe_create(NULL, PCMK_XE_NODE); + crm_xml_add(tmp1, PCMK_XA_ID, pcmk__cluster_node_uuid(join_node)); + crm_xml_add(tmp1, PCMK_XA_UNAME, join_to); + fsa_cib_anon_update(PCMK_XE_NODES, tmp1); free_xml(tmp1); if (join_node->join == crm_join_nack_quiet) { @@ -866,8 +878,9 @@ finalize_join_for(gpointer key, gpointer value, gpointer user_data) return; } - join_node = crm_get_peer(0, join_to); - if (!crm_is_peer_active(join_node)) { + join_node = pcmk__get_node(0, join_to, NULL, + pcmk__node_search_cluster_member); + if (!pcmk__cluster_is_node_active(join_node)) { /* * NACK'ing nodes that the membership layer doesn't know about yet * simply creates more churn @@ -896,10 +909,10 @@ finalize_join_for(gpointer key, gpointer value, gpointer user_data) * node hosts each to the ACK message. This keeps new controllers in * sync with what has already happened. */ - if (crm_remote_peer_cache_size() != 0) { + if (pcmk__cluster_num_remote_nodes() > 0) { GHashTableIter iter; crm_node_t *node = NULL; - xmlNode *remotes = create_xml_node(acknak, XML_CIB_TAG_NODES); + xmlNode *remotes = pcmk__xe_create(acknak, PCMK_XE_NODES); g_hash_table_iter_init(&iter, crm_remote_peer_cache); while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) { @@ -909,16 +922,16 @@ finalize_join_for(gpointer key, gpointer value, gpointer user_data) continue; } - remote = create_xml_node(remotes, XML_CIB_TAG_NODE); + remote = pcmk__xe_create(remotes, PCMK_XE_NODE); pcmk__xe_set_props(remote, - XML_ATTR_ID, node->uname, - XML_CIB_TAG_STATE, node->state, - PCMK__XA_CONN_HOST, node->conn_host, + PCMK_XA_ID, node->uname, + PCMK__XA_NODE_STATE, node->state, + PCMK__XA_CONNECTION_HOST, node->conn_host, NULL); } } } - send_cluster_message(join_node, crm_msg_crmd, acknak, TRUE); + pcmk__cluster_send_message(join_node, crm_msg_crmd, acknak); free_xml(acknak); return; } diff --git a/daemons/controld/controld_membership.c b/daemons/controld/controld_membership.c index f25d1e9..1079d6a 100644 --- a/daemons/controld/controld_membership.c +++ b/daemons/controld/controld_membership.c @@ -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. * @@ -13,7 +13,6 @@ #include <string.h> #include <crm/crm.h> -#include <crm/msg_xml.h> #include <crm/common/xml.h> #include <crm/common/xml_internal.h> #include <crm/cluster/internal.h> @@ -29,7 +28,7 @@ reap_dead_nodes(gpointer key, gpointer value, gpointer user_data) { crm_node_t *node = value; - if (crm_is_peer_active(node) == FALSE) { + if (!pcmk__cluster_is_node_active(node)) { crm_update_peer_join(__func__, node, crm_join_none); if(node && node->uname) { @@ -85,7 +84,7 @@ post_cache_update(int instance) */ no_op = create_request(CRM_OP_NOOP, NULL, NULL, CRM_SYSTEM_CRMD, AM_I_DC ? CRM_SYSTEM_DC : CRM_SYSTEM_CRMD, NULL); - send_cluster_message(NULL, crm_msg_crmd, no_op, FALSE); + pcmk__cluster_send_message(NULL, crm_msg_crmd, no_op); free_xml(no_op); } @@ -132,19 +131,20 @@ create_node_state_update(crm_node_t *node, int flags, xmlNode *parent, return NULL; } - node_state = create_xml_node(parent, XML_CIB_TAG_STATE); + node_state = pcmk__xe_create(parent, PCMK__XE_NODE_STATE); if (pcmk_is_set(node->flags, crm_remote_node)) { - pcmk__xe_set_bool_attr(node_state, XML_NODE_IS_REMOTE, true); + pcmk__xe_set_bool_attr(node_state, PCMK_XA_REMOTE_NODE, true); } - if (crm_xml_add(node_state, XML_ATTR_ID, crm_peer_uuid(node)) == NULL) { + if (crm_xml_add(node_state, PCMK_XA_ID, + pcmk__cluster_node_uuid(node)) == NULL) { crm_info("Node update for %s cancelled: no ID", node->uname); free_xml(node_state); return NULL; } - crm_xml_add(node_state, XML_ATTR_UNAME, node->uname); + crm_xml_add(node_state, PCMK_XA_UNAME, node->uname); if ((flags & node_update_cluster) && node->state) { if (compare_version(controld_globals.dc_version, "3.18.0") >= 0) { @@ -162,15 +162,15 @@ create_node_state_update(crm_node_t *node, int flags, xmlNode *parent, if (flags & node_update_peer) { if (compare_version(controld_globals.dc_version, "3.18.0") >= 0) { // A value 0 means the peer is offline in CPG. - crm_xml_add_ll(node_state, PCMK__XA_CRMD, node->when_online); + crm_xml_add_ll(node_state, PCMK_XA_CRMD, node->when_online); } else { // @COMPAT DCs < 2.1.7 use online/offline rather than timestamp - value = OFFLINESTATUS; + value = PCMK_VALUE_OFFLINE; if (pcmk_is_set(node->processes, crm_get_cluster_proc())) { - value = ONLINESTATUS; + value = PCMK_VALUE_ONLINE; } - crm_xml_add(node_state, PCMK__XA_CRMD, value); + crm_xml_add(node_state, PCMK_XA_CRMD, value); } } @@ -184,11 +184,11 @@ create_node_state_update(crm_node_t *node, int flags, xmlNode *parent, } if (flags & node_update_expected) { - crm_xml_add(node_state, PCMK__XA_EXPECTED, node->expected); + crm_xml_add(node_state, PCMK_XA_EXPECTED, node->expected); } } - crm_xml_add(node_state, XML_ATTR_ORIGIN, source); + crm_xml_add(node_state, PCMK_XA_CRM_DEBUG_ORIGIN, source); return node_state; } @@ -222,26 +222,22 @@ search_conflicting_node_callback(xmlNode * msg, int call_id, int rc, return; } - if (pcmk__xe_is(output, XML_CIB_TAG_NODE)) { + if (pcmk__xe_is(output, PCMK_XE_NODE)) { node_xml = output; } else { - node_xml = pcmk__xml_first_child(output); + node_xml = pcmk__xe_first_child(output, PCMK_XE_NODE, NULL, NULL); } - for (; node_xml != NULL; node_xml = pcmk__xml_next(node_xml)) { + for (; node_xml != NULL; node_xml = pcmk__xe_next_same(node_xml)) { const char *node_uuid = NULL; const char *node_uname = NULL; GHashTableIter iter; crm_node_t *node = NULL; gboolean known = FALSE; - if (!pcmk__xe_is(node_xml, XML_CIB_TAG_NODE)) { - continue; - } - - node_uuid = crm_element_value(node_xml, XML_ATTR_ID); - node_uname = crm_element_value(node_xml, XML_ATTR_UNAME); + node_uuid = crm_element_value(node_xml, PCMK_XA_ID); + node_uname = crm_element_value(node_xml, PCMK_XA_UNAME); if (node_uuid == NULL || node_uname == NULL) { continue; @@ -267,20 +263,19 @@ search_conflicting_node_callback(xmlNode * msg, int call_id, int rc, crm_notice("Deleting unknown node %s/%s which has conflicting uname with %s", node_uuid, node_uname, new_node_uuid); - delete_call_id = cib_conn->cmds->remove(cib_conn, XML_CIB_TAG_NODES, + delete_call_id = cib_conn->cmds->remove(cib_conn, PCMK_XE_NODES, node_xml, cib_scope_local); - fsa_register_cib_callback(delete_call_id, strdup(node_uuid), + fsa_register_cib_callback(delete_call_id, pcmk__str_copy(node_uuid), remove_conflicting_node_callback); - node_state_xml = create_xml_node(NULL, XML_CIB_TAG_STATE); - crm_xml_add(node_state_xml, XML_ATTR_ID, node_uuid); - crm_xml_add(node_state_xml, XML_ATTR_UNAME, node_uname); + node_state_xml = pcmk__xe_create(NULL, PCMK__XE_NODE_STATE); + crm_xml_add(node_state_xml, PCMK_XA_ID, node_uuid); + crm_xml_add(node_state_xml, PCMK_XA_UNAME, node_uname); - delete_call_id = cib_conn->cmds->remove(cib_conn, - XML_CIB_TAG_STATUS, + delete_call_id = cib_conn->cmds->remove(cib_conn, PCMK_XE_STATUS, node_state_xml, cib_scope_local); - fsa_register_cib_callback(delete_call_id, strdup(node_uuid), + fsa_register_cib_callback(delete_call_id, pcmk__str_copy(node_uuid), remove_conflicting_node_callback); free_xml(node_state_xml); } @@ -311,10 +306,12 @@ populate_cib_nodes(enum node_update_flags flags, const char *source) int call_id = 0; gboolean from_hashtable = TRUE; - xmlNode *node_list = create_xml_node(NULL, XML_CIB_TAG_NODES); + xmlNode *node_list = pcmk__xe_create(NULL, PCMK_XE_NODES); #if SUPPORT_COROSYNC - if (!pcmk_is_set(flags, node_update_quick) && is_corosync_cluster()) { + if (!pcmk_is_set(flags, node_update_quick) + && (pcmk_get_cluster_layer() == pcmk_cluster_layer_corosync)) { + from_hashtable = pcmk__corosync_add_nodes(node_list); } #endif @@ -337,22 +334,22 @@ populate_cib_nodes(enum node_update_flags flags, const char *source) } /* We need both to be valid */ - new_node = create_xml_node(node_list, XML_CIB_TAG_NODE); - crm_xml_add(new_node, XML_ATTR_ID, node->uuid); - crm_xml_add(new_node, XML_ATTR_UNAME, node->uname); + new_node = pcmk__xe_create(node_list, PCMK_XE_NODE); + crm_xml_add(new_node, PCMK_XA_ID, node->uuid); + crm_xml_add(new_node, PCMK_XA_UNAME, node->uname); /* Search and remove unknown nodes with the conflicting uname from CIB */ pcmk__g_strcat(xpath, - "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION - "/" XML_CIB_TAG_NODES "/" XML_CIB_TAG_NODE - "[@" XML_ATTR_UNAME "='", node->uname, "']" - "[@" XML_ATTR_ID "!='", node->uuid, "']", NULL); + "/" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION + "/" PCMK_XE_NODES "/" PCMK_XE_NODE + "[@" PCMK_XA_UNAME "='", node->uname, "']" + "[@" PCMK_XA_ID "!='", node->uuid, "']", NULL); call_id = cib_conn->cmds->query(cib_conn, (const char *) xpath->str, NULL, cib_scope_local|cib_xpath); - fsa_register_cib_callback(call_id, strdup(node->uuid), + fsa_register_cib_callback(call_id, pcmk__str_copy(node->uuid), search_conflicting_node_callback); } } @@ -364,7 +361,7 @@ populate_cib_nodes(enum node_update_flags flags, const char *source) crm_trace("Populating <nodes> section from %s", from_hashtable ? "hashtable" : "cluster"); - if ((controld_update_cib(XML_CIB_TAG_NODES, node_list, cib_scope_local, + if ((controld_update_cib(PCMK_XE_NODES, node_list, cib_scope_local, node_list_update_callback) == pcmk_rc_ok) && (crm_peer_cache != NULL) && AM_I_DC) { /* @@ -375,7 +372,7 @@ populate_cib_nodes(enum node_update_flags flags, const char *source) crm_node_t *node = NULL; free_xml(node_list); - node_list = create_xml_node(NULL, XML_CIB_TAG_STATUS); + node_list = pcmk__xe_create(NULL, PCMK_XE_STATUS); g_hash_table_iter_init(&iter, crm_peer_cache); while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) { @@ -389,7 +386,7 @@ populate_cib_nodes(enum node_update_flags flags, const char *source) } } - controld_update_cib(XML_CIB_TAG_STATUS, node_list, cib_scope_local, + controld_update_cib(PCMK_XE_STATUS, node_list, cib_scope_local, crmd_node_update_complete); } free_xml(node_list); @@ -429,12 +426,12 @@ crm_update_quorum(gboolean quorum, gboolean force_update) || force_update)) { xmlNode *update = NULL; - update = create_xml_node(NULL, XML_TAG_CIB); - crm_xml_add_int(update, XML_ATTR_HAVE_QUORUM, quorum); - crm_xml_add(update, XML_ATTR_DC_UUID, controld_globals.our_uuid); + update = pcmk__xe_create(NULL, PCMK_XE_CIB); + crm_xml_add_int(update, PCMK_XA_HAVE_QUORUM, quorum); + crm_xml_add(update, PCMK_XA_DC_UUID, controld_globals.our_uuid); crm_debug("Updating quorum status to %s", pcmk__btoa(quorum)); - controld_update_cib(XML_TAG_CIB, update, cib_scope_local, + controld_update_cib(PCMK_XE_CIB, update, cib_scope_local, cib_quorum_update_complete); free_xml(update); @@ -453,11 +450,11 @@ crm_update_quorum(gboolean quorum, gboolean force_update) * nodes are joining around the same time, so the one that brings us * to quorum doesn't cause all the remaining ones to be fenced. */ - abort_after_delay(INFINITY, pcmk__graph_restart, "Quorum gained", - 5000); + abort_after_delay(PCMK_SCORE_INFINITY, pcmk__graph_restart, + "Quorum gained", 5000); } else { - abort_transition(INFINITY, pcmk__graph_restart, "Quorum lost", - NULL); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, + "Quorum lost", NULL); } } diff --git a/daemons/controld/controld_messages.c b/daemons/controld/controld_messages.c index 39f3c7a..5f7a78c 100644 --- a/daemons/controld/controld_messages.c +++ b/daemons/controld/controld_messages.c @@ -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. * @@ -14,7 +14,6 @@ #include <time.h> #include <crm/crm.h> -#include <crm/msg_xml.h> #include <crm/common/xml.h> #include <crm/cluster/internal.h> #include <crm/cib.h> @@ -22,8 +21,6 @@ #include <pacemaker-controld.h> -extern void crm_shutdown(int nsig); - static enum crmd_fsa_input handle_message(xmlNode *msg, enum crmd_fsa_cause cause); static void handle_response(xmlNode *stored_msg); @@ -102,7 +99,7 @@ register_fsa_input_adv(enum crmd_fsa_cause cause, enum crmd_fsa_input input, fsa_input2string(input), fsa_cause2string(cause), (data? "with" : "without")); - fsa_data = calloc(1, sizeof(fsa_data_t)); + fsa_data = pcmk__assert_alloc(1, sizeof(fsa_data_t)); fsa_data->id = last_data_id; fsa_data->fsa_input = input; fsa_data->fsa_cause = cause; @@ -191,11 +188,14 @@ fsa_dump_queue(int log_level) ha_msg_input_t * copy_ha_msg_input(ha_msg_input_t * orig) { - ha_msg_input_t *copy = calloc(1, sizeof(ha_msg_input_t)); + xmlNode *wrapper = NULL; + + ha_msg_input_t *copy = pcmk__assert_alloc(1, sizeof(ha_msg_input_t)); + + copy->msg = (orig != NULL)? pcmk__xml_copy(NULL, orig->msg) : NULL; - CRM_ASSERT(copy != NULL); - copy->msg = (orig && orig->msg)? copy_xml(orig->msg) : NULL; - copy->xml = get_message_xml(copy->msg, F_CRM_DATA); + wrapper = pcmk__xe_first_child(copy->msg, PCMK__XE_CRM_XML, NULL, NULL); + copy->xml = pcmk__xe_first_child(wrapper, NULL, NULL, NULL); return copy; } @@ -328,7 +328,7 @@ route_message(enum crmd_fsa_cause cause, xmlNode * input) gboolean relay_message(xmlNode * msg, gboolean originated_locally) { - enum crm_ais_msg_types dest = crm_msg_ais; + enum crm_ais_msg_types dest = crm_msg_none; bool is_for_dc = false; bool is_for_dcib = false; bool is_for_te = false; @@ -346,12 +346,12 @@ relay_message(xmlNode * msg, gboolean originated_locally) CRM_CHECK(msg != NULL, return TRUE); - host_to = crm_element_value(msg, F_CRM_HOST_TO); - sys_to = crm_element_value(msg, F_CRM_SYS_TO); - sys_from = crm_element_value(msg, F_CRM_SYS_FROM); - type = crm_element_value(msg, F_TYPE); - task = crm_element_value(msg, F_CRM_TASK); - ref = crm_element_value(msg, XML_ATTR_REFERENCE); + host_to = crm_element_value(msg, PCMK__XA_CRM_HOST_TO); + sys_to = crm_element_value(msg, PCMK__XA_CRM_SYS_TO); + sys_from = crm_element_value(msg, PCMK__XA_CRM_SYS_FROM); + type = crm_element_value(msg, PCMK__XA_T); + task = crm_element_value(msg, PCMK__XA_CRM_TASK); + ref = crm_element_value(msg, PCMK_XA_REFERENCE); broadcast = pcmk__str_empty(host_to); @@ -367,8 +367,9 @@ relay_message(xmlNode * msg, gboolean originated_locally) } // Require message type (set by create_request()) - if (!pcmk__str_eq(type, T_CRM, pcmk__str_casei)) { - crm_warn("Ignoring invalid message %s with type '%s' (not '" T_CRM "')", + if (!pcmk__str_eq(type, PCMK__VALUE_CRMD, pcmk__str_none)) { + crm_warn("Ignoring invalid message %s with type '%s' " + "(not '" PCMK__VALUE_CRMD "')", ref, pcmk__s(type, "")); crm_log_xml_trace(msg, "ignored"); return TRUE; @@ -376,15 +377,16 @@ relay_message(xmlNode * msg, gboolean originated_locally) // Require a destination subsystem (also set by create_request()) if (sys_to == NULL) { - crm_warn("Ignoring invalid message %s with no " F_CRM_SYS_TO, ref); + crm_warn("Ignoring invalid message %s with no " PCMK__XA_CRM_SYS_TO, + ref); crm_log_xml_trace(msg, "ignored"); return TRUE; } // Get the message type appropriate to the destination subsystem - if (is_corosync_cluster()) { - dest = text2msg_type(sys_to); - if ((dest < crm_msg_ais) || (dest > crm_msg_stonith_ng)) { + if (pcmk_get_cluster_layer() == pcmk_cluster_layer_corosync) { + dest = pcmk__cluster_parse_msg_type(sys_to); + if (dest == crm_msg_none) { /* Unrecognized value, use a sane default * * @TODO Maybe we should bail instead @@ -427,10 +429,12 @@ relay_message(xmlNode * msg, gboolean originated_locally) is_local = true; } else if (is_for_crm && pcmk__str_eq(task, CRM_OP_LRM_DELETE, pcmk__str_casei)) { - xmlNode *msg_data = get_message_xml(msg, F_CRM_DATA); + xmlNode *wrapper = pcmk__xe_first_child(msg, PCMK__XE_CRM_XML, NULL, + NULL); + xmlNode *msg_data = pcmk__xe_first_child(wrapper, NULL, NULL, NULL); const char *mode = crm_element_value(msg_data, PCMK__XA_MODE); - if (pcmk__str_eq(mode, XML_TAG_CIB, pcmk__str_casei)) { + if (pcmk__str_eq(mode, PCMK__VALUE_CIB, pcmk__str_none)) { // Local delete of an offline node's resource history is_local = true; } @@ -458,9 +462,10 @@ relay_message(xmlNode * msg, gboolean originated_locally) ref, pcmk__s(host_to, "broadcast")); crm_log_xml_trace(msg, "relayed"); if (!broadcast) { - node_to = crm_get_peer(0, host_to); + node_to = pcmk__get_node(0, host_to, NULL, + pcmk__node_search_cluster_member); } - send_cluster_message(node_to, dest, msg, TRUE); + pcmk__cluster_send_message(node_to, dest, msg); return TRUE; } @@ -484,7 +489,8 @@ relay_message(xmlNode * msg, gboolean originated_locally) } if (!broadcast) { - node_to = pcmk__search_cluster_node_cache(0, host_to, NULL); + node_to = pcmk__search_node_caches(0, host_to, + pcmk__node_search_cluster_member); if (node_to == NULL) { crm_warn("Ignoring message %s because node %s is unknown", ref, host_to); @@ -496,7 +502,7 @@ relay_message(xmlNode * msg, gboolean originated_locally) crm_trace("Relay message %s to %s", ref, pcmk__s(host_to, "all peers")); crm_log_xml_trace(msg, "relayed"); - send_cluster_message(node_to, dest, msg, TRUE); + pcmk__cluster_send_message(node_to, dest, msg); return TRUE; } @@ -539,10 +545,11 @@ bool controld_authorize_ipc_message(const xmlNode *client_msg, pcmk__client_t *curr_client, const char *proxy_session) { + xmlNode *wrapper = NULL; xmlNode *message_data = NULL; const char *client_name = NULL; - const char *op = crm_element_value(client_msg, F_CRM_TASK); - const char *ref = crm_element_value(client_msg, XML_ATTR_REFERENCE); + const char *op = crm_element_value(client_msg, PCMK__XA_CRM_TASK); + const char *ref = crm_element_value(client_msg, PCMK_XA_REFERENCE); const char *uuid = (curr_client? curr_client->id : proxy_session); if (uuid == NULL) { @@ -556,27 +563,28 @@ controld_authorize_ipc_message(const xmlNode *client_msg, pcmk__client_t *curr_c return true; } - message_data = get_message_xml(client_msg, F_CRM_DATA); + wrapper = pcmk__xe_first_child(client_msg, PCMK__XE_CRM_XML, NULL, NULL); + message_data = pcmk__xe_first_child(wrapper, NULL, NULL, NULL); - client_name = crm_element_value(message_data, "client_name"); + client_name = crm_element_value(message_data, PCMK__XA_CLIENT_NAME); if (pcmk__str_empty(client_name)) { crm_warn("IPC hello from client rejected: No client name", CRM_XS " ref=%s uuid=%s", (ref? ref : "none"), uuid); goto rejected; } - if (!authorize_version(message_data, "major_version", client_name, ref, - uuid)) { + if (!authorize_version(message_data, PCMK__XA_MAJOR_VERSION, client_name, + ref, uuid)) { goto rejected; } - if (!authorize_version(message_data, "minor_version", client_name, ref, - uuid)) { + if (!authorize_version(message_data, PCMK__XA_MINOR_VERSION, client_name, + ref, uuid)) { goto rejected; } crm_trace("Validated IPC hello from client %s", client_name); crm_log_xml_trace(client_msg, "hello"); if (curr_client) { - curr_client->userdata = strdup(client_name); + curr_client->userdata = pcmk__str_copy(client_name); } controld_trigger_fsa(); return false; @@ -596,16 +604,17 @@ handle_message(xmlNode *msg, enum crmd_fsa_cause cause) CRM_CHECK(msg != NULL, return I_NULL); - type = crm_element_value(msg, F_CRM_MSG_TYPE); - if (pcmk__str_eq(type, XML_ATTR_REQUEST, pcmk__str_none)) { + type = crm_element_value(msg, PCMK__XA_SUBT); + if (pcmk__str_eq(type, PCMK__VALUE_REQUEST, pcmk__str_none)) { return handle_request(msg, cause); + } - } else if (pcmk__str_eq(type, XML_ATTR_RESPONSE, pcmk__str_none)) { + if (pcmk__str_eq(type, PCMK__VALUE_RESPONSE, pcmk__str_none)) { handle_response(msg); return I_NULL; } - crm_warn("Ignoring message with unknown " F_CRM_MSG_TYPE " '%s'", + crm_warn("Ignoring message with unknown " PCMK__XA_SUBT" '%s'", pcmk__s(type, "")); crm_log_xml_trace(msg, "bad"); return I_NULL; @@ -620,31 +629,36 @@ handle_failcount_op(xmlNode * stored_msg) char *interval_spec = NULL; guint interval_ms = 0; gboolean is_remote_node = FALSE; - xmlNode *xml_op = get_message_xml(stored_msg, F_CRM_DATA); + + xmlNode *wrapper = pcmk__xe_first_child(stored_msg, PCMK__XE_CRM_XML, NULL, + NULL); + xmlNode *xml_op = pcmk__xe_first_child(wrapper, NULL, NULL, NULL); if (xml_op) { - xmlNode *xml_rsc = first_named_child(xml_op, XML_CIB_TAG_RESOURCE); - xmlNode *xml_attrs = first_named_child(xml_op, XML_TAG_ATTRS); + xmlNode *xml_rsc = pcmk__xe_first_child(xml_op, PCMK_XE_PRIMITIVE, NULL, + NULL); + xmlNode *xml_attrs = pcmk__xe_first_child(xml_op, PCMK__XE_ATTRIBUTES, + NULL, NULL); if (xml_rsc) { - rsc = ID(xml_rsc); + rsc = pcmk__xe_id(xml_rsc); } if (xml_attrs) { op = crm_element_value(xml_attrs, - CRM_META "_" XML_RSC_ATTR_CLEAR_OP); + CRM_META "_" PCMK__META_CLEAR_FAILURE_OP); crm_element_value_ms(xml_attrs, - CRM_META "_" XML_RSC_ATTR_CLEAR_INTERVAL, + CRM_META "_" PCMK__META_CLEAR_FAILURE_INTERVAL, &interval_ms); } } - uname = crm_element_value(xml_op, XML_LRM_ATTR_TARGET); + uname = crm_element_value(xml_op, PCMK__META_ON_NODE); if ((rsc == NULL) || (uname == NULL)) { crm_log_xml_warn(stored_msg, "invalid failcount op"); return I_NULL; } - if (crm_element_value(xml_op, XML_LRM_ATTR_ROUTER_NODE)) { + if (crm_element_value(xml_op, PCMK__XA_ROUTER_NODE)) { is_remote_node = TRUE; } @@ -669,7 +683,9 @@ static enum crmd_fsa_input handle_lrm_delete(xmlNode *stored_msg) { const char *mode = NULL; - xmlNode *msg_data = get_message_xml(stored_msg, F_CRM_DATA); + xmlNode *wrapper = pcmk__xe_first_child(stored_msg, PCMK__XE_CRM_XML, NULL, + NULL); + xmlNode *msg_data = pcmk__xe_first_child(wrapper, NULL, NULL, NULL); CRM_CHECK(msg_data != NULL, return I_NULL); @@ -679,14 +695,14 @@ handle_lrm_delete(xmlNode *stored_msg) * CIB, and do some bookkeeping in the controller. * * However, if the affected node is offline, the client will specify - * mode="cib" which means the controller receiving the operation should - * clear the resource's history from the CIB and nothing else. This is used - * to clear shutdown locks. + * mode=PCMK__VALUE_CIB which means the controller receiving the operation + * should clear the resource's history from the CIB and nothing else. This + * is used to clear shutdown locks. */ mode = crm_element_value(msg_data, PCMK__XA_MODE); - if ((mode == NULL) || strcmp(mode, XML_TAG_CIB)) { + if (!pcmk__str_eq(mode, PCMK__VALUE_CIB, pcmk__str_none)) { // Relay to affected node - crm_xml_add(stored_msg, F_CRM_SYS_TO, CRM_SYSTEM_LRMD); + crm_xml_add(stored_msg, PCMK__XA_CRM_SYS_TO, CRM_SYSTEM_LRMD); return I_ROUTER; } else { @@ -698,13 +714,13 @@ handle_lrm_delete(xmlNode *stored_msg) xmlNode *rsc_xml = NULL; int rc = pcmk_rc_ok; - rsc_xml = first_named_child(msg_data, XML_CIB_TAG_RESOURCE); + rsc_xml = pcmk__xe_first_child(msg_data, PCMK_XE_PRIMITIVE, NULL, NULL); CRM_CHECK(rsc_xml != NULL, return I_NULL); - rsc_id = ID(rsc_xml); - from_sys = crm_element_value(stored_msg, F_CRM_SYS_FROM); - node = crm_element_value(msg_data, XML_LRM_ATTR_TARGET); - user_name = pcmk__update_acl_user(stored_msg, F_CRM_USER, NULL); + rsc_id = pcmk__xe_id(rsc_xml); + from_sys = crm_element_value(stored_msg, PCMK__XA_CRM_SYS_FROM); + node = crm_element_value(msg_data, PCMK__META_ON_NODE); + user_name = pcmk__update_acl_user(stored_msg, PCMK__XA_CRM_USER, NULL); crm_debug("Handling " CRM_OP_LRM_DELETE " for %s on %s locally%s%s " "(clearing CIB resource history only)", rsc_id, node, (user_name? " for user " : ""), (user_name? user_name : "")); @@ -715,19 +731,20 @@ handle_lrm_delete(xmlNode *stored_msg) crmd_cib_smart_opt()); } - //Notify client and tengine.(Only notify tengine if mode = "cib" and CRM_OP_LRM_DELETE.) + /* Notify client. Also notify tengine if mode=PCMK__VALUE_CIB and + * op=CRM_OP_LRM_DELETE. + */ if (from_sys) { lrmd_event_data_t *op = NULL; - const char *from_host = crm_element_value(stored_msg, - F_CRM_HOST_FROM); + const char *from_host = crm_element_value(stored_msg, PCMK__XA_SRC); const char *transition; if (strcmp(from_sys, CRM_SYSTEM_TENGINE)) { transition = crm_element_value(msg_data, - XML_ATTR_TRANSITION_KEY); + PCMK__XA_TRANSITION_KEY); } else { transition = crm_element_value(stored_msg, - XML_ATTR_TRANSITION_KEY); + PCMK__XA_TRANSITION_KEY); } crm_info("Notifying %s on %s that %s was%s deleted", @@ -735,10 +752,10 @@ handle_lrm_delete(xmlNode *stored_msg) ((rc == pcmk_rc_ok)? "" : " not")); op = lrmd_new_event(rsc_id, PCMK_ACTION_DELETE, 0); op->type = lrmd_event_exec_complete; - op->user_data = strdup(transition? transition : FAKE_TE_ID); + op->user_data = pcmk__str_copy(pcmk__s(transition, FAKE_TE_ID)); op->params = pcmk__strkey_table(free, free); - g_hash_table_insert(op->params, strdup(XML_ATTR_CRM_VERSION), - strdup(CRM_FEATURE_SET)); + pcmk__insert_dup(op->params, PCMK_XA_CRM_FEATURE_SET, + CRM_FEATURE_SET); controld_rc2event(op, rc); controld_ack_event_directly(from_host, from_sys, NULL, op, rsc_id); lrmd_free_event(op); @@ -759,7 +776,7 @@ static enum crmd_fsa_input handle_remote_state(const xmlNode *msg) { const char *conn_host = NULL; - const char *remote_uname = ID(msg); + const char *remote_uname = pcmk__xe_id(msg); crm_node_t *remote_peer; bool remote_is_up = false; int rc = pcmk_rc_ok; @@ -768,14 +785,14 @@ handle_remote_state(const xmlNode *msg) CRM_CHECK(remote_uname && rc == pcmk_rc_ok, return I_NULL); - remote_peer = crm_remote_peer_get(remote_uname); + remote_peer = pcmk__cluster_lookup_remote_node(remote_uname); CRM_CHECK(remote_peer, return I_NULL); pcmk__update_peer_state(__func__, remote_peer, remote_is_up ? CRM_NODE_MEMBER : CRM_NODE_LOST, 0); - conn_host = crm_element_value(msg, PCMK__XA_CONN_HOST); + conn_host = crm_element_value(msg, PCMK__XA_CONNECTION_HOST); if (conn_host) { pcmk__str_update(&remote_peer->conn_host, conn_host); } else if (remote_peer->conn_host) { @@ -802,18 +819,18 @@ handle_ping(const xmlNode *msg) // Build reply - ping = create_xml_node(NULL, XML_CRM_TAG_PING); - value = crm_element_value(msg, F_CRM_SYS_TO); - crm_xml_add(ping, XML_PING_ATTR_SYSFROM, value); + ping = pcmk__xe_create(NULL, PCMK__XE_PING_RESPONSE); + value = crm_element_value(msg, PCMK__XA_CRM_SYS_TO); + crm_xml_add(ping, PCMK__XA_CRM_SUBSYSTEM, value); // Add controller state value = fsa_state2string(controld_globals.fsa_state); - crm_xml_add(ping, XML_PING_ATTR_CRMDSTATE, value); + crm_xml_add(ping, PCMK__XA_CRMD_STATE, value); crm_notice("Current ping state: %s", value); // CTS needs this // Add controller health // @TODO maybe do some checks to determine meaningful status - crm_xml_add(ping, XML_PING_ATTR_STATUS, "ok"); + crm_xml_add(ping, PCMK_XA_RESULT, "ok"); // Send reply reply = create_reply(msg, ping); @@ -843,13 +860,13 @@ handle_node_list(const xmlNode *request) xmlNode *reply_data = NULL; // Create message data for reply - reply_data = create_xml_node(NULL, XML_CIB_TAG_NODES); + reply_data = pcmk__xe_create(NULL, PCMK_XE_NODES); g_hash_table_iter_init(&iter, crm_peer_cache); while (g_hash_table_iter_next(&iter, NULL, (gpointer *) & node)) { - xmlNode *xml = create_xml_node(reply_data, XML_CIB_TAG_NODE); + xmlNode *xml = pcmk__xe_create(reply_data, PCMK_XE_NODE); - crm_xml_add_ll(xml, XML_ATTR_ID, (long long) node->id); // uint32_t - crm_xml_add(xml, XML_ATTR_UNAME, node->uname); + crm_xml_add_ll(xml, PCMK_XA_ID, (long long) node->id); // uint32_t + crm_xml_add(xml, PCMK_XA_UNAME, node->uname); crm_xml_add(xml, PCMK__XA_IN_CCM, node->state); } @@ -883,32 +900,32 @@ handle_node_info_request(const xmlNode *msg) // Build reply - reply_data = create_xml_node(NULL, XML_CIB_TAG_NODE); - crm_xml_add(reply_data, XML_PING_ATTR_SYSFROM, CRM_SYSTEM_CRMD); + reply_data = pcmk__xe_create(NULL, PCMK_XE_NODE); + crm_xml_add(reply_data, PCMK__XA_CRM_SUBSYSTEM, CRM_SYSTEM_CRMD); // Add whether current partition has quorum - pcmk__xe_set_bool_attr(reply_data, XML_ATTR_HAVE_QUORUM, + pcmk__xe_set_bool_attr(reply_data, PCMK_XA_HAVE_QUORUM, pcmk_is_set(controld_globals.flags, controld_has_quorum)); // Check whether client requested node info by ID and/or name - crm_element_value_int(msg, XML_ATTR_ID, &node_id); + crm_element_value_int(msg, PCMK_XA_ID, &node_id); if (node_id < 0) { node_id = 0; } - value = crm_element_value(msg, XML_ATTR_UNAME); + value = crm_element_value(msg, PCMK_XA_UNAME); // Default to local node if none given if ((node_id == 0) && (value == NULL)) { value = controld_globals.our_nodename; } - node = pcmk__search_node_caches(node_id, value, CRM_GET_PEER_ANY); + node = pcmk__search_node_caches(node_id, value, pcmk__node_search_any); if (node) { - crm_xml_add(reply_data, XML_ATTR_ID, node->uuid); - crm_xml_add(reply_data, XML_ATTR_UNAME, node->uname); - crm_xml_add(reply_data, PCMK__XA_CRMD, node->state); - pcmk__xe_set_bool_attr(reply_data, XML_NODE_IS_REMOTE, + crm_xml_add(reply_data, PCMK_XA_ID, node->uuid); + crm_xml_add(reply_data, PCMK_XA_UNAME, node->uname); + crm_xml_add(reply_data, PCMK_XA_CRMD, node->state); + pcmk__xe_set_bool_attr(reply_data, PCMK_XA_REMOTE_NODE, pcmk_is_set(node->flags, crm_remote_node)); } @@ -927,7 +944,7 @@ handle_node_info_request(const xmlNode *msg) static void verify_feature_set(xmlNode *msg) { - const char *dc_version = crm_element_value(msg, XML_ATTR_CRM_VERSION); + const char *dc_version = crm_element_value(msg, PCMK_XA_CRM_FEATURE_SET); if (dc_version == NULL) { /* All we really know is that the DC feature set is older than 3.1.0, @@ -953,7 +970,7 @@ verify_feature_set(xmlNode *msg) static enum crmd_fsa_input handle_shutdown_self_ack(xmlNode *stored_msg) { - const char *host_from = crm_element_value(stored_msg, F_CRM_HOST_FROM); + const char *host_from = crm_element_value(stored_msg, PCMK__XA_SRC); if (pcmk_is_set(controld_globals.fsa_input_register, R_SHUTDOWN)) { // The expected case -- we initiated own shutdown sequence @@ -986,7 +1003,7 @@ handle_shutdown_self_ack(xmlNode *stored_msg) static enum crmd_fsa_input handle_shutdown_ack(xmlNode *stored_msg) { - const char *host_from = crm_element_value(stored_msg, F_CRM_HOST_FROM); + const char *host_from = crm_element_value(stored_msg, PCMK__XA_SRC); if (host_from == NULL) { crm_warn("Ignoring shutdown request without origin specified"); @@ -1016,19 +1033,20 @@ static enum crmd_fsa_input handle_request(xmlNode *stored_msg, enum crmd_fsa_cause cause) { xmlNode *msg = NULL; - const char *op = crm_element_value(stored_msg, F_CRM_TASK); + const char *op = crm_element_value(stored_msg, PCMK__XA_CRM_TASK); /* Optimize this for the DC - it has the most to do */ crm_log_xml_trace(stored_msg, "request"); if (op == NULL) { - crm_warn("Ignoring request without " F_CRM_TASK); + crm_warn("Ignoring request without " PCMK__XA_CRM_TASK); return I_NULL; } if (strcmp(op, CRM_OP_SHUTDOWN_REQ) == 0) { - const char *from = crm_element_value(stored_msg, F_CRM_HOST_FROM); - crm_node_t *node = pcmk__search_cluster_node_cache(0, from, NULL); + const char *from = crm_element_value(stored_msg, PCMK__XA_SRC); + crm_node_t *node = + pcmk__search_node_caches(0, from, pcmk__node_search_cluster_member); pcmk__update_peer_expected(__func__, node, CRMD_JOINSTATE_DOWN); if(AM_I_DC == FALSE) { @@ -1099,11 +1117,13 @@ handle_request(xmlNode *stored_msg, enum crmd_fsa_cause cause) } else if (strcmp(op, CRM_OP_JOIN_OFFER) == 0) { verify_feature_set(stored_msg); - crm_debug("Raising I_JOIN_OFFER: join-%s", crm_element_value(stored_msg, F_CRM_JOIN_ID)); + crm_debug("Raising I_JOIN_OFFER: join-%s", + crm_element_value(stored_msg, PCMK__XA_JOIN_ID)); return I_JOIN_OFFER; } else if (strcmp(op, CRM_OP_JOIN_ACKNAK) == 0) { - crm_debug("Raising I_JOIN_RESULT: join-%s", crm_element_value(stored_msg, F_CRM_JOIN_ID)); + crm_debug("Raising I_JOIN_RESULT: join-%s", + crm_element_value(stored_msg, PCMK__XA_JOIN_ID)); return I_JOIN_RESULT; } else if (strcmp(op, CRM_OP_LRM_DELETE) == 0) { @@ -1113,18 +1133,12 @@ handle_request(xmlNode *stored_msg, enum crmd_fsa_cause cause) || (strcmp(op, CRM_OP_LRM_REFRESH) == 0) // @COMPAT || (strcmp(op, CRM_OP_REPROBE) == 0)) { - crm_xml_add(stored_msg, F_CRM_SYS_TO, CRM_SYSTEM_LRMD); + crm_xml_add(stored_msg, PCMK__XA_CRM_SYS_TO, CRM_SYSTEM_LRMD); return I_ROUTER; } else if (strcmp(op, CRM_OP_NOOP) == 0) { return I_NULL; - } else if (strcmp(op, CRM_OP_LOCAL_SHUTDOWN) == 0) { - - crm_shutdown(SIGTERM); - /*return I_SHUTDOWN; */ - return I_NULL; - } else if (strcmp(op, CRM_OP_PING) == 0) { return handle_ping(stored_msg); @@ -1135,12 +1149,12 @@ handle_request(xmlNode *stored_msg, enum crmd_fsa_cause cause) int id = 0; const char *name = NULL; - crm_element_value_int(stored_msg, XML_ATTR_ID, &id); - name = crm_element_value(stored_msg, XML_ATTR_UNAME); + crm_element_value_int(stored_msg, PCMK_XA_ID, &id); + name = crm_element_value(stored_msg, PCMK_XA_UNAME); if(cause == C_IPC_MESSAGE) { msg = create_request(CRM_OP_RM_NODE_CACHE, NULL, NULL, CRM_SYSTEM_CRMD, CRM_SYSTEM_CRMD, NULL); - if (send_cluster_message(NULL, crm_msg_crmd, msg, TRUE) == FALSE) { + if (!pcmk__cluster_send_message(NULL, crm_msg_crmd, msg)) { crm_err("Could not instruct peers to remove references to node %s/%u", name, id); } else { crm_notice("Instructing peers to remove references to node %s/%u", name, id); @@ -1148,7 +1162,7 @@ handle_request(xmlNode *stored_msg, enum crmd_fsa_cause cause) free_xml(msg); } else { - reap_crm_member(id, name); + pcmk__cluster_forget_cluster_node(id, name); /* If we're forgetting this node, also forget any failures to fence * it, so we don't carry that over to any node added later with the @@ -1158,7 +1172,9 @@ handle_request(xmlNode *stored_msg, enum crmd_fsa_cause cause) } } else if (strcmp(op, CRM_OP_MAINTENANCE_NODES) == 0) { - xmlNode *xml = get_message_xml(stored_msg, F_CRM_DATA); + xmlNode *wrapper = pcmk__xe_first_child(stored_msg, PCMK__XE_CRM_XML, + NULL, NULL); + xmlNode *xml = pcmk__xe_first_child(wrapper, NULL, NULL, NULL); remote_ra_process_maintenance_nodes(xml); @@ -1183,15 +1199,15 @@ handle_request(xmlNode *stored_msg, enum crmd_fsa_cause cause) static void handle_response(xmlNode *stored_msg) { - const char *op = crm_element_value(stored_msg, F_CRM_TASK); + const char *op = crm_element_value(stored_msg, PCMK__XA_CRM_TASK); crm_log_xml_trace(stored_msg, "reply"); if (op == NULL) { - crm_warn("Ignoring reply without " F_CRM_TASK); + crm_warn("Ignoring reply without " PCMK__XA_CRM_TASK); } else if (AM_I_DC && strcmp(op, CRM_OP_PECALC) == 0) { // Check whether scheduler answer been superseded by subsequent request - const char *msg_ref = crm_element_value(stored_msg, XML_ATTR_REFERENCE); + const char *msg_ref = crm_element_value(stored_msg, PCMK_XA_REFERENCE); if (msg_ref == NULL) { crm_err("%s - Ignoring calculation with no reference", op); @@ -1212,7 +1228,7 @@ handle_response(xmlNode *stored_msg) || strcmp(op, CRM_OP_SHUTDOWN_REQ) == 0 || strcmp(op, CRM_OP_SHUTDOWN) == 0) { } else { - const char *host_from = crm_element_value(stored_msg, F_CRM_HOST_FROM); + const char *host_from = crm_element_value(stored_msg, PCMK__XA_SRC); crm_err("Unexpected response (op=%s, src=%s) sent to the %s", op, host_from, AM_I_DC ? "DC" : "controller"); @@ -1230,7 +1246,7 @@ handle_shutdown_request(xmlNode * stored_msg) */ char *now_s = NULL; - const char *host_from = crm_element_value(stored_msg, F_CRM_HOST_FROM); + const char *host_from = crm_element_value(stored_msg, PCMK__XA_SRC); if (host_from == NULL) { /* we're shutting down and the DC */ @@ -1242,7 +1258,7 @@ handle_shutdown_request(xmlNode * stored_msg) crm_log_xml_trace(stored_msg, "message"); now_s = pcmk__ttoa(time(NULL)); - update_attrd(host_from, XML_CIB_ATTR_SHUTDOWN, now_s, NULL, FALSE); + update_attrd(host_from, PCMK__NODE_ATTR_SHUTDOWN, now_s, NULL, FALSE); free(now_s); /* will be picked up by the TE as long as its running */ @@ -1258,8 +1274,8 @@ send_msg_via_ipc(xmlNode * msg, const char *sys) client_channel = pcmk__find_client_by_id(sys); - if (crm_element_value(msg, F_CRM_HOST_FROM) == NULL) { - crm_xml_add(msg, F_CRM_HOST_FROM, controld_globals.our_nodename); + if (crm_element_value(msg, PCMK__XA_SRC) == NULL) { + crm_xml_add(msg, PCMK__XA_SRC, controld_globals.our_nodename); } if (client_channel != NULL) { @@ -1267,16 +1283,21 @@ send_msg_via_ipc(xmlNode * msg, const char *sys) pcmk__ipc_send_xml(client_channel, 0, msg, crm_ipc_server_event); } else if (pcmk__str_eq(sys, CRM_SYSTEM_TENGINE, pcmk__str_none)) { - xmlNode *data = get_message_xml(msg, F_CRM_DATA); + xmlNode *wrapper = pcmk__xe_first_child(msg, PCMK__XE_CRM_XML, NULL, + NULL); + xmlNode *data = pcmk__xe_first_child(wrapper, NULL, NULL, NULL); process_te_message(msg, data); } else if (pcmk__str_eq(sys, CRM_SYSTEM_LRMD, pcmk__str_none)) { fsa_data_t fsa_data; ha_msg_input_t fsa_input; + xmlNode *wrapper = NULL; fsa_input.msg = msg; - fsa_input.xml = get_message_xml(msg, F_CRM_DATA); + + wrapper = pcmk__xe_first_child(msg, PCMK__XE_CRM_XML, NULL, NULL); + fsa_input.xml = pcmk__xe_first_child(wrapper, NULL, NULL, NULL); fsa_data.id = 0; fsa_data.actions = 0; @@ -1323,14 +1344,15 @@ broadcast_remote_state_message(const char *node_name, bool node_up) crm_info("Notifying cluster of Pacemaker Remote node %s %s", node_name, node_up? "coming up" : "going down"); - crm_xml_add(msg, XML_ATTR_ID, node_name); + crm_xml_add(msg, PCMK_XA_ID, node_name); pcmk__xe_set_bool_attr(msg, PCMK__XA_IN_CCM, node_up); if (node_up) { - crm_xml_add(msg, PCMK__XA_CONN_HOST, controld_globals.our_nodename); + crm_xml_add(msg, PCMK__XA_CONNECTION_HOST, + controld_globals.our_nodename); } - send_cluster_message(NULL, crm_msg_crmd, msg, TRUE); + pcmk__cluster_send_message(NULL, crm_msg_crmd, msg); free_xml(msg); } diff --git a/daemons/controld/controld_metadata.c b/daemons/controld/controld_metadata.c index c813ceb..37df38c 100644 --- a/daemons/controld/controld_metadata.c +++ b/daemons/controld/controld_metadata.c @@ -1,5 +1,5 @@ /* - * Copyright 2017-2023 the Pacemaker project contributors + * Copyright 2017-2024 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -70,25 +70,18 @@ metadata_cache_reset(GHashTable *mdc) static struct ra_param_s * ra_param_from_xml(xmlNode *param_xml) { - const char *param_name = crm_element_value(param_xml, "name"); + const char *param_name = crm_element_value(param_xml, PCMK_XA_NAME); struct ra_param_s *p; - p = calloc(1, sizeof(struct ra_param_s)); - if (p == NULL) { - return NULL; - } + p = pcmk__assert_alloc(1, sizeof(struct ra_param_s)); - p->rap_name = strdup(param_name); - if (p->rap_name == NULL) { - free(p); - return NULL; - } + p->rap_name = pcmk__str_copy(param_name); - if (pcmk__xe_attr_is_true(param_xml, "reloadable")) { + if (pcmk__xe_attr_is_true(param_xml, PCMK_XA_RELOADABLE)) { controld_set_ra_param_flags(p, ra_param_reloadable); } - if (pcmk__xe_attr_is_true(param_xml, "unique")) { + if (pcmk__xe_attr_is_true(param_xml, PCMK_XA_UNIQUE)) { controld_set_ra_param_flags(p, ra_param_unique); } @@ -139,21 +132,19 @@ controld_cache_metadata(GHashTable *mdc, const lrmd_rsc_info_t *rsc, goto err; } - metadata = string2xml(metadata_str); + metadata = pcmk__xml_parse(metadata_str); if (!metadata) { reason = "Metadata is not valid XML"; goto err; } - md = calloc(1, sizeof(struct ra_metadata_s)); - if (md == NULL) { - reason = "Could not allocate memory"; - goto err; - } + md = pcmk__assert_alloc(1, sizeof(struct ra_metadata_s)); if (strcmp(rsc->standard, PCMK_RESOURCE_CLASS_OCF) == 0) { xmlChar *content = NULL; - xmlNode *version_element = first_named_child(metadata, "version"); + xmlNode *version_element = pcmk__xe_first_child(metadata, + PCMK_XE_VERSION, NULL, + NULL); if (version_element != NULL) { content = xmlNodeGetContent(version_element); @@ -166,11 +157,11 @@ controld_cache_metadata(GHashTable *mdc, const lrmd_rsc_info_t *rsc, } // Check supported actions - match = first_named_child(metadata, "actions"); - for (match = first_named_child(match, "action"); match != NULL; - match = crm_next_same_xml(match)) { + match = pcmk__xe_first_child(metadata, PCMK_XE_ACTIONS, NULL, NULL); + for (match = pcmk__xe_first_child(match, PCMK_XE_ACTION, NULL, NULL); + match != NULL; match = pcmk__xe_next_same(match)) { - const char *action_name = crm_element_value(match, "name"); + const char *action_name = crm_element_value(match, PCMK_XA_NAME); if (pcmk__str_eq(action_name, PCMK_ACTION_RELOAD_AGENT, pcmk__str_none)) { @@ -188,15 +179,15 @@ controld_cache_metadata(GHashTable *mdc, const lrmd_rsc_info_t *rsc, } // Build a parameter list - match = first_named_child(metadata, "parameters"); - for (match = first_named_child(match, "parameter"); match != NULL; - match = crm_next_same_xml(match)) { + match = pcmk__xe_first_child(metadata, PCMK_XE_PARAMETERS, NULL, NULL); + for (match = pcmk__xe_first_child(match, PCMK_XE_PARAMETER, NULL, NULL); + match != NULL; match = pcmk__xe_next_same(match)) { - const char *param_name = crm_element_value(match, "name"); + const char *param_name = crm_element_value(match, PCMK_XA_NAME); if (param_name == NULL) { - crm_warn("Metadata for %s:%s:%s has parameter without a name", - rsc->standard, rsc->provider, rsc->type); + crm_warn("Metadata for %s:%s:%s has parameter without a " + PCMK_XA_NAME, rsc->standard, rsc->provider, rsc->type); } else { struct ra_param_s *p = ra_param_from_xml(match); diff --git a/daemons/controld/controld_remote_ra.c b/daemons/controld/controld_remote_ra.c index d692ef6..4bbf80c 100644 --- a/daemons/controld/controld_remote_ra.c +++ b/daemons/controld/controld_remote_ra.c @@ -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. * @@ -10,7 +10,7 @@ #include <crm_internal.h> #include <crm/crm.h> -#include <crm/msg_xml.h> +#include <crm/common/xml.h> #include <crm/common/xml_internal.h> #include <crm/lrmd.h> #include <crm/lrmd_internal.h> @@ -206,7 +206,8 @@ should_purge_attributes(crm_node_t *node) /* Get the node that was hosting the remote connection resource from the * peer cache. That's the one we really care about here. */ - conn_node = crm_get_peer(0, node->conn_host); + conn_node = pcmk__get_node(0, node->conn_host, NULL, + pcmk__node_search_cluster_member); if (conn_node == NULL) { return purge; } @@ -296,7 +297,7 @@ remote_node_up(const char *node_name) update_attrd(node_name, CRM_OP_PROBED, NULL, NULL, TRUE); /* Ensure node is in the remote peer cache with member status */ - node = crm_remote_peer_get(node_name); + node = pcmk__cluster_lookup_remote_node(node_name); CRM_CHECK(node != NULL, return); purge_remote_node_attrs(call_opt, node); @@ -324,24 +325,24 @@ remote_node_up(const char *node_name) */ broadcast_remote_state_message(node_name, true); - update = create_xml_node(NULL, XML_CIB_TAG_STATUS); + update = pcmk__xe_create(NULL, PCMK_XE_STATUS); state = create_node_state_update(node, node_update_cluster, update, __func__); - /* Clear the XML_NODE_IS_FENCED flag in the node state. If the node ever + /* Clear the PCMK__XA_NODE_FENCED flag in the node state. If the node ever * needs to be fenced, this flag will allow various actions to determine * whether the fencing has happened yet. */ - crm_xml_add(state, XML_NODE_IS_FENCED, "0"); + crm_xml_add(state, PCMK__XA_NODE_FENCED, "0"); /* TODO: If the remote connection drops, and this (async) CIB update either * failed or has not yet completed, later actions could mistakenly think the - * node has already been fenced (if the XML_NODE_IS_FENCED attribute was + * node has already been fenced (if the PCMK__XA_NODE_FENCED attribute was * previously set, because it won't have been cleared). This could prevent * actual fencing or allow recurring monitor failures to be cleared too * soon. Ideally, we wouldn't rely on the CIB for the fenced status. */ - controld_update_cib(XML_CIB_TAG_STATUS, update, call_opt, NULL); + controld_update_cib(PCMK_XE_STATUS, update, call_opt, NULL); free_xml(update); } @@ -379,7 +380,7 @@ remote_node_down(const char *node_name, const enum down_opts opts) } /* Ensure node is in the remote peer cache with lost state */ - node = crm_remote_peer_get(node_name); + node = pcmk__cluster_lookup_remote_node(node_name); CRM_CHECK(node != NULL, return); pcmk__update_peer_state(__func__, node, CRM_NODE_LOST, 0); @@ -387,9 +388,9 @@ remote_node_down(const char *node_name, const enum down_opts opts) broadcast_remote_state_message(node_name, false); /* Update CIB node state */ - update = create_xml_node(NULL, XML_CIB_TAG_STATUS); + update = pcmk__xe_create(NULL, PCMK_XE_STATUS); create_node_state_update(node, node_update_cluster, update, __func__); - controld_update_cib(XML_CIB_TAG_STATUS, update, call_opt, NULL); + controld_update_cib(PCMK_XE_STATUS, update, call_opt, NULL); free_xml(update); } @@ -419,7 +420,7 @@ check_remote_node_state(const remote_ra_cmd_t *cmd) * it hasn't been tracking the remote node, and other code relies on * the cache to distinguish remote nodes from unseen cluster nodes. */ - crm_node_t *node = crm_remote_peer_get(cmd->rsc_id); + crm_node_t *node = pcmk__cluster_lookup_remote_node(cmd->rsc_id); CRM_CHECK(node != NULL, return); pcmk__update_peer_state(__func__, node, CRM_NODE_MEMBER, 0); @@ -437,7 +438,7 @@ check_remote_node_state(const remote_ra_cmd_t *cmd) * so if the connection migrated elsewhere and we aren't DC, * un-cache the node, so we don't have stale info */ - crm_remote_peer_cache_remove(cmd->rsc_id); + pcmk__cluster_forget_remote_node(cmd->rsc_id); } } } @@ -493,7 +494,7 @@ report_remote_ra_result(remote_ra_cmd_t * cmd) op.params = pcmk__strkey_table(free, free); for (tmp = cmd->params; tmp; tmp = tmp->next) { - g_hash_table_insert(op.params, strdup(tmp->key), strdup(tmp->value)); + pcmk__insert_dup(op.params, tmp->key, tmp->value); } } @@ -861,12 +862,17 @@ handle_remote_ra_start(lrm_state_t * lrm_state, remote_ra_cmd_t * cmd, int timeo int rc = pcmk_rc_ok; for (tmp = cmd->params; tmp; tmp = tmp->next) { - if (pcmk__strcase_any_of(tmp->key, XML_RSC_ATTR_REMOTE_RA_ADDR, - XML_RSC_ATTR_REMOTE_RA_SERVER, NULL)) { + if (pcmk__strcase_any_of(tmp->key, + PCMK_REMOTE_RA_ADDR, PCMK_REMOTE_RA_SERVER, + NULL)) { server = tmp->value; - } else if (pcmk__str_eq(tmp->key, XML_RSC_ATTR_REMOTE_RA_PORT, pcmk__str_casei)) { + + } else if (pcmk__str_eq(tmp->key, PCMK_REMOTE_RA_PORT, + pcmk__str_none)) { port = atoi(tmp->value); - } else if (pcmk__str_eq(tmp->key, CRM_META "_" XML_RSC_ATTR_CONTAINER, pcmk__str_casei)) { + + } else if (pcmk__str_eq(tmp->key, CRM_META "_" PCMK__META_CONTAINER, + pcmk__str_none)) { lrm_remote_set_flags(lrm_state, controlling_guest); } } @@ -967,9 +973,9 @@ handle_remote_ra_exec(gpointer user_data) } else if (pcmk__str_any_of(cmd->action, PCMK_ACTION_RELOAD, PCMK_ACTION_RELOAD_AGENT, NULL)) { - /* Currently the only reloadable parameter is reconnect_interval, - * which is only used by the scheduler via the CIB, so reloads are a - * no-op. + /* Currently the only reloadable parameter is + * PCMK_REMOTE_RA_RECONNECT_INTERVAL, which is only used by the + * scheduler via the CIB, so reloads are a no-op. * * @COMPAT DC <2.1.0: We only need to check for "reload" in case * we're in a rolling upgrade with a DC scheduling "reload" instead @@ -995,7 +1001,7 @@ remote_ra_data_init(lrm_state_t * lrm_state) return; } - ra_data = calloc(1, sizeof(remote_ra_data_t)); + ra_data = pcmk__assert_alloc(1, sizeof(remote_ra_data_t)); ra_data->work = mainloop_add_trigger(G_PRIORITY_HIGH, handle_remote_ra_exec, lrm_state); lrm_state->remote_ra_data = ra_data; } @@ -1041,12 +1047,12 @@ remote_ra_get_rsc_info(lrm_state_t * lrm_state, const char *rsc_id) lrmd_rsc_info_t *info = NULL; if ((lrm_state_find(rsc_id))) { - info = calloc(1, sizeof(lrmd_rsc_info_t)); + info = pcmk__assert_alloc(1, sizeof(lrmd_rsc_info_t)); - info->id = strdup(rsc_id); - info->type = strdup(REMOTE_LRMD_RA); - info->standard = strdup(PCMK_RESOURCE_CLASS_OCF); - info->provider = strdup("pacemaker"); + info->id = pcmk__str_copy(rsc_id); + info->type = pcmk__str_copy(REMOTE_LRMD_RA); + info->standard = pcmk__str_copy(PCMK_RESOURCE_CLASS_OCF); + info->provider = pcmk__str_copy("pacemaker"); } return info; @@ -1202,7 +1208,7 @@ handle_dup: /* update the userdata */ if (userdata) { free(cmd->userdata); - cmd->userdata = strdup(userdata); + cmd->userdata = pcmk__str_copy(userdata); } /* if we've already reported success, generate a new call id */ @@ -1280,23 +1286,12 @@ controld_execute_remote_agent(const lrm_state_t *lrm_state, const char *rsc_id, return pcmk_rc_ok; } - cmd = calloc(1, sizeof(remote_ra_cmd_t)); - if (cmd == NULL) { - lrmd_key_value_freeall(params); - return ENOMEM; - } - - cmd->owner = strdup(lrm_state->node_name); - cmd->rsc_id = strdup(rsc_id); - cmd->action = strdup(action); - cmd->userdata = strdup(userdata); - if ((cmd->owner == NULL) || (cmd->rsc_id == NULL) || (cmd->action == NULL) - || (cmd->userdata == NULL)) { - free_cmd(cmd); - lrmd_key_value_freeall(params); - return ENOMEM; - } + cmd = pcmk__assert_alloc(1, sizeof(remote_ra_cmd_t)); + cmd->owner = pcmk__str_copy(lrm_state->node_name); + cmd->rsc_id = pcmk__str_copy(rsc_id); + cmd->action = pcmk__str_copy(action); + cmd->userdata = pcmk__str_copy(userdata); cmd->interval_ms = interval_ms; cmd->timeout = timeout_ms; cmd->start_delay = start_delay_ms; @@ -1347,9 +1342,8 @@ remote_ra_fail(const char *node_name) * </downed> * </pseudo_event> */ -#define XPATH_PSEUDO_FENCE "/" XML_GRAPH_TAG_PSEUDO_EVENT \ - "[@" XML_LRM_ATTR_TASK "='stonith']/" XML_GRAPH_TAG_DOWNED \ - "/" XML_CIB_TAG_NODE +#define XPATH_PSEUDO_FENCE "/" PCMK__XE_PSEUDO_EVENT \ + "[@" PCMK_XA_OPERATION "='stonith']/" PCMK__XE_DOWNED "/" PCMK_XE_NODE /*! * \internal @@ -1380,7 +1374,7 @@ remote_ra_process_pseudo(xmlNode *xml) * recovered. */ if (result) { - const char *remote = ID(result); + const char *remote = pcmk__xe_id(result); if (remote) { remote_node_down(remote, DOWN_ERASE_LRM); @@ -1398,13 +1392,13 @@ remote_ra_maintenance(lrm_state_t * lrm_state, gboolean maintenance) crm_node_t *node; call_opt = crmd_cib_smart_opt(); - node = crm_remote_peer_get(lrm_state->node_name); + node = pcmk__cluster_lookup_remote_node(lrm_state->node_name); CRM_CHECK(node != NULL, return); - update = create_xml_node(NULL, XML_CIB_TAG_STATUS); + update = pcmk__xe_create(NULL, PCMK_XE_STATUS); state = create_node_state_update(node, node_update_none, update, __func__); - crm_xml_add(state, XML_NODE_IS_MAINTENANCE, maintenance?"1":"0"); - if (controld_update_cib(XML_CIB_TAG_STATUS, update, call_opt, + crm_xml_add(state, PCMK__XA_NODE_IN_MAINTENANCE, (maintenance? "1" : "0")); + if (controld_update_cib(PCMK_XE_STATUS, update, call_opt, NULL) == pcmk_rc_ok) { /* TODO: still not 100% sure that async update will succeed ... */ if (maintenance) { @@ -1416,9 +1410,9 @@ remote_ra_maintenance(lrm_state_t * lrm_state, gboolean maintenance) free_xml(update); } -#define XPATH_PSEUDO_MAINTENANCE "//" XML_GRAPH_TAG_PSEUDO_EVENT \ - "[@" XML_LRM_ATTR_TASK "='" PCMK_ACTION_MAINTENANCE_NODES "']/" \ - XML_GRAPH_TAG_MAINTENANCE +#define XPATH_PSEUDO_MAINTENANCE "//" PCMK__XE_PSEUDO_EVENT \ + "[@" PCMK_XA_OPERATION "='" PCMK_ACTION_MAINTENANCE_NODES "']/" \ + PCMK__XE_MAINTENANCE /*! * \internal @@ -1435,25 +1429,29 @@ remote_ra_process_maintenance_nodes(xmlNode *xml) xmlNode *node; int cnt = 0, cnt_remote = 0; - for (node = first_named_child(getXpathResult(search, 0), - XML_CIB_TAG_NODE); - node != NULL; node = crm_next_same_xml(node)) { + for (node = pcmk__xe_first_child(getXpathResult(search, 0), + PCMK_XE_NODE, NULL, NULL); + node != NULL; node = pcmk__xe_next_same(node)) { - lrm_state_t *lrm_state = lrm_state_find(ID(node)); + lrm_state_t *lrm_state = lrm_state_find(pcmk__xe_id(node)); cnt++; if (lrm_state && lrm_state->remote_ra_data && pcmk_is_set(((remote_ra_data_t *) lrm_state->remote_ra_data)->status, remote_active)) { - int is_maint; + + const char *in_maint_s = NULL; + int in_maint; cnt_remote++; - pcmk__scan_min_int(crm_element_value(node, XML_NODE_IS_MAINTENANCE), - &is_maint, 0); - remote_ra_maintenance(lrm_state, is_maint); + in_maint_s = crm_element_value(node, + PCMK__XA_NODE_IN_MAINTENANCE); + pcmk__scan_min_int(in_maint_s, &in_maint, 0); + remote_ra_maintenance(lrm_state, in_maint); } } - crm_trace("Action holds %d nodes (%d remotes found) " - "adjusting maintenance-mode", cnt, cnt_remote); + crm_trace("Action holds %d nodes (%d remotes found) adjusting " + PCMK_OPT_MAINTENANCE_MODE, + cnt, cnt_remote); } freeXpathObject(search); } diff --git a/daemons/controld/controld_schedulerd.c b/daemons/controld/controld_schedulerd.c index 8aca83f..3081304 100644 --- a/daemons/controld/controld_schedulerd.c +++ b/daemons/controld/controld_schedulerd.c @@ -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. * @@ -15,7 +15,6 @@ #include <crm/cluster.h> #include <crm/common/xml.h> #include <crm/crm.h> -#include <crm/msg_xml.h> #include <crm/common/xml_internal.h> #include <crm/common/ipc.h> #include <crm/common/ipc_schedulerd.h> @@ -65,7 +64,7 @@ save_cib_contents(xmlNode *msg, int call_id, int rc, xmlNode *output, if (rc == pcmk_ok) { char *filename = crm_strdup_printf(PE_STATE_DIR "/pe-core-%s.bz2", id); - if (write_xml_file(output, filename, TRUE) < 0) { + if (pcmk__xml_write_file(output, filename, true, NULL) != pcmk_rc_ok) { crm_err("Could not save Cluster Information Base to %s after scheduler crash", filename); } else { @@ -144,12 +143,13 @@ handle_reply(pcmk_schedulerd_api_reply_t *reply) * * The name of the top level element here is irrelevant. Nothing checks it. */ - fsa_input.msg = create_xml_node(NULL, "dummy-reply"); - crm_xml_add(fsa_input.msg, XML_ATTR_REFERENCE, msg_ref); - crm_xml_add(fsa_input.msg, F_CRM_TGRAPH_INPUT, reply->data.graph.input); + fsa_input.msg = pcmk__xe_create(NULL, "dummy-reply"); + crm_xml_add(fsa_input.msg, PCMK_XA_REFERENCE, msg_ref); + crm_xml_add(fsa_input.msg, PCMK__XA_CRM_TGRAPH_IN, + reply->data.graph.input); - crm_data_node = create_xml_node(fsa_input.msg, F_CRM_DATA); - add_node_copy(crm_data_node, reply->data.graph.tgraph); + crm_data_node = pcmk__xe_create(fsa_input.msg, PCMK__XE_CRM_XML); + pcmk__xml_copy(crm_data_node, reply->data.graph.tgraph); register_fsa_input_later(C_IPC_MESSAGE, I_PE_SUCCESS, &fsa_input); free_xml(fsa_input.msg); @@ -378,14 +378,14 @@ force_local_option(xmlNode *xml, const char *attr_name, const char *attr_value) char *xpath_string = NULL; xmlXPathObjectPtr xpathObj = NULL; - xpath_base = pcmk_cib_xpath_for(XML_CIB_TAG_CRMCONFIG); + xpath_base = pcmk_cib_xpath_for(PCMK_XE_CRM_CONFIG); if (xpath_base == NULL) { - crm_err(XML_CIB_TAG_CRMCONFIG " CIB element not known (bug?)"); + crm_err(PCMK_XE_CRM_CONFIG " CIB element not known (bug?)"); return; } xpath_string = crm_strdup_printf("%s//%s//nvpair[@name='%s']", - xpath_base, XML_CIB_TAG_PROPSET, + xpath_base, PCMK_XE_CLUSTER_PROPERTY_SET, attr_name); xpathObj = xpath_search(xml, xpath_string); max = numXpathResults(xpathObj); @@ -393,8 +393,9 @@ force_local_option(xmlNode *xml, const char *attr_name, const char *attr_value) for (lpc = 0; lpc < max; lpc++) { xmlNode *match = getXpathResult(xpathObj, lpc); - crm_trace("Forcing %s/%s = %s", ID(match), attr_name, attr_value); - crm_xml_add(match, XML_NVPAIR_ATTR_VALUE, attr_value); + crm_trace("Forcing %s/%s = %s", + pcmk__xe_id(match), attr_name, attr_value); + crm_xml_add(match, PCMK_XA_VALUE, attr_value); } if(max == 0) { @@ -403,32 +404,37 @@ force_local_option(xmlNode *xml, const char *attr_name, const char *attr_value) xmlNode *cluster_property_set = NULL; crm_trace("Creating %s-%s for %s=%s", - CIB_OPTIONS_FIRST, attr_name, attr_name, attr_value); + PCMK_VALUE_CIB_BOOTSTRAP_OPTIONS, attr_name, attr_name, + attr_value); - configuration = pcmk__xe_match(xml, XML_CIB_TAG_CONFIGURATION, NULL, - NULL); + configuration = pcmk__xe_first_child(xml, PCMK_XE_CONFIGURATION, NULL, + NULL); if (configuration == NULL) { - configuration = create_xml_node(xml, XML_CIB_TAG_CONFIGURATION); + configuration = pcmk__xe_create(xml, PCMK_XE_CONFIGURATION); } - crm_config = pcmk__xe_match(configuration, XML_CIB_TAG_CRMCONFIG, NULL, - NULL); + crm_config = pcmk__xe_first_child(configuration, PCMK_XE_CRM_CONFIG, + NULL, NULL); if (crm_config == NULL) { - crm_config = create_xml_node(configuration, XML_CIB_TAG_CRMCONFIG); + crm_config = pcmk__xe_create(configuration, PCMK_XE_CRM_CONFIG); } - cluster_property_set = pcmk__xe_match(crm_config, XML_CIB_TAG_PROPSET, - NULL, NULL); + cluster_property_set = + pcmk__xe_first_child(crm_config, PCMK_XE_CLUSTER_PROPERTY_SET, NULL, + NULL); if (cluster_property_set == NULL) { - cluster_property_set = create_xml_node(crm_config, XML_CIB_TAG_PROPSET); - crm_xml_add(cluster_property_set, XML_ATTR_ID, CIB_OPTIONS_FIRST); + cluster_property_set = + pcmk__xe_create(crm_config, PCMK_XE_CLUSTER_PROPERTY_SET); + crm_xml_add(cluster_property_set, PCMK_XA_ID, + PCMK_VALUE_CIB_BOOTSTRAP_OPTIONS); } - xml = create_xml_node(cluster_property_set, XML_CIB_TAG_NVPAIR); + xml = pcmk__xe_create(cluster_property_set, PCMK_XE_NVPAIR); - crm_xml_set_id(xml, "%s-%s", CIB_OPTIONS_FIRST, attr_name); - crm_xml_add(xml, XML_NVPAIR_ATTR_NAME, attr_name); - crm_xml_add(xml, XML_NVPAIR_ATTR_VALUE, attr_value); + crm_xml_set_id(xml, "%s-%s", + PCMK_VALUE_CIB_BOOTSTRAP_OPTIONS, attr_name); + crm_xml_add(xml, PCMK_XA_NAME, attr_name); + crm_xml_add(xml, PCMK_XA_VALUE, attr_value); } freeXpathObject(xpathObj); } @@ -476,16 +482,16 @@ do_pe_invoke_callback(xmlNode * msg, int call_id, int rc, xmlNode * output, void * scheduler is invoked */ pcmk__refresh_node_caches_from_cib(output); - crm_xml_add(output, XML_ATTR_DC_UUID, controld_globals.our_uuid); - pcmk__xe_set_bool_attr(output, XML_ATTR_HAVE_QUORUM, + crm_xml_add(output, PCMK_XA_DC_UUID, controld_globals.our_uuid); + pcmk__xe_set_bool_attr(output, PCMK_XA_HAVE_QUORUM, pcmk_is_set(controld_globals.flags, controld_has_quorum)); - force_local_option(output, XML_ATTR_HAVE_WATCHDOG, pcmk__btoa(watchdog)); + force_local_option(output, PCMK_OPT_HAVE_WATCHDOG, pcmk__btoa(watchdog)); if (pcmk_is_set(controld_globals.flags, controld_ever_had_quorum) && !crm_have_quorum) { - crm_xml_add_int(output, XML_ATTR_QUORUM_PANIC, 1); + crm_xml_add_int(output, PCMK_XA_NO_QUORUM_PANIC, 1); } rc = pcmk_rc2legacy(pcmk_schedulerd_api_graph(schedulerd_api, output, &ref)); @@ -498,8 +504,8 @@ do_pe_invoke_callback(xmlNode * msg, int call_id, int rc, xmlNode * output, void CRM_ASSERT(ref != NULL); controld_expect_sched_reply(ref); crm_debug("Invoking the scheduler: query=%d, ref=%s, seq=%llu, " - "quorate=%s", fsa_pe_query, controld_globals.fsa_pe_ref, - crm_peer_seq, pcmk__btoa(pcmk_is_set(controld_globals.flags, - controld_has_quorum))); + "quorate=%s", + fsa_pe_query, controld_globals.fsa_pe_ref, crm_peer_seq, + pcmk__flag_text(controld_globals.flags, controld_has_quorum)); } } diff --git a/daemons/controld/controld_te_actions.c b/daemons/controld/controld_te_actions.c index fe6b744..a4c99fc 100644 --- a/daemons/controld/controld_te_actions.c +++ b/daemons/controld/controld_te_actions.c @@ -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. * @@ -13,7 +13,6 @@ #include <crm/crm.h> #include <crm/cib.h> #include <crm/lrmd.h> // lrmd_event_data_t, lrmd_free_event() -#include <crm/msg_xml.h> #include <crm/common/xml.h> #include <crm/cluster.h> @@ -44,7 +43,7 @@ te_start_action_timer(const pcmk__graph_t *graph, pcmk__graph_action_t *action) static int execute_pseudo_action(pcmk__graph_t *graph, pcmk__graph_action_t *pseudo) { - const char *task = crm_element_value(pseudo->xml, XML_LRM_ATTR_TASK); + const char *task = crm_element_value(pseudo->xml, PCMK_XA_OPERATION); /* send to peers as well? */ if (pcmk__str_eq(task, PCMK_ACTION_MAINTENANCE_NODES, pcmk__str_casei)) { @@ -62,7 +61,7 @@ execute_pseudo_action(pcmk__graph_t *graph, pcmk__graph_action_t *pseudo) cmd = create_request(task, pseudo->xml, node->uname, CRM_SYSTEM_CRMD, CRM_SYSTEM_TENGINE, NULL); - send_cluster_message(node, crm_msg_crmd, cmd, FALSE); + pcmk__cluster_send_message(node, crm_msg_crmd, cmd); free_xml(cmd); } @@ -73,7 +72,7 @@ execute_pseudo_action(pcmk__graph_t *graph, pcmk__graph_action_t *pseudo) } crm_debug("Pseudo-action %d (%s) fired and confirmed", pseudo->id, - crm_element_value(pseudo->xml, XML_LRM_ATTR_TASK_KEY)); + crm_element_value(pseudo->xml, PCMK__XA_OPERATION_KEY)); te_action_confirmed(pseudo, graph); return pcmk_rc_ok; } @@ -83,7 +82,7 @@ get_target_rc(pcmk__graph_action_t *action) { int exit_status; - pcmk__scan_min_int(crm_meta_value(action->params, XML_ATTR_TE_TARGET_RC), + pcmk__scan_min_int(crm_meta_value(action->params, PCMK__META_OP_TARGET_RC), &exit_status, 0); return exit_status; } @@ -113,22 +112,24 @@ execute_cluster_action(pcmk__graph_t *graph, pcmk__graph_action_t *action) gboolean rc = TRUE; gboolean no_wait = FALSE; - id = ID(action->xml); + const crm_node_t *node = NULL; + + id = pcmk__xe_id(action->xml); CRM_CHECK(!pcmk__str_empty(id), return EPROTO); - task = crm_element_value(action->xml, XML_LRM_ATTR_TASK); + task = crm_element_value(action->xml, PCMK_XA_OPERATION); CRM_CHECK(!pcmk__str_empty(task), return EPROTO); - on_node = crm_element_value(action->xml, XML_LRM_ATTR_TARGET); + on_node = crm_element_value(action->xml, PCMK__META_ON_NODE); CRM_CHECK(!pcmk__str_empty(on_node), return pcmk_rc_node_unknown); - router_node = crm_element_value(action->xml, XML_LRM_ATTR_ROUTER_NODE); + router_node = crm_element_value(action->xml, PCMK__XA_ROUTER_NODE); if (router_node == NULL) { router_node = on_node; if (pcmk__str_eq(task, PCMK_ACTION_LRM_DELETE, pcmk__str_none)) { const char *mode = crm_element_value(action->xml, PCMK__XA_MODE); - if (pcmk__str_eq(mode, XML_TAG_CIB, pcmk__str_none)) { + if (pcmk__str_eq(mode, PCMK__VALUE_CIB, pcmk__str_none)) { router_node = controld_globals.our_nodename; } } @@ -139,7 +140,7 @@ execute_cluster_action(pcmk__graph_t *graph, pcmk__graph_action_t *action) is_local = TRUE; } - value = crm_meta_value(action->params, XML_ATTR_TE_NOWAIT); + value = crm_meta_value(action->params, PCMK__META_OP_NO_WAIT); if (crm_is_true(value)) { no_wait = TRUE; } @@ -158,7 +159,8 @@ execute_cluster_action(pcmk__graph_t *graph, pcmk__graph_action_t *action) return pcmk_rc_ok; } else if (pcmk__str_eq(task, PCMK_ACTION_DO_SHUTDOWN, pcmk__str_none)) { - crm_node_t *peer = crm_get_peer(0, router_node); + crm_node_t *peer = pcmk__get_node(0, router_node, NULL, + pcmk__node_search_cluster_member); pcmk__update_peer_expected(__func__, peer, CRMD_JOINSTATE_DOWN); } @@ -168,9 +170,11 @@ execute_cluster_action(pcmk__graph_t *graph, pcmk__graph_action_t *action) counter = pcmk__transition_key(controld_globals.transition_graph->id, action->id, get_target_rc(action), controld_globals.te_uuid); - crm_xml_add(cmd, XML_ATTR_TRANSITION_KEY, counter); + crm_xml_add(cmd, PCMK__XA_TRANSITION_KEY, counter); - rc = send_cluster_message(crm_get_peer(0, router_node), crm_msg_crmd, cmd, TRUE); + node = pcmk__get_node(0, router_node, NULL, + pcmk__node_search_cluster_member); + rc = pcmk__cluster_send_message(node, crm_msg_crmd, cmd); free(counter); free_xml(cmd); @@ -213,16 +217,17 @@ static lrmd_event_data_t * synthesize_timeout_event(const pcmk__graph_action_t *action, int target_rc) { lrmd_event_data_t *op = NULL; - const char *target = crm_element_value(action->xml, XML_LRM_ATTR_TARGET); + const char *target = crm_element_value(action->xml, PCMK__META_ON_NODE); const char *reason = NULL; char *dynamic_reason = NULL; - if (pcmk__str_eq(target, get_local_node_name(), pcmk__str_casei)) { + if (pcmk__str_eq(target, pcmk__cluster_local_node_name(), + pcmk__str_casei)) { reason = "Local executor did not return result in time"; } else { const char *router_node = NULL; - router_node = crm_element_value(action->xml, XML_LRM_ATTR_ROUTER_NODE); + router_node = crm_element_value(action->xml, PCMK__XA_ROUTER_NODE); if (router_node == NULL) { router_node = target; } @@ -254,18 +259,21 @@ controld_record_action_event(pcmk__graph_action_t *action, int rc = pcmk_ok; const char *rsc_id = NULL; - const char *target = crm_element_value(action->xml, XML_LRM_ATTR_TARGET); - const char *task_uuid = crm_element_value(action->xml, XML_LRM_ATTR_TASK_KEY); - const char *target_uuid = crm_element_value(action->xml, XML_LRM_ATTR_TARGET_UUID); + const char *target = crm_element_value(action->xml, PCMK__META_ON_NODE); + const char *task_uuid = crm_element_value(action->xml, + PCMK__XA_OPERATION_KEY); + const char *target_uuid = crm_element_value(action->xml, + PCMK__META_ON_NODE_UUID); int target_rc = get_target_rc(action); - action_rsc = find_xml_node(action->xml, XML_CIB_TAG_RESOURCE, TRUE); + action_rsc = pcmk__xe_first_child(action->xml, PCMK_XE_PRIMITIVE, NULL, + NULL); if (action_rsc == NULL) { return; } - rsc_id = ID(action_rsc); + rsc_id = pcmk__xe_id(action_rsc); CRM_CHECK(rsc_id != NULL, crm_log_xml_err(action->xml, "Bad:action"); return); @@ -278,27 +286,27 @@ controld_record_action_event(pcmk__graph_action_t *action, <lrm_resource id="rsc2" last_op="start" op_code="0" target="hadev"/> */ - state = create_xml_node(NULL, XML_CIB_TAG_STATE); + state = pcmk__xe_create(NULL, PCMK__XE_NODE_STATE); - crm_xml_add(state, XML_ATTR_ID, target_uuid); - crm_xml_add(state, XML_ATTR_UNAME, target); + crm_xml_add(state, PCMK_XA_ID, target_uuid); + crm_xml_add(state, PCMK_XA_UNAME, target); - rsc = create_xml_node(state, XML_CIB_TAG_LRM); - crm_xml_add(rsc, XML_ATTR_ID, target_uuid); + rsc = pcmk__xe_create(state, PCMK__XE_LRM); + crm_xml_add(rsc, PCMK_XA_ID, target_uuid); - rsc = create_xml_node(rsc, XML_LRM_TAG_RESOURCES); - rsc = create_xml_node(rsc, XML_LRM_TAG_RESOURCE); - crm_xml_add(rsc, XML_ATTR_ID, rsc_id); + rsc = pcmk__xe_create(rsc, PCMK__XE_LRM_RESOURCES); + rsc = pcmk__xe_create(rsc, PCMK__XE_LRM_RESOURCE); + crm_xml_add(rsc, PCMK_XA_ID, rsc_id); - crm_copy_xml_element(action_rsc, rsc, XML_ATTR_TYPE); - crm_copy_xml_element(action_rsc, rsc, XML_AGENT_ATTR_CLASS); - crm_copy_xml_element(action_rsc, rsc, XML_AGENT_ATTR_PROVIDER); + crm_copy_xml_element(action_rsc, rsc, PCMK_XA_TYPE); + crm_copy_xml_element(action_rsc, rsc, PCMK_XA_CLASS); + crm_copy_xml_element(action_rsc, rsc, PCMK_XA_PROVIDER); pcmk__create_history_xml(rsc, op, CRM_FEATURE_SET, target_rc, target, __func__); - rc = cib_conn->cmds->modify(cib_conn, XML_CIB_TAG_STATUS, state, + rc = cib_conn->cmds->modify(cib_conn, PCMK_XE_STATUS, state, cib_scope_local); fsa_register_cib_callback(rc, NULL, cib_action_updated); free_xml(state); @@ -313,8 +321,9 @@ controld_record_action_timeout(pcmk__graph_action_t *action) { lrmd_event_data_t *op = NULL; - const char *target = crm_element_value(action->xml, XML_LRM_ATTR_TARGET); - const char *task_uuid = crm_element_value(action->xml, XML_LRM_ATTR_TASK_KEY); + const char *target = crm_element_value(action->xml, PCMK__META_ON_NODE); + const char *task_uuid = crm_element_value(action->xml, + PCMK__XA_OPERATION_KEY); int target_rc = get_target_rc(action); @@ -362,17 +371,17 @@ execute_rsc_action(pcmk__graph_t *graph, pcmk__graph_action_t *action) CRM_ASSERT(action->xml != NULL); pcmk__clear_graph_action_flags(action, pcmk__graph_action_executed); - on_node = crm_element_value(action->xml, XML_LRM_ATTR_TARGET); + on_node = crm_element_value(action->xml, PCMK__META_ON_NODE); CRM_CHECK(!pcmk__str_empty(on_node), crm_err("Corrupted command(id=%s) %s: no node", - ID(action->xml), pcmk__s(task, "without task")); + pcmk__xe_id(action->xml), pcmk__s(task, "without task")); return pcmk_rc_node_unknown); rsc_op = action->xml; - task = crm_element_value(rsc_op, XML_LRM_ATTR_TASK); - task_uuid = crm_element_value(action->xml, XML_LRM_ATTR_TASK_KEY); - router_node = crm_element_value(rsc_op, XML_LRM_ATTR_ROUTER_NODE); + task = crm_element_value(rsc_op, PCMK_XA_OPERATION); + task_uuid = crm_element_value(action->xml, PCMK__XA_OPERATION_KEY); + router_node = crm_element_value(rsc_op, PCMK__XA_ROUTER_NODE); if (!router_node) { router_node = on_node; @@ -381,14 +390,14 @@ execute_rsc_action(pcmk__graph_t *graph, pcmk__graph_action_t *action) counter = pcmk__transition_key(controld_globals.transition_graph->id, action->id, get_target_rc(action), controld_globals.te_uuid); - crm_xml_add(rsc_op, XML_ATTR_TRANSITION_KEY, counter); + crm_xml_add(rsc_op, PCMK__XA_TRANSITION_KEY, counter); if (pcmk__str_eq(router_node, controld_globals.our_nodename, pcmk__str_casei)) { is_local = TRUE; } - value = crm_meta_value(action->params, XML_ATTR_TE_NOWAIT); + value = crm_meta_value(action->params, PCMK__META_OP_NO_WAIT); if (crm_is_true(value)) { no_wait = TRUE; } @@ -421,7 +430,11 @@ execute_rsc_action(pcmk__graph_t *graph, pcmk__graph_action_t *action) I_NULL, &msg); } else { - rc = send_cluster_message(crm_get_peer(0, router_node), crm_msg_lrmd, cmd, TRUE); + const crm_node_t *node = + pcmk__get_node(0, router_node, NULL, + pcmk__node_search_cluster_member); + + rc = pcmk__cluster_send_message(node, crm_msg_lrmd, cmd); } free(counter); @@ -500,8 +513,8 @@ te_update_job_count_on(const char *target, int offset, bool migrate) r = g_hash_table_lookup(te_targets, target); if(r == NULL) { - r = calloc(1, sizeof(struct te_peer_s)); - r->name = strdup(target); + r = pcmk__assert_alloc(1, sizeof(struct te_peer_s)); + r->name = pcmk__str_copy(target); g_hash_table_insert(te_targets, r->name, r); } @@ -515,8 +528,8 @@ te_update_job_count_on(const char *target, int offset, bool migrate) static void te_update_job_count(pcmk__graph_action_t *action, int offset) { - const char *task = crm_element_value(action->xml, XML_LRM_ATTR_TASK); - const char *target = crm_element_value(action->xml, XML_LRM_ATTR_TARGET); + const char *task = crm_element_value(action->xml, PCMK_XA_OPERATION); + const char *target = crm_element_value(action->xml, PCMK__META_ON_NODE); if ((action->type != pcmk__rsc_graph_action) || (target == NULL)) { /* No limit on these */ @@ -527,19 +540,22 @@ te_update_job_count(pcmk__graph_action_t *action, int offset) * on a remote node. For now, we count all actions occurring on a * remote node against the job list on the cluster node hosting * the connection resources */ - target = crm_element_value(action->xml, XML_LRM_ATTR_ROUTER_NODE); + target = crm_element_value(action->xml, PCMK__XA_ROUTER_NODE); if ((target == NULL) && pcmk__strcase_any_of(task, PCMK_ACTION_MIGRATE_TO, PCMK_ACTION_MIGRATE_FROM, NULL)) { - const char *t1 = crm_meta_value(action->params, XML_LRM_ATTR_MIGRATE_SOURCE); - const char *t2 = crm_meta_value(action->params, XML_LRM_ATTR_MIGRATE_TARGET); + + const char *t1 = crm_meta_value(action->params, + PCMK__META_MIGRATE_SOURCE); + const char *t2 = crm_meta_value(action->params, + PCMK__META_MIGRATE_TARGET); te_update_job_count_on(t1, offset, TRUE); te_update_job_count_on(t2, offset, TRUE); return; } else if (target == NULL) { - target = crm_element_value(action->xml, XML_LRM_ATTR_TARGET); + target = crm_element_value(action->xml, PCMK__META_ON_NODE); } te_update_job_count_on(target, offset, FALSE); @@ -561,8 +577,8 @@ allowed_on_node(const pcmk__graph_t *graph, const pcmk__graph_action_t *action, { int limit = 0; struct te_peer_s *r = NULL; - const char *task = crm_element_value(action->xml, XML_LRM_ATTR_TASK); - const char *id = crm_element_value(action->xml, XML_LRM_ATTR_TASK_KEY); + const char *task = crm_element_value(action->xml, PCMK_XA_OPERATION); + const char *id = crm_element_value(action->xml, PCMK__XA_OPERATION_KEY); if(target == NULL) { /* No limit on these */ @@ -576,8 +592,8 @@ allowed_on_node(const pcmk__graph_t *graph, const pcmk__graph_action_t *action, limit = throttle_get_job_limit(target); if(r == NULL) { - r = calloc(1, sizeof(struct te_peer_s)); - r->name = strdup(target); + r = pcmk__assert_alloc(1, sizeof(struct te_peer_s)); + r->name = pcmk__str_copy(target); g_hash_table_insert(te_targets, r->name, r); } @@ -613,7 +629,7 @@ static bool graph_action_allowed(pcmk__graph_t *graph, pcmk__graph_action_t *action) { const char *target = NULL; - const char *task = crm_element_value(action->xml, XML_LRM_ATTR_TASK); + const char *task = crm_element_value(action->xml, PCMK_XA_OPERATION); if (action->type != pcmk__rsc_graph_action) { /* No limit on these */ @@ -624,20 +640,20 @@ graph_action_allowed(pcmk__graph_t *graph, pcmk__graph_action_t *action) * on a remote node. For now, we count all actions occurring on a * remote node against the job list on the cluster node hosting * the connection resources */ - target = crm_element_value(action->xml, XML_LRM_ATTR_ROUTER_NODE); + target = crm_element_value(action->xml, PCMK__XA_ROUTER_NODE); if ((target == NULL) && pcmk__strcase_any_of(task, PCMK_ACTION_MIGRATE_TO, PCMK_ACTION_MIGRATE_FROM, NULL)) { - target = crm_meta_value(action->params, XML_LRM_ATTR_MIGRATE_SOURCE); + target = crm_meta_value(action->params, PCMK__META_MIGRATE_SOURCE); if (!allowed_on_node(graph, action, target)) { return false; } - target = crm_meta_value(action->params, XML_LRM_ATTR_MIGRATE_TARGET); + target = crm_meta_value(action->params, PCMK__META_MIGRATE_TARGET); } else if (target == NULL) { - target = crm_element_value(action->xml, XML_LRM_ATTR_TARGET); + target = crm_element_value(action->xml, PCMK__META_ON_NODE); } return allowed_on_node(graph, action, target); @@ -654,7 +670,7 @@ te_action_confirmed(pcmk__graph_action_t *action, pcmk__graph_t *graph) { if (!pcmk_is_set(action->flags, pcmk__graph_action_confirmed)) { if ((action->type == pcmk__rsc_graph_action) - && (crm_element_value(action->xml, XML_LRM_ATTR_TARGET) != NULL)) { + && (crm_element_value(action->xml, PCMK__META_ON_NODE) != NULL)) { te_update_job_count(action, -1); } pcmk__set_graph_action_flags(action, pcmk__graph_action_confirmed); diff --git a/daemons/controld/controld_te_callbacks.c b/daemons/controld/controld_te_callbacks.c index c26e757..901d44d 100644 --- a/daemons/controld/controld_te_callbacks.c +++ b/daemons/controld/controld_te_callbacks.c @@ -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. * @@ -14,23 +14,21 @@ #include <crm/crm.h> #include <crm/common/xml.h> #include <crm/common/xml_internal.h> -#include <crm/msg_xml.h> -#include <crm/cluster.h> /* For ONLINESTATUS etc */ #include <pacemaker-controld.h> void te_update_confirm(const char *event, xmlNode * msg); -#define RSC_OP_PREFIX "//" XML_TAG_DIFF_ADDED "//" XML_TAG_CIB \ - "//" XML_LRM_TAG_RSC_OP "[@" XML_ATTR_ID "='" +#define RSC_OP_PREFIX "//" PCMK__XE_DIFF_ADDED "//" PCMK_XE_CIB \ + "//" PCMK__XE_LRM_RSC_OP "[@" PCMK_XA_ID "='" -// An explicit shutdown-lock of 0 means the lock has been cleared +// An explicit PCMK_OPT_SHUTDOWN_LOCK of 0 means the lock has been cleared static bool shutdown_lock_cleared(xmlNode *lrm_resource) { time_t shutdown_lock = 0; - return (crm_element_value_epoch(lrm_resource, XML_CONFIG_ATTR_SHUTDOWN_LOCK, + return (crm_element_value_epoch(lrm_resource, PCMK_OPT_SHUTDOWN_LOCK, &shutdown_lock) == pcmk_ok) && (shutdown_lock == 0); } @@ -49,19 +47,21 @@ te_update_diff_v1(const char *event, xmlNode *diff) "xml-patchset", diff); if (cib__config_changed_v1(NULL, NULL, &diff)) { - abort_transition(INFINITY, pcmk__graph_restart, "Non-status change", - diff); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, + "Non-status change", diff); goto bail; /* configuration changed */ } /* Tickets Attributes - Added/Updated */ xpathObj = xpath_search(diff, - "//" F_CIB_UPDATE_RESULT "//" XML_TAG_DIFF_ADDED "//" XML_CIB_TAG_TICKETS); + "//" PCMK__XE_CIB_UPDATE_RESULT + "//" PCMK__XE_DIFF_ADDED + "//" PCMK_XE_TICKETS); if (numXpathResults(xpathObj) > 0) { xmlNode *aborted = getXpathResult(xpathObj, 0); - abort_transition(INFINITY, pcmk__graph_restart, + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, "Ticket attribute: update", aborted); goto bail; @@ -71,11 +71,13 @@ te_update_diff_v1(const char *event, xmlNode *diff) /* Tickets Attributes - Removed */ xpathObj = xpath_search(diff, - "//" F_CIB_UPDATE_RESULT "//" XML_TAG_DIFF_REMOVED "//" XML_CIB_TAG_TICKETS); + "//" PCMK__XE_CIB_UPDATE_RESULT + "//" PCMK__XE_DIFF_REMOVED + "//" PCMK_XE_TICKETS); if (numXpathResults(xpathObj) > 0) { xmlNode *aborted = getXpathResult(xpathObj, 0); - abort_transition(INFINITY, pcmk__graph_restart, + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, "Ticket attribute: removal", aborted); goto bail; } @@ -84,23 +86,24 @@ te_update_diff_v1(const char *event, xmlNode *diff) /* Transient Attributes - Removed */ xpathObj = xpath_search(diff, - "//" F_CIB_UPDATE_RESULT "//" XML_TAG_DIFF_REMOVED "//" - XML_TAG_TRANSIENT_NODEATTRS); + "//" PCMK__XE_CIB_UPDATE_RESULT + "//" PCMK__XE_DIFF_REMOVED + "//" PCMK__XE_TRANSIENT_ATTRIBUTES); if (numXpathResults(xpathObj) > 0) { xmlNode *aborted = getXpathResult(xpathObj, 0); - abort_transition(INFINITY, pcmk__graph_restart, + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, "Transient attribute: removal", aborted); goto bail; } freeXpathObject(xpathObj); - // Check for lrm_resource entries + // Check for PCMK__XE_LRM_RESOURCE entries xpathObj = xpath_search(diff, - "//" F_CIB_UPDATE_RESULT - "//" XML_TAG_DIFF_ADDED - "//" XML_LRM_TAG_RESOURCE); + "//" PCMK__XE_CIB_UPDATE_RESULT + "//" PCMK__XE_DIFF_ADDED + "//" PCMK__XE_LRM_RESOURCE); max = numXpathResults(xpathObj); /* @@ -117,8 +120,8 @@ te_update_diff_v1(const char *event, xmlNode *diff) crm_debug("Ignoring resource operation updates due to history refresh of %d resources", max); crm_log_xml_trace(diff, "lrm-refresh"); - abort_transition(INFINITY, pcmk__graph_restart, "History refresh", - NULL); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, + "History refresh", NULL); goto bail; } @@ -127,7 +130,7 @@ te_update_diff_v1(const char *event, xmlNode *diff) if (shutdown_lock_cleared(lrm_resource)) { // @TODO would be more efficient to abort once after transition done - abort_transition(INFINITY, pcmk__graph_restart, + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, "Shutdown lock cleared", lrm_resource); // Still process results, so we stop timers and update failcounts } @@ -137,7 +140,9 @@ te_update_diff_v1(const char *event, xmlNode *diff) /* Process operation updates */ xpathObj = xpath_search(diff, - "//" F_CIB_UPDATE_RESULT "//" XML_TAG_DIFF_ADDED "//" XML_LRM_TAG_RSC_OP); + "//" PCMK__XE_CIB_UPDATE_RESULT + "//" PCMK__XE_DIFF_ADDED + "//" PCMK__XE_LRM_RSC_OP); max = numXpathResults(xpathObj); if (max > 0) { int lpc = 0; @@ -152,7 +157,9 @@ te_update_diff_v1(const char *event, xmlNode *diff) freeXpathObject(xpathObj); /* Detect deleted (as opposed to replaced or added) actions - eg. crm_resource -C */ - xpathObj = xpath_search(diff, "//" XML_TAG_DIFF_REMOVED "//" XML_LRM_TAG_RSC_OP); + xpathObj = xpath_search(diff, + "//" PCMK__XE_DIFF_REMOVED + "//" PCMK__XE_LRM_RSC_OP); max = numXpathResults(xpathObj); for (lpc = 0; lpc < max; lpc++) { const char *op_id = NULL; @@ -162,7 +169,7 @@ te_update_diff_v1(const char *event, xmlNode *diff) CRM_LOG_ASSERT(match != NULL); if(match == NULL) { continue; }; - op_id = ID(match); + op_id = pcmk__xe_id(match); if (rsc_op_xpath == NULL) { rsc_op_xpath = g_string_new(RSC_OP_PREFIX); @@ -180,13 +187,14 @@ te_update_diff_v1(const char *event, xmlNode *diff) if (cancelled == NULL) { crm_debug("No match for deleted action %s (%s on %s)", (const char *) rsc_op_xpath->str, op_id, node); - abort_transition(INFINITY, pcmk__graph_restart, + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, "Resource op removal", match); freeXpathObject(op_match); goto bail; } else { - crm_debug("Deleted lrm_rsc_op %s on %s was for graph event %d", + crm_debug("Deleted " PCMK__XE_LRM_RSC_OP " %s on %s was for " + "graph event %d", op_id, node, cancelled->id); } } @@ -204,14 +212,14 @@ te_update_diff_v1(const char *event, xmlNode *diff) static void process_lrm_resource_diff(xmlNode *lrm_resource, const char *node) { - for (xmlNode *rsc_op = pcmk__xml_first_child(lrm_resource); rsc_op != NULL; - rsc_op = pcmk__xml_next(rsc_op)) { + for (xmlNode *rsc_op = pcmk__xe_first_child(lrm_resource, NULL, NULL, NULL); + rsc_op != NULL; rsc_op = pcmk__xe_next(rsc_op)) { process_graph_event(rsc_op, node); } if (shutdown_lock_cleared(lrm_resource)) { // @TODO would be more efficient to abort once after transition done - abort_transition(INFINITY, pcmk__graph_restart, "Shutdown lock cleared", - lrm_resource); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, + "Shutdown lock cleared", lrm_resource); } } @@ -225,12 +233,12 @@ process_resource_updates(const char *node, xmlNode *xml, xmlNode *change, return; } - if (pcmk__xe_is(xml, XML_CIB_TAG_LRM)) { - xml = first_named_child(xml, XML_LRM_TAG_RESOURCES); + if (pcmk__xe_is(xml, PCMK__XE_LRM)) { + xml = pcmk__xe_first_child(xml, PCMK__XE_LRM_RESOURCES, NULL, NULL); CRM_CHECK(xml != NULL, return); } - CRM_CHECK(pcmk__xe_is(xml, XML_LRM_TAG_RESOURCES), return); + CRM_CHECK(pcmk__xe_is(xml, PCMK__XE_LRM_RESOURCES), return); /* * Updates by, or in response to, TE actions will never contain updates @@ -248,31 +256,31 @@ process_resource_updates(const char *node, xmlNode *xml, xmlNode *change, && (xml->children != NULL) && (xml->children->next != NULL)) { crm_log_xml_trace(change, "lrm-refresh"); - abort_transition(INFINITY, pcmk__graph_restart, "History refresh", - NULL); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, + "History refresh", NULL); return; } - for (rsc = pcmk__xml_first_child(xml); rsc != NULL; - rsc = pcmk__xml_next(rsc)) { - crm_trace("Processing %s", ID(rsc)); + for (rsc = pcmk__xe_first_child(xml, NULL, NULL, NULL); rsc != NULL; + rsc = pcmk__xe_next(rsc)) { + crm_trace("Processing %s", pcmk__xe_id(rsc)); process_lrm_resource_diff(rsc, node); } } static char *extract_node_uuid(const char *xpath) { - char *mutable_path = strdup(xpath); + char *mutable_path = pcmk__str_copy(xpath); char *node_uuid = NULL; char *search = NULL; char *match = NULL; - match = strstr(mutable_path, "node_state[@" XML_ATTR_ID "=\'"); + match = strstr(mutable_path, PCMK__XE_NODE_STATE "[@" PCMK_XA_ID "=\'"); if (match == NULL) { free(mutable_path); return NULL; } - match += strlen("node_state[@" XML_ATTR_ID "=\'"); + match += strlen(PCMK__XE_NODE_STATE "[@" PCMK_XA_ID "=\'"); search = strchr(match, '\''); if (search == NULL) { @@ -281,7 +289,7 @@ static char *extract_node_uuid(const char *xpath) } search[0] = 0; - node_uuid = strdup(match); + node_uuid = pcmk__str_copy(match); free(mutable_path); return node_uuid; } @@ -293,22 +301,25 @@ abort_unless_down(const char *xpath, const char *op, xmlNode *change, char *node_uuid = NULL; pcmk__graph_action_t *down = NULL; - if(!pcmk__str_eq(op, "delete", pcmk__str_casei)) { - abort_transition(INFINITY, pcmk__graph_restart, reason, change); + if (!pcmk__str_eq(op, PCMK_VALUE_DELETE, pcmk__str_none)) { + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, reason, + change); return; } node_uuid = extract_node_uuid(xpath); if(node_uuid == NULL) { crm_err("Could not extract node ID from %s", xpath); - abort_transition(INFINITY, pcmk__graph_restart, reason, change); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, reason, + change); return; } down = match_down_event(node_uuid); if (down == NULL) { crm_trace("Not expecting %s to be down (%s)", node_uuid, xpath); - abort_transition(INFINITY, pcmk__graph_restart, reason, change); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, reason, + change); } else { crm_trace("Expecting changes to %s (%s)", node_uuid, xpath); } @@ -318,7 +329,7 @@ abort_unless_down(const char *xpath, const char *op, xmlNode *change, static void process_op_deletion(const char *xpath, xmlNode *change) { - char *mutable_key = strdup(xpath); + char *mutable_key = pcmk__str_copy(xpath); char *key; char *node_uuid; @@ -338,7 +349,7 @@ process_op_deletion(const char *xpath, xmlNode *change) node_uuid = extract_node_uuid(xpath); if (confirm_cancel_action(key, node_uuid) == FALSE) { - abort_transition(INFINITY, pcmk__graph_restart, + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, "Resource operation removal", change); } free(mutable_key); @@ -348,13 +359,13 @@ process_op_deletion(const char *xpath, xmlNode *change) static void process_delete_diff(const char *xpath, const char *op, xmlNode *change) { - if (strstr(xpath, "/" XML_LRM_TAG_RSC_OP "[")) { + if (strstr(xpath, "/" PCMK__XE_LRM_RSC_OP "[")) { process_op_deletion(xpath, change); - } else if (strstr(xpath, "/" XML_CIB_TAG_LRM "[")) { + } else if (strstr(xpath, "/" PCMK__XE_LRM "[")) { abort_unless_down(xpath, op, change, "Resource state removal"); - } else if (strstr(xpath, "/" XML_CIB_TAG_STATE "[")) { + } else if (strstr(xpath, "/" PCMK__XE_NODE_STATE "[")) { abort_unless_down(xpath, op, change, "Node state removal"); } else { @@ -366,17 +377,18 @@ static void process_node_state_diff(xmlNode *state, xmlNode *change, const char *op, const char *xpath) { - xmlNode *lrm = first_named_child(state, XML_CIB_TAG_LRM); + xmlNode *lrm = pcmk__xe_first_child(state, PCMK__XE_LRM, NULL, NULL); - process_resource_updates(ID(state), lrm, change, op, xpath); + process_resource_updates(pcmk__xe_id(state), lrm, change, op, xpath); } static void process_status_diff(xmlNode *status, xmlNode *change, const char *op, const char *xpath) { - for (xmlNode *state = pcmk__xml_first_child(status); state != NULL; - state = pcmk__xml_next(state)) { + for (xmlNode *state = pcmk__xe_first_child(status, NULL, NULL, NULL); + state != NULL; state = pcmk__xe_next(state)) { + process_node_state_diff(state, change, op, xpath); } } @@ -385,144 +397,152 @@ static void process_cib_diff(xmlNode *cib, xmlNode *change, const char *op, const char *xpath) { - xmlNode *status = first_named_child(cib, XML_CIB_TAG_STATUS); - xmlNode *config = first_named_child(cib, XML_CIB_TAG_CONFIGURATION); + xmlNode *status = pcmk__xe_first_child(cib, PCMK_XE_STATUS, NULL, NULL); + xmlNode *config = pcmk__xe_first_child(cib, PCMK_XE_CONFIGURATION, NULL, + NULL); if (status) { process_status_diff(status, change, op, xpath); } if (config) { - abort_transition(INFINITY, pcmk__graph_restart, + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, "Non-status-only change", change); } } -static void -te_update_diff_v2(xmlNode *diff) +static int +te_update_diff_element_v2(xmlNode *change, void *userdata) { - crm_log_xml_trace(diff, "Patch:Raw"); - - for (xmlNode *change = pcmk__xml_first_child(diff); change != NULL; - change = pcmk__xml_next(change)) { - - xmlNode *match = NULL; - const char *name = NULL; - const char *xpath = crm_element_value(change, XML_DIFF_PATH); - - // Possible ops: create, modify, delete, move - const char *op = crm_element_value(change, XML_DIFF_OP); - - // Ignore uninteresting updates - if (op == NULL) { - continue; - - } else if (xpath == NULL) { - crm_trace("Ignoring %s change for version field", op); - continue; - - } else if ((strcmp(op, "move") == 0) - && (strstr(xpath, - "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION - "/" XML_CIB_TAG_RESOURCES) == NULL)) { - /* We still need to consider moves within the resources section, - * since they affect placement order. - */ - crm_trace("Ignoring move change at %s", xpath); - continue; + xmlNode *match = NULL; + const char *name = NULL; + const char *xpath = crm_element_value(change, PCMK_XA_PATH); + + // Possible ops: create, modify, delete, move + const char *op = crm_element_value(change, PCMK_XA_OPERATION); + + // Ignore uninteresting updates + if (op == NULL) { + return pcmk_rc_ok; + + } else if (xpath == NULL) { + crm_trace("Ignoring %s change for version field", op); + return pcmk_rc_ok; + + } else if ((strcmp(op, PCMK_VALUE_MOVE) == 0) + && (strstr(xpath, + "/" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION + "/" PCMK_XE_RESOURCES) == NULL)) { + /* We still need to consider moves within the resources section, + * since they affect placement order. + */ + crm_trace("Ignoring move change at %s", xpath); + return pcmk_rc_ok; + } + + // Find the result of create/modify ops + if (strcmp(op, PCMK_VALUE_CREATE) == 0) { + match = change->children; + + } else if (strcmp(op, PCMK_VALUE_MODIFY) == 0) { + match = pcmk__xe_first_child(change, PCMK_XE_CHANGE_RESULT, NULL, NULL); + if(match) { + match = match->children; } - // Find the result of create/modify ops - if (strcmp(op, "create") == 0) { - match = change->children; - - } else if (strcmp(op, "modify") == 0) { - match = first_named_child(change, XML_DIFF_RESULT); - if(match) { - match = match->children; - } - - } else if (!pcmk__str_any_of(op, "delete", "move", NULL)) { - crm_warn("Ignoring malformed CIB update (%s operation on %s is unrecognized)", - op, xpath); - continue; - } + } else if (!pcmk__str_any_of(op, + PCMK_VALUE_DELETE, PCMK_VALUE_MOVE, + NULL)) { + crm_warn("Ignoring malformed CIB update (%s operation on %s is unrecognized)", + op, xpath); + return pcmk_rc_ok; + } - if (match) { - if (match->type == XML_COMMENT_NODE) { - crm_trace("Ignoring %s operation for comment at %s", op, xpath); - continue; - } - name = (const char *)match->name; + if (match) { + if (match->type == XML_COMMENT_NODE) { + crm_trace("Ignoring %s operation for comment at %s", op, xpath); + return pcmk_rc_ok; } + name = (const char *)match->name; + } - crm_trace("Handling %s operation for %s%s%s", - op, (xpath? xpath : "CIB"), - (name? " matched by " : ""), (name? name : "")); + crm_trace("Handling %s operation for %s%s%s", + op, (xpath? xpath : "CIB"), + (name? " matched by " : ""), (name? name : "")); - if (strstr(xpath, "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION)) { - abort_transition(INFINITY, pcmk__graph_restart, - "Configuration change", change); - break; // Won't be packaged with operation results we may be waiting for + if (strstr(xpath, "/" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION)) { + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, + "Configuration change", change); + return pcmk_rc_cib_modified; // Won't be packaged with operation results we may be waiting for - } else if (strstr(xpath, "/" XML_CIB_TAG_TICKETS) - || pcmk__str_eq(name, XML_CIB_TAG_TICKETS, pcmk__str_none)) { - abort_transition(INFINITY, pcmk__graph_restart, - "Ticket attribute change", change); - break; // Won't be packaged with operation results we may be waiting for + } else if (strstr(xpath, "/" PCMK_XE_TICKETS) + || pcmk__str_eq(name, PCMK_XE_TICKETS, pcmk__str_none)) { + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, + "Ticket attribute change", change); + return pcmk_rc_cib_modified; // Won't be packaged with operation results we may be waiting for - } else if (strstr(xpath, "/" XML_TAG_TRANSIENT_NODEATTRS "[") - || pcmk__str_eq(name, XML_TAG_TRANSIENT_NODEATTRS, - pcmk__str_none)) { - abort_unless_down(xpath, op, change, "Transient attribute change"); - break; // Won't be packaged with operation results we may be waiting for + } else if (strstr(xpath, "/" PCMK__XE_TRANSIENT_ATTRIBUTES "[") + || pcmk__str_eq(name, PCMK__XE_TRANSIENT_ATTRIBUTES, + pcmk__str_none)) { + abort_unless_down(xpath, op, change, "Transient attribute change"); + return pcmk_rc_cib_modified; // Won't be packaged with operation results we may be waiting for - } else if (strcmp(op, "delete") == 0) { - process_delete_diff(xpath, op, change); + } else if (strcmp(op, PCMK_VALUE_DELETE) == 0) { + process_delete_diff(xpath, op, change); - } else if (name == NULL) { - crm_warn("Ignoring malformed CIB update (%s at %s has no result)", - op, xpath); + } else if (name == NULL) { + crm_warn("Ignoring malformed CIB update (%s at %s has no result)", + op, xpath); - } else if (strcmp(name, XML_TAG_CIB) == 0) { - process_cib_diff(match, change, op, xpath); + } else if (strcmp(name, PCMK_XE_CIB) == 0) { + process_cib_diff(match, change, op, xpath); - } else if (strcmp(name, XML_CIB_TAG_STATUS) == 0) { - process_status_diff(match, change, op, xpath); + } else if (strcmp(name, PCMK_XE_STATUS) == 0) { + process_status_diff(match, change, op, xpath); - } else if (strcmp(name, XML_CIB_TAG_STATE) == 0) { - process_node_state_diff(match, change, op, xpath); + } else if (strcmp(name, PCMK__XE_NODE_STATE) == 0) { + process_node_state_diff(match, change, op, xpath); - } else if (strcmp(name, XML_CIB_TAG_LRM) == 0) { - process_resource_updates(ID(match), match, change, op, xpath); + } else if (strcmp(name, PCMK__XE_LRM) == 0) { + process_resource_updates(pcmk__xe_id(match), match, change, op, + xpath); - } else if (strcmp(name, XML_LRM_TAG_RESOURCES) == 0) { - char *local_node = pcmk__xpath_node_id(xpath, "lrm"); + } else if (strcmp(name, PCMK__XE_LRM_RESOURCES) == 0) { + char *local_node = pcmk__xpath_node_id(xpath, PCMK__XE_LRM); - process_resource_updates(local_node, match, change, op, xpath); - free(local_node); + process_resource_updates(local_node, match, change, op, xpath); + free(local_node); - } else if (strcmp(name, XML_LRM_TAG_RESOURCE) == 0) { - char *local_node = pcmk__xpath_node_id(xpath, "lrm"); + } else if (strcmp(name, PCMK__XE_LRM_RESOURCE) == 0) { + char *local_node = pcmk__xpath_node_id(xpath, PCMK__XE_LRM); - process_lrm_resource_diff(match, local_node); - free(local_node); + process_lrm_resource_diff(match, local_node); + free(local_node); - } else if (strcmp(name, XML_LRM_TAG_RSC_OP) == 0) { - char *local_node = pcmk__xpath_node_id(xpath, "lrm"); + } else if (strcmp(name, PCMK__XE_LRM_RSC_OP) == 0) { + char *local_node = pcmk__xpath_node_id(xpath, PCMK__XE_LRM); - process_graph_event(match, local_node); - free(local_node); + process_graph_event(match, local_node); + free(local_node); - } else { - crm_warn("Ignoring malformed CIB update (%s at %s has unrecognized result %s)", - op, xpath, name); - } + } else { + crm_warn("Ignoring malformed CIB update (%s at %s has unrecognized result %s)", + op, xpath, name); } + + return pcmk_rc_ok; +} + +static void +te_update_diff_v2(xmlNode *diff) +{ + crm_log_xml_trace(diff, "Patch:Raw"); + pcmk__xe_foreach_child(diff, NULL, te_update_diff_element_v2, NULL); } void te_update_diff(const char *event, xmlNode * msg) { + xmlNode *wrapper = NULL; xmlNode *diff = NULL; const char *op = NULL; int rc = -EINVAL; @@ -531,7 +551,7 @@ te_update_diff(const char *event, xmlNode * msg) int p_del[] = { 0, 0, 0 }; CRM_CHECK(msg != NULL, return); - crm_element_value_int(msg, F_CIB_RC, &rc); + crm_element_value_int(msg, PCMK__XA_CIB_RC, &rc); if (controld_globals.transition_graph == NULL) { crm_trace("No graph"); @@ -550,8 +570,10 @@ te_update_diff(const char *event, xmlNode * msg) return; } - op = crm_element_value(msg, F_CIB_OPERATION); - diff = get_message_xml(msg, F_CIB_UPDATE_RESULT); + op = crm_element_value(msg, PCMK__XA_CIB_OP); + + wrapper = pcmk__xe_first_child(msg, PCMK__XE_CIB_UPDATE_RESULT, NULL, NULL); + diff = pcmk__xe_first_child(wrapper, NULL, NULL, NULL); xml_patch_versions(diff, p_add, p_del); crm_debug("Processing (%s) diff: %d.%d.%d -> %d.%d.%d (%s)", op, @@ -583,7 +605,7 @@ process_te_message(xmlNode * msg, xmlNode * xml_data) CRM_CHECK(msg != NULL, return); // Transition requests must specify transition engine as subsystem - value = crm_element_value(msg, F_CRM_SYS_TO); + value = crm_element_value(msg, PCMK__XA_CRM_SYS_TO); if (pcmk__str_empty(value) || !pcmk__str_eq(value, CRM_SYSTEM_TENGINE, pcmk__str_none)) { crm_info("Received invalid transition request: subsystem '%s' not '" @@ -592,7 +614,7 @@ process_te_message(xmlNode * msg, xmlNode * xml_data) } // Only the lrm_invoke command is supported as a transition request - value = crm_element_value(msg, F_CRM_TASK); + value = crm_element_value(msg, PCMK__XA_CRM_TASK); if (!pcmk__str_eq(value, CRM_OP_INVOKE_LRM, pcmk__str_none)) { crm_info("Received invalid transition request: command '%s' not '" CRM_OP_INVOKE_LRM "'", pcmk__s(value, "")); @@ -600,7 +622,7 @@ process_te_message(xmlNode * msg, xmlNode * xml_data) } // Transition requests must be marked as coming from the executor - value = crm_element_value(msg, F_CRM_SYS_FROM); + value = crm_element_value(msg, PCMK__XA_CRM_SYS_FROM); if (!pcmk__str_eq(value, CRM_SYSTEM_LRMD, pcmk__str_none)) { crm_info("Received invalid transition request: from '%s' not '" CRM_SYSTEM_LRMD "'", pcmk__s(value, "")); @@ -608,10 +630,10 @@ process_te_message(xmlNode * msg, xmlNode * xml_data) } crm_debug("Processing transition request with ref='%s' origin='%s'", - pcmk__s(crm_element_value(msg, F_CRM_REFERENCE), ""), - pcmk__s(crm_element_value(msg, F_ORIG), "")); + pcmk__s(crm_element_value(msg, PCMK_XA_REFERENCE), ""), + pcmk__s(crm_element_value(msg, PCMK__XA_SRC), "")); - xpathObj = xpath_search(xml_data, "//" XML_LRM_TAG_RSC_OP); + xpathObj = xpath_search(xml_data, "//" PCMK__XE_LRM_RSC_OP); nmatches = numXpathResults(xpathObj); if (nmatches == 0) { crm_err("Received transition request with no results (bug?)"); @@ -653,9 +675,9 @@ action_timer_callback(gpointer data) stop_te_timer(action); - task = crm_element_value(action->xml, XML_LRM_ATTR_TASK); - on_node = crm_element_value(action->xml, XML_LRM_ATTR_TARGET); - via_node = crm_element_value(action->xml, XML_LRM_ATTR_ROUTER_NODE); + task = crm_element_value(action->xml, PCMK_XA_OPERATION); + on_node = crm_element_value(action->xml, PCMK__META_ON_NODE); + via_node = crm_element_value(action->xml, PCMK__XA_ROUTER_NODE); if (controld_globals.transition_graph->complete) { crm_notice("Node %s did not send %s result (via %s) within %dms " @@ -666,7 +688,7 @@ action_timer_callback(gpointer data) /* fail the action */ crm_err("Node %s did not send %s result (via %s) within %dms " - "(action timeout plus cluster-delay)", + "(action timeout plus " PCMK_OPT_CLUSTER_DELAY ")", (on_node? on_node : ""), (task? task : "unknown action"), (via_node? via_node : "controller"), (action->timeout @@ -676,7 +698,8 @@ action_timer_callback(gpointer data) pcmk__set_graph_action_flags(action, pcmk__graph_action_failed); te_action_confirmed(action, controld_globals.transition_graph); - abort_transition(INFINITY, pcmk__graph_restart, "Action lost", NULL); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, + "Action lost", NULL); // Record timeout in the CIB if appropriate if ((action->type == pcmk__rsc_graph_action) diff --git a/daemons/controld/controld_te_events.c b/daemons/controld/controld_te_events.c index 28977c0..49c09f6 100644 --- a/daemons/controld/controld_te_events.c +++ b/daemons/controld/controld_te_events.c @@ -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. * @@ -12,12 +12,11 @@ #include <sys/param.h> #include <crm/crm.h> #include <crm/cib.h> -#include <crm/msg_xml.h> #include <crm/common/xml.h> #include <pacemaker-controld.h> -#include <crm/common/attrd_internal.h> +#include <crm/common/attrs_internal.h> #include <crm/common/ipc_attrd_internal.h> /*! @@ -109,17 +108,22 @@ fail_incompletable_actions(pcmk__graph_t *graph, const char *down_node) || pcmk_is_set(action->flags, pcmk__graph_action_confirmed)) { continue; } else if (action->type == pcmk__cluster_graph_action) { - const char *task = crm_element_value(action->xml, XML_LRM_ATTR_TASK); + const char *task = crm_element_value(action->xml, + PCMK_XA_OPERATION); if (pcmk__str_eq(task, PCMK_ACTION_STONITH, pcmk__str_casei)) { continue; } } - target_uuid = crm_element_value(action->xml, XML_LRM_ATTR_TARGET_UUID); - router = crm_element_value(action->xml, XML_LRM_ATTR_ROUTER_NODE); + target_uuid = crm_element_value(action->xml, + PCMK__META_ON_NODE_UUID); + router = crm_element_value(action->xml, PCMK__XA_ROUTER_NODE); if (router) { - crm_node_t *node = crm_get_peer(0, router); + const crm_node_t *node = + pcmk__get_node(0, router, NULL, + pcmk__node_search_cluster_member); + if (node) { router_uuid = node->uuid; } @@ -134,10 +138,15 @@ fail_incompletable_actions(pcmk__graph_t *graph, const char *down_node) if (pcmk_is_set(synapse->flags, pcmk__synapse_executed)) { crm_notice("Action %d (%s) was pending on %s (offline)", - action->id, crm_element_value(action->xml, XML_LRM_ATTR_TASK_KEY), down_node); + action->id, + crm_element_value(action->xml, + PCMK__XA_OPERATION_KEY), + down_node); } else { crm_info("Action %d (%s) is scheduled for %s (offline)", - action->id, crm_element_value(action->xml, XML_LRM_ATTR_TASK_KEY), down_node); + action->id, + crm_element_value(action->xml, PCMK__XA_OPERATION_KEY), + down_node); } } } @@ -145,8 +154,8 @@ fail_incompletable_actions(pcmk__graph_t *graph, const char *down_node) if (last_action != NULL) { crm_info("Node %s shutdown resulted in un-runnable actions", down_node); - abort_transition(INFINITY, pcmk__graph_restart, "Node failure", - last_action); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, + "Node failure", last_action); return TRUE; } @@ -176,9 +185,9 @@ update_failcount(const xmlNode *event, const char *event_node_uuid, int rc, char *rsc_id = NULL; const char *value = NULL; - const char *id = crm_element_value(event, XML_LRM_ATTR_TASK_KEY); - const char *on_uname = crm_peer_uname(event_node_uuid); - const char *origin = crm_element_value(event, XML_ATTR_ORIGIN); + const char *id = crm_element_value(event, PCMK__XA_OPERATION_KEY); + const char *on_uname = pcmk__node_name_from_uuid(event_node_uuid); + const char *origin = crm_element_value(event, PCMK_XA_CRM_DEBUG_ORIGIN); // Nothing needs to be done for success or status refresh if (rc == target_rc) { @@ -192,7 +201,7 @@ update_failcount(const xmlNode *event, const char *event_node_uuid, int rc, /* Sanity check */ CRM_CHECK(on_uname != NULL, return TRUE); CRM_CHECK(parse_op_key(id, &rsc_id, &task, &interval_ms), - crm_err("Couldn't parse: %s", ID(event)); goto bail); + crm_err("Couldn't parse: %s", pcmk__xe_id(event)); goto bail); /* Decide whether update is necessary and what value to use */ if ((interval_ms > 0) @@ -203,12 +212,12 @@ update_failcount(const xmlNode *event, const char *event_node_uuid, int rc, } else if (pcmk__str_eq(task, PCMK_ACTION_START, pcmk__str_none)) { do_update = TRUE; value = pcmk__s(controld_globals.transition_graph->failed_start_offset, - CRM_INFINITY_S); + PCMK_VALUE_INFINITY); } else if (pcmk__str_eq(task, PCMK_ACTION_STOP, pcmk__str_none)) { do_update = TRUE; value = pcmk__s(controld_globals.transition_graph->failed_stop_offset, - CRM_INFINITY_S); + PCMK_VALUE_INFINITY); } if (do_update) { @@ -224,7 +233,7 @@ update_failcount(const xmlNode *event, const char *event_node_uuid, int rc, // Fail count will be either incremented or set to infinity if (!pcmk_str_is_infinity(value)) { - value = XML_NVPAIR_ATTR_VALUE "++"; + value = PCMK_XA_VALUE "++"; } if (g_hash_table_lookup(crm_remote_peer_cache, event_node_uuid)) { @@ -237,8 +246,7 @@ update_failcount(const xmlNode *event, const char *event_node_uuid, int rc, /* Update the fail count, if we're not ignoring failures */ if (!ignore_failures) { - fail_pair = calloc(1, sizeof(pcmk__attrd_query_pair_t)); - CRM_ASSERT(fail_pair != NULL); + fail_pair = pcmk__assert_alloc(1, sizeof(pcmk__attrd_query_pair_t)); fail_name = pcmk__failcount_name(rsc_id, task, interval_ms); fail_pair->name = fail_name; @@ -251,8 +259,7 @@ update_failcount(const xmlNode *event, const char *event_node_uuid, int rc, /* Update the last failure time (even if we're ignoring failures, * so that failure can still be detected and shown, e.g. by crm_mon) */ - last_pair = calloc(1, sizeof(pcmk__attrd_query_pair_t)); - CRM_ASSERT(last_pair != NULL); + last_pair = pcmk__assert_alloc(1, sizeof(pcmk__attrd_query_pair_t)); last_name = pcmk__lastfailure_name(rsc_id, task, interval_ms); last_pair->name = last_name; @@ -313,18 +320,18 @@ get_cancel_action(const char *id, const char *node) const char *target = NULL; pcmk__graph_action_t *action = (pcmk__graph_action_t *) gIter2->data; - task = crm_element_value(action->xml, XML_LRM_ATTR_TASK); + task = crm_element_value(action->xml, PCMK_XA_OPERATION); if (!pcmk__str_eq(PCMK_ACTION_CANCEL, task, pcmk__str_casei)) { continue; } - task = crm_element_value(action->xml, XML_LRM_ATTR_TASK_KEY); + task = crm_element_value(action->xml, PCMK__XA_OPERATION_KEY); if (!pcmk__str_eq(task, id, pcmk__str_casei)) { crm_trace("Wrong key %s for %s on %s", task, id, node); continue; } - target = crm_element_value(action->xml, XML_LRM_ATTR_TARGET_UUID); + target = crm_element_value(action->xml, PCMK__META_ON_NODE_UUID); if (node && !pcmk__str_eq(target, node, pcmk__str_casei)) { crm_trace("Wrong node %s for %s on %s", target, id, node); continue; @@ -348,8 +355,8 @@ confirm_cancel_action(const char *id, const char *node_id) if (cancel == NULL) { return FALSE; } - op_key = crm_element_value(cancel->xml, XML_LRM_ATTR_TASK_KEY); - node_name = crm_element_value(cancel->xml, XML_LRM_ATTR_TARGET); + op_key = crm_element_value(cancel->xml, PCMK__XA_OPERATION_KEY); + node_name = crm_element_value(cancel->xml, PCMK__META_ON_NODE); stop_te_timer(cancel); te_action_confirmed(cancel, controld_globals.transition_graph); @@ -360,8 +367,8 @@ confirm_cancel_action(const char *id, const char *node_id) } /* downed nodes are listed like: <downed> <node id="UUID1" /> ... </downed> */ -#define XPATH_DOWNED "//" XML_GRAPH_TAG_DOWNED \ - "/" XML_CIB_TAG_NODE "[@" XML_ATTR_ID "='%s']" +#define XPATH_DOWNED "//" PCMK__XE_DOWNED \ + "/" PCMK_XE_NODE "[@" PCMK_XA_ID "='%s']" /*! * \brief Find a transition event that would have made a specified node down @@ -405,7 +412,8 @@ match_down_event(const char *target) if (match != NULL) { crm_debug("Shutdown action %d (%s) found for node %s", match->id, - crm_element_value(match->xml, XML_LRM_ATTR_TASK_KEY), target); + crm_element_value(match->xml, PCMK__XA_OPERATION_KEY), + target); } else { crm_debug("No reason to expect node %s to be down", target); } @@ -434,20 +442,20 @@ process_graph_event(xmlNode *event, const char *event_node) <lrm_rsc_op id="rsc_east-05_last_0" operation_key="rsc_east-05_monitor_0" operation="monitor" crm-debug-origin="do_update_resource" crm_feature_set="3.0.6" transition-key="9:2:7:be2e97d9-05e2-439d-863e-48f7aecab2aa" transition-magic="0:7;9:2:7:be2e97d9-05e2-439d-863e-48f7aecab2aa" call-id="17" rc-code="7" op-status="0" interval="0" last-rc-change="1355361636" exec-time="128" queue-time="0" op-digest="c81f5f40b1c9e859c992e800b1aa6972"/> */ - magic = crm_element_value(event, XML_ATTR_TRANSITION_KEY); + magic = crm_element_value(event, PCMK__XA_TRANSITION_KEY); if (magic == NULL) { /* non-change */ return; } - crm_element_value_int(event, XML_LRM_ATTR_OPSTATUS, &status); + crm_element_value_int(event, PCMK__XA_OP_STATUS, &status); if (status == PCMK_EXEC_PENDING) { return; } - id = crm_element_value(event, XML_LRM_ATTR_TASK_KEY); - crm_element_value_int(event, XML_LRM_ATTR_RC, &rc); - crm_element_value_int(event, XML_LRM_ATTR_CALLID, &callid); + id = crm_element_value(event, PCMK__XA_OPERATION_KEY); + crm_element_value_int(event, PCMK__XA_RC_CODE, &rc); + crm_element_value_int(event, PCMK__XA_CALL_ID, &callid); rc = pcmk__effective_rc(rc); @@ -456,7 +464,8 @@ process_graph_event(xmlNode *event, const char *event_node) // decode_transition_key() already logged the bad key crm_err("Can't process action %s result: Incompatible versions? " CRM_XS " call-id=%d", id, callid); - abort_transition(INFINITY, pcmk__graph_restart, "Bad event", event); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, + "Bad event", event); return; } @@ -468,14 +477,15 @@ process_graph_event(xmlNode *event, const char *event_node) goto bail; } desc = "initiated outside of the cluster"; - abort_transition(INFINITY, pcmk__graph_restart, "Unexpected event", - event); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, + "Unexpected event", event); } else if ((action_num < 0) || !pcmk__str_eq(update_te_uuid, controld_globals.te_uuid, pcmk__str_none)) { desc = "initiated by a different DC"; - abort_transition(INFINITY, pcmk__graph_restart, "Foreign event", event); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, + "Foreign event", event); } else if ((controld_globals.transition_graph->id != transition_num) || controld_globals.transition_graph->complete) { @@ -496,16 +506,17 @@ process_graph_event(xmlNode *event, const char *event_node) } desc = "arrived after initial scheduling"; - abort_transition(INFINITY, pcmk__graph_restart, + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, "Change in recurring result", event); } else if (controld_globals.transition_graph->id != transition_num) { desc = "arrived really late"; - abort_transition(INFINITY, pcmk__graph_restart, "Old event", event); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, + "Old event", event); } else { desc = "arrived late"; - abort_transition(INFINITY, pcmk__graph_restart, "Inactive graph", - event); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, + "Inactive graph", event); } } else { @@ -515,8 +526,8 @@ process_graph_event(xmlNode *event, const char *event_node) if (action == NULL) { // Should never happen desc = "unknown"; - abort_transition(INFINITY, pcmk__graph_restart, "Unknown event", - event); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, + "Unknown event", event); } else if (pcmk_is_set(action->flags, pcmk__graph_action_confirmed)) { /* Nothing further needs to be done if the action has already been @@ -533,7 +544,8 @@ process_graph_event(xmlNode *event, const char *event_node) * (This is the only case where desc == NULL.) */ - if (pcmk__str_eq(crm_meta_value(action->params, XML_OP_ATTR_ON_FAIL), "ignore", pcmk__str_casei)) { + if (pcmk__str_eq(crm_meta_value(action->params, PCMK_META_ON_FAIL), + PCMK_VALUE_IGNORE, pcmk__str_casei)) { ignore_failures = TRUE; } else if (rc != target_rc) { @@ -553,7 +565,7 @@ process_graph_event(xmlNode *event, const char *event_node) if (id == NULL) { id = "unknown action"; } - uname = crm_element_value(event, XML_LRM_ATTR_TARGET); + uname = crm_element_value(event, PCMK__META_ON_NODE); if (uname == NULL) { uname = "unknown node"; } diff --git a/daemons/controld/controld_te_utils.c b/daemons/controld/controld_te_utils.c index 5a9f029..3e71209 100644 --- a/daemons/controld/controld_te_utils.c +++ b/daemons/controld/controld_te_utils.c @@ -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. * @@ -9,7 +9,6 @@ #include <crm_internal.h> #include <crm/crm.h> -#include <crm/msg_xml.h> #include <crm/common/xml.h> #include <pacemaker-controld.h> @@ -192,8 +191,8 @@ node_pending_timer_popped(gpointer key) return FALSE; } - crm_warn("Node with id '%s' pending timed out (%us) on joining the process " - "group", + crm_warn("Node with " PCMK_XA_ID " '%s' pending timed out (%us) " + "on joining the process group", (const char *) key, controld_globals.node_pending_timeout); if (controld_globals.node_pending_timeout > 0) { @@ -224,22 +223,19 @@ init_node_pending_timer(const crm_node_t *node, guint timeout) return; } - crm_notice("Waiting for pending %s with id '%s' to join the process " - "group (timeout=%us)", + crm_notice("Waiting for pending %s with " PCMK_XA_ID " '%s' " + "to join the process group (timeout=%us)", node->uname ? node->uname : "node", node->uuid, controld_globals.node_pending_timeout); - node_pending_timer = calloc(1, sizeof(struct abort_timer_s)); - CRM_ASSERT(node_pending_timer != NULL); + key = pcmk__str_copy(node->uuid); + node_pending_timer = pcmk__assert_alloc(1, sizeof(struct abort_timer_s)); node_pending_timer->aborted = FALSE; - node_pending_timer->priority = INFINITY; + node_pending_timer->priority = PCMK_SCORE_INFINITY; node_pending_timer->action = pcmk__graph_restart; node_pending_timer->text = "Node pending timed out"; - key = strdup(node->uuid); - CRM_ASSERT(key != NULL); - g_hash_table_replace(node_pending_timers, key, node_pending_timer); node_pending_timer->id = g_timeout_add_seconds(timeout, @@ -264,8 +260,8 @@ controld_node_pending_timer(const crm_node_t *node) long long remaining_timeout = 0; /* If the node is not an active cluster node, is leaving the cluster, or is - * already part of CPG, or node-pending-timeout is disabled, free any - * node pending timer for it. + * already part of CPG, or PCMK_OPT_NODE_PENDING_TIMEOUT is disabled, free + * any node pending timer for it. */ if (pcmk_is_set(node->flags, crm_remote_node) || (node->when_member <= 1) || (node->when_online > 0) @@ -386,7 +382,7 @@ abort_transition_graph(int abort_priority, enum pcmk__graph_next abort_action, const xmlNode *search = NULL; for(search = reason; search; search = search->parent) { - if (pcmk__xe_is(search, XML_TAG_DIFF)) { + if (pcmk__xe_is(search, PCMK_XE_DIFF)) { diff = search; break; } @@ -395,7 +391,7 @@ abort_transition_graph(int abort_priority, enum pcmk__graph_next abort_action, if(diff) { xml_patch_versions(diff, add, del); for(search = reason; search; search = search->parent) { - if (pcmk__xe_is(search, XML_DIFF_CHANGE)) { + if (pcmk__xe_is(search, PCMK_XE_CHANGE)) { change = search; break; } @@ -417,21 +413,22 @@ abort_transition_graph(int abort_priority, enum pcmk__graph_next abort_action, do_crm_log(level, "Transition %d aborted by %s.%s: %s " CRM_XS " cib=%d.%d.%d source=%s:%d path=%s complete=%s", controld_globals.transition_graph->id, reason->name, - ID(reason), abort_text, add[0], add[1], add[2], fn, line, - (const char *) local_path->str, + pcmk__xe_id(reason), abort_text, add[0], add[1], add[2], fn, + line, (const char *) local_path->str, pcmk__btoa(controld_globals.transition_graph->complete)); g_string_free(local_path, TRUE); } else { - const char *op = crm_element_value(change, XML_DIFF_OP); - const char *path = crm_element_value(change, XML_DIFF_PATH); + const char *op = crm_element_value(change, PCMK_XA_OPERATION); + const char *path = crm_element_value(change, PCMK_XA_PATH); if(change == reason) { - if(strcmp(op, "create") == 0) { + if (strcmp(op, PCMK_VALUE_CREATE) == 0) { reason = reason->children; - } else if(strcmp(op, "modify") == 0) { - reason = first_named_child(reason, XML_DIFF_RESULT); + } else if (strcmp(op, PCMK_VALUE_MODIFY) == 0) { + reason = pcmk__xe_first_child(reason, PCMK_XE_CHANGE_RESULT, + NULL, NULL); if(reason) { reason = reason->children; } @@ -439,7 +436,7 @@ abort_transition_graph(int abort_priority, enum pcmk__graph_next abort_action, CRM_CHECK(reason != NULL, goto done); } - if(strcmp(op, "delete") == 0) { + if (strcmp(op, PCMK_VALUE_DELETE) == 0) { const char *shortpath = strrchr(path, '/'); do_crm_log(level, "Transition %d aborted by deletion of %s: %s " @@ -449,40 +446,42 @@ abort_transition_graph(int abort_priority, enum pcmk__graph_next abort_action, add[0], add[1], add[2], fn, line, path, pcmk__btoa(controld_globals.transition_graph->complete)); - } else if (pcmk__xe_is(reason, XML_CIB_TAG_NVPAIR)) { + } else if (pcmk__xe_is(reason, PCMK_XE_NVPAIR)) { do_crm_log(level, "Transition %d aborted by %s doing %s %s=%s: %s " CRM_XS " cib=%d.%d.%d source=%s:%d path=%s complete=%s", controld_globals.transition_graph->id, - crm_element_value(reason, XML_ATTR_ID), op, - crm_element_value(reason, XML_NVPAIR_ATTR_NAME), - crm_element_value(reason, XML_NVPAIR_ATTR_VALUE), + crm_element_value(reason, PCMK_XA_ID), op, + crm_element_value(reason, PCMK_XA_NAME), + crm_element_value(reason, PCMK_XA_VALUE), abort_text, add[0], add[1], add[2], fn, line, path, pcmk__btoa(controld_globals.transition_graph->complete)); - } else if (pcmk__xe_is(reason, XML_LRM_TAG_RSC_OP)) { - const char *magic = crm_element_value(reason, XML_ATTR_TRANSITION_MAGIC); + } else if (pcmk__xe_is(reason, PCMK__XE_LRM_RSC_OP)) { + const char *magic = crm_element_value(reason, + PCMK__XA_TRANSITION_MAGIC); do_crm_log(level, "Transition %d aborted by operation %s '%s' on %s: %s " CRM_XS " magic=%s cib=%d.%d.%d source=%s:%d complete=%s", controld_globals.transition_graph->id, - crm_element_value(reason, XML_LRM_ATTR_TASK_KEY), op, - crm_element_value(reason, XML_LRM_ATTR_TARGET), abort_text, + crm_element_value(reason, PCMK__XA_OPERATION_KEY), op, + crm_element_value(reason, PCMK__META_ON_NODE), + abort_text, magic, add[0], add[1], add[2], fn, line, pcmk__btoa(controld_globals.transition_graph->complete)); } else if (pcmk__str_any_of((const char *) reason->name, - XML_CIB_TAG_STATE, XML_CIB_TAG_NODE, NULL)) { - const char *uname = crm_peer_uname(ID(reason)); + PCMK__XE_NODE_STATE, PCMK_XE_NODE, NULL)) { + const char *uname = pcmk__node_name_from_uuid(pcmk__xe_id(reason)); do_crm_log(level, "Transition %d aborted by %s '%s' on %s: %s " CRM_XS " cib=%d.%d.%d source=%s:%d complete=%s", controld_globals.transition_graph->id, - reason->name, op, pcmk__s(uname, ID(reason)), + reason->name, op, pcmk__s(uname, pcmk__xe_id(reason)), abort_text, add[0], add[1], add[2], fn, line, pcmk__btoa(controld_globals.transition_graph->complete)); } else { - const char *id = ID(reason); + const char *id = pcmk__xe_id(reason); do_crm_log(level, "Transition %d aborted by %s.%s '%s': %s " CRM_XS " cib=%d.%d.%d source=%s:%d path=%s complete=%s", diff --git a/daemons/controld/controld_throttle.c b/daemons/controld/controld_throttle.c index a4775e5..08ec329 100644 --- a/daemons/controld/controld_throttle.c +++ b/daemons/controld/controld_throttle.c @@ -1,5 +1,5 @@ /* - * Copyright 2013-2021 the Pacemaker project contributors + * Copyright 2013-2024 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -17,7 +17,7 @@ #include <dirent.h> #include <crm/crm.h> -#include <crm/msg_xml.h> +#include <crm/common/xml.h> #include <crm/cluster.h> #include <pacemaker-controld.h> @@ -160,7 +160,7 @@ throttle_cib_load(float *load) } if(fgets(buffer, sizeof(buffer), stream)) { - char *comm = calloc(1, 256); + char *comm = pcmk__assert_alloc(1, 256); char state = 0; int rc = 0, pid = 0, ppid = 0, pgrp = 0, session = 0, tty_nr = 0, tpgid = 0; unsigned long flags = 0, minflt = 0, cminflt = 0, majflt = 0, cmajflt = 0, utime = 0, stime = 0; @@ -368,10 +368,10 @@ throttle_send_command(enum throttle_state_e mode) last = mode; xml = create_request(CRM_OP_THROTTLE, NULL, NULL, CRM_SYSTEM_CRMD, CRM_SYSTEM_CRMD, NULL); - crm_xml_add_int(xml, F_CRM_THROTTLE_MODE, mode); - crm_xml_add_int(xml, F_CRM_THROTTLE_MAX, throttle_job_max); + crm_xml_add_int(xml, PCMK__XA_CRM_LIMIT_MODE, mode); + crm_xml_add_int(xml, PCMK__XA_CRM_LIMIT_MAX, throttle_job_max); - send_cluster_message(NULL, crm_msg_crmd, xml, TRUE); + pcmk__cluster_send_message(NULL, crm_msg_crmd, xml); free_xml(xml); } } @@ -401,7 +401,8 @@ throttle_set_load_target(float target) * \internal * \brief Update the maximum number of simultaneous jobs * - * \param[in] preference Cluster-wide node-action-limit from the CIB + * \param[in] preference Cluster-wide \c PCMK_OPT_NODE_ACTION_LIMIT from the + * CIB */ static void throttle_update_job_max(const char *preference) @@ -416,7 +417,7 @@ throttle_update_job_max(const char *preference) pcmk__scan_ll(preference, &max, 0LL); } if (max > 0) { - throttle_job_max = (int) max; + throttle_job_max = (max >= INT_MAX)? INT_MAX : (int) max; } else { // Default is based on the number of cores detected throttle_job_max = 2 * pcmk__procfs_num_cores(); @@ -444,13 +445,13 @@ throttle_init(void) void controld_configure_throttle(GHashTable *options) { - const char *value = g_hash_table_lookup(options, "load-threshold"); + const char *value = g_hash_table_lookup(options, PCMK_OPT_LOAD_THRESHOLD); if (value != NULL) { throttle_set_load_target(strtof(value, NULL) / 100.0); } - value = g_hash_table_lookup(options, "node-action-limit"); + value = g_hash_table_lookup(options, PCMK_OPT_NODE_ACTION_LIMIT); throttle_update_job_max(value); } @@ -473,7 +474,7 @@ throttle_get_total_job_limit(int l) /* Cluster-wide limit */ GHashTableIter iter; int limit = l; - int peers = crm_active_peers(); + int peers = pcmk__cluster_num_active_nodes(); struct throttle_record_s *r = NULL; g_hash_table_iter_init(&iter, throttle_records); @@ -497,13 +498,12 @@ throttle_get_total_job_limit(int l) } } if(limit == l) { - /* crm_trace("No change to batch-limit=%d", limit); */ } else if(l == 0) { - crm_trace("Using batch-limit=%d", limit); + crm_trace("Using " PCMK_OPT_BATCH_LIMIT "=%d", limit); } else { - crm_trace("Using batch-limit=%d instead of %d", limit, l); + crm_trace("Using " PCMK_OPT_BATCH_LIMIT "=%d instead of %d", limit, l); } return limit; } @@ -516,8 +516,8 @@ throttle_get_job_limit(const char *node) r = g_hash_table_lookup(throttle_records, node); if(r == NULL) { - r = calloc(1, sizeof(struct throttle_record_s)); - r->node = strdup(node); + r = pcmk__assert_alloc(1, sizeof(struct throttle_record_s)); + r->node = pcmk__str_copy(node); r->mode = throttle_low; r->max = throttle_job_max; crm_trace("Defaulting to local values for unknown node %s", node); @@ -552,16 +552,16 @@ throttle_update(xmlNode *xml) int max = 0; int mode = 0; struct throttle_record_s *r = NULL; - const char *from = crm_element_value(xml, F_CRM_HOST_FROM); + const char *from = crm_element_value(xml, PCMK__XA_SRC); - crm_element_value_int(xml, F_CRM_THROTTLE_MODE, &mode); - crm_element_value_int(xml, F_CRM_THROTTLE_MAX, &max); + crm_element_value_int(xml, PCMK__XA_CRM_LIMIT_MODE, &mode); + crm_element_value_int(xml, PCMK__XA_CRM_LIMIT_MAX, &max); r = g_hash_table_lookup(throttle_records, from); if(r == NULL) { - r = calloc(1, sizeof(struct throttle_record_s)); - r->node = strdup(from); + r = pcmk__assert_alloc(1, sizeof(struct throttle_record_s)); + r->node = pcmk__str_copy(from); g_hash_table_insert(throttle_records, r->node, r); } diff --git a/daemons/controld/controld_timers.c b/daemons/controld/controld_timers.c index a65bef5..0d387b9 100644 --- a/daemons/controld/controld_timers.c +++ b/daemons/controld/controld_timers.c @@ -1,5 +1,5 @@ /* - * Copyright 2004-2022 the Pacemaker project contributors + * Copyright 2004-2024 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -13,7 +13,7 @@ #include <stdlib.h> #include <crm/crm.h> -#include <crm/msg_xml.h> +#include <crm/common/xml.h> #include <pacemaker-controld.h> //! FSA mainloop timer type @@ -38,10 +38,10 @@ static fsa_timer_t *election_timer = NULL; //! Delay start of new transition with expectation something else might happen static fsa_timer_t *transition_timer = NULL; -//! join-integration-timeout +//! \c PCMK_OPT_JOIN_INTEGRATION_TIMEOUT static fsa_timer_t *integration_timer = NULL; -//! join-finalization-timeout +//! \c PCMK_OPT_JOIN_FINALIZATION_TIMEOUT static fsa_timer_t *finalization_timer = NULL; // Wait for DC to stop all resources and give us the all-clear to shut down @@ -229,40 +229,13 @@ crm_timer_popped(gpointer data) bool controld_init_fsa_timers(void) { - transition_timer = calloc(1, sizeof(fsa_timer_t)); - if (transition_timer == NULL) { - return FALSE; - } - - integration_timer = calloc(1, sizeof(fsa_timer_t)); - if (integration_timer == NULL) { - return FALSE; - } - - finalization_timer = calloc(1, sizeof(fsa_timer_t)); - if (finalization_timer == NULL) { - return FALSE; - } - - election_timer = calloc(1, sizeof(fsa_timer_t)); - if (election_timer == NULL) { - return FALSE; - } - - shutdown_escalation_timer = calloc(1, sizeof(fsa_timer_t)); - if (shutdown_escalation_timer == NULL) { - return FALSE; - } - - wait_timer = calloc(1, sizeof(fsa_timer_t)); - if (wait_timer == NULL) { - return FALSE; - } - - recheck_timer = calloc(1, sizeof(fsa_timer_t)); - if (recheck_timer == NULL) { - return FALSE; - } + transition_timer = pcmk__assert_alloc(1, sizeof(fsa_timer_t)); + integration_timer = pcmk__assert_alloc(1, sizeof(fsa_timer_t)); + finalization_timer = pcmk__assert_alloc(1, sizeof(fsa_timer_t)); + election_timer = pcmk__assert_alloc(1, sizeof(fsa_timer_t)); + shutdown_escalation_timer = pcmk__assert_alloc(1, sizeof(fsa_timer_t)); + wait_timer = pcmk__assert_alloc(1, sizeof(fsa_timer_t)); + recheck_timer = pcmk__assert_alloc(1, sizeof(fsa_timer_t)); election_timer->source_id = 0; election_timer->period_ms = 0; @@ -332,30 +305,30 @@ controld_configure_fsa_timers(GHashTable *options) const char *value = NULL; // Election timer - value = g_hash_table_lookup(options, XML_CONFIG_ATTR_DC_DEADTIME); - election_timer->period_ms = crm_parse_interval_spec(value); + value = g_hash_table_lookup(options, PCMK_OPT_DC_DEADTIME); + pcmk_parse_interval_spec(value, &(election_timer->period_ms)); // Integration timer - value = g_hash_table_lookup(options, "join-integration-timeout"); - integration_timer->period_ms = crm_parse_interval_spec(value); + value = g_hash_table_lookup(options, PCMK_OPT_JOIN_INTEGRATION_TIMEOUT); + pcmk_parse_interval_spec(value, &(integration_timer->period_ms)); // Finalization timer - value = g_hash_table_lookup(options, "join-finalization-timeout"); - finalization_timer->period_ms = crm_parse_interval_spec(value); + value = g_hash_table_lookup(options, PCMK_OPT_JOIN_FINALIZATION_TIMEOUT); + pcmk_parse_interval_spec(value, &(finalization_timer->period_ms)); // Shutdown escalation timer - value = g_hash_table_lookup(options, XML_CONFIG_ATTR_FORCE_QUIT); - shutdown_escalation_timer->period_ms = crm_parse_interval_spec(value); + value = g_hash_table_lookup(options, PCMK_OPT_SHUTDOWN_ESCALATION); + pcmk_parse_interval_spec(value, &(shutdown_escalation_timer->period_ms)); crm_debug("Shutdown escalation occurs if DC has not responded to request " "in %ums", shutdown_escalation_timer->period_ms); // Transition timer - value = g_hash_table_lookup(options, "transition-delay"); - transition_timer->period_ms = crm_parse_interval_spec(value); + value = g_hash_table_lookup(options, PCMK_OPT_TRANSITION_DELAY); + pcmk_parse_interval_spec(value, &(transition_timer->period_ms)); // Recheck interval - value = g_hash_table_lookup(options, XML_CONFIG_ATTR_RECHECK); - recheck_interval_ms = crm_parse_interval_spec(value); + value = g_hash_table_lookup(options, PCMK_OPT_CLUSTER_RECHECK_INTERVAL); + pcmk_parse_interval_spec(value, &recheck_interval_ms); crm_debug("Re-run scheduler after %dms of inactivity", recheck_interval_ms); } diff --git a/daemons/controld/controld_transition.c b/daemons/controld/controld_transition.c index 897c6d3..184253d 100644 --- a/daemons/controld/controld_transition.c +++ b/daemons/controld/controld_transition.c @@ -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. * @@ -10,7 +10,6 @@ #include <crm_internal.h> #include <crm/crm.h> -#include <crm/msg_xml.h> #include <crm/common/xml.h> #include <pacemaker-controld.h> @@ -41,7 +40,8 @@ do_te_control(long long action, controld_globals.transition_graph = NULL; if (cib_conn != NULL) { - cib_conn->cmds->del_notify_callback(cib_conn, T_CIB_DIFF_NOTIFY, + cib_conn->cmds->del_notify_callback(cib_conn, + PCMK__VALUE_CIB_DIFF_NOTIFY, te_update_diff); } @@ -71,12 +71,11 @@ do_te_control(long long action, crm_err("Could not set CIB callbacks"); init_ok = FALSE; - } else { - if (cib_conn->cmds->add_notify_callback(cib_conn, T_CIB_DIFF_NOTIFY, - te_update_diff) != pcmk_ok) { - crm_err("Could not set CIB notification callback"); - init_ok = FALSE; - } + } else if (cib_conn->cmds->add_notify_callback(cib_conn, + PCMK__VALUE_CIB_DIFF_NOTIFY, + te_update_diff) != pcmk_ok) { + crm_err("Could not set CIB notification callback"); + init_ok = FALSE; } if (init_ok) { @@ -110,13 +109,15 @@ do_te_invoke(long long action, if (action & A_TE_CANCEL) { crm_debug("Cancelling the transition: %sactive", controld_globals.transition_graph->complete? "in" : ""); - abort_transition(INFINITY, pcmk__graph_restart, "Peer Cancelled", NULL); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, + "Peer Cancelled", NULL); if (!controld_globals.transition_graph->complete) { crmd_fsa_stall(FALSE); } } else if (action & A_TE_HALT) { - abort_transition(INFINITY, pcmk__graph_wait, "Peer Halt", NULL); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_wait, "Peer Halt", + NULL); if (!controld_globals.transition_graph->complete) { crmd_fsa_stall(FALSE); } @@ -124,11 +125,11 @@ do_te_invoke(long long action, } else if (action & A_TE_INVOKE) { ha_msg_input_t *input = fsa_typed_data(fsa_dt_ha_msg); xmlNode *graph_data = input->xml; - const char *ref = crm_element_value(input->msg, XML_ATTR_REFERENCE); - const char *graph_file = crm_element_value(input->msg, F_CRM_TGRAPH); - const char *graph_input = crm_element_value(input->msg, F_CRM_TGRAPH_INPUT); + const char *ref = crm_element_value(input->msg, PCMK_XA_REFERENCE); + const char *graph_input = crm_element_value(input->msg, + PCMK__XA_CRM_TGRAPH_IN); - if (graph_file == NULL && graph_data == NULL) { + if (graph_data == NULL) { crm_log_xml_err(input->msg, "Bad command"); register_fsa_error(C_FSA_INTERNAL, I_FAIL, NULL); return; @@ -136,8 +137,8 @@ do_te_invoke(long long action, if (!controld_globals.transition_graph->complete) { crm_info("Another transition is already active"); - abort_transition(INFINITY, pcmk__graph_restart, "Transition Active", - NULL); + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, + "Transition Active", NULL); return; } @@ -147,14 +148,10 @@ do_te_invoke(long long action, crm_info("Transition is redundant: %s expected but %s received", pcmk__s(controld_globals.fsa_pe_ref, "no reference"), pcmk__s(ref, "no reference")); - abort_transition(INFINITY, pcmk__graph_restart, + abort_transition(PCMK_SCORE_INFINITY, pcmk__graph_restart, "Transition Redundant", NULL); } - if (graph_data == NULL && graph_file != NULL) { - graph_data = filename2xml(graph_file); - } - if (controld_is_started_transition_timer()) { crm_debug("The transitioner wait for a transition timer"); return; diff --git a/daemons/controld/controld_utils.c b/daemons/controld/controld_utils.c index 9b306ee..fc0a8fd 100644 --- a/daemons/controld/controld_utils.c +++ b/daemons/controld/controld_utils.c @@ -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. * @@ -14,7 +14,6 @@ #include <crm/crm.h> #include <crm/cib.h> -#include <crm/msg_xml.h> #include <crm/common/xml.h> #include <pacemaker-controld.h> @@ -694,8 +693,8 @@ update_dc(xmlNode * msg) if (msg != NULL) { gboolean invalid = FALSE; - dc_version = crm_element_value(msg, F_CRM_VERSION); - welcome_from = crm_element_value(msg, F_CRM_HOST_FROM); + dc_version = crm_element_value(msg, PCMK_XA_VERSION); + welcome_from = crm_element_value(msg, PCMK__XA_SRC); CRM_CHECK(dc_version != NULL, return FALSE); CRM_CHECK(welcome_from != NULL, return FALSE); @@ -734,7 +733,8 @@ update_dc(xmlNode * msg) /* do nothing */ } else if (controld_globals.dc_name != NULL) { - crm_node_t *dc_node = crm_get_peer(0, controld_globals.dc_name); + crm_node_t *dc_node = pcmk__get_node(0, controld_globals.dc_name, NULL, + pcmk__node_search_cluster_member); crm_info("Set DC to %s (%s)", controld_globals.dc_name, @@ -828,10 +828,10 @@ get_node_id(xmlNode *lrm_rsc_op) { xmlNode *node = lrm_rsc_op; - while ((node != NULL) && !pcmk__xe_is(node, XML_CIB_TAG_STATE)) { + while ((node != NULL) && !pcmk__xe_is(node, PCMK__XE_NODE_STATE)) { node = node->parent; } CRM_CHECK(node != NULL, return NULL); - return ID(node); + return pcmk__xe_id(node); } diff --git a/daemons/controld/pacemaker-controld.c b/daemons/controld/pacemaker-controld.c index e4a72c2..913518b 100644 --- a/daemons/controld/pacemaker-controld.c +++ b/daemons/controld/pacemaker-controld.c @@ -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. * @@ -46,11 +46,23 @@ static pcmk__supported_format_t formats[] = { { NULL, NULL, NULL } }; +/* @COMPAT Deprecated since 2.1.8. Use pcmk_list_cluster_options() or + * crm_attribute --list-options=cluster instead of querying daemon metadata. + */ +static int +controld_metadata(pcmk__output_t *out) +{ + return pcmk__daemon_metadata(out, "pacemaker-controld", + "Pacemaker controller options", + "Cluster options used by Pacemaker's " + "controller", + pcmk__opt_controld); +} + static GOptionContext * build_arg_context(pcmk__common_args_t *args, GOptionGroup **group) { - return pcmk__build_arg_context(args, "text (default), xml", group, - "[metadata]"); + return pcmk__build_arg_context(args, "text (default), xml", group, NULL); } int @@ -96,8 +108,14 @@ main(int argc, char **argv) if ((g_strv_length(processed_args) >= 2) && pcmk__str_eq(processed_args[1], "metadata", pcmk__str_none)) { - crmd_metadata(); + initialize = false; + rc = controld_metadata(out); + if (rc != pcmk_rc_ok) { + exit_code = CRM_EX_FATAL; + g_set_error(&error, PCMK__EXITC_ERROR, exit_code, + "Unable to display metadata: %s", pcmk_rc_str(rc)); + } goto done; } @@ -178,7 +196,7 @@ crmd_init(void) init_dotfile(); register_fsa_input(C_STARTUP, I_STARTUP, NULL); - crm_peer_init(); + pcmk__cluster_init_node_caches(); state = s_crmd_fsa(C_STARTUP); if (state == S_PENDING || state == S_STARTING) { diff --git a/daemons/controld/pacemaker-controld.h b/daemons/controld/pacemaker-controld.h index 2334cce..ba8dc8f 100644 --- a/daemons/controld/pacemaker-controld.h +++ b/daemons/controld/pacemaker-controld.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. * @@ -28,7 +28,6 @@ # define controld_trigger_config() \ controld_trigger_config_as(__func__, __LINE__) -void crmd_metadata(void); void controld_trigger_config_as(const char *fn, int line); void controld_election_init(const char *uname); void controld_configure_election(GHashTable *options); |