From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53696) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6kVw-0004qC-K1 for qemu-devel@nongnu.org; Fri, 24 Jan 2014 12:26:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W6kVq-0000OY-Qf for qemu-devel@nongnu.org; Fri, 24 Jan 2014 12:25:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48356) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6kVq-0000OS-BA for qemu-devel@nongnu.org; Fri, 24 Jan 2014 12:25:50 -0500 From: Kevin Wolf Date: Fri, 24 Jan 2014 18:22:03 +0100 Message-Id: <1390584136-24703-81-git-send-email-kwolf@redhat.com> In-Reply-To: <1390584136-24703-1-git-send-email-kwolf@redhat.com> References: <1390584136-24703-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 80/93] block: Make zero-after-EOF work with larger alignment List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org 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 Reviewed-by: Max Reitz Reviewed-by: Benoit Canet --- block.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 1591649..0a391bd 100644 --- a/block.c +++ b/block.c @@ -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); -- 1.8.1.4