From patchwork Thu Apr 4 08:35:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Durgin X-Patchwork-Id: 233682 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 763FB2C0079 for ; Thu, 4 Apr 2013 19:36:17 +1100 (EST) Received: from localhost ([::1]:52342 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNfeY-0005i1-I0 for incoming@patchwork.ozlabs.org; Thu, 04 Apr 2013 04:36:14 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60130) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNfe1-0005gk-A2 for qemu-devel@nongnu.org; Thu, 04 Apr 2013 04:35:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UNfdu-0005ah-Ks for qemu-devel@nongnu.org; Thu, 04 Apr 2013 04:35:41 -0400 Received: from mail.hq.newdream.net ([66.33.206.127]:46894) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNfdu-0005aJ-Db for qemu-devel@nongnu.org; Thu, 04 Apr 2013 04:35:34 -0400 Received: from mail.hq.newdream.net (localhost [127.0.0.1]) by mail.hq.newdream.net (Postfix) with ESMTP id CF41E25E16; Thu, 4 Apr 2013 01:41:01 -0700 (PDT) Received: from plana32.front.sepia.ceph.com (ip-64-90-32-34.dreamhost.com [64.90.32.34]) by mail.hq.newdream.net (Postfix) with ESMTPSA id C18AE25E14; Thu, 4 Apr 2013 01:41:01 -0700 (PDT) From: Josh Durgin To: qemu-devel@nongnu.org Date: Thu, 4 Apr 2013 01:35:14 -0700 Message-Id: <1365064515-23222-1-git-send-email-josh.durgin@inktank.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <20130402141042.GL2341@dhcp-200-207.str.redhat.com> References: <20130402141042.GL2341@dhcp-200-207.str.redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 66.33.206.127 Cc: Kevin Wolf , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v3 1/2] rbd: add an asynchronous flush X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Signed-off-by: Josh Durgin --- Since v2: * remove #ifdefs around bdrv_aio_flush and qemu_rbd_aio_flush, since they are dealt with at runtime in the next patch block/rbd.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index 1a8ea6d..037d82b 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 { @@ -379,8 +380,7 @@ static void qemu_rbd_complete_aio(RADOSCB *rcb) r = rcb->ret; - if (acb->cmd == RBD_AIO_WRITE || - acb->cmd == RBD_AIO_DISCARD) { + if (acb->cmd != RBD_AIO_READ) { if (r < 0) { acb->ret = r; acb->error = 1; @@ -659,6 +659,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 +689,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 +733,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 +775,13 @@ static BlockDriverAIOCB *qemu_rbd_aio_writev(BlockDriverState *bs, RBD_AIO_WRITE); } +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); +} + static int qemu_rbd_co_flush(BlockDriverState *bs) { #if LIBRBD_VERSION_CODE >= LIBRBD_VERSION(0, 1, 1) @@ -949,6 +969,8 @@ static BlockDriver bdrv_rbd = { .bdrv_aio_readv = qemu_rbd_aio_readv, .bdrv_aio_writev = qemu_rbd_aio_writev, + + .bdrv_aio_flush = qemu_rbd_aio_flush, .bdrv_co_flush_to_disk = qemu_rbd_co_flush, #ifdef LIBRBD_SUPPORTS_DISCARD