[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 10/54] qcow2: Switch sectors_covered_by_bitmap_cluste
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 10/54] qcow2: Switch sectors_covered_by_bitmap_cluster() to byte-based |
Date: |
Fri, 6 Oct 2017 17:53:38 +0200 |
From: Eric Blake <address@hidden>
We are gradually converting to byte-based interfaces, as they are
easier to reason about than sector-based. Change the qcow2 bitmap
helper function sectors_covered_by_bitmap_cluster(), renaming it
to bytes_covered_by_bitmap_cluster() in the process.
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 | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
index 9e799996e6..8324468b16 100644
--- a/block/qcow2-bitmap.c
+++ b/block/qcow2-bitmap.c
@@ -269,18 +269,16 @@ static int free_bitmap_clusters(BlockDriverState *bs,
Qcow2BitmapTable *tb)
return 0;
}
-/* This function returns the number of disk sectors covered by a single qcow2
- * cluster of bitmap data. */
-static uint64_t sectors_covered_by_bitmap_cluster(const BDRVQcow2State *s,
- const BdrvDirtyBitmap
*bitmap)
+/* Return the disk size covered by a single qcow2 cluster of bitmap data. */
+static uint64_t bytes_covered_by_bitmap_cluster(const BDRVQcow2State *s,
+ const BdrvDirtyBitmap *bitmap)
{
- uint64_t sector_granularity =
- bdrv_dirty_bitmap_granularity(bitmap) >> BDRV_SECTOR_BITS;
- uint64_t sbc = sector_granularity * (s->cluster_size << 3);
+ uint64_t granularity = bdrv_dirty_bitmap_granularity(bitmap);
+ uint64_t limit = granularity * (s->cluster_size << 3);
- assert(QEMU_IS_ALIGNED(sbc << BDRV_SECTOR_BITS,
+ assert(QEMU_IS_ALIGNED(limit,
bdrv_dirty_bitmap_serialization_align(bitmap)));
- return sbc;
+ return limit;
}
/* load_bitmap_data
@@ -293,7 +291,7 @@ static int load_bitmap_data(BlockDriverState *bs,
{
int ret = 0;
BDRVQcow2State *s = bs->opaque;
- uint64_t sector, sbc;
+ uint64_t sector, limit, sbc;
uint64_t bm_size = bdrv_dirty_bitmap_size(bitmap);
uint64_t bm_sectors = DIV_ROUND_UP(bm_size, BDRV_SECTOR_SIZE);
uint8_t *buf = NULL;
@@ -306,7 +304,8 @@ static int load_bitmap_data(BlockDriverState *bs,
}
buf = g_malloc(s->cluster_size);
- sbc = sectors_covered_by_bitmap_cluster(s, bitmap);
+ limit = bytes_covered_by_bitmap_cluster(s, bitmap);
+ sbc = limit >> BDRV_SECTOR_BITS;
for (i = 0, sector = 0; i < tab_size; ++i, sector += sbc) {
uint64_t count = MIN(bm_sectors - sector, sbc);
uint64_t entry = bitmap_table[i];
@@ -1080,7 +1079,7 @@ static uint64_t *store_bitmap_data(BlockDriverState *bs,
int ret;
BDRVQcow2State *s = bs->opaque;
int64_t sector;
- uint64_t sbc;
+ uint64_t limit, sbc;
uint64_t bm_size = bdrv_dirty_bitmap_size(bitmap);
uint64_t bm_sectors = DIV_ROUND_UP(bm_size, BDRV_SECTOR_SIZE);
const char *bm_name = bdrv_dirty_bitmap_name(bitmap);
@@ -1106,8 +1105,9 @@ static uint64_t *store_bitmap_data(BlockDriverState *bs,
dbi = bdrv_dirty_iter_new(bitmap, 0);
buf = g_malloc(s->cluster_size);
- sbc = sectors_covered_by_bitmap_cluster(s, bitmap);
- assert(DIV_ROUND_UP(bm_sectors, sbc) == tb_size);
+ limit = bytes_covered_by_bitmap_cluster(s, bitmap);
+ sbc = limit >> BDRV_SECTOR_BITS;
+ assert(DIV_ROUND_UP(bm_size, limit) == tb_size);
while ((sector = bdrv_dirty_iter_next(dbi)) != -1) {
uint64_t cluster = sector / sbc;
--
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, 2017/10/06
- [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 <=
- [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
- [Qemu-block] [PULL 16/54] mirror: Switch mirror_dirty_init() to byte-based iteration, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 15/54] dirty-bitmap: Change bdrv_[re]set_dirty_bitmap() to use bytes, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 13/54] dirty-bitmap: Change bdrv_get_dirty_count() to report bytes, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 17/54] qcow2: Switch qcow2_measure() to byte-based iteration, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 14/54] dirty-bitmap: Change bdrv_get_dirty_locked() to take bytes, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 19/54] qcow2: Switch store_bitmap_data() to byte-based iteration, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 18/54] qcow2: Switch load_bitmap_data() to byte-based iteration, Kevin Wolf, 2017/10/06