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