From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57352) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzOGb-0004Q9-AB for qemu-devel@nongnu.org; Wed, 17 Jul 2013 05:43:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UzOGY-0007xJ-FC for qemu-devel@nongnu.org; Wed, 17 Jul 2013 05:43:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50249) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzOGY-0007x9-8i for qemu-devel@nongnu.org; Wed, 17 Jul 2013 05:43:22 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6H9hLHI030362 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 17 Jul 2013 05:43:21 -0400 From: Fam Zheng Date: Wed, 17 Jul 2013 17:42:16 +0800 Message-Id: <1374054136-28741-12-git-send-email-famz@redhat.com> In-Reply-To: <1374054136-28741-1-git-send-email-famz@redhat.com> References: <1374054136-28741-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH v2 11/11] qmp: add command 'blockdev-backup' List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, famz@redhat.com, hbrock@redhat.com, rjones@redhat.com, imain@redhat.com, stefanha@redhat.com, pbonzini@redhat.com Similar to drive-backup, but this command uses a device id as target instead of creating/opening an image file. Signed-off-by: Fam Zheng --- blockdev.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ qapi-schema.json | 49 ++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 22 ++++++++++++++++++ 3 files changed, 142 insertions(+) diff --git a/blockdev.c b/blockdev.c index bb986a1..a3fa5d1 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1517,7 +1517,78 @@ void qmp_drive_backup(const char *device, const char *target, error_propagate(errp, local_err); return; } + /* Grab a reference so hotplug does not delete the BlockDriverState from + * underneath us. + */ + drive_get_ref(drive_get_by_blockdev(bs)); +} + +void qmp_blockdev_backup(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) +{ + BlockDriverState *bs; + BlockDriverState *target_bs; + Error *local_err = NULL; + + if (sync != MIRROR_SYNC_MODE_FULL) { + error_setg(errp, "only sync mode 'full' is currently supported"); + return; + } + if (!has_speed) { + speed = 0; + } + if (!has_on_source_error) { + on_source_error = BLOCKDEV_ON_ERROR_REPORT; + } + if (!has_on_target_error) { + on_target_error = BLOCKDEV_ON_ERROR_REPORT; + } + + bs = bdrv_find(device); + if (!bs) { + error_set(errp, QERR_DEVICE_NOT_FOUND, device); + return; + } + + if (!bdrv_is_inserted(bs)) { + error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); + return; + } + + if (bdrv_in_use(bs)) { + error_set(errp, QERR_DEVICE_IN_USE, device); + return; + } + + target_bs = bdrv_find(target); + if (!target_bs) { + error_set(errp, QERR_DEVICE_NOT_FOUND, target); + return; + } + + if (!bdrv_is_inserted(target_bs)) { + error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, target); + return; + } + + if (bdrv_in_use(target_bs)) { + error_set(errp, QERR_DEVICE_IN_USE, target); + return; + } + backup_start(bs, target_bs, speed, on_source_error, on_target_error, + block_job_cb, bs, &local_err); + if (local_err != NULL) { + bdrv_delete(target_bs); + error_propagate(errp, local_err); + return; + } /* Grab a reference so hotplug does not delete the BlockDriverState from * underneath us. */ diff --git a/qapi-schema.json b/qapi-schema.json index 7b9fef1..3b7cfcc 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1665,6 +1665,40 @@ '*on-target-error': 'BlockdevOnError' } } ## +# @BlockdevBackup +# +# @device: the name of the device which should be copied. +# +# @target: the name of the backup target device +# +# @sync: what parts of the disk image should be copied to the destination +# (all the disk, only the sectors allocated in the topmost image, or +# only new I/O). +# +# @speed: #optional the maximum speed, in bytes per second +# +# @on-source-error: #optional the action to take on an error on the source, +# default 'report'. 'stop' and 'enospc' can only be used +# if the block device supports io-status (see BlockInfo). +# +# @on-target-error: #optional the action to take on an error on the target, +# default 'report' (no limitations, since this applies to +# a different block device than @device). +# +# Note that @on-source-error and @on-target-error only affect background I/O. +# If an error occurs during a guest write request, the device's rerror/werror +# actions will be used. +# +# Since: 1.6 +## +{ 'type': 'BlockdevBackup', + 'data': { 'device': 'str', 'target': 'str', + 'sync': 'MirrorSyncMode', + '*speed': 'int', + '*on-source-error': 'BlockdevOnError', + '*on-target-error': 'BlockdevOnError' } } + +## # @Abort # # This action can be used to test transaction failure. @@ -1806,6 +1840,21 @@ { 'command': 'drive-backup', 'data': 'DriveBackup' } ## +# @blockdev-backup +# +# Block device version for drive-backup command. Use existing device as target +# of backup. +# +# For the arguments, see the documentation of BlockdevBackup. +# +# Returns: nothing on success +# If @device or @target is not a valid block device, DeviceNotFound +# +# Since 1.6 +## +{ 'command': 'blockdev-backup', 'data': 'BlockdevBackup' } + +## # @drive-mirror # # Start mirroring a block device's writes to a new destination. diff --git a/qmp-commands.hx b/qmp-commands.hx index e075df4..ecd9f64 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -959,6 +959,28 @@ Example: -> { "execute": "drive-backup", "arguments": { "device": "drive0", "target": "backup.img" } } <- { "return": {} } + +EQMP + + { + .name = "blockdev-backup", + .args_type = "sync:s,device:B,target:B,speed:i?," + "on-source-error:s?,on-target-error:s?", + .mhandler.cmd_new = qmp_marshal_input_blockdev_backup, + }, + +SQMP +blockdev-backup +------------ + +The device version of drive-backup: this command doesn't create new image for +target, instead it uses a existing named device as target. + +Example: +-> { "execute": "blockdev-backup", "arguments": { "device": "drive0", + "target": "drive1" } } +<- { "return": {} } + EQMP { -- 1.8.3.2