diff mbox

[7/5] block: Refactor zero_beyond_eof hack in bdrv_aligned_preadv()

Message ID 1464995608-15264-1-git-send-email-eblake@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Eric Blake June 3, 2016, 11:13 p.m. UTC
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(-)

Comments

Kevin Wolf June 7, 2016, 1:49 p.m. UTC | #1
Am 04.06.2016 um 01:13 hat Eric Blake geschrieben:
> 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>

If you don't mind, I would prefer to leave this patch out because it
conflicts with my series. Once I remove bs->zero_beyond_eof, we should
end up in the same place anyway.

Kevin
diff mbox

Patch

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: