[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 02/43] block: Tighter assertions on bdrv_aligned_pwri
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 02/43] block: Tighter assertions on bdrv_aligned_pwritev() |
Date: |
Tue, 5 Jul 2016 17:50:11 +0200 |
From: Eric Blake <address@hidden>
For symmetry with bdrv_aligned_preadv(), assert that the caller
really has aligned things properly. This requires adding an align
parameter, which is used now only in the new asserts, but will
come in handy in a later patch that adds auto-fragmentation to the
max transfer size, since that value need not always be a multiple
of the alignment, and therefore must be rounded down.
Signed-off-by: Eric Blake <address@hidden>
Reviewed-by: Kevin Wolf <address@hidden>
Reviewed-by: Fam Zheng <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/io.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/block/io.c b/block/io.c
index 7cf3645..b95e856 100644
--- a/block/io.c
+++ b/block/io.c
@@ -1254,7 +1254,7 @@ fail:
*/
static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,
BdrvTrackedRequest *req, int64_t offset, unsigned int bytes,
- QEMUIOVector *qiov, int flags)
+ int64_t align, QEMUIOVector *qiov, int flags)
{
BlockDriver *drv = bs->drv;
bool waited;
@@ -1263,6 +1263,9 @@ static int coroutine_fn
bdrv_aligned_pwritev(BlockDriverState *bs,
int64_t start_sector = offset >> BDRV_SECTOR_BITS;
int64_t end_sector = DIV_ROUND_UP(offset + bytes, BDRV_SECTOR_SIZE);
+ assert(is_power_of_2(align));
+ assert((offset & (align - 1)) == 0);
+ assert((bytes & (align - 1)) == 0);
assert(!qiov || bytes == qiov->size);
assert((bs->open_flags & BDRV_O_NO_IO) == 0);
assert(!(flags & ~BDRV_REQ_MASK));
@@ -1349,7 +1352,7 @@ static int coroutine_fn
bdrv_co_do_zero_pwritev(BlockDriverState *bs,
memset(buf + head_padding_bytes, 0, zero_bytes);
ret = bdrv_aligned_pwritev(bs, req, offset & ~(align - 1), align,
- &local_qiov,
+ align, &local_qiov,
flags & ~BDRV_REQ_ZERO_WRITE);
if (ret < 0) {
goto fail;
@@ -1362,7 +1365,7 @@ static int coroutine_fn
bdrv_co_do_zero_pwritev(BlockDriverState *bs,
if (bytes >= align) {
/* Write the aligned part in the middle. */
uint64_t aligned_bytes = bytes & ~(align - 1);
- ret = bdrv_aligned_pwritev(bs, req, offset, aligned_bytes,
+ ret = bdrv_aligned_pwritev(bs, req, offset, aligned_bytes, align,
NULL, flags);
if (ret < 0) {
goto fail;
@@ -1386,7 +1389,7 @@ static int coroutine_fn
bdrv_co_do_zero_pwritev(BlockDriverState *bs,
bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_AFTER_TAIL);
memset(buf, 0, bytes);
- ret = bdrv_aligned_pwritev(bs, req, offset, align,
+ ret = bdrv_aligned_pwritev(bs, req, offset, align, align,
&local_qiov, flags & ~BDRV_REQ_ZERO_WRITE);
}
fail:
@@ -1511,7 +1514,7 @@ int coroutine_fn bdrv_co_pwritev(BlockDriverState *bs,
bytes = ROUND_UP(bytes, align);
}
- ret = bdrv_aligned_pwritev(bs, &req, offset, bytes,
+ ret = bdrv_aligned_pwritev(bs, &req, offset, bytes, align,
use_local_qiov ? &local_qiov : qiov,
flags);
--
1.8.3.1
- [Qemu-block] [PULL 00/43] Block layer patches, Kevin Wolf, 2016/07/05
- [Qemu-block] [PULL 01/43] qemu-img: fix failed autotests, Kevin Wolf, 2016/07/05
- [Qemu-block] [PULL 03/43] block: Document supported flags during bdrv_aligned_preadv(), Kevin Wolf, 2016/07/05
- [Qemu-block] [PULL 04/43] block: Fix harmless off-by-one in bdrv_aligned_preadv(), Kevin Wolf, 2016/07/05
- [Qemu-block] [PULL 05/43] nbd: Allow larger requests, Kevin Wolf, 2016/07/05
- [Qemu-block] [PULL 07/43] iscsi: Advertise realistic limits to block layer, Kevin Wolf, 2016/07/05
- [Qemu-block] [PULL 02/43] block: Tighter assertions on bdrv_aligned_pwritev(),
Kevin Wolf <=
- [Qemu-block] [PULL 08/43] scsi: Advertise limits by blocksize, not 512, Kevin Wolf, 2016/07/05
- [Qemu-block] [PULL 06/43] nbd: Advertise realistic limits to block layer, Kevin Wolf, 2016/07/05
- [Qemu-block] [PULL 09/43] block: Give nonzero result to blk_get_max_transfer_length(), Kevin Wolf, 2016/07/05
- [Qemu-block] [PULL 11/43] iscsi: Set request_alignment during .bdrv_refresh_limits(), Kevin Wolf, 2016/07/05
- [Qemu-block] [PULL 10/43] blkdebug: Set request_alignment during .bdrv_refresh_limits(), Kevin Wolf, 2016/07/05
- [Qemu-block] [PULL 12/43] qcow2: Set request_alignment during .bdrv_refresh_limits(), Kevin Wolf, 2016/07/05
- [Qemu-block] [PULL 13/43] raw-win32: Set request_alignment during .bdrv_refresh_limits(), Kevin Wolf, 2016/07/05
- [Qemu-block] [PULL 16/43] block: Switch transfer length bounds to byte-based, Kevin Wolf, 2016/07/05
- [Qemu-block] [PULL 14/43] block: Set request_alignment during .bdrv_refresh_limits(), Kevin Wolf, 2016/07/05
- [Qemu-block] [PULL 17/43] block: Wording tweaks to write zeroes limits, Kevin Wolf, 2016/07/05