[Sheepdog] [PATCH] simplify work_queue

FUJITA Tomonori fujita.tomonori at lab.ntt.co.jp
Thu Apr 22 09:19:45 CEST 2010


we don't use multiple queues (and unlikely use it in the future).

Signed-off-by: FUJITA Tomonori <fujita.tomonori at lab.ntt.co.jp>
---
 collie/collie.c |    4 ++--
 collie/collie.h |    3 +--
 collie/group.c  |    2 +-
 collie/net.c    |    2 +-
 collie/store.c  |   12 +++++-------
 collie/vdi.c    |   10 +++++-----
 collie/work.c   |   29 +++++++++++++++++++----------
 collie/work.h   |   14 ++------------
 8 files changed, 36 insertions(+), 40 deletions(-)

diff --git a/collie/collie.c b/collie/collie.c
index 9ab14de..984955f 100644
--- a/collie/collie.c
+++ b/collie/collie.c
@@ -112,8 +112,8 @@ int main(int argc, char **argv)
 	if (ret)
 		exit(1);
 
-	dobj_queue = init_work_queue(DATA_OBJ_NR_WORKER_THREAD);
-	if (!dobj_queue)
+	ret = init_work_queue(NR_WORKER_THREAD);
+	if (ret)
 		exit(1);
 
 	ret = create_listen_port(port, sys);
diff --git a/collie/collie.h b/collie/collie.h
index 8e43492..4f9164b 100644
--- a/collie/collie.h
+++ b/collie/collie.h
@@ -120,8 +120,7 @@ int get_global_nr_copies(uint32_t *copies);
 int set_nodeid(uint64_t nodeid);
 int get_nodeid(uint64_t *nodeid);
 
-#define DATA_OBJ_NR_WORKER_THREAD 4
-extern struct work_queue *dobj_queue;
+#define NR_WORKER_THREAD 4
 
 int epoch_log_write(uint32_t epoch, char *buf, int len);
 int epoch_log_read(uint32_t epoch, char *buf, int len);
diff --git a/collie/group.c b/collie/group.c
index d141f27..9216e60 100644
--- a/collie/group.c
+++ b/collie/group.c
@@ -1317,7 +1317,7 @@ static void start_cpg_event_work(void)
 	cpg_event_work.fn = cpg_event_fn;
 	cpg_event_work.done = cpg_event_done;
 
-	queue_work(dobj_queue, &cpg_event_work);
+	queue_work(&cpg_event_work);
 }
 
 static void sd_confchg(cpg_handle_t handle, const struct cpg_name *group_name,
diff --git a/collie/net.c b/collie/net.c
index 4428ee1..586c7f1 100644
--- a/collie/net.c
+++ b/collie/net.c
@@ -111,7 +111,7 @@ static void queue_request(struct request *req)
 
 	list_del(&req->r_wlist);
 
-	queue_work(dobj_queue, &req->work);
+	queue_work(&req->work);
 }
 
 static struct request *alloc_request(struct client_info *ci, int data_length)
diff --git a/collie/store.c b/collie/store.c
index a9ca52d..b35a656 100644
--- a/collie/store.c
+++ b/collie/store.c
@@ -36,8 +36,6 @@ static char *zero_block;
 static mode_t def_dmode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP;
 static mode_t def_fmode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
 
-struct work_queue *dobj_queue;
-
 static int stat_sheep(uint64_t *store_size, uint64_t *store_free, uint32_t epoch)
 {
 	struct statvfs vs;
@@ -1228,7 +1226,7 @@ static void __start_recovery(struct work *work, int idx);
 static void recover_timer(void *data)
 {
 	struct recovery_work *rw = (struct recovery_work *)data;
-	queue_work(dobj_queue, &rw->work);
+	queue_work(&rw->work);
 }
 
 static void recover_done(struct work *work, int idx)
@@ -1247,7 +1245,7 @@ static void recover_done(struct work *work, int idx)
 	if (rw->done < rw->count && list_empty(&recovery_work_list)) {
 		rw->work.fn = recover_one;
 
-		queue_work(dobj_queue, &rw->work);
+		queue_work(&rw->work);
 		return;
 	}
 
@@ -1265,7 +1263,7 @@ static void recover_done(struct work *work, int idx)
 		list_del(&rw->rw_siblings);
 
 		recovering = 1;
-		queue_work(dobj_queue, &rw->work);
+		queue_work(&rw->work);
 	}
 }
 
@@ -1466,7 +1464,7 @@ int start_recovery(uint32_t epoch, unsigned long *failed_vdis, int nr_failed_vdi
 		list_add_tail(&rw->rw_siblings, &recovery_work_list);
 	else {
 		recovering = 1;
-		queue_work(dobj_queue, &rw->work);
+		queue_work(&rw->work);
 	}
 
 	return 0;
@@ -1669,7 +1667,7 @@ int init_store(char *d)
 	if (ret)
 		return ret;
 
-	zero_block = zalloc(SD_DATA_OBJ_SIZE * DATA_OBJ_NR_WORKER_THREAD);
+	zero_block = zalloc(SD_DATA_OBJ_SIZE * NR_WORKER_THREAD);
 	if (!zero_block)
 		return 1;
 
diff --git a/collie/vdi.c b/collie/vdi.c
index 7a87760..6747afa 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -385,7 +385,7 @@ static void delete_one_done(struct work *work, int idx)
 
 	dw->done++;
 	if (dw->done < dw->count) {
-		queue_work(dobj_queue, &dw->work);
+		queue_work(&dw->work);
 		return;
 	}
 
@@ -401,7 +401,7 @@ static void delete_one_done(struct work *work, int idx)
 				      struct deletion_work, dw_siblings);
 
 		deleting++;
