From patchwork Fri Dec 6 17:22:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 298156 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A1EE92C00B9 for ; Sat, 7 Dec 2013 05:01:18 +1100 (EST) Received: from localhost ([::1]:60665 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VozFX-0004AS-G0 for incoming@patchwork.ozlabs.org; Fri, 06 Dec 2013 12:31:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Voz7v-0001lD-5Q for qemu-devel@nongnu.org; Fri, 06 Dec 2013 12:23:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Voz7p-0001u2-5Y for qemu-devel@nongnu.org; Fri, 06 Dec 2013 12:23:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47876) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Voz7o-0001tr-UI for qemu-devel@nongnu.org; Fri, 06 Dec 2013 12:23:37 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rB6HNaE7008094 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 6 Dec 2013 12:23:36 -0500 Received: from dhcp-200-207.str.redhat.com (ovpn-116-51.ams2.redhat.com [10.36.116.51]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rB6HNAUG012982; Fri, 6 Dec 2013 12:23:34 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Fri, 6 Dec 2013 18:22:54 +0100 Message-Id: <1386350580-5666-14-git-send-email-kwolf@redhat.com> In-Reply-To: <1386350580-5666-1-git-send-email-kwolf@redhat.com> References: <1386350580-5666-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, pbonzini@redhat.com, armbru@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [RFC PATCH 13/19] block: Make zero-after-EOF work with larger alignment X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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 --- block.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 5eaeb3a..0b1f08a 100644 --- a/block.c +++ b/block.c @@ -2663,7 +2663,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; @@ -2711,7 +2711,7 @@ 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)); if (max_nb_sectors > 0) { ret = drv->bdrv_co_readv(bs, sector_num, MIN(nb_sectors, max_nb_sectors), qiov); @@ -2796,7 +2796,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);