From: Federico Simoncelli <fsimonce@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, mtosatti@redhat.com, armbru@redhat.com,
lcapitulino@redhat.com, Federico Simoncelli <fsimonce@redhat.com>,
pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH 2/2 v2] Add the blockdev-reopen and blockdev-migrate commands
Date: Fri, 24 Feb 2012 16:49:04 +0000 [thread overview]
Message-ID: <1330102144-14491-2-git-send-email-fsimonce@redhat.com> (raw)
In-Reply-To: <1329930815-7995-1-git-send-email-fsimonce@redhat.com>
Signed-off-by: Federico Simoncelli <fsimonce@redhat.com>
---
blockdev.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++------
hmp-commands.hx | 38 +++++++++++++++++++
hmp.c | 24 ++++++++++++
hmp.h | 2 +
qapi-schema.json | 54 +++++++++++++++++++++++++++
5 files changed, 213 insertions(+), 12 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 2c132a3..f51bd6f 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -646,9 +646,8 @@ void do_commit(Monitor *mon, const QDict *qdict)
}
}
-void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file,
- bool has_format, const char *format,
- Error **errp)
+static void change_blockdev_image(const char *device, const char *new_image_file,
+ const char *format, bool create, Error **errp)
{
BlockDriverState *bs;
BlockDriver *drv, *old_drv, *proto_drv;
@@ -671,7 +670,7 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file,
old_drv = bs->drv;
flags = bs->open_flags;
- if (!has_format) {
+ if (!format) {
format = "qcow2";
}
@@ -681,24 +680,26 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file,
return;
}
- proto_drv = bdrv_find_protocol(snapshot_file);
+ proto_drv = bdrv_find_protocol(new_image_file);
if (!proto_drv) {
error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
return;
}
- ret = bdrv_img_create(snapshot_file, format, bs->filename,
- bs->drv->format_name, NULL, -1, flags);
- if (ret) {
- error_set(errp, QERR_UNDEFINED_ERROR);
- return;
+ if (create) {
+ ret = bdrv_img_create(new_image_file, format, bs->filename,
+ bs->drv->format_name, NULL, -1, flags);
+ if (ret) {
+ error_set(errp, QERR_UNDEFINED_ERROR);
+ return;
+ }
}
bdrv_drain_all();
bdrv_flush(bs);
bdrv_close(bs);
- ret = bdrv_open(bs, snapshot_file, flags, drv);
+ ret = bdrv_open(bs, new_image_file, flags, drv);
/*
* If reopening the image file we just created fails, fall back
* and try to re-open the original image. If that fails too, we
@@ -709,11 +710,93 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file,
if (ret != 0) {
error_set(errp, QERR_OPEN_FILE_FAILED, old_filename);
} else {
- error_set(errp, QERR_OPEN_FILE_FAILED, snapshot_file);
+ error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
}
}
}
+void qmp_drive_reopen(const char *device, const char *new_image_file,
+ bool has_format, const char *format, Error **errp)
+{
+ change_blockdev_image(device, new_image_file,
+ has_format ? format : NULL, false, errp);
+}
+
+void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file,
+ bool has_format, const char *format,
+ Error **errp)
+{
+ change_blockdev_image(device, snapshot_file,
+ has_format ? format : NULL, true, errp);
+}
+
+static void qmp_blockdev_mirror(const char *device, const char *destination,
+ const char *new_image_file, Error **errp)
+{
+ BlockDriver *drv;
+ int i, j, escape;
+ char new_filename[2048], *filename;
+
+ drv = bdrv_find_format("blkmirror");
+ if (!drv) {
+ error_set(errp, QERR_INVALID_BLOCK_FORMAT, "blkmirror");
+ return;
+ }
+
+ escape = 0;
+ for (i = 0, j = 0; j < strlen(new_image_file); j++) {
+ loop:
+ if (!(i < sizeof(new_filename) - 2)) {
+ error_set(errp, QERR_INVALID_PARAMETER_VALUE,
+ "new-image-file", "shorter filename");
+ return;
+ }
+
+ if (new_image_file[j] == ':' || new_image_file[j] == '\\') {
+ if (!escape) {
+ new_filename[i++] = '\\', escape = 1;
+ goto loop;
+ } else {
+ escape = 0;
+ }
+ }
+
+ new_filename[i++] = new_image_file[j];
+ }
+
+ filename = g_strdup_printf("blkmirror:%s:%s", new_filename, destination);
+ change_blockdev_image(device, filename, "blkmirror", false, errp);
+ g_free(filename);
+}
+
+void qmp_blockdev_migrate(const char *device, bool incremental,
+ const char *destination, bool has_new_image_file,
+ const char *new_image_file, Error **errp)
+{
+ BlockDriverState *bs;
+
+ bs = bdrv_find(device);
+ if (!bs) {
+ error_set(errp, QERR_DEVICE_NOT_FOUND, device);
+ return;
+ }
+ if (bdrv_in_use(bs)) {
+ error_set(errp, QERR_DEVICE_IN_USE, device);
+ return;
+ }
+
+ if (incremental) {
+ if (!has_new_image_file) {
+ error_set(errp, QERR_INVALID_PARAMETER_VALUE,
+ "incremental", "a new image file");
+ } else {
+ qmp_blockdev_mirror(device, destination, new_image_file, errp);
+ }
+ } else {
+ error_set(errp, QERR_NOT_SUPPORTED);
+ }
+}
+
static void eject_device(BlockDriverState *bs, int force, Error **errp)
{
if (bdrv_in_use(bs)) {
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 573b823..4aacf2a 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -886,6 +886,44 @@ Snapshot device, using snapshot file as target if provided
ETEXI
{
+ .name = "drive_reopen",
+ .args_type = "device:B,new-image-file:s?,format:s?",
+ .params = "device [new-image-file] [format]",
+ .help = "Assigns a new image file to a device.\n\t\t\t"
+ "The image will be opened using the format\n\t\t\t"
+ "specified or 'qcow2' by default.\n\t\t\t"
+ "This command is deprecated.",
+ .mhandler.cmd = hmp_drive_reopen,
+ },
+
+STEXI
+@item drive_reopen
+@findex drive_reopen
+Assigns a new image file to a device.
+ETEXI
+
+ {
+ .name = "blkdev_migrate",
+ .args_type = "incremental:-i,device:B,destination:s,new-image-file:s?",
+ .params = "device mode destination [new-image-file]",
+ .help = "Migrates the device to a new destination.\n\t\t\t"
+ "If the incremental (-i) option is used then\n\t\t\t"
+ "only the new writes are sent to the destination.\n\t\t\t"
+ "This method is particularly useful if used in\n\t\t\t"
+ "conjunction with new-image-file (a new image for\n\t\t\t"
+ "the device) allowing the current image to be\n\t\t\t"
+ "transferred to the destination by an external\n\t\t\t"
+ "manager.",
+ .mhandler.cmd = hmp_blkdev_migrate,
+ },
+
+STEXI
+@item blkdev_migrate
+@findex blkdev_migrate
+Migrates the device to a new destination.
+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 8ff8c94..282d3e5 100644
--- a/hmp.c
+++ b/hmp.c
@@ -701,6 +701,30 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
hmp_handle_error(mon, &errp);
}
+void hmp_drive_reopen(Monitor *mon, const QDict *qdict)
+{
+ const char *device = qdict_get_str(qdict, "device");
+ const char *filename = qdict_get_str(qdict, "new-image-file");
+ const char *format = qdict_get_try_str(qdict, "format");
+ Error *errp = NULL;
+
+ qmp_drive_reopen(device, filename, !!format, format, &errp);
+ hmp_handle_error(mon, &errp);
+}
+
+void hmp_blkdev_migrate(Monitor *mon, const QDict *qdict)
+{
+ bool incremental = qdict_get_try_bool(qdict, "incremental", 0);
+ const char *device = qdict_get_str(qdict, "device");
+ const char *destination = qdict_get_str(qdict, "destination");
+ const char *new_image_file = qdict_get_try_str(qdict, "new-image-file");
+ Error *errp = NULL;
+
+ qmp_blockdev_migrate(device, incremental, destination,
+ !!new_image_file, new_image_file, &errp);
+ hmp_handle_error(mon, &errp);
+}
+
void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
{
qmp_migrate_cancel(NULL);
diff --git a/hmp.h b/hmp.h
index 18eecbd..3c66257 100644
--- a/hmp.h
+++ b/hmp.h
@@ -47,6 +47,8 @@ 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_reopen(Monitor *mon, const QDict *qdict);
+void hmp_blkdev_migrate(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 d02ee86..df1248c 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1136,6 +1136,60 @@
'data': { 'device': 'str', 'snapshot-file': 'str', '*format': 'str' } }
##
+# @drive-reopen
+#
+# Assigns a new image file to a device.
+#
+# @device: the name of the device for which we are chainging the image file.
+#
+# @new-image-file: the target of the new image. If the file doesn't exists the
+# command will fail.
+#
+# @format: #optional the format of the new image, default is 'qcow2'.
+#
+# Returns: nothing on success
+# If @device is not a valid block device, DeviceNotFound
+# If @new-image-file can't be opened, OpenFileFailed
+# If @format is invalid, InvalidBlockFormat
+#
+# Notes: This command is deprecated.
+#
+# Since 1.1
+##
+
+{ 'command': 'drive-reopen',
+ 'data': { 'device': 'str', 'new-image-file': 'str', '*format': 'str' } }
+
+##
+# @blockdev-migrate
+#
+# Migrates the device to a new destination.
+#
+# @device: the name of the block device to migrate.
+#
+# @incremental: if true only the new writes are sent to the destination.
+# This method is particularly useful if used in conjunction
+# with new-image-file allowing the current image to be
+# transferred to the destination by an external manager.
+#
+# @destination: the destination of the block migration.
+#
+# @new-image-file: #optional an existing image file that will replace
+# the current one in the device.
+#
+# Returns: nothing on success
+# If @device is not a valid block device, DeviceNotFound
+# If @mode is not a valid migration mode, InvalidParameterValue
+# If @destination can't be opened, OpenFileFailed
+# If @new-image-file can't be opened, OpenFileFailed
+#
+# Since 1.1
+##
+{ 'command': 'blockdev-migrate',
+ 'data': { 'device': 'str', 'incremental' : 'bool',
+ 'destination': 'str', '*new-image-file': 'str' } }
+
+##
# @human-monitor-command:
#
# Execute a command on the human monitor and return the output.
--
1.7.1
next prev parent reply other threads:[~2012-02-24 16:49 UTC|newest]
Thread overview: 95+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-22 17:13 [Qemu-devel] Live Block Migration using Mirroring Federico Simoncelli
2012-02-22 17:13 ` [Qemu-devel] [PATCH 1/3] Add blkmirror block driver Federico Simoncelli
2012-02-23 16:14 ` Stefan Hajnoczi
2012-02-23 16:18 ` Stefan Hajnoczi
2012-02-23 16:20 ` Federico Simoncelli
2012-02-23 16:28 ` Stefan Hajnoczi
2012-02-23 16:51 ` Federico Simoncelli
2012-02-23 16:18 ` Federico Simoncelli
2012-02-27 9:23 ` Stefan Hajnoczi
2012-02-27 11:37 ` Paolo Bonzini
2012-02-27 11:42 ` Stefan Hajnoczi
2012-02-27 11:48 ` Paolo Bonzini
2012-02-27 13:09 ` Stefan Hajnoczi
2012-02-27 13:47 ` Paolo Bonzini
2012-02-27 14:49 ` Stefan Hajnoczi
2012-02-27 14:59 ` Stefan Hajnoczi
2012-02-27 15:08 ` Paolo Bonzini
2012-02-22 17:13 ` [Qemu-devel] [PATCH 2/3] Update the " Federico Simoncelli
2012-02-23 7:18 ` Paolo Bonzini
2012-02-23 9:44 ` Federico Simoncelli
2012-02-23 9:45 ` Paolo Bonzini
2012-02-22 17:13 ` [Qemu-devel] [PATCH 3/3] Add nocreate option to snapshot_blkdev Federico Simoncelli
2012-02-23 7:19 ` Paolo Bonzini
2012-02-23 7:38 ` Paolo Bonzini
2012-02-23 9:39 ` Federico Simoncelli
2012-02-23 9:48 ` Paolo Bonzini
2012-02-23 10:19 ` Federico Simoncelli
2012-02-23 11:30 ` Paolo Bonzini
2012-02-23 15:47 ` [Qemu-devel] Live Block Migration using Mirroring Stefan Hajnoczi
2012-02-23 16:10 ` Federico Simoncelli
2012-02-23 16:35 ` Stefan Hajnoczi
2012-02-23 17:06 ` Federico Simoncelli
2012-02-24 11:37 ` [Qemu-devel] [PATCH 1/2] Add blkmirror block driver Federico Simoncelli
2012-02-24 11:37 ` [Qemu-devel] [PATCH 2/2] Add the blockdev-reopen and blockdev-migrate commands Federico Simoncelli
2012-02-24 12:03 ` Kevin Wolf
2012-02-24 12:12 ` Federico Simoncelli
2012-02-24 13:11 ` Paolo Bonzini
2012-02-24 17:04 ` Luiz Capitulino
2012-02-27 14:57 ` Markus Armbruster
2012-02-24 16:49 ` [Qemu-devel] [PATCH 1/2 v2] Add blkmirror block driver Federico Simoncelli
2012-02-24 17:02 ` Eric Blake
2012-02-24 17:15 ` Federico Simoncelli
2012-02-24 18:49 ` Paolo Bonzini
2012-02-24 18:17 ` Luiz Capitulino
2012-02-27 9:17 ` Federico Simoncelli
2012-02-24 16:49 ` Federico Simoncelli [this message]
2012-02-24 17:46 ` [Qemu-devel] [PATCH 2/2 v2] Add the blockdev-reopen and blockdev-migrate commands Eric Blake
2012-02-24 18:57 ` Paolo Bonzini
2012-02-24 19:37 ` Eric Blake
2012-02-24 19:01 ` Luiz Capitulino
2012-02-24 19:40 ` Eric Blake
2012-02-24 20:26 ` Luiz Capitulino
2012-02-24 22:46 ` Eric Blake
2012-02-24 20:32 ` Paolo Bonzini
2012-02-24 20:36 ` Luiz Capitulino
2012-02-24 21:05 ` Paolo Bonzini
2012-02-24 22:30 ` Eric Blake
2012-02-25 6:47 ` Paolo Bonzini
2012-02-27 11:29 ` Federico Simoncelli
2012-02-27 12:12 ` Luiz Capitulino
2012-02-27 12:49 ` Paolo Bonzini
2012-02-27 13:06 ` Luiz Capitulino
2012-02-27 14:39 ` [Qemu-devel] drive transactions (was Re: [PATCH 2/2 v2] Add the blockdev-reopen and blockdev-migrate commands) Paolo Bonzini
2012-02-27 14:46 ` Anthony Liguori
2012-02-27 14:54 ` Paolo Bonzini
2012-02-27 14:59 ` Anthony Liguori
2012-02-27 15:03 ` Paolo Bonzini
2012-02-27 15:06 ` Anthony Liguori
2012-02-27 15:17 ` Kevin Wolf
2012-02-27 15:24 ` Anthony Liguori
2012-02-27 16:51 ` Paolo Bonzini
2012-02-27 16:58 ` Anthony Liguori
2012-02-27 17:06 ` Paolo Bonzini
2012-02-27 16:33 ` Federico Simoncelli
2012-02-27 16:41 ` Paolo Bonzini
2012-02-27 16:42 ` Anthony Liguori
2012-02-27 16:50 ` Federico Simoncelli
2012-02-27 16:53 ` Anthony Liguori
2012-02-27 16:54 ` Paolo Bonzini
2012-02-27 16:59 ` Anthony Liguori
2012-02-27 17:37 ` Luiz Capitulino
2012-02-28 15:47 ` [Qemu-devel] Live Block Migration using Mirroring Stefan Hajnoczi
2012-02-28 17:15 ` Federico Simoncelli
2012-02-28 17:36 ` Paolo Bonzini
2012-02-28 17:46 ` Federico Simoncelli
2012-02-28 18:02 ` Paolo Bonzini
2012-02-28 18:21 ` Federico Simoncelli
2012-02-28 17:26 ` Paolo Bonzini
2012-02-29 12:28 ` [Qemu-devel] [PATCHv3] Add blkmirror block driver Federico Simoncelli
2012-02-29 13:02 ` Federico Simoncelli
2012-02-29 17:01 ` [Qemu-devel] [PATCHv4] " Federico Simoncelli
2012-03-05 16:59 ` [Qemu-devel] Live Block Migration using Mirroring Marcelo Tosatti
2012-03-05 17:20 ` Eric Blake
2012-03-05 17:44 ` Marcelo Tosatti
2012-03-05 18:05 ` Paolo Bonzini
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=1330102144-14491-2-git-send-email-fsimonce@redhat.com \
--to=fsimonce@redhat.com \
--cc=armbru@redhat.com \
--cc=kwolf@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).