[sheepdog] [PATCH 1/2] sheep: add cache option 'page' to use page cache on storage nodes
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Mon Oct 22 05:14:00 CEST 2012
This option is useful when VMs are running on different cluster from
sheeps and we can use a lot of memory on sheep nodes for a Sheepdog
VDI cache.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
sheep/ops.c | 2 +-
sheep/plain_store.c | 9 +++++++++
sheep/sheep.c | 7 +++++++
sheep/sheep_priv.h | 6 ++++++
4 files changed, 23 insertions(+), 1 deletions(-)
diff --git a/sheep/ops.c b/sheep/ops.c
index 5e6df0e..63168e7 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -665,7 +665,7 @@ static int local_flush_vdi(struct request *req)
return ret;
}
- if (is_disk_cache_enabled()) {
+ if (is_disk_cache_enabled() || is_page_cache_enabled()) {
struct sd_req hdr;
sd_init_req(&hdr, SD_OP_FLUSH_NODES);
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index 9ff2fc3..3d52a52 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -139,8 +139,12 @@ int default_write(uint64_t oid, const struct siocb *iocb)
}
get_obj_path(oid, path);
+
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())
+ flags &= ~(O_DSYNC | O_DIRECT);
+
fd = open(path, flags, def_fmode);
if (fd < 0)
return err_to_sderr(oid, errno);
@@ -236,6 +240,9 @@ 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())
+ flags &= ~O_DIRECT;
+
fd = open(path, flags);
if (fd < 0)
@@ -304,6 +311,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())
+ flags &= ~(O_DSYNC | O_DIRECT);
fd = open(tmp_path, flags, def_fmode);
if (fd < 0) {
diff --git a/sheep/sheep.c b/sheep/sheep.c
index 3ec2c4d..bac4829 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -272,6 +272,12 @@ static void disk_cache_set(char *s)
sys->enabled_cache_type |= CACHE_TYPE_DISK;
}
+static void page_cache_set(char *s)
+{
+ assert(!strcmp(s, "page"));
+ sys->enabled_cache_type |= CACHE_TYPE_PAGE;
+}
+
static void do_cache_type(char *s)
{
int i;
@@ -283,6 +289,7 @@ static void do_cache_type(char *s)
struct cache_type cache_types[] = {
{ "object", object_cache_set },
{ "disk", disk_cache_set },
+ { "page", page_cache_set },
{ NULL, NULL },
};
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 0480e26..af9ff43 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -117,6 +117,7 @@ struct cluster_info {
#define CACHE_TYPE_OBJECT 0x1
#define CACHE_TYPE_DISK 0x2
+#define CACHE_TYPE_PAGE 0x4
int enabled_cache_type;
uint32_t object_cache_size;
@@ -417,4 +418,9 @@ static inline bool is_disk_cache_enabled(void)
return !!(sys->enabled_cache_type & CACHE_TYPE_DISK);
}
+static inline bool is_page_cache_enabled(void)
+{
+ return !!(sys->enabled_cache_type & CACHE_TYPE_PAGE);
+}
+
#endif
--
1.7.2.5
More information about the sheepdog
mailing list