2 * Human Monitor Interface
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.
18 #include "qemu-option.h"
19 #include "qemu-timer.h"
20 #include "qmp-commands.h"
21 #include "qemu_socket.h"
25 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
27 if (error_is_set(errp
)) {
28 monitor_printf(mon
, "%s\n", error_get_pretty(*errp
));
33 void hmp_info_name(Monitor
*mon
)
37 info
= qmp_query_name(NULL
);
39 monitor_printf(mon
, "%s\n", info
->name
);
41 qapi_free_NameInfo(info
);
44 void hmp_info_version(Monitor
*mon
)
48 info
= qmp_query_version(NULL
);
50 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
51 info
->qemu
.major
, info
->qemu
.minor
, info
->qemu
.micro
,
54 qapi_free_VersionInfo(info
);
57 void hmp_info_kvm(Monitor
*mon
)
61 info
= qmp_query_kvm(NULL
);
62 monitor_printf(mon
, "kvm support: ");
64 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
66 monitor_printf(mon
, "not compiled\n");
69 qapi_free_KvmInfo(info
);
72 void hmp_info_status(Monitor
*mon
)
76 info
= qmp_query_status(NULL
);
78 monitor_printf(mon
, "VM status: %s%s",
79 info
->running
? "running" : "paused",
80 info
->singlestep
? " (single step mode)" : "");
82 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
83 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
86 monitor_printf(mon
, "\n");
88 qapi_free_StatusInfo(info
);
91 void hmp_info_uuid(Monitor
*mon
)
95 info
= qmp_query_uuid(NULL
);
96 monitor_printf(mon
, "%s\n", info
->UUID
);
97 qapi_free_UuidInfo(info
);
100 void hmp_info_chardev(Monitor
*mon
)
102 ChardevInfoList
*char_info
, *info
;
104 char_info
= qmp_query_chardev(NULL
);
105 for (info
= char_info
; info
; info
= info
->next
) {
106 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
107 info
->value
->filename
);
110 qapi_free_ChardevInfoList(char_info
);
113 void hmp_info_mice(Monitor
*mon
)
115 MouseInfoList
*mice_list
, *mouse
;
117 mice_list
= qmp_query_mice(NULL
);
119 monitor_printf(mon
, "No mouse devices connected\n");
123 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
124 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
125 mouse
->value
->current
? '*' : ' ',
126 mouse
->value
->index
, mouse
->value
->name
,
127 mouse
->value
->absolute
? " (absolute)" : "");
130 qapi_free_MouseInfoList(mice_list
);
133 void hmp_info_migrate(Monitor
*mon
)
136 MigrationCapabilityStatusList
*caps
, *cap
;
138 info
= qmp_query_migrate(NULL
);
139 caps
= qmp_query_migrate_capabilities(NULL
);
141 /* do not display parameters during setup */
142 if (info
->has_status
&& caps
) {
143 monitor_printf(mon
, "capabilities: ");
144 for (cap
= caps
; cap
; cap
= cap
->next
) {
145 monitor_printf(mon
, "%s: %s ",
146 MigrationCapability_lookup
[cap
->value
->capability
],
147 cap
->value
->state
? "on" : "off");
149 monitor_printf(mon
, "\n");
152 if (info
->has_status
) {
153 monitor_printf(mon
, "Migration status: %s\n", info
->status
);
154 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
156 if (info
->has_expected_downtime
) {
157 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
158 info
->expected_downtime
);
160 if (info
->has_downtime
) {
161 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
167 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
168 info
->ram
->transferred
>> 10);
169 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
170 info
->ram
->remaining
>> 10);
171 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
172 info
->ram
->total
>> 10);
173 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
174 info
->ram
->duplicate
);
175 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
177 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
178 info
->ram
->normal_bytes
>> 10);
179 if (info
->ram
->dirty_pages_rate
) {
180 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
181 info
->ram
->dirty_pages_rate
);
185 if (info
->has_disk
) {
186 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
187 info
->disk
->transferred
>> 10);
188 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
189 info
->disk
->remaining
>> 10);
190 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
191 info
->disk
->total
>> 10);
194 if (info
->has_xbzrle_cache
) {
195 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
196 info
->xbzrle_cache
->cache_size
);
197 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
198 info
->xbzrle_cache
->bytes
>> 10);
199 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
200 info
->xbzrle_cache
->pages
);
201 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
202 info
->xbzrle_cache
->cache_miss
);
203 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
204 info
->xbzrle_cache
->overflow
);
207 qapi_free_MigrationInfo(info
);
208 qapi_free_MigrationCapabilityStatusList(caps
);
211 void hmp_info_migrate_capabilities(Monitor
*mon
)
213 MigrationCapabilityStatusList
*caps
, *cap
;
215 caps
= qmp_query_migrate_capabilities(NULL
);
218 monitor_printf(mon
, "capabilities: ");
219 for (cap
= caps
; cap
; cap
= cap
->next
) {
220 monitor_printf(mon
, "%s: %s ",
221 MigrationCapability_lookup
[cap
->value
->capability
],
222 cap
->value
->state
? "on" : "off");
224 monitor_printf(mon
, "\n");
227 qapi_free_MigrationCapabilityStatusList(caps
);
230 void hmp_info_migrate_cache_size(Monitor
*mon
)
232 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
233 qmp_query_migrate_cache_size(NULL
) >> 10);
236 void hmp_info_cpus(Monitor
*mon
)
238 CpuInfoList
*cpu_list
, *cpu
;
240 cpu_list
= qmp_query_cpus(NULL
);
242 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
245 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
249 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
251 if (cpu
->value
->has_pc
) {
252 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->pc
);
254 if (cpu
->value
->has_nip
) {
255 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->nip
);
257 if (cpu
->value
->has_npc
) {
258 monitor_printf(mon
, " npc=0x%016" PRIx64
, cpu
->value
->npc
);
260 if (cpu
->value
->has_PC
) {
261 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->PC
);
264 if (cpu
->value
->halted
) {
265 monitor_printf(mon
, " (halted)");
268 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
271 qapi_free_CpuInfoList(cpu_list
);
274 void hmp_info_block(Monitor
*mon
)
276 BlockInfoList
*block_list
, *info
;
278 block_list
= qmp_query_block(NULL
);
280 for (info
= block_list
; info
; info
= info
->next
) {
281 monitor_printf(mon
, "%s: removable=%d",
282 info
->value
->device
, info
->value
->removable
);
284 if (info
->value
->removable
) {
285 monitor_printf(mon
, " locked=%d", info
->value
->locked
);
286 monitor_printf(mon
, " tray-open=%d", info
->value
->tray_open
);
289 if (info
->value
->has_io_status
) {
290 monitor_printf(mon
, " io-status=%s",
291 BlockDeviceIoStatus_lookup
[info
->value
->io_status
]);
294 if (info
->value
->has_inserted
) {
295 monitor_printf(mon
, " file=");
296 monitor_print_filename(mon
, info
->value
->inserted
->file
);
298 if (info
->value
->inserted
->has_backing_file
) {
299 monitor_printf(mon
, " backing_file=");
300 monitor_print_filename(mon
, info
->value
->inserted
->backing_file
);
301 monitor_printf(mon
, " backing_file_depth=%" PRId64
,
302 info
->value
->inserted
->backing_file_depth
);
304 monitor_printf(mon
, " ro=%d drv=%s encrypted=%d",
305 info
->value
->inserted
->ro
,
306 info
->value
->inserted
->drv
,
307 info
->value
->inserted
->encrypted
);
309 monitor_printf(mon
, " bps=%" PRId64
" bps_rd=%" PRId64
310 " bps_wr=%" PRId64
" iops=%" PRId64
311 " iops_rd=%" PRId64
" iops_wr=%" PRId64
,
312 info
->value
->inserted
->bps
,
313 info
->value
->inserted
->bps_rd
,
314 info
->value
->inserted
->bps_wr
,
315 info
->value
->inserted
->iops
,
316 info
->value
->inserted
->iops_rd
,
317 info
->value
->inserted
->iops_wr
);
319 monitor_printf(mon
, " [not inserted]");
322 monitor_printf(mon
, "\n");
325 qapi_free_BlockInfoList(block_list
);
328 void hmp_info_blockstats(Monitor
*mon
)
330 BlockStatsList
*stats_list
, *stats
;
332 stats_list
= qmp_query_blockstats(NULL
);
334 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
335 if (!stats
->value
->has_device
) {
339 monitor_printf(mon
, "%s:", stats
->value
->device
);
340 monitor_printf(mon
, " rd_bytes=%" PRId64
342 " rd_operations=%" PRId64
343 " wr_operations=%" PRId64
344 " flush_operations=%" PRId64
345 " wr_total_time_ns=%" PRId64
346 " rd_total_time_ns=%" PRId64
347 " flush_total_time_ns=%" PRId64
349 stats
->value
->stats
->rd_bytes
,
350 stats
->value
->stats
->wr_bytes
,
351 stats
->value
->stats
->rd_operations
,
352 stats
->value
->stats
->wr_operations
,
353 stats
->value
->stats
->flush_operations
,
354 stats
->value
->stats
->wr_total_time_ns
,
355 stats
->value
->stats
->rd_total_time_ns
,
356 stats
->value
->stats
->flush_total_time_ns
);
359 qapi_free_BlockStatsList(stats_list
);
362 void hmp_info_vnc(Monitor
*mon
)
366 VncClientInfoList
*client
;
368 info
= qmp_query_vnc(&err
);
370 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
375 if (!info
->enabled
) {
376 monitor_printf(mon
, "Server: disabled\n");
380 monitor_printf(mon
, "Server:\n");
381 if (info
->has_host
&& info
->has_service
) {
382 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
384 if (info
->has_auth
) {
385 monitor_printf(mon
, " auth: %s\n", info
->auth
);
388 if (!info
->has_clients
|| info
->clients
== NULL
) {
389 monitor_printf(mon
, "Client: none\n");
391 for (client
= info
->clients
; client
; client
= client
->next
) {
392 monitor_printf(mon
, "Client:\n");
393 monitor_printf(mon
, " address: %s:%s\n",
394 client
->value
->host
, client
->value
->service
);
395 monitor_printf(mon
, " x509_dname: %s\n",
396 client
->value
->x509_dname
?
397 client
->value
->x509_dname
: "none");
398 monitor_printf(mon
, " username: %s\n",
399 client
->value
->has_sasl_username
?
400 client
->value
->sasl_username
: "none");
405 qapi_free_VncInfo(info
);
408 void hmp_info_spice(Monitor
*mon
)
410 SpiceChannelList
*chan
;
413 info
= qmp_query_spice(NULL
);
415 if (!info
->enabled
) {
416 monitor_printf(mon
, "Server: disabled\n");
420 monitor_printf(mon
, "Server:\n");
421 if (info
->has_port
) {
422 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
423 info
->host
, info
->port
);
425 if (info
->has_tls_port
) {
426 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
427 info
->host
, info
->tls_port
);
429 monitor_printf(mon
, " migrated: %s\n",
430 info
->migrated
? "true" : "false");
431 monitor_printf(mon
, " auth: %s\n", info
->auth
);
432 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
433 monitor_printf(mon
, " mouse-mode: %s\n",
434 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
436 if (!info
->has_channels
|| info
->channels
== NULL
) {
437 monitor_printf(mon
, "Channels: none\n");
439 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
440 monitor_printf(mon
, "Channel:\n");
441 monitor_printf(mon
, " address: %s:%s%s\n",
442 chan
->value
->host
, chan
->value
->port
,
443 chan
->value
->tls
? " [tls]" : "");
444 monitor_printf(mon
, " session: %" PRId64
"\n",
445 chan
->value
->connection_id
);
446 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
447 chan
->value
->channel_type
, chan
->value
->channel_id
);
452 qapi_free_SpiceInfo(info
);
455 void hmp_info_balloon(Monitor
*mon
)
460 info
= qmp_query_balloon(&err
);
462 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
467 monitor_printf(mon
, "balloon: actual=%" PRId64
, info
->actual
>> 20);
468 if (info
->has_mem_swapped_in
) {
469 monitor_printf(mon
, " mem_swapped_in=%" PRId64
, info
->mem_swapped_in
);
471 if (info
->has_mem_swapped_out
) {
472 monitor_printf(mon
, " mem_swapped_out=%" PRId64
, info
->mem_swapped_out
);
474 if (info
->has_major_page_faults
) {
475 monitor_printf(mon
, " major_page_faults=%" PRId64
,
476 info
->major_page_faults
);
478 if (info
->has_minor_page_faults
) {
479 monitor_printf(mon
, " minor_page_faults=%" PRId64
,
480 info
->minor_page_faults
);
482 if (info
->has_free_mem
) {
483 monitor_printf(mon
, " free_mem=%" PRId64
, info
->free_mem
);
485 if (info
->has_total_mem
) {
486 monitor_printf(mon
, " total_mem=%" PRId64
, info
->total_mem
);
489 monitor_printf(mon
, "\n");
491 qapi_free_BalloonInfo(info
);
494 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
496 PciMemoryRegionList
*region
;
498 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
499 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
500 dev
->slot
, dev
->function
);
501 monitor_printf(mon
, " ");
503 if (dev
->class_info
.has_desc
) {
504 monitor_printf(mon
, "%s", dev
->class_info
.desc
);
506 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
.class);
509 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
510 dev
->id
.vendor
, dev
->id
.device
);
513 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
516 if (dev
->has_pci_bridge
) {
517 monitor_printf(mon
, " BUS %" PRId64
".\n",
518 dev
->pci_bridge
->bus
.number
);
519 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
520 dev
->pci_bridge
->bus
.secondary
);
521 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
522 dev
->pci_bridge
->bus
.subordinate
);
524 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
525 dev
->pci_bridge
->bus
.io_range
->base
,
526 dev
->pci_bridge
->bus
.io_range
->limit
);
529 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
530 dev
->pci_bridge
->bus
.memory_range
->base
,
531 dev
->pci_bridge
->bus
.memory_range
->limit
);
533 monitor_printf(mon
, " prefetchable memory range "
534 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
535 dev
->pci_bridge
->bus
.prefetchable_range
->base
,
536 dev
->pci_bridge
->bus
.prefetchable_range
->limit
);
539 for (region
= dev
->regions
; region
; region
= region
->next
) {
542 addr
= region
->value
->address
;
543 size
= region
->value
->size
;
545 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
547 if (!strcmp(region
->value
->type
, "io")) {
548 monitor_printf(mon
, "I/O at 0x%04" PRIx64
549 " [0x%04" PRIx64
"].\n",
550 addr
, addr
+ size
- 1);
552 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
553 " [0x%08" PRIx64
"].\n",
554 region
->value
->mem_type_64
? 64 : 32,
555 region
->value
->prefetch
? " prefetchable" : "",
556 addr
, addr
+ size
- 1);
560 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
562 if (dev
->has_pci_bridge
) {
563 if (dev
->pci_bridge
->has_devices
) {
564 PciDeviceInfoList
*cdev
;
565 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
566 hmp_info_pci_device(mon
, cdev
->value
);
572 void hmp_info_pci(Monitor
*mon
)
574 PciInfoList
*info_list
, *info
;
577 info_list
= qmp_query_pci(&err
);
579 monitor_printf(mon
, "PCI devices not supported\n");
584 for (info
= info_list
; info
; info
= info
->next
) {
585 PciDeviceInfoList
*dev
;
587 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
588 hmp_info_pci_device(mon
, dev
->value
);
592 qapi_free_PciInfoList(info_list
);
595 void hmp_info_block_jobs(Monitor
*mon
)
597 BlockJobInfoList
*list
;
600 list
= qmp_query_block_jobs(&err
);
604 monitor_printf(mon
, "No active jobs\n");
609 if (strcmp(list
->value
->type
, "stream") == 0) {
610 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
611 " of %" PRId64
" bytes, speed limit %" PRId64
618 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
619 " of %" PRId64
" bytes, speed limit %" PRId64
631 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
633 monitor_suspend(mon
);
637 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
642 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
644 qmp_system_reset(NULL
);
647 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
649 qmp_system_powerdown(NULL
);
652 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
656 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
657 use it are converted to the QAPI */
658 cpu_index
= qdict_get_int(qdict
, "index");
659 if (monitor_set_cpu(cpu_index
) < 0) {
660 monitor_printf(mon
, "invalid CPU index\n");
664 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
666 uint32_t size
= qdict_get_int(qdict
, "size");
667 const char *filename
= qdict_get_str(qdict
, "filename");
668 uint64_t addr
= qdict_get_int(qdict
, "val");
671 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &errp
);
672 hmp_handle_error(mon
, &errp
);
675 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
677 uint32_t size
= qdict_get_int(qdict
, "size");
678 const char *filename
= qdict_get_str(qdict
, "filename");
679 uint64_t addr
= qdict_get_int(qdict
, "val");
682 qmp_pmemsave(addr
, size
, filename
, &errp
);
683 hmp_handle_error(mon
, &errp
);
686 static void hmp_cont_cb(void *opaque
, int err
)
693 static bool key_is_missing(const BlockInfo
*bdev
)
695 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
698 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
700 BlockInfoList
*bdev_list
, *bdev
;
703 bdev_list
= qmp_query_block(NULL
);
704 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
705 if (key_is_missing(bdev
->value
)) {
706 monitor_read_block_device_key(mon
, bdev
->value
->device
,
713 hmp_handle_error(mon
, &errp
);
716 qapi_free_BlockInfoList(bdev_list
);
719 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
721 qmp_system_wakeup(NULL
);
724 void hmp_inject_nmi(Monitor
*mon
, const QDict
*qdict
)
728 qmp_inject_nmi(&errp
);
729 hmp_handle_error(mon
, &errp
);
732 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
734 const char *name
= qdict_get_str(qdict
, "name");
735 int up
= qdict_get_bool(qdict
, "up");
738 qmp_set_link(name
, up
, &errp
);
739 hmp_handle_error(mon
, &errp
);
742 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
744 const char *device
= qdict_get_str(qdict
, "device");
745 const char *password
= qdict_get_str(qdict
, "password");
748 qmp_block_passwd(device
, password
, &errp
);
749 hmp_handle_error(mon
, &errp
);
752 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
754 int64_t value
= qdict_get_int(qdict
, "value");
757 qmp_balloon(value
, &errp
);
758 if (error_is_set(&errp
)) {
759 monitor_printf(mon
, "balloon: %s\n", error_get_pretty(errp
));
764 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
766 const char *device
= qdict_get_str(qdict
, "device");
767 int64_t size
= qdict_get_int(qdict
, "size");
770 qmp_block_resize(device
, size
, &errp
);
771 hmp_handle_error(mon
, &errp
);
774 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
776 const char *device
= qdict_get_str(qdict
, "device");
777 const char *filename
= qdict_get_str(qdict
, "target");
778 const char *format
= qdict_get_try_str(qdict
, "format");
779 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
780 int full
= qdict_get_try_bool(qdict
, "full", 0);
781 enum NewImageMode mode
;
785 error_set(&errp
, QERR_MISSING_PARAMETER
, "target");
786 hmp_handle_error(mon
, &errp
);
791 mode
= NEW_IMAGE_MODE_EXISTING
;
793 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
796 qmp_drive_mirror(device
, filename
, !!format
, format
,
797 full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
798 true, mode
, false, 0,
799 false, 0, false, 0, &errp
);
800 hmp_handle_error(mon
, &errp
);
803 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
805 const char *device
= qdict_get_str(qdict
, "device");
806 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
807 const char *format
= qdict_get_try_str(qdict
, "format");
808 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
809 enum NewImageMode mode
;
813 /* In the future, if 'snapshot-file' is not specified, the snapshot
814 will be taken internally. Today it's actually required. */
815 error_set(&errp
, QERR_MISSING_PARAMETER
, "snapshot-file");
816 hmp_handle_error(mon
, &errp
);
820 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
821 qmp_blockdev_snapshot_sync(device
, filename
, !!format
, format
,
823 hmp_handle_error(mon
, &errp
);
826 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
828 qmp_migrate_cancel(NULL
);
831 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
833 double value
= qdict_get_double(qdict
, "value");
834 qmp_migrate_set_downtime(value
, NULL
);
837 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
839 int64_t value
= qdict_get_int(qdict
, "value");
842 qmp_migrate_set_cache_size(value
, &err
);
844 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
850 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
852 int64_t value
= qdict_get_int(qdict
, "value");
853 qmp_migrate_set_speed(value
, NULL
);
856 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
858 const char *cap
= qdict_get_str(qdict
, "capability");
859 bool state
= qdict_get_bool(qdict
, "state");
861 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
864 for (i
= 0; i
< MIGRATION_CAPABILITY_MAX
; i
++) {
865 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
866 caps
->value
= g_malloc0(sizeof(*caps
->value
));
867 caps
->value
->capability
= i
;
868 caps
->value
->state
= state
;
870 qmp_migrate_set_capabilities(caps
, &err
);
875 if (i
== MIGRATION_CAPABILITY_MAX
) {
876 error_set(&err
, QERR_INVALID_PARAMETER
, cap
);
879 qapi_free_MigrationCapabilityStatusList(caps
);
882 monitor_printf(mon
, "migrate_set_parameter: %s\n",
883 error_get_pretty(err
));
888 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
890 const char *protocol
= qdict_get_str(qdict
, "protocol");
891 const char *password
= qdict_get_str(qdict
, "password");
892 const char *connected
= qdict_get_try_str(qdict
, "connected");
895 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
896 hmp_handle_error(mon
, &err
);
899 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
901 const char *protocol
= qdict_get_str(qdict
, "protocol");
902 const char *whenstr
= qdict_get_str(qdict
, "time");
905 qmp_expire_password(protocol
, whenstr
, &err
);
906 hmp_handle_error(mon
, &err
);
909 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
911 int force
= qdict_get_try_bool(qdict
, "force", 0);
912 const char *device
= qdict_get_str(qdict
, "device");
915 qmp_eject(device
, true, force
, &err
);
916 hmp_handle_error(mon
, &err
);
919 static void hmp_change_read_arg(Monitor
*mon
, const char *password
,
922 qmp_change_vnc_password(password
, NULL
);
923 monitor_read_command(mon
, 1);
926 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
928 const char *device
= qdict_get_str(qdict
, "device");
929 const char *target
= qdict_get_str(qdict
, "target");
930 const char *arg
= qdict_get_try_str(qdict
, "arg");
933 if (strcmp(device
, "vnc") == 0 &&
934 (strcmp(target
, "passwd") == 0 ||
935 strcmp(target
, "password") == 0)) {
937 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
942 qmp_change(device
, target
, !!arg
, arg
, &err
);
943 if (error_is_set(&err
) &&
944 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
946 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
949 hmp_handle_error(mon
, &err
);
952 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
956 qmp_block_set_io_throttle(qdict_get_str(qdict
, "device"),
957 qdict_get_int(qdict
, "bps"),
958 qdict_get_int(qdict
, "bps_rd"),
959 qdict_get_int(qdict
, "bps_wr"),
960 qdict_get_int(qdict
, "iops"),
961 qdict_get_int(qdict
, "iops_rd"),
962 qdict_get_int(qdict
, "iops_wr"), &err
);
963 hmp_handle_error(mon
, &err
);
966 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
969 const char *device
= qdict_get_str(qdict
, "device");
970 const char *base
= qdict_get_try_str(qdict
, "base");
971 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
973 qmp_block_stream(device
, base
!= NULL
, base
,
974 qdict_haskey(qdict
, "speed"), speed
,
975 BLOCKDEV_ON_ERROR_REPORT
, true, &error
);
977 hmp_handle_error(mon
, &error
);
980 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
983 const char *device
= qdict_get_str(qdict
, "device");
984 int64_t value
= qdict_get_int(qdict
, "speed");
986 qmp_block_job_set_speed(device
, value
, &error
);
988 hmp_handle_error(mon
, &error
);
991 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
994 const char *device
= qdict_get_str(qdict
, "device");
995 bool force
= qdict_get_try_bool(qdict
, "force", 0);
997 qmp_block_job_cancel(device
, true, force
, &error
);
999 hmp_handle_error(mon
, &error
);
1002 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1004 Error
*error
= NULL
;
1005 const char *device
= qdict_get_str(qdict
, "device");
1007 qmp_block_job_pause(device
, &error
);
1009 hmp_handle_error(mon
, &error
);
1012 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1014 Error
*error
= NULL
;
1015 const char *device
= qdict_get_str(qdict
, "device");
1017 qmp_block_job_resume(device
, &error
);
1019 hmp_handle_error(mon
, &error
);
1022 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1024 Error
*error
= NULL
;
1025 const char *device
= qdict_get_str(qdict
, "device");
1027 qmp_block_job_complete(device
, &error
);
1029 hmp_handle_error(mon
, &error
);
1032 typedef struct MigrationStatus
1036 bool is_block_migration
;
1039 static void hmp_migrate_status_cb(void *opaque
)
1041 MigrationStatus
*status
= opaque
;
1042 MigrationInfo
*info
;
1044 info
= qmp_query_migrate(NULL
);
1045 if (!info
->has_status
|| strcmp(info
->status
, "active") == 0) {
1046 if (info
->has_disk
) {
1049 if (info
->disk
->remaining
) {
1050 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1055 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1056 monitor_flush(status
->mon
);
1059 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
) + 1000);
1061 if (status
->is_block_migration
) {
1062 monitor_printf(status
->mon
, "\n");
1064 monitor_resume(status
->mon
);
1065 qemu_del_timer(status
->timer
);
1069 qapi_free_MigrationInfo(info
);
1072 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1074 int detach
= qdict_get_try_bool(qdict
, "detach", 0);
1075 int blk
= qdict_get_try_bool(qdict
, "blk", 0);
1076 int inc
= qdict_get_try_bool(qdict
, "inc", 0);
1077 const char *uri
= qdict_get_str(qdict
, "uri");
1080 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1082 monitor_printf(mon
, "migrate: %s\n", error_get_pretty(err
));
1088 MigrationStatus
*status
;
1090 if (monitor_suspend(mon
) < 0) {
1091 monitor_printf(mon
, "terminal does not allow synchronous "
1092 "migration, continuing detached\n");
1096 status
= g_malloc0(sizeof(*status
));
1098 status
->is_block_migration
= blk
|| inc
;
1099 status
->timer
= qemu_new_timer_ms(rt_clock
, hmp_migrate_status_cb
,
1101 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
));
1105 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1107 const char *id
= qdict_get_str(qdict
, "id");
1110 qmp_device_del(id
, &err
);
1111 hmp_handle_error(mon
, &err
);
1114 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1117 int paging
= qdict_get_try_bool(qdict
, "paging", 0);
1118 const char *file
= qdict_get_str(qdict
, "filename");
1119 bool has_begin
= qdict_haskey(qdict
, "begin");
1120 bool has_length
= qdict_haskey(qdict
, "length");
1126 begin
= qdict_get_int(qdict
, "begin");
1129 length
= qdict_get_int(qdict
, "length");
1132 prot
= g_strconcat("file:", file
, NULL
);
1134 qmp_dump_guest_memory(paging
, prot
, has_begin
, begin
, has_length
, length
,
1136 hmp_handle_error(mon
, &errp
);
1140 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1145 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1146 if (error_is_set(&err
)) {
1150 netdev_add(opts
, &err
);
1151 if (error_is_set(&err
)) {
1152 qemu_opts_del(opts
);
1156 hmp_handle_error(mon
, &err
);
1159 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1161 const char *id
= qdict_get_str(qdict
, "id");
1164 qmp_netdev_del(id
, &err
);
1165 hmp_handle_error(mon
, &err
);
1168 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1170 const char *fdname
= qdict_get_str(qdict
, "fdname");
1173 qmp_getfd(fdname
, &errp
);
1174 hmp_handle_error(mon
, &errp
);
1177 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1179 const char *fdname
= qdict_get_str(qdict
, "fdname");
1182 qmp_closefd(fdname
, &errp
);
1183 hmp_handle_error(mon
, &errp
);
1186 void hmp_send_key(Monitor
*mon
, const QDict
*qdict
)
1188 const char *keys
= qdict_get_str(qdict
, "keys");
1189 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
1190 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1191 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1193 char keyname_buf
[16];
1198 separator
= strchr(keys
, '-');
1199 keyname_len
= separator
? separator
- keys
: strlen(keys
);
1200 pstrcpy(keyname_buf
, sizeof(keyname_buf
), keys
);
1202 /* Be compatible with old interface, convert user inputted "<" */
1203 if (!strncmp(keyname_buf
, "<", 1) && keyname_len
== 1) {
1204 pstrcpy(keyname_buf
, sizeof(keyname_buf
), "less");
1207 keyname_buf
[keyname_len
] = 0;
1209 keylist
= g_malloc0(sizeof(*keylist
));
1210 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
1216 tmp
->next
= keylist
;
1220 if (strstart(keyname_buf
, "0x", NULL
)) {
1222 int value
= strtoul(keyname_buf
, &endp
, 0);
1223 if (*endp
!= '\0') {
1226 keylist
->value
->kind
= KEY_VALUE_KIND_NUMBER
;
1227 keylist
->value
->number
= value
;
1229 int idx
= index_from_key(keyname_buf
);
1230 if (idx
== Q_KEY_CODE_MAX
) {
1233 keylist
->value
->kind
= KEY_VALUE_KIND_QCODE
;
1234 keylist
->value
->qcode
= idx
;
1240 keys
= separator
+ 1;
1243 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1244 hmp_handle_error(mon
, &err
);
1247 qapi_free_KeyValueList(head
);
1251 monitor_printf(mon
, "invalid parameter: %s\n", keyname_buf
);
1255 void hmp_screen_dump(Monitor
*mon
, const QDict
*qdict
)
1257 const char *filename
= qdict_get_str(qdict
, "filename");
1260 qmp_screendump(filename
, &err
);
1261 hmp_handle_error(mon
, &err
);
1264 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
1266 const char *uri
= qdict_get_str(qdict
, "uri");
1267 int writable
= qdict_get_try_bool(qdict
, "writable", 0);
1268 int all
= qdict_get_try_bool(qdict
, "all", 0);
1269 Error
*local_err
= NULL
;
1270 BlockInfoList
*block_list
, *info
;
1271 SocketAddress
*addr
;
1273 if (writable
&& !all
) {
1274 error_setg(&local_err
, "-w only valid together with -a");
1278 /* First check if the address is valid and start the server. */
1279 addr
= socket_parse(uri
, &local_err
);
1280 if (local_err
!= NULL
) {
1284 qmp_nbd_server_start(addr
, &local_err
);
1285 qapi_free_SocketAddress(addr
);
1286 if (local_err
!= NULL
) {
1294 /* Then try adding all block devices. If one fails, close all and
1297 block_list
= qmp_query_block(NULL
);
1299 for (info
= block_list
; info
; info
= info
->next
) {
1300 if (!info
->value
->has_inserted
) {
1304 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
1306 if (local_err
!= NULL
) {
1307 qmp_nbd_server_stop(NULL
);
1312 qapi_free_BlockInfoList(block_list
);
1315 hmp_handle_error(mon
, &local_err
);
1318 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
1320 const char *device
= qdict_get_str(qdict
, "device");
1321 int writable
= qdict_get_try_bool(qdict
, "writable", 0);
1322 Error
*local_err
= NULL
;
1324 qmp_nbd_server_add(device
, true, writable
, &local_err
);
1326 if (local_err
!= NULL
) {
1327 hmp_handle_error(mon
, &local_err
);
1331 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
1335 qmp_nbd_server_stop(&errp
);
1336 hmp_handle_error(mon
, &errp
);