[sheepdog] [PATCH] object cache: enable external cache location

Liu Yuan namei.unix at gmail.com
Tue Jan 8 11:08:34 CET 2013


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

Then we can specify external cache local as:
 $ sheep /store -w object:dir=/path/to/cache

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/object_cache.c |    9 ++++++++-
 sheep/sheep.c        |   27 ++++++++++++++++++++++++---
 sheep/sheep_priv.h   |    2 +-
 sheep/store.c        |   21 +--------------------
 4 files changed, 34 insertions(+), 25 deletions(-)

diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 4cf9764..8e637da 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -1224,10 +1224,17 @@ int object_cache_init(const char *p)
 	struct strbuf buf = STRBUF_INIT;
 
 	strbuf_addstr(&buf, p);
+	if (mkdir(buf.buf, def_dmode) < 0) {
+		if (errno != EEXIST) {
+			eprintf("%s %m\n", buf.buf);
+			ret = -1;
+			goto err;
+		}
+	}
 	strbuf_addstr(&buf, "/cache");
 	if (mkdir(buf.buf, def_dmode) < 0) {
 		if (errno != EEXIST) {
-			eprintf("%m\n");
+			eprintf("%s %m\n", buf.buf);
 			ret = -1;
 			goto err;
 		}
diff --git a/sheep/sheep.c b/sheep/sheep.c
index 7f4bf26..9f3965d 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -215,6 +215,15 @@ static void object_cache_directio_set(char *s)
 	sys->object_cache_directio = true;
 }
 
+static char ocpath[PATH_MAX];
+static void object_cache_dir_set(char *s)
+{
+	char *p = s;
+
+	p = p + strlen("dir=");
+	sprintf(ocpath, "%s", p);
+}
+
 static void _object_cache_set(char *s)
 {
 	int i;
@@ -228,6 +237,7 @@ static void _object_cache_set(char *s)
 	struct object_cache_arg object_cache_args[] = {
 		{ "size=", object_cache_size_set },
 		{ "directio", object_cache_directio_set },
+		{ "dir=", object_cache_dir_set },
 		{ NULL, NULL },
 	};
 
@@ -593,9 +603,20 @@ int main(int argc, char **argv)
 	if (ret)
 		exit(1);
 
-	ret = init_store(dir);
-	if (ret)
-		exit(1);
+	if (!sys->gateway_only) {
+		ret = init_store_driver();
+		if (ret)
+			exit(1);
+	}
+
+	if (is_object_cache_enabled()) {
+		if (!strlen(ocpath))
+			/* use object cache internally */
+			memcpy(ocpath, dir, strlen(dir));
+		ret = object_cache_init(ocpath);
+		if (ret)
+			exit(1);
+	}
 
 	ret = trace_init();
 	if (ret)
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 1cfbab7..6653c68 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -220,7 +220,7 @@ static inline uint32_t sys_epoch(void)
 int create_listen_port(char *bindaddr, int port);
 int init_unix_domain_socket(const char *dir);
 
-int init_store(const char *dir);
+int init_store_driver(void);
 int init_global_pathnames(const char *d);
 int init_base_path(const char *dir);
 int init_obj_path(const char *d);
diff --git a/sheep/store.c b/sheep/store.c
index e321e1d..6a1e010 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -301,7 +301,7 @@ static int init_jrnl_path(const char *base_path)
 	return 0;
 }
 
-static int init_store_driver(void)
+int init_store_driver(void)
 {
 	char driver_name[STORE_LEN], *p;
 	int ret;
@@ -395,25 +395,6 @@ int init_global_pathnames(const char *d)
 	return 0;
 }
 
-int init_store(const char *d)
-{
-	int ret;
-
-	if (!sys->gateway_only) {
-		ret = init_store_driver();
-		if (ret)
-			return ret;
-	}
-
-	if (is_object_cache_enabled()) {
-		ret = object_cache_init(d);
-		if (ret)
-			return 1;
-	}
-
-	return ret;
-}
-
 /*
  * Write data to both local object cache (if enabled) and backends
  */
-- 
1.7.9.5




More information about the sheepdog mailing list