From patchwork Wed May 20 06:16:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 474187 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 5DECC1400A0 for ; Wed, 20 May 2015 16:22:09 +1000 (AEST) Received: from localhost ([::1]:50049 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuxOJ-0002Ak-Ah for incoming@patchwork.ozlabs.org; Wed, 20 May 2015 02:22:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34197) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuxJi-0001jp-VW for qemu-devel@nongnu.org; Wed, 20 May 2015 02:17:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YuxJd-0002m2-GK for qemu-devel@nongnu.org; Wed, 20 May 2015 02:17:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44258) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuxJd-0002lk-7s; Wed, 20 May 2015 02:17:17 -0400 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 (8.14.4/8.14.4) with ESMTP id t4K6H95T030191 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 20 May 2015 02:17:09 -0400 Received: from ad.nay.redhat.com (dhcp-14-155.nay.redhat.com [10.66.14.155]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t4K6GHCI026839; Wed, 20 May 2015 02:17:05 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 20 May 2015 14:16:12 +0800 Message-Id: <1432102576-6637-10-git-send-email-famz@redhat.com> In-Reply-To: <1432102576-6637-1-git-send-email-famz@redhat.com> References: <1432102576-6637-1-git-send-email-famz@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: Kevin Wolf , qemu-block@nongnu.org, jcody@redhat.com, armbru@redhat.com, mreitz@redhat.com, Stefan Hajnoczi , amit.shah@redhat.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH v5 09/13] blockdev: Block device IO during external snapshot transaction 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 Signed-off-by: Fam Zheng --- blockdev.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/blockdev.c b/blockdev.c index 7f763d9..923fc90 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1404,6 +1404,7 @@ typedef struct ExternalSnapshotState { BlockDriverState *old_bs; BlockDriverState *new_bs; AioContext *aio_context; + Error *blocker; } ExternalSnapshotState; static void external_snapshot_prepare(BlkTransactionState *common, @@ -1525,6 +1526,9 @@ static void external_snapshot_prepare(BlkTransactionState *common, if (ret != 0) { error_propagate(errp, local_err); } + + error_setg(&state->blocker, "snapshot in progress"); + bdrv_op_block(state->old_bs, BLOCK_OP_TYPE_DEVICE_IO, state->blocker); } static void external_snapshot_commit(BlkTransactionState *common) @@ -1541,8 +1545,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) @@ -1552,6 +1554,17 @@ 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->old_bs) { + bdrv_op_unblock(state->old_bs, BLOCK_OP_TYPE_DEVICE_IO, state->blocker); + error_free(state->blocker); + } if (state->aio_context) { aio_context_release(state->aio_context); } @@ -1716,6 +1729,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),