[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 32/47] Postcopy: postcopy_start
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [PATCH v3 32/47] Postcopy: postcopy_start |
Date: |
Thu, 28 Aug 2014 16:03:49 +0100 |
From: "Dr. David Alan Gilbert" <address@hidden>
postcopy_start:
Perform all the initialisation associated with starting up postcopy
mode from the source.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
migration.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 85 insertions(+)
diff --git a/migration.c b/migration.c
index f5d9d02..1ae5b7d 100644
--- a/migration.c
+++ b/migration.c
@@ -899,6 +899,91 @@ static void
await_outgoing_return_path_close(MigrationState *ms)
DPRINTF("%s: Exit", __func__);
}
+/* Switch from normal iteration to postcopy
+ * Returns non-0 on error
+ */
+static int postcopy_start(MigrationState *ms)
+{
+ int ret;
+ const QEMUSizedBuffer *qsb;
+ migrate_set_state(ms, MIG_STATE_ACTIVE, MIG_STATE_POSTCOPY_ACTIVE);
+
+ DPRINTF("postcopy_start\n");
+ qemu_mutex_lock_iothread();
+ DPRINTF("postcopy_start: setting run state\n");
+ ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
+
+ if (ret < 0) {
+ migrate_set_state(ms, MIG_STATE_POSTCOPY_ACTIVE, MIG_STATE_ERROR);
+ qemu_mutex_unlock_iothread();
+ return -1;
+ }
+
+ /*
+ * in Finish migrate and with the io-lock held everything should
+ * be quiet, but we've potentially still got dirty pages and we
+ * need to tell the destination to throw any pages it's already received
+ * that are dirty
+ */
+ if (postcopy_send_discard_bitmap(ms)) {
+ DPRINTF("postcopy send discard bitmap failed\n");
+ migrate_set_state(ms, MIG_STATE_POSTCOPY_ACTIVE, MIG_STATE_ERROR);
+ qemu_mutex_unlock_iothread();
+ return -1;
+ }
+
+ DPRINTF("postcopy_start: sending req 2\n");
+ qemu_savevm_send_reqack(ms->file, 2);
+ /*
+ * send rest of state - note things that are doing postcopy
+ * will notice we're in MIG_STATE_POSTCOPY_ACTIVE and not actually
+ * wrap their state up here
+ */
+ qemu_file_set_rate_limit(ms->file, INT64_MAX);
+ DPRINTF("postcopy_start: do state_complete\n");
+
+ /*
+ * We need to leave the fd free for page transfers during the
+ * loading of the device state, so wrap all the remaining
+ * commands and state into a package that gets sent in one go
+ */
+ QEMUFile *fb = qemu_bufopen("w", NULL);
+
+ qemu_savevm_state_complete(fb);
+ DPRINTF("postcopy_start: sending req 3\n");
+ qemu_savevm_send_reqack(fb, 3);
+
+ qemu_savevm_send_postcopy_ram_run(fb);
+
+ /* <><> end of stuff going into the package */
+ qsb = qemu_buf_get(fb);
+
+ /* Now send that blob */
+ if (qsb_get_length(qsb) > MAX_VM_CMD_PACKAGED_SIZE) {
+ DPRINTF("postcopy_start: Unreasonably large packaged state: %lu\n",
+ (unsigned long)(qsb_get_length(qsb)));
+ migrate_set_state(ms, MIG_STATE_POSTCOPY_ACTIVE, MIG_STATE_ERROR);
+ qemu_mutex_unlock_iothread();
+ qemu_fclose(fb);
+ return -1;
+ }
+ qemu_savevm_send_packaged(ms->file, qsb);
+ qemu_fclose(fb);
+
+ qemu_mutex_unlock_iothread();
+
+ DPRINTF("postcopy_start not finished sending ack\n");
+ qemu_savevm_send_reqack(ms->file, 4);
+
+ ret = qemu_file_get_error(ms->file);
+ if (ret) {
+ error_report("postcopy_start: Migration stream errored");
+ migrate_set_state(ms, MIG_STATE_POSTCOPY_ACTIVE, MIG_STATE_ERROR);
+ }
+
+ return ret;
+}
+
/*
* Master migration thread on the source VM.
* It drives the migration and pumps the data down the outgoing channel.
--
1.9.3
- [Qemu-devel] [PATCH v3 25/47] MIG_STATE_POSTCOPY_ACTIVE: Add new migration state, (continued)
- [Qemu-devel] [PATCH v3 25/47] MIG_STATE_POSTCOPY_ACTIVE: Add new migration state, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 27/47] Postcopy: Maintain sentmap during postcopy pre phase, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 28/47] Postcopy page-map-incoming (PMI) structure, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 29/47] postcopy: Add incoming_init/cleanup functions, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 26/47] qemu_savevm_state_complete: Postcopy changes, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 15/47] qemu_loadvm errors and debug, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 19/47] Add wrappers and handlers for sending/receiving the postcopy-ram migration messages., Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 31/47] postcopy: ram_enable_notify to switch on userfault, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 34/47] mig fd_connect: open return path, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 33/47] Postcopy: Rework migration thread for postcopy mode, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 32/47] Postcopy: postcopy_start,
Dr. David Alan Gilbert (git) <=
- [Qemu-devel] [PATCH v3 36/47] Page request: Add MIG_RPCOMM_REQPAGES reverse command, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 37/47] Page request: Process incoming page request, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 39/47] Add assertion to check migration_dirty_pages, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 38/47] Page request: Consume pages off the post-copy queue, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 41/47] Postcopy: Use helpers to map pages during migration, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 42/47] qemu_ram_block_from_host, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 43/47] Don't sync dirty bitmaps in postcopy, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 44/47] Postcopy; Handle userfault requests, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 46/47] postcopy: Wire up loadvm_postcopy_ram_handle_{run, end} commands, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 45/47] Start up a postcopy/listener thread ready for incoming page data, Dr. David Alan Gilbert (git), 2014/08/28