]>
Commit | Line | Data |
---|---|---|
119f50ce MA |
1 | /* |
2 | * HMP commands related to migration | |
3 | * | |
4 | * Copyright IBM, Corp. 2011 | |
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 | * | |
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. | |
14 | */ | |
15 | ||
16 | #include "qemu/osdep.h" | |
17 | #include "block/qapi.h" | |
119f50ce MA |
18 | #include "migration/snapshot.h" |
19 | #include "monitor/hmp.h" | |
20 | #include "monitor/monitor.h" | |
21 | #include "qapi/error.h" | |
22 | #include "qapi/qapi-commands-migration.h" | |
23 | #include "qapi/qapi-visit-migration.h" | |
24 | #include "qapi/qmp/qdict.h" | |
119f50ce MA |
25 | #include "qapi/string-input-visitor.h" |
26 | #include "qapi/string-output-visitor.h" | |
27 | #include "qemu/cutils.h" | |
28 | #include "qemu/error-report.h" | |
29 | #include "qemu/sockets.h" | |
30 | #include "sysemu/runstate.h" | |
31 | #include "ui/qemu-spice.h" | |
c9381577 JQ |
32 | #include "sysemu/sysemu.h" |
33 | #include "migration.h" | |
34 | ||
35 | static void migration_global_dump(Monitor *mon) | |
36 | { | |
37 | MigrationState *ms = migrate_get_current(); | |
38 | ||
39 | monitor_printf(mon, "globals:\n"); | |
40 | monitor_printf(mon, "store-global-state: %s\n", | |
41 | ms->store_global_state ? "on" : "off"); | |
42 | monitor_printf(mon, "only-migratable: %s\n", | |
43 | only_migratable ? "on" : "off"); | |
44 | monitor_printf(mon, "send-configuration: %s\n", | |
45 | ms->send_configuration ? "on" : "off"); | |
46 | monitor_printf(mon, "send-section-footer: %s\n", | |
47 | ms->send_section_footer ? "on" : "off"); | |
48 | monitor_printf(mon, "decompress-error-check: %s\n", | |
49 | ms->decompress_error_check ? "on" : "off"); | |
50 | monitor_printf(mon, "clear-bitmap-shift: %u\n", | |
51 | ms->clear_bitmap_shift); | |
52 | } | |
119f50ce MA |
53 | |
54 | void hmp_info_migrate(Monitor *mon, const QDict *qdict) | |
55 | { | |
56 | MigrationInfo *info; | |
57 | ||
58 | info = qmp_query_migrate(NULL); | |
59 | ||
60 | migration_global_dump(mon); | |
61 | ||
62 | if (info->blocked_reasons) { | |
63 | strList *reasons = info->blocked_reasons; | |
64 | monitor_printf(mon, "Outgoing migration blocked:\n"); | |
65 | while (reasons) { | |
66 | monitor_printf(mon, " %s\n", reasons->value); | |
67 | reasons = reasons->next; | |
68 | } | |
69 | } | |
70 | ||
71 | if (info->has_status) { | |
72 | monitor_printf(mon, "Migration status: %s", | |
73 | MigrationStatus_str(info->status)); | |
74 | if (info->status == MIGRATION_STATUS_FAILED && info->error_desc) { | |
75 | monitor_printf(mon, " (%s)\n", info->error_desc); | |
76 | } else { | |
77 | monitor_printf(mon, "\n"); | |
78 | } | |
79 | ||
80 | monitor_printf(mon, "total time: %" PRIu64 " ms\n", | |
81 | info->total_time); | |
82 | if (info->has_expected_downtime) { | |
83 | monitor_printf(mon, "expected downtime: %" PRIu64 " ms\n", | |
84 | info->expected_downtime); | |
85 | } | |
86 | if (info->has_downtime) { | |
87 | monitor_printf(mon, "downtime: %" PRIu64 " ms\n", | |
88 | info->downtime); | |
89 | } | |
90 | if (info->has_setup_time) { | |
91 | monitor_printf(mon, "setup: %" PRIu64 " ms\n", | |
92 | info->setup_time); | |
93 | } | |
94 | } | |
95 | ||
96 | if (info->ram) { | |
97 | monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n", | |
98 | info->ram->transferred >> 10); | |
99 | monitor_printf(mon, "throughput: %0.2f mbps\n", | |
100 | info->ram->mbps); | |
101 | monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n", | |
102 | info->ram->remaining >> 10); | |
103 | monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n", | |
104 | info->ram->total >> 10); | |
105 | monitor_printf(mon, "duplicate: %" PRIu64 " pages\n", | |
106 | info->ram->duplicate); | |
107 | monitor_printf(mon, "skipped: %" PRIu64 " pages\n", | |
108 | info->ram->skipped); | |
109 | monitor_printf(mon, "normal: %" PRIu64 " pages\n", | |
110 | info->ram->normal); | |
111 | monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n", | |
112 | info->ram->normal_bytes >> 10); | |
113 | monitor_printf(mon, "dirty sync count: %" PRIu64 "\n", | |
114 | info->ram->dirty_sync_count); | |
115 | monitor_printf(mon, "page size: %" PRIu64 " kbytes\n", | |
116 | info->ram->page_size >> 10); | |
117 | monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n", | |
118 | info->ram->multifd_bytes >> 10); | |
119 | monitor_printf(mon, "pages-per-second: %" PRIu64 "\n", | |
120 | info->ram->pages_per_second); | |
121 | ||
122 | if (info->ram->dirty_pages_rate) { | |
123 | monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n", | |
124 | info->ram->dirty_pages_rate); | |
125 | } | |
126 | if (info->ram->postcopy_requests) { | |
127 | monitor_printf(mon, "postcopy request count: %" PRIu64 "\n", | |
128 | info->ram->postcopy_requests); | |
129 | } | |
130 | if (info->ram->precopy_bytes) { | |
131 | monitor_printf(mon, "precopy ram: %" PRIu64 " kbytes\n", | |
132 | info->ram->precopy_bytes >> 10); | |
133 | } | |
134 | if (info->ram->downtime_bytes) { | |
135 | monitor_printf(mon, "downtime ram: %" PRIu64 " kbytes\n", | |
136 | info->ram->downtime_bytes >> 10); | |
137 | } | |
138 | if (info->ram->postcopy_bytes) { | |
139 | monitor_printf(mon, "postcopy ram: %" PRIu64 " kbytes\n", | |
140 | info->ram->postcopy_bytes >> 10); | |
141 | } | |
142 | if (info->ram->dirty_sync_missed_zero_copy) { | |
143 | monitor_printf(mon, | |
144 | "Zero-copy-send fallbacks happened: %" PRIu64 " times\n", | |
145 | info->ram->dirty_sync_missed_zero_copy); | |
146 | } | |
147 | } | |
148 | ||
149 | if (info->disk) { | |
150 | monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n", | |
151 | info->disk->transferred >> 10); | |
152 | monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n", | |
153 | info->disk->remaining >> 10); | |
154 | monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n", | |
155 | info->disk->total >> 10); | |
156 | } | |
157 | ||
158 | if (info->xbzrle_cache) { | |
159 | monitor_printf(mon, "cache size: %" PRIu64 " bytes\n", | |
160 | info->xbzrle_cache->cache_size); | |
161 | monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n", | |
162 | info->xbzrle_cache->bytes >> 10); | |
163 | monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n", | |
164 | info->xbzrle_cache->pages); | |
165 | monitor_printf(mon, "xbzrle cache miss: %" PRIu64 " pages\n", | |
166 | info->xbzrle_cache->cache_miss); | |
167 | monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n", | |
168 | info->xbzrle_cache->cache_miss_rate); | |
169 | monitor_printf(mon, "xbzrle encoding rate: %0.2f\n", | |
170 | info->xbzrle_cache->encoding_rate); | |
171 | monitor_printf(mon, "xbzrle overflow: %" PRIu64 "\n", | |
172 | info->xbzrle_cache->overflow); | |
173 | } | |
174 | ||
175 | if (info->compression) { | |
176 | monitor_printf(mon, "compression pages: %" PRIu64 " pages\n", | |
177 | info->compression->pages); | |
178 | monitor_printf(mon, "compression busy: %" PRIu64 "\n", | |
179 | info->compression->busy); | |
180 | monitor_printf(mon, "compression busy rate: %0.2f\n", | |
181 | info->compression->busy_rate); | |
182 | monitor_printf(mon, "compressed size: %" PRIu64 " kbytes\n", | |
183 | info->compression->compressed_size >> 10); | |
184 | monitor_printf(mon, "compression rate: %0.2f\n", | |
185 | info->compression->compression_rate); | |
186 | } | |
187 | ||
188 | if (info->has_cpu_throttle_percentage) { | |
189 | monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n", | |
190 | info->cpu_throttle_percentage); | |
191 | } | |
192 | ||
193 | if (info->has_postcopy_blocktime) { | |
194 | monitor_printf(mon, "postcopy blocktime: %u\n", | |
195 | info->postcopy_blocktime); | |
196 | } | |
197 | ||
198 | if (info->has_postcopy_vcpu_blocktime) { | |
199 | Visitor *v; | |
200 | char *str; | |
201 | v = string_output_visitor_new(false, &str); | |
202 | visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, | |
203 | &error_abort); | |
204 | visit_complete(v, &str); | |
205 | monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str); | |
206 | g_free(str); | |
207 | visit_free(v); | |
208 | } | |
209 | if (info->has_socket_address) { | |
210 | SocketAddressList *addr; | |
211 | ||
212 | monitor_printf(mon, "socket address: [\n"); | |
213 | ||
214 | for (addr = info->socket_address; addr; addr = addr->next) { | |
215 | char *s = socket_uri(addr->value); | |
216 | monitor_printf(mon, "\t%s\n", s); | |
217 | g_free(s); | |
218 | } | |
219 | monitor_printf(mon, "]\n"); | |
220 | } | |
221 | ||
222 | if (info->vfio) { | |
223 | monitor_printf(mon, "vfio device transferred: %" PRIu64 " kbytes\n", | |
224 | info->vfio->transferred >> 10); | |
225 | } | |
226 | ||
227 | qapi_free_MigrationInfo(info); | |
228 | } | |
229 | ||
230 | void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict) | |
231 | { | |
232 | MigrationCapabilityStatusList *caps, *cap; | |
233 | ||
234 | caps = qmp_query_migrate_capabilities(NULL); | |
235 | ||
236 | if (caps) { | |
237 | for (cap = caps; cap; cap = cap->next) { | |
238 | monitor_printf(mon, "%s: %s\n", | |
239 | MigrationCapability_str(cap->value->capability), | |
240 | cap->value->state ? "on" : "off"); | |
241 | } | |
242 | } | |
243 | ||
244 | qapi_free_MigrationCapabilityStatusList(caps); | |
245 | } | |
246 | ||
247 | void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) | |
248 | { | |
249 | MigrationParameters *params; | |
250 | ||
251 | params = qmp_query_migrate_parameters(NULL); | |
252 | ||
253 | if (params) { | |
254 | monitor_printf(mon, "%s: %" PRIu64 " ms\n", | |
255 | MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL), | |
256 | params->announce_initial); | |
257 | monitor_printf(mon, "%s: %" PRIu64 " ms\n", | |
258 | MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX), | |
259 | params->announce_max); | |
260 | monitor_printf(mon, "%s: %" PRIu64 "\n", | |
261 | MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS), | |
262 | params->announce_rounds); | |
263 | monitor_printf(mon, "%s: %" PRIu64 " ms\n", | |
264 | MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP), | |
265 | params->announce_step); | |
266 | assert(params->has_compress_level); | |
267 | monitor_printf(mon, "%s: %u\n", | |
268 | MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL), | |
269 | params->compress_level); | |
270 | assert(params->has_compress_threads); | |
271 | monitor_printf(mon, "%s: %u\n", | |
272 | MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS), | |
273 | params->compress_threads); | |
274 | assert(params->has_compress_wait_thread); | |
275 | monitor_printf(mon, "%s: %s\n", | |
276 | MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD), | |
277 | params->compress_wait_thread ? "on" : "off"); | |
278 | assert(params->has_decompress_threads); | |
279 | monitor_printf(mon, "%s: %u\n", | |
280 | MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS), | |
281 | params->decompress_threads); | |
282 | assert(params->has_throttle_trigger_threshold); | |
283 | monitor_printf(mon, "%s: %u\n", | |
284 | MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD), | |
285 | params->throttle_trigger_threshold); | |
286 | assert(params->has_cpu_throttle_initial); | |
287 | monitor_printf(mon, "%s: %u\n", | |
288 | MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL), | |
289 | params->cpu_throttle_initial); | |
290 | assert(params->has_cpu_throttle_increment); | |
291 | monitor_printf(mon, "%s: %u\n", | |
292 | MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT), | |
293 | params->cpu_throttle_increment); | |
294 | assert(params->has_cpu_throttle_tailslow); | |
295 | monitor_printf(mon, "%s: %s\n", | |
296 | MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW), | |
297 | params->cpu_throttle_tailslow ? "on" : "off"); | |
298 | assert(params->has_max_cpu_throttle); | |
299 | monitor_printf(mon, "%s: %u\n", | |
300 | MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE), | |
301 | params->max_cpu_throttle); | |
302 | assert(params->tls_creds); | |
303 | monitor_printf(mon, "%s: '%s'\n", | |
304 | MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS), | |
305 | params->tls_creds); | |
306 | assert(params->tls_hostname); | |
307 | monitor_printf(mon, "%s: '%s'\n", | |
308 | MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME), | |
309 | params->tls_hostname); | |
310 | assert(params->has_max_bandwidth); | |
311 | monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n", | |
312 | MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH), | |
313 | params->max_bandwidth); | |
314 | assert(params->has_downtime_limit); | |
315 | monitor_printf(mon, "%s: %" PRIu64 " ms\n", | |
316 | MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT), | |
317 | params->downtime_limit); | |
318 | assert(params->has_x_checkpoint_delay); | |
319 | monitor_printf(mon, "%s: %u ms\n", | |
320 | MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY), | |
321 | params->x_checkpoint_delay); | |
322 | assert(params->has_block_incremental); | |
323 | monitor_printf(mon, "%s: %s\n", | |
324 | MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL), | |
325 | params->block_incremental ? "on" : "off"); | |
326 | monitor_printf(mon, "%s: %u\n", | |
327 | MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS), | |
328 | params->multifd_channels); | |
329 | monitor_printf(mon, "%s: %s\n", | |
330 | MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION), | |
331 | MultiFDCompression_str(params->multifd_compression)); | |
332 | monitor_printf(mon, "%s: %" PRIu64 " bytes\n", | |
333 | MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE), | |
334 | params->xbzrle_cache_size); | |
335 | monitor_printf(mon, "%s: %" PRIu64 "\n", | |
336 | MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH), | |
337 | params->max_postcopy_bandwidth); | |
338 | monitor_printf(mon, "%s: '%s'\n", | |
339 | MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ), | |
340 | params->tls_authz); | |
341 | ||
342 | if (params->has_block_bitmap_mapping) { | |
343 | const BitmapMigrationNodeAliasList *bmnal; | |
344 | ||
345 | monitor_printf(mon, "%s:\n", | |
346 | MigrationParameter_str( | |
347 | MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING)); | |
348 | ||
349 | for (bmnal = params->block_bitmap_mapping; | |
350 | bmnal; | |
351 | bmnal = bmnal->next) | |
352 | { | |
353 | const BitmapMigrationNodeAlias *bmna = bmnal->value; | |
354 | const BitmapMigrationBitmapAliasList *bmbal; | |
355 | ||
356 | monitor_printf(mon, " '%s' -> '%s'\n", | |
357 | bmna->node_name, bmna->alias); | |
358 | ||
359 | for (bmbal = bmna->bitmaps; bmbal; bmbal = bmbal->next) { | |
360 | const BitmapMigrationBitmapAlias *bmba = bmbal->value; | |
361 | ||
362 | monitor_printf(mon, " '%s' -> '%s'\n", | |
363 | bmba->name, bmba->alias); | |
364 | } | |
365 | } | |
366 | } | |
367 | } | |
368 | ||
369 | qapi_free_MigrationParameters(params); | |
370 | } | |
371 | ||
372 | void hmp_loadvm(Monitor *mon, const QDict *qdict) | |
373 | { | |
374 | int saved_vm_running = runstate_is_running(); | |
375 | const char *name = qdict_get_str(qdict, "name"); | |
376 | Error *err = NULL; | |
377 | ||
378 | vm_stop(RUN_STATE_RESTORE_VM); | |
379 | ||
380 | if (load_snapshot(name, NULL, false, NULL, &err) && saved_vm_running) { | |
381 | vm_start(); | |
382 | } | |
383 | hmp_handle_error(mon, err); | |
384 | } | |
385 | ||
386 | void hmp_savevm(Monitor *mon, const QDict *qdict) | |
387 | { | |
388 | Error *err = NULL; | |
389 | ||
390 | save_snapshot(qdict_get_try_str(qdict, "name"), | |
391 | true, NULL, false, NULL, &err); | |
392 | hmp_handle_error(mon, err); | |
393 | } | |
394 | ||
395 | void hmp_delvm(Monitor *mon, const QDict *qdict) | |
396 | { | |
397 | Error *err = NULL; | |
398 | const char *name = qdict_get_str(qdict, "name"); | |
399 | ||
400 | delete_snapshot(name, false, NULL, &err); | |
401 | hmp_handle_error(mon, err); | |
402 | } | |
403 | ||
404 | void hmp_migrate_cancel(Monitor *mon, const QDict *qdict) | |
405 | { | |
406 | qmp_migrate_cancel(NULL); | |
407 | } | |
408 | ||
409 | void hmp_migrate_continue(Monitor *mon, const QDict *qdict) | |
410 | { | |
411 | Error *err = NULL; | |
412 | const char *state = qdict_get_str(qdict, "state"); | |
413 | int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err); | |
414 | ||
415 | if (val >= 0) { | |
416 | qmp_migrate_continue(val, &err); | |
417 | } | |
418 | ||
419 | hmp_handle_error(mon, err); | |
420 | } | |
421 | ||
422 | void hmp_migrate_incoming(Monitor *mon, const QDict *qdict) | |
423 | { | |
424 | Error *err = NULL; | |
425 | const char *uri = qdict_get_str(qdict, "uri"); | |
426 | ||
427 | qmp_migrate_incoming(uri, &err); | |
428 | ||
429 | hmp_handle_error(mon, err); | |
430 | } | |
431 | ||
432 | void hmp_migrate_recover(Monitor *mon, const QDict *qdict) | |
433 | { | |
434 | Error *err = NULL; | |
435 | const char *uri = qdict_get_str(qdict, "uri"); | |
436 | ||
437 | qmp_migrate_recover(uri, &err); | |
438 | ||
439 | hmp_handle_error(mon, err); | |
440 | } | |
441 | ||
442 | void hmp_migrate_pause(Monitor *mon, const QDict *qdict) | |
443 | { | |
444 | Error *err = NULL; | |
445 | ||
446 | qmp_migrate_pause(&err); | |
447 | ||
448 | hmp_handle_error(mon, err); | |
449 | } | |
450 | ||
451 | ||
452 | void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict) | |
453 | { | |
454 | const char *cap = qdict_get_str(qdict, "capability"); | |
455 | bool state = qdict_get_bool(qdict, "state"); | |
456 | Error *err = NULL; | |
457 | MigrationCapabilityStatusList *caps = NULL; | |
458 | MigrationCapabilityStatus *value; | |
459 | int val; | |
460 | ||
461 | val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err); | |
462 | if (val < 0) { | |
463 | goto end; | |
464 | } | |
465 | ||
466 | value = g_malloc0(sizeof(*value)); | |
467 | value->capability = val; | |
468 | value->state = state; | |
469 | QAPI_LIST_PREPEND(caps, value); | |
470 | qmp_migrate_set_capabilities(caps, &err); | |
471 | qapi_free_MigrationCapabilityStatusList(caps); | |
472 | ||
473 | end: | |
474 | hmp_handle_error(mon, err); | |
475 | } | |
476 | ||
477 | void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) | |
478 | { | |
479 | const char *param = qdict_get_str(qdict, "parameter"); | |
480 | const char *valuestr = qdict_get_str(qdict, "value"); | |
481 | Visitor *v = string_input_visitor_new(valuestr); | |
482 | MigrateSetParameters *p = g_new0(MigrateSetParameters, 1); | |
483 | uint64_t valuebw = 0; | |
484 | uint64_t cache_size; | |
485 | Error *err = NULL; | |
486 | int val, ret; | |
487 | ||
488 | val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err); | |
489 | if (val < 0) { | |
490 | goto cleanup; | |
491 | } | |
492 | ||
493 | switch (val) { | |
494 | case MIGRATION_PARAMETER_COMPRESS_LEVEL: | |
495 | p->has_compress_level = true; | |
496 | visit_type_uint8(v, param, &p->compress_level, &err); | |
497 | break; | |
498 | case MIGRATION_PARAMETER_COMPRESS_THREADS: | |
499 | p->has_compress_threads = true; | |
500 | visit_type_uint8(v, param, &p->compress_threads, &err); | |
501 | break; | |
502 | case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD: | |
503 | p->has_compress_wait_thread = true; | |
504 | visit_type_bool(v, param, &p->compress_wait_thread, &err); | |
505 | break; | |
506 | case MIGRATION_PARAMETER_DECOMPRESS_THREADS: | |
507 | p->has_decompress_threads = true; | |
508 | visit_type_uint8(v, param, &p->decompress_threads, &err); | |
509 | break; | |
510 | case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD: | |
511 | p->has_throttle_trigger_threshold = true; | |
512 | visit_type_uint8(v, param, &p->throttle_trigger_threshold, &err); | |
513 | break; | |
514 | case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL: | |
515 | p->has_cpu_throttle_initial = true; | |
516 | visit_type_uint8(v, param, &p->cpu_throttle_initial, &err); | |
517 | break; | |
518 | case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT: | |
519 | p->has_cpu_throttle_increment = true; | |
520 | visit_type_uint8(v, param, &p->cpu_throttle_increment, &err); | |
521 | break; | |
522 | case MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW: | |
523 | p->has_cpu_throttle_tailslow = true; | |
524 | visit_type_bool(v, param, &p->cpu_throttle_tailslow, &err); | |
525 | break; | |
526 | case MIGRATION_PARAMETER_MAX_CPU_THROTTLE: | |
527 | p->has_max_cpu_throttle = true; | |
528 | visit_type_uint8(v, param, &p->max_cpu_throttle, &err); | |
529 | break; | |
530 | case MIGRATION_PARAMETER_TLS_CREDS: | |
531 | p->tls_creds = g_new0(StrOrNull, 1); | |
532 | p->tls_creds->type = QTYPE_QSTRING; | |
533 | visit_type_str(v, param, &p->tls_creds->u.s, &err); | |
534 | break; | |
535 | case MIGRATION_PARAMETER_TLS_HOSTNAME: | |
536 | p->tls_hostname = g_new0(StrOrNull, 1); | |
537 | p->tls_hostname->type = QTYPE_QSTRING; | |
538 | visit_type_str(v, param, &p->tls_hostname->u.s, &err); | |
539 | break; | |
540 | case MIGRATION_PARAMETER_TLS_AUTHZ: | |
541 | p->tls_authz = g_new0(StrOrNull, 1); | |
542 | p->tls_authz->type = QTYPE_QSTRING; | |
543 | visit_type_str(v, param, &p->tls_authz->u.s, &err); | |
544 | break; | |
545 | case MIGRATION_PARAMETER_MAX_BANDWIDTH: | |
546 | p->has_max_bandwidth = true; | |
547 | /* | |
548 | * Can't use visit_type_size() here, because it | |
549 | * defaults to Bytes rather than Mebibytes. | |
550 | */ | |
551 | ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw); | |
552 | if (ret < 0 || valuebw > INT64_MAX | |
553 | || (size_t)valuebw != valuebw) { | |
554 | error_setg(&err, "Invalid size %s", valuestr); | |
555 | break; | |
556 | } | |
557 | p->max_bandwidth = valuebw; | |
558 | break; | |
559 | case MIGRATION_PARAMETER_DOWNTIME_LIMIT: | |
560 | p->has_downtime_limit = true; | |
561 | visit_type_size(v, param, &p->downtime_limit, &err); | |
562 | break; | |
563 | case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY: | |
564 | p->has_x_checkpoint_delay = true; | |
565 | visit_type_uint32(v, param, &p->x_checkpoint_delay, &err); | |
566 | break; | |
567 | case MIGRATION_PARAMETER_BLOCK_INCREMENTAL: | |
568 | p->has_block_incremental = true; | |
569 | visit_type_bool(v, param, &p->block_incremental, &err); | |
570 | break; | |
571 | case MIGRATION_PARAMETER_MULTIFD_CHANNELS: | |
572 | p->has_multifd_channels = true; | |
573 | visit_type_uint8(v, param, &p->multifd_channels, &err); | |
574 | break; | |
575 | case MIGRATION_PARAMETER_MULTIFD_COMPRESSION: | |
576 | p->has_multifd_compression = true; | |
577 | visit_type_MultiFDCompression(v, param, &p->multifd_compression, | |
578 | &err); | |
579 | break; | |
580 | case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL: | |
581 | p->has_multifd_zlib_level = true; | |
582 | visit_type_uint8(v, param, &p->multifd_zlib_level, &err); | |
583 | break; | |
584 | case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL: | |
585 | p->has_multifd_zstd_level = true; | |
586 | visit_type_uint8(v, param, &p->multifd_zstd_level, &err); | |
587 | break; | |
588 | case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE: | |
589 | p->has_xbzrle_cache_size = true; | |
590 | if (!visit_type_size(v, param, &cache_size, &err)) { | |
591 | break; | |
592 | } | |
593 | if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) { | |
594 | error_setg(&err, "Invalid size %s", valuestr); | |
595 | break; | |
596 | } | |
597 | p->xbzrle_cache_size = cache_size; | |
598 | break; | |
599 | case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH: | |
600 | p->has_max_postcopy_bandwidth = true; | |
601 | visit_type_size(v, param, &p->max_postcopy_bandwidth, &err); | |
602 | break; | |
603 | case MIGRATION_PARAMETER_ANNOUNCE_INITIAL: | |
604 | p->has_announce_initial = true; | |
605 | visit_type_size(v, param, &p->announce_initial, &err); | |
606 | break; | |
607 | case MIGRATION_PARAMETER_ANNOUNCE_MAX: | |
608 | p->has_announce_max = true; | |
609 | visit_type_size(v, param, &p->announce_max, &err); | |
610 | break; | |
611 | case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS: | |
612 | p->has_announce_rounds = true; | |
613 | visit_type_size(v, param, &p->announce_rounds, &err); | |
614 | break; | |
615 | case MIGRATION_PARAMETER_ANNOUNCE_STEP: | |
616 | p->has_announce_step = true; | |
617 | visit_type_size(v, param, &p->announce_step, &err); | |
618 | break; | |
619 | case MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING: | |
620 | error_setg(&err, "The block-bitmap-mapping parameter can only be set " | |
621 | "through QMP"); | |
622 | break; | |
623 | default: | |
624 | assert(0); | |
625 | } | |
626 | ||
627 | if (err) { | |
628 | goto cleanup; | |
629 | } | |
630 | ||
631 | qmp_migrate_set_parameters(p, &err); | |
632 | ||
633 | cleanup: | |
634 | qapi_free_MigrateSetParameters(p); | |
635 | visit_free(v); | |
636 | hmp_handle_error(mon, err); | |
637 | } | |
638 | ||
119f50ce MA |
639 | void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict) |
640 | { | |
641 | Error *err = NULL; | |
642 | qmp_migrate_start_postcopy(&err); | |
643 | hmp_handle_error(mon, err); | |
644 | } | |
645 | ||
51e47cf8 | 646 | #ifdef CONFIG_REPLICATION |
119f50ce MA |
647 | void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict) |
648 | { | |
649 | Error *err = NULL; | |
650 | ||
651 | qmp_x_colo_lost_heartbeat(&err); | |
652 | hmp_handle_error(mon, err); | |
653 | } | |
51e47cf8 | 654 | #endif |
119f50ce MA |
655 | |
656 | typedef struct HMPMigrationStatus { | |
657 | QEMUTimer *timer; | |
658 | Monitor *mon; | |
659 | bool is_block_migration; | |
660 | } HMPMigrationStatus; | |
661 | ||
662 | static void hmp_migrate_status_cb(void *opaque) | |
663 | { | |
664 | HMPMigrationStatus *status = opaque; | |
665 | MigrationInfo *info; | |
666 | ||
667 | info = qmp_query_migrate(NULL); | |
668 | if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE || | |
669 | info->status == MIGRATION_STATUS_SETUP) { | |
670 | if (info->disk) { | |
671 | int progress; | |
672 | ||
673 | if (info->disk->remaining) { | |
674 | progress = info->disk->transferred * 100 / info->disk->total; | |
675 | } else { | |
676 | progress = 100; | |
677 | } | |
678 | ||
679 | monitor_printf(status->mon, "Completed %d %%\r", progress); | |
680 | monitor_flush(status->mon); | |
681 | } | |
682 | ||
683 | timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000); | |
684 | } else { | |
685 | if (status->is_block_migration) { | |
686 | monitor_printf(status->mon, "\n"); | |
687 | } | |
688 | if (info->error_desc) { | |
689 | error_report("%s", info->error_desc); | |
690 | } | |
691 | monitor_resume(status->mon); | |
692 | timer_free(status->timer); | |
693 | g_free(status); | |
694 | } | |
695 | ||
696 | qapi_free_MigrationInfo(info); | |
697 | } | |
698 | ||
699 | void hmp_migrate(Monitor *mon, const QDict *qdict) | |
700 | { | |
701 | bool detach = qdict_get_try_bool(qdict, "detach", false); | |
702 | bool blk = qdict_get_try_bool(qdict, "blk", false); | |
703 | bool inc = qdict_get_try_bool(qdict, "inc", false); | |
704 | bool resume = qdict_get_try_bool(qdict, "resume", false); | |
705 | const char *uri = qdict_get_str(qdict, "uri"); | |
706 | Error *err = NULL; | |
707 | ||
708 | qmp_migrate(uri, !!blk, blk, !!inc, inc, | |
709 | false, false, true, resume, &err); | |
710 | if (hmp_handle_error(mon, err)) { | |
711 | return; | |
712 | } | |
713 | ||
714 | if (!detach) { | |
715 | HMPMigrationStatus *status; | |
716 | ||
717 | if (monitor_suspend(mon) < 0) { | |
718 | monitor_printf(mon, "terminal does not allow synchronous " | |
719 | "migration, continuing detached\n"); | |
720 | return; | |
721 | } | |
722 | ||
723 | status = g_malloc0(sizeof(*status)); | |
724 | status->mon = mon; | |
725 | status->is_block_migration = blk || inc; | |
726 | status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb, | |
727 | status); | |
728 | timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME)); | |
729 | } | |
730 | } | |
731 | ||
732 | void migrate_set_capability_completion(ReadLineState *rs, int nb_args, | |
733 | const char *str) | |
734 | { | |
735 | size_t len; | |
736 | ||
737 | len = strlen(str); | |
738 | readline_set_completion_index(rs, len); | |
739 | if (nb_args == 2) { | |
740 | int i; | |
741 | for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) { | |
742 | readline_add_completion_of(rs, str, MigrationCapability_str(i)); | |
743 | } | |
744 | } else if (nb_args == 3) { | |
745 | readline_add_completion_of(rs, str, "on"); | |
746 | readline_add_completion_of(rs, str, "off"); | |
747 | } | |
748 | } | |
749 | ||
750 | void migrate_set_parameter_completion(ReadLineState *rs, int nb_args, | |
751 | const char *str) | |
752 | { | |
753 | size_t len; | |
754 | ||
755 | len = strlen(str); | |
756 | readline_set_completion_index(rs, len); | |
757 | if (nb_args == 2) { | |
758 | int i; | |
759 | for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) { | |
760 | readline_add_completion_of(rs, str, MigrationParameter_str(i)); | |
761 | } | |
762 | } | |
763 | } | |
764 | ||
765 | static void vm_completion(ReadLineState *rs, const char *str) | |
766 | { | |
767 | size_t len; | |
768 | BlockDriverState *bs; | |
769 | BdrvNextIterator it; | |
770 | ||
771 | len = strlen(str); | |
772 | readline_set_completion_index(rs, len); | |
773 | ||
774 | for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { | |
775 | SnapshotInfoList *snapshots, *snapshot; | |
776 | AioContext *ctx = bdrv_get_aio_context(bs); | |
777 | bool ok = false; | |
778 | ||
779 | aio_context_acquire(ctx); | |
780 | if (bdrv_can_snapshot(bs)) { | |
781 | ok = bdrv_query_snapshot_info_list(bs, &snapshots, NULL) == 0; | |
782 | } | |
783 | aio_context_release(ctx); | |
784 | if (!ok) { | |
785 | continue; | |
786 | } | |
787 | ||
788 | snapshot = snapshots; | |
789 | while (snapshot) { | |
790 | readline_add_completion_of(rs, str, snapshot->value->name); | |
791 | readline_add_completion_of(rs, str, snapshot->value->id); | |
792 | snapshot = snapshot->next; | |
793 | } | |
794 | qapi_free_SnapshotInfoList(snapshots); | |
795 | } | |
796 | ||
797 | } | |
798 | ||
799 | void delvm_completion(ReadLineState *rs, int nb_args, const char *str) | |
800 | { | |
801 | if (nb_args == 2) { | |
802 | vm_completion(rs, str); | |
803 | } | |
804 | } | |
805 | ||
806 | void loadvm_completion(ReadLineState *rs, int nb_args, const char *str) | |
807 | { | |
808 | if (nb_args == 2) { | |
809 | vm_completion(rs, str); | |
810 | } | |
811 | } |