10 #include <sys/types.h> 20 is_matched_failure(
const char *rsc_id,
const xmlNode *conf_op_xml,
21 const xmlNode *lrm_op_xml)
23 gboolean matched = FALSE;
24 const char *conf_op_name = NULL;
25 const char *lrm_op_task = NULL;
26 const char *conf_op_interval_spec = NULL;
27 guint conf_op_interval_ms = 0;
28 guint lrm_op_interval_ms = 0;
29 const char *lrm_op_id = NULL;
30 char *last_failure_key = NULL;
32 if (rsc_id == NULL || conf_op_xml == NULL || lrm_op_xml == NULL) {
45 if ((conf_op_interval_ms != lrm_op_interval_ms)
50 lrm_op_id = pcmk__xe_id(lrm_op_xml);
51 last_failure_key =
pcmk__op_key(rsc_id,
"last_failure", 0);
57 char *expected_op_key =
pcmk__op_key(rsc_id, conf_op_name,
65 if (rc != target_rc) {
69 free(expected_op_key);
72 free(last_failure_key);
78 const xmlNode *xml_op)
100 gboolean should_block = FALSE;
105 int max = numXpathResults(xpathObj);
108 for (lpc = 0; lpc < max; lpc++) {
112 should_block = is_matched_failure(xml_name, pref, xml_op);
118 const char *conf_op_name = NULL;
119 const char *conf_op_interval_spec = NULL;
120 guint conf_op_interval_ms = 0;
121 char *lrm_op_xpath = NULL;
122 xmlXPathObject *lrm_op_xpathObj = NULL;
129 &conf_op_interval_ms);
131 #define XPATH_FMT "//" PCMK__XE_NODE_STATE "[@" PCMK_XA_UNAME "='%s']" \ 132 "//" PCMK__XE_LRM_RESOURCE "[@" PCMK_XA_ID "='%s']" \ 133 "/" PCMK__XE_LRM_RSC_OP "[@" PCMK_XA_OPERATION "='%s']" \ 134 "[@" PCMK_META_INTERVAL "='%u']" 139 conf_op_interval_ms);
144 if (lrm_op_xpathObj) {
145 int max2 = numXpathResults(lrm_op_xpathObj);
148 for (lpc2 = 0; lpc2 < max2; lpc2++) {
152 should_block = is_matched_failure(xml_name, pref,
206 generate_fail_regex(
const char *prefix,
const char *rsc_name,
207 gboolean is_legacy, gboolean is_unique, regex_t *re)
214 const char *op_pattern = (is_legacy?
"" :
"#.+_[0-9]+");
222 const char *instance_pattern = (is_unique?
"" :
"(:[0-9]+)?");
225 instance_pattern, op_pattern);
226 if (regcomp(re, pattern, REG_EXTENDED|REG_NOSUB) != 0) {
249 regex_t *failcount_re, regex_t *lastfailure_re)
252 char *rsc_name = rsc_fail_name(rsc);
269 regfree(failcount_re);
277 struct failcount_data {
281 const xmlNode *xml_op;
282 regex_t failcount_re;
283 regex_t lastfailure_re;
297 update_failcount_for_attr(gpointer key, gpointer value, gpointer user_data)
299 struct failcount_data *fc_data = user_data;
302 if (regexec(&(fc_data->failcount_re), (
const char *) key, 0, NULL, 0) == 0) {
308 "because '%s' is not a valid fail count: %s",
309 (
const char *) key, pcmk__node_name(fc_data->node),
314 pcmk__rsc_trace(fc_data->rsc,
"Added %s (%s) to %s fail count (now %s)",
315 (
const char *) key, (
const char *) value,
322 if (regexec(&(fc_data->lastfailure_re), (
const char *) key, 0, NULL,
328 crm_info(
"Ignoring invalid value '%s' for %s: %s",
329 (
const char *) value, (
const char *) key,
pcmk_rc_str(rc));
332 fc_data->last_failure = (time_t) QB_MAX(fc_data->last_failure, last_ll);
344 update_failcount_for_filler(gpointer
data, gpointer user_data)
347 struct failcount_data *fc_data = user_data;
348 time_t filler_last_failure = 0;
351 &filler_last_failure, fc_data->flags,
353 fc_data->last_failure = QB_MAX(fc_data->last_failure, filler_last_failure);
374 time_t *last_failure, uint32_t
flags,
const xmlNode *xml_op)
376 struct failcount_data fc_data = {
382 .last_failure = (time_t) 0,
386 CRM_CHECK(generate_fail_regexes(rsc, &fc_data.failcount_re,
389 g_hash_table_foreach(node->
details->
attrs, update_failcount_for_attr,
391 regfree(&(fc_data.failcount_re));
392 regfree(&(fc_data.lastfailure_re));
396 && block_failure(node, rsc, xml_op)) {
399 "because it conflicts with " 413 rsc->
id, pcmk__node_name(node),
415 fc_data.failcount = 0;
430 && !pcmk__is_bundled(rsc)) {
432 g_list_foreach(rsc->
fillers, update_failcount_for_filler, &fc_data);
433 if (fc_data.failcount > 0) {
435 "Container %s and the resources within it " 436 "have failed %s time%s on %s",
439 pcmk__node_name(node));
442 }
else if (fc_data.failcount > 0) {
446 pcmk__node_name(node));
449 if (last_failure != NULL) {
450 if ((fc_data.failcount > 0) && (fc_data.last_failure > 0)) {
451 *last_failure = fc_data.last_failure;
456 return fc_data.failcount;
483 rsc->
id, pcmk__node_name(node), reason, clear->
uuid);
#define CRM_CHECK(expr, failure_action)
#define crm_notice(fmt, args...)
pcmk_scheduler_t * cluster
const char * pcmk_readable_score(int score)
Return a displayable static string for a score value.
#define PCMK_XE_PRIMITIVE
#define pcmk__config_warn(fmt...)
#define pcmk__rsc_trace(rsc, fmt, args...)
int pe__target_rc_from_xml(const xmlNode *xml_op)
#define pcmk__rsc_info(rsc, fmt, args...)
#define pcmk__insert_meta(obj, name, value)
#define PCMK_ACTION_CLEAR_FAILCOUNT
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
#define PCMK__LAST_FAILURE_PREFIX
#define pcmk__rsc_debug(rsc, fmt, args...)
int pe_get_failcount(const pcmk_node_t *node, pcmk_resource_t *rsc, time_t *last_failure, uint32_t flags, const xmlNode *xml_op)
char int pcmk_parse_interval_spec(const char *input, guint *result_ms)
Parse milliseconds from a Pacemaker interval specification.
int pcmk__scan_ll(const char *text, long long *result, long long default_value)
#define crm_warn(fmt, args...)
int crm_element_value_ms(const xmlNode *data, const char *name, guint *dest)
Retrieve the millisecond value of an XML attribute.
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
char * clone_strip(const char *last_rsc_id)
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.
struct pe_node_shared_s * details
Wrappers for and extensions to libxml2.
#define PCMK__FAIL_COUNT_PREFIX
char * pcmk__op_key(const char *rsc_id, const char *op_type, guint interval_ms)
Generate an operation key (RESOURCE_ACTION_INTERVAL)
int pcmk__add_scores(int score1, int score2)
pcmk_action_t * custom_action(pcmk_resource_t *rsc, char *key, const char *task, const pcmk_node_t *on_node, gboolean optional, pcmk_scheduler_t *scheduler)
Create or update an action object.
#define PCMK_XA_CRM_FEATURE_SET
xmlXPathObjectPtr xpath_search(const xmlNode *xml_top, const char *path)
#define PCMK_META_INTERVAL
pcmk_scheduler_t * scheduler
#define PCMK__META_OP_NO_WAIT
xmlNode * getXpathResult(xmlXPathObjectPtr xpathObj, int index)
#define PCMK_META_ON_FAIL
int compare_version(const char *version1, const char *version2)
int pcmk_parse_score(const char *score_s, int *score, int default_score)
Parse an integer score from a string.
#define pcmk__plural_s(i)
pcmk_action_t * pe__clear_failcount(pcmk_resource_t *rsc, const pcmk_node_t *node, const char *reason, pcmk_scheduler_t *scheduler)
Schedule a controller operation to clear a fail count.
time_t get_effective_time(pcmk_scheduler_t *scheduler)
void freeXpathObject(xmlXPathObjectPtr xpathObj)
#define crm_info(fmt, args...)