Skip to contentSkip to conversation

cleanup savevm

PATCH In review Wei Yang 4 participants 18 messages Apr 24, 2019 – May 15, 2019

lore
Share & tools
lore

Wei Yang

author
#0 lore raw

cover cleanup savevm

There are several trivial cleanup for savevm.

* remove duplicate check
* more restrict check
* reorder load sequence
* wrap several steps into qemu_loadvm_state_header

Wei Yang (4):
migration/savevm: remove duplicate check of migration_is_blocked migration/savevm: use migration_is_blocked to validate migration/savevm: load_header before load_setup migration/savevm: wrap into qemu_loadvm_state_header()

 migration/savevm.c | 75 +++++++++++++++++++++++++---------------------
 1 file changed, 41 insertions(+), 34 deletions(-)
Signature · 1 line
2.19.1
author
#1 lore raw

PATCH 1/4 migration/savevm: remove duplicate check of migration_is_blocked

Current call flow of save_snapshot is:

save_snapshot
migration_is_blocked
qemu_savevm_state
migration_is_blocked

Since qemu_savevm_state is only called in save_snapshot, this means migration_is_blocked has been already checked.

---
 migration/savevm.c | 4 ----
 1 file changed, 4 deletions(-)
migration/savevm.c +0 -4
index 92af2471cd..2eea604624 100644
@@ -1412,10 +1412,6 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
         return -EINVAL;
     }
 
-    if (migration_is_blocked(errp)) {
-        return -EINVAL;
-    }
-
     if (migrate_use_block()) {
         error_setg(errp, "Block migration and snapshots are incompatible");
         return -EINVAL;
Signature · 1 line
2.19.1
Reviewed-by on v1 1/4
#2 lore raw

Re: [Qemu-devel] [PATCH 1/4] migration/savevm: remove duplicate check of migration_is_blocked

Quoted 9 lines · Wei Yang

Current call flow of save_snapshot is:

save_snapshot
migration_is_blocked
qemu_savevm_state
migration_is_blocked

Since qemu_savevm_state is only called in save_snapshot, this means migration_is_blocked has been already checked.

I think it would be a nice touch to add a comment in qemu_savevm_state, saying that the function must be called with migration_is_blocked() context. Just in case someone else in the future ends up re-using the function.

Other than that, +1 for less code duplication.

Quoted 21 lines
---
  migration/savevm.c | 4 ----
  1 file changed, 4 deletions(-)
migration/savevm.c +0 -4
index 92af2471cd..2eea604624 100644
@@ -1412,10 +1412,6 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
          return -EINVAL;
      }
 
-    if (migration_is_blocked(errp)) {
-        return -EINVAL;
-    }
-
      if (migrate_use_block()) {
          error_setg(errp, "Block migration and snapshots are incompatible");
          return -EINVAL;
author
#3 lore raw

Re: [Qemu-devel] [PATCH 1/4] migration/savevm: remove duplicate check of migration_is_blocked

Quoted 10 lines · Daniel Henrique Barboza
Quoted 7 lines · Wei Yang

Current call flow of save_snapshot is:

save_snapshot
migration_is_blocked
qemu_savevm_state
migration_is_blocked

Quoted 8 lines
Quoted 2 lines

Since qemu_savevm_state is only called in save_snapshot, this means migration_is_blocked has been already checked.

I think it would be a nice touch to add a comment in qemu_savevm_state, saying that the function must be called with migration_is_blocked() context. Just in case someone else in the future ends up re-using the function.

That's reasonable, let me add a comment for qemu_savevm_state().

Quoted 29 lines

Other than that, +1 for less code duplication.

Quoted 20 lines
---
  migration/savevm.c | 4 ----
  1 file changed, 4 deletions(-)
migration/savevm.c +0 -4
index 92af2471cd..2eea604624 100644
@@ -1412,10 +1412,6 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
          return -EINVAL;
      }
-    if (migration_is_blocked(errp)) {
-        return -EINVAL;
-    }
-
      if (migrate_use_block()) {
          error_setg(errp, "Block migration and snapshots are incompatible");
          return -EINVAL;
Signature · 2 lines
Wei Yang
Help you, Help me
Reviewed-by on v1 1/4
#4 lore raw

Re: [Qemu-devel] [PATCH 1/4] migration/savevm: remove duplicate check of migration_is_blocked

In reply to Wei Yang
Quoted 11 lines · * Wei Yang ([email protected]) wrote:

Current call flow of save_snapshot is:

save_snapshot
migration_is_blocked
qemu_savevm_state
migration_is_blocked

Since qemu_savevm_state is only called in save_snapshot, this means migration_is_blocked has been already checked.

Quoted 22 lines
---
 migration/savevm.c | 4 ----
 1 file changed, 4 deletions(-)
migration/savevm.c +0 -4
index 92af2471cd..2eea604624 100644
@@ -1412,10 +1412,6 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
         return -EINVAL;
     }
 
