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 From: Fam Zheng 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> Subject: [Qemu-devel] [PATCH 1/2] block: don't lose data from last incomplete sector List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, asias@redhat.com, famz@redhat.com, stefanha@redhat.com 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, -- 1.8.3.1