qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Amit Shah <amit.shah@redhat.com>
To: Juan Quintela <quintela@redhat.com>
Cc: Amit Shah <amit.shah@redhat.com>,
	qemu list <qemu-devel@nongnu.org>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>
Subject: [Qemu-devel] [migration PULL 3/9] Split out end of migration code from migration_thread
Date: Tue, 29 Sep 2015 12:02:18 +0530	[thread overview]
Message-ID: <09f6c85e39ee9e57bd245adbe6f400d387061707.1443508205.git.amit.shah@redhat.com> (raw)
In-Reply-To: <cover.1443508205.git.amit.shah@redhat.com>
In-Reply-To: <cover.1443508205.git.amit.shah@redhat.com>

From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

The code that gets run at the end of the migration process
is getting large, and I'm about to add more for postcopy.
Split it into a separate function.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Message-Id: <1439463094-5394-3-git-send-email-dgilbert@redhat.com>
Reviewed-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Reviewed-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
 migration/migration.c | 75 ++++++++++++++++++++++++++++++++-------------------
 trace-events          |  2 ++
 2 files changed, 49 insertions(+), 28 deletions(-)

diff --git a/migration/migration.c b/migration/migration.c
index 662e77e..46bb410 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -913,6 +913,50 @@ int64_t migrate_xbzrle_cache_size(void)
     return s->xbzrle_cache_size;
 }
 
+/**
+ * migration_completion: Used by migration_thread when there's not much left.
+ *   The caller 'breaks' the loop when this returns.
+ *
+ * @s: Current migration state
+ * @*old_vm_running: Pointer to old_vm_running flag
+ * @*start_time: Pointer to time to update
+ */
+static void migration_completion(MigrationState *s, bool *old_vm_running,
+                                 int64_t *start_time)
+{
+    int ret;
+
+    qemu_mutex_lock_iothread();
+    *start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
+    qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
+    *old_vm_running = runstate_is_running();
+
+    ret = global_state_store();
+    if (!ret) {
+        ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
+        if (ret >= 0) {
+            qemu_file_set_rate_limit(s->file, INT64_MAX);
+            qemu_savevm_state_complete(s->file);
+        }
+    }
+    qemu_mutex_unlock_iothread();
+
+    if (ret < 0) {
+        goto fail;
+    }
+
+    if (qemu_file_get_error(s->file)) {
+        trace_migration_completion_file_err();
+        goto fail;
+    }
+
+    migrate_set_state(s, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_COMPLETED);
+    return;
+
+fail:
+    migrate_set_state(s, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_FAILED);
+}
+
 /* migration thread support */
 
 static void *migration_thread(void *opaque)
@@ -943,34 +987,9 @@ static void *migration_thread(void *opaque)
             if (pending_size && pending_size >= max_size) {
                 qemu_savevm_state_iterate(s->file);
             } else {
-                int ret;
-
-                qemu_mutex_lock_iothread();
-                start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
-                qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
-                old_vm_running = runstate_is_running();
-
-                ret = global_state_store();
-                if (!ret) {
-                    ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
-                    if (ret >= 0) {
-                        qemu_file_set_rate_limit(s->file, INT64_MAX);
-                        qemu_savevm_state_complete(s->file);
-                    }
-                }
-                qemu_mutex_unlock_iothread();
-
-                if (ret < 0) {
-                    migrate_set_state(s, MIGRATION_STATUS_ACTIVE,
-                                      MIGRATION_STATUS_FAILED);
-                    break;
-                }
-
-                if (!qemu_file_get_error(s->file)) {
-                    migrate_set_state(s, MIGRATION_STATUS_ACTIVE,
-                                      MIGRATION_STATUS_COMPLETED);
-                    break;
-                }
+                trace_migration_thread_low_pending(pending_size);
+                migration_completion(s, &old_vm_running, &start_time);
+                break;
             }
         }
 
diff --git a/trace-events b/trace-events
index a70ea9c..59266e9 100644
--- a/trace-events
+++ b/trace-events
@@ -1420,6 +1420,8 @@ migrate_transferred(uint64_t tranferred, uint64_t time_spent, double bandwidth,
 migrate_state_too_big(void) ""
 migrate_global_state_post_load(const char *state) "loaded state: %s"
 migrate_global_state_pre_save(const char *state) "saved state: %s"
+migration_completion_file_err(void) ""
+migration_thread_low_pending(uint64_t pending) "%" PRIu64
 
 # migration/rdma.c
 qemu_rdma_accept_incoming_migration(void) ""
-- 
2.4.3

  parent reply	other threads:[~2015-09-29  6:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-29  6:32 [Qemu-devel] [migration PULL 0/9] Migration queue - for Juan Amit Shah
2015-09-29  6:32 ` [Qemu-devel] [migration PULL 1/9] vmstate: Remove redefinition of VMSTATE_UINT32_ARRAY Amit Shah
2015-09-29  6:32 ` [Qemu-devel] [migration PULL 2/9] migration/ram.c: Use RAMBlock rather than MemoryRegion Amit Shah
2015-09-29  6:32 ` Amit Shah [this message]
2015-09-29  6:32 ` [Qemu-devel] [migration PULL 4/9] Init page sizes in qtest Amit Shah
2015-09-29  6:32 ` [Qemu-devel] [migration PULL 5/9] migration: size_t'ify some of qemu-file Amit Shah
2015-09-29  6:32 ` [Qemu-devel] [migration PULL 6/9] migration: qemu-file more size_t'ifying Amit Shah
2015-09-29  6:32 ` [Qemu-devel] [migration PULL 7/9] migration: Use g_new() & friends where that makes obvious sense Amit Shah
2015-09-29  6:32 ` [Qemu-devel] [migration PULL 8/9] Move dirty page search state into separate structure Amit Shah
2015-09-29  6:32 ` [Qemu-devel] [migration PULL 9/9] ram_find_and_save_block: Split out the finding Amit Shah
2015-09-29 12:50 ` [Qemu-devel] [migration PULL 0/9] Migration queue - for Juan Peter Maydell
2015-09-29 13:05   ` Amit Shah
2015-09-29 13:23     ` Peter Maydell
2015-09-30 16:23   ` 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=09f6c85e39ee9e57bd245adbe6f400d387061707.1443508205.git.amit.shah@redhat.com \
    --to=amit.shah@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /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).