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");
91 crm_warn(
"Ignore failed CIB update: %s " QB_XS
" rc=%d",
100 if (*patchset == NULL) {
101 crm_err(
"CIB diff notification received with no patchset");
120 xmlNode *cib_root = NULL, *config = NULL;
138 #if PCMK__RESOURCE_STICKINESS_DEFAULT != 0 155 cib_acl_enabled(xmlNode *xml,
const char *user)
160 const char *value = NULL;
166 g_hash_table_destroy(options);
169 crm_trace(
"CIB ACL is %s", rc ?
"enabled" :
"disabled");
184 should_copy_cib(
const char *op,
const char *section,
int call_options)
224 xmlNode *req, xmlNode *
input,
bool manage_counters,
225 bool *config_changed, xmlNode **current_cib,
226 xmlNode **result_cib, xmlNode **diff, xmlNode **output)
229 bool check_schema =
true;
230 bool make_copy =
true;
232 xmlNode *scratch = NULL;
233 xmlNode *patchset_cib = NULL;
234 xmlNode *local_diff = NULL;
237 bool with_digest =
false;
241 (is_query?
"read-only " :
""), op);
243 CRM_CHECK(output != NULL,
return -ENOMSG);
244 CRM_CHECK(current_cib != NULL,
return -ENOMSG);
245 CRM_CHECK(result_cib != NULL,
return -ENOMSG);
246 CRM_CHECK(config_changed != NULL,
return -ENOMSG);
253 *config_changed =
false;
260 xmlNode *cib_ro = *current_cib;
261 xmlNode *cib_filtered = NULL;
263 if (cib_acl_enabled(cib_ro, user)
267 if (cib_filtered == NULL) {
268 crm_debug(
"Pre-filtered the entire cib");
271 cib_ro = cib_filtered;
275 rc = (*fn) (op, call_options, section, req,
input, cib_ro, result_cib, output);
277 if(output == NULL || *output == NULL) {
280 }
else if(cib_filtered == *output) {
283 }
else if (*output == *current_cib) {
286 }
else if(cib_filtered && (*output)->doc == cib_filtered->doc) {
290 }
else if ((*output)->doc == (*current_cib)->doc) {
299 make_copy = should_copy_cib(op, section, call_options);
304 scratch = *current_cib;
312 rc = (*fn) (op, call_options, section, req,
input, scratch, &scratch, output);
317 *current_cib = scratch;
321 patchset_cib = *current_cib;
324 rc = (*fn) (op, call_options, section, req,
input, *current_cib,
328 crm_trace(
"Inferring changes after %s op", op);
330 cib_acl_enabled(*current_cib, user));
333 CRM_CHECK(*current_cib != scratch,
return -EINVAL);
338 if (rc ==
pcmk_ok && scratch == NULL) {
343 crm_trace(
"ACL rejected part or all of the proposed changes");
360 crm_err(
"Discarding update with feature set '%s' greater than " 367 if (patchset_cib != NULL) {
375 crm_err(
"%s went backwards: %d -> %d (Opts: %#x)",
381 }
else if (old ==
new) {
385 crm_err(
"%s went backwards: %d -> %d (Opts: %#x)",
398 static time_t expires = 0;
399 time_t tm_now = time(NULL);
401 if (expires < tm_now) {
402 expires = tm_now + 60;
408 config_changed, manage_counters);
419 if (make_copy && (local_diff != NULL)) {
437 crm_err(
"v%d patchset error, patch failed to apply: %s " 453 check_schema =
false;
471 if (schema == NULL) {
486 if (origin != NULL) {
492 if (client != NULL) {
506 crm_trace(
"Perform validation: %s", pcmk__btoa(check_schema));
507 if ((rc ==
pcmk_ok) && check_schema
514 *result_cib = scratch;
519 if ((rc !=
pcmk_ok) && cib_acl_enabled(patchset_cib, user)
522 if (*result_cib == NULL) {
523 crm_debug(
"Pre-filtered the entire cib result");
541 const char *section, xmlNode *
data,
int call_options,
542 const char *user_name,
const char *client_name,
545 CRM_CHECK((cib != NULL) && (op_msg != NULL),
return -EPROTO);
562 crm_trace(
"Sending call options: %.8lx, %d", (
long)call_options, call_options);
583 validate_transaction_request(
const xmlNode *request)
596 crm_err(
"Operation %s is not supported in CIB transactions", op);
601 crm_err(
"Operation targeting a specific node (%s) is not supported in " 625 rc = validate_transaction_request(request);
636 const char *client_id = NULL;
639 crm_err(
"Failed to add '%s' operation to transaction for client %s: %s",
640 op, pcmk__s(client_id,
"(unidentified)"),
pcmk_rc_str(rc));
649 xmlNode *output = NULL;
653 xmlNode *wrapper = NULL;
664 crm_trace(
"No callback found for call %d", call_id);
677 crm_trace(
"Invoking callback %s for call %d",
678 pcmk__s(blob->
id,
"without ID"), call_id);
681 }
else if ((cib != NULL) && (rc !=
pcmk_ok)) {
691 crm_trace(
"OP callback activated for %d", call_id);
697 xmlNode *msg = user_data;
699 const char *
event = NULL;
702 crm_warn(
"Skipping callback - NULL message");
709 crm_warn(
"Skipping callback - NULL callback client");
712 }
else if (entry->
callback == NULL) {
713 crm_warn(
"Skipping callback - NULL callback");
717 crm_trace(
"Skipping callback - event mismatch %p/%s vs. %s", entry, entry->
event, event);
721 crm_trace(
"Invoking callback for %p/%s event...", entry, event);
729 xmlNode *config = NULL;
732 if (options == NULL || current_cib == NULL) {
738 g_hash_table_remove_all(options);
756 const char *section, xmlNode *
data,
757 xmlNode ** output_data,
int call_options,
const char *user_name)
759 int (*delegate)(
cib_t *cib,
const char *op,
const char *
host,
760 const char *section, xmlNode *
data, xmlNode **output_data,
761 int call_options,
const char *user_name) = NULL;
768 if (delegate == NULL) {
769 return -EPROTONOSUPPORT;
771 if (user_name == NULL) {
772 user_name = getenv(
"CIB_user");
774 return delegate(cib, op,
host, section,
data, output_data, call_options, user_name);
794 xmlNode *wrapper = NULL;
795 xmlNode *diff = NULL;
804 if (rc <
pcmk_ok || diff == NULL) {
808 if (level > LOG_CRIT) {
817 crm_debug(
"Update didn't apply: %s (%d) %p",
821 crm_trace(
"Masking error, we already have the supplied update");
832 #define log_signon_query_err(out, fmt, args...) do { \ 834 out->err(out, fmt, ##args); \ 836 crm_err(fmt, ##args); \ 844 cib_t *cib_conn = NULL;
857 if (cib_conn == NULL) {
887 if ((rc ==
pcmk_rc_ok) && (*cib_object == NULL)) {
898 crm_trace(
"Attempting connection to CIB manager (up to %d time%s)",
901 for (
int remaining = attempts - 1; remaining >= 0; --remaining) {
906 || ((errno != EAGAIN) && (errno != EALREADY))) {
912 crm_debug(
"Re-attempting connection to CIB manager (%d attempt%s remaining)",
928 rc = (*cib)->cmds->signoff(*cib);
#define pcmk_err_old_data
#define CRM_CHECK(expr, failure_action)
#define pcmk_err_schema_validation
xmlNode * pcmk__xml_copy(xmlNode *parent, xmlNode *src)
xmlNode * pcmk__xe_first_child(const xmlNode *parent, const char *node_name, const char *attr_n, const char *attr_v)
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)
cib_t * cib_new(void)
Create a new CIB connection object.
#define PCMK_XA_UPDATE_ORIGIN
enum pcmk_ipc_server type
void save_xml_to_file(const xmlNode *xml, const char *desc, const char *filename)
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.
void(* callback)(const char *event, xmlNode *msg)
#define PCMK_XE_RSC_DEFAULTS
#define PCMK_XA_NUM_UPDATES
#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)
#define PCMK_OPT_ENABLE_ACL
int cib_apply_patch_event(xmlNode *event, xmlNode *input, xmlNode **output, int level)
Apply a CIB update patch to a given CIB.
Supported in a transaction.
void pcmk__xe_remove_attr(xmlNode *element, const char *name)
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 cib__clean_up_connection(cib_t **cib)
void cib_delete(cib_t *cib)
Free all memory used by CIB connection.
xmlNode * pcmk__xe_create(xmlNode *parent, const char *name)
cib_callback_client_t * cib__lookup_id(int call_id)
bool xml_tracking_changes(xmlNode *xml)
void pcmk__xml_free(xmlNode *xml)
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
gboolean cib_read_config(GHashTable *options, xmlNode *current_cib)
int cib__get_notify_patchset(const xmlNode *msg, const xmlNode **patchset)
#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)
xmlNode * pcmk_find_cib_element(xmlNode *cib, const char *element_name)
Find an element in the CIB.
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
void(* callback)(xmlNode *, int, int, xmlNode *, void *)
#define crm_trace(fmt, args...)
#define PCMK_XA_UPDATE_USER
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
#define PCMK__XE_CIB_CALLDATA
#define crm_log_xml_debug(xml, text)
#define PCMK_XE_CLUSTER_PROPERTY_SET
#define PCMK_META_RESOURCE_STICKINESS
Wrappers for and extensions to libxml2.
#define crm_log_xml_warn(xml, text)
int(* query)(cib_t *cib, const char *section, xmlNode **output_data, int call_options)
const char * pcmk__xe_add_last_written(xmlNode *xe)
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.
#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
#define PCMK_XE_META_ATTRIBUTES
void patchset_process_digest(xmlNode *patch, xmlNode *source, xmlNode *target, bool with_digest)
#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 **)
#define pcmk_err_diff_resync
int pcmk__xe_copy_attrs(xmlNode *target, const xmlNode *src, uint32_t flags)
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)
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
Retrieve the integer value of an XML attribute.
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.
gboolean crm_is_true(const char *s)
#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 cib__signon_attempts(cib_t *cib, enum cib_conn_type type, int attempts)
#define crm_log_xml_trace(xml, text)
#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)
#define PCMK__XE_CIB_UPDATE_RESULT
const char * pcmk__highest_schema_name(void)
#define PCMK_XA_ADMIN_EPOCH
#define PCMK__XA_CIB_CLIENTNAME
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_err_cib_corrupt
#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)
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
Create an XML attribute with specified name and integer value.
void crm_time_free(crm_time_t *dt)