diff options
Diffstat (limited to 'migration')
-rw-r--r-- | migration/Makefile.objs | 3 | ||||
-rw-r--r-- | migration/migration.c | 61 | ||||
-rw-r--r-- | migration/ram.c | 18 | ||||
-rw-r--r-- | migration/savevm.c | 41 | ||||
-rw-r--r-- | migration/socket.c | 11 | ||||
-rw-r--r-- | migration/tls.c | 19 | ||||
-rw-r--r-- | migration/trace-events | 12 | ||||
-rw-r--r-- | migration/vmstate.c | 203 |
8 files changed, 287 insertions, 81 deletions
diff --git a/migration/Makefile.objs b/migration/Makefile.objs index 3f3e237142..480dd493a9 100644 --- a/migration/Makefile.objs +++ b/migration/Makefile.objs @@ -1,7 +1,6 @@ common-obj-y += migration.o socket.o fd.o exec.o common-obj-y += tls.o -common-obj-y += colo-comm.o -common-obj-$(CONFIG_COLO) += colo.o colo-failover.o +common-obj-y += colo-comm.o colo.o colo-failover.o common-obj-y += vmstate.o common-obj-y += qemu-file.o common-obj-y += qemu-file-channel.o diff --git a/migration/migration.c b/migration/migration.c index f498ab84f2..2766d2f586 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1006,6 +1006,16 @@ static void migrate_fd_cancel(MigrationState *s) if (s->state == MIGRATION_STATUS_CANCELLING && f) { qemu_file_shutdown(f); } + if (s->state == MIGRATION_STATUS_CANCELLING && s->block_inactive) { + Error *local_err = NULL; + + bdrv_invalidate_cache_all(&local_err); + if (local_err) { + error_report_err(local_err); + } else { + s->block_inactive = false; + } + } } void add_migration_state_change_notifier(Notifier *notify) @@ -1044,6 +1054,31 @@ bool migration_in_postcopy_after_devices(MigrationState *s) return migration_in_postcopy(s) && s->postcopy_after_devices; } +bool migration_is_idle(MigrationState *s) +{ + if (!s) { + s = migrate_get_current(); + } + + switch (s->state) { + case MIGRATION_STATUS_NONE: + case MIGRATION_STATUS_CANCELLED: + case MIGRATION_STATUS_COMPLETED: + case MIGRATION_STATUS_FAILED: + return true; + case MIGRATION_STATUS_SETUP: + case MIGRATION_STATUS_CANCELLING: + case MIGRATION_STATUS_ACTIVE: + case MIGRATION_STATUS_POSTCOPY_ACTIVE: + case MIGRATION_STATUS_COLO: + return false; + case MIGRATION_STATUS__MAX: + g_assert_not_reached(); + } + + return false; +} + MigrationState *migrate_init(const MigrationParams *params) { MigrationState *s = migrate_get_current(); @@ -1086,9 +1121,24 @@ MigrationState *migrate_init(const MigrationParams *params) static GSList *migration_blockers; -void migrate_add_blocker(Error *reason) +int migrate_add_blocker(Error *reason, Error **errp) { - migration_blockers = g_slist_prepend(migration_blockers, reason); + if (only_migratable) { + error_propagate(errp, error_copy(reason)); + error_prepend(errp, "disallowing migration blocker " + "(--only_migratable) for: "); + return -EACCES; + } + + if (migration_is_idle(NULL)) { + migration_blockers = g_slist_prepend(migration_blockers, reason); + return 0; + } + + error_propagate(errp, error_copy(reason)); + error_prepend(errp, "disallowing migration blocker (migration in " + "progress) for: "); + return -EBUSY; } void migrate_del_blocker(Error *reason) @@ -1705,6 +1755,7 @@ static void migration_completion(MigrationState *s, int current_active_state, if (ret >= 0) { qemu_file_set_rate_limit(s->to_dst_file, INT64_MAX); qemu_savevm_state_complete_precopy(s->to_dst_file, false); + s->block_inactive = true; } } qemu_mutex_unlock_iothread(); @@ -1755,10 +1806,14 @@ fail_invalidate: if (s->state == MIGRATION_STATUS_ACTIVE) { Error *local_err = NULL; + qemu_mutex_lock_iothread(); bdrv_invalidate_cache_all(&local_err); if (local_err) { error_report_err(local_err); + } else { + s->block_inactive = false; } + qemu_mutex_unlock_iothread(); } fail: @@ -1969,7 +2024,7 @@ void migrate_fd_connect(MigrationState *s) } migrate_compress_threads_create(); - qemu_thread_create(&s->thread, "migration", migration_thread, s, + qemu_thread_create(&s->thread, "live_migration", migration_thread, s, QEMU_THREAD_JOINABLE); s->migration_thread_running = true; } diff --git a/migration/ram.c b/migration/ram.c index a1c8089010..ef8fadfe69 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -45,14 +45,6 @@ #include "qemu/rcu_queue.h" #include "migration/colo.h" -#ifdef DEBUG_MIGRATION_RAM -#define DPRINTF(fmt, ...) \ - do { fprintf(stdout, "migration_ram: " fmt, ## __VA_ARGS__); } while (0) -#else -#define DPRINTF(fmt, ...) \ - do { } while (0) -#endif - static int dirty_rate_high_cnt; static uint64_t bitmap_sync_count; @@ -507,10 +499,10 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t **current_data, TARGET_PAGE_SIZE, XBZRLE.encoded_buf, TARGET_PAGE_SIZE); if (encoded_len == 0) { - DPRINTF("Skipping unmodified page\n"); + trace_save_xbzrle_page_skipping(); return 0; } else if (encoded_len == -1) { - DPRINTF("Overflow\n"); + trace_save_xbzrle_page_overflow(); acct_info.xbzrle_overflows++; /* update data in the cache */ if (!last_stage) { @@ -2020,8 +2012,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) if ((i & 63) == 0) { uint64_t t1 = (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - t0) / 1000000; if (t1 > MAX_WAIT) { - DPRINTF("big wait: %" PRIu64 " milliseconds, %d iterations\n", - t1, i); + trace_ram_save_iterate_big_wait(t1, i); break; } } @@ -2594,8 +2585,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) wait_for_decompress_done(); rcu_read_unlock(); - DPRINTF("Completed load of VM with exit code %d seq iteration " - "%" PRIu64 "\n", ret, seq_iter); + trace_ram_load_complete(ret, seq_iter); return ret; } diff --git a/migration/savevm.c b/migration/savevm.c index 0363372acc..455d5bac1e 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -220,17 +220,20 @@ void timer_get(QEMUFile *f, QEMUTimer *ts) * Not in vmstate.c to not add qemu-timer.c as dependency to vmstate.c */ -static int get_timer(QEMUFile *f, void *pv, size_t size) +static int get_timer(QEMUFile *f, void *pv, size_t size, VMStateField *field) { QEMUTimer *v = pv; timer_get(f, v); return 0; } -static void put_timer(QEMUFile *f, void *pv, size_t size) +static int put_timer(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) { QEMUTimer *v = pv; timer_put(f, v); + + return 0; } const VMStateInfo vmstate_info_timer = { @@ -532,6 +535,34 @@ static int calculate_compat_instance_id(const char *idstr) return instance_id; } +static inline MigrationPriority save_state_priority(SaveStateEntry *se) +{ + if (se->vmsd) { + return se->vmsd->priority; + } + return MIG_PRI_DEFAULT; +} + +static void savevm_state_handler_insert(SaveStateEntry *nse) +{ + MigrationPriority priority = save_state_priority(nse); + SaveStateEntry *se; + + assert(priority <= MIG_PRI_MAX); + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + if (save_state_priority(se) < priority) { + break; + } + } + + if (se) { + QTAILQ_INSERT_BEFORE(se, nse, entry); + } else { + QTAILQ_INSERT_TAIL(&savevm_state.handlers, nse, entry); + } +} + /* TODO: Individual devices generally have very little idea about the rest of the system, so instance_id should be removed/replaced. Meanwhile pass -1 as instance_id if you do not already have a clearly @@ -578,8 +609,7 @@ int register_savevm_live(DeviceState *dev, se->instance_id = instance_id; } assert(!se->compat || se->instance_id == 0); - /* add at the end of list */ - QTAILQ_INSERT_TAIL(&savevm_state.handlers, se, entry); + savevm_state_handler_insert(se); return 0; } @@ -662,8 +692,7 @@ int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, se->instance_id = instance_id; } assert(!se->compat || se->instance_id == 0); - /* add at the end of list */ - QTAILQ_INSERT_TAIL(&savevm_state.handlers, se, entry); + savevm_state_handler_insert(se); return 0; } diff --git a/migration/socket.c b/migration/socket.c index 11f80b119b..13966f1d26 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -70,22 +70,23 @@ static void socket_connect_data_free(void *opaque) g_free(data); } -static void socket_outgoing_migration(Object *src, - Error *err, +static void socket_outgoing_migration(QIOTask *task, gpointer opaque) { struct SocketConnectData *data = opaque; - QIOChannel *sioc = QIO_CHANNEL(src); + QIOChannel *sioc = QIO_CHANNEL(qio_task_get_source(task)); + Error *err = NULL; - if (err) { + if (qio_task_propagate_error(task, &err)) { trace_migration_socket_outgoing_error(error_get_pretty(err)); data->s->to_dst_file = NULL; migrate_fd_error(data->s, err); + error_free(err); } else { trace_migration_socket_outgoing_connected(data->hostname); migration_channel_connect(data->s, sioc, data->hostname); } - object_unref(src); + object_unref(OBJECT(sioc)); } static void socket_start_outgoing_migration(MigrationState *s, diff --git a/migration/tls.c b/migration/tls.c index 49ca9a8930..203c11d025 100644 --- a/migration/tls.c +++ b/migration/tls.c @@ -61,15 +61,15 @@ migration_tls_get_creds(MigrationState *s, } -static void migration_tls_incoming_handshake(Object *src, - Error *err, +static void migration_tls_incoming_handshake(QIOTask *task, gpointer opaque) { - QIOChannel *ioc = QIO_CHANNEL(src); + QIOChannel *ioc = QIO_CHANNEL(qio_task_get_source(task)); + Error *err = NULL; - if (err) { + if (qio_task_propagate_error(task, &err)) { trace_migration_tls_incoming_handshake_error(error_get_pretty(err)); - error_report("%s", error_get_pretty(err)); + error_report_err(err); } else { trace_migration_tls_incoming_handshake_complete(); migration_channel_process_incoming(migrate_get_current(), ioc); @@ -107,17 +107,18 @@ void migration_tls_channel_process_incoming(MigrationState *s, } -static void migration_tls_outgoing_handshake(Object *src, - Error *err, +static void migration_tls_outgoing_handshake(QIOTask *task, gpointer opaque) { MigrationState *s = opaque; - QIOChannel *ioc = QIO_CHANNEL(src); + QIOChannel *ioc = QIO_CHANNEL(qio_task_get_source(task)); + Error *err = NULL; - if (err) { + if (qio_task_propagate_error(task, &err)) { trace_migration_tls_outgoing_handshake_error(error_get_pretty(err)); s->to_dst_file = NULL; migrate_fd_error(s, err); + error_free(err); } else { trace_migration_tls_outgoing_handshake_complete(); migration_channel_connect(s, ioc, NULL); diff --git a/migration/trace-events b/migration/trace-events index 94134f700b..48e531d3b8 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -40,6 +40,10 @@ savevm_state_iterate(void) "" savevm_state_cleanup(void) "" savevm_state_complete_precopy(void) "" vmstate_save(const char *idstr, const char *vmsd_name) "%s, %s" +vmstate_save_state_loop(const char *name, const char *field, int n_elems) "%s/%s[%d]" +vmstate_save_state_top(const char *idstr) "%s" +vmstate_subsection_save_loop(const char *name, const char *sub) "%s/%s" +vmstate_subsection_save_top(const char *idstr) "%s" vmstate_load(const char *idstr, const char *vmsd_name) "%s, %s" qemu_announce_self_iter(const char *mac) "%s" @@ -52,6 +56,10 @@ vmstate_n_elems(const char *name, int n_elems) "%s: %d" vmstate_subsection_load(const char *parent) "%s" vmstate_subsection_load_bad(const char *parent, const char *sub, const char *sub2) "%s: %s/%s" vmstate_subsection_load_good(const char *parent) "%s" +get_qtailq(const char *name, int version_id) "%s v%d" +get_qtailq_end(const char *name, const char *reason, int val) "%s %s/%d" +put_qtailq(const char *name, int version_id) "%s v%d" +put_qtailq_end(const char *name, const char *reason) "%s %s" # migration/qemu-file.c qemu_file_fclose(void) "" @@ -186,6 +194,10 @@ postcopy_ram_incoming_cleanup_closeuf(void) "" postcopy_ram_incoming_cleanup_entry(void) "" postcopy_ram_incoming_cleanup_exit(void) "" postcopy_ram_incoming_cleanup_join(void) "" +save_xbzrle_page_skipping(void) "" +save_xbzrle_page_overflow(void) "" +ram_save_iterate_big_wait(uint64_t milliconds, int iterations) "big wait: %" PRIu64 " milliseconds, %d iterations" +ram_load_complete(int ret, uint64_t seq_iter) "exit_code %d seq iteration %" PRIu64 # migration/exec.c migration_exec_outgoing(const char *cmd) "cmd=%s" diff --git a/migration/vmstate.c b/migration/vmstate.c index 0bc9f35ef8..2b2b3a58e6 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -5,7 +5,9 @@ #include "migration/vmstate.h" #include "qemu/bitops.h" #include "qemu/error-report.h" +#include "qemu/queue.h" #include "trace.h" +#include "migration/qjson.h" static void vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd, void *opaque, QJSON *vmdesc); @@ -83,6 +85,9 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, trace_vmstate_load_state(vmsd->name, version_id); if (version_id > vmsd->version_id) { + error_report("%s: incoming version_id %d is too new " + "for local version_id %d", + vmsd->name, version_id, vmsd->version_id); trace_vmstate_load_state_end(vmsd->name, "too new", -EINVAL); return -EINVAL; } @@ -93,6 +98,9 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, trace_vmstate_load_state_end(vmsd->name, "old path", ret); return ret; } + error_report("%s: incoming version_id %d is too old " + "for local minimum version_id %d", + vmsd->name, version_id, vmsd->minimum_version_id); trace_vmstate_load_state_end(vmsd->name, "too old", -EINVAL); return -EINVAL; } @@ -122,8 +130,7 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, ret = vmstate_load_state(f, field->vmsd, addr, field->vmsd->version_id); } else { - ret = field->info->get(f, addr, size); - + ret = field->info->get(f, addr, size, field); } if (ret >= 0) { ret = qemu_file_get_error(f); @@ -299,6 +306,8 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, { VMStateField *field = vmsd->fields; + trace_vmstate_save_state_top(vmsd->name); + if (vmsd->pre_save) { vmsd->pre_save(opaque); } @@ -318,6 +327,7 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, int64_t old_offset, written_bytes; QJSON *vmdesc_loop = vmdesc; + trace_vmstate_save_state_loop(vmsd->name, field->name, n_elems); for (i = 0; i < n_elems; i++) { void *addr = base_addr + size * i; @@ -330,7 +340,7 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, if (field->flags & VMS_STRUCT) { vmstate_save_state(f, field->vmsd, addr, vmdesc_loop); } else { - field->info->put(f, addr, size); + field->info->put(f, addr, size, field, vmdesc_loop); } written_bytes = qemu_ftell_fast(f) - old_offset; @@ -427,11 +437,13 @@ static void vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd, const VMStateDescription **sub = vmsd->subsections; bool subsection_found = false; + trace_vmstate_subsection_save_top(vmsd->name); while (sub && *sub && (*sub)->needed) { if ((*sub)->needed(opaque)) { - const VMStateDescription *vmsd = *sub; + const VMStateDescription *vmsdsub = *sub; uint8_t len; + trace_vmstate_subsection_save_loop(vmsd->name, vmsdsub->name); if (vmdesc) { /* Only create subsection array when we have any */ if (!subsection_found) { @@ -443,11 +455,11 @@ static void vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd, } qemu_put_byte(f, QEMU_VM_SUBSECTION); - len = strlen(vmsd->name); + len = strlen(vmsdsub->name); qemu_put_byte(f, len); - qemu_put_buffer(f, (uint8_t *)vmsd->name, len); - qemu_put_be32(f, vmsd->version_id); - vmstate_save_state(f, vmsd, opaque, vmdesc); + qemu_put_buffer(f, (uint8_t *)vmsdsub->name, len); + qemu_put_be32(f, vmsdsub->version_id); + vmstate_save_state(f, vmsdsub, opaque, vmdesc); if (vmdesc) { json_end_object(vmdesc); @@ -463,17 +475,19 @@ static void vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd, /* bool */ -static int get_bool(QEMUFile *f, void *pv, size_t size) +static int get_bool(QEMUFile *f, void *pv, size_t size, VMStateField *field) { bool *v = pv; *v = qemu_get_byte(f); return 0; } -static void put_bool(QEMUFile *f, void *pv, size_t size) +static int put_bool(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) { bool *v = pv; qemu_put_byte(f, *v); + return 0; } const VMStateInfo vmstate_info_bool = { @@ -484,17 +498,19 @@ const VMStateInfo vmstate_info_bool = { /* 8 bit int */ -static int get_int8(QEMUFile *f, void *pv, size_t size) +static int get_int8(QEMUFile *f, void *pv, size_t size, VMStateField *field) { int8_t *v = pv; qemu_get_s8s(f, v); return 0; } -static void put_int8(QEMUFile *f, void *pv, size_t size) +static int put_int8(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) { int8_t *v = pv; qemu_put_s8s(f, v); + return 0; } const VMStateInfo vmstate_info_int8 = { @@ -505,17 +521,19 @@ const VMStateInfo vmstate_info_int8 = { /* 16 bit int */ -static int get_int16(QEMUFile *f, void *pv, size_t size) +static int get_int16(QEMUFile *f, void *pv, size_t size, VMStateField *field) { int16_t *v = pv; qemu_get_sbe16s(f, v); return 0; } -static void put_int16(QEMUFile *f, void *pv, size_t size) +static int put_int16(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) { int16_t *v = pv; qemu_put_sbe16s(f, v); + return 0; } const VMStateInfo vmstate_info_int16 = { @@ -526,17 +544,19 @@ const VMStateInfo vmstate_info_int16 = { /* 32 bit int */ -static int get_int32(QEMUFile *f, void *pv, size_t size) +static int get_int32(QEMUFile *f, void *pv, size_t size, VMStateField *field) { int32_t *v = pv; qemu_get_sbe32s(f, v); return 0; } -static void put_int32(QEMUFile *f, void *pv, size_t size) +static int put_int32(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) { int32_t *v = pv; qemu_put_sbe32s(f, v); + return 0; } const VMStateInfo vmstate_info_int32 = { @@ -548,7 +568,8 @@ const VMStateInfo vmstate_info_int32 = { /* 32 bit int. See that the received value is the same than the one in the field */ -static int get_int32_equal(QEMUFile *f, void *pv, size_t size) +static int get_int32_equal(QEMUFile *f, void *pv, size_t size, + VMStateField *field) { int32_t *v = pv; int32_t v2; @@ -571,7 +592,7 @@ const VMStateInfo vmstate_info_int32_equal = { * and less than or equal to the one in the field. */ -static int get_int32_le(QEMUFile *f, void *pv, size_t size) +static int get_int32_le(QEMUFile *f, void *pv, size_t size, VMStateField *field) { int32_t *cur = pv; int32_t loaded; @@ -595,17 +616,19 @@ const VMStateInfo vmstate_info_int32_le = { /* 64 bit int */ -static int get_int64(QEMUFile *f, void *pv, size_t size) +static int get_int64(QEMUFile *f, void *pv, size_t size, VMStateField *field) { int64_t *v = pv; qemu_get_sbe64s(f, v); return 0; } -static void put_int64(QEMUFile *f, void *pv, size_t size) +static int put_int64(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) { int64_t *v = pv; qemu_put_sbe64s(f, v); + return 0; } const VMStateInfo vmstate_info_int64 = { @@ -616,17 +639,19 @@ const VMStateInfo vmstate_info_int64 = { /* 8 bit unsigned int */ -static int get_uint8(QEMUFile *f, void *pv, size_t size) +static int get_uint8(QEMUFile *f, void *pv, size_t size, VMStateField *field) { uint8_t *v = pv; qemu_get_8s(f, v); return 0; } -static void put_uint8(QEMUFile *f, void *pv, size_t size) +static int put_uint8(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) { uint8_t *v = pv; qemu_put_8s(f, v); + return 0; } const VMStateInfo vmstate_info_uint8 = { @@ -637,17 +662,19 @@ const VMStateInfo vmstate_info_uint8 = { /* 16 bit unsigned int */ -static int get_uint16(QEMUFile *f, void *pv, size_t size) +static int get_uint16(QEMUFile *f, void *pv, size_t size, VMStateField *field) { uint16_t *v = pv; qemu_get_be16s(f, v); return 0; } -static void put_uint16(QEMUFile *f, void *pv, size_t size) +static int put_uint16(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) { uint16_t *v = pv; qemu_put_be16s(f, v); + return 0; } const VMStateInfo vmstate_info_uint16 = { @@ -658,17 +685,19 @@ const VMStateInfo vmstate_info_uint16 = { /* 32 bit unsigned int */ -static int get_uint32(QEMUFile *f, void *pv, size_t size) +static int get_uint32(QEMUFile *f, void *pv, size_t size, VMStateField *field) { uint32_t *v = pv; qemu_get_be32s(f, v); return 0; } -static void put_uint32(QEMUFile *f, void *pv, size_t size) +static int put_uint32(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) { uint32_t *v = pv; qemu_put_be32s(f, v); + return 0; } const VMStateInfo vmstate_info_uint32 = { @@ -680,7 +709,8 @@ const VMStateInfo vmstate_info_uint32 = { /* 32 bit uint. See that the received value is the same than the one in the field */ -static int get_uint32_equal(QEMUFile *f, void *pv, size_t size) +static int get_uint32_equal(QEMUFile *f, void *pv, size_t size, + VMStateField *field) { uint32_t *v = pv; uint32_t v2; @@ -701,17 +731,19 @@ const VMStateInfo vmstate_info_uint32_equal = { /* 64 bit unsigned int */ -static int get_uint64(QEMUFile *f, void *pv, size_t size) +static int get_uint64(QEMUFile *f, void *pv, size_t size, VMStateField *field) { uint64_t *v = pv; qemu_get_be64s(f, v); return 0; } -static void put_uint64(QEMUFile *f, void *pv, size_t size) +static int put_uint64(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) { uint64_t *v = pv; qemu_put_be64s(f, v); + return 0; } const VMStateInfo vmstate_info_uint64 = { @@ -723,7 +755,8 @@ const VMStateInfo vmstate_info_uint64 = { /* 64 bit unsigned int. See that the received value is the same than the one in the field */ -static int get_uint64_equal(QEMUFile *f, void *pv, size_t size) +static int get_uint64_equal(QEMUFile *f, void *pv, size_t size, + VMStateField *field) { uint64_t *v = pv; uint64_t v2; @@ -745,7 +778,8 @@ const VMStateInfo vmstate_info_uint64_equal = { /* 8 bit int. See that the received value is the same than the one in the field */ -static int get_uint8_equal(QEMUFile *f, void *pv, size_t size) +static int get_uint8_equal(QEMUFile *f, void *pv, size_t size, + VMStateField *field) { uint8_t *v = pv; uint8_t v2; @@ -767,7 +801,8 @@ const VMStateInfo vmstate_info_uint8_equal = { /* 16 bit unsigned int int. See that the received value is the same than the one in the field */ -static int get_uint16_equal(QEMUFile *f, void *pv, size_t size) +static int get_uint16_equal(QEMUFile *f, void *pv, size_t size, + VMStateField *field) { uint16_t *v = pv; uint16_t v2; @@ -788,7 +823,8 @@ const VMStateInfo vmstate_info_uint16_equal = { /* floating point */ -static int get_float64(QEMUFile *f, void *pv, size_t size) +static int get_float64(QEMUFile *f, void *pv, size_t size, + VMStateField *field) { float64 *v = pv; @@ -796,11 +832,13 @@ static int get_float64(QEMUFile *f, void *pv, size_t size) return 0; } -static void put_float64(QEMUFile *f, void *pv, size_t size) +static int put_float64(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) { uint64_t *v = pv; qemu_put_be64(f, float64_val(*v)); + return 0; } const VMStateInfo vmstate_info_float64 = { @@ -811,7 +849,8 @@ const VMStateInfo vmstate_info_float64 = { /* CPU_DoubleU type */ -static int get_cpudouble(QEMUFile *f, void *pv, size_t size) +static int get_cpudouble(QEMUFile *f, void *pv, size_t size, + VMStateField *field) { CPU_DoubleU *v = pv; qemu_get_be32s(f, &v->l.upper); @@ -819,11 +858,13 @@ static int get_cpudouble(QEMUFile *f, void *pv, size_t size) return 0; } -static void put_cpudouble(QEMUFile *f, void *pv, size_t size) +static int put_cpudouble(QEMUFile *f, void *pv, size_t size, + VMStateField *field, QJSON *vmdesc) { CPU_DoubleU *v = pv; qemu_put_be32s(f, &v->l.upper); qemu_put_be32s(f, &v->l.lower); + return 0; } const VMStateInfo vmstate_info_cpudouble = { @@ -834,17 +875,20 @@ const VMStateInfo vmstate_info_cpudouble = { /* uint8_t buffers */ -static int get_buffer(QEMUFile *f, void *pv, size_t size) +static int get_buffer(QEMUFile *f, void *pv, size_t size, + VMStateField *field) { uint8_t *v = pv; qemu_get_buffer(f, v, size); return 0; } -static void put_buffer(QEMUFile *f, void *pv, size_t size) +static int put_buffer(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) { uint8_t *v = pv; qemu_put_buffer(f, v, size); + return 0; } const VMStateInfo vmstate_info_buffer = { @@ -856,7 +900,8 @@ const VMStateInfo vmstate_info_buffer = { /* unused buffers: space that was used for some fields that are not useful anymore */ -static int get_unused_buffer(QEMUFile *f, void *pv, size_t size) +static int get_unused_buffer(QEMUFile *f, void *pv, size_t size, + VMStateField *field) { uint8_t buf[1024]; int block_len; @@ -869,7 +914,8 @@ static int get_unused_buffer(QEMUFile *f, void *pv, size_t size) return 0; } -static void put_unused_buffer(QEMUFile *f, void *pv, size_t size) +static int put_unused_buffer(QEMUFile *f, void *pv, size_t size, + VMStateField *field, QJSON *vmdesc) { static const uint8_t buf[1024]; int block_len; @@ -879,6 +925,8 @@ static void put_unused_buffer(QEMUFile *f, void *pv, size_t size) size -= block_len; qemu_put_buffer(f, buf, block_len); } + + return 0; } const VMStateInfo vmstate_info_unused_buffer = { @@ -894,7 +942,7 @@ const VMStateInfo vmstate_info_unused_buffer = { */ /* This is the number of 64 bit words sent over the wire */ #define BITS_TO_U64S(nr) DIV_ROUND_UP(nr, 64) -static int get_bitmap(QEMUFile *f, void *pv, size_t size) +static int get_bitmap(QEMUFile *f, void *pv, size_t size, VMStateField *field) { unsigned long *bmp = pv; int i, idx = 0; @@ -908,7 +956,8 @@ static int get_bitmap(QEMUFile *f, void *pv, size_t size) return 0; } -static void put_bitmap(QEMUFile *f, void *pv, size_t size) +static int put_bitmap(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) { unsigned long *bmp = pv; int i, idx = 0; @@ -919,6 +968,8 @@ static void put_bitmap(QEMUFile *f, void *pv, size_t size) } qemu_put_be64(f, w); } + + return 0; } const VMStateInfo vmstate_info_bitmap = { @@ -926,3 +977,71 @@ const VMStateInfo vmstate_info_bitmap = { .get = get_bitmap, .put = put_bitmap, }; + +/* get for QTAILQ + * meta data about the QTAILQ is encoded in a VMStateField structure + */ +static int get_qtailq(QEMUFile *f, void *pv, size_t unused_size, + VMStateField *field) +{ + int ret = 0; + const VMStateDescription *vmsd = field->vmsd; + /* size of a QTAILQ element */ + size_t size = field->size; + /* offset of the QTAILQ entry in a QTAILQ element */ + size_t entry_offset = field->start; + int version_id = field->version_id; + void *elm; + + trace_get_qtailq(vmsd->name, version_id); + if (version_id > vmsd->version_id) { + error_report("%s %s", vmsd->name, "too new"); + trace_get_qtailq_end(vmsd->name, "too new", -EINVAL); + + return -EINVAL; + } + if (version_id < vmsd->minimum_version_id) { + error_report("%s %s", vmsd->name, "too old"); + trace_get_qtailq_end(vmsd->name, "too old", -EINVAL); + return -EINVAL; + } + + while (qemu_get_byte(f)) { + elm = g_malloc(size); + ret = vmstate_load_state(f, vmsd, elm, version_id); + if (ret) { + return ret; + } + QTAILQ_RAW_INSERT_TAIL(pv, elm, entry_offset); + } + + trace_get_qtailq_end(vmsd->name, "end", ret); + return ret; +} + +/* put for QTAILQ */ +static int put_qtailq(QEMUFile *f, void *pv, size_t unused_size, + VMStateField *field, QJSON *vmdesc) +{ + const VMStateDescription *vmsd = field->vmsd; + /* offset of the QTAILQ entry in a QTAILQ element*/ + size_t entry_offset = field->start; + void *elm; + + trace_put_qtailq(vmsd->name, vmsd->version_id); + + QTAILQ_RAW_FOREACH(elm, pv, entry_offset) { + qemu_put_byte(f, true); + vmstate_save_state(f, vmsd, elm, vmdesc); + } + qemu_put_byte(f, false); + + trace_put_qtailq_end(vmsd->name, "end"); + + return 0; +} +const VMStateInfo vmstate_info_qtailq = { + .name = "qtailq", + .get = get_qtailq, + .put = put_qtailq, +}; |