From patchwork Tue Jul 26 11:49:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 106863 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6125EB70C5 for ; Tue, 26 Jul 2011 22:48:27 +1000 (EST) Received: from localhost ([::1]:43545 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qlg6f-0004Qh-I2 for incoming@patchwork.ozlabs.org; Tue, 26 Jul 2011 07:47:25 -0400 Received: from eggs.gnu.org ([140.186.70.92]:54361) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qlg5m-0001hF-Dx for qemu-devel@nongnu.org; Tue, 26 Jul 2011 07:46:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qlg5k-0004CM-6b for qemu-devel@nongnu.org; Tue, 26 Jul 2011 07:46:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38376) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qlg5j-0004C2-Kq for qemu-devel@nongnu.org; Tue, 26 Jul 2011 07:46:28 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6QBkQ2t017018 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 26 Jul 2011 07:46:26 -0400 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p6QBkCMr001996; Tue, 26 Jul 2011 07:46:25 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Tue, 26 Jul 2011 13:49:08 +0200 Message-Id: <1311680948-7648-11-git-send-email-kwolf@redhat.com> In-Reply-To: <1311680948-7648-1-git-send-email-kwolf@redhat.com> References: <1311680948-7648-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, stefanha@gmail.com Subject: [Qemu-devel] [PATCH 10/10] block: Use bdrv_co_* instead of synchronous versions in coroutines 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 If we're already in a coroutine, there is no reason to use the synchronous version of block layer functions when a coroutine one exists. This makes bdrv_read/write/flush use bdrv_co_* when used inside a coroutine. Signed-off-by: Kevin Wolf --- block.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 43 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index 39819e9..e2075d4 100644 --- a/block.c +++ b/block.c @@ -70,6 +70,7 @@ static int coroutine_fn bdrv_co_readv_em(BlockDriverState *bs, static int coroutine_fn bdrv_co_writev_em(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *iov); +static int coroutine_fn bdrv_co_flush_em(BlockDriverState *bs); static QTAILQ_HEAD(, BlockDriverState) bdrv_states = QTAILQ_HEAD_INITIALIZER(bdrv_states); @@ -950,6 +951,17 @@ int bdrv_read(BlockDriverState *bs, int64_t sector_num, { BlockDriver *drv = bs->drv; + if (qemu_in_coroutine()) { + QEMUIOVector qiov; + struct iovec iov = { + .iov_base = (void *)buf, + .iov_len = nb_sectors * BDRV_SECTOR_SIZE, + }; + + qemu_iovec_init_external(&qiov, &iov, 1); + return bdrv_co_readv(bs, sector_num, nb_sectors, &qiov); + } + if (!drv) return -ENOMEDIUM; if (bdrv_check_request(bs, sector_num, nb_sectors)) @@ -996,6 +1008,18 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num, const uint8_t *buf, int nb_sectors) { BlockDriver *drv = bs->drv; + + if (qemu_in_coroutine()) { + QEMUIOVector qiov; + struct iovec iov = { + .iov_base = (void *)buf, + .iov_len = nb_sectors * BDRV_SECTOR_SIZE, + }; + + qemu_iovec_init_external(&qiov, &iov, 1); + return bdrv_co_writev(bs, sector_num, nb_sectors, &qiov); + } + if (!bs->drv) return -ENOMEDIUM; if (bs->read_only) @@ -1661,6 +1685,10 @@ int bdrv_flush(BlockDriverState *bs) return 0; } + if (qemu_in_coroutine()) { + return bdrv_co_flush_em(bs); + } + if (bs->drv && bs->drv->bdrv_flush) { return bs->drv->bdrv_flush(bs); } @@ -2929,6 +2957,21 @@ static int coroutine_fn bdrv_co_writev_em(BlockDriverState *bs, return bdrv_co_io_em(bs, sector_num, nb_sectors, iov, true); } +static int coroutine_fn bdrv_co_flush_em(BlockDriverState *bs) +{ + CoroutineIOCompletion co = { + .coroutine = qemu_coroutine_self(), + }; + BlockDriverAIOCB *acb; + + acb = bdrv_aio_flush(bs, bdrv_co_io_em_complete, &co); + if (!acb) { + return -EIO; + } + qemu_coroutine_yield(); + return co.ret; +} + /**************************************************************/ /* removable device support */