cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-Make-bdrv_pwrite-a-bdrv_prwv_co-wrapper.patch

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