2 * HMP commands related to migration
4 * Copyright IBM, Corp. 2011
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
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.
16 #include "qemu/osdep.h"
17 #include "block/qapi.h"
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"
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"
32 #include "sysemu/sysemu.h"
34 #include "migration.h"
36 static void migration_global_dump(Monitor
*mon
)
38 MigrationState
*ms
= migrate_get_current();
40 monitor_printf(mon
, "globals:\n");
41 monitor_printf(mon
, "store-global-state: %s\n",
42 ms
->store_global_state
? "on" : "off");
43 monitor_printf(mon
, "only-migratable: %s\n",
44 only_migratable
? "on" : "off");
45 monitor_printf(mon
, "send-configuration: %s\n",
46 ms
->send_configuration
? "on" : "off");
47 monitor_printf(mon
, "send-section-footer: %s\n",
48 ms
->send_section_footer
? "on" : "off");
49 monitor_printf(mon
, "clear-bitmap-shift: %u\n",
50 ms
->clear_bitmap_shift
);
53 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
57 info
= qmp_query_migrate(NULL
);
59 migration_global_dump(mon
);
61 if (info
->blocked_reasons
) {
62 strList
*reasons
= info
->blocked_reasons
;
63 monitor_printf(mon
, "Outgoing migration blocked:\n");
65 monitor_printf(mon
, " %s\n", reasons
->value
);
66 reasons
= reasons
->next
;
70 if (info
->has_status
) {
71 monitor_printf(mon
, "Migration status: %s",
72 MigrationStatus_str(info
->status
));
73 if (info
->status
== MIGRATION_STATUS_FAILED
&& info
->error_desc
) {
74 monitor_printf(mon
, " (%s)\n", info
->error_desc
);
76 monitor_printf(mon
, "\n");
79 monitor_printf(mon
, "total time: %" PRIu64
" ms\n",
81 if (info
->has_expected_downtime
) {
82 monitor_printf(mon
, "expected downtime: %" PRIu64
" ms\n",
83 info
->expected_downtime
);
85 if (info
->has_downtime
) {
86 monitor_printf(mon
, "downtime: %" PRIu64
" ms\n",
89 if (info
->has_setup_time
) {
90 monitor_printf(mon
, "setup: %" PRIu64
" ms\n",
96 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
97 info
->ram
->transferred
>> 10);
98 monitor_printf(mon
, "throughput: %0.2f mbps\n",
100 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
101 info
->ram
->remaining
>> 10);
102 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
103 info
->ram
->total
>> 10);
104 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
105 info
->ram
->duplicate
);
106 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
108 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
109 info
->ram
->normal_bytes
>> 10);
110 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
111 info
->ram
->dirty_sync_count
);
112 monitor_printf(mon
, "page size: %" PRIu64
" kbytes\n",
113 info
->ram
->page_size
>> 10);
114 monitor_printf(mon
, "multifd bytes: %" PRIu64
" kbytes\n",
115 info
->ram
->multifd_bytes
>> 10);
116 monitor_printf(mon
, "pages-per-second: %" PRIu64
"\n",
117 info
->ram
->pages_per_second
);
119 if (info
->ram
->dirty_pages_rate
) {
120 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
121 info
->ram
->dirty_pages_rate
);
123 if (info
->ram
->postcopy_requests
) {
124 monitor_printf(mon
, "postcopy request count: %" PRIu64
"\n",
125 info
->ram
->postcopy_requests
);
127 if (info
->ram
->precopy_bytes
) {
128 monitor_printf(mon
, "precopy ram: %" PRIu64
" kbytes\n",
129 info
->ram
->precopy_bytes
>> 10);
131 if (info
->ram
->downtime_bytes
) {
132 monitor_printf(mon
, "downtime ram: %" PRIu64
" kbytes\n",
133 info
->ram
->downtime_bytes
>> 10);
135 if (info
->ram
->postcopy_bytes
) {
136 monitor_printf(mon
, "postcopy ram: %" PRIu64
" kbytes\n",
137 info
->ram
->postcopy_bytes
>> 10);
139 if (info
->ram
->dirty_sync_missed_zero_copy
) {
141 "Zero-copy-send fallbacks happened: %" PRIu64
" times\n",
142 info
->ram
->dirty_sync_missed_zero_copy
);
146 if (info
->xbzrle_cache
) {
147 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
148 info
->xbzrle_cache
->cache_size
);
149 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
150 info
->xbzrle_cache
->bytes
>> 10);
151 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
152 info
->xbzrle_cache
->pages
);
153 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
" pages\n",
154 info
->xbzrle_cache
->cache_miss
);
155 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
156 info
->xbzrle_cache
->cache_miss_rate
);
157 monitor_printf(mon
, "xbzrle encoding rate: %0.2f\n",
158 info
->xbzrle_cache
->encoding_rate
);
159 monitor_printf(mon
, "xbzrle overflow: %" PRIu64
"\n",
160 info
->xbzrle_cache
->overflow
);
163 if (info
->has_cpu_throttle_percentage
) {
164 monitor_printf(mon
, "cpu throttle percentage: %" PRIu64
"\n",
165 info
->cpu_throttle_percentage
);
168 if (info
->has_dirty_limit_throttle_time_per_round
) {
169 monitor_printf(mon
, "dirty-limit throttle time: %" PRIu64
" us\n",
170 info
->dirty_limit_throttle_time_per_round
);
173 if (info
->has_dirty_limit_ring_full_time
) {
174 monitor_printf(mon
, "dirty-limit ring full time: %" PRIu64
" us\n",
175 info
->dirty_limit_ring_full_time
);
178 if (info
->has_postcopy_blocktime
) {
179 monitor_printf(mon
, "postcopy blocktime: %u\n",
180 info
->postcopy_blocktime
);
183 if (info
->has_postcopy_vcpu_blocktime
) {
186 v
= string_output_visitor_new(false, &str
);
187 visit_type_uint32List(v
, NULL
, &info
->postcopy_vcpu_blocktime
,
189 visit_complete(v
, &str
);
190 monitor_printf(mon
, "postcopy vcpu blocktime: %s\n", str
);
194 if (info
->has_socket_address
) {
195 SocketAddressList
*addr
;
197 monitor_printf(mon
, "socket address: [\n");
199 for (addr
= info
->socket_address
; addr
; addr
= addr
->next
) {
200 char *s
= socket_uri(addr
->value
);
201 monitor_printf(mon
, "\t%s\n", s
);
204 monitor_printf(mon
, "]\n");
208 monitor_printf(mon
, "vfio device transferred: %" PRIu64
" kbytes\n",
209 info
->vfio
->transferred
>> 10);
212 qapi_free_MigrationInfo(info
);
215 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
217 MigrationCapabilityStatusList
*caps
, *cap
;
219 caps
= qmp_query_migrate_capabilities(NULL
);
222 for (cap
= caps
; cap
; cap
= cap
->next
) {
223 monitor_printf(mon
, "%s: %s\n",
224 MigrationCapability_str(cap
->value
->capability
),
225 cap
->value
->state
? "on" : "off");
229 qapi_free_MigrationCapabilityStatusList(caps
);
232 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
234 MigrationParameters
*params
;
236 params
= qmp_query_migrate_parameters(NULL
);
239 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
240 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL
),
241 params
->announce_initial
);
242 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
243 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX
),
244 params
->announce_max
);
245 monitor_printf(mon
, "%s: %" PRIu64
"\n",
246 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS
),
247 params
->announce_rounds
);
248 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
249 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP
),
250 params
->announce_step
);
251 assert(params
->has_throttle_trigger_threshold
);
252 monitor_printf(mon
, "%s: %u\n",
253 MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD
),
254 params
->throttle_trigger_threshold
);
255 assert(params
->has_cpu_throttle_initial
);
256 monitor_printf(mon
, "%s: %u\n",
257 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
),
258 params
->cpu_throttle_initial
);
259 assert(params
->has_cpu_throttle_increment
);
260 monitor_printf(mon
, "%s: %u\n",
261 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
),
262 params
->cpu_throttle_increment
);
263 assert(params
->has_cpu_throttle_tailslow
);
264 monitor_printf(mon
, "%s: %s\n",
265 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW
),
266 params
->cpu_throttle_tailslow
? "on" : "off");
267 assert(params
->has_max_cpu_throttle
);
268 monitor_printf(mon
, "%s: %u\n",
269 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE
),
270 params
->max_cpu_throttle
);
271 assert(params
->tls_creds
);
272 monitor_printf(mon
, "%s: '%s'\n",
273 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS
),
275 assert(params
->tls_hostname
);
276 monitor_printf(mon
, "%s: '%s'\n",
277 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME
),
278 params
->tls_hostname
);
279 assert(params
->has_max_bandwidth
);
280 monitor_printf(mon
, "%s: %" PRIu64
" bytes/second\n",
281 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH
),
282 params
->max_bandwidth
);
283 assert(params
->has_avail_switchover_bandwidth
);
284 monitor_printf(mon
, "%s: %" PRIu64
" bytes/second\n",
285 MigrationParameter_str(MIGRATION_PARAMETER_AVAIL_SWITCHOVER_BANDWIDTH
),
286 params
->avail_switchover_bandwidth
);
287 assert(params
->has_downtime_limit
);
288 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
289 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT
),
290 params
->downtime_limit
);
291 assert(params
->has_x_checkpoint_delay
);
292 monitor_printf(mon
, "%s: %u ms\n",
293 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
),
294 params
->x_checkpoint_delay
);
295 monitor_printf(mon
, "%s: %u\n",
296 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS
),
297 params
->multifd_channels
);
298 monitor_printf(mon
, "%s: %s\n",
299 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION
),
300 MultiFDCompression_str(params
->multifd_compression
));
301 assert(params
->has_zero_page_detection
);
302 monitor_printf(mon
, "%s: %s\n",
303 MigrationParameter_str(MIGRATION_PARAMETER_ZERO_PAGE_DETECTION
),
304 qapi_enum_lookup(&ZeroPageDetection_lookup
,
305 params
->zero_page_detection
));
306 monitor_printf(mon
, "%s: %" PRIu64
" bytes\n",
307 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
),
308 params
->xbzrle_cache_size
);
309 monitor_printf(mon
, "%s: %" PRIu64
"\n",
310 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH
),
311 params
->max_postcopy_bandwidth
);
312 monitor_printf(mon
, "%s: '%s'\n",
313 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ
),
316 if (params
->has_block_bitmap_mapping
) {
317 const BitmapMigrationNodeAliasList
*bmnal
;
319 monitor_printf(mon
, "%s:\n",
320 MigrationParameter_str(
321 MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING
));
323 for (bmnal
= params
->block_bitmap_mapping
;
327 const BitmapMigrationNodeAlias
*bmna
= bmnal
->value
;
328 const BitmapMigrationBitmapAliasList
*bmbal
;
330 monitor_printf(mon
, " '%s' -> '%s'\n",
331 bmna
->node_name
, bmna
->alias
);
333 for (bmbal
= bmna
->bitmaps
; bmbal
; bmbal
= bmbal
->next
) {
334 const BitmapMigrationBitmapAlias
*bmba
= bmbal
->value
;
336 monitor_printf(mon
, " '%s' -> '%s'\n",
337 bmba
->name
, bmba
->alias
);
342 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
343 MigrationParameter_str(MIGRATION_PARAMETER_X_VCPU_DIRTY_LIMIT_PERIOD
),
344 params
->x_vcpu_dirty_limit_period
);
346 monitor_printf(mon
, "%s: %" PRIu64
" MB/s\n",
347 MigrationParameter_str(MIGRATION_PARAMETER_VCPU_DIRTY_LIMIT
),
348 params
->vcpu_dirty_limit
);
350 assert(params
->has_mode
);
351 monitor_printf(mon
, "%s: %s\n",
352 MigrationParameter_str(MIGRATION_PARAMETER_MODE
),
353 qapi_enum_lookup(&MigMode_lookup
, params
->mode
));
355 if (params
->has_direct_io
) {
356 monitor_printf(mon
, "%s: %s\n",
357 MigrationParameter_str(
358 MIGRATION_PARAMETER_DIRECT_IO
),
359 params
->direct_io
? "on" : "off");
363 qapi_free_MigrationParameters(params
);
366 void hmp_loadvm(Monitor
*mon
, const QDict
*qdict
)
368 RunState saved_state
= runstate_get();
370 const char *name
= qdict_get_str(qdict
, "name");
373 vm_stop(RUN_STATE_RESTORE_VM
);
375 if (load_snapshot(name
, NULL
, false, NULL
, &err
)) {
376 load_snapshot_resume(saved_state
);
379 hmp_handle_error(mon
, err
);
382 void hmp_savevm(Monitor
*mon
, const QDict
*qdict
)
386 save_snapshot(qdict_get_try_str(qdict
, "name"),
387 true, NULL
, false, NULL
, &err
);
388 hmp_handle_error(mon
, err
);
391 void hmp_delvm(Monitor
*mon
, const QDict
*qdict
)
394 const char *name
= qdict_get_str(qdict
, "name");
396 delete_snapshot(name
, false, NULL
, &err
);
397 hmp_handle_error(mon
, err
);
400 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
402 qmp_migrate_cancel(NULL
);
405 void hmp_migrate_continue(Monitor
*mon
, const QDict
*qdict
)
408 const char *state
= qdict_get_str(qdict
, "state");
409 int val
= qapi_enum_parse(&MigrationStatus_lookup
, state
, -1, &err
);
412 qmp_migrate_continue(val
, &err
);
415 hmp_handle_error(mon
, err
);
418 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
421 const char *uri
= qdict_get_str(qdict
, "uri");
422 MigrationChannelList
*caps
= NULL
;
423 g_autoptr(MigrationChannel
) channel
= NULL
;
425 if (!migrate_uri_parse(uri
, &channel
, &err
)) {
428 QAPI_LIST_PREPEND(caps
, g_steal_pointer(&channel
));
430 qmp_migrate_incoming(NULL
, true, caps
, true, false, &err
);
431 qapi_free_MigrationChannelList(caps
);
434 hmp_handle_error(mon
, err
);
437 void hmp_migrate_recover(Monitor
*mon
, const QDict
*qdict
)
440 const char *uri
= qdict_get_str(qdict
, "uri");
442 qmp_migrate_recover(uri
, &err
);
444 hmp_handle_error(mon
, err
);
447 void hmp_migrate_pause(Monitor
*mon
, const QDict
*qdict
)
451 qmp_migrate_pause(&err
);
453 hmp_handle_error(mon
, err
);
457 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
459 const char *cap
= qdict_get_str(qdict
, "capability");
460 bool state
= qdict_get_bool(qdict
, "state");
462 MigrationCapabilityStatusList
*caps
= NULL
;
463 MigrationCapabilityStatus
*value
;
466 val
= qapi_enum_parse(&MigrationCapability_lookup
, cap
, -1, &err
);
471 value
= g_malloc0(sizeof(*value
));
472 value
->capability
= val
;
473 value
->state
= state
;
474 QAPI_LIST_PREPEND(caps
, value
);
475 qmp_migrate_set_capabilities(caps
, &err
);
476 qapi_free_MigrationCapabilityStatusList(caps
);
479 hmp_handle_error(mon
, err
);
482 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
484 const char *param
= qdict_get_str(qdict
, "parameter");
485 const char *valuestr
= qdict_get_str(qdict
, "value");
486 Visitor
*v
= string_input_visitor_new(valuestr
);
487 MigrateSetParameters
*p
= g_new0(MigrateSetParameters
, 1);
488 uint64_t valuebw
= 0;
493 val
= qapi_enum_parse(&MigrationParameter_lookup
, param
, -1, &err
);
499 case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD
:
500 p
->has_throttle_trigger_threshold
= true;
501 visit_type_uint8(v
, param
, &p
->throttle_trigger_threshold
, &err
);
503 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
504 p
->has_cpu_throttle_initial
= true;
505 visit_type_uint8(v
, param
, &p
->cpu_throttle_initial
, &err
);
507 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
508 p
->has_cpu_throttle_increment
= true;
509 visit_type_uint8(v
, param
, &p
->cpu_throttle_increment
, &err
);
511 case MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW
:
512 p
->has_cpu_throttle_tailslow
= true;
513 visit_type_bool(v
, param
, &p
->cpu_throttle_tailslow
, &err
);
515 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE
:
516 p
->has_max_cpu_throttle
= true;
517 visit_type_uint8(v
, param
, &p
->max_cpu_throttle
, &err
);
519 case MIGRATION_PARAMETER_TLS_CREDS
:
520 p
->tls_creds
= g_new0(StrOrNull
, 1);
521 p
->tls_creds
->type
= QTYPE_QSTRING
;
522 visit_type_str(v
, param
, &p
->tls_creds
->u
.s
, &err
);
524 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
525 p
->tls_hostname
= g_new0(StrOrNull
, 1);
526 p
->tls_hostname
->type
= QTYPE_QSTRING
;
527 visit_type_str(v
, param
, &p
->tls_hostname
->u
.s
, &err
);
529 case MIGRATION_PARAMETER_TLS_AUTHZ
:
530 p
->tls_authz
= g_new0(StrOrNull
, 1);
531 p
->tls_authz
->type
= QTYPE_QSTRING
;
532 visit_type_str(v
, param
, &p
->tls_authz
->u
.s
, &err
);
534 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
535 p
->has_max_bandwidth
= true;
537 * Can't use visit_type_size() here, because it
538 * defaults to Bytes rather than Mebibytes.
540 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
541 if (ret
< 0 || valuebw
> INT64_MAX
542 || (size_t)valuebw
!= valuebw
) {
543 error_setg(&err
, "Invalid size %s", valuestr
);
546 p
->max_bandwidth
= valuebw
;
548 case MIGRATION_PARAMETER_AVAIL_SWITCHOVER_BANDWIDTH
:
549 p
->has_avail_switchover_bandwidth
= true;
550 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
551 if (ret
< 0 || valuebw
> INT64_MAX
552 || (size_t)valuebw
!= valuebw
) {
553 error_setg(&err
, "Invalid size %s", valuestr
);
556 p
->avail_switchover_bandwidth
= valuebw
;
558 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
559 p
->has_downtime_limit
= true;
560 visit_type_size(v
, param
, &p
->downtime_limit
, &err
);
562 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
563 p
->has_x_checkpoint_delay
= true;
564 visit_type_uint32(v
, param
, &p
->x_checkpoint_delay
, &err
);
566 case MIGRATION_PARAMETER_MULTIFD_CHANNELS
:
567 p
->has_multifd_channels
= true;
568 visit_type_uint8(v
, param
, &p
->multifd_channels
, &err
);
570 case MIGRATION_PARAMETER_MULTIFD_COMPRESSION
:
571 p
->has_multifd_compression
= true;
572 visit_type_MultiFDCompression(v
, param
, &p
->multifd_compression
,
575 case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL
:
576 p
->has_multifd_zlib_level
= true;
577 visit_type_uint8(v
, param
, &p
->multifd_zlib_level
, &err
);
579 case MIGRATION_PARAMETER_MULTIFD_QATZIP_LEVEL
:
580 p
->has_multifd_qatzip_level
= true;
581 visit_type_uint8(v
, param
, &p
->multifd_qatzip_level
, &err
);
583 case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL
:
584 p
->has_multifd_zstd_level
= true;
585 visit_type_uint8(v
, param
, &p
->multifd_zstd_level
, &err
);
587 case MIGRATION_PARAMETER_ZERO_PAGE_DETECTION
:
588 p
->has_zero_page_detection
= true;
589 visit_type_ZeroPageDetection(v
, param
, &p
->zero_page_detection
, &err
);
591 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
:
592 p
->has_xbzrle_cache_size
= true;
593 if (!visit_type_size(v
, param
, &cache_size
, &err
)) {
596 if (cache_size
> INT64_MAX
|| (size_t)cache_size
!= cache_size
) {
597 error_setg(&err
, "Invalid size %s", valuestr
);
600 p
->xbzrle_cache_size
= cache_size
;
602 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH
:
603 p
->has_max_postcopy_bandwidth
= true;
604 visit_type_size(v
, param
, &p
->max_postcopy_bandwidth
, &err
);
606 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL
:
607 p
->has_announce_initial
= true;
608 visit_type_size(v
, param
, &p
->announce_initial
, &err
);
610 case MIGRATION_PARAMETER_ANNOUNCE_MAX
:
611 p
->has_announce_max
= true;
612 visit_type_size(v
, param
, &p
->announce_max
, &err
);
614 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS
:
615 p
->has_announce_rounds
= true;
616 visit_type_size(v
, param
, &p
->announce_rounds
, &err
);
618 case MIGRATION_PARAMETER_ANNOUNCE_STEP
:
619 p
->has_announce_step
= true;
620 visit_type_size(v
, param
, &p
->announce_step
, &err
);
622 case MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING
:
623 error_setg(&err
, "The block-bitmap-mapping parameter can only be set "
626 case MIGRATION_PARAMETER_X_VCPU_DIRTY_LIMIT_PERIOD
:
627 p
->has_x_vcpu_dirty_limit_period
= true;
628 visit_type_size(v
, param
, &p
->x_vcpu_dirty_limit_period
, &err
);
630 case MIGRATION_PARAMETER_VCPU_DIRTY_LIMIT
:
631 p
->has_vcpu_dirty_limit
= true;
632 visit_type_size(v
, param
, &p
->vcpu_dirty_limit
, &err
);
634 case MIGRATION_PARAMETER_MODE
:
636 visit_type_MigMode(v
, param
, &p
->mode
, &err
);
638 case MIGRATION_PARAMETER_DIRECT_IO
:
639 p
->has_direct_io
= true;
640 visit_type_bool(v
, param
, &p
->direct_io
, &err
);
643 g_assert_not_reached();
650 qmp_migrate_set_parameters(p
, &err
);
653 qapi_free_MigrateSetParameters(p
);
655 hmp_handle_error(mon
, err
);
658 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
661 qmp_migrate_start_postcopy(&err
);
662 hmp_handle_error(mon
, err
);
665 #ifdef CONFIG_REPLICATION
666 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
670 qmp_x_colo_lost_heartbeat(&err
);
671 hmp_handle_error(mon
, err
);
675 typedef struct HMPMigrationStatus
{
678 } HMPMigrationStatus
;
680 static void hmp_migrate_status_cb(void *opaque
)
682 HMPMigrationStatus
*status
= opaque
;
685 info
= qmp_query_migrate(NULL
);
686 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
687 info
->status
== MIGRATION_STATUS_SETUP
) {
688 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
690 if (info
->error_desc
) {
691 error_report("%s", info
->error_desc
);
693 monitor_resume(status
->mon
);
694 timer_free(status
->timer
);
698 qapi_free_MigrationInfo(info
);
701 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
703 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
704 bool resume
= qdict_get_try_bool(qdict
, "resume", false);
705 const char *uri
= qdict_get_str(qdict
, "uri");
707 g_autoptr(MigrationChannelList
) caps
= NULL
;
708 g_autoptr(MigrationChannel
) channel
= NULL
;
710 if (!migrate_uri_parse(uri
, &channel
, &err
)) {
711 hmp_handle_error(mon
, err
);
714 QAPI_LIST_PREPEND(caps
, g_steal_pointer(&channel
));
716 qmp_migrate(NULL
, true, caps
, false, false, true, resume
, &err
);
717 if (hmp_handle_error(mon
, err
)) {
722 HMPMigrationStatus
*status
;
724 if (monitor_suspend(mon
) < 0) {
725 monitor_printf(mon
, "terminal does not allow synchronous "
726 "migration, continuing detached\n");
730 status
= g_malloc0(sizeof(*status
));
732 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
734 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
738 void migrate_set_capability_completion(ReadLineState
*rs
, int nb_args
,
744 readline_set_completion_index(rs
, len
);
747 for (i
= 0; i
< MIGRATION_CAPABILITY__MAX
; i
++) {
748 readline_add_completion_of(rs
, str
, MigrationCapability_str(i
));
750 } else if (nb_args
== 3) {
751 readline_add_completion_of(rs
, str
, "on");
752 readline_add_completion_of(rs
, str
, "off");
756 void migrate_set_parameter_completion(ReadLineState
*rs
, int nb_args
,
762 readline_set_completion_index(rs
, len
);
765 for (i
= 0; i
< MIGRATION_PARAMETER__MAX
; i
++) {
766 readline_add_completion_of(rs
, str
, MigrationParameter_str(i
));
771 static void vm_completion(ReadLineState
*rs
, const char *str
)
774 BlockDriverState
*bs
;
777 GRAPH_RDLOCK_GUARD_MAINLOOP();
780 readline_set_completion_index(rs
, len
);
782 for (bs
= bdrv_first(&it
); bs
; bs
= bdrv_next(&it
)) {
783 SnapshotInfoList
*snapshots
, *snapshot
;
786 if (bdrv_can_snapshot(bs
)) {
787 ok
= bdrv_query_snapshot_info_list(bs
, &snapshots
, NULL
) == 0;
793 snapshot
= snapshots
;
795 readline_add_completion_of(rs
, str
, snapshot
->value
->name
);
796 readline_add_completion_of(rs
, str
, snapshot
->value
->id
);
797 snapshot
= snapshot
->next
;
799 qapi_free_SnapshotInfoList(snapshots
);
804 void delvm_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
807 vm_completion(rs
, str
);
811 void loadvm_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
814 vm_completion(rs
, str
);