pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
Macros | Typedefs | Functions
rules.c File Reference
#include <crm_internal.h>
#include <crm/crm.h>
#include <crm/msg_xml.h>
#include <crm/common/xml.h>
#include <crm/common/xml_internal.h>
#include <glib.h>
#include <crm/pengine/rules.h>
#include <crm/pengine/rules_internal.h>
#include <crm/pengine/internal.h>
#include <sys/types.h>
#include <regex.h>
#include <ctype.h>
#include <crm/pengine/rules_compat.h>
Include dependency graph for rules.c:

Go to the source code of this file.

Macros

#define CHECK_ONE(spec, name, var)
 

Typedefs

typedef struct sorted_set_s sorted_set_t
 
typedef struct unpack_data_s unpack_data_t
 

Functions

 CRM_TRACE_INIT_DATA (pe_rules)
 
gboolean pe_evaluate_rules (xmlNode *ruleset, GHashTable *node_hash, crm_time_t *now, crm_time_t *next_change)
 Evaluate any rules contained by given XML element. More...
 
gboolean pe_test_rule (xmlNode *rule, GHashTable *node_hash, enum rsc_role_e role, crm_time_t *now, crm_time_t *next_change, pe_match_data_t *match_data)
 
gboolean pe_test_expression (xmlNode *expr, GHashTable *node_hash, enum rsc_role_e role, crm_time_t *now, crm_time_t *next_change, pe_match_data_t *match_data)
 Evaluate one rule subelement (pass/fail) More...
 
enum expression_type find_expression_type (xmlNode *expr)
 
int pe_cron_range_satisfied (const crm_time_t *now, const xmlNode *cron_spec)
 
void pe_eval_nvpairs (xmlNode *top, const xmlNode *xml_obj, const char *set_name, const pe_rule_eval_data_t *rule_data, GHashTable *hash, const char *always_first, gboolean overwrite, crm_time_t *next_change)
 Extract nvpair blocks contained by an XML element into a hash table. More...
 
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. More...
 
char * pe_expand_re_matches (const char *string, const pe_re_match_data_t *match_data)
 Expand any regular expression submatches (%0-%9) in a string. More...
 
gboolean pe_eval_rules (xmlNode *ruleset, const pe_rule_eval_data_t *rule_data, crm_time_t *next_change)
 Evaluate rules. More...
 
gboolean pe_eval_expr (xmlNode *rule, const pe_rule_eval_data_t *rule_data, crm_time_t *next_change)
 Evaluate all of a rule's expressions. More...
 
gboolean pe_eval_subexpr (xmlNode *expr, const pe_rule_eval_data_t *rule_data, crm_time_t *next_change)
 Evaluate a single rule expression, including any subexpressions. More...
 
gboolean pe__eval_attr_expr (const xmlNode *expr, const pe_rule_eval_data_t *rule_data)
 
int pe__eval_date_expr (const xmlNode *expr, const pe_rule_eval_data_t *rule_data, crm_time_t *next_change)
 
gboolean pe__eval_op_expr (const xmlNode *expr, const pe_rule_eval_data_t *rule_data)
 
gboolean pe__eval_role_expr (const xmlNode *expr, const pe_rule_eval_data_t *rule_data)
 
gboolean pe__eval_rsc_expr (const xmlNode *expr, const pe_rule_eval_data_t *rule_data)
 
gboolean test_ruleset (xmlNode *ruleset, GHashTable *node_hash, crm_time_t *now)
 
gboolean test_rule (xmlNode *rule, GHashTable *node_hash, enum rsc_role_e role, crm_time_t *now)
 
gboolean pe_test_rule_re (xmlNode *rule, GHashTable *node_hash, enum rsc_role_e role, crm_time_t *now, pe_re_match_data_t *re_match_data)
 
gboolean pe_test_rule_full (xmlNode *rule, GHashTable *node_hash, enum rsc_role_e role, crm_time_t *now, pe_match_data_t *match_data)
 
gboolean test_expression (xmlNode *expr, GHashTable *node_hash, enum rsc_role_e role, crm_time_t *now)
 
gboolean pe_test_expression_re (xmlNode *expr, GHashTable *node_hash, enum rsc_role_e role, crm_time_t *now, pe_re_match_data_t *re_match_data)
 
gboolean pe_test_expression_full (xmlNode *expr, GHashTable *node_hash, enum rsc_role_e role, crm_time_t *now, pe_match_data_t *match_data)
 
void unpack_instance_attributes (xmlNode *top, xmlNode *xml_obj, const char *set_name, GHashTable *node_hash, GHashTable *hash, const char *always_first, gboolean overwrite, crm_time_t *now)
 

Macro Definition Documentation

◆ CHECK_ONE

