17 #include <sys/param.h>
18 #include <sys/types.h>
27 cib_process_query(
const char *op,
int options,
const char *section, xmlNode * req, xmlNode * input,
28 xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
30 xmlNode *obj_root = NULL;
37 existing_cib, result_cib, answer);
49 if (obj_root == NULL) {
53 const char *tag =
TYPE(obj_root);
63 if (result ==
pcmk_ok && *answer == NULL) {
64 crm_err(
"Error creating query response");
72 cib_process_erase(
const char *op,
int options,
const char *section, xmlNode * req, xmlNode * input,
73 xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
90 xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
95 int current_version = 0;
101 crm_trace(
"Processing \"%s\" event with max=%s", op, max);
113 if (new_version > current_version) {
124 cib_process_bump(
const char *op,
int options,
const char *section, xmlNode * req, xmlNode * input,
125 xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
129 crm_trace(
"Processing \"%s\" event for epoch=%s",
141 char *new_value = NULL;
142 char *old_value = NULL;
148 if (old_value != NULL) {
149 int_value = atoi(old_value);
150 new_value = crm_itoa(++int_value);
152 new_value = strdup(
"1");
166 xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
169 const char *tag = NULL;
176 existing_cib, result_cib, answer);
185 tag = crm_element_name(input);
199 int replace_updates = 0;
200 int replace_epoch = 0;
201 int replace_admin_epoch = 0;
203 const char *reason = NULL;
214 crm_err(
"Digest mis-match on replace from %s: %s vs. %s (expected)", peer,
215 digest_verify, digest);
216 reason =
"digest mismatch";
219 crm_info(
"Digest matched on replace from %s: %s", peer, digest);
230 if (replace_admin_epoch < admin_epoch) {
233 }
else if (replace_admin_epoch > admin_epoch) {
236 }
else if (replace_epoch < epoch) {
239 }
else if (replace_epoch > epoch) {
242 }
else if (replace_updates < updates) {
246 if (reason != NULL) {
247 crm_info(
"Replacement %d.%d.%d from %s not applied to %d.%d.%d:"
248 " current %s is greater than the replacement",
249 replace_admin_epoch, replace_epoch,
250 replace_updates, peer, admin_epoch, epoch, updates, reason);
253 crm_info(
"Replaced %d.%d.%d with %d.%d.%d from %s",
254 admin_epoch, epoch, updates,
255 replace_admin_epoch, replace_epoch, replace_updates, peer);
262 xmlNode *obj_root = NULL;
268 crm_trace(
"No matching object to replace");
278 xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
280 xmlNode *obj_root = NULL;
282 crm_trace(
"Processing \"%s\" event", op);
286 existing_cib, result_cib, answer);
290 crm_err(
"Cannot perform modification with no data");
295 if(
safe_str_eq(crm_element_name(input), section)) {
296 xmlNode *child = NULL;
297 for(child = __xml_first_child(input); child; child = __xml_next(child)) {
299 crm_trace(
"No matching object to delete: %s=%s", child->name,
ID(child));
304 crm_trace(
"No matching object to delete: %s=%s", input->name,
ID(input));
312 xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
314 xmlNode *obj_root = NULL;
316 crm_trace(
"Processing \"%s\" event", op);
320 existing_cib, result_cib, answer);
324 crm_err(
"Cannot perform modification with no data");
329 if (obj_root == NULL) {
330 xmlNode *tmp_section = NULL;
344 CRM_CHECK(obj_root != NULL,
return -EINVAL);
356 xmlXPathObjectPtr xpathObj =
xpath_search(*result_cib,
"//@__delete__");
359 max = numXpathResults(xpathObj);
363 for (lpc = 0; lpc < max; lpc++) {
365 xmlChar *match_path = xmlGetNodePath(match);
378 update_cib_object(xmlNode * parent, xmlNode * update)
382 xmlNode *a_child = NULL;
383 const char *replace = NULL;
384 const char *object_id = NULL;
385 const char *object_name = NULL;
387 CRM_CHECK(update != NULL,
return -EINVAL);
388 CRM_CHECK(parent != NULL,
return -EINVAL);
390 object_name = crm_element_name(update);
391 CRM_CHECK(object_name != NULL,
return -EINVAL);
393 object_id =
ID(update);
396 if (object_id == NULL) {
401 target =
find_entity(parent, object_name, object_id);
404 if (target == NULL) {
411 if (replace != NULL) {
412 xmlNode *
remove = NULL;
413 int last = 0, lpc = 0, len = 0;
415 len = strlen(replace);
417 if (replace[lpc] ==
',' || replace[lpc] == 0) {
418 char *replace_item = NULL;
426 replace_item =
strndup(replace + last, lpc - last);
428 if (
remove != NULL) {
430 replace_item, crm_element_name(target));
448 for (a_child = __xml_first_child(update); a_child != NULL; a_child = __xml_next(a_child)) {
451 crm_trace(
"Updating child <%s id=%s>", crm_element_name(a_child),
ID(a_child));
453 tmp_result = update_cib_object(target, a_child);
457 crm_err(
"Error updating child <%s id=%s>", crm_element_name(a_child),
ID(a_child));
471 add_cib_object(xmlNode * parent, xmlNode * new_obj)
474 const char *object_name = NULL;
475 const char *object_id = NULL;
476 xmlNode *equiv_node = NULL;
478 if (new_obj != NULL) {
479 object_name = crm_element_name(new_obj);
485 if (new_obj == NULL || object_name == NULL) {
488 }
else if (parent == NULL) {
491 }
else if (object_id == NULL) {
496 equiv_node =
find_entity(parent, object_name, object_id);
502 }
else if (equiv_node != NULL) {
506 result = update_cib_object(parent, new_obj);
514 xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
516 xmlNode *failed = NULL;
518 xmlNode *update_section = NULL;
534 crm_err(
"Cannot perform modification with no data");
538 if (section == NULL) {
546 if (
safe_str_eq(crm_element_name(input), section)) {
547 xmlNode *a_child = NULL;
549 for (a_child = __xml_first_child(input); a_child != NULL; a_child = __xml_next(a_child)) {
550 result = add_cib_object(update_section, a_child);
557 result = add_cib_object(update_section, input);
577 cib_process_diff(
const char *op,
int options,
const char *section, xmlNode * req, xmlNode * input,
578 xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
580 const char *originator = NULL;
586 crm_trace(
"Processing \"%s\" event from %s %s",
587 op, originator, is_set(options,
cib_force_diff)?
"(global update)":
"");
590 *result_cib =
copy_xml(existing_cib);
597 int lpc = 0, max = 0;
598 gboolean config_changes = FALSE;
599 xmlXPathObject *xpathObj = NULL;
604 if (*diff == NULL && last != NULL && next != NULL) {
617 if (numXpathResults(xpathObj) > 0) {
618 config_changes = TRUE;
629 max = numXpathResults(xpathObj);
631 for (lpc = 0; lpc < max; lpc++) {
635 config_changes = TRUE;
639 config_changes = TRUE;
644 config_changes = TRUE;
648 config_changes = TRUE;
652 config_changes = TRUE;
656 config_changes = TRUE;
663 return config_changes;
667 cib_process_xpath(
const char *op,
int options,
const char *section, xmlNode * req, xmlNode * input,
668 xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
675 xmlXPathObjectPtr xpathObj = NULL;
677 crm_trace(
"Processing \"%s\" event", op);
685 max = numXpathResults(xpathObj);
688 crm_debug(
"%s was already removed", section);
690 }
else if (max < 1) {
691 crm_debug(
"%s: %s does not exist", op, section);
694 }
else if (is_query) {
704 for (lpc = 0; lpc < max; lpc++) {
705 xmlChar *path = NULL;
712 path = xmlGetNodePath(match);
713 crm_debug(
"Processing %s op for %s with %s", op, section, path);
717 if (match == *result_cib) {
719 crm_warn(
"Cannot perform %s for %s: The xpath is addressing the whole /cib", op, section);
725 if ((options & cib_multiple) == 0) {
732 }
else if ((options & cib_multiple) == 0) {
743 const char *tag =
TYPE(match);
748 if (*answer == NULL) {
754 xmlNode *parent = match;
756 while (parent && parent->type == XML_ELEMENT_NODE) {
758 char *new_path = NULL;
770 parent = parent->parent;
774 if (*answer == NULL) {
781 }
else if (*answer) {
789 xmlNode *parent = match->parent;
796 if ((options & cib_multiple) == 0) {
808 update_results(xmlNode * failed, xmlNode * target,
const char *operation,
int return_code)
810 xmlNode *xml_node = NULL;
811 gboolean was_error = FALSE;
812 const char *error_msg = NULL;
826 crm_warn(
"Action %s failed: %s (cde=%d)", operation, error_msg, return_code);
#define pcmk_err_old_data
#define CRM_CHECK(expr, failure_action)
xmlNode * find_xml_node(xmlNode *cib, const char *node_path, gboolean must_find)
const char * pcmk_strerror(int rc)
gboolean cib_version_details(xmlNode *cib, int *admin_epoch, int *epoch, int *updates)
#define XML_CIB_TAG_SECTION_ALL
gboolean safe_str_neq(const char *a, const char *b)
gboolean update_results(xmlNode *failed, xmlNode *target, const char *operation, int return_code)
#define XML_ATTR_NUMUPDATES
int cib_process_delete(const char *op, int options, const char *section, xmlNode *req, xmlNode *input, xmlNode *existing_cib, xmlNode **result_cib, xmlNode **answer)
int cib_process_replace(const char *op, int options, const char *section, xmlNode *req, xmlNode *input, xmlNode *existing_cib, xmlNode **result_cib, xmlNode **answer)
xmlNode * get_object_root(const char *object_type, xmlNode *the_root)
xmlNode * find_entity(xmlNode *parent, const char *node_name, const char *id)
int cib_process_erase(const char *op, int options, const char *section, xmlNode *req, xmlNode *input, xmlNode *existing_cib, xmlNode **result_cib, xmlNode **answer)
int cib_process_bump(const char *op, int options, const char *section, xmlNode *req, xmlNode *input, xmlNode *existing_cib, xmlNode **result_cib, xmlNode **answer)
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
int get_schema_version(const char *name)
int cib_update_counter(xmlNode *xml_obj, const char *field, gboolean reset)
#define CRM_LOG_ASSERT(expr)
void copy_in_properties(xmlNode *target, xmlNode *src)
int cib_process_xpath(const char *op, int options, const char *section, xmlNode *req, xmlNode *input, xmlNode *existing_cib, xmlNode **result_cib, xmlNode **answer)
void dedupXpathResults(xmlXPathObjectPtr xpathObj)
const char * get_object_parent(const char *object_type)
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
Retrieve the integer value of an XML attribute.
char * strndup(const char *str, size_t len)
#define XML_ATTR_GENERATION
xmlNode * copy_xml(xmlNode *src_node)
#define crm_warn(fmt, args...)
#define crm_debug(fmt, args...)
int cib_process_diff(const char *op, int options, const char *section, xmlNode *req, xmlNode *input, xmlNode *existing_cib, xmlNode **result_cib, xmlNode **answer)
gboolean cib_config_changed(xmlNode *last, xmlNode *next, xmlNode **diff)
int xml_apply_patchset(xmlNode *xml, xmlNode *patchset, bool check_version)
char * crm_element_value_copy(const xmlNode *data, const char *name)
Retrieve a copy of the value of an XML attribute.
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
gboolean update_xml_child(xmlNode *child, xmlNode *to_update)
#define crm_trace(fmt, args...)
xmlNode * createEmptyCib(int admin_epoch)
xmlNode * add_node_copy(xmlNode *new_parent, xmlNode *xml_node)
Wrappers for and extensions to libxml2.
xmlNode * create_xml_node(xmlNode *parent, const char *name)
#define XML_ATTR_VALIDATION
#define XML_FAILCIB_ATTR_OP
void free_xml(xmlNode *child)
gboolean xml_has_children(const xmlNode *root)
#define XML_FAILCIB_ATTR_OBJTYPE
int cib_process_query(const char *op, int options, const char *section, xmlNode *req, xmlNode *input, xmlNode *existing_cib, xmlNode **result_cib, xmlNode **answer)
#define crm_log_xml_err(xml, text)
#define crm_err(fmt, args...)
xmlXPathObjectPtr xpath_search(xmlNode *xml_top, const char *path)
#define XML_FAILCIB_ATTR_REASON
void xml_remove_prop(xmlNode *obj, const char *name)
xmlNode * getXpathResult(xmlXPathObjectPtr xpathObj, int index)
char * calculate_xml_versioned_digest(xmlNode *input, gboolean sort, gboolean do_filter, const char *version)
Calculate and return digest of XML tree.
#define XML_ATTR_GENERATION_ADMIN
#define XML_CIB_ATTR_REPLACE
#define XML_ATTR_CRM_VERSION
int update_validation(xmlNode **xml_blob, int *best, int max, gboolean transform, gboolean to_logs)
Update CIB XML to most recent schema version.
xmlNode * diff_xml_object(xmlNode *left, xmlNode *right, gboolean suppress)
#define crm_log_xml_trace(xml, text)
#define XML_TAG_DIFF_REMOVED
#define XML_CIB_TAG_CONFIGURATION
#define XML_FAILCIB_ATTR_ID
#define safe_str_eq(a, b)
void freeXpathObject(xmlXPathObjectPtr xpathObj)
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
int cib_process_upgrade(const char *op, int options, const char *section, xmlNode *req, xmlNode *input, xmlNode *existing_cib, xmlNode **result_cib, xmlNode **answer)
#define crm_info(fmt, args...)
int cib_process_modify(const char *op, int options, const char *section, xmlNode *req, xmlNode *input, xmlNode *existing_cib, xmlNode **result_cib, xmlNode **answer)
int cib_process_create(const char *op, int options, const char *section, xmlNode *req, xmlNode *input, xmlNode *existing_cib, xmlNode **result_cib, xmlNode **answer)
gboolean replace_xml_child(xmlNode *parent, xmlNode *child, xmlNode *update, gboolean delete_only)