diff options
author | Kevin Wolf <kwolf@redhat.com> | 2013-12-04 12:13:10 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2014-01-24 17:40:02 +0100 |
commit | ec746e10cb2e6276a8d2e036454792fe0674864a (patch) | |
tree | 2a78501412007a8a26021584a485758f10c999dd /block.c | |
parent | 65afd211c71fc91750d8a18f9604c1e57a5202fb (diff) |
block: Make zero-after-EOF work with larger alignment
Odd file sizes could make bdrv_aligned_preadv() shorten the request in
non-aligned ways. Fix it by rounding to the required alignment instead
of 512 bytes.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Benoit Canet <benoit@irqsave.net>
Diffstat (limited to 'block.c')
-rw-r--r-- | block.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -2910,7 +2910,7 @@ err: */ static int coroutine_fn bdrv_aligned_preadv(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; int ret; @@ -2958,7 +2958,8 @@ static int coroutine_fn bdrv_aligned_preadv(BlockDriverState *bs, } total_sectors = DIV_ROUND_UP(len, BDRV_SECTOR_SIZE); - max_nb_sectors = MAX(0, total_sectors - sector_num); + max_nb_sectors = MAX(0, ROUND_UP(total_sectors - sector_num, + align >> BDRV_SECTOR_BITS)); if (max_nb_sectors > 0) { ret = drv->bdrv_co_readv(bs, sector_num, MIN(nb_sectors, max_nb_sectors), qiov); @@ -3044,7 +3045,7 @@ static int coroutine_fn bdrv_co_do_preadv(BlockDriverState *bs, } tracked_request_begin(&req, bs, offset, bytes, false); - ret = bdrv_aligned_preadv(bs, &req, offset, bytes, + ret = bdrv_aligned_preadv(bs, &req, offset, bytes, align, use_local_qiov ? &local_qiov : qiov, flags); tracked_request_end(&req); |