From: Robin Dong <san...@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 <isolate...@gmail.com>
Signed-off-by: Robin Dong <san...@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

-- 
sheepdog mailing list
sheepdog@lists.wpkg.org
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to