[sheepdog] [PATCH stable-0.8] sheep: remove last slash for new->path in md_add_disk()

Hitoshi Mitake mitake.hitoshi at gmail.com
Tue Jul 29 03:27:18 CEST 2014

From: Meng An <isolate000 at gmail.com>

Follow these steps:

  1. sheep /meta/,/data1/,/data2/...... (add slash before data path)
  2. upload data
  3. remove /data1/*
  4. get data

then the sheep daemon will go to dead loops and print logs like:

  ERROR [io 1234] err_to_sderr(96) /data1/ corrupted
  ERROR [io 1234] err_to_sderr(96) /disk5/ corrupted

The reason is when the sheep daemon start, it use "/data1/" as disk->path, but
when it occur a error-io, sheep will call md_remove_disk() with argument disk which
contain path of "/data1" (without slash), so sheep can not actually unplug "/data1/"
in md ring and it will try to forward request forever.

We can fix this by remove last slash when sheep call md_add_disk().

Signed-off-by: Robin Dong <sanbai at taobao.com>
Signed-off-by: Meng An <isolate000 at gmail.com>
Signed-off-by: Liu Yuan <namei.unix at gmail.com>
 sheep/md.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sheep/md.c b/sheep/md.c
index 6da5828..09ddd4b 100644
--- a/sheep/md.c
+++ b/sheep/md.c
@@ -318,6 +318,7 @@ bool md_add_disk(const char *path, bool purge)
 	new = xmalloc(sizeof(*new));
 	pstrcpy(new->path, PATH_MAX, path);
+	trim_last_slash(new->path);
 	new->space = init_path_space(new->path, purge);
 	if (!new->space) {

More information about the sheepdog mailing list