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 <[email protected]>
Cc: Liu Yuan <[email protected]>
Signed-off-by: Hitoshi Mitake <[email protected]>
---
 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 91126e2..ede61ad 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 26aa6dc..fa3cf60 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -418,6 +418,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,
@@ -431,6 +462,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 a96b3c3..26a46e4 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -157,6 +157,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);
@@ -358,6 +359,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

-- 
sheepdog mailing list
[email protected]
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to