This source file includes following definitions.
- rsc_is_known_on
- order_start_vs_fencing
- order_stop_vs_fencing
- rsc_stonith_ordering
- pcmk__order_vs_fence
- pcmk__order_vs_unfence
- pcmk__fence_guest
- pcmk__node_unfenced
- pcmk__is_unfence_device
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <glib.h>
13
14 #include <crm/crm.h>
15 #include <crm/pengine/status.h>
16 #include <pacemaker-internal.h>
17 #include "libpacemaker_private.h"
18
19
20
21
22
23
24
25
26
27
28 static bool
29 rsc_is_known_on(pe_resource_t *rsc, const pe_node_t *node)
30 {
31 if (pe_hash_table_lookup(rsc->known_on, node->details->id)) {
32 return TRUE;
33
34 } else if ((rsc->variant == pe_native)
35 && pe_rsc_is_anon_clone(rsc->parent)
36 && pe_hash_table_lookup(rsc->parent->known_on, node->details->id)) {
37
38
39
40
41 return TRUE;
42 }
43 return FALSE;
44 }
45
46
47
48
49
50
51
52
53
54 static void
55 order_start_vs_fencing(pe_resource_t *rsc, pe_action_t *stonith_op,
56 pe_working_set_t *data_set)
57 {
58 pe_node_t *target;
59 GList *gIter = NULL;
60
61 CRM_CHECK(stonith_op && stonith_op->node, return);
62 target = stonith_op->node;
63
64 for (gIter = rsc->actions; gIter != NULL; gIter = gIter->next) {
65 pe_action_t *action = (pe_action_t *) gIter->data;
66
67 switch (action->needs) {
68 case rsc_req_nothing:
69
70 break;
71
72 case rsc_req_stonith:
73 order_actions(stonith_op, action, pe_order_optional);
74 break;
75
76 case rsc_req_quorum:
77 if (pcmk__str_eq(action->task, RSC_START, pcmk__str_casei)
78 && pe_hash_table_lookup(rsc->allowed_nodes, target->details->id)
79 && !rsc_is_known_on(rsc, target)) {
80
81
82
83
84
85
86
87
88
89
90 pe_rsc_debug(rsc, "Ordering %s after %s recovery", action->uuid,
91 target->details->uname);
92 order_actions(stonith_op, action,
93 pe_order_optional | pe_order_runnable_left);
94 }
95 break;
96 }
97 }
98 }
99
100
101
102
103
104
105
106
107
108 static void
109 order_stop_vs_fencing(pe_resource_t *rsc, pe_action_t *stonith_op,
110 pe_working_set_t *data_set)
111 {
112 GList *gIter = NULL;
113 GList *action_list = NULL;
114 bool order_implicit = false;
115
116 pe_resource_t *top = uber_parent(rsc);
117 pe_action_t *parent_stop = NULL;
118 pe_node_t *target;
119
120 CRM_CHECK(stonith_op && stonith_op->node, return);
121 target = stonith_op->node;
122
123
124 action_list = pe__resource_actions(rsc, target, RSC_STOP, FALSE);
125
126
127
128
129
130
131
132 if (pcmk_is_set(rsc->flags, pe_rsc_needs_fencing)
133 || pe__is_guest_node(target)) {
134
135 order_implicit = true;
136 }
137
138 if (action_list && order_implicit) {
139 parent_stop = find_first_action(top->actions, NULL, RSC_STOP, NULL);
140 }
141
142 for (gIter = action_list; gIter != NULL; gIter = gIter->next) {
143 pe_action_t *action = (pe_action_t *) gIter->data;
144
145
146 pe__set_action_flags(action, pe_action_pseudo|pe_action_runnable);
147
148 if (order_implicit) {
149 pe__set_action_flags(action, pe_action_implied_by_stonith);
150
151
152
153
154
155
156
157
158
159
160
161
162
163 if (!pe_rsc_is_bundled(rsc)) {
164 order_actions(stonith_op, action, pe_order_preserve);
165 }
166 order_actions(stonith_op, parent_stop, pe_order_preserve);
167 }
168
169 if (pcmk_is_set(rsc->flags, pe_rsc_failed)) {
170 crm_notice("Stop of failed resource %s is implicit %s %s is fenced",
171 rsc->id, (order_implicit? "after" : "because"),
172 target->details->uname);
173 } else {
174 crm_info("%s is implicit %s %s is fenced",
175 action->uuid, (order_implicit? "after" : "because"),
176 target->details->uname);
177 }
178
179 if (pcmk_is_set(rsc->flags, pe_rsc_notify)) {
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200 create_secondary_notification(action, rsc, stonith_op, data_set);
201 }
202
203 #if 0
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221 crm_info("Moving healthy resource %s off %s before fencing",
222 rsc->id, node->details->uname);
223 pcmk__new_ordering(rsc, stop_key(rsc), NULL, NULL,
224 strdup(CRM_OP_FENCE), stonith_op,
225 pe_order_optional, data_set);
226 #endif
227 }
228
229 g_list_free(action_list);
230
231
232 action_list = pe__resource_actions(rsc, target, RSC_DEMOTE, FALSE);
233
234 for (gIter = action_list; gIter != NULL; gIter = gIter->next) {
235 pe_action_t *action = (pe_action_t *) gIter->data;
236
237 if (!(action->node->details->online) || action->node->details->unclean
238 || pcmk_is_set(rsc->flags, pe_rsc_failed)) {
239
240 if (pcmk_is_set(rsc->flags, pe_rsc_failed)) {
241 pe_rsc_info(rsc,
242 "Demote of failed resource %s is implicit after %s is fenced",
243 rsc->id, target->details->uname);
244 } else {
245 pe_rsc_info(rsc, "%s is implicit after %s is fenced",
246 action->uuid, target->details->uname);
247 }
248
249
250
251
252 pe__set_action_flags(action, pe_action_pseudo|pe_action_runnable);
253
254 if (pe_rsc_is_bundled(rsc)) {
255
256
257 } else if (order_implicit) {
258 order_actions(stonith_op, action, pe_order_preserve|pe_order_optional);
259 }
260 }
261 }
262
263 g_list_free(action_list);
264 }
265
266
267
268
269
270
271
272
273
274 static void
275 rsc_stonith_ordering(pe_resource_t *rsc, pe_action_t *stonith_op,
276 pe_working_set_t *data_set)
277 {
278 if (rsc->children) {
279 GList *gIter = NULL;
280
281 for (gIter = rsc->children; gIter != NULL; gIter = gIter->next) {
282 pe_resource_t *child_rsc = (pe_resource_t *) gIter->data;
283
284 rsc_stonith_ordering(child_rsc, stonith_op, data_set);
285 }
286
287 } else if (!pcmk_is_set(rsc->flags, pe_rsc_managed)) {
288 pe_rsc_trace(rsc,
289 "Skipping fencing constraints for unmanaged resource: %s",
290 rsc->id);
291
292 } else {
293 order_start_vs_fencing(rsc, stonith_op, data_set);
294 order_stop_vs_fencing(rsc, stonith_op, data_set);
295 }
296 }
297
298
299
300
301
302
303
304
305
306
307
308
309 void
310 pcmk__order_vs_fence(pe_action_t *stonith_op, pe_working_set_t *data_set)
311 {
312 CRM_CHECK(stonith_op && data_set, return);
313 for (GList *r = data_set->resources; r != NULL; r = r->next) {
314 rsc_stonith_ordering((pe_resource_t *) r->data, stonith_op, data_set);
315 }
316 }
317
318
319
320
321
322
323
324
325
326
327
328 void
329 pcmk__order_vs_unfence(pe_resource_t *rsc, pe_node_t *node, pe_action_t *action,
330 enum pe_ordering order, pe_working_set_t *data_set)
331 {
332
333
334
335
336
337
338
339 if (pcmk__is_unfence_device(rsc, data_set)
340 || pcmk_is_set(rsc->flags, pe_rsc_needs_unfencing)) {
341
342
343
344
345
346 pe_action_t *unfence = pe_fence_op(node, "on", TRUE, NULL, FALSE, data_set);
347
348 order_actions(unfence, action, order);
349
350 if (!pcmk__node_unfenced(node)) {
351
352 char *reason = crm_strdup_printf("required by %s %s",
353 rsc->id, action->task);
354
355 trigger_unfencing(NULL, node, reason, NULL, data_set);
356 free(reason);
357 }
358 }
359 }
360
361
362
363
364
365
366
367
368 void
369 pcmk__fence_guest(pe_node_t *node, pe_working_set_t *data_set)
370 {
371 pe_resource_t *container = node->details->remote_rsc->container;
372 pe_action_t *stop = NULL;
373 pe_action_t *stonith_op = NULL;
374
375
376
377
378
379
380
381 const char *fence_action = "off";
382
383
384
385
386 if (container) {
387 stop = find_first_action(container->actions, NULL, CRMD_ACTION_STOP,
388 NULL);
389
390 if (find_first_action(container->actions, NULL, CRMD_ACTION_START,
391 NULL)) {
392 fence_action = "reboot";
393 }
394 }
395
396
397
398
399 stonith_op = pe_fence_op(node, fence_action, FALSE, "guest is unclean",
400 FALSE, data_set);
401 pe__set_action_flags(stonith_op, pe_action_pseudo|pe_action_runnable);
402
403
404
405
406
407 if ((stop != NULL) && pcmk_is_set(stop->flags, pe_action_pseudo)) {
408 pe_action_t *parent_stonith_op = pe_fence_op(stop->node, NULL, FALSE,
409 NULL, FALSE, data_set);
410
411 crm_info("Implying guest node %s is down (action %d) after %s fencing",
412 node->details->uname, stonith_op->id,
413 stop->node->details->uname);
414 order_actions(parent_stonith_op, stonith_op,
415 pe_order_runnable_left|pe_order_implies_then);
416
417 } else if (stop) {
418 order_actions(stop, stonith_op,
419 pe_order_runnable_left|pe_order_implies_then);
420 crm_info("Implying guest node %s is down (action %d) "
421 "after container %s is stopped (action %d)",
422 node->details->uname, stonith_op->id,
423 container->id, stop->id);
424 } else {
425
426
427
428
429
430
431
432 stop = find_first_action(node->details->remote_rsc->actions, NULL,
433 RSC_STOP, NULL);
434
435 if (stop) {
436 order_actions(stop, stonith_op, pe_order_optional);
437 crm_info("Implying guest node %s is down (action %d) "
438 "after connection is stopped (action %d)",
439 node->details->uname, stonith_op->id, stop->id);
440 } else {
441
442
443
444 crm_info("Implying guest node %s is down (action %d) ",
445 node->details->uname, stonith_op->id);
446 }
447 }
448
449
450 pcmk__order_vs_fence(stonith_op, data_set);
451 }
452
453
454
455
456
457
458
459
460
461
462 bool
463 pcmk__node_unfenced(pe_node_t *node)
464 {
465 const char *unfenced = pe_node_attribute_raw(node, CRM_ATTR_UNFENCED);
466
467 return !pcmk__str_eq(unfenced, "0", pcmk__str_null_matches);
468 }
469
470
471
472
473
474
475
476
477
478
479
480 bool
481 pcmk__is_unfence_device(const pe_resource_t *rsc,
482 const pe_working_set_t *data_set)
483 {
484 return pcmk_is_set(rsc->flags, pe_rsc_fence_device)
485 && pcmk_is_set(data_set->flags, pe_flag_enable_unfencing);
486 }