0a122b
From 94789223da7e51599209395f167a95026e707ab8 Mon Sep 17 00:00:00 2001
0a122b
From: Kevin Wolf <kwolf@redhat.com>
0a122b
Date: Thu, 5 Dec 2013 12:29:59 +0100
0a122b
Subject: [PATCH 28/37] block: Make bdrv_pread() a bdrv_prwv_co() wrapper
0a122b
0a122b
Message-id: <1392117622-28812-29-git-send-email-kwolf@redhat.com>
0a122b
Patchwork-id: 57193
0a122b
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 28/37] block: Make bdrv_pread() a bdrv_prwv_co() wrapper
0a122b
Bugzilla: 748906
0a122b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
0a122b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
RH-Acked-by: Max Reitz <mreitz@redhat.com>
0a122b
0a122b
Instead of implementing the alignment adjustment here, use the now
0a122b
existing functionality of bdrv_co_do_preadv().
0a122b
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
Reviewed-by: Max Reitz <mreitz@redhat.com>
0a122b
(cherry picked from commit a3ef65718506fb94cb9e5a903ef9bf9ad8fbe6de)
0a122b
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
---
0a122b
 block.c | 49 +++++++++++++------------------------------------
0a122b
 1 file changed, 13 insertions(+), 36 deletions(-)
0a122b
---
0a122b
 block.c |   51 ++++++++++++++-------------------------------------
0a122b
 1 files changed, 14 insertions(+), 37 deletions(-)
0a122b
0a122b
diff --git a/block.c b/block.c
0a122b
index 3b5b706..e76dec6 100644
0a122b
--- a/block.c
0a122b
+++ b/block.c
0a122b
@@ -2566,49 +2566,26 @@ int bdrv_make_zero(BlockDriverState *bs, BdrvRequestFlags flags)
0a122b
     }
0a122b
 }
0a122b
 
0a122b
-int bdrv_pread(BlockDriverState *bs, int64_t offset,
0a122b
-               void *buf, int count1)
0a122b
+int bdrv_pread(BlockDriverState *bs, int64_t offset, void *buf, int bytes)
0a122b
 {
0a122b
-    uint8_t tmp_buf[BDRV_SECTOR_SIZE];
0a122b
-    int len, nb_sectors, count;
0a122b
-    int64_t sector_num;
0a122b
+    QEMUIOVector qiov;
0a122b
+    struct iovec iov = {
0a122b
+        .iov_base = (void *)buf,
0a122b
+        .iov_len = bytes,
0a122b
+    };
0a122b
     int ret;
0a122b
 
0a122b
-    count = count1;
0a122b
-    /* first read to align to sector start */
0a122b
-    len = (BDRV_SECTOR_SIZE - offset) & (BDRV_SECTOR_SIZE - 1);
0a122b
-    if (len > count)
0a122b
-        len = count;
0a122b
-    sector_num = offset >> BDRV_SECTOR_BITS;
0a122b
-    if (len > 0) {
0a122b
-        if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0)
0a122b
-            return ret;
0a122b
-        memcpy(buf, tmp_buf + (offset & (BDRV_SECTOR_SIZE - 1)), len);
0a122b
-        count -= len;
0a122b
-        if (count == 0)
0a122b
-            return count1;
0a122b
-        sector_num++;
0a122b
-        buf += len;
0a122b
+    if (bytes < 0) {
0a122b
+        return -EINVAL;
0a122b
     }
0a122b
 
0a122b
-    /* read the sectors "in place" */
0a122b
-    nb_sectors = count >> BDRV_SECTOR_BITS;
0a122b
-    if (nb_sectors > 0) {
0a122b
-        if ((ret = bdrv_read(bs, sector_num, buf, nb_sectors)) < 0)
0a122b
-            return ret;
0a122b
-        sector_num += nb_sectors;
0a122b
-        len = nb_sectors << BDRV_SECTOR_BITS;
0a122b
-        buf += len;
0a122b
-        count -= len;
0a122b
+    qemu_iovec_init_external(&qiov, &iov, 1);
0a122b
+    ret = bdrv_prwv_co(bs, offset, &qiov, false, 0);
0a122b
+    if (ret < 0) {
0a122b
+        return ret;
0a122b
     }
0a122b
 
0a122b
-    /* add data from the last sector */
0a122b
-    if (count > 0) {
0a122b
-        if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0)
0a122b
-            return ret;
0a122b
-        memcpy(buf, tmp_buf, count);
0a122b
-    }
0a122b
-    return count1;
0a122b
+    return bytes;
0a122b
 }
0a122b
 
0a122b
 int bdrv_pwritev(BlockDriverState *bs, int64_t offset, QEMUIOVector *qiov)
0a122b
-- 
0a122b
1.7.1
0a122b