-    if (migration_is_blocked(errp)) {
-        return -EINVAL;
-    }
-
     if (migrate_use_block()) {
         error_setg(errp, "Block migration and snapshots are incompatible");
         return -EINVAL;
Signature · 1 line
2.19.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#5 lore raw

Re: [Qemu-devel] [PATCH 1/4] migration/savevm: remove duplicate check of migration_is_blocked

In reply to Wei Yang
Quoted 11 lines · * Wei Yang ([email protected]) wrote:

Current call flow of save_snapshot is:

save_snapshot
migration_is_blocked
qemu_savevm_state
migration_is_blocked

Since qemu_savevm_state is only called in save_snapshot, this means migration_is_blocked has been already checked.

Queued 1,3,4

Quoted 22 lines
---
 migration/savevm.c | 4 ----
 1 file changed, 4 deletions(-)
migration/savevm.c +0 -4
index 92af2471cd..2eea604624 100644
@@ -1412,10 +1412,6 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
         return -EINVAL;
     }
 
-    if (migration_is_blocked(errp)) {
-        return -EINVAL;
-    }
-
     if (migrate_use_block()) {
         error_setg(errp, "Block migration and snapshots are incompatible");
         return -EINVAL;
Signature · 1 line
2.19.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#6 lore raw

PATCH 2/4 migration/savevm: use migration_is_blocked to validate

In reply to Wei Yang

migration_is_blocked() is used in migrate_prepare() and save_snapshot(), this is more proper to use this instead of qemu_savevm_state_blocked() in qemu_loadvm_state().

---
 migration/savevm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
migration/savevm.c +1 -1
index 2eea604624..6c61056cde 100644
@@ -2406,7 +2406,7 @@ int qemu_loadvm_state(QEMUFile *f)
     unsigned int v;
     int ret;
 
-    if (qemu_savevm_state_blocked(&local_err)) {
+    if (migration_is_blocked(&local_err)) {
         error_report_err(local_err);
         return -EINVAL;
     }
Signature · 1 line
2.19.1
#7 lore raw

Re: [Qemu-devel] [PATCH 2/4] migration/savevm: use migration_is_blocked to validate

Quoted 3 lines · Wei Yang

migration_is_blocked() is used in migrate_prepare() and save_snapshot(), this is more proper to use this instead of qemu_savevm_state_blocked() in qemu_loadvm_state().

migration_is_blocked() does an additional verification:

"if (migration_blockers)"

comparing to what was previously done in qemu_loadvm_state.

I've checked what migration_blockers does and it is a GList used for callers to block the migration process. This is used via 'migration_add_blocker', from migration.c.

'migration_add_blocker' is called all over the place, most notably in  _realize() functions  and _open() functions from block.

Thus, I am not sure if this change will impact the use of qemu_loadvm_state() from load_snapshot() (i.e. can load_snapshot be called with migration_blockers?). It's better to someone with a better understanding of this code to comment on that.

DHB

Quoted 18 lines
---
  migration/savevm.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
migration/savevm.c +1 -1
index 2eea604624..6c61056cde 100644
@@ -2406,7 +2406,7 @@ int qemu_loadvm_state(QEMUFile *f)
      unsigned int v;
      int ret;
 
-    if (qemu_savevm_state_blocked(&local_err)) {
+    if (migration_is_blocked(&local_err)) {
          error_report_err(local_err);
          return -EINVAL;
      }
author
#8 lore raw

Re: [Qemu-devel] [PATCH 2/4] migration/savevm: use migration_is_blocked to validate

Quoted 18 lines · Daniel Henrique Barboza
Quoted 3 lines · Wei Yang

migration_is_blocked() is used in migrate_prepare() and save_snapshot(), this is more proper to use this instead of qemu_savevm_state_blocked() in qemu_loadvm_state().

migration_is_blocked() does an additional verification:

"if (migration_blockers)"

comparing to what was previously done in qemu_loadvm_state.

I've checked what migration_blockers does and it is a GList used for callers to block the migration process. This is used via 'migration_add_blocker', from migration.c.

Quoted 8 lines

'migration_add_blocker' is called all over the place, most notably in  _realize() functions  and _open() functions from block.

Thus, I am not sure if this change will impact the use of qemu_loadvm_state() from load_snapshot() (i.e. can load_snapshot be called with migration_blockers?). It's better to someone with a better understanding of this code to comment on that.

Well, when you look into the source side of migration:

qmp_migrate
migrate_prepare
migration_is_blocked

This means if migration_is_blocked fails, the source will not start migration. And it is the same as save_snapshot.

Quoted 1 line

From my understanding, when we load a vm, it should check the same

requirement.

Signature · 2 lines
Wei Yang
Help you, Help me
#9 lore raw

Re: [Qemu-devel] [PATCH 2/4] migration/savevm: use migration_is_blocked to validate

Quoted 34 lines · * Wei Yang ([email protected]) wrote:
Quoted 18 lines · Daniel Henrique Barboza
Quoted 3 lines · Wei Yang

migration_is_blocked() is used in migrate_prepare() and save_snapshot(), this is more proper to use this instead of qemu_savevm_state_blocked() in qemu_loadvm_state().

migration_is_blocked() does an additional verification:

"if (migration_blockers)"

comparing to what was previously done in qemu_loadvm_state.

I've checked what migration_blockers does and it is a GList used for callers to block the migration process. This is used via 'migration_add_blocker', from migration.c.

Quoted 8 lines

'migration_add_blocker' is called all over the place, most notably in  _realize() functions  and _open() functions from block.

Thus, I am not sure if this change will impact the use of qemu_loadvm_state() from load_snapshot() (i.e. can load_snapshot be called with migration_blockers?). It's better to someone with a better understanding of this code to comment on that.

Well, when you look into the source side of migration:

qmp_migrate
migrate_prepare
migration_is_blocked

Quoted 5 lines

This means if migration_is_blocked fails, the source will not start migration. And it is the same as save_snapshot.

From my understanding, when we load a vm, it should check the same requirement.

I've been thinking about this, and I think I agree with Daniel on this. The 'migration_blockers' list tells you that something about the *current* state of a device means that it can't be migrated - e.g. a 9pfs with a mounted filesystem can't be migrated.

If we're about to reload the state from a snapshot, then the saved snapshot's state must have been migratable, so that's OK.

(Whether all the device code is actually OK about being reset in that state is a different question; but I think it should be).

Dave

Quoted 3 lines
Signature · 2 lines
Wei Yang
Help you, Help me

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#10 lore raw

Re: [Qemu-devel] [PATCH 2/4] migration/savevm: use migration_is_blocked to validate

Quoted 14 lines · Dr. David Alan Gilbert
Quoted 7 lines · * Wei Yang ([email protected]) wrote:

Well, when you look into the source side of migration:

qmp_migrate
migrate_prepare
migration_is_blocked

Quoted 5 lines

This means if migration_is_blocked fails, the source will not start migration. And it is the same as save_snapshot.

From my understanding, when we load a vm, it should check the same requirement.

Quoted 8 lines

I've been thinking about this, and I think I agree with Daniel on this. The 'migration_blockers' list tells you that something about the *current* state of a device means that it can't be migrated - e.g. a 9pfs with a mounted filesystem can't be migrated.

If we're about to reload the state from a snapshot, then the saved snapshot's state must have been migratable, so that's OK.

The situation is on a vm with 'migration_blockers' still could reload from a snapshot.

This sounds reasonable. Thanks :-)

Quoted 10 lines

(Whether all the device code is actually OK about being reset in that state is a different question; but I think it should be).

Dave

Quoted 3 lines
Signature · 2 lines
Wei Yang
Help you, Help me

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Signature · 2 lines
Wei Yang
Help you, Help me
author
#11 lore raw

Re: [Qemu-devel] [PATCH 2/4] migration/savevm: use migration_is_blocked to validate

Quoted 20 lines · Wei Yang
Quoted 19 lines · Dr. David Alan Gilbert
Quoted 7 lines · * Wei Yang ([email protected]) wrote:

Well, when you look into the source side of migration:

qmp_migrate
migrate_prepare
migration_is_blocked

Quoted 5 lines

This means if migration_is_blocked fails, the source will not start migration. And it is the same as save_snapshot.

From my understanding, when we load a vm, it should check the same requirement.

I've been thinking about this, and I think I agree with Daniel on this. The 'migration_blockers' list tells you that something about the *current* state of a device means that it can't be migrated - e.g. a 9pfs with a mounted filesystem can't be migrated.

Quoted 9 lines
Quoted 3 lines

If we're about to reload the state from a snapshot, then the saved snapshot's state must have been migratable, so that's OK.

The situation is on a vm with 'migration_blockers' still could reload from a snapshot.

This sounds reasonable. Thanks :-)

Well, this is still a little strange. The means source vm and destination vm could have different configuration. Is this common?

Signature · 2 lines
Wei Yang
Help you, Help me
#12 lore raw

Re: [Qemu-devel] [PATCH 2/4] migration/savevm: use migration_is_blocked to validate

Quoted 25 lines · * Wei Yang ([email protected]) wrote:
Quoted 24 lines · Wei Yang
Quoted 22 lines · Dr. David Alan Gilbert
Quoted 7 lines · * Wei Yang ([email protected]) wrote:

Well, when you look into the source side of migration:

qmp_migrate
migrate_prepare
migration_is_blocked

Quoted 5 lines

This means if migration_is_blocked fails, the source will not start migration. And it is the same as save_snapshot.

From my understanding, when we load a vm, it should check the same requirement.

I've been thinking about this, and I think I agree with Daniel on this. The 'migration_blockers' list tells you that something about the *current* state of a device means that it can't be migrated - e.g. a 9pfs with a mounted filesystem can't be migrated.

If we're about to reload the state from a snapshot, then the saved snapshot's state must have been migratable, so that's OK.

Quoted 8 lines
Quoted 5 lines

The situation is on a vm with 'migration_blockers' still could reload from a snapshot.

This sounds reasonable. Thanks :-)

