Migration events + optional sections
v2 cover Migration events + optional sections
Hi
At the end, Daved asked for a couple of things on previous series.
[v2]
- Ensure that we start in NONE even after failed/canceled migration
- move printf's to traces
- make sure that we can migrate the new states like guest-panicked (not sure if it is a good idea to enable migrate a guest-panicked, but it is not this series the place to forbid it)
- address all comments from Dave and Eric.
Please, review.
[v1]
As the beggining of both series have been accepted, I merged both here. Changes:
- answered all comments on list and applied suggested changes
- Use migrate_set_state() consistently
- we were misusing atomic_cmpxchg(), it didn't matter until now because we were missing only traces, but it showed with events missing.
- Reorganized how the migration events are generated, now only on migrate_set_state.
Please review.
Juan Quintela (12):
runstate: Add runstate store
runstate: migration allows more transitions now
migration: create new section to store global state
global_state: Make section optional
vmstate: Create optional sections
migration: Add configuration section
migration: Use cmpxchg correctly
migration: ensure we start in NONE state
migration: Use always helper to set state
migration: No need to call trace_migrate_set_state()
migration: create migration event
migration: Add migration events on target side
docs/qmp/qmp-events.txt | 14 ++++ hw/i386/pc_piix.c | 2 + hw/i386/pc_q35.c | 2 + include/migration/migration.h | 4 ++ include/migration/vmstate.h | 2 + include/sysemu/sysemu.h | 1 + migration/migration.c | 157 ++++++++++++++++++++++++++++++++++++++---- migration/savevm.c | 69 +++++++++++++++++++ migration/vmstate.c | 11 +++ qapi/event.json | 12 ++++ trace-events | 4 ++ vl.c | 21 +++++- 12 files changed, 283 insertions(+), 16 deletions(-)
Signature · 1 line
2.4.3
PATCH v2 1/12 runstate: Add runstate store
This allows us to store the current state to send it through migration.
--- include/sysemu/sysemu.h | 1 + vl.c | 12 ++++++++++++ 2 files changed, 13 insertions(+)
include/sysemu/sysemu.h +1 -0
@@ -28,6 +28,7 @@ bool runstate_check(RunState state);void runstate_set (RunState new_state);int runstate_is_running (void );bool runstate_needs_reset (void ); +bool runstate_store (char *str,size_t size);typedef struct vm_change_state_entry VMChangeStateEntry ;typedef void VMChangeStateHandler (void *opaque,int running,RunState state);
vl.c +12 -0
@@ -634,6 +634,18 @@ bool runstate_check(RunState state)return current_run_state == state; } +bool runstate_store (char *str,size_t size) +{ +const char *state = RunState_lookup[current_run_state]; +size_t len =strlen (state) +1 ; + +if (len > size) { +return false; + } +memcpy (str, state, len); +return true; +} +static void runstate_init (void ) {const RunStateTransition *p;
Signature · 1 line
2.4.3
PATCH v2 2/12 runstate: migration allows more transitions now
In reply to Juan QuintelaNext commit would allow to move from incoming migration to error happening on source.
Should we add more states to this transition? Luiz?
--- vl.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
vl.c +7 -1
@@ -573,8 +573,14 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_DEBUG, RUN_STATE_RUNNING }, { RUN_STATE_DEBUG, RUN_STATE_FINISH_MIGRATE }, - { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING }, + { RUN_STATE_INMIGRATE, RUN_STATE_INTERNAL_ERROR }, + { RUN_STATE_INMIGRATE, RUN_STATE_IO_ERROR }, { RUN_STATE_INMIGRATE, RUN_STATE_PAUSED }, + { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING }, + { RUN_STATE_INMIGRATE, RUN_STATE_SHUTDOWN }, + { RUN_STATE_INMIGRATE, RUN_STATE_SUSPENDED }, + { RUN_STATE_INMIGRATE, RUN_STATE_WHATCHDOG }, + { RUN_STATE_INMIGRATE, RUN_STATE_GUEST_PANICKED }, { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED }, { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },
Signature · 1 line
2.4.3
PATCH v2 3/12 migration: create new section to store global state
In reply to Juan QuintelaThis includes a new section that for now just stores the current qemu state.
Right now, there are only one way to control what is the state of the target after migration.
- If you run the target qemu with -S, it would start stopped.
- If you run the target qemu without -S, it would run just after migration finishes.
The problem here is what happens if we start the target without -S and there happens one error during migration that puts current state as -EIO. Migration would ends (notice that the error happend doing block IO, network IO, i.e. nothing related with migration), and when migration finish, we would just "continue" running on destination, probably hanging the guest/corruption data, whatever.
--- include/migration/migration.h | 1 + migration/migration.c | 105 +++++++++++++++++++++++++++++++++++++++--- trace-events | 3 ++ vl.c | 1 + 4 files changed, 103 insertions(+), 7 deletions(-)
include/migration/migration.h +1 -0
@@ -197,4 +197,5 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,void ram_mig_init (void );void savevm_skip_section_footers (void ); +void register_global_state (void );#endif
migration/migration.c +98 -7
130 lines not on this page · raw message
trace-events +3 -0
@@ -1403,6 +1403,9 @@ migrate_fd_error(void) "" migrate_fd_cancel(void) "" migrate_pending(uint64_t size, uint64_t max) "pending size %" PRIu64 " max %" PRIu64 migrate_transferred(uint64_t tranferred, uint64_t time_spent, double bandwidth, uint64_t size) "transferred %" PRIu64 " time_spent %" PRIu64 " bandwidth %g max_size %" PRId64 +migrate_state_too_big(void) "" +migrate_global_state_post_load(const char *state) "loaded state: %s" +migrate_global_state_pre_save(const char *state) "saved state: %s" # migration/rdma.c qemu_dma_accept_incoming_migration(void) ""
vl.c +1 -0
@@ -4624,6 +4624,7 @@ int main(int argc, char **argv, char **envp)return 0 ; } +register_global_state ();if (incoming) {Error *local_err =NULL ;qemu_start_incoming_migration (incoming, &local_err);
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH 03/12] migration: create new section to store global state
Quoted 52 lines · * Juan Quintela ([email protected]) wrote:
This includes a new section that for now just stores the current qemu state.
Right now, there are only one way to control what is the state of the target after migration.
- If you run the target qemu with -S, it would start stopped.
- If you run the target qemu without -S, it would run just after migration finishes.The problem here is what happens if we start the target without -S and there happens one error during migration that puts current state as
-EIO. Migration would ends (notice that the error happend doing block IO, network IO, i.e. nothing related with migration), and when migration finish, we would just "continue" running on destination, probably hanging the guest/corruption data, whatever.Signed-off-by Juan Quintela <[email protected]>--- include/migration/migration.h | 1 + migration/migration.c | 105 +++++++++++++++++++++++++++++++++++++++--- trace-events | 3 ++ vl.c | 1 + 4 files changed, 103 insertions(+), 7 deletions(-)include/migration/migration.h +1
-0@@ -197,4 +197,5 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,void ram_mig_init (void );void savevm_skip_section_footers (void ); +void register_global_state (void );#endif migration/migration.c +4
-0@@ -26,6 +26,7 @@#include "qemu/thread.h" #include "qmp-commands.h" #include "trace.h" +#include "qapi/util.h" #define MAX_THROTTLE (32 << 20)/* Migration speed throttling */ @@ -97,6 +98,83 @@ void migration_incoming_state_destroy(void) mis_current =NULL ; } + +typedef struct { + uint32_t size;
migration/migration.c void migration_incoming_state_destroy(void) · line 113
Quoted 10 lines
migration/migration.c +10
-0+uint8_t runstate[100 ]; +} GlobalState; + +static GlobalState global_state; + +static int global_state_store (void ) +{ +if (!runstate_store ((char *)global_state.runstate, +sizeof (global_state.runstate))) { +trace_migrate_state_too_big ();
Hmm ok, but that should have stayed as the error_report - the only problem with that in the previous version was a \n (error_report for errors, trace_ for debug)
Quoted 32 lines
migration/migration.c +32
-0+return -EINVAL ; + } +return 0 ; +} + +static char *global_state_get_runstate (void ) +{ +return (char *)global_state.runstate; +} + +static int global_state_post_load (void *opaque,int version_id) +{ +GlobalState *s = opaque; +int ret =0 ; +char *runstate = (char *)s->runstate; + +trace_migrate_global_state_post_load (runstate); + +if (strcmp (runstate,"running" ) !=0 ) { +Error *local_err =NULL ; +int r =qapi_enum_parse (RunState_lookup, runstate,RUN_STATE_MAX , +-1 , &local_err); + +if (r ==-1 ) { +if (local_err) { +error_report_err (local_err); + } +return -EINVAL ; + } + ret =vm_stop_force_state (r); + } +
migration/migration.c void migration_incoming_state_destroy(void) · line 155
Quoted 10 lines
migration/migration.c +10
-0+return ret; +} + +static void global_state_pre_save (void *opaque) +{ +GlobalState *s = opaque; + +trace_migrate_global_state_pre_save ((char *)s->runstate); + s->size =strlen ((char *)s->runstate) +1 ; +printf ("saved state: %s\n" , s->runstate);
Stray printf
Other than that,
Quoted 96 lines
migration/migration.c +42
-7+} + +static const VMStateDescription vmstate_globalstate = { + .name ="globalstate" , + .version_id =1 , + .minimum_version_id =1 , + .post_load = global_state_post_load, + .pre_save = global_state_pre_save, + .fields = (VMStateField []) { +VMSTATE_UINT32 (size, GlobalState), +VMSTATE_BUFFER (runstate, GlobalState), +VMSTATE_END_OF_LIST () + }, +}; + +void register_global_state (void ) +{ +/* We would use it independently that we receive it */ +strcpy ((char *)&global_state.runstate,"" ); +vmstate_register (NULL ,0 , &vmstate_globalstate, &global_state); +} +/* * Called on -incoming with a defer: uri. * The migration can be started later after any parameters have been @@ -164,10 +242,20 @@ static void process_incoming_migration_co(void *opaque)exit (EXIT_FAILURE ); } -if (autostart) { +/* runstate == "" means that we haven't received it through the +* wire, so we obey autostart. runstate == runing means that we +* need to run it, we need to make sure that we do it after +* everything else has finished. Every other state change is done +* at the post_load function */ + +if (strcmp (global_state_get_runstate (),"running" ) ==0 ) {vm_start (); - }else { -runstate_set (RUN_STATE_PAUSED ); + }else if (strcmp (global_state_get_runstate (),"" ) ==0 ) { +if (autostart) { +vm_start (); + }else { +runstate_set (RUN_STATE_PAUSED ); + } }migrate_decompress_threads_join (); }@@ -793,10 +881,13 @@ static void *migration_thread(void *opaque)qemu_system_wakeup_request (QEMU_WAKEUP_REASON_OTHER ); old_vm_running =runstate_is_running (); - ret =vm_stop_force_state (RUN_STATE_FINISH_MIGRATE ); -if (ret >=0 ) { -qemu_file_set_rate_limit (s->file,INT64_MAX ); -qemu_savevm_state_complete (s->file); + ret =global_state_store (); +if (!ret) { + ret =vm_stop_force_state (RUN_STATE_FINISH_MIGRATE ); +if (ret >=0 ) { +qemu_file_set_rate_limit (s->file,INT64_MAX ); +qemu_savevm_state_complete (s->file); + } }qemu_mutex_unlock_iothread ();trace-events +3
-0@@ -1403,6 +1403,9 @@ migrate_fd_error(void) "" migrate_fd_cancel(void) "" migrate_pending(uint64_t size, uint64_t max) "pending size %" PRIu64 " max %" PRIu64 migrate_transferred(uint64_t tranferred, uint64_t time_spent, double bandwidth, uint64_t size) "transferred %" PRIu64 " time_spent %" PRIu64 " bandwidth %g max_size %" PRId64 +migrate_state_too_big(void) "" +migrate_global_state_post_load(const char *state) "loaded state: %s" +migrate_global_state_pre_save(const char *state) "saved state: %s" # migration/rdma.c qemu_dma_accept_incoming_migration(void) ""vl.c +1
-0@@ -4624,6 +4624,7 @@ int main(int argc, char **argv, char **envp)return 0 ; } +register_global_state ();if (incoming) {Error *local_err =NULL ;qemu_start_incoming_migration (incoming, &local_err);Signature · 1 line
2.4.3
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH 03/12] migration: create new section to store global state
Quoted 104 lines · Dr. David Alan Gilbert
Quoted 52 lines · * Juan Quintela ([email protected]) wrote:
This includes a new section that for now just stores the current qemu state.
Right now, there are only one way to control what is the state of the target after migration.
- If you run the target qemu with -S, it would start stopped.
- If you run the target qemu without -S, it would run just after migration finishes.The problem here is what happens if we start the target without -S and there happens one error during migration that puts current state as
-EIO. Migration would ends (notice that the error happend doing block IO, network IO, i.e. nothing related with migration), and when migration finish, we would just "continue" running on destination, probably hanging the guest/corruption data, whatever.Signed-off-by Juan Quintela <[email protected]>--- include/migration/migration.h | 1 + migration/migration.c | 105 +++++++++++++++++++++++++++++++++++++++--- trace-events | 3 ++ vl.c | 1 + 4 files changed, 103 insertions(+), 7 deletions(-)include/migration/migration.h +1
-0@@ -197,4 +197,5 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,void ram_mig_init (void );void savevm_skip_section_footers (void ); +void register_global_state (void );#endif migration/migration.c +4
-0@@ -26,6 +26,7 @@#include "qemu/thread.h" #include "qmp-commands.h" #include "trace.h" +#include "qapi/util.h" #define MAX_THROTTLE (32 << 20)/* Migration speed throttling */ @@ -97,6 +98,83 @@ void migration_incoming_state_destroy(void) mis_current =NULL ; } + +typedef struct { + uint32_t size;migration/migration.c void migration_incoming_state_destroy(void) · line 113
Quoted 10 lines
migration/migration.c +10
-0+uint8_t runstate[100 ]; +} GlobalState; + +static GlobalState global_state; + +static int global_state_store (void ) +{ +if (!runstate_store ((char *)global_state.runstate, +sizeof (global_state.runstate))) { +trace_migrate_state_too_big ();Hmm ok, but that should have stayed as the
error_report- the only problem with that in the previous version was a \n (error_reportfor errors,trace_for debug)Quoted 36 lines
migration/migration.c +36
-0+return -EINVAL ; + } +return 0 ; +} + +static char *global_state_get_runstate (void ) +{ +return (char *)global_state.runstate; +} + +static int global_state_post_load (void *opaque,int version_id) +{ +GlobalState *s = opaque; +int ret =0 ; +char *runstate = (char *)s->runstate; + +trace_migrate_global_state_post_load (runstate); + +if (strcmp (runstate,"running" ) !=0 ) { +Error *local_err =NULL ; +int r =qapi_enum_parse (RunState_lookup, runstate,RUN_STATE_MAX , +-1 , &local_err); + +if (r ==-1 ) { +if (local_err) { +error_report_err (local_err); + } +return -EINVAL ; + } + ret =vm_stop_force_state (r); + } + +return ret; +} + +static void global_state_pre_save (void *opaque)
Quoted 8 lines
migration/migration.c void migration_incoming_state_destroy(void) · line 155
Quoted 6 lines
migration/migration.c +6
-0+{ +GlobalState *s = opaque; + +trace_migrate_global_state_pre_save ((char *)s->runstate); + s->size =strlen ((char *)s->runstate) +1 ; +printf ("saved state: %s\n" , s->runstate);Stray printf
grrr, the removal got somehow on the following patch.
Thanks.
Quoted 105 lines
Other than that,
Reviewed-by Dr. David Alan Gilbert <[email protected]>Quoted 97 lines
migration/migration.c +35
-3+} + +static const VMStateDescription vmstate_globalstate = { + .name ="globalstate" , + .version_id =1 , + .minimum_version_id =1 , + .post_load = global_state_post_load, + .pre_save = global_state_pre_save, + .fields = (VMStateField []) { +VMSTATE_UINT32 (size, GlobalState), +VMSTATE_BUFFER (runstate, GlobalState), +VMSTATE_END_OF_LIST () + }, +}; + +void register_global_state (void ) +{ +/* We would use it independently that we receive it */ +strcpy ((char *)&global_state.runstate,"" ); +vmstate_register (NULL ,0 , &vmstate_globalstate, &global_state); +} +/* * Called on -incoming with a defer: uri. * The migration can be started later after any parameters have been @@ -164,10 +242,20 @@ static void process_incoming_migration_co(void *opaque)exit (EXIT_FAILURE ); } -if (autostart) { +/* runstate == "" means that we haven't received it through the +* wire, so we obey autostart. runstate == runing means that we +* need to run it, we need to make sure that we do it after +* everything else has finished. Every other state change is done +* at the post_load function */ + +if (strcmp (global_state_get_runstate (),"running" ) ==0 ) {vm_start (); - }else { -runstate_set (RUN_STATE_PAUSED ); + }else if (strcmp (global_state_get_runstate (),"" ) ==0 ) { +if (autostart) { +vm_start (); + }else { +runstate_set (RUN_STATE_PAUSED ); + } }migrate_decompress_threads_join ();}
migration/migration.c +7
-4@@ -793,10 +881,13 @@ static void *migration_thread(void *opaque)qemu_system_wakeup_request (QEMU_WAKEUP_REASON_OTHER ); old_vm_running =runstate_is_running (); - ret =vm_stop_force_state (RUN_STATE_FINISH_MIGRATE ); -if (ret >=0 ) { -qemu_file_set_rate_limit (s->file,INT64_MAX ); -qemu_savevm_state_complete (s->file); + ret =global_state_store (); +if (!ret) { + ret =vm_stop_force_state (RUN_STATE_FINISH_MIGRATE ); +if (ret >=0 ) { +qemu_file_set_rate_limit (s->file,INT64_MAX ); +qemu_savevm_state_complete (s->file); + } }qemu_mutex_unlock_iothread ();trace-events +3
-0@@ -1403,6 +1403,9 @@ migrate_fd_error(void) "" migrate_fd_cancel(void) "" migrate_pending(uint64_t size, uint64_t max) "pending size %" PRIu64 " max %" PRIu64 migrate_transferred(uint64_t tranferred, uint64_t time_spent, double bandwidth, uint64_t size) "transferred %" PRIu64 " time_spent %" PRIu64 " bandwidth %g max_size %" PRId64 +migrate_state_too_big(void) "" +migrate_global_state_post_load(const char *state) "loaded state: %s" +migrate_global_state_pre_save(const char *state) "saved state: %s" # migration/rdma.c qemu_dma_accept_incoming_migration(void) ""vl.c +1
-0@@ -4624,6 +4624,7 @@ int main(int argc, char **argv, char **envp)return 0 ; } +register_global_state ();if (incoming) {Error *local_err =NULL ;qemu_start_incoming_migration (incoming, &local_err);Signature · 1 line
2.4.3--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
PATCH v2 4/12 global_state: Make section optional
In reply to Juan QuintelaThis section would be sent:
a- for all new machine types
b- for old achine types if section state is different form {running,paused}
that were the only giving us troubles.
So, in new qemus: it is alwasy there. In old qemus: they are only there if it an error has happened, basically stoping on target.
--- hw/i386/pc_piix.c | 1 + hw/i386/pc_q35.c | 1 + include/migration/migration.h | 1 + migration/migration.c | 30 +++++++++++++++++++++++++++++- 4 files changed, 32 insertions(+), 1 deletion(-)
hw/i386/pc_piix.c +1 -0
@@ -307,6 +307,7 @@ static void pc_init1(MachineState *machine)static void pc_compat_2_3 (MachineState *machine) {savevm_skip_section_footers (); +global_state_set_optional (); }static void pc_compat_2_2 (MachineState *machine)
hw/i386/pc_q35.c +1 -0
@@ -291,6 +291,7 @@ static void pc_q35_init(MachineState *machine)static void pc_compat_2_3 (MachineState *machine) {savevm_skip_section_footers (); +global_state_set_optional (); }static void pc_compat_2_2 (MachineState *machine)
include/migration/migration.h +1 -0
@@ -198,4 +198,5 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,void ram_mig_init (void );void savevm_skip_section_footers (void );void register_global_state (void ); +void global_state_set_optional (void );#endif
migration/migration.c +29 -1
@@ -100,6 +100,7 @@ void migration_incoming_state_destroy(void)typedef struct { +bool optional;uint32_t size;uint8_t runstate[100 ]; }GlobalState ;
@@ -121,6 +122,33 @@ static char *global_state_get_runstate(void)return (char *)global_state.runstate; } +void global_state_set_optional (void ) +{ + global_state.optional = true; +} + +static bool global_state_needed (void *opaque) +{ +GlobalState *s = opaque; +char *runstate = (char *)s->runstate; + +/* If it is not optional, it is mandatory */ + +if (s->optional == false) { +return true; + } + +/* If state is running or paused, it is not needed */ + +if (strcmp (runstate,"running" ) ==0 || +strcmp (runstate,"paused" ) ==0 ) { +return false; + } + +/* for any other state it is needed */ +return true; +} +static int global_state_post_load (void *opaque,int version_id) {GlobalState *s = opaque;
@@ -152,7 +180,6 @@ static void global_state_pre_save(void *opaque)trace_migrate_global_state_pre_save ((char *)s->runstate); s->size =strlen ((char *)s->runstate) +1 ; -printf ("saved state: %s\n" , s->runstate); }static const VMStateDescription vmstate_globalstate = {
@@ -161,6 +188,7 @@ static const VMStateDescription vmstate_globalstate = { .minimum_version_id = 1, .post_load = global_state_post_load, .pre_save = global_state_pre_save, + .needed = global_state_needed, .fields = (VMStateField []) {VMSTATE_UINT32 (size, GlobalState),VMSTATE_BUFFER (runstate, GlobalState),
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH 04/12] global_state: Make section optional
Quoted 10 lines · * Juan Quintela ([email protected]) wrote:
This section would be sent:
a- for all new machine types
b- for old achine types if section state is different form {running,paused}
that were the only giving us troubles.So, in new qemus: it is alwasy there. In old qemus: they are only there if it an error has happened, basically stoping on target.
Signed-off-by Juan Quintela <[email protected]>
Note you should probably also fix Power (see my 'Fix for section footers for power')
Quoted 106 lines
--- hw/i386/pc_piix.c | 1 + hw/i386/pc_q35.c | 1 + include/migration/migration.h | 1 + migration/migration.c | 30 +++++++++++++++++++++++++++++- 4 files changed, 32 insertions(+), 1 deletion(-)hw/i386/pc_piix.c +1
-0@@ -307,6 +307,7 @@ static void pc_init1(MachineState *machine)static void pc_compat_2_3 (MachineState *machine) {savevm_skip_section_footers (); +global_state_set_optional (); }static void pc_compat_2_2 (MachineState *machine)hw/i386/pc_q35.c +1
-0@@ -291,6 +291,7 @@ static void pc_q35_init(MachineState *machine)static void pc_compat_2_3 (MachineState *machine) {savevm_skip_section_footers (); +global_state_set_optional (); }static void pc_compat_2_2 (MachineState *machine)include/migration/migration.h +1
-0@@ -198,4 +198,5 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,void ram_mig_init (void );void savevm_skip_section_footers (void );void register_global_state (void ); +void global_state_set_optional (void );#endif migration/migration.c +29
-1@@ -100,6 +100,7 @@ void migration_incoming_state_destroy(void)typedef struct { +bool optional;uint32_t size;uint8_t runstate[100 ]; }GlobalState ;@@ -121,6 +122,33 @@ static char *global_state_get_runstate(void)return (char *)global_state.runstate; } +void global_state_set_optional (void ) +{ + global_state.optional = true; +} + +static bool global_state_needed (void *opaque) +{ +GlobalState *s = opaque; +char *runstate = (char *)s->runstate; + +/* If it is not optional, it is mandatory */ + +if (s->optional == false) { +return true; + } + +/* If state is running or paused, it is not needed */ + +if (strcmp (runstate,"running" ) ==0 || +strcmp (runstate,"paused" ) ==0 ) { +return false; + } + +/* for any other state it is needed */ +return true; +} +static int global_state_post_load (void *opaque,int version_id) {GlobalState *s = opaque;@@ -152,7 +180,6 @@ static void global_state_pre_save(void *opaque)trace_migrate_global_state_pre_save ((char *)s->runstate); s->size =strlen ((char *)s->runstate) +1 ; -printf ("saved state: %s\n" , s->runstate); }static const VMStateDescription vmstate_globalstate = {@@ -161,6 +188,7 @@ static const VMStateDescription vmstate_globalstate = { .minimum_version_id = 1, .post_load = global_state_post_load, .pre_save = global_state_pre_save, + .needed = global_state_needed, .fields = (VMStateField []) {VMSTATE_UINT32 (size, GlobalState),VMSTATE_BUFFER (runstate, GlobalState),Signature · 1 line
2.4.3
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH 04/12] global_state: Make section optional
In reply to Juan QuintelaQuoted 4 lines · Juan Quintela
This section would be sent:
a- for all new machine types
b- for old achine types if section state is different form {running,paused}
s/achine/machine/
Quoted 110 lines
that were the only giving us troubles.
So, in new qemus: it is alwasy there. In old qemus: they are only there if it an error has happened, basically stoping on target.
Signed-off-by Juan Quintela <[email protected]>--- hw/i386/pc_piix.c | 1 + hw/i386/pc_q35.c | 1 + include/migration/migration.h | 1 + migration/migration.c | 30 +++++++++++++++++++++++++++++- 4 files changed, 32 insertions(+), 1 deletion(-)hw/i386/pc_piix.c +1
-0@@ -307,6 +307,7 @@ static void pc_init1(MachineState *machine)static void pc_compat_2_3 (MachineState *machine) {savevm_skip_section_footers (); +global_state_set_optional (); }static void pc_compat_2_2 (MachineState *machine)hw/i386/pc_q35.c +1
-0@@ -291,6 +291,7 @@ static void pc_q35_init(MachineState *machine)static void pc_compat_2_3 (MachineState *machine) {savevm_skip_section_footers (); +global_state_set_optional (); }static void pc_compat_2_2 (MachineState *machine)include/migration/migration.h +1
-0@@ -198,4 +198,5 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,void ram_mig_init (void );void savevm_skip_section_footers (void );void register_global_state (void ); +void global_state_set_optional (void );#endif migration/migration.c +29
-1@@ -100,6 +100,7 @@ void migration_incoming_state_destroy(void)typedef struct { +bool optional;uint32_t size;uint8_t runstate[100 ]; }GlobalState ;@@ -121,6 +122,33 @@ static char *global_state_get_runstate(void)return (char *)global_state.runstate; } +void global_state_set_optional (void ) +{ + global_state.optional = true; +} + +static bool global_state_needed (void *opaque) +{ +GlobalState *s = opaque; +char *runstate = (char *)s->runstate; + +/* If it is not optional, it is mandatory */ + +if (s->optional == false) { +return true; + } + +/* If state is running or paused, it is not needed */ + +if (strcmp (runstate,"running" ) ==0 || +strcmp (runstate,"paused" ) ==0 ) { +return false; + } + +/* for any other state it is needed */ +return true; +} +static int global_state_post_load (void *opaque,int version_id) {GlobalState *s = opaque;@@ -152,7 +180,6 @@ static void global_state_pre_save(void *opaque)trace_migrate_global_state_pre_save ((char *)s->runstate); s->size =strlen ((char *)s->runstate) +1 ; -printf ("saved state: %s\n" , s->runstate); }static const VMStateDescription vmstate_globalstate = {@@ -161,6 +188,7 @@ static const VMStateDescription vmstate_globalstate = { .minimum_version_id = 1, .post_load = global_state_post_load, .pre_save = global_state_pre_save, + .needed = global_state_needed, .fields = (VMStateField []) {VMSTATE_UINT32 (size, GlobalState),VMSTATE_BUFFER (runstate, GlobalState),
Signature · 2 lines
Thanks, Yang.
Re: [Qemu-devel] [PATCH 04/12] global_state: Make section optional
Quoted 7 lines · Yang Hongyang
Quoted 4 lines · Juan Quintela
This section would be sent:
a- for all new machine types
b- for old achine types if section state is different form {running,paused}s/achine/machine/
Thanks, done
PATCH v2 5/12 vmstate: Create optional sections
In reply to Juan QuintelaTo make sections optional, we need to do it at the beggining of the code.
--- include/migration/vmstate.h | 2 ++ migration/savevm.c | 8 ++++++++ migration/vmstate.c | 11 +++++++++++ trace-events | 1 + 4 files changed, 22 insertions(+)
include/migration/vmstate.h +2 -0
@@ -820,6 +820,8 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,void vmstate_save_state (QEMUFile *f,const VMStateDescription *vmsd,void *opaque,QJSON *vmdesc); +bool vmstate_save_needed (const VMStateDescription *vmsd,void *opaque); + int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, const VMStateDescription *vmsd, void *base, int alias_id,
migration/savevm.c +8 -0
@@ -836,6 +836,11 @@ void qemu_savevm_state_complete(QEMUFile *f)if ((!se->ops || !se->ops->save_state) && !se->vmsd) {continue ; } +if (se->vmsd && !vmstate_save_needed (se->vmsd, se->opaque)) { +trace_savevm_section_skip (se->idstr, se->section_id); +continue ; + } +trace_savevm_section_start (se->idstr, se->section_id);json_start_object (vmdesc,NULL );
@@ -949,6 +954,9 @@ static int qemu_save_device_state(QEMUFile *f)if ((!se->ops || !se->ops->save_state) && !se->vmsd) {continue ; } +if (se->vmsd && !vmstate_save_needed (se->vmsd, se->opaque)) { +continue ; + }save_section_header (f, se,QEMU_VM_SECTION_FULL );
migration/vmstate.c +11 -0
@@ -276,6 +276,17 @@ static void vmsd_desc_field_end(const VMStateDescription *vmsd, QJSON *vmdesc,json_end_object (vmdesc); } + +bool vmstate_save_needed (const VMStateDescription *vmsd,void *opaque) +{ +if (vmsd->needed && !vmsd->needed (opaque)) { +/* optional section not needed */ +return false; + } +return true; +} + +void vmstate_save_state (QEMUFile *f,const VMStateDescription *vmsd,void *opaque,QJSON *vmdesc) {
trace-events +1 -0
@@ -1191,6 +1191,7 @@ qemu_loadvm_state_section_partend(uint32_t section_id) "%u" qemu_loadvm_state_section_startfull(uint32_t section_id, const char *idstr, uint32_t instance_id, uint32_t version_id) "%u(%s) %u %u" savevm_section_start(const char *id, unsigned int section_id) "%s, section_id %u" savevm_section_end(const char *id, unsigned int section_id, int ret) "%s, section_id %u -> %d" +savevm_section_skip(const char *id, unsigned int section_id) "%s, section_id %u" savevm_state_begin(void) "" savevm_state_header(void) "" savevm_state_iterate(void) ""
Signature · 1 line
2.4.3
PATCH v2 6/12 migration: Add configuration section
In reply to Juan QuintelaIt needs to be the first one and it is not optional, that is the reason why it is opencoded. For new machine types, it is required than machine type name is the same in both sides.
It is just done right now for pc's.
--- hw/i386/pc_piix.c | 1 + hw/i386/pc_q35.c | 1 + include/migration/migration.h | 2 ++ migration/savevm.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+)
hw/i386/pc_piix.c +1 -0
@@ -308,6 +308,7 @@ static void pc_compat_2_3(MachineState *machine) {savevm_skip_section_footers ();global_state_set_optional (); +savevm_skip_configuration (); }static void pc_compat_2_2 (MachineState *machine)
hw/i386/pc_q35.c +1 -0
@@ -292,6 +292,7 @@ static void pc_compat_2_3(MachineState *machine) {savevm_skip_section_footers ();global_state_set_optional (); +savevm_skip_configuration (); }static void pc_compat_2_2 (MachineState *machine)
include/migration/migration.h +2 -0
@@ -34,6 +34,7 @@#define QEMU_VM_SECTION_FULL 0x04#define QEMU_VM_SUBSECTION 0x05#define QEMU_VM_VMDESCRIPTION 0x06 +#define QEMU_VM_CONFIGURATION 0x07#define QEMU_VM_SECTION_FOOTER 0x7estruct MigrationParams {
@@ -199,4 +200,5 @@ void ram_mig_init(void);void savevm_skip_section_footers (void );void register_global_state (void );void global_state_set_optional (void ); +void savevm_skip_configuration (void );#endif
migration/savevm.c +61 -0
84 lines not on this page · raw message
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH 06/12] migration: Add configuration section
Quoted 2 lines · Juan Quintela
It needs to be the first one and it is not optional, that is the reason why it is opencoded. For new machine types, it is required than machine
s/than/that/
BTW, only check machine type is enough? should we send/check all the configurations?
Quoted 147 lines
type name is the same in both sides.
It is just done right now for pc's.
Signed-off-by Juan Quintela <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>--- hw/i386/pc_piix.c | 1 + hw/i386/pc_q35.c | 1 + include/migration/migration.h | 2 ++ migration/savevm.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+)hw/i386/pc_piix.c +1
-0@@ -308,6 +308,7 @@ static void pc_compat_2_3(MachineState *machine) {savevm_skip_section_footers ();global_state_set_optional (); +savevm_skip_configuration (); }static void pc_compat_2_2 (MachineState *machine)hw/i386/pc_q35.c +1
-0@@ -292,6 +292,7 @@ static void pc_compat_2_3(MachineState *machine) {savevm_skip_section_footers ();global_state_set_optional (); +savevm_skip_configuration (); }static void pc_compat_2_2 (MachineState *machine)include/migration/migration.h +2
-0@@ -34,6 +34,7 @@#define QEMU_VM_SECTION_FULL 0x04#define QEMU_VM_SUBSECTION 0x05#define QEMU_VM_VMDESCRIPTION 0x06 +#define QEMU_VM_CONFIGURATION 0x07#define QEMU_VM_SECTION_FOOTER 0x7estruct MigrationParams {@@ -199,4 +200,5 @@ void ram_mig_init(void);void savevm_skip_section_footers (void );void register_global_state (void );void global_state_set_optional (void ); +void savevm_skip_configuration (void );#endif migration/savevm.c +61
-0@@ -246,11 +246,55 @@ typedef struct SaveStateEntry {typedef struct SaveState { QTAILQ_HEAD(, SaveStateEntry) handlers;int global_section_id; +bool skip_configuration; +uint32_t len; +const char *name; }SaveState ;static SaveState savevm_state = { .handlers =QTAILQ_HEAD_INITIALIZER (savevm_state.handlers), .global_section_id =0 , + .skip_configuration = false, +}; + +void savevm_skip_configuration (void ) +{ + savevm_state.skip_configuration = true; +} + + +static void configuration_pre_save (void *opaque) +{ +SaveState *state = opaque; +const char *current_name =MACHINE_GET_CLASS (current_machine)->name; + + state->len =strlen (current_name); + state->name = current_name; +} + +static int configuration_post_load (void *opaque,int version_id) +{ +SaveState *state = opaque; +const char *current_name =MACHINE_GET_CLASS (current_machine)->name; + +if (strncmp (state->name, current_name, state->len) !=0 ) { +error_report ("Machine type received is '%s' and local is '%s'" , + state->name, current_name); +return -EINVAL ; + } +return 0 ; +} + +static const VMStateDescription vmstate_configuration = { + .name ="configuration" , + .version_id =1 , + .post_load = configuration_post_load, + .pre_save = configuration_pre_save, + .fields = (VMStateField []) { +VMSTATE_UINT32 (len, SaveState), +VMSTATE_VBUFFER_ALLOC_UINT32 (name, SaveState,0 ,NULL ,0 , len), +VMSTATE_END_OF_LIST () + }, }; static void dump_vmstate_vmsd(FILE *out_file,@@ -723,6 +767,11 @@ void qemu_savevm_state_begin(QEMUFile *f, se->ops->set_params (params, se->opaque); } +if (!savevm_state.skip_configuration) { +qemu_put_byte (f,QEMU_VM_CONFIGURATION ); +vmstate_save_state (f, &vmstate_configuration, &savevm_state,0 ); + } + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {if (!se->ops || !se->ops->save_live_setup) {continue ;@@ -1037,6 +1086,18 @@ int qemu_loadvm_state(QEMUFile *f)return -ENOTSUP ; } +if (!savevm_state.skip_configuration) { +if (qemu_get_byte (f) !=QEMU_VM_CONFIGURATION ) { +error_report ("Configuration section missing" ); +return -EINVAL ; + } + ret =vmstate_load_state (f, &vmstate_configuration, &savevm_state,0 ); + +if (ret) { +return ret; + } + } +while ((section_type =qemu_get_byte (f)) !=QEMU_VM_EOF ) {uint32_t instance_id, version_id, section_id;SaveStateEntry *se;
Signature · 2 lines
Thanks, Yang.
Re: [Qemu-devel] [PATCH 06/12] migration: Add configuration section
Quoted 8 lines · Yang Hongyang
Quoted 2 lines · Juan Quintela
It needs to be the first one and it is not optional, that is the reason why it is opencoded. For new machine types, it is required than machine
s/than/that/
BTW, only check machine type is enough? should we send/check all the configurations?
Be my guest. You can add a subsection to that section to test whatever you want. I don't know how to test all devices really, but now, there is a place *where* you can do it.
Thanks, Juan.
PATCH v2 7/12 migration: Use cmpxchg correctly
In reply to Juan Quintelacmpxchg returns the old value
--- migration/migration.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
migration/migration.c +1 -1
@@ -508,7 +508,7 @@ void qmp_migrate_set_parameters(bool has_compress_level,static void migrate_set_state (MigrationState *s,int old_state,int new_state) { -if (atomic_cmpxchg (&s->state, old_state, new_state) == new_state) { +if (atomic_cmpxchg (&s->state, old_state, new_state) == old_state) {trace_migrate_set_state (new_state); } }
Signature · 1 line
2.4.3
PATCH v2 8/12 migration: ensure we start in NONE state
In reply to Juan Quintela--- migration/migration.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
migration/migration.c +6 -1
@@ -693,7 +693,6 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,error_setg (errp,QERR_MIGRATION_ACTIVE );return ; } -if (runstate_check (RUN_STATE_INMIGRATE )) {error_setg (errp,"Guest is waiting for an incoming migration" );return ;
@@ -708,6 +707,12 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,return ; } +/* We are starting a new migration, so we want to start in a clean +state. This change is only needed if previous migration +failed/was cancelled. We don't use migrate_set_state() because +we are setting the initial state, not changing it. */ + s->state =MIGRATION_STATUS_NONE ; + s =migrate_init (¶ms);if (strstart (uri,"tcp:" , &p)) {
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH 08/12] migration: ensure we start in NONE state
Quoted 18 lines · * Juan Quintela ([email protected]) wrote:
Signed-off-by Juan Quintela <[email protected]>--- migration/migration.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)migration/migration.c +0
-1@@ -693,7 +693,6 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,error_setg (errp,QERR_MIGRATION_ACTIVE );return ; } -if (runstate_check (RUN_STATE_INMIGRATE )) {error_setg (errp,"Guest is waiting for an incoming migration" );return ;
migration/migration.c void qmp_migrate(const char *uri, bool has_blk, bool blk, · line 715
Quoted 9 lines
migration/migration.c +6
-0@@ -708,6 +707,12 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,return ; } +/* We are starting a new migration, so we want to start in a clean +state. This change is only needed if previous migration +failed/was cancelled. We don't use migrate_set_state() because +we are setting the initial state, not changing it. */ + s->state =MIGRATION_STATUS_NONE ; +
Yes, I think that should work; we've already checked which state we're in, so we can't already be running a migration at this point, and this would be run from the main thread.
Quoted 6 lines
migration/migration.c +0
-0s =migrate_init (¶ms);if (strstart (uri,"tcp:" , &p)) {Signature · 1 line
2.4.3
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH 08/12] migration: ensure we start in NONE state
In reply to Juan QuintelaQuoted 10 lines · Juan Quintela
Signed-off-by Juan Quintela <[email protected]>--- migration/migration.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)migration/migration.c +0
-0
migration/migration.c void qmp_migrate(const char *uri, bool has_blk, bool blk, · line 696
Quoted 4 lines
migration/migration.c +0
-1@@ -693,7 +693,6 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,error_setg (errp,QERR_MIGRATION_ACTIVE );return ; } -
suspicious blank line removal?
Quoted 17 lines
migration/migration.c +6
-0if (runstate_check (RUN_STATE_INMIGRATE )) {error_setg (errp,"Guest is waiting for an incoming migration" );return ;@@ -708,6 +707,12 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,return ; } +/* We are starting a new migration, so we want to start in a clean +state. This change is only needed if previous migration +failed/was cancelled. We don't use migrate_set_state() because +we are setting the initial state, not changing it. */ + s->state =MIGRATION_STATUS_NONE ; + s =migrate_init (¶ms);if (strstart (uri,"tcp:" , &p)) {
Signature · 2 lines
Thanks, Yang.
PATCH v2 9/12 migration: Use always helper to set state
In reply to Juan QuintelaThere were three places that were not using the migrate_set_state() helper, just fix that.
--- migration/migration.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
migration/migration.c +3 -3
@@ -548,7 +548,7 @@ void migrate_fd_error(MigrationState *s) {trace_migrate_fd_error ();assert (s->file ==NULL ); - s->state =MIGRATION_STATUS_FAILED ; +migrate_set_state (s,MIGRATION_STATUS_SETUP ,MIGRATION_STATUS_FAILED );trace_migrate_set_state (MIGRATION_STATUS_FAILED );notifier_list_notify (&migration_state_notifiers, s); }
@@ -633,7 +633,7 @@ static MigrationState *migrate_init(const MigrationParams *params) s->parameters[MIGRATION_PARAMETER_DECOMPRESS_THREADS ] = decompress_thread_count; s->bandwidth_limit = bandwidth_limit; - s->state =MIGRATION_STATUS_SETUP ; +migrate_set_state (s,MIGRATION_STATUS_NONE ,MIGRATION_STATUS_SETUP );trace_migrate_set_state (MIGRATION_STATUS_SETUP ); s->total_time =qemu_clock_get_ms (QEMU_CLOCK_REALTIME );
@@ -732,7 +732,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, }else {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"uri" ,"a valid migration protocol" ); - s->state =MIGRATION_STATUS_FAILED ; +migrate_set_state (s,MIGRATION_STATUS_SETUP ,MIGRATION_STATUS_FAILED );return ; }
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH 09/12] migration: Use always helper to set state
Quoted 4 lines · * Juan Quintela ([email protected]) wrote:
There were three places that were not using the
migrate_set_state()helper, just fix that.Signed-off-by Juan Quintela <[email protected]>
Quoted 38 lines
--- migration/migration.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)migration/migration.c +3
-3@@ -548,7 +548,7 @@ void migrate_fd_error(MigrationState *s) {trace_migrate_fd_error ();assert (s->file ==NULL ); - s->state =MIGRATION_STATUS_FAILED ; +migrate_set_state (s,MIGRATION_STATUS_SETUP ,MIGRATION_STATUS_FAILED );trace_migrate_set_state (MIGRATION_STATUS_FAILED );notifier_list_notify (&migration_state_notifiers, s); }@@ -633,7 +633,7 @@ static MigrationState *migrate_init(const MigrationParams *params) s->parameters[MIGRATION_PARAMETER_DECOMPRESS_THREADS ] = decompress_thread_count; s->bandwidth_limit = bandwidth_limit; - s->state =MIGRATION_STATUS_SETUP ; +migrate_set_state (s,MIGRATION_STATUS_NONE ,MIGRATION_STATUS_SETUP );trace_migrate_set_state (MIGRATION_STATUS_SETUP ); s->total_time =qemu_clock_get_ms (QEMU_CLOCK_REALTIME );@@ -732,7 +732,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, }else {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"uri" ,"a valid migration protocol" ); - s->state =MIGRATION_STATUS_FAILED ; +migrate_set_state (s,MIGRATION_STATUS_SETUP ,MIGRATION_STATUS_FAILED );return ; }Signature · 1 line
2.4.3
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH 09/12] migration: Use always helper to set state
In reply to Juan QuintelaQuoted 4 lines · Juan Quintela
There were three places that were not using the
migrate_set_state()helper, just fix that.Signed-off-by Juan Quintela <[email protected]>
Quoted 35 lines
--- migration/migration.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)migration/migration.c +3
-3@@ -548,7 +548,7 @@ void migrate_fd_error(MigrationState *s) {trace_migrate_fd_error ();assert (s->file ==NULL ); - s->state =MIGRATION_STATUS_FAILED ; +migrate_set_state (s,MIGRATION_STATUS_SETUP ,MIGRATION_STATUS_FAILED );trace_migrate_set_state (MIGRATION_STATUS_FAILED );notifier_list_notify (&migration_state_notifiers, s); }@@ -633,7 +633,7 @@ static MigrationState *migrate_init(const MigrationParams *params) s->parameters[MIGRATION_PARAMETER_DECOMPRESS_THREADS ] = decompress_thread_count; s->bandwidth_limit = bandwidth_limit; - s->state =MIGRATION_STATUS_SETUP ; +migrate_set_state (s,MIGRATION_STATUS_NONE ,MIGRATION_STATUS_SETUP );trace_migrate_set_state (MIGRATION_STATUS_SETUP ); s->total_time =qemu_clock_get_ms (QEMU_CLOCK_REALTIME );@@ -732,7 +732,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, }else {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"uri" ,"a valid migration protocol" ); - s->state =MIGRATION_STATUS_FAILED ; +migrate_set_state (s,MIGRATION_STATUS_SETUP ,MIGRATION_STATUS_FAILED );return ; }
Signature · 2 lines
Thanks, Yang.
PATCH v2 10/12 migration: No need to call trace_migrate_set_state()
In reply to Juan QuintelaWe now use the helper everywhere, so no need to call this on this two places. See on previous commit that there were a place where we missed to mark the trace. Now all tracing is done in migrate_set_state().
--- migration/migration.c | 2 -- 1 file changed, 2 deletions(-)
migration/migration.c +0 -2
@@ -549,7 +549,6 @@ void migrate_fd_error(MigrationState *s)trace_migrate_fd_error ();assert (s->file ==NULL );migrate_set_state (s,MIGRATION_STATUS_SETUP ,MIGRATION_STATUS_FAILED ); -trace_migrate_set_state (MIGRATION_STATUS_FAILED );notifier_list_notify (&migration_state_notifiers, s); }
@@ -634,7 +633,6 @@ static MigrationState *migrate_init(const MigrationParams *params) decompress_thread_count; s->bandwidth_limit = bandwidth_limit;migrate_set_state (s,MIGRATION_STATUS_NONE ,MIGRATION_STATUS_SETUP ); -trace_migrate_set_state (MIGRATION_STATUS_SETUP ); s->total_time =qemu_clock_get_ms (QEMU_CLOCK_REALTIME );return s;
Signature · 1 line
2.4.3
PATCH v2 11/12 migration: create migration event
In reply to Juan QuintelaWe have one argument that tells us what event has happened.
--- docs/qmp/qmp-events.txt | 14 ++++++++++++++ migration/migration.c | 2 ++ qapi/event.json | 12 ++++++++++++ 3 files changed, 28 insertions(+)
docs/qmp/qmp-events.txt +14 -0
@@ -473,6 +473,20 @@ Example: { "timestamp": {"seconds": 1290688046, "microseconds": 417172}, "event": "SPICE_MIGRATE_COMPLETED" } +MIGRATION +--------- + +Emitted when a migration event happens + +Data: None. + + - "status": migration status + See MigrationStatus in ~/qapi-schema.json for possible values + +Example: + +{"timestamp": {"seconds": 1432121972, "microseconds": 744001}, + "event": "MIGRATION", "data": {"status": "completed"}} STOP ----
migration/migration.c +2 -0
@@ -27,6 +27,7 @@#include "qmp-commands.h" #include "trace.h" #include "qapi/util.h" +#include "qapi-event.h" #define MAX_THROTTLE (32 << 20)/* Migration speed throttling */
@@ -509,6 +510,7 @@ void qmp_migrate_set_parameters(bool has_compress_level,static void migrate_set_state (MigrationState *s,int old_state,int new_state) {if (atomic_cmpxchg (&s->state, old_state, new_state) == old_state) { +qapi_event_send_migration (new_state, &error_abort);trace_migrate_set_state (new_state); } }
qapi/event.json +12 -0
@@ -243,6 +243,18 @@ { 'event': 'SPICE_MIGRATE_COMPLETED' } ## +# @MIGRATION +# +# Emitted when a migration event happens +# +# @status: @MigrationStatus describing the current migration status. +# +# Since: 2.4 +## +{ 'event': 'MIGRATION', + 'data': {'status': 'MigrationStatus'}} + +## # @ACPI_DEVICE_OST # # Emitted when guest executes ACPI _OST method.
Signature · 1 line
2.4.3
PATCH v2 12/12 migration: Add migration events on target side
In reply to Juan QuintelaWe reuse the migration events from the source side, sending them on the appropiate place.
--- migration/migration.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
migration/migration.c +4 -1
@@ -221,6 +221,7 @@ void qemu_start_incoming_migration(const char *uri, Error **errp) {const char *p; +qapi_event_send_migration (MIGRATION_STATUS_SETUP , &error_abort);if (!strcmp (uri,"defer" )) {deferred_incoming_migration (errp); }else if (strstart (uri,"tcp:" , &p)) {
@@ -249,7 +250,7 @@ static void process_incoming_migration_co(void *opaque)int ret;migration_incoming_state_new (f); - +qapi_event_send_migration (MIGRATION_STATUS_ACTIVE , &error_abort); ret =qemu_loadvm_state (f);qemu_fclose (f);
@@ -257,10 +258,12 @@ static void process_incoming_migration_co(void *opaque)migration_incoming_state_destroy ();if (ret <0 ) { +qapi_event_send_migration (MIGRATION_STATUS_FAILED , &error_abort);error_report ("load of migration failed: %s" ,strerror (-ret));migrate_decompress_threads_join ();exit (EXIT_FAILURE ); } +qapi_event_send_migration (MIGRATION_STATUS_COMPLETED , &error_abort);qemu_announce_self ();/* Make sure all file formats flush their mutable metadata */
Signature · 1 line
2.4.3