qapi: Convert migrate
v2 cover qapi: Convert migrate
v2
o Drop qemu_get_fd() (use monitor_get_fd(cur_mon, instead)
o Drop qdict_copy() (use refcount instead)
o Check for monitor_suspend() return value
o Other minor changes
Original intro:
This is a rebase of Anthony's conversion, from his glib branch; and this is also the beginning of the conversion of complex commands to the qapi.
There are two important changes that should be observed:
1. patch 3/4 purges the 'mon' object from migration code. One of the consequences is that we loose the ability to print progress status to the HMP user (esp. in block migration)
2. The HMP hmp_migrate() command is a bit tricky when in non-detached
mode: we lock the monitor and poll for the migration status from a timer handler. This obviously assumes that migration will end at some point
arch_init.c | 2 +- block-migration.c | 58 ++++++++++++++++++----------------------- error.c | 13 ++++++++++ error.h | 5 ++++ hmp-commands.hx | 3 +-- hmp.c | 56 ++++++++++++++++++++++++++++++++++++++++ hmp.h | 1 + migration-fd.c | 2 +- migration.c | 74 +++++++++++++++-------------------------------------- migration.h | 5 +--- qapi-schema.json | 21 +++++++++++++++ qerror.c | 8 ++++++ qerror.h | 6 +++++ qmp-commands.hx | 9 +------ savevm.c | 42 +++++++++++++++--------------- sysemu.h | 11 ++++---- vmstate.h | 3 +-- 17 files changed, 187 insertions(+), 132 deletions(-)
PATCH v2 1/4 QError: Introduce new errors for the migration command
The new errors are QERR_MIGRATION_ACTIVE and QERR_MIGRATION_NOT_SUPPORTED, which are going to be used by the QAPI converted migration command.
--- qerror.c | 8 ++++++++ qerror.h | 6 ++++++ 2 files changed, 14 insertions(+)
qerror.c +8 -0
@@ -193,6 +193,14 @@ static const QErrorStringTable qerror_table[] = { .desc = "Using KVM without %(capability), %(feature) unavailable", }, { + .error_fmt = QERR_MIGRATION_ACTIVE, + .desc = "There's a migration process in progress", + }, + { + .error_fmt = QERR_MIGRATION_NOT_SUPPORTED, + .desc = "State blocked by non-migratable device '%(device)'", + }, + { .error_fmt = QERR_MIGRATION_EXPECTED, .desc = "An incoming migration is expected before this command can be executed", },
qerror.h +6 -0
@@ -166,6 +166,12 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_KVM_MISSING_CAP \ "{ 'class': 'KVMMissingCap', 'data': { 'capability': %s, 'feature': %s } }" +#define QERR_MIGRATION_ACTIVE \ + "{ 'class': 'MigrationActive', 'data': {} }" + +#define QERR_MIGRATION_NOT_SUPPORTED \ + "{ 'class': 'MigrationNotSupported', 'data': {'device': %s} }" +#define QERR_MIGRATION_EXPECTED \ "{ 'class': 'MigrationExpected', 'data': {} }"
Signature · 1 line
1.7.9.2.384.g4a92a
PATCH v2 2/4 Error: Introduce error_copy()
In reply to Luiz Capitulino--- error.c | 13 +++++++++++++ error.h | 5 +++++ 2 files changed, 18 insertions(+)
error.c +13 -0
@@ -43,6 +43,19 @@ void error_set(Error **errp, const char *fmt, ...) *errp = err; } +Error *error_copy (const Error *err) +{ +Error *err_new; + + err_new =g_malloc0 (sizeof (*err)); + err_new->msg =g_strdup (err->msg); + err_new->fmt = err->fmt; + err_new->obj = err->obj; +QINCREF (err_new->obj); + +return err_new; +} +bool error_is_set (Error **errp) {return (errp && *errp);
error.h +5 -0
@@ -35,6 +35,11 @@ void error_set(Error **err, const char *fmt, ...) GCC_FMT_ATTR(2, 3);bool error_is_set (Error **err);/** +* Returns an exact copy of the error passed as an argument. +*/ +Error *error_copy (const Error *err); + +/** * Get a human readable representation of an error object. */ const char *error_get_pretty (Error *err);
Signature · 1 line
1.7.9.2.384.g4a92a
PATCH v2 3/4 Purge migration of (almost) everything to do with monitors
In reply to Luiz CapitulinoThe Monitor object is passed back and forth within the migration/savevm code so that it can print errors and progress to the user.
However, that approach assumes a HMP monitor, being completely invalid in QMP.
This commit drops almost every single usage of the Monitor object, all monitor_printf() calls have been converted into DPRINTF() ones.
There are a few remaining Monitor objects, those are going to be dropped by the next commit.
--- arch_init.c | 2 +- block-migration.c | 58 +++++++++++++++++++++++------------------------------ migration.c | 8 ++++---- migration.h | 2 +- savevm.c | 29 +++++++++++++-------------- sysemu.h | 9 ++++----- vmstate.h | 3 +-- 7 files changed, 50 insertions(+), 61 deletions(-)
arch_init.c +1 -1
@@ -260,7 +260,7 @@ static void sort_ram_list(void)g_free (blocks); } -int ram_save_live (Monitor *mon,QEMUFile *f,int stage,void *opaque) +int ram_save_live (QEMUFile *f,int stage,void *opaque) {ram_addr_t addr;uint64_t bytes_transferred_last;
block-migration.c +25 -33
192 lines not on this page · raw message
migration.c +4 -4
@@ -258,7 +258,7 @@ static void migrate_fd_put_ready(void *opaque) }DPRINTF ("iterate\n" ); - ret =qemu_savevm_state_iterate (s->mon, s->file); + ret =qemu_savevm_state_iterate (s->file);if (ret <0 ) {migrate_fd_error (s); }else if (ret ==1 ) {
@@ -267,7 +267,7 @@ static void migrate_fd_put_ready(void *opaque)DPRINTF ("done iterating\n" );vm_stop_force_state (RUN_STATE_FINISH_MIGRATE ); -if (qemu_savevm_state_complete (s->mon, s->file) <0 ) { +if (qemu_savevm_state_complete (s->file) <0 ) {migrate_fd_error (s); }else {migrate_fd_completed (s);
@@ -289,7 +289,7 @@ static void migrate_fd_cancel(MigrationState *s) s->state =MIG_STATE_CANCELLED ;notifier_list_notify (&migration_state_notifiers, s); -qemu_savevm_state_cancel (s->mon, s->file); +qemu_savevm_state_cancel (s->file);migrate_fd_cleanup (s); }
@@ -367,7 +367,7 @@ void migrate_fd_connect(MigrationState *s) migrate_fd_close);DPRINTF ("beginning savevm\n" ); - ret =qemu_savevm_state_begin (s->mon, s->file, s->blk, s->shared); + ret =qemu_savevm_state_begin (s->file, s->blk, s->shared);if (ret <0 ) {DPRINTF ("failed, %d\n" , ret);migrate_fd_error (s);
migration.h +1 -1
@@ -78,7 +78,7 @@ uint64_t ram_bytes_remaining(void);uint64_t ram_bytes_transferred (void );uint64_t ram_bytes_total (void ); -int ram_save_live (Monitor *mon,QEMUFile *f,int stage,void *opaque); +int ram_save_live (QEMUFile *f,int stage,void *opaque);int ram_load (QEMUFile *f,void *opaque,int version_id);/**
savevm.c +14 -15
@@ -1554,8 +1554,7 @@ bool qemu_savevm_state_blocked(Monitor *mon)return false; } -int qemu_savevm_state_begin (Monitor *mon,QEMUFile *f,int blk_enable, -int shared) +int qemu_savevm_state_begin (QEMUFile *f,int blk_enable,int shared) {SaveStateEntry *se;int ret;
@@ -1588,15 +1587,15 @@ int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, int blk_enable,qemu_put_be32 (f, se->instance_id);qemu_put_be32 (f, se->version_id); - ret = se->save_live_state (mon, f,QEMU_VM_SECTION_START , se->opaque); + ret = se->save_live_state (f,QEMU_VM_SECTION_START , se->opaque);if (ret <0 ) { -qemu_savevm_state_cancel (mon, f); +qemu_savevm_state_cancel (f);return ret; } } ret =qemu_file_get_error (f);if (ret !=0 ) { -qemu_savevm_state_cancel (mon, f); +qemu_savevm_state_cancel (f); }return ret;
@@ -1609,7 +1608,7 @@ int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, int blk_enable,* 0 : We haven't finished, caller have to go again * 1 : We have finished, we can go to complete phase */ -int qemu_savevm_state_iterate (Monitor *mon,QEMUFile *f) +int qemu_savevm_state_iterate (QEMUFile *f) {SaveStateEntry *se;int ret =1 ;
@@ -1622,7 +1621,7 @@ int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f)qemu_put_byte (f,QEMU_VM_SECTION_PART );qemu_put_be32 (f, se->section_id); - ret = se->save_live_state (mon, f,QEMU_VM_SECTION_PART , se->opaque); + ret = se->save_live_state (f,QEMU_VM_SECTION_PART , se->opaque);if (ret <=0 ) {/* Do not proceed to the next vmstate before this one reported completion of the current stage. This serializes the migration
@@ -1636,12 +1635,12 @@ int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f) } ret =qemu_file_get_error (f);if (ret !=0 ) { -qemu_savevm_state_cancel (mon, f); +qemu_savevm_state_cancel (f); }return ret; } -int qemu_savevm_state_complete (Monitor *mon,QEMUFile *f) +int qemu_savevm_state_complete (QEMUFile *f) {SaveStateEntry *se;int ret;
@@ -1656,7 +1655,7 @@ int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f)qemu_put_byte (f,QEMU_VM_SECTION_END );qemu_put_be32 (f, se->section_id); - ret = se->save_live_state (mon, f,QEMU_VM_SECTION_END , se->opaque); + ret = se->save_live_state (f,QEMU_VM_SECTION_END , se->opaque);if (ret <0 ) {return ret; }
@@ -1688,13 +1687,13 @@ int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f)return qemu_file_get_error (f); } -void qemu_savevm_state_cancel (Monitor *mon,QEMUFile *f) +void qemu_savevm_state_cancel (QEMUFile *f) {SaveStateEntry *se; QTAILQ_FOREACH(se, &savevm_handlers, entry) {if (se->save_live_state) { - se->save_live_state (mon, f,-1 , se->opaque); + se->save_live_state (f,-1 , se->opaque); } } }
@@ -1708,17 +1707,17 @@ static int qemu_savevm_state(Monitor *mon, QEMUFile *f) goto out; } - ret =qemu_savevm_state_begin (mon, f,0 ,0 ); + ret =qemu_savevm_state_begin (f,0 ,0 );if (ret <0 ) goto out;do { - ret =qemu_savevm_state_iterate (mon, f); + ret =qemu_savevm_state_iterate (f);if (ret <0 ) goto out; }while (ret ==0 ); - ret =qemu_savevm_state_complete (mon, f); + ret =qemu_savevm_state_complete (f); out:if (ret ==0 ) {
sysemu.h +4 -5
@@ -77,11 +77,10 @@ void do_info_snapshots(Monitor *mon);void qemu_announce_self (void );bool qemu_savevm_state_blocked (Monitor *mon); -int qemu_savevm_state_begin (Monitor *mon,QEMUFile *f,int blk_enable, -int shared); -int qemu_savevm_state_iterate (Monitor *mon,QEMUFile *f); -int qemu_savevm_state_complete (Monitor *mon,QEMUFile *f); -void qemu_savevm_state_cancel (Monitor *mon,QEMUFile *f); +int qemu_savevm_state_begin (QEMUFile *f,int blk_enable,int shared); +int qemu_savevm_state_iterate (QEMUFile *f); +int qemu_savevm_state_complete (QEMUFile *f); +void qemu_savevm_state_cancel (QEMUFile *f);int qemu_loadvm_state (QEMUFile *f);/* SLIRP */
vmstate.h +1 -2
@@ -28,8 +28,7 @@typedef void SaveSetParamsHandler (int blk_enable,int shared,void * opaque);typedef void SaveStateHandler (QEMUFile *f,void *opaque); -typedef int SaveLiveStateHandler (Monitor *mon,QEMUFile *f,int stage, -void *opaque); +typedef int SaveLiveStateHandler (QEMUFile *f,int stage,void *opaque);typedef int LoadStateHandler (QEMUFile *f,void *opaque,int version_id); int register_savevm(DeviceState *dev,
Signature · 1 line
1.7.9.2.384.g4a92a
Re: [Qemu-devel] [PATCH 3/4] Purge migration of (almost) everything to do with monitors
Quoted 8 lines · Luiz Capitulino
The Monitor object is passed back and forth within the migration/savevm code so that it can print errors and progress to the user.
However, that approach assumes a HMP monitor, being completely invalid in QMP.
This commit drops almost every single usage of the Monitor object, all
monitor_printf()calls have been converted intoDPRINTF()ones.
I guess for most printfs, this is OK. But do you provide an alternative for the block migration progress output? I did not find anything on first glance. That is not a debugging feature.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Re: [Qemu-devel] [PATCH 3/4] Purge migration of (almost) everything to do with monitors
Quoted 7 lines · On Fri, 09 Mar 2012 19:20:56 +0100 Jan Kiszka <[email protected]> wrote:
Quoted 6 lines · Luiz Capitulino
The Monitor object is passed back and forth within the migration/savevm code so that it can print errors and progress to the user.
However, that approach assumes a HMP monitor, being completely invalid in QMP.
Quoted 6 lines
Quoted 2 lines
This commit drops almost every single usage of the Monitor object, all
monitor_printf()calls have been converted intoDPRINTF()ones.I guess for most printfs, this is OK. But do you provide an alternative for the block migration progress output? I did not find anything on first glance. That is not a debugging feature.
Can't the info migrate command be used for that?
Re: [Qemu-devel] [PATCH 3/4] Purge migration of (almost) everything to do with monitors
Quoted 10 lines · Luiz Capitulino
Quoted 7 lines · On Fri, 09 Mar 2012 19:20:56 +0100 Jan Kiszka <[email protected]> wrote:
Quoted 6 lines · Luiz Capitulino
The Monitor object is passed back and forth within the migration/savevm code so that it can print errors and progress to the user.
However, that approach assumes a HMP monitor, being completely invalid in QMP.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
This commit drops almost every single usage of the Monitor object, all
monitor_printf()calls have been converted intoDPRINTF()ones.I guess for most printfs, this is OK. But do you provide an alternative for the block migration progress output? I did not find anything on first glance. That is not a debugging feature.
Can't the info migrate command be used for that?
This was introduced for synchronous migration, as usability improvement.
Either we expose this feature or we drop it completely. But converting it to a /dev/null output is pointless.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Re: [Qemu-devel] [PATCH 3/4] Purge migration of (almost) everything to do with monitors
Quoted 14 lines · Jan Kiszka
Quoted 13 lines · Luiz Capitulino
Quoted 10 lines · On Fri, 09 Mar 2012 19:20:56 +0100 Jan Kiszka<[email protected]> wrote:
Quoted 8 lines · Luiz Capitulino
The Monitor object is passed back and forth within the migration/savevm code so that it can print errors and progress to the user.
However, that approach assumes a HMP monitor, being completely invalid in QMP.
This commit drops almost every single usage of the Monitor object, all
monitor_printf()calls have been converted intoDPRINTF()ones.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
I guess for most printfs, this is OK. But do you provide an alternative for the block migration progress output? I did not find anything on first glance. That is not a debugging feature.
Can't the info migrate command be used for that?
This was introduced for synchronous migration, as usability improvement.
Synchronous migration doesn't exist in QMP.
It's certainly possible to make the synchronous monitor command spit out status as it already uses a polling loop to determine when migration completes.
Regards,
Anthony Liguori
Quoted 6 lines
Either we expose this feature or we drop it completely. But converting it to a
/dev/nulloutput is pointless.Jan
Re: [Qemu-devel] [PATCH 3/4] Purge migration of (almost) everything to do with monitors
Quoted 19 lines · On Fri, 09 Mar 2012 13:12:43 -0600 Anthony Liguori <[email protected]> wrote:
Quoted 18 lines · Jan Kiszka
Quoted 17 lines · Luiz Capitulino
Quoted 13 lines · On Fri, 09 Mar 2012 19:20:56 +0100 Jan Kiszka<[email protected]> wrote:
Quoted 8 lines · Luiz Capitulino
The Monitor object is passed back and forth within the migration/savevm code so that it can print errors and progress to the user.
However, that approach assumes a HMP monitor, being completely invalid in QMP.
This commit drops almost every single usage of the Monitor object, all
monitor_printf()calls have been converted intoDPRINTF()ones.I guess for most printfs, this is OK. But do you provide an alternative for the block migration progress output? I did not find anything on first glance. That is not a debugging feature.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Can't the info migrate command be used for that?
This was introduced for synchronous migration, as usability improvement.
Synchronous migration doesn't exist in QMP.
It's certainly possible to make the synchronous monitor command spit out status as it already uses a polling loop to determine when migration completes.
As HMP now uses QMP as a real client, we'd have to make that information available for all QMP users. Best place is probably query-migrate.
Don't you prefer to drop the whole thing instead? :-)
Re: [Qemu-devel] [PATCH 3/4] Purge migration of (almost) everything to do with monitors
Quoted 7 lines · On Fri, 9 Mar 2012 16:48:10 -0300 Luiz Capitulino <[email protected]>…
Quoted 2 lines
It's certainly possible to make the synchronous monitor command spit out status as it already uses a polling loop to determine when migration completes.
As HMP now uses QMP as a real client, we'd have to make that information available for all QMP users. Best place is probably query-migrate.
Don't you prefer to drop the whole thing instead? :-)
Oh, we actually have block migration information in query-migrate already, maybe we can use that to have a progress bar (not sure it's the same info used by current progress bar though).
But dropping it is still a viable alternative :)
Re: [Qemu-devel] [PATCH 3/4] Purge migration of (almost) everything to do with monitors
Am 09.03.2012 20:57, schrieb Luiz Capitulino:
Quoted 9 lines
Quoted 6 lines · On Fri, 9 Mar 2012 16:48:10 -0300 Luiz Capitulino <[email protected]>…
Quoted 2 lines
It's certainly possible to make the synchronous monitor command spit out status as it already uses a polling loop to determine when migration completes.
As HMP now uses QMP as a real client, we'd have to make that information available for all QMP users. Best place is probably query-migrate.
Quoted 7 lines
Quoted 1 line
Don't you prefer to drop the whole thing instead? :-)
Oh, we actually have block migration information in query-migrate already, maybe we can use that to have a progress bar (not sure it's the same info used by current progress bar though).
But dropping it is still a viable alternative :)
We should use the decoupling of the human monitor to make it better rather than worse. :-)
Kevin
Re: [Qemu-devel] [PATCH 3/4] Purge migration of (almost) everything to do with monitors
Quoted 12 lines · On Mon, 12 Mar 2012 15:51:04 +0100 Kevin Wolf <[email protected]> wrote:
Am 09.03.2012 20:57, schrieb Luiz Capitulino:
Quoted 11 lines
Quoted 7 lines · On Fri, 9 Mar 2012 16:48:10 -0300 Luiz Capitulino <[email protected]>…
Quoted 2 lines
It's certainly possible to make the synchronous monitor command spit out status as it already uses a polling loop to determine when migration completes.
As HMP now uses QMP as a real client, we'd have to make that information available for all QMP users. Best place is probably query-migrate.
Don't you prefer to drop the whole thing instead? :-)
Quoted 8 lines
Quoted 5 lines
Oh, we actually have block migration information in query-migrate already, maybe we can use that to have a progress bar (not sure it's the same info used by current progress bar though).
But dropping it is still a viable alternative :)
We should use the decoupling of the human monitor to make it better rather than worse. :-)
I've implemented the progress counting and will submit a new version of the series later today.
Re: [Qemu-devel] [PATCH 3/4] Purge migration of (almost) everything to do with monitors
In reply to Jan KiszkaQuoted 7 lines · Jan Kiszka
Quoted 6 lines · Luiz Capitulino
The Monitor object is passed back and forth within the migration/savevm code so that it can print errors and progress to the user.
However, that approach assumes a HMP monitor, being completely invalid in QMP.
Quoted 6 lines
Quoted 2 lines
This commit drops almost every single usage of the Monitor object, all
monitor_printf()calls have been converted intoDPRINTF()ones.I guess for most printfs, this is OK. But do you provide an alternative for the block migration progress output? I did not find anything on first glance. That is not a debugging feature.
The block migration progress stuff is horribly broken and I regret ever merging it. Are you actively relying on this?
Does block migration even work?
Could we just remove block migration entirely...
Regards,
Anthony Liguori
Quoted 3 lines
Jan
Re: [Qemu-devel] [PATCH 3/4] Purge migration of (almost) everything to do with monitors
Quoted 15 lines · Anthony Liguori
Quoted 7 lines · Jan Kiszka
Quoted 6 lines · Luiz Capitulino
The Monitor object is passed back and forth within the migration/savevm code so that it can print errors and progress to the user.
However, that approach assumes a HMP monitor, being completely invalid in QMP.
Quoted 6 lines
Quoted 2 lines
This commit drops almost every single usage of the Monitor object, all
monitor_printf()calls have been converted intoDPRINTF()ones.I guess for most printfs, this is OK. But do you provide an alternative for the block migration progress output? I did not find anything on first glance. That is not a debugging feature.
Quoted 6 lines
The block migration progress stuff is horribly broken and I regret ever merging it. Are you actively relying on this?
Does block migration even work?
Could we just remove block migration entirely...
Libvirt has already exposed block migration to users, but it is untested; if, as you say, it is horribly broken, then libvirt needs to pass on the error message back to the user that it is broken. But we regularly get people complaining that they don't have shared storage set up, and they are looking for a magic bullet that will do block migration alongside the domain migration; perhaps libvirt can still provide that with block mirroring or other (working) solutions from the same API it gives to the user if you end up pulling it out of the migrate QMP command. At the end of the day, it's your call whether to pull it out, and libvirt will adapt, but it would be nice to know what kosher working alternative(s) to use instead.
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 3/4] Purge migration of (almost) everything to do with monitors
Quoted 16 lines · Eric Blake
Quoted 15 lines · Anthony Liguori
Quoted 13 lines · Jan Kiszka
Quoted 8 lines · Luiz Capitulino
The Monitor object is passed back and forth within the migration/savevm code so that it can print errors and progress to the user.
However, that approach assumes a HMP monitor, being completely invalid in QMP.
This commit drops almost every single usage of the Monitor object, all
monitor_printf()calls have been converted intoDPRINTF()ones.I guess for most printfs, this is OK. But do you provide an alternative for the block migration progress output? I did not find anything on first glance. That is not a debugging feature.
Quoted 8 lines
Quoted 6 lines
The block migration progress stuff is horribly broken and I regret ever merging it. Are you actively relying on this?
Does block migration even work?
Could we just remove block migration entirely...
Libvirt has already exposed block migration to users,
:-(
Do you rely on the progress stats that are printed?
Quoted 9 lines
but it is
untested; if, as you say, it is horribly broken, then libvirt needs to pass on the error message back to the user that it is broken. But we regularly get people complaining that they don't have shared storage set up, and they are looking for a magic bullet that will do block migration alongside the domain migration; perhaps libvirt can still provide that with block mirroring or other (working) solutions from the same API it gives to the user if you end up pulling it out of the migrate QMP command.
Well block mirroring is hopefully around the corner.
Regards,
Anthony Liguori
Quoted 4 lines
At the end of the day, it's your call whether to pull it out, and libvirt will adapt, but it would be nice to know what kosher working alternative(s) to use instead.
Re: [Qemu-devel] [PATCH 3/4] Purge migration of (almost) everything to do with monitors
Quoted 8 lines · Anthony Liguori
Quoted 4 lines
Quoted 2 lines
Could we just remove block migration entirely...
Libvirt has already exposed block migration to users,
:-(
Do you rely on the progress stats that are printed?
I've never personally used it (as I said earlier, the libvirt support for blk and inc doesn't get much testing), but I can state that if you do:
virsh migrate --copy-storage-all --copy-storage-inc --verbose ...
that virsh will cause libvirt to start up a detached migration, then repeatedly call the query-migrate monitor command to update an on-screen progress monitor to the user; this progress monitor tracks both ram and disk status to compute the percentage complete showed to the user, so at some level, libvirt really is trying to rely on accurate block migration progress numbers.
Quoted 8 lines
Quoted 6 lines
regularly get people complaining that they don't have shared storage set up, and they are looking for a magic bullet that will do block migration alongside the domain migration; perhaps libvirt can still provide that with block mirroring or other (working) solutions from the same API it gives to the user if you end up pulling it out of the migrate QMP command.
Well block mirroring is hopefully around the corner.
Just so I'm clear, are you talking about a more complete mirroring solution than just the storage migration use of mirroring that enables live block migration without also migrating VM state? Also, is this a qemu 1.1 planned feature, or will it more likely be in the 1.2 timeframe?
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 3/4] Purge migration of (almost) everything to do with monitors
Quoted 13 lines · Eric Blake
Quoted 8 lines · Anthony Liguori
Quoted 4 lines
Quoted 2 lines
Could we just remove block migration entirely...
Libvirt has already exposed block migration to users,
:-(
Do you rely on the progress stats that are printed?
I've never personally used it (as I said earlier, the libvirt support for blk and inc doesn't get much testing), but I can state that if you do:
Quoted 8 lines
virsh migrate --copy-storage-all --copy-storage-inc --verbose ...
that virsh will cause libvirt to start up a detached migration, then repeatedly call the query-migrate monitor command to update an on-screen progress monitor to the user; this progress monitor tracks both ram and disk status to compute the percentage complete showed to the user, so at some level, libvirt really is trying to rely on accurate block migration progress numbers.
Just realized I wasn't very clear:
libvirt does _not_ play back qemu's status numbers, so much as computing its _own_ progress monitor based on parsing the output of the repeated query-migrate commands. And since libvirt tends to favor QMP over HMP, the only monitoring we need from QMP is what we query for; we don't need HMP-style update messages. Having HMP update a progress line each time it rearms the one second timer while waiting for the migration to complete is probably good enough for HMP, and libvirt won't care.
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 3/4] Purge migration of (almost) everything to do with monitors
In reply to Anthony LiguoriQuoted 11 lines · Anthony Liguori
Quoted 10 lines · Jan Kiszka
Quoted 8 lines · Luiz Capitulino
The Monitor object is passed back and forth within the migration/savevm code so that it can print errors and progress to the user.
However, that approach assumes a HMP monitor, being completely invalid in QMP.
This commit drops almost every single usage of the Monitor object, all
monitor_printf()calls have been converted intoDPRINTF()ones.
Quoted 8 lines
Quoted 3 lines
I guess for most printfs, this is OK. But do you provide an alternative for the block migration progress output? I did not find anything on first glance. That is not a debugging feature.
The block migration progress stuff is horribly broken and I regret ever merging it. Are you actively relying on this?
Does block migration even work?
The last time I tried (a while back), it worked for me, but I also received reports that it was not working reliably.
Quoted 2 lines
Could we just remove block migration entirely...
Well, if we have a better alternative, replace it.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
PATCH v2 4/4 qapi: Convert migrate
In reply to Luiz CapitulinoThe migrate command is one of those commands where HMP and QMP completely mix up together. This made the conversion to the QAPI (which separates the command into QMP and HMP parts) a bit difficult.
The first important change to be noticed is that this commit completes the removal of the Monitor object from migration code, started by the previous commit.
Another important and tricky change is about supporting the non-detached mode. That's, if the user doesn't pass '-d' the migrate command will lock the monitor and will only release it when migration is finished.
To support that in the new HMP command (hmp_migrate()), it is necessary to create a timer which runs every second and checks if the migration is still active. If it's, the timer callback will re-schedule itself to run one second in the future. If the migration has already finished, the monitor lock is relased and the user can use it normally.
All these changes should be transparent to the user.
--- hmp-commands.hx | 3 +-- hmp.c | 56 +++++++++++++++++++++++++++++++++++++++++++++ hmp.h | 1 + migration-fd.c | 2 +- migration.c | 66 ++++++++++++++---------------------------------------- migration.h | 3 --- qapi-schema.json | 21 +++++++++++++++++ qmp-commands.hx | 9 +------- savevm.c | 13 +++++------ sysemu.h | 2 +- 10 files changed, 105 insertions(+), 71 deletions(-)
hmp-commands.hx +1 -2
@@ -806,8 +806,7 @@ ETEXI " full copy of disk\n\t\t\t -i for migration without " "shared storage with incremental copy of disk " "(base image shared between src and destination)", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_migrate, + .mhandler.cmd = hmp_migrate, },
hmp.c +56 -0
65 lines not on this page · raw message
hmp.h +1 -0
@@ -59,5 +59,6 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict);void hmp_block_stream (Monitor *mon,const QDict *qdict);void hmp_block_job_set_speed (Monitor *mon,const QDict *qdict);void hmp_block_job_cancel (Monitor *mon,const QDict *qdict); +void hmp_migrate (Monitor *mon,const QDict *qdict);#endif
migration-fd.c +1 -1
@@ -75,7 +75,7 @@ static int fd_close(MigrationState *s)int fd_start_outgoing_migration (MigrationState *s,const char *fdname) { - s->fd =monitor_get_fd (s->mon, fdname); + s->fd =monitor_get_fd (cur_mon, fdname);if (s->fd ==-1 ) {DPRINTF ("fd_migration: invalid file descriptor identifier\n" ); goto err_after_get_fd;
migration.c +17 -49
130 lines not on this page · raw message
migration.h +0 -3
@@ -26,7 +26,6 @@ struct MigrationStateint64_t bandwidth_limit;QEMUFile *file;int fd; -Monitor *mon;int state;int (*get_error)(MigrationState *s);int (*close)(MigrationState *s);
@@ -40,8 +39,6 @@ void process_incoming_migration(QEMUFile *f);int qemu_start_incoming_migration (const char *uri); -int do_migrate (Monitor *mon,const QDict *qdict,QObject **ret_data); -uint64_t migrate_max_downtime (void );void do_info_migrate_print (Monitor *mon,const QObject *data);
qapi-schema.json +21 -0
@@ -1631,3 +1631,24 @@ { 'command': 'qom-list-types', 'data': { '*implements': 'str', '*abstract': 'bool' }, 'returns': [ 'ObjectTypeInfo' ] } + +## +# @migrate +# +# Migrates the current running guest to another Virtual Machine. +# +# @uri: the Uniform Resource Identifier of the destination VM +# +# @blk: #optional do block migration (full disk copy) +# +# @inc: #optional incremental disk copy migration +# +# @detach: this argument exists only for compatibility reasons and should not +# be used. +# +# Returns: nothing on success +# +# Since: 0.14.0 +## +{ 'command': 'migrate', + 'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool' } }
qmp-commands.hx +1 -8
@@ -446,14 +446,7 @@ EQMP { .name = "migrate", .args_type = "detach:-d,blk:-b,inc:-i,uri:s", - .params = "[-d] [-b] [-i] uri", - .help = "migrate to URI (using -d to not wait for completion)" - "\n\t\t\t -b for migration without shared storage with" - " full copy of disk\n\t\t\t -i for migration without " - "shared storage with incremental copy of disk " - "(base image shared between src and destination)", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_migrate, + .mhandler.cmd_new = qmp_marshal_input_migrate, }, SQMP
savevm.c +6 -7
@@ -1540,14 +1540,13 @@ static void vmstate_save(QEMUFile *f, SaveStateEntry *se)#define QEMU_VM_SECTION_FULL 0x04#define QEMU_VM_SUBSECTION 0x05 -bool qemu_savevm_state_blocked (Monitor *mon) +bool qemu_savevm_state_blocked (Error **errp) {SaveStateEntry *se; QTAILQ_FOREACH(se, &savevm_handlers, entry) {if (se->no_migrate) { -monitor_printf (mon,"state blocked by non-migratable device '%s'\n" , - se->idstr); +error_set (errp,QERR_MIGRATION_NOT_SUPPORTED , se->idstr);return true; } }
@@ -1698,11 +1697,11 @@ void qemu_savevm_state_cancel(QEMUFile *f) } } -static int qemu_savevm_state (Monitor *mon,QEMUFile *f) +static int qemu_savevm_state (QEMUFile *f) {int ret; -if (qemu_savevm_state_blocked (mon)) { +if (qemu_savevm_state_blocked (NULL )) { ret = -EINVAL ; goto out; }
@@ -1836,7 +1835,7 @@ int qemu_loadvm_state(QEMUFile *f)unsigned int v;int ret; -if (qemu_savevm_state_blocked (default_mon)) { +if (qemu_savevm_state_blocked (NULL )) {return -EINVAL ; }
@@ -2080,7 +2079,7 @@ void do_savevm(Monitor *mon, const QDict *qdict)monitor_printf (mon,"Could not open VM state file\n" ); goto the_end; } - ret =qemu_savevm_state (mon, f); + ret =qemu_savevm_state (f); vm_state_size =qemu_ftell (f);qemu_fclose (f);if (ret <0 ) {
sysemu.h +1 -1
@@ -76,7 +76,7 @@ void do_info_snapshots(Monitor *mon);void qemu_announce_self (void ); -bool qemu_savevm_state_blocked (Monitor *mon); +bool qemu_savevm_state_blocked (Error **errp);int qemu_savevm_state_begin (QEMUFile *f,int blk_enable,int shared);int qemu_savevm_state_iterate (QEMUFile *f);int qemu_savevm_state_complete (QEMUFile *f);
Signature · 1 line
1.7.9.2.384.g4a92a
Quoted 10 lines · Luiz Capitulino
The migrate command is one of those commands where HMP and QMP completely mix up together. This made the conversion to the QAPI (which separates the command into QMP and HMP parts) a bit difficult.
The first important change to be noticed is that this commit completes the removal of the Monitor object from migration code, started by the previous commit.
Another important and tricky change is about supporting the non-detached mode. That's, if the user doesn't pass '-d' the migrate command will lock
As a native speaker, I can state that it is unusual or even wrong to see a contraction immediately before a comma. I would do:
s/That's,/That is,/
Quoted 5 lines
the monitor and will only release it when migration is finished.
To support that in the new HMP command (
hmp_migrate()), it is necessary to create a timer which runs every second and checks if the migration is still active. If it's, the timer callback will re-schedule itself to run
Another instance of the same grammar problem:
s/it's/it is/
Quoted 2 lines
one second in the future. If the migration has already finished, the monitor lock is relased and the user can use it normally.
s/relased/released/
Quoted 13 lines
All these changes should be transparent to the user.
+++
b/qapi-schema.jsonqapi-schema.json +4
-0@@ -1631,3 +1631,24 @@ { 'command': 'qom-list-types', 'data': { '*implements': 'str', '*abstract': 'bool' }, 'returns': [ 'ObjectTypeInfo' ] } + +## +# @migrate +#
qapi-schema.json line 1647
Quoted 10 lines
qapi-schema.json +10
-0+# Migrates the current running guest to another Virtual Machine. +# +# @uri: the Uniform Resource Identifier of the destination VM +# +# @blk: #optional do block migration (full disk copy) +# +# @inc: #optional incremental disk copy migration +# +# @detach: this argument exists only for compatibility reasons and should not +# be used.
Libvirt is currently using it, but it appears that libvirt always sets it to true. Does this mean the argument is ignored no matter whether you pass true or false? Or does this value have a default if omitted, and it is safe to explicitly pass the default (I assume the default is true), and that it is wrong to pass an explicit value that contradicts the default (that is, I'm assuming passing an explicit 'detach':'false' is wrong)?
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 9 lines · On Fri, 09 Mar 2012 11:26:53 -0700 Eric Blake <[email protected]> wrote:
Quoted 8 lines · Luiz Capitulino
The migrate command is one of those commands where HMP and QMP completely mix up together. This made the conversion to the QAPI (which separates the command into QMP and HMP parts) a bit difficult.
The first important change to be noticed is that this commit completes the removal of the Monitor object from migration code, started by the previous commit.
Quoted 5 lines
Quoted 2 lines
Another important and tricky change is about supporting the non-detached mode. That's, if the user doesn't pass '-d' the migrate command will lock
As a native speaker, I can state that it is unusual or even wrong to see a contraction immediately before a comma. I would do:
Oh, that rule is new to me. Thanks for letting me know!
Quoted 42 lines
s/That's,/That is,/
Quoted 5 lines
the monitor and will only release it when migration is finished.
To support that in the new HMP command (
hmp_migrate()), it is necessary to create a timer which runs every second and checks if the migration is still active. If it's, the timer callback will re-schedule itself to runAnother instance of the same grammar problem:
s/it's/it is/
Quoted 2 lines
one second in the future. If the migration has already finished, the monitor lock is relased and the user can use it normally.
s/relased/released/
Quoted 13 lines
All these changes should be transparent to the user.
+++
b/qapi-schema.jsonqapi-schema.json +4
-0@@ -1631,3 +1631,24 @@ { 'command': 'qom-list-types', 'data': { '*implements': 'str', '*abstract': 'bool' }, 'returns': [ 'ObjectTypeInfo' ] } + +## +# @migrate +#qapi-schema.json line 1647
Quoted 10 lines
qapi-schema.json +10
-0+# Migrates the current running guest to another Virtual Machine. +# +# @uri: the Uniform Resource Identifier of the destination VM +# +# @blk: #optional do block migration (full disk copy) +# +# @inc: #optional incremental disk copy migration +# +# @detach: this argument exists only for compatibility reasons and should not +# be used.
Quoted 7 lines
Libvirt is currently using it, but it appears that libvirt always sets it to true. Does this mean the argument is ignored no matter whether you pass true or false? Or does this value have a default if omitted, and it is safe to explicitly pass the default (I assume the default is true), and that it is wrong to pass an explicit value that contradicts the default (that is, I'm assuming passing an explicit 'detach':'false' is wrong)?
'detach' is completely ignored in QMP, it's never read.
Quoted 51 lines · Eric Blake
Quoted 10 lines · Luiz Capitulino
The migrate command is one of those commands where HMP and QMP completely mix up together. This made the conversion to the QAPI (which separates the command into QMP and HMP parts) a bit difficult.
The first important change to be noticed is that this commit completes the removal of the Monitor object from migration code, started by the previous commit.
Another important and tricky change is about supporting the non-detached mode. That's, if the user doesn't pass '-d' the migrate command will lock
As a native speaker, I can state that it is unusual or even wrong to see a contraction immediately before a comma. I would do:
s/That's,/That is,/
Quoted 5 lines
the monitor and will only release it when migration is finished.
To support that in the new HMP command (
hmp_migrate()), it is necessary to create a timer which runs every second and checks if the migration is still active. If it's, the timer callback will re-schedule itself to runAnother instance of the same grammar problem:
s/it's/it is/
Quoted 2 lines
one second in the future. If the migration has already finished, the monitor lock is relased and the user can use it normally.
s/relased/released/
Quoted 19 lines
All these changes should be transparent to the user.
+++
b/qapi-schema.jsonqapi-schema.json +10
-0@@ -1631,3 +1631,24 @@ { 'command': 'qom-list-types', 'data': { '*implements': 'str', '*abstract': 'bool' }, 'returns': [ 'ObjectTypeInfo' ] } + +## +# @migrate +# +# Migrates the current running guest to another Virtual Machine. +# +# @uri: the Uniform Resource Identifier of the destination VM +# +# @blk: #optional do block migration (full disk copy) +#
Quoted 8 lines
qapi-schema.json line 1647
Quoted 4 lines
qapi-schema.json +4
-0+# @inc: #optional incremental disk copy migration +# +# @detach: this argument exists only for compatibility reasons and should not +# be used.Libvirt is currently using it, but it appears that libvirt always sets it to true. Does this mean the argument is ignored no matter whether you pass true or false?
Yes, and we should specify that. The argument is ignored by QEMU.
Regards,
Anthony Liguori
Quoted 18 lines · On Fri, 09 Mar 2012 12:35:32 -0600 Anthony Liguori <[email protected]> wrote:
Quoted 9 lines
Quoted 9 lines
qapi-schema.json +9
-0+## +# @migrate +# +# Migrates the current running guest to another Virtual Machine. +# +# @uri: the Uniform Resource Identifier of the destination VM +# +# @blk: #optional do block migration (full disk copy) +#Quoted 8 lines
qapi-schema.json line 1647
Quoted 4 lines
qapi-schema.json +4
-0+# @inc: #optional incremental disk copy migration +# +# @detach: this argument exists only for compatibility reasons and should not +# be used.Libvirt is currently using it, but it appears that libvirt always sets it to true. Does this mean the argument is ignored no matter whether you pass true or false?
Quoted 1 line
Yes, and we should specify that. The argument is ignored by QEMU.
Will do for v3.
Quoted 98 lines · Luiz Capitulino
The migrate command is one of those commands where HMP and QMP completely mix up together. This made the conversion to the QAPI (which separates the command into QMP and HMP parts) a bit difficult.
The first important change to be noticed is that this commit completes the removal of the Monitor object from migration code, started by the previous commit.
Another important and tricky change is about supporting the non-detached mode. That's, if the user doesn't pass '-d' the migrate command will lock the monitor and will only release it when migration is finished.
To support that in the new HMP command (
hmp_migrate()), it is necessary to create a timer which runs every second and checks if the migration is still active. If it's, the timer callback will re-schedule itself to run one second in the future. If the migration has already finished, the monitor lock is relased and the user can use it normally.All these changes should be transparent to the user.
Signed-off-by Anthony Liguori <[email protected]>Signed-off-by Luiz Capitulino <[email protected]>--- hmp-commands.hx | 3 +-- hmp.c | 56 +++++++++++++++++++++++++++++++++++++++++++++ hmp.h | 1 + migration-fd.c | 2 +- migration.c | 66 ++++++++++++++---------------------------------------- migration.h | 3 --- qapi-schema.json | 21 +++++++++++++++++ qmp-commands.hx | 9 +------- savevm.c | 13 +++++------ sysemu.h | 2 +- 10 files changed, 105 insertions(+), 71 deletions(-)hmp-commands.hx +1
-2@@ -806,8 +806,7 @@ ETEXI " full copy of disk\n\t\t\t -i for migration without " "shared storage with incremental copy of disk " "(base image shared between src and destination)", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_migrate, + .mhandler.cmd = hmp_migrate, },hmp.c +34
-0@@ -14,6 +14,7 @@*/ #include "hmp.h" +#include "qemu-timer.h" #include "qmp-commands.h" static void hmp_handle_error (Monitor *mon,Error **errp)@@ -856,3 +857,58 @@ void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)hmp_handle_error (mon, &error); } + +typedef struct MigrationStatus +{ +QEMUTimer *timer; +Monitor *mon; +}MigrationStatus ; + +static void hmp_migrate_status_cb (void *opaque) +{ +MigrationStatus *status = opaque; +MigrationInfo *info; + + info =qmp_query_migrate (NULL ); +if (!info->has_status ||strcmp (info->status,"active" ) ==0 ) { +qemu_mod_timer (status->timer,qemu_get_clock_ms (rt_clock) +1000 ); + }else { +monitor_resume (status->mon); +qemu_del_timer (status->timer); +g_free (status); + } + +qapi_free_MigrationInfo (info); +} + +void hmp_migrate (Monitor *mon,const QDict *qdict) +{ +int detach =qdict_get_try_bool (qdict,"detach" ,0 ); +int blk =qdict_get_try_bool (qdict,"blk" ,0 ); +int inc =qdict_get_try_bool (qdict,"inc" ,0 ); +const char *uri =qdict_get_str (qdict,"uri" ); +Error *err =NULL ; + +qmp_migrate (uri, !!blk, blk, !!inc, inc, false, false, &err);
hmp.c void hmp_block_job_cancel(Monitor *mon, const QDict *qdict) · line 902
Quoted 10 lines
hmp.c +10
-0+if (err) { +monitor_printf (mon,"migrate: %s\n" ,error_get_pretty (err)); +error_free (err); +return ; + } + +if (!detach) { +MigrationStatus *status; + +if (monitor_suspend (mon) <0 ) {
So using monitor_suspend is ok? is that a possible solution for the screendump issue? I could pass the Monitor through the vga callback. Tbh I think it's ugly, but at least it doesn't introduce any new command.
Quoted 317 lines
hmp.c +12
-0+monitor_printf (mon,"terminal does not allow synchronous " +"migration, continuing detached\n" ); +return ; + } + + status =g_malloc0 (sizeof (*status)); + status->mon = mon; + status->timer =qemu_new_timer_ms (rt_clock, hmp_migrate_status_cb, + status); +qemu_mod_timer (status->timer,qemu_get_clock_ms (rt_clock)); + } +}hmp.h +1
-0@@ -59,5 +59,6 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict);void hmp_block_stream (Monitor *mon,const QDict *qdict);void hmp_block_job_set_speed (Monitor *mon,const QDict *qdict);void hmp_block_job_cancel (Monitor *mon,const QDict *qdict); +void hmp_migrate (Monitor *mon,const QDict *qdict);#endif migration-fd.c +1
-1@@ -75,7 +75,7 @@ static int fd_close(MigrationState *s)int fd_start_outgoing_migration (MigrationState *s,const char *fdname) { - s->fd =monitor_get_fd (s->mon, fdname); + s->fd =monitor_get_fd (cur_mon, fdname);if (s->fd ==-1 ) {DPRINTF ("fd_migration: invalid file descriptor identifier\n" ); goto err_after_get_fd;migration.c +17
-49@@ -158,16 +158,6 @@ MigrationInfo *qmp_query_migrate(Error **errp)/* shared migration helpers */ -static void migrate_fd_monitor_suspend (MigrationState *s,Monitor *mon) -{ -if (monitor_suspend (mon) ==0 ) { -DPRINTF ("suspending monitor\n" ); - }else { -monitor_printf (mon,"terminal does not allow synchronous " -"migration, continuing detached\n" ); - } -} -static int migrate_fd_cleanup (MigrationState *s) {int ret =0 ;@@ -178,10 +168,6 @@ static int migrate_fd_cleanup(MigrationState *s)DPRINTF ("closing file\n" ); ret =qemu_fclose (s->file); s->file =NULL ; - }else { -if (s->mon) { -monitor_resume (s->mon); - } }if (s->fd !=-1 ) {@@ -321,9 +307,6 @@ static int migrate_fd_close(void *opaque) {MigrationState *s = opaque; -if (s->mon) { -monitor_resume (s->mon); - }qemu_set_fd_handler2 (s->fd,NULL ,NULL ,NULL ,NULL );return s->close (s); }@@ -376,7 +359,7 @@ void migrate_fd_connect(MigrationState *s)migrate_fd_put_ready (s); } -static MigrationState *migrate_init (Monitor *mon,int detach,int blk,int inc) +static MigrationState *migrate_init (int blk,int inc) {MigrationState *s =migrate_get_current ();int64_t bandwidth_limit = s->bandwidth_limit;@@ -386,18 +369,9 @@ static MigrationState *migrate_init(Monitor *mon, int detach, int blk, int inc) s->blk = blk; s->shared = inc; -/* s->mon is used for two things: -- pass fd in fd migration -- suspend/resume monitor for not detached migration -*/ - s->mon = mon; s->bandwidth_limit = bandwidth_limit; s->state =MIG_STATE_SETUP ; -if (!detach) { -migrate_fd_monitor_suspend (s, mon); - } -return s; }@@ -413,32 +387,29 @@ void migrate_del_blocker(Error *reason) migration_blockers =g_slist_remove (migration_blockers, reason); } -int do_migrate (Monitor *mon,const QDict *qdict,QObject **ret_data) +void qmp_migrate (const char *uri,bool has_blk,bool blk, +bool has_inc,bool inc,bool has_detach,bool detach, +Error **errp) {MigrationState *s =migrate_get_current ();const char *p; -int detach =qdict_get_try_bool (qdict,"detach" ,0 ); -int blk =qdict_get_try_bool (qdict,"blk" ,0 ); -int inc =qdict_get_try_bool (qdict,"inc" ,0 ); -const char *uri =qdict_get_str (qdict,"uri" );int ret;if (s->state ==MIG_STATE_ACTIVE ) { -monitor_printf (mon,"migration already in progress\n" ); -return -1 ; +error_set (errp,QERR_MIGRATION_ACTIVE ); +return ; } -if (qemu_savevm_state_blocked (mon)) { -return -1 ; +if (qemu_savevm_state_blocked (errp)) { +return ; }if (migration_blockers) { -Error *err = migration_blockers->data; -qerror_report_err (err); -return -1 ; + *errp =error_copy (migration_blockers->data); +return ; } - s =migrate_init (mon, detach, blk, inc); + s =migrate_init (blk, inc);if (strstart (uri,"tcp:" , &p)) { ret =tcp_start_outgoing_migration (s, p);@@ -451,21 +422,18 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data) ret =fd_start_outgoing_migration (s, p);#endif }else { -monitor_printf (mon,"unknown migration protocol: %s\n" , uri); - ret = -EINVAL ; +error_set (errp,QERR_INVALID_PARAMETER_VALUE ,"uri" ,"a valid migration protocol" ); +return ; }if (ret <0 ) { -monitor_printf (mon,"migration failed: %s\n" ,strerror (-ret)); -return ret; - } - -if (detach) { - s->mon =NULL ; +DPRINTF ("migration failed: %s\n" ,strerror (-ret)); +/* FIXME: we should return meaningful errors */ +error_set (errp,QERR_UNDEFINED_ERROR ); +return ; }notifier_list_notify (&migration_state_notifiers, s); -return 0 ; }void qmp_migrate_cancel (Error **errp)migration.h +0
-3@@ -26,7 +26,6 @@ struct MigrationStateint64_t bandwidth_limit;QEMUFile *file;int fd; -Monitor *mon;int state;int (*get_error)(MigrationState *s);int (*close)(MigrationState *s);@@ -40,8 +39,6 @@ void process_incoming_migration(QEMUFile *f);int qemu_start_incoming_migration (const char *uri); -int do_migrate (Monitor *mon,const QDict *qdict,QObject **ret_data); -uint64_t migrate_max_downtime (void );void do_info_migrate_print (Monitor *mon,const QObject *data);qapi-schema.json +21
-0@@ -1631,3 +1631,24 @@ { 'command': 'qom-list-types', 'data': { '*implements': 'str', '*abstract': 'bool' }, 'returns': [ 'ObjectTypeInfo' ] } + +## +# @migrate +# +# Migrates the current running guest to another Virtual Machine. +# +# @uri: the Uniform Resource Identifier of the destination VM +# +# @blk: #optional do block migration (full disk copy) +# +# @inc: #optional incremental disk copy migration +# +# @detach: this argument exists only for compatibility reasons and should not +# be used. +# +# Returns: nothing on success +# +# Since: 0.14.0 +## +{ 'command': 'migrate', + 'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool' } }qmp-commands.hx +1
-8@@ -446,14 +446,7 @@ EQMP { .name = "migrate", .args_type = "detach:-d,blk:-b,inc:-i,uri:s", - .params = "[-d] [-b] [-i] uri", - .help = "migrate to URI (using -d to not wait for completion)" - "\n\t\t\t -b for migration without shared storage with" - " full copy of disk\n\t\t\t -i for migration without " - "shared storage with incremental copy of disk " - "(base image shared between src and destination)", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_migrate, + .mhandler.cmd_new = qmp_marshal_input_migrate, }, SQMPsavevm.c +6
-7@@ -1540,14 +1540,13 @@ static void vmstate_save(QEMUFile *f, SaveStateEntry *se)#define QEMU_VM_SECTION_FULL 0x04#define QEMU_VM_SUBSECTION 0x05 -bool qemu_savevm_state_blocked (Monitor *mon) +bool qemu_savevm_state_blocked (Error **errp) {SaveStateEntry *se; QTAILQ_FOREACH(se, &savevm_handlers, entry) {if (se->no_migrate) { -monitor_printf (mon,"state blocked by non-migratable device '%s'\n" , - se->idstr); +error_set (errp,QERR_MIGRATION_NOT_SUPPORTED , se->idstr);return true; } }@@ -1698,11 +1697,11 @@ void qemu_savevm_state_cancel(QEMUFile *f) } } -static int qemu_savevm_state (Monitor *mon,QEMUFile *f) +static int qemu_savevm_state (QEMUFile *f) {int ret; -if (qemu_savevm_state_blocked (mon)) { +if (qemu_savevm_state_blocked (NULL )) { ret = -EINVAL ; goto out; }@@ -1836,7 +1835,7 @@ int qemu_loadvm_state(QEMUFile *f)unsigned int v;int ret; -if (qemu_savevm_state_blocked (default_mon)) { +if (qemu_savevm_state_blocked (NULL )) {return -EINVAL ; }@@ -2080,7 +2079,7 @@ void do_savevm(Monitor *mon, const QDict *qdict)monitor_printf (mon,"Could not open VM state file\n" ); goto the_end; } - ret =qemu_savevm_state (mon, f); + ret =qemu_savevm_state (f); vm_state_size =qemu_ftell (f);qemu_fclose (f);if (ret <0 ) {sysemu.h +1
-1@@ -76,7 +76,7 @@ void do_info_snapshots(Monitor *mon);void qemu_announce_self (void ); -bool qemu_savevm_state_blocked (Monitor *mon); +bool qemu_savevm_state_blocked (Error **errp);int qemu_savevm_state_begin (QEMUFile *f,int blk_enable,int shared);int qemu_savevm_state_iterate (QEMUFile *f);int qemu_savevm_state_complete (QEMUFile *f);Signature · 1 line
1.7.9.2.384.g4a92a
Quoted 105 lines · On Sat, 10 Mar 2012 00:51:29 +0200 Alon Levy <[email protected]> wrote:
Quoted 104 lines · Luiz Capitulino
The migrate command is one of those commands where HMP and QMP completely mix up together. This made the conversion to the QAPI (which separates the command into QMP and HMP parts) a bit difficult.
The first important change to be noticed is that this commit completes the removal of the Monitor object from migration code, started by the previous commit.
Another important and tricky change is about supporting the non-detached mode. That's, if the user doesn't pass '-d' the migrate command will lock the monitor and will only release it when migration is finished.
To support that in the new HMP command (
hmp_migrate()), it is necessary to create a timer which runs every second and checks if the migration is still active. If it's, the timer callback will re-schedule itself to run one second in the future. If the migration has already finished, the monitor lock is relased and the user can use it normally.All these changes should be transparent to the user.
Signed-off-by Anthony Liguori <[email protected]>Signed-off-by Luiz Capitulino <[email protected]>--- hmp-commands.hx | 3 +-- hmp.c | 56 +++++++++++++++++++++++++++++++++++++++++++++ hmp.h | 1 + migration-fd.c | 2 +- migration.c | 66 ++++++++++++++---------------------------------------- migration.h | 3 --- qapi-schema.json | 21 +++++++++++++++++ qmp-commands.hx | 9 +------- savevm.c | 13 +++++------ sysemu.h | 2 +- 10 files changed, 105 insertions(+), 71 deletions(-)hmp-commands.hx +1
-2@@ -806,8 +806,7 @@ ETEXI " full copy of disk\n\t\t\t -i for migration without " "shared storage with incremental copy of disk " "(base image shared between src and destination)", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_migrate, + .mhandler.cmd = hmp_migrate, },hmp.c +40
-0@@ -14,6 +14,7 @@*/ #include "hmp.h" +#include "qemu-timer.h" #include "qmp-commands.h" static void hmp_handle_error (Monitor *mon,Error **errp)@@ -856,3 +857,58 @@ void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)hmp_handle_error (mon, &error); } + +typedef struct MigrationStatus +{ +QEMUTimer *timer; +Monitor *mon; +}MigrationStatus ; + +static void hmp_migrate_status_cb (void *opaque) +{ +MigrationStatus *status = opaque; +MigrationInfo *info; + + info =qmp_query_migrate (NULL ); +if (!info->has_status ||strcmp (info->status,"active" ) ==0 ) { +qemu_mod_timer (status->timer,qemu_get_clock_ms (rt_clock) +1000 ); + }else { +monitor_resume (status->mon); +qemu_del_timer (status->timer); +g_free (status); + } + +qapi_free_MigrationInfo (info); +} + +void hmp_migrate (Monitor *mon,const QDict *qdict) +{ +int detach =qdict_get_try_bool (qdict,"detach" ,0 ); +int blk =qdict_get_try_bool (qdict,"blk" ,0 ); +int inc =qdict_get_try_bool (qdict,"inc" ,0 ); +const char *uri =qdict_get_str (qdict,"uri" ); +Error *err =NULL ; + +qmp_migrate (uri, !!blk, blk, !!inc, inc, false, false, &err); +if (err) { +monitor_printf (mon,"migrate: %s\n" ,error_get_pretty (err)); +error_free (err); +return ; + } +
Quoted 8 lines
hmp.c void hmp_block_job_cancel(Monitor *mon, const QDict *qdict) · line 902
Quoted 4 lines
hmp.c +4
-0+if (!detach) { +MigrationStatus *status; + +if (monitor_suspend (mon) <0 ) {So using
monitor_suspendis ok? is that a possible solution for the screendump issue? I could pass the Monitor through the vga callback. Tbh I think it's ugly, but at least it doesn't introduce any new command.
This is only valid for HMP.
Quoted 319 lines
Quoted 318 lines
hmp.c +12
-0+monitor_printf (mon,"terminal does not allow synchronous " +"migration, continuing detached\n" ); +return ; + } + + status =g_malloc0 (sizeof (*status)); + status->mon = mon; + status->timer =qemu_new_timer_ms (rt_clock, hmp_migrate_status_cb, + status); +qemu_mod_timer (status->timer,qemu_get_clock_ms (rt_clock)); + } +}hmp.h +1
-0@@ -59,5 +59,6 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict);void hmp_block_stream (Monitor *mon,const QDict *qdict);void hmp_block_job_set_speed (Monitor *mon,const QDict *qdict);void hmp_block_job_cancel (Monitor *mon,const QDict *qdict); +void hmp_migrate (Monitor *mon,const QDict *qdict);#endif migration-fd.c +1
-1@@ -75,7 +75,7 @@ static int fd_close(MigrationState *s)int fd_start_outgoing_migration (MigrationState *s,const char *fdname) { - s->fd =monitor_get_fd (s->mon, fdname); + s->fd =monitor_get_fd (cur_mon, fdname);if (s->fd ==-1 ) {DPRINTF ("fd_migration: invalid file descriptor identifier\n" ); goto err_after_get_fd;migration.c +17
-49@@ -158,16 +158,6 @@ MigrationInfo *qmp_query_migrate(Error **errp)/* shared migration helpers */ -static void migrate_fd_monitor_suspend (MigrationState *s,Monitor *mon) -{ -if (monitor_suspend (mon) ==0 ) { -DPRINTF ("suspending monitor\n" ); - }else { -monitor_printf (mon,"terminal does not allow synchronous " -"migration, continuing detached\n" ); - } -} -static int migrate_fd_cleanup (MigrationState *s) {int ret =0 ;@@ -178,10 +168,6 @@ static int migrate_fd_cleanup(MigrationState *s)DPRINTF ("closing file\n" ); ret =qemu_fclose (s->file); s->file =NULL ; - }else { -if (s->mon) { -monitor_resume (s->mon); - } }if (s->fd !=-1 ) {@@ -321,9 +307,6 @@ static int migrate_fd_close(void *opaque) {MigrationState *s = opaque; -if (s->mon) { -monitor_resume (s->mon); - }qemu_set_fd_handler2 (s->fd,NULL ,NULL ,NULL ,NULL );return s->close (s); }@@ -376,7 +359,7 @@ void migrate_fd_connect(MigrationState *s)migrate_fd_put_ready (s); } -static MigrationState *migrate_init (Monitor *mon,int detach,int blk,int inc) +static MigrationState *migrate_init (int blk,int inc) {MigrationState *s =migrate_get_current ();int64_t bandwidth_limit = s->bandwidth_limit;@@ -386,18 +369,9 @@ static MigrationState *migrate_init(Monitor *mon, int detach, int blk, int inc) s->blk = blk; s->shared = inc; -/* s->mon is used for two things: -- pass fd in fd migration -- suspend/resume monitor for not detached migration -*/ - s->mon = mon; s->bandwidth_limit = bandwidth_limit; s->state =MIG_STATE_SETUP ; -if (!detach) { -migrate_fd_monitor_suspend (s, mon); - } -return s; }@@ -413,32 +387,29 @@ void migrate_del_blocker(Error *reason) migration_blockers =g_slist_remove (migration_blockers, reason); } -int do_migrate (Monitor *mon,const QDict *qdict,QObject **ret_data) +void qmp_migrate (const char *uri,bool has_blk,bool blk, +bool has_inc,bool inc,bool has_detach,bool detach, +Error **errp) {MigrationState *s =migrate_get_current ();const char *p; -int detach =qdict_get_try_bool (qdict,"detach" ,0 ); -int blk =qdict_get_try_bool (qdict,"blk" ,0 ); -int inc =qdict_get_try_bool (qdict,"inc" ,0 ); -const char *uri =qdict_get_str (qdict,"uri" );int ret;if (s->state ==MIG_STATE_ACTIVE ) { -monitor_printf (mon,"migration already in progress\n" ); -return -1 ; +error_set (errp,QERR_MIGRATION_ACTIVE ); +return ; } -if (qemu_savevm_state_blocked (mon)) { -return -1 ; +if (qemu_savevm_state_blocked (errp)) { +return ; }if (migration_blockers) { -Error *err = migration_blockers->data; -qerror_report_err (err); -return -1 ; + *errp =error_copy (migration_blockers->data); +return ; } - s =migrate_init (mon, detach, blk, inc); + s =migrate_init (blk, inc);if (strstart (uri,"tcp:" , &p)) { ret =tcp_start_outgoing_migration (s, p);@@ -451,21 +422,18 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data) ret =fd_start_outgoing_migration (s, p);#endif }else { -monitor_printf (mon,"unknown migration protocol: %s\n" , uri); - ret = -EINVAL ; +error_set (errp,QERR_INVALID_PARAMETER_VALUE ,"uri" ,"a valid migration protocol" ); +return ; }if (ret <0 ) { -monitor_printf (mon,"migration failed: %s\n" ,strerror (-ret)); -return ret; - } - -if (detach) { - s->mon =NULL ; +DPRINTF ("migration failed: %s\n" ,strerror (-ret)); +/* FIXME: we should return meaningful errors */ +error_set (errp,QERR_UNDEFINED_ERROR ); +return ; }notifier_list_notify (&migration_state_notifiers, s); -return 0 ; }void qmp_migrate_cancel (Error **errp)migration.h +0
-3@@ -26,7 +26,6 @@ struct MigrationStateint64_t bandwidth_limit;QEMUFile *file;int fd; -Monitor *mon;int state;int (*get_error)(MigrationState *s);int (*close)(MigrationState *s);@@ -40,8 +39,6 @@ void process_incoming_migration(QEMUFile *f);int qemu_start_incoming_migration (const char *uri); -int do_migrate (Monitor *mon,const QDict *qdict,QObject **ret_data); -uint64_t migrate_max_downtime (void );void do_info_migrate_print (Monitor *mon,const QObject *data);qapi-schema.json +21
-0@@ -1631,3 +1631,24 @@ { 'command': 'qom-list-types', 'data': { '*implements': 'str', '*abstract': 'bool' }, 'returns': [ 'ObjectTypeInfo' ] } + +## +# @migrate +# +# Migrates the current running guest to another Virtual Machine. +# +# @uri: the Uniform Resource Identifier of the destination VM +# +# @blk: #optional do block migration (full disk copy) +# +# @inc: #optional incremental disk copy migration +# +# @detach: this argument exists only for compatibility reasons and should not +# be used. +# +# Returns: nothing on success +# +# Since: 0.14.0 +## +{ 'command': 'migrate', + 'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool' } }qmp-commands.hx +1
-8@@ -446,14 +446,7 @@ EQMP { .name = "migrate", .args_type = "detach:-d,blk:-b,inc:-i,uri:s", - .params = "[-d] [-b] [-i] uri", - .help = "migrate to URI (using -d to not wait for completion)" - "\n\t\t\t -b for migration without shared storage with" - " full copy of disk\n\t\t\t -i for migration without " - "shared storage with incremental copy of disk " - "(base image shared between src and destination)", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_migrate, + .mhandler.cmd_new = qmp_marshal_input_migrate, }, SQMPsavevm.c +6
-7@@ -1540,14 +1540,13 @@ static void vmstate_save(QEMUFile *f, SaveStateEntry *se)#define QEMU_VM_SECTION_FULL 0x04#define QEMU_VM_SUBSECTION 0x05 -bool qemu_savevm_state_blocked (Monitor *mon) +bool qemu_savevm_state_blocked (Error **errp) {SaveStateEntry *se; QTAILQ_FOREACH(se, &savevm_handlers, entry) {if (se->no_migrate) { -monitor_printf (mon,"state blocked by non-migratable device '%s'\n" , - se->idstr); +error_set (errp,QERR_MIGRATION_NOT_SUPPORTED , se->idstr);return true; } }@@ -1698,11 +1697,11 @@ void qemu_savevm_state_cancel(QEMUFile *f) } } -static int qemu_savevm_state (Monitor *mon,QEMUFile *f) +static int qemu_savevm_state (QEMUFile *f) {int ret; -if (qemu_savevm_state_blocked (mon)) { +if (qemu_savevm_state_blocked (NULL )) { ret = -EINVAL ; goto out; }@@ -1836,7 +1835,7 @@ int qemu_loadvm_state(QEMUFile *f)unsigned int v;int ret; -if (qemu_savevm_state_blocked (default_mon)) { +if (qemu_savevm_state_blocked (NULL )) {return -EINVAL ; }@@ -2080,7 +2079,7 @@ void do_savevm(Monitor *mon, const QDict *qdict)monitor_printf (mon,"Could not open VM state file\n" ); goto the_end; } - ret =qemu_savevm_state (mon, f); + ret =qemu_savevm_state (f); vm_state_size =qemu_ftell (f);qemu_fclose (f);if (ret <0 ) {sysemu.h +1
-1@@ -76,7 +76,7 @@ void do_info_snapshots(Monitor *mon);void qemu_announce_self (void ); -bool qemu_savevm_state_blocked (Monitor *mon); +bool qemu_savevm_state_blocked (Error **errp);int qemu_savevm_state_begin (QEMUFile *f,int blk_enable,int shared);int qemu_savevm_state_iterate (QEMUFile *f);int qemu_savevm_state_complete (QEMUFile *f);Signature · 1 line
1.7.9.2.384.g4a92a
Quoted 117 lines · Luiz Capitulino
Quoted 105 lines · On Sat, 10 Mar 2012 00:51:29 +0200 Alon Levy <[email protected]> wrote:
Quoted 104 lines · Luiz Capitulino
The migrate command is one of those commands where HMP and QMP completely mix up together. This made the conversion to the QAPI (which separates the command into QMP and HMP parts) a bit difficult.
The first important change to be noticed is that this commit completes the removal of the Monitor object from migration code, started by the previous commit.
Another important and tricky change is about supporting the non-detached mode. That's, if the user doesn't pass '-d' the migrate command will lock the monitor and will only release it when migration is finished.
To support that in the new HMP command (
hmp_migrate()), it is necessary to create a timer which runs every second and checks if the migration is still active. If it's, the timer callback will re-schedule itself to run one second in the future. If the migration has already finished, the monitor lock is relased and the user can use it normally.All these changes should be transparent to the user.
Signed-off-by Anthony Liguori <[email protected]>Signed-off-by Luiz Capitulino <[email protected]>--- hmp-commands.hx | 3 +-- hmp.c | 56 +++++++++++++++++++++++++++++++++++++++++++++ hmp.h | 1 + migration-fd.c | 2 +- migration.c | 66 ++++++++++++++---------------------------------------- migration.h | 3 --- qapi-schema.json | 21 +++++++++++++++++ qmp-commands.hx | 9 +------- savevm.c | 13 +++++------ sysemu.h | 2 +- 10 files changed, 105 insertions(+), 71 deletions(-)hmp-commands.hx +1
-2@@ -806,8 +806,7 @@ ETEXI " full copy of disk\n\t\t\t -i for migration without " "shared storage with incremental copy of disk " "(base image shared between src and destination)", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_migrate, + .mhandler.cmd = hmp_migrate, },hmp.c +40
-0@@ -14,6 +14,7 @@*/ #include "hmp.h" +#include "qemu-timer.h" #include "qmp-commands.h" static void hmp_handle_error (Monitor *mon,Error **errp)@@ -856,3 +857,58 @@ void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)hmp_handle_error (mon, &error); } + +typedef struct MigrationStatus +{ +QEMUTimer *timer; +Monitor *mon; +}MigrationStatus ; + +static void hmp_migrate_status_cb (void *opaque) +{ +MigrationStatus *status = opaque; +MigrationInfo *info; + + info =qmp_query_migrate (NULL ); +if (!info->has_status ||strcmp (info->status,"active" ) ==0 ) { +qemu_mod_timer (status->timer,qemu_get_clock_ms (rt_clock) +1000 ); + }else { +monitor_resume (status->mon); +qemu_del_timer (status->timer); +g_free (status); + } + +qapi_free_MigrationInfo (info); +} + +void hmp_migrate (Monitor *mon,const QDict *qdict) +{ +int detach =qdict_get_try_bool (qdict,"detach" ,0 ); +int blk =qdict_get_try_bool (qdict,"blk" ,0 ); +int inc =qdict_get_try_bool (qdict,"inc" ,0 ); +const char *uri =qdict_get_str (qdict,"uri" ); +Error *err =NULL ; + +qmp_migrate (uri, !!blk, blk, !!inc, inc, false, false, &err); +if (err) { +monitor_printf (mon,"migrate: %s\n" ,error_get_pretty (err)); +error_free (err); +return ; + } +Quoted 8 lines
hmp.c void hmp_block_job_cancel(Monitor *mon, const QDict *qdict) · line 902
Quoted 4 lines
hmp.c +4
-0+if (!detach) { +MigrationStatus *status; + +if (monitor_suspend (mon) <0 ) {So using
monitor_suspendis ok? is that a possible solution for the screendump issue? I could pass the Monitor through the vga callback. Tbh I think it's ugly, but at least it doesn't introduce any new command.
Quoted 2 lines
This is only valid for HMP.
Yes, I'm thinking at this point for qmp to wait for the output file to be written via repeated poll / inotify.
Quoted 320 lines
Quoted 319 lines
Quoted 318 lines
hmp.c +12
-0+monitor_printf (mon,"terminal does not allow synchronous " +"migration, continuing detached\n" ); +return ; + } + + status =g_malloc0 (sizeof (*status)); + status->mon = mon; + status->timer =qemu_new_timer_ms (rt_clock, hmp_migrate_status_cb, + status); +qemu_mod_timer (status->timer,qemu_get_clock_ms (rt_clock)); + } +}hmp.h +1
-0@@ -59,5 +59,6 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict);void hmp_block_stream (Monitor *mon,const QDict *qdict);void hmp_block_job_set_speed (Monitor *mon,const QDict *qdict);void hmp_block_job_cancel (Monitor *mon,const QDict *qdict); +void hmp_migrate (Monitor *mon,const QDict *qdict);#endif migration-fd.c +1
-1@@ -75,7 +75,7 @@ static int fd_close(MigrationState *s)int fd_start_outgoing_migration (MigrationState *s,const char *fdname) { - s->fd =monitor_get_fd (s->mon, fdname); + s->fd =monitor_get_fd (cur_mon, fdname);if (s->fd ==-1 ) {DPRINTF ("fd_migration: invalid file descriptor identifier\n" ); goto err_after_get_fd;migration.c +17
-49@@ -158,16 +158,6 @@ MigrationInfo *qmp_query_migrate(Error **errp)/* shared migration helpers */ -static void migrate_fd_monitor_suspend (MigrationState *s,Monitor *mon) -{ -if (monitor_suspend (mon) ==0 ) { -DPRINTF ("suspending monitor\n" ); - }else { -monitor_printf (mon,"terminal does not allow synchronous " -"migration, continuing detached\n" ); - } -} -static int migrate_fd_cleanup (MigrationState *s) {int ret =0 ;@@ -178,10 +168,6 @@ static int migrate_fd_cleanup(MigrationState *s)DPRINTF ("closing file\n" ); ret =qemu_fclose (s->file); s->file =NULL ; - }else { -if (s->mon) { -monitor_resume (s->mon); - } }if (s->fd !=-1 ) {@@ -321,9 +307,6 @@ static int migrate_fd_close(void *opaque) {MigrationState *s = opaque; -if (s->mon) { -monitor_resume (s->mon); - }qemu_set_fd_handler2 (s->fd,NULL ,NULL ,NULL ,NULL );return s->close (s); }@@ -376,7 +359,7 @@ void migrate_fd_connect(MigrationState *s)migrate_fd_put_ready (s); } -static MigrationState *migrate_init (Monitor *mon,int detach,int blk,int inc) +static MigrationState *migrate_init (int blk,int inc) {MigrationState *s =migrate_get_current ();int64_t bandwidth_limit = s->bandwidth_limit;@@ -386,18 +369,9 @@ static MigrationState *migrate_init(Monitor *mon, int detach, int blk, int inc) s->blk = blk; s->shared = inc; -/* s->mon is used for two things: -- pass fd in fd migration -- suspend/resume monitor for not detached migration -*/ - s->mon = mon; s->bandwidth_limit = bandwidth_limit; s->state =MIG_STATE_SETUP ; -if (!detach) { -migrate_fd_monitor_suspend (s, mon); - } -return s; }@@ -413,32 +387,29 @@ void migrate_del_blocker(Error *reason) migration_blockers =g_slist_remove (migration_blockers, reason); } -int do_migrate (Monitor *mon,const QDict *qdict,QObject **ret_data) +void qmp_migrate (const char *uri,bool has_blk,bool blk, +bool has_inc,bool inc,bool has_detach,bool detach, +Error **errp) {MigrationState *s =migrate_get_current ();const char *p; -int detach =qdict_get_try_bool (qdict,"detach" ,0 ); -int blk =qdict_get_try_bool (qdict,"blk" ,0 ); -int inc =qdict_get_try_bool (qdict,"inc" ,0 ); -const char *uri =qdict_get_str (qdict,"uri" );int ret;if (s->state ==MIG_STATE_ACTIVE ) { -monitor_printf (mon,"migration already in progress\n" ); -return -1 ; +error_set (errp,QERR_MIGRATION_ACTIVE ); +return ; } -if (qemu_savevm_state_blocked (mon)) { -return -1 ; +if (qemu_savevm_state_blocked (errp)) { +return ; }if (migration_blockers) { -Error *err = migration_blockers->data; -qerror_report_err (err); -return -1 ; + *errp =error_copy (migration_blockers->data); +return ; } - s =migrate_init (mon, detach, blk, inc); + s =migrate_init (blk, inc);if (strstart (uri,"tcp:" , &p)) { ret =tcp_start_outgoing_migration (s, p);@@ -451,21 +422,18 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data) ret =fd_start_outgoing_migration (s, p);#endif }else { -monitor_printf (mon,"unknown migration protocol: %s\n" , uri); - ret = -EINVAL ; +error_set (errp,QERR_INVALID_PARAMETER_VALUE ,"uri" ,"a valid migration protocol" ); +return ; }if (ret <0 ) { -monitor_printf (mon,"migration failed: %s\n" ,strerror (-ret)); -return ret; - } - -if (detach) { - s->mon =NULL ; +DPRINTF ("migration failed: %s\n" ,strerror (-ret)); +/* FIXME: we should return meaningful errors */ +error_set (errp,QERR_UNDEFINED_ERROR ); +return ; }notifier_list_notify (&migration_state_notifiers, s); -return 0 ; }void qmp_migrate_cancel (Error **errp)migration.h +0
-3@@ -26,7 +26,6 @@ struct MigrationStateint64_t bandwidth_limit;QEMUFile *file;int fd; -Monitor *mon;int state;int (*get_error)(MigrationState *s);int (*close)(MigrationState *s);@@ -40,8 +39,6 @@ void process_incoming_migration(QEMUFile *f);int qemu_start_incoming_migration (const char *uri); -int do_migrate (Monitor *mon,const QDict *qdict,QObject **ret_data); -uint64_t migrate_max_downtime (void );void do_info_migrate_print (Monitor *mon,const QObject *data);qapi-schema.json +21
-0@@ -1631,3 +1631,24 @@ { 'command': 'qom-list-types', 'data': { '*implements': 'str', '*abstract': 'bool' }, 'returns': [ 'ObjectTypeInfo' ] } + +## +# @migrate +# +# Migrates the current running guest to another Virtual Machine. +# +# @uri: the Uniform Resource Identifier of the destination VM +# +# @blk: #optional do block migration (full disk copy) +# +# @inc: #optional incremental disk copy migration +# +# @detach: this argument exists only for compatibility reasons and should not +# be used. +# +# Returns: nothing on success +# +# Since: 0.14.0 +## +{ 'command': 'migrate', + 'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool' } }qmp-commands.hx +1
-8@@ -446,14 +446,7 @@ EQMP { .name = "migrate", .args_type = "detach:-d,blk:-b,inc:-i,uri:s", - .params = "[-d] [-b] [-i] uri", - .help = "migrate to URI (using -d to not wait for completion)" - "\n\t\t\t -b for migration without shared storage with" - " full copy of disk\n\t\t\t -i for migration without " - "shared storage with incremental copy of disk " - "(base image shared between src and destination)", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_migrate, + .mhandler.cmd_new = qmp_marshal_input_migrate, }, SQMPsavevm.c +6
-7@@ -1540,14 +1540,13 @@ static void vmstate_save(QEMUFile *f, SaveStateEntry *se)#define QEMU_VM_SECTION_FULL 0x04#define QEMU_VM_SUBSECTION 0x05 -bool qemu_savevm_state_blocked (Monitor *mon) +bool qemu_savevm_state_blocked (Error **errp) {SaveStateEntry *se; QTAILQ_FOREACH(se, &savevm_handlers, entry) {if (se->no_migrate) { -monitor_printf (mon,"state blocked by non-migratable device '%s'\n" , - se->idstr); +error_set (errp,QERR_MIGRATION_NOT_SUPPORTED , se->idstr);return true; } }@@ -1698,11 +1697,11 @@ void qemu_savevm_state_cancel(QEMUFile *f) } } -static int qemu_savevm_state (Monitor *mon,QEMUFile *f) +static int qemu_savevm_state (QEMUFile *f) {int ret; -if (qemu_savevm_state_blocked (mon)) { +if (qemu_savevm_state_blocked (NULL )) { ret = -EINVAL ; goto out; }@@ -1836,7 +1835,7 @@ int qemu_loadvm_state(QEMUFile *f)unsigned int v;int ret; -if (qemu_savevm_state_blocked (default_mon)) { +if (qemu_savevm_state_blocked (NULL )) {return -EINVAL ; }@@ -2080,7 +2079,7 @@ void do_savevm(Monitor *mon, const QDict *qdict)monitor_printf (mon,"Could not open VM state file\n" ); goto the_end; } - ret =qemu_savevm_state (mon, f); + ret =qemu_savevm_state (f); vm_state_size =qemu_ftell (f);qemu_fclose (f);if (ret <0 ) {sysemu.h +1
-1@@ -76,7 +76,7 @@ void do_info_snapshots(Monitor *mon);void qemu_announce_self (void ); -bool qemu_savevm_state_blocked (Monitor *mon); +bool qemu_savevm_state_blocked (Error **errp);int qemu_savevm_state_begin (QEMUFile *f,int blk_enable,int shared);int qemu_savevm_state_iterate (QEMUFile *f);int qemu_savevm_state_complete (QEMUFile *f);Signature · 1 line
1.7.9.2.384.g4a92a
Quoted 118 lines · On Mon, 12 Mar 2012 15:49:27 +0200 Alon Levy <[email protected]> wrote:
Quoted 117 lines · Luiz Capitulino
Quoted 113 lines · On Sat, 10 Mar 2012 00:51:29 +0200 Alon Levy <[email protected]> wrote:
Quoted 98 lines · Luiz Capitulino
The migrate command is one of those commands where HMP and QMP completely mix up together. This made the conversion to the QAPI (which separates the command into QMP and HMP parts) a bit difficult.
The first important change to be noticed is that this commit completes the removal of the Monitor object from migration code, started by the previous commit.
Another important and tricky change is about supporting the non-detached mode. That's, if the user doesn't pass '-d' the migrate command will lock the monitor and will only release it when migration is finished.
To support that in the new HMP command (
hmp_migrate()), it is necessary to create a timer which runs every second and checks if the migration is still active. If it's, the timer callback will re-schedule itself to run one second in the future. If the migration has already finished, the monitor lock is relased and the user can use it normally.All these changes should be transparent to the user.
Signed-off-by Anthony Liguori <[email protected]>Signed-off-by Luiz Capitulino <[email protected]>--- hmp-commands.hx | 3 +-- hmp.c | 56 +++++++++++++++++++++++++++++++++++++++++++++ hmp.h | 1 + migration-fd.c | 2 +- migration.c | 66 ++++++++++++++---------------------------------------- migration.h | 3 --- qapi-schema.json | 21 +++++++++++++++++ qmp-commands.hx | 9 +------- savevm.c | 13 +++++------ sysemu.h | 2 +- 10 files changed, 105 insertions(+), 71 deletions(-)hmp-commands.hx +1
-2@@ -806,8 +806,7 @@ ETEXI " full copy of disk\n\t\t\t -i for migration without " "shared storage with incremental copy of disk " "(base image shared between src and destination)", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_migrate, + .mhandler.cmd = hmp_migrate, },hmp.c +34
-0@@ -14,6 +14,7 @@*/ #include "hmp.h" +#include "qemu-timer.h" #include "qmp-commands.h" static void hmp_handle_error (Monitor *mon,Error **errp)@@ -856,3 +857,58 @@ void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)hmp_handle_error (mon, &error); } + +typedef struct MigrationStatus +{ +QEMUTimer *timer; +Monitor *mon; +}MigrationStatus ; + +static void hmp_migrate_status_cb (void *opaque) +{ +MigrationStatus *status = opaque; +MigrationInfo *info; + + info =qmp_query_migrate (NULL ); +if (!info->has_status ||strcmp (info->status,"active" ) ==0 ) { +qemu_mod_timer (status->timer,qemu_get_clock_ms (rt_clock) +1000 ); + }else { +monitor_resume (status->mon); +qemu_del_timer (status->timer); +g_free (status); + } + +qapi_free_MigrationInfo (info); +} + +void hmp_migrate (Monitor *mon,const QDict *qdict) +{ +int detach =qdict_get_try_bool (qdict,"detach" ,0 ); +int blk =qdict_get_try_bool (qdict,"blk" ,0 ); +int inc =qdict_get_try_bool (qdict,"inc" ,0 ); +const char *uri =qdict_get_str (qdict,"uri" ); +Error *err =NULL ; + +qmp_migrate (uri, !!blk, blk, !!inc, inc, false, false, &err);hmp.c void hmp_block_job_cancel(Monitor *mon, const QDict *qdict) · line 902
Quoted 10 lines
hmp.c +10
-0+if (err) { +monitor_printf (mon,"migrate: %s\n" ,error_get_pretty (err)); +error_free (err); +return ; + } + +if (!detach) { +MigrationStatus *status; + +if (monitor_suspend (mon) <0 ) {So using
monitor_suspendis ok? is that a possible solution for the screendump issue? I could pass the Monitor through the vga callback. Tbh I think it's ugly, but at least it doesn't introduce any new command.
Quoted 5 lines
Quoted 2 lines
This is only valid for HMP.
Yes, I'm thinking at this point for qmp to wait for the output file to be written via repeated poll / inotify.
Making this synchronous you mean? This will hold the global mutex for too long, won't it?
Quoted 121 lines · Luiz Capitulino
Quoted 118 lines · On Mon, 12 Mar 2012 15:49:27 +0200 Alon Levy <[email protected]> wrote:
Quoted 117 lines · Luiz Capitulino
Quoted 113 lines · On Sat, 10 Mar 2012 00:51:29 +0200 Alon Levy <[email protected]> wrote:
Quoted 98 lines · Luiz Capitulino
The migrate command is one of those commands where HMP and QMP completely mix up together. This made the conversion to the QAPI (which separates the command into QMP and HMP parts) a bit difficult.
The first important change to be noticed is that this commit completes the removal of the Monitor object from migration code, started by the previous commit.
Another important and tricky change is about supporting the non-detached mode. That's, if the user doesn't pass '-d' the migrate command will lock the monitor and will only release it when migration is finished.
To support that in the new HMP command (
hmp_migrate()), it is necessary to create a timer which runs every second and checks if the migration is still active. If it's, the timer callback will re-schedule itself to run one second in the future. If the migration has already finished, the monitor lock is relased and the user can use it normally.All these changes should be transparent to the user.
Signed-off-by Anthony Liguori <[email protected]>Signed-off-by Luiz Capitulino <[email protected]>--- hmp-commands.hx | 3 +-- hmp.c | 56 +++++++++++++++++++++++++++++++++++++++++++++ hmp.h | 1 + migration-fd.c | 2 +- migration.c | 66 ++++++++++++++---------------------------------------- migration.h | 3 --- qapi-schema.json | 21 +++++++++++++++++ qmp-commands.hx | 9 +------- savevm.c | 13 +++++------ sysemu.h | 2 +- 10 files changed, 105 insertions(+), 71 deletions(-)hmp-commands.hx +1
-2@@ -806,8 +806,7 @@ ETEXI " full copy of disk\n\t\t\t -i for migration without " "shared storage with incremental copy of disk " "(base image shared between src and destination)", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_migrate, + .mhandler.cmd = hmp_migrate, },hmp.c +34
-0@@ -14,6 +14,7 @@*/ #include "hmp.h" +#include "qemu-timer.h" #include "qmp-commands.h" static void hmp_handle_error (Monitor *mon,Error **errp)@@ -856,3 +857,58 @@ void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)hmp_handle_error (mon, &error); } + +typedef struct MigrationStatus +{ +QEMUTimer *timer; +Monitor *mon; +}MigrationStatus ; + +static void hmp_migrate_status_cb (void *opaque) +{ +MigrationStatus *status = opaque; +MigrationInfo *info; + + info =qmp_query_migrate (NULL ); +if (!info->has_status ||strcmp (info->status,"active" ) ==0 ) { +qemu_mod_timer (status->timer,qemu_get_clock_ms (rt_clock) +1000 ); + }else { +monitor_resume (status->mon); +qemu_del_timer (status->timer); +g_free (status); + } + +qapi_free_MigrationInfo (info); +} + +void hmp_migrate (Monitor *mon,const QDict *qdict) +{ +int detach =qdict_get_try_bool (qdict,"detach" ,0 ); +int blk =qdict_get_try_bool (qdict,"blk" ,0 ); +int inc =qdict_get_try_bool (qdict,"inc" ,0 ); +const char *uri =qdict_get_str (qdict,"uri" ); +Error *err =NULL ; + +qmp_migrate (uri, !!blk, blk, !!inc, inc, false, false, &err);hmp.c void hmp_block_job_cancel(Monitor *mon, const QDict *qdict) · line 902
Quoted 10 lines
hmp.c +10
-0+if (err) { +monitor_printf (mon,"migrate: %s\n" ,error_get_pretty (err)); +error_free (err); +return ; + } + +if (!detach) { +MigrationStatus *status; + +if (monitor_suspend (mon) <0 ) {So using
monitor_suspendis ok? is that a possible solution for the screendump issue? I could pass the Monitor through the vga callback. Tbh I think it's ugly, but at least it doesn't introduce any new command.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
This is only valid for HMP.
Yes, I'm thinking at this point for qmp to wait for the output file to be written via repeated poll / inotify.
Making this synchronous you mean? This will hold the global mutex for too long, won't it?
No, not at all what I mean. I'm talking about a libvirt change. There is nothing that we can do in qemu other than maybe implementing a qmp_suspend (automatic nack), already suggested screendump-async (nack by no update) and now waiting for comments on just the HMP fix for screendump.
Quoted 125 lines · On Mon, 12 Mar 2012 16:23:01 +0200 Alon Levy <[email protected]> wrote:
Quoted 124 lines · Luiz Capitulino
Quoted 121 lines · On Mon, 12 Mar 2012 15:49:27 +0200 Alon Levy <[email protected]> wrote:
Quoted 119 lines · Luiz Capitulino
Quoted 105 lines · On Sat, 10 Mar 2012 00:51:29 +0200 Alon Levy <[email protected]> wrote:
Quoted 104 lines · Luiz Capitulino
The migrate command is one of those commands where HMP and QMP completely mix up together. This made the conversion to the QAPI (which separates the command into QMP and HMP parts) a bit difficult.
The first important change to be noticed is that this commit completes the removal of the Monitor object from migration code, started by the previous commit.
Another important and tricky change is about supporting the non-detached mode. That's, if the user doesn't pass '-d' the migrate command will lock the monitor and will only release it when migration is finished.
To support that in the new HMP command (
hmp_migrate()), it is necessary to create a timer which runs every second and checks if the migration is still active. If it's, the timer callback will re-schedule itself to run one second in the future. If the migration has already finished, the monitor lock is relased and the user can use it normally.All these changes should be transparent to the user.
Signed-off-by Anthony Liguori <[email protected]>Signed-off-by Luiz Capitulino <[email protected]>--- hmp-commands.hx | 3 +-- hmp.c | 56 +++++++++++++++++++++++++++++++++++++++++++++ hmp.h | 1 + migration-fd.c | 2 +- migration.c | 66 ++++++++++++++---------------------------------------- migration.h | 3 --- qapi-schema.json | 21 +++++++++++++++++ qmp-commands.hx | 9 +------- savevm.c | 13 +++++------ sysemu.h | 2 +- 10 files changed, 105 insertions(+), 71 deletions(-)hmp-commands.hx +1
-2@@ -806,8 +806,7 @@ ETEXI " full copy of disk\n\t\t\t -i for migration without " "shared storage with incremental copy of disk " "(base image shared between src and destination)", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_migrate, + .mhandler.cmd = hmp_migrate, },hmp.c +40
-0@@ -14,6 +14,7 @@*/ #include "hmp.h" +#include "qemu-timer.h" #include "qmp-commands.h" static void hmp_handle_error (Monitor *mon,Error **errp)@@ -856,3 +857,58 @@ void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)hmp_handle_error (mon, &error); } + +typedef struct MigrationStatus +{ +QEMUTimer *timer; +Monitor *mon; +}MigrationStatus ; + +static void hmp_migrate_status_cb (void *opaque) +{ +MigrationStatus *status = opaque; +MigrationInfo *info; + + info =qmp_query_migrate (NULL ); +if (!info->has_status ||strcmp (info->status,"active" ) ==0 ) { +qemu_mod_timer (status->timer,qemu_get_clock_ms (rt_clock) +1000 ); + }else { +monitor_resume (status->mon); +qemu_del_timer (status->timer); +g_free (status); + } + +qapi_free_MigrationInfo (info); +} + +void hmp_migrate (Monitor *mon,const QDict *qdict) +{ +int detach =qdict_get_try_bool (qdict,"detach" ,0 ); +int blk =qdict_get_try_bool (qdict,"blk" ,0 ); +int inc =qdict_get_try_bool (qdict,"inc" ,0 ); +const char *uri =qdict_get_str (qdict,"uri" ); +Error *err =NULL ; + +qmp_migrate (uri, !!blk, blk, !!inc, inc, false, false, &err); +if (err) { +monitor_printf (mon,"migrate: %s\n" ,error_get_pretty (err)); +error_free (err); +return ; + } +Quoted 8 lines
hmp.c void hmp_block_job_cancel(Monitor *mon, const QDict *qdict) · line 902
Quoted 4 lines
hmp.c +4
-0+if (!detach) { +MigrationStatus *status; + +if (monitor_suspend (mon) <0 ) {So using
monitor_suspendis ok? is that a possible solution for the screendump issue? I could pass the Monitor through the vga callback. Tbh I think it's ugly, but at least it doesn't introduce any new command.This is only valid for HMP.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Yes, I'm thinking at this point for qmp to wait for the output file to be written via repeated poll / inotify.
Making this synchronous you mean? This will hold the global mutex for too long, won't it?
No, not at all what I mean. I'm talking about a libvirt change.
Oh, good idea, that's a valid workaround.
Quoted 5 lines
There is
nothing that we can do in qemu other than maybe implementing aqmp_suspend(automatic nack), already suggested screendump-async (nack by no update) and now waiting for comments on just the HMP fix for screendump.
Will review it shortly.