From patchwork Wed Jan 13 16:37:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 567056 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A00E7140BAB for ; Thu, 14 Jan 2016 03:39:48 +1100 (AEDT) Received: from localhost ([::1]:38130 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJOSY-0004jV-Ho for incoming@patchwork.ozlabs.org; Wed, 13 Jan 2016 11:39:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59197) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJOQY-0000OS-Gd for qemu-devel@nongnu.org; Wed, 13 Jan 2016 11:37:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aJOQX-0001sz-IR for qemu-devel@nongnu.org; Wed, 13 Jan 2016 11:37:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49490) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJOQV-0001pp-HW; Wed, 13 Jan 2016 11:37:39 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 2ED84A452B; Wed, 13 Jan 2016 16:37:39 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-117.ams2.redhat.com [10.36.116.117]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0DGbN1L027066; Wed, 13 Jan 2016 11:37:37 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 13 Jan 2016 17:37:14 +0100 Message-Id: <1452703036-17999-8-git-send-email-kwolf@redhat.com> In-Reply-To: <1452703036-17999-1-git-send-email-kwolf@redhat.com> References: <1452703036-17999-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Subject: [Qemu-devel] [PATCH v2 7/9] qcow2: Implement .bdrv_inactivate 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 The callback has to ensure that closing or flushing the image afterwards wouldn't cause a write access to the image files. This means that just the caches have to be written out, which is part of the existing .bdrv_close implementation. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- block/qcow2.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 9e4abf3..519e2ae 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1685,6 +1685,32 @@ fail: return ret; } +static int qcow2_inactivate(BlockDriverState *bs) +{ + BDRVQcow2State *s = bs->opaque; + int ret, result = 0; + + ret = qcow2_cache_flush(bs, s->l2_table_cache); + if (ret) { + result = ret; + error_report("Failed to flush the L2 table cache: %s", + strerror(-ret)); + } + + ret = qcow2_cache_flush(bs, s->refcount_block_cache); + if (ret) { + result = ret; + error_report("Failed to flush the refcount block cache: %s", + strerror(-ret)); + } + + if (result == 0) { + qcow2_mark_clean(bs); + } + + return result; +} + static void qcow2_close(BlockDriverState *bs) { BDRVQcow2State *s = bs->opaque; @@ -1693,23 +1719,7 @@ static void qcow2_close(BlockDriverState *bs) s->l1_table = NULL; if (!(bs->open_flags & BDRV_O_INACTIVE)) { - int ret1, ret2; - - ret1 = qcow2_cache_flush(bs, s->l2_table_cache); - ret2 = qcow2_cache_flush(bs, s->refcount_block_cache); - - if (ret1) { - error_report("Failed to flush the L2 table cache: %s", - strerror(-ret1)); - } - if (ret2) { - error_report("Failed to flush the refcount block cache: %s", - strerror(-ret2)); - } - - if (!ret1 && !ret2) { - qcow2_mark_clean(bs); - } + qcow2_inactivate(bs); } cache_clean_timer_del(bs); @@ -3340,6 +3350,7 @@ BlockDriver bdrv_qcow2 = { .bdrv_refresh_limits = qcow2_refresh_limits, .bdrv_invalidate_cache = qcow2_invalidate_cache, + .bdrv_inactivate = qcow2_inactivate, .create_opts = &qcow2_create_opts, .bdrv_check = qcow2_check,