4 files changed, 32 insertions(+), 65 deletions(-)
include/crm/cib_ops.h | 2 -
include/crm/cib_util.h | 2 -
lib/cib/cib_ops.c | 90 +++++++++++++++---------------------------------
lib/cib/cib_utils.c | 3 +
# HG changeset patch
# User Andrew Beekhof <[EMAIL PROTECTED]>
# Date 1226393688 -3600
# Branch stable-1.0
# Node ID 43d4557f2136fea86af652f31b356d148a53598e
# Parent 18d6f38efda628d32646f88fe5878c8ace3380a3
Low: cib: Simplify the cib_config_changed() logic with xpath
diff --git a/include/crm/cib_ops.h b/include/crm/cib_ops.h
--- a/include/crm/cib_ops.h
+++ b/include/crm/cib_ops.h
@@ -88,7 +88,7 @@ enum cib_errors cib_update_counter(xmlNo
enum cib_errors cib_update_counter(xmlNode *xml_obj, const char *field, gboolean reset);
xmlNode *diff_cib_object(xmlNode *old_cib, xmlNode *new_cib, gboolean suppress);
gboolean apply_cib_diff(xmlNode *old, xmlNode *diff, xmlNode **new);
-gboolean cib_config_changed(xmlNode *old_cib, xmlNode *new_cib, xmlNode **result);
+gboolean cib_config_changed(xmlNode *diff);
gboolean update_results(
xmlNode *failed, xmlNode *target, const char* operation, int return_code);
diff --git a/include/crm/cib_util.h b/include/crm/cib_util.h
--- a/include/crm/cib_util.h
+++ b/include/crm/cib_util.h
@@ -32,8 +32,6 @@ extern int cib_section2enum(const char *
extern int cib_section2enum(const char *a_section);
#define create_cib_fragment(update,cib_section) create_cib_fragment_adv(update, cib_section, __FUNCTION__)
-
-extern gboolean cib_config_changed(xmlNode *old_cib, xmlNode *new_cib, xmlNode **result);
extern xmlNode *diff_cib_object(
xmlNode *old, xmlNode *new,gboolean suppress);
diff --git a/lib/cib/cib_ops.c b/lib/cib/cib_ops.c
--- a/lib/cib/cib_ops.c
+++ b/lib/cib/cib_ops.c
@@ -765,73 +765,41 @@ apply_cib_diff(xmlNode *old, xmlNode *di
}
gboolean
-cib_config_changed(xmlNode *old_cib, xmlNode *new_cib, xmlNode **result)
+cib_config_changed(xmlNode *diff)
{
- gboolean config_changes = FALSE;
- const char *tag = NULL;
- xmlNode *diff = NULL;
- xmlNode *dest = NULL;
+ gboolean config_changes = FALSE;
+ xmlXPathObject *xpathObj = NULL;
- if(result) {
- *result = NULL;
- }
-
- diff = diff_xml_object(old_cib, new_cib, FALSE);
- if(diff == NULL) {
- return FALSE;
- }
-
- tag = "diff-removed";
- dest = find_xml_node(diff, tag, FALSE);
- if(dest) {
- dest = find_xml_node(dest, XML_TAG_CIB, FALSE);
- }
-
- if(dest) {
- xml_child_iter(dest, child,
- const char *tag = crm_element_name(child);
- if(crm_str_eq(tag, XML_CIB_TAG_STATUS, TRUE)) {
- continue;
- }
- config_changes = TRUE;
- goto done;
- );
- }
-
- tag = "diff-added";
- dest = find_xml_node(diff, tag, FALSE);
- if(dest) {
- dest = find_xml_node(dest, XML_TAG_CIB, FALSE);
- }
-
- if(dest) {
- xml_child_iter(dest, child,
- const char *tag = crm_element_name(child);
- if(crm_str_eq(tag, XML_CIB_TAG_STATUS, TRUE)) {
- continue;
- }
- config_changes = TRUE;
- goto done;
- );
-
- xml_prop_iter(dest, name, value,
- if(crm_str_eq(name, XML_ATTR_NUMUPDATES, TRUE)) {
- continue;
- }
+ if(diff == NULL) {
+ goto done;
+ }
+
+ xpathObj = xpath_search(diff, "//"XML_CIB_TAG_CONFIGURATION);
+ if(xpathObj && xpathObj->nodesetval->nodeNr > 0) {
+ config_changes = TRUE;
+ goto done;
+ }
+
+ xpathObj = xpath_search(diff, "//"XML_TAG_CIB);
+ if(xpathObj) {
+ int lpc = 0, max = xpathObj->nodesetval->nodeNr;
+ for(lpc = 0; lpc < max; lpc++) {
+ xmlNode *top = getXpathResult(xpathObj, lpc);
+ xml_prop_iter(top, name, value,
+ if(crm_str_eq(XML_ATTR_NUMUPDATES, name, TRUE) == FALSE) {
+ crm_info("Attr changes");
config_changes = TRUE;
goto done;
- );
-
- }
+ }
+ );
+ }
+ }
done:
- if(result) {
- *result = diff;
- } else {
- free_xml(diff);
- }
-
- return config_changes;
+ if(xpathObj) {
+ xmlXPathFreeObject(xpathObj);
+ }
+ return config_changes;
}
xmlNode *
diff --git a/lib/cib/cib_utils.c b/lib/cib/cib_utils.c
--- a/lib/cib/cib_utils.c
+++ b/lib/cib/cib_utils.c
@@ -591,7 +591,8 @@ cib_perform_op(const char *op, int call_
fix_plus_plus_recursive(scratch);
/* crm_log_xml_debug(scratch, "newer"); */
if(manage_counters) {
- *config_changed = cib_config_changed(current_cib, scratch, diff);
+ *diff = diff_xml_object(current_cib, scratch, FALSE);
+ *config_changed = cib_config_changed(*diff);
/* crm_log_xml_debug(scratch, "newest"); */
if(*config_changed) {
_______________________________________________
Pacemaker mailing list
[email protected]
http://list.clusterlabs.org/mailman/listinfo/pacemaker