Well, this is still a little strange. The means source vm and destination vm could have different configuration. Is this common?

It's not different configuration that I'm worried about here; but it's different runtime state. Items can get added/removed from migration_blockers dynamically
depending on the behaviour of the guest; e.g. a device might only
migratable in certain states.

Dave

Quoted 3 lines
Signature · 2 lines
Wei Yang
Help you, Help me

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#13 lore raw

Re: [Qemu-devel] [PATCH 2/4] migration/savevm: use migration_is_blocked to validate

Quoted 32 lines · Dr. David Alan Gilbert
Quoted 31 lines · * Wei Yang ([email protected]) wrote:
Quoted 29 lines · Wei Yang
Quoted 14 lines · Dr. David Alan Gilbert
Quoted 7 lines · * Wei Yang ([email protected]) wrote:

Well, when you look into the source side of migration:

qmp_migrate
migrate_prepare
migration_is_blocked

Quoted 5 lines

This means if migration_is_blocked fails, the source will not start migration. And it is the same as save_snapshot.

From my understanding, when we load a vm, it should check the same requirement.

Quoted 8 lines

I've been thinking about this, and I think I agree with Daniel on this. The 'migration_blockers' list tells you that something about the *current* state of a device means that it can't be migrated - e.g. a 9pfs with a mounted filesystem can't be migrated.

