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 *agent = NULL;
119 const char *rsc_provides = NULL;
120 stonith_key_value_t *params = NULL;
121
122
123 if (rsc->children != NULL) {
124 for (GList *iter = rsc->children; iter != NULL; iter = iter->next) {
125 register_if_fencing_device(iter->data, NULL);
126 if (pcmk__is_clone(rsc)) {
127 return;
128 }
129 }
130 return;
131 }
132
133 if (!pcmk_is_set(rsc->flags, pcmk_rsc_fence_device)) {
134 return;
135 }
136
137 if (pe__resource_is_disabled(rsc)) {
138 crm_info("Ignoring fencing device %s because it is disabled", rsc->id);
139 return;
140 }
141
142 if ((stonith_watchdog_timeout_ms <= 0) &&
143 pcmk__str_eq(rsc->id, STONITH_WATCHDOG_ID, pcmk__str_none)) {
144 crm_info("Ignoring fencing device %s "
145 "because watchdog fencing is disabled", rsc->id);
146 return;
147 }
148
149
150 node = local_node_allowed_for(rsc);
151 if (node == NULL) {
152 crm_info("Ignoring fencing device %s "
153 "because local node is not allowed to run it", rsc->id);
154 return;
155 }
156 if (node->weight < 0) {
157 crm_info("Ignoring fencing device %s "
158 "because local node has preference %s for it",
159 rsc->id, pcmk_readable_score(node->weight));
160 return;
161 }
162
163
164 if (pcmk__is_group(rsc->parent)) {
165 pcmk_node_t *group_node = local_node_allowed_for(rsc->parent);
166
167 if ((group_node != NULL) && (group_node->weight < 0)) {
168 crm_info("Ignoring fencing device %s "
169 "because local node has preference %s for its group",
170 rsc->id, pcmk_readable_score(group_node->weight));
171 return;
172 }
173 }
174
175 crm_debug("Reloading configuration of fencing device %s", rsc->id);
176
177 agent = crm_element_value(rsc->xml, PCMK_XA_TYPE);
178
179
180
181
182
183 get_meta_attributes(rsc->meta, rsc, node, scheduler);
184 rsc_provides = g_hash_table_lookup(rsc->meta, PCMK_STONITH_PROVIDES);
185
186 g_hash_table_iter_init(&hash_iter, pe_rsc_params(rsc, node, scheduler));
187 while (g_hash_table_iter_next(&hash_iter, (gpointer *) &name,
188 (gpointer *) &value)) {
189 if ((name == NULL) || (value == NULL)) {
190 continue;
191 }
192 params = stonith_key_value_add(params, name, value);
193 }
194
195 xml = create_device_registration_xml(pcmk__s(rsc->clone_name, rsc->id),
196 st_namespace_any, agent, params,
197 rsc_provides);
198 stonith_key_value_freeall(params, 1, 1);
199 pcmk__assert(stonith_device_register(xml, TRUE) == pcmk_ok);
200 free_xml(xml);
201 }
202
203
204
205
206
207
208
209 void
210 fenced_scheduler_run(xmlNode *cib)
211 {
212 CRM_CHECK((cib != NULL) && (scheduler != NULL), return);
213
214 if (scheduler->now != NULL) {
215 crm_time_free(scheduler->now);
216 scheduler->now = NULL;
217 }
218 scheduler->localhost = stonith_our_uname;
219 pcmk__schedule_actions(cib, pcmk_sched_location_only
220 |pcmk_sched_no_compat
221 |pcmk_sched_no_counts, scheduler);
222 g_list_foreach(scheduler->resources, register_if_fencing_device, NULL);
223
224 scheduler->input = NULL;
225 pe_reset_working_set(scheduler);
226 }