[sheepdog] [PATCH] corosync: give up cpg_initialize after retrying CPG_INIT_RETRY_CNT times

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Tue Sep 4 11:03:16 CEST 2012


It seems that, with corosync 1.x.x, cpg_initialize returns
CS_ERR_TRY_AGAIN when the corosync daemon is not running.

This patch avoids an infinite loop to limit the retry count.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/cluster/corosync.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/sheep/cluster/corosync.c b/sheep/cluster/corosync.c
index 497ae66..a2b18b1 100644
--- a/sheep/cluster/corosync.c
+++ b/sheep/cluster/corosync.c
@@ -18,6 +18,8 @@
 #include "event.h"
 #include "work.h"
 
+#define CPG_INIT_RETRY_CNT 10
+
 struct cpg_node {
 	uint32_t nodeid;
 	uint32_t pid;
@@ -719,7 +721,7 @@ out:
 
 static int corosync_init(const char *option)
 {
-	int ret, fd;
+	int ret, fd, retry_cnt = 0;
 	uint32_t nodeid;
 	cpg_callbacks_t cb = {
 		.cpg_deliver_fn = cdrv_cpg_deliver,
@@ -733,7 +735,13 @@ again:
 		/* success */
 		break;
 	case CS_ERR_TRY_AGAIN:
+		if (retry_cnt++ == CPG_INIT_RETRY_CNT) {
+			eprintf("failed to initialize cpg (%d) - "
+				"is corosync running?\n", ret);
+			return -1;
+		}
 		dprintf("retry cpg_initialize\n");
+		usleep(200000);
 		goto again;
 	default:
 		eprintf("failed to initialize cpg (%d) - "
-- 
1.7.2.5




More information about the sheepdog mailing list