From patchwork Thu Jan 7 22:57:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 564510 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 97A231401DE for ; Fri, 8 Jan 2016 10:08:12 +1100 (AEDT) Received: from localhost ([::1]:33252 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aHJf8-000196-B0 for incoming@patchwork.ozlabs.org; Thu, 07 Jan 2016 18:08:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49126) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aHJWA-0008Oz-52 for qemu-devel@nongnu.org; Thu, 07 Jan 2016 17:58:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aHJW8-00049H-RD for qemu-devel@nongnu.org; Thu, 07 Jan 2016 17:58:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46017) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aHJW6-000481-9n; Thu, 07 Jan 2016 17:58:50 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id D20EDE7094; Thu, 7 Jan 2016 22:58:49 +0000 (UTC) Received: from localhost (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u07MwlLU002091 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 7 Jan 2016 17:58:49 -0500 From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 7 Jan 2016 23:57:32 +0100 Message-Id: <1452207455-10806-19-git-send-email-mreitz@redhat.com> In-Reply-To: <1452207455-10806-1-git-send-email-mreitz@redhat.com> References: <1452207455-10806-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Fam Zheng , qemu-devel@nongnu.org, Max Reitz Subject: [Qemu-devel] [PULL 18/21] block: Extract blockdev part of qmp_drive_mirror 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 From: Fam Zheng This is the part that will be reused by blockdev-mirror. Signed-off-by: Fam Zheng Reviewed-by: Max Reitz Message-id: 1450932306-13717-3-git-send-email-famz@redhat.com Signed-off-by: Max Reitz --- blockdev.c | 114 ++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 42 deletions(-) diff --git a/blockdev.c b/blockdev.c index bd6f68e..22e06ba 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3291,29 +3291,23 @@ void qmp_blockdev_backup(const char *device, const char *target, NULL, errp); } -void qmp_drive_mirror(const char *device, const char *target, - bool has_format, const char *format, - bool has_node_name, const char *node_name, - bool has_replaces, const char *replaces, - enum MirrorSyncMode sync, - bool has_mode, enum NewImageMode mode, - bool has_speed, int64_t speed, - bool has_granularity, uint32_t granularity, - bool has_buf_size, int64_t buf_size, - bool has_on_source_error, BlockdevOnError on_source_error, - bool has_on_target_error, BlockdevOnError on_target_error, - bool has_unmap, bool unmap, - Error **errp) +/* Parameter check and block job starting for drive mirroring. + * Caller should hold @device and @target's aio context (must be the same). + **/ +static void blockdev_mirror_common(BlockDriverState *bs, + BlockDriverState *target, + bool has_replaces, const char *replaces, + enum MirrorSyncMode sync, + bool has_speed, int64_t speed, + bool has_granularity, uint32_t granularity, + bool has_buf_size, int64_t buf_size, + bool has_on_source_error, + BlockdevOnError on_source_error, + bool has_on_target_error, + BlockdevOnError on_target_error, + bool has_unmap, bool unmap, + Error **errp) { - BlockBackend *blk; - BlockDriverState *bs; - BlockDriverState *source, *target_bs; - AioContext *aio_context; - Error *local_err = NULL; - QDict *options; - int flags; - int64_t size; - int ret; if (!has_speed) { speed = 0; @@ -3324,9 +3318,6 @@ void qmp_drive_mirror(const char *device, const char *target, if (!has_on_target_error) { on_target_error = BLOCKDEV_ON_ERROR_REPORT; } - if (!has_mode) { - mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS; - } if (!has_granularity) { granularity = 0; } @@ -3348,6 +3339,48 @@ void qmp_drive_mirror(const char *device, const char *target, return; } + if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_MIRROR_SOURCE, errp)) { + return; + } + + if (!bs->backing && sync == MIRROR_SYNC_MODE_TOP) { + sync = MIRROR_SYNC_MODE_FULL; + } + + /* pass the node name to replace to mirror start since it's loose coupling + * and will allow to check whether the node still exist at mirror completion + */ + mirror_start(bs, target, + has_replaces ? replaces : NULL, + speed, granularity, buf_size, sync, + on_source_error, on_target_error, unmap, + block_job_cb, bs, errp); +} + +void qmp_drive_mirror(const char *device, const char *target, + bool has_format, const char *format, + bool has_node_name, const char *node_name, + bool has_replaces, const char *replaces, + enum MirrorSyncMode sync, + bool has_mode, enum NewImageMode mode, + bool has_speed, int64_t speed, + bool has_granularity, uint32_t granularity, + bool has_buf_size, int64_t buf_size, + bool has_on_source_error, BlockdevOnError on_source_error, + bool has_on_target_error, BlockdevOnError on_target_error, + bool has_unmap, bool unmap, + Error **errp) +{ + BlockDriverState *bs; + BlockBackend *blk; + BlockDriverState *source, *target_bs; + AioContext *aio_context; + Error *local_err = NULL; + QDict *options = NULL; + int flags; + int64_t size; + int ret; + blk = blk_by_name(device); if (!blk) { error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, @@ -3363,15 +3396,14 @@ void qmp_drive_mirror(const char *device, const char *target, goto out; } bs = blk_bs(blk); + if (!has_mode) { + mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS; + } if (!has_format) { format = mode == NEW_IMAGE_MODE_EXISTING ? NULL : bs->drv->format_name; } - if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_MIRROR_SOURCE, errp)) { - goto out; - } - flags = bs->open_flags | BDRV_O_RDWR; source = backing_bs(bs); if (!source && sync == MIRROR_SYNC_MODE_TOP) { @@ -3466,21 +3498,19 @@ void qmp_drive_mirror(const char *device, const char *target, bdrv_set_aio_context(target_bs, aio_context); - /* pass the node name to replace to mirror start since it's loose coupling - * and will allow to check whether the node still exist at mirror completion - */ - mirror_start(bs, target_bs, - has_replaces ? replaces : NULL, - speed, granularity, buf_size, sync, - on_source_error, on_target_error, - unmap, - block_job_cb, bs, &local_err); - if (local_err != NULL) { - bdrv_unref(target_bs); + blockdev_mirror_common(bs, target_bs, + has_replaces, replaces, sync, + has_speed, speed, + has_granularity, granularity, + has_buf_size, buf_size, + has_on_source_error, on_source_error, + has_on_target_error, on_target_error, + has_unmap, unmap, + &local_err); + if (local_err) { error_propagate(errp, local_err); - goto out; + bdrv_unref(target_bs); } - out: aio_context_release(aio_context); }