Message ID | 1383740591-27739-4-git-send-email-charlie@ctshepherd.com |
---|---|
State | New |
Headers | show |
Il 06/11/2013 13:23, Charlie Shepherd ha scritto: > + set = cow_find_streak(bitmap, 1, bitnum, sector_bits); > + if (set == sector_bits) { > + continue; I think this shouldn't be a continue; these lines should be executed: bitnum += sector_bits; nb_sectors -= sector_bits; offset += BDRV_SECTOR_SIZE; > + } > + bitnum += set; Here you're adjusting bitnum but not nb_sectors and sector_bits. Paolo
On 06/11/2013 12:29, Paolo Bonzini wrote: > Il 06/11/2013 13:23, Charlie Shepherd ha scritto: >> + set = cow_find_streak(bitmap, 1, bitnum, sector_bits); >> + if (set == sector_bits) { >> + continue; > I think this shouldn't be a continue; these lines should be executed: > > bitnum += sector_bits; > nb_sectors -= sector_bits; > offset += BDRV_SECTOR_SIZE; Good point, this is basically a poor man's for-loop. I'll turn it into a for loop then continue will make sense here. >> + } >> + bitnum += set; > Here you're adjusting bitnum but not nb_sectors and sector_bits. Good catch. Charlie
diff --git a/block/cow.c b/block/cow.c index 4a081cb..d7d992b 100644 --- a/block/cow.c +++ b/block/cow.c @@ -203,7 +203,7 @@ static int cow_update_bitmap(BlockDriverState *bs, int64_t sector_num, bool first = true; while (nb_sectors) { - int ret; + int ret, set; uint8_t bitmap[BDRV_SECTOR_SIZE]; bitnum &= BITS_PER_BITMAP_SECTOR - 1; @@ -214,6 +214,13 @@ static int cow_update_bitmap(BlockDriverState *bs, int64_t sector_num, return ret; } + /* Skip over any already set bits */ + set = cow_find_streak(bitmap, 1, bitnum, sector_bits); + if (set == sector_bits) { + continue; + } + bitnum += set; + if (first) { ret = bdrv_flush(bs->file); if (ret < 0) {
Rather than unnecessarily setting bits that are already set, re-use cow_find_streak to find how many bits are already set for this sector, and only set unset bits. Do this before the flush to avoid it if no bits need to be set at all. Signed-off-by: Charlie Shepherd <charlie@ctshepherd.com> --- block/cow.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)