From patchwork Thu Jul 21 19:40:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 9242425 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 96DC2602F0 for ; Thu, 21 Jul 2016 19:51:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8661427A98 for ; Thu, 21 Jul 2016 19:51:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A98627D85; Thu, 21 Jul 2016 19:51:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B491D27A98 for ; Thu, 21 Jul 2016 19:51:53 +0000 (UTC) Received: from localhost ([::1]:43344 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQK0e-0003pE-Qn for patchwork-qemu-devel@patchwork.kernel.org; Thu, 21 Jul 2016 15:51:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35829) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQJpk-0002QE-7a for qemu-devel@nongnu.org; Thu, 21 Jul 2016 15:40:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQJph-00014W-QK for qemu-devel@nongnu.org; Thu, 21 Jul 2016 15:40:35 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:46337 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQJpg-0000zS-Q6 for qemu-devel@nongnu.org; Thu, 21 Jul 2016 15:40:33 -0400 Received: from hades.sw.ru ([10.30.8.132]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u6KBAfvg027557; Wed, 20 Jul 2016 14:10:43 +0300 (MSK) From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Thu, 21 Jul 2016 22:40:15 +0300 Message-Id: <1469130019-18497-13-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1469130019-18497-1-git-send-email-den@openvz.org> References: <1469130019-18497-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH v6 12/16] block: simplify blockdev-backup X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Pavel Butsykin , Jeff Cody , Markus Armbruster , Stefan Hajnoczi , den@openvz.org, John Snow Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Pavel Butsykin Now that we can support boxed commands, use it to greatly reduce the number of parameters (and likelihood of getting out of sync) when adjusting blockdev-backup parameters. Signed-off-by: Pavel Butsykin Reviewed-by: Stefan Hajnoczi Signed-off-by: Denis V. Lunev CC: Jeff Cody CC: Markus Armbruster CC: Eric Blake CC: John Snow CC: Stefan Hajnoczi CC: Kevin Wolf --- blockdev.c | 70 +++++++++++++++++----------------------------------- qapi/block-core.json | 6 ++++- 2 files changed, 27 insertions(+), 49 deletions(-) diff --git a/blockdev.c b/blockdev.c index e29147a..0c5ea25 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1906,14 +1906,8 @@ typedef struct BlockdevBackupState { AioContext *aio_context; } BlockdevBackupState; -static void do_blockdev_backup(const char *job_id, const char *device, - const char *target, enum MirrorSyncMode sync, - bool has_speed, int64_t speed, - bool has_on_source_error, - BlockdevOnError on_source_error, - bool has_on_target_error, - BlockdevOnError on_target_error, - BlockJobTxn *txn, Error **errp); +static void do_blockdev_backup(BlockdevBackup *backup, BlockJobTxn *txn, + Error **errp); static void blockdev_backup_prepare(BlkActionState *common, Error **errp) { @@ -1953,12 +1947,7 @@ static void blockdev_backup_prepare(BlkActionState *common, Error **errp) state->bs = blk_bs(blk); bdrv_drained_begin(state->bs); - do_blockdev_backup(backup->has_job_id ? backup->job_id : NULL, - 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, - common->block_job_txn, &local_err); + do_blockdev_backup(backup, common->block_job_txn, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -3275,14 +3264,7 @@ BlockDeviceInfoList *qmp_query_named_block_nodes(Error **errp) return bdrv_named_nodes_list(errp); } -void do_blockdev_backup(const char *job_id, const char *device, - const char *target, enum MirrorSyncMode sync, - bool has_speed, int64_t speed, - bool has_on_source_error, - BlockdevOnError on_source_error, - bool has_on_target_error, - BlockdevOnError on_target_error, - BlockJobTxn *txn, Error **errp) +void do_blockdev_backup(BlockdevBackup *backup, BlockJobTxn *txn, Error **errp) { BlockBackend *blk; BlockDriverState *bs; @@ -3290,19 +3272,22 @@ void do_blockdev_backup(const char *job_id, const char *device, Error *local_err = NULL; AioContext *aio_context; - if (!has_speed) { - speed = 0; + if (!backup->has_speed) { + backup->speed = 0; } - if (!has_on_source_error) { - on_source_error = BLOCKDEV_ON_ERROR_REPORT; + if (!backup->has_on_source_error) { + backup->on_source_error = BLOCKDEV_ON_ERROR_REPORT; } - if (!has_on_target_error) { - on_target_error = BLOCKDEV_ON_ERROR_REPORT; + if (!backup->has_on_target_error) { + backup->on_target_error = BLOCKDEV_ON_ERROR_REPORT; + } + if (!backup->has_job_id) { + backup->job_id = NULL; } - blk = blk_by_name(device); + blk = blk_by_name(backup->device); if (!blk) { - error_setg(errp, "Device '%s' not found", device); + error_setg(errp, "Device '%s' not found", backup->device); return; } @@ -3310,12 +3295,12 @@ void do_blockdev_backup(const char *job_id, const char *device, aio_context_acquire(aio_context); if (!blk_is_available(blk)) { - error_setg(errp, "Device '%s' has no medium", device); + error_setg(errp, "Device '%s' has no medium", backup->device); goto out; } bs = blk_bs(blk); - target_bs = bdrv_lookup_bs(target, target, errp); + target_bs = bdrv_lookup_bs(backup->target, backup->target, errp); if (!target_bs) { goto out; } @@ -3331,8 +3316,9 @@ void do_blockdev_backup(const char *job_id, const char *device, goto out; } } - backup_start(job_id, bs, target_bs, speed, sync, NULL, on_source_error, - on_target_error, block_job_cb, bs, txn, &local_err); + backup_start(backup->job_id, bs, target_bs, backup->speed, backup->sync, + NULL, backup->on_source_error, backup->on_target_error, + block_job_cb, bs, txn, &local_err); if (local_err != NULL) { error_propagate(errp, local_err); } @@ -3340,21 +3326,9 @@ out: aio_context_release(aio_context); } -void qmp_blockdev_backup(bool has_job_id, const char *job_id, - const char *device, const char *target, - enum MirrorSyncMode sync, - bool has_speed, int64_t speed, - bool has_on_source_error, - BlockdevOnError on_source_error, - bool has_on_target_error, - BlockdevOnError on_target_error, - Error **errp) +void qmp_blockdev_backup(BlockdevBackup *arg, Error **errp) { - do_blockdev_backup(has_job_id ? job_id : NULL, device, target, - sync, has_speed, speed, - has_on_source_error, on_source_error, - has_on_target_error, on_target_error, - NULL, errp); + do_blockdev_backup(arg, NULL, errp); } /* Parameter check and block job starting for drive mirroring. diff --git a/qapi/block-core.json b/qapi/block-core.json index 121a540..44cf9c6 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1100,9 +1100,13 @@ # # For the arguments, see the documentation of BlockdevBackup. # +# Returns: nothing on success +# If @device is not a valid block device, DeviceNotFound +# # Since 2.3 ## -{ 'command': 'blockdev-backup', 'data': 'BlockdevBackup' } +{ 'command': 'blockdev-backup', 'boxed': true, + 'data': 'BlockdevBackup' } ##