qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Juan Quintela <quintela@redhat.com>
To: qemu-devel@nongnu.org
Cc: amit.shah@redhat.com
Subject: [Qemu-devel] [PULL 08/21] migration: create savevm_state
Date: Wed,  3 Jun 2015 14:05:44 +0200	[thread overview]
Message-ID: <1433333157-9939-9-git-send-email-quintela@redhat.com> (raw)
In-Reply-To: <1433333157-9939-1-git-send-email-quintela@redhat.com>

This way, we will put savevm global state here, instead of lots of variables.

Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 migration/savevm.c | 51 ++++++++++++++++++++++++++++-----------------------
 1 file changed, 28 insertions(+), 23 deletions(-)

diff --git a/migration/savevm.c b/migration/savevm.c
index 3dfa425..1a45d39 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -239,10 +239,15 @@ typedef struct SaveStateEntry {
     int is_ram;
 } SaveStateEntry;

+typedef struct SaveState {
+    QTAILQ_HEAD(, SaveStateEntry) handlers;
+    int global_section_id;
+} SaveState;

-static QTAILQ_HEAD(savevm_handlers, SaveStateEntry) savevm_handlers =
-    QTAILQ_HEAD_INITIALIZER(savevm_handlers);
-static int global_section_id;
+static SaveState savevm_state = {
+    .handlers = QTAILQ_HEAD_INITIALIZER(savevm_state.handlers),
+    .global_section_id = 0,
+};

 static void dump_vmstate_vmsd(FILE *out_file,
                               const VMStateDescription *vmsd, int indent,
@@ -387,7 +392,7 @@ static int calculate_new_instance_id(const char *idstr)
     SaveStateEntry *se;
     int instance_id = 0;

-    QTAILQ_FOREACH(se, &savevm_handlers, entry) {
+    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
         if (strcmp(idstr, se->idstr) == 0
             && instance_id <= se->instance_id) {
             instance_id = se->instance_id + 1;
@@ -401,7 +406,7 @@ static int calculate_compat_instance_id(const char *idstr)
     SaveStateEntry *se;
     int instance_id = 0;

-    QTAILQ_FOREACH(se, &savevm_handlers, entry) {
+    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
         if (!se->compat) {
             continue;
         }
@@ -429,7 +434,7 @@ int register_savevm_live(DeviceState *dev,

     se = g_malloc0(sizeof(SaveStateEntry));
     se->version_id = version_id;
-    se->section_id = global_section_id++;
+    se->section_id = savevm_state.global_section_id++;
     se->ops = ops;
     se->opaque = opaque;
     se->vmsd = NULL;
@@ -461,7 +466,7 @@ int register_savevm_live(DeviceState *dev,
     }
     assert(!se->compat || se->instance_id == 0);
     /* add at the end of list */
-    QTAILQ_INSERT_TAIL(&savevm_handlers, se, entry);
+    QTAILQ_INSERT_TAIL(&savevm_state.handlers, se, entry);
     return 0;
 }

@@ -495,9 +500,9 @@ void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque)
     }
     pstrcat(id, sizeof(id), idstr);

-    QTAILQ_FOREACH_SAFE(se, &savevm_handlers, entry, new_se) {
+    QTAILQ_FOREACH_SAFE(se, &savevm_state.handlers, entry, new_se) {
         if (strcmp(se->idstr, id) == 0 && se->opaque == opaque) {
-            QTAILQ_REMOVE(&savevm_handlers, se, entry);
+            QTAILQ_REMOVE(&savevm_state.handlers, se, entry);
             if (se->compat) {
                 g_free(se->compat);
             }
@@ -519,7 +524,7 @@ int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,

     se = g_malloc0(sizeof(SaveStateEntry));
     se->version_id = vmsd->version_id;
-    se->section_id = global_section_id++;
+    se->section_id = savevm_state.global_section_id++;
     se->opaque = opaque;
     se->vmsd = vmsd;
     se->alias_id = alias_id;
@@ -547,7 +552,7 @@ int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
     }
     assert(!se->compat || se->instance_id == 0);
     /* add at the end of list */
-    QTAILQ_INSERT_TAIL(&savevm_handlers, se, entry);
+    QTAILQ_INSERT_TAIL(&savevm_state.handlers, se, entry);
     return 0;
 }

@@ -556,9 +561,9 @@ void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd,
 {
     SaveStateEntry *se, *new_se;

-    QTAILQ_FOREACH_SAFE(se, &savevm_handlers, entry, new_se) {
+    QTAILQ_FOREACH_SAFE(se, &savevm_state.handlers, entry, new_se) {
         if (se->vmsd == vmsd && se->opaque == opaque) {
-            QTAILQ_REMOVE(&savevm_handlers, se, entry);
+            QTAILQ_REMOVE(&savevm_state.handlers, se, entry);
             if (se->compat) {
                 g_free(se->compat);
             }
@@ -610,7 +615,7 @@ bool qemu_savevm_state_blocked(Error **errp)
 {
     SaveStateEntry *se;

-    QTAILQ_FOREACH(se, &savevm_handlers, entry) {
+    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
         if (se->vmsd && se->vmsd->unmigratable) {
             error_setg(errp, "State blocked by non-migratable device '%s'",
                        se->idstr);
@@ -627,7 +632,7 @@ void qemu_savevm_state_begin(QEMUFile *f,
     int ret;

     trace_savevm_state_begin();
-    QTAILQ_FOREACH(se, &savevm_handlers, entry) {
+    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
         if (!se->ops || !se->ops->set_params) {
             continue;
         }
@@ -637,7 +642,7 @@ void qemu_savevm_state_begin(QEMUFile *f,
     qemu_put_be32(f, QEMU_VM_FILE_MAGIC);
     qemu_put_be32(f, QEMU_VM_FILE_VERSION);

-    QTAILQ_FOREACH(se, &savevm_handlers, entry) {
+    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
         int len;

         if (!se->ops || !se->ops->save_live_setup) {
@@ -680,7 +685,7 @@ int qemu_savevm_state_iterate(QEMUFile *f)
     int ret = 1;

     trace_savevm_state_iterate();
-    QTAILQ_FOREACH(se, &savevm_handlers, entry) {
+    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
         if (!se->ops || !se->ops->save_live_iterate) {
             continue;
         }
@@ -731,7 +736,7 @@ void qemu_savevm_state_complete(QEMUFile *f)

     cpu_synchronize_all_states();

-    QTAILQ_FOREACH(se, &savevm_handlers, entry) {
+    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
         if (!se->ops || !se->ops->save_live_complete) {
             continue;
         }
@@ -756,7 +761,7 @@ void qemu_savevm_state_complete(QEMUFile *f)
     vmdesc = qjson_new();
     json_prop_int(vmdesc, "page_size", TARGET_PAGE_SIZE);
     json_start_array(vmdesc, "devices");
-    QTAILQ_FOREACH(se, &savevm_handlers, entry) {
+    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
         int len;

         if ((!se->ops || !se->ops->save_state) && !se->vmsd) {
@@ -807,7 +812,7 @@ uint64_t qemu_savevm_state_pending(QEMUFile *f, uint64_t max_size)
     SaveStateEntry *se;
     uint64_t ret = 0;

-    QTAILQ_FOREACH(se, &savevm_handlers, entry) {
+    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
         if (!se->ops || !se->ops->save_live_pending) {
             continue;
         }
@@ -826,7 +831,7 @@ void qemu_savevm_state_cancel(void)
     SaveStateEntry *se;

     trace_savevm_state_cancel();
-    QTAILQ_FOREACH(se, &savevm_handlers, entry) {
+    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
         if (se->ops && se->ops->cancel) {
             se->ops->cancel(se->opaque);
         }
@@ -876,7 +881,7 @@ static int qemu_save_device_state(QEMUFile *f)

     cpu_synchronize_all_states();

-    QTAILQ_FOREACH(se, &savevm_handlers, entry) {
+    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
         int len;

         if (se->is_ram) {
@@ -910,7 +915,7 @@ static SaveStateEntry *find_se(const char *idstr, int instance_id)
 {
     SaveStateEntry *se;

-    QTAILQ_FOREACH(se, &savevm_handlers, entry) {
+    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
         if (!strcmp(se->idstr, idstr) &&
             (instance_id == se->instance_id ||
              instance_id == se->alias_id))
-- 
2.4.1

  parent reply	other threads:[~2015-06-03 12:06 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-03 12:05 [Qemu-devel] [PULL 00/21] Migration pull request Juan Quintela
2015-06-03 12:05 ` [Qemu-devel] [PULL 01/21] migration: move ram stuff to migration/ram Juan Quintela
2015-06-03 12:05 ` [Qemu-devel] [PULL 02/21] migration: move savevm.c inside migration/ Juan Quintela
2015-06-03 12:05 ` [Qemu-devel] [PULL 03/21] migration: Add myself to the copyright list of both files Juan Quintela
2015-06-03 12:05 ` [Qemu-devel] [PULL 04/21] migration: reduce include files Juan Quintela
2015-06-03 12:05 ` [Qemu-devel] [PULL 05/21] arch_init: Clean up the duplicate variable 'len' defining in ram_load() Juan Quintela
2015-06-03 12:05 ` [Qemu-devel] [PULL 06/21] rdma: Fix qemu crash when IPv6 address is used for migration Juan Quintela
2015-06-03 12:05 ` [Qemu-devel] [PULL 07/21] migration: Remove duplicated assignment of SETUP status Juan Quintela
2015-06-03 12:05 ` Juan Quintela [this message]
2015-06-03 12:05 ` [Qemu-devel] [PULL 09/21] migration: Use normal VMStateDescriptions for Subsections Juan Quintela
2015-06-03 12:05 ` [Qemu-devel] [PULL 10/21] Add qemu_get_counted_string to read a string prefixed by a count byte Juan Quintela
2015-06-03 12:05 ` [Qemu-devel] [PULL 11/21] Split header writing out of qemu_savevm_state_begin Juan Quintela
2015-06-03 12:05 ` [Qemu-devel] [PULL 12/21] qemu_ram_foreach_block: pass up error value, and down the ramblock name Juan Quintela
2015-06-03 12:05 ` [Qemu-devel] [PULL 13/21] Create MigrationIncomingState Juan Quintela
2015-06-03 12:05 ` [Qemu-devel] [PULL 14/21] Move copy out of qemu_peek_buffer Juan Quintela
2015-06-03 12:05 ` [Qemu-devel] [PULL 15/21] Move loadvm_handlers into MigrationIncomingState Juan Quintela
2015-06-03 12:05 ` [Qemu-devel] [PULL 16/21] Merge section header writing Juan Quintela
2015-06-03 12:05 ` [Qemu-devel] [PULL 17/21] Disable section footers on older machine types Juan Quintela
2015-06-03 12:05 ` [Qemu-devel] [PULL 18/21] Add a protective section footer Juan Quintela
2015-06-03 12:05 ` [Qemu-devel] [PULL 19/21] Teach analyze-migration.py about section footers Juan Quintela
2015-06-03 12:05 ` [Qemu-devel] [PULL 20/21] Rename RDMA structures to make destination clear Juan Quintela
2015-06-03 12:05 ` [Qemu-devel] [PULL 21/21] Remove unneeded memset Juan Quintela
2015-06-04 11:48 ` [Qemu-devel] [PULL 00/21] Migration pull request Peter Maydell
2015-06-04 13:01   ` Juan Quintela
  -- strict thread matches above, loose matches on Subject: below --
2015-06-12  5:03 [Qemu-devel] [PULL v2 00/21] migration " Juan Quintela
2015-06-12  5:03 ` [Qemu-devel] [PULL 08/21] migration: create savevm_state Juan Quintela

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=1433333157-9939-9-git-send-email-quintela@redhat.com \
    --to=quintela@redhat.com \
    --cc=amit.shah@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).