Received: from eggs.gnu.org ([2001:4830:134:3::10]:44332) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgqyW-0000l7-BL for qemu-devel@nongnu.org; Wed, 22 Oct 2014 04:09:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XgqyQ-00044f-4z for qemu-devel@nongnu.org; Wed, 22 Oct 2014 04:08:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64575) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgqyP-00044a-Tb for qemu-devel@nongnu.org; Wed, 22 Oct 2014 04:08:50 -0400 From: Max Reitz Date: Wed, 22 Oct 2014 10:08:31 +0200 Message-Id: <1413965324-14541-1-git-send-email-mreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v7 00/13] qcow2: Fix image repairing List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , =?UTF-8?q?Beno=C3=AEt=20Canet?= , Stefan Hajnoczi , Max Reitz 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. v7: - Patch 1 (added): Adds qemu_blockalign0() - Patch 5 (added): Converts a pre-existing instance of sizeof(uint16_t) for the in-memory refcount table to sizeof(**refcount_table) [Kevin] - Patch 8 (prev. 6): - INT64_MAX comparison reordered [Kevin] - Use sizeof(**refcount_table) instead of sizeof(uint16_t) [Kevin] - Patch 9 (prev. 7): - Rebase conflict because of sizeof(**refcount_table) - Pull the lonely "if (refcount1 =3D=3D 0)" block up into the other condition blocks regarding refcount1 and refcount2 [Kevin] - Increment res->check_errors in case the refcount structure should be rebuilt [Kevin] - Patch 10 (prev. 8): - Renamed nb_clusters to imrt_nb_clusters in alloc_clusters_imrt(); nowhere else because it's already called nb_clusters in all of the check-related functions [Kevin] - Fixed leaks due to g_try_realloc() by saving the result in a temporary variable before overwriting the "real" pointer [Kevin] - Use sizeof(**refcount_table) instead of sizeof(uint16_t) [Kevin] - Renamed reftable to on_disk_reftable in rebuild_refcount_structure() [Kevin] - One instance of rt instead of reftable was left, fix it [Beno=C3=AEt] - Use qemu_blockalign0() instead of g_malloc() for the on_disk_refblock [Kevin] - Use s->refcount_block_size instead of s->cluster_size / sizeof(uint16_t) - Use bdrv_pwrite() instead of bdrv_write() for writing the reftable [Kevin] - Increment res->check_errors and bail out if the refcount structures need to be rebuilt but errors should not be fixed [Kevin] - Patch 11 (prev. 9): - Use an additional temporary variable for saving and restoring the check result [Kevin] - Keep track of leaks introduced by rebuilding the refcount structure that could not be fixed [Kevin] - Patch 13 (prev. 10): Use hexadecimal numbers (enclosed by $(()), if necessary) [Kevin said it would be possible, so I did it] git-backport-diff against v6: Key: [----] : patches are identical [####] : number of functional differences between upstream/downstream pat= ch [down] : patch is downstream-only The flags [FC] indicate (F)unctional and (C)ontextual differences, respec= tively 001/13:[down] 'block: Add qemu_{,try_}blockalign0()' 002/13:[----] [--] 'qcow2: Calculate refcount block entry count' 003/13:[----] [--] 'qcow2: Fix leaks in dirty images' 004/13:[----] [--] 'qcow2: Split qcow2_check_refcounts()' 005/13:[down] 'qcow2: Use sizeof(**refcount_table)' 006/13:[----] [--] 'qcow2: Pull check_refblocks() up' 007/13:[----] [--] 'qcow2: Reuse refcount table in calculate_refcounts()' 008/13:[0007] [FC] 'qcow2: Fix refcount blocks beyond image end' 009/13:[0012] [FC] 'qcow2: Do not perform potentially damaging repairs' 010/13:[0082] [FC] 'qcow2: Rebuild refcount structure during check' 011/13:[0016] [FC] 'qcow2: Clean up after refcount rebuild' 012/13:[----] [--] 'iotests: Fix test outputs' 013/13:[0034] [FC] 'iotests: Add test for potentially damaging repairs' Max Reitz (13): block: Add qemu_{,try_}blockalign0() qcow2: Calculate refcount block entry count qcow2: Fix leaks in dirty images qcow2: Split qcow2_check_refcounts() qcow2: Use sizeof(**refcount_table) qcow2: Pull check_refblocks() up qcow2: Reuse refcount table in calculate_refcounts() 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.c | 16 + block/qcow2-refcount.c | 706 ++++++++++++++++++++++++++++++++-------= ------ block/qcow2.c | 5 +- block/qcow2.h | 2 + include/block/block.h | 2 + tests/qemu-iotests/039.out | 10 +- tests/qemu-iotests/060.out | 10 +- tests/qemu-iotests/061.out | 18 +- tests/qemu-iotests/108 | 141 +++++++++ tests/qemu-iotests/108.out | 110 +++++++ tests/qemu-iotests/group | 1 + 11 files changed, 815 insertions(+), 206 deletions(-) create mode 100755 tests/qemu-iotests/108 create mode 100644 tests/qemu-iotests/108.out --=20 1.9.3