blob: 8380e2f2d1f540c1a52ec2944e7fb4ff5e05a0a5 [file] [log] [blame]
aliguori5bb79102008-10-13 03:12:02 +00001/*
2 * QEMU live migration
3 *
4 * Copyright IBM, Corp. 2008
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
Paolo Bonzini6b620ca2012-01-13 17:44:23 +010012 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
aliguori5bb79102008-10-13 03:12:02 +000014 */
15
16#include "qemu-common.h"
Markus Armbrusterd49b6832015-03-17 18:29:20 +010017#include "qemu/error-report.h"
Alex Bligh6a1751b2013-08-21 16:02:47 +010018#include "qemu/main-loop.h"
Paolo Bonzinicaf71f82012-12-17 18:19:50 +010019#include "migration/migration.h"
Juan Quintela0d82d0e2012-10-03 14:18:33 +020020#include "migration/qemu-file.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010021#include "sysemu/sysemu.h"
Paolo Bonzini737e1502012-12-17 18:19:44 +010022#include "block/block.h"
Markus Armbrustercc7a8ea2015-03-17 17:22:46 +010023#include "qapi/qmp/qerror.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010024#include "qemu/sockets.h"
Paolo Bonziniab28bd22015-07-09 08:55:38 +020025#include "qemu/rcu.h"
Paolo Bonzinicaf71f82012-12-17 18:19:50 +010026#include "migration/block.h"
Juan Quintela766bd172012-07-23 05:45:29 +020027#include "qemu/thread.h"
Luiz Capitulino791e7c82011-09-13 17:37:16 -030028#include "qmp-commands.h"
Kazuya Saitoc09e5bb2013-02-22 17:36:19 +010029#include "trace.h"
Juan Quinteladf4b1022014-10-08 10:58:10 +020030#include "qapi/util.h"
Juan Quintela598cd2b2015-05-20 12:16:15 +020031#include "qapi-event.h"
Jason J. Herne070afca2015-09-08 13:12:35 -040032#include "qom/cpu.h"
aliguori065e2812008-11-11 16:46:33 +000033
Jason J. Hernedc325622015-09-08 13:12:37 -040034#define MAX_THROTTLE (32 << 20) /* Migration transfer speed throttling */
aliguori5bb79102008-10-13 03:12:02 +000035
Juan Quintela5b4e1eb2012-12-19 10:40:48 +010036/* Amount of time to allocate to each "chunk" of bandwidth-throttled
37 * data. */
38#define BUFFER_DELAY 100
39#define XFER_LIMIT_RATIO (1000 / BUFFER_DELAY)
40
Liang Li8706d2d2015-03-23 16:32:17 +080041/* Default compression thread count */
42#define DEFAULT_MIGRATE_COMPRESS_THREAD_COUNT 8
Liang Li3fcb38c2015-03-23 16:32:18 +080043/* Default decompression thread count, usually decompression is at
44 * least 4 times as fast as compression.*/
45#define DEFAULT_MIGRATE_DECOMPRESS_THREAD_COUNT 2
Liang Li8706d2d2015-03-23 16:32:17 +080046/*0: means nocompress, 1: best speed, ... 9: best compress ratio */
47#define DEFAULT_MIGRATE_COMPRESS_LEVEL 1
Jason J. Herne1626fee2015-09-08 13:12:34 -040048/* Define default autoconverge cpu throttle migration parameters */
49#define DEFAULT_MIGRATE_X_CPU_THROTTLE_INITIAL 20
50#define DEFAULT_MIGRATE_X_CPU_THROTTLE_INCREMENT 10
Liang Li8706d2d2015-03-23 16:32:17 +080051
Orit Wasserman17ad9b32012-08-06 21:42:53 +030052/* Migration XBZRLE default cache size */
53#define DEFAULT_MIGRATE_CACHE_SIZE (64 * 1024 * 1024)
54
Gerd Hoffmann99a0db92010-12-13 17:30:12 +010055static NotifierList migration_state_notifiers =
56 NOTIFIER_LIST_INITIALIZER(migration_state_notifiers);
57
Dr. David Alan Gilbertadde2202015-02-19 11:40:27 +000058static bool deferred_incoming;
59
Juan Quintela17549e82011-10-05 13:50:43 +020060/* When we add fault tolerance, we could have several
61 migrations at once. For now we don't need to add
62 dynamic creation of migration */
63
Dr. David Alan Gilbertbca78562015-05-21 13:24:14 +010064/* For outgoing */
Juan Quintela859bc752012-08-13 09:42:49 +020065MigrationState *migrate_get_current(void)
Juan Quintela17549e82011-10-05 13:50:43 +020066{
67 static MigrationState current_migration = {
zhanghailiang31194732015-03-13 16:08:38 +080068 .state = MIGRATION_STATUS_NONE,
Juan Quintelad0ae46c2011-02-23 00:33:19 +010069 .bandwidth_limit = MAX_THROTTLE,
Orit Wasserman17ad9b32012-08-06 21:42:53 +030070 .xbzrle_cache_size = DEFAULT_MIGRATE_CACHE_SIZE,
Michael R. Hines7e114f82013-06-25 21:35:30 -040071 .mbps = -1,
Liang Li43c60a82015-03-23 16:32:27 +080072 .parameters[MIGRATION_PARAMETER_COMPRESS_LEVEL] =
73 DEFAULT_MIGRATE_COMPRESS_LEVEL,
74 .parameters[MIGRATION_PARAMETER_COMPRESS_THREADS] =
75 DEFAULT_MIGRATE_COMPRESS_THREAD_COUNT,
76 .parameters[MIGRATION_PARAMETER_DECOMPRESS_THREADS] =
77 DEFAULT_MIGRATE_DECOMPRESS_THREAD_COUNT,
Jason J. Herne1626fee2015-09-08 13:12:34 -040078 .parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL] =
79 DEFAULT_MIGRATE_X_CPU_THROTTLE_INITIAL,
80 .parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT] =
81 DEFAULT_MIGRATE_X_CPU_THROTTLE_INCREMENT,
Juan Quintela17549e82011-10-05 13:50:43 +020082 };
83
84 return &current_migration;
85}
86
Dr. David Alan Gilbertbca78562015-05-21 13:24:14 +010087/* For incoming */
88static MigrationIncomingState *mis_current;
89
90MigrationIncomingState *migration_incoming_get_current(void)
91{
92 return mis_current;
93}
94
95MigrationIncomingState *migration_incoming_state_new(QEMUFile* f)
96{
Markus Armbruster97f3ad32015-09-14 13:51:31 +020097 mis_current = g_new0(MigrationIncomingState, 1);
Dr. David Alan Gilbert42e2aa52015-11-05 18:10:34 +000098 mis_current->from_src_file = f;
Dr. David Alan Gilbert1a8f46f2015-05-21 13:24:16 +010099 QLIST_INIT(&mis_current->loadvm_handlers);
Dr. David Alan Gilbert6decec92015-11-05 18:10:47 +0000100 qemu_mutex_init(&mis_current->rp_mutex);
Dr. David Alan Gilbertbca78562015-05-21 13:24:14 +0100101
102 return mis_current;
103}
104
105void migration_incoming_state_destroy(void)
106{
Dr. David Alan Gilbert1a8f46f2015-05-21 13:24:16 +0100107 loadvm_free_handlers(mis_current);
Dr. David Alan Gilbertbca78562015-05-21 13:24:14 +0100108 g_free(mis_current);
109 mis_current = NULL;
110}
111
Juan Quinteladf4b1022014-10-08 10:58:10 +0200112
113typedef struct {
Juan Quintela13d16812014-10-08 13:58:24 +0200114 bool optional;
Juan Quinteladf4b1022014-10-08 10:58:10 +0200115 uint32_t size;
116 uint8_t runstate[100];
Juan Quintela172c4352015-07-08 13:56:26 +0200117 RunState state;
118 bool received;
Juan Quinteladf4b1022014-10-08 10:58:10 +0200119} GlobalState;
120
121static GlobalState global_state;
122
Juan Quintela560d0272015-07-15 09:53:46 +0200123int global_state_store(void)
Juan Quinteladf4b1022014-10-08 10:58:10 +0200124{
125 if (!runstate_store((char *)global_state.runstate,
126 sizeof(global_state.runstate))) {
127 error_report("runstate name too big: %s", global_state.runstate);
128 trace_migrate_state_too_big();
129 return -EINVAL;
130 }
131 return 0;
132}
133
Anthony PERARDc69adea2015-08-03 15:29:19 +0100134void global_state_store_running(void)
135{
136 const char *state = RunState_lookup[RUN_STATE_RUNNING];
137 strncpy((char *)global_state.runstate,
138 state, sizeof(global_state.runstate));
139}
140
Juan Quintela172c4352015-07-08 13:56:26 +0200141static bool global_state_received(void)
Juan Quinteladf4b1022014-10-08 10:58:10 +0200142{
Juan Quintela172c4352015-07-08 13:56:26 +0200143 return global_state.received;
144}
145
146static RunState global_state_get_runstate(void)
147{
148 return global_state.state;
Juan Quinteladf4b1022014-10-08 10:58:10 +0200149}
150
Juan Quintela13d16812014-10-08 13:58:24 +0200151void global_state_set_optional(void)
152{
153 global_state.optional = true;
154}
155
156static bool global_state_needed(void *opaque)
157{
158 GlobalState *s = opaque;
159 char *runstate = (char *)s->runstate;
160
161 /* If it is not optional, it is mandatory */
162
163 if (s->optional == false) {
164 return true;
165 }
166
167 /* If state is running or paused, it is not needed */
168
169 if (strcmp(runstate, "running") == 0 ||
170 strcmp(runstate, "paused") == 0) {
171 return false;
172 }
173
174 /* for any other state it is needed */
175 return true;
176}
177
Juan Quinteladf4b1022014-10-08 10:58:10 +0200178static int global_state_post_load(void *opaque, int version_id)
179{
180 GlobalState *s = opaque;
Juan Quintela172c4352015-07-08 13:56:26 +0200181 Error *local_err = NULL;
182 int r;
Juan Quinteladf4b1022014-10-08 10:58:10 +0200183 char *runstate = (char *)s->runstate;
184
Juan Quintela172c4352015-07-08 13:56:26 +0200185 s->received = true;
Juan Quinteladf4b1022014-10-08 10:58:10 +0200186 trace_migrate_global_state_post_load(runstate);
187
Juan Quintela172c4352015-07-08 13:56:26 +0200188 r = qapi_enum_parse(RunState_lookup, runstate, RUN_STATE_MAX,
Juan Quinteladf4b1022014-10-08 10:58:10 +0200189 -1, &local_err);
190
Juan Quintela172c4352015-07-08 13:56:26 +0200191 if (r == -1) {
192 if (local_err) {
193 error_report_err(local_err);
Juan Quinteladf4b1022014-10-08 10:58:10 +0200194 }
Juan Quintela172c4352015-07-08 13:56:26 +0200195 return -EINVAL;
Juan Quinteladf4b1022014-10-08 10:58:10 +0200196 }
Juan Quintela172c4352015-07-08 13:56:26 +0200197 s->state = r;
Juan Quinteladf4b1022014-10-08 10:58:10 +0200198
Juan Quintela172c4352015-07-08 13:56:26 +0200199 return 0;
Juan Quinteladf4b1022014-10-08 10:58:10 +0200200}
201
202static void global_state_pre_save(void *opaque)
203{
204 GlobalState *s = opaque;
205
206 trace_migrate_global_state_pre_save((char *)s->runstate);
207 s->size = strlen((char *)s->runstate) + 1;
208}
209
210static const VMStateDescription vmstate_globalstate = {
211 .name = "globalstate",
212 .version_id = 1,
213 .minimum_version_id = 1,
214 .post_load = global_state_post_load,
215 .pre_save = global_state_pre_save,
Juan Quintela13d16812014-10-08 13:58:24 +0200216 .needed = global_state_needed,
Juan Quinteladf4b1022014-10-08 10:58:10 +0200217 .fields = (VMStateField[]) {
218 VMSTATE_UINT32(size, GlobalState),
219 VMSTATE_BUFFER(runstate, GlobalState),
220 VMSTATE_END_OF_LIST()
221 },
222};
223
224void register_global_state(void)
225{
226 /* We would use it independently that we receive it */
227 strcpy((char *)&global_state.runstate, "");
Juan Quintela172c4352015-07-08 13:56:26 +0200228 global_state.received = false;
Juan Quinteladf4b1022014-10-08 10:58:10 +0200229 vmstate_register(NULL, 0, &vmstate_globalstate, &global_state);
230}
231
Juan Quintelab05dc722015-07-07 14:44:05 +0200232static void migrate_generate_event(int new_state)
233{
234 if (migrate_use_events()) {
235 qapi_event_send_migration(new_state, &error_abort);
Juan Quintelab05dc722015-07-07 14:44:05 +0200236 }
237}
238
Dr. David Alan Gilbertadde2202015-02-19 11:40:27 +0000239/*
240 * Called on -incoming with a defer: uri.
241 * The migration can be started later after any parameters have been
242 * changed.
243 */
244static void deferred_incoming_migration(Error **errp)
245{
246 if (deferred_incoming) {
247 error_setg(errp, "Incoming migration already deferred");
248 }
249 deferred_incoming = true;
250}
251
Paolo Bonzini43eaae22012-10-02 18:21:18 +0200252void qemu_start_incoming_migration(const char *uri, Error **errp)
aliguori5bb79102008-10-13 03:12:02 +0000253{
aliguori34c9dd82008-10-13 03:14:31 +0000254 const char *p;
255
Juan Quintela7cf1fe62015-05-20 17:15:42 +0200256 qapi_event_send_migration(MIGRATION_STATUS_SETUP, &error_abort);
Dr. David Alan Gilbertadde2202015-02-19 11:40:27 +0000257 if (!strcmp(uri, "defer")) {
258 deferred_incoming_migration(errp);
259 } else if (strstart(uri, "tcp:", &p)) {
Paolo Bonzini43eaae22012-10-02 18:21:18 +0200260 tcp_start_incoming_migration(p, errp);
Michael R. Hines2da776d2013-07-22 10:01:54 -0400261#ifdef CONFIG_RDMA
Dr. David Alan Gilbertadde2202015-02-19 11:40:27 +0000262 } else if (strstart(uri, "rdma:", &p)) {
Michael R. Hines2da776d2013-07-22 10:01:54 -0400263 rdma_start_incoming_migration(p, errp);
264#endif
aliguori065e2812008-11-11 16:46:33 +0000265#if !defined(WIN32)
Dr. David Alan Gilbertadde2202015-02-19 11:40:27 +0000266 } else if (strstart(uri, "exec:", &p)) {
Paolo Bonzini43eaae22012-10-02 18:21:18 +0200267 exec_start_incoming_migration(p, errp);
Dr. David Alan Gilbertadde2202015-02-19 11:40:27 +0000268 } else if (strstart(uri, "unix:", &p)) {
Paolo Bonzini43eaae22012-10-02 18:21:18 +0200269 unix_start_incoming_migration(p, errp);
Dr. David Alan Gilbertadde2202015-02-19 11:40:27 +0000270 } else if (strstart(uri, "fd:", &p)) {
Paolo Bonzini43eaae22012-10-02 18:21:18 +0200271 fd_start_incoming_migration(p, errp);
aliguori065e2812008-11-11 16:46:33 +0000272#endif
Dr. David Alan Gilbertadde2202015-02-19 11:40:27 +0000273 } else {
Markus Armbruster312fd5f2013-02-08 21:22:16 +0100274 error_setg(errp, "unknown migration protocol: %s", uri);
Juan Quintela8ca5e802010-06-09 14:10:54 +0200275 }
aliguori5bb79102008-10-13 03:12:02 +0000276}
277
Paolo Bonzini82a4da72012-08-07 10:57:43 +0200278static void process_incoming_migration_co(void *opaque)
Juan Quintela511c0232010-06-09 14:10:55 +0200279{
Paolo Bonzini82a4da72012-08-07 10:57:43 +0200280 QEMUFile *f = opaque;
Kevin Wolf5a8a30d2014-03-12 15:59:16 +0100281 Error *local_err = NULL;
Paolo Bonzini1c12e1f2012-08-07 10:51:51 +0200282 int ret;
283
Dr. David Alan Gilbertbca78562015-05-21 13:24:14 +0100284 migration_incoming_state_new(f);
Juan Quintela7cf1fe62015-05-20 17:15:42 +0200285 migrate_generate_event(MIGRATION_STATUS_ACTIVE);
Paolo Bonzini1c12e1f2012-08-07 10:51:51 +0200286 ret = qemu_loadvm_state(f);
Dr. David Alan Gilbertbca78562015-05-21 13:24:14 +0100287
Paolo Bonzini1c12e1f2012-08-07 10:51:51 +0200288 qemu_fclose(f);
Gonglei (Arei)905f26f2014-01-30 20:08:35 +0200289 free_xbzrle_decoded_buf();
Dr. David Alan Gilbertbca78562015-05-21 13:24:14 +0100290 migration_incoming_state_destroy();
291
Paolo Bonzini1c12e1f2012-08-07 10:51:51 +0200292 if (ret < 0) {
Juan Quintela7cf1fe62015-05-20 17:15:42 +0200293 migrate_generate_event(MIGRATION_STATUS_FAILED);
Peter Lievendb80fac2014-06-10 11:29:16 +0200294 error_report("load of migration failed: %s", strerror(-ret));
Liang Li3fcb38c2015-03-23 16:32:18 +0800295 migrate_decompress_threads_join();
Eric Blake4aead692013-04-16 15:50:41 -0600296 exit(EXIT_FAILURE);
Juan Quintela511c0232010-06-09 14:10:55 +0200297 }
Juan Quintela511c0232010-06-09 14:10:55 +0200298
Anthony Liguori0f154232011-11-14 15:09:45 -0600299 /* Make sure all file formats flush their mutable metadata */
Kevin Wolf5a8a30d2014-03-12 15:59:16 +0100300 bdrv_invalidate_cache_all(&local_err);
301 if (local_err) {
Dr. David Alan Gilberted1f3e02015-10-13 12:21:27 +0100302 migrate_generate_event(MIGRATION_STATUS_FAILED);
Markus Armbruster97baf9d2015-02-18 19:21:52 +0100303 error_report_err(local_err);
Liang Li3fcb38c2015-03-23 16:32:18 +0800304 migrate_decompress_threads_join();
Kevin Wolf5a8a30d2014-03-12 15:59:16 +0100305 exit(EXIT_FAILURE);
306 }
Anthony Liguori0f154232011-11-14 15:09:45 -0600307
Amit Shah92e37622015-10-14 17:37:19 +0530308 /*
309 * This must happen after all error conditions are dealt with and
310 * we're sure the VM is going to be running on this host.
311 */
312 qemu_announce_self();
313
Juan Quintela172c4352015-07-08 13:56:26 +0200314 /* If global state section was not received or we are in running
315 state, we need to obey autostart. Any other state is set with
316 runstate_set. */
Juan Quinteladf4b1022014-10-08 10:58:10 +0200317
Juan Quintela172c4352015-07-08 13:56:26 +0200318 if (!global_state_received() ||
319 global_state_get_runstate() == RUN_STATE_RUNNING) {
Juan Quinteladf4b1022014-10-08 10:58:10 +0200320 if (autostart) {
321 vm_start();
322 } else {
323 runstate_set(RUN_STATE_PAUSED);
324 }
Juan Quintela172c4352015-07-08 13:56:26 +0200325 } else {
326 runstate_set(global_state_get_runstate());
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300327 }
Liang Li3fcb38c2015-03-23 16:32:18 +0800328 migrate_decompress_threads_join();
Dr. David Alan Gilberted1f3e02015-10-13 12:21:27 +0100329 /*
330 * This must happen after any state changes since as soon as an external
331 * observer sees this event they might start to prod at the VM assuming
332 * it's ready to use.
333 */
334 migrate_generate_event(MIGRATION_STATUS_COMPLETED);
Juan Quintela511c0232010-06-09 14:10:55 +0200335}
336
Paolo Bonzini82a4da72012-08-07 10:57:43 +0200337void process_incoming_migration(QEMUFile *f)
338{
339 Coroutine *co = qemu_coroutine_create(process_incoming_migration_co);
340 int fd = qemu_get_fd(f);
341
342 assert(fd != -1);
Liang Li3fcb38c2015-03-23 16:32:18 +0800343 migrate_decompress_threads_create();
Stefan Hajnoczif9e8cac2013-03-27 10:10:43 +0100344 qemu_set_nonblock(fd);
Paolo Bonzini82a4da72012-08-07 10:57:43 +0200345 qemu_coroutine_enter(co, f);
346}
347
Dr. David Alan Gilbert6decec92015-11-05 18:10:47 +0000348/*
349 * Send a message on the return channel back to the source
350 * of the migration.
351 */
352void migrate_send_rp_message(MigrationIncomingState *mis,
353 enum mig_rp_message_type message_type,
354 uint16_t len, void *data)
355{
356 trace_migrate_send_rp_message((int)message_type, len);
357 qemu_mutex_lock(&mis->rp_mutex);
358 qemu_put_be16(mis->to_src_file, (unsigned int)message_type);
359 qemu_put_be16(mis->to_src_file, len);
360 qemu_put_buffer(mis->to_src_file, data, len);
361 qemu_fflush(mis->to_src_file);
362 qemu_mutex_unlock(&mis->rp_mutex);
363}
364
365/*
366 * Send a 'SHUT' message on the return channel with the given value
367 * to indicate that we've finished with the RP. Non-0 value indicates
368 * error.
369 */
370void migrate_send_rp_shut(MigrationIncomingState *mis,
371 uint32_t value)
372{
373 uint32_t buf;
374
375 buf = cpu_to_be32(value);
376 migrate_send_rp_message(mis, MIG_RP_MSG_SHUT, sizeof(buf), &buf);
377}
378
379/*
380 * Send a 'PONG' message on the return channel with the given value
381 * (normally in response to a 'PING')
382 */
383void migrate_send_rp_pong(MigrationIncomingState *mis,
384 uint32_t value)
385{
386 uint32_t buf;
387
388 buf = cpu_to_be32(value);
389 migrate_send_rp_message(mis, MIG_RP_MSG_PONG, sizeof(buf), &buf);
390}
391
Glauber Costaa0a3fd62009-05-28 15:22:57 -0400392/* amount of nanoseconds we are willing to wait for migration to be down.
393 * the choice of nanoseconds is because it is the maximum resolution that
394 * get_clock() can achieve. It is an internal measure. All user-visible
395 * units must be in seconds */
Alexey Kardashevskiyf7cd55a2014-03-27 14:57:26 +1100396static uint64_t max_downtime = 300000000;
Glauber Costaa0a3fd62009-05-28 15:22:57 -0400397
398uint64_t migrate_max_downtime(void)
399{
400 return max_downtime;
401}
402
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300403MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp)
404{
405 MigrationCapabilityStatusList *head = NULL;
406 MigrationCapabilityStatusList *caps;
407 MigrationState *s = migrate_get_current();
408 int i;
409
Michael Tokarev387eede2013-10-05 13:18:28 +0400410 caps = NULL; /* silence compiler warning */
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300411 for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
412 if (head == NULL) {
413 head = g_malloc0(sizeof(*caps));
414 caps = head;
415 } else {
416 caps->next = g_malloc0(sizeof(*caps));
417 caps = caps->next;
418 }
419 caps->value =
420 g_malloc(sizeof(*caps->value));
421 caps->value->capability = i;
422 caps->value->state = s->enabled_capabilities[i];
423 }
424
425 return head;
426}
427
Liang Li85de8322015-03-23 16:32:28 +0800428MigrationParameters *qmp_query_migrate_parameters(Error **errp)
429{
430 MigrationParameters *params;
431 MigrationState *s = migrate_get_current();
432
433 params = g_malloc0(sizeof(*params));
434 params->compress_level = s->parameters[MIGRATION_PARAMETER_COMPRESS_LEVEL];
435 params->compress_threads =
436 s->parameters[MIGRATION_PARAMETER_COMPRESS_THREADS];
437 params->decompress_threads =
438 s->parameters[MIGRATION_PARAMETER_DECOMPRESS_THREADS];
Jason J. Herne1626fee2015-09-08 13:12:34 -0400439 params->x_cpu_throttle_initial =
440 s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL];
441 params->x_cpu_throttle_increment =
442 s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT];
Liang Li85de8322015-03-23 16:32:28 +0800443
444 return params;
445}
446
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300447static void get_xbzrle_cache_stats(MigrationInfo *info)
448{
449 if (migrate_use_xbzrle()) {
450 info->has_xbzrle_cache = true;
451 info->xbzrle_cache = g_malloc0(sizeof(*info->xbzrle_cache));
452 info->xbzrle_cache->cache_size = migrate_xbzrle_cache_size();
453 info->xbzrle_cache->bytes = xbzrle_mig_bytes_transferred();
454 info->xbzrle_cache->pages = xbzrle_mig_pages_transferred();
455 info->xbzrle_cache->cache_miss = xbzrle_mig_pages_cache_miss();
ChenLiang8bc39232014-04-04 17:57:56 +0800456 info->xbzrle_cache->cache_miss_rate = xbzrle_mig_cache_miss_rate();
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300457 info->xbzrle_cache->overflow = xbzrle_mig_pages_overflow();
458 }
459}
460
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300461MigrationInfo *qmp_query_migrate(Error **errp)
aliguori5bb79102008-10-13 03:12:02 +0000462{
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300463 MigrationInfo *info = g_malloc0(sizeof(*info));
Juan Quintela17549e82011-10-05 13:50:43 +0200464 MigrationState *s = migrate_get_current();
aliguori376253e2009-03-05 23:01:23 +0000465
Juan Quintela17549e82011-10-05 13:50:43 +0200466 switch (s->state) {
zhanghailiang31194732015-03-13 16:08:38 +0800467 case MIGRATION_STATUS_NONE:
Juan Quintela17549e82011-10-05 13:50:43 +0200468 /* no migration has happened ever */
469 break;
zhanghailiang31194732015-03-13 16:08:38 +0800470 case MIGRATION_STATUS_SETUP:
Michael R. Hines29ae8a42013-07-22 10:01:57 -0400471 info->has_status = true;
Michael R. Hinesed4fbd12013-07-22 10:01:58 -0400472 info->has_total_time = false;
Michael R. Hines29ae8a42013-07-22 10:01:57 -0400473 break;
zhanghailiang31194732015-03-13 16:08:38 +0800474 case MIGRATION_STATUS_ACTIVE:
475 case MIGRATION_STATUS_CANCELLING:
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300476 info->has_status = true;
Juan Quintela7aa939a2012-08-18 13:17:10 +0200477 info->has_total_time = true;
Alex Blighbc72ad62013-08-21 16:03:08 +0100478 info->total_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME)
Juan Quintela7aa939a2012-08-18 13:17:10 +0200479 - s->total_time;
Juan Quintela2c52ddf2012-08-13 09:53:12 +0200480 info->has_expected_downtime = true;
481 info->expected_downtime = s->expected_downtime;
Michael R. Hinesed4fbd12013-07-22 10:01:58 -0400482 info->has_setup_time = true;
483 info->setup_time = s->setup_time;
Luiz Capitulinoc86a6682009-12-10 17:16:05 -0200484
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300485 info->has_ram = true;
486 info->ram = g_malloc0(sizeof(*info->ram));
487 info->ram->transferred = ram_bytes_transferred();
488 info->ram->remaining = ram_bytes_remaining();
489 info->ram->total = ram_bytes_total();
Orit Wasserman004d4c12012-08-06 21:42:56 +0300490 info->ram->duplicate = dup_mig_pages_transferred();
Peter Lievenf1c72792013-03-26 10:58:37 +0100491 info->ram->skipped = skipped_mig_pages_transferred();
Orit Wasserman004d4c12012-08-06 21:42:56 +0300492 info->ram->normal = norm_mig_pages_transferred();
493 info->ram->normal_bytes = norm_mig_bytes_transferred();
Juan Quintela8d017192012-08-13 12:31:25 +0200494 info->ram->dirty_pages_rate = s->dirty_pages_rate;
Michael R. Hines7e114f82013-06-25 21:35:30 -0400495 info->ram->mbps = s->mbps;
ChenLiang58570ed2014-04-04 17:57:55 +0800496 info->ram->dirty_sync_count = s->dirty_sync_count;
Juan Quintela8d017192012-08-13 12:31:25 +0200497
Juan Quintela17549e82011-10-05 13:50:43 +0200498 if (blk_mig_active()) {
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300499 info->has_disk = true;
500 info->disk = g_malloc0(sizeof(*info->disk));
501 info->disk->transferred = blk_mig_bytes_transferred();
502 info->disk->remaining = blk_mig_bytes_remaining();
503 info->disk->total = blk_mig_bytes_total();
aliguoriff8d81d2008-10-24 22:10:31 +0000504 }
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300505
Jason J. Herne47828932015-09-08 13:12:36 -0400506 if (cpu_throttle_active()) {
507 info->has_x_cpu_throttle_percentage = true;
508 info->x_cpu_throttle_percentage = cpu_throttle_get_percentage();
509 }
510
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300511 get_xbzrle_cache_stats(info);
Juan Quintela17549e82011-10-05 13:50:43 +0200512 break;
zhanghailiang31194732015-03-13 16:08:38 +0800513 case MIGRATION_STATUS_COMPLETED:
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300514 get_xbzrle_cache_stats(info);
515
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300516 info->has_status = true;
Pawit Pornkitprasan00c14992013-07-19 11:23:45 +0900517 info->has_total_time = true;
Juan Quintela7aa939a2012-08-18 13:17:10 +0200518 info->total_time = s->total_time;
Juan Quintela9c5a9fc2012-08-13 09:35:16 +0200519 info->has_downtime = true;
520 info->downtime = s->downtime;
Michael R. Hinesed4fbd12013-07-22 10:01:58 -0400521 info->has_setup_time = true;
522 info->setup_time = s->setup_time;
Juan Quintelad5f8a572012-05-21 22:01:07 +0200523
524 info->has_ram = true;
525 info->ram = g_malloc0(sizeof(*info->ram));
526 info->ram->transferred = ram_bytes_transferred();
527 info->ram->remaining = 0;
528 info->ram->total = ram_bytes_total();
Orit Wasserman004d4c12012-08-06 21:42:56 +0300529 info->ram->duplicate = dup_mig_pages_transferred();
Peter Lievenf1c72792013-03-26 10:58:37 +0100530 info->ram->skipped = skipped_mig_pages_transferred();
Orit Wasserman004d4c12012-08-06 21:42:56 +0300531 info->ram->normal = norm_mig_pages_transferred();
532 info->ram->normal_bytes = norm_mig_bytes_transferred();
Michael R. Hines7e114f82013-06-25 21:35:30 -0400533 info->ram->mbps = s->mbps;
ChenLiang58570ed2014-04-04 17:57:55 +0800534 info->ram->dirty_sync_count = s->dirty_sync_count;
Juan Quintela17549e82011-10-05 13:50:43 +0200535 break;
zhanghailiang31194732015-03-13 16:08:38 +0800536 case MIGRATION_STATUS_FAILED:
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300537 info->has_status = true;
Juan Quintela17549e82011-10-05 13:50:43 +0200538 break;
zhanghailiang31194732015-03-13 16:08:38 +0800539 case MIGRATION_STATUS_CANCELLED:
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300540 info->has_status = true;
Juan Quintela17549e82011-10-05 13:50:43 +0200541 break;
aliguori5bb79102008-10-13 03:12:02 +0000542 }
zhanghailiangcde63fb2015-03-13 16:08:41 +0800543 info->status = s->state;
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300544
545 return info;
aliguori5bb79102008-10-13 03:12:02 +0000546}
547
Orit Wasserman00458432012-08-06 21:42:48 +0300548void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
549 Error **errp)
550{
551 MigrationState *s = migrate_get_current();
552 MigrationCapabilityStatusList *cap;
553
zhanghailiang31194732015-03-13 16:08:38 +0800554 if (s->state == MIGRATION_STATUS_ACTIVE ||
555 s->state == MIGRATION_STATUS_SETUP) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100556 error_setg(errp, QERR_MIGRATION_ACTIVE);
Orit Wasserman00458432012-08-06 21:42:48 +0300557 return;
558 }
559
560 for (cap = params; cap; cap = cap->next) {
561 s->enabled_capabilities[cap->value->capability] = cap->value->state;
562 }
563}
564
Liang Li85de8322015-03-23 16:32:28 +0800565void qmp_migrate_set_parameters(bool has_compress_level,
566 int64_t compress_level,
567 bool has_compress_threads,
568 int64_t compress_threads,
569 bool has_decompress_threads,
Jason J. Herne1626fee2015-09-08 13:12:34 -0400570 int64_t decompress_threads,
571 bool has_x_cpu_throttle_initial,
572 int64_t x_cpu_throttle_initial,
573 bool has_x_cpu_throttle_increment,
574 int64_t x_cpu_throttle_increment, Error **errp)
Liang Li85de8322015-03-23 16:32:28 +0800575{
576 MigrationState *s = migrate_get_current();
577
578 if (has_compress_level && (compress_level < 0 || compress_level > 9)) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100579 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_level",
580 "is invalid, it should be in the range of 0 to 9");
Liang Li85de8322015-03-23 16:32:28 +0800581 return;
582 }
583 if (has_compress_threads &&
584 (compress_threads < 1 || compress_threads > 255)) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100585 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
586 "compress_threads",
587 "is invalid, it should be in the range of 1 to 255");
Liang Li85de8322015-03-23 16:32:28 +0800588 return;
589 }
590 if (has_decompress_threads &&
591 (decompress_threads < 1 || decompress_threads > 255)) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100592 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
593 "decompress_threads",
594 "is invalid, it should be in the range of 1 to 255");
Liang Li85de8322015-03-23 16:32:28 +0800595 return;
596 }
Jason J. Herne1626fee2015-09-08 13:12:34 -0400597 if (has_x_cpu_throttle_initial &&
598 (x_cpu_throttle_initial < 1 || x_cpu_throttle_initial > 99)) {
599 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
600 "x_cpu_throttle_initial",
601 "an integer in the range of 1 to 99");
602 }
603 if (has_x_cpu_throttle_increment &&
604 (x_cpu_throttle_increment < 1 || x_cpu_throttle_increment > 99)) {
605 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
606 "x_cpu_throttle_increment",
607 "an integer in the range of 1 to 99");
608 }
Liang Li85de8322015-03-23 16:32:28 +0800609
610 if (has_compress_level) {
611 s->parameters[MIGRATION_PARAMETER_COMPRESS_LEVEL] = compress_level;
612 }
613 if (has_compress_threads) {
614 s->parameters[MIGRATION_PARAMETER_COMPRESS_THREADS] = compress_threads;
615 }
616 if (has_decompress_threads) {
617 s->parameters[MIGRATION_PARAMETER_DECOMPRESS_THREADS] =
618 decompress_threads;
619 }
Jason J. Herne1626fee2015-09-08 13:12:34 -0400620 if (has_x_cpu_throttle_initial) {
621 s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL] =
622 x_cpu_throttle_initial;
623 }
624
625 if (has_x_cpu_throttle_increment) {
626 s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT] =
627 x_cpu_throttle_increment;
628 }
Liang Li85de8322015-03-23 16:32:28 +0800629}
630
aliguori065e2812008-11-11 16:46:33 +0000631/* shared migration helpers */
632
Zhanghaoyu (A)51cf4c12013-11-07 11:01:15 +0000633static void migrate_set_state(MigrationState *s, int old_state, int new_state)
634{
Juan Quintelaa5c17b52015-06-17 02:06:20 +0200635 if (atomic_cmpxchg(&s->state, old_state, new_state) == old_state) {
Juan Quintela4ba4bc52015-07-08 13:58:27 +0200636 trace_migrate_set_state(new_state);
Juan Quintelab05dc722015-07-07 14:44:05 +0200637 migrate_generate_event(new_state);
Zhanghaoyu (A)51cf4c12013-11-07 11:01:15 +0000638 }
639}
640
Paolo Bonzinibb1fadc2013-02-22 17:36:21 +0100641static void migrate_fd_cleanup(void *opaque)
aliguori065e2812008-11-11 16:46:33 +0000642{
Paolo Bonzinibb1fadc2013-02-22 17:36:21 +0100643 MigrationState *s = opaque;
644
645 qemu_bh_delete(s->cleanup_bh);
646 s->cleanup_bh = NULL;
647
aliguori065e2812008-11-11 16:46:33 +0000648 if (s->file) {
Alexey Kardashevskiy9013dca2014-03-11 10:42:29 +1100649 trace_migrate_fd_cleanup();
Paolo Bonzini404a7c02013-02-22 17:36:46 +0100650 qemu_mutex_unlock_iothread();
651 qemu_thread_join(&s->thread);
652 qemu_mutex_lock_iothread();
653
Liang Li8706d2d2015-03-23 16:32:17 +0800654 migrate_compress_threads_join();
Paolo Bonzini6f190a02013-02-22 17:36:48 +0100655 qemu_fclose(s->file);
656 s->file = NULL;
aliguori065e2812008-11-11 16:46:33 +0000657 }
658
zhanghailiang31194732015-03-13 16:08:38 +0800659 assert(s->state != MIGRATION_STATUS_ACTIVE);
Paolo Bonzini7a2c1722013-02-22 17:36:09 +0100660
Liang Li94f5a432015-11-02 15:37:00 +0800661 if (s->state == MIGRATION_STATUS_CANCELLING) {
662 migrate_set_state(s, MIGRATION_STATUS_CANCELLING,
663 MIGRATION_STATUS_CANCELLED);
Paolo Bonzini7a2c1722013-02-22 17:36:09 +0100664 }
Paolo Bonzinia3fa1d72013-02-22 17:36:18 +0100665
666 notifier_list_notify(&migration_state_notifiers, s);
aliguori065e2812008-11-11 16:46:33 +0000667}
668
Juan Quintela8b6b99b2011-09-11 20:28:22 +0200669void migrate_fd_error(MigrationState *s)
aliguori065e2812008-11-11 16:46:33 +0000670{
Alexey Kardashevskiy9013dca2014-03-11 10:42:29 +1100671 trace_migrate_fd_error();
Paolo Bonzinibb1fadc2013-02-22 17:36:21 +0100672 assert(s->file == NULL);
Juan Quintela78443372015-06-17 01:36:40 +0200673 migrate_set_state(s, MIGRATION_STATUS_SETUP, MIGRATION_STATUS_FAILED);
Paolo Bonzinibb1fadc2013-02-22 17:36:21 +0100674 notifier_list_notify(&migration_state_notifiers, s);
Juan Quintela458cf282011-02-22 23:32:54 +0100675}
676
Juan Quintela0edda1c2010-05-11 16:28:39 +0200677static void migrate_fd_cancel(MigrationState *s)
aliguori065e2812008-11-11 16:46:33 +0000678{
Zhanghaoyu (A)6f2b8112013-11-07 08:21:23 +0000679 int old_state ;
Dr. David Alan Gilberta26ba262015-01-08 11:11:32 +0000680 QEMUFile *f = migrate_get_current()->file;
Alexey Kardashevskiy9013dca2014-03-11 10:42:29 +1100681 trace_migrate_fd_cancel();
aliguori065e2812008-11-11 16:46:33 +0000682
Zhanghaoyu (A)6f2b8112013-11-07 08:21:23 +0000683 do {
684 old_state = s->state;
zhanghailiang31194732015-03-13 16:08:38 +0800685 if (old_state != MIGRATION_STATUS_SETUP &&
686 old_state != MIGRATION_STATUS_ACTIVE) {
Zhanghaoyu (A)6f2b8112013-11-07 08:21:23 +0000687 break;
688 }
zhanghailiang31194732015-03-13 16:08:38 +0800689 migrate_set_state(s, old_state, MIGRATION_STATUS_CANCELLING);
690 } while (s->state != MIGRATION_STATUS_CANCELLING);
Dr. David Alan Gilberta26ba262015-01-08 11:11:32 +0000691
692 /*
693 * If we're unlucky the migration code might be stuck somewhere in a
694 * send/write while the network has failed and is waiting to timeout;
695 * if we've got shutdown(2) available then we can force it to quit.
696 * The outgoing qemu file gets closed in migrate_fd_cleanup that is
697 * called in a bh, so there is no race against this cancel.
698 */
zhanghailiang31194732015-03-13 16:08:38 +0800699 if (s->state == MIGRATION_STATUS_CANCELLING && f) {
Dr. David Alan Gilberta26ba262015-01-08 11:11:32 +0000700 qemu_file_shutdown(f);
701 }
aliguori065e2812008-11-11 16:46:33 +0000702}
703
Gerd Hoffmann99a0db92010-12-13 17:30:12 +0100704void add_migration_state_change_notifier(Notifier *notify)
705{
706 notifier_list_add(&migration_state_notifiers, notify);
707}
708
709void remove_migration_state_change_notifier(Notifier *notify)
710{
Paolo Bonzini31552522012-01-13 17:34:01 +0100711 notifier_remove(notify);
Gerd Hoffmann99a0db92010-12-13 17:30:12 +0100712}
713
Stefan Hajnoczi02edd2e2013-07-29 15:01:58 +0200714bool migration_in_setup(MigrationState *s)
Gerd Hoffmannafe2df62011-10-25 13:50:11 +0200715{
zhanghailiang31194732015-03-13 16:08:38 +0800716 return s->state == MIGRATION_STATUS_SETUP;
Gerd Hoffmannafe2df62011-10-25 13:50:11 +0200717}
718
Juan Quintela70736932011-02-23 00:43:59 +0100719bool migration_has_finished(MigrationState *s)
Gerd Hoffmann99a0db92010-12-13 17:30:12 +0100720{
zhanghailiang31194732015-03-13 16:08:38 +0800721 return s->state == MIGRATION_STATUS_COMPLETED;
Gerd Hoffmann99a0db92010-12-13 17:30:12 +0100722}
Juan Quintela0edda1c2010-05-11 16:28:39 +0200723
Gerd Hoffmannafe2df62011-10-25 13:50:11 +0200724bool migration_has_failed(MigrationState *s)
725{
zhanghailiang31194732015-03-13 16:08:38 +0800726 return (s->state == MIGRATION_STATUS_CANCELLED ||
727 s->state == MIGRATION_STATUS_FAILED);
Gerd Hoffmannafe2df62011-10-25 13:50:11 +0200728}
729
Dr. David Alan Gilbertaefeb182015-11-05 18:10:40 +0000730MigrationState *migrate_init(const MigrationParams *params)
Juan Quintela0edda1c2010-05-11 16:28:39 +0200731{
Juan Quintela17549e82011-10-05 13:50:43 +0200732 MigrationState *s = migrate_get_current();
Juan Quintelad0ae46c2011-02-23 00:33:19 +0100733 int64_t bandwidth_limit = s->bandwidth_limit;
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300734 bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300735 int64_t xbzrle_cache_size = s->xbzrle_cache_size;
Liang Li43c60a82015-03-23 16:32:27 +0800736 int compress_level = s->parameters[MIGRATION_PARAMETER_COMPRESS_LEVEL];
737 int compress_thread_count =
738 s->parameters[MIGRATION_PARAMETER_COMPRESS_THREADS];
739 int decompress_thread_count =
740 s->parameters[MIGRATION_PARAMETER_DECOMPRESS_THREADS];
Jason J. Herne1626fee2015-09-08 13:12:34 -0400741 int x_cpu_throttle_initial =
742 s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL];
743 int x_cpu_throttle_increment =
744 s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT];
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300745
746 memcpy(enabled_capabilities, s->enabled_capabilities,
747 sizeof(enabled_capabilities));
Juan Quintela0edda1c2010-05-11 16:28:39 +0200748
Juan Quintela17549e82011-10-05 13:50:43 +0200749 memset(s, 0, sizeof(*s));
Isaku Yamahata6607ae22012-06-19 18:43:09 +0300750 s->params = *params;
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300751 memcpy(s->enabled_capabilities, enabled_capabilities,
752 sizeof(enabled_capabilities));
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300753 s->xbzrle_cache_size = xbzrle_cache_size;
Juan Quintela1299c632011-11-09 21:29:01 +0100754
Liang Li43c60a82015-03-23 16:32:27 +0800755 s->parameters[MIGRATION_PARAMETER_COMPRESS_LEVEL] = compress_level;
756 s->parameters[MIGRATION_PARAMETER_COMPRESS_THREADS] =
757 compress_thread_count;
758 s->parameters[MIGRATION_PARAMETER_DECOMPRESS_THREADS] =
759 decompress_thread_count;
Jason J. Herne1626fee2015-09-08 13:12:34 -0400760 s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL] =
761 x_cpu_throttle_initial;
762 s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT] =
763 x_cpu_throttle_increment;
Juan Quintela0edda1c2010-05-11 16:28:39 +0200764 s->bandwidth_limit = bandwidth_limit;
Juan Quintela78443372015-06-17 01:36:40 +0200765 migrate_set_state(s, MIGRATION_STATUS_NONE, MIGRATION_STATUS_SETUP);
Juan Quintela0edda1c2010-05-11 16:28:39 +0200766
Alex Blighbc72ad62013-08-21 16:03:08 +0100767 s->total_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
Juan Quintela0edda1c2010-05-11 16:28:39 +0200768 return s;
769}
Juan Quintelacab30142011-02-22 23:54:21 +0100770
Anthony Liguorifa2756b2011-11-14 15:09:43 -0600771static GSList *migration_blockers;
772
773void migrate_add_blocker(Error *reason)
774{
775 migration_blockers = g_slist_prepend(migration_blockers, reason);
776}
777
778void migrate_del_blocker(Error *reason)
779{
780 migration_blockers = g_slist_remove(migration_blockers, reason);
781}
782
Dr. David Alan Gilbertbf1ae1f2015-02-19 11:40:28 +0000783void qmp_migrate_incoming(const char *uri, Error **errp)
784{
785 Error *local_err = NULL;
Dr. David Alan Gilbert4debb5f2015-02-26 14:54:41 +0000786 static bool once = true;
Dr. David Alan Gilbertbf1ae1f2015-02-19 11:40:28 +0000787
788 if (!deferred_incoming) {
Dr. David Alan Gilbert4debb5f2015-02-26 14:54:41 +0000789 error_setg(errp, "For use with '-incoming defer'");
Dr. David Alan Gilbertbf1ae1f2015-02-19 11:40:28 +0000790 return;
791 }
Dr. David Alan Gilbert4debb5f2015-02-26 14:54:41 +0000792 if (!once) {
793 error_setg(errp, "The incoming migration has already been started");
794 }
Dr. David Alan Gilbertbf1ae1f2015-02-19 11:40:28 +0000795
796 qemu_start_incoming_migration(uri, &local_err);
797
798 if (local_err) {
799 error_propagate(errp, local_err);
800 return;
801 }
802
Dr. David Alan Gilbert4debb5f2015-02-26 14:54:41 +0000803 once = false;
Dr. David Alan Gilbertbf1ae1f2015-02-19 11:40:28 +0000804}
805
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -0200806void qmp_migrate(const char *uri, bool has_blk, bool blk,
807 bool has_inc, bool inc, bool has_detach, bool detach,
808 Error **errp)
Juan Quintelacab30142011-02-22 23:54:21 +0100809{
Paolo Bonzinibe7059c2012-10-03 14:34:33 +0200810 Error *local_err = NULL;
Juan Quintela17549e82011-10-05 13:50:43 +0200811 MigrationState *s = migrate_get_current();
Isaku Yamahata6607ae22012-06-19 18:43:09 +0300812 MigrationParams params;
Juan Quintelacab30142011-02-22 23:54:21 +0100813 const char *p;
Juan Quintelacab30142011-02-22 23:54:21 +0100814
Pawit Pornkitprasan8c0426a2013-07-30 08:39:52 +0900815 params.blk = has_blk && blk;
816 params.shared = has_inc && inc;
Isaku Yamahata6607ae22012-06-19 18:43:09 +0300817
zhanghailiang31194732015-03-13 16:08:38 +0800818 if (s->state == MIGRATION_STATUS_ACTIVE ||
819 s->state == MIGRATION_STATUS_SETUP ||
820 s->state == MIGRATION_STATUS_CANCELLING) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100821 error_setg(errp, QERR_MIGRATION_ACTIVE);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -0200822 return;
Juan Quintelacab30142011-02-22 23:54:21 +0100823 }
Dr. David Alan Gilbertca999932014-04-14 17:03:59 +0100824 if (runstate_check(RUN_STATE_INMIGRATE)) {
825 error_setg(errp, "Guest is waiting for an incoming migration");
826 return;
827 }
828
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -0200829 if (qemu_savevm_state_blocked(errp)) {
830 return;
Juan Quintelacab30142011-02-22 23:54:21 +0100831 }
832
Anthony Liguorifa2756b2011-11-14 15:09:43 -0600833 if (migration_blockers) {
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -0200834 *errp = error_copy(migration_blockers->data);
835 return;
Anthony Liguorifa2756b2011-11-14 15:09:43 -0600836 }
837
Juan Quintela656a2332015-07-01 09:32:29 +0200838 /* We are starting a new migration, so we want to start in a clean
839 state. This change is only needed if previous migration
840 failed/was cancelled. We don't use migrate_set_state() because
841 we are setting the initial state, not changing it. */
842 s->state = MIGRATION_STATUS_NONE;
843
Isaku Yamahata6607ae22012-06-19 18:43:09 +0300844 s = migrate_init(&params);
Juan Quintelacab30142011-02-22 23:54:21 +0100845
846 if (strstart(uri, "tcp:", &p)) {
Paolo Bonzinif37afb52012-10-02 10:02:46 +0200847 tcp_start_outgoing_migration(s, p, &local_err);
Michael R. Hines2da776d2013-07-22 10:01:54 -0400848#ifdef CONFIG_RDMA
Michael R. Hines41310c62013-12-19 04:52:01 +0800849 } else if (strstart(uri, "rdma:", &p)) {
Michael R. Hines2da776d2013-07-22 10:01:54 -0400850 rdma_start_outgoing_migration(s, p, &local_err);
851#endif
Juan Quintelacab30142011-02-22 23:54:21 +0100852#if !defined(WIN32)
853 } else if (strstart(uri, "exec:", &p)) {
Paolo Bonzinif37afb52012-10-02 10:02:46 +0200854 exec_start_outgoing_migration(s, p, &local_err);
Juan Quintelacab30142011-02-22 23:54:21 +0100855 } else if (strstart(uri, "unix:", &p)) {
Paolo Bonzinif37afb52012-10-02 10:02:46 +0200856 unix_start_outgoing_migration(s, p, &local_err);
Juan Quintelacab30142011-02-22 23:54:21 +0100857 } else if (strstart(uri, "fd:", &p)) {
Paolo Bonzinif37afb52012-10-02 10:02:46 +0200858 fd_start_outgoing_migration(s, p, &local_err);
Juan Quintelacab30142011-02-22 23:54:21 +0100859#endif
860 } else {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100861 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "uri",
862 "a valid migration protocol");
Juan Quintela78443372015-06-17 01:36:40 +0200863 migrate_set_state(s, MIGRATION_STATUS_SETUP, MIGRATION_STATUS_FAILED);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -0200864 return;
Juan Quintelacab30142011-02-22 23:54:21 +0100865 }
866
Paolo Bonzinif37afb52012-10-02 10:02:46 +0200867 if (local_err) {
Paolo Bonzini342ab8d2012-10-02 09:59:38 +0200868 migrate_fd_error(s);
Paolo Bonzinif37afb52012-10-02 10:02:46 +0200869 error_propagate(errp, local_err);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -0200870 return;
Juan Quintela1299c632011-11-09 21:29:01 +0100871 }
Juan Quintelacab30142011-02-22 23:54:21 +0100872}
873
Luiz Capitulino6cdedb02011-11-27 22:54:09 -0200874void qmp_migrate_cancel(Error **errp)
Juan Quintelacab30142011-02-22 23:54:21 +0100875{
Juan Quintela17549e82011-10-05 13:50:43 +0200876 migrate_fd_cancel(migrate_get_current());
Juan Quintelacab30142011-02-22 23:54:21 +0100877}
878
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +0300879void qmp_migrate_set_cache_size(int64_t value, Error **errp)
880{
881 MigrationState *s = migrate_get_current();
Orit Wassermanc91e6812014-01-30 20:08:34 +0200882 int64_t new_size;
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +0300883
884 /* Check for truncation */
885 if (value != (size_t)value) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100886 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
887 "exceeding address space");
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +0300888 return;
889 }
890
Orit Wassermana5615b12014-01-30 20:08:36 +0200891 /* Cache should not be larger than guest ram size */
892 if (value > ram_bytes_total()) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100893 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
894 "exceeds guest ram size ");
Orit Wassermana5615b12014-01-30 20:08:36 +0200895 return;
896 }
897
Orit Wassermanc91e6812014-01-30 20:08:34 +0200898 new_size = xbzrle_cache_resize(value);
899 if (new_size < 0) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100900 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
901 "is smaller than page size");
Orit Wassermanc91e6812014-01-30 20:08:34 +0200902 return;
903 }
904
905 s->xbzrle_cache_size = new_size;
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +0300906}
907
908int64_t qmp_query_migrate_cache_size(Error **errp)
909{
910 return migrate_xbzrle_cache_size();
911}
912
Luiz Capitulino3dc85382011-11-28 11:59:37 -0200913void qmp_migrate_set_speed(int64_t value, Error **errp)
Juan Quintelacab30142011-02-22 23:54:21 +0100914{
Juan Quintelacab30142011-02-22 23:54:21 +0100915 MigrationState *s;
916
Luiz Capitulino3dc85382011-11-28 11:59:37 -0200917 if (value < 0) {
918 value = 0;
Juan Quintelacab30142011-02-22 23:54:21 +0100919 }
Paolo Bonzini442773c2013-02-22 17:36:44 +0100920 if (value > SIZE_MAX) {
921 value = SIZE_MAX;
922 }
Juan Quintelacab30142011-02-22 23:54:21 +0100923
Juan Quintela17549e82011-10-05 13:50:43 +0200924 s = migrate_get_current();
Luiz Capitulino3dc85382011-11-28 11:59:37 -0200925 s->bandwidth_limit = value;
Paolo Bonzini442773c2013-02-22 17:36:44 +0100926 if (s->file) {
927 qemu_file_set_rate_limit(s->file, s->bandwidth_limit / XFER_LIMIT_RATIO);
928 }
Juan Quintelacab30142011-02-22 23:54:21 +0100929}
930
Luiz Capitulino4f0a9932011-11-27 23:18:01 -0200931void qmp_migrate_set_downtime(double value, Error **errp)
Juan Quintelacab30142011-02-22 23:54:21 +0100932{
Luiz Capitulino4f0a9932011-11-27 23:18:01 -0200933 value *= 1e9;
934 value = MAX(0, MIN(UINT64_MAX, value));
935 max_downtime = (uint64_t)value;
aliguori5bb79102008-10-13 03:12:02 +0000936}
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300937
Chegu Vinodbde1e2e2013-06-24 03:49:42 -0600938bool migrate_auto_converge(void)
939{
940 MigrationState *s;
941
942 s = migrate_get_current();
943
944 return s->enabled_capabilities[MIGRATION_CAPABILITY_AUTO_CONVERGE];
945}
946
Peter Lieven323004a2013-07-18 09:48:50 +0200947bool migrate_zero_blocks(void)
948{
949 MigrationState *s;
950
951 s = migrate_get_current();
952
953 return s->enabled_capabilities[MIGRATION_CAPABILITY_ZERO_BLOCKS];
954}
955
Liang Li8706d2d2015-03-23 16:32:17 +0800956bool migrate_use_compression(void)
957{
Liang Lidde4e692015-03-23 16:32:26 +0800958 MigrationState *s;
959
960 s = migrate_get_current();
961
962 return s->enabled_capabilities[MIGRATION_CAPABILITY_COMPRESS];
Liang Li8706d2d2015-03-23 16:32:17 +0800963}
964
965int migrate_compress_level(void)
966{
967 MigrationState *s;
968
969 s = migrate_get_current();
970
Liang Li43c60a82015-03-23 16:32:27 +0800971 return s->parameters[MIGRATION_PARAMETER_COMPRESS_LEVEL];
Liang Li8706d2d2015-03-23 16:32:17 +0800972}
973
974int migrate_compress_threads(void)
975{
976 MigrationState *s;
977
978 s = migrate_get_current();
979
Liang Li43c60a82015-03-23 16:32:27 +0800980 return s->parameters[MIGRATION_PARAMETER_COMPRESS_THREADS];
Liang Li8706d2d2015-03-23 16:32:17 +0800981}
982
Liang Li3fcb38c2015-03-23 16:32:18 +0800983int migrate_decompress_threads(void)
984{
985 MigrationState *s;
986
987 s = migrate_get_current();
988
Liang Li43c60a82015-03-23 16:32:27 +0800989 return s->parameters[MIGRATION_PARAMETER_DECOMPRESS_THREADS];
Liang Li3fcb38c2015-03-23 16:32:18 +0800990}
991
Juan Quintelab05dc722015-07-07 14:44:05 +0200992bool migrate_use_events(void)
993{
994 MigrationState *s;
995
996 s = migrate_get_current();
997
998 return s->enabled_capabilities[MIGRATION_CAPABILITY_EVENTS];
999}
1000
Orit Wasserman17ad9b32012-08-06 21:42:53 +03001001int migrate_use_xbzrle(void)
1002{
1003 MigrationState *s;
1004
1005 s = migrate_get_current();
1006
1007 return s->enabled_capabilities[MIGRATION_CAPABILITY_XBZRLE];
1008}
1009
1010int64_t migrate_xbzrle_cache_size(void)
1011{
1012 MigrationState *s;
1013
1014 s = migrate_get_current();
1015
1016 return s->xbzrle_cache_size;
1017}
Juan Quintela0d82d0e2012-10-03 14:18:33 +02001018
Dr. David Alan Gilbert09f6c852015-08-13 11:51:31 +01001019/**
1020 * migration_completion: Used by migration_thread when there's not much left.
1021 * The caller 'breaks' the loop when this returns.
1022 *
1023 * @s: Current migration state
1024 * @*old_vm_running: Pointer to old_vm_running flag
1025 * @*start_time: Pointer to time to update
1026 */
1027static void migration_completion(MigrationState *s, bool *old_vm_running,
1028 int64_t *start_time)
1029{
1030 int ret;
1031
1032 qemu_mutex_lock_iothread();
1033 *start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
1034 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
1035 *old_vm_running = runstate_is_running();
1036
1037 ret = global_state_store();
1038 if (!ret) {
1039 ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
1040 if (ret >= 0) {
1041 qemu_file_set_rate_limit(s->file, INT64_MAX);
Dr. David Alan Gilberta3e06c32015-11-05 18:10:41 +00001042 qemu_savevm_state_complete_precopy(s->file);
Dr. David Alan Gilbert09f6c852015-08-13 11:51:31 +01001043 }
1044 }
1045 qemu_mutex_unlock_iothread();
1046
1047 if (ret < 0) {
1048 goto fail;
1049 }
1050
1051 if (qemu_file_get_error(s->file)) {
1052 trace_migration_completion_file_err();
1053 goto fail;
1054 }
1055
1056 migrate_set_state(s, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_COMPLETED);
1057 return;
1058
1059fail:
1060 migrate_set_state(s, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_FAILED);
1061}
1062
Juan Quintela0d82d0e2012-10-03 14:18:33 +02001063/* migration thread support */
1064
Juan Quintela5f496a12013-02-22 17:36:30 +01001065static void *migration_thread(void *opaque)
Juan Quintela0d82d0e2012-10-03 14:18:33 +02001066{
Juan Quintela9848a402012-12-19 09:55:50 +01001067 MigrationState *s = opaque;
Alex Blighbc72ad62013-08-21 16:03:08 +01001068 int64_t initial_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
1069 int64_t setup_start = qemu_clock_get_ms(QEMU_CLOCK_HOST);
Paolo Bonzinibe7172e2013-02-22 17:36:43 +01001070 int64_t initial_bytes = 0;
Juan Quintela0d82d0e2012-10-03 14:18:33 +02001071 int64_t max_size = 0;
Paolo Bonzinia3fa1d72013-02-22 17:36:18 +01001072 int64_t start_time = initial_time;
Liang Li94f5a432015-11-02 15:37:00 +08001073 int64_t end_time;
Paolo Bonzinia3fa1d72013-02-22 17:36:18 +01001074 bool old_vm_running = false;
Juan Quintela76f59332012-10-03 20:16:24 +02001075
Paolo Bonziniab28bd22015-07-09 08:55:38 +02001076 rcu_register_thread();
1077
Dr. David Alan Gilbertf796baa2015-05-21 13:24:12 +01001078 qemu_savevm_state_header(s->file);
Paolo Bonzinidba433c2013-02-22 17:36:17 +01001079 qemu_savevm_state_begin(s->file, &s->params);
Juan Quintela0d82d0e2012-10-03 14:18:33 +02001080
Alex Blighbc72ad62013-08-21 16:03:08 +01001081 s->setup_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) - setup_start;
zhanghailiang31194732015-03-13 16:08:38 +08001082 migrate_set_state(s, MIGRATION_STATUS_SETUP, MIGRATION_STATUS_ACTIVE);
Michael R. Hines29ae8a42013-07-22 10:01:57 -04001083
zhanghailiang31194732015-03-13 16:08:38 +08001084 while (s->state == MIGRATION_STATUS_ACTIVE) {
Juan Quintelaa3e879c2013-02-01 12:39:08 +01001085 int64_t current_time;
Juan Quintelac369f402012-10-03 20:33:34 +02001086 uint64_t pending_size;
Juan Quintela0d82d0e2012-10-03 14:18:33 +02001087
Paolo Bonzinia0ff0442013-02-22 17:36:35 +01001088 if (!qemu_file_rate_limit(s->file)) {
Juan Quintelac369f402012-10-03 20:33:34 +02001089 pending_size = qemu_savevm_state_pending(s->file, max_size);
Alexey Kardashevskiy9013dca2014-03-11 10:42:29 +11001090 trace_migrate_pending(pending_size, max_size);
Juan Quintelab22ff1f2012-10-17 21:06:31 +02001091 if (pending_size && pending_size >= max_size) {
Paolo Bonzinidba433c2013-02-22 17:36:17 +01001092 qemu_savevm_state_iterate(s->file);
Juan Quintelac369f402012-10-03 20:33:34 +02001093 } else {
Dr. David Alan Gilbert09f6c852015-08-13 11:51:31 +01001094 trace_migration_thread_low_pending(pending_size);
1095 migration_completion(s, &old_vm_running, &start_time);
1096 break;
Juan Quintelac369f402012-10-03 20:33:34 +02001097 }
1098 }
Paolo Bonzinif4410a52013-02-22 17:36:20 +01001099
Paolo Bonzinifd45ee22013-02-22 17:36:33 +01001100 if (qemu_file_get_error(s->file)) {
zhanghailiang31194732015-03-13 16:08:38 +08001101 migrate_set_state(s, MIGRATION_STATUS_ACTIVE,
1102 MIGRATION_STATUS_FAILED);
Paolo Bonzinifd45ee22013-02-22 17:36:33 +01001103 break;
1104 }
Alex Blighbc72ad62013-08-21 16:03:08 +01001105 current_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
Juan Quintela0d82d0e2012-10-03 14:18:33 +02001106 if (current_time >= initial_time + BUFFER_DELAY) {
Paolo Bonzinibe7172e2013-02-22 17:36:43 +01001107 uint64_t transferred_bytes = qemu_ftell(s->file) - initial_bytes;
Michael Roth77417f12013-05-16 16:25:44 -05001108 uint64_t time_spent = current_time - initial_time;
Juan Quintela0d82d0e2012-10-03 14:18:33 +02001109 double bandwidth = transferred_bytes / time_spent;
1110 max_size = bandwidth * migrate_max_downtime() / 1000000;
1111
Michael R. Hines7e114f82013-06-25 21:35:30 -04001112 s->mbps = time_spent ? (((double) transferred_bytes * 8.0) /
1113 ((double) time_spent / 1000.0)) / 1000.0 / 1000.0 : -1;
1114
Alexey Kardashevskiy9013dca2014-03-11 10:42:29 +11001115 trace_migrate_transferred(transferred_bytes, time_spent,
1116 bandwidth, max_size);
Juan Quintela90f8ae72013-02-01 13:22:37 +01001117 /* if we haven't sent anything, we don't want to recalculate
1118 10000 is a small enough number for our purposes */
1119 if (s->dirty_bytes_rate && transferred_bytes > 10000) {
1120 s->expected_downtime = s->dirty_bytes_rate / bandwidth;
1121 }
Juan Quintela0d82d0e2012-10-03 14:18:33 +02001122
Paolo Bonzini1964a392013-02-22 17:36:45 +01001123 qemu_file_reset_rate_limit(s->file);
Juan Quintela0d82d0e2012-10-03 14:18:33 +02001124 initial_time = current_time;
Paolo Bonzinibe7172e2013-02-22 17:36:43 +01001125 initial_bytes = qemu_ftell(s->file);
Juan Quintela0d82d0e2012-10-03 14:18:33 +02001126 }
Paolo Bonzinia0ff0442013-02-22 17:36:35 +01001127 if (qemu_file_rate_limit(s->file)) {
Juan Quintela0d82d0e2012-10-03 14:18:33 +02001128 /* usleep expects microseconds */
1129 g_usleep((initial_time + BUFFER_DELAY - current_time)*1000);
1130 }
Paolo Bonzinia3fa1d72013-02-22 17:36:18 +01001131 }
1132
Jason J. Herne070afca2015-09-08 13:12:35 -04001133 /* If we enabled cpu throttling for auto-converge, turn it off. */
1134 cpu_throttle_stop();
Liang Li94f5a432015-11-02 15:37:00 +08001135 end_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
Jason J. Herne070afca2015-09-08 13:12:35 -04001136
Paolo Bonzinif4410a52013-02-22 17:36:20 +01001137 qemu_mutex_lock_iothread();
Liang Liea7415f2015-11-02 15:37:01 +08001138 qemu_savevm_state_cleanup();
zhanghailiang31194732015-03-13 16:08:38 +08001139 if (s->state == MIGRATION_STATUS_COMPLETED) {
Peter Lievend6ed7312014-05-12 10:46:00 +02001140 uint64_t transferred_bytes = qemu_ftell(s->file);
Paolo Bonzinia3fa1d72013-02-22 17:36:18 +01001141 s->total_time = end_time - s->total_time;
1142 s->downtime = end_time - start_time;
Peter Lievend6ed7312014-05-12 10:46:00 +02001143 if (s->total_time) {
1144 s->mbps = (((double) transferred_bytes * 8.0) /
1145 ((double) s->total_time)) / 1000;
1146 }
Paolo Bonzinia3fa1d72013-02-22 17:36:18 +01001147 runstate_set(RUN_STATE_POSTMIGRATE);
1148 } else {
1149 if (old_vm_running) {
Paolo Bonzinia3fa1d72013-02-22 17:36:18 +01001150 vm_start();
Paolo Bonzinidba433c2013-02-22 17:36:17 +01001151 }
Juan Quintela0d82d0e2012-10-03 14:18:33 +02001152 }
Paolo Bonzinibb1fadc2013-02-22 17:36:21 +01001153 qemu_bh_schedule(s->cleanup_bh);
Paolo Bonzinidba433c2013-02-22 17:36:17 +01001154 qemu_mutex_unlock_iothread();
Paolo Bonzinif4410a52013-02-22 17:36:20 +01001155
Paolo Bonziniab28bd22015-07-09 08:55:38 +02001156 rcu_unregister_thread();
Juan Quintela0d82d0e2012-10-03 14:18:33 +02001157 return NULL;
1158}
1159
Juan Quintela9848a402012-12-19 09:55:50 +01001160void migrate_fd_connect(MigrationState *s)
Juan Quintela0d82d0e2012-10-03 14:18:33 +02001161{
Juan Quintelacc283e32013-02-01 11:12:26 +01001162 /* This is a best 1st approximation. ns to ms */
1163 s->expected_downtime = max_downtime/1000000;
Paolo Bonzinibb1fadc2013-02-22 17:36:21 +01001164 s->cleanup_bh = qemu_bh_new(migrate_fd_cleanup, s);
Juan Quintela0d82d0e2012-10-03 14:18:33 +02001165
Paolo Bonzini442773c2013-02-22 17:36:44 +01001166 qemu_file_set_rate_limit(s->file,
1167 s->bandwidth_limit / XFER_LIMIT_RATIO);
1168
Stefan Hajnoczi9287ac22013-07-29 15:01:57 +02001169 /* Notify before starting migration thread */
1170 notifier_list_notify(&migration_state_notifiers, s);
1171
Liang Li8706d2d2015-03-23 16:32:17 +08001172 migrate_compress_threads_create();
Dr. David Alan Gilbert49001162014-01-30 10:20:32 +00001173 qemu_thread_create(&s->thread, "migration", migration_thread, s,
Paolo Bonzinibb1fadc2013-02-22 17:36:21 +01001174 QEMU_THREAD_JOINABLE);
Juan Quintela0d82d0e2012-10-03 14:18:33 +02001175}