From patchwork Fri Mar 7 08:20:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 327840 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 4E7C32C0322 for ; Fri, 7 Mar 2014 19:28:04 +1100 (EST) Received: from localhost ([::1]:35158 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLq8Q-0003yi-1j for incoming@patchwork.ozlabs.org; Fri, 07 Mar 2014 03:28:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36751) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLq2a-00005V-Bc for qemu-devel@nongnu.org; Fri, 07 Mar 2014 03:22:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WLq2S-0006v7-Up for qemu-devel@nongnu.org; Fri, 07 Mar 2014 03:22:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35576) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLq2S-0006ur-MO for qemu-devel@nongnu.org; Fri, 07 Mar 2014 03:21:52 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s278LnDT021979 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 7 Mar 2014 03:21:49 -0500 Received: from T430.nay.redhat.com ([10.66.6.152]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s278KfJ2007439; Fri, 7 Mar 2014 03:21:44 -0500 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 7 Mar 2014 16:20:54 +0800 Message-Id: <1394180456-18139-13-git-send-email-famz@redhat.com> In-Reply-To: <1394180456-18139-1-git-send-email-famz@redhat.com> References: <1394180456-18139-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, benoit.canet@irqsave.net, rjones@redhat.com, jcody@redhat.com, armbru@redhat.com, ptoscano@redhat.com, imain@redhat.com, stefanha@redhat.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH v16 12/14] block: Add blockdev-backup to 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 | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ qapi-schema.json | 1 + 2 files changed, 49 insertions(+) diff --git a/blockdev.c b/blockdev.c index 065d0ac..4f2c6f9 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1409,6 +1409,49 @@ static void drive_backup_abort(BlkTransactionState *common) } } +typedef struct BlockdevBackupState { + BlkTransactionState common; + BlockDriverState *bs; + BlockJob *job; +} BlockdevBackupState; + +static void blockdev_backup_prepare(BlkTransactionState *common, Error **errp) +{ + BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common); + BlockdevBackup *backup; + Error *local_err = NULL; + + assert(common->action->kind == TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP); + backup = common->action->blockdev_backup; + + qmp_blockdev_backup(backup->device, backup->target, + backup->sync, + backup->has_speed, backup->speed, + backup->has_on_source_error, backup->on_source_error, + backup->has_on_target_error, backup->on_target_error, + &local_err); + if (error_is_set(&local_err)) { + error_propagate(errp, local_err); + state->bs = NULL; + state->job = NULL; + return; + } + + state->bs = bdrv_find(backup->device); + state->job = state->bs->job; +} + +static void blockdev_backup_abort(BlkTransactionState *common) +{ + BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common); + BlockDriverState *bs = state->bs; + + /* Only cancel if it's the job we started */ + if (bs && bs->job && bs->job == state->job) { + block_job_cancel_sync(bs->job); + } +} + static void abort_prepare(BlkTransactionState *common, Error **errp) { error_setg(errp, "Transaction aborted using Abort action"); @@ -1431,6 +1474,11 @@ static const BdrvActionOps actions[] = { .prepare = drive_backup_prepare, .abort = drive_backup_abort, }, + [TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP] = { + .instance_size = sizeof(BlockdevBackupState), + .prepare = blockdev_backup_prepare, + .abort = blockdev_backup_abort, + }, [TRANSACTION_ACTION_KIND_ABORT] = { .instance_size = sizeof(BlkTransactionState), .prepare = abort_prepare, diff --git a/qapi-schema.json b/qapi-schema.json index adb9d70..d449a55 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1972,6 +1972,7 @@ 'data': { 'blockdev-snapshot-sync': 'BlockdevSnapshot', 'drive-backup': 'DriveBackup', + 'blockdev-backup': 'BlockdevBackup', 'abort': 'Abort', 'blockdev-snapshot-internal-sync': 'BlockdevSnapshotInternal' } }