[Sheepdog] [PATCH 1/2] sheep: cleanup request list handling

Christoph Hellwig hch at infradead.org
Fri May 11 15:19:05 CEST 2012


Remove the embedded cevent in struct request and use a single list for
the requests that are under I/O, delayed and completed.

Signed-off-by: Christoph Hellwig <hch at lst.de>

diff --git a/sheep/group.c b/sheep/group.c
index 855e70e..f4ba663 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -924,9 +924,6 @@ static void event_fn(struct work *work)
 	case EVENT_NOTIFY:
 		__sd_notify(cevent);
 		break;
-	case EVENT_REQUEST:
-		vprintf(SDOG_ERR, "should not happen\n");
-		break;
 	default:
 		vprintf(SDOG_ERR, "unknown event %d\n", cevent->ctype);
 	}
@@ -955,9 +952,6 @@ static void event_done(struct work *work)
 	case EVENT_NOTIFY:
 		__sd_notify_done(cevent);
 		break;
-	case EVENT_REQUEST:
-		vprintf(SDOG_ERR, "should not happen\n");
-		break;
 	default:
 		vprintf(SDOG_ERR, "unknown event %d\n", cevent->ctype);
 	}
@@ -976,7 +970,7 @@ int is_access_to_busy_objects(uint64_t oid)
 {
 	struct request *req;
 
-	list_for_each_entry(req, &sys->outstanding_req_list, r_wlist) {
+	list_for_each_entry(req, &sys->outstanding_req_list, request_list) {
 		if (oid == req->local_oid)
 			return 1;
 	}
@@ -1020,30 +1014,29 @@ static inline void set_consistency_check(struct request *req, uint64_t oid)
 
 static void process_request_queue(void)
 {
-	struct event_struct *cevent, *n;
+	struct request *req, *n;
 
-	list_for_each_entry_safe(cevent, n, &sys->request_queue, event_list) {
-		struct request *req = container_of(cevent, struct request, cev);
-		struct sd_obj_req *hdr = (struct sd_obj_req *)&req->rq;
-
-		list_del(&cevent->event_list);
+	list_for_each_entry_safe(req, n, &sys->request_queue, request_list) {
+		list_del(&req->request_list);
 
 		if (is_io_op(req->op)) {
+			struct sd_obj_req *hdr = (struct sd_obj_req *)&req->rq;
 			int copies = sys->nr_copies;
 
 			if (copies > req->vnodes->nr_zones)
 				copies = req->vnodes->nr_zones;
 
+			list_add_tail(&req->request_list,
+				      &sys->outstanding_req_list);
+
 			if (!(req->rq.flags & SD_FLAG_CMD_IO_LOCAL) &&
 			    object_is_cached(hdr->oid)) {
 				/* If we have cache of it we are at its service. */
-				list_add_tail(&req->r_wlist, &sys->outstanding_req_list);
 				sys->nr_outstanding_io++;
 				queue_work(sys->gateway_wqueue, &req->work);
 				continue;
 			}
 
-			list_add_tail(&req->r_wlist, &sys->outstanding_req_list);
 			sys->nr_outstanding_io++;
 
 			if (need_consistency_check(req->rq.opcode, req->rq.flags))
diff --git a/sheep/sdnet.c b/sheep/sdnet.c
index 8aad8f9..ec93718 100644
--- a/sheep/sdnet.c
+++ b/sheep/sdnet.c
@@ -22,14 +22,12 @@
 
 void resume_pending_requests(void)
 {
-	struct request *next, *tmp;
+	struct request *req, *n;
 
-	list_for_each_entry_safe(next, tmp, &sys->req_wait_for_obj_list,
-				 r_wlist) {
-		struct event_struct *cevent = &next->cev;
-
-		list_del(&next->r_wlist);
-		list_add_tail(&cevent->event_list, &sys->request_queue);
+	list_for_each_entry_safe(req, n, &sys->req_wait_for_obj_list,
+				 request_list) {
+		list_del(&req->request_list);
+		list_add_tail(&req->request_list, &sys->request_queue);
 	}
 
 	if (!list_empty(&sys->request_queue))
@@ -111,7 +109,7 @@ static void io_op_done(struct work *work)
 	struct request *req = container_of(work, struct request, work);
 	struct sd_obj_req *hdr = (struct sd_obj_req *)&req->rq;
 
-	list_del(&req->r_wlist);
+	list_del(&req->request_list);
 	sys->nr_outstanding_io--;
 
 	switch (req->rp.result) {
@@ -153,7 +151,7 @@ retry:
 	put_vnode_info(req->vnodes);
 	req->vnodes = get_vnode_info();
 	setup_access_to_local_objects(req);
-	list_add_tail(&req->cev.event_list, &sys->request_queue);
+	list_add_tail(&req->request_list, &sys->request_queue);
 
 	resume_pending_requests();
 	resume_recovery_work();
@@ -240,15 +238,13 @@ static int check_request(struct request *req)
 			req->work.done(&req->work);
 		} else {
 			/* Gateway request */
-			list_del(&req->r_wlist);
-			list_add_tail(&req->r_wlist, &sys->req_wait_for_obj_list);
+			list_add_tail(&req->request_list, &sys->req_wait_for_obj_list);
 		}
 		return -1;
 	}
 
 	if (is_access_to_busy_objects(req->local_oid)) {
-		list_del(&req->r_wlist);
-		list_add_tail(&req->r_wlist, &sys->req_wait_for_obj_list);
+		list_add_tail(&req->request_list, &sys->req_wait_for_obj_list);
 		return -1;
 	}
 
@@ -257,10 +253,11 @@ static int check_request(struct request *req)
 
 static void queue_request(struct request *req)
 {
-	struct event_struct *cevent = &req->cev;
 	struct sd_req *hdr = (struct sd_req *)&req->rq;
 	struct sd_rsp *rsp = (struct sd_rsp *)&req->rp;
 
+	assert(list_empty(&req->request_list));
+
 	req->op = get_sd_op(hdr->opcode);
 	if (!req->op) {
 		eprintf("invalid opcode %d\n", hdr->opcode);
@@ -331,10 +328,9 @@ static void queue_request(struct request *req)
 		req->done(req);
 		return;
 	}
-	list_del(&req->r_wlist);
 
-	cevent->ctype = EVENT_REQUEST;
-	list_add_tail(&cevent->event_list, &sys->request_queue);
+	list_add_tail(&req->request_list, &sys->request_queue);
+
 	process_request_event_queues();
 	return;
 done:
@@ -363,8 +359,7 @@ static struct request *alloc_request(struct client_info *ci, int data_length)
 		}
 	}
 
-	list_add(&req->r_siblings, &ci->reqs);
-	INIT_LIST_HEAD(&req->r_wlist);
+	INIT_LIST_HEAD(&req->request_list);
 
 	sys->nr_outstanding_reqs++;
 	sys->outstanding_data_size += data_length;
@@ -377,7 +372,6 @@ static void free_request(struct request *req)
 	sys->nr_outstanding_reqs--;
 	sys->outstanding_data_size -= req->data_length;
 
-	list_del(&req->r_siblings);
 	put_vnode_info(req->vnodes);
 	free(req->data);
 	free(req);
@@ -385,17 +379,14 @@ static void free_request(struct request *req)
 
 static void req_done(struct request *req)
 {
-	int dead = 0;
 	struct client_info *ci = req->ci;
 
 	if (conn_tx_on(&ci->conn)) {
 		dprintf("connection seems to be dead\n");
-		dead = 1;
-	} else
-		list_add(&req->r_wlist, &ci->done_reqs);
-
-	if (dead)
 		free_request(req);
+	} else {
+		list_add(&req->request_list, &ci->done_reqs);
+	}
 
 	client_decref(ci);
 }
@@ -491,8 +482,8 @@ static void init_tx_hdr(struct client_info *ci)
 
 	memset(rsp, 0, sizeof(*rsp));
 
-	req = list_first_entry(&ci->done_reqs, struct request, r_wlist);
-	list_del(&req->r_wlist);
+	req = list_first_entry(&ci->done_reqs, struct request, request_list);
+	list_del(&req->request_list);
 
 	ci->tx_req = req;
 	ci->conn.tx_length = sizeof(*rsp);
@@ -616,7 +607,6 @@ static struct client_info *create_client(int fd, struct cluster_info *cluster)
 	ci->conn.events = EPOLLIN;
 	ci->refcnt = 1;
 
-	INIT_LIST_HEAD(&ci->reqs);
 	INIT_LIST_HEAD(&ci->done_reqs);
 
 	init_rx_hdr(ci);
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 2275a93..e74c0eb 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -38,7 +38,6 @@ enum event_type {
 	EVENT_JOIN,
 	EVENT_LEAVE,
 	EVENT_NOTIFY,
-	EVENT_REQUEST,
 };
 
 #define is_membership_change_event(x) \
@@ -56,7 +55,6 @@ struct client_info {
 
 	struct request *tx_req;
 
-	struct list_head reqs;
 	struct list_head done_reqs;
 
 	int refcnt;
@@ -68,7 +66,6 @@ struct vnode_info;
 typedef void (*req_end_t) (struct request *);
 
 struct request {
-	struct event_struct cev;
 	struct sd_req rq;
 	struct sd_rsp rp;
 
@@ -78,8 +75,7 @@ struct request {
 	unsigned int data_length;
 
 	struct client_info *ci;
-	struct list_head r_siblings;
-	struct list_head r_wlist;
+	struct list_head request_list;
 	struct list_head pending_list;
 
 	uint64_t local_oid;



More information about the sheepdog mailing list