If we're about to reload the state from a snapshot, then the saved snapshot's state must have been migratable, so that's OK.

The situation is on a vm with 'migration_blockers' still could reload from a snapshot.

This sounds reasonable. Thanks :-)

Quoted 8 lines
Quoted 2 lines

Well, this is still a little strange. The means source vm and destination vm could have different configuration. Is this common?

It's not different configuration that I'm worried about here; but it's different runtime state. Items can get added/removed from migration_blockers dynamically
depending on the behaviour of the guest; e.g. a device might only
migratable in certain states.

I am not familiar with the usage of migration_blockers, just found one case when we add a reason to it. -- vhost_dev_init().

Per my understanding, this is a device. We specify it in command line or use hot-plug to add it. To me, guest may not alter the add/remove? Looks even we have one such device, we still could load vm. This looks not bad, but we have the different devices from source.

BTW, migration works if source and destination have different devices?

As you mentioned, these is some case where guest could add/remove a reason to migration_blockers. This is what you concerned right?

Do we need to limit the usage of migration_blockers? Just use this in the case you concerned?

Quoted 8 lines

Dave

Quoted 3 lines
Signature · 2 lines
Wei Yang
Help you, Help me

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Signature · 2 lines
Wei Yang
Help you, Help me
author
#14 lore raw

PATCH 3/4 migration/savevm: load_header before load_setup

In reply to Wei Yang

In migration_thread() and qemu_savevm_state(), we savevm_state in following sequence:

    qemu_savevm_state_header(f);
    qemu_savevm_state_setup(f);