-		queue_work(dobj_queue, &dw->work);
+		queue_work(&dw->work);
 	}
 }
 
@@ -498,7 +498,7 @@ static void __start_deletion_done(struct work *work, int idx)
 		dw->work.fn = delete_one;
 		dw->work.done = delete_one_done;
 
-		queue_work(dobj_queue, &dw->work);
+		queue_work(&dw->work);
 		return;
 	}
 
@@ -514,7 +514,7 @@ static void __start_deletion_done(struct work *work, int idx)
 				      struct deletion_work, dw_siblings);
 
 		deleting++;
-		queue_work(dobj_queue, &dw->work);
+		queue_work(&dw->work);
 	}
 }
 
@@ -542,7 +542,7 @@ int start_deletion(uint64_t oid)
 
 	if (!deleting) {
 		deleting++;
-		queue_work(dobj_queue, &dw->work);
+		queue_work(&dw->work);
 	}
 
 	return 0;
diff --git a/collie/work.c b/collie/work.c
index 6aeded9..a591b57 100644
--- a/collie/work.c
+++ b/collie/work.c
@@ -43,6 +43,13 @@ extern int signalfd(int fd, const sigset_t *mask, int flags);
 static int sig_fd;
 static LIST_HEAD(worker_info_list);
 
+struct work_queue {
+	int wq_state;
+	int nr_active;
+	struct list_head pending_list;
+	struct list_head blocked_list;
+};
+
 enum wq_state {
 	WQ_BLOCKED = (1U << 0),
 	WQ_DEAD = (1U << 1),
@@ -128,16 +135,18 @@ static void __queue_work(struct work_queue *q, struct work *work, int enabled)
 		list_add_tail(&work->w_list, &wi->q.blocked_list);
 }
 
-void queue_work(struct work_queue *q, struct work *work)
+static struct work_queue *wqueue;
+
+void queue_work(struct work *work)
 {
 	int enabled;
 
-	if (!list_empty(&q->blocked_list))
+	if (!list_empty(&wqueue->blocked_list))
 		enabled = 0;
 	else
-		enabled = work_enabled(q, work);
+		enabled = work_enabled(wqueue, work);
 
-	__queue_work(q, work, enabled);
+	__queue_work(wqueue, work, enabled);
 }
 
 static void work_post_done(struct work_queue *q, enum work_attr attr)
@@ -266,22 +275,21 @@ static int init_signalfd(void)
 
 	ret = register_event(sig_fd, bs_thread_request_done, NULL);
 
-
 	return 0;
 }
 
-struct work_queue *init_work_queue(int nr)
+int init_work_queue(int nr)
 {
 	int i, ret;
 	struct worker_info *wi;
 
 	ret = init_signalfd();
 	if (ret)
-		return NULL;
+		return -1;
 
 	wi = zalloc(sizeof(*wi) + nr * sizeof(pthread_t));
 	if (!wi)
-		return NULL;
+		return -1;
 
 	wi->nr_threads = nr;
 
@@ -310,8 +318,9 @@ struct work_queue *init_work_queue(int nr)
 	pthread_mutex_unlock(&wi->startup_lock);
 
 	list_add(&wi->worker_info_siblings, &worker_info_list);
+	wqueue = &wi->q;
 
-	return &wi->q;
+	return 0;
 destroy_threads:
 
 	wi->q.wq_state |= WQ_DEAD;
@@ -327,7 +336,7 @@ destroy_threads:
 	pthread_mutex_destroy(&wi->startup_lock);
 	pthread_mutex_destroy(&wi->finished_lock);
 
-	return NULL;
+	return -1;
 }
 
 void exit_work_queue(struct work_queue *q)
diff --git a/collie/work.h b/collie/work.h
index 6b9000c..05367cb 100644
--- a/collie/work.h
+++ b/collie/work.h
@@ -10,13 +10,6 @@ enum work_attr {
 	WORK_ORDERED,
 };
 
-struct work_queue {
-	int wq_state;
-	int nr_active;
-	struct list_head pending_list;
-	struct list_head blocked_list;
-};
-
 struct work {
 	struct list_head w_list;
 	work_func_t fn;
@@ -24,10 +17,7 @@ struct work {
 	enum work_attr attr;
 };
 
-struct work_queue *init_work_queue(int nr);
-void exit_work_queue(struct work_queue *q);
-void queue_work(struct work_queue *q, struct work *work);
-void resume_work_queue(struct work_queue *q);
-void wait_work_queue_inactive(struct work_queue *q);
+int init_work_queue(int nr);
+void queue_work(struct work *work);
 
 #endif
-- 
1.6.5




More information about the sheepdog mailing list