Skip to content

Commit cf34f4c

Browse files
committed
PE/attrd: Allow bundle resources to read/write attributes based on the physical host rather than the container name
1 parent 0a67748 commit cf34f4c

40 files changed

+339
-219
lines changed

include/crm/msg_xml.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@
194194

195195
# define XML_CIB_TAG_RSC_TEMPLATE "template"
196196

197+
# define XML_RSC_ATTR_TARGET "container-attribute-target"
197198
# define XML_RSC_ATTR_ISOLATION_INSTANCE "isolation-instance"
198199
# define XML_RSC_ATTR_ISOLATION_WRAPPER "isolation-wrapper"
199200
# define XML_RSC_ATTR_ISOLATION_HOST "isolation-host"

include/crm/pengine/internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,5 +298,7 @@ bool remote_id_conflict(const char *remote_name, pe_working_set_t *data);
298298
void common_print(resource_t * rsc, const char *pre_text, const char *name, node_t *node, long options, void *print_data);
299299
resource_t *find_container_child(const char *stem, resource_t * rsc, node_t *node);
300300
bool fix_remote_addr(resource_t * rsc);
301+
const char *node_attribute_calculated(pe_node_t *node, const char *name, resource_t *rsc);
302+
const char *node_attribute_raw(pe_node_t *node, const char *name);
301303

302304
#endif

include/crm_internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ long crm_read_pidfile(const char *filename);
289289
# define ATTRD_OP_SYNC_RESPONSE "sync-response"
290290
# define ATTRD_OP_CLEAR_FAILURE "clear-failure"
291291

292+
# define PCMK_ENV_PHYSICAL_HOST "physical_host"
293+
294+
292295
# if SUPPORT_COROSYNC
293296
# if CS_USES_LIBQB
294297
# include <qb/qbipc_common.h>

lib/pengine/common.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,3 +431,51 @@ add_hash_param(GHashTable * hash, const char *name, const char *value)
431431
g_hash_table_insert(hash, strdup(name), strdup(value));
432432
}
433433
}
434+
435+
const char *
436+
node_attribute_calculated(pe_node_t *node, const char *name, resource_t *rsc)
437+
{
438+
const char *source;
439+
440+
if(node == NULL) {
441+
return NULL;
442+
443+
} else if(rsc == NULL) {
444+
return g_hash_table_lookup(node->details->attrs, name);
445+
}
446+
447+
source = g_hash_table_lookup(rsc->meta, XML_RSC_ATTR_TARGET);
448+
if(source == NULL || safe_str_eq("host", source) == FALSE) {
449+
return g_hash_table_lookup(node->details->attrs, name);
450+
}
451+
452+
/* Use attributes set for the containers location
453+
* instead of for the container itself
454+
*
455+
* Useful when the container is using the host's local
456+
* storage
457+
*/
458+
459+
CRM_ASSERT(node->details->remote_rsc);
460+
CRM_ASSERT(node->details->remote_rsc->container);
461+
462+
if(node->details->remote_rsc->container->running_on) {
463+
pe_node_t *host = node->details->remote_rsc->container->running_on->data;
464+
pe_rsc_trace(rsc, "%s: Looking for %s on the container host %s", rsc->id, name, host->details->uname);
465+
return g_hash_table_lookup(host->details->attrs, name);
466+
}
467+
468+
pe_rsc_trace(rsc, "%s: Not looking for %s on the container host: %s is inactive",
469+
rsc->id, name, node->details->remote_rsc->container->id);
470+
return NULL;
471+
}
472+
473+
const char *
474+
node_attribute_raw(pe_node_t *node, const char *name)
475+
{
476+
if(node == NULL) {
477+
return NULL;
478+
}
479+
return g_hash_table_lookup(node->details->attrs, name);
480+
}
481+

lib/pengine/container.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,12 @@ container_unpack(resource_t * rsc, pe_working_set_t * data_set)
764764

765765
offset += allocate_ip(container_data, tuple, buffer+offset, max-offset);
766766
container_data->tuples = g_list_append(container_data->tuples, tuple);
767+
container_data->attribute_target = g_hash_table_lookup(tuple->child->meta, XML_RSC_ATTR_TARGET);
767768
}
768769
container_data->docker_host_options = buffer;
770+
if(container_data->attribute_target) {
771+
g_hash_table_replace(rsc->meta, strdup(XML_RSC_ATTR_TARGET), strdup(container_data->attribute_target));
772+
}
769773

770774
} else {
771775
// Just a naked container, no pacemaker-remote
@@ -782,7 +786,6 @@ container_unpack(resource_t * rsc, pe_working_set_t * data_set)
782786
container_data->docker_host_options = buffer;
783787
}
784788

