From patchwork Wed Sep 18 11:14:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 275678 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 A3E542C00E1 for ; Wed, 18 Sep 2013 21:14:56 +1000 (EST) Received: from localhost ([::1]:45959 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VMFig-0002Yl-NR for incoming@patchwork.ozlabs.org; Wed, 18 Sep 2013 07:14:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33096) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VMFiH-0002WU-BW for qemu-devel@nongnu.org; Wed, 18 Sep 2013 07:14:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VMFiB-0000fx-C0 for qemu-devel@nongnu.org; Wed, 18 Sep 2013 07:14:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46691) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VMFiB-0000ft-3n for qemu-devel@nongnu.org; Wed, 18 Sep 2013 07:14:23 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8IBEMKW005911 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 18 Sep 2013 07:14:22 -0400 Received: from T430s.nay.redhat.com ([10.66.6.17]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r8IBEGlA010422; Wed, 18 Sep 2013 07:14:20 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 18 Sep 2013 19:14:14 +0800 Message-Id: <1379502855-27759-2-git-send-email-famz@redhat.com> In-Reply-To: <1379502855-27759-1-git-send-email-famz@redhat.com> References: <1379502855-27759-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, asias@redhat.com, famz@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH 1/2] block: don't lose data from last incomplete sector 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 To read the last sector that is not aligned to sector boundary, current code for growable backends, since commit 893a8f6 "block: Produce zeros when protocols reading beyond end of file", drops the data and directly returns zeroes. That is incorrect. Signed-off-by: Fam Zheng --- block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block.c b/block.c index a325efc..9b28ef9 100644 --- a/block.c +++ b/block.c @@ -2613,7 +2613,7 @@ static int coroutine_fn bdrv_co_do_readv(BlockDriverState *bs, goto out; } - total_sectors = len >> BDRV_SECTOR_BITS; + total_sectors = (len + BDRV_SECTOR_SIZE - 1) >> BDRV_SECTOR_BITS; max_nb_sectors = MAX(0, total_sectors - sector_num); if (max_nb_sectors > 0) { ret = drv->bdrv_co_readv(bs, sector_num,