From patchwork Mon Mar 5 17:34: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: 144727 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 670D5B6F9F for ; Tue, 6 Mar 2012 04:36:13 +1100 (EST) Received: from localhost ([::1]:49663 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4bpR-0000k0-Qx for incoming@patchwork.ozlabs.org; Mon, 05 Mar 2012 12:36:09 -0500 Received: from eggs.gnu.org ([208.118.235.92]:49922) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4boN-00078f-IU for qemu-devel@nongnu.org; Mon, 05 Mar 2012 12:35:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S4boD-0002Cl-BI for qemu-devel@nongnu.org; Mon, 05 Mar 2012 12:35:03 -0500 Received: from mail-pz0-f46.google.com ([209.85.210.46]:63888) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4boC-00021k-Uy for qemu-devel@nongnu.org; Mon, 05 Mar 2012 12:34:53 -0500 Received: by mail-pz0-f46.google.com with SMTP id r28so6691453daj.33 for ; Mon, 05 Mar 2012 09:34:52 -0800 (PST) Received-SPF: pass (google.com: domain of paolo.bonzini@gmail.com designates 10.68.129.228 as permitted sender) client-ip=10.68.129.228; Authentication-Results: mr.google.com; spf=pass (google.com: domain of paolo.bonzini@gmail.com designates 10.68.129.228 as permitted sender) smtp.mail=paolo.bonzini@gmail.com; dkim=pass header.i=paolo.bonzini@gmail.com Received: from mr.google.com ([10.68.129.228]) by 10.68.129.228 with SMTP id nz4mr52555272pbb.91.1330968892131 (num_hops = 1); Mon, 05 Mar 2012 09:34:52 -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=A/aT18L0S4oyMFoT8QyYMPae8t22rub1KQlFZOSF7KA=; b=knupoO6DFPZdRrkikbo+aqdRwL00kI5hUjqWqrR5yqErOuS+qgeDYe7Tzcm+D10UwO r5SUREr7JqT/sFVSjpkHsbh16fjIp0mbByNqjT5SW3n4pK/RAl9lll4I3ycqCs6uRYzH AJL5K2xKFE1W5g1+HBbJxAtpyfhED4XIFphN5qyrnzEoaURdPuuRjDSyZXKrmdIMumFV FRlQYrziprAZSHcOWGxlP9LA2VbiHXgyKqpbSeyRrS1lJ1C2mGBx2BtdBIvarwtBv1TT j0Qte5+GMep5TGbi6/Iss+D5MtjpmzCV+ijWXUJC9COOG+GCkafR4XgI5gunLkzFCAd0 h4RQ== Received: by 10.68.129.228 with SMTP id nz4mr45017152pbb.91.1330968892087; Mon, 05 Mar 2012 09:34:52 -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 i9sm13836905pba.22.2012.03.05.09.34.48 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 05 Mar 2012 09:34:51 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 5 Mar 2012 18:34:02 +0100 Message-Id: <1330968842-24635-9-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1330968842-24635-1-git-send-email-pbonzini@redhat.com> References: <1330968842-24635-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.46 Cc: kwolf@redhat.com, fsimonce@redhat.com, eblake@redhat.com, stefanha@linux.vnet.ibm.com, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH v3 8/8] 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 | 24 ++++++++++++++++++++++++ hmp-commands.hx | 22 ++++++++++++++++++++++ hmp.c | 28 ++++++++++++++++++++++++++++ hmp.h | 1 + qapi-schema.json | 26 ++++++++++++++++++++++++++ qmp-commands.hx | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 134 insertions(+), 0 deletions(-) diff --git a/blockdev.c b/blockdev.c index df086d1..60fdc7b 100644 --- a/blockdev.c +++ b/blockdev.c @@ -671,6 +671,30 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file, qmp_transaction(&list, 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, + }; + BlockdevAction action = { + .kind = BLOCKDEV_ACTION_KIND_DRIVE_MIRROR, + .drive_mirror = &mirror, + }; + BlockdevActionList list = { + .value = &action, + .next = NULL + }; + + qmp_transaction(&list, 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 a61e90c..16e8786 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1262,6 +1262,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 9dcafd4..b8a93d1 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,