qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: mreitz@redhat.com, kwolf@redhat.com, qemu-block@nongnu.org,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Fam Zheng <famz@redhat.com>
Subject: [Qemu-devel] [PATCH 7/5] block: Refactor zero_beyond_eof hack in bdrv_aligned_preadv()
Date: Fri,  3 Jun 2016 17:13:28 -0600	[thread overview]
Message-ID: <1464995608-15264-1-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1464973388-15821-1-git-send-email-eblake@redhat.com>

Reindent code so that later removal of zero_beyond_eof doesn't
interfere as much with upcoming changes to the normal path.

Patch viewed best with 'git diff -b'.

Signed-off-by: Eric Blake <eblake@redhat.com>
---
 block/io.c | 74 +++++++++++++++++++++++++++++++-------------------------------
 1 file changed, 37 insertions(+), 37 deletions(-)

diff --git a/block/io.c b/block/io.c
index c8b323e..243d18a 100644
--- a/block/io.c
+++ b/block/io.c
@@ -944,6 +944,7 @@ static int coroutine_fn bdrv_aligned_preadv(BlockDriverState *bs,
 {
     int ret;

+    int64_t total_sectors, max_nb_sectors;
     int64_t sector_num = offset >> BDRV_SECTOR_BITS;
     unsigned int nb_sectors = bytes >> BDRV_SECTOR_BITS;

@@ -981,46 +982,45 @@ static int coroutine_fn bdrv_aligned_preadv(BlockDriverState *bs,
         }
     }

-    /* Forward the request to the BlockDriver */
+    /* Hack for stashing vmstate beyond guest visibility */
     if (!bs->zero_beyond_eof) {
         ret = bdrv_driver_preadv(bs, offset, bytes, qiov, flags);
+        goto out;
+    }
+
+    /* Forward the request to the BlockDriver */
+    total_sectors = bdrv_nb_sectors(bs);
+    if (total_sectors < 0) {
+        ret = total_sectors;
+        goto out;
+    }
+
+    max_nb_sectors = ROUND_UP(MAX(0, total_sectors - sector_num),
+                              align >> BDRV_SECTOR_BITS);
+    if (nb_sectors <= max_nb_sectors) {
+        ret = bdrv_driver_preadv(bs, offset, bytes, qiov, flags);
+    } else if (max_nb_sectors > 0) {
+        QEMUIOVector local_qiov;
+
+        qemu_iovec_init(&local_qiov, qiov->niov);
+        qemu_iovec_concat(&local_qiov, qiov, 0,
+                          max_nb_sectors * BDRV_SECTOR_SIZE);
+
+        ret = bdrv_driver_preadv(bs, offset,
+                                 max_nb_sectors * BDRV_SECTOR_SIZE,
+                                 &local_qiov, flags);
+
+        qemu_iovec_destroy(&local_qiov);
     } else {
-        /* Read zeros after EOF */
-        int64_t total_sectors, max_nb_sectors;
-
-        total_sectors = bdrv_nb_sectors(bs);
-        if (total_sectors < 0) {
-            ret = total_sectors;
-            goto out;
-        }
-
-        max_nb_sectors = ROUND_UP(MAX(0, total_sectors - sector_num),
-                                  align >> BDRV_SECTOR_BITS);
-        if (nb_sectors <= max_nb_sectors) {
-            ret = bdrv_driver_preadv(bs, offset, bytes, qiov, flags);
-        } else if (max_nb_sectors > 0) {
-            QEMUIOVector local_qiov;
-
-            qemu_iovec_init(&local_qiov, qiov->niov);
-            qemu_iovec_concat(&local_qiov, qiov, 0,
-                              max_nb_sectors * BDRV_SECTOR_SIZE);
-
-            ret = bdrv_driver_preadv(bs, offset,
-                                     max_nb_sectors * BDRV_SECTOR_SIZE,
-                                     &local_qiov, flags);
-
-            qemu_iovec_destroy(&local_qiov);
-        } else {
-            ret = 0;
-        }
-
-        /* Reading beyond end of file is supposed to produce zeroes */
-        if (ret == 0 && total_sectors < sector_num + nb_sectors) {
-            uint64_t offset = MAX(0, total_sectors - sector_num);
-            uint64_t bytes = (sector_num + nb_sectors - offset) *
-                              BDRV_SECTOR_SIZE;
-            qemu_iovec_memset(qiov, offset * BDRV_SECTOR_SIZE, 0, bytes);
-        }
+        ret = 0;
+    }
+
+    /* Reading beyond end of file is supposed to produce zeroes */
+    if (ret == 0 && total_sectors < sector_num + nb_sectors) {
+        uint64_t offset = MAX(0, total_sectors - sector_num);
+        uint64_t bytes = (sector_num + nb_sectors - offset) *
+                          BDRV_SECTOR_SIZE;
+        qemu_iovec_memset(qiov, offset * BDRV_SECTOR_SIZE, 0, bytes);
     }

 out:
-- 
2.5.5

  parent reply	other threads:[~2016-06-03 23:13 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-03 17:03 [Qemu-devel] [PATCH 0/5] Byte-based block limits Eric Blake
2016-06-03 17:03 ` [Qemu-devel] [PATCH 1/5] block: Tighter assertions on bdrv_aligned_preadv() Eric Blake
2016-06-07 12:15   ` Kevin Wolf
2016-06-03 17:03 ` [Qemu-devel] [PATCH 2/5] block: Honor flags during bdrv_aligned_preadv() Eric Blake
2016-06-07 12:12   ` Kevin Wolf
2016-06-11 21:43     ` Eric Blake
2016-06-03 17:03 ` [Qemu-devel] [PATCH 3/5] block: Switch transfer length bounds to byte-based Eric Blake
2016-06-07 12:45   ` Kevin Wolf
2016-06-11 22:06     ` Eric Blake
2016-06-14  8:20       ` Kevin Wolf
2016-06-03 17:03 ` [Qemu-devel] [PATCH 4/5] block: Switch discard " Eric Blake
2016-06-07 13:12   ` Kevin Wolf
2016-06-03 17:03 ` [Qemu-devel] [PATCH 5/5] block: Move request_alignment into BlockLimit Eric Blake
2016-06-03 17:49   ` Eric Blake
2016-06-03 21:43     ` Eric Blake
2016-06-07 10:08       ` Kevin Wolf
2016-06-07 11:04         ` Paolo Bonzini
2016-06-07 11:24           ` Kevin Wolf
2016-06-14  4:39         ` Eric Blake
2016-06-14  8:05           ` Kevin Wolf
2016-06-14 14:47             ` Eric Blake
2016-06-14 15:30               ` Kevin Wolf
2016-06-07 13:19   ` Kevin Wolf
2016-06-03 23:06 ` [Qemu-devel] [PATCH 6/5] block: Fix harmless off-by-one in bdrv_aligned_preadv() Eric Blake
2016-06-07 13:47   ` Kevin Wolf
2016-06-03 23:13 ` Eric Blake [this message]
2016-06-07 13:49   ` [Qemu-devel] [PATCH 7/5] block: Refactor zero_beyond_eof hack " 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=1464995608-15264-1-git-send-email-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=famz@redhat.com \
    --cc=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).