[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 11/20] block/io: support int64_t bytes in bdrv_co_do_pwrite_zeroes
From: |
Eric Blake |
Subject: |
[PULL 11/20] block/io: support int64_t bytes in bdrv_co_do_pwrite_zeroes() |
Date: |
Tue, 2 Feb 2021 16:45:20 -0600 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
We are generally moving to int64_t for both offset and bytes parameters
on all io paths.
Main motivation is realization of 64-bit write_zeroes operation for
fast zeroing large disk chunks, up to the whole disk.
We chose signed type, to be consistent with off_t (which is signed) and
with possibility for signed return type (where negative value means
error).
So, prepare bdrv_co_do_pwrite_zeroes() now.
Callers are safe, as converting int to int64_t is safe. Concentrate on
'bytes' usage in the function (thx to Eric Blake):
compute 'int tail' via % 'int alignment' - safe
fragmentation loop 'int num' - still fragments with a cap on
max_transfer
use of 'num' within the loop
MIN(bytes, max_transfer) as well as %alignment - still works, so
calculations in if (head) {} are safe
clamp size by 'int max_write_zeroes' - safe
drv->bdrv_co_pwrite_zeroes(int) - safe because of clamping
clamp size by 'int max_transfer' - safe
buf allocation is still clamped to max_transfer
qemu_iovec_init_buf(size_t) - safe because of clamping
bdrv_driver_pwritev(uint64_t) - safe
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20201211183934.169161-11-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
---
block/io.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/block/io.c b/block/io.c
index cb5064155b6a..98d9f5bdf48a 100644
--- a/block/io.c
+++ b/block/io.c
@@ -41,7 +41,7 @@
static void bdrv_parent_cb_resize(BlockDriverState *bs);
static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,
- int64_t offset, int bytes, BdrvRequestFlags flags);
+ int64_t offset, int64_t bytes, BdrvRequestFlags flags);
static void bdrv_parent_drained_begin(BlockDriverState *bs, BdrvChild *ignore,
bool ignore_bds_parents)
@@ -1819,7 +1819,7 @@ int coroutine_fn bdrv_co_preadv_part(BdrvChild *child,
}
static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,
- int64_t offset, int bytes, BdrvRequestFlags flags)
+ int64_t offset, int64_t bytes, BdrvRequestFlags flags)
{
BlockDriver *drv = bs->drv;
QEMUIOVector qiov;
@@ -1834,6 +1834,8 @@ static int coroutine_fn
bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,
bs->bl.request_alignment);
int max_transfer = MIN_NON_ZERO(bs->bl.max_transfer, MAX_BOUNCE_BUFFER);
+ bdrv_check_request(offset, bytes, &error_abort);
+
if (!drv) {
return -ENOMEDIUM;
}
@@ -1849,7 +1851,7 @@ static int coroutine_fn
bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,
assert(max_write_zeroes >= bs->bl.request_alignment);
while (bytes > 0 && !ret) {
- int num = bytes;
+ int64_t num = bytes;
/* Align request. Block drivers can expect the "bulk" of the request
* to be aligned, and that unaligned requests do not cross cluster
--
2.30.0
- [PULL 01/20] iotests: Fix expected whitespace for 185, (continued)
- [PULL 01/20] iotests: Fix expected whitespace for 185, Eric Blake, 2021/02/02
- [PULL 03/20] util/iov: make qemu_iovec_init_extended() honest, Eric Blake, 2021/02/02
- [PULL 04/20] block: fix theoretical overflow in bdrv_init_padding(), Eric Blake, 2021/02/02
- [PULL 02/20] block: refactor bdrv_check_request: add errp, Eric Blake, 2021/02/02
- [PULL 07/20] block/throttle-groups: throttle_group_co_io_limits_intercept(): 64bit bytes, Eric Blake, 2021/02/02
- [PULL 05/20] block/io: refactor bdrv_pad_request(): move bdrv_pad_request() up, Eric Blake, 2021/02/02
- [PULL 08/20] block/io: improve bdrv_check_request: check qiov too, Eric Blake, 2021/02/02
- [PULL 06/20] block/io: bdrv_pad_request(): support qemu_iovec_init_extended failure, Eric Blake, 2021/02/02
- [PULL 09/20] block: use int64_t as bytes type in tracked requests, Eric Blake, 2021/02/02
- [PULL 10/20] block/io: use int64_t bytes in driver wrappers, Eric Blake, 2021/02/02
- [PULL 11/20] block/io: support int64_t bytes in bdrv_co_do_pwrite_zeroes(),
Eric Blake <=
- [PULL 12/20] block/io: support int64_t bytes in bdrv_aligned_pwritev(), Eric Blake, 2021/02/02
- [PULL 16/20] block/io: support int64_t bytes in read/write wrappers, Eric Blake, 2021/02/02
- [PULL 17/20] block/io: use int64_t bytes in copy_range, Eric Blake, 2021/02/02
- [PULL 15/20] block/io: support int64_t bytes in bdrv_co_p{read, write}v_part(), Eric Blake, 2021/02/02
- [PULL 19/20] block/nbd: only enter connection coroutine if it's present, Eric Blake, 2021/02/02
- [PULL 20/20] nbd: make nbd_read* return -EIO on error, Eric Blake, 2021/02/02
- [PULL 14/20] block/io: support int64_t bytes in bdrv_aligned_preadv(), Eric Blake, 2021/02/02
- [PULL 18/20] block/nbd: only detach existing iochannel from aio_context, Eric Blake, 2021/02/02
- [PULL 13/20] block/io: support int64_t bytes in bdrv_co_do_copy_on_readv(), Eric Blake, 2021/02/02
- Re: [PULL 00/20] NBD patches for 2021-02-02, no-reply, 2021/02/02