qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert (git)" <dgilbert@redhat.com>
To: qemu-devel@nongnu.org, quintela@redhat.com, peterx@redhat.com,
	ehabkost@redhat.com, richardw.yang@linux.intel.com,
	yury-kotov@yandex-team.ru, chen.zhang@intel.com
Subject: [Qemu-devel] [PULL 13/16] migration/savevm: wrap into qemu_loadvm_state_header()
Date: Tue, 14 May 2019 19:34:51 +0100	[thread overview]
Message-ID: <20190514183454.12758-14-dgilbert@redhat.com> (raw)
In-Reply-To: <20190514183454.12758-1-dgilbert@redhat.com>

From: Wei Yang <richardw.yang@linux.intel.com>

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 <richardw.yang@linux.intel.com>
Message-Id: <20190424004700.12766-5-richardw.yang@linux.intel.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 migration/savevm.c | 69 +++++++++++++++++++++++++++-------------------
 1 file changed, 40 insertions(+), 29 deletions(-)

diff --git a/migration/savevm.c b/migration/savevm.c
index 4c7b8379e8..c0e557b4c2 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -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;
@@ -2410,7 +2447,6 @@ 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)) {
@@ -2418,34 +2454,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) {
-- 
2.21.0



  parent reply	other threads:[~2019-05-14 18:45 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-14 18:34 [Qemu-devel] [PULL 00/16] migration queue Dr. David Alan Gilbert (git)
2019-05-14 18:34 ` [Qemu-devel] [PULL 01/16] migration: comment VMSTATE_UNUSED*() properly Dr. David Alan Gilbert (git)
2019-05-14 18:34 ` [Qemu-devel] [PULL 02/16] migration: not necessary to check ops again Dr. David Alan Gilbert (git)
2019-05-14 18:34 ` [Qemu-devel] [PULL 03/16] migration: remove not used field xfer_limit Dr. David Alan Gilbert (git)
2019-05-14 18:34 ` [Qemu-devel] [PULL 04/16] vmstate: check subsection_found is enough Dr. David Alan Gilbert (git)
2019-05-14 18:34 ` [Qemu-devel] [PULL 05/16] migration: savevm: fix error code with migration blockers Dr. David Alan Gilbert (git)
2019-05-14 18:34 ` [Qemu-devel] [PULL 06/16] migration/colo.c: Remove redundant input parameter Dr. David Alan Gilbert (git)
2019-05-14 18:34 ` [Qemu-devel] [PULL 07/16] migration/colo.h: Remove obsolete codes Dr. David Alan Gilbert (git)
2019-05-14 18:34 ` [Qemu-devel] [PULL 08/16] qemu-option.hx: Update missed parameter for colo-compare Dr. David Alan Gilbert (git)
2019-05-14 18:34 ` [Qemu-devel] [PULL 09/16] migration/ram.c: start of migration_bitmap_sync_range is always 0 Dr. David Alan Gilbert (git)
2019-05-14 18:34 ` [Qemu-devel] [PULL 10/16] migration: update comments of migration bitmap Dr. David Alan Gilbert (git)
2019-05-14 18:34 ` [Qemu-devel] [PULL 11/16] migration/savevm: remove duplicate check of migration_is_blocked Dr. David Alan Gilbert (git)
2019-05-14 18:34 ` [Qemu-devel] [PULL 12/16] migration/savevm: load_header before load_setup Dr. David Alan Gilbert (git)
2019-05-14 18:34 ` Dr. David Alan Gilbert (git) [this message]
2019-05-14 18:34 ` [Qemu-devel] [PULL 14/16] migration: Fix use-after-free during process exit Dr. David Alan Gilbert (git)
2019-05-14 18:34 ` [Qemu-devel] [PULL 15/16] migration/ram.c: fix typos in comments Dr. David Alan Gilbert (git)
2019-05-14 18:34 ` [Qemu-devel] [PULL 16/16] monitor: Call mon_get_cpu() only once at hmp_gva2gpa() Dr. David Alan Gilbert (git)
2019-05-16 11:54 ` [Qemu-devel] [PULL 00/16] migration queue Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190514183454.12758-14-dgilbert@redhat.com \
    --to=dgilbert@redhat.com \
    --cc=chen.zhang@intel.com \
    --cc=ehabkost@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=richardw.yang@linux.intel.com \
    --cc=yury-kotov@yandex-team.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).