]>
Commit | Line | Data |
---|---|---|
5bb7910a AL |
1 | /* |
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 | * | |
6b620ca3 PB |
12 | * Contributions after 2012-01-13 are licensed under the terms of the |
13 | * GNU GPL, version 2 or (at your option) any later version. | |
5bb7910a AL |
14 | */ |
15 | ||
16 | #include "qemu-common.h" | |
17 | #include "migration.h" | |
376253ec | 18 | #include "monitor.h" |
065e2813 AL |
19 | #include "buffered_file.h" |
20 | #include "sysemu.h" | |
21 | #include "block.h" | |
22 | #include "qemu_socket.h" | |
25f23643 | 23 | #include "block-migration.h" |
791e7c82 | 24 | #include "qmp-commands.h" |
065e2813 AL |
25 | |
26 | //#define DEBUG_MIGRATION | |
27 | ||
28 | #ifdef DEBUG_MIGRATION | |
d0f2c4c6 | 29 | #define DPRINTF(fmt, ...) \ |
065e2813 AL |
30 | do { printf("migration: " fmt, ## __VA_ARGS__); } while (0) |
31 | #else | |
d0f2c4c6 | 32 | #define DPRINTF(fmt, ...) \ |
065e2813 AL |
33 | do { } while (0) |
34 | #endif | |
5bb7910a | 35 | |
7dc688ed JQ |
36 | enum { |
37 | MIG_STATE_ERROR, | |
38 | MIG_STATE_SETUP, | |
39 | MIG_STATE_CANCELLED, | |
40 | MIG_STATE_ACTIVE, | |
41 | MIG_STATE_COMPLETED, | |
42 | }; | |
5bb7910a | 43 | |
d0ae46c1 | 44 | #define MAX_THROTTLE (32 << 20) /* Migration speed throttling */ |
5bb7910a | 45 | |
17ad9b35 OW |
46 | /* Migration XBZRLE default cache size */ |
47 | #define DEFAULT_MIGRATE_CACHE_SIZE (64 * 1024 * 1024) | |
48 | ||
99a0db9b GH |
49 | static NotifierList migration_state_notifiers = |
50 | NOTIFIER_LIST_INITIALIZER(migration_state_notifiers); | |
51 | ||
17549e84 JQ |
52 | /* When we add fault tolerance, we could have several |
53 | migrations at once. For now we don't need to add | |
54 | dynamic creation of migration */ | |
55 | ||
859bc756 | 56 | MigrationState *migrate_get_current(void) |
17549e84 JQ |
57 | { |
58 | static MigrationState current_migration = { | |
59 | .state = MIG_STATE_SETUP, | |
d0ae46c1 | 60 | .bandwidth_limit = MAX_THROTTLE, |
17ad9b35 | 61 | .xbzrle_cache_size = DEFAULT_MIGRATE_CACHE_SIZE, |
17549e84 JQ |
62 | }; |
63 | ||
64 | return ¤t_migration; | |
65 | } | |
66 | ||
d5c5dacc | 67 | int qemu_start_incoming_migration(const char *uri, Error **errp) |
5bb7910a | 68 | { |
34c9dd8e | 69 | const char *p; |
8ca5e801 | 70 | int ret; |
34c9dd8e AL |
71 | |
72 | if (strstart(uri, "tcp:", &p)) | |
d5c5dacc | 73 | ret = tcp_start_incoming_migration(p, errp); |
065e2813 AL |
74 | #if !defined(WIN32) |
75 | else if (strstart(uri, "exec:", &p)) | |
8ca5e801 | 76 | ret = exec_start_incoming_migration(p); |
4951f65b | 77 | else if (strstart(uri, "unix:", &p)) |
8ca5e801 | 78 | ret = unix_start_incoming_migration(p); |
5ac1fad3 | 79 | else if (strstart(uri, "fd:", &p)) |
8ca5e801 | 80 | ret = fd_start_incoming_migration(p); |
065e2813 | 81 | #endif |
8ca5e801 | 82 | else { |
34c9dd8e | 83 | fprintf(stderr, "unknown migration protocol: %s\n", uri); |
8ca5e801 JQ |
84 | ret = -EPROTONOSUPPORT; |
85 | } | |
86 | return ret; | |
5bb7910a AL |
87 | } |
88 | ||
511c0231 JQ |
89 | void process_incoming_migration(QEMUFile *f) |
90 | { | |
91 | if (qemu_loadvm_state(f) < 0) { | |
92 | fprintf(stderr, "load of migration failed\n"); | |
93 | exit(0); | |
94 | } | |
95 | qemu_announce_self(); | |
96 | DPRINTF("successfully loaded vm state\n"); | |
97 | ||
901862cb | 98 | bdrv_clear_incoming_migration_all(); |
0f15423c AL |
99 | /* Make sure all file formats flush their mutable metadata */ |
100 | bdrv_invalidate_cache_all(); | |
101 | ||
f5bbfba1 | 102 | if (autostart) { |
511c0231 | 103 | vm_start(); |
f5bbfba1 | 104 | } else { |
0461d5a6 | 105 | runstate_set(RUN_STATE_PRELAUNCH); |
f5bbfba1 | 106 | } |
511c0231 JQ |
107 | } |
108 | ||
a0a3fd60 GC |
109 | /* amount of nanoseconds we are willing to wait for migration to be down. |
110 | * the choice of nanoseconds is because it is the maximum resolution that | |
111 | * get_clock() can achieve. It is an internal measure. All user-visible | |
112 | * units must be in seconds */ | |
113 | static uint64_t max_downtime = 30000000; | |
114 | ||
115 | uint64_t migrate_max_downtime(void) | |
116 | { | |
117 | return max_downtime; | |
118 | } | |
119 | ||
bbf6da32 OW |
120 | MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp) |
121 | { | |
122 | MigrationCapabilityStatusList *head = NULL; | |
123 | MigrationCapabilityStatusList *caps; | |
124 | MigrationState *s = migrate_get_current(); | |
125 | int i; | |
126 | ||
127 | for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) { | |
128 | if (head == NULL) { | |
129 | head = g_malloc0(sizeof(*caps)); | |
130 | caps = head; | |
131 | } else { | |
132 | caps->next = g_malloc0(sizeof(*caps)); | |
133 | caps = caps->next; | |
134 | } | |
135 | caps->value = | |
136 | g_malloc(sizeof(*caps->value)); | |
137 | caps->value->capability = i; | |
138 | caps->value->state = s->enabled_capabilities[i]; | |
139 | } | |
140 | ||
141 | return head; | |
142 | } | |
143 | ||
f36d55af OW |
144 | static void get_xbzrle_cache_stats(MigrationInfo *info) |
145 | { | |
146 | if (migrate_use_xbzrle()) { | |
147 | info->has_xbzrle_cache = true; | |
148 | info->xbzrle_cache = g_malloc0(sizeof(*info->xbzrle_cache)); | |
149 | info->xbzrle_cache->cache_size = migrate_xbzrle_cache_size(); | |
150 | info->xbzrle_cache->bytes = xbzrle_mig_bytes_transferred(); | |
151 | info->xbzrle_cache->pages = xbzrle_mig_pages_transferred(); | |
152 | info->xbzrle_cache->cache_miss = xbzrle_mig_pages_cache_miss(); | |
153 | info->xbzrle_cache->overflow = xbzrle_mig_pages_overflow(); | |
154 | } | |
155 | } | |
156 | ||
791e7c82 | 157 | MigrationInfo *qmp_query_migrate(Error **errp) |
5bb7910a | 158 | { |
791e7c82 | 159 | MigrationInfo *info = g_malloc0(sizeof(*info)); |
17549e84 JQ |
160 | MigrationState *s = migrate_get_current(); |
161 | ||
162 | switch (s->state) { | |
163 | case MIG_STATE_SETUP: | |
164 | /* no migration has happened ever */ | |
165 | break; | |
166 | case MIG_STATE_ACTIVE: | |
791e7c82 LC |
167 | info->has_status = true; |
168 | info->status = g_strdup("active"); | |
7aa939af JQ |
169 | info->has_total_time = true; |
170 | info->total_time = qemu_get_clock_ms(rt_clock) | |
171 | - s->total_time; | |
2c52ddf1 JQ |
172 | info->has_expected_downtime = true; |
173 | info->expected_downtime = s->expected_downtime; | |
17549e84 | 174 | |
791e7c82 LC |
175 | info->has_ram = true; |
176 | info->ram = g_malloc0(sizeof(*info->ram)); | |
177 | info->ram->transferred = ram_bytes_transferred(); | |
178 | info->ram->remaining = ram_bytes_remaining(); | |
179 | info->ram->total = ram_bytes_total(); | |
004d4c10 OW |
180 | info->ram->duplicate = dup_mig_pages_transferred(); |
181 | info->ram->normal = norm_mig_pages_transferred(); | |
182 | info->ram->normal_bytes = norm_mig_bytes_transferred(); | |
8d017193 JQ |
183 | info->ram->dirty_pages_rate = s->dirty_pages_rate; |
184 | ||
17549e84 JQ |
185 | |
186 | if (blk_mig_active()) { | |
791e7c82 LC |
187 | info->has_disk = true; |
188 | info->disk = g_malloc0(sizeof(*info->disk)); | |
189 | info->disk->transferred = blk_mig_bytes_transferred(); | |
190 | info->disk->remaining = blk_mig_bytes_remaining(); | |
191 | info->disk->total = blk_mig_bytes_total(); | |
ff8d81d8 | 192 | } |
f36d55af OW |
193 | |
194 | get_xbzrle_cache_stats(info); | |
17549e84 JQ |
195 | break; |
196 | case MIG_STATE_COMPLETED: | |
f36d55af OW |
197 | get_xbzrle_cache_stats(info); |
198 | ||
791e7c82 LC |
199 | info->has_status = true; |
200 | info->status = g_strdup("completed"); | |
7aa939af | 201 | info->total_time = s->total_time; |
9c5a9fcf JQ |
202 | info->has_downtime = true; |
203 | info->downtime = s->downtime; | |
d5f8a570 JQ |
204 | |
205 | info->has_ram = true; | |
206 | info->ram = g_malloc0(sizeof(*info->ram)); | |
207 | info->ram->transferred = ram_bytes_transferred(); | |
208 | info->ram->remaining = 0; | |
209 | info->ram->total = ram_bytes_total(); | |
004d4c10 OW |
210 | info->ram->duplicate = dup_mig_pages_transferred(); |
211 | info->ram->normal = norm_mig_pages_transferred(); | |
212 | info->ram->normal_bytes = norm_mig_bytes_transferred(); | |
17549e84 JQ |
213 | break; |
214 | case MIG_STATE_ERROR: | |
791e7c82 LC |
215 | info->has_status = true; |
216 | info->status = g_strdup("failed"); | |
17549e84 JQ |
217 | break; |
218 | case MIG_STATE_CANCELLED: | |
791e7c82 LC |
219 | info->has_status = true; |
220 | info->status = g_strdup("cancelled"); | |
17549e84 | 221 | break; |
5bb7910a | 222 | } |
791e7c82 LC |
223 | |
224 | return info; | |
5bb7910a AL |
225 | } |
226 | ||
00458433 OW |
227 | void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params, |
228 | Error **errp) | |
229 | { | |
230 | MigrationState *s = migrate_get_current(); | |
231 | MigrationCapabilityStatusList *cap; | |
232 | ||
233 | if (s->state == MIG_STATE_ACTIVE) { | |
234 | error_set(errp, QERR_MIGRATION_ACTIVE); | |
235 | return; | |
236 | } | |
237 | ||
238 | for (cap = params; cap; cap = cap->next) { | |
239 | s->enabled_capabilities[cap->value->capability] = cap->value->state; | |
240 | } | |
241 | } | |
242 | ||
065e2813 AL |
243 | /* shared migration helpers */ |
244 | ||
8b6b99b3 | 245 | static int migrate_fd_cleanup(MigrationState *s) |
065e2813 | 246 | { |
41ef56e6 AL |
247 | int ret = 0; |
248 | ||
3202beca OW |
249 | if (s->fd != -1) { |
250 | qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); | |
251 | } | |
065e2813 AL |
252 | |
253 | if (s->file) { | |
d0f2c4c6 | 254 | DPRINTF("closing file\n"); |
a6d34a94 | 255 | ret = qemu_fclose(s->file); |
5d39c799 | 256 | s->file = NULL; |
065e2813 AL |
257 | } |
258 | ||
84ec6552 | 259 | if (s->fd != -1) { |
065e2813 | 260 | close(s->fd); |
84ec6552 | 261 | s->fd = -1; |
f327aa0c | 262 | } |
065e2813 | 263 | |
41ef56e6 | 264 | return ret; |
065e2813 AL |
265 | } |
266 | ||
8b6b99b3 | 267 | void migrate_fd_error(MigrationState *s) |
065e2813 | 268 | { |
8b6b99b3 JQ |
269 | DPRINTF("setting error state\n"); |
270 | s->state = MIG_STATE_ERROR; | |
e0eb7390 | 271 | notifier_list_notify(&migration_state_notifiers, s); |
8b6b99b3 JQ |
272 | migrate_fd_cleanup(s); |
273 | } | |
274 | ||
458cf28e JQ |
275 | static void migrate_fd_completed(MigrationState *s) |
276 | { | |
277 | DPRINTF("setting completed state\n"); | |
278 | if (migrate_fd_cleanup(s) < 0) { | |
279 | s->state = MIG_STATE_ERROR; | |
280 | } else { | |
281 | s->state = MIG_STATE_COMPLETED; | |
282 | runstate_set(RUN_STATE_POSTMIGRATE); | |
283 | } | |
e0eb7390 | 284 | notifier_list_notify(&migration_state_notifiers, s); |
458cf28e JQ |
285 | } |
286 | ||
8b6b99b3 | 287 | static void migrate_fd_put_notify(void *opaque) |
065e2813 | 288 | { |
22f00a44 | 289 | MigrationState *s = opaque; |
065e2813 AL |
290 | |
291 | qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); | |
292 | qemu_file_put_notify(s->file); | |
1fdc11c3 | 293 | if (s->file && qemu_file_get_error(s->file)) { |
2350e13c YT |
294 | migrate_fd_error(s); |
295 | } | |
065e2813 AL |
296 | } |
297 | ||
c87b015b JQ |
298 | ssize_t migrate_fd_put_buffer(MigrationState *s, const void *data, |
299 | size_t size) | |
065e2813 | 300 | { |
065e2813 AL |
301 | ssize_t ret; |
302 | ||
fdbecb5d JQ |
303 | if (s->state != MIG_STATE_ACTIVE) { |
304 | return -EIO; | |
305 | } | |
306 | ||
065e2813 AL |
307 | do { |
308 | ret = s->write(s, data, size); | |
95b134ea | 309 | } while (ret == -1 && ((s->get_error(s)) == EINTR)); |
065e2813 AL |
310 | |
311 | if (ret == -1) | |
312 | ret = -(s->get_error(s)); | |
313 | ||
e447b1a6 | 314 | if (ret == -EAGAIN) { |
065e2813 | 315 | qemu_set_fd_handler2(s->fd, NULL, NULL, migrate_fd_put_notify, s); |
e447b1a6 | 316 | } |
065e2813 AL |
317 | |
318 | return ret; | |
319 | } | |
320 | ||
2c9adcb8 | 321 | void migrate_fd_put_ready(MigrationState *s) |
065e2813 AL |
322 | { |
323 | int ret; | |
324 | ||
065e2813 | 325 | if (s->state != MIG_STATE_ACTIVE) { |
d0f2c4c6 | 326 | DPRINTF("put_ready returning because of non-active state\n"); |
065e2813 AL |
327 | return; |
328 | } | |
329 | ||
d0f2c4c6 | 330 | DPRINTF("iterate\n"); |
539de124 | 331 | ret = qemu_savevm_state_iterate(s->file); |
39346385 JQ |
332 | if (ret < 0) { |
333 | migrate_fd_error(s); | |
334 | } else if (ret == 1) { | |
1354869c | 335 | int old_vm_running = runstate_is_running(); |
9c5a9fcf | 336 | int64_t start_time, end_time; |
eeb34af9 | 337 | |
d0f2c4c6 | 338 | DPRINTF("done iterating\n"); |
9c5a9fcf | 339 | start_time = qemu_get_clock_ms(rt_clock); |
7b5d3aa2 | 340 | qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); |
8a9236f1 | 341 | vm_stop_force_state(RUN_STATE_FINISH_MIGRATE); |
065e2813 | 342 | |
539de124 | 343 | if (qemu_savevm_state_complete(s->file) < 0) { |
67afff79 | 344 | migrate_fd_error(s); |
b161d123 | 345 | } else { |
458cf28e | 346 | migrate_fd_completed(s); |
b161d123 | 347 | } |
97d4d961 JQ |
348 | end_time = qemu_get_clock_ms(rt_clock); |
349 | s->total_time = end_time - s->total_time; | |
9c5a9fcf | 350 | s->downtime = end_time - start_time; |
48a2f4d6 | 351 | if (s->state != MIG_STATE_COMPLETED) { |
41ef56e6 AL |
352 | if (old_vm_running) { |
353 | vm_start(); | |
354 | } | |
f5bbfba1 | 355 | } |
065e2813 AL |
356 | } |
357 | } | |
358 | ||
0edda1c4 | 359 | static void migrate_fd_cancel(MigrationState *s) |
065e2813 | 360 | { |
065e2813 AL |
361 | if (s->state != MIG_STATE_ACTIVE) |
362 | return; | |
363 | ||
d0f2c4c6 | 364 | DPRINTF("cancelling migration\n"); |
065e2813 AL |
365 | |
366 | s->state = MIG_STATE_CANCELLED; | |
e0eb7390 | 367 | notifier_list_notify(&migration_state_notifiers, s); |
539de124 | 368 | qemu_savevm_state_cancel(s->file); |
065e2813 AL |
369 | |
370 | migrate_fd_cleanup(s); | |
371 | } | |
372 | ||
749f7909 | 373 | void migrate_fd_wait_for_unfreeze(MigrationState *s) |
065e2813 | 374 | { |
065e2813 AL |
375 | int ret; |
376 | ||
d0f2c4c6 | 377 | DPRINTF("wait for unfreeze\n"); |
065e2813 AL |
378 | if (s->state != MIG_STATE_ACTIVE) |
379 | return; | |
380 | ||
381 | do { | |
382 | fd_set wfds; | |
383 | ||
384 | FD_ZERO(&wfds); | |
385 | FD_SET(s->fd, &wfds); | |
386 | ||
387 | ret = select(s->fd + 1, NULL, &wfds, NULL, NULL); | |
388 | } while (ret == -1 && (s->get_error(s)) == EINTR); | |
af509450 JQ |
389 | |
390 | if (ret == -1) { | |
dcd1d224 | 391 | qemu_file_set_error(s->file, -s->get_error(s)); |
af509450 | 392 | } |
065e2813 AL |
393 | } |
394 | ||
8b6b99b3 | 395 | static int migrate_fd_close(void *opaque) |
065e2813 | 396 | { |
22f00a44 | 397 | MigrationState *s = opaque; |
e19252d3 UL |
398 | |
399 | qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); | |
065e2813 AL |
400 | return s->close(s); |
401 | } | |
99a0db9b GH |
402 | |
403 | void add_migration_state_change_notifier(Notifier *notify) | |
404 | { | |
405 | notifier_list_add(&migration_state_notifiers, notify); | |
406 | } | |
407 | ||
408 | void remove_migration_state_change_notifier(Notifier *notify) | |
409 | { | |
31552529 | 410 | notifier_remove(notify); |
99a0db9b GH |
411 | } |
412 | ||
afe2df69 GH |
413 | bool migration_is_active(MigrationState *s) |
414 | { | |
415 | return s->state == MIG_STATE_ACTIVE; | |
416 | } | |
417 | ||
7073693b | 418 | bool migration_has_finished(MigrationState *s) |
99a0db9b | 419 | { |
7073693b | 420 | return s->state == MIG_STATE_COMPLETED; |
99a0db9b | 421 | } |
0edda1c4 | 422 | |
afe2df69 GH |
423 | bool migration_has_failed(MigrationState *s) |
424 | { | |
425 | return (s->state == MIG_STATE_CANCELLED || | |
426 | s->state == MIG_STATE_ERROR); | |
427 | } | |
428 | ||
8b6b99b3 | 429 | void migrate_fd_connect(MigrationState *s) |
99a0db9b | 430 | { |
8b6b99b3 JQ |
431 | int ret; |
432 | ||
d5934dde | 433 | s->state = MIG_STATE_ACTIVE; |
8b6b99b3 JQ |
434 | s->file = qemu_fopen_ops_buffered(s, |
435 | s->bandwidth_limit, | |
8b6b99b3 JQ |
436 | migrate_fd_close); |
437 | ||
438 | DPRINTF("beginning savevm\n"); | |
6607ae23 | 439 | ret = qemu_savevm_state_begin(s->file, &s->params); |
8b6b99b3 JQ |
440 | if (ret < 0) { |
441 | DPRINTF("failed, %d\n", ret); | |
442 | migrate_fd_error(s); | |
443 | return; | |
444 | } | |
445 | migrate_fd_put_ready(s); | |
446 | } | |
447 | ||
6607ae23 | 448 | static MigrationState *migrate_init(const MigrationParams *params) |
0edda1c4 | 449 | { |
17549e84 | 450 | MigrationState *s = migrate_get_current(); |
d0ae46c1 | 451 | int64_t bandwidth_limit = s->bandwidth_limit; |
bbf6da32 | 452 | bool enabled_capabilities[MIGRATION_CAPABILITY_MAX]; |
17ad9b35 | 453 | int64_t xbzrle_cache_size = s->xbzrle_cache_size; |
bbf6da32 OW |
454 | |
455 | memcpy(enabled_capabilities, s->enabled_capabilities, | |
456 | sizeof(enabled_capabilities)); | |
0edda1c4 | 457 | |
17549e84 | 458 | memset(s, 0, sizeof(*s)); |
d0ae46c1 | 459 | s->bandwidth_limit = bandwidth_limit; |
6607ae23 | 460 | s->params = *params; |
bbf6da32 OW |
461 | memcpy(s->enabled_capabilities, enabled_capabilities, |
462 | sizeof(enabled_capabilities)); | |
17ad9b35 | 463 | s->xbzrle_cache_size = xbzrle_cache_size; |
1299c631 | 464 | |
0edda1c4 | 465 | s->bandwidth_limit = bandwidth_limit; |
d5934dde | 466 | s->state = MIG_STATE_SETUP; |
d5f8a570 | 467 | s->total_time = qemu_get_clock_ms(rt_clock); |
0edda1c4 | 468 | |
0edda1c4 JQ |
469 | return s; |
470 | } | |
cab30143 | 471 | |
fa2756b7 AL |
472 | static GSList *migration_blockers; |
473 | ||
474 | void migrate_add_blocker(Error *reason) | |
475 | { | |
476 | migration_blockers = g_slist_prepend(migration_blockers, reason); | |
477 | } | |
478 | ||
479 | void migrate_del_blocker(Error *reason) | |
480 | { | |
481 | migration_blockers = g_slist_remove(migration_blockers, reason); | |
482 | } | |
483 | ||
e1c37d0e LC |
484 | void qmp_migrate(const char *uri, bool has_blk, bool blk, |
485 | bool has_inc, bool inc, bool has_detach, bool detach, | |
486 | Error **errp) | |
cab30143 | 487 | { |
17549e84 | 488 | MigrationState *s = migrate_get_current(); |
6607ae23 | 489 | MigrationParams params; |
cab30143 | 490 | const char *p; |
cab30143 JQ |
491 | int ret; |
492 | ||
6607ae23 IY |
493 | params.blk = blk; |
494 | params.shared = inc; | |
495 | ||
17549e84 | 496 | if (s->state == MIG_STATE_ACTIVE) { |
e1c37d0e LC |
497 | error_set(errp, QERR_MIGRATION_ACTIVE); |
498 | return; | |
cab30143 JQ |
499 | } |
500 | ||
e1c37d0e LC |
501 | if (qemu_savevm_state_blocked(errp)) { |
502 | return; | |
cab30143 JQ |
503 | } |
504 | ||
fa2756b7 | 505 | if (migration_blockers) { |
e1c37d0e LC |
506 | *errp = error_copy(migration_blockers->data); |
507 | return; | |
fa2756b7 AL |
508 | } |
509 | ||
6607ae23 | 510 | s = migrate_init(¶ms); |
cab30143 JQ |
511 | |
512 | if (strstart(uri, "tcp:", &p)) { | |
d5c5dacc | 513 | ret = tcp_start_outgoing_migration(s, p, errp); |
cab30143 JQ |
514 | #if !defined(WIN32) |
515 | } else if (strstart(uri, "exec:", &p)) { | |
516 | ret = exec_start_outgoing_migration(s, p); | |
517 | } else if (strstart(uri, "unix:", &p)) { | |
518 | ret = unix_start_outgoing_migration(s, p); | |
519 | } else if (strstart(uri, "fd:", &p)) { | |
520 | ret = fd_start_outgoing_migration(s, p); | |
521 | #endif | |
99a0db9b | 522 | } else { |
e1c37d0e LC |
523 | error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol"); |
524 | return; | |
cab30143 JQ |
525 | } |
526 | ||
527 | if (ret < 0) { | |
d5c5dacc AK |
528 | if (!error_is_set(errp)) { |
529 | DPRINTF("migration failed: %s\n", strerror(-ret)); | |
530 | /* FIXME: we should return meaningful errors */ | |
531 | error_set(errp, QERR_UNDEFINED_ERROR); | |
532 | } | |
e1c37d0e | 533 | return; |
1299c631 JQ |
534 | } |
535 | ||
e0eb7390 | 536 | notifier_list_notify(&migration_state_notifiers, s); |
cab30143 JQ |
537 | } |
538 | ||
6cdedb07 | 539 | void qmp_migrate_cancel(Error **errp) |
cab30143 | 540 | { |
17549e84 | 541 | migrate_fd_cancel(migrate_get_current()); |
cab30143 JQ |
542 | } |
543 | ||
9e1ba4cc OW |
544 | void qmp_migrate_set_cache_size(int64_t value, Error **errp) |
545 | { | |
546 | MigrationState *s = migrate_get_current(); | |
547 | ||
548 | /* Check for truncation */ | |
549 | if (value != (size_t)value) { | |
550 | error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", | |
551 | "exceeding address space"); | |
552 | return; | |
553 | } | |
554 | ||
555 | s->xbzrle_cache_size = xbzrle_cache_resize(value); | |
556 | } | |
557 | ||
558 | int64_t qmp_query_migrate_cache_size(Error **errp) | |
559 | { | |
560 | return migrate_xbzrle_cache_size(); | |
561 | } | |
562 | ||
3dc85383 | 563 | void qmp_migrate_set_speed(int64_t value, Error **errp) |
cab30143 | 564 | { |
cab30143 JQ |
565 | MigrationState *s; |
566 | ||
3dc85383 LC |
567 | if (value < 0) { |
568 | value = 0; | |
99a0db9b | 569 | } |
cab30143 | 570 | |
17549e84 | 571 | s = migrate_get_current(); |
3dc85383 | 572 | s->bandwidth_limit = value; |
d0ae46c1 | 573 | qemu_file_set_rate_limit(s->file, s->bandwidth_limit); |
cab30143 JQ |
574 | } |
575 | ||
4f0a993b | 576 | void qmp_migrate_set_downtime(double value, Error **errp) |
cab30143 | 577 | { |
4f0a993b LC |
578 | value *= 1e9; |
579 | value = MAX(0, MIN(UINT64_MAX, value)); | |
580 | max_downtime = (uint64_t)value; | |
99a0db9b | 581 | } |
17ad9b35 OW |
582 | |
583 | int migrate_use_xbzrle(void) | |
584 | { | |
585 | MigrationState *s; | |
586 | ||
587 | s = migrate_get_current(); | |
588 | ||
589 | return s->enabled_capabilities[MIGRATION_CAPABILITY_XBZRLE]; | |
590 | } | |
591 | ||
592 | int64_t migrate_xbzrle_cache_size(void) | |
593 | { | |
594 | MigrationState *s; | |
595 | ||
596 | s = migrate_get_current(); | |
597 | ||
598 | return s->xbzrle_cache_size; | |
599 | } |