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