[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 88/93] block: Make bdrv_pwrite() a bdrv_prwv_co() wra
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 88/93] block: Make bdrv_pwrite() a bdrv_prwv_co() wrapper |
Date: |
Fri, 24 Jan 2014 18:22:11 +0100 |
Instead of implementing the alignment adjustment here, use the now
existing functionality of bdrv_co_do_pwritev().
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
block.c | 64 ++++++++-------------------------------------------
include/block/block.h | 1 -
2 files changed, 9 insertions(+), 56 deletions(-)
diff --git a/block.c b/block.c
index 07114f3..179d27a 100644
--- a/block.c
+++ b/block.c
@@ -2667,11 +2667,6 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num,
return bdrv_rw_co(bs, sector_num, (uint8_t *)buf, nb_sectors, true, 0);
}
-int bdrv_writev(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov)
-{
- return bdrv_prwv_co(bs, sector_num << BDRV_SECTOR_BITS, qiov, true, 0);
-}
-
int bdrv_write_zeroes(BlockDriverState *bs, int64_t sector_num,
int nb_sectors, BdrvRequestFlags flags)
{
@@ -2745,70 +2740,29 @@ int bdrv_pread(BlockDriverState *bs, int64_t offset,
void *buf, int bytes)
int bdrv_pwritev(BlockDriverState *bs, int64_t offset, QEMUIOVector *qiov)
{
- uint8_t tmp_buf[BDRV_SECTOR_SIZE];
- int len, nb_sectors, count;
- int64_t sector_num;
int ret;
- count = qiov->size;
-
- /* first write to align to sector start */
- len = (BDRV_SECTOR_SIZE - offset) & (BDRV_SECTOR_SIZE - 1);
- if (len > count)
- len = count;
- sector_num = offset >> BDRV_SECTOR_BITS;
- if (len > 0) {
- if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0)
- return ret;
- qemu_iovec_to_buf(qiov, 0, tmp_buf + (offset & (BDRV_SECTOR_SIZE - 1)),
- len);
- if ((ret = bdrv_write(bs, sector_num, tmp_buf, 1)) < 0)
- return ret;
- count -= len;
- if (count == 0)
- return qiov->size;
- sector_num++;
- }
-
- /* write the sectors "in place" */
- nb_sectors = count >> BDRV_SECTOR_BITS;
- if (nb_sectors > 0) {
- QEMUIOVector qiov_inplace;
-
- qemu_iovec_init(&qiov_inplace, qiov->niov);
- qemu_iovec_concat(&qiov_inplace, qiov, len,
- nb_sectors << BDRV_SECTOR_BITS);
- ret = bdrv_writev(bs, sector_num, &qiov_inplace);
- qemu_iovec_destroy(&qiov_inplace);
- if (ret < 0) {
- return ret;
- }
-
- sector_num += nb_sectors;
- len = nb_sectors << BDRV_SECTOR_BITS;
- count -= len;
+ ret = bdrv_prwv_co(bs, offset, qiov, true, 0);
+ if (ret < 0) {
+ return ret;
}
- /* add data from the last sector */
- if (count > 0) {
- if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0)
- return ret;
- qemu_iovec_to_buf(qiov, qiov->size - count, tmp_buf, count);
- if ((ret = bdrv_write(bs, sector_num, tmp_buf, 1)) < 0)
- return ret;
- }
return qiov->size;
}
int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
- const void *buf, int count1)
+ const void *buf, int bytes)
{
QEMUIOVector qiov;
struct iovec iov = {
.iov_base = (void *) buf,
- .iov_len = count1,
+ .iov_len = bytes,
};
+ if (bytes < 0) {
+ return -EINVAL;
+ }
+
qemu_iovec_init_external(&qiov, &iov, 1);
return bdrv_pwritev(bs, offset, &qiov);
}
diff --git a/include/block/block.h b/include/block/block.h
index a2f5657..1085992 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -224,7 +224,6 @@ BlockDriverAIOCB *bdrv_aio_write_zeroes(BlockDriverState
*bs, int64_t sector_num
int nb_sectors, BdrvRequestFlags flags,
BlockDriverCompletionFunc *cb, void
*opaque);
int bdrv_make_zero(BlockDriverState *bs, BdrvRequestFlags flags);
-int bdrv_writev(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov);
int bdrv_pread(BlockDriverState *bs, int64_t offset,
void *buf, int count);
int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
--
1.8.1.4
- [Qemu-devel] [PULL 78/93] block: Switch BdrvTrackedRequest to byte granularity, (continued)
- [Qemu-devel] [PULL 78/93] block: Switch BdrvTrackedRequest to byte granularity, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 79/93] block: Allow waiting for overlapping requests between begin/end, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 80/93] block: Make zero-after-EOF work with larger alignment, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 81/93] block: Generalise and optimise COR serialisation, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 82/93] block: Make overlap range for serialisation dynamic, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 83/93] block: Allow wait_serialising_requests() at any point, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 84/93] block: Align requests in bdrv_co_do_pwritev(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 85/93] block: Assert serialisation assumptions in pwritev, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 86/93] block: Change coroutine wrapper to byte granularity, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 87/93] block: Make bdrv_pread() a bdrv_prwv_co() wrapper, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 88/93] block: Make bdrv_pwrite() a bdrv_prwv_co() wrapper,
Kevin Wolf <=
- [Qemu-devel] [PULL 89/93] iscsi: Set bs->request_alignment, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 90/93] blkdebug: Make required alignment configurable, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 92/93] qemu-iotests: Test pwritev RMW logic, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 59/93] qmp: Allow to take external snapshots on bs graphs node., Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 93/93] block: Switch bdrv_io_limits_intercept() to byte granularity, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 73/93] block: Introduce bdrv_aligned_preadv(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 74/93] block: Introduce bdrv_co_do_preadv(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 91/93] qemu-io: New command 'sleep', Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 60/93] block/curl: Implement the libcurl timer callback interface, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 55/93] qmp: Add QMP query-named-block-nodes to list the named BlockDriverState nodes., Kevin Wolf, 2014/01/24