This source file includes following definitions.
- pcmk__node_attr_target
- pcmk_promotion_score_name
- pcmk__node_attr
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <stdio.h>
13
14 #include <crm/common/xml.h>
15 #include <crm/common/scheduler.h>
16 #include <crm/common/scheduler_internal.h>
17
18 #define OCF_RESKEY_PREFIX "OCF_RESKEY_"
19 #define LRM_TARGET_ENV OCF_RESKEY_PREFIX CRM_META "_" PCMK__META_ON_NODE
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 const char *
38 pcmk__node_attr_target(const char *name)
39 {
40 if (name == NULL || pcmk__strcase_any_of(name, "auto", "localhost", NULL)) {
41 char buf[128] = OCF_RESKEY_PREFIX;
42 size_t offset = sizeof(OCF_RESKEY_PREFIX) - 1;
43 char *target_var = crm_meta_name(PCMK_META_CONTAINER_ATTRIBUTE_TARGET);
44 char *phys_var = crm_meta_name(PCMK__META_PHYSICAL_HOST);
45 const char *target = NULL;
46 const char *host_physical = NULL;
47
48 snprintf(buf + offset, sizeof(buf) - offset, "%s", target_var);
49 target = getenv(buf);
50
51 snprintf(buf + offset, sizeof(buf) - offset, "%s", phys_var);
52 host_physical = getenv(buf);
53
54
55 if (host_physical
56 && pcmk__str_eq(target, PCMK_VALUE_HOST, pcmk__str_casei)) {
57 name = host_physical;
58
59 } else {
60 const char *host_pcmk = getenv(LRM_TARGET_ENV);
61
62 if (host_pcmk) {
63 name = host_pcmk;
64 }
65 }
66 free(target_var);
67 free(phys_var);
68
69
70
71 return name;
72 } else {
73 return NULL;
74 }
75 }
76
77
78
79
80
81
82
83
84
85
86
87 char *
88 pcmk_promotion_score_name(const char *rsc_id)
89 {
90 if (pcmk__str_empty(rsc_id)) {
91 rsc_id = getenv("OCF_RESOURCE_INSTANCE");
92 if (pcmk__str_empty(rsc_id)) {
93 return NULL;
94 }
95 }
96 return crm_strdup_printf("master-%s", rsc_id);
97 }
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113 const char *
114 pcmk__node_attr(const pcmk_node_t *node, const char *name, const char *target,
115 enum pcmk__rsc_node node_type)
116 {
117
118 const char *value = NULL;
119 const char *node_type_s = NULL;
120 const pcmk_node_t *host = NULL;
121 const pcmk_resource_t *container = NULL;
122
123 if ((node == NULL) || (name == NULL)) {
124 return NULL;
125 }
126
127
128
129
130 if (!pcmk__is_guest_or_bundle_node(node)
131 || !pcmk__str_eq(target, PCMK_VALUE_HOST, pcmk__str_casei)) {
132 value = g_hash_table_lookup(node->priv->attrs, name);
133 crm_trace("%s='%s' on %s",
134 name, pcmk__s(value, ""), pcmk__node_name(node));
135 return value;
136 }
137
138
139
140
141
142 container = node->priv->remote->priv->launcher;
143
144 switch (node_type) {
145 case pcmk__rsc_node_assigned:
146 host = container->priv->assigned_node;
147 if (host == NULL) {
148 crm_trace("Skipping %s lookup for %s because "
149 "its container %s is unassigned",
150 name, pcmk__node_name(node), container->id);
151 return NULL;
152 }
153 node_type_s = "assigned";
154 break;
155
156 case pcmk__rsc_node_current:
157 if (container->priv->active_nodes != NULL) {
158 host = container->priv->active_nodes->data;
159 }
160 if (host == NULL) {
161 crm_trace("Skipping %s lookup for %s because "
162 "its container %s is inactive",
163 name, pcmk__node_name(node), container->id);
164 return NULL;
165 }
166 node_type_s = "current";
167 break;
168
169 default:
170
171 pcmk__assert(false);
172 break;
173 }
174
175 value = g_hash_table_lookup(host->priv->attrs, name);
176 crm_trace("%s='%s' for %s on %s container host %s",
177 name, pcmk__s(value, ""), pcmk__node_name(node), node_type_s,
178 pcmk__node_name(host));
179 return value;
180 }