[sheepdog] [PATCH v4 2/4] sheep: add new operation flush() to store_driver
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Fri Sep 7 07:25:52 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>
---
v4: close the file descriptor for syncfs() even if syncfs() returns error
8<---
configure.ac | 2 +-
sheep/farm/farm.c | 1 +
sheep/plain_store.c | 31 +++++++++++++++++++++++++++++++
sheep/sheep_priv.h | 1 +
4 files changed, 34 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 89dd844..1cd0038 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -130,6 +130,8 @@ int default_write(uint64_t oid, struct siocb *iocb, int create)
}
get_obj_path(oid, path);
+ if (iocb->flags & SD_FLAG_CMD_CACHE && is_disk_cache_enabled())
+ flags &= ~O_DSYNC;
fd = open(path, flags, def_fmode);
if (fd < 0)
return err_to_sderr(oid, errno);
@@ -431,6 +433,34 @@ 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, ret = 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));
+ ret = SD_RES_EIO;
+ }
+
+ close(fd);
+
+ return ret;
+}
+
struct store_driver plain_store = {
.name = "plain",
.init = default_init,
@@ -444,6 +474,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 7f046f3..c095101 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);
--
1.7.2.5
More information about the sheepdog
mailing list