[sheepdog] [PATCH] md: trim last slashes from paths

Liu Yuan namei.unix at gmail.com
Wed Apr 17 14:05:00 CEST 2013


From: Liu Yuan <tailai.ly at taobao.com>

Currently, same path with different trailing slashes will be treated as
different paths such as following example

$ collie node md plug /store
$ collie node md plug /store/

Both will plug succeed (so as to unplug). This is obviously wrong.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/farm/farm.c |    2 +-
 sheep/md.c        |    7 +++++++
 sheep/store.c     |    2 +-
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/sheep/farm/farm.c b/sheep/farm/farm.c
index 952a70b..2e85ed6 100644
--- a/sheep/farm/farm.c
+++ b/sheep/farm/farm.c
@@ -31,7 +31,7 @@ static int create_directory(const char *p)
 	struct strbuf buf = STRBUF_INIT;
 
 	strbuf_addstr(&buf, p);
-	strbuf_addstr(&buf, ".farm");
+	strbuf_addstr(&buf, "/.farm");
 	if (xmkdir(buf.buf, 0755) < 0) {
 		sd_eprintf("%m");
 		ret = -1;
diff --git a/sheep/md.c b/sheep/md.c
index f60b58b..e3ea454 100644
--- a/sheep/md.c
+++ b/sheep/md.c
@@ -126,10 +126,17 @@ static inline struct vdisk *oid_to_vdisk(uint64_t oid)
 	return oid_to_vdisk_from(md_vds, md_nr_vds, oid);
 }
 
+static inline void trim_last_slash(char *path)
+{
+	while (path[strlen(path) - 1] == '/')
+		path[strlen(path) - 1] = '\0';
+}
+
 static int path_to_disk_idx(char *path)
 {
 	int i;
 
+	trim_last_slash(path);
 	for (i = 0; i < md_nr_disks; i++)
 		if (strcmp(md_disks[i].path, path) == 0)
 			return i;
diff --git a/sheep/store.c b/sheep/store.c
index a961f9f..cbc6f1c 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -263,7 +263,7 @@ int init_base_path(const char *d)
 	return lock_base_dir(d);
 }
 
-#define OBJ_PATH "/obj/"
+#define OBJ_PATH "/obj"
 
 /*
  * farm needs extra HEX_LEN + 3 chars to store snapshot objects.
-- 
1.7.9.5




More information about the sheepdog mailing list