Create setup/cleanup methods for migration incoming side
cover Create setup/cleanup methods for migration incoming side
Hi
This series make:
- use of cleanup/save methods generic, not only for save_live methods
- create the equivalent methods for the load side (load_setup/cleanup)
- Make ram use this methods to see how/when they are used.
Stefan, Kevin, this were the methods that you asked for the block.c migration, right? Please, comment if they are enough for you.
This are on top of the ramstate_dynamic series that I just posted.
Please, review.
Later, Juan.
Juan Quintela (5):
migration: Rename save_live_setup() to save_setup()
migration: Rename cleanup() to save_cleanup()
migration: Create load_setup()/cleanup() methods
migration: Convert ram to use new load_setup()/load_cleanup()
migration: Make compression_threads use save/load_setup/cleanup()
hw/ppc/spapr.c | 4 +-- include/migration/register.h | 6 ++-- migration/block.c | 4 +-- migration/migration.c | 8 ------ migration/ram.c | 66 ++++++++++++++++++++++++++++++-------------- migration/ram.h | 6 ---- migration/savevm.c | 41 +++++++++++++++++++++++---- 7 files changed, 89 insertions(+), 46 deletions(-)
Signature · 1 line
2.9.4
PATCH 1/5 migration: Rename save_live_setup() to save_setup()
We are going to use it now for more than save live regions.
--- hw/ppc/spapr.c | 2 +- include/migration/register.h | 2 +- migration/block.c | 2 +- migration/ram.c | 2 +- migration/savevm.c | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-)
hw/ppc/spapr.c +1 -1
@@ -1873,7 +1873,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,
include/migration/register.h +1 -1
@@ -36,7 +36,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,
migration/block.c +1 -1
@@ -995,7 +995,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,
migration/ram.c +1 -1
@@ -2597,7 +2597,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,
migration/savevm.c +3 -3
@@ -606,7 +606,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 ; }
@@ -1000,7 +1000,7 @@ void qemu_savevm_state_begin(QEMUFile *f)trace_savevm_state_begin (); 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) {
@@ -1010,7 +1010,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);
Signature · 1 line
2.9.4
PATCH 2/5 migration: Rename cleanup() to save_cleanup()
In reply to Juan QuintelaWe need a cleanup for loads.
--- hw/ppc/spapr.c | 2 +- include/migration/register.h | 2 +- migration/block.c | 2 +- migration/ram.c | 2 +- migration/savevm.c | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-)
hw/ppc/spapr.c +1 -1
@@ -1876,7 +1876,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_cleanup, .load_state = htab_load, };
include/migration/register.h +1 -1
@@ -21,7 +21,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);
migration/block.c +1 -1
@@ -1000,7 +1000,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, };
migration/ram.c +1 -1
@@ -2603,7 +2603,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 )
migration/savevm.c +2 -2
@@ -1242,8 +1242,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); } } }
Signature · 1 line
2.9.4
PATCH 3/5 migration: Create load_setup()/cleanup() methods
In reply to Juan QuintelaWe need to do things at load time.
--- include/migration/register.h | 2 ++ migration/savevm.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
include/migration/register.h +2 -0
@@ -42,6 +42,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(DeviceState *dev,
migration/savevm.c +31 -0
@@ -1928,6 +1928,31 @@ qemu_loadvm_section_part_end(QEMUFile *f, MigrationIncomingState *mis)return 0 ; } +static int qemu_savevm_load_state_begin (QEMUFile *f) +{ +SaveStateEntry *se; +int ret; + +trace_savevm_state_begin (); + 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); +return ret; + } + } +return 0 ; +} +static int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis) {uint8_t section_type;
@@ -2000,6 +2025,12 @@ int qemu_loadvm_state(QEMUFile *f)return -ENOTSUP ; } + +if (qemu_savevm_load_state_begin (f) !=0 ) { +error_report ("Load state of one device failed" ); +return -EINVAL ; + } +if (!savevm_state.skip_configuration ||enforce_config_section ()) {if (qemu_get_byte (f) !=QEMU_VM_CONFIGURATION ) {error_report ("Configuration section missing" );
Signature · 1 line
2.9.4
Re: [Qemu-devel] [PATCH 3/5] migration: Create load_setup()/cleanup() methods
Am 02.06.2017 um 00:15 hat Juan Quintela geschrieben:
Quoted 13 lines
We need to do things at load time.
Signed-off-by Juan Quintela <[email protected]>--- include/migration/register.h | 2 ++ migration/savevm.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)include/migration/register.h +0
-0
include/migration/register.h typedef struct SaveVMHandlers { · line 47
Quoted 6 lines
include/migration/register.h +2
-0@@ -42,6 +42,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;
I see that you add code to call load_setup(), but don't you want to call load_cleanup() somewhere, too?
Kevin
Re: [Qemu-devel] [PATCH 3/5] migration: Create load_setup()/cleanup() methods
Quoted 9 lines · Kevin Wolf
Am 02.06.2017 um 00:15 hat Juan Quintela geschrieben:
Quoted 8 lines
We need to do things at load time.
Signed-off-by Juan Quintela <[email protected]>--- include/migration/register.h | 2 ++ migration/savevm.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
Quoted 14 lines
include/migration/register.h typedef struct SaveVMHandlers { · line 47
Quoted 11 lines
include/migration/register.h +2
-0@@ -42,6 +42,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;I see that you add code to call
load_setup(), but don't you want to callload_cleanup()somewhere, too?
Oops, you are right.
I just sent another version of this series. They are built on top of my pull request. And I added the call to load_cleanup.
Thanks for the review, Juan.
PATCH 4/5 migration: Convert ram to use new load_setup()/load_cleanup()
In reply to Juan QuintelaOnce there, I rename ram_migration_cleanup() to ram_save_cleanup(). Notice that this is the first pass, and I only passed XBZRLE to the new scheme. Moved decoded_buf to inside XBZRLE struct. As a bonus, I don't have to export xbzrle functions from ram.c.
--- migration/migration.c | 3 --- migration/ram.c | 52 +++++++++++++++++++++++++++++++++++---------------- migration/ram.h | 1 - 3 files changed, 36 insertions(+), 20 deletions(-)
migration/migration.c +0 -3
@@ -350,9 +350,6 @@ static void process_incoming_migration_co(void *opaque)migrate_decompress_threads_join ();exit (EXIT_FAILURE ); } - -free_xbzrle_decoded_buf (); - mis->bh =qemu_bh_new (process_incoming_migration_bh, mis);qemu_bh_schedule (mis->bh); }
migration/ram.c +36 -16
95 lines not on this page · raw message
migration/ram.h +0 -1
@@ -46,7 +46,6 @@ void migrate_decompress_threads_join(void);uint64_t ram_pagesize_summary (void );int ram_save_queue_pages (const char *rbname,ram_addr_t start,ram_addr_t len);void acct_update_position (QEMUFile *f,size_t size,bool zero); -void free_xbzrle_decoded_buf (void );void ram_debug_dump_bitmap (unsigned long *todump,bool expected,unsigned long pages);void ram_postcopy_migrated_memory_release (MigrationState *ms);
Signature · 1 line
2.9.4
PATCH 5/5 migration: Make compression_threads use save/load_setup/cleanup()
In reply to Juan QuintelaOnce there, be consistent and use
compress_thread_{save,load}_{setup,cleanup}.
--- migration/migration.c | 5 ----- migration/ram.c | 12 ++++++++---- migration/ram.h | 5 ----- 3 files changed, 8 insertions(+), 14 deletions(-)
migration/migration.c +0 -5
@@ -284,7 +284,6 @@ static void process_incoming_migration_bh(void *opaque) }else {runstate_set (global_state_get_runstate ()); } -migrate_decompress_threads_join ();/* * This must happen after any state changes since as soon as an external * observer sees this event they might start to prod at the VM assuming
@@ -347,7 +346,6 @@ static void process_incoming_migration_co(void *opaque)migrate_set_state (&mis->state,MIGRATION_STATUS_ACTIVE ,MIGRATION_STATUS_FAILED );error_report ("load of migration failed: %s" ,strerror (-ret)); -migrate_decompress_threads_join ();exit (EXIT_FAILURE ); } mis->bh =qemu_bh_new (process_incoming_migration_bh, mis);
@@ -358,7 +356,6 @@ void migration_fd_process_incoming(QEMUFile *f) {Coroutine *co =qemu_coroutine_create (process_incoming_migration_co, f); -migrate_decompress_threads_create ();qemu_file_set_blocking (f, false);qemu_coroutine_enter (co); }
@@ -823,7 +820,6 @@ static void migrate_fd_cleanup(void *opaque) }qemu_mutex_lock_iothread (); -migrate_compress_threads_join ();qemu_fclose (s->to_dst_file); s->to_dst_file =NULL ; }
@@ -1974,7 +1970,6 @@ void migrate_fd_connect(MigrationState *s) } } -migrate_compress_threads_create ();qemu_thread_create (&s->thread,"live_migration" , migration_thread, s,QEMU_THREAD_JOINABLE ); s->migration_thread_running = true;
migration/ram.c +8 -4
@@ -299,7 +299,7 @@ static inline void terminate_compression_threads(void) } } -void migrate_compress_threads_join (void ) +static void compress_threads_save_cleanup (void ) {int i, thread_count;
@@ -322,7 +322,7 @@ void migrate_compress_threads_join(void) comp_param =NULL ; } -void migrate_compress_threads_create (void ) +static void compress_threads_save_setup (void ) {int i, thread_count;
@@ -1383,6 +1383,7 @@ static void ram_save_cleanup(void *opaque) }XBZRLE_cache_unlock ();migration_page_queue_free (*rsp); +compress_threads_save_cleanup ();g_free (*rsp); *rsp =NULL ; }
@@ -1915,6 +1916,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque) }rcu_read_unlock (); +compress_threads_save_setup ();ram_control_before_iterate (f,RAM_CONTROL_SETUP );ram_control_after_iterate (f,RAM_CONTROL_SETUP );
@@ -2220,7 +2222,7 @@ static void wait_for_decompress_done(void)qemu_mutex_unlock (&decomp_done_lock); } -void migrate_decompress_threads_create (void ) +static void compress_threads_load_setup (void ) {int i, thread_count;
@@ -2241,7 +2243,7 @@ void migrate_decompress_threads_create(void) } } -void migrate_decompress_threads_join (void ) +static void compress_threads_load_cleanup (void ) {int i, thread_count;
@@ -2304,12 +2306,14 @@ static void decompress_data_with_multi_threads(QEMUFile *f,static int ram_load_setup (QEMUFile *f,void *opaque) {xbzrle_load_setup (); +compress_threads_load_setup ();return 0 ; }static int ram_load_cleanup (void *opaque) {xbzrle_load_cleanup (); +compress_threads_load_cleanup ();return 0 ; }
migration/ram.h +0 -5
@@ -38,11 +38,6 @@ extern XBZRLECacheStats xbzrle_counters;int64_t xbzrle_cache_resize (int64_t new_size);uint64_t ram_bytes_total (void ); -void migrate_compress_threads_create (void ); -void migrate_compress_threads_join (void ); -void migrate_decompress_threads_create (void ); -void migrate_decompress_threads_join (void ); -uint64_t ram_pagesize_summary (void );int ram_save_queue_pages (const char *rbname,ram_addr_t start,ram_addr_t len);void acct_update_position (QEMUFile *f,size_t size,bool zero);
Signature · 1 line
2.9.4
Quoted 1 line · Juan Quintela
Hi
Hi Kevin and Stefan, I intended to cc you on this series.
Is this what you were asking for block layer migration?
Do you need anything else?
Thanks, Juan.
Quoted 29 lines
This series make:
- use of cleanup/save methods generic, not only forsave_livemethods
- create the equivalent methods for the load side (load_setup/cleanup)
- Make ram use this methods to see how/when they are used.Stefan, Kevin, this were the methods that you asked for the
block.cmigration, right? Please, comment if they are enough for you.This are on top of the
ramstate_dynamicseries that I just posted.Please, review.
Later, Juan.
Juan Quintela (5):
migration: Renamesave_live_setup()tosave_setup()
migration: Renamecleanup()tosave_cleanup()
migration: Create load_setup()/cleanup() methods
migration: Convert ram to use new load_setup()/load_cleanup()
migration: Makecompression_threadsuse save/load_setup/cleanup()hw/ppc/spapr.c | 4 +-- include/migration/register.h | 6 ++-- migration/block.c | 4 +-- migration/migration.c | 8 ------ migration/ram.c | 66 ++++++++++++++++++++++++++++++-------------- migration/ram.h | 6 ---- migration/savevm.c | 41 +++++++++++++++++++++++---- 7 files changed, 89 insertions(+), 46 deletions(-)
Am 07.06.2017 um 19:53 hat Juan Quintela geschrieben:
Quoted 8 lines
Quoted 1 line · Juan Quintela
Hi
Hi Kevin and Stefan, I intended to cc you on this series.
Is this what you were asking for block layer migration?
Do you need anything else?
I didn't manage to apply this to my local git tree, so my review is based on scanning the emails.
The important part for us is probably where you call the .cleanup_load callback. As I commented on the patch, I don't see any place in this series that calls it. We need it before bdrv_invalidate_cache_all() is called, I think.
Kevin