As can be seen in the final patch of this series, there are certain cases where the current repair implementation of qcow2 actually damages the image further because it allocates new clusters for the refcount structure which overlap with existing but according to the on-disk refcounts (which are assumed to be wrong to begin with) unallocated clusters.
This series fixes this by completely recreating the refcount structure based on the in-memory information calculated during the check operation if the possibility of damaging the image while repairing the refcount structures in-place exists. Max Reitz (8): qcow2: Factor out refcount accounting for check qcow2: Factor out refcount comparison for check qcow2: Fix refcount blocks beyond image end qcow2: Do not perform potentially damaging repairs qcow2: Rebuild refcount structure during check qcow2: Clean up after refcount rebuild iotests: Fix test outputs iotests: Add test for potentially damaging repairs block/qcow2-refcount.c | 657 +++++++++++++++++++++++++++++++-------------- tests/qemu-iotests/039.out | 10 +- tests/qemu-iotests/060.out | 10 +- tests/qemu-iotests/061.out | 18 +- tests/qemu-iotests/101 | 98 +++++++ tests/qemu-iotests/101.out | 46 ++++ tests/qemu-iotests/group | 1 + 7 files changed, 626 insertions(+), 214 deletions(-) create mode 100755 tests/qemu-iotests/101 create mode 100644 tests/qemu-iotests/101.out -- 2.0.3