[sheepdog] [PATCH 2/2] sheep: add cache option 'unsafe' to disable sync

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Mon Oct 22 05:14:01 CEST 2012


This option is useful when a datacenter can provide a reliable power
and we are unlikely to lose in-memory data.  We can also use this
option for testing purpose.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/plain_store.c |    8 +++++---
 sheep/sheep.c       |    7 +++++++
 sheep/sheep_priv.h  |    6 ++++++
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index 3d52a52..d9703af 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -142,7 +142,8 @@ int default_write(uint64_t oid, const struct siocb *iocb)
 
 	if (iocb->flags & SD_FLAG_CMD_CACHE && is_disk_cache_enabled())
 		flags &= ~O_DSYNC;
-	if (iocb->flags & SD_FLAG_CMD_CACHE && is_page_cache_enabled())
+	if (iocb->flags & SD_FLAG_CMD_CACHE &&
+	    (is_page_cache_enabled() || is_unsafe_cache_enabled()))
 		flags &= ~(O_DSYNC | O_DIRECT);
 
 	fd = open(path, flags, def_fmode);
@@ -240,7 +241,7 @@ static int default_read_from_path(uint64_t oid, const char *path,
 	int flags = get_open_flags(oid, false), fd, ret = SD_RES_SUCCESS;
 	ssize_t size;
 
-	if (is_page_cache_enabled())
+	if (is_page_cache_enabled() || is_unsafe_cache_enabled())
 		flags &= ~O_DIRECT;
 
 	fd = open(path, flags);
@@ -311,7 +312,8 @@ int default_create_and_write(uint64_t oid, const struct siocb *iocb)
 
 	if (iocb->flags & SD_FLAG_CMD_CACHE && is_disk_cache_enabled())
 		flags &= ~O_DSYNC;
-	if (iocb->flags & SD_FLAG_CMD_CACHE && is_page_cache_enabled())
+	if (iocb->flags & SD_FLAG_CMD_CACHE &&
+	    (is_page_cache_enabled() || is_unsafe_cache_enabled()))
 		flags &= ~(O_DSYNC | O_DIRECT);
 
 	fd = open(tmp_path, flags, def_fmode);
diff --git a/sheep/sheep.c b/sheep/sheep.c
index bac4829..e23c57a 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -278,6 +278,12 @@ static void page_cache_set(char *s)
 	sys->enabled_cache_type |= CACHE_TYPE_PAGE;
 }
 
+static void unsafe_cache_set(char *s)
+{
+	assert(!strcmp(s, "unsafe"));
+	sys->enabled_cache_type |= CACHE_TYPE_UNSAFE;
+}
+
 static void do_cache_type(char *s)
 {
 	int i;
@@ -290,6 +296,7 @@ static void do_cache_type(char *s)
 		{ "object", object_cache_set },
 		{ "disk", disk_cache_set },
 		{ "page", page_cache_set },
+		{ "unsafe", unsafe_cache_set },
 		{ NULL, NULL },
 	};
 
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index af9ff43..4058263 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -118,6 +118,7 @@ struct cluster_info {
 #define CACHE_TYPE_OBJECT 0x1
 #define CACHE_TYPE_DISK   0x2
 #define CACHE_TYPE_PAGE   0x4
+#define CACHE_TYPE_UNSAFE 0x8
 	int enabled_cache_type;
 
 	uint32_t object_cache_size;
@@ -423,4 +424,9 @@ static inline bool is_page_cache_enabled(void)
 	return !!(sys->enabled_cache_type & CACHE_TYPE_PAGE);
 }
 
+static inline bool is_unsafe_cache_enabled(void)
+{
+	return !!(sys->enabled_cache_type & CACHE_TYPE_UNSAFE);
+}
+
 #endif
-- 
1.7.2.5




More information about the sheepdog mailing list