[PATCH v6 05/25] parallels: Limit search in parallels_mark_used to the last marked cluster
"Denis V. Lunev" <[email protected]>
| Newsgroups | gmane.comp.emulators.qemu,gmane.comp.emulators.qemu.block |
|---|---|
| Message-ID | <[email protected]> |
From: Denis V. Lunev <[email protected]> There is no necessity to search to the end of the bitmap. Limit the search area as cluster_index + count. Add cluster_end variable to avoid its calculation in a few places. Based on the original work from Alexander Ivanov. Cc: Stefan Hajnoczi <[email protected]> Signed-off-by: Denis V. Lunev <[email protected]> --- block/parallels.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 6f7a9911d7..d537b0bb53 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -192,12 +192,14 @@ int parallels_mark_used(BlockDriverState *bs, unsigned long *bitmap, { BDRVParallelsState *s = bs->opaque; uint32_t cluster_index = host_cluster_index(s, off); + uint64_t cluster_end = (uint64_t)cluster_index + count; unsigned long next_used; - if ((uint64_t)cluster_index + count > bitmap_size) { + + if (cluster_end > bitmap_size) { return -E2BIG; } - next_used = find_next_bit(bitmap, bitmap_size, cluster_index); - if (next_used < (uint64_t)cluster_index + count) { + next_used = find_next_bit(bitmap, cluster_end, cluster_index); + if (next_used < cluster_end) { return -EBUSY; } bitmap_set(bitmap, cluster_index, count); -- 2.53.0