qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] rbd: add an asynchronous flush
@ 2013-03-29  7:59 Josh Durgin
  2013-03-29 20:03 ` [Qemu-devel] [PATCH v2] " Josh Durgin
  0 siblings, 1 reply; 24+ messages in thread
From: Josh Durgin @ 2013-03-29  7:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi

The existing bdrv_co_flush_to_disk implementation uses rbd_flush(),
which is sychronous and causes the main qemu thread to block until it
is complete. This results in unresponsiveness and extra latency for
the guest.

Fix this by using an asynchronous version of flush.  This was added to
librbd with a special #define to indicate its presence, since it will
be backported to stable versions. Thus, there is no need to check the
version of librbd.

Implement this as bdrv_aio_flush, since it matches other aio functions
in the rbd block driver, and leave out bdrv_co_flush_to_disk when the
asynchronous version is available.

Reported-by: Oliver Francke <oliver@filoo.de>
Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
---
 block/rbd.c |   34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/block/rbd.c b/block/rbd.c
index 1a8ea6d..568b279 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -63,7 +63,8 @@
 typedef enum {
     RBD_AIO_READ,
     RBD_AIO_WRITE,
-    RBD_AIO_DISCARD
+    RBD_AIO_DISCARD,
+    RBD_AIO_FLUSH
 } RBDAIOCmd;
 
 typedef struct RBDAIOCB {
@@ -659,6 +660,16 @@ static int rbd_aio_discard_wrapper(rbd_image_t image,
 #endif
 }
 
+static int rbd_aio_flush_wrapper(rbd_image_t image,
+                                 rbd_completion_t comp)
+{
+#ifdef LIBRBD_SUPPORTS_AIO_FLUSH
+    return rbd_aio_flush(image, comp);
+#else
+    return -ENOTSUP;
+#endif
+}
+
 static BlockDriverAIOCB *rbd_start_aio(BlockDriverState *bs,
                                        int64_t sector_num,
                                        QEMUIOVector *qiov,
@@ -679,7 +690,7 @@ static BlockDriverAIOCB *rbd_start_aio(BlockDriverState *bs,
     acb = qemu_aio_get(&rbd_aiocb_info, bs, cb, opaque);
     acb->cmd = cmd;
     acb->qiov = qiov;
-    if (cmd == RBD_AIO_DISCARD) {
+    if (cmd == RBD_AIO_DISCARD || cmd == RBD_AIO_FLUSH) {
         acb->bounce = NULL;
     } else {
         acb->bounce = qemu_blockalign(bs, qiov->size);
@@ -723,6 +734,9 @@ static BlockDriverAIOCB *rbd_start_aio(BlockDriverState *bs,
     case RBD_AIO_DISCARD:
         r = rbd_aio_discard_wrapper(s->image, off, size, c);
         break;
+    case RBD_AIO_FLUSH:
+        r = rbd_aio_flush_wrapper(s->image, c);
+        break;
     default:
         r = -EINVAL;
     }
@@ -762,6 +776,16 @@ static BlockDriverAIOCB *qemu_rbd_aio_writev(BlockDriverState *bs,
                          RBD_AIO_WRITE);
 }
 
+#ifdef LIBRBD_SUPPORTS_AIO_FLUSH
+static BlockDriverAIOCB *qemu_rbd_aio_flush(BlockDriverState *bs,
+                                            BlockDriverCompletionFunc *cb,
+                                            void *opaque)
+{
+    return rbd_start_aio(bs, 0, NULL, 0, cb, opaque, RBD_AIO_FLUSH);
+}
+
+#else
+
 static int qemu_rbd_co_flush(BlockDriverState *bs)
 {
 #if LIBRBD_VERSION_CODE >= LIBRBD_VERSION(0, 1, 1)
@@ -772,6 +796,7 @@ static int qemu_rbd_co_flush(BlockDriverState *bs)
     return 0;
 #endif
 }
+#endif
 
 static int qemu_rbd_getinfo(BlockDriverState *bs, BlockDriverInfo *bdi)
 {
@@ -949,7 +974,12 @@ static BlockDriver bdrv_rbd = {
 
     .bdrv_aio_readv         = qemu_rbd_aio_readv,
     .bdrv_aio_writev        = qemu_rbd_aio_writev,
+
+#ifdef LIBRBD_SUPPORTS_AIO_FLUSH
+    .bdrv_aio_flush         = qemu_rbd_aio_flush,
+#else
     .bdrv_co_flush_to_disk  = qemu_rbd_co_flush,
+#endif
 
 #ifdef LIBRBD_SUPPORTS_DISCARD
     .bdrv_aio_discard       = qemu_rbd_aio_discard,
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2013-06-21 19:14 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-29  7:59 [Qemu-devel] [PATCH] rbd: add an asynchronous flush Josh Durgin
2013-03-29 20:03 ` [Qemu-devel] [PATCH v2] " Josh Durgin
2013-04-02 14:10   ` Kevin Wolf
2013-04-04  8:35     ` [Qemu-devel] [PATCH v3 1/2] " Josh Durgin
2013-04-04  8:35     ` [Qemu-devel] [PATCH 2/2] rbd: disable unsupported librbd functions at runtime Josh Durgin
2013-04-04 10:10       ` Kevin Wolf
2013-04-04 16:50         ` Josh Durgin
2013-04-05  9:31           ` Kevin Wolf
2013-04-10  0:05             ` [Qemu-devel] [PATCH v3 2/2] rbd: link and load librbd dynamically Josh Durgin
2013-04-10  8:09               ` Stefan Hajnoczi
2013-04-10 14:52                 ` [Qemu-devel] runtime Block driver modules (was Re: [PATCH v3 2/2] rbd: link and load librbd dynamically) Josh Durgin
2013-04-10 15:08                 ` [Qemu-devel] [PATCH v3 2/2] rbd: link and load librbd dynamically Anthony Liguori
2013-04-10 21:19                   ` Paolo Bonzini
2013-04-11  8:04                     ` Stefan Hajnoczi
2013-04-11  7:59                   ` Stefan Hajnoczi
2013-06-21 18:42                   ` Sage Weil
2013-06-21 19:08                     ` Alex Bligh
2013-06-21 19:13                     ` Anthony Liguori
2013-04-10 14:03     ` [Qemu-devel] [PATCH v2] rbd: add an asynchronous flush Josh Durgin
2013-04-11  8:02       ` Stefan Hajnoczi
2013-04-11  8:48         ` Kevin Wolf
2013-04-11 17:19           ` Josh Durgin
2013-04-12  6:50             ` Kevin Wolf
2013-04-12  7:42               ` Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).