From patchwork Sat Nov 12 15:56:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 125353 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2B9B91007DA for ; Sun, 13 Nov 2011 03:04:37 +1100 (EST) Received: from localhost ([::1]:57268 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RPFy8-0002A9-Qw for incoming@patchwork.ozlabs.org; Sat, 12 Nov 2011 10:58:12 -0500 Received: from eggs.gnu.org ([140.186.70.92]:59041) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RPFxO-00008W-Ol for qemu-devel@nongnu.org; Sat, 12 Nov 2011 10:57:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RPFxN-0007AO-Ky for qemu-devel@nongnu.org; Sat, 12 Nov 2011 10:57:26 -0500 Received: from cpe-70-123-132-139.austin.res.rr.com ([70.123.132.139]:42196 helo=localhost6.localdomain6) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RPFxN-0007AK-Dc for qemu-devel@nongnu.org; Sat, 12 Nov 2011 10:57:25 -0500 Received: from localhost6.localdomain6 (localhost.localdomain [127.0.0.1]) by localhost6.localdomain6 (8.14.4/8.14.4/Debian-2ubuntu1) with ESMTP id pACFvKkU003318; Sat, 12 Nov 2011 09:57:20 -0600 Received: (from anthony@localhost) by localhost6.localdomain6 (8.14.4/8.14.4/Submit) id pACFvI3f003314; Sat, 12 Nov 2011 09:57:18 -0600 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Sat, 12 Nov 2011 09:56:59 -0600 Message-Id: <1321113420-3252-6-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1321113420-3252-1-git-send-email-aliguori@us.ibm.com> References: <1321113420-3252-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 70.123.132.139 Cc: Kevin Wolf , Lucas Meneghel Rodrigues , Anthony Liguori , Stefan Hajnoczi , Juan Quintela , Avi Kivity Subject: [Qemu-devel] [PATCH 6/7] qcow2: implement bdrv_invalidate_cache 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 We don't reopen the actual file, but instead invoke the close and open routines. We specifically ignore the backing file since it's contents are read-only and therefore immutable. Signed-off-by: Anthony Liguori --- block/qcow2.c | 19 +++++++++++++++++++ block/qcow2.h | 2 ++ 2 files changed, 21 insertions(+), 0 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index e4126b7..b5171e0 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -241,6 +241,7 @@ static int qcow2_open(BlockDriverState *bs, int flags) s->cluster_data = qemu_blockalign(bs, QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size + 512); s->cluster_cache_offset = -1; + s->flags = flags; ret = qcow2_refcount_init(bs); if (ret != 0) { @@ -641,6 +642,22 @@ static void qcow2_close(BlockDriverState *bs) qcow2_refcount_close(bs); } +static void qcow2_invalidate_cache(BlockDriverState *bs) +{ + BDRVQcowState *s = bs->opaque; + int flags = s->flags; + + /* + * Backing files are read-only which makes all of their metadata immutable, + * that means we don't have to worry about reopening them here. + */ + + qcow2_close(bs); + + memset(s, 0, sizeof(BDRVQcowState)); + qcow2_open(bs, flags); +} + /* * Updates the variable length parts of the qcow2 header, i.e. the backing file * name and all extensions. qcow2 was not designed to allow such changes, so if @@ -1278,6 +1295,8 @@ static BlockDriver bdrv_qcow2 = { .bdrv_change_backing_file = qcow2_change_backing_file, + .bdrv_invalidate_cache = qcow2_invalidate_cache, + .create_options = qcow2_create_options, .bdrv_check = qcow2_check, }; diff --git a/block/qcow2.h b/block/qcow2.h index 0734b23..6312cd9 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -127,6 +127,8 @@ typedef struct BDRVQcowState { QCowSnapshot *snapshots; Error *migration_blocker; + + int flags; } BDRVQcowState; /* XXX: use std qcow open function ? */