785-
786789
for (GListPtr gIter = container_data->tuples; gIter != NULL; gIter = gIter->next) {
787790
container_grouping_t *tuple = (container_grouping_t *)gIter->data;
788791
// TODO: Remove from list if create_container() returns TRUE

lib/pengine/unpack.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ unpack_handle_remote_attrs(node_t *this_node, xmlNode *state, pe_working_set_t *
10701070
attrs = find_xml_node(state, XML_TAG_TRANSIENT_NODEATTRS, FALSE);
10711071
add_node_attrs(attrs, this_node, TRUE, data_set);
10721072

1073-
shutdown = g_hash_table_lookup(this_node->details->attrs, XML_CIB_ATTR_SHUTDOWN);
1073+
shutdown = node_attribute_raw(this_node, XML_CIB_ATTR_SHUTDOWN);
10741074
if (shutdown != NULL && safe_str_neq("0", shutdown)) {
10751075
crm_info("Node %s is shutting down", this_node->details->uname);
10761076
this_node->details->shutdown = TRUE;
@@ -1079,18 +1079,18 @@ unpack_handle_remote_attrs(node_t *this_node, xmlNode *state, pe_working_set_t *
10791079
}
10801080
}
10811081

1082-
if (crm_is_true(g_hash_table_lookup(this_node->details->attrs, "standby"))) {
1082+
if (crm_is_true(node_attribute_raw(this_node, "standby"))) {
10831083
crm_info("Node %s is in standby-mode", this_node->details->uname);
10841084
this_node->details->standby = TRUE;
10851085
}
10861086

1087-
if (crm_is_true(g_hash_table_lookup(this_node->details->attrs, "maintenance")) ||
1087+
if (crm_is_true(node_attribute_raw(this_node, "maintenance")) ||
10881088
(rsc && !is_set(rsc->flags, pe_rsc_managed))) {
10891089
crm_info("Node %s is in maintenance-mode", this_node->details->uname);
10901090
this_node->details->maintenance = TRUE;
10911091
}
10921092

1093-
resource_discovery_enabled = g_hash_table_lookup(this_node->details->attrs, XML_NODE_ATTR_RSC_DISCOVERY);
1093+
resource_discovery_enabled = node_attribute_raw(this_node, XML_NODE_ATTR_RSC_DISCOVERY);
10941094
if (resource_discovery_enabled && !crm_is_true(resource_discovery_enabled)) {
10951095
if (is_baremetal_remote_node(this_node) && is_not_set(data_set->flags, pe_flag_stonith_enabled)) {
10961096
crm_warn("ignoring %s attribute on baremetal remote node %s, disabling resource discovery requires stonith to be enabled.",
@@ -1246,17 +1246,17 @@ unpack_status(xmlNode * status, pe_working_set_t * data_set)
12461246
attrs = find_xml_node(state, XML_TAG_TRANSIENT_NODEATTRS, FALSE);
12471247
add_node_attrs(attrs, this_node, TRUE, data_set);
12481248

1249-
if (crm_is_true(g_hash_table_lookup(this_node->details->attrs, "standby"))) {
1249+
if (crm_is_true(node_attribute_raw(this_node, "standby"))) {
12501250
crm_info("Node %s is in standby-mode", this_node->details->uname);
12511251
this_node->details->standby = TRUE;
12521252
}
12531253

1254-
if (crm_is_true(g_hash_table_lookup(this_node->details->attrs, "maintenance"))) {
1254+
if (crm_is_true(node_attribute_raw(this_node, "maintenance"))) {
12551255
crm_info("Node %s is in maintenance-mode", this_node->details->uname);
12561256
this_node->details->maintenance = TRUE;
12571257
}
12581258

1259-
resource_discovery_enabled = g_hash_table_lookup(this_node->details->attrs, XML_NODE_ATTR_RSC_DISCOVERY);
1259+
resource_discovery_enabled = node_attribute_raw(this_node, XML_NODE_ATTR_RSC_DISCOVERY);
12601260
if (resource_discovery_enabled && !crm_is_true(resource_discovery_enabled)) {
12611261
crm_warn("ignoring %s attribute on node %s, disabling resource discovery is not allowed on cluster nodes",
12621262
XML_NODE_ATTR_RSC_DISCOVERY, this_node->details->uname);
@@ -1342,7 +1342,7 @@ determine_online_status_fencing(pe_working_set_t * data_set, xmlNode * node_stat
13421342
const char *is_peer = crm_element_value(node_state, XML_NODE_IS_PEER);
13431343
const char *in_cluster = crm_element_value(node_state, XML_NODE_IN_CLUSTER);
13441344
const char *exp_state = crm_element_value(node_state, XML_NODE_EXPECTED);
1345-
const char *terminate = g_hash_table_lookup(this_node->details->attrs, "terminate");
1345+
const char *terminate = node_attribute_raw(this_node, "terminate");
13461346

13471347
/*
13481348
- XML_NODE_IN_CLUSTER ::= true|false
@@ -1516,7 +1516,7 @@ determine_online_status(xmlNode * node_state, node_t * this_node, pe_working_set
15161516

15171517
this_node->details->shutdown = FALSE;
15181518
this_node->details->expected_up = FALSE;
1519-
shutdown = g_hash_table_lookup(this_node->details->attrs, XML_CIB_ATTR_SHUTDOWN);
1519+
shutdown = node_attribute_raw(this_node, XML_CIB_ATTR_SHUTDOWN);
15201520

15211521
if (shutdown != NULL && safe_str_neq("0", shutdown)) {
15221522
this_node->details->shutdown = TRUE;
@@ -3368,8 +3368,8 @@ add_node_attrs(xmlNode * xml_obj, node_t * node, gboolean overwrite, pe_working_
33683368
unpack_instance_attributes(data_set->input, xml_obj, XML_TAG_ATTR_SETS, NULL,
33693369
node->details->attrs, NULL, overwrite, data_set->now);
33703370

3371-
if (g_hash_table_lookup(node->details->attrs, "#site-name") == NULL) {
3372-
const char *site_name = g_hash_table_lookup(node->details->attrs, "site-name");
3371+
if (node_attribute_raw(node, "#site-name") == NULL) {
3372+
const char *site_name = node_attribute_raw(node, "site-name");
33733373

33743374
if (site_name) {
33753375
/* Prefix '#' to the key */

lib/pengine/utils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,8 +1987,8 @@ fencing_action_digest_cmp(resource_t * rsc, node_t * node, pe_working_set_t * da
19871987
char *key = generate_op_key(rsc->id, STONITH_DIGEST_TASK, 0);
19881988
op_digest_cache_t *data = rsc_action_digest(rsc, STONITH_DIGEST_TASK, key, node, NULL, data_set);
19891989

1990-
const char *digest_all = g_hash_table_lookup(node->details->attrs, "digests-all");
1991-
const char *digest_secure = g_hash_table_lookup(node->details->attrs, "digests-secure");
1990+
const char *digest_all = node_attribute_raw(node, "digests-all");
1991+
const char *digest_secure = node_attribute_raw(node, "digests-secure");
19921992

19931993
/* No 'reloads' for fencing device changes
19941994
*

lib/pengine/variant.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ typedef struct container_variant_data_s {
100100
char *docker_host_options;
101101
char *docker_run_options;
102102
char *docker_run_command;
103+
const char *attribute_target;
103104

104105
resource_t *child;
105106

pengine/allocate.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,6 @@ apply_system_health(pe_working_set_t * data_set)
861861
rsc2node_new(health_strategy, rsc, system_health, NULL, node, data_set);
862862
}
863863
}
864-
865864
}
866865

867866
return TRUE;
@@ -898,7 +897,7 @@ probe_resources(pe_working_set_t * data_set)
898897

899898
for (GListPtr gIter = data_set->nodes; gIter != NULL; gIter = gIter->next) {
900899
node_t *node = (node_t *) gIter->data;
901-
const char *probed = g_hash_table_lookup(node->details->attrs, CRM_OP_PROBED);
900+
const char *probed = node_attribute_raw(node, CRM_OP_PROBED);
902901

903902
if (is_container_remote_node(node)) {
904903
/* TODO enable guest node probes once ordered probing is implemented */

pengine/constraints.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ unpack_location(xmlNode * xml_obj, pe_working_set_t * data_set)
957957
}
958958

959959
static int
960-
get_node_score(const char *rule, const char *score, gboolean raw, node_t * node)
960+
get_node_score(const char *rule, const char *score, gboolean raw, node_t * node, resource_t *rsc)
961961
{
962962
int score_f = 0;
963963

@@ -968,7 +968,7 @@ get_node_score(const char *rule, const char *score, gboolean raw, node_t * node)
968968
score_f = char2score(score);
969969

970970
} else {
971-
const char *attr_score = g_hash_table_lookup(node->details->attrs, score);
971+
const char *attr_score = node_attribute_calculated(node, score, rsc);
972972

973973
if (attr_score == NULL) {
974974
crm_debug("Rule %s: node %s did not have a value for %s",
@@ -1060,7 +1060,7 @@ generate_location_rule(resource_t * rsc, xmlNode * rule_xml, const char *discove
10601060
for (gIter = match_L; gIter != NULL; gIter = gIter->next) {
10611061
node_t *node = (node_t *) gIter->data;
10621062

1063-
node->weight = get_node_score(rule_id, score, raw_score, node);
1063+
node->weight = get_node_score(rule_id, score, raw_score, node, rsc);
10641064
}
10651065
}
10661066

@@ -1073,7 +1073,7 @@ generate_location_rule(resource_t * rsc, xmlNode * rule_xml, const char *discove
10731073
crm_trace("Rule %s %s on %s", ID(rule_xml), accept ? "passed" : "failed",
10741074
node->details->uname);
10751075

1076-
score_f = get_node_score(rule_id, score, raw_score, node);
1076+
score_f = get_node_score(rule_id, score, raw_score, node, rsc);
10771077
/* if(accept && score_f == -INFINITY) { */
10781078
/* accept = FALSE; */
10791079
/* } */

0 commit comments

Comments
 (0)