From b605c47b57b58e61a901a50a0762dccf43d94783 Mon Sep 17 00:00:00 2001 From: Peter Xu Date: Wed, 5 Jul 2017 16:21:20 +0800 Subject: migration: fix handling for --only-migratable MigrateState object is not ready at that time, so we'll get an assertion. Use qemu_global_option() instead. Reported-by: Eduardo Habkost Suggested-by: Eduardo Habkost Reviewed-by: Eduardo Habkost Reviewed-by: Juan Quintela Fixes: 3df663e ("migration: move only_migratable to MigrationState") Signed-off-by: Peter Xu Message-Id: <1499242883-2184-2-git-send-email-peterx@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- include/migration/misc.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include') diff --git a/include/migration/misc.h b/include/migration/misc.h index 22551216bb..c079b7771b 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -53,7 +53,6 @@ bool migration_has_finished(MigrationState *); bool migration_has_failed(MigrationState *); /* ...and after the device transmission */ bool migration_in_postcopy_after_devices(MigrationState *); -void migration_only_migratable_set(void); void migration_global_dump(Monitor *mon); #endif -- cgit v1.2.3-55-g7522 From 9907e842d70165ae0059fcd8f770342718c0fa0f Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Wed, 28 Jun 2017 11:52:24 +0200 Subject: migration: Rename save_live_setup() to save_setup() We are going to use it now for more than save live regions. Once there rename qemu_savevm_state_begin() to qemu_savevm_state_setup(). Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Message-Id: <20170628095228.4661-2-quintela@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- hw/ppc/spapr.c | 2 +- include/migration/register.h | 2 +- migration/block.c | 2 +- migration/colo.c | 2 +- migration/migration.c | 2 +- migration/ram.c | 2 +- migration/savevm.c | 12 ++++++------ migration/savevm.h | 2 +- migration/trace-events | 2 +- 9 files changed, 14 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 0ee9fac50b..ba87be5d48 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1953,7 +1953,7 @@ static void htab_cleanup(void *opaque) } static SaveVMHandlers savevm_htab_handlers = { - .save_live_setup = htab_save_setup, + .save_setup = htab_save_setup, .save_live_iterate = htab_save_iterate, .save_live_complete_precopy = htab_save_complete, .cleanup = htab_cleanup, diff --git a/include/migration/register.h b/include/migration/register.h index d9498d95eb..f607769e83 100644 --- a/include/migration/register.h +++ b/include/migration/register.h @@ -33,7 +33,7 @@ typedef struct SaveVMHandlers { int (*save_live_iterate)(QEMUFile *f, void *opaque); /* This runs outside the iothread lock! */ - int (*save_live_setup)(QEMUFile *f, void *opaque); + int (*save_setup)(QEMUFile *f, void *opaque); void (*save_live_pending)(QEMUFile *f, void *opaque, uint64_t threshold_size, uint64_t *non_postcopiable_pending, diff --git a/migration/block.c b/migration/block.c index 86c0b96cd1..7a7e83a268 100644 --- a/migration/block.c +++ b/migration/block.c @@ -1008,7 +1008,7 @@ static bool block_is_active(void *opaque) } static SaveVMHandlers savevm_block_handlers = { - .save_live_setup = block_save_setup, + .save_setup = block_save_setup, .save_live_iterate = block_save_iterate, .save_live_complete_precopy = block_save_complete, .save_live_pending = block_save_pending, diff --git a/migration/colo.c b/migration/colo.c index c4ba4c328b..ef35f00c9a 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -350,7 +350,7 @@ static int colo_do_checkpoint_transaction(MigrationState *s, /* Disable block migration */ migrate_set_block_enabled(false, &local_err); qemu_savevm_state_header(fb); - qemu_savevm_state_begin(fb); + qemu_savevm_state_setup(fb); qemu_mutex_lock_iothread(); qemu_savevm_state_complete_precopy(fb, false, false); qemu_mutex_unlock_iothread(); diff --git a/migration/migration.c b/migration/migration.c index 31d46d1343..beea01ce63 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1835,7 +1835,7 @@ static void *migration_thread(void *opaque) qemu_savevm_send_postcopy_advise(s->to_dst_file); } - qemu_savevm_state_begin(s->to_dst_file); + qemu_savevm_state_setup(s->to_dst_file); s->setup_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) - setup_start; migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, diff --git a/migration/ram.c b/migration/ram.c index 0baa1e0d56..480248a00f 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2623,7 +2623,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) } static SaveVMHandlers savevm_ram_handlers = { - .save_live_setup = ram_save_setup, + .save_setup = ram_save_setup, .save_live_iterate = ram_save_iterate, .save_live_complete_postcopy = ram_save_complete, .save_live_complete_precopy = ram_save_complete, diff --git a/migration/savevm.c b/migration/savevm.c index be3f885119..66f816040e 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -596,7 +596,7 @@ int register_savevm_live(DeviceState *dev, se->opaque = opaque; se->vmsd = NULL; /* if this is a live_savem then set is_ram */ - if (ops->save_live_setup != NULL) { + if (ops->save_setup != NULL) { se->is_ram = 1; } @@ -955,14 +955,14 @@ void qemu_savevm_state_header(QEMUFile *f) } } -void qemu_savevm_state_begin(QEMUFile *f) +void qemu_savevm_state_setup(QEMUFile *f) { SaveStateEntry *se; int ret; - trace_savevm_state_begin(); + trace_savevm_state_setup(); QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { - if (!se->ops || !se->ops->save_live_setup) { + if (!se->ops || !se->ops->save_setup) { continue; } if (se->ops && se->ops->is_active) { @@ -972,7 +972,7 @@ void qemu_savevm_state_begin(QEMUFile *f) } save_section_header(f, se, QEMU_VM_SECTION_START); - ret = se->ops->save_live_setup(f, se->opaque); + ret = se->ops->save_setup(f, se->opaque); save_section_footer(f, se); if (ret < 0) { qemu_file_set_error(f, ret); @@ -1241,7 +1241,7 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp) qemu_mutex_unlock_iothread(); qemu_savevm_state_header(f); - qemu_savevm_state_begin(f); + qemu_savevm_state_setup(f); qemu_mutex_lock_iothread(); while (qemu_file_get_error(f) == 0) { diff --git a/migration/savevm.h b/migration/savevm.h index 5a2ed1161d..6babc6221a 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -30,7 +30,7 @@ #define QEMU_VM_SECTION_FOOTER 0x7e bool qemu_savevm_state_blocked(Error **errp); -void qemu_savevm_state_begin(QEMUFile *f); +void qemu_savevm_state_setup(QEMUFile *f); void qemu_savevm_state_header(QEMUFile *f); int qemu_savevm_state_iterate(QEMUFile *f, bool postcopy); void qemu_savevm_state_cleanup(void); diff --git a/migration/trace-events b/migration/trace-events index 38345be9c3..9669e94ddc 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -32,7 +32,7 @@ savevm_send_open_return_path(void) "" savevm_send_ping(uint32_t val) "%x" savevm_send_postcopy_listen(void) "" savevm_send_postcopy_run(void) "" -savevm_state_begin(void) "" +savevm_state_setup(void) "" savevm_state_header(void) "" savevm_state_iterate(void) "" savevm_state_cleanup(void) "" -- cgit v1.2.3-55-g7522 From 70f794fcfa7c1b9d7af465d124a0e6175da30e39 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Wed, 28 Jun 2017 11:52:25 +0200 Subject: migration: Rename cleanup() to save_cleanup() We need a cleanup for loads, so we rename here to be consistent. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert -- Rename htab_cleanup to htap_save_cleanup as dave suggestion Message-Id: <20170628095228.4661-3-quintela@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- hw/ppc/spapr.c | 4 ++-- include/migration/register.h | 2 +- migration/block.c | 2 +- migration/ram.c | 2 +- migration/savevm.c | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index ba87be5d48..990772b633 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1945,7 +1945,7 @@ static int htab_load(QEMUFile *f, void *opaque, int version_id) return 0; } -static void htab_cleanup(void *opaque) +static void htab_save_cleanup(void *opaque) { sPAPRMachineState *spapr = opaque; @@ -1956,7 +1956,7 @@ static SaveVMHandlers savevm_htab_handlers = { .save_setup = htab_save_setup, .save_live_iterate = htab_save_iterate, .save_live_complete_precopy = htab_save_complete, - .cleanup = htab_cleanup, + .save_cleanup = htab_save_cleanup, .load_state = htab_load, }; diff --git a/include/migration/register.h b/include/migration/register.h index f607769e83..938ea2bc3d 100644 --- a/include/migration/register.h +++ b/include/migration/register.h @@ -18,7 +18,7 @@ typedef struct SaveVMHandlers { /* This runs inside the iothread lock. */ SaveStateHandler *save_state; - void (*cleanup)(void *opaque); + void (*save_cleanup)(void *opaque); int (*save_live_complete_postcopy)(QEMUFile *f, void *opaque); int (*save_live_complete_precopy)(QEMUFile *f, void *opaque); diff --git a/migration/block.c b/migration/block.c index 7a7e83a268..9171f60028 100644 --- a/migration/block.c +++ b/migration/block.c @@ -1013,7 +1013,7 @@ static SaveVMHandlers savevm_block_handlers = { .save_live_complete_precopy = block_save_complete, .save_live_pending = block_save_pending, .load_state = block_load, - .cleanup = block_migration_cleanup, + .save_cleanup = block_migration_cleanup, .is_active = block_is_active, }; diff --git a/migration/ram.c b/migration/ram.c index 480248a00f..649f76cb52 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2629,7 +2629,7 @@ static SaveVMHandlers savevm_ram_handlers = { .save_live_complete_precopy = ram_save_complete, .save_live_pending = ram_save_pending, .load_state = ram_load, - .cleanup = ram_migration_cleanup, + .save_cleanup = ram_migration_cleanup, }; void ram_mig_init(void) diff --git a/migration/savevm.c b/migration/savevm.c index 66f816040e..fee11c5d28 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1215,8 +1215,8 @@ void qemu_savevm_state_cleanup(void) trace_savevm_state_cleanup(); QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { - if (se->ops && se->ops->cleanup) { - se->ops->cleanup(se->opaque); + if (se->ops && se->ops->save_cleanup) { + se->ops->save_cleanup(se->opaque); } } } -- cgit v1.2.3-55-g7522 From acb5ea86971a7f3d0eac30996c4d0eab7b873879 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Wed, 28 Jun 2017 11:52:26 +0200 Subject: migration: Create load_setup()/cleanup() methods We need to do things at load time and at cleanup time. Signed-off-by: Juan Quintela -- Move the printing of the error message so we can print the device giving the error. Add call to postcopy stuff Message-Id: <20170628095228.4661-4-quintela@redhat.com> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert --- include/migration/register.h | 2 ++ migration/savevm.c | 45 +++++++++++++++++++++++++++++++++++++++++++- migration/savevm.h | 1 + migration/trace-events | 2 ++ 4 files changed, 49 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/migration/register.h b/include/migration/register.h index 938ea2bc3d..a0f1edd8c7 100644 --- a/include/migration/register.h +++ b/include/migration/register.h @@ -39,6 +39,8 @@ typedef struct SaveVMHandlers { uint64_t *non_postcopiable_pending, uint64_t *postcopiable_pending); LoadStateHandler *load_state; + int (*load_setup)(QEMUFile *f, void *opaque); + int (*load_cleanup)(void *opaque); } SaveVMHandlers; int register_savevm_live(DeviceState *dev, diff --git a/migration/savevm.c b/migration/savevm.c index fee11c5d28..fdd15fa0a7 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1541,7 +1541,7 @@ static void *postcopy_ram_listen_thread(void *opaque) * got a bad migration state). */ migration_incoming_state_destroy(); - + qemu_loadvm_state_cleanup(); return NULL; } @@ -1901,6 +1901,44 @@ qemu_loadvm_section_part_end(QEMUFile *f, MigrationIncomingState *mis) return 0; } +static int qemu_loadvm_state_setup(QEMUFile *f) +{ + SaveStateEntry *se; + int ret; + + trace_loadvm_state_setup(); + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + if (!se->ops || !se->ops->load_setup) { + continue; + } + if (se->ops && se->ops->is_active) { + if (!se->ops->is_active(se->opaque)) { + continue; + } + } + + ret = se->ops->load_setup(f, se->opaque); + if (ret < 0) { + qemu_file_set_error(f, ret); + error_report("Load state of device %s failed", se->idstr); + return ret; + } + } + return 0; +} + +void qemu_loadvm_state_cleanup(void) +{ + SaveStateEntry *se; + + trace_loadvm_state_cleanup(); + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + if (se->ops && se->ops->load_cleanup) { + se->ops->load_cleanup(se->opaque); + } + } +} + static int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis) { uint8_t section_type; @@ -1973,6 +2011,10 @@ int qemu_loadvm_state(QEMUFile *f) return -ENOTSUP; } + if (qemu_loadvm_state_setup(f) != 0) { + return -EINVAL; + } + if (migrate_get_current()->send_configuration) { if (qemu_get_byte(f) != QEMU_VM_CONFIGURATION) { error_report("Configuration section missing"); @@ -2036,6 +2078,7 @@ int qemu_loadvm_state(QEMUFile *f) } } + qemu_loadvm_state_cleanup(); cpu_synchronize_all_post_init(); return ret; diff --git a/migration/savevm.h b/migration/savevm.h index 6babc6221a..295c4a1f2c 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -53,5 +53,6 @@ void qemu_savevm_send_postcopy_ram_discard(QEMUFile *f, const char *name, uint64_t *length_list); int qemu_loadvm_state(QEMUFile *f); +void qemu_loadvm_state_cleanup(void); #endif diff --git a/migration/trace-events b/migration/trace-events index 9669e94ddc..cb2c4b5b40 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -7,6 +7,8 @@ qemu_loadvm_state_section_partend(uint32_t section_id) "%u" qemu_loadvm_state_post_main(int ret) "%d" qemu_loadvm_state_section_startfull(uint32_t section_id, const char *idstr, uint32_t instance_id, uint32_t version_id) "%u(%s) %u %u" qemu_savevm_send_packaged(void) "" +loadvm_state_setup(void) "" +loadvm_state_cleanup(void) "" loadvm_handle_cmd_packaged(unsigned int length) "%u" loadvm_handle_cmd_packaged_main(int ret) "%d" loadvm_handle_cmd_packaged_received(int ret) "%d" -- cgit v1.2.3-55-g7522