iotests: Prepare for refcount_width option

Some tests do not work well with certain refcount widths (i.e. you
cannot create internal snapshots with refcount_width=1), so make those
widths unsupported.

Furthermore, add another filter to _filter_img_create in common.filter
which filters out the refcount_width value.

Signed-off-by: Max Reitz <mreitz@redhat.com>
qcow2: Allow creation with refcount_order != 4

Add a creation option to qcow2 for setting the refcount_order of images
to be created, and respect that options value.

This breaks some test outputs, fix them.

Signed-off-by: Max Reitz <mreitz@redhat.com>
block: Add opaque value to the amend CB

Add an opaque value which is to be passed to the bdrv_amend_options()
status callback.

Signed-off-by: Max Reitz <mreitz@redhat.com>
qcow2: Pull compat < 1.1 check up

Currently, there is only one feature compat=0.10 does not support which
can be set through amend (which is lazy_refcounts); but in a future
patch, the refcount_order will be amendable as well, so introduce a
common place to test whether the option combinations are valid (for now,
this means testing which compat=1.1 features should be enabled although
the image is not compat=1.1 and upgrading it to 1.1 was not requested).

Signed-off-by: Max Reitz <mreitz@redhat.com>
qcow2: Split upgrade/downgrade paths for amend

If the image version should be upgraded, that is the first we should do;
if it should be downgraded, that is the last we should do. So split the
version change block into an upgrade part at the start and a downgrade
part at the end.

Signed-off-by: Max Reitz <mreitz@redhat.com>
qcow2: Use intermediate helper CB for amend

If there is more than one time-consuming operation to be performed for
bdrv_amend_options(), we need an intermediate CB which coordinates the
progress of the individual operations and passes the result to the
original status callback.

Signed-off-by: Max Reitz <mreitz@redhat.com>
qcow2: Add function for refcount order amendment

Add a function qcow2_change_refcount_order() which allows changing the
refcount order of a qcow2 image.

Signed-off-by: Max Reitz <mreitz@redhat.com>
qcow2: Invoke refcount order amendment function

Make use of qcow2_change_refcount_order() to support changing the
refcount order with qemu-img amend.

Signed-off-by: Max Reitz <mreitz@redhat.com>
qcow2: Point at amend function in check

If a reference count is not representable with the current refcount
order, the image check should point at qemu-img amend for increasing the
refcount order. However, qemu-img amend needs write access to the image
which cannot be provided if the image is marked corrupt; and the image
check will not mark the image consistent unless everything actually is
consistent.

Therefore, if an image is marked corrupt and the image check encounters
a reference count overflow, it cannot be fixed by using qemu-img amend
to increase the refcount order. Instead, one has to use qemu-img convert
to create a completely new copy of the image in this case.

Alternatively, we may want to give the user a way of manually removing
the corrupt flag, maybe through qemu-img amend, but this is not part of
this patch.

Signed-off-by: Max Reitz <mreitz@redhat.com>
iotests: Add test for different refcount widths

Add a test for conversion between different refcount widths and errors
specific to certain widths (i.e. snapshots with refcount_width=1).

Signed-off-by: Max Reitz <mreitz@redhat.com>