Message ID | 1478715476-132280-7-git-send-email-vsementsov@virtuozzo.com |
---|---|
State | New |
Headers | show |
On 11/09/2016 01:17 PM, Vladimir Sementsov-Ogievskiy wrote: > Add bdrv_dirty_bitmap_deserialize_ones() function, which is needed for > qcow2 bitmap loading, to handle unallocated bitmap parts, marked as > all-ones. > > Reviewed-by: Kevin Wolf <kwolf@redhat.com> > Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> It's odd to have the S-o-B below the R-B, but likely not truly important. Reviewed-by: John Snow <jsnow@redhat.com> > --- > block/dirty-bitmap.c | 7 +++++++ > include/block/dirty-bitmap.h | 3 +++ > include/qemu/hbitmap.h | 15 +++++++++++++++ > util/hbitmap.c | 17 +++++++++++++++++ > 4 files changed, 42 insertions(+) > > diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c > index 186941c..90af372 100644 > --- a/block/dirty-bitmap.c > +++ b/block/dirty-bitmap.c > @@ -499,6 +499,13 @@ void bdrv_dirty_bitmap_deserialize_zeroes(BdrvDirtyBitmap *bitmap, > hbitmap_deserialize_zeroes(bitmap->bitmap, start, count, finish); > } > > +void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *bitmap, > + uint64_t start, uint64_t count, > + bool finish) > +{ > + hbitmap_deserialize_ones(bitmap->bitmap, start, count, finish); > +} > + > void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap) > { > hbitmap_deserialize_finish(bitmap->bitmap); > diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h > index 7cbe623..1e17729 100644 > --- a/include/block/dirty-bitmap.h > +++ b/include/block/dirty-bitmap.h > @@ -70,6 +70,9 @@ void bdrv_dirty_bitmap_deserialize_part(BdrvDirtyBitmap *bitmap, > void bdrv_dirty_bitmap_deserialize_zeroes(BdrvDirtyBitmap *bitmap, > uint64_t start, uint64_t count, > bool finish); > +void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *bitmap, > + uint64_t start, uint64_t count, > + bool finish); > void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap); > > #endif > diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h > index 594f6f8..5c9dd74 100644 > --- a/include/qemu/hbitmap.h > +++ b/include/qemu/hbitmap.h > @@ -216,6 +216,21 @@ void hbitmap_deserialize_zeroes(HBitmap *hb, uint64_t start, uint64_t count, > bool finish); > > /** > + * hbitmap_deserialize_ones > + * @hb: HBitmap to operate on. > + * @start: First bit to restore. > + * @count: Number of bits to restore. > + * @finish: Whether to call hbitmap_deserialize_finish automatically. > + * > + * Fills the bitmap with ones. > + * > + * If @finish is false, caller must call hbitmap_serialize_finish before using > + * the bitmap. > + */ > +void hbitmap_deserialize_ones(HBitmap *hb, uint64_t start, uint64_t count, > + bool finish); > + > +/** > * hbitmap_deserialize_finish > * @hb: HBitmap to operate on. > * > diff --git a/util/hbitmap.c b/util/hbitmap.c > index 48d8b2d..72623f4 100644 > --- a/util/hbitmap.c > +++ b/util/hbitmap.c > @@ -531,6 +531,23 @@ void hbitmap_deserialize_zeroes(HBitmap *hb, uint64_t start, uint64_t count, > } > } > > +void hbitmap_deserialize_ones(HBitmap *hb, uint64_t start, uint64_t count, > + bool finish) > +{ > + uint64_t el_count; > + unsigned long *first; > + > + if (!count) { > + return; > + } > + serialization_chunk(hb, start, count, &first, &el_count); > + > + memset(first, 0xff, el_count * sizeof(unsigned long)); > + if (finish) { > + hbitmap_deserialize_finish(hb); > + } > +} > + > void hbitmap_deserialize_finish(HBitmap *bitmap) > { > int64_t i, size, prev_size; >
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 186941c..90af372 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -499,6 +499,13 @@ void bdrv_dirty_bitmap_deserialize_zeroes(BdrvDirtyBitmap *bitmap, hbitmap_deserialize_zeroes(bitmap->bitmap, start, count, finish); } +void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *bitmap, + uint64_t start, uint64_t count, + bool finish) +{ + hbitmap_deserialize_ones(bitmap->bitmap, start, count, finish); +} + void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap) { hbitmap_deserialize_finish(bitmap->bitmap); diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 7cbe623..1e17729 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -70,6 +70,9 @@ void bdrv_dirty_bitmap_deserialize_part(BdrvDirtyBitmap *bitmap, void bdrv_dirty_bitmap_deserialize_zeroes(BdrvDirtyBitmap *bitmap, uint64_t start, uint64_t count, bool finish); +void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *bitmap, + uint64_t start, uint64_t count, + bool finish); void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap); #endif diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index 594f6f8..5c9dd74 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -216,6 +216,21 @@ void hbitmap_deserialize_zeroes(HBitmap *hb, uint64_t start, uint64_t count, bool finish); /** + * hbitmap_deserialize_ones + * @hb: HBitmap to operate on. + * @start: First bit to restore. + * @count: Number of bits to restore. + * @finish: Whether to call hbitmap_deserialize_finish automatically. + * + * Fills the bitmap with ones. + * + * If @finish is false, caller must call hbitmap_serialize_finish before using + * the bitmap. + */ +void hbitmap_deserialize_ones(HBitmap *hb, uint64_t start, uint64_t count, + bool finish); + +/** * hbitmap_deserialize_finish * @hb: HBitmap to operate on. * diff --git a/util/hbitmap.c b/util/hbitmap.c index 48d8b2d..72623f4 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -531,6 +531,23 @@ void hbitmap_deserialize_zeroes(HBitmap *hb, uint64_t start, uint64_t count, } } +void hbitmap_deserialize_ones(HBitmap *hb, uint64_t start, uint64_t count, + bool finish) +{ + uint64_t el_count; + unsigned long *first; + + if (!count) { + return; + } + serialization_chunk(hb, start, count, &first, &el_count); + + memset(first, 0xff, el_count * sizeof(unsigned long)); + if (finish) { + hbitmap_deserialize_finish(hb); + } +} + void hbitmap_deserialize_finish(HBitmap *bitmap) { int64_t i, size, prev_size;