From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
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
Date: Tue, 6 Mar 2012 18:56:02 +0100 [thread overview]
Message-ID: <1331056563-7503-10-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1331056563-7503-1-git-send-email-pbonzini@redhat.com>
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 <pbonzini@redhat.com>
---
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 = "[[<domain>:]<bus>:]<slot>\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,
--
1.7.7.6
next prev parent reply other threads:[~2012-03-06 17:57 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-06 17:55 [Qemu-devel] [PATCH v4 00/10] Mirrored block writes Paolo Bonzini
2012-03-06 17:55 ` [Qemu-devel] [PATCH v4 01/10] use QSIMPLEQ_FOREACH_SAFE when freeing list elements Paolo Bonzini
2012-03-06 17:55 ` [Qemu-devel] [PATCH v4 02/10] fix format name for backing file Paolo Bonzini
2012-03-06 17:55 ` [Qemu-devel] [PATCH v4 03/10] qapi: complete implementation of unions Paolo Bonzini
2012-03-06 17:55 ` [Qemu-devel] [PATCH v4 04/10] rename blockdev-group-snapshot-sync Paolo Bonzini
2012-03-06 17:55 ` [Qemu-devel] [PATCH v4 05/10] add mode field to blockdev-snapshot-sync transaction item Paolo Bonzini
2012-03-06 17:55 ` [Qemu-devel] [PATCH v4 06/10] qmp: convert blockdev-snapshot-sync to a wrapper around transactions Paolo Bonzini
2012-03-06 17:56 ` [Qemu-devel] [PATCH v4 07/10] Add blkmirror block driver Paolo Bonzini
2012-03-06 17:56 ` [Qemu-devel] [PATCH v4 08/10] add mirroring to transaction Paolo Bonzini
2012-03-06 17:56 ` Paolo Bonzini [this message]
2012-03-06 17:56 ` [Qemu-devel] [PATCH v4 10/10] Add the drive-reopen command Paolo Bonzini
2012-03-13 20:48 ` Eric Blake
2012-03-14 0:14 ` Federico Simoncelli
2012-03-14 9:34 ` Kevin Wolf
2012-03-14 13:11 ` Eric Blake
2012-03-14 14:30 ` Kevin Wolf
2012-03-14 13:29 ` Federico Simoncelli
2012-03-14 9:17 ` Kevin Wolf
2012-03-14 9:19 ` Paolo Bonzini
2012-03-14 9:35 ` Kevin Wolf
2012-03-09 15:36 ` [Qemu-devel] [PATCH v4 00/10] Mirrored block writes Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1331056563-7503-10-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=eblake@redhat.com \
--cc=fsimonce@redhat.com \
--cc=kwolf@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).