All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 37/43] block: Convert bdrv_write() to BdrvChild
Date: Tue,  5 Jul 2016 17:50:46 +0200	[thread overview]
Message-ID: <1467733852-27097-38-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1467733852-27097-1-git-send-email-kwolf@redhat.com>

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 block/io.c             |  5 +++--
 block/qcow.c           | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 block/qcow2-cluster.c  |  2 +-
 block/qcow2-refcount.c |  2 +-
 block/qcow2.c          | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
 block/vdi.c            |  4 ++--
 block/vvfat.c          |  5 ++---
 include/block/block.h  |  2 +-
 8 files changed, 100 insertions(+), 12 deletions(-)

diff --git a/block/io.c b/block/io.c
index 6dfc0eb..2e04a80 100644
--- a/block/io.c
+++ b/block/io.c
@@ -642,10 +642,11 @@ int bdrv_read(BdrvChild *child, int64_t sector_num,
   -EINVAL      Invalid sector number or nb_sectors
   -EACCES      Trying to write a read-only device
 */
-int bdrv_write(BlockDriverState *bs, int64_t sector_num,
+int bdrv_write(BdrvChild *child, int64_t sector_num,
                const uint8_t *buf, int nb_sectors)
 {
-    return bdrv_rw_co(bs, sector_num, (uint8_t *)buf, nb_sectors, true, 0);
+    return bdrv_rw_co(child->bs, sector_num, (uint8_t *)buf, nb_sectors,
+                      true, 0);
 }
 
 int bdrv_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
diff --git a/block/qcow.c b/block/qcow.c
index 0db43f8..674595e 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -913,6 +913,49 @@ static int qcow_make_empty(BlockDriverState *bs)
     return 0;
 }
 
+typedef struct QcowWriteCo {
+    BlockDriverState *bs;
+    int64_t sector_num;
+    const uint8_t *buf;
+    int nb_sectors;
+    int ret;
+} QcowWriteCo;
+
+static void qcow_write_co_entry(void *opaque)
+{
+    QcowWriteCo *co = opaque;
+    QEMUIOVector qiov;
+
+    struct iovec iov = (struct iovec) {
+        .iov_base   = (uint8_t*) co->buf,
+        .iov_len    = co->nb_sectors * BDRV_SECTOR_SIZE,
+    };
+    qemu_iovec_init_external(&qiov, &iov, 1);
+
+    co->ret = qcow_co_writev(co->bs, co->sector_num, co->nb_sectors, &qiov);
+}
+
+/* Wrapper for non-coroutine contexts */
+static int qcow_write(BlockDriverState *bs, int64_t sector_num,
+                      const uint8_t *buf, int nb_sectors)
+{
+    Coroutine *co;
+    AioContext *aio_context = bdrv_get_aio_context(bs);
+    QcowWriteCo data = {
+        .bs         = bs,
+        .sector_num = sector_num,
+        .buf        = buf,
+        .nb_sectors = nb_sectors,
+        .ret        = -EINPROGRESS,
+    };
+    co = qemu_coroutine_create(qcow_write_co_entry);
+    qemu_coroutine_enter(co, &data);
+    while (data.ret == -EINPROGRESS) {
+        aio_poll(aio_context, true);
+    }
+    return data.ret;
+}
+
 /* XXX: put compressed sectors first, then all the cluster aligned
    tables to avoid losing bytes in alignment */
 static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
@@ -969,7 +1012,7 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
 
     if (ret != Z_STREAM_END || out_len >= s->cluster_size) {
         /* could not compress: write normal cluster */
-        ret = bdrv_write(bs, sector_num, buf, s->cluster_sectors);
+        ret = qcow_write(bs, sector_num, buf, s->cluster_sectors);
         if (ret < 0) {
             goto fail;
         }
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index c1e9eee..a2490d7 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -1784,7 +1784,7 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
                     goto fail;
                 }
 
-                ret = bdrv_write(bs->file->bs, l2_offset / BDRV_SECTOR_SIZE,
+                ret = bdrv_write(bs->file, l2_offset / BDRV_SECTOR_SIZE,
                                  (void *)l2_table, s->cluster_sectors);
                 if (ret < 0) {
                     goto fail;
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 3bef410..12e7e6b 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -2098,7 +2098,7 @@ write_refblocks:
         on_disk_refblock = (void *)((char *) *refcount_table +
                                     refblock_index * s->cluster_size);
 
-        ret = bdrv_write(bs->file->bs, refblock_offset / BDRV_SECTOR_SIZE,
+        ret = bdrv_write(bs->file, refblock_offset / BDRV_SECTOR_SIZE,
                          on_disk_refblock, s->cluster_sectors);
         if (ret < 0) {
             fprintf(stderr, "ERROR writing refblock: %s\n", strerror(-ret));
diff --git a/block/qcow2.c b/block/qcow2.c
index 0178931..cd9c27b 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2533,6 +2533,51 @@ static int qcow2_truncate(BlockDriverState *bs, int64_t offset)
     return 0;
 }
 
+typedef struct Qcow2WriteCo {
+    BlockDriverState *bs;
+    int64_t sector_num;
+    const uint8_t *buf;
+    int nb_sectors;
+    int ret;
+} Qcow2WriteCo;
+
+static void qcow2_write_co_entry(void *opaque)
+{
+    Qcow2WriteCo *co = opaque;
+    QEMUIOVector qiov;
+    uint64_t offset = co->sector_num * BDRV_SECTOR_SIZE;
+    uint64_t bytes = co->nb_sectors * BDRV_SECTOR_SIZE;
+
+    struct iovec iov = (struct iovec) {
+        .iov_base   = (uint8_t*) co->buf,
+        .iov_len    = bytes,
+    };
+    qemu_iovec_init_external(&qiov, &iov, 1);
+
+    co->ret = qcow2_co_pwritev(co->bs, offset, bytes, &qiov, 0);
+}
+
+/* Wrapper for non-coroutine contexts */
+static int qcow2_write(BlockDriverState *bs, int64_t sector_num,
+                       const uint8_t *buf, int nb_sectors)
+{
+    Coroutine *co;
+    AioContext *aio_context = bdrv_get_aio_context(bs);
+    Qcow2WriteCo data = {
+        .bs         = bs,
+        .sector_num = sector_num,
+        .buf        = buf,
+        .nb_sectors = nb_sectors,
+        .ret        = -EINPROGRESS,
+    };
+    co = qemu_coroutine_create(qcow2_write_co_entry);
+    qemu_coroutine_enter(co, &data);
+    while (data.ret == -EINPROGRESS) {
+        aio_poll(aio_context, true);
+    }
+    return data.ret;
+}
+
 /* XXX: put compressed sectors first, then all the cluster aligned
    tables to avoid losing bytes in alignment */
 static int qcow2_write_compressed(BlockDriverState *bs, int64_t sector_num,
@@ -2596,7 +2641,7 @@ static int qcow2_write_compressed(BlockDriverState *bs, int64_t sector_num,
 
     if (ret != Z_STREAM_END || out_len >= s->cluster_size) {
         /* could not compress: write normal cluster */
-        ret = bdrv_write(bs, sector_num, buf, s->cluster_sectors);
+        ret = qcow2_write(bs, sector_num, buf, s->cluster_sectors);
         if (ret < 0) {
             goto fail;
         }
diff --git a/block/vdi.c b/block/vdi.c
index 46a3436..b2871ca 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -719,7 +719,7 @@ vdi_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
         assert(VDI_IS_ALLOCATED(bmap_first));
         *header = s->header;
         vdi_header_to_le(header);
-        ret = bdrv_write(bs->file->bs, 0, block, 1);
+        ret = bdrv_write(bs->file, 0, block, 1);
         g_free(block);
         block = NULL;
 
@@ -737,7 +737,7 @@ vdi_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
         base = ((uint8_t *)&s->bmap[0]) + bmap_first * SECTOR_SIZE;
         logout("will write %u block map sectors starting from entry %u\n",
                n_sectors, bmap_first);
-        ret = bdrv_write(bs->file->bs, offset, base, n_sectors);
+        ret = bdrv_write(bs->file, offset, base, n_sectors);
     }
 
     return ret;
diff --git a/block/vvfat.c b/block/vvfat.c
index 5f980bb..c3f24c6 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -1834,8 +1834,7 @@ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s,
                         if (res) {
                             return -1;
                         }
-                        res = bdrv_write(s->qcow->bs, offset,
-                                         s->cluster_buffer, 1);
+                        res = bdrv_write(s->qcow, offset, s->cluster_buffer, 1);
                         if (res) {
                             return -2;
                         }
@@ -2889,7 +2888,7 @@ DLOG(checkpoint());
      * Use qcow backend. Commit later.
      */
 DLOG(fprintf(stderr, "Write to qcow backend: %d + %d\n", (int)sector_num, nb_sectors));
-    ret = bdrv_write(s->qcow->bs, sector_num, buf, nb_sectors);
+    ret = bdrv_write(s->qcow, sector_num, buf, nb_sectors);
     if (ret < 0) {
 	fprintf(stderr, "Error writing to qcow backend\n");
 	return ret;
diff --git a/include/block/block.h b/include/block/block.h
index b6744ab..ea17936 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -228,7 +228,7 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_state);
 void bdrv_reopen_abort(BDRVReopenState *reopen_state);
 int bdrv_read(BdrvChild *child, int64_t sector_num,
               uint8_t *buf, int nb_sectors);
-int bdrv_write(BlockDriverState *bs, int64_t sector_num,
+int bdrv_write(BdrvChild *child, int64_t sector_num,
                const uint8_t *buf, int nb_sectors);
 int bdrv_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
                        int count, BdrvRequestFlags flags);
-- 
1.8.3.1

  parent reply	other threads:[~2016-07-05 15:51 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-05 15:50 [Qemu-devel] [PULL 00/43] Block layer patches Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 01/43] qemu-img: fix failed autotests Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 02/43] block: Tighter assertions on bdrv_aligned_pwritev() Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 03/43] block: Document supported flags during bdrv_aligned_preadv() Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 04/43] block: Fix harmless off-by-one in bdrv_aligned_preadv() Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 05/43] nbd: Allow larger requests Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 06/43] nbd: Advertise realistic limits to block layer Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 07/43] iscsi: " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 08/43] scsi: Advertise limits by blocksize, not 512 Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 09/43] block: Give nonzero result to blk_get_max_transfer_length() Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 10/43] blkdebug: Set request_alignment during .bdrv_refresh_limits() Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 11/43] iscsi: " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 12/43] qcow2: " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 13/43] raw-win32: " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 14/43] block: " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 15/43] block: Set default request_alignment during bdrv_refresh_limits() Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 16/43] block: Switch transfer length bounds to byte-based Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 17/43] block: Wording tweaks to write zeroes limits Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 18/43] block: Switch discard length bounds to byte-based Kevin Wolf
