From: Andrey Gruzdev via <qemu-devel@nongnu.org>
To: qemu-devel@nongnu.org
Cc: Den Lunev <den@openvz.org>, Eric Blake <eblake@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Juan Quintela <quintela@redhat.com>,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
Peter Xu <peterx@redhat.com>,
Andrey Gruzdev <andrey.gruzdev@virtuozzo.com>
Subject: [PATCH v3 6/7] the rest of write tracking migration code
Date: Thu, 19 Nov 2020 15:59:39 +0300 [thread overview]
Message-ID: <20201119125940.20017-7-andrey.gruzdev@virtuozzo.com> (raw)
In-Reply-To: <20201119125940.20017-1-andrey.gruzdev@virtuozzo.com>
Signed-off-by: Andrey Gruzdev <andrey.gruzdev@virtuozzo.com>
---
migration/migration.c | 72 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 70 insertions(+), 2 deletions(-)
diff --git a/migration/migration.c b/migration/migration.c
index dba388f8bd..ccb451b238 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -3212,6 +3212,48 @@ fail:
MIGRATION_STATUS_FAILED);
}
+/**
+ * wt_migration_completion: Used by wt_migration_thread when after all the
+ * RAM has been saved. The caller 'breaks' the loop when this returns.
+ *
+ * @s: Current migration state
+ */
+static void wt_migration_completion(MigrationState *s)
+{
+ int current_active_state = s->state;
+
+ /* Stop tracking RAM writes - un-protect memory, un-register UFFD memory ranges,
+ * flush kernel wait queues and wake up threads waiting for write fault to be
+ * resolved. All of this is essentially done by closing UFFD file descriptor */
+ ram_write_tracking_stop();
+
+ if (s->state == MIGRATION_STATUS_ACTIVE) {
+ /*
+ * By this moment we have RAM content saved into the migration stream.
+ * The next step is to flush the non-RAM content (device state)
+ * right after the ram content. The device state has been stored into
+ * the temporary buffer before RAM saving started.
+ */
+ qemu_put_buffer(s->to_dst_file, s->bioc->data, s->bioc->usage);
+ qemu_fflush(s->to_dst_file);
+ } else if (s->state == MIGRATION_STATUS_CANCELLING) {
+ goto fail;
+ }
+
+ if (qemu_file_get_error(s->to_dst_file)) {
+ trace_migration_completion_file_err();
+ goto fail;
+ }
+
+ migrate_set_state(&s->state, current_active_state,
+ MIGRATION_STATUS_COMPLETED);
+ return;
+
+fail:
+ migrate_set_state(&s->state, current_active_state,
+ MIGRATION_STATUS_FAILED);
+}
+
bool migrate_colo_enabled(void)
{
MigrationState *s = migrate_get_current();
@@ -3554,7 +3596,26 @@ static void migration_iteration_finish(MigrationState *s)
static void wt_migration_iteration_finish(MigrationState *s)
{
- /* TODO: implement */
+ qemu_mutex_lock_iothread();
+ switch (s->state) {
+ case MIGRATION_STATUS_COMPLETED:
+ migration_calculate_complete(s);
+ break;
+
+ case MIGRATION_STATUS_ACTIVE:
+ case MIGRATION_STATUS_FAILED:
+ case MIGRATION_STATUS_CANCELLED:
+ case MIGRATION_STATUS_CANCELLING:
+ break;
+
+ default:
+ /* Should not reach here, but if so, forgive the VM. */
+ error_report("%s: Unknown ending state %d", __func__, s->state);
+ break;
+ }
+
+ migrate_fd_cleanup_schedule(s);
+ qemu_mutex_unlock_iothread();
}
/*
@@ -3563,7 +3624,14 @@ static void wt_migration_iteration_finish(MigrationState *s)
*/
static MigIterateState wt_migration_iteration_run(MigrationState *s)
{
- /* TODO: implement */
+ int res;
+
+ res = qemu_savevm_state_iterate(s->to_dst_file, false);
+ if (res) {
+ wt_migration_completion(s);
+ return MIG_ITERATE_BREAK;
+ }
+
return MIG_ITERATE_RESUME;
}
--
2.25.1
next prev parent reply other threads:[~2020-11-19 13:04 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-19 12:59 [PATCH v3 0/7] UFFD write-tracking migration/snapshots Andrey Gruzdev via
2020-11-19 12:59 ` [PATCH v3 1/7] introduce 'track-writes-ram' migration capability Andrey Gruzdev via
2020-11-19 18:51 ` Peter Xu
2020-11-19 19:07 ` Peter Xu
2020-11-20 11:35 ` Andrey Gruzdev
2020-11-24 16:55 ` Dr. David Alan Gilbert
2020-11-24 17:25 ` Andrey Gruzdev
2020-11-20 11:32 ` Andrey Gruzdev
2020-11-19 12:59 ` [PATCH v3 2/7] introduce UFFD-WP low-level interface helpers Andrey Gruzdev via
2020-11-19 18:39 ` Peter Xu
2020-11-20 11:04 ` Andrey Gruzdev
2020-11-20 15:01 ` Peter Xu
2020-11-20 15:43 ` Andrey Gruzdev
2020-11-24 17:57 ` Dr. David Alan Gilbert
2020-11-25 8:11 ` Andrey Gruzdev
2020-11-25 18:43 ` Dr. David Alan Gilbert
2020-11-25 19:17 ` Andrey Gruzdev
2020-11-19 12:59 ` [PATCH v3 3/7] support UFFD write fault processing in ram_save_iterate() Andrey Gruzdev via
2020-11-19 18:25 ` Peter Xu
2020-11-20 10:44 ` Andrey Gruzdev
2020-11-20 15:07 ` Peter Xu
2020-11-20 16:15 ` Andrey Gruzdev
2020-11-20 16:43 ` Peter Xu
2020-11-20 16:53 ` Andrey Gruzdev
2020-11-23 21:34 ` Peter Xu
2020-11-24 8:02 ` Andrey Gruzdev
2020-11-24 15:17 ` Peter Xu
2020-11-24 17:40 ` Andrey Gruzdev
2020-11-25 13:08 ` Dr. David Alan Gilbert
2020-11-25 14:40 ` Andrey Gruzdev
2020-11-25 18:41 ` Dr. David Alan Gilbert
2020-11-25 19:12 ` Andrey Gruzdev
2020-11-19 12:59 ` [PATCH v3 4/7] implementation of write-tracking migration thread Andrey Gruzdev via
2020-11-19 18:47 ` Peter Xu
2020-11-20 11:41 ` Andrey Gruzdev
2020-11-19 12:59 ` [PATCH v3 5/7] implementation of vm_start() BH Andrey Gruzdev via
2020-11-19 18:46 ` Peter Xu
2020-11-20 11:13 ` Andrey Gruzdev
2020-11-19 12:59 ` Andrey Gruzdev via [this message]
2020-11-19 12:59 ` [PATCH v3 7/7] introduce simple linear scan rate limiting mechanism Andrey Gruzdev via
2020-11-19 20:02 ` Peter Xu
2020-11-20 12:06 ` Andrey Gruzdev
2020-11-20 15:23 ` Peter Xu
2020-11-24 16:41 ` [PATCH v3 0/7] UFFD write-tracking migration/snapshots Dr. David Alan Gilbert
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=20201119125940.20017-7-andrey.gruzdev@virtuozzo.com \
--to=qemu-devel@nongnu.org \
--cc=andrey.gruzdev@virtuozzo.com \
--cc=armbru@redhat.com \
--cc=den@openvz.org \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--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).