[sheepdog] [PATCH v3 2/4] sheep: add new operation flush() to store_driver

Hitoshi Mitake h.mitake at gmail.com
Wed Sep 5 16:31:03 CEST 2012


This patch adds new operation flush() to store_driver for flushing
underlying cache of storage. flush() is required for enabling disk
cache in sheep.

This patch also adds default_flush() for farm and
plain_store. default_flush() is based on syncfs() (if it is available)
or sync().

Cc: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
Cc: Liu Yuan <tailai.ly at taobao.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 configure.ac        |    2 +-
 sheep/farm/farm.c   |    1 +
 sheep/plain_store.c |   32 ++++++++++++++++++++++++++++++++
 sheep/sheep_priv.h  |    2 ++
 4 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/configure.ac b/configure.ac
index d6ed0dd..b6326d8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -124,7 +124,7 @@ AC_FUNC_VPRINTF
 AC_CHECK_FUNCS([alarm alphasort atexit bzero dup2 endgrent endpwent fcntl \
 		getcwd getpeerucred getpeereid gettimeofday inet_ntoa memmove \
 		memset mkdir scandir select socket strcasecmp strchr strdup \
-		strerror strrchr strspn strstr])
+		strerror strrchr strspn strstr syncfs])
 
 AC_CONFIG_FILES([Makefile
 		collie/Makefile
diff --git a/sheep/farm/farm.c b/sheep/farm/farm.c
index f5b26b1..fb68c3a 100644
--- a/sheep/farm/farm.c
+++ b/sheep/farm/farm.c
@@ -331,6 +331,7 @@ struct store_driver farm = {
 	.format = default_format,
 	.purge_obj = default_purge_obj,
 	.remove_object = default_remove_object,
+	.flush = default_flush,
 };
 
 add_store_driver(farm);
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index cd1c41b..036812d 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -424,6 +424,37 @@ int default_purge_obj(void)
 	return for_each_object_in_wd(move_object_to_stale_dir, &tgt_epoch);
 }
 
+#ifndef HAVE_SYNCFS
+static int syncfs(int fd)
+{
+	sync();
+	return 0;
+}
+#endif
+
+int default_flush(void)
+{
+	int fd;
+
+	if (sys->gateway_only)
+		return SD_RES_SUCCESS;
+
+	fd = open(obj_path, O_RDONLY);
+	if (fd < 0) {
+		eprintf("error at open() %s, %s\n", obj_path, strerror(errno));
+		return SD_RES_NO_OBJ;
+	}
+
+	if (syncfs(fd)) {
+		eprintf("error at syncfs(), %s\n", strerror(errno));
+		return SD_RES_EIO;
+	}
+
+	close(fd);
+
+	return SD_RES_SUCCESS;
+}
+
 struct store_driver plain_store = {
 	.name = "plain",
 	.init = default_init,
@@ -437,6 +468,7 @@ struct store_driver plain_store = {
 	.format = default_format,
 	.remove_object = default_remove_object,
 	.purge_obj = default_purge_obj,
+	.flush = default_flush,
 };
 
 add_store_driver(plain_store);
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index acad0b9..ae9ef66 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -158,6 +158,7 @@ struct store_driver {
 	int (*cleanup)(void);
 	int (*restore)(struct siocb *);
 	int (*get_snap_file)(struct siocb *);
+	int (*flush)(void);
 };
 
 int default_init(char *p);
@@ -359,6 +360,7 @@ int peer_read_obj(struct request *req);
 int peer_write_obj(struct request *req);
 int peer_create_and_write_obj(struct request *req);
 int peer_remove_obj(struct request *req);
+int default_flush(void);
 
 /* object_cache */
 
-- 
1.7.5.1




More information about the sheepdog mailing list