From patchwork Fri Oct 16 10:12:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 531241 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 F1B90140F93 for ; Fri, 16 Oct 2015 22:43:01 +1100 (AEDT) Received: from localhost ([::1]:52466 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn21F-0007ZX-3I for incoming@patchwork.ozlabs.org; Fri, 16 Oct 2015 06:13:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55506) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn20m-0007Jo-85 for qemu-devel@nongnu.org; Fri, 16 Oct 2015 06:13:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zn20l-0002ZY-9I for qemu-devel@nongnu.org; Fri, 16 Oct 2015 06:13:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52403) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn20f-0002Xy-4m; Fri, 16 Oct 2015 06:13:13 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id B8862319AF1; Fri, 16 Oct 2015 10:13:12 +0000 (UTC) Received: from fam-t430.redhat.com (vpn1-4-198.pek2.redhat.com [10.72.4.198]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9GACOtH006508; Fri, 16 Oct 2015 06:13:03 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 16 Oct 2015 18:12:17 +0800 Message-Id: <1444990343-25109-7-git-send-email-famz@redhat.com> In-Reply-To: <1444990343-25109-1-git-send-email-famz@redhat.com> References: <1444990343-25109-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org Subject: [Qemu-devel] [PATCH v3 06/12] block: Add "drained begin/end" for transactional external snapshot 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 This ensures the atomicity of the transaction by avoiding processing of external requests such as those from ioeventfd. Signed-off-by: Fam Zheng --- blockdev.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/blockdev.c b/blockdev.c index 32b04b4..90f1e15 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1479,6 +1479,7 @@ static void external_snapshot_prepare(BlkTransactionState *common, /* Acquire AioContext now so any threads operating on old_bs stop */ state->aio_context = bdrv_get_aio_context(state->old_bs); aio_context_acquire(state->aio_context); + bdrv_drained_begin(state->old_bs); if (!bdrv_is_inserted(state->old_bs)) { error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); @@ -1548,8 +1549,6 @@ static void external_snapshot_commit(BlkTransactionState *common) * don't want to abort all of them if one of them fails the reopen */ bdrv_reopen(state->new_bs, state->new_bs->open_flags & ~BDRV_O_RDWR, NULL); - - aio_context_release(state->aio_context); } static void external_snapshot_abort(BlkTransactionState *common) @@ -1559,7 +1558,14 @@ static void external_snapshot_abort(BlkTransactionState *common) if (state->new_bs) { bdrv_unref(state->new_bs); } +} + +static void external_snapshot_clean(BlkTransactionState *common) +{ + ExternalSnapshotState *state = + DO_UPCAST(ExternalSnapshotState, common, common); if (state->aio_context) { + bdrv_drained_end(state->old_bs); aio_context_release(state->aio_context); } } @@ -1724,6 +1730,7 @@ static const BdrvActionOps actions[] = { .prepare = external_snapshot_prepare, .commit = external_snapshot_commit, .abort = external_snapshot_abort, + .clean = external_snapshot_clean, }, [TRANSACTION_ACTION_KIND_DRIVE_BACKUP] = { .instance_size = sizeof(DriveBackupState),