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 22/61] qcow2: Pass a QEMUIOVector to do_perform_cow_{read, write}()
Date: Fri, 23 Jun 2017 18:21:20 +0200	[thread overview]
Message-ID: <1498234919-27316-23-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1498234919-27316-1-git-send-email-kwolf@redhat.com>

From: Alberto Garcia <berto@igalia.com>

Instead of passing a single buffer pointer to do_perform_cow_write(),
pass a QEMUIOVector. This will allow us to merge the write requests
for the COW regions and the actual data into a single one.

Although do_perform_cow_read() does not strictly need to change its
API, we're doing it here as well for consistency.

Signed-off-by: Alberto Garcia <berto@igalia.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/qcow2-cluster.c | 51 ++++++++++++++++++++++++---------------------------
 1 file changed, 24 insertions(+), 27 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 20fb531..3ac26d6 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -406,19 +406,14 @@ int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num,
 static int coroutine_fn do_perform_cow_read(BlockDriverState *bs,
                                             uint64_t src_cluster_offset,
                                             unsigned offset_in_cluster,
-                                            uint8_t *buffer,
-                                            unsigned bytes)
+                                            QEMUIOVector *qiov)
 {
-    QEMUIOVector qiov;
-    struct iovec iov = { .iov_base = buffer, .iov_len = bytes };
     int ret;
 
-    if (bytes == 0) {
+    if (qiov->size == 0) {
         return 0;
     }
 
-    qemu_iovec_init_external(&qiov, &iov, 1);
-
     BLKDBG_EVENT(bs->file, BLKDBG_COW_READ);
 
     if (!bs->drv) {
@@ -430,7 +425,7 @@ static int coroutine_fn do_perform_cow_read(BlockDriverState *bs,
      * which can lead to deadlock when block layer copy-on-read is enabled.
      */
     ret = bs->drv->bdrv_co_preadv(bs, src_cluster_offset + offset_in_cluster,
-                                  bytes, &qiov, 0);
+                                  qiov->size, qiov, 0);
     if (ret < 0) {
         return ret;
     }
@@ -462,28 +457,23 @@ static bool coroutine_fn do_perform_cow_encrypt(BlockDriverState *bs,
 static int coroutine_fn do_perform_cow_write(BlockDriverState *bs,
                                              uint64_t cluster_offset,
                                              unsigned offset_in_cluster,
-                                             uint8_t *buffer,
-                                             unsigned bytes)
+                                             QEMUIOVector *qiov)
 {
-    QEMUIOVector qiov;
-    struct iovec iov = { .iov_base = buffer, .iov_len = bytes };
     int ret;
 
-    if (bytes == 0) {
+    if (qiov->size == 0) {
         return 0;
     }
 
-    qemu_iovec_init_external(&qiov, &iov, 1);
-
     ret = qcow2_pre_write_overlap_check(bs, 0,
-            cluster_offset + offset_in_cluster, bytes);
+            cluster_offset + offset_in_cluster, qiov->size);
     if (ret < 0) {
         return ret;
     }
 
     BLKDBG_EVENT(bs->file, BLKDBG_COW_WRITE);
     ret = bdrv_co_pwritev(bs->file, cluster_offset + offset_in_cluster,
-                          bytes, &qiov, 0);
+                          qiov->size, qiov, 0);
     if (ret < 0) {
         return ret;
     }
@@ -780,6 +770,7 @@ static int perform_cow(BlockDriverState *bs, QCowL2Meta *m)
     unsigned data_bytes = end->offset - (start->offset + start->nb_bytes);
     bool merge_reads;
     uint8_t *start_buffer, *end_buffer;
+    QEMUIOVector qiov;
     int ret;
 
     assert(start->nb_bytes <= UINT_MAX - end->nb_bytes);
@@ -816,22 +807,25 @@ static int perform_cow(BlockDriverState *bs, QCowL2Meta *m)
     /* The part of the buffer where the end region is located */
     end_buffer = start_buffer + buffer_size - end->nb_bytes;
 
+    qemu_iovec_init(&qiov, 1);
+
     qemu_co_mutex_unlock(&s->lock);
     /* First we read the existing data from both COW regions. We
      * either read the whole region in one go, or the start and end
      * regions separately. */
     if (merge_reads) {
-        ret = do_perform_cow_read(bs, m->offset, start->offset,
-                                  start_buffer, buffer_size);
+        qemu_iovec_add(&qiov, start_buffer, buffer_size);
+        ret = do_perform_cow_read(bs, m->offset, start->offset, &qiov);
     } else {
-        ret = do_perform_cow_read(bs, m->offset, start->offset,
-                                  start_buffer, start->nb_bytes);
+        qemu_iovec_add(&qiov, start_buffer, start->nb_bytes);
+        ret = do_perform_cow_read(bs, m->offset, start->offset, &qiov);
         if (ret < 0) {
             goto fail;
         }
 
-        ret = do_perform_cow_read(bs, m->offset, end->offset,
-                                  end_buffer, end->nb_bytes);
+        qemu_iovec_reset(&qiov);
+        qemu_iovec_add(&qiov, end_buffer, end->nb_bytes);
+        ret = do_perform_cow_read(bs, m->offset, end->offset, &qiov);
     }
     if (ret < 0) {
         goto fail;
@@ -849,14 +843,16 @@ static int perform_cow(BlockDriverState *bs, QCowL2Meta *m)
     }
 
     /* And now we can write everything */
-    ret = do_perform_cow_write(bs, m->alloc_offset, start->offset,
-                               start_buffer, start->nb_bytes);
+    qemu_iovec_reset(&qiov);
+    qemu_iovec_add(&qiov, start_buffer, start->nb_bytes);
+    ret = do_perform_cow_write(bs, m->alloc_offset, start->offset, &qiov);
     if (ret < 0) {
         goto fail;
     }
 
-    ret = do_perform_cow_write(bs, m->alloc_offset, end->offset,
-                               end_buffer, end->nb_bytes);
+    qemu_iovec_reset(&qiov);
+    qemu_iovec_add(&qiov, end_buffer, end->nb_bytes);
+    ret = do_perform_cow_write(bs, m->alloc_offset, end->offset, &qiov);
 fail:
     qemu_co_mutex_lock(&s->lock);
 
@@ -870,6 +866,7 @@ fail:
     }
 
     qemu_vfree(start_buffer);
+    qemu_iovec_destroy(&qiov);
     return ret;
 }
 
-- 
1.8.3.1

  parent reply	other threads:[~2017-06-23 16:22 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-23 16:20 [Qemu-devel] [PULL 00/61] Block layer patches Kevin Wolf
2017-06-23 16:20 ` [Qemu-devel] [PULL 01/61] commit: Fix completion with extra reference Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 02/61] qemu-iotests: Allow starting new qemu after cleanup Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 03/61] qemu-iotests: Test exiting qemu with running job Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 04/61] block: count bdrv_co_rw_vmstate() requests Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 05/61] block: use BDRV_POLL_WHILE() in bdrv_rw_vmstate() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 06/61] migration: avoid recursive AioContext locking in save_vmstate() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 07/61] migration: use bdrv_drain_all_begin/end() instead bdrv_drain_all() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 08/61] doc: Document generic -blockdev options Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 09/61] doc: Document driver-specific " Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 10/61] throttle: Update throttle-groups.c documentation Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 11/61] virtio-pci: use ioeventfd even when KVM is disabled Kevin Wolf
2017-06-28 10:11   ` [Qemu-devel] [Qemu-block] " QingFeng Hao
2017-06-28 10:22     ` Kevin Wolf
2017-06-28 13:07       ` QingFeng Hao
2017-07-03  6:01       ` QingFeng Hao
2017-06-23 16:21 ` [Qemu-devel] [PULL 12/61] migration: hold AioContext lock for loadvm qemu_fclose() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 13/61] qemu-iotests: 068: extract _qemu() function Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 14/61] qemu-iotests: 068: use -drive/-device instead of -hda Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 15/61] qemu-iotests: 068: test iothread mode Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 16/61] nvme: Add support for Read Data and Write Data in CMBs Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 17/61] qcow2: Remove unused Error variable in do_perform_cow() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 18/61] qcow2: Use unsigned int for both members of Qcow2COWRegion Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 19/61] qcow2: Make perform_cow() call do_perform_cow() twice Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 20/61] qcow2: Split do_perform_cow() into _read(), _encrypt() and _write() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 21/61] qcow2: Allow reading both COW regions with only one request Kevin Wolf
2017-06-23 16:21 ` Kevin Wolf [this message]
2017-06-23 16:21 ` [Qemu-devel] [PULL 23/61] qcow2: Merge the writing of the COW regions with the guest data Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 24/61] qcow2: Use offset_into_cluster() and offset_to_l2_index() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 25/61] qed: Use bottom half to resume waiting requests Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 26/61] qed: Make qed_read_table() synchronous Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 27/61] qed: Remove callback from qed_read_table() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 28/61] qed: Remove callback from qed_read_l2_table() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 29/61] qed: Remove callback from qed_find_cluster() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 30/61] qed: Make qed_read_backing_file() synchronous Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 31/61] qed: Make qed_copy_from_backing_file() synchronous Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 32/61] qed: Remove callback from qed_copy_from_backing_file() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 33/61] qed: Make qed_write_header() synchronous Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 34/61] qed: Remove callback from qed_write_header() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 35/61] qed: Make qed_write_table() synchronous Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 36/61] qed: Remove GenericCB Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 37/61] qed: Remove callback from qed_write_table() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 38/61] qed: Make qed_aio_read_data() synchronous Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 39/61] qed: Make qed_aio_write_main() synchronous Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 40/61] qed: Inline qed_commit_l2_update() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 41/61] qed: Add return value to qed_aio_write_l1_update() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 42/61] qed: Add return value to qed_aio_write_l2_update() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 43/61] qed: Add return value to qed_aio_write_main() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 44/61] qed: Add return value to qed_aio_write_cow() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 45/61] qed: Add return value to qed_aio_write_inplace/alloc() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 46/61] qed: Add return value to qed_aio_read/write_data() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 47/61] qed: Remove ret argument from qed_aio_next_io() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 48/61] qed: Remove recursion in qed_aio_next_io() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 49/61] qed: Implement .bdrv_co_readv/writev Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 50/61] qed: Use CoQueue for serialising allocations Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 51/61] qed: Simplify request handling Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 52/61] qed: Use a coroutine for need_check_timer Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 53/61] qed: Add coroutine_fn to I/O path functions Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 54/61] qed: Use bdrv_co_* for coroutine_fns Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 55/61] block: Remove bdrv_aio_readv/writev/flush() Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 56/61] block: change variable names in BlockDriverState Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 57/61] fix: avoid an infinite loop or a dangling pointer problem in img_commit Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 58/61] blkdebug: Catch bs->exact_filename overflow Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 59/61] blkverify: " Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 60/61] block: Do not strcmp() with NULL uri->scheme Kevin Wolf
2017-06-23 16:21 ` [Qemu-devel] [PULL 61/61] qemu-img: don't shadow opts variable in img_dd() Kevin Wolf
2017-06-26 10:23 ` [Qemu-devel] [PULL 00/61] Block layer patches Peter Maydell
2017-06-26 10:26   ` Peter Maydell
2017-06-26 12:50   ` Kevin Wolf

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=1498234919-27316-23-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.