From patchwork Tue Mar 6 17:56:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 144980 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4D376B6F62 for ; Wed, 7 Mar 2012 05:26:19 +1100 (EST) Received: from localhost ([::1]:43706 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4ye0-0001Lk-I6 for incoming@patchwork.ozlabs.org; Tue, 06 Mar 2012 12:57:52 -0500 Received: from eggs.gnu.org ([208.118.235.92]:56750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4ydF-00084c-5L for qemu-devel@nongnu.org; Tue, 06 Mar 2012 12:57:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S4yd2-0002Hd-Kw for qemu-devel@nongnu.org; Tue, 06 Mar 2012 12:57:04 -0500 Received: from mail-iy0-f173.google.com ([209.85.210.173]:50703) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4yd2-00029J-DV for qemu-devel@nongnu.org; Tue, 06 Mar 2012 12:56:52 -0500 Received: by mail-iy0-f173.google.com with SMTP id j26so7948148iaf.4 for ; Tue, 06 Mar 2012 09:56:51 -0800 (PST) Received-SPF: pass (google.com: domain of paolo.bonzini@gmail.com designates 10.50.41.161 as permitted sender) client-ip=10.50.41.161; Authentication-Results: mr.google.com; spf=pass (google.com: domain of paolo.bonzini@gmail.com designates 10.50.41.161 as permitted sender) smtp.mail=paolo.bonzini@gmail.com; dkim=pass header.i=paolo.bonzini@gmail.com Received: from mr.google.com ([10.50.41.161]) by 10.50.41.161 with SMTP id g1mr11429235igl.5.1331056611635 (num_hops = 1); Tue, 06 Mar 2012 09:56:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=uS4wrxNyxKw1p9gSFRtnX7jakzNyxYLDICWDQqtXckY=; b=QLlX7dWbRnoobfWgdOMzQNAkmq49FZrjNRU/358ZITfmzmfbxHKDSs1IKFAPN50NxH gs51DRoJJnv4z+8qf1kA2Jj8VLUF5iJEGCXMNVu+aqp5lNWor1ZxEYiiUyZwtku6Rqz3 Op0m8jXaSQ2LT/7DpBGG0N6anx640MkfW1XvuXJ13BDW35VPCNemIWcNRzLk0TN6y26V jE0X5dmucAef88hcWeof00R6sNpxGt4yCtOhtbzSXYwE1qEc9ojPj3FVBkr5kZI1flGg +wIflEf8T7//Iitm0pfBFKUt4XYxf4jtwnGr4Ch1Wnht7RCvOeHrPO99anbmIZ9VQJzt DMVg== Received: by 10.50.41.161 with SMTP id g1mr9529692igl.5.1331056611559; Tue, 06 Mar 2012 09:56:51 -0800 (PST) Received: from yakj.usersys.redhat.com (93-34-182-16.ip50.fastwebnet.it. [93.34.182.16]) by mx.google.com with ESMTPS id s8sm10504373igw.16.2012.03.06.09.56.48 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 06 Mar 2012 09:56:50 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 6 Mar 2012 18:56:02 +0100 Message-Id: <1331056563-7503-10-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1331056563-7503-1-git-send-email-pbonzini@redhat.com> References: <1331056563-7503-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.210.173 Cc: kwolf@redhat.com, fsimonce@redhat.com, eblake@redhat.com, stefanha@linux.vnet.ibm.com, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH v4 09/10] add drive-mirror command and HMP equivalent 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 Since QMP transactions are supposed to take (pseudo) QMP commands, add a standalone drive-mirror command. The corresponding HMP command does not provide atomic snapshot+mirror, but it can still be used together with image streaming. Signed-off-by: Paolo Bonzini --- blockdev.c | 15 +++++++++++++++ hmp-commands.hx | 22 ++++++++++++++++++++++ hmp.c | 28 ++++++++++++++++++++++++++++ hmp.h | 1 + qapi-schema.json | 27 +++++++++++++++++++++++++++ qmp-commands.hx | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 126 insertions(+), 0 deletions(-) diff --git a/blockdev.c b/blockdev.c index 9d3a362..2958419 100644 --- a/blockdev.c +++ b/blockdev.c @@ -675,6 +675,21 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file, errp); } +void qmp_drive_mirror(const char *device, const char *target, + bool has_format, const char *format, + bool has_mode, enum NewImageMode mode, Error **errp) +{ + BlockdevMirror mirror = { + .device = (char *) device, + .target = (char *) target, + .has_format = has_format, + .format = (char *) format, + .has_mode = has_mode, + .mode = mode, + }; + blockdev_do_action(BLOCKDEV_ACTION_KIND_DRIVE_MIRROR, &mirror, errp); +} + /* New and old BlockDriverState structs for group snapshots */ typedef struct BlkTransactionStates { diff --git a/hmp-commands.hx b/hmp-commands.hx index 6980214..9c49c33 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -903,6 +903,28 @@ Snapshot device, using snapshot file as target if provided ETEXI { + .name = "drive_mirror", + .args_type = "reuse:-n,no-backing:-s,device:B,target:s,format:s?", + .params = "[-n] [-s] device [new-image-file] [format]", + .help = "initiates live storage\n\t\t\t" + "migration for a device. New writes are mirrored to the\n\t\t\t" + "specified new image file, and the block_stream\n\t\t\t" + "command can then be started.\n\t\t\t" + "The default format is qcow2. The -n flag requests QEMU\n\t\t\t" + "to reuse the image found in new-image-file, instead of\n\t\t\t" + "recreating it from scratch. The -s flag requests QEMU\n\t\t\t" + "to create a root image, that does not have the current\n\t\t\t" + "image as the backing file.", + .mhandler.cmd = hmp_drive_mirror, + }, +STEXI +@item drive_mirror +@findex drive_mirror +Start mirroring a block device's writes to a new destination, +using the specified target. +ETEXI + + { .name = "drive_add", .args_type = "pci_addr:s,opts:s", .params = "[[:]:]\n" diff --git a/hmp.c b/hmp.c index 290c43d..e706db9 100644 --- a/hmp.c +++ b/hmp.c @@ -687,6 +687,34 @@ void hmp_block_resize(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, &errp); } +void hmp_drive_mirror(Monitor *mon, const QDict *qdict) +{ + const char *device = qdict_get_str(qdict, "device"); + const char *filename = qdict_get_try_str(qdict, "target"); + const char *format = qdict_get_try_str(qdict, "format"); + int reuse = qdict_get_try_bool(qdict, "reuse", 0); + int no_backing = qdict_get_try_bool(qdict, "no-backing", 0); + enum NewImageMode mode; + Error *errp = NULL; + + if (!filename) { + error_set(&errp, QERR_MISSING_PARAMETER, "target"); + hmp_handle_error(mon, &errp); + return; + } + + if (reuse) { + mode = NEW_IMAGE_MODE_EXISTING; + } else if (no_backing) { + mode = NEW_IMAGE_MODE_NO_BACKING_FILE; + } else { + mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS; + } + + qmp_drive_mirror(device, filename, !!format, format, true, mode, &errp); + hmp_handle_error(mon, &errp); +} + void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) { const char *device = qdict_get_str(qdict, "device"); diff --git a/hmp.h b/hmp.h index 5409464..5352f00 100644 --- a/hmp.h +++ b/hmp.h @@ -48,6 +48,7 @@ void hmp_block_passwd(Monitor *mon, const QDict *qdict); void hmp_balloon(Monitor *mon, const QDict *qdict); void hmp_block_resize(Monitor *mon, const QDict *qdict); void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict); +void hmp_drive_mirror(Monitor *mon, const QDict *qdict); void hmp_migrate_cancel(Monitor *mon, const QDict *qdict); void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict); void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict); diff --git a/qapi-schema.json b/qapi-schema.json index 75ac978..4cebf78 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1263,6 +1263,33 @@ 'returns': 'str' } ## +# @drive-mirror +# +# Start mirroring a block device's writes to a new destination. +# +# @device: the name of the device whose writes should be mirrored. +# +# @target: the target of the new image. If the file exists, or if it +# is a device, the existing file/device will be used as the new +# destination. If it does not exist, a new file will be created. +# +# @format: #optional the format of the new destination, default is 'qcow2'. +# +# @mode: #optional whether and how QEMU should create a new image, default is +# 'absolute-paths'. +# +# Returns: nothing on success +# If @device is not a valid block device, DeviceNotFound +# If @target can't be opened, OpenFileFailed +# If @format is invalid, InvalidBlockFormat +# +# Since 1.1 +## +{ 'command': 'drive-mirror', + 'data': { 'device': 'str', 'target': 'str', '*format': 'str', + '*mode': 'NewImageMode'} } + +## # @migrate_cancel # # Cancel the current executing migration process. diff --git a/qmp-commands.hx b/qmp-commands.hx index 0438632..122ebe7 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -785,6 +785,39 @@ Example: EQMP { + .name = "drive-mirror", + .args_type = "device:B,snapshot-file:s,mode:s?,format:s?", + .mhandler.cmd_new = qmp_marshal_input_drive_mirror, + }, + +SQMP +drive-mirror +------------ + +Start mirroring a block device's writes to a new destination. target +specifies the target of the new image. If the file exists, or if it is +a device, it will be used as the new destination for writes. If does not +exist, a new file will be created. format specifies the format of the +mirror image, default is qcow2. + +Arguments: + +- "device": device name to operate on (json-string) +- "target": name of new image file (json-string) +- "format": format of new image (json-string, optional) +- "mode": how an image file should be created into the target + file/device (NewImageMode, optional, default 'absolute-paths') + +Example: + +-> { "execute": "drive-mirror", "arguments": { "device": "ide-hd0", + "target": "/some/place/my-image", + "format": "qcow2" } } +<- { "return": {} } + +EQMP + + { .name = "balloon", .args_type = "value:M", .mhandler.cmd_new = qmp_marshal_input_balloon,