qmp: Add block-dirty-bitmap-add and block-dirty-bitmap-remove

The new command pair is added to manage user created dirty bitmap. The
dirty bitmap's name is mandatory and must be unique for the same device,
but different devices can have bitmaps with the same names.

The granularity is an optional field. If it is not specified, we will
choose a default granularity based on the cluster size if available,
clamped to between 4K and 64K (To mirror how the 'mirror' code was
already choosing granularity.) If we do not have cluster size info
available, we choose 64K. This code has been factored out into helper
shared with block/mirror.

The types added to block-core.json will be re-used in future patches
in this series, see:
'qapi: Add transaction support to block-dirty-bitmap-{add, enable, disable}'

Signed-off-by: Fam Zheng <famz@redhat.com>
block: Introduce bdrv_dirty_bitmap_granularity()

This returns the granularity (in bytes) of dirty bitmap,
which matches the QMP interface and the existing query
interface.

Signed-off-by: Fam Zheng <famz@redhat.com>
hbitmap: Add hbitmap_copy

This makes a deep copy of an HBitmap.

Signed-off-by: Fam Zheng <famz@redhat.com>
block: Add bdrv_copy_dirty_bitmap and bdrv_reset_dirty_bitmap

Signed-off-by: Fam Zheng <famz@redhat.com>
qmp: Add block-dirty-bitmap-enable and block-dirty-bitmap-disable

This allows to put the dirty bitmap into a disabled state where no more
writes will be tracked.

It will be used before backup or writing to persistent file.

Signed-off-by: Fam Zheng <famz@redhat.com>
qmp: Add support of "dirty-bitmap" sync mode for drive-backup

For "dirty-bitmap" sync mode, the block job will iterate through the
given dirty bitmap to decide if a sector needs backup (backup all the
dirty clusters and skip clean ones), just as allocation conditions of
"top" sync mode.

There are two bitmap use modes for sync=dirty-bitmap:

 - reset: backup job makes a copy of bitmap and resets the original
   one.
 - consume: backup job makes the original anonymous (invisible to user)
   and releases it after use.

Signed-off-by: Fam Zheng <famz@redhat.com>
qapi: Add transaction support to block-dirty-bitmap-{add, enable, disable}

This adds three qmp commands to transactions.

Users can stop a dirty bitmap, start backup of it, and start another
dirty bitmap atomically, so that the dirty bitmap is tracked
incrementally and we don't miss any write.

Signed-off-by: Fam Zheng <famz@redhat.com>
qmp: Add dirty bitmap 'enabled' field in query-block

Signed-off-by: Fam Zheng <famz@redhat.com>
qemu-iotests: Add tests for drive-backup sync=dirty-bitmap

Signed-off-by: Fam Zheng <famz@redhat.com>