diff mbox

[PATCH-Block] rbd:disable we if rbd cache is off

Message ID 2BCF477A-579C-45A0-8A11-8B5AC3D2B7B2@chinac.com (mailing list archive)
State New, archived
Headers show

Commit Message

张欢 June 20, 2016, 10:43 a.m. UTC
rbd: disable wce if rbd cache is off
    
    wce will be enabled when cachemode is 'none',
    disable wce will NOT impact data consistency but will
    extremely improve the guest os db workload (write/fsync)
    performance since fsync will wait all in-flight io to
    complete introduced by 'rbd asynchronous flush' commit.
    
    Signed-off-by: Huan Zhang <zhanghuan@chinac.com>
diff mbox

Patch

diff --git a/block/block-backend.c b/block/block-backend.c
index 34500e6..ce1aff4 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -76,7 +76,7 @@  static const AIOCBInfo block_backend_aiocb_info = {
 };
 
 static void drive_info_del(DriveInfo *dinfo);
-static BlockBackend *bdrv_first_blk(BlockDriverState *bs);
+BlockBackend *bdrv_first_blk(BlockDriverState *bs);
 
 /* All BlockBackends */
 static QTAILQ_HEAD(, BlockBackend) block_backends =
@@ -389,7 +389,7 @@  BlockDriverState *blk_bs(BlockBackend *blk)
     return blk->root ? blk->root->bs : NULL;
 }
 
-static BlockBackend *bdrv_first_blk(BlockDriverState *bs)
+BlockBackend *bdrv_first_blk(BlockDriverState *bs)
 {
     BdrvChild *child;
     QLIST_FOREACH(child, &bs->parents, next_parent) {
diff --git a/block/rbd.c b/block/rbd.c
index 5226b6f..514cd98 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -20,6 +20,7 @@ 
 #include "qemu/cutils.h"
 
 #include <rbd/librbd.h>
+#include "sysemu/block-backend.h"
 
 /*
  * When specifying the image filename use:
@@ -547,7 +548,16 @@  static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
      * be set up, fall back to no caching.
      */
     if (flags & BDRV_O_NOCACHE) {
+        /*
+         * Disable Guest WCE if rbd cache is off.
+         * disable wce will NOT impact data consistency bu will
+         * extremely improve the db workload(write/fsync) performance.
+         */
         rados_conf_set(s->cluster, "rbd_cache", "false");
+        if (bdrv_has_blk(bs)) {
+            blk_set_enable_write_cache(bdrv_first_blk(bs), false);
+        }
+
     } else {
         rados_conf_set(s->cluster, "rbd_cache", "true");
     }
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index c04af8e..9f9a34d 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -93,6 +93,7 @@  void monitor_remove_blk(BlockBackend *blk);
 
 BlockBackendPublic *blk_get_public(BlockBackend *blk);
 BlockBackend *blk_by_public(BlockBackendPublic *public);
+BlockBackend *bdrv_first_blk(BlockDriverState *bs);
 
 BlockDriverState *blk_bs(BlockBackend *blk);
 void blk_remove_bs(BlockBackend *blk);