20 #include <sys/types.h>
30 static regex_t *notify_migrate_re = NULL;
45 pcmk__op_key(
const char *rsc_id,
const char *op_type, guint interval_ms)
52 static inline gboolean
53 convert_interval(
const char *s, guint *interval_ms)
58 l = strtoul(s, NULL, 10);
64 *interval_ms = (guint) l;
69 try_fast_match(
const char *key,
const char *underbar1,
const char *underbar2,
70 char **rsc_id,
char **op_type, guint *interval_ms)
73 if (!convert_interval(underbar2+1, interval_ms)) {
79 *rsc_id =
strndup(key, underbar1-key);
83 *op_type =
strndup(underbar1+1, underbar2-underbar1-1);
90 try_basic_match(
const char *key,
char **rsc_id,
char **op_type, guint *interval_ms)
92 char *interval_sep = NULL;
93 char *type_sep = NULL;
96 interval_sep = strrchr(key,
'_');
97 if (interval_sep == NULL) {
102 if (!convert_interval(interval_sep+1, interval_ms)) {
107 type_sep = interval_sep-1;
110 if (*type_sep ==
'_') {
112 }
else if (type_sep == key) {
126 *op_type =
strndup(type_sep+1, interval_sep-type_sep-1);
131 *rsc_id =
strndup(key, type_sep-key);
138 try_migrate_notify_match(
const char *key,
char **rsc_id,
char **op_type, guint *interval_ms)
142 regmatch_t pmatch[nmatch];
144 if (notify_migrate_re == NULL) {
146 notify_migrate_re = calloc(1,
sizeof(regex_t));
147 rc = regcomp(notify_migrate_re,
"^(.*)_(migrate_(from|to)|(pre|post)_notify_([a-z]+|migrate_(from|to)))_([0-9]+)$",
152 rc = regexec(notify_migrate_re, key, nmatch, pmatch, 0);
153 if (rc == REG_NOMATCH) {
158 *rsc_id =
strndup(key+pmatch[1].rm_so, pmatch[1].rm_eo-pmatch[1].rm_so);
162 *op_type =
strndup(key+pmatch[2].rm_so, pmatch[2].rm_eo-pmatch[2].rm_so);
166 if (!convert_interval(key+pmatch[7].rm_so, interval_ms)) {
185 parse_op_key(
const char *key,
char **rsc_id,
char **op_type, guint *interval_ms)
187 char *underbar1 = NULL;
188 char *underbar2 = NULL;
189 char *underbar3 = NULL;
206 underbar1 = strchr(key,
'_');
211 underbar2 = strchr(underbar1+1,
'_');
216 underbar3 = strchr(underbar2+1,
'_');
219 return try_fast_match(key, underbar1, underbar2,
220 rsc_id, op_type, interval_ms);
221 }
else if (try_migrate_notify_match(key, rsc_id, op_type, interval_ms)) {
224 return try_basic_match(key, rsc_id, op_type, interval_ms);
234 CRM_CHECK(notify_type != NULL,
return NULL);
236 rsc_id, notify_type, op_type);
256 int *
op_status,
int *op_rc,
int *target_rc)
260 gboolean result = TRUE;
261 int local_op_status = -1;
262 int local_op_rc = -1;
267 res = sscanf(magic,
"%d:%d;%ms", &local_op_status, &local_op_rc, &key);
269 key = calloc(1, strlen(magic) - 3);
271 res = sscanf(magic,
"%d:%d;%s", &local_op_status, &local_op_rc, key);
274 crm_err(
"Could not decode transition information '%s': %s",
277 }
else if (res < 3) {
278 crm_warn(
"Transition information '%s' incomplete (%d of 3 expected items)",
283 *op_status = local_op_status;
286 *op_rc = local_op_rc;
301 action_id, transition_id, target_rc, 36, node);
321 int local_transition_id = -1;
322 int local_action_id = -1;
323 int local_target_rc = -1;
324 char local_uuid[37] = {
'\0' };
341 if (sscanf(key,
"%d:%d:%d:%36s", &local_action_id, &local_transition_id,
342 &local_target_rc, local_uuid) != 4) {
343 crm_err(
"Invalid transition key '%s'", key);
346 if (strlen(local_uuid) != 36) {
347 crm_warn(
"Invalid UUID '%s' in transition key '%s'", local_uuid, key);
350 *uuid = strdup(local_uuid);
354 *transition_id = local_transition_id;
357 *action_id = local_action_id;
360 *target_rc = local_target_rc;
367 should_filter_for_digest(xmlAttrPtr a,
void *user_data)
369 if (strncmp((
const char *) a->name,
CRM_META "_",
394 guint interval_ms = 0;
396 if (param_set == NULL) {
409 if (interval_ms != 0) {
418 if (timeout != NULL) {
452 if (target_rc != op->
rc) {
473 const char *interval_spec,
const char *
timeout)
477 CRM_CHECK(prefix && task && interval_spec,
return NULL);
506 CRM_CHECK((rsc_class != NULL) || (op != NULL),
return false);
508 if ((rsc_class != NULL)
#define CRM_CHECK(expr, failure_action)
gboolean parse_op_key(const char *key, char **rsc_id, char **op_type, guint *interval_ms)
xmlNode * crm_create_op_xml(xmlNode *parent, const char *prefix, const char *task, const char *interval_spec, const char *timeout)
Create a CIB XML element for an operation.
#define CRMD_ACTION_MIGRATED
const char * pcmk_strerror(int rc)
int rsc_op_expected_rc(lrmd_event_data_t *event)
#define CRMD_ACTION_NOTIFY
#define XML_LRM_ATTR_INTERVAL
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
#define XML_LRM_ATTR_OP_DIGEST
#define CRMD_ACTION_PROMOTE
bool crm_op_needs_metadata(const char *rsc_class, const char *op)
Check whether an operation requires resource agent meta-data.
void pcmk__filter_op_for_digest(xmlNode *param_set)
char * strndup(const char *str, size_t len)
char * crm_meta_name(const char *field)
#define CRMD_ACTION_START
#define crm_warn(fmt, args...)
#define CRMD_ACTION_RELOAD_AGENT
#define CRMD_ACTION_DEMOTE
char * pcmk__notify_key(const char *rsc_id, const char *notify_type, const char *op_type)
int crm_element_value_ms(const xmlNode *data, const char *name, guint *dest)
Retrieve the millisecond value of an XML attribute.
char * crm_element_value_copy(const xmlNode *data, const char *name)
Retrieve a copy of the value of an XML attribute.
void pcmk__xe_remove_matching_attrs(xmlNode *element, bool(*match)(xmlAttrPtr, void *), void *user_data)
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.
void crm_xml_set_id(xmlNode *xml, const char *format,...) G_GNUC_PRINTF(2
Wrappers for and extensions to libxml2.
xmlNode * create_xml_node(xmlNode *parent, const char *name)
bool pcmk__str_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
char * pcmk__op_key(const char *rsc_id, const char *op_type, guint interval_ms)
Generate an operation key (RESOURCE_ACTION_INTERVAL)
#define CRMD_ACTION_RELOAD
#define XML_LRM_ATTR_TARGET_UUID
gboolean did_rsc_op_fail(lrmd_event_data_t *event, int target_rc)
#define crm_err(fmt, args...)
gboolean decode_transition_key(const char *key, char **uuid, int *transition_id, int *action_id, int *target_rc)
Parse a transition key into its constituent parts.
#define XML_LRM_ATTR_INTERVAL_MS
#define CRMD_ACTION_MIGRATE
#define XML_ATTR_CRM_VERSION
gboolean decode_transition_magic(const char *magic, char **uuid, int *transition_id, int *action_id, int *op_status, int *op_rc, int *target_rc)
Parse a transition magic string into its constituent parts.
char * pcmk__transition_key(int transition_id, int action_id, int target_rc, const char *node)
uint32_t pcmk_get_ra_caps(const char *standard)
Get capabilities of a resource agent standard.
#define XML_LRM_ATTR_TARGET
#define CRMD_ACTION_STATUS