[sheepdog] [PATCH v2 1/4] sheep: leave cluster after unpluging all disks

Robin Dong robin.k.dong at gmail.com
Fri Jun 20 10:21:27 CEST 2014


From: Robin Dong <sanbai at taobao.com>

After following steps:

 1. start 6 sheep cluster, every sheep has 4 data path
 2. unplug 4 data path for one sheep daemon

then we will see the sheep daemon which has no data path is also
in the cluster by using 'dog node list'.But a sheep daemon with
no data path should be a pure gateway.

So we should return EIO after unpluging last disk which will cause
sheep to leave cluster.

Reported-by: Meng An <isolate000 at gmail.com>
Signed-off-by: Robin Dong <sanbai at taobao.com>
---
 sheep/md.c      |  6 ++++++
 sheep/request.c | 15 +++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/sheep/md.c b/sheep/md.c
index 538f696..29f263f 100644
--- a/sheep/md.c
+++ b/sheep/md.c
@@ -813,6 +813,12 @@ static int do_plug_unplug(char *disks, bool plug)
 	if (old_nr == md.nr_disks)
 		goto out;
 
+	/* If all disks are gone, change to pure gateway */
+	if (md.nr_disks == 0) {
+		ret = SD_RES_EIO;
+		goto out;
+	}
+
 	ret = SD_RES_SUCCESS;
 out:
 	sd_rw_unlock(&md.lock);
diff --git a/sheep/request.c b/sheep/request.c
index dc5e5a2..7f09426 100644
--- a/sheep/request.c
+++ b/sheep/request.c
@@ -158,6 +158,21 @@ static void local_op_done(struct work *work)
 						 &req->rp, req->data);
 	}
 
+	switch (req->rp.result) {
+	case SD_RES_EIO:
+		req->rp.result = SD_RES_NETWORK_ERROR;
+
+		sd_err("leaving sheepdog cluster");
+		leave_cluster();
+		break;
+	case SD_RES_SUCCESS:
+	case SD_RES_NETWORK_ERROR:
+		break;
+	default:
+		sd_debug("unhandled error %s", sd_strerror(req->rp.result));
+		break;
+	}
+
 	put_request(req);
 }
 
-- 
1.7.12.4




More information about the sheepdog mailing list