[Sheepdog] [PATCH v2 10/13] sheep: revert coroutine for fixing group_handler() race

Liu Yuan namei.unix at gmail.com
Thu Feb 16 12:21:29 CET 2012


From: Liu Yuan <tailai.ly at taobao.com>


Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/group.c |   51 +++++++++++++++++----------------------------------
 1 files changed, 17 insertions(+), 34 deletions(-)

diff --git a/sheep/group.c b/sheep/group.c
index 5f38445..ee45b05 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -23,10 +23,7 @@
 #include "logger.h"
 #include "work.h"
 #include "cluster.h"
-#include "coroutine.h"
 
-static int cdrv_fd;
-static struct coroutine *cdrv_co;
 extern struct store_driver *sd_store;
 extern char *obj_path;
 
@@ -260,21 +257,22 @@ void do_cluster_request(struct work *work)
 	free(msg);
 }
 
-static void group_handler(int listen_fd, int events, void *data);
-
-static void cluster_dispatch(void *opaque)
-{
-	if (sys->cdrv->dispatch() != 0)
-		panic("oops... an error occurred inside corosync\n");
-}
-
 static void group_handler(int listen_fd, int events, void *data)
 {
-	if (events & EPOLLHUP)
-		panic("received EPOLLHUP event: has corosync exited?\n");
+	int ret;
+	if (events & EPOLLHUP) {
+		eprintf("received EPOLLHUP event: has corosync exited?\n");
+		goto out;
+	}
 
-	cdrv_co = coroutine_create(cluster_dispatch);
-	coroutine_enter(cdrv_co, NULL);
+	ret = sys->cdrv->dispatch();
+	if (ret == 0)
+		return;
+	else
+		eprintf("oops... an error occurred inside corosync\n");
+out:
+	log_close();
+	exit(1);
 }
 
 static inline int get_nodes_nr_from(struct list_head *l)
@@ -671,10 +669,6 @@ static void sd_notify_handler(struct sd_node *sender,
 	list_add_tail(&cevent->cpg_event_list, &sys->cpg_event_siblings);
 
 	start_cpg_event_work();
-
-	unregister_event(cdrv_fd);
-	coroutine_yield();
-	register_event(cdrv_fd, group_handler, NULL);
 }
 
 /*
@@ -970,8 +964,6 @@ static void cpg_event_done(struct work *work)
 	cpg_event_free(cevent);
 	cpg_event_running = 0;
 
-	coroutine_enter(cdrv_co, NULL);
-
 	if (!list_empty(&sys->cpg_event_siblings))
 		start_cpg_event_work();
 }
@@ -1246,11 +1238,6 @@ static void sd_join_handler(struct sd_node *joined,
 
 		list_add_tail(&cevent->cpg_event_list, &sys->cpg_event_siblings);
 		start_cpg_event_work();
-
-		unregister_event(cdrv_fd);
-		coroutine_yield();
-		register_event(cdrv_fd, group_handler, NULL);
-
 		break;
 	case CJ_RES_FAIL:
 	case CJ_RES_JOIN_LATER:
@@ -1368,10 +1355,6 @@ static void sd_leave_handler(struct sd_node *left,
 	list_add_tail(&cevent->cpg_event_list, &sys->cpg_event_siblings);
 	start_cpg_event_work();
 
-	unregister_event(cdrv_fd);
-	coroutine_yield();
-	register_event(cdrv_fd, group_handler, NULL);
-
 	return;
 oom:
 	if (w) {
@@ -1384,7 +1367,7 @@ oom:
 
 int create_cluster(int port, int64_t zone)
 {
-	int ret;
+	int fd, ret;
 	struct cdrv_handlers handlers = {
 		.join_handler = sd_join_handler,
 		.leave_handler = sd_leave_handler,
@@ -1402,8 +1385,8 @@ int create_cluster(int port, int64_t zone)
 		}
 	}
 
-	cdrv_fd = sys->cdrv->init(&handlers, sys->cdrv_option, sys->this_node.addr);
-	if (cdrv_fd < 0)
+	fd = sys->cdrv->init(&handlers, sys->cdrv_option, sys->this_node.addr);
+	if (fd < 0)
 		return -1;
 
 	sys->this_node.port = port;
@@ -1430,7 +1413,7 @@ int create_cluster(int port, int64_t zone)
 
 	INIT_LIST_HEAD(&sys->cpg_event_siblings);
 
-	ret = register_event(cdrv_fd, group_handler, NULL);
+	ret = register_event(fd, group_handler, NULL);
 	if (ret) {
 		eprintf("failed to register epoll events (%d)\n", ret);
 		return 1;
-- 
1.7.8.2




More information about the sheepdog mailing list