From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=47650 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OI3tK-0003gH-2i for qemu-devel@nongnu.org; Fri, 28 May 2010 14:02:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OI3sh-0002WF-SY for qemu-devel@nongnu.org; Fri, 28 May 2010 14:02:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43953) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OI3sh-0002Vw-ME for qemu-devel@nongnu.org; Fri, 28 May 2010 14:02:03 -0400 From: Kevin Wolf Date: Fri, 28 May 2010 20:01:32 +0200 Message-Id: <1275069692-5756-7-git-send-email-kwolf@redhat.com> In-Reply-To: <1275069692-5756-1-git-send-email-kwolf@redhat.com> References: <1275069692-5756-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [STABLE PATCH 6/6] qcow2: Fix corruption after error in update_refcount List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org 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 (cherry picked from commit 86fa8da83771238de55dc44819a1a27bafef5353) --- block/qcow2-refcount.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index fa78e46..465d5d3 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -402,6 +402,10 @@ static int write_refcount_block_entries(BDRVQcowState *s, return 0; } + if (first_index < 0) { + return 0; + } + first_index &= ~(REFCOUNTS_PER_SECTOR - 1); last_index = (last_index + REFCOUNTS_PER_SECTOR) & ~(REFCOUNTS_PER_SECTOR - 1); -- 1.6.6.1