From ad250dba466051174b88eb8b00c1b33bc8cc92a1 Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Apr 07 2021 22:24:53 +0000 Subject: Refactor: scheduler: Change args to pe__unpack_dataset_nvpairs. It should now take a pe_rule_eval_data_t instead of various separate arguments. This will allow passing further data that needs to be tested against in the future (such as rsc_defaults and op_defaults). It's also convenient to make versions of pe_unpack_nvpairs and pe_unpack_versioned_attributes that take the same arguments. Then, adapt callers of pe__unpack_dataset_nvpairs to pass the new argument. --- diff --git a/include/crm/pengine/internal.h b/include/crm/pengine/internal.h index d29b161..25554cf 100644 --- a/include/crm/pengine/internal.h +++ b/include/crm/pengine/internal.h @@ -460,7 +460,7 @@ void pe__update_recheck_time(time_t recheck, pe_working_set_t *data_set); void pe__register_messages(pcmk__output_t *out); void pe__unpack_dataset_nvpairs(xmlNode *xml_obj, const char *set_name, - GHashTable *node_hash, GHashTable *hash, + pe_rule_eval_data_t *rule_data, GHashTable *hash, const char *always_first, gboolean overwrite, pe_working_set_t *data_set); diff --git a/include/crm/pengine/rules.h b/include/crm/pengine/rules.h index a74c629..cbae8ed 100644 --- a/include/crm/pengine/rules.h +++ b/include/crm/pengine/rules.h @@ -46,12 +46,21 @@ gboolean pe_test_expression(xmlNode *expr, GHashTable *node_hash, crm_time_t *next_change, pe_match_data_t *match_data); +void pe_eval_nvpairs(xmlNode *top, xmlNode *xml_obj, const char *set_name, + pe_rule_eval_data_t *rule_data, GHashTable *hash, + const char *always_first, gboolean overwrite, + crm_time_t *next_change); + void pe_unpack_nvpairs(xmlNode *top, 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); #if ENABLE_VERSIONED_ATTRS +void pe_eval_versioned_attributes(xmlNode *top, xmlNode *xml_obj, + const char *set_name, pe_rule_eval_data_t *rule_data, + xmlNode *hash, crm_time_t *next_change); + void pe_unpack_versioned_attributes(xmlNode *top, xmlNode *xml_obj, const char *set_name, GHashTable *node_hash, xmlNode *hash, crm_time_t *now, diff --git a/lib/pengine/complex.c b/lib/pengine/complex.c index 16f3a71..d91c95e 100644 --- a/lib/pengine/complex.c +++ b/lib/pengine/complex.c @@ -95,10 +95,17 @@ void get_meta_attributes(GHashTable * meta_hash, pe_resource_t * rsc, pe_node_t * node, pe_working_set_t * data_set) { - GHashTable *node_hash = NULL; + pe_rule_eval_data_t rule_data = { + .node_hash = NULL, + .role = RSC_ROLE_UNKNOWN, + .now = data_set->now, + .match_data = NULL, + .rsc_data = NULL, + .op_data = NULL + }; if (node) { - node_hash = node->details->attrs; + rule_data.node_hash = node->details->attrs; } if (rsc->xml) { @@ -112,7 +119,7 @@ get_meta_attributes(GHashTable * meta_hash, pe_resource_t * rsc, } } - pe__unpack_dataset_nvpairs(rsc->xml, XML_TAG_META_SETS, node_hash, + pe__unpack_dataset_nvpairs(rsc->xml, XML_TAG_META_SETS, &rule_data, meta_hash, NULL, FALSE, data_set); /* set anything else based on the parent */ @@ -122,20 +129,27 @@ get_meta_attributes(GHashTable * meta_hash, pe_resource_t * rsc, /* and finally check the defaults */ pe__unpack_dataset_nvpairs(data_set->rsc_defaults, XML_TAG_META_SETS, - node_hash, meta_hash, NULL, FALSE, data_set); + &rule_data, meta_hash, NULL, FALSE, data_set); } void get_rsc_attributes(GHashTable * meta_hash, pe_resource_t * rsc, pe_node_t * node, pe_working_set_t * data_set) { - GHashTable *node_hash = NULL; + pe_rule_eval_data_t rule_data = { + .node_hash = NULL, + .role = RSC_ROLE_UNKNOWN, + .now = data_set->now, + .match_data = NULL, + .rsc_data = NULL, + .op_data = NULL + }; if (node) { - node_hash = node->details->attrs; + rule_data.node_hash = node->details->attrs; } - pe__unpack_dataset_nvpairs(rsc->xml, XML_TAG_ATTR_SETS, node_hash, + pe__unpack_dataset_nvpairs(rsc->xml, XML_TAG_ATTR_SETS, &rule_data, meta_hash, NULL, FALSE, data_set); /* set anything else based on the parent */ @@ -145,7 +159,7 @@ get_rsc_attributes(GHashTable * meta_hash, pe_resource_t * rsc, } else { /* and finally check the defaults */ pe__unpack_dataset_nvpairs(data_set->rsc_defaults, XML_TAG_ATTR_SETS, - node_hash, meta_hash, NULL, FALSE, data_set); + &rule_data, meta_hash, NULL, FALSE, data_set); } } @@ -376,6 +390,15 @@ common_unpack(xmlNode * xml_obj, pe_resource_t ** rsc, bool remote_node = FALSE; bool has_versioned_params = FALSE; + pe_rule_eval_data_t rule_data = { + .node_hash = NULL, + .role = RSC_ROLE_UNKNOWN, + .now = data_set->now, + .match_data = NULL, + .rsc_data = NULL, + .op_data = NULL + }; + crm_log_xml_trace(xml_obj, "Processing resource input..."); if (id == NULL) { @@ -706,7 +729,7 @@ common_unpack(xmlNode * xml_obj, pe_resource_t ** rsc, (*rsc)->utilization = crm_str_table_new(); - pe__unpack_dataset_nvpairs((*rsc)->xml, XML_TAG_UTILIZATION, NULL, + pe__unpack_dataset_nvpairs((*rsc)->xml, XML_TAG_UTILIZATION, &rule_data, (*rsc)->utilization, NULL, FALSE, data_set); /* data_set->resources = g_list_append(data_set->resources, (*rsc)); */ diff --git a/lib/pengine/rules.c b/lib/pengine/rules.c index 2709d68..7575011 100644 --- a/lib/pengine/rules.c +++ b/lib/pengine/rules.c @@ -686,6 +686,16 @@ unpack_nvpair_blocks(xmlNode *top, xmlNode *xml_obj, const char *set_name, } } +void +pe_eval_nvpairs(xmlNode *top, xmlNode *xml_obj, const char *set_name, + pe_rule_eval_data_t *rule_data, GHashTable *hash, + const char *always_first, gboolean overwrite, + crm_time_t *next_change) +{ + unpack_nvpair_blocks(top, xml_obj, set_name, hash, always_first, + overwrite, rule_data, next_change, unpack_attr_set); +} + /*! * \brief Extract nvpair blocks contained by an XML element into a hash table * @@ -714,12 +724,21 @@ pe_unpack_nvpairs(xmlNode *top, xmlNode *xml_obj, const char *set_name, .op_data = NULL }; - unpack_nvpair_blocks(top, xml_obj, set_name, hash, always_first, - overwrite, &rule_data, next_change, unpack_attr_set); + pe_eval_nvpairs(top, xml_obj, set_name, &rule_data, hash, + always_first, overwrite, next_change); } #if ENABLE_VERSIONED_ATTRS void +pe_eval_versioned_attributes(xmlNode *top, xmlNode *xml_obj, const char *set_name, + pe_rule_eval_data_t *rule_data, xmlNode *hash, + crm_time_t *next_change) +{ + unpack_nvpair_blocks(top, xml_obj, set_name, hash, NULL, FALSE, rule_data, + next_change, unpack_versioned_attr_set); +} + +void pe_unpack_versioned_attributes(xmlNode *top, xmlNode *xml_obj, const char *set_name, GHashTable *node_hash, xmlNode *hash, crm_time_t *now, diff --git a/lib/pengine/unpack.c b/lib/pengine/unpack.c index e5d40c4..3c6606b 100644 --- a/lib/pengine/unpack.c +++ b/lib/pengine/unpack.c @@ -188,9 +188,18 @@ unpack_config(xmlNode * config, pe_working_set_t * data_set) const char *value = NULL; GHashTable *config_hash = crm_str_table_new(); + pe_rule_eval_data_t rule_data = { + .node_hash = NULL, + .role = RSC_ROLE_UNKNOWN, + .now = data_set->now, + .match_data = NULL, + .rsc_data = NULL, + .op_data = NULL + }; + data_set->config_hash = config_hash; - pe__unpack_dataset_nvpairs(config, XML_CIB_TAG_PROPSET, NULL, config_hash, + pe__unpack_dataset_nvpairs(config, XML_CIB_TAG_PROPSET, &rule_data, config_hash, CIB_OPTIONS_FIRST, FALSE, data_set); verify_pe_options(data_set->config_hash); @@ -515,6 +524,15 @@ unpack_nodes(xmlNode * xml_nodes, pe_working_set_t * data_set) const char *type = NULL; const char *score = NULL; + pe_rule_eval_data_t rule_data = { + .node_hash = NULL, + .role = RSC_ROLE_UNKNOWN, + .now = data_set->now, + .match_data = NULL, + .rsc_data = NULL, + .op_data = NULL + }; + for (xml_obj = __xml_first_child_element(xml_nodes); xml_obj != NULL; xml_obj = __xml_next_element(xml_obj)) { @@ -547,7 +565,7 @@ unpack_nodes(xmlNode * xml_nodes, pe_working_set_t * data_set) handle_startup_fencing(data_set, new_node); add_node_attrs(xml_obj, new_node, FALSE, data_set); - pe__unpack_dataset_nvpairs(xml_obj, XML_TAG_UTILIZATION, NULL, + pe__unpack_dataset_nvpairs(xml_obj, XML_TAG_UTILIZATION, &rule_data, new_node->details->utilization, NULL, FALSE, data_set); @@ -3698,6 +3716,15 @@ add_node_attrs(xmlNode *xml_obj, pe_node_t *node, bool overwrite, { const char *cluster_name = NULL; + pe_rule_eval_data_t rule_data = { + .node_hash = NULL, + .role = RSC_ROLE_UNKNOWN, + .now = data_set->now, + .match_data = NULL, + .rsc_data = NULL, + .op_data = NULL + }; + g_hash_table_insert(node->details->attrs, strdup(CRM_ATTR_UNAME), strdup(node->details->uname)); @@ -3719,7 +3746,7 @@ add_node_attrs(xmlNode *xml_obj, pe_node_t *node, bool overwrite, strdup(cluster_name)); } - pe__unpack_dataset_nvpairs(xml_obj, XML_TAG_ATTR_SETS, NULL, + pe__unpack_dataset_nvpairs(xml_obj, XML_TAG_ATTR_SETS, &rule_data, node->details->attrs, NULL, overwrite, data_set); if (pe_node_attribute_raw(node, CRM_ATTR_SITE_NAME) == NULL) { diff --git a/lib/pengine/utils.c b/lib/pengine/utils.c index b18b7e4..4cfd336 100644 --- a/lib/pengine/utils.c +++ b/lib/pengine/utils.c @@ -597,10 +597,19 @@ custom_action(pe_resource_t * rsc, char *key, const char *task, if (is_set(action->flags, pe_action_have_node_attrs) == FALSE && action->node != NULL && action->op_entry != NULL) { + pe_rule_eval_data_t rule_data = { + .node_hash = action->node->details->attrs, + .role = RSC_ROLE_UNKNOWN, + .now = data_set->now, + .match_data = NULL, + .rsc_data = NULL, + .op_data = NULL + }; + pe_set_action_bit(action, pe_action_have_node_attrs); pe__unpack_dataset_nvpairs(action->op_entry, XML_TAG_ATTR_SETS, - action->node->details->attrs, - action->extra, NULL, FALSE, data_set); + &rule_data, action->extra, NULL, + FALSE, data_set); } if (is_set(action->flags, pe_action_pseudo)) { @@ -873,6 +882,15 @@ pe_get_configured_timeout(pe_resource_t *rsc, const char *action, pe_working_set const char *timeout = NULL; int timeout_ms = 0; + pe_rule_eval_data_t rule_data = { + .node_hash = NULL, + .role = RSC_ROLE_UNKNOWN, + .now = data_set->now, + .match_data = NULL, + .rsc_data = NULL, + .op_data = NULL + }; + for (child = first_named_child(rsc->ops_xml, XML_ATTR_OP); child != NULL; child = crm_next_same_xml(child)) { if (safe_str_eq(action, crm_element_value(child, XML_NVPAIR_ATTR_NAME))) { @@ -884,7 +902,7 @@ pe_get_configured_timeout(pe_resource_t *rsc, const char *action, pe_working_set if (timeout == NULL && data_set->op_defaults) { GHashTable *action_meta = crm_str_table_new(); pe__unpack_dataset_nvpairs(data_set->op_defaults, XML_TAG_META_SETS, - NULL, action_meta, NULL, FALSE, data_set); + &rule_data, action_meta, NULL, FALSE, data_set); timeout = g_hash_table_lookup(action_meta, XML_ATTR_TIMEOUT); } @@ -964,10 +982,19 @@ unpack_operation(pe_action_t * action, xmlNode * xml_obj, pe_resource_t * contai pe_rsc_action_details_t *rsc_details = NULL; #endif + pe_rule_eval_data_t rule_data = { + .node_hash = NULL, + .role = RSC_ROLE_UNKNOWN, + .now = data_set->now, + .match_data = NULL, + .rsc_data = NULL, + .op_data = NULL + }; + CRM_CHECK(action && action->rsc, return); // Cluster-wide - pe__unpack_dataset_nvpairs(data_set->op_defaults, XML_TAG_META_SETS, NULL, + pe__unpack_dataset_nvpairs(data_set->op_defaults, XML_TAG_META_SETS, &rule_data, action->meta, NULL, FALSE, data_set); // Probe timeouts default differently, so handle timeout default later @@ -981,19 +1008,20 @@ unpack_operation(pe_action_t * action, xmlNode * xml_obj, pe_resource_t * contai xmlAttrPtr xIter = NULL; // take precedence over defaults - pe__unpack_dataset_nvpairs(xml_obj, XML_TAG_META_SETS, NULL, + pe__unpack_dataset_nvpairs(xml_obj, XML_TAG_META_SETS, &rule_data, action->meta, NULL, TRUE, data_set); #if ENABLE_VERSIONED_ATTRS rsc_details = pe_rsc_action_details(action); - pe_unpack_versioned_attributes(data_set->input, xml_obj, - XML_TAG_ATTR_SETS, NULL, - rsc_details->versioned_parameters, - data_set->now, NULL); - pe_unpack_versioned_attributes(data_set->input, xml_obj, - XML_TAG_META_SETS, NULL, - rsc_details->versioned_meta, - data_set->now, NULL); + + pe_eval_versioned_attributes(data_set->input, xml_obj, + XML_TAG_ATTR_SETS, &rule_data, + rsc_details->versioned_parameters, + NULL); + pe_eval_versioned_attributes(data_set->input, xml_obj, + XML_TAG_META_SETS, &rule_data, + rsc_details->versioned_meta, + NULL); #endif /* Anything set as an XML property has highest precedence. @@ -2693,14 +2721,14 @@ pe__update_recheck_time(time_t recheck, pe_working_set_t *data_set) */ void pe__unpack_dataset_nvpairs(xmlNode *xml_obj, const char *set_name, - GHashTable *node_hash, GHashTable *hash, + pe_rule_eval_data_t *rule_data, GHashTable *hash, const char *always_first, gboolean overwrite, pe_working_set_t *data_set) { crm_time_t *next_change = crm_time_new_undefined(); - pe_unpack_nvpairs(data_set->input, xml_obj, set_name, node_hash, hash, - always_first, overwrite, data_set->now, next_change); + pe_eval_nvpairs(data_set->input, xml_obj, set_name, rule_data, hash, + always_first, overwrite, next_change); if (crm_time_is_defined(next_change)) { time_t recheck = (time_t) crm_time_get_seconds_since_epoch(next_change);