9ae3a8
From 571796285399dce82633b305dd9e03bcb8ac5634 Mon Sep 17 00:00:00 2001
9ae3a8
From: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Date: Thu, 5 Dec 2013 12:34:02 +0100
9ae3a8
Subject: [PATCH 29/37] block: Make bdrv_pwrite() a bdrv_prwv_co() wrapper
9ae3a8
9ae3a8
Message-id: <1392117622-28812-30-git-send-email-kwolf@redhat.com>
9ae3a8
Patchwork-id: 57194
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 29/37] block: Make bdrv_pwrite() a bdrv_prwv_co() wrapper
9ae3a8
Bugzilla: 748906
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9ae3a8
9ae3a8
Instead of implementing the alignment adjustment here, use the now
9ae3a8
existing functionality of bdrv_co_do_pwritev().
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Reviewed-by: Max Reitz <mreitz@redhat.com>
9ae3a8
(cherry picked from commit 8407d5d7e265911b05949ee2ffd9e45c97bf0505)
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
---
9ae3a8
 block.c               | 64 ++++++++-------------------------------------------
9ae3a8
 include/block/block.h |  1 -
9ae3a8
 2 files changed, 9 insertions(+), 56 deletions(-)
9ae3a8
---
9ae3a8
 block.c               |   64 +++++++------------------------------------------
9ae3a8
 include/block/block.h |    1 -
9ae3a8
 2 files changed, 9 insertions(+), 56 deletions(-)
9ae3a8
9ae3a8
diff --git a/block.c b/block.c
9ae3a8
index e76dec6..d18c2df 100644
9ae3a8
--- a/block.c
9ae3a8
+++ b/block.c
9ae3a8
@@ -2517,11 +2517,6 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num,
9ae3a8
     return bdrv_rw_co(bs, sector_num, (uint8_t *)buf, nb_sectors, true, 0);
9ae3a8
 }
9ae3a8
 
9ae3a8
-int bdrv_writev(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov)
9ae3a8
-{
9ae3a8
-    return bdrv_prwv_co(bs, sector_num << BDRV_SECTOR_BITS, qiov, true, 0);
9ae3a8
-}
9ae3a8
-
9ae3a8
 int bdrv_write_zeroes(BlockDriverState *bs, int64_t sector_num,
9ae3a8
                       int nb_sectors, BdrvRequestFlags flags)
9ae3a8
 {
9ae3a8
@@ -2590,70 +2585,29 @@ int bdrv_pread(BlockDriverState *bs, int64_t offset, void *buf, int bytes)
9ae3a8
 
9ae3a8
 int bdrv_pwritev(BlockDriverState *bs, int64_t offset, QEMUIOVector *qiov)
9ae3a8
 {
9ae3a8
-    uint8_t tmp_buf[BDRV_SECTOR_SIZE];
9ae3a8
-    int len, nb_sectors, count;
9ae3a8
-    int64_t sector_num;
9ae3a8
     int ret;
9ae3a8
 
9ae3a8
-    count = qiov->size;
9ae3a8
-
9ae3a8
-    /* first write to align to sector start */
9ae3a8
-    len = (BDRV_SECTOR_SIZE - offset) & (BDRV_SECTOR_SIZE - 1);
9ae3a8
-    if (len > count)
9ae3a8
-        len = count;
9ae3a8
-    sector_num = offset >> BDRV_SECTOR_BITS;
9ae3a8
-    if (len > 0) {
9ae3a8
-        if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0)
9ae3a8
-            return ret;
9ae3a8
-        qemu_iovec_to_buf(qiov, 0, tmp_buf + (offset & (BDRV_SECTOR_SIZE - 1)),
9ae3a8
-                          len);
9ae3a8
-        if ((ret = bdrv_write(bs, sector_num, tmp_buf, 1)) < 0)
9ae3a8
-            return ret;
9ae3a8
-        count -= len;
9ae3a8
-        if (count == 0)
9ae3a8
-            return qiov->size;
9ae3a8
-        sector_num++;
9ae3a8
-    }
9ae3a8
-
9ae3a8
-    /* write the sectors "in place" */
9ae3a8
-    nb_sectors = count >> BDRV_SECTOR_BITS;
9ae3a8
-    if (nb_sectors > 0) {
9ae3a8
-        QEMUIOVector qiov_inplace;
9ae3a8
-
9ae3a8
-        qemu_iovec_init(&qiov_inplace, qiov->niov);
9ae3a8
-        qemu_iovec_concat(&qiov_inplace, qiov, len,
9ae3a8
-                          nb_sectors << BDRV_SECTOR_BITS);
9ae3a8
-        ret = bdrv_writev(bs, sector_num, &qiov_inplace);
9ae3a8
-        qemu_iovec_destroy(&qiov_inplace);
9ae3a8
-        if (ret < 0) {
9ae3a8
-            return ret;
9ae3a8
-        }
9ae3a8
-
9ae3a8
-        sector_num += nb_sectors;
9ae3a8
-        len = nb_sectors << BDRV_SECTOR_BITS;
9ae3a8
-        count -= len;
9ae3a8
+    ret = bdrv_prwv_co(bs, offset, qiov, true, 0);
9ae3a8
+    if (ret < 0) {
9ae3a8
+        return ret;
9ae3a8
     }
9ae3a8
 
9ae3a8
-    /* add data from the last sector */
9ae3a8
-    if (count > 0) {
9ae3a8
-        if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0)
9ae3a8
-            return ret;
9ae3a8
-        qemu_iovec_to_buf(qiov, qiov->size - count, tmp_buf, count);
9ae3a8
-        if ((ret = bdrv_write(bs, sector_num, tmp_buf, 1)) < 0)
9ae3a8
-            return ret;
9ae3a8
-    }
9ae3a8
     return qiov->size;
9ae3a8
 }
9ae3a8
 
9ae3a8
 int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
9ae3a8
-                const void *buf, int count1)
9ae3a8
+                const void *buf, int bytes)
9ae3a8
 {
9ae3a8
     QEMUIOVector qiov;
9ae3a8
     struct iovec iov = {
9ae3a8
         .iov_base   = (void *) buf,
9ae3a8
-        .iov_len    = count1,
9ae3a8
+        .iov_len    = bytes,
9ae3a8
     };
9ae3a8
 
9ae3a8
+    if (bytes < 0) {
9ae3a8
+        return -EINVAL;
9ae3a8
+    }
9ae3a8
+
9ae3a8
     qemu_iovec_init_external(&qiov, &iov, 1);
9ae3a8
     return bdrv_pwritev(bs, offset, &qiov);
9ae3a8
 }
9ae3a8
diff --git a/include/block/block.h b/include/block/block.h
9ae3a8
index 2a9aa5b..feb1926 100644
9ae3a8
--- a/include/block/block.h
9ae3a8
+++ b/include/block/block.h
9ae3a8
@@ -221,7 +221,6 @@ BlockDriverAIOCB *bdrv_aio_write_zeroes(BlockDriverState *bs, int64_t sector_num
9ae3a8
                                         int nb_sectors, BdrvRequestFlags flags,
9ae3a8
                                         BlockDriverCompletionFunc *cb, void *opaque);
9ae3a8
 int bdrv_make_zero(BlockDriverState *bs, BdrvRequestFlags flags);
9ae3a8
-int bdrv_writev(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov);
9ae3a8
 int bdrv_pread(BlockDriverState *bs, int64_t offset,
9ae3a8
                void *buf, int count);
9ae3a8
 int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8