Skip to content

Commit a93d81c

Browse files
Vladimir Sementsov-Ogievskiyebblake
authored andcommitted
block-backend: convert blk_aio_ functions to int64_t bytes paramter
1. Convert bytes in BlkAioEmAIOCB: aio->bytes is only passed to already int64_t interfaces, and set in blk_aio_prwv, which is updated here. 2. For all updated functions the parameter type becomes wider so callers are safe. 3. In blk_aio_prwv we only store bytes to BlkAioEmAIOCB, which is updated here. 4. Other updated functions are wrappers on blk_aio_prwv. Note that blk_aio_preadv and blk_aio_pwritev become safer: before this commit, it's theoretically possible to pass qiov with size exceeding INT_MAX, which than converted to int argument of blk_aio_prwv. Now it's converted to int64_t which is a lot better. Still add assertions. Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]> Message-Id: <[email protected]> Reviewed-by: Eric Blake <[email protected]> [eblake: tweak assertion and grammar] Signed-off-by: Eric Blake <[email protected]>
1 parent e192179 commit a93d81c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

block/block-backend.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ BlockAIOCB *blk_abort_aio_request(BlockBackend *blk,
13801380
typedef struct BlkAioEmAIOCB {
13811381
BlockAIOCB common;
13821382
BlkRwCo rwco;
1383-
int bytes;
1383+
int64_t bytes;
13841384
bool has_returned;
13851385
} BlkAioEmAIOCB;
13861386

@@ -1412,7 +1412,8 @@ static void blk_aio_complete_bh(void *opaque)
14121412
blk_aio_complete(acb);
14131413
}
14141414

1415-
static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, int64_t offset, int bytes,
1415+
static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, int64_t offset,
1416+
int64_t bytes,
14161417
void *iobuf, CoroutineEntry co_entry,
14171418
BdrvRequestFlags flags,
14181419
BlockCompletionFunc *cb, void *opaque)
@@ -1469,10 +1470,10 @@ static void blk_aio_write_entry(void *opaque)
14691470
}
14701471

14711472
BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk, int64_t offset,
1472-
int count, BdrvRequestFlags flags,
1473+
int64_t bytes, BdrvRequestFlags flags,
14731474
BlockCompletionFunc *cb, void *opaque)
14741475
{
1475-
return blk_aio_prwv(blk, offset, count, NULL, blk_aio_write_entry,
1476+
return blk_aio_prwv(blk, offset, bytes, NULL, blk_aio_write_entry,
14761477
flags | BDRV_REQ_ZERO_WRITE, cb, opaque);
14771478
}
14781479

@@ -1530,6 +1531,7 @@ BlockAIOCB *blk_aio_preadv(BlockBackend *blk, int64_t offset,
15301531
QEMUIOVector *qiov, BdrvRequestFlags flags,
15311532
BlockCompletionFunc *cb, void *opaque)
15321533
{
1534+
assert((uint64_t)qiov->size <= INT64_MAX);
15331535
return blk_aio_prwv(blk, offset, qiov->size, qiov,
15341536
blk_aio_read_entry, flags, cb, opaque);
15351537
}
@@ -1538,6 +1540,7 @@ BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset,
15381540
QEMUIOVector *qiov, BdrvRequestFlags flags,
15391541
BlockCompletionFunc *cb, void *opaque)
15401542
{
1543+
assert(qiov->size <= INT64_MAX);
15411544
return blk_aio_prwv(blk, offset, qiov->size, qiov,
15421545
blk_aio_write_entry, flags, cb, opaque);
15431546
}
@@ -1618,7 +1621,7 @@ static void blk_aio_pdiscard_entry(void *opaque)
16181621
}
16191622

16201623
BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk,
1621-
int64_t offset, int bytes,
1624+
int64_t offset, int64_t bytes,
16221625
BlockCompletionFunc *cb, void *opaque)
16231626
{
16241627
return blk_aio_prwv(blk, offset, bytes, NULL, blk_aio_pdiscard_entry, 0,

include/sysemu/block-backend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static inline int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset,
157157
int blk_pwrite_zeroes(BlockBackend *blk, int64_t offset,
158158
int64_t bytes, BdrvRequestFlags flags);
159159
BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk, int64_t offset,
160-
int bytes, BdrvRequestFlags flags,
160+
int64_t bytes, BdrvRequestFlags flags,
161161
BlockCompletionFunc *cb, void *opaque);
162162
int blk_make_zero(BlockBackend *blk, BdrvRequestFlags flags);
163163
int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes);
@@ -174,7 +174,7 @@ BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset,
174174
BlockCompletionFunc *cb, void *opaque);
175175
BlockAIOCB *blk_aio_flush(BlockBackend *blk,
176176
BlockCompletionFunc *cb, void *opaque);
177-
BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, int64_t offset, int bytes,
177+
BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes,
178178
BlockCompletionFunc *cb, void *opaque);
179179
void blk_aio_cancel(BlockAIOCB *acb);
180180
void blk_aio_cancel_async(BlockAIOCB *acb);

0 commit comments

Comments
 (0)