#define CHECK_ONE (   spec,
  name,
  var 
)
Value:
do { \
int subpart_rc = check_one(spec, name, var); \
if (check_passes(subpart_rc) == FALSE) { \
return subpart_rc; \
} \
} while (0)
const char * name
Definition: cib.c:26

Definition at line 229 of file rules.c.

Typedef Documentation

◆ sorted_set_t

typedef struct sorted_set_s sorted_set_t

◆ unpack_data_t

typedef struct unpack_data_s unpack_data_t

Function Documentation

◆ CRM_TRACE_INIT_DATA()

CRM_TRACE_INIT_DATA ( pe_rules  )

◆ find_expression_type()

enum expression_type find_expression_type ( xmlNode *  expr)

Definition at line 105 of file rules.c.

◆ pe__eval_attr_expr()

gboolean pe__eval_attr_expr ( const xmlNode *  expr,
const pe_rule_eval_data_t rule_data 
)

Definition at line 972 of file rules.c.

◆ pe__eval_date_expr()

int pe__eval_date_expr ( const xmlNode *  expr,
const pe_rule_eval_data_t rule_data,
crm_time_t next_change 
)

Definition at line 1036 of file rules.c.

◆ pe__eval_op_expr()

gboolean pe__eval_op_expr ( const xmlNode *  expr,
const pe_rule_eval_data_t rule_data 
)

Definition at line 1119 of file rules.c.

◆ pe__eval_role_expr()

gboolean pe__eval_role_expr ( const xmlNode *  expr,
const pe_rule_eval_data_t rule_data 
)

Definition at line 1161 of file rules.c.

◆ pe__eval_rsc_expr()

gboolean pe__eval_rsc_expr ( const xmlNode *  expr,
const pe_rule_eval_data_t rule_data 
)

Definition at line 1204 of file rules.c.

◆ pe_cron_range_satisfied()

int pe_cron_range_satisfied ( const crm_time_t now,
const xmlNode *  cron_spec 
)

Definition at line 237 of file rules.c.

◆ pe_eval_expr()

gboolean pe_eval_expr ( xmlNode *  rule,
const pe_rule_eval_data_t rule_data,
crm_time_t next_change 
)

Evaluate all of a rule's expressions.

Parameters
[in,out]ruleXML containing a rule definition or its id-ref
[in]rule_dataMatching parameters to check against rule
[out]next_changeIf not NULL, set to when evaluation will change
Returns
TRUE if rule_data passes rule, otherwise FALSE

Definition at line 663 of file rules.c.

◆ pe_eval_nvpairs()

void pe_eval_nvpairs ( xmlNode *  top,
const xmlNode *  xml_obj,
const char *  set_name,
const pe_rule_eval_data_t rule_data,
GHashTable *  hash,
const char *  always_first,
gboolean  overwrite,
crm_time_t next_change 
)

Extract nvpair blocks contained by an XML element into a hash table.

