※リポジトリは、https://github.com/linux-ha-japan/pm_extras-1.0 へ移行しました。
Pacemaker用拡張リソースエージェント・プラグインパッケージ。
Heartbeat-2.* 用 hb-extras パッケージ(*)の Pacemaker 1.0対応版
(*) http://sourceforge.jp/projects/linux-ha/releases/?package_id=10538
Revision | de06ca331522fc178a5ace631998d882a46ae64d (tree) |
---|---|
Time | 2012-06-06 07:53:11 |
Author | <hideoyamauchi@inte...> |
Attribute update after the waiting for DC decision.
@@ -32,11 +32,21 @@ | ||
32 | 32 | int ident; /* our pid */ |
33 | 33 | cib_t *cib_conn = NULL; |
34 | 34 | |
35 | +GHashTable *iface_hash = NULL; | |
36 | +IPC_Channel *crmd_channel = NULL; | |
37 | +char *ifcheckd_uuid = NULL; | |
38 | +int message_timer_id = -1; | |
39 | +int message_timeout_ms = 1*1000; | |
40 | + | |
35 | 41 | static void ifcheckd_lstatus_callback( |
36 | 42 | const char *node, const char *link, const char *status, void *private_data); |
37 | 43 | static void do_node_walk(ll_cluster_t *hb_cluster); |
38 | -static void do_if_walk(ll_cluster_t *hb_cluster, const char *ha_node); | |
44 | +static void do_if_walk(ll_cluster_t *hb_cluster, const char *ha_node, gboolean boSend); | |
39 | 45 | static void send_update(gpointer attr_name, gpointer attr_value, gpointer user_data); |
46 | +static void crmifcheckd_ipc_connection_destroy(gpointer user_data); | |
47 | +static gboolean ifcheckd_message_timeout(gpointer data); | |
48 | +static gboolean connect_crm(void); | |
49 | +static void send_crm_op_ping_message(void); | |
40 | 50 | |
41 | 51 | static void |
42 | 52 | ifcheckd_shutdown(int nsig) |
@@ -127,16 +137,18 @@ | ||
127 | 137 | } |
128 | 138 | |
129 | 139 | static void |
130 | -do_if_walk(ll_cluster_t *hb_cluster, const char *ha_node) | |
140 | +do_if_walk(ll_cluster_t *hb_cluster, const char *ha_node, gboolean boSend) | |
131 | 141 | { |
132 | 142 | const char *iface_name = NULL; |
133 | 143 | const char *iface_status = NULL; |
134 | 144 | const char *ha_node_status = NULL; |
135 | 145 | const char *ha_node_type = NULL; |
136 | 146 | char *attr_name = NULL; |
137 | - GHashTable *iface_hash = NULL; | |
138 | 147 | |
139 | 148 | crm_debug_2("Invoked"); |
149 | + if (iface_hash == NULL) { | |
150 | + iface_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
151 | + } | |
140 | 152 | ha_node_type = hb_cluster->llc_ops->node_type(hb_cluster, ha_node); |
141 | 153 | if(safe_str_eq("ping", ha_node_type)) { |
142 | 154 | /* ignore ping node */ |
@@ -144,7 +156,6 @@ | ||
144 | 156 | return; |
145 | 157 | } |
146 | 158 | |
147 | - iface_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
148 | 159 | |
149 | 160 | if(hb_cluster->llc_ops->init_ifwalk(hb_cluster, ha_node) != HA_OK) { |
150 | 161 | crm_err("Cannot start heartbeat link interface walk."); |
@@ -174,20 +185,38 @@ | ||
174 | 185 | return; |
175 | 186 | } |
176 | 187 | |
177 | - g_hash_table_foreach(iface_hash, send_update, NULL); | |
178 | - g_hash_table_destroy(iface_hash); | |
188 | + if (boSend){ | |
189 | + send_crm_op_ping_message(); | |
190 | + } | |
191 | + | |
179 | 192 | crm_debug_2("Complete"); |
180 | 193 | } |
181 | 194 | |
195 | +static void | |
196 | +send_crm_op_ping_message() { | |
197 | + if ( message_timer_id == -1 ) { | |
198 | + message_timer_id = g_timeout_add( | |
199 | + message_timeout_ms, ifcheckd_message_timeout, NULL); | |
200 | + } | |
201 | + return; | |
202 | +} | |
182 | 203 | static void |
183 | 204 | do_node_walk(ll_cluster_t *hb_cluster) |
184 | 205 | { |
185 | 206 | const char *ha_node = NULL; |
186 | 207 | |
208 | + if (iface_hash == NULL) { | |
209 | + iface_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
210 | + } | |
211 | + | |
187 | 212 | crm_info("Requesting the list of configured nodes"); |
188 | 213 | if(hb_cluster->llc_ops->init_nodewalk(hb_cluster) != HA_OK) { |
189 | 214 | crm_err("Cannot start node walk."); |
190 | 215 | crm_err("REASON: %s", hb_cluster->llc_ops->errmsg(hb_cluster)); |
216 | + if (iface_hash != NULL) { | |
217 | + g_hash_table_destroy(iface_hash); | |
218 | + iface_hash = NULL; | |
219 | + } | |
191 | 220 | return; |
192 | 221 | } |
193 | 222 |
@@ -197,15 +226,21 @@ | ||
197 | 226 | crm_debug("Node %s: The own node skips", ha_node); |
198 | 227 | continue; |
199 | 228 | } |
200 | - do_if_walk(hb_cluster, ha_node); | |
229 | + do_if_walk(hb_cluster, ha_node, FALSE); | |
201 | 230 | } |
202 | 231 | |
203 | 232 | if(hb_cluster->llc_ops->end_nodewalk(hb_cluster) != HA_OK) { |
204 | 233 | crm_err("Cannot end node walk."); |
205 | 234 | crm_err("REASON: %s", hb_cluster->llc_ops->errmsg(hb_cluster)); |
235 | + if (iface_hash != NULL) { | |
236 | + g_hash_table_destroy(iface_hash); | |
237 | + iface_hash = NULL; | |
238 | + } | |
206 | 239 | return; |
207 | 240 | } |
208 | 241 | |
242 | + send_crm_op_ping_message(); | |
243 | + | |
209 | 244 | crm_debug_2("Complete"); |
210 | 245 | } |
211 | 246 |
@@ -220,6 +255,129 @@ | ||
220 | 255 | "updating the CIB with a changed attribute"}, |
221 | 256 | {0, 0, 0, 0} |
222 | 257 | }; |
258 | +void | |
259 | +ifchecked_ipc_connection_destroy(gpointer user_data) | |
260 | +{ | |
261 | + crm_debug_2("Invoked"); | |
262 | + crm_err("Connection to CRMd was terminated"); | |
263 | + | |
264 | + if (mainloop != NULL && g_main_is_running(mainloop)) { | |
265 | + g_main_quit(mainloop); | |
266 | + return; | |
267 | + } | |
268 | + exit(LSB_EXIT_OK); | |
269 | +} | |
270 | + | |
271 | +gboolean | |
272 | +ifcheckd_message_timeout(gpointer data) | |
273 | +{ | |
274 | + xmlNode *msg_data = NULL; | |
275 | + | |
276 | + crm_debug_2("Invoked"); | |
277 | + crm_debug("send message CRM_OP_PING"); | |
278 | + | |
279 | + xmlNode *cmd = create_request( | |
280 | + CRM_OP_PING, msg_data, NULL, CRM_SYSTEM_DC, | |
281 | + crm_system_name, ifcheckd_uuid); | |
282 | + | |
283 | + send_ipc_message(crmd_channel, cmd); | |
284 | + free_xml(cmd); | |
285 | + | |
286 | + return TRUE; | |
287 | +} | |
288 | +gboolean | |
289 | +ifcheckd_msg_callback(IPC_Channel * server, void *private_data) | |
290 | +{ | |
291 | + int lpc = 0; | |
292 | + xmlNode *msg = NULL; | |
293 | + gboolean stay_connected = TRUE; | |
294 | + gboolean isLiveDC = FALSE; | |
295 | + | |
296 | + | |
297 | + g_source_remove(message_timer_id); | |
298 | + message_timer_id = -1; | |
299 | + | |
300 | + while(IPC_ISRCONN(server)) { | |
301 | + if(server->ops->is_message_pending(server) == 0) { | |
302 | + break; | |
303 | + } | |
304 | + | |
305 | + msg = xmlfromIPC(server, MAX_IPC_DELAY); | |
306 | + if (msg == NULL) { | |
307 | + break; | |
308 | + } | |
309 | + | |
310 | + lpc++; | |
311 | + fprintf(stderr, "."); | |
312 | + crm_log_xml(LOG_DEBUG_2, "[inbound]", msg); | |
313 | + | |
314 | + const char *dc = crm_element_value(msg, F_CRM_HOST_FROM); | |
315 | + if(dc != NULL) { | |
316 | + crm_debug_2("Alive DC(%s)", dc); | |
317 | + isLiveDC = TRUE; | |
318 | + } else { | |
319 | + crm_debug_2("Not Alive DC"); | |
320 | + } | |
321 | + | |
322 | + free_xml(msg); | |
323 | + msg = NULL; | |
324 | + | |
325 | + if(server->ch_status != IPC_CONNECT) { | |
326 | + stay_connected = FALSE; | |
327 | + break; | |
328 | + } | |
329 | + | |
330 | + if (isLiveDC == TRUE && iface_hash != NULL) { | |
331 | + crm_debug_2("Alive DC send_update() CALL"); | |
332 | + g_hash_table_foreach(iface_hash, send_update, NULL); | |
333 | + g_hash_table_destroy(iface_hash); | |
334 | + iface_hash = NULL; | |
335 | + } else if (isLiveDC == FALSE && iface_hash != NULL) { | |
336 | + crm_debug_2("Not Alive DC(wait.....)"); | |
337 | + } | |
338 | + } | |
339 | + | |
340 | + crm_debug_2("Processed %d messages (%d)", lpc, server->ch_status); | |
341 | + | |
342 | + if (isLiveDC == FALSE && iface_hash != NULL && stay_connected == TRUE) { | |
343 | + crm_debug_2("Not Live DC timer set"); | |
344 | + message_timer_id = g_timeout_add( | |
345 | + message_timeout_ms, ifcheckd_message_timeout, NULL); | |
346 | + } | |
347 | + | |
348 | + return stay_connected; | |
349 | +} | |
350 | +gboolean | |
351 | +connect_crm(void) | |
352 | +{ | |
353 | + GCHSource *src = NULL; | |
354 | + | |
355 | + crm_malloc0(ifcheckd_uuid, 11); | |
356 | + if(ifcheckd_uuid != NULL) { | |
357 | + snprintf(ifcheckd_uuid, 10, "%d", getpid()); | |
358 | + ifcheckd_uuid[10] = '\0'; | |
359 | + } | |
360 | + | |
361 | + while(src == NULL) { | |
362 | + src = init_client_ipc_comms( | |
363 | + CRM_SYSTEM_CRMD, ifcheckd_msg_callback, NULL, &crmd_channel); | |
364 | + if(src == NULL) { | |
365 | + crm_debug("Waiting signing on to the CRMd service\n"); | |
366 | + sleep(1); | |
367 | + } | |
368 | + } | |
369 | + | |
370 | + if(crmd_channel != NULL) { | |
371 | + send_hello_message( | |
372 | + crmd_channel, ifcheckd_uuid, crm_system_name,"0", "1"); | |
373 | + | |
374 | + set_IPC_Channel_dnotify(src, ifchecked_ipc_connection_destroy); | |
375 | + | |
376 | + crm_info("signing on to the CRMd service\n"); | |
377 | + return TRUE; | |
378 | + } | |
379 | + return FALSE; | |
380 | +} | |
223 | 381 | |
224 | 382 | int |
225 | 383 | main(int argc, char **argv) |
@@ -315,6 +473,17 @@ | ||
315 | 473 | } |
316 | 474 | sleep(1); |
317 | 475 | } |
476 | + if(cib_conn) { | |
477 | + cib_conn->cmds->signoff(cib_conn); | |
478 | + cib_delete(cib_conn); | |
479 | + } | |
480 | + | |
481 | + | |
482 | + if (connect_crm() == FALSE) { | |
483 | + crm_err("crmd connection failed"); | |
484 | + cl_flush_logs(); | |
485 | + exit(LSB_EXIT_GENERIC); | |
486 | + } | |
318 | 487 | |
319 | 488 | if(register_with_ha() == FALSE) { |
320 | 489 | crm_err("HA registration failed"); |
@@ -332,10 +501,6 @@ | ||
332 | 501 | hb_cluster->llc_ops->delete(hb_cluster); |
333 | 502 | } |
334 | 503 | |
335 | - if(cib_conn) { | |
336 | - cib_conn->cmds->signoff(cib_conn); | |
337 | - cib_delete(cib_conn); | |
338 | - } | |
339 | 504 | |
340 | 505 | return 0; |
341 | 506 | } |
@@ -356,7 +521,7 @@ | ||
356 | 521 | { |
357 | 522 | crm_debug("Link status change: node %s link %s now has status [%s]", node, lnk, status); |
358 | 523 | |
359 | - do_if_walk(hb_cluster, node); | |
524 | + do_if_walk(hb_cluster, node, TRUE); | |
360 | 525 | |
361 | 526 | return; |
362 | 527 | } |