2016-07-06  2:14   ` Eric Blake
2016-07-06  8:27     ` Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 19/43] block: Drop raw_refresh_limits() Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 20/43] block: Split bdrv_merge_limits() from bdrv_refresh_limits() Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 21/43] block: Move request_alignment into BlockLimit Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 22/43] block: Fix error message style Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 23/43] block: Use bool as appropriate for BDS members Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 24/43] block: fix return code for partial write for Linux AIO Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 25/43] block/qdev: Fix NULL access when using BB twice Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 26/43] vvfat: Use BdrvChild for s->qcow Kevin Wolf
2016-07-11 14:02   ` Paolo Bonzini
2016-07-05 15:50 ` [Qemu-devel] [PULL 27/43] blkreplay: Convert to byte-based I/O Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 28/43] vhdx: Some more BlockBackend use in vhdx_create() Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 29/43] block: Convert bdrv_co_readv() to BdrvChild Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 30/43] block: Convert bdrv_co_writev() " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 31/43] block: Convert bdrv_aio_readv() " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 32/43] block: Convert bdrv_aio_writev() " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 33/43] block: Convert bdrv_co_do_readv/writev " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 34/43] block: Move bdrv_commit() to block/commit.c Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 35/43] block: Use BlockBackend for I/O in bdrv_commit() Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 36/43] block: Convert bdrv_read() to BdrvChild Kevin Wolf
2016-07-05 15:50 ` Kevin Wolf [this message]
2016-07-05 15:50 ` [Qemu-devel] [PULL 38/43] block: Convert bdrv_pread(v) " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 39/43] block: Convert bdrv_pwrite(v/_sync) " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 40/43] block: Convert bdrv_pwrite_zeroes() " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 41/43] block: Convert bdrv_prwv_co() " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 42/43] block: Convert bdrv_co_preadv/pwritev " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 43/43] block/qcow2: Don't use cpu_to_*w() Kevin Wolf
2016-07-06  9:23 ` [Qemu-devel] [PULL 00/43] Block layer patches Peter Maydell

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=1467733852-27097-38-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.