This source file includes following definitions.
- fenced_scheduler_init
- fenced_scheduler_cleanup
- local_node_allowed_for
- register_if_fencing_device
- fenced_scheduler_run
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <stdio.h>
13 #include <errno.h>
14 #include <glib.h>
15
16 #include <crm/pengine/status.h>
17 #include <crm/pengine/internal.h>
18
19 #include <pacemaker-internal.h>
20 #include <pacemaker-fenced.h>
21
22 static pcmk_scheduler_t *scheduler = NULL;
23
24
25
26
27
28
29
30 int
31 fenced_scheduler_init(void)
32 {
33 pcmk__output_t *logger = NULL;
34 int rc = pcmk__log_output_new(&logger);
35
36 if (rc != pcmk_rc_ok) {
37 return rc;
38 }
39
40 scheduler = pe_new_working_set();
41 if (scheduler == NULL) {
42 pcmk__output_free(logger);
43 return ENOMEM;
44 }
45
46 pe__register_messages(logger);
47 pcmk__register_lib_messages(logger);
48 pcmk__output_set_log_level(logger, LOG_TRACE);
49 scheduler->priv = logger;
50
51 return pcmk_rc_ok;
52 }
53
54
55
56
57
58 void
59 fenced_scheduler_cleanup(void)
60 {
61 if (scheduler != NULL) {
62 pcmk__output_t *logger = scheduler->priv;
63
64 if (logger != NULL) {
65 logger->finish(logger, CRM_EX_OK, true, NULL);
66 pcmk__output_free(logger);
67 scheduler->priv = NULL;
68 }
69 pe_free_working_set(scheduler);
70 scheduler = NULL;
71 }
72 }
73
74
75
76
77
78
79
80
81
82 static pcmk_node_t *
83 local_node_allowed_for(const pcmk_resource_t *rsc)
84 {
85 if ((rsc != NULL) && (stonith_our_uname != NULL)) {
86 GHashTableIter iter;
87 pcmk_node_t *node = NULL;
88
89 g_hash_table_iter_init(&iter, rsc->allowed_nodes);
90 while (g_hash_table_iter_next(&iter, NULL, (void **) &node)) {
91 if (pcmk__str_eq(node->details->uname, stonith_our_uname,
92 pcmk__str_casei)) {
93 return node;
94 }
95 }
96 }
97 return NULL;
98 }
99
100
101
102
103
104
105
106
107
108 static void
109 register_if_fencing_device(gpointer data, gpointer user_data)
110 {
111 pcmk_resource_t *rsc = data;
112
113 xmlNode *xml = NULL;
114 GHashTableIter hash_iter;
115 pcmk_node_t *node = NULL;
116 const char *name = NULL;
117 const char *value = NULL;
118 const char *rclass = NULL;
119 const char *agent = NULL;
120 const char *rsc_provides = NULL;
121 stonith_key_value_t *params = NULL;
122
123
124 if (rsc->children != NULL) {
125 for (GList *iter = rsc->children; iter != NULL; iter = iter->next) {
126 register_if_fencing_device(iter->data, NULL);
127 if (pcmk__is_clone(rsc)) {
128 return;
129 }
130 }
131 return;
132 }
133
134 rclass = crm_element_value(rsc->xml, PCMK_XA_CLASS);
135 if (!pcmk__str_eq(rclass, PCMK_RESOURCE_CLASS_STONITH, pcmk__str_casei)) {
136 return;
137 }
138
139 if (pe__resource_is_disabled(rsc)) {
140 crm_info("Ignoring fencing device %s because it is disabled", rsc->id);
141 return;
142 }
143
144 if ((stonith_watchdog_timeout_ms <= 0) &&
145 pcmk__str_eq(rsc->id, STONITH_WATCHDOG_ID, pcmk__str_none)) {
146 crm_info("Ignoring fencing device %s "
147 "because watchdog fencing is disabled", rsc->id);
148 return;
149 }
150
151
152 node = local_node_allowed_for(rsc);
153 if (node == NULL) {
154 crm_info("Ignoring fencing device %s "
155 "because local node is not allowed to run it", rsc->id);
156 return;
157 }
158 if (node->weight < 0) {
159 crm_info("Ignoring fencing device %s "
160 "because local node has preference %s for it",
161 rsc->id, pcmk_readable_score(node->weight));
162 return;
163 }
164
165
166 if (pcmk__is_group(rsc->parent)) {
167 pcmk_node_t *group_node = local_node_allowed_for(rsc->parent);
168
169 if ((group_node != NULL) && (group_node->weight < 0)) {
170 crm_info("Ignoring fencing device %s "
171 "because local node has preference %s for its group",
172 rsc->id, pcmk_readable_score(group_node->weight));
173 return;
174 }
175 }
176
177 crm_debug("Reloading configuration of fencing device %s", rsc->id);
178
179 agent = crm_element_value(rsc->xml, PCMK_XA_TYPE);
180
181
182
183
184
185 get_meta_attributes(rsc->meta, rsc, node, scheduler);
186 rsc_provides = g_hash_table_lookup(rsc->meta, PCMK_STONITH_PROVIDES);
187
188 g_hash_table_iter_init(&hash_iter, pe_rsc_params(rsc, node, scheduler));
189 while (g_hash_table_iter_next(&hash_iter, (gpointer *) &name,
190 (gpointer *) &value)) {
191 if ((name == NULL) || (value == NULL)) {
192 continue;
193 }
194 params = stonith_key_value_add(params, name, value);
195 }
196
197 xml = create_device_registration_xml(pcmk__s(rsc->clone_name, rsc->id),
198 st_namespace_any, agent, params,
199 rsc_provides);
200 stonith_key_value_freeall(params, 1, 1);
201 CRM_ASSERT(stonith_device_register(xml, TRUE) == pcmk_ok);
202 free_xml(xml);
203 }
204
205
206
207
208
209
210
211 void
212 fenced_scheduler_run(xmlNode *cib)
213 {
214 CRM_CHECK((cib != NULL) && (scheduler != NULL), return);
215
216 if (scheduler->now != NULL) {
217 crm_time_free(scheduler->now);
218 scheduler->now = NULL;
219 }
220 scheduler->localhost = stonith_our_uname;
221 pcmk__schedule_actions(cib, pcmk_sched_location_only
222 |pcmk_sched_no_compat
223 |pcmk_sched_no_counts, scheduler);
224 g_list_foreach(scheduler->resources, register_if_fencing_device, NULL);
225
226 scheduler->input = NULL;
227 pe_reset_working_set(scheduler);
228 }