From b11f38fcdf837c6ba1d4287b1c685eb3ae5351a8 Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Thu, 17 May 2012 13:42:29 -0700 Subject: rbd: hook up cache options Writeback caching was added in Ceph 0.46, and writethrough will be in 0.47. These are controlled by general config options, so there's no need to check for librbd version. Signed-off-by: Josh Durgin Signed-off-by: Kevin Wolf --- block/rbd.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/block/rbd.c b/block/rbd.c index 1280d66d3c..eebc334462 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -476,6 +476,25 @@ static int qemu_rbd_open(BlockDriverState *bs, const char *filename, int flags) s->snap = g_strdup(snap_buf); } + /* + * Fallback to more conservative semantics if setting cache + * options fails. Ignore errors from setting rbd_cache because the + * only possible error is that the option does not exist, and + * librbd defaults to no caching. If write through caching cannot + * be set up, fall back to no caching. + */ + if (flags & BDRV_O_NOCACHE) { + rados_conf_set(s->cluster, "rbd_cache", "false"); + } else { + rados_conf_set(s->cluster, "rbd_cache", "true"); + if (!(flags & BDRV_O_CACHE_WB)) { + r = rados_conf_set(s->cluster, "rbd_cache_max_dirty", "0"); + if (r < 0) { + rados_conf_set(s->cluster, "rbd_cache", "false"); + } + } + } + if (strstr(conf, "conf=") == NULL) { /* try default location, but ignore failure */ rados_conf_read_file(s->cluster, NULL); -- cgit v1.2.3