};
typedef struct RAMState RAMState;
-static RAMState ram_state;
+static RAMState *ram_state;
uint64_t ram_bytes_remaining(void)
{
- return ram_state.migration_dirty_pages * TARGET_PAGE_SIZE;
+ return ram_state->migration_dirty_pages * TARGET_PAGE_SIZE;
}
MigrationStats ram_counters;
static int do_compress_ram_page(QEMUFile *f, RAMBlock *block,
ram_addr_t offset)
{
- RAMState *rs = &ram_state;
+ RAMState *rs = ram_state;
int bytes_sent, blen;
uint8_t *p = block->host + (offset & TARGET_PAGE_MASK);
int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len)
{
RAMBlock *ramblock;
- RAMState *rs = &ram_state;
+ RAMState *rs = ram_state;
ram_counters.postcopy_requests++;
rcu_read_lock();
static void ram_migration_cleanup(void *opaque)
{
- RAMState *rs = opaque;
+ RAMState **rsp = opaque;
RAMBlock *block;
/* caller have hold iothread lock or is in a bh, so there is
XBZRLE.zero_target_page = NULL;
}
XBZRLE_cache_unlock();
- migration_page_queue_free(rs);
+ migration_page_queue_free(*rsp);
+ g_free(*rsp);
+ *rsp = NULL;
}
static void ram_state_reset(RAMState *rs)
RAMBlock *block,
PostcopyDiscardState *pds)
{
- RAMState *rs = &ram_state;
+ RAMState *rs = ram_state;
unsigned long *bitmap = block->bmap;
unsigned long *unsentmap = block->unsentmap;
unsigned int host_ratio = block->page_size / TARGET_PAGE_SIZE;
*/
int ram_postcopy_send_discard_bitmap(MigrationState *ms)
{
- RAMState *rs = &ram_state;
+ RAMState *rs = ram_state;
RAMBlock *block;
int ret;
return ret;
}
-static int ram_state_init(RAMState *rs)
+static int ram_state_init(RAMState **rsp)
{
- memset(rs, 0, sizeof(*rs));
- qemu_mutex_init(&rs->bitmap_mutex);
- qemu_mutex_init(&rs->src_page_req_mutex);
- QSIMPLEQ_INIT(&rs->src_page_requests);
+ *rsp = g_new0(RAMState, 1);
+
+ qemu_mutex_init(&(*rsp)->bitmap_mutex);
+ qemu_mutex_init(&(*rsp)->src_page_req_mutex);
+ QSIMPLEQ_INIT(&(*rsp)->src_page_requests);
if (migrate_use_xbzrle()) {
XBZRLE_cache_lock();
if (!XBZRLE.cache) {
XBZRLE_cache_unlock();
error_report("Error creating cache");
+ g_free(*rsp);
+ *rsp = NULL;
return -1;
}
XBZRLE_cache_unlock();
XBZRLE.encoded_buf = g_try_malloc0(TARGET_PAGE_SIZE);
if (!XBZRLE.encoded_buf) {
error_report("Error allocating encoded_buf");
+ g_free(*rsp);
+ *rsp = NULL;
return -1;
}
error_report("Error allocating current_buf");
g_free(XBZRLE.encoded_buf);
XBZRLE.encoded_buf = NULL;
+ g_free(*rsp);
+ *rsp = NULL;
return -1;
}
}
qemu_mutex_lock_ramlist();
rcu_read_lock();
- ram_state_reset(rs);
+ ram_state_reset(*rsp);
/* Skip setting bitmap if there is no RAM */
if (ram_bytes_total()) {
* Count the total number of pages used by ram blocks not including any
* gaps due to alignment or unplugs.
*/
- rs->migration_dirty_pages = ram_bytes_total() >> TARGET_PAGE_BITS;
+ (*rsp)->migration_dirty_pages = ram_bytes_total() >> TARGET_PAGE_BITS;
memory_global_dirty_log_start();
- migration_bitmap_sync(rs);
+ migration_bitmap_sync(*rsp);
qemu_mutex_unlock_ramlist();
qemu_mutex_unlock_iothread();
rcu_read_unlock();
*/
static int ram_save_setup(QEMUFile *f, void *opaque)
{
- RAMState *rs = opaque;
+ RAMState **rsp = opaque;
RAMBlock *block;
/* migration has already setup the bitmap, reuse it. */
if (!migration_in_colo_state()) {
- if (ram_state_init(rs) < 0) {
+ if (ram_state_init(rsp) != 0) {
return -1;
- }
+ }
}
- rs->f = f;
+ (*rsp)->f = f;
rcu_read_lock();
*/
static int ram_save_iterate(QEMUFile *f, void *opaque)
{
- RAMState *rs = opaque;
+ RAMState **temp = opaque;
+ RAMState *rs = *temp;
int ret;
int i;
int64_t t0;
*/
static int ram_save_complete(QEMUFile *f, void *opaque)
{
- RAMState *rs = opaque;
+ RAMState **temp = opaque;
+ RAMState *rs = *temp;
rcu_read_lock();
uint64_t *non_postcopiable_pending,
uint64_t *postcopiable_pending)
{
- RAMState *rs = opaque;
+ RAMState **temp = opaque;
+ RAMState *rs = *temp;
uint64_t remaining_size;
remaining_size = rs->migration_dirty_pages * TARGET_PAGE_SIZE;