[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 04/54] qcow2: Ensure bitmap serialization is aligned
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 04/54] qcow2: Ensure bitmap serialization is aligned |
Date: |
Fri, 6 Oct 2017 17:53:32 +0200 |
From: Eric Blake <address@hidden>
When subdividing a bitmap serialization, the code in hbitmap.c
enforces that start/count parameters are aligned (except that
count can end early at end-of-bitmap). We exposed this required
alignment through bdrv_dirty_bitmap_serialization_align(), but
forgot to actually check that we comply with it.
Fortunately, qcow2 is never dividing bitmap serialization smaller
than one cluster (which is a minimum of 512 bytes); so we are
always compliant with the serialization alignment (which insists
that we partition at least 64 bits per chunk) because we are doing
at least 4k bits per chunk.
Still, it's safer to add an assertion (for the unlikely case that
we'd ever support a cluster smaller than 512 bytes, or if the
hbitmap implementation changes what it considers to be aligned),
rather than leaving bdrv_dirty_bitmap_serialization_align()
without a caller.
Signed-off-by: Eric Blake <address@hidden>
Reviewed-by: John Snow <address@hidden>
Reviewed-by: Kevin Wolf <address@hidden>
Reviewed-by: Fam Zheng <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/qcow2-bitmap.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
index 14f41d0427..1fc375b40a 100644
--- a/block/qcow2-bitmap.c
+++ b/block/qcow2-bitmap.c
@@ -274,10 +274,13 @@ static int free_bitmap_clusters(BlockDriverState *bs,
Qcow2BitmapTable *tb)
static uint64_t sectors_covered_by_bitmap_cluster(const BDRVQcow2State *s,
const BdrvDirtyBitmap
*bitmap)
{
- uint32_t sector_granularity =
+ uint64_t sector_granularity =
bdrv_dirty_bitmap_granularity(bitmap) >> BDRV_SECTOR_BITS;
+ uint64_t sbc = sector_granularity * (s->cluster_size << 3);
- return (uint64_t)sector_granularity * (s->cluster_size << 3);
+ assert(QEMU_IS_ALIGNED(sbc,
+ bdrv_dirty_bitmap_serialization_align(bitmap)));
+ return sbc;
}
/* load_bitmap_data
--
2.13.6
- [Qemu-block] [PULL 00/54] Block layer patches, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 01/54] block: Typo fix in copy_on_readv(), Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 04/54] qcow2: Ensure bitmap serialization is aligned,
Kevin Wolf <=
- [Qemu-block] [PULL 02/54] block: Make bdrv_img_create() size selection easier to read, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 03/54] hbitmap: Rename serialization_granularity to serialization_align, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 05/54] dirty-bitmap: Drop unused functions, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 06/54] dirty-bitmap: Avoid size query failure during truncate, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 07/54] dirty-bitmap: Change bdrv_dirty_bitmap_size() to report bytes, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 08/54] dirty-bitmap: Track bitmap size by bytes, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 10/54] qcow2: Switch sectors_covered_by_bitmap_cluster() to byte-based, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 11/54] dirty-bitmap: Set iterator start by offset, not sector, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 09/54] dirty-bitmap: Change bdrv_dirty_bitmap_*serialize*() to take bytes, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 12/54] dirty-bitmap: Change bdrv_dirty_iter_next() to report byte offset, Kevin Wolf, 2017/10/06