Skip to content

Commit

Permalink
migration/savevm: wrap into qemu_loadvm_state_header()
Browse files Browse the repository at this point in the history
On source side, we have qemu_savevm_state_header() to send related data,
while on the receiving side those steps are scattered in
qemu_loadvm_state().

This patch wrap those related steps into qemu_loadvm_state_header() to
make it friendly to read.

Signed-off-by: Wei Yang <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Daniel Henrique Barboza <[email protected]>
Signed-off-by: Dr. David Alan Gilbert <[email protected]>
  • Loading branch information
Wei Yang authored and dagrh committed May 14, 2019
1 parent 9e14b84 commit 16015d3
Showing 1 changed file with 40 additions and 29 deletions.
69 changes: 40 additions & 29 deletions migration/savevm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2262,6 +2262,43 @@ qemu_loadvm_section_part_end(QEMUFile *f, MigrationIncomingState *mis)
return 0;
}

static int qemu_loadvm_state_header(QEMUFile *f)
{
unsigned int v;
int ret;

v = qemu_get_be32(f);
if (v != QEMU_VM_FILE_MAGIC) {
error_report("Not a migration stream");
return -EINVAL;
}

v = qemu_get_be32(f);
if (v == QEMU_VM_FILE_VERSION_COMPAT) {
error_report("SaveVM v2 format is obsolete and don't work anymore");
return -ENOTSUP;
}
if (v != QEMU_VM_FILE_VERSION) {
error_report("Unsupported migration stream version");
return -ENOTSUP;
}

if (migrate_get_current()->send_configuration) {
if (qemu_get_byte(f) != QEMU_VM_CONFIGURATION) {
error_report("Configuration section missing");
qemu_loadvm_state_cleanup();
return -EINVAL;
}
ret = vmstate_load_state(f, &vmstate_configuration, &savevm_state, 0);

if (ret) {
qemu_loadvm_state_cleanup();
return ret;
}
}
return 0;
}

static int qemu_loadvm_state_setup(QEMUFile *f)
{
SaveStateEntry *se;
Expand Down Expand Up @@ -2410,42 +2447,16 @@ int qemu_loadvm_state(QEMUFile *f)
{
MigrationIncomingState *mis = migration_incoming_get_current();
Error *local_err = NULL;
unsigned int v;
int ret;

if (qemu_savevm_state_blocked(&local_err)) {
error_report_err(local_err);
return -EINVAL;
}

v = qemu_get_be32(f);
if (v != QEMU_VM_FILE_MAGIC) {
error_report("Not a migration stream");
return -EINVAL;
}

v = qemu_get_be32(f);
if (v == QEMU_VM_FILE_VERSION_COMPAT) {
error_report("SaveVM v2 format is obsolete and don't work anymore");
return -ENOTSUP;
}
if (v != QEMU_VM_FILE_VERSION) {
error_report("Unsupported migration stream version");
return -ENOTSUP;
}

if (migrate_get_current()->send_configuration) {
if (qemu_get_byte(f) != QEMU_VM_CONFIGURATION) {
error_report("Configuration section missing");
qemu_loadvm_state_cleanup();
return -EINVAL;
}
ret = vmstate_load_state(f, &vmstate_configuration, &savevm_state, 0);

if (ret) {
qemu_loadvm_state_cleanup();
return ret;
}
ret = qemu_loadvm_state_header(f);
if (ret) {
return ret;
}

if (qemu_loadvm_state_setup(f) != 0) {
Expand Down

0 comments on commit 16015d3

Please sign in to comment.