pacemaker  2.0.2-debe490
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cib_utils.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004 International Business Machines
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  */
19 #include <crm_internal.h>
20 #include <unistd.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <stdarg.h>
24 #include <string.h>
25 #include <sys/utsname.h>
26 
27 #include <glib.h>
28 
29 #include <crm/crm.h>
30 #include <crm/cib/internal.h>
31 #include <crm/msg_xml.h>
32 #include <crm/common/xml.h>
33 #include <crm/pengine/rules.h>
34 
35 struct config_root_s {
36  const char *name;
37  const char *parent;
38  const char *path;
39 };
40 
41  /*
42  * "//crm_config" will also work in place of "/cib/configuration/crm_config"
43  * The / prefix means find starting from the root, whereas the // prefix means
44  * find anywhere and risks multiple matches
45  */
46 /* *INDENT-OFF* */
47 struct config_root_s known_paths[] = {
48  { NULL, NULL, "//cib" },
49  { XML_TAG_CIB, NULL, "//cib" },
50  { XML_CIB_TAG_STATUS, "/cib", "//cib/status" },
51  { XML_CIB_TAG_CONFIGURATION,"/cib", "//cib/configuration" },
52  { XML_CIB_TAG_CRMCONFIG, "/cib/configuration", "//cib/configuration/crm_config" },
53  { XML_CIB_TAG_NODES, "/cib/configuration", "//cib/configuration/nodes" },
54  { XML_CIB_TAG_DOMAINS, "/cib/configuration", "//cib/configuration/domains" },
55  { XML_CIB_TAG_RESOURCES, "/cib/configuration", "//cib/configuration/resources" },
56  { XML_CIB_TAG_CONSTRAINTS, "/cib/configuration", "//cib/configuration/constraints" },
57  { XML_CIB_TAG_OPCONFIG, "/cib/configuration", "//cib/configuration/op_defaults" },
58  { XML_CIB_TAG_RSCCONFIG, "/cib/configuration", "//cib/configuration/rsc_defaults" },
59  { XML_CIB_TAG_ACLS, "/cib/configuration", "//cib/configuration/acls" },
60  { XML_TAG_FENCING_TOPOLOGY, "/cib/configuration", "//cib/configuration/fencing-topology" },
61  { XML_CIB_TAG_SECTION_ALL, NULL, "//cib" },
62 };
63 /* *INDENT-ON* */
64 
65 xmlNode *
67 {
68  xmlNode *the_cib = NULL;
69  xmlNode *generation = create_xml_node(NULL, XML_CIB_TAG_GENERATION_TUPPLE);
70 
71  cib->cmds->query(cib, NULL, &the_cib, cib_scope_local | cib_sync_call);
72  if (the_cib != NULL) {
73  copy_in_properties(generation, the_cib);
74  free_xml(the_cib);
75  }
76 
77  return generation;
78 }
79 
80 gboolean
81 cib_version_details(xmlNode * cib, int *admin_epoch, int *epoch, int *updates)
82 {
83  *epoch = -1;
84  *updates = -1;
85  *admin_epoch = -1;
86 
87  if (cib == NULL) {
88  return FALSE;
89 
90  } else {
94  }
95  return TRUE;
96 }
97 
98 gboolean
99 cib_diff_version_details(xmlNode * diff, int *admin_epoch, int *epoch, int *updates,
100  int *_admin_epoch, int *_epoch, int *_updates)
101 {
102  int add[] = { 0, 0, 0 };
103  int del[] = { 0, 0, 0 };
104 
105  xml_patch_versions(diff, add, del);
106 
107  *admin_epoch = add[0];
108  *epoch = add[1];
109  *updates = add[2];
110 
111  *_admin_epoch = del[0];
112  *_epoch = del[1];
113  *_updates = del[2];
114 
115  return TRUE;
116 }
117 
118 /*
119  * The caller should never free the return value
120  */
121 
122 const char *
123 get_object_path(const char *object_type)
124 {
125  int lpc = 0;
126  int max = DIMOF(known_paths);
127 
128  for (; lpc < max; lpc++) {
129  if ((object_type == NULL && known_paths[lpc].name == NULL)
130  || safe_str_eq(object_type, known_paths[lpc].name)) {
131  return known_paths[lpc].path;
132  }
133  }
134  return NULL;
135 }
136 
137 const char *
138 get_object_parent(const char *object_type)
139 {
140  int lpc = 0;
141  int max = DIMOF(known_paths);
142 
143  for (; lpc < max; lpc++) {
144  if (safe_str_eq(object_type, known_paths[lpc].name)) {
145  return known_paths[lpc].parent;
146  }
147  }
148  return NULL;
149 }
150 
151 xmlNode *
152 get_object_root(const char *object_type, xmlNode * the_root)
153 {
154  const char *xpath = get_object_path(object_type);
155 
156  if (xpath == NULL) {
157  return the_root; /* or return NULL? */
158  }
159 
160  return get_xpath_object(xpath, the_root, LOG_TRACE);
161 }
162 
163 /*
164  * It is the callers responsibility to free both the new CIB (output)
165  * and the new CIB (input)
166  */
167 xmlNode *
168 createEmptyCib(int admin_epoch)
169 {
170  xmlNode *cib_root = NULL, *config = NULL;
171 
172  cib_root = create_xml_node(NULL, XML_TAG_CIB);
175 
176  crm_xml_add_int(cib_root, XML_ATTR_GENERATION, admin_epoch);
177  crm_xml_add_int(cib_root, XML_ATTR_NUMUPDATES, 0);
179 
180  config = create_xml_node(cib_root, XML_CIB_TAG_CONFIGURATION);
182 
187 
188  return cib_root;
189 }
190 
191 static bool
192 cib_acl_enabled(xmlNode *xml, const char *user)
193 {
194  bool rc = FALSE;
195 
196 #if ENABLE_ACL
197  if(pcmk_acl_required(user)) {
198  const char *value = NULL;
199  GHashTable *options = crm_str_table_new();
200 
201  cib_read_config(options, xml);
202  value = cib_pref(options, "enable-acl");
203  rc = crm_is_true(value);
204  g_hash_table_destroy(options);
205  }
206 
207  crm_trace("CIB ACL is %s", rc ? "enabled" : "disabled");
208 #endif
209  return rc;
210 }
211 
212 int
213 cib_perform_op(const char *op, int call_options, cib_op_t * fn, gboolean is_query,
214  const char *section, xmlNode * req, xmlNode * input,
215  gboolean manage_counters, gboolean * config_changed,
216  xmlNode * current_cib, xmlNode ** result_cib, xmlNode ** diff, xmlNode ** output)
217 {
218  int rc = pcmk_ok;
219  gboolean check_schema = TRUE;
220  xmlNode *top = NULL;
221  xmlNode *scratch = NULL;
222  xmlNode *local_diff = NULL;
223 
224  const char *new_version = NULL;
225  static struct qb_log_callsite *diff_cs = NULL;
226  const char *user = crm_element_value(req, F_CIB_USER);
227  bool with_digest = FALSE;
228 
229  crm_trace("Begin %s%s%s op", is_set(call_options, cib_dryrun)?"dry-run of ":"", is_query ? "read-only " : "", op);
230 
231  CRM_CHECK(output != NULL, return -ENOMSG);
232  CRM_CHECK(result_cib != NULL, return -ENOMSG);
233  CRM_CHECK(config_changed != NULL, return -ENOMSG);
234 
235  if(output) {
236  *output = NULL;
237  }
238 
239  *result_cib = NULL;
240  *config_changed = FALSE;
241 
242  if (fn == NULL) {
243  return -EINVAL;
244  }
245 
246  if (is_query) {
247  xmlNode *cib_ro = current_cib;
248  xmlNode *cib_filtered = NULL;
249 
250  if(cib_acl_enabled(cib_ro, user)) {
251  if(xml_acl_filtered_copy(user, current_cib, current_cib, &cib_filtered)) {
252  if (cib_filtered == NULL) {
253  crm_debug("Pre-filtered the entire cib");
254  return -EACCES;
255  }
256  cib_ro = cib_filtered;
257  crm_log_xml_trace(cib_ro, "filtered");
258  }
259  }
260 
261  rc = (*fn) (op, call_options, section, req, input, cib_ro, result_cib, output);
262 
263  if(output == NULL || *output == NULL) {
264  /* nothing */
265 
266  } else if(cib_filtered == *output) {
267  cib_filtered = NULL; /* Let them have this copy */
268 
269  } else if(*output == current_cib) {
270  /* They already know not to free it */
271 
272  } else if(cib_filtered && (*output)->doc == cib_filtered->doc) {
273  /* We're about to free the document of which *output is a part */
274  *output = copy_xml(*output);
275 
276  } else if((*output)->doc == current_cib->doc) {
277  /* Give them a copy they can free */
278  *output = copy_xml(*output);
279  }
280 
281  free_xml(cib_filtered);
282  return rc;
283  }
284 
285 
286  if (is_set(call_options, cib_zero_copy)) {
287  /* Conditional on v2 patch style */
288 
289  scratch = current_cib;
290 
291  /* Create a shallow copy of current_cib for the version details */
292  current_cib = create_xml_node(NULL, (const char *)scratch->name);
293  copy_in_properties(current_cib, scratch);
294  top = current_cib;
295 
296  xml_track_changes(scratch, user, NULL, cib_acl_enabled(scratch, user));
297  rc = (*fn) (op, call_options, section, req, input, scratch, &scratch, output);
298 
299  } else {
300  scratch = copy_xml(current_cib);
301  xml_track_changes(scratch, user, NULL, cib_acl_enabled(scratch, user));
302  rc = (*fn) (op, call_options, section, req, input, current_cib, &scratch, output);
303 
304  if(scratch && xml_tracking_changes(scratch) == FALSE) {
305  crm_trace("Inferring changes after %s op", op);
306  xml_track_changes(scratch, user, current_cib, cib_acl_enabled(current_cib, user));
307  xml_calculate_changes(current_cib, scratch);
308  }
309  CRM_CHECK(current_cib != scratch, return -EINVAL);
310  }
311 
312  xml_acl_disable(scratch); /* Allow the system to make any additional changes */
313 
314  if (rc == pcmk_ok && scratch == NULL) {
315  rc = -EINVAL;
316  goto done;
317 
318  } else if(rc == pcmk_ok && xml_acl_denied(scratch)) {
319  crm_trace("ACL rejected part or all of the proposed changes");
320  rc = -EACCES;
321  goto done;
322 
323  } else if (rc != pcmk_ok) {
324  goto done;
325  }
326 
327  if (scratch) {
328  new_version = crm_element_value(scratch, XML_ATTR_CRM_VERSION);
329 
330  if (new_version && compare_version(new_version, CRM_FEATURE_SET) > 0) {
331  crm_err("Discarding update with feature set '%s' greater than our own '%s'",
332  new_version, CRM_FEATURE_SET);
333  rc = -EPROTONOSUPPORT;
334  goto done;
335  }
336  }
337 
338  if (current_cib) {
339  int old = 0;
340  int new = 0;
341 
344 
345  if (old > new) {
346  crm_err("%s went backwards: %d -> %d (Opts: 0x%x)",
347  XML_ATTR_GENERATION_ADMIN, old, new, call_options);
348  crm_log_xml_warn(req, "Bad Op");
349  crm_log_xml_warn(input, "Bad Data");
350  rc = -pcmk_err_old_data;
351 
352  } else if (old == new) {
354  crm_element_value_int(current_cib, XML_ATTR_GENERATION, &old);
355  if (old > new) {
356  crm_err("%s went backwards: %d -> %d (Opts: 0x%x)",
357  XML_ATTR_GENERATION, old, new, call_options);
358  crm_log_xml_warn(req, "Bad Op");
359  crm_log_xml_warn(input, "Bad Data");
360  rc = -pcmk_err_old_data;
361  }
362  }
363  }
364 
365  crm_trace("Massaging CIB contents");
366  strip_text_nodes(scratch);
367  fix_plus_plus_recursive(scratch);
368 
369  if (is_set(call_options, cib_zero_copy)) {
370  /* At this point, current_cib is just the 'cib' tag and its properties,
371  *
372  * The v1 format would barf on this, but we know the v2 patch
373  * format only needs it for the top-level version fields
374  */
375  local_diff = xml_create_patchset(2, current_cib, scratch, (bool*)config_changed, manage_counters);
376 
377  } else {
378  static time_t expires = 0;
379  time_t tm_now = time(NULL);
380 
381  if (expires < tm_now) {
382  expires = tm_now + 60; /* Validate clients are correctly applying v2-style diffs at most once a minute */
383  with_digest = TRUE;
384  }
385 
386  local_diff = xml_create_patchset(0, current_cib, scratch, (bool*)config_changed, manage_counters);
387  }
388 
389  xml_log_changes(LOG_TRACE, __FUNCTION__, scratch);
390  xml_accept_changes(scratch);
391 
392  if (diff_cs == NULL) {
393  diff_cs = qb_log_callsite_get(__PRETTY_FUNCTION__, __FILE__, "diff-validation", LOG_DEBUG, __LINE__, crm_trace_nonlog);
394  }
395 
396  if(local_diff) {
397  patchset_process_digest(local_diff, current_cib, scratch, with_digest);
398 
399  xml_log_patchset(LOG_INFO, __FUNCTION__, local_diff);
400  crm_log_xml_trace(local_diff, "raw patch");
401  }
402 
403  if (is_not_set(call_options, cib_zero_copy) /* The original to compare against doesn't exist */
404  && local_diff
405  && crm_is_callsite_active(diff_cs, LOG_TRACE, 0)) {
406 
407  /* Validate the calculated patch set */
408  int test_rc, format = 1;
409  xmlNode * c = copy_xml(current_cib);
410 
411  crm_element_value_int(local_diff, "format", &format);
412  test_rc = xml_apply_patchset(c, local_diff, manage_counters);
413 
414  if(test_rc != pcmk_ok) {
415  save_xml_to_file(c, "PatchApply:calculated", NULL);
416  save_xml_to_file(current_cib, "PatchApply:input", NULL);
417  save_xml_to_file(scratch, "PatchApply:actual", NULL);
418  save_xml_to_file(local_diff, "PatchApply:diff", NULL);
419  crm_err("v%d patchset error, patch failed to apply: %s (%d)", format, pcmk_strerror(test_rc), test_rc);
420  }
421  free_xml(c);
422  }
423 
424  if (safe_str_eq(section, XML_CIB_TAG_STATUS)) {
425  /* Throttle the amount of costly validation we perform due to status updates
426  * a) we don't really care whats in the status section
427  * b) we don't validate any of its contents at the moment anyway
428  */
429  check_schema = FALSE;
430  }
431 
432  /* === scratch must not be modified after this point ===
433  * Exceptions, anything in:
434 
435  static filter_t filter[] = {
436  { 0, XML_ATTR_ORIGIN },
437  { 0, XML_CIB_ATTR_WRITTEN },
438  { 0, XML_ATTR_UPDATE_ORIG },
439  { 0, XML_ATTR_UPDATE_CLIENT },
440  { 0, XML_ATTR_UPDATE_USER },
441  };
442  */
443 
444  if (*config_changed && is_not_set(call_options, cib_no_mtime)) {
445  char *now_str = NULL;
446  time_t now = time(NULL);
447  const char *schema = crm_element_value(scratch, XML_ATTR_VALIDATION);
448 
449  now_str = ctime(&now);
450  now_str[24] = EOS; /* replace the newline */
451  crm_xml_replace(scratch, XML_CIB_ATTR_WRITTEN, now_str);
452 
453  if (schema) {
454  static int minimum_schema = 0;
455  int current_schema = get_schema_version(schema);
456 
457  if (minimum_schema == 0) {
458  minimum_schema = get_schema_version("pacemaker-1.2");
459  }
460 
461  /* Does the CIB support the "update-*" attributes... */
462  if (current_schema >= minimum_schema) {
463  const char *origin = crm_element_value(req, F_ORIG);
464 
465  CRM_LOG_ASSERT(origin != NULL);
466  crm_xml_replace(scratch, XML_ATTR_UPDATE_ORIG, origin);
469 #if ENABLE_ACL
471 #endif
472  }
473  }
474  }
475 
476  crm_trace("Perform validation: %s", (check_schema? "true" : "false"));
477  if ((rc == pcmk_ok) && check_schema && !validate_xml(scratch, NULL, TRUE)) {
478  const char *current_schema = crm_element_value(scratch,
480 
481  crm_warn("Updated CIB does not validate against %s schema",
482  crm_str(current_schema));
484  }
485 
486  done:
487 
488  *result_cib = scratch;
489 #if ENABLE_ACL
490  if(rc != pcmk_ok && cib_acl_enabled(current_cib, user)) {
491  if(xml_acl_filtered_copy(user, current_cib, scratch, result_cib)) {
492  if (*result_cib == NULL) {
493  crm_debug("Pre-filtered the entire cib result");
494  }
495  free_xml(scratch);
496  }
497  }
498 #endif
499 
500  if(diff) {
501  *diff = local_diff;
502  } else {
503  free_xml(local_diff);
504  }
505 
506  free_xml(top);
507  crm_trace("Done");
508  return rc;
509 }
510 
511 xmlNode *
512 cib_create_op(int call_id, const char *token, const char *op, const char *host, const char *section,
513  xmlNode * data, int call_options, const char *user_name)
514 {
515  xmlNode *op_msg = create_xml_node(NULL, "cib_command");
516 
517  CRM_CHECK(op_msg != NULL, return NULL);
518  CRM_CHECK(token != NULL, return NULL);
519 
520  crm_xml_add(op_msg, F_XML_TAGNAME, "cib_command");
521 
522  crm_xml_add(op_msg, F_TYPE, T_CIB);
523  crm_xml_add(op_msg, F_CIB_CALLBACK_TOKEN, token);
524  crm_xml_add(op_msg, F_CIB_OPERATION, op);
525  crm_xml_add(op_msg, F_CIB_HOST, host);
526  crm_xml_add(op_msg, F_CIB_SECTION, section);
527  crm_xml_add_int(op_msg, F_CIB_CALLID, call_id);
528 #if ENABLE_ACL
529  if (user_name) {
530  crm_xml_add(op_msg, F_CIB_USER, user_name);
531  }
532 #endif
533  crm_trace("Sending call options: %.8lx, %d", (long)call_options, call_options);
534  crm_xml_add_int(op_msg, F_CIB_CALLOPTS, call_options);
535 
536  if (data != NULL) {
537  add_message_xml(op_msg, F_CIB_CALLDATA, data);
538  }
539 
540  if (call_options & cib_inhibit_bcast) {
541  CRM_CHECK((call_options & cib_scope_local), return NULL);
542  }
543  return op_msg;
544 }
545 
546 void
547 cib_native_callback(cib_t * cib, xmlNode * msg, int call_id, int rc)
548 {
549  xmlNode *output = NULL;
550  cib_callback_client_t *blob = NULL;
551 
552  if (msg != NULL) {
553  crm_element_value_int(msg, F_CIB_RC, &rc);
554  crm_element_value_int(msg, F_CIB_CALLID, &call_id);
555  output = get_message_xml(msg, F_CIB_CALLDATA);
556  }
557 
558  blob = g_hash_table_lookup(cib_op_callback_table, GINT_TO_POINTER(call_id));
559  if (blob == NULL) {
560  crm_trace("No callback found for call %d", call_id);
561  }
562 
563  if (cib == NULL) {
564  crm_debug("No cib object supplied");
565  }
566 
567  if (rc == -pcmk_err_diff_resync) {
568  /* This is an internal value that clients do not and should not care about */
569  rc = pcmk_ok;
570  }
571 
572  if (blob && blob->callback && (rc == pcmk_ok || blob->only_success == FALSE)) {
573  crm_trace("Invoking callback %s for call %d", crm_str(blob->id), call_id);
574  blob->callback(msg, call_id, rc, output, blob->user_data);
575 
576  } else if (cib && cib->op_callback == NULL && rc != pcmk_ok) {
577  crm_warn("CIB command failed: %s", pcmk_strerror(rc));
578  crm_log_xml_debug(msg, "Failed CIB Update");
579  }
580 
581  /* This may free user_data, so do it after the callback */
582  if (blob) {
583  remove_cib_op_callback(call_id, FALSE);
584  }
585 
586  if (cib && cib->op_callback != NULL) {
587  crm_trace("Invoking global callback for call %d", call_id);
588  cib->op_callback(msg, call_id, rc, output);
589  }
590  crm_trace("OP callback activated for %d", call_id);
591 }
592 
593 void
594 cib_native_notify(gpointer data, gpointer user_data)
595 {
596  xmlNode *msg = user_data;
597  cib_notify_client_t *entry = data;
598  const char *event = NULL;
599 
600  if (msg == NULL) {
601  crm_warn("Skipping callback - NULL message");
602  return;
603  }
604 
605  event = crm_element_value(msg, F_SUBTYPE);
606 
607  if (entry == NULL) {
608  crm_warn("Skipping callback - NULL callback client");
609  return;
610 
611  } else if (entry->callback == NULL) {
612  crm_warn("Skipping callback - NULL callback");
613  return;
614 
615  } else if (safe_str_neq(entry->event, event)) {
616  crm_trace("Skipping callback - event mismatch %p/%s vs. %s", entry, entry->event, event);
617  return;
618  }
619 
620  crm_trace("Invoking callback for %p/%s event...", entry, event);
621  entry->callback(event, msg);
622  crm_trace("Callback invoked...");
623 }
624 
625 static pe_cluster_option cib_opts[] = {
626  /*
627  * name, legacy name,
628  * type, allowed values, default, validator,
629  * short description,
630  * long description
631  */
632  {
633  "enable-acl", NULL,
634  "boolean", NULL, "false", &check_boolean,
635  "Enable CIB ACL",
636  NULL
637  },
638  {
639  "cluster-ipc-limit", NULL,
640  "integer", NULL, "500", &check_positive_number,
641  "Maximum IPC message backlog before disconnecting a cluster daemon",
642  "Raise this if log has \"Evicting client\" messages for cluster daemon"
643  " PIDs (a good value is the number of resources in the cluster"
644  " multiplied by the number of nodes)"
645  },
646 };
647 
648 void
650 {
651  config_metadata("Cluster Information Base", "1.0",
652  "Cluster Information Base Options",
653  "This is a fake resource that details the options that can be configured for the Cluster Information Base.",
654  cib_opts, DIMOF(cib_opts));
655 }
656 
657 void
658 verify_cib_options(GHashTable * options)
659 {
660  verify_all_options(options, cib_opts, DIMOF(cib_opts));
661 }
662 
663 const char *
664 cib_pref(GHashTable * options, const char *name)
665 {
666  return get_cluster_pref(options, cib_opts, DIMOF(cib_opts), name);
667 }
668 
669 gboolean
670 cib_read_config(GHashTable * options, xmlNode * current_cib)
671 {
672  xmlNode *config = NULL;
673  crm_time_t *now = NULL;
674 
675  if (options == NULL || current_cib == NULL) {
676  return FALSE;
677  }
678 
679  now = crm_time_new(NULL);
680 
681  g_hash_table_remove_all(options);
682 
683  config = get_object_root(XML_CIB_TAG_CRMCONFIG, current_cib);
684  if (config) {
685  unpack_instance_attributes(current_cib, config, XML_CIB_TAG_PROPSET, NULL, options,
686  CIB_OPTIONS_FIRST, TRUE, now);
687  }
688 
689  verify_cib_options(options);
690 
691  crm_time_free(now);
692 
693  return TRUE;
694 }
695 
696 int
697 cib_apply_patch_event(xmlNode * event, xmlNode * input, xmlNode ** output, int level)
698 {
699  int rc = pcmk_err_generic;
700 
701  xmlNode *diff = NULL;
702 
703  CRM_ASSERT(event);
704  CRM_ASSERT(input);
705  CRM_ASSERT(output);
706 
707  crm_element_value_int(event, F_CIB_RC, &rc);
708  diff = get_message_xml(event, F_CIB_UPDATE_RESULT);
709 
710  if (rc < pcmk_ok || diff == NULL) {
711  return rc;
712  }
713 
714  if (level > LOG_CRIT) {
715  xml_log_patchset(level, "Config update", diff);
716  }
717 
718  if (input != NULL) {
719  rc = cib_process_diff(NULL, cib_none, NULL, event, diff, input, output, NULL);
720 
721  if (rc != pcmk_ok) {
722  crm_debug("Update didn't apply: %s (%d) %p", pcmk_strerror(rc), rc, *output);
723 
724  if (rc == -pcmk_err_old_data) {
725  crm_trace("Masking error, we already have the supplied update");
726  return pcmk_ok;
727  }
728  free_xml(*output); *output = NULL;
729 
730  return rc;
731  }
732  }
733 
734  return rc;
735 }
736 
737 /* v2 and v2 patch formats */
738 #define XPATH_CONFIG_CHANGE \
739  "//" XML_CIB_TAG_CRMCONFIG " | " \
740  "//" XML_DIFF_CHANGE "[contains(@" XML_DIFF_PATH ",'/" XML_CIB_TAG_CRMCONFIG "/')]"
741 
742 gboolean
744 {
745  gboolean changed = FALSE;
746 
747  if (diff) {
748  xmlXPathObject *xpathObj = xpath_search(diff, XPATH_CONFIG_CHANGE);
749 
750  if (numXpathResults(xpathObj) > 0) {
751  changed = TRUE;
752  }
753  freeXpathObject(xpathObj);
754  }
755  return changed;
756 }
757 
758 int
759 cib_internal_op(cib_t * cib, const char *op, const char *host,
760  const char *section, xmlNode * data,
761  xmlNode ** output_data, int call_options, const char *user_name)
762 {
763  int (*delegate) (cib_t * cib, const char *op, const char *host,
764  const char *section, xmlNode * data,
765  xmlNode ** output_data, int call_options, const char *user_name) =
766  cib->delegate_fn;
767 
768 #if ENABLE_ACL
769  if(user_name == NULL) {
770  user_name = getenv("CIB_user");
771  }
772 #endif
773 
774  return delegate(cib, op, host, section, data, output_data, call_options, user_name);
775 }
#define pcmk_err_old_data
Definition: results.h:64
int(* query)(cib_t *cib, const char *section, xmlNode **output_data, int call_options)
Definition: cib.h:103
#define LOG_TRACE
Definition: logging.h:26
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:156
#define XML_ATTR_UPDATE_ORIG
Definition: msg_xml.h:103
#define pcmk_err_schema_validation
Definition: results.h:62
A dumping ground.
#define F_TYPE
Definition: msg_xml.h:30
xmlNode * get_message_xml(xmlNode *msg, const char *field)
Definition: xml.c:2504
#define XML_ATTR_UPDATE_CLIENT
Definition: msg_xml.h:104
const char * pcmk_strerror(int rc)
Definition: results.c:188
gboolean cib_version_details(xmlNode *cib, int *admin_epoch, int *epoch, int *updates)
Definition: cib_utils.c:81
#define XML_CIB_TAG_SECTION_ALL
Definition: msg_xml.h:137
gboolean safe_str_neq(const char *a, const char *b)
Definition: strings.c:157
#define XML_CIB_TAG_DOMAINS
Definition: msg_xml.h:142
#define XML_ATTR_NUMUPDATES
Definition: msg_xml.h:89
#define XPATH_CONFIG_CHANGE
Definition: cib_utils.c:738
struct crm_time_s crm_time_t
Definition: iso8601.h:32
#define XML_CIB_TAG_CONSTRAINTS
Definition: msg_xml.h:143
xmlNode * get_object_root(const char *object_type, xmlNode *the_root)
Definition: cib_utils.c:152
#define F_SUBTYPE
Definition: msg_xml.h:26
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
Create an XML attribute with specified name and integer value.
Definition: nvpair.c:383
#define CRM_FEATURE_SET
Definition: crm.h:32
int(* cib_op_t)(const char *, int, const char *, xmlNode *, xmlNode *, xmlNode *, xmlNode **, xmlNode **)
Definition: internal.h:105
#define XML_ATTR_UPDATE_USER
Definition: msg_xml.h:105
const char * get_object_path(const char *object_type)
Definition: cib_utils.c:123
#define XML_TAG_FENCING_TOPOLOGY
Definition: msg_xml.h:391
void xml_track_changes(xmlNode *xml, const char *user, xmlNode *acl_source, bool enforce_acls)
Definition: xml.c:299
void remove_cib_op_callback(int call_id, gboolean all_callbacks)
Definition: cib_client.c:641
bool xml_acl_denied(xmlNode *xml)
Definition: acl.c:522
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
Definition: nvpair.c:275
#define F_CIB_CALLBACK_TOKEN
Definition: internal.h:49
#define pcmk_err_generic
Definition: results.h:60
int get_schema_version(const char *name)
Definition: schemas.c:1025
AIS_Host host
Definition: internal.h:86
#define CRM_LOG_ASSERT(expr)
Definition: logging.h:142
void copy_in_properties(xmlNode *target, xmlNode *src)
Definition: xml.c:1750
void xml_accept_changes(xmlNode *xml)
Definition: xml.c:1000
gboolean only_success
Definition: internal.h:93
unsigned int crm_trace_nonlog
Definition: logging.c:39
const char * get_object_parent(const char *object_type)
Definition: cib_utils.c:138
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
Retrieve the integer value of an XML attribute.
Definition: nvpair.c:459
#define XML_CIB_TAG_NODES
Definition: msg_xml.h:141
#define F_CIB_SECTION
Definition: internal.h:38
void(* callback)(const char *event, xmlNode *msg)
Definition: internal.h:85
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
Definition: xpath.c:220
Definition: cib.h:55
#define XML_ATTR_GENERATION
Definition: msg_xml.h:87
gboolean validate_xml(xmlNode *xml_blob, const char *validation, gboolean to_logs)
Definition: schemas.c:696
#define XML_CIB_TAG_PROPSET
Definition: msg_xml.h:162
bool xml_tracking_changes(xmlNode *xml)
Definition: xml.c:314
xmlNode * cib_create_op(int call_id, const char *token, const char *op, const char *host, const char *section, xmlNode *data, int call_options, const char *user_name)
Definition: cib_utils.c:512
void cib_native_notify(gpointer data, gpointer user_data)
Definition: cib_utils.c:594
xmlNode * copy_xml(xmlNode *src_node)
Definition: xml.c:2020
#define XML_CIB_TAG_RESOURCES
Definition: msg_xml.h:140
xmlNode * cib_get_generation(cib_t *cib)
Definition: cib_utils.c:66
void(* callback)(xmlNode *, int, int, xmlNode *, void *)
Definition: internal.h:90
void config_metadata(const char *name, const char *version, const char *desc_short, const char *desc_long, pe_cluster_option *option_list, int len)
Definition: utils.c:344
#define crm_warn(fmt, args...)
Definition: logging.h:241
bool pcmk_acl_required(const char *user)
Definition: acl.c:621
cib_api_operations_t * cmds
Definition: cib.h:157
#define crm_debug(fmt, args...)
Definition: logging.h:245
int cib_process_diff(const char *op, int options, const char *section, xmlNode *req, xmlNode *input, xmlNode *existing_cib, xmlNode **result_cib, xmlNode **answer)
Definition: cib_ops.c:577
int xml_apply_patchset(xmlNode *xml, xmlNode *patchset, bool check_version)
Definition: xml.c:1601
#define F_CIB_RC
Definition: internal.h:40
gboolean cib_internal_config_changed(xmlNode *diff)
Definition: cib_utils.c:743
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition: nvpair.c:423
#define F_CIB_OPERATION
Definition: internal.h:36
void(* op_callback)(const xmlNode *msg, int call_id, int rc, xmlNode *output)
Definition: cib.h:155
#define F_CIB_CLIENTNAME
Definition: internal.h:52
const char * crm_xml_replace(xmlNode *node, const char *name, const char *value)
Replace an XML attribute with specified name and (possibly NULL) value.
Definition: nvpair.c:332
#define crm_trace(fmt, args...)
Definition: logging.h:246
xmlNode * createEmptyCib(int admin_epoch)
Definition: cib_utils.c:168
#define F_CIB_USER
Definition: internal.h:56
#define crm_log_xml_debug(xml, text)
Definition: logging.h:253
#define F_CIB_UPDATE_RESULT
Definition: internal.h:51
#define F_CIB_HOST
Definition: internal.h:39
Wrappers for and extensions to libxml2.
xmlNode * create_xml_node(xmlNode *parent, const char *name)
Definition: xml.c:1890
#define crm_log_xml_warn(xml, text)
Definition: logging.h:250
gboolean check_positive_number(const char *value)
Definition: utils.c:123
#define XML_ATTR_VALIDATION
Definition: msg_xml.h:81
const char * event
Definition: internal.h:82
void xml_acl_disable(xmlNode *xml)
Definition: acl.c:533
#define CIB_OPTIONS_FIRST
Definition: msg_xml.h:49
#define F_ORIG
Definition: msg_xml.h:18
gboolean add_message_xml(xmlNode *msg, const char *field, xmlNode *xml)
Definition: xml.c:2512
gboolean check_boolean(const char *value)
Definition: utils.c:91
void free_xml(xmlNode *child)
Definition: xml.c:2014
#define ENABLE_ACL
Definition: config.h:53
#define EOS
Definition: crm.h:34
#define XML_CIB_TAG_ACLS
Definition: msg_xml.h:147
#define XML_CIB_TAG_GENERATION_TUPPLE
Definition: msg_xml.h:354
Definition: cib.h:65
#define T_CIB
Definition: internal.h:61
const char * xml_latest_schema(void)
Definition: schemas.c:115
void patchset_process_digest(xmlNode *patch, xmlNode *source, xmlNode *target, bool with_digest)
Definition: xml.c:781
gboolean crm_is_callsite_active(struct qb_log_callsite *cs, uint8_t level, uint32_t tags)
Definition: logging.c:624
bool xml_patch_versions(xmlNode *patchset, int add[3], int del[3])
Definition: xml.c:1192
GHashTable * cib_op_callback_table
Definition: cib_client.c:26
void xml_log_changes(uint8_t level, const char *function, xmlNode *xml)
Definition: xml.c:969
#define XML_TAG_CIB
Definition: msg_xml.h:76
gboolean cib_read_config(GHashTable *options, xmlNode *current_cib)
Definition: cib_utils.c:670
#define pcmk_err_diff_resync
Definition: results.h:66
#define F_CIB_CALLOPTS
Definition: internal.h:33
int cib_apply_patch_event(xmlNode *event, xmlNode *input, xmlNode **output, int level)
Definition: cib_utils.c:697
#define F_CIB_CALLDATA
Definition: internal.h:35
#define crm_err(fmt, args...)
Definition: logging.h:240
gboolean cib_diff_version_details(xmlNode *diff, int *admin_epoch, int *epoch, int *updates, int *_admin_epoch, int *_epoch, int *_updates)
Definition: cib_utils.c:99
#define CRM_ASSERT(expr)
Definition: results.h:42
xmlXPathObjectPtr xpath_search(xmlNode *xml_top, const char *path)
Definition: xpath.c:145
#define XML_CIB_ATTR_WRITTEN
Definition: msg_xml.h:93
crm_time_t * crm_time_new(const char *string)
Definition: iso8601.c:84
#define XML_CIB_TAG_CRMCONFIG
Definition: msg_xml.h:144
#define XML_CIB_TAG_RSCCONFIG
Definition: msg_xml.h:146
void verify_cib_options(GHashTable *options)
Definition: cib_utils.c:658
const char * id
Definition: internal.h:91
int compare_version(const char *version1, const char *version2)
Definition: utils.c:461
int cib_perform_op(const char *op, int call_options, cib_op_t *fn, gboolean is_query, const char *section, xmlNode *req, xmlNode *input, gboolean manage_counters, gboolean *config_changed, xmlNode *current_cib, xmlNode **result_cib, xmlNode **diff, xmlNode **output)
Definition: cib_utils.c:213
bool xml_acl_filtered_copy(const char *user, xmlNode *acl_source, xmlNode *xml, xmlNode **result)
Definition: acl.c:395
#define DIMOF(a)
Definition: crm.h:35
#define XML_ATTR_GENERATION_ADMIN
Definition: msg_xml.h:88
char data[0]
Definition: internal.h:92
#define crm_str(x)
Definition: logging.h:266
#define XML_ATTR_CRM_VERSION
Definition: msg_xml.h:79
void verify_all_options(GHashTable *options, pe_cluster_option *option_list, int len)
Definition: utils.c:379
const char * cib_pref(GHashTable *options, const char *name)
Definition: cib_utils.c:664
void save_xml_to_file(xmlNode *xml, const char *desc, const char *filename)
Definition: xml.c:3249
void strip_text_nodes(xmlNode *xml)
Definition: xml.c:2208
#define pcmk_ok
Definition: results.h:57
void cib_native_callback(cib_t *cib, xmlNode *msg, int call_id, int rc)
Definition: cib_utils.c:547
#define XML_CIB_TAG_STATUS
Definition: msg_xml.h:139
void unpack_instance_attributes(xmlNode *top, xmlNode *xml_obj, const char *set_name, GHashTable *node_hash, GHashTable *hash, const char *always_first, gboolean overwrite, crm_time_t *now)
Definition: rules.c:904
#define crm_log_xml_trace(xml, text)
Definition: logging.h:254
#define F_CIB_CALLID
Definition: internal.h:34
gboolean crm_is_true(const char *s)
Definition: strings.c:172
void cib_metadata(void)
Definition: cib_utils.c:649
#define XML_CIB_TAG_CONFIGURATION
Definition: msg_xml.h:138
int cib_internal_op(cib_t *cib, const char *op, const char *host, const char *section, xmlNode *data, xmlNode **output_data, int call_options, const char *user_name)
Definition: cib_utils.c:759
void xml_log_patchset(uint8_t level, const char *function, xmlNode *xml)
Definition: xml.c:814
#define safe_str_eq(a, b)
Definition: util.h:59
struct config_root_s known_paths[]
Definition: cib_utils.c:47
#define F_XML_TAGNAME
Definition: msg_xml.h:38
const char * get_cluster_pref(GHashTable *options, pe_cluster_option *option_list, int len, const char *name)
Definition: utils.c:325
void fix_plus_plus_recursive(xmlNode *target)
Definition: xml.c:1773
void freeXpathObject(xmlXPathObjectPtr xpathObj)
Definition: xpath.c:45
#define XML_CIB_TAG_OPCONFIG
Definition: msg_xml.h:145
xmlNode * xml_create_patchset(int format, xmlNode *source, xmlNode *target, bool *config, bool manage_version)
Definition: xml.c:724
void xml_calculate_changes(xmlNode *old_xml, xmlNode *new_xml)
Definition: xml.c:3532
Definition: cib.h:144
void * delegate_fn
Definition: cib.h:152
void crm_time_free(crm_time_t *dt)
Definition: iso8601.c:101