Then it would be more proper to loadvm_state in the save sequence.

---
 migration/savevm.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
migration/savevm.c +4 -4
index 6c61056cde..a80ae83663 100644
@@ -2427,10 +2427,6 @@ int qemu_loadvm_state(QEMUFile *f)
         return -ENOTSUP;
     }
 
-    if (qemu_loadvm_state_setup(f) != 0) {
-        return -EINVAL;
-    }
-
     if (migrate_get_current()->send_configuration) {
         if (qemu_get_byte(f) != QEMU_VM_CONFIGURATION) {
             error_report("Configuration section missing");
@@ -2445,6 +2441,10 @@ int qemu_loadvm_state(QEMUFile *f)
         }
     }
 
+    if (qemu_loadvm_state_setup(f) != 0) {
+        return -EINVAL;
+    }
+
     cpu_synchronize_all_pre_loadvm();
 
     ret = qemu_loadvm_state_main(f, mis);
Signature · 1 line
2.19.1
Reviewed-by on v1 3/4
#15 lore raw

Re: [Qemu-devel] [PATCH 3/4] migration/savevm: load_header before load_setup

Quoted 9 lines · * Wei Yang ([email protected]) wrote:

In migration_thread() and qemu_savevm_state(), we savevm_state in following sequence:

    qemu_savevm_state_header(f);
    qemu_savevm_state_setup(f);

Then it would be more proper to loadvm_state in the save sequence.

Yes, OK, I think that makes sense; the loadvm_state_setup and savevm_state_setup are actually quite different in what they do, however it does make sense to do the loadvm_state_setup after we have the configuration loaded, because then potentially it means we can alter the setup.

Quoted 33 lines
---
 migration/savevm.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
migration/savevm.c +4 -4
index 6c61056cde..a80ae83663 100644
@@ -2427,10 +2427,6 @@ int qemu_loadvm_state(QEMUFile *f)
         return -ENOTSUP;
     }
 
-    if (qemu_loadvm_state_setup(f) != 0) {
-        return -EINVAL;
-    }
-
     if (migrate_get_current()->send_configuration) {
         if (qemu_get_byte(f) != QEMU_VM_CONFIGURATION) {
             error_report("Configuration section missing");
@@ -2445,6 +2441,10 @@ int qemu_loadvm_state(QEMUFile *f)
         }
     }
 
+    if (qemu_loadvm_state_setup(f) != 0) {
+        return -EINVAL;
+    }
+
     cpu_synchronize_all_pre_loadvm();
 
     ret = qemu_loadvm_state_main(f, mis);
Signature · 1 line
2.19.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#16 lore raw

PATCH 4/4 migration/savevm: wrap into qemu_loadvm_state_header()

In reply to Wei Yang

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.

---
 migration/savevm.c | 69 +++++++++++++++++++++++++++-------------------
 1 file changed, 40 insertions(+), 29 deletions(-)
migration/savevm.c +40 -29
index a80ae83663..64d23682c6 100644
@@ -2256,6 +2256,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;
@@ -2403,7 +2440,6 @@ int qemu_loadvm_state(QEMUFile *f)
 {
     MigrationIncomingState *mis = migration_incoming_get_current();
     Error *local_err = NULL;
-    unsigned int v;
     int ret;
 
     if (migration_is_blocked(&local_err)) {
@@ -2411,34 +2447,9 @@ int qemu_loadvm_state(QEMUFile *f)
         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) {
Signature · 1 line
2.19.1
Reviewed-by on v1 4/4
#17 lore raw

Re: [Qemu-devel] [PATCH 4/4] migration/savevm: wrap into qemu_loadvm_state_header()

Quoted 8 lines · Wei Yang

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.

Quoted 98 lines
---
  migration/savevm.c | 69 +++++++++++++++++++++++++++-------------------
  1 file changed, 40 insertions(+), 29 deletions(-)
migration/savevm.c +40 -29
index a80ae83663..64d23682c6 100644
@@ -2256,6 +2256,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;
@@ -2403,7 +2440,6 @@ int qemu_loadvm_state(QEMUFile *f)
  {
      MigrationIncomingState *mis = migration_incoming_get_current();
      Error *local_err = NULL;
-    unsigned int v;
      int ret;
 
      if (migration_is_blocked(&local_err)) {
@@ -2411,34 +2447,9 @@ int qemu_loadvm_state(QEMUFile *f)
          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) {