From patchwork Mon Mar 4 14:02:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 224728 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D52EE2C030F for ; Tue, 5 Mar 2013 01:04:38 +1100 (EST) Received: from localhost ([::1]:38444 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCW0L-00070Z-0C for incoming@patchwork.ozlabs.org; Mon, 04 Mar 2013 09:04:37 -0500 Received: from eggs.gnu.org ([208.118.235.92]:40286) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCVyZ-00049j-T8 for qemu-devel@nongnu.org; Mon, 04 Mar 2013 09:02:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UCVyT-00064Z-59 for qemu-devel@nongnu.org; Mon, 04 Mar 2013 09:02:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33009) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCVyS-00064O-Ul for qemu-devel@nongnu.org; Mon, 04 Mar 2013 09:02:41 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r24E2e8b014775 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 4 Mar 2013 09:02:40 -0500 Received: from localhost (ovpn-112-24.ams2.redhat.com [10.36.112.24]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r24E2dr7030345; Mon, 4 Mar 2013 09:02:39 -0500 From: Stefan Hajnoczi To: Date: Mon, 4 Mar 2013 15:02:30 +0100 Message-Id: <1362405755-3308-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1362405755-3308-1-git-send-email-stefanha@redhat.com> References: <1362405755-3308-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v2 1/6] qcow2: flush refcount cache correctly in alloc_refcount_block() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org update_refcount() affects the refcount cache, it does not write to disk. Therefore bdrv_flush(bs->file) does nothing. We need to flush the refcount cache in order to write out the refcount updates! While we're here also add error returns when qcow2_cache_flush() fails. Signed-off-by: Stefan Hajnoczi --- block/qcow2-refcount.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 55543ed..e8b5d0a 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -201,7 +201,10 @@ static int alloc_refcount_block(BlockDriverState *bs, *refcount_block = NULL; /* We write to the refcount table, so we might depend on L2 tables */ - qcow2_cache_flush(bs, s->l2_table_cache); + ret = qcow2_cache_flush(bs, s->l2_table_cache); + if (ret < 0) { + return ret; + } /* Allocate the refcount block itself and mark it as used */ int64_t new_block = alloc_clusters_noref(bs, s->cluster_size); @@ -237,7 +240,10 @@ static int alloc_refcount_block(BlockDriverState *bs, goto fail_block; } - bdrv_flush(bs->file); + ret = qcow2_cache_flush(bs, s->refcount_block_cache); + if (ret < 0) { + goto fail_block; + } /* Initialize the new refcount block only after updating its refcount, * update_refcount uses the refcount cache itself */