Parameters
[in,out]topXML document root (used to expand id-ref's)
[in]xml_objXML element containing blocks of nvpair elements
[in]set_nameIf not NULL, only use blocks of this element
[in]rule_dataMatching parameters to use when unpacking
[out]hashWhere to store extracted name/value pairs
[in]always_firstIf not NULL, process block with this ID first
[in]overwriteWhether to replace existing values with same name
[out]next_changeIf not NULL, set to when evaluation will change

Definition at line 500 of file rules.c.

◆ pe_eval_rules()

gboolean pe_eval_rules ( xmlNode *  ruleset,
const pe_rule_eval_data_t rule_data,
crm_time_t next_change 
)

Evaluate rules.

Parameters
[in,out]rulesetXML possibly containing rule sub-elements
[in]rule_data
[out]next_changeIf not NULL, set to when evaluation will change
Returns
TRUE if there are no rules or

Definition at line 629 of file rules.c.

◆ pe_eval_subexpr()

gboolean pe_eval_subexpr ( xmlNode *  expr,
const pe_rule_eval_data_t rule_data,
crm_time_t next_change 
)

Evaluate a single rule expression, including any subexpressions.

Parameters
[in,out]exprXML containing a rule expression
[in]rule_dataMatching parameters to check against expression
[out]next_changeIf not NULL, set to when evaluation will change
Returns
TRUE if rule_data passes expr, otherwise FALSE

Definition at line 715 of file rules.c.

◆ pe_evaluate_rules()

gboolean pe_evaluate_rules ( xmlNode *  ruleset,
GHashTable *  node_hash,
crm_time_t now,
crm_time_t next_change 
)

Evaluate any rules contained by given XML element.

Parameters
[in,out]xmlXML element to check for rules
[in]node_hashNode attributes to use to evaluate expressions
[in]nowTime to use when evaluating expressions
[out]next_changeIf not NULL, set to when evaluation will change
Returns
TRUE if no rules, or any of rules present is in effect, else FALSE

Definition at line 39 of file rules.c.

◆ pe_expand_re_matches()

char* pe_expand_re_matches ( const char *  string,
const pe_re_match_data_t match_data 
)

Expand any regular expression submatches (%0-%9) in a string.

Parameters
[in]stringString possibly containing submatch variables
[in]match_dataIf not NULL, regular expression matches
Returns
Newly allocated string identical to string with submatches expanded, or NULL if there were no matches

Definition at line 563 of file rules.c.

◆ pe_test_expression()

gboolean pe_test_expression ( xmlNode *  expr,
GHashTable *  node_hash,
enum rsc_role_e  role,
crm_time_t now,
crm_time_t next_change,
pe_match_data_t match_data 
)

Evaluate one rule subelement (pass/fail)

A rule element may contain another rule, a node attribute expression, or a date expression. Given any one of those, evaluate it and return whether it passed.

Parameters
[in,out]exprRule subelement XML
[in]node_hashNode attributes to use when evaluating expression
[in]roleResource role to use when evaluating expression
[in]nowTime to use when evaluating expression
[out]next_changeIf not NULL, set to when evaluation will change
[in]match_dataIf not NULL, resource back-references and params
Returns
TRUE if expression is in effect under given conditions, else FALSE

Definition at line 88 of file rules.c.

◆ pe_test_expression_full()

gboolean pe_test_expression_full ( xmlNode *  expr,
GHashTable *  node_hash,
enum rsc_role_e  role,
crm_time_t now,
pe_match_data_t match_data 
)
Deprecated:
Use pe_test_expression() instead

Definition at line 1292 of file rules.c.

◆ pe_test_expression_re()

gboolean pe_test_expression_re ( xmlNode *  expr,
GHashTable *  node_hash,
enum rsc_role_e  role,
crm_time_t now,
pe_re_match_data_t re_match_data 
)
Deprecated:
Use pe_test_expression() instead

Definition at line 1281 of file rules.c.

◆ pe_test_rule()

gboolean pe_test_rule ( xmlNode *  rule,
GHashTable *  node_hash,
enum rsc_role_e  role,
crm_time_t now,
crm_time_t next_change,
pe_match_data_t match_data 
)

Definition at line 55 of file rules.c.

◆ pe_test_rule_full()

gboolean pe_test_rule_full ( xmlNode *  rule,
GHashTable *  node_hash,
enum rsc_role_e  role,
crm_time_t now,
pe_match_data_t match_data 
)
Deprecated:
Use pe_test_rule() instead

Definition at line 1268 of file rules.c.

◆ pe_test_rule_re()

gboolean pe_test_rule_re ( xmlNode *  rule,
GHashTable *  node_hash,
enum rsc_role_e  role,
crm_time_t now,
pe_re_match_data_t re_match_data 
)
Deprecated:
Use pe_test_rule() instead

Definition at line 1257 of file rules.c.

◆ pe_unpack_nvpairs()

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.

Parameters
[in,out]topXML document root (used to expand id-ref's)
[in]xml_objXML element containing blocks of nvpair elements
[in]set_nameElement name to identify nvpair blocks
[in]node_hashNode attributes to use when evaluating rules
[out]hashWhere to store extracted name/value pairs
[in]always_firstIf not NULL, process block with this ID first
[in]overwriteWhether to replace existing values with same name
[in]nowTime to use when evaluating rules
[out]next_changeIf not NULL, set to when evaluation will change

Definition at line 535 of file rules.c.

◆ test_expression()

gboolean test_expression ( xmlNode *  expr,
GHashTable *  node_hash,
enum rsc_role_e  role,
crm_time_t now 
)
Deprecated:
Use pe_test_expression() instead

Definition at line 1275 of file rules.c.

◆ test_rule()

gboolean test_rule ( xmlNode *  rule,
GHashTable *  node_hash,
enum rsc_role_e  role,
crm_time_t now 
)
Deprecated:
Use pe_test_rule() instead

Definition at line 1251 of file rules.c.

◆ test_ruleset()

gboolean test_ruleset ( xmlNode *  ruleset,
GHashTable *  node_hash,
crm_time_t now 
)
Deprecated:
Use pe_evaluate_rules() instead

Definition at line 1245 of file rules.c.

◆ unpack_instance_attributes()

void unpack_instance_attributes ( xmlNode *  top,
xmlNode *  xml_obj,
const char *  set_name,
GHashTable *  node_hash,
GHashTable *  hash,
const char *  always_first,
gboolean  overwrite,
crm_time_t now 
)
Deprecated:
Use pe_unpack_nvpairs() instead

Definition at line 1300 of file rules.c.