cow: make reads go at a decent speed

Do not do two reads for each sector; load each sector of the bitmap
and use bitmap operations to process it.

Writes are still dog slow!

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
cow: make writes go at a less indecent speed

Only sync once per write, rather than once per sector.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
cow: do not call bdrv_co_is_allocated

The next patches will make it a bit slower by calling bs->file.  It is
still appropriate for online jobs, but not for reads/writes.  Call the
internal function instead.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: make bdrv_co_is_allocated static

bdrv_is_allocated can detect coroutine context and go through a fast
path, similar to other block layer functions.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: remove bdrv_is_allocated_above/bdrv_co_is_allocated_above distinction

Now that bdrv_is_allocated detects coroutine context, the two can
use the same code.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: introduce bdrv_get_block_status API

For now, bdrv_get_block_status is just another name for bdrv_is_allocated.
The next patches will add more flags.

This also touches all block drivers with a mostly mechanical rename.  The
sole exception is cow; because it calls cow_co_is_allocated from the read
code, we keep that function and make cow_co_get_block_status a wrapper.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: make bdrv_has_zero_init return false for copy-on-write-images

This helps implementing is_allocated on top of get_block_status.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: define get_block_status return value

Define the return value of get_block_status.  Bits 0, 1, 2 and 8-62
are valid; bit 63 (the sign bit) is reserved for errors.  Bits 3-7
are left for future extensions.

The return code is compatible with the old is_allocated API: returning
just 0 or 1 (aka BDRV_BLOCK_DATA) will not cause any behavioral change
in clients of is_allocated.  We will return more precise information
in the next patches.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: use bdrv_has_zero_init to return BDRV_BLOCK_ZERO

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: return get_block_status data and flags for formats

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
raw-posix: return get_block_status data and flags

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
raw-posix: detect XFS unwritten extents

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: add default get_block_status implementation for protocols

Protocols return raw data, so you can assume the offsets to pass
through unchanged.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: look for zero blocks in bs->file

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>