From f5a1740117ff0ad0bdce38148e42955eee495982 Mon Sep 17 00:00:00 2001 From: Kevin Wolf <kwolf@redhat.com> Date: Fri, 18 Jun 2010 15:22:28 -0300 Subject: [PATCH 10/18] qcow2: Fix corruption after error in update_refcount RH-Author: Kevin Wolf <kwolf@redhat.com> Message-id: <patch-9985-clone-for-rhel55-rhel55> Patchwork-id: 10043 O-Subject: [RHEL-5.6 KVM PATCH 10/16] qcow2: Fix corruption after error in update_refcount Bugzilla: 612508 RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com> RH-Acked-by: Juan Quintela <quintela@redhat.com> RH-Acked-by: Christoph Hellwig <chellwig@redhat.com> RH-Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com> Bugzilla: 605701 Upstream commit: 86fa8da83771238de55dc44819a1a27bafef5353 After it is done with updating refcounts in the cache, update_refcount writes all changed entries to disk. If a refcount block allocation fails, however, there was no change yet and therefore first_index = last_index = -1. Don't treat -1 as a normal sector index (resulting in a 512 byte write!) but return without updating anything in this case. Signed-off-by: Kevin Wolf <kwolf@redhat.com> --- qemu/block-qcow2.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- qemu/block-qcow2.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/qemu/block-qcow2.c b/qemu/block-qcow2.c index 75c6759..5274f12 100644 --- a/qemu/block-qcow2.c +++ b/qemu/block-qcow2.c @@ -2999,6 +2999,10 @@ static int write_refcount_block_entries(BDRVQcowState *s, size_t size; int ret; + if (first_index < 0) { + return 0; + } + first_index &= ~(REFCOUNTS_PER_SECTOR - 1); last_index = (last_index + REFCOUNTS_PER_SECTOR) & ~(REFCOUNTS_PER_SECTOR - 1); -- 1.7.0.3