qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, stefanha@gmail.com
Subject: [Qemu-devel] [PATCH 10/10] block: Use bdrv_co_* instead of synchronous versions in coroutines
Date: Tue, 26 Jul 2011 13:49:08 +0200	[thread overview]
Message-ID: <1311680948-7648-11-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1311680948-7648-1-git-send-email-kwolf@redhat.com>

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 <kwolf@redhat.com>
---
 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 */
 
-- 
1.7.6

  parent reply	other threads:[~2011-07-26 11:46 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-26 11:48 [Qemu-devel] [PATCH 00/10] block: Coroutine support Kevin Wolf
2011-07-26 11:48 ` [Qemu-devel] [PATCH 01/10] block: Add bdrv_co_readv/writev Kevin Wolf
2011-07-26 11:49 ` [Qemu-devel] [PATCH 02/10] block: Emulate AIO functions with bdrv_co_readv/writev Kevin Wolf
2011-07-26 11:49 ` [Qemu-devel] [PATCH 03/10] block: Add bdrv_co_readv/writev emulation Kevin Wolf
2011-08-02 12:12   ` Kevin Wolf
2011-07-26 11:49 ` [Qemu-devel] [PATCH 04/10] coroutines: Locks Kevin Wolf
2011-07-26 11:49 ` [Qemu-devel] [PATCH 05/10] qcow2: Use coroutines Kevin Wolf
2011-07-29 13:20   ` Stefan Hajnoczi
2011-07-26 11:49 ` [Qemu-devel] [PATCH 06/10] qcow: " Kevin Wolf
2011-07-26 11:49 ` [Qemu-devel] [PATCH 07/10] async: Remove AsyncContext Kevin Wolf
2011-07-26 11:49 ` [Qemu-devel] [PATCH 08/10] coroutines: Use one global bottom half for CoQueue Kevin Wolf
2011-07-26 11:49 ` [Qemu-devel] [PATCH 09/10] posix-aio-compat: Allow read after EOF Kevin Wolf
2011-07-26 13:55   ` Frediano Ziglio
2011-07-26 14:22     ` Kevin Wolf
2011-07-26 11:49 ` Kevin Wolf [this message]
2011-08-02 13:56   ` [Qemu-devel] [PATCH v2 10/10] block: Use bdrv_co_* instead of synchronous versions in coroutines Kevin Wolf
2011-08-01  9:59 ` [Qemu-devel] [PATCH 00/10] block: Coroutine support Stefan Hajnoczi
2011-08-02 14:23 ` Avi Kivity
2011-08-02 14:50   ` Kevin Wolf
2011-08-02 14:55     ` Frediano Ziglio
2011-08-02 15:14       ` Kevin Wolf
2011-08-02 14:58     ` Anthony Liguori
2011-08-02 14:59     ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1311680948-7648-11-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).