summaryrefslogtreecommitdiffstats
path: root/daemons/based/based_callbacks.c
diff options
context:
space:
mode:
Diffstat (limited to 'daemons/based/based_callbacks.c')
-rw-r--r--daemons/based/based_callbacks.c361
1 files changed, 211 insertions, 150 deletions
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);
}