migration: Use savevm_handlers instead of loadvm copy

There is no reason for having the loadvm_handlers at all.  There is
only one use, and we can use the savevm handlers.

We will remove the loadvm handlers on a following patch.

Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

--

- Added load_version_id: version_id read from the stream (laurent)
- Added load_section_id: section_id read from the stream (dave)
This commit is contained in:
Juan Quintela 2017-05-24 09:09:58 +02:00
parent c077a998eb
commit 0f42f65781

View file

@ -272,7 +272,11 @@ typedef struct SaveStateEntry {
int instance_id; int instance_id;
int alias_id; int alias_id;
int version_id; int version_id;
/* version id read from the stream */
int load_version_id;
int section_id; int section_id;
/* section id read from the stream */
int load_section_id;
SaveVMHandlers *ops; SaveVMHandlers *ops;
const VMStateDescription *vmsd; const VMStateDescription *vmsd;
void *opaque; void *opaque;
@ -1813,7 +1817,7 @@ struct LoadStateEntry {
* Returns: true if the footer was good * Returns: true if the footer was good
* false if there is a problem (and calls error_report to say why) * false if there is a problem (and calls error_report to say why)
*/ */
static bool check_section_footer(QEMUFile *f, LoadStateEntry *le) static bool check_section_footer(QEMUFile *f, SaveStateEntry *se)
{ {
uint8_t read_mark; uint8_t read_mark;
uint32_t read_section_id; uint32_t read_section_id;
@ -1826,15 +1830,15 @@ static bool check_section_footer(QEMUFile *f, LoadStateEntry *le)
read_mark = qemu_get_byte(f); read_mark = qemu_get_byte(f);
if (read_mark != QEMU_VM_SECTION_FOOTER) { if (read_mark != QEMU_VM_SECTION_FOOTER) {
error_report("Missing section footer for %s", le->se->idstr); error_report("Missing section footer for %s", se->idstr);
return false; return false;
} }
read_section_id = qemu_get_be32(f); read_section_id = qemu_get_be32(f);
if (read_section_id != le->section_id) { if (read_section_id != se->load_section_id) {
error_report("Mismatched section id in footer for %s -" error_report("Mismatched section id in footer for %s -"
" read 0x%x expected 0x%x", " read 0x%x expected 0x%x",
le->se->idstr, read_section_id, le->section_id); se->idstr, read_section_id, se->load_section_id);
return false; return false;
} }
@ -1887,6 +1891,8 @@ qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis)
version_id, idstr, se->version_id); version_id, idstr, se->version_id);
return -EINVAL; return -EINVAL;
} }
se->load_version_id = version_id;
se->load_section_id = section_id;
/* Validate if it is a device's state */ /* Validate if it is a device's state */
if (xen_enabled() && se->is_ram) { if (xen_enabled() && se->is_ram) {
@ -1902,13 +1908,13 @@ qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis)
le->version_id = version_id; le->version_id = version_id;
QLIST_INSERT_HEAD(&mis->loadvm_handlers, le, entry); QLIST_INSERT_HEAD(&mis->loadvm_handlers, le, entry);
ret = vmstate_load(f, le->se, le->version_id); ret = vmstate_load(f, se, se->load_version_id);
if (ret < 0) { if (ret < 0) {
error_report("error while loading state for instance 0x%x of" error_report("error while loading state for instance 0x%x of"
" device '%s'", instance_id, idstr); " device '%s'", instance_id, idstr);
return ret; return ret;
} }
if (!check_section_footer(f, le)) { if (!check_section_footer(f, se)) {
return -EINVAL; return -EINVAL;
} }
@ -1919,29 +1925,29 @@ static int
qemu_loadvm_section_part_end(QEMUFile *f, MigrationIncomingState *mis) qemu_loadvm_section_part_end(QEMUFile *f, MigrationIncomingState *mis)
{ {
uint32_t section_id; uint32_t section_id;
LoadStateEntry *le; SaveStateEntry *se;
int ret; int ret;
section_id = qemu_get_be32(f); section_id = qemu_get_be32(f);
trace_qemu_loadvm_state_section_partend(section_id); trace_qemu_loadvm_state_section_partend(section_id);
QLIST_FOREACH(le, &mis->loadvm_handlers, entry) { QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
if (le->section_id == section_id) { if (se->load_section_id == section_id) {
break; break;
} }
} }
if (le == NULL) { if (se == NULL) {
error_report("Unknown savevm section %d", section_id); error_report("Unknown savevm section %d", section_id);
return -EINVAL; return -EINVAL;
} }
ret = vmstate_load(f, le->se, le->version_id); ret = vmstate_load(f, se, se->load_version_id);
if (ret < 0) { if (ret < 0) {
error_report("error while loading state section id %d(%s)", error_report("error while loading state section id %d(%s)",
section_id, le->se->idstr); section_id, se->idstr);
return ret; return ret;
} }
if (!check_section_footer(f, le)) { if (!check_section_footer(f, se)) {
return -EINVAL; return -EINVAL;
} }