Process a whole sector's worth of COW bits by reading a sector, setting the
bits after skipping
any already set bits, then writing it out again. Make sure we only flush once
before writing
metadata, and only if we need to write metadata.
Signed-off-by: Charlie Shepherd <address@hidden>
---
block/cow.c | 87 ++++++++++++++++++++++++++++++++++---------------------------
1 file changed, 49 insertions(+), 38 deletions(-)
@@ -204,18 +182,51 @@ static int64_t coroutine_fn
cow_co_get_block_status(BlockDriverState *bs,
static int cow_update_bitmap(BlockDriverState *bs, int64_t sector_num,
int nb_sectors)
{
- int error = 0;
- int i;
+ int64_t bitnum = sector_num + sizeof(struct cow_header_v2) * 8;
+ uint64_t offset = (bitnum / 8) & -BDRV_SECTOR_SIZE;
bool first = true;
- for (i = 0; i < nb_sectors; i++) {
- error = cow_set_bit(bs, sector_num + i, &first);
- if (error) {
- break;
+ for ( ; nb_sectors;
+ bitnum += sector_bits,
+ nb_sectors -= sector_bits,
+ offset += BDRV_SECTOR_SIZE) {