[sheepdog] [PATCH 2/3] sheep: rename some stuff about local request handling

Liu Yuan namei.unix at gmail.com
Tue Mar 26 07:30:07 CET 2013


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

This is a prepare patch for later patch.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/group.c      |    2 +-
 sheep/request.c    |   32 +++++++++++++++++---------------
 sheep/sheep_priv.h |    8 ++++----
 3 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/sheep/group.c b/sheep/group.c
index 212f642..9d8a9ac 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -1257,7 +1257,7 @@ int create_cluster(int port, int64_t zone, int nr_vnodes,
 	INIT_LIST_HEAD(&sys->failed_nodes);
 	INIT_LIST_HEAD(&sys->delayed_nodes);
 
-	INIT_LIST_HEAD(&sys->wait_req_queue);
+	INIT_LIST_HEAD(&sys->local_req_queue);
 	INIT_LIST_HEAD(&sys->wait_rw_queue);
 	INIT_LIST_HEAD(&sys->wait_obj_queue);
 
diff --git a/sheep/request.c b/sheep/request.c
index be12015..57edb1f 100644
--- a/sheep/request.c
+++ b/sheep/request.c
@@ -457,17 +457,17 @@ int exec_local_req(struct sd_req *rq, void *data)
 
 	req = alloc_local_request(data, rq->data_length);
 	req->rq = *rq;
-	req->wait_efd = eventfd(0, 0);
+	req->local_req_efd = eventfd(0, 0);
 
-	pthread_mutex_lock(&sys->wait_req_lock);
-	list_add_tail(&req->request_list, &sys->wait_req_queue);
-	pthread_mutex_unlock(&sys->wait_req_lock);
+	pthread_mutex_lock(&sys->local_req_lock);
+	list_add_tail(&req->request_list, &sys->local_req_queue);
+	pthread_mutex_unlock(&sys->local_req_lock);
 
-	eventfd_write(sys->req_efd, value);
+	eventfd_write(sys->local_req_efd, value);
 
 again:
 	/* In error case (for e.g, EINTR) just retry read */
-	ret = eventfd_read(req->wait_efd, &value);
+	ret = eventfd_read(req->local_req_efd, &value);
 	if (ret < 0) {
 		sd_eprintf("%m");
 		if (errno == EINTR)
@@ -479,7 +479,7 @@ again:
 	/* fill rq with response header as exec_req does */
 	memcpy(rq, &req->rp, sizeof(req->rp));
 
-	close(req->wait_efd);
+	close(req->local_req_efd);
 	ret = req->rp.result;
 	free_local_request(req);
 
@@ -532,7 +532,7 @@ void put_request(struct request *req)
 		return;
 
 	if (req->local)
-		eventfd_write(req->wait_efd, value);
+		eventfd_write(req->local_req_efd, value);
 	else {
 		if (conn_tx_on(&ci->conn)) {
 			clear_client_info(ci);
@@ -894,7 +894,7 @@ int init_unix_domain_socket(const char *dir)
 					 &is_inet_socket);
 }
 
-static void req_handler(int listen_fd, int events, void *data)
+static void local_req_handler(int listen_fd, int events, void *data)
 {
 	eventfd_t value;
 	struct request *req, *t;
@@ -908,9 +908,9 @@ static void req_handler(int listen_fd, int events, void *data)
 	if (ret < 0)
 		return;
 
-	pthread_mutex_lock(&sys->wait_req_lock);
-	list_splice_init(&sys->wait_req_queue, &pending_list);
-	pthread_mutex_unlock(&sys->wait_req_lock);
+	pthread_mutex_lock(&sys->local_req_lock);
+	list_splice_init(&sys->local_req_queue, &pending_list);
+	pthread_mutex_unlock(&sys->local_req_lock);
 
 	list_for_each_entry_safe(req, t, &pending_list, request_list) {
 		list_del(&req->request_list);
@@ -920,7 +920,9 @@ static void req_handler(int listen_fd, int events, void *data)
 
 void local_req_init(void)
 {
-	pthread_mutex_init(&sys->wait_req_lock, NULL);
-	sys->req_efd = eventfd(0, EFD_NONBLOCK);
-	register_event(sys->req_efd, req_handler, NULL);
+	pthread_mutex_init(&sys->local_req_lock, NULL);
+	sys->local_req_efd = eventfd(0, EFD_NONBLOCK);
+	if (sys->local_req_efd < 0)
+		panic("failed to init local req efd");
+	register_event(sys->local_req_efd, local_req_handler, NULL);
 }
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 0e22938..6180442 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -53,7 +53,7 @@ struct request {
 
 	int refcnt;
 	bool local;
-	int wait_efd;
+	int local_req_efd;
 
 	uint64_t local_oid;
 
@@ -94,10 +94,10 @@ struct cluster_info {
 	DECLARE_BITMAP(vdi_inuse, SD_NR_VDIS);
 
 	uint8_t nr_copies;
-	int req_efd;
+	int local_req_efd;
 
-	pthread_mutex_t wait_req_lock;
-	struct list_head wait_req_queue;
+	pthread_mutex_t local_req_lock;
+	struct list_head local_req_queue;
 	struct list_head wait_rw_queue;
 	struct list_head wait_obj_queue;
 	int nr_outstanding_reqs;
-- 
1.7.9.5




More information about the sheepdog mailing list