16 #include <sys/utsname.h> 47 int *_admin_epoch,
int *_epoch,
int *_updates)
49 int add[] = { 0, 0, 0 };
50 int del[] = { 0, 0, 0 };
54 *admin_epoch = add[0];
58 *_admin_epoch = del[0];
78 xmlNode *wrapper = NULL;
84 crm_err(
"CIB diff notification received with no XML");
100 if (*patchset == NULL) {
101 crm_err(
"CIB diff notification received with no patchset");
107 #define XPATH_DIFF_V1 "//" PCMK__XE_CIB_UPDATE_RESULT "//" PCMK__XE_DIFF_ADDED 120 element_in_patchset_v1(
const xmlNode *patchset,
const char *element)
124 xmlXPathObject *xpath_obj =
xpath_search(patchset, xpath);
128 if (xpath_obj == NULL) {
147 element_in_patchset_v2(
const xmlNode *patchset,
const char *element)
151 char *element_regex = NULL;
154 CRM_CHECK(element_xpath != NULL,
return false);
208 return element_in_patchset_v1(patchset, element);
211 return element_in_patchset_v2(patchset, element);
214 crm_warn(
"Unknown patch format: %d", format);
230 xmlNode *cib_root = NULL, *config = NULL;
248 #if PCMK__RESOURCE_STICKINESS_DEFAULT != 0 265 cib_acl_enabled(xmlNode *xml,
const char *user)
270 const char *value = NULL;
276 g_hash_table_destroy(options);
279 crm_trace(
"CIB ACL is %s", rc ?
"enabled" :
"disabled");
294 should_copy_cib(
const char *op,
const char *section,
int call_options)
334 xmlNode *req, xmlNode *
input,
bool manage_counters,
335 bool *config_changed, xmlNode **current_cib,
336 xmlNode **result_cib, xmlNode **diff, xmlNode **output)
339 bool check_schema =
true;
340 bool make_copy =
true;
342 xmlNode *scratch = NULL;
343 xmlNode *patchset_cib = NULL;
344 xmlNode *local_diff = NULL;
347 bool with_digest =
false;
351 (is_query?
"read-only " :
""), op);
353 CRM_CHECK(output != NULL,
return -ENOMSG);
354 CRM_CHECK(current_cib != NULL,
return -ENOMSG);
355 CRM_CHECK(result_cib != NULL,
return -ENOMSG);
356 CRM_CHECK(config_changed != NULL,
return -ENOMSG);
363 *config_changed =
false;
370 xmlNode *cib_ro = *current_cib;
371 xmlNode *cib_filtered = NULL;
373 if (cib_acl_enabled(cib_ro, user)
377 if (cib_filtered == NULL) {
378 crm_debug(
"Pre-filtered the entire cib");
381 cib_ro = cib_filtered;
385 rc = (*fn) (op, call_options, section, req,
input, cib_ro, result_cib, output);
387 if(output == NULL || *output == NULL) {
390 }
else if(cib_filtered == *output) {
393 }
else if (*output == *current_cib) {
396 }
else if(cib_filtered && (*output)->doc == cib_filtered->doc) {
400 }
else if ((*output)->doc == (*current_cib)->doc) {
409 make_copy = should_copy_cib(op, section, call_options);
414 scratch = *current_cib;
422 rc = (*fn) (op, call_options, section, req,
input, scratch, &scratch, output);
427 *current_cib = scratch;
431 patchset_cib = *current_cib;
434 rc = (*fn) (op, call_options, section, req,
input, *current_cib,
438 crm_trace(
"Inferring changes after %s op", op);
440 cib_acl_enabled(*current_cib, user));
443 CRM_CHECK(*current_cib != scratch,
return -EINVAL);
448 if (rc ==
pcmk_ok && scratch == NULL) {
453 crm_trace(
"ACL rejected part or all of the proposed changes");
470 pcmk__config_err(
"Discarding update with feature set '%s' greater than our own '%s'",
477 if (patchset_cib != NULL) {
485 crm_err(
"%s went backwards: %d -> %d (Opts: %#x)",
491 }
else if (old ==
new) {
495 crm_err(
"%s went backwards: %d -> %d (Opts: %#x)",
515 config_changed, manage_counters);
518 static time_t expires = 0;
519 time_t tm_now = time(NULL);
521 if (expires < tm_now) {
522 expires = tm_now + 60;
527 config_changed, manage_counters);
539 if (make_copy && (local_diff != NULL)) {
557 crm_err(
"v%d patchset error, patch failed to apply: %s " 573 check_schema =
false;
602 if (origin != NULL) {
608 if (client != NULL) {
622 crm_trace(
"Perform validation: %s", pcmk__btoa(check_schema));
623 if ((rc ==
pcmk_ok) && check_schema
628 crm_warn(
"Updated CIB does not validate against %s schema",
629 pcmk__s(current_schema,
"unspecified"));
635 *result_cib = scratch;
640 if ((rc !=
pcmk_ok) && cib_acl_enabled(patchset_cib, user)
643 if (*result_cib == NULL) {
644 crm_debug(
"Pre-filtered the entire cib result");
662 const char *section, xmlNode *
data,
int call_options,
663 const char *user_name,
const char *client_name,
666 CRM_CHECK((cib != NULL) && (op_msg != NULL),
return -EPROTO);
683 crm_trace(
"Sending call options: %.8lx, %d", (
long)call_options, call_options);
708 validate_transaction_request(
const xmlNode *request)
721 crm_err(
"Operation %s is not supported in CIB transactions", op);
726 crm_err(
"Operation targeting a specific node (%s) is not supported in " 750 rc = validate_transaction_request(request);
761 const char *client_id = NULL;
764 crm_err(
"Failed to add '%s' operation to transaction for client %s: %s",
765 op, pcmk__s(client_id,
"(unidentified)"),
pcmk_rc_str(rc));
774 xmlNode *output = NULL;
778 xmlNode *wrapper = NULL;
789 crm_trace(
"No callback found for call %d", call_id);
802 crm_trace(
"Invoking callback %s for call %d",
803 pcmk__s(blob->
id,
"without ID"), call_id);
817 crm_trace(
"Invoking global callback for call %d", call_id);
820 crm_trace(
"OP callback activated for %d", call_id);
826 xmlNode *msg = user_data;
828 const char *
event = NULL;
831 crm_warn(
"Skipping callback - NULL message");
838 crm_warn(
"Skipping callback - NULL callback client");
841 }
else if (entry->
callback == NULL) {
842 crm_warn(
"Skipping callback - NULL callback");
846 crm_trace(
"Skipping callback - event mismatch %p/%s vs. %s", entry, entry->
event, event);
850 crm_trace(
"Invoking callback for %p/%s event...", entry, event);
858 xmlNode *config = NULL;
861 if (options == NULL || current_cib == NULL) {
867 g_hash_table_remove_all(options);
885 const char *section, xmlNode *
data,
886 xmlNode ** output_data,
int call_options,
const char *user_name)
888 int (*delegate)(
cib_t *cib,
const char *op,
const char *
host,
889 const char *section, xmlNode *
data, xmlNode **output_data,
890 int call_options,
const char *user_name) = NULL;
897 if (delegate == NULL) {
898 return -EPROTONOSUPPORT;
900 if (user_name == NULL) {
901 user_name = getenv(
"CIB_user");
903 return delegate(cib, op,
host, section,
data, output_data, call_options, user_name);
923 xmlNode *wrapper = NULL;
924 xmlNode *diff = NULL;
933 if (rc <
pcmk_ok || diff == NULL) {
937 if (level > LOG_CRIT) {
946 crm_debug(
"Update didn't apply: %s (%d) %p",
950 crm_trace(
"Masking error, we already have the supplied update");
961 #define log_signon_query_err(out, fmt, args...) do { \ 963 out->err(out, fmt, ##args); \ 965 crm_err(fmt, ##args); \ 973 cib_t *cib_conn = NULL;
986 if (cib_conn == NULL) {
1004 rc = cib_conn->
cmds->
query(cib_conn, NULL, cib_object,
1017 if ((rc ==
pcmk_rc_ok) && (*cib_object == NULL)) {
1029 crm_trace(
"Attempting connection to CIB manager (up to %d time%s)",
1032 for (
int remaining = attempts - 1; remaining >= 0; --remaining) {
1037 || ((errno != EAGAIN) && (errno != EALREADY))) {
1043 crm_debug(
"Re-attempting connection to CIB manager (%d attempt%s remaining)",
1059 rc = (*cib)->cmds->signoff(*cib);
1073 xmlNode *the_cib = NULL;
1077 if (the_cib != NULL) {
1121 "Cluster Information Base manager options",
1122 "Cluster options used by Pacemaker's Cluster " 1123 "Information Base manager",
#define pcmk_err_old_data
#define CRM_CHECK(expr, failure_action)
#define pcmk_err_schema_validation
const char * get_object_parent(const char *object_type)
xmlNode * pcmk__xml_copy(xmlNode *parent, xmlNode *src)
const char * pcmk_strerror(int rc)
int pcmk__cmp_schemas_by_name(const char *schema1_name, const char *schema2_name)
#define pcmk__if_tracing(if_action, else_action)
int pcmk_rc2legacy(int rc)
int pcmk__xe_copy_attrs(xmlNode *target, const xmlNode *src, uint32_t flags)
cib_t * cib_new(void)
Create a new CIB connection object.
#define PCMK_XA_UPDATE_ORIGIN
int pcmk__daemon_metadata(pcmk__output_t *out, const char *name, const char *short_desc, const char *long_desc, enum pcmk__opt_flags filter)
void save_xml_to_file(const xmlNode *xml, const char *desc, const char *filename)
#define PCMK__XE_GENERATION_TUPLE
const char * pcmk__xe_add_last_written(xmlNode *xe)
struct crm_time_s crm_time_t
gboolean cib_version_details(xmlNode *cib, int *admin_epoch, int *epoch, int *updates)
#define PCMK__RESOURCE_STICKINESS_DEFAULT
bool xml_acl_filtered_copy(const char *user, xmlNode *acl_source, xmlNode *xml, xmlNode **result)
Copy ACL-allowed portions of specified XML.
#define PCMK_XE_CONSTRAINTS
#define PCMK__XE_CIB_COMMAND
void pe_unpack_nvpairs(xmlNode *top, const xmlNode *xml_obj, const char *set_name, GHashTable *node_hash, GHashTable *hash, const char *always_first, gboolean overwrite, crm_time_t *now, crm_time_t *next_change)
Extract nvpair blocks contained by an XML element into a hash table.
#define PCMK_VALUE_CREATE
void(* callback)(const char *event, xmlNode *msg)
int cib__signon_attempts(cib_t *cib, const char *name, enum cib_conn_type type, int attempts)
#define PCMK_XE_RSC_DEFAULTS
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
Create an XML attribute with specified name and integer value.
#define pcmk__config_err(fmt...)
#define PCMK_XA_NUM_UPDATES
xmlNode * cib_get_generation(cib_t *cib)
#define PCMK__CIB_REQUEST_COMMIT_TRANSACT
void xml_track_changes(xmlNode *xml, const char *user, xmlNode *acl_source, bool enforce_acls)
void remove_cib_op_callback(int call_id, gboolean all_callbacks)
int cib__extend_transaction(cib_t *cib, xmlNode *request)
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
#define PCMK_OPT_ENABLE_ACL
xmlNode * get_object_root(const char *object_type, xmlNode *the_root)
int cib_apply_patch_event(xmlNode *event, xmlNode *input, xmlNode **output, int level)
Apply a CIB update patch to a given CIB.
enum crm_ais_msg_types type
Supported in a transaction.
Deprecated Pacemaker configuration utilities.
void xml_accept_changes(xmlNode *xml)
#define PCMK__XA_CIB_SECTION
void pcmk__validate_cluster_options(GHashTable *options)
const char * pcmk__cluster_option(GHashTable *options, const char *name)
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
Retrieve the integer value of an XML attribute.
#define PCMK_XA_OPERATION
int cib__clean_up_connection(cib_t **cib)
void cib_delete(cib_t *cib)
Free all memory used by CIB connection.
cib_callback_client_t * cib__lookup_id(int call_id)
bool cib__element_in_patchset(const xmlNode *patchset, const char *element)
bool xml_tracking_changes(xmlNode *xml)
gboolean cib_read_config(GHashTable *options, xmlNode *current_cib)
int cib__get_notify_patchset(const xmlNode *msg, const xmlNode **patchset)
const char * get_object_path(const char *object_type)
#define crm_warn(fmt, args...)
#define PCMK__XA_CIB_HOST
int cib__signon_query(pcmk__output_t *out, cib_t **cib, xmlNode **cib_object)
void pcmk__strip_xml_text(xmlNode *xml)
void pcmk__sleep_ms(unsigned int ms)
cib_api_operations_t * cmds
#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)
void cib_native_callback(cib_t *cib, xmlNode *msg, int call_id, int rc)
int xml_apply_patchset(xmlNode *xml, xmlNode *patchset, bool check_version)
#define PCMK__XA_CIB_CALLOPT
int(* signon)(cib_t *cib, const char *name, enum cib_conn_type type)
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
xmlNode * pcmk__xe_first_child(const xmlNode *parent, const char *node_name, const char *attr_n, const char *attr_v)
xmlNode * pcmk_find_cib_element(xmlNode *cib, const char *element_name)
Find an element in the CIB.
void(* callback)(xmlNode *, int, int, xmlNode *, void *)
#define crm_trace(fmt, args...)
#define PCMK_XA_UPDATE_USER
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
#define PCMK__XE_CIB_CALLDATA
void(* op_callback)(const xmlNode *msg, int call_id, int rc, xmlNode *output)
#define crm_log_xml_debug(xml, text)
#define PCMK_XE_CLUSTER_PROPERTY_SET
#define PCMK_META_RESOURCE_STICKINESS
Wrappers for and extensions to libxml2.
void pcmk__xe_remove_attr(xmlNode *element, const char *name)
void(* finish)(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_dest)
#define crm_log_xml_warn(xml, text)
int(* query)(cib_t *cib, const char *section, xmlNode **output_data, int call_options)
const char * pcmk_cib_parent_name_for(const char *element_name)
Get the parent element name of a given CIB element name.
int(*) int(* transient)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
int pcmk_legacy2rc(int legacy_rc)
xmlNode * createEmptyCib(int cib_epoch)
Create XML for a new (empty) CIB.
void free_xml(xmlNode *child)
#define PCMK_XE_CONFIGURATION
gboolean cib_diff_version_details(xmlNode *diff, int *admin_epoch, int *epoch, int *updates, int *_admin_epoch, int *_epoch, int *_updates)
#define PCMK_XA_VALIDATE_WITH
const char * pcmk__cib_abs_xpath_for(const char *element)
#define PCMK_XE_META_ATTRIBUTES
void pcmk__output_free(pcmk__output_t *out)
void patchset_process_digest(xmlNode *patch, xmlNode *source, xmlNode *target, bool with_digest)
const char * pcmk_cib_xpath_for(const char *element_name)
Get the relative XPath needed to find a specified CIB element name.
#define pcmk__assert(expr)
#define PCMK_XA_CRM_FEATURE_SET
int(* cib__op_fn_t)(const char *, int, const char *, xmlNode *, xmlNode *, xmlNode *, xmlNode **, xmlNode **)
xmlXPathObjectPtr xpath_search(const xmlNode *xml_top, const char *path)
#define pcmk_err_diff_resync
GHashTable * pcmk__strkey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
#define PCMK_VALUE_CIB_BOOTSTRAP_OPTIONS
int cib__create_op(cib_t *cib, const char *op, const char *host, const char *section, xmlNode *data, int call_options, const char *user_name, const char *client_name, xmlNode **op_msg)
#define crm_err(fmt, args...)
crm_time_t * crm_time_new(const char *string)
void xml_acl_disable(xmlNode *xml)
This structure contains everything that makes up a single output formatter.
#define crm_log_xml_info(xml, text)
uint32_t flags
Group of enum cib__op_attr flags.
#define pcmk__plural_s(i)
bool xml_acl_denied(const xmlNode *xml)
Check whether or not an XML node is ACL-denied.
#define pcmk__log_xml_patchset(level, patchset)
int pcmk__output_new(pcmk__output_t **out, const char *fmt_name, const char *filename, char **argv)
#define crm_log_xml_trace(xml, text)
gboolean crm_is_true(const char *s)
#define pcmk__log_xml_changes(level, xml)
#define PCMK__XA_CIB_USER
bool pcmk__configured_schema_validates(xmlNode *xml)
bool xml_patch_versions(const xmlNode *patchset, int add[3], int del[3])
void pcmk__warn_if_schema_deprecated(const char *schema)
int cib__get_operation(const char *op, const cib__operation_t **operation)
const char * cib_pref(GHashTable *options, const char *name)
#define PCMK__XE_CIB_UPDATE_RESULT
const char * pcmk__highest_schema_name(void)
#define PCMK_XA_ADMIN_EPOCH
xmlNode * pcmk__xe_create(xmlNode *parent, const char *name)
#define PCMK__XA_CIB_CLIENTNAME
void freeXpathObject(xmlXPathObjectPtr xpathObj)
xmlNode * pcmk__xe_next_same(const xmlNode *node)
int(* client_id)(const cib_t *cib, const char **async_id, const char **sync_id)
Get the given CIB connection's unique client identifier(s)
xmlNode * xml_create_patchset(int format, xmlNode *source, xmlNode *target, bool *config, bool manage_version)
void cib_native_notify(gpointer data, gpointer user_data)
#define PCMK_XA_UPDATE_CLIENT
#define PCMK__XA_CIB_CALLID
void xml_calculate_changes(xmlNode *old_xml, xmlNode *new_xml)
Process request when the client commits the active transaction.
#define PCMK_XE_RESOURCES
bool pcmk_acl_required(const char *user)
Check whether ACLs are required for a given user.
#define log_signon_query_err(out, fmt, args...)
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)
#define PCMK_XE_CRM_CONFIG
int pcmk__check_feature_set(const char *cib_version)
int cib_perform_op(cib_t *cib, const char *op, uint32_t call_options, cib__op_fn_t fn, bool is_query, const char *section, xmlNode *req, xmlNode *input, bool manage_counters, bool *config_changed, xmlNode **current_cib, xmlNode **result_cib, xmlNode **diff, xmlNode **output)
void crm_time_free(crm_time_t *dt)