From patchwork Mon Mar 4 14:02:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 224729 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 23D6E2C030F for ; Tue, 5 Mar 2013 01:05:39 +1100 (EST) Received: from localhost ([::1]:40516 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCW1J-0008Ey-8K for incoming@patchwork.ozlabs.org; Mon, 04 Mar 2013 09:05:37 -0500 Received: from eggs.gnu.org ([208.118.235.92]:40263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCVyX-000450-UV for qemu-devel@nongnu.org; Mon, 04 Mar 2013 09:02:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UCVyV-00065L-2N for qemu-devel@nongnu.org; Mon, 04 Mar 2013 09:02:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59620) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCVyU-00065A-PW for qemu-devel@nongnu.org; Mon, 04 Mar 2013 09:02:42 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r24E2giI020302 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 4 Mar 2013 09:02:42 -0500 Received: from localhost (ovpn-112-24.ams2.redhat.com [10.36.112.24]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r24E2fOR011225; Mon, 4 Mar 2013 09:02:41 -0500 From: Stefan Hajnoczi To: Date: Mon, 4 Mar 2013 15:02:31 +0100 Message-Id: <1362405755-3308-3-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.68 on 10.5.11.23 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 2/6] qcow2: flush refcount cache correctly in qcow2_write_snapshots() 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 Since qcow2 metadata is cached we need to flush the caches, not just the underlying file. Use bdrv_flush(bs) instead of bdrv_flush(bs->file). Also add the error return path when bdrv_flush() fails and move the flush after checking for qcow2_alloc_clusters() failure so that the qcow2_alloc_clusters() error return value takes precedence. Signed-off-by: Stefan Hajnoczi --- block/qcow2-snapshot.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index eb8fcd5..f4719d9 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -180,11 +180,14 @@ static int qcow2_write_snapshots(BlockDriverState *bs) /* Allocate space for the new snapshot list */ snapshots_offset = qcow2_alloc_clusters(bs, snapshots_size); - bdrv_flush(bs->file); offset = snapshots_offset; if (offset < 0) { return offset; } + ret = bdrv_flush(bs); + if (ret < 0) { + return ret; + } /* Write all snapshots to the new list */ for(i = 0; i < s->nb_snapshots; i++) {