root/lib/cib/cib_utils.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. cib_get_generation
  2. cib_version_details
  3. cib_diff_version_details
  4. createEmptyCib
  5. cib_acl_enabled
  6. cib_perform_op
  7. cib_create_op
  8. cib_native_callback
  9. cib_native_notify
  10. cib_metadata
  11. verify_cib_options
  12. cib_pref
  13. cib_read_config
  14. cib_internal_config_changed
  15. cib_internal_op
  16. cib_apply_patch_event
  17. cib__signon_query
  18. cib__clean_up_connection
  19. get_object_path
  20. get_object_parent
  21. get_object_root

   1 /*
   2  * Original copyright 2004 International Business Machines
   3  * Later changes copyright 2008-2022 the Pacemaker project contributors
   4  *
   5  * The version control history for this file may have further details.
   6  *
   7  * This source code is licensed under the GNU Lesser General Public License
   8  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
   9  */
  10 #include <crm_internal.h>
  11 #include <unistd.h>
  12 #include <stdlib.h>
  13 #include <stdio.h>
  14 #include <stdarg.h>
  15 #include <string.h>
  16 #include <sys/utsname.h>
  17 
  18 #include <glib.h>
  19 
  20 #include <crm/crm.h>
  21 #include <crm/cib/internal.h>
  22 #include <crm/msg_xml.h>
  23 #include <crm/common/xml.h>
  24 #include <crm/common/xml_internal.h>
  25 #include <crm/pengine/rules.h>
  26 
  27 xmlNode *
  28 cib_get_generation(cib_t * cib)
     /* [previous][next][first][last][top][bottom][index][help] */
  29 {
  30     xmlNode *the_cib = NULL;
  31     xmlNode *generation = create_xml_node(NULL, XML_CIB_TAG_GENERATION_TUPPLE);
  32 
  33     cib->cmds->query(cib, NULL, &the_cib, cib_scope_local | cib_sync_call);
  34     if (the_cib != NULL) {
  35         copy_in_properties(generation, the_cib);
  36         free_xml(the_cib);
  37     }
  38 
  39     return generation;
  40 }
  41 
  42 gboolean
  43 cib_version_details(xmlNode * cib, int *admin_epoch, int *epoch, int *updates)
     /* [previous][next][first][last][top][bottom][index][help] */
  44 {
  45     *epoch = -1;
  46     *updates = -1;
  47     *admin_epoch = -1;
  48 
  49     if (cib == NULL) {
  50         return FALSE;
  51 
  52     } else {
  53         crm_element_value_int(cib, XML_ATTR_GENERATION, epoch);
  54         crm_element_value_int(cib, XML_ATTR_NUMUPDATES, updates);
  55         crm_element_value_int(cib, XML_ATTR_GENERATION_ADMIN, admin_epoch);
  56     }
  57     return TRUE;
  58 }
  59 
  60 gboolean
  61 cib_diff_version_details(xmlNode * diff, int *admin_epoch, int *epoch, int *updates,
     /* [previous][next][first][last][top][bottom][index][help] */
  62                          int *_admin_epoch, int *_epoch, int *_updates)
  63 {
  64     int add[] = { 0, 0, 0 };
  65     int del[] = { 0, 0, 0 };
  66 
  67     xml_patch_versions(diff, add, del);
  68 
  69     *admin_epoch = add[0];
  70     *epoch = add[1];
  71     *updates = add[2];
  72 
  73     *_admin_epoch = del[0];
  74     *_epoch = del[1];
  75     *_updates = del[2];
  76 
  77     return TRUE;
  78 }
  79 
  80 /*!
  81  * \brief Create XML for a new (empty) CIB
  82  *
  83  * \param[in] cib_epoch   What to use as "epoch" CIB property
  84  *
  85  * \return Newly created XML for empty CIB
  86  * \note It is the caller's responsibility to free the result with free_xml().
  87  */
  88 xmlNode *
  89 createEmptyCib(int cib_epoch)
     /* [previous][next][first][last][top][bottom][index][help] */
  90 {
  91     xmlNode *cib_root = NULL, *config = NULL;
  92 
  93     cib_root = create_xml_node(NULL, XML_TAG_CIB);
  94     crm_xml_add(cib_root, XML_ATTR_CRM_VERSION, CRM_FEATURE_SET);
  95     crm_xml_add(cib_root, XML_ATTR_VALIDATION, xml_latest_schema());
  96 
  97     crm_xml_add_int(cib_root, XML_ATTR_GENERATION, cib_epoch);
  98     crm_xml_add_int(cib_root, XML_ATTR_NUMUPDATES, 0);
  99     crm_xml_add_int(cib_root, XML_ATTR_GENERATION_ADMIN, 0);
 100 
 101     config = create_xml_node(cib_root, XML_CIB_TAG_CONFIGURATION);
 102     create_xml_node(cib_root, XML_CIB_TAG_STATUS);
 103 
 104     create_xml_node(config, XML_CIB_TAG_CRMCONFIG);
 105     create_xml_node(config, XML_CIB_TAG_NODES);
 106     create_xml_node(config, XML_CIB_TAG_RESOURCES);
 107     create_xml_node(config, XML_CIB_TAG_CONSTRAINTS);
 108 
 109 #if PCMK__RESOURCE_STICKINESS_DEFAULT != 0
 110     {
 111         xmlNode *rsc_defaults = create_xml_node(config, XML_CIB_TAG_RSCCONFIG);
 112         xmlNode *meta = create_xml_node(rsc_defaults, XML_TAG_META_SETS);
 113         xmlNode *nvpair = create_xml_node(meta, XML_CIB_TAG_NVPAIR);
 114 
 115         crm_xml_add(meta, XML_ATTR_ID, "build-resource-defaults");
 116         crm_xml_add(nvpair, XML_ATTR_ID, "build-" XML_RSC_ATTR_STICKINESS);
 117         crm_xml_add(nvpair, XML_NVPAIR_ATTR_NAME, XML_RSC_ATTR_STICKINESS);
 118         crm_xml_add_int(nvpair, XML_NVPAIR_ATTR_VALUE,
 119                         PCMK__RESOURCE_STICKINESS_DEFAULT);
 120     }
 121 #endif
 122     return cib_root;
 123 }
 124 
 125 static bool
 126 cib_acl_enabled(xmlNode *xml, const char *user)
     /* [previous][next][first][last][top][bottom][index][help] */
 127 {
 128     bool rc = FALSE;
 129 
 130     if(pcmk_acl_required(user)) {
 131         const char *value = NULL;
 132         GHashTable *options = pcmk__strkey_table(free, free);
 133 
 134         cib_read_config(options, xml);
 135         value = cib_pref(options, "enable-acl");
 136         rc = crm_is_true(value);
 137         g_hash_table_destroy(options);
 138     }
 139 
 140     crm_trace("CIB ACL is %s", rc ? "enabled" : "disabled");
 141     return rc;
 142 }
 143 
 144 int
 145 cib_perform_op(const char *op, int call_options, cib_op_t * fn, gboolean is_query,
     /* [previous][next][first][last][top][bottom][index][help] */
 146                const char *section, xmlNode * req, xmlNode * input,
 147                gboolean manage_counters, gboolean * config_changed,
 148                xmlNode * current_cib, xmlNode ** result_cib, xmlNode ** diff, xmlNode ** output)
 149 {
 150     int rc = pcmk_ok;
 151     gboolean check_schema = TRUE;
 152     xmlNode *top = NULL;
 153     xmlNode *scratch = NULL;
 154     xmlNode *local_diff = NULL;
 155 
 156     const char *new_version = NULL;
 157     static struct qb_log_callsite *diff_cs = NULL;
 158     const char *user = crm_element_value(req, F_CIB_USER);
 159     bool with_digest = FALSE;
 160 
 161     crm_trace("Begin %s%s%s op",
 162               (pcmk_is_set(call_options, cib_dryrun)? "dry run of " : ""),
 163               (is_query? "read-only " : ""), op);
 164 
 165     CRM_CHECK(output != NULL, return -ENOMSG);
 166     CRM_CHECK(result_cib != NULL, return -ENOMSG);
 167     CRM_CHECK(config_changed != NULL, return -ENOMSG);
 168 
 169     if(output) {
 170         *output = NULL;
 171     }
 172 
 173     *result_cib = NULL;
 174     *config_changed = FALSE;
 175 
 176     if (fn == NULL) {
 177         return -EINVAL;
 178     }
 179 
 180     if (is_query) {
 181         xmlNode *cib_ro = current_cib;
 182         xmlNode *cib_filtered = NULL;
 183 
 184         if(cib_acl_enabled(cib_ro, user)) {
 185             if(xml_acl_filtered_copy(user, current_cib, current_cib, &cib_filtered)) {
 186                 if (cib_filtered == NULL) {
 187                     crm_debug("Pre-filtered the entire cib");
 188                     return -EACCES;
 189                 }
 190                 cib_ro = cib_filtered;
 191                 crm_log_xml_trace(cib_ro, "filtered");
 192             }
 193         }
 194 
 195         rc = (*fn) (op, call_options, section, req, input, cib_ro, result_cib, output);
 196 
 197         if(output == NULL || *output == NULL) {
 198             /* nothing */
 199 
 200         } else if(cib_filtered == *output) {
 201             cib_filtered = NULL; /* Let them have this copy */
 202 
 203         } else if(*output == current_cib) {
 204             /* They already know not to free it */
 205 
 206         } else if(cib_filtered && (*output)->doc == cib_filtered->doc) {
 207             /* We're about to free the document of which *output is a part */
 208             *output = copy_xml(*output);
 209 
 210         } else if((*output)->doc == current_cib->doc) {
 211             /* Give them a copy they can free */
 212             *output = copy_xml(*output);
 213         }
 214 
 215         free_xml(cib_filtered);
 216         return rc;
 217     }
 218 
 219 
 220     if (pcmk_is_set(call_options, cib_zero_copy)) {
 221         /* Conditional on v2 patch style */
 222 
 223         scratch = current_cib;
 224 
 225         /* Create a shallow copy of current_cib for the version details */
 226         current_cib = create_xml_node(NULL, (const char *)scratch->name);
 227         copy_in_properties(current_cib, scratch);
 228         top = current_cib;
 229 
 230         xml_track_changes(scratch, user, NULL, cib_acl_enabled(scratch, user));
 231         rc = (*fn) (op, call_options, section, req, input, scratch, &scratch, output);
 232 
 233     } else {
 234         scratch = copy_xml(current_cib);
 235         xml_track_changes(scratch, user, NULL, cib_acl_enabled(scratch, user));
 236         rc = (*fn) (op, call_options, section, req, input, current_cib, &scratch, output);
 237 
 238         if(scratch && xml_tracking_changes(scratch) == FALSE) {
 239             crm_trace("Inferring changes after %s op", op);
 240             xml_track_changes(scratch, user, current_cib, cib_acl_enabled(current_cib, user));
 241             xml_calculate_changes(current_cib, scratch);
 242         }
 243         CRM_CHECK(current_cib != scratch, return -EINVAL);
 244     }
 245 
 246     xml_acl_disable(scratch); /* Allow the system to make any additional changes */
 247 
 248     if (rc == pcmk_ok && scratch == NULL) {
 249         rc = -EINVAL;
 250         goto done;
 251 
 252     } else if(rc == pcmk_ok && xml_acl_denied(scratch)) {
 253         crm_trace("ACL rejected part or all of the proposed changes");
 254         rc = -EACCES;
 255         goto done;
 256 
 257     } else if (rc != pcmk_ok) {
 258         goto done;
 259     }
 260 
 261     if (scratch) {
 262         new_version = crm_element_value(scratch, XML_ATTR_CRM_VERSION);
 263 
 264         if (new_version && compare_version(new_version, CRM_FEATURE_SET) > 0) {
 265             crm_err("Discarding update with feature set '%s' greater than our own '%s'",
 266                     new_version, CRM_FEATURE_SET);
 267             rc = -EPROTONOSUPPORT;
 268             goto done;
 269         }
 270     }
 271 
 272     if (current_cib) {
 273         int old = 0;
 274         int new = 0;
 275 
 276         crm_element_value_int(scratch, XML_ATTR_GENERATION_ADMIN, &new);
 277         crm_element_value_int(current_cib, XML_ATTR_GENERATION_ADMIN, &old);
 278 
 279         if (old > new) {
 280             crm_err("%s went backwards: %d -> %d (Opts: %#x)",
 281                     XML_ATTR_GENERATION_ADMIN, old, new, call_options);
 282             crm_log_xml_warn(req, "Bad Op");
 283             crm_log_xml_warn(input, "Bad Data");
 284             rc = -pcmk_err_old_data;
 285 
 286         } else if (old == new) {
 287             crm_element_value_int(scratch, XML_ATTR_GENERATION, &new);
 288             crm_element_value_int(current_cib, XML_ATTR_GENERATION, &old);
 289             if (old > new) {
 290                 crm_err("%s went backwards: %d -> %d (Opts: %#x)",
 291                         XML_ATTR_GENERATION, old, new, call_options);
 292                 crm_log_xml_warn(req, "Bad Op");
 293                 crm_log_xml_warn(input, "Bad Data");
 294                 rc = -pcmk_err_old_data;
 295             }
 296         }
 297     }
 298 
 299     crm_trace("Massaging CIB contents");
 300     pcmk__strip_xml_text(scratch);
 301     fix_plus_plus_recursive(scratch);
 302 
 303     if (pcmk_is_set(call_options, cib_zero_copy)) {
 304         /* At this point, current_cib is just the 'cib' tag and its properties,
 305          *
 306          * The v1 format would barf on this, but we know the v2 patch
 307          * format only needs it for the top-level version fields
 308          */
 309         local_diff = xml_create_patchset(2, current_cib, scratch, (bool*)config_changed, manage_counters);
 310 
 311     } else {
 312         static time_t expires = 0;
 313         time_t tm_now = time(NULL);
 314 
 315         if (expires < tm_now) {
 316             expires = tm_now + 60;  /* Validate clients are correctly applying v2-style diffs at most once a minute */
 317             with_digest = TRUE;
 318         }
 319 
 320         local_diff = xml_create_patchset(0, current_cib, scratch, (bool*)config_changed, manage_counters);
 321     }
 322 
 323     xml_log_changes(LOG_TRACE, __func__, scratch);
 324     xml_accept_changes(scratch);
 325 
 326     if (diff_cs == NULL) {
 327         diff_cs = qb_log_callsite_get(__PRETTY_FUNCTION__, __FILE__, "diff-validation", LOG_DEBUG, __LINE__, crm_trace_nonlog);
 328     }
 329 
 330     if(local_diff) {
 331         patchset_process_digest(local_diff, current_cib, scratch, with_digest);
 332 
 333         xml_log_patchset(LOG_INFO, __func__, local_diff);
 334         crm_log_xml_trace(local_diff, "raw patch");
 335     }
 336 
 337     if (!pcmk_is_set(call_options, cib_zero_copy) // Original to compare against doesn't exist
 338         && local_diff
 339         && crm_is_callsite_active(diff_cs, LOG_TRACE, 0)) {
 340 
 341         /* Validate the calculated patch set */
 342         int test_rc, format = 1;
 343         xmlNode * c = copy_xml(current_cib);
 344 
 345         crm_element_value_int(local_diff, "format", &format);
 346         test_rc = xml_apply_patchset(c, local_diff, manage_counters);
 347 
 348         if(test_rc != pcmk_ok) {
 349             save_xml_to_file(c,           "PatchApply:calculated", NULL);
 350             save_xml_to_file(current_cib, "PatchApply:input", NULL);
 351             save_xml_to_file(scratch,     "PatchApply:actual", NULL);
 352             save_xml_to_file(local_diff,  "PatchApply:diff", NULL);
 353             crm_err("v%d patchset error, patch failed to apply: %s (%d)", format, pcmk_strerror(test_rc), test_rc);
 354         }
 355         free_xml(c);
 356     }
 357 
 358     if (pcmk__str_eq(section, XML_CIB_TAG_STATUS, pcmk__str_casei)) {
 359         /* Throttle the amount of costly validation we perform due to status updates
 360          * a) we don't really care whats in the status section
 361          * b) we don't validate any of its contents at the moment anyway
 362          */
 363         check_schema = FALSE;
 364     }
 365 
 366     /* === scratch must not be modified after this point ===
 367      * Exceptions, anything in:
 368 
 369      static filter_t filter[] = {
 370      { 0, XML_ATTR_ORIGIN },
 371      { 0, XML_CIB_ATTR_WRITTEN },
 372      { 0, XML_ATTR_UPDATE_ORIG },
 373      { 0, XML_ATTR_UPDATE_CLIENT },
 374      { 0, XML_ATTR_UPDATE_USER },
 375      };
 376      */
 377 
 378     if (*config_changed && !pcmk_is_set(call_options, cib_no_mtime)) {
 379         const char *schema = crm_element_value(scratch, XML_ATTR_VALIDATION);
 380 
 381         pcmk__xe_add_last_written(scratch);
 382         if (schema) {
 383             static int minimum_schema = 0;
 384             int current_schema = get_schema_version(schema);
 385 
 386             if (minimum_schema == 0) {
 387                 minimum_schema = get_schema_version("pacemaker-1.2");
 388             }
 389 
 390             /* Does the CIB support the "update-*" attributes... */
 391             if (current_schema >= minimum_schema) {
 392                 const char *origin = crm_element_value(req, F_ORIG);
 393 
 394                 CRM_LOG_ASSERT(origin != NULL);
 395                 crm_xml_replace(scratch, XML_ATTR_UPDATE_ORIG, origin);
 396                 crm_xml_replace(scratch, XML_ATTR_UPDATE_CLIENT,
 397                                 crm_element_value(req, F_CIB_CLIENTNAME));
 398                 crm_xml_replace(scratch, XML_ATTR_UPDATE_USER, crm_element_value(req, F_CIB_USER));
 399             }
 400         }
 401     }
 402 
 403     crm_trace("Perform validation: %s", pcmk__btoa(check_schema));
 404     if ((rc == pcmk_ok) && check_schema && !validate_xml(scratch, NULL, TRUE)) {
 405         const char *current_schema = crm_element_value(scratch,
 406                                                        XML_ATTR_VALIDATION);
 407 
 408         crm_warn("Updated CIB does not validate against %s schema",
 409                  pcmk__s(current_schema, "unspecified"));
 410         rc = -pcmk_err_schema_validation;
 411     }
 412 
 413   done:
 414 
 415     *result_cib = scratch;
 416     if(rc != pcmk_ok && cib_acl_enabled(current_cib, user)) {
 417         if(xml_acl_filtered_copy(user, current_cib, scratch, result_cib)) {
 418             if (*result_cib == NULL) {
 419                 crm_debug("Pre-filtered the entire cib result");
 420             }
 421             free_xml(scratch);
 422         }
 423     }
 424 
 425     if(diff) {
 426         *diff = local_diff;
 427     } else {
 428         free_xml(local_diff);
 429     }
 430 
 431     free_xml(top);
 432     crm_trace("Done");
 433     return rc;
 434 }
 435 
 436 xmlNode *
 437 cib_create_op(int call_id, const char *token, const char *op, const char *host, const char *section,
     /* [previous][next][first][last][top][bottom][index][help] */
 438               xmlNode * data, int call_options, const char *user_name)
 439 {
 440     xmlNode *op_msg = create_xml_node(NULL, "cib_command");
 441 
 442     CRM_CHECK(op_msg != NULL, return NULL);
 443     CRM_CHECK(token != NULL, return NULL);
 444 
 445     crm_xml_add(op_msg, F_XML_TAGNAME, "cib_command");
 446 
 447     crm_xml_add(op_msg, F_TYPE, T_CIB);
 448     crm_xml_add(op_msg, F_CIB_CALLBACK_TOKEN, token);
 449     crm_xml_add(op_msg, F_CIB_OPERATION, op);
 450     crm_xml_add(op_msg, F_CIB_HOST, host);
 451     crm_xml_add(op_msg, F_CIB_SECTION, section);
 452     crm_xml_add_int(op_msg, F_CIB_CALLID, call_id);
 453     if (user_name) {
 454         crm_xml_add(op_msg, F_CIB_USER, user_name);
 455     }
 456     crm_trace("Sending call options: %.8lx, %d", (long)call_options, call_options);
 457     crm_xml_add_int(op_msg, F_CIB_CALLOPTS, call_options);
 458 
 459     if (data != NULL) {
 460         add_message_xml(op_msg, F_CIB_CALLDATA, data);
 461     }
 462 
 463     if (call_options & cib_inhibit_bcast) {
 464         CRM_CHECK((call_options & cib_scope_local), return NULL);
 465     }
 466     return op_msg;
 467 }
 468 
 469 void
 470 cib_native_callback(cib_t * cib, xmlNode * msg, int call_id, int rc)
     /* [previous][next][first][last][top][bottom][index][help] */
 471 {
 472     xmlNode *output = NULL;
 473     cib_callback_client_t *blob = NULL;
 474 
 475     if (msg != NULL) {
 476         crm_element_value_int(msg, F_CIB_RC, &rc);
 477         crm_element_value_int(msg, F_CIB_CALLID, &call_id);
 478         output = get_message_xml(msg, F_CIB_CALLDATA);
 479     }
 480 
 481     blob = cib__lookup_id(call_id);
 482 
 483     if (blob == NULL) {
 484         crm_trace("No callback found for call %d", call_id);
 485     }
 486 
 487     if (cib == NULL) {
 488         crm_debug("No cib object supplied");
 489     }
 490 
 491     if (rc == -pcmk_err_diff_resync) {
 492         /* This is an internal value that clients do not and should not care about */
 493         rc = pcmk_ok;
 494     }
 495 
 496     if (blob && blob->callback && (rc == pcmk_ok || blob->only_success == FALSE)) {
 497         crm_trace("Invoking callback %s for call %d",
 498                   pcmk__s(blob->id, "without ID"), call_id);
 499         blob->callback(msg, call_id, rc, output, blob->user_data);
 500 
 501     } else if (cib && cib->op_callback == NULL && rc != pcmk_ok) {
 502         crm_warn("CIB command failed: %s", pcmk_strerror(rc));
 503         crm_log_xml_debug(msg, "Failed CIB Update");
 504     }
 505 
 506     /* This may free user_data, so do it after the callback */
 507     if (blob) {
 508         remove_cib_op_callback(call_id, FALSE);
 509     }
 510 
 511     if (cib && cib->op_callback != NULL) {
 512         crm_trace("Invoking global callback for call %d", call_id);
 513         cib->op_callback(msg, call_id, rc, output);
 514     }
 515     crm_trace("OP callback activated for %d", call_id);
 516 }
 517 
 518 void
 519 cib_native_notify(gpointer data, gpointer user_data)
     /* [previous][next][first][last][top][bottom][index][help] */
 520 {
 521     xmlNode *msg = user_data;
 522     cib_notify_client_t *entry = data;
 523     const char *event = NULL;
 524 
 525     if (msg == NULL) {
 526         crm_warn("Skipping callback - NULL message");
 527         return;
 528     }
 529 
 530     event = crm_element_value(msg, F_SUBTYPE);
 531 
 532     if (entry == NULL) {
 533         crm_warn("Skipping callback - NULL callback client");
 534         return;
 535 
 536     } else if (entry->callback == NULL) {
 537         crm_warn("Skipping callback - NULL callback");
 538         return;
 539 
 540     } else if (!pcmk__str_eq(entry->event, event, pcmk__str_casei)) {
 541         crm_trace("Skipping callback - event mismatch %p/%s vs. %s", entry, entry->event, event);
 542         return;
 543     }
 544 
 545     crm_trace("Invoking callback for %p/%s event...", entry, event);
 546     entry->callback(event, msg);
 547     crm_trace("Callback invoked...");
 548 }
 549 
 550 static pcmk__cluster_option_t cib_opts[] = {
 551     /* name, legacy name, type, allowed values,
 552      * default value, validator,
 553      * short description,
 554      * long description
 555      */
 556     {
 557         "enable-acl", NULL, "boolean", NULL,
 558         "false", pcmk__valid_boolean,
 559         N_("Enable Access Control Lists (ACLs) for the CIB"),
 560         NULL
 561     },
 562     {
 563         "cluster-ipc-limit", NULL, "integer", NULL,
 564         "500", pcmk__valid_positive_number,
 565         N_("Maximum IPC message backlog before disconnecting a cluster daemon"),
 566         N_("Raise this if log has \"Evicting client\" messages for cluster daemon"
 567             " PIDs (a good value is the number of resources in the cluster"
 568             " multiplied by the number of nodes).")
 569     },
 570 };
 571 
 572 void
 573 cib_metadata(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 574 {
 575     const char *desc_short = "Cluster Information Base manager options";
 576     const char *desc_long = "Cluster options used by Pacemaker's Cluster "
 577                             "Information Base manager";
 578 
 579     gchar *s = pcmk__format_option_metadata("pacemaker-based", desc_short,
 580                                             desc_long, cib_opts,
 581                                             PCMK__NELEM(cib_opts));
 582     printf("%s", s);
 583     g_free(s);
 584 }
 585 
 586 void
 587 verify_cib_options(GHashTable * options)
     /* [previous][next][first][last][top][bottom][index][help] */
 588 {
 589     pcmk__validate_cluster_options(options, cib_opts, PCMK__NELEM(cib_opts));
 590 }
 591 
 592 const char *
 593 cib_pref(GHashTable * options, const char *name)
     /* [previous][next][first][last][top][bottom][index][help] */
 594 {
 595     return pcmk__cluster_option(options, cib_opts, PCMK__NELEM(cib_opts),
 596                                 name);
 597 }
 598 
 599 gboolean
 600 cib_read_config(GHashTable * options, xmlNode * current_cib)
     /* [previous][next][first][last][top][bottom][index][help] */
 601 {
 602     xmlNode *config = NULL;
 603     crm_time_t *now = NULL;
 604 
 605     if (options == NULL || current_cib == NULL) {
 606         return FALSE;
 607     }
 608 
 609     now = crm_time_new(NULL);
 610 
 611     g_hash_table_remove_all(options);
 612 
 613     config = pcmk_find_cib_element(current_cib, XML_CIB_TAG_CRMCONFIG);
 614     if (config) {
 615         pe_unpack_nvpairs(current_cib, config, XML_CIB_TAG_PROPSET, NULL,
 616                           options, CIB_OPTIONS_FIRST, TRUE, now, NULL);
 617     }
 618 
 619     verify_cib_options(options);
 620 
 621     crm_time_free(now);
 622 
 623     return TRUE;
 624 }
 625 
 626 /* v2 and v2 patch formats */
 627 #define XPATH_CONFIG_CHANGE \
 628     "//" XML_CIB_TAG_CRMCONFIG " | " \
 629     "//" XML_DIFF_CHANGE "[contains(@" XML_DIFF_PATH ",'/" XML_CIB_TAG_CRMCONFIG "/')]"
 630 
 631 gboolean
 632 cib_internal_config_changed(xmlNode *diff)
     /* [previous][next][first][last][top][bottom][index][help] */
 633 {
 634     gboolean changed = FALSE;
 635 
 636     if (diff) {
 637         xmlXPathObject *xpathObj = xpath_search(diff, XPATH_CONFIG_CHANGE);
 638 
 639         if (numXpathResults(xpathObj) > 0) {
 640             changed = TRUE;
 641         }
 642         freeXpathObject(xpathObj);
 643     }
 644     return changed;
 645 }
 646 
 647 int
 648 cib_internal_op(cib_t * cib, const char *op, const char *host,
     /* [previous][next][first][last][top][bottom][index][help] */
 649                 const char *section, xmlNode * data,
 650                 xmlNode ** output_data, int call_options, const char *user_name)
 651 {
 652     int (*delegate) (cib_t * cib, const char *op, const char *host,
 653                      const char *section, xmlNode * data,
 654                      xmlNode ** output_data, int call_options, const char *user_name) =
 655         cib->delegate_fn;
 656 
 657     if(user_name == NULL) {
 658         user_name = getenv("CIB_user");
 659     }
 660 
 661     return delegate(cib, op, host, section, data, output_data, call_options, user_name);
 662 }
 663 
 664 /*!
 665  * \brief Apply a CIB update patch to a given CIB
 666  *
 667  * \param[in]  event   CIB update patch
 668  * \param[in]  input   CIB to patch
 669  * \param[out] output  Resulting CIB after patch
 670  * \param[in]  level   Log the patch at this log level (unless LOG_CRIT)
 671  *
 672  * \return Legacy Pacemaker return code
 673  * \note sbd calls this function
 674  */
 675 int
 676 cib_apply_patch_event(xmlNode *event, xmlNode *input, xmlNode **output,
     /* [previous][next][first][last][top][bottom][index][help] */
 677                       int level)
 678 {
 679     int rc = pcmk_err_generic;
 680 
 681     xmlNode *diff = NULL;
 682 
 683     CRM_ASSERT(event);
 684     CRM_ASSERT(input);
 685     CRM_ASSERT(output);
 686 
 687     crm_element_value_int(event, F_CIB_RC, &rc);
 688     diff = get_message_xml(event, F_CIB_UPDATE_RESULT);
 689 
 690     if (rc < pcmk_ok || diff == NULL) {
 691         return rc;
 692     }
 693 
 694     if (level > LOG_CRIT) {
 695         xml_log_patchset(level, "Config update", diff);
 696     }
 697 
 698     if (input != NULL) {
 699         rc = cib_process_diff(NULL, cib_none, NULL, event, diff, input, output,
 700                               NULL);
 701 
 702         if (rc != pcmk_ok) {
 703             crm_debug("Update didn't apply: %s (%d) %p",
 704                       pcmk_strerror(rc), rc, *output);
 705 
 706             if (rc == -pcmk_err_old_data) {
 707                 crm_trace("Masking error, we already have the supplied update");
 708                 return pcmk_ok;
 709             }
 710             free_xml(*output);
 711             *output = NULL;
 712             return rc;
 713         }
 714     }
 715     return rc;
 716 }
 717 
 718 int
 719 cib__signon_query(cib_t **cib, xmlNode **cib_object)
     /* [previous][next][first][last][top][bottom][index][help] */
 720 {
 721     int rc = pcmk_rc_ok;
 722     cib_t *cib_conn = NULL;
 723 
 724     CRM_ASSERT(cib_object != NULL);
 725 
 726     if (cib == NULL) {
 727         cib_conn = cib_new();
 728     } else {
 729         *cib = cib_new();
 730         cib_conn = *cib;
 731     }
 732 
 733     if (cib_conn == NULL) {
 734         return ENOMEM;
 735     }
 736 
 737     rc = cib_conn->cmds->signon(cib_conn, crm_system_name, cib_command);
 738     rc = pcmk_legacy2rc(rc);
 739 
 740     if (rc == pcmk_rc_ok) {
 741         rc = cib_conn->cmds->query(cib_conn, NULL, cib_object, cib_scope_local | cib_sync_call);
 742         rc = pcmk_legacy2rc(rc);
 743     }
 744 
 745     if (cib == NULL) {
 746         cib__clean_up_connection(&cib_conn);
 747     }
 748 
 749     if (*cib_object == NULL) {
 750         return pcmk_rc_no_input;
 751     }
 752     return rc;
 753 }
 754 
 755 int
 756 cib__clean_up_connection(cib_t **cib)
     /* [previous][next][first][last][top][bottom][index][help] */
 757 {
 758     int rc;
 759 
 760     if (*cib == NULL) {
 761         return pcmk_rc_ok;
 762     }
 763 
 764     rc = (*cib)->cmds->signoff(*cib);
 765     cib_delete(*cib);
 766     *cib = NULL;
 767     return pcmk_legacy2rc(rc);
 768 }
 769 
 770 // Deprecated functions kept only for backward API compatibility
 771 // LCOV_EXCL_START
 772 
 773 #include <crm/cib/util_compat.h>
 774 
 775 const char *
 776 get_object_path(const char *object_type)
     /* [previous][next][first][last][top][bottom][index][help] */
 777 {
 778     return pcmk_cib_xpath_for(object_type);
 779 }
 780 
 781 const char *
 782 get_object_parent(const char *object_type)
     /* [previous][next][first][last][top][bottom][index][help] */
 783 {
 784     return pcmk_cib_parent_name_for(object_type);
 785 }
 786 
 787 xmlNode *
 788 get_object_root(const char *object_type, xmlNode *the_root)
     /* [previous][next][first][last][top][bottom][index][help] */
 789 {
 790     return pcmk_find_cib_element(the_root, object_type);
 791 }
 792 
 793 // LCOV_EXCL_STOP
 794 // End deprecated API

/* [previous][next][first][last][top][bottom][index][help] */