Commit eb36b953 authored by Peter Lieven's avatar Peter Lieven Committed by Paolo Bonzini

block/iscsi: fix rounding in iscsi_allocationmap_set

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.

   <--|_________________|-->  (<--> = expanded)

Instead you are setting nb_clusters=3, so that 6..8 is not marked.

   <--|______________|!!!     (! = wrong)

Reported-by: 's avatarPaolo Bonzini <>
Signed-off-by: 's avatarPeter Lieven <>
Message-Id: <>
Signed-off-by: 's avatarPaolo Bonzini <>
parent e5dfc5e8
......@@ -432,12 +432,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) {
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,
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment