qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com,
	mreitz@redhat.com
Subject: [Qemu-devel] [PATCH 3/8] block: Use blk_co_pwritev() for blk_write()
Date: Tue,  8 Mar 2016 13:47:48 +0100	[thread overview]
Message-ID: <1457441273-29821-4-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1457441273-29821-1-git-send-email-kwolf@redhat.com>

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/block-backend.c     | 39 ++++++++++++++++++++++++++++++---------
 block/io.c                |  5 +----
 include/block/block_int.h |  3 +++
 3 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index d97d1ac..e159647 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -711,6 +711,18 @@ static int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset,
     return bdrv_co_do_preadv(blk_bs(blk), offset, bytes, qiov, flags);
 }
 
+static int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset,
+                                      unsigned int bytes, QEMUIOVector *qiov,
+                                      BdrvRequestFlags flags)
+{
+    int ret = blk_check_byte_request(blk, offset, bytes);
+    if (ret < 0) {
+        return ret;
+    }
+
+    return bdrv_co_do_pwritev(blk_bs(blk), offset, bytes, qiov, flags);
+}
+
 typedef struct BlkRwCo {
     BlockBackend *blk;
     int64_t offset;
@@ -727,8 +739,16 @@ static void blk_read_entry(void *opaque)
                               rwco->qiov, rwco->flags);
 }
 
-int blk_read(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
-             int nb_sectors)
+static void blk_write_entry(void *opaque)
+{
+    BlkRwCo *rwco = opaque;
+
+    rwco->ret = blk_co_pwritev(rwco->blk, rwco->offset, rwco->qiov->size,
+                               rwco->qiov, rwco->flags);
+}
+
+static int blk_rw(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
+                  int nb_sectors, CoroutineEntry co_entry)
 {
     AioContext *aio_context;
     QEMUIOVector qiov;
@@ -753,7 +773,7 @@ int blk_read(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
         .ret    = NOT_DONE,
     };
 
-    co = qemu_coroutine_create(blk_read_entry);
+    co = qemu_coroutine_create(co_entry);
     qemu_coroutine_enter(co, &rwco);
 
     aio_context = blk_get_aio_context(blk);
@@ -764,6 +784,12 @@ int blk_read(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
     return rwco.ret;
 }
 
+int blk_read(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
+             int nb_sectors)
+{
+    return blk_rw(blk, sector_num, buf, nb_sectors, blk_read_entry);
+}
+
 int blk_read_unthrottled(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
                          int nb_sectors)
 {
@@ -778,12 +804,7 @@ int blk_read_unthrottled(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
 int blk_write(BlockBackend *blk, int64_t sector_num, const uint8_t *buf,
               int nb_sectors)
 {
-    int ret = blk_check_request(blk, sector_num, nb_sectors);
-    if (ret < 0) {
-        return ret;
-    }
-
-    return bdrv_write(blk_bs(blk), sector_num, buf, nb_sectors);
+    return blk_rw(blk, sector_num, (uint8_t*) buf, nb_sectors, blk_write_entry);
 }
 
 int blk_write_zeroes(BlockBackend *blk, int64_t sector_num,
diff --git a/block/io.c b/block/io.c
index c7084e4..aa8537c 100644
--- a/block/io.c
+++ b/block/io.c
@@ -44,9 +44,6 @@ 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_do_pwritev(BlockDriverState *bs,
-    int64_t offset, unsigned int bytes, QEMUIOVector *qiov,
-    BdrvRequestFlags flags);
 static BlockAIOCB *bdrv_co_aio_rw_vector(BlockDriverState *bs,
                                          int64_t sector_num,
                                          QEMUIOVector *qiov,
@@ -1281,7 +1278,7 @@ fail:
 /*
  * Handle a write request in coroutine context
  */
-static int coroutine_fn bdrv_co_do_pwritev(BlockDriverState *bs,
+int coroutine_fn bdrv_co_do_pwritev(BlockDriverState *bs,
     int64_t offset, unsigned int bytes, QEMUIOVector *qiov,
     BdrvRequestFlags flags)
 {
diff --git a/include/block/block_int.h b/include/block/block_int.h
index db830f6..35ba42f 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -511,6 +511,9 @@ void bdrv_setup_io_funcs(BlockDriver *bdrv);
 int coroutine_fn bdrv_co_do_preadv(BlockDriverState *bs,
     int64_t offset, unsigned int bytes, QEMUIOVector *qiov,
     BdrvRequestFlags flags);
+int coroutine_fn bdrv_co_do_pwritev(BlockDriverState *bs,
+    int64_t offset, unsigned int bytes, QEMUIOVector *qiov,
+    BdrvRequestFlags flags);
 
 int get_tmp_filename(char *filename, int size);
 BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size,
-- 
1.8.3.1

  parent reply	other threads:[~2016-03-08 12:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-08 12:47 [Qemu-devel] [PATCH 0/8] block: Introduce common read/write function Kevin Wolf
2016-03-08 12:47 ` [Qemu-devel] [PATCH 1/8] block: Use BdrvChild in BlockBackend Kevin Wolf
2016-03-08 12:47 ` [Qemu-devel] [PATCH 2/8] block: Use blk_co_preadv() for blk_read() Kevin Wolf
2016-03-08 12:47 ` Kevin Wolf [this message]
2016-03-08 12:47 ` [Qemu-devel] [PATCH 4/8] block: Pull up blk_read_unthrottled() implementation Kevin Wolf
2016-03-08 12:47 ` [Qemu-devel] [PATCH 5/8] block: Use blk_co_pwritev() in blk_write_zeroes() Kevin Wolf
2016-03-08 12:47 ` [Qemu-devel] [PATCH 6/8] block: Use blk_prw() in blk_pread()/blk_pwrite() Kevin Wolf
2016-03-08 12:47 ` [Qemu-devel] [PATCH 7/8] block: Use blk_aio_prwv() for aio_read/write/write_zeroes Kevin Wolf
2016-03-08 12:47 ` [Qemu-devel] [PATCH 8/8] block: Use blk_co_pwritev() in blk_co_write_zeroes() Kevin Wolf
2016-03-17 14:08 ` [Qemu-devel] [PATCH 0/8] block: Introduce common read/write function Kevin Wolf
2016-03-17 14:35 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi

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=1457441273-29821-4-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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).