mirror of
https://github.com/xemu-project/xemu.git
synced 2024-12-18 01:08:51 +00:00
block/iscsi: avoid data corruption with cache=writeback
nb_cls_shrunk in iscsi_allocmap_update can become -1 if the
request starts and ends within the same cluster. This results
in passing -1 to bitmap_set and bitmap_clear and they don't
handle negative values properly. In the end this leads to data
corruption.
Fixes: e1123a3b40
Cc: qemu-stable@nongnu.org
Signed-off-by: Peter Lieven <pl@kamp.de>
Message-Id: <1484579832-18589-1-git-send-email-pl@kamp.de>
Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
b8bab8eb69
commit
1da45e0c4c
@ -499,14 +499,18 @@ iscsi_allocmap_update(IscsiLun *iscsilun, int64_t sector_num,
|
|||||||
if (allocated) {
|
if (allocated) {
|
||||||
bitmap_set(iscsilun->allocmap, cl_num_expanded, nb_cls_expanded);
|
bitmap_set(iscsilun->allocmap, cl_num_expanded, nb_cls_expanded);
|
||||||
} else {
|
} else {
|
||||||
bitmap_clear(iscsilun->allocmap, cl_num_shrunk, nb_cls_shrunk);
|
if (nb_cls_shrunk > 0) {
|
||||||
|
bitmap_clear(iscsilun->allocmap, cl_num_shrunk, nb_cls_shrunk);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iscsilun->allocmap_valid == NULL) {
|
if (iscsilun->allocmap_valid == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (valid) {
|
if (valid) {
|
||||||
bitmap_set(iscsilun->allocmap_valid, cl_num_shrunk, nb_cls_shrunk);
|
if (nb_cls_shrunk > 0) {
|
||||||
|
bitmap_set(iscsilun->allocmap_valid, cl_num_shrunk, nb_cls_shrunk);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
bitmap_clear(iscsilun->allocmap_valid, cl_num_expanded,
|
bitmap_clear(iscsilun->allocmap_valid, cl_num_expanded,
|
||||||
nb_cls_expanded);
|
nb_cls_expanded);
|
||||||
|
Loading…
Reference in New Issue
Block a user