Skip to content

Commit e9e52ef

Browse files
Vladimir Sementsov-Ogievskiyebblake
authored andcommitted
block/io: support int64_t bytes in read/write wrappers
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). Now, since bdrv_co_preadv_part() and bdrv_co_pwritev_part() have been updated, update all their wrappers. For all of them type of 'bytes' is widening, so callers are safe. We have update request_fn in blkverify.c simultaneously. Still it's just a pointer to one of bdrv_co_pwritev() or bdrv_co_preadv(), and type is widening for callers of the request_fn anyway. Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]> Message-Id: <[email protected]> Reviewed-by: Eric Blake <[email protected]> [eblake: grammar tweak] Signed-off-by: Eric Blake <[email protected]>
1 parent 37e9403 commit e9e52ef

File tree

5 files changed

+18
-16
lines changed

5 files changed

+18
-16
lines changed

block/blkverify.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ typedef struct BlkverifyRequest {
3131
uint64_t bytes;
3232
int flags;
3333

34-
int (*request_fn)(BdrvChild *, int64_t, unsigned int, QEMUIOVector *,
34+
int (*request_fn)(BdrvChild *, int64_t, int64_t, QEMUIOVector *,
3535
BdrvRequestFlags);
3636

3737
int ret; /* test image result */

block/io.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ static int bdrv_check_request32(int64_t offset, int64_t bytes,
10051005
}
10061006

10071007
int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset,
1008-
int bytes, BdrvRequestFlags flags)
1008+
int64_t bytes, BdrvRequestFlags flags)
10091009
{
10101010
return bdrv_pwritev(child, offset, bytes, NULL,
10111011
BDRV_REQ_ZERO_WRITE | flags);
@@ -1053,7 +1053,7 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags)
10531053
}
10541054

10551055
/* See bdrv_pwrite() for the return codes */
1056-
int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int bytes)
1056+
int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int64_t bytes)
10571057
{
10581058
int ret;
10591059
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
@@ -1073,7 +1073,8 @@ int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int bytes)
10731073
-EINVAL Invalid offset or number of bytes
10741074
-EACCES Trying to write a read-only device
10751075
*/
1076-
int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, int bytes)
1076+
int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf,
1077+
int64_t bytes)
10771078
{
10781079
int ret;
10791080
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
@@ -1094,7 +1095,7 @@ int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, int bytes)
10941095
* Returns 0 on success, -errno in error cases.
10951096
*/
10961097
int bdrv_pwrite_sync(BdrvChild *child, int64_t offset,
1097-
const void *buf, int count)
1098+
const void *buf, int64_t count)
10981099
{
10991100
int ret;
11001101

@@ -1759,7 +1760,7 @@ static int bdrv_pad_request(BlockDriverState *bs,
17591760
}
17601761

17611762
int coroutine_fn bdrv_co_preadv(BdrvChild *child,
1762-
int64_t offset, unsigned int bytes, QEMUIOVector *qiov,
1763+
int64_t offset, int64_t bytes, QEMUIOVector *qiov,
17631764
BdrvRequestFlags flags)
17641765
{
17651766
return bdrv_co_preadv_part(child, offset, bytes, qiov, 0, flags);
@@ -2186,7 +2187,7 @@ static int coroutine_fn bdrv_co_do_zero_pwritev(BdrvChild *child,
21862187
* Handle a write request in coroutine context
21872188
*/
21882189
int coroutine_fn bdrv_co_pwritev(BdrvChild *child,
2189-
int64_t offset, unsigned int bytes, QEMUIOVector *qiov,
2190+
int64_t offset, int64_t bytes, QEMUIOVector *qiov,
21902191
BdrvRequestFlags flags)
21912192
{
21922193
return bdrv_co_pwritev_part(child, offset, bytes, qiov, 0, flags);
@@ -2279,7 +2280,7 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child,
22792280
}
22802281

22812282
int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset,
2282-
int bytes, BdrvRequestFlags flags)
2283+
int64_t bytes, BdrvRequestFlags flags)
22832284
{
22842285
trace_bdrv_co_pwrite_zeroes(child->bs, offset, bytes, flags);
22852286

block/trace-events

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ blk_root_detach(void *child, void *blk, void *bs) "child %p blk %p bs %p"
1313
# io.c
1414
bdrv_co_preadv_part(void *bs, int64_t offset, int64_t bytes, unsigned int flags) "bs %p offset %" PRId64 " bytes %" PRId64 " flags 0x%x"
1515
bdrv_co_pwritev_part(void *bs, int64_t offset, int64_t bytes, unsigned int flags) "bs %p offset %" PRId64 " bytes %" PRId64 " flags 0x%x"
16-
bdrv_co_pwrite_zeroes(void *bs, int64_t offset, int count, int flags) "bs %p offset %"PRId64" count %d flags 0x%x"
16+
bdrv_co_pwrite_zeroes(void *bs, int64_t offset, int64_t bytes, int flags) "bs %p offset %" PRId64 " bytes %" PRId64 " flags 0x%x"
1717
bdrv_co_do_copy_on_readv(void *bs, int64_t offset, int64_t bytes, int64_t cluster_offset, int64_t cluster_bytes) "bs %p offset %" PRId64 " bytes %" PRId64 " cluster_offset %" PRId64 " cluster_bytes %" PRId64
1818
bdrv_co_copy_range_from(void *src, uint64_t src_offset, void *dst, uint64_t dst_offset, uint64_t bytes, int read_flags, int write_flags) "src %p offset %"PRIu64" dst %p offset %"PRIu64" bytes %"PRIu64" rw flags 0x%x 0x%x"
1919
bdrv_co_copy_range_to(void *src, uint64_t src_offset, void *dst, uint64_t dst_offset, uint64_t bytes, int read_flags, int write_flags) "src %p offset %"PRIu64" dst %p offset %"PRIu64" bytes %"PRIu64" rw flags 0x%x 0x%x"

include/block/block.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,20 +392,21 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state,
392392
void bdrv_reopen_commit(BDRVReopenState *reopen_state);
393393
void bdrv_reopen_abort(BDRVReopenState *reopen_state);
394394
int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset,
395-
int bytes, BdrvRequestFlags flags);
395+
int64_t bytes, BdrvRequestFlags flags);
396396
int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags);
397-
int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int bytes);
398-
int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, int bytes);
397+
int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int64_t bytes);
398+
int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf,
399+
int64_t bytes);
399400
int bdrv_pwrite_sync(BdrvChild *child, int64_t offset,
400-
const void *buf, int count);
401+
const void *buf, int64_t bytes);
401402
/*
402403
* Efficiently zero a region of the disk image. Note that this is a regular
403404
* I/O request like read or write and should have a reasonable size. This
404405
* function is not suitable for zeroing the entire image in a single request
405406
* because it may allocate memory for the entire region.
406407
*/
407408
int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset,
408-
int bytes, BdrvRequestFlags flags);
409+
int64_t bytes, BdrvRequestFlags flags);
409410
BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
410411
const char *backing_file);
411412
void bdrv_refresh_filename(BlockDriverState *bs);

include/block/block_int.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,13 +1032,13 @@ extern BlockDriver bdrv_raw;
10321032
extern BlockDriver bdrv_qcow2;
10331033

10341034
int coroutine_fn bdrv_co_preadv(BdrvChild *child,
1035-
int64_t offset, unsigned int bytes, QEMUIOVector *qiov,
1035+
int64_t offset, int64_t bytes, QEMUIOVector *qiov,
10361036
BdrvRequestFlags flags);
10371037
int coroutine_fn bdrv_co_preadv_part(BdrvChild *child,
10381038
int64_t offset, int64_t bytes,
10391039
QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags);
10401040
int coroutine_fn bdrv_co_pwritev(BdrvChild *child,
1041-
int64_t offset, unsigned int bytes, QEMUIOVector *qiov,
1041+
int64_t offset, int64_t bytes, QEMUIOVector *qiov,
10421042
BdrvRequestFlags flags);
10431043
int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child,
10441044
int64_t offset, int64_t bytes,

0 commit comments

Comments
 (0)