• R/O
  • SSH

pm_extras: Commit

※リポジトリは、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


Commit MetaInfo

Revisionde06ca331522fc178a5ace631998d882a46ae64d (tree)
Time2012-06-06 07:53:11
Author <hideoyamauchi@inte...>

Log Message

Attribute update after the waiting for DC decision.

Change Summary

Incremental Difference

diff -r baf537c71439 -r de06ca331522 tools/ifcheckd.c
--- a/tools/ifcheckd.c Thu Feb 23 09:33:55 2012 +0900
+++ b/tools/ifcheckd.c Wed Jun 06 07:53:11 2012 +0900
@@ -32,11 +32,21 @@
3232 int ident; /* our pid */
3333 cib_t *cib_conn = NULL;
3434
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+
3541 static void ifcheckd_lstatus_callback(
3642 const char *node, const char *link, const char *status, void *private_data);
3743 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);
3945 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);
4050
4151 static void
4252 ifcheckd_shutdown(int nsig)
@@ -127,16 +137,18 @@
127137 }
128138
129139 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)
131141 {
132142 const char *iface_name = NULL;
133143 const char *iface_status = NULL;
134144 const char *ha_node_status = NULL;
135145 const char *ha_node_type = NULL;
136146 char *attr_name = NULL;
137- GHashTable *iface_hash = NULL;
138147
139148 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+ }
140152 ha_node_type = hb_cluster->llc_ops->node_type(hb_cluster, ha_node);
141153 if(safe_str_eq("ping", ha_node_type)) {
142154 /* ignore ping node */
@@ -144,7 +156,6 @@
144156 return;
145157 }
146158
147- iface_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
148159
149160 if(hb_cluster->llc_ops->init_ifwalk(hb_cluster, ha_node) != HA_OK) {
150161 crm_err("Cannot start heartbeat link interface walk.");
@@ -174,20 +185,38 @@
174185 return;
175186 }
176187
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+
179192 crm_debug_2("Complete");
180193 }
181194
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+}
182203 static void
183204 do_node_walk(ll_cluster_t *hb_cluster)
184205 {
185206 const char *ha_node = NULL;
186207
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+
187212 crm_info("Requesting the list of configured nodes");
188213 if(hb_cluster->llc_ops->init_nodewalk(hb_cluster) != HA_OK) {
189214 crm_err("Cannot start node walk.");
190215 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+ }
191220 return;
192221 }
193222
@@ -197,15 +226,21 @@
197226 crm_debug("Node %s: The own node skips", ha_node);
198227 continue;
199228 }
200- do_if_walk(hb_cluster, ha_node);
229+ do_if_walk(hb_cluster, ha_node, FALSE);
201230 }
202231
203232 if(hb_cluster->llc_ops->end_nodewalk(hb_cluster) != HA_OK) {
204233 crm_err("Cannot end node walk.");
205234 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+ }
206239 return;
207240 }
208241
242+ send_crm_op_ping_message();
243+
209244 crm_debug_2("Complete");
210245 }
211246
@@ -220,6 +255,129 @@
220255 "updating the CIB with a changed attribute"},
221256 {0, 0, 0, 0}
222257 };
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+}
223381
224382 int
225383 main(int argc, char **argv)
@@ -315,6 +473,17 @@
315473 }
316474 sleep(1);
317475 }
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+ }
318487
319488 if(register_with_ha() == FALSE) {
320489 crm_err("HA registration failed");
@@ -332,10 +501,6 @@
332501 hb_cluster->llc_ops->delete(hb_cluster);
333502 }
334503
335- if(cib_conn) {
336- cib_conn->cmds->signoff(cib_conn);
337- cib_delete(cib_conn);
338- }
339504
340505 return 0;
341506 }
@@ -356,7 +521,7 @@
356521 {
357522 crm_debug("Link status change: node %s link %s now has status [%s]", node, lnk, status);
358523
359- do_if_walk(hb_cluster, node);
524+ do_if_walk(hb_cluster, node, TRUE);
360525
361526 return;
362527 }
Show on old repository browser