[Sheepdog] [PATCH 4/9] sheep: shutdown after processing outstanding requests

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Sat Jan 1 20:53:15 CET 2011


Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/sdnet.c      |   10 ++++++++++
 sheep/sheep.c      |    2 +-
 sheep/sheep_priv.h |    1 +
 3 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/sheep/sdnet.c b/sheep/sdnet.c
index 1d38fd9..923121c 100644
--- a/sheep/sdnet.c
+++ b/sheep/sdnet.c
@@ -279,6 +279,8 @@ 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);
 
+	sys->nr_outstanding_reqs++;
+
 	return req;
 }
 
@@ -286,6 +288,8 @@ static void free_request(struct request *req)
 {
 	list_del(&req->r_siblings);
 	free(req);
+
+	sys->nr_outstanding_reqs--;
 }
 
 static void req_done(struct request *req)
@@ -519,6 +523,12 @@ static void listen_handler(int listen_fd, int events, void *data)
 	int fd, ret, opt;
 	struct client_info *ci;
 
+	if (sys->status == SD_STATUS_SHUTDOWN) {
+		dprintf("unregister %d\n", fd);
+		unregister_event(listen_fd);
+		return;
+	}
+
 	namesize = sizeof(from);
 	fd = accept(listen_fd, (struct sockaddr *)&from, &namesize);
 	if (fd < 0) {
diff --git a/sheep/sheep.c b/sheep/sheep.c
index d6c776d..19df6ef 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -134,7 +134,7 @@ int main(int argc, char **argv)
 
 	vprintf(SDOG_NOTICE "Sheepdog daemon (version %s) started\n", PACKAGE_VERSION);
 
-	while (sys->status != SD_STATUS_SHUTDOWN)
+	while (sys->status != SD_STATUS_SHUTDOWN || sys->nr_outstanding_reqs != 0)
 		event_loop(-1);
 
 	vprintf(SDOG_INFO "shutdown\n");
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index e2b79be..d91e572 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -130,6 +130,7 @@ struct cluster_info {
 	struct cpg_event *cur_cevent;
 	unsigned long cpg_event_work_flags;
 	int nr_outstanding_io;
+	int nr_outstanding_reqs;
 
 	uint32_t recovered_epoch;
 };
-- 
1.5.6.5




More information about the sheepdog mailing list