[Sheepdog] [PATCH 3/5] call queue_work for request to start_cpg_event_work

FUJITA Tomonori fujita.tomonori at lab.ntt.co.jp
Thu May 6 09:06:25 CEST 2010


preparation of executing requests and cpg events in the proper order.

Signed-off-by: FUJITA Tomonori <fujita.tomonori at lab.ntt.co.jp>
---
 collie/collie.h |    3 +++
 collie/group.c  |   33 +++++++++++++++++++++++++--------
 collie/net.c    |    6 +++++-
 3 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/collie/collie.h b/collie/collie.h
index 46307c0..89e4209 100644
--- a/collie/collie.h
+++ b/collie/collie.h
@@ -28,6 +28,7 @@
 enum cpg_event_type {
 	CPG_EVENT_CONCHG,
 	CPG_EVENT_DELIVER,
+	CPG_EVENT_REQUEST,
 };
 
 struct cpg_event {
@@ -52,6 +53,7 @@ struct request;
 typedef void (*req_end_t) (struct request *);
 
 struct request {
+	struct cpg_event cev;
 	struct sd_req rq;
 	struct sd_rsp rp;
 
@@ -116,6 +118,7 @@ int get_ordered_sd_node_list(struct sheepdog_node_list_entry *entries);
 
 int create_cluster(int port);
 
+void start_cpg_event_work(void);
 void store_queue_request(struct work *work, int idx);
 
 int read_epoch(uint32_t *epoch, uint64_t *ctime,
diff --git a/collie/group.c b/collie/group.c
index c11b87e..d5de0e3 100644
--- a/collie/group.c
+++ b/collie/group.c
@@ -944,8 +944,6 @@ static void __sd_deliver_done(struct cpg_event *cevent)
 		start_recovery(sys->epoch, NULL, 0);
 }
 
-static void start_cpg_event_work(void);
-
 static void sd_deliver(cpg_handle_t handle, const struct cpg_name *group_name,
 		       uint32_t nodeid, uint32_t pid, void *msg, size_t msg_len)
 {
@@ -1185,6 +1183,8 @@ static void cpg_event_free(struct cpg_event *cevent)
 		free(w);
 		break;
 	}
+	default:
+		break;
 	}
 }
 
@@ -1213,6 +1213,9 @@ static void cpg_event_fn(struct work *w, int idx)
 		__sd_deliver(cevent);
 		break;
 	}
+	case CPG_EVENT_REQUEST:
+		vprintf(SDOG_ERR "should not happen\n");
+		break;
 	default:
 		vprintf(SDOG_ERR "unknown event %d\n", cevent->ctype);
 	}
@@ -1272,6 +1275,8 @@ static void cpg_event_done(struct work *w, int idx)
 		__sd_deliver_done(cevent);
 		break;
 	}
+	case CPG_EVENT_REQUEST:
+		vprintf(SDOG_ERR "should not happen\n");
 	default:
 		vprintf(SDOG_ERR "unknown event %d\n", cevent->ctype);
 	}
@@ -1286,22 +1291,34 @@ out:
 }
 
 /* can be called only by the main process */
-static void start_cpg_event_work(void)
+void start_cpg_event_work(void)
 {
-	struct cpg_event *cevent;
+	struct cpg_event *cevent, *n;
+
+	if (list_empty(&sys->cpg_event_siblings))
+		vprintf(SDOG_ERR "bug\n");
 
 	if (cpg_event_running())
 		return;
 
+	if (cpg_event_suspended())
+		return;
+
+	list_for_each_entry_safe(cevent, n, &sys->cpg_event_siblings, cpg_event_list) {
+		struct request *req = container_of(cevent, struct request, cev);
+		if (cevent->ctype != CPG_EVENT_REQUEST)
+			continue;
+
+		list_del(&cevent->cpg_event_list);
+		queue_work(&req->work);
+	}
+
 	if (list_empty(&sys->cpg_event_siblings))
-		vprintf(SDOG_ERR "bug\n");
+		return;
 
 	cevent = list_first_entry(&sys->cpg_event_siblings,
 				  struct cpg_event, cpg_event_list);
 
-	if (cpg_event_suspended())
-		return;
-
 	list_del(&cevent->cpg_event_list);
 	sys->cur_cevent = cevent;
 
diff --git a/collie/net.c b/collie/net.c
index 8877535..01648aa 100644
--- a/collie/net.c
+++ b/collie/net.c
@@ -37,6 +37,8 @@ static void __done(struct work *work, int idx)
 
 static void queue_request(struct request *req)
 {
+	struct cpg_event *cevent = &req->cev;
+
 	struct sd_req *hdr = (struct sd_req *)&req->rq;
 	struct sd_rsp *rsp = (struct sd_rsp *)&req->rp;;
 
@@ -111,7 +113,9 @@ static void queue_request(struct request *req)
 
 	list_del(&req->r_wlist);
 
-	queue_work(&req->work);
+	cevent->ctype = CPG_EVENT_REQUEST;
+	list_add_tail(&cevent->cpg_event_list, &sys->cpg_event_siblings);
+	start_cpg_event_work();
 }
 
 static struct request *alloc_request(struct client_info *ci, int data_length)
-- 
1.6.5




More information about the sheepdog mailing list