Received: from eggs.gnu.org ([2001:4830:134:3::10]:42440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWrkg-0004YR-7C for qemu-devel@nongnu.org; Mon, 08 Aug 2016 17:06:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bWrkc-0006CC-2X for qemu-devel@nongnu.org; Mon, 08 Aug 2016 17:06:25 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:52814 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWrkb-0006Bi-Tk for qemu-devel@nongnu.org; Mon, 08 Aug 2016 17:06:22 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u78Kxllb105425 for ; Mon, 8 Aug 2016 17:06:21 -0400 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0a-001b2d01.pphosted.com with ESMTP id 24nbs0rn8x-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 08 Aug 2016 17:06:21 -0400 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 8 Aug 2016 15:06:20 -0600 From: Michael Roth Date: Mon, 8 Aug 2016 16:04:19 -0500 In-Reply-To: <1470690267-31454-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1470690267-31454-1-git-send-email-mdroth@linux.vnet.ibm.com> Message-Id: <1470690267-31454-49-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 48/56] block/iscsi: fix rounding in iscsi_allocationmap_set List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Peter Lieven , Paolo Bonzini From: Peter Lieven when setting clusters as alloacted the boundaries have to be expanded. As Paolo pointed out the calculation of the number of clusters is wrong: Suppose cluster_sectors is 2, sector_num = 1, nb_sectors = 6: In the "mark allocated" case, you want to set 0..8, i.e. cluster_num=0, nb_clusters=4. 0--.--2--.--4--.--6--.--8 <--|_________________|--> (<--> = expanded) Instead you are setting nb_clusters=3, so that 6..8 is not marked. 0--.--2--.--4--.--6--.--8 <--|______________|!!! (! = wrong) Cc: qemu-stable@nongnu.org Reported-by: Paolo Bonzini Signed-off-by: Peter Lieven Message-Id: <1468831940-15556-2-git-send-email-pl@kamp.de> Signed-off-by: Paolo Bonzini (cherry picked from commit eb36b953e0ebf4129b188a241fbc367062ac2e06) Signed-off-by: Michael Roth --- block/iscsi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 172e6cf..0466c30 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -425,12 +425,14 @@ static unsigned long *iscsi_allocationmap_init(IscsiLun *iscsilun) static void iscsi_allocationmap_set(IscsiLun *iscsilun, int64_t sector_num, int nb_sectors) { + int64_t cluster_num, nb_clusters; if (iscsilun->allocationmap == NULL) { return; } - bitmap_set(iscsilun->allocationmap, - sector_num / iscsilun->cluster_sectors, - DIV_ROUND_UP(nb_sectors, iscsilun->cluster_sectors)); + cluster_num = sector_num / iscsilun->cluster_sectors; + nb_clusters = DIV_ROUND_UP(sector_num + nb_sectors, + iscsilun->cluster_sectors) - cluster_num; + bitmap_set(iscsilun->allocationmap, cluster_num, nb_clusters); } static void iscsi_allocationmap_clear(IscsiLun *iscsilun, int64_t sector_num, -- 1.9.1