summaryrefslogtreecommitdiffstats
path: root/daemons/fenced/fenced_cib.c
diff options
context:
space:
mode:
Diffstat (limited to 'daemons/fenced/fenced_cib.c')
-rw-r--r--daemons/fenced/fenced_cib.c219
1 files changed, 129 insertions, 90 deletions
diff --git a/daemons/fenced/fenced_cib.c b/daemons/fenced/fenced_cib.c
index e11bf68..6bf0e6f 100644
--- a/daemons/fenced/fenced_cib.c
+++ b/daemons/fenced/fenced_cib.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2009-2023 the Pacemaker project contributors
+ * Copyright 2009-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -15,7 +15,6 @@
#include <libxml/xpath.h>
#include <crm/crm.h>
-#include <crm/msg_xml.h>
#include <crm/common/xml.h>
#include <crm/cluster/internal.h>
@@ -55,11 +54,12 @@ node_has_attr(const char *node, const char *name, const char *value)
*/
xpath = g_string_sized_new(256);
pcmk__g_strcat(xpath,
- "//" XML_CIB_TAG_NODES "/" XML_CIB_TAG_NODE
- "[@" XML_ATTR_UNAME "='", node, "']/" XML_TAG_ATTR_SETS
- "/" XML_CIB_TAG_NVPAIR
- "[@" XML_NVPAIR_ATTR_NAME "='", name, "' "
- "and @" XML_NVPAIR_ATTR_VALUE "='", value, "']", NULL);
+ "//" PCMK_XE_NODES "/" PCMK_XE_NODE
+ "[@" PCMK_XA_UNAME "='", node, "']"
+ "/" PCMK_XE_INSTANCE_ATTRIBUTES
+ "/" PCMK_XE_NVPAIR
+ "[@" PCMK_XA_NAME "='", name, "' "
+ "and @" PCMK_XA_VALUE "='", value, "']", NULL);
match = get_xpath_object((const char *) xpath->str, local_cib, LOG_NEVER);
@@ -76,7 +76,7 @@ add_topology_level(xmlNode *match)
CRM_CHECK(match != NULL, return);
fenced_register_level(match, &desc, &result);
- fenced_send_level_notification(STONITH_OP_LEVEL_ADD, &result, desc);
+ fenced_send_config_notification(STONITH_OP_LEVEL_ADD, &result, desc);
pcmk__reset_result(&result);
free(desc);
}
@@ -86,14 +86,14 @@ topology_remove_helper(const char *node, int level)
{
char *desc = NULL;
pcmk__action_result_t result = PCMK__UNKNOWN_RESULT;
- xmlNode *data = create_xml_node(NULL, XML_TAG_FENCING_LEVEL);
+ xmlNode *data = pcmk__xe_create(NULL, PCMK_XE_FENCING_LEVEL);
- crm_xml_add(data, F_STONITH_ORIGIN, __func__);
- crm_xml_add_int(data, XML_ATTR_STONITH_INDEX, level);
- crm_xml_add(data, XML_ATTR_STONITH_TARGET, node);
+ crm_xml_add(data, PCMK__XA_ST_ORIGIN, __func__);
+ crm_xml_add_int(data, PCMK_XA_INDEX, level);
+ crm_xml_add(data, PCMK_XA_TARGET, node);
fenced_unregister_level(data, &desc, &result);
- fenced_send_level_notification(STONITH_OP_LEVEL_DEL, &result, desc);
+ fenced_send_config_notification(STONITH_OP_LEVEL_DEL, &result, desc);
pcmk__reset_result(&result);
free_xml(data);
free(desc);
@@ -108,7 +108,7 @@ remove_topology_level(xmlNode *match)
CRM_CHECK(match != NULL, return);
key = stonith_level_key(match, fenced_target_by_unknown);
- crm_element_value_int(match, XML_ATTR_STONITH_INDEX, &index);
+ crm_element_value_int(match, PCMK_XA_INDEX, &index);
topology_remove_helper(key, index);
free(key);
}
@@ -149,7 +149,7 @@ void
fencing_topology_init(void)
{
xmlXPathObjectPtr xpathObj = NULL;
- const char *xpath = "//" XML_TAG_FENCING_LEVEL;
+ const char *xpath = "//" PCMK_XE_FENCING_LEVEL;
crm_trace("Full topology refresh");
free_topology_list();
@@ -174,37 +174,41 @@ remove_cib_device(xmlXPathObjectPtr xpathObj)
CRM_LOG_ASSERT(match != NULL);
if(match != NULL) {
- standard = crm_element_value(match, XML_AGENT_ATTR_CLASS);
+ standard = crm_element_value(match, PCMK_XA_CLASS);
}
if (!pcmk__str_eq(standard, PCMK_RESOURCE_CLASS_STONITH, pcmk__str_casei)) {
continue;
}
- rsc_id = crm_element_value(match, XML_ATTR_ID);
+ rsc_id = crm_element_value(match, PCMK_XA_ID);
stonith_device_remove(rsc_id, true);
}
}
+#define XPATH_WATCHDOG_TIMEOUT "//" PCMK_XE_NVPAIR \
+ "[@" PCMK_XA_NAME "='" \
+ PCMK_OPT_STONITH_WATCHDOG_TIMEOUT "']"
+
static void
update_stonith_watchdog_timeout_ms(xmlNode *cib)
{
- long timeout_ms = 0;
+ long long timeout_ms = 0;
xmlNode *stonith_watchdog_xml = NULL;
const char *value = NULL;
- stonith_watchdog_xml = get_xpath_object("//nvpair[@name='stonith-watchdog-timeout']",
- cib, LOG_NEVER);
+ stonith_watchdog_xml = get_xpath_object(XPATH_WATCHDOG_TIMEOUT, cib,
+ LOG_NEVER);
if (stonith_watchdog_xml) {
- value = crm_element_value(stonith_watchdog_xml, XML_NVPAIR_ATTR_VALUE);
+ value = crm_element_value(stonith_watchdog_xml, PCMK_XA_VALUE);
}
if (value) {
timeout_ms = crm_get_msec(value);
}
if (timeout_ms < 0) {
- timeout_ms = pcmk__auto_watchdog_timeout();
+ timeout_ms = pcmk__auto_stonith_watchdog_timeout();
}
stonith_watchdog_timeout_ms = timeout_ms;
@@ -221,9 +225,9 @@ cib_devices_update(void)
stonith_device_t *device = NULL;
crm_info("Updating devices to version %s.%s.%s",
- crm_element_value(local_cib, XML_ATTR_GENERATION_ADMIN),
- crm_element_value(local_cib, XML_ATTR_GENERATION),
- crm_element_value(local_cib, XML_ATTR_NUMUPDATES));
+ crm_element_value(local_cib, PCMK_XA_ADMIN_EPOCH),
+ crm_element_value(local_cib, PCMK_XA_EPOCH),
+ crm_element_value(local_cib, PCMK_XA_NUM_UPDATES));
g_hash_table_iter_init(&iter, device_list);
while (g_hash_table_iter_next(&iter, NULL, (void **)&device)) {
@@ -256,7 +260,9 @@ update_cib_stonith_devices_v1(const char *event, xmlNode * msg)
xmlXPathObjectPtr xpath_obj = NULL;
/* process new constraints */
- xpath_obj = xpath_search(msg, "//" F_CIB_UPDATE_RESULT "//" XML_CONS_TAG_RSC_LOCATION);
+ xpath_obj = xpath_search(msg,
+ "//" PCMK__XE_CIB_UPDATE_RESULT
+ "//" PCMK_XE_RSC_LOCATION);
if (numXpathResults(xpath_obj) > 0) {
int max = numXpathResults(xpath_obj), lpc = 0;
@@ -273,14 +279,20 @@ update_cib_stonith_devices_v1(const char *event, xmlNode * msg)
freeXpathObject(xpath_obj);
/* process deletions */
- xpath_obj = xpath_search(msg, "//" F_CIB_UPDATE_RESULT "//" XML_TAG_DIFF_REMOVED "//" XML_CIB_TAG_RESOURCE);
+ xpath_obj = xpath_search(msg,
+ "//" PCMK__XE_CIB_UPDATE_RESULT
+ "//" PCMK__XE_DIFF_REMOVED
+ "//" PCMK_XE_PRIMITIVE);
if (numXpathResults(xpath_obj) > 0) {
remove_cib_device(xpath_obj);
}
freeXpathObject(xpath_obj);
/* process additions */
- xpath_obj = xpath_search(msg, "//" F_CIB_UPDATE_RESULT "//" XML_TAG_DIFF_ADDED "//" XML_CIB_TAG_RESOURCE);
+ xpath_obj = xpath_search(msg,
+ "//" PCMK__XE_CIB_UPDATE_RESULT
+ "//" PCMK__XE_DIFF_ADDED
+ "//" PCMK_XE_PRIMITIVE);
if (numXpathResults(xpath_obj) > 0) {
int max = numXpathResults(xpath_obj), lpc = 0;
@@ -289,8 +301,8 @@ update_cib_stonith_devices_v1(const char *event, xmlNode * msg)
const char *standard = NULL;
xmlNode *match = getXpathResult(xpath_obj, lpc);
- rsc_id = crm_element_value(match, XML_ATTR_ID);
- standard = crm_element_value(match, XML_AGENT_ATTR_CLASS);
+ rsc_id = crm_element_value(match, PCMK_XA_ID);
+ standard = crm_element_value(match, PCMK_XA_CLASS);
if (!pcmk__str_eq(standard, PCMK_RESOURCE_CLASS_STONITH, pcmk__str_casei)) {
continue;
@@ -314,35 +326,39 @@ update_cib_stonith_devices_v2(const char *event, xmlNode * msg)
{
xmlNode *change = NULL;
char *reason = NULL;
- bool needs_update = FALSE;
- xmlNode *patchset = get_message_xml(msg, F_CIB_UPDATE_RESULT);
+ xmlNode *wrapper = pcmk__xe_first_child(msg, PCMK__XE_CIB_UPDATE_RESULT,
+ NULL, NULL);
+ xmlNode *patchset = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
+
+ for (change = pcmk__xe_first_child(patchset, NULL, NULL, NULL);
+ change != NULL; change = pcmk__xe_next(change)) {
- for (change = pcmk__xml_first_child(patchset); change != NULL;
- change = pcmk__xml_next(change)) {
- const char *op = crm_element_value(change, XML_DIFF_OP);
- const char *xpath = crm_element_value(change, XML_DIFF_PATH);
+ const char *op = crm_element_value(change, PCMK_XA_OPERATION);
+ const char *xpath = crm_element_value(change, PCMK_XA_PATH);
const char *shortpath = NULL;
- if ((op == NULL) ||
- (strcmp(op, "move") == 0) ||
- strstr(xpath, "/"XML_CIB_TAG_STATUS)) {
+ if (pcmk__str_eq(op, PCMK_VALUE_MOVE, pcmk__str_null_matches)
+ || (strstr(xpath, "/" PCMK_XE_STATUS) != NULL)) {
continue;
- } else if (pcmk__str_eq(op, "delete", pcmk__str_casei) && strstr(xpath, "/"XML_CIB_TAG_RESOURCE)) {
+ }
+
+ if (pcmk__str_eq(op, PCMK_VALUE_DELETE, pcmk__str_none)
+ && (strstr(xpath, "/" PCMK_XE_PRIMITIVE) != NULL)) {
const char *rsc_id = NULL;
char *search = NULL;
char *mutable = NULL;
- if (strstr(xpath, XML_TAG_ATTR_SETS) ||
- strstr(xpath, XML_TAG_META_SETS)) {
- needs_update = TRUE;
- pcmk__str_update(&reason,
- "(meta) attribute deleted from resource");
+ if ((strstr(xpath, PCMK_XE_INSTANCE_ATTRIBUTES) != NULL)
+ || (strstr(xpath, PCMK_XE_META_ATTRIBUTES) != NULL)) {
+
+ reason = pcmk__str_copy("(meta) attribute deleted from "
+ "resource");
break;
}
- pcmk__str_update(&mutable, xpath);
- rsc_id = strstr(mutable, "primitive[@" XML_ATTR_ID "=\'");
+ mutable = pcmk__str_copy(xpath);
+ rsc_id = strstr(mutable, PCMK_XE_PRIMITIVE "[@" PCMK_XA_ID "=\'");
if (rsc_id != NULL) {
- rsc_id += strlen("primitive[@" XML_ATTR_ID "=\'");
+ rsc_id += strlen(PCMK_XE_PRIMITIVE "[@" PCMK_XA_ID "=\'");
search = strchr(rsc_id, '\'');
}
if (search != NULL) {
@@ -355,30 +371,31 @@ update_cib_stonith_devices_v2(const char *event, xmlNode * msg)
}
free(mutable);
- } else if (strstr(xpath, "/"XML_CIB_TAG_RESOURCES) ||
- strstr(xpath, "/"XML_CIB_TAG_CONSTRAINTS) ||
- strstr(xpath, "/"XML_CIB_TAG_RSCCONFIG)) {
+ } else if (strstr(xpath, "/" PCMK_XE_RESOURCES)
+ || strstr(xpath, "/" PCMK_XE_CONSTRAINTS)
+ || strstr(xpath, "/" PCMK_XE_RSC_DEFAULTS)) {
shortpath = strrchr(xpath, '/'); CRM_ASSERT(shortpath);
reason = crm_strdup_printf("%s %s", op, shortpath+1);
- needs_update = TRUE;
break;
}
}
- if(needs_update) {
+ if (reason != NULL) {
crm_info("Updating device list from CIB: %s", reason);
cib_devices_update();
+ free(reason);
} else {
crm_trace("No updates for device list found in CIB");
}
- free(reason);
}
static void
update_cib_stonith_devices(const char *event, xmlNode * msg)
{
int format = 1;
- xmlNode *patchset = get_message_xml(msg, F_CIB_UPDATE_RESULT);
+ xmlNode *wrapper = pcmk__xe_first_child(msg, PCMK__XE_CIB_UPDATE_RESULT,
+ NULL, NULL);
+ xmlNode *patchset = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
CRM_ASSERT(patchset);
crm_element_value_int(patchset, PCMK_XA_FORMAT, &format);
@@ -465,17 +482,19 @@ remove_fencing_topology(xmlXPathObjectPtr xpathObj)
xmlNode *match = getXpathResult(xpathObj, lpc);
CRM_LOG_ASSERT(match != NULL);
- if (match && crm_element_value(match, XML_DIFF_MARKER)) {
+ if (match && crm_element_value(match, PCMK__XA_CRM_DIFF_MARKER)) {
/* Deletion */
int index = 0;
char *target = stonith_level_key(match, fenced_target_by_unknown);
- crm_element_value_int(match, XML_ATTR_STONITH_INDEX, &index);
+ crm_element_value_int(match, PCMK_XA_INDEX, &index);
if (target == NULL) {
- crm_err("Invalid fencing target in element %s", ID(match));
+ crm_err("Invalid fencing target in element %s",
+ pcmk__xe_id(match));
} else if (index <= 0) {
- crm_err("Invalid level for %s in element %s", target, ID(match));
+ crm_err("Invalid level for %s in element %s",
+ target, pcmk__xe_id(match));
} else {
topology_remove_helper(target, index);
@@ -491,21 +510,27 @@ update_fencing_topology(const char *event, xmlNode * msg)
int format = 1;
const char *xpath;
xmlXPathObjectPtr xpathObj = NULL;
- xmlNode *patchset = get_message_xml(msg, F_CIB_UPDATE_RESULT);
+ xmlNode *wrapper = pcmk__xe_first_child(msg, PCMK__XE_CIB_UPDATE_RESULT,
+ NULL, NULL);
+ xmlNode *patchset = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
CRM_ASSERT(patchset);
crm_element_value_int(patchset, PCMK_XA_FORMAT, &format);
if(format == 1) {
/* Process deletions (only) */
- xpath = "//" F_CIB_UPDATE_RESULT "//" XML_TAG_DIFF_REMOVED "//" XML_TAG_FENCING_LEVEL;
+ xpath = "//" PCMK__XE_CIB_UPDATE_RESULT
+ "//" PCMK__XE_DIFF_REMOVED
+ "//" PCMK_XE_FENCING_LEVEL;
xpathObj = xpath_search(msg, xpath);
remove_fencing_topology(xpathObj);
freeXpathObject(xpathObj);
/* Process additions and changes */
- xpath = "//" F_CIB_UPDATE_RESULT "//" XML_TAG_DIFF_ADDED "//" XML_TAG_FENCING_LEVEL;
+ xpath = "//" PCMK__XE_CIB_UPDATE_RESULT
+ "//" PCMK__XE_DIFF_ADDED
+ "//" PCMK_XE_FENCING_LEVEL;
xpathObj = xpath_search(msg, xpath);
register_fencing_topology(xpathObj);
@@ -518,33 +543,36 @@ update_fencing_topology(const char *event, xmlNode * msg)
xml_patch_versions(patchset, add, del);
- for (change = pcmk__xml_first_child(patchset); change != NULL;
- change = pcmk__xml_next(change)) {
- const char *op = crm_element_value(change, XML_DIFF_OP);
- const char *xpath = crm_element_value(change, XML_DIFF_PATH);
+ for (change = pcmk__xe_first_child(patchset, NULL, NULL, NULL);
+ change != NULL; change = pcmk__xe_next(change)) {
+
+ const char *op = crm_element_value(change, PCMK_XA_OPERATION);
+ const char *xpath = crm_element_value(change, PCMK_XA_PATH);
if(op == NULL) {
continue;
- } else if(strstr(xpath, "/" XML_TAG_FENCING_LEVEL) != NULL) {
+ } else if(strstr(xpath, "/" PCMK_XE_FENCING_LEVEL) != NULL) {
/* Change to a specific entry */
crm_trace("Handling %s operation %d.%d.%d for %s", op, add[0], add[1], add[2], xpath);
- if(strcmp(op, "move") == 0) {
+ if (strcmp(op, PCMK_VALUE_MOVE) == 0) {
continue;
- } else if(strcmp(op, "create") == 0) {
+ } else if (strcmp(op, PCMK_VALUE_CREATE) == 0) {
add_topology_level(change->children);
- } else if(strcmp(op, "modify") == 0) {
- xmlNode *match = first_named_child(change, XML_DIFF_RESULT);
+ } else if (strcmp(op, PCMK_VALUE_MODIFY) == 0) {
+ xmlNode *match = pcmk__xe_first_child(change,
+ PCMK_XE_CHANGE_RESULT,
+ NULL, NULL);
if(match) {
remove_topology_level(match->children);
add_topology_level(match->children);
}
- } else if(strcmp(op, "delete") == 0) {
+ } else if (strcmp(op, PCMK_VALUE_DELETE) == 0) {
/* Nuclear option, all we have is the path and an id... not enough to remove a specific entry */
crm_info("Re-initializing fencing topology after %s operation %d.%d.%d for %s",
op, add[0], add[1], add[2], xpath);
@@ -552,20 +580,23 @@ update_fencing_topology(const char *event, xmlNode * msg)
return;
}
- } else if (strstr(xpath, "/" XML_TAG_FENCING_TOPOLOGY) != NULL) {
+ } else if (strstr(xpath, "/" PCMK_XE_FENCING_TOPOLOGY) != NULL) {
/* Change to the topology in general */
crm_info("Re-initializing fencing topology after top-level %s operation %d.%d.%d for %s",
op, add[0], add[1], add[2], xpath);
fencing_topology_init();
return;
- } else if (strstr(xpath, "/" XML_CIB_TAG_CONFIGURATION)) {
+ } else if (strstr(xpath, "/" PCMK_XE_CONFIGURATION)) {
/* Changes to the whole config section, possibly including the topology as a whild */
- if(first_named_child(change, XML_TAG_FENCING_TOPOLOGY) == NULL) {
+ if (pcmk__xe_first_child(change, PCMK_XE_FENCING_TOPOLOGY, NULL,
+ NULL) == NULL) {
crm_trace("Nothing for us in %s operation %d.%d.%d for %s.",
op, add[0], add[1], add[2], xpath);
- } else if(strcmp(op, "delete") == 0 || strcmp(op, "create") == 0) {
+ } else if (pcmk__str_any_of(op,
+ PCMK_VALUE_DELETE,
+ PCMK_VALUE_CREATE, NULL)) {
crm_info("Re-initializing fencing topology after top-level %s operation %d.%d.%d for %s.",
op, add[0], add[1], add[2], xpath);
fencing_topology_init();
@@ -586,7 +617,7 @@ update_fencing_topology(const char *event, xmlNode * msg)
static void
update_cib_cache_cb(const char *event, xmlNode * msg)
{
- long timeout_ms_saved = stonith_watchdog_timeout_ms;
+ long long timeout_ms_saved = stonith_watchdog_timeout_ms;
bool need_full_refresh = false;
if(!have_cib_devices) {
@@ -603,14 +634,18 @@ update_cib_cache_cb(const char *event, xmlNode * msg)
*/
if (local_cib != NULL) {
int rc = pcmk_ok;
+ xmlNode *wrapper = NULL;
xmlNode *patchset = NULL;
- crm_element_value_int(msg, F_CIB_RC, &rc);
+ crm_element_value_int(msg, PCMK__XA_CIB_RC, &rc);
if (rc != pcmk_ok) {
return;
}
- patchset = get_message_xml(msg, F_CIB_UPDATE_RESULT);
+ wrapper = pcmk__xe_first_child(msg, PCMK__XE_CIB_UPDATE_RESULT, NULL,
+ NULL);
+ patchset = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
+
rc = xml_apply_patchset(local_cib, patchset, TRUE);
switch (rc) {
case pcmk_ok:
@@ -660,7 +695,7 @@ init_cib_cache_cb(xmlNode * msg, int call_id, int rc, xmlNode * output, void *us
{
crm_info("Updating device list from CIB");
have_cib_devices = TRUE;
- local_cib = copy_xml(output);
+ local_cib = pcmk__xml_copy(NULL, output);
pcmk__refresh_node_caches_from_cib(local_cib);
update_stonith_watchdog_timeout_ms(local_cib);
@@ -693,7 +728,7 @@ void
fenced_cib_cleanup(void)
{
if (cib_api != NULL) {
- cib_api->cmds->del_notify_callback(cib_api, T_CIB_DIFF_NOTIFY,
+ cib_api->cmds->del_notify_callback(cib_api, PCMK__VALUE_CIB_DIFF_NOTIFY,
update_cib_cache_cb);
cib__clean_up_connection(&cib_api);
}
@@ -719,16 +754,20 @@ setup_cib(void)
if (rc != pcmk_ok) {
crm_err("Could not connect to the CIB manager: %s (%d)", pcmk_strerror(rc), rc);
+ return;
+ }
- } else if (pcmk_ok !=
- cib_api->cmds->add_notify_callback(cib_api, T_CIB_DIFF_NOTIFY, update_cib_cache_cb)) {
+ rc = cib_api->cmds->add_notify_callback(cib_api,
+ PCMK__VALUE_CIB_DIFF_NOTIFY,
+ update_cib_cache_cb);
+ if (rc != pcmk_ok) {
crm_err("Could not set CIB notification callback");
-
- } else {
- rc = cib_api->cmds->query(cib_api, NULL, NULL, cib_scope_local);
- cib_api->cmds->register_callback(cib_api, rc, 120, FALSE, NULL, "init_cib_cache_cb",
- init_cib_cache_cb);
- cib_api->cmds->set_connection_dnotify(cib_api, cib_connection_destroy);
- crm_info("Watching for fencing topology changes");
+ return;
}
+
+ rc = cib_api->cmds->query(cib_api, NULL, NULL, cib_scope_local);
+ cib_api->cmds->register_callback(cib_api, rc, 120, FALSE, NULL,
+ "init_cib_cache_cb", init_cib_cache_cb);
+ cib_api->cmds->set_connection_dnotify(cib_api, cib_connection_destroy);
+ crm_info("Watching for fencing topology changes");
}