From f265e0e437a5d5fd0b48143012e2242b85816f61 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Wed, 28 Jun 2017 11:52:27 +0200 Subject: migration: Convert ram to use new load_setup()/load_cleanup() Once 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. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert -- loaded_data pointer was needed because called can change it (dave) spell loaded correctly in comment (dave) Message-Id: <20170628095228.4661-5-quintela@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- migration/ram.c | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) (limited to 'migration/ram.c') diff --git a/migration/ram.c b/migration/ram.c index 649f76cb52..73aec34161 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -85,11 +85,10 @@ static struct { QemuMutex lock; /* it will store a page full of zeros */ uint8_t *zero_target_page; + /* buffer used for XBZRLE decoding */ + uint8_t *decoded_buf; } XBZRLE; -/* buffer used for XBZRLE decoding */ -static uint8_t *xbzrle_decoded_buf; - static void XBZRLE_cache_lock(void) { if (migrate_use_xbzrle()) @@ -1350,13 +1349,18 @@ uint64_t ram_bytes_total(void) return total; } -void free_xbzrle_decoded_buf(void) +static void xbzrle_load_setup(void) { - g_free(xbzrle_decoded_buf); - xbzrle_decoded_buf = NULL; + XBZRLE.decoded_buf = g_malloc(TARGET_PAGE_SIZE); } -static void ram_migration_cleanup(void *opaque) +static void xbzrle_load_cleanup(void) +{ + g_free(XBZRLE.decoded_buf); + XBZRLE.decoded_buf = NULL; +} + +static void ram_save_cleanup(void *opaque) { RAMState **rsp = opaque; RAMBlock *block; @@ -2078,11 +2082,6 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host) int xh_flags; uint8_t *loaded_data; - if (!xbzrle_decoded_buf) { - xbzrle_decoded_buf = g_malloc(TARGET_PAGE_SIZE); - } - loaded_data = xbzrle_decoded_buf; - /* extract RLE header */ xh_flags = qemu_get_byte(f); xh_len = qemu_get_be16(f); @@ -2096,7 +2095,9 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host) error_report("Failed to load XBZRLE page - len overflow!"); return -1; } + loaded_data = XBZRLE.decoded_buf; /* load data and decode */ + /* it can change loaded_data to point to an internal buffer */ qemu_get_buffer_in_place(f, &loaded_data, xh_len); /* decode RLE */ @@ -2309,6 +2310,26 @@ static void decompress_data_with_multi_threads(QEMUFile *f, qemu_mutex_unlock(&decomp_done_lock); } +/** + * ram_load_setup: Setup RAM for migration incoming side + * + * Returns zero to indicate success and negative for error + * + * @f: QEMUFile where to receive the data + * @opaque: RAMState pointer + */ +static int ram_load_setup(QEMUFile *f, void *opaque) +{ + xbzrle_load_setup(); + return 0; +} + +static int ram_load_cleanup(void *opaque) +{ + xbzrle_load_cleanup(); + return 0; +} + /** * ram_postcopy_incoming_init: allocate postcopy data structures * @@ -2629,7 +2650,9 @@ static SaveVMHandlers savevm_ram_handlers = { .save_live_complete_precopy = ram_save_complete, .save_live_pending = ram_save_pending, .load_state = ram_load, - .save_cleanup = ram_migration_cleanup, + .save_cleanup = ram_save_cleanup, + .load_setup = ram_load_setup, + .load_cleanup = ram_load_cleanup, }; void ram_mig_init(void) -- cgit v1.2.1