On 12/12/2012 06:46 AM, Paolo Bonzini wrote:
> Signed-off-by: Paolo Bonzini <pbonz...@redhat.com>
> ---
>  block.c     | 133 
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  block.h     |   5 +++
>  block_int.h |   5 +++
>  3 files changed, 141 insertions(+), 2 deletions(-)
> 

> +void bdrv_enable_persistent_dirty_tracking(BlockDriverState *bs, const char 
> *file,
> +                                           Error **errp)
> +{
> +    int rc;
> +    int granularity_bits;
> +    int64_t bitmap_size;
> +    size_t file_size;
> +    QEMUMmapArea mm;
> +    HBitmap *new_bitmap;
> +    bool load;
> +
> +    assert(bs->dirty_usage > 0);
> +
> +    granularity_bits = hbitmap_granularity(bs->dirty_bitmap);
> +    bitmap_size = (bdrv_getlength(bs) >> BDRV_SECTOR_BITS);
> +    file_size = hbitmap_required_size(bitmap_size, granularity_bits);
> +
> +    load = access(file, R_OK) >= 0;
> +    if (bdrv_in_use(bs) && load) {
> +        error_set(errp, QERR_DEVICE_IN_USE, bdrv_get_device_name(bs));
> +        return;
> +    }
> +
> +    /*
> +     * Do not touch fields in BS until we're sure we can complete
> +     * successfully.
> +     */
> +    rc = qemu_mmap_alloc(&mm, file, file_size);
> +    if (rc < 0) {
> +        error_set(errp, QERR_OPEN_FILE_FAILED, file);
> +        return;
> +    }
> +
> +    new_bitmap = hbitmap_alloc_with_data(bitmap_size, granularity_bits, 
> mm.mem);
> +    if (!load) {
> +        hbitmap_copy(new_bitmap, bs->dirty_bitmap);

Here's where my comment earlier in the series, about
hbitmap_alloc_with_data repopulating the upper layers of the hbitmap on
reused data, becomes essential.  But since that fix is earlier in the
series, and I didn't see anything else suspicious in this patch, you can
add:

Reviewed-by: Eric Blake <ebl...@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to