summaryrefslogtreecommitdiffstats
path: root/daemons/based
diff options
context:
space:
mode:
Diffstat (limited to 'daemons/based')
-rw-r--r--daemons/based/Makefile.am9
-rw-r--r--daemons/based/based_callbacks.c361
-rw-r--r--daemons/based/based_io.c35
-rw-r--r--daemons/based/based_messages.c286
-rw-r--r--daemons/based/based_notify.c64
-rw-r--r--daemons/based/based_operation.c1
-rw-r--r--daemons/based/based_remote.c63
-rw-r--r--daemons/based/based_transaction.c34
-rw-r--r--daemons/based/pacemaker-based.c61
-rw-r--r--daemons/based/pacemaker-based.h6
10 files changed, 531 insertions, 389 deletions
diff --git a/daemons/based/Makefile.am b/daemons/based/Makefile.am
index 022fc47..c10b461 100644
--- a/daemons/based/Makefile.am
+++ b/daemons/based/Makefile.am
@@ -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.
#
@@ -8,6 +8,7 @@
#
include $(top_srcdir)/mk/common.mk
+include $(top_srcdir)/mk/man.mk
EXTRA_DIST = cib.pam
@@ -35,6 +36,12 @@ pacemaker_based_SOURCES = pacemaker-based.c \
based_remote.c \
based_transaction.c
+if BUILD_XML_HELP
+man7_MANS = pacemaker-based.7
+endif
+
+CLEANFILES = $(man7_MANS)
+
.PHONY: install-exec-hook
install-exec-hook:
if BUILD_LEGACY_LINKS
diff --git a/daemons/based/based_callbacks.c b/daemons/based/based_callbacks.c
index 4fac222..b1a8209 100644
--- a/daemons/based/based_callbacks.c
+++ b/daemons/based/based_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.
*
@@ -25,7 +25,6 @@
#include <crm/crm.h>
#include <crm/cib.h>
-#include <crm/msg_xml.h>
#include <crm/cluster/internal.h>
#include <crm/common/xml.h>
@@ -72,11 +71,11 @@ cib_ipc_accept(qb_ipcs_connection_t * c, uid_t uid, gid_t gid)
if (cib_shutdown_flag) {
crm_info("Ignoring new IPC client [%d] during shutdown",
pcmk__client_pid(c));
- return -EPERM;
+ return -ECONNREFUSED;
}
if (pcmk__new_client(c, uid, gid) == NULL) {
- return -EIO;
+ return -ENOMEM;
}
return 0;
}
@@ -159,20 +158,20 @@ static xmlNode *
create_cib_reply(const char *op, const char *call_id, const char *client_id,
int call_options, int rc, xmlNode *call_data)
{
- xmlNode *reply = create_xml_node(NULL, "cib-reply");
+ xmlNode *reply = pcmk__xe_create(NULL, PCMK__XE_CIB_REPLY);
- CRM_ASSERT(reply != NULL);
-
- crm_xml_add(reply, F_TYPE, T_CIB);
- crm_xml_add(reply, F_CIB_OPERATION, op);
- crm_xml_add(reply, F_CIB_CALLID, call_id);
- crm_xml_add(reply, F_CIB_CLIENTID, client_id);
- crm_xml_add_int(reply, F_CIB_CALLOPTS, call_options);
- crm_xml_add_int(reply, F_CIB_RC, rc);
+ crm_xml_add(reply, PCMK__XA_T, PCMK__VALUE_CIB);
+ crm_xml_add(reply, PCMK__XA_CIB_OP, op);
+ crm_xml_add(reply, PCMK__XA_CIB_CALLID, call_id);
+ crm_xml_add(reply, PCMK__XA_CIB_CLIENTID, client_id);
+ crm_xml_add_int(reply, PCMK__XA_CIB_CALLOPT, call_options);
+ crm_xml_add_int(reply, PCMK__XA_CIB_RC, rc);
if (call_data != NULL) {
+ xmlNode *wrapper = pcmk__xe_create(reply, PCMK__XE_CIB_CALLDATA);
+
crm_trace("Attaching reply output");
- add_message_xml(reply, F_CIB_CALLDATA, call_data);
+ pcmk__xml_copy(wrapper, call_data);
}
crm_log_xml_explicit(reply, "cib:reply");
@@ -189,7 +188,7 @@ do_local_notify(const xmlNode *notify_src, const char *client_id,
CRM_ASSERT(notify_src && client_id);
- crm_element_value_int(notify_src, F_CIB_CALLID, &call_id);
+ crm_element_value_int(notify_src, PCMK__XA_CIB_CALLID, &call_id);
client_obj = pcmk__find_client_by_id(client_id);
if (client_obj == NULL) {
@@ -252,10 +251,10 @@ void
cib_common_callback_worker(uint32_t id, uint32_t flags, xmlNode * op_request,
pcmk__client_t *cib_client, gboolean privileged)
{
- const char *op = crm_element_value(op_request, F_CIB_OPERATION);
+ const char *op = crm_element_value(op_request, PCMK__XA_CIB_OP);
int call_options = cib_none;
- crm_element_value_int(op_request, F_CIB_CALLOPTS, &call_options);
+ crm_element_value_int(op_request, PCMK__XA_CIB_CALLOPT, &call_options);
/* Requests with cib_transaction set should not be sent to based directly
* (outside of a commit-transaction request)
@@ -266,38 +265,43 @@ cib_common_callback_worker(uint32_t id, uint32_t flags, xmlNode * op_request,
if (pcmk__str_eq(op, CRM_OP_REGISTER, pcmk__str_none)) {
if (flags & crm_ipc_client_response) {
- xmlNode *ack = create_xml_node(NULL, __func__);
+ xmlNode *ack = pcmk__xe_create(NULL, __func__);
- crm_xml_add(ack, F_CIB_OPERATION, CRM_OP_REGISTER);
- crm_xml_add(ack, F_CIB_CLIENTID, cib_client->id);
+ crm_xml_add(ack, PCMK__XA_CIB_OP, CRM_OP_REGISTER);
+ crm_xml_add(ack, PCMK__XA_CIB_CLIENTID, cib_client->id);
pcmk__ipc_send_xml(cib_client, id, ack, flags);
cib_client->request_id = 0;
free_xml(ack);
}
return;
- } else if (pcmk__str_eq(op, T_CIB_NOTIFY, pcmk__str_none)) {
+ } else if (pcmk__str_eq(op, PCMK__VALUE_CIB_NOTIFY, pcmk__str_none)) {
/* Update the notify filters for this client */
int on_off = 0;
crm_exit_t status = CRM_EX_OK;
uint64_t bit = UINT64_C(0);
- const char *type = crm_element_value(op_request, F_CIB_NOTIFY_TYPE);
+ const char *type = crm_element_value(op_request,
+ PCMK__XA_CIB_NOTIFY_TYPE);
- crm_element_value_int(op_request, F_CIB_NOTIFY_ACTIVATE, &on_off);
+ crm_element_value_int(op_request, PCMK__XA_CIB_NOTIFY_ACTIVATE,
+ &on_off);
crm_debug("Setting %s callbacks %s for client %s",
type, (on_off? "on" : "off"), pcmk__client_name(cib_client));
- if (pcmk__str_eq(type, T_CIB_POST_NOTIFY, pcmk__str_casei)) {
+ if (pcmk__str_eq(type, PCMK__VALUE_CIB_POST_NOTIFY, pcmk__str_none)) {
bit = cib_notify_post;
- } else if (pcmk__str_eq(type, T_CIB_PRE_NOTIFY, pcmk__str_casei)) {
+ } else if (pcmk__str_eq(type, PCMK__VALUE_CIB_PRE_NOTIFY,
+ pcmk__str_none)) {
bit = cib_notify_pre;
- } else if (pcmk__str_eq(type, T_CIB_UPDATE_CONFIRM, pcmk__str_casei)) {
+ } else if (pcmk__str_eq(type, PCMK__VALUE_CIB_UPDATE_CONFIRMATION,
+ pcmk__str_none)) {
bit = cib_notify_confirm;
- } else if (pcmk__str_eq(type, T_CIB_DIFF_NOTIFY, pcmk__str_casei)) {
+ } else if (pcmk__str_eq(type, PCMK__VALUE_CIB_DIFF_NOTIFY,
+ pcmk__str_none)) {
bit = cib_notify_diff;
} else {
@@ -312,7 +316,7 @@ cib_common_callback_worker(uint32_t id, uint32_t flags, xmlNode * op_request,
}
}
- pcmk__ipc_send_ack(cib_client, id, flags, "ack", NULL, status);
+ pcmk__ipc_send_ack(cib_client, id, flags, PCMK__XE_ACK, NULL, status);
return;
}
@@ -329,12 +333,13 @@ cib_common_callback(qb_ipcs_connection_t * c, void *data, size_t size, gboolean
xmlNode *op_request = pcmk__client_data2xml(cib_client, data, &id, &flags);
if (op_request) {
- crm_element_value_int(op_request, F_CIB_CALLOPTS, &call_options);
+ crm_element_value_int(op_request, PCMK__XA_CIB_CALLOPT, &call_options);
}
if (op_request == NULL) {
crm_trace("Invalid message from %p", c);
- pcmk__ipc_send_ack(cib_client, id, flags, "nack", NULL, CRM_EX_PROTOCOL);
+ pcmk__ipc_send_ack(cib_client, id, flags, PCMK__XE_NACK, NULL,
+ CRM_EX_PROTOCOL);
return 0;
} else if(cib_client == NULL) {
@@ -349,12 +354,13 @@ cib_common_callback(qb_ipcs_connection_t * c, void *data, size_t size, gboolean
}
if (cib_client->name == NULL) {
- const char *value = crm_element_value(op_request, F_CIB_CLIENTNAME);
+ const char *value = crm_element_value(op_request,
+ PCMK__XA_CIB_CLIENTNAME);
if (value == NULL) {
cib_client->name = pcmk__itoa(cib_client->pid);
} else {
- cib_client->name = strdup(value);
+ cib_client->name = pcmk__str_copy(value);
if (crm_is_daemon_name(value)) {
pcmk__set_client_flags(cib_client, cib_is_daemon);
}
@@ -363,7 +369,7 @@ cib_common_callback(qb_ipcs_connection_t * c, void *data, size_t size, gboolean
/* Allow cluster daemons more leeway before being evicted */
if (pcmk_is_set(cib_client->flags, cib_is_daemon)) {
- const char *qmax = cib_config_lookup("cluster-ipc-limit");
+ const char *qmax = cib_config_lookup(PCMK_OPT_CLUSTER_IPC_LIMIT);
if (pcmk__set_client_queue_max(cib_client, qmax)) {
crm_trace("IPC threshold for client %s[%u] is now %u",
@@ -372,11 +378,11 @@ cib_common_callback(qb_ipcs_connection_t * c, void *data, size_t size, gboolean
}
}
- crm_xml_add(op_request, F_CIB_CLIENTID, cib_client->id);
- crm_xml_add(op_request, F_CIB_CLIENTNAME, cib_client->name);
+ crm_xml_add(op_request, PCMK__XA_CIB_CLIENTID, cib_client->id);
+ crm_xml_add(op_request, PCMK__XA_CIB_CLIENTNAME, cib_client->name);
CRM_LOG_ASSERT(cib_client->user != NULL);
- pcmk__update_acl_user(op_request, F_CIB_USER, cib_client->user);
+ pcmk__update_acl_user(op_request, PCMK__XA_CIB_USER, cib_client->user);
cib_common_callback_worker(id, flags, op_request, cib_client, privileged);
free_xml(op_request);
@@ -393,7 +399,7 @@ cib_digester_cb(gpointer data)
{
if (based_is_primary) {
char buffer[32];
- xmlNode *ping = create_xml_node(NULL, "ping");
+ xmlNode *ping = pcmk__xe_create(NULL, PCMK__XE_PING);
ping_seq++;
free(ping_digest);
@@ -402,12 +408,12 @@ cib_digester_cb(gpointer data)
snprintf(buffer, 32, "%" PRIu64, ping_seq);
crm_trace("Requesting peer digests (%s)", buffer);
- crm_xml_add(ping, F_TYPE, "cib");
- crm_xml_add(ping, F_CIB_OPERATION, CRM_OP_PING);
- crm_xml_add(ping, F_CIB_PING_ID, buffer);
+ crm_xml_add(ping, PCMK__XA_T, PCMK__VALUE_CIB);
+ crm_xml_add(ping, PCMK__XA_CIB_OP, CRM_OP_PING);
+ crm_xml_add(ping, PCMK__XA_CIB_PING_ID, buffer);
- crm_xml_add(ping, XML_ATTR_CRM_VERSION, CRM_FEATURE_SET);
- send_cluster_message(NULL, crm_msg_cib, ping, TRUE);
+ crm_xml_add(ping, PCMK_XA_CRM_FEATURE_SET, CRM_FEATURE_SET);
+ pcmk__cluster_send_message(NULL, crm_msg_cib, ping);
free_xml(ping);
}
@@ -418,14 +424,17 @@ static void
process_ping_reply(xmlNode *reply)
{
uint64_t seq = 0;
- const char *host = crm_element_value(reply, F_ORIG);
+ const char *host = crm_element_value(reply, PCMK__XA_SRC);
- xmlNode *pong = get_message_xml(reply, F_CIB_CALLDATA);
- const char *seq_s = crm_element_value(pong, F_CIB_PING_ID);
- const char *digest = crm_element_value(pong, XML_ATTR_DIGEST);
+ xmlNode *wrapper = pcmk__xe_first_child(reply, PCMK__XE_CIB_CALLDATA, NULL,
+ NULL);
+ xmlNode *pong = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
+
+ const char *seq_s = crm_element_value(pong, PCMK__XA_CIB_PING_ID);
+ const char *digest = crm_element_value(pong, PCMK__XA_DIGEST);
if (seq_s == NULL) {
- crm_debug("Ignoring ping reply with no " F_CIB_PING_ID);
+ crm_debug("Ignoring ping reply with no " PCMK__XA_CIB_PING_ID);
return;
} else {
@@ -447,7 +456,7 @@ process_ping_reply(xmlNode *reply)
crm_trace("Ignoring ping reply %s from %s: cib updated since", seq_s, host);
} else {
- const char *version = crm_element_value(pong, XML_ATTR_CRM_VERSION);
+ const char *version = crm_element_value(pong, PCMK_XA_CRM_FEATURE_SET);
if(ping_digest == NULL) {
crm_trace("Calculating new digest");
@@ -456,16 +465,30 @@ process_ping_reply(xmlNode *reply)
crm_trace("Processing ping reply %s from %s (%s)", seq_s, host, digest);
if (!pcmk__str_eq(ping_digest, digest, pcmk__str_casei)) {
- xmlNode *remote_cib = get_message_xml(pong, F_CIB_CALLDATA);
+ xmlNode *wrapper = pcmk__xe_first_child(pong, PCMK__XE_CIB_CALLDATA,
+ NULL, NULL);
+ xmlNode *remote_cib = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
+
+ const char *admin_epoch_s = NULL;
+ const char *epoch_s = NULL;
+ const char *num_updates_s = NULL;
+
+ if (remote_cib != NULL) {
+ admin_epoch_s = crm_element_value(remote_cib,
+ PCMK_XA_ADMIN_EPOCH);
+ epoch_s = crm_element_value(remote_cib, PCMK_XA_EPOCH);
+ num_updates_s = crm_element_value(remote_cib,
+ PCMK_XA_NUM_UPDATES);
+ }
crm_notice("Local CIB %s.%s.%s.%s differs from %s: %s.%s.%s.%s %p",
- crm_element_value(the_cib, XML_ATTR_GENERATION_ADMIN),
- crm_element_value(the_cib, XML_ATTR_GENERATION),
- crm_element_value(the_cib, XML_ATTR_NUMUPDATES),
+ crm_element_value(the_cib, PCMK_XA_ADMIN_EPOCH),
+ crm_element_value(the_cib, PCMK_XA_EPOCH),
+ crm_element_value(the_cib, PCMK_XA_NUM_UPDATES),
ping_digest, host,
- remote_cib?crm_element_value(remote_cib, XML_ATTR_GENERATION_ADMIN):"_",
- remote_cib?crm_element_value(remote_cib, XML_ATTR_GENERATION):"_",
- remote_cib?crm_element_value(remote_cib, XML_ATTR_NUMUPDATES):"_",
+ pcmk__s(admin_epoch_s, "_"),
+ pcmk__s(epoch_s, "_"),
+ pcmk__s(num_updates_s, "_"),
digest, remote_cib);
if(remote_cib && remote_cib->children) {
@@ -513,10 +536,11 @@ static void
queue_local_notify(xmlNode * notify_src, const char *client_id, gboolean sync_reply,
gboolean from_peer)
{
- cib_local_notify_t *notify = calloc(1, sizeof(cib_local_notify_t));
+ cib_local_notify_t *notify = pcmk__assert_alloc(1,
+ sizeof(cib_local_notify_t));
notify->notify_src = notify_src;
- notify->client_id = strdup(client_id);
+ notify->client_id = pcmk__str_copy(client_id);
notify->sync_reply = sync_reply;
notify->from_peer = from_peer;
@@ -658,12 +682,12 @@ parse_peer_options_v1(const cib__operation_t *operation, xmlNode *request,
const char *op = NULL;
const char *host = NULL;
const char *delegated = NULL;
- const char *originator = crm_element_value(request, F_ORIG);
- const char *reply_to = crm_element_value(request, F_CIB_ISREPLY);
+ const char *originator = crm_element_value(request, PCMK__XA_SRC);
+ const char *reply_to = crm_element_value(request, PCMK__XA_CIB_ISREPLYTO);
gboolean is_reply = pcmk__str_eq(reply_to, OUR_NODENAME, pcmk__str_casei);
- if (pcmk__xe_attr_is_true(request, F_CIB_GLOBAL_UPDATE)) {
+ if (pcmk__xe_attr_is_true(request, PCMK__XA_CIB_UPDATE)) {
*needs_reply = FALSE;
if (is_reply) {
*local_notify = TRUE;
@@ -675,7 +699,7 @@ parse_peer_options_v1(const cib__operation_t *operation, xmlNode *request,
return TRUE;
}
- op = crm_element_value(request, F_CIB_OPERATION);
+ op = crm_element_value(request, PCMK__XA_CIB_OP);
crm_trace("Processing legacy %s request sent by %s", op, originator);
if (pcmk__str_eq(op, PCMK__CIB_REQUEST_SHUTDOWN, pcmk__str_none)) {
@@ -703,7 +727,7 @@ parse_peer_options_v1(const cib__operation_t *operation, xmlNode *request,
return TRUE;
}
- host = crm_element_value(request, F_CIB_HOST);
+ host = crm_element_value(request, PCMK__XA_CIB_HOST);
if (pcmk__str_eq(host, OUR_NODENAME, pcmk__str_casei)) {
crm_trace("Processing %s request sent to us from %s", op, originator);
return TRUE;
@@ -719,7 +743,7 @@ parse_peer_options_v1(const cib__operation_t *operation, xmlNode *request,
return TRUE;
}
- delegated = crm_element_value(request, F_CIB_DELEGATED);
+ delegated = crm_element_value(request, PCMK__XA_CIB_DELEGATED_FROM);
if (delegated != NULL) {
crm_trace("Ignoring message for primary instance");
@@ -755,10 +779,11 @@ parse_peer_options_v2(const cib__operation_t *operation, xmlNode *request,
gboolean *process)
{
const char *host = NULL;
- const char *delegated = crm_element_value(request, F_CIB_DELEGATED);
- const char *op = crm_element_value(request, F_CIB_OPERATION);
- const char *originator = crm_element_value(request, F_ORIG);
- const char *reply_to = crm_element_value(request, F_CIB_ISREPLY);
+ const char *delegated = crm_element_value(request,
+ PCMK__XA_CIB_DELEGATED_FROM);
+ const char *op = crm_element_value(request, PCMK__XA_CIB_OP);
+ const char *originator = crm_element_value(request, PCMK__XA_SRC);
+ const char *reply_to = crm_element_value(request, PCMK__XA_CIB_ISREPLYTO);
gboolean is_reply = pcmk__str_eq(reply_to, OUR_NODENAME, pcmk__str_casei);
@@ -767,7 +792,7 @@ parse_peer_options_v2(const cib__operation_t *operation, xmlNode *request,
}
if (pcmk__str_eq(op, PCMK__CIB_REQUEST_REPLACE, pcmk__str_none)) {
- /* sync_our_cib() sets F_CIB_ISREPLY */
+ // sync_our_cib() sets PCMK__XA_CIB_ISREPLYTO
if (reply_to) {
delegated = reply_to;
}
@@ -783,17 +808,18 @@ parse_peer_options_v2(const cib__operation_t *operation, xmlNode *request,
} else if (pcmk__str_eq(op, PCMK__CIB_REQUEST_UPGRADE, pcmk__str_none)) {
/* Only the DC (node with the oldest software) should process
- * this operation if F_CIB_SCHEMA_MAX is unset
+ * this operation if PCMK__XA_CIB_SCHEMA_MAX is unset.
*
* If the DC is happy it will then send out another
* PCMK__CIB_REQUEST_UPGRADE which will tell all nodes to do the actual
* upgrade.
*
- * Except this time F_CIB_SCHEMA_MAX will be set which puts a
+ * Except this time PCMK__XA_CIB_SCHEMA_MAX will be set which puts a
* limit on how far newer nodes will go
*/
- const char *max = crm_element_value(request, F_CIB_SCHEMA_MAX);
- const char *upgrade_rc = crm_element_value(request, F_CIB_UPGRADE_RC);
+ const char *max = crm_element_value(request, PCMK__XA_CIB_SCHEMA_MAX);
+ const char *upgrade_rc = crm_element_value(request,
+ PCMK__XA_CIB_UPGRADE_RC);
crm_trace("Parsing upgrade %s for %s with max=%s and upgrade_rc=%s",
(is_reply? "reply" : "request"),
@@ -802,7 +828,7 @@ parse_peer_options_v2(const cib__operation_t *operation, xmlNode *request,
if (upgrade_rc != NULL) {
// Our upgrade request was rejected by DC, notify clients of result
- crm_xml_add(request, F_CIB_RC, upgrade_rc);
+ crm_xml_add(request, PCMK__XA_CIB_RC, upgrade_rc);
} else if ((max == NULL) && based_is_primary) {
/* We are the DC, check if this upgrade is allowed */
@@ -817,7 +843,7 @@ parse_peer_options_v2(const cib__operation_t *operation, xmlNode *request,
return FALSE;
}
- } else if (pcmk__xe_attr_is_true(request, F_CIB_GLOBAL_UPDATE)) {
+ } else if (pcmk__xe_attr_is_true(request, PCMK__XA_CIB_UPDATE)) {
crm_info("Detected legacy %s global update from %s", op, originator);
send_sync_request(NULL);
legacy_mode = TRUE;
@@ -854,7 +880,7 @@ parse_peer_options_v2(const cib__operation_t *operation, xmlNode *request,
*local_notify = pcmk__str_eq(delegated, OUR_NODENAME, pcmk__str_casei);
- host = crm_element_value(request, F_CIB_HOST);
+ host = crm_element_value(request, PCMK__XA_CIB_HOST);
if (pcmk__str_eq(host, OUR_NODENAME, pcmk__str_casei)) {
crm_trace("Processing %s request sent to us from %s", op, originator);
*needs_reply = TRUE;
@@ -871,8 +897,10 @@ parse_peer_options_v2(const cib__operation_t *operation, xmlNode *request,
crm_trace("Processing %s request broadcast by %s call %s on %s "
"(local clients will%s be notified)", op,
- pcmk__s(crm_element_value(request, F_CIB_CLIENTNAME), "client"),
- pcmk__s(crm_element_value(request, F_CIB_CALLID), "without ID"),
+ pcmk__s(crm_element_value(request, PCMK__XA_CIB_CLIENTNAME),
+ "client"),
+ pcmk__s(crm_element_value(request, PCMK__XA_CIB_CALLID),
+ "without ID"),
originator, (*local_notify? "" : "not"));
return TRUE;
}
@@ -904,12 +932,14 @@ parse_peer_options(const cib__operation_t *operation, xmlNode *request,
static void
forward_request(xmlNode *request)
{
- const char *op = crm_element_value(request, F_CIB_OPERATION);
- const char *section = crm_element_value(request, F_CIB_SECTION);
- const char *host = crm_element_value(request, F_CIB_HOST);
- const char *originator = crm_element_value(request, F_ORIG);
- const char *client_name = crm_element_value(request, F_CIB_CLIENTNAME);
- const char *call_id = crm_element_value(request, F_CIB_CALLID);
+ const char *op = crm_element_value(request, PCMK__XA_CIB_OP);
+ const char *section = crm_element_value(request, PCMK__XA_CIB_SECTION);
+ const char *host = crm_element_value(request, PCMK__XA_CIB_HOST);
+ const char *originator = crm_element_value(request, PCMK__XA_SRC);
+ const char *client_name = crm_element_value(request,
+ PCMK__XA_CIB_CLIENTNAME);
+ const char *call_id = crm_element_value(request, PCMK__XA_CIB_CALLID);
+ crm_node_t *peer = NULL;
int log_level = LOG_INFO;
@@ -926,13 +956,15 @@ forward_request(xmlNode *request)
pcmk__s(client_name, "unspecified"),
pcmk__s(call_id, "unspecified"));
- crm_xml_add(request, F_CIB_DELEGATED, OUR_NODENAME);
+ crm_xml_add(request, PCMK__XA_CIB_DELEGATED_FROM, OUR_NODENAME);
- send_cluster_message(((host != NULL)? crm_get_peer(0, host) : NULL),
- crm_msg_cib, request, FALSE);
+ if (host != NULL) {
+ peer = pcmk__get_node(0, host, NULL, pcmk__node_search_cluster_member);
+ }
+ pcmk__cluster_send_message(peer, crm_msg_cib, request);
// Return the request to its original state
- xml_remove_prop(request, F_CIB_DELEGATED);
+ pcmk__xe_remove_attr(request, PCMK__XA_CIB_DELEGATED_FROM);
}
static gboolean
@@ -957,8 +989,10 @@ send_peer_reply(xmlNode * msg, xmlNode * result_diff, const char *originator, gb
const char *digest = NULL;
int format = 1;
+ xmlNode *wrapper = NULL;
+
CRM_LOG_ASSERT(result_diff != NULL);
- digest = crm_element_value(result_diff, XML_ATTR_DIGEST);
+ digest = crm_element_value(result_diff, PCMK__XA_DIGEST);
crm_element_value_int(result_diff, PCMK_XA_FORMAT, &format);
cib_diff_version_details(result_diff,
@@ -969,24 +1003,30 @@ send_peer_reply(xmlNode * msg, xmlNode * result_diff, const char *originator, gb
diff_del_admin_epoch, diff_del_epoch, diff_del_updates,
diff_add_admin_epoch, diff_add_epoch, diff_add_updates, digest);
- crm_xml_add(msg, F_CIB_ISREPLY, originator);
- pcmk__xe_set_bool_attr(msg, F_CIB_GLOBAL_UPDATE, true);
- crm_xml_add(msg, F_CIB_OPERATION, PCMK__CIB_REQUEST_APPLY_PATCH);
- crm_xml_add(msg, F_CIB_USER, CRM_DAEMON_USER);
+ crm_xml_add(msg, PCMK__XA_CIB_ISREPLYTO, originator);
+ pcmk__xe_set_bool_attr(msg, PCMK__XA_CIB_UPDATE, true);
+ crm_xml_add(msg, PCMK__XA_CIB_OP, PCMK__CIB_REQUEST_APPLY_PATCH);
+ crm_xml_add(msg, PCMK__XA_CIB_USER, CRM_DAEMON_USER);
if (format == 1) {
CRM_ASSERT(digest != NULL);
}
- add_message_xml(msg, F_CIB_UPDATE_DIFF, result_diff);
+ wrapper = pcmk__xe_create(msg, PCMK__XE_CIB_UPDATE_DIFF);
+ pcmk__xml_copy(wrapper, result_diff);
+
crm_log_xml_explicit(msg, "copy");
- return send_cluster_message(NULL, crm_msg_cib, msg, TRUE);
+ return pcmk__cluster_send_message(NULL, crm_msg_cib, msg);
} else if (originator != NULL) {
/* send reply via HA to originating node */
+ const crm_node_t *node =
+ pcmk__get_node(0, originator, NULL,
+ pcmk__node_search_cluster_member);
+
crm_trace("Sending request result to %s only", originator);
- crm_xml_add(msg, F_CIB_ISREPLY, originator);
- return send_cluster_message(crm_get_peer(0, originator), crm_msg_cib, msg, FALSE);
+ crm_xml_add(msg, PCMK__XA_CIB_ISREPLYTO, originator);
+ return pcmk__cluster_send_message(node, crm_msg_cib, msg);
}
return FALSE;
@@ -1020,19 +1060,20 @@ cib_process_request(xmlNode *request, gboolean privileged,
xmlNode *result_diff = NULL;
int rc = pcmk_ok;
- const char *op = crm_element_value(request, F_CIB_OPERATION);
- const char *originator = crm_element_value(request, F_ORIG);
- const char *host = crm_element_value(request, F_CIB_HOST);
+ const char *op = crm_element_value(request, PCMK__XA_CIB_OP);
+ const char *originator = crm_element_value(request, PCMK__XA_SRC);
+ const char *host = crm_element_value(request, PCMK__XA_CIB_HOST);
const char *target = NULL;
- const char *call_id = crm_element_value(request, F_CIB_CALLID);
- const char *client_id = crm_element_value(request, F_CIB_CLIENTID);
- const char *client_name = crm_element_value(request, F_CIB_CLIENTNAME);
- const char *reply_to = crm_element_value(request, F_CIB_ISREPLY);
+ const char *call_id = crm_element_value(request, PCMK__XA_CIB_CALLID);
+ const char *client_id = crm_element_value(request, PCMK__XA_CIB_CLIENTID);
+ const char *client_name = crm_element_value(request,
+ PCMK__XA_CIB_CLIENTNAME);
+ const char *reply_to = crm_element_value(request, PCMK__XA_CIB_ISREPLYTO);
const cib__operation_t *operation = NULL;
cib__op_fn_t op_function = NULL;
- crm_element_value_int(request, F_CIB_CALLOPTS, &call_options);
+ crm_element_value_int(request, PCMK__XA_CIB_CALLOPT, &call_options);
if ((host != NULL) && (*host == '\0')) {
host = NULL;
@@ -1053,7 +1094,7 @@ cib_process_request(xmlNode *request, gboolean privileged,
crm_trace("Processing peer %s operation from %s/%s on %s intended for %s (reply=%s)",
op, client_name, call_id, originator, target, reply_to);
} else {
- crm_xml_add(request, F_ORIG, OUR_NODENAME);
+ crm_xml_add(request, PCMK__XA_SRC, OUR_NODENAME);
crm_trace("Processing local %s operation from %s/%s intended for %s", op, client_name, call_id, target);
}
@@ -1124,7 +1165,10 @@ cib_process_request(xmlNode *request, gboolean privileged,
time_t finished = 0;
time_t now = time(NULL);
int level = LOG_INFO;
- const char *section = crm_element_value(request, F_CIB_SECTION);
+ const char *section = crm_element_value(request, PCMK__XA_CIB_SECTION);
+ const char *admin_epoch_s = NULL;
+ const char *epoch_s = NULL;
+ const char *num_updates_s = NULL;
rc = cib_process_command(request, operation, op_function, &op_reply,
&result_diff, privileged);
@@ -1132,7 +1176,7 @@ cib_process_request(xmlNode *request, gboolean privileged,
if (!is_update) {
level = LOG_TRACE;
- } else if (pcmk__xe_attr_is_true(request, F_CIB_GLOBAL_UPDATE)) {
+ } else if (pcmk__xe_attr_is_true(request, PCMK__XA_CIB_UPDATE)) {
switch (rc) {
case pcmk_ok:
level = LOG_INFO;
@@ -1150,13 +1194,19 @@ cib_process_request(xmlNode *request, gboolean privileged,
level = LOG_WARNING;
}
+ if (the_cib != NULL) {
+ admin_epoch_s = crm_element_value(the_cib, PCMK_XA_ADMIN_EPOCH);
+ epoch_s = crm_element_value(the_cib, PCMK_XA_EPOCH);
+ num_updates_s = crm_element_value(the_cib, PCMK_XA_NUM_UPDATES);
+ }
+
do_crm_log(level,
"Completed %s operation for section %s: %s (rc=%d, origin=%s/%s/%s, version=%s.%s.%s)",
op, section ? section : "'all'", pcmk_strerror(rc), rc,
originator ? originator : "local", client_name, call_id,
- the_cib ? crm_element_value(the_cib, XML_ATTR_GENERATION_ADMIN) : "0",
- the_cib ? crm_element_value(the_cib, XML_ATTR_GENERATION) : "0",
- the_cib ? crm_element_value(the_cib, XML_ATTR_NUMUPDATES) : "0");
+ pcmk__s(admin_epoch_s, "0"),
+ pcmk__s(epoch_s, "0"),
+ pcmk__s(num_updates_s, "0"));
finished = time(NULL);
if ((finished - now) > 3) {
@@ -1186,7 +1236,8 @@ cib_process_request(xmlNode *request, gboolean privileged,
gboolean broadcast = FALSE;
cib_local_bcast_num++;
- crm_xml_add_int(request, F_CIB_LOCAL_NOTIFY_ID, cib_local_bcast_num);
+ crm_xml_add_int(request, PCMK__XA_CIB_LOCAL_NOTIFY_ID,
+ cib_local_bcast_num);
broadcast = send_peer_reply(request, result_diff, originator, TRUE);
if (broadcast && client_id && local_notify && op_reply) {
@@ -1261,27 +1312,35 @@ static xmlNode *
prepare_input(const xmlNode *request, enum cib__op_type type,
const char **section)
{
+ xmlNode *wrapper = NULL;
xmlNode *input = NULL;
*section = NULL;
switch (type) {
case cib__op_apply_patch:
- if (pcmk__xe_attr_is_true(request, F_CIB_GLOBAL_UPDATE)) {
- input = get_message_xml(request, F_CIB_UPDATE_DIFF);
- } else {
- input = get_message_xml(request, F_CIB_CALLDATA);
+ {
+ const char *wrapper_name = PCMK__XE_CIB_CALLDATA;
+
+ if (pcmk__xe_attr_is_true(request, PCMK__XA_CIB_UPDATE)) {
+ wrapper_name = PCMK__XE_CIB_UPDATE_DIFF;
+ }
+ wrapper = pcmk__xe_first_child(request, wrapper_name, NULL,
+ NULL);
+ input = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
}
break;
default:
- input = get_message_xml(request, F_CIB_CALLDATA);
- *section = crm_element_value(request, F_CIB_SECTION);
+ wrapper = pcmk__xe_first_child(request, PCMK__XE_CIB_CALLDATA, NULL,
+ NULL);
+ input = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
+ *section = crm_element_value(request, PCMK__XA_CIB_SECTION);
break;
}
// Grab the specified section
- if ((*section != NULL) && pcmk__xe_is(input, XML_TAG_CIB)) {
+ if ((*section != NULL) && pcmk__xe_is(input, PCMK_XE_CIB)) {
input = pcmk_find_cib_element(input, *section);
}
@@ -1289,10 +1348,10 @@ prepare_input(const xmlNode *request, enum cib__op_type type,
}
// v1 and v2 patch formats
-#define XPATH_CONFIG_CHANGE \
- "//" XML_CIB_TAG_CRMCONFIG " | " \
- "//" XML_DIFF_CHANGE \
- "[contains(@" XML_DIFF_PATH ",'/" XML_CIB_TAG_CRMCONFIG "/')]"
+#define XPATH_CONFIG_CHANGE \
+ "//" PCMK_XE_CRM_CONFIG " | " \
+ "//" PCMK_XE_CHANGE \
+ "[contains(@" PCMK_XA_PATH ",'/" PCMK_XE_CRM_CONFIG "/')]"
static bool
contains_config_change(xmlNode *diff)
@@ -1323,10 +1382,11 @@ cib_process_command(xmlNode *request, const cib__operation_t *operation,
const char *op = NULL;
const char *section = NULL;
- const char *call_id = crm_element_value(request, F_CIB_CALLID);
- const char *client_id = crm_element_value(request, F_CIB_CLIENTID);
- const char *client_name = crm_element_value(request, F_CIB_CLIENTNAME);
- const char *originator = crm_element_value(request, F_ORIG);
+ const char *call_id = crm_element_value(request, PCMK__XA_CIB_CALLID);
+ const char *client_id = crm_element_value(request, PCMK__XA_CIB_CLIENTID);
+ const char *client_name = crm_element_value(request,
+ PCMK__XA_CIB_CLIENTNAME);
+ const char *originator = crm_element_value(request, PCMK__XA_SRC);
int rc = pcmk_ok;
@@ -1345,8 +1405,8 @@ cib_process_command(xmlNode *request, const cib__operation_t *operation,
*cib_diff = NULL;
/* Start processing the request... */
- op = crm_element_value(request, F_CIB_OPERATION);
- crm_element_value_int(request, F_CIB_CALLOPTS, &call_options);
+ op = crm_element_value(request, PCMK__XA_CIB_OP);
+ crm_element_value_int(request, PCMK__XA_CIB_CALLOPT, &call_options);
if (!privileged && pcmk_is_set(operation->flags, cib__op_attr_privileged)) {
rc = -EACCES;
@@ -1357,7 +1417,7 @@ cib_process_command(xmlNode *request, const cib__operation_t *operation,
input = prepare_input(request, operation->type, &section);
if (!pcmk_is_set(operation->flags, cib__op_attr_modifies)) {
- rc = cib_perform_op(op, call_options, op_function, true, section,
+ rc = cib_perform_op(NULL, op, call_options, op_function, true, section,
request, input, false, &config_changed, &the_cib,
&result_cib, NULL, &output);
@@ -1368,11 +1428,11 @@ cib_process_command(xmlNode *request, const cib__operation_t *operation,
/* @COMPAT: Handle a valid write action (legacy)
*
* @TODO: Re-evaluate whether this is all truly legacy. The cib_force_diff
- * portion is. However, F_CIB_GLOBAL_UPDATE may be set by a sync operation
+ * portion is. However, PCMK__XA_CIB_UPDATE may be set by a sync operation
* even in non-legacy mode, and manage_counters tells xml_create_patchset()
* whether to update version/epoch info.
*/
- if (pcmk__xe_attr_is_true(request, F_CIB_GLOBAL_UPDATE)) {
+ if (pcmk__xe_attr_is_true(request, PCMK__XA_CIB_UPDATE)) {
manage_counters = false;
cib__set_call_options(call_options, "call", cib_force_diff);
crm_trace("Global update detected");
@@ -1390,7 +1450,7 @@ cib_process_command(xmlNode *request, const cib__operation_t *operation,
}
// result_cib must not be modified after cib_perform_op() returns
- rc = cib_perform_op(op, call_options, op_function, false, section,
+ rc = cib_perform_op(NULL, op, call_options, op_function, false, section,
request, input, manage_counters, &config_changed,
&the_cib, &result_cib, cib_diff, &output);
@@ -1426,8 +1486,8 @@ cib_process_command(xmlNode *request, const cib__operation_t *operation,
}
crm_trace("Activating %s->%s%s",
- crm_element_value(the_cib, XML_ATTR_NUMUPDATES),
- crm_element_value(result_cib, XML_ATTR_NUMUPDATES),
+ crm_element_value(the_cib, PCMK_XA_NUM_UPDATES),
+ crm_element_value(result_cib, PCMK_XA_NUM_UPDATES),
(config_changed? " changed" : ""));
rc = activateCibXml(result_cib, config_changed, op);
@@ -1451,7 +1511,8 @@ cib_process_command(xmlNode *request, const cib__operation_t *operation,
*/
if ((operation->type == cib__op_commit_transact)
&& pcmk__str_eq(originator, OUR_NODENAME, pcmk__str_casei)
- && compare_version(crm_element_value(the_cib, XML_ATTR_CRM_VERSION),
+ && compare_version(crm_element_value(the_cib,
+ PCMK_XA_CRM_FEATURE_SET),
"3.19.0") < 0) {
sync_our_cib(request, TRUE);
@@ -1473,7 +1534,7 @@ cib_process_command(xmlNode *request, const cib__operation_t *operation,
} else {
crm_trace("Not activating %d %d %s", rc,
pcmk_is_set(call_options, cib_dryrun),
- crm_element_value(result_cib, XML_ATTR_NUMUPDATES));
+ crm_element_value(result_cib, PCMK_XA_NUM_UPDATES));
if (result_cib != the_cib) {
free_xml(result_cib);
@@ -1507,7 +1568,7 @@ void
cib_peer_callback(xmlNode * msg, void *private_data)
{
const char *reason = NULL;
- const char *originator = crm_element_value(msg, F_ORIG);
+ const char *originator = crm_element_value(msg, PCMK__XA_SRC);
if (cib_legacy_mode()
&& pcmk__str_eq(originator, OUR_NODENAME,
@@ -1515,7 +1576,8 @@ cib_peer_callback(xmlNode * msg, void *private_data)
/* message is from ourselves */
int bcast_id = 0;
- if (!(crm_element_value_int(msg, F_CIB_LOCAL_NOTIFY_ID, &bcast_id))) {
+ if (crm_element_value_int(msg, PCMK__XA_CIB_LOCAL_NOTIFY_ID,
+ &bcast_id) == 0) {
check_local_notify(bcast_id);
}
return;
@@ -1525,8 +1587,8 @@ cib_peer_callback(xmlNode * msg, void *private_data)
goto bail;
}
- if (crm_element_value(msg, F_CIB_CLIENTNAME) == NULL) {
- crm_xml_add(msg, F_CIB_CLIENTNAME, originator);
+ if (crm_element_value(msg, PCMK__XA_CIB_CLIENTNAME) == NULL) {
+ crm_xml_add(msg, PCMK__XA_CIB_CLIENTNAME, originator);
}
/* crm_log_xml_trace(msg, "Peer[inbound]"); */
@@ -1535,10 +1597,9 @@ cib_peer_callback(xmlNode * msg, void *private_data)
bail:
if (reason) {
- const char *seq = crm_element_value(msg, F_SEQ);
- const char *op = crm_element_value(msg, F_CIB_OPERATION);
+ const char *op = crm_element_value(msg, PCMK__XA_CIB_OP);
- crm_warn("Discarding %s message (%s) from %s: %s", op, seq, originator, reason);
+ crm_warn("Discarding %s message from %s: %s", op, originator, reason);
}
}
@@ -1565,7 +1626,7 @@ initiate_exit(void)
int active = 0;
xmlNode *leaving = NULL;
- active = crm_active_peers();
+ active = pcmk__cluster_num_active_nodes();
if (active < 2) { // This is the last active node
terminate_cib(__func__, 0);
return;
@@ -1573,11 +1634,11 @@ initiate_exit(void)
crm_info("Sending shutdown request to %d peers", active);
- leaving = create_xml_node(NULL, "exit-notification");
- crm_xml_add(leaving, F_TYPE, "cib");
- crm_xml_add(leaving, F_CIB_OPERATION, PCMK__CIB_REQUEST_SHUTDOWN);
+ leaving = pcmk__xe_create(NULL, PCMK__XE_EXIT_NOTIFICATION);
+ crm_xml_add(leaving, PCMK__XA_T, PCMK__VALUE_CIB);
+ crm_xml_add(leaving, PCMK__XA_CIB_OP, PCMK__CIB_REQUEST_SHUTDOWN);
- send_cluster_message(NULL, crm_msg_cib, leaving, TRUE);
+ pcmk__cluster_send_message(NULL, crm_msg_cib, leaving);
free_xml(leaving);
g_timeout_add(EXIT_ESCALATION_MS, cib_force_exit, NULL);
@@ -1688,14 +1749,14 @@ terminate_cib(const char *caller, int fast)
* peer caches).
*/
if (fast == 0) {
- crm_cluster_disconnect(crm_cluster);
+ pcmk_cluster_disconnect(crm_cluster);
}
g_main_loop_quit(mainloop);
} else {
/* Quit via clean exit. Even the peer status callback can disconnect
* here, because we're not returning control to the caller. */
- crm_cluster_disconnect(crm_cluster);
+ pcmk_cluster_disconnect(crm_cluster);
pcmk__stop_based_ipc(ipcs_ro, ipcs_rw, ipcs_shm);
crm_exit(CRM_EX_OK);
}
diff --git a/daemons/based/based_io.c b/daemons/based/based_io.c
index f252ac1..7410b03 100644
--- a/daemons/based/based_io.c
+++ b/daemons/based/based_io.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.
*
@@ -29,7 +29,6 @@
#include <crm/cib.h>
#include <crm/common/util.h>
-#include <crm/msg_xml.h>
#include <crm/common/xml.h>
#include <crm/cib/internal.h>
#include <crm/cluster.h>
@@ -258,20 +257,20 @@ readCibXmlFile(const char *dir, const char *file, gboolean discard_status)
crm_err("*** Disabling disk writes to avoid confusing Valgrind ***");
}
- status = find_xml_node(root, XML_CIB_TAG_STATUS, FALSE);
+ status = pcmk__xe_first_child(root, PCMK_XE_STATUS, NULL, NULL);
if (discard_status && status != NULL) {
- /* strip out the status section if there is one */
+ // Strip out the PCMK_XE_STATUS section if there is one
free_xml(status);
status = NULL;
}
if (status == NULL) {
- create_xml_node(root, XML_CIB_TAG_STATUS);
+ pcmk__xe_create(root, PCMK_XE_STATUS);
}
/* Do this before schema validation happens */
/* fill in some defaults */
- name = XML_ATTR_GENERATION_ADMIN;
+ name = PCMK_XA_ADMIN_EPOCH;
value = crm_element_value(root, name);
if (value == NULL) {
crm_warn("No value for %s was specified in the configuration.", name);
@@ -283,38 +282,38 @@ readCibXmlFile(const char *dir, const char *file, gboolean discard_status)
crm_xml_add_int(root, name, 0);
}
- name = XML_ATTR_GENERATION;
+ name = PCMK_XA_EPOCH;
value = crm_element_value(root, name);
if (value == NULL) {
crm_xml_add_int(root, name, 0);
}
- name = XML_ATTR_NUMUPDATES;
+ name = PCMK_XA_NUM_UPDATES;
value = crm_element_value(root, name);
if (value == NULL) {
crm_xml_add_int(root, name, 0);
}
// Unset (DC should set appropriate value)
- xml_remove_prop(root, XML_ATTR_DC_UUID);
+ pcmk__xe_remove_attr(root, PCMK_XA_DC_UUID);
if (discard_status) {
crm_log_xml_trace(root, "[on-disk]");
}
- validation = crm_element_value(root, XML_ATTR_VALIDATION);
- if (validate_xml(root, NULL, TRUE) == FALSE) {
+ validation = crm_element_value(root, PCMK_XA_VALIDATE_WITH);
+ if (!pcmk__configured_schema_validates(root)) {
crm_err("CIB does not validate with %s",
pcmk__s(validation, "no schema specified"));
cib_status = -pcmk_err_schema_validation;
+ // @COMPAT Not specifying validate-with is deprecated since 2.1.8
} else if (validation == NULL) {
- int version = 0;
-
- update_validation(&root, &version, 0, FALSE, FALSE);
- if (version > 0) {
+ pcmk__update_schema(&root, NULL, false, false);
+ validation = crm_element_value(root, PCMK_XA_VALIDATE_WITH);
+ if (validation != NULL) {
crm_notice("Enabling %s validation on"
- " the existing (sane) configuration", get_schema_name(version));
+ " the existing (sane) configuration", validation);
} else {
crm_err("CIB does not validate with any known schema");
cib_status = -pcmk_err_schema_validation;
@@ -408,7 +407,7 @@ write_cib_contents(gpointer p)
/* Make a copy of the CIB to write (possibly in a forked child) */
if (p) {
/* Synchronous write out */
- cib_local = copy_xml(p);
+ cib_local = pcmk__xml_copy(NULL, p);
} else {
int pid = 0;
@@ -445,7 +444,7 @@ write_cib_contents(gpointer p)
/* In theory, we can scribble on the_cib here and not affect the parent,
* but let's be safe anyway.
*/
- cib_local = copy_xml(the_cib);
+ cib_local = pcmk__xml_copy(NULL, the_cib);
}
/* Write the CIB */
diff --git a/daemons/based/based_messages.c b/daemons/based/based_messages.c
index 35d639a..87b7eb1 100644
--- a/daemons/based/based_messages.c
+++ b/daemons/based/based_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.
*
@@ -24,7 +24,6 @@
#include <crm/crm.h>
#include <crm/cib/internal.h>
-#include <crm/msg_xml.h>
#include <crm/common/xml.h>
#include <crm/common/ipc_internal.h>
@@ -45,11 +44,11 @@ cib_process_shutdown_req(const char *op, int options, const char *section, xmlNo
xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
xmlNode ** answer)
{
- const char *host = crm_element_value(req, F_ORIG);
+ const char *host = crm_element_value(req, PCMK__XA_SRC);
*answer = NULL;
- if (crm_element_value(req, F_CIB_ISREPLY) == NULL) {
+ if (crm_element_value(req, PCMK__XA_CIB_ISREPLYTO) == NULL) {
crm_info("Peer %s is requesting to shut down", host);
return pcmk_ok;
}
@@ -117,17 +116,21 @@ static int sync_in_progress = 0;
void
send_sync_request(const char *host)
{
- xmlNode *sync_me = create_xml_node(NULL, "sync-me");
+ xmlNode *sync_me = pcmk__xe_create(NULL, "sync-me");
+ crm_node_t *peer = NULL;
crm_info("Requesting re-sync from %s", (host? host : "all peers"));
sync_in_progress = 1;
- crm_xml_add(sync_me, F_TYPE, "cib");
- crm_xml_add(sync_me, F_CIB_OPERATION, PCMK__CIB_REQUEST_SYNC_TO_ONE);
- crm_xml_add(sync_me, F_CIB_DELEGATED,
+ crm_xml_add(sync_me, PCMK__XA_T, PCMK__VALUE_CIB);
+ crm_xml_add(sync_me, PCMK__XA_CIB_OP, PCMK__CIB_REQUEST_SYNC_TO_ONE);
+ crm_xml_add(sync_me, PCMK__XA_CIB_DELEGATED_FROM,
stand_alone? "localhost" : crm_cluster->uname);
- send_cluster_message(host ? crm_get_peer(0, host) : NULL, crm_msg_cib, sync_me, FALSE);
+ if (host != NULL) {
+ peer = pcmk__get_node(0, host, NULL, pcmk__node_search_cluster_member);
+ }
+ pcmk__cluster_send_message(peer, crm_msg_cib, sync_me);
free_xml(sync_me);
}
@@ -135,38 +138,44 @@ int
cib_process_ping(const char *op, int options, const char *section, xmlNode * req, xmlNode * input,
xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
{
- const char *host = crm_element_value(req, F_ORIG);
- const char *seq = crm_element_value(req, F_CIB_PING_ID);
+ const char *host = crm_element_value(req, PCMK__XA_SRC);
+ const char *seq = crm_element_value(req, PCMK__XA_CIB_PING_ID);
char *digest = calculate_xml_versioned_digest(the_cib, FALSE, TRUE, CRM_FEATURE_SET);
+ xmlNode *wrapper = NULL;
+
crm_trace("Processing \"%s\" event %s from %s", op, seq, host);
- *answer = create_xml_node(NULL, XML_CRM_TAG_PING);
-
- crm_xml_add(*answer, XML_ATTR_CRM_VERSION, CRM_FEATURE_SET);
- crm_xml_add(*answer, XML_ATTR_DIGEST, digest);
- crm_xml_add(*answer, F_CIB_PING_ID, seq);
-
- pcmk__if_tracing(
- {
- // Append additional detail so the receiver can log the differences
- add_message_xml(*answer, F_CIB_CALLDATA, the_cib);
- },
- if (the_cib != NULL) {
- // Always include at least the version details
- xmlNode *shallow = create_xml_node(NULL,
- (const char *) the_cib->name);
-
- copy_in_properties(shallow, the_cib);
- add_message_xml(*answer, F_CIB_CALLDATA, shallow);
- free_xml(shallow);
- }
- );
+ *answer = pcmk__xe_create(NULL, PCMK__XE_PING_RESPONSE);
+
+ crm_xml_add(*answer, PCMK_XA_CRM_FEATURE_SET, CRM_FEATURE_SET);
+ crm_xml_add(*answer, PCMK__XA_DIGEST, digest);
+ crm_xml_add(*answer, PCMK__XA_CIB_PING_ID, seq);
+
+ wrapper = pcmk__xe_create(*answer, PCMK__XE_CIB_CALLDATA);
+
+ if (the_cib != NULL) {
+ pcmk__if_tracing(
+ {
+ /* Append additional detail so the receiver can log the
+ * differences
+ */
+ pcmk__xml_copy(wrapper, the_cib);
+ },
+ {
+ // Always include at least the version details
+ const char *name = (const char *) the_cib->name;
+ xmlNode *shallow = pcmk__xe_create(wrapper, name);
+
+ pcmk__xe_copy_attrs(shallow, the_cib, pcmk__xaf_none);
+ }
+ );
+ }
crm_info("Reporting our current digest to %s: %s for %s.%s.%s",
host, digest,
- crm_element_value(existing_cib, XML_ATTR_GENERATION_ADMIN),
- crm_element_value(existing_cib, XML_ATTR_GENERATION),
- crm_element_value(existing_cib, XML_ATTR_NUMUPDATES));
+ crm_element_value(existing_cib, PCMK_XA_ADMIN_EPOCH),
+ crm_element_value(existing_cib, PCMK_XA_EPOCH),
+ crm_element_value(existing_cib, PCMK_XA_NUM_UPDATES));
free(digest);
@@ -188,51 +197,51 @@ cib_process_upgrade_server(const char *op, int options, const char *section, xml
*answer = NULL;
- if(crm_element_value(req, F_CIB_SCHEMA_MAX)) {
+ if (crm_element_value(req, PCMK__XA_CIB_SCHEMA_MAX) != NULL) {
/* The originator of an upgrade request sends it to the DC, without
- * F_CIB_SCHEMA_MAX. If an upgrade is needed, the DC re-broadcasts the
- * request with F_CIB_SCHEMA_MAX, and each node performs the upgrade
- * (and notifies its local clients) here.
+ * PCMK__XA_CIB_SCHEMA_MAX. If an upgrade is needed, the DC
+ * re-broadcasts the request with PCMK__XA_CIB_SCHEMA_MAX, and each node
+ * performs the upgrade (and notifies its local clients) here.
*/
return cib_process_upgrade(
op, options, section, req, input, existing_cib, result_cib, answer);
} else {
- int new_version = 0;
- int current_version = 0;
- xmlNode *scratch = copy_xml(existing_cib);
- const char *host = crm_element_value(req, F_ORIG);
- const char *value = crm_element_value(existing_cib, XML_ATTR_VALIDATION);
- const char *client_id = crm_element_value(req, F_CIB_CLIENTID);
- const char *call_opts = crm_element_value(req, F_CIB_CALLOPTS);
- const char *call_id = crm_element_value(req, F_CIB_CALLID);
+ xmlNode *scratch = pcmk__xml_copy(NULL, existing_cib);
+ const char *host = crm_element_value(req, PCMK__XA_SRC);
+ const char *original_schema = NULL;
+ const char *new_schema = NULL;
+ const char *client_id = crm_element_value(req, PCMK__XA_CIB_CLIENTID);
+ const char *call_opts = crm_element_value(req, PCMK__XA_CIB_CALLOPT);
+ const char *call_id = crm_element_value(req, PCMK__XA_CIB_CALLID);
crm_trace("Processing \"%s\" event", op);
- if (value != NULL) {
- current_version = get_schema_version(value);
- }
+ original_schema = crm_element_value(existing_cib,
+ PCMK_XA_VALIDATE_WITH);
+ rc = pcmk__update_schema(&scratch, NULL, true, true);
+ rc = pcmk_rc2legacy(rc);
+ new_schema = crm_element_value(scratch, PCMK_XA_VALIDATE_WITH);
- rc = update_validation(&scratch, &new_version, 0, TRUE, TRUE);
- if (new_version > current_version) {
- xmlNode *up = create_xml_node(NULL, __func__);
+ if (pcmk__cmp_schemas_by_name(new_schema, original_schema) > 0) {
+ xmlNode *up = pcmk__xe_create(NULL, __func__);
rc = pcmk_ok;
crm_notice("Upgrade request from %s verified", host);
- crm_xml_add(up, F_TYPE, "cib");
- crm_xml_add(up, F_CIB_OPERATION, PCMK__CIB_REQUEST_UPGRADE);
- crm_xml_add(up, F_CIB_SCHEMA_MAX, get_schema_name(new_version));
- crm_xml_add(up, F_CIB_DELEGATED, host);
- crm_xml_add(up, F_CIB_CLIENTID, client_id);
- crm_xml_add(up, F_CIB_CALLOPTS, call_opts);
- crm_xml_add(up, F_CIB_CALLID, call_id);
+ crm_xml_add(up, PCMK__XA_T, PCMK__VALUE_CIB);
+ crm_xml_add(up, PCMK__XA_CIB_OP, PCMK__CIB_REQUEST_UPGRADE);
+ crm_xml_add(up, PCMK__XA_CIB_SCHEMA_MAX, new_schema);
+ crm_xml_add(up, PCMK__XA_CIB_DELEGATED_FROM, host);
+ crm_xml_add(up, PCMK__XA_CIB_CLIENTID, client_id);
+ crm_xml_add(up, PCMK__XA_CIB_CALLOPT, call_opts);
+ crm_xml_add(up, PCMK__XA_CIB_CALLID, call_id);
if (cib_legacy_mode() && based_is_primary) {
rc = cib_process_upgrade(
op, options, section, up, input, existing_cib, result_cib, answer);
} else {
- send_cluster_message(NULL, crm_msg_cib, up, FALSE);
+ pcmk__cluster_send_message(NULL, crm_msg_cib, up);
}
free_xml(up);
@@ -243,25 +252,27 @@ cib_process_upgrade_server(const char *op, int options, const char *section, xml
if (rc != pcmk_ok) {
// Notify originating peer so it can notify its local clients
- crm_node_t *origin = pcmk__search_cluster_node_cache(0, host, NULL);
+ crm_node_t *origin = NULL;
+
+ origin = pcmk__search_node_caches(0, host,
+ pcmk__node_search_cluster_member);
crm_info("Rejecting upgrade request from %s: %s "
CRM_XS " rc=%d peer=%s", host, pcmk_strerror(rc), rc,
(origin? origin->uname : "lost"));
if (origin) {
- xmlNode *up = create_xml_node(NULL, __func__);
-
- crm_xml_add(up, F_TYPE, "cib");
- crm_xml_add(up, F_CIB_OPERATION, PCMK__CIB_REQUEST_UPGRADE);
- crm_xml_add(up, F_CIB_DELEGATED, host);
- crm_xml_add(up, F_CIB_ISREPLY, host);
- crm_xml_add(up, F_CIB_CLIENTID, client_id);
- crm_xml_add(up, F_CIB_CALLOPTS, call_opts);
- crm_xml_add(up, F_CIB_CALLID, call_id);
- crm_xml_add_int(up, F_CIB_UPGRADE_RC, rc);
- if (send_cluster_message(origin, crm_msg_cib, up, TRUE)
- == FALSE) {
+ xmlNode *up = pcmk__xe_create(NULL, __func__);
+
+ crm_xml_add(up, PCMK__XA_T, PCMK__VALUE_CIB);
+ crm_xml_add(up, PCMK__XA_CIB_OP, PCMK__CIB_REQUEST_UPGRADE);
+ crm_xml_add(up, PCMK__XA_CIB_DELEGATED_FROM, host);
+ crm_xml_add(up, PCMK__XA_CIB_ISREPLYTO, host);
+ crm_xml_add(up, PCMK__XA_CIB_CLIENTID, client_id);
+ crm_xml_add(up, PCMK__XA_CIB_CALLOPT, call_opts);
+ crm_xml_add(up, PCMK__XA_CIB_CALLID, call_id);
+ crm_xml_add_int(up, PCMK__XA_CIB_UPGRADE_RC, rc);
+ if (!pcmk__cluster_send_message(origin, crm_msg_cib, up)) {
crm_warn("Could not send CIB upgrade result to %s", host);
}
free_xml(up);
@@ -351,7 +362,7 @@ cib_process_replace_svr(const char *op, int options, const char *section, xmlNod
int rc =
cib_process_replace(op, options, section, req, input, existing_cib, result_cib, answer);
- if ((rc == pcmk_ok) && pcmk__xe_is(input, XML_TAG_CIB)) {
+ if ((rc == pcmk_ok) && pcmk__xe_is(input, PCMK_XE_CIB)) {
sync_in_progress = 0;
}
return rc;
@@ -370,32 +381,26 @@ static xmlNode *
cib_msg_copy(xmlNode *msg)
{
static const char *field_list[] = {
- F_XML_TAGNAME,
- F_TYPE,
- F_CIB_CLIENTID,
- F_CIB_CALLOPTS,
- F_CIB_CALLID,
- F_CIB_OPERATION,
- F_CIB_ISREPLY,
- F_CIB_SECTION,
- F_CIB_HOST,
- F_CIB_RC,
- F_CIB_DELEGATED,
- F_CIB_OBJID,
- F_CIB_OBJTYPE,
- F_CIB_EXISTING,
- F_CIB_SEENCOUNT,
- F_CIB_TIMEOUT,
- F_CIB_GLOBAL_UPDATE,
- F_CIB_CLIENTNAME,
- F_CIB_USER,
- F_CIB_NOTIFY_TYPE,
- F_CIB_NOTIFY_ACTIVATE
+ PCMK__XA_T,
+ PCMK__XA_CIB_CLIENTID,
+ PCMK__XA_CIB_CALLOPT,
+ PCMK__XA_CIB_CALLID,
+ PCMK__XA_CIB_OP,
+ PCMK__XA_CIB_ISREPLYTO,
+ PCMK__XA_CIB_SECTION,
+ PCMK__XA_CIB_HOST,
+ PCMK__XA_CIB_RC,
+ PCMK__XA_CIB_DELEGATED_FROM,
+ PCMK__XA_CIB_OBJECT,
+ PCMK__XA_CIB_OBJECT_TYPE,
+ PCMK__XA_CIB_UPDATE,
+ PCMK__XA_CIB_CLIENTNAME,
+ PCMK__XA_CIB_USER,
+ PCMK__XA_CIB_NOTIFY_TYPE,
+ PCMK__XA_CIB_NOTIFY_ACTIVATE,
};
- xmlNode *copy = create_xml_node(NULL, "copy");
-
- CRM_ASSERT(copy != NULL);
+ xmlNode *copy = pcmk__xe_create(NULL, PCMK__XE_COPY);
for (int lpc = 0; lpc < PCMK__NELEM(field_list); lpc++) {
const char *field = field_list[lpc];
@@ -414,10 +419,11 @@ sync_our_cib(xmlNode * request, gboolean all)
{
int result = pcmk_ok;
char *digest = NULL;
- const char *host = crm_element_value(request, F_ORIG);
- const char *op = crm_element_value(request, F_CIB_OPERATION);
-
+ const char *host = crm_element_value(request, PCMK__XA_SRC);
+ const char *op = crm_element_value(request, PCMK__XA_CIB_OP);
+ crm_node_t *peer = NULL;
xmlNode *replace_request = NULL;
+ xmlNode *wrapper = NULL;
CRM_CHECK(the_cib != NULL, return -EINVAL);
CRM_CHECK(all || (host != NULL), return -EINVAL);
@@ -427,24 +433,30 @@ sync_our_cib(xmlNode * request, gboolean all)
replace_request = cib_msg_copy(request);
if (host != NULL) {
- crm_xml_add(replace_request, F_CIB_ISREPLY, host);
+ crm_xml_add(replace_request, PCMK__XA_CIB_ISREPLYTO, host);
}
if (all) {
- xml_remove_prop(replace_request, F_CIB_HOST);
+ pcmk__xe_remove_attr(replace_request, PCMK__XA_CIB_HOST);
}
- crm_xml_add(replace_request, F_CIB_OPERATION, PCMK__CIB_REQUEST_REPLACE);
- crm_xml_add(replace_request, "original_" F_CIB_OPERATION, op);
- pcmk__xe_set_bool_attr(replace_request, F_CIB_GLOBAL_UPDATE, true);
+ crm_xml_add(replace_request, PCMK__XA_CIB_OP, PCMK__CIB_REQUEST_REPLACE);
+
+ // @TODO Keep for tracing, or drop?
+ crm_xml_add(replace_request, PCMK__XA_ORIGINAL_CIB_OP, op);
+
+ pcmk__xe_set_bool_attr(replace_request, PCMK__XA_CIB_UPDATE, true);
- crm_xml_add(replace_request, XML_ATTR_CRM_VERSION, CRM_FEATURE_SET);
+ crm_xml_add(replace_request, PCMK_XA_CRM_FEATURE_SET, CRM_FEATURE_SET);
digest = calculate_xml_versioned_digest(the_cib, FALSE, TRUE, CRM_FEATURE_SET);
- crm_xml_add(replace_request, XML_ATTR_DIGEST, digest);
+ crm_xml_add(replace_request, PCMK__XA_DIGEST, digest);
- add_message_xml(replace_request, F_CIB_CALLDATA, the_cib);
+ wrapper = pcmk__xe_create(replace_request, PCMK__XE_CIB_CALLDATA);
+ pcmk__xml_copy(wrapper, the_cib);
- if (send_cluster_message
- (all ? NULL : crm_get_peer(0, host), crm_msg_cib, replace_request, FALSE) == FALSE) {
+ if (!all) {
+ peer = pcmk__get_node(0, host, NULL, pcmk__node_search_cluster_member);
+ }
+ if (!pcmk__cluster_send_message(peer, crm_msg_cib, replace_request)) {
result = -ENOTCONN;
}
free_xml(replace_request);
@@ -463,8 +475,8 @@ cib_process_commit_transaction(const char *op, int options, const char *section,
* On failure, our caller will free *result_cib.
*/
int rc = pcmk_rc_ok;
- const char *client_id = crm_element_value(req, F_CIB_CLIENTID);
- const char *origin = crm_element_value(req, F_ORIG);
+ const char *client_id = crm_element_value(req, PCMK__XA_CIB_CLIENTID);
+ const char *origin = crm_element_value(req, PCMK__XA_SRC);
pcmk__client_t *client = pcmk__find_client_by_id(client_id);
rc = based_commit_transaction(input, client, origin, result_cib);
@@ -478,3 +490,49 @@ cib_process_commit_transaction(const char *op, int options, const char *section,
}
return pcmk_rc2legacy(rc);
}
+
+int
+cib_process_schemas(const char *op, int options, const char *section, xmlNode *req,
+ xmlNode *input, xmlNode *existing_cib, xmlNode **result_cib,
+ xmlNode **answer)
+{
+ xmlNode *wrapper = NULL;
+ xmlNode *data = NULL;
+
+ const char *after_ver = NULL;
+ GList *schemas = NULL;
+ GList *already_included = NULL;
+
+ *answer = pcmk__xe_create(NULL, PCMK__XA_SCHEMAS);
+
+ wrapper = pcmk__xe_first_child(req, PCMK__XE_CIB_CALLDATA, NULL, NULL);
+ data = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
+ if (data == NULL) {
+ crm_warn("No data specified in request");
+ return -EPROTO;
+ }
+
+ after_ver = crm_element_value(data, PCMK_XA_VERSION);
+ if (after_ver == NULL) {
+ crm_warn("No version specified in request");
+ return -EPROTO;
+ }
+
+ /* The client requested all schemas after the latest one we know about, which
+ * means the client is fully up-to-date. Return a properly formatted reply
+ * with no schemas.
+ */
+ if (pcmk__str_eq(after_ver, pcmk__highest_schema_name(), pcmk__str_none)) {
+ return pcmk_ok;
+ }
+
+ schemas = pcmk__schema_files_later_than(after_ver);
+
+ for (GList *iter = schemas; iter != NULL; iter = iter->next) {
+ pcmk__build_schema_xml_node(*answer, iter->data, &already_included);
+ }
+
+ g_list_free_full(schemas, free);
+ g_list_free_full(already_included, free);
+ return pcmk_ok;
+}
diff --git a/daemons/based/based_notify.c b/daemons/based/based_notify.c
index 00a4c54..5160645 100644
--- a/daemons/based/based_notify.c
+++ b/daemons/based/based_notify.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.
*
@@ -26,7 +26,6 @@
#include <crm/crm.h>
#include <crm/cib/internal.h>
-#include <crm/msg_xml.h>
#include <crm/common/xml.h>
#include <crm/common/remote_internal.h>
@@ -53,25 +52,27 @@ cib_notify_send_one(gpointer key, gpointer value, gpointer user_data)
return;
}
- type = crm_element_value(update->msg, F_SUBTYPE);
+ type = crm_element_value(update->msg, PCMK__XA_SUBT);
CRM_LOG_ASSERT(type != NULL);
if (pcmk_is_set(client->flags, cib_notify_diff)
- && pcmk__str_eq(type, T_CIB_DIFF_NOTIFY, pcmk__str_casei)) {
+ && pcmk__str_eq(type, PCMK__VALUE_CIB_DIFF_NOTIFY, pcmk__str_none)) {
do_send = TRUE;
} else if (pcmk_is_set(client->flags, cib_notify_confirm)
- && pcmk__str_eq(type, T_CIB_UPDATE_CONFIRM, pcmk__str_casei)) {
+ && pcmk__str_eq(type, PCMK__VALUE_CIB_UPDATE_CONFIRMATION,
+ pcmk__str_none)) {
do_send = TRUE;
} else if (pcmk_is_set(client->flags, cib_notify_pre)
- && pcmk__str_eq(type, T_CIB_PRE_NOTIFY, pcmk__str_casei)) {
+ && pcmk__str_eq(type, PCMK__VALUE_CIB_PRE_NOTIFY,
+ pcmk__str_none)) {
do_send = TRUE;
} else if (pcmk_is_set(client->flags, cib_notify_post)
- && pcmk__str_eq(type, T_CIB_POST_NOTIFY, pcmk__str_casei)) {
-
+ && pcmk__str_eq(type, PCMK__VALUE_CIB_POST_NOTIFY,
+ pcmk__str_none)) {
do_send = TRUE;
}
@@ -125,15 +126,14 @@ cib_notify_send(const xmlNode *xml)
}
static void
-attach_cib_generation(xmlNode *msg, const char *field, xmlNode *a_cib)
+attach_cib_generation(xmlNode *msg)
{
- xmlNode *generation = create_xml_node(NULL, XML_CIB_TAG_GENERATION_TUPPLE);
+ xmlNode *wrapper = pcmk__xe_create(msg, PCMK__XE_CIB_GENERATION);
+ xmlNode *generation = pcmk__xe_create(wrapper, PCMK__XE_GENERATION_TUPLE);
- if (a_cib != NULL) {
- copy_in_properties(generation, a_cib);
+ if (the_cib != NULL) {
+ pcmk__xe_copy_attrs(generation, the_cib, pcmk__xaf_none);
}
- add_message_xml(msg, field, generation);
- free_xml(generation);
}
void
@@ -152,6 +152,7 @@ cib_diff_notify(const char *op, int result, const char *call_id,
uint8_t log_level = LOG_TRACE;
xmlNode *update_msg = NULL;
+ xmlNode *wrapper = NULL;
const char *type = NULL;
if (diff == NULL) {
@@ -191,17 +192,18 @@ cib_diff_notify(const char *op, int result, const char *call_id,
pcmk__s(origin, "unspecified peer"), pcmk_strerror(result));
}
- update_msg = create_xml_node(NULL, "notify");
+ update_msg = pcmk__xe_create(NULL, PCMK__XE_NOTIFY);
- crm_xml_add(update_msg, F_TYPE, T_CIB_NOTIFY);
- crm_xml_add(update_msg, F_SUBTYPE, T_CIB_DIFF_NOTIFY);
- crm_xml_add(update_msg, F_CIB_OPERATION, op);
- crm_xml_add(update_msg, F_CIB_CLIENTID, client_id);
- crm_xml_add(update_msg, F_CIB_CLIENTNAME, client_name);
- crm_xml_add(update_msg, F_CIB_CALLID, call_id);
- crm_xml_add(update_msg, F_ORIG, origin);
- crm_xml_add_int(update_msg, F_CIB_RC, result);
+ crm_xml_add(update_msg, PCMK__XA_T, PCMK__VALUE_CIB_NOTIFY);
+ crm_xml_add(update_msg, PCMK__XA_SUBT, PCMK__VALUE_CIB_DIFF_NOTIFY);
+ crm_xml_add(update_msg, PCMK__XA_CIB_OP, op);
+ crm_xml_add(update_msg, PCMK__XA_CIB_CLIENTID, client_id);
+ crm_xml_add(update_msg, PCMK__XA_CIB_CLIENTNAME, client_name);
+ crm_xml_add(update_msg, PCMK__XA_CIB_CALLID, call_id);
+ crm_xml_add(update_msg, PCMK__XA_SRC, origin);
+ crm_xml_add_int(update_msg, PCMK__XA_CIB_RC, result);
+ // @COMPAT Unused internally, drop at 3.0.0
if (update != NULL) {
type = (const char *) update->name;
crm_trace("Setting type to update->name: %s", type);
@@ -209,14 +211,20 @@ cib_diff_notify(const char *op, int result, const char *call_id,
type = (const char *) diff->name;
crm_trace("Setting type to new_obj->name: %s", type);
}
- crm_xml_add(update_msg, F_CIB_OBJID, ID(diff));
- crm_xml_add(update_msg, F_CIB_OBJTYPE, type);
- attach_cib_generation(update_msg, "cib_generation", the_cib);
+ // @COMPAT Unused internally, drop at 3.0.0
+ crm_xml_add(update_msg, PCMK__XA_CIB_OBJECT, pcmk__xe_id(diff));
+ crm_xml_add(update_msg, PCMK__XA_CIB_OBJECT_TYPE, type);
+ attach_cib_generation(update_msg);
+
+ // @COMPAT Unused internally, drop at 3.0.0
if (update != NULL) {
- add_message_xml(update_msg, F_CIB_UPDATE, update);
+ wrapper = pcmk__xe_create(update_msg, PCMK__XE_CIB_UPDATE);
+ pcmk__xml_copy(wrapper, update);
}
- add_message_xml(update_msg, F_CIB_UPDATE_RESULT, diff);
+
+ wrapper = pcmk__xe_create(update_msg, PCMK__XE_CIB_UPDATE_RESULT);
+ pcmk__xml_copy(wrapper, diff);
crm_log_xml_trace(update_msg, "diff-notify");
cib_notify_send(update_msg);
diff --git a/daemons/based/based_operation.c b/daemons/based/based_operation.c
index 736d425..8dd07af 100644
--- a/daemons/based/based_operation.c
+++ b/daemons/based/based_operation.c
@@ -35,6 +35,7 @@ static const cib__op_fn_t cib_op_functions[] = {
[cib__op_sync_all] = cib_process_sync,
[cib__op_sync_one] = cib_process_sync_one,
[cib__op_upgrade] = cib_process_upgrade_server,
+ [cib__op_schemas] = cib_process_schemas,
};
/*!
diff --git a/daemons/based/based_remote.c b/daemons/based/based_remote.c
index 4aa41fa..b3cb655 100644
--- a/daemons/based/based_remote.c
+++ b/daemons/based/based_remote.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.
*
@@ -27,7 +27,6 @@
#include <glib.h>
#include <libxml/tree.h>
-#include <crm/msg_xml.h>
#include <crm/common/ipc.h>
#include <crm/common/ipc_internal.h>
#include <crm/common/xml.h>
@@ -224,20 +223,20 @@ cib_remote_auth(xmlNode * login)
return FALSE;
}
- if (!pcmk__xe_is(login, T_CIB_COMMAND)) {
+ if (!pcmk__xe_is(login, PCMK__XE_CIB_COMMAND)) {
crm_err("Unrecognizable message from remote client");
crm_log_xml_info(login, "bad");
return FALSE;
}
- tmp = crm_element_value(login, "op");
+ tmp = crm_element_value(login, PCMK_XA_OP);
if (!pcmk__str_eq(tmp, "authenticate", pcmk__str_casei)) {
crm_err("Wrong operation: %s", tmp);
return FALSE;
}
- user = crm_element_value(login, "user");
- pass = crm_element_value(login, "password");
+ user = crm_element_value(login, PCMK_XA_USER);
+ pass = crm_element_value(login, PCMK__XA_PASSWORD);
if (!user || !pass) {
crm_err("missing auth credentials");
@@ -317,7 +316,7 @@ cib_remote_listen(gpointer data)
num_clients++;
new_client = pcmk__new_unauth_client(NULL);
- new_client->remote = calloc(1, sizeof(pcmk__remote_t));
+ new_client->remote = pcmk__assert_alloc(1, sizeof(pcmk__remote_t));
if (ssock == remote_tls_fd) {
#ifdef HAVE_GNUTLS_GNUTLS_H
@@ -411,42 +410,35 @@ cib_remote_connection_destroy(gpointer user_data)
static void
cib_handle_remote_msg(pcmk__client_t *client, xmlNode *command)
{
- const char *value = NULL;
-
- if (!pcmk__xe_is(command, T_CIB_COMMAND)) {
+ if (!pcmk__xe_is(command, PCMK__XE_CIB_COMMAND)) {
crm_log_xml_trace(command, "bad");
return;
}
if (client->name == NULL) {
- value = crm_element_value(command, F_CLIENTNAME);
- if (value == NULL) {
- client->name = strdup(client->id);
- } else {
- client->name = strdup(value);
- }
+ client->name = pcmk__str_copy(client->id);
}
/* unset dangerous options */
- xml_remove_prop(command, F_ORIG);
- xml_remove_prop(command, F_CIB_HOST);
- xml_remove_prop(command, F_CIB_GLOBAL_UPDATE);
+ pcmk__xe_remove_attr(command, PCMK__XA_SRC);
+ pcmk__xe_remove_attr(command, PCMK__XA_CIB_HOST);
+ pcmk__xe_remove_attr(command, PCMK__XA_CIB_UPDATE);
- crm_xml_add(command, F_TYPE, T_CIB);
- crm_xml_add(command, F_CIB_CLIENTID, client->id);
- crm_xml_add(command, F_CIB_CLIENTNAME, client->name);
- crm_xml_add(command, F_CIB_USER, client->user);
+ crm_xml_add(command, PCMK__XA_T, PCMK__VALUE_CIB);
+ crm_xml_add(command, PCMK__XA_CIB_CLIENTID, client->id);
+ crm_xml_add(command, PCMK__XA_CIB_CLIENTNAME, client->name);
+ crm_xml_add(command, PCMK__XA_CIB_USER, client->user);
- if (crm_element_value(command, F_CIB_CALLID) == NULL) {
+ if (crm_element_value(command, PCMK__XA_CIB_CALLID) == NULL) {
char *call_uuid = crm_generate_uuid();
/* fix the command */
- crm_xml_add(command, F_CIB_CALLID, call_uuid);
+ crm_xml_add(command, PCMK__XA_CIB_CALLID, call_uuid);
free(call_uuid);
}
- if (crm_element_value(command, F_CIB_CALLOPTS) == NULL) {
- crm_xml_add_int(command, F_CIB_CALLOPTS, 0);
+ if (crm_element_value(command, PCMK__XA_CIB_CALLOPT) == NULL) {
+ crm_xml_add_int(command, PCMK__XA_CIB_CALLOPT, 0);
}
crm_log_xml_trace(command, "Remote command: ");
@@ -515,17 +507,17 @@ cib_remote_msg(gpointer data)
pcmk__set_client_flags(client, pcmk__client_authenticated);
g_source_remove(client->remote->auth_timeout);
client->remote->auth_timeout = 0;
- client->name = crm_element_value_copy(command, "name");
+ client->name = crm_element_value_copy(command, PCMK_XA_NAME);
- user = crm_element_value(command, "user");
+ user = crm_element_value(command, PCMK_XA_USER);
if (user) {
- client->user = strdup(user);
+ client->user = pcmk__str_copy(user);
}
/* send ACK */
- reg = create_xml_node(NULL, "cib_result");
- crm_xml_add(reg, F_CIB_OPERATION, CRM_OP_REGISTER);
- crm_xml_add(reg, F_CIB_CLIENTID, client->id);
+ reg = pcmk__xe_create(NULL, PCMK__XE_CIB_RESULT);
+ crm_xml_add(reg, PCMK__XA_CIB_OP, CRM_OP_REGISTER);
+ crm_xml_add(reg, PCMK__XA_CIB_CLIENTID, client->id);
pcmk__remote_send_xml(client->remote, reg);
free_xml(reg);
free_xml(command);
@@ -559,8 +551,7 @@ construct_pam_passwd(int num_msg, const struct pam_message **msg,
CRM_CHECK(data, return PAM_CONV_ERR);
CRM_CHECK(num_msg == 1, return PAM_CONV_ERR); /* We only want to handle one message */
- reply = calloc(1, sizeof(struct pam_response));
- CRM_ASSERT(reply != NULL);
+ reply = pcmk__assert_alloc(1, sizeof(struct pam_response));
for (count = 0; count < num_msg; ++count) {
switch (msg[count]->msg_style) {
@@ -634,7 +625,7 @@ authenticate_user(const char *user, const char *passwd)
}
p_conv.conv = construct_pam_passwd;
- p_conv.appdata_ptr = strdup(passwd);
+ p_conv.appdata_ptr = pcmk__str_copy(passwd);
rc = pam_start(pam_name, user, &p_conv, &pam_h);
if (rc != PAM_SUCCESS) {
diff --git a/daemons/based/based_transaction.c b/daemons/based/based_transaction.c
index 89aea2e..39b3439 100644
--- a/daemons/based/based_transaction.c
+++ b/daemons/based/based_transaction.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2023 the Pacemaker project contributors
+ * Copyright 2023-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -28,21 +28,15 @@
char *
based_transaction_source_str(const pcmk__client_t *client, const char *origin)
{
- char *source = NULL;
-
if (client != NULL) {
- source = crm_strdup_printf("client %s (%s)%s%s",
- pcmk__client_name(client),
- pcmk__s(client->id, "unidentified"),
- ((origin != NULL)? " on " : ""),
- pcmk__s(origin, ""));
-
+ return crm_strdup_printf("client %s (%s)%s%s",
+ pcmk__client_name(client),
+ pcmk__s(client->id, "unidentified"),
+ ((origin != NULL)? " on " : ""),
+ pcmk__s(origin, ""));
} else {
- source = strdup((origin != NULL)? origin : "unknown source");
+ return pcmk__str_copy(pcmk__s(origin, "unknown source"));
}
-
- CRM_ASSERT(source != NULL);
- return source;
}
/*!
@@ -61,11 +55,13 @@ static int
process_transaction_requests(xmlNodePtr transaction,
const pcmk__client_t *client, const char *source)
{
- for (xmlNodePtr request = first_named_child(transaction, T_CIB_COMMAND);
- request != NULL; request = crm_next_same_xml(request)) {
+ for (xmlNode *request = pcmk__xe_first_child(transaction,
+ PCMK__XE_CIB_COMMAND, NULL,
+ NULL);
+ request != NULL; request = pcmk__xe_next_same(request)) {
- const char *op = crm_element_value(request, F_CIB_OPERATION);
- const char *host = crm_element_value(request, F_CIB_HOST);
+ const char *op = crm_element_value(request, PCMK__XA_CIB_OP);
+ const char *host = crm_element_value(request, PCMK__XA_CIB_HOST);
const cib__operation_t *operation = NULL;
int rc = cib__get_operation(op, &operation);
@@ -127,7 +123,7 @@ based_commit_transaction(xmlNodePtr transaction, const pcmk__client_t *client,
CRM_ASSERT(result_cib != NULL);
- CRM_CHECK(pcmk__xe_is(transaction, T_CIB_TRANSACTION),
+ CRM_CHECK(pcmk__xe_is(transaction, PCMK__XE_CIB_TRANSACTION),
return pcmk_rc_no_transaction);
/* *result_cib should be a copy of the_cib (created by cib_perform_op()). If
@@ -138,7 +134,7 @@ based_commit_transaction(xmlNodePtr transaction, const pcmk__client_t *client,
* * cib_perform_op() will infer changes for the commit request at the end.
*/
CRM_CHECK((*result_cib != NULL) && (*result_cib != the_cib),
- *result_cib = copy_xml(the_cib));
+ *result_cib = pcmk__xml_copy(NULL, the_cib));
source = based_transaction_source_str(client, origin);
crm_trace("Committing transaction for %s to working CIB", source);
diff --git a/daemons/based/pacemaker-based.c b/daemons/based/pacemaker-based.c
index 5dd7938..137930b 100644
--- a/daemons/based/pacemaker-based.c
+++ b/daemons/based/pacemaker-based.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.
*
@@ -21,7 +21,6 @@
#include <crm/crm.h>
#include <crm/cib/internal.h>
-#include <crm/msg_xml.h>
#include <crm/cluster/internal.h>
#include <crm/common/cmdline_internal.h>
#include <crm/common/mainloop.h>
@@ -36,7 +35,7 @@ extern int init_remote_listener(int port, gboolean encrypted);
gboolean cib_shutdown_flag = FALSE;
int cib_status = pcmk_ok;
-crm_cluster_t *crm_cluster = NULL;
+pcmk_cluster_t *crm_cluster = NULL;
GMainLoop *mainloop = NULL;
gchar *cib_root = NULL;
@@ -126,6 +125,19 @@ setup_stand_alone(GError **error)
return pcmk_rc_ok;
}
+/* @COMPAT Deprecated since 2.1.8. Use pcmk_list_cluster_options() or
+ * crm_attribute --list-options=cluster instead of querying daemon metadata.
+ */
+static int
+based_metadata(pcmk__output_t *out)
+{
+ return pcmk__daemon_metadata(out, "pacemaker-based",
+ "Cluster Information Base manager options",
+ "Cluster options used by Pacemaker's Cluster "
+ "Information Base manager",
+ pcmk__opt_based);
+}
+
static GOptionEntry entries[] = {
{ "stand-alone", 's', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &stand_alone,
"(Advanced use only) Run in stand-alone mode", NULL },
@@ -154,8 +166,7 @@ build_arg_context(pcmk__common_args_t *args, GOptionGroup **group)
{
GOptionContext *context = NULL;
- context = pcmk__build_arg_context(args, "text (default), xml", group,
- "[metadata]");
+ context = pcmk__build_arg_context(args, "text (default), xml", group, NULL);
pcmk__add_main_args(context, entries);
return context;
}
@@ -204,7 +215,13 @@ main(int argc, char **argv)
if ((g_strv_length(processed_args) >= 2)
&& pcmk__str_eq(processed_args[1], "metadata", pcmk__str_none)) {
- cib_metadata();
+
+ rc = based_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;
}
@@ -254,7 +271,7 @@ main(int argc, char **argv)
goto done;
}
- crm_peer_init();
+ pcmk__cluster_init_node_caches();
// Read initial CIB, connect to cluster, and start IPC servers
cib_init();
@@ -267,14 +284,14 @@ main(int argc, char **argv)
/* If main loop returned, clean up and exit. We disconnect in case
* terminate_cib() was called with fast=-1.
*/
- crm_cluster_disconnect(crm_cluster);
+ pcmk_cluster_disconnect(crm_cluster);
pcmk__stop_based_ipc(ipcs_ro, ipcs_rw, ipcs_shm);
done:
g_strfreev(processed_args);
pcmk__free_arg_context(context);
- crm_peer_destroy();
+ pcmk__cluster_destroy_node_caches();
if (local_notify_queue != NULL) {
g_hash_table_destroy(local_notify_queue);
@@ -306,20 +323,19 @@ cib_cs_dispatch(cpg_handle_t handle,
uint32_t kind = 0;
xmlNode *xml = NULL;
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) {
- xml = string2xml(data);
+ xml = pcmk__xml_parse(data);
if (xml == NULL) {
crm_err("Invalid XML: '%.120s'", data);
free(data);
return;
}
- crm_xml_add(xml, F_ORIG, from);
- /* crm_xml_add_int(xml, F_SEQ, wrapper->id); */
+ crm_xml_add(xml, PCMK__XA_SRC, from);
cib_peer_callback(xml, NULL);
}
@@ -359,7 +375,7 @@ cib_peer_update_callback(enum crm_status_type type, crm_node_t * node, const voi
case crm_status_uname:
case crm_status_nstate:
- if (cib_shutdown_flag && (crm_active_peers() < 2)
+ if (cib_shutdown_flag && (pcmk__cluster_num_active_nodes() < 2)
&& (pcmk__ipc_client_count() == 0)) {
crm_info("No more peers");
@@ -375,10 +391,10 @@ cib_init(void)
crm_cluster = pcmk_cluster_new();
#if SUPPORT_COROSYNC
- if (is_corosync_cluster()) {
- crm_cluster->destroy = cib_cs_destroy;
- crm_cluster->cpg.cpg_deliver_fn = cib_cs_dispatch;
- crm_cluster->cpg.cpg_confchg_fn = pcmk_cpg_membership;
+ if (pcmk_get_cluster_layer() == pcmk_cluster_layer_corosync) {
+ pcmk_cluster_set_destroy_fn(crm_cluster, cib_cs_destroy);
+ pcmk_cpg_set_deliver_fn(crm_cluster, cib_cs_dispatch);
+ pcmk_cpg_set_confchg_fn(crm_cluster, pcmk__cpg_confchg_cb);
}
#endif // SUPPORT_COROSYNC
@@ -390,9 +406,9 @@ cib_init(void)
}
if (!stand_alone) {
- crm_set_status_callback(&cib_peer_update_callback);
+ pcmk__cluster_set_status_callback(&cib_peer_update_callback);
- if (!crm_cluster_connect(crm_cluster)) {
+ if (pcmk_cluster_connect(crm_cluster) != pcmk_rc_ok) {
crm_crit("Cannot sign in to the cluster... terminating");
crm_exit(CRM_EX_FATAL);
}
@@ -419,12 +435,13 @@ startCib(const char *filename)
cib_read_config(config_hash, cib);
- pcmk__scan_port(crm_element_value(cib, "remote-tls-port"), &port);
+ pcmk__scan_port(crm_element_value(cib, PCMK_XA_REMOTE_TLS_PORT), &port);
if (port >= 0) {
remote_tls_fd = init_remote_listener(port, TRUE);
}
- pcmk__scan_port(crm_element_value(cib, "remote-clear-port"), &port);
+ pcmk__scan_port(crm_element_value(cib, PCMK_XA_REMOTE_CLEAR_PORT),
+ &port);
if (port >= 0) {
remote_fd = init_remote_listener(port, FALSE);
}
diff --git a/daemons/based/pacemaker-based.h b/daemons/based/pacemaker-based.h
index 33c7642..16b0e78 100644
--- a/daemons/based/pacemaker-based.h
+++ b/daemons/based/pacemaker-based.h
@@ -56,7 +56,7 @@ extern crm_trigger_t *cib_writer;
extern gboolean cib_writes_enabled;
extern GMainLoop *mainloop;
-extern crm_cluster_t *crm_cluster;
+extern pcmk_cluster_t *crm_cluster;
extern GHashTable *local_notify_queue;
extern gboolean legacy_mode;
extern gboolean stand_alone;
@@ -122,6 +122,10 @@ int cib_process_commit_transaction(const char *op, int options,
const char *section, xmlNode *req,
xmlNode *input, xmlNode *existing_cib,
xmlNode **result_cib, xmlNode **answer);
+int cib_process_schemas(const char *op, int options, const char *section,
+ xmlNode *req, xmlNode *input, xmlNode *existing_cib,
+ xmlNode **result_cib, xmlNode **answer);
+
void send_sync_request(const char *host);
int sync_our_cib(xmlNode *request, gboolean all);