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"
24 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
26 if (error_is_set(errp
)) {
27 monitor_printf(mon
, "%s\n", error_get_pretty(*errp
));
32 void hmp_info_name(Monitor
*mon
)
36 info
= qmp_query_name(NULL
);
38 monitor_printf(mon
, "%s\n", info
->name
);
40 qapi_free_NameInfo(info
);
43 void hmp_info_version(Monitor
*mon
)
47 info
= qmp_query_version(NULL
);
49 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
50 info
->qemu
.major
, info
->qemu
.minor
, info
->qemu
.micro
,
53 qapi_free_VersionInfo(info
);
56 void hmp_info_kvm(Monitor
*mon
)
60 info
= qmp_query_kvm(NULL
);
61 monitor_printf(mon
, "kvm support: ");
63 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
65 monitor_printf(mon
, "not compiled\n");
68 qapi_free_KvmInfo(info
);
71 void hmp_info_status(Monitor
*mon
)
75 info
= qmp_query_status(NULL
);
77 monitor_printf(mon
, "VM status: %s%s",
78 info
->running
? "running" : "paused",
79 info
->singlestep
? " (single step mode)" : "");
81 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
82 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
85 monitor_printf(mon
, "\n");
87 qapi_free_StatusInfo(info
);
90 void hmp_info_uuid(Monitor
*mon
)
94 info
= qmp_query_uuid(NULL
);
95 monitor_printf(mon
, "%s\n", info
->UUID
);
96 qapi_free_UuidInfo(info
);
99 void hmp_info_chardev(Monitor
*mon
)
101 ChardevInfoList
*char_info
, *info
;
103 char_info
= qmp_query_chardev(NULL
);
104 for (info
= char_info
; info
; info
= info
->next
) {
105 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
106 info
->value
->filename
);
109 qapi_free_ChardevInfoList(char_info
);
112 void hmp_info_mice(Monitor
*mon
)
114 MouseInfoList
*mice_list
, *mouse
;
116 mice_list
= qmp_query_mice(NULL
);
118 monitor_printf(mon
, "No mouse devices connected\n");
122 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
123 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
124 mouse
->value
->current
? '*' : ' ',
125 mouse
->value
->index
, mouse
->value
->name
,
126 mouse
->value
->absolute
? " (absolute)" : "");
129 qapi_free_MouseInfoList(mice_list
);
132 void hmp_info_migrate(Monitor
*mon
)
135 MigrationCapabilityStatusList
*caps
, *cap
;
137 info
= qmp_query_migrate(NULL
);
138 caps
= qmp_query_migrate_capabilities(NULL
);
140 /* do not display parameters during setup */
141 if (info
->has_status
&& caps
) {
142 monitor_printf(mon
, "capabilities: ");
143 for (cap
= caps
; cap
; cap
= cap
->next
) {
144 monitor_printf(mon
, "%s: %s ",
145 MigrationCapability_lookup
[cap
->value
->capability
],
146 cap
->value
->state
? "on" : "off");
148 monitor_printf(mon
, "\n");
151 if (info
->has_status
) {
152 monitor_printf(mon
, "Migration status: %s\n", info
->status
);
153 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
155 if (info
->has_expected_downtime
) {
156 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
157 info
->expected_downtime
);
159 if (info
->has_downtime
) {
160 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
166 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
167 info
->ram
->transferred
>> 10);
168 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
169 info
->ram
->remaining
>> 10);
170 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
171 info
->ram
->total
>> 10);
172 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
173 info
->ram
->duplicate
);
174 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
176 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
177 info
->ram
->normal_bytes
>> 10);
180 if (info
->has_disk
) {
181 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
182 info
->disk
->transferred
>> 10);
183 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
184 info
->disk
->remaining
>> 10);
185 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
186 info
->disk
->total
>> 10);
189 if (info
->has_xbzrle_cache
) {
190 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
191 info
->xbzrle_cache
->cache_size
);
192 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
193 info
->xbzrle_cache
->bytes
>> 10);
194 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
195 info
->xbzrle_cache
->pages
);
196 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
197 info
->xbzrle_cache
->cache_miss
);
198 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
199 info
->xbzrle_cache
->overflow
);
202 qapi_free_MigrationInfo(info
);
203 qapi_free_MigrationCapabilityStatusList(caps
);
206 void hmp_info_migrate_capabilities(Monitor
*mon
)
208 MigrationCapabilityStatusList
*caps
, *cap
;
210 caps
= qmp_query_migrate_capabilities(NULL
);
213 monitor_printf(mon
, "capabilities: ");
214 for (cap
= caps
; cap
; cap
= cap
->next
) {
215 monitor_printf(mon
, "%s: %s ",
216 MigrationCapability_lookup
[cap
->value
->capability
],
217 cap
->value
->state
? "on" : "off");
219 monitor_printf(mon
, "\n");
222 qapi_free_MigrationCapabilityStatusList(caps
);
225 void hmp_info_migrate_cache_size(Monitor
*mon
)
227 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
228 qmp_query_migrate_cache_size(NULL
) >> 10);
231 void hmp_info_cpus(Monitor
*mon
)
233 CpuInfoList
*cpu_list
, *cpu
;
235 cpu_list
= qmp_query_cpus(NULL
);
237 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
240 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
244 monitor_printf(mon
, "%c CPU #%" PRId64
": ", active
, cpu
->value
->CPU
);
246 if (cpu
->value
->has_pc
) {
247 monitor_printf(mon
, "pc=0x%016" PRIx64
, cpu
->value
->pc
);
249 if (cpu
->value
->has_nip
) {
250 monitor_printf(mon
, "nip=0x%016" PRIx64
, cpu
->value
->nip
);
252 if (cpu
->value
->has_npc
) {
253 monitor_printf(mon
, "pc=0x%016" PRIx64
, cpu
->value
->pc
);
254 monitor_printf(mon
, "npc=0x%016" PRIx64
, cpu
->value
->npc
);
256 if (cpu
->value
->has_PC
) {
257 monitor_printf(mon
, "PC=0x%016" PRIx64
, cpu
->value
->PC
);
260 if (cpu
->value
->halted
) {
261 monitor_printf(mon
, " (halted)");
264 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
267 qapi_free_CpuInfoList(cpu_list
);
270 void hmp_info_block(Monitor
*mon
)
272 BlockInfoList
*block_list
, *info
;
274 block_list
= qmp_query_block(NULL
);
276 for (info
= block_list
; info
; info
= info
->next
) {
277 monitor_printf(mon
, "%s: removable=%d",
278 info
->value
->device
, info
->value
->removable
);
280 if (info
->value
->removable
) {
281 monitor_printf(mon
, " locked=%d", info
->value
->locked
);
282 monitor_printf(mon
, " tray-open=%d", info
->value
->tray_open
);
285 if (info
->value
->has_io_status
) {
286 monitor_printf(mon
, " io-status=%s",
287 BlockDeviceIoStatus_lookup
[info
->value
->io_status
]);
290 if (info
->value
->has_inserted
) {
291 monitor_printf(mon
, " file=");
292 monitor_print_filename(mon
, info
->value
->inserted
->file
);
294 if (info
->value
->inserted
->has_backing_file
) {
295 monitor_printf(mon
, " backing_file=");
296 monitor_print_filename(mon
, info
->value
->inserted
->backing_file
);
297 monitor_printf(mon
, " backing_file_depth=%" PRId64
,
298 info
->value
->inserted
->backing_file_depth
);
300 monitor_printf(mon
, " ro=%d drv=%s encrypted=%d",
301 info
->value
->inserted
->ro
,
302 info
->value
->inserted
->drv
,
303 info
->value
->inserted
->encrypted
);
305 monitor_printf(mon
, " bps=%" PRId64
" bps_rd=%" PRId64
306 " bps_wr=%" PRId64
" iops=%" PRId64
307 " iops_rd=%" PRId64
" iops_wr=%" PRId64
,
308 info
->value
->inserted
->bps
,
309 info
->value
->inserted
->bps_rd
,
310 info
->value
->inserted
->bps_wr
,
311 info
->value
->inserted
->iops
,
312 info
->value
->inserted
->iops_rd
,
313 info
->value
->inserted
->iops_wr
);
315 monitor_printf(mon
, " [not inserted]");
318 monitor_printf(mon
, "\n");
321 qapi_free_BlockInfoList(block_list
);
324 void hmp_info_blockstats(Monitor
*mon
)
326 BlockStatsList
*stats_list
, *stats
;
328 stats_list
= qmp_query_blockstats(NULL
);
330 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
331 if (!stats
->value
->has_device
) {
335 monitor_printf(mon
, "%s:", stats
->value
->device
);
336 monitor_printf(mon
, " rd_bytes=%" PRId64
338 " rd_operations=%" PRId64
339 " wr_operations=%" PRId64
340 " flush_operations=%" PRId64
341 " wr_total_time_ns=%" PRId64
342 " rd_total_time_ns=%" PRId64
343 " flush_total_time_ns=%" PRId64
345 stats
->value
->stats
->rd_bytes
,
346 stats
->value
->stats
->wr_bytes
,
347 stats
->value
->stats
->rd_operations
,
348 stats
->value
->stats
->wr_operations
,
349 stats
->value
->stats
->flush_operations
,
350 stats
->value
->stats
->wr_total_time_ns
,
351 stats
->value
->stats
->rd_total_time_ns
,
352 stats
->value
->stats
->flush_total_time_ns
);
355 qapi_free_BlockStatsList(stats_list
);
358 void hmp_info_vnc(Monitor
*mon
)
362 VncClientInfoList
*client
;
364 info
= qmp_query_vnc(&err
);
366 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
371 if (!info
->enabled
) {
372 monitor_printf(mon
, "Server: disabled\n");
376 monitor_printf(mon
, "Server:\n");
377 if (info
->has_host
&& info
->has_service
) {
378 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
380 if (info
->has_auth
) {
381 monitor_printf(mon
, " auth: %s\n", info
->auth
);
384 if (!info
->has_clients
|| info
->clients
== NULL
) {
385 monitor_printf(mon
, "Client: none\n");
387 for (client
= info
->clients
; client
; client
= client
->next
) {
388 monitor_printf(mon
, "Client:\n");
389 monitor_printf(mon
, " address: %s:%s\n",
390 client
->value
->host
, client
->value
->service
);
391 monitor_printf(mon
, " x509_dname: %s\n",
392 client
->value
->x509_dname
?
393 client
->value
->x509_dname
: "none");
394 monitor_printf(mon
, " username: %s\n",
395 client
->value
->has_sasl_username
?
396 client
->value
->sasl_username
: "none");
401 qapi_free_VncInfo(info
);
404 void hmp_info_spice(Monitor
*mon
)
406 SpiceChannelList
*chan
;
409 info
= qmp_query_spice(NULL
);
411 if (!info
->enabled
) {
412 monitor_printf(mon
, "Server: disabled\n");
416 monitor_printf(mon
, "Server:\n");
417 if (info
->has_port
) {
418 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
419 info
->host
, info
->port
);
421 if (info
->has_tls_port
) {
422 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
423 info
->host
, info
->tls_port
);
425 monitor_printf(mon
, " migrated: %s\n",
426 info
->migrated
? "true" : "false");
427 monitor_printf(mon
, " auth: %s\n", info
->auth
);
428 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
429 monitor_printf(mon
, " mouse-mode: %s\n",
430 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
432 if (!info
->has_channels
|| info
->channels
== NULL
) {
433 monitor_printf(mon
, "Channels: none\n");
435 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
436 monitor_printf(mon
, "Channel:\n");
437 monitor_printf(mon
, " address: %s:%s%s\n",
438 chan
->value
->host
, chan
->value
->port
,
439 chan
->value
->tls
? " [tls]" : "");
440 monitor_printf(mon
, " session: %" PRId64
"\n",
441 chan
->value
->connection_id
);
442 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
443 chan
->value
->channel_type
, chan
->value
->channel_id
);
448 qapi_free_SpiceInfo(info
);
451 void hmp_info_balloon(Monitor
*mon
)
456 info
= qmp_query_balloon(&err
);
458 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
463 monitor_printf(mon
, "balloon: actual=%" PRId64
, info
->actual
>> 20);
464 if (info
->has_mem_swapped_in
) {
465 monitor_printf(mon
, " mem_swapped_in=%" PRId64
, info
->mem_swapped_in
);
467 if (info
->has_mem_swapped_out
) {
468 monitor_printf(mon
, " mem_swapped_out=%" PRId64
, info
->mem_swapped_out
);
470 if (info
->has_major_page_faults
) {
471 monitor_printf(mon
, " major_page_faults=%" PRId64
,
472 info
->major_page_faults
);
474 if (info
->has_minor_page_faults
) {
475 monitor_printf(mon
, " minor_page_faults=%" PRId64
,
476 info
->minor_page_faults
);
478 if (info
->has_free_mem
) {
479 monitor_printf(mon
, " free_mem=%" PRId64
, info
->free_mem
);
481 if (info
->has_total_mem
) {
482 monitor_printf(mon
, " total_mem=%" PRId64
, info
->total_mem
);
485 monitor_printf(mon
, "\n");
487 qapi_free_BalloonInfo(info
);
490 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
492 PciMemoryRegionList
*region
;
494 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
495 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
496 dev
->slot
, dev
->function
);
497 monitor_printf(mon
, " ");
499 if (dev
->class_info
.has_desc
) {
500 monitor_printf(mon
, "%s", dev
->class_info
.desc
);
502 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
.class);
505 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
506 dev
->id
.vendor
, dev
->id
.device
);
509 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
512 if (dev
->has_pci_bridge
) {
513 monitor_printf(mon
, " BUS %" PRId64
".\n",
514 dev
->pci_bridge
->bus
.number
);
515 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
516 dev
->pci_bridge
->bus
.secondary
);
517 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
518 dev
->pci_bridge
->bus
.subordinate
);
520 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
521 dev
->pci_bridge
->bus
.io_range
->base
,
522 dev
->pci_bridge
->bus
.io_range
->limit
);
525 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
526 dev
->pci_bridge
->bus
.memory_range
->base
,
527 dev
->pci_bridge
->bus
.memory_range
->limit
);
529 monitor_printf(mon
, " prefetchable memory range "
530 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
531 dev
->pci_bridge
->bus
.prefetchable_range
->base
,
532 dev
->pci_bridge
->bus
.prefetchable_range
->limit
);
535 for (region
= dev
->regions
; region
; region
= region
->next
) {
538 addr
= region
->value
->address
;
539 size
= region
->value
->size
;
541 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
543 if (!strcmp(region
->value
->type
, "io")) {
544 monitor_printf(mon
, "I/O at 0x%04" PRIx64
545 " [0x%04" PRIx64
"].\n",
546 addr
, addr
+ size
- 1);
548 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
549 " [0x%08" PRIx64
"].\n",
550 region
->value
->mem_type_64
? 64 : 32,
551 region
->value
->prefetch
? " prefetchable" : "",
552 addr
, addr
+ size
- 1);
556 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
558 if (dev
->has_pci_bridge
) {
559 if (dev
->pci_bridge
->has_devices
) {
560 PciDeviceInfoList
*cdev
;
561 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
562 hmp_info_pci_device(mon
, cdev
->value
);
568 void hmp_info_pci(Monitor
*mon
)
570 PciInfoList
*info_list
, *info
;
573 info_list
= qmp_query_pci(&err
);
575 monitor_printf(mon
, "PCI devices not supported\n");
580 for (info
= info_list
; info
; info
= info
->next
) {
581 PciDeviceInfoList
*dev
;
583 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
584 hmp_info_pci_device(mon
, dev
->value
);
588 qapi_free_PciInfoList(info_list
);
591 void hmp_info_block_jobs(Monitor
*mon
)
593 BlockJobInfoList
*list
;
596 list
= qmp_query_block_jobs(&err
);
600 monitor_printf(mon
, "No active jobs\n");
605 if (strcmp(list
->value
->type
, "stream") == 0) {
606 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
607 " of %" PRId64
" bytes, speed limit %" PRId64
614 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
615 " of %" PRId64
" bytes, speed limit %" PRId64
627 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
629 monitor_suspend(mon
);
633 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
638 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
640 qmp_system_reset(NULL
);
643 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
645 qmp_system_powerdown(NULL
);
648 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
652 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
653 use it are converted to the QAPI */
654 cpu_index
= qdict_get_int(qdict
, "index");
655 if (monitor_set_cpu(cpu_index
) < 0) {
656 monitor_printf(mon
, "invalid CPU index\n");
660 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
662 uint32_t size
= qdict_get_int(qdict
, "size");
663 const char *filename
= qdict_get_str(qdict
, "filename");
664 uint64_t addr
= qdict_get_int(qdict
, "val");
667 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &errp
);
668 hmp_handle_error(mon
, &errp
);
671 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
673 uint32_t size
= qdict_get_int(qdict
, "size");
674 const char *filename
= qdict_get_str(qdict
, "filename");
675 uint64_t addr
= qdict_get_int(qdict
, "val");
678 qmp_pmemsave(addr
, size
, filename
, &errp
);
679 hmp_handle_error(mon
, &errp
);
682 static void hmp_cont_cb(void *opaque
, int err
)
689 static bool key_is_missing(const BlockInfo
*bdev
)
691 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
694 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
696 BlockInfoList
*bdev_list
, *bdev
;
699 bdev_list
= qmp_query_block(NULL
);
700 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
701 if (key_is_missing(bdev
->value
)) {
702 monitor_read_block_device_key(mon
, bdev
->value
->device
,
709 hmp_handle_error(mon
, &errp
);
712 qapi_free_BlockInfoList(bdev_list
);
715 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
717 qmp_system_wakeup(NULL
);
720 void hmp_inject_nmi(Monitor
*mon
, const QDict
*qdict
)
724 qmp_inject_nmi(&errp
);
725 hmp_handle_error(mon
, &errp
);
728 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
730 const char *name
= qdict_get_str(qdict
, "name");
731 int up
= qdict_get_bool(qdict
, "up");
734 qmp_set_link(name
, up
, &errp
);
735 hmp_handle_error(mon
, &errp
);
738 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
740 const char *device
= qdict_get_str(qdict
, "device");
741 const char *password
= qdict_get_str(qdict
, "password");
744 qmp_block_passwd(device
, password
, &errp
);
745 hmp_handle_error(mon
, &errp
);
748 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
750 int64_t value
= qdict_get_int(qdict
, "value");
753 qmp_balloon(value
, &errp
);
754 if (error_is_set(&errp
)) {
755 monitor_printf(mon
, "balloon: %s\n", error_get_pretty(errp
));
760 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
762 const char *device
= qdict_get_str(qdict
, "device");
763 int64_t size
= qdict_get_int(qdict
, "size");
766 qmp_block_resize(device
, size
, &errp
);
767 hmp_handle_error(mon
, &errp
);
770 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
772 const char *device
= qdict_get_str(qdict
, "device");
773 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
774 const char *format
= qdict_get_try_str(qdict
, "format");
775 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
776 enum NewImageMode mode
;
780 /* In the future, if 'snapshot-file' is not specified, the snapshot
781 will be taken internally. Today it's actually required. */
782 error_set(&errp
, QERR_MISSING_PARAMETER
, "snapshot-file");
783 hmp_handle_error(mon
, &errp
);
787 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
788 qmp_blockdev_snapshot_sync(device
, filename
, !!format
, format
,
790 hmp_handle_error(mon
, &errp
);
793 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
795 qmp_migrate_cancel(NULL
);
798 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
800 double value
= qdict_get_double(qdict
, "value");
801 qmp_migrate_set_downtime(value
, NULL
);
804 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
806 int64_t value
= qdict_get_int(qdict
, "value");
809 qmp_migrate_set_cache_size(value
, &err
);
811 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
817 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
819 int64_t value
= qdict_get_int(qdict
, "value");
820 qmp_migrate_set_speed(value
, NULL
);
823 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
825 const char *cap
= qdict_get_str(qdict
, "capability");
826 bool state
= qdict_get_bool(qdict
, "state");
828 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
831 for (i
= 0; i
< MIGRATION_CAPABILITY_MAX
; i
++) {
832 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
833 caps
->value
= g_malloc0(sizeof(*caps
->value
));
834 caps
->value
->capability
= i
;
835 caps
->value
->state
= state
;
837 qmp_migrate_set_capabilities(caps
, &err
);
842 if (i
== MIGRATION_CAPABILITY_MAX
) {
843 error_set(&err
, QERR_INVALID_PARAMETER
, cap
);
846 qapi_free_MigrationCapabilityStatusList(caps
);
849 monitor_printf(mon
, "migrate_set_parameter: %s\n",
850 error_get_pretty(err
));
855 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
857 const char *protocol
= qdict_get_str(qdict
, "protocol");
858 const char *password
= qdict_get_str(qdict
, "password");
859 const char *connected
= qdict_get_try_str(qdict
, "connected");
862 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
863 hmp_handle_error(mon
, &err
);
866 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
868 const char *protocol
= qdict_get_str(qdict
, "protocol");
869 const char *whenstr
= qdict_get_str(qdict
, "time");
872 qmp_expire_password(protocol
, whenstr
, &err
);
873 hmp_handle_error(mon
, &err
);
876 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
878 int force
= qdict_get_try_bool(qdict
, "force", 0);
879 const char *device
= qdict_get_str(qdict
, "device");
882 qmp_eject(device
, true, force
, &err
);
883 hmp_handle_error(mon
, &err
);
886 static void hmp_change_read_arg(Monitor
*mon
, const char *password
,
889 qmp_change_vnc_password(password
, NULL
);
890 monitor_read_command(mon
, 1);
893 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
895 const char *device
= qdict_get_str(qdict
, "device");
896 const char *target
= qdict_get_str(qdict
, "target");
897 const char *arg
= qdict_get_try_str(qdict
, "arg");
900 if (strcmp(device
, "vnc") == 0 &&
901 (strcmp(target
, "passwd") == 0 ||
902 strcmp(target
, "password") == 0)) {
904 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
909 qmp_change(device
, target
, !!arg
, arg
, &err
);
910 if (error_is_set(&err
) &&
911 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
913 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
916 hmp_handle_error(mon
, &err
);
919 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
923 qmp_block_set_io_throttle(qdict_get_str(qdict
, "device"),
924 qdict_get_int(qdict
, "bps"),
925 qdict_get_int(qdict
, "bps_rd"),
926 qdict_get_int(qdict
, "bps_wr"),
927 qdict_get_int(qdict
, "iops"),
928 qdict_get_int(qdict
, "iops_rd"),
929 qdict_get_int(qdict
, "iops_wr"), &err
);
930 hmp_handle_error(mon
, &err
);
933 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
936 const char *device
= qdict_get_str(qdict
, "device");
937 const char *base
= qdict_get_try_str(qdict
, "base");
938 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
940 qmp_block_stream(device
, base
!= NULL
, base
,
941 qdict_haskey(qdict
, "speed"), speed
,
942 BLOCKDEV_ON_ERROR_REPORT
, true, &error
);
944 hmp_handle_error(mon
, &error
);
947 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
950 const char *device
= qdict_get_str(qdict
, "device");
951 int64_t value
= qdict_get_int(qdict
, "speed");
953 qmp_block_job_set_speed(device
, value
, &error
);
955 hmp_handle_error(mon
, &error
);
958 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
961 const char *device
= qdict_get_str(qdict
, "device");
962 bool force
= qdict_get_try_bool(qdict
, "force", 0);
964 qmp_block_job_cancel(device
, true, force
, &error
);
966 hmp_handle_error(mon
, &error
);
969 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
972 const char *device
= qdict_get_str(qdict
, "device");
974 qmp_block_job_pause(device
, &error
);
976 hmp_handle_error(mon
, &error
);
979 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
982 const char *device
= qdict_get_str(qdict
, "device");
984 qmp_block_job_resume(device
, &error
);
986 hmp_handle_error(mon
, &error
);
989 typedef struct MigrationStatus
993 bool is_block_migration
;
996 static void hmp_migrate_status_cb(void *opaque
)
998 MigrationStatus
*status
= opaque
;
1001 info
= qmp_query_migrate(NULL
);
1002 if (!info
->has_status
|| strcmp(info
->status
, "active") == 0) {
1003 if (info
->has_disk
) {
1006 if (info
->disk
->remaining
) {
1007 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1012 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1013 monitor_flush(status
->mon
);
1016 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
) + 1000);
1018 if (status
->is_block_migration
) {
1019 monitor_printf(status
->mon
, "\n");
1021 monitor_resume(status
->mon
);
1022 qemu_del_timer(status
->timer
);
1026 qapi_free_MigrationInfo(info
);
1029 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1031 int detach
= qdict_get_try_bool(qdict
, "detach", 0);
1032 int blk
= qdict_get_try_bool(qdict
, "blk", 0);
1033 int inc
= qdict_get_try_bool(qdict
, "inc", 0);
1034 const char *uri
= qdict_get_str(qdict
, "uri");
1037 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1039 monitor_printf(mon
, "migrate: %s\n", error_get_pretty(err
));
1045 MigrationStatus
*status
;
1047 if (monitor_suspend(mon
) < 0) {
1048 monitor_printf(mon
, "terminal does not allow synchronous "
1049 "migration, continuing detached\n");
1053 status
= g_malloc0(sizeof(*status
));
1055 status
->is_block_migration
= blk
|| inc
;
1056 status
->timer
= qemu_new_timer_ms(rt_clock
, hmp_migrate_status_cb
,
1058 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
));
1062 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1064 const char *id
= qdict_get_str(qdict
, "id");
1067 qmp_device_del(id
, &err
);
1068 hmp_handle_error(mon
, &err
);
1071 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1074 int paging
= qdict_get_try_bool(qdict
, "paging", 0);
1075 const char *file
= qdict_get_str(qdict
, "filename");
1076 bool has_begin
= qdict_haskey(qdict
, "begin");
1077 bool has_length
= qdict_haskey(qdict
, "length");
1083 begin
= qdict_get_int(qdict
, "begin");
1086 length
= qdict_get_int(qdict
, "length");
1089 prot
= g_strconcat("file:", file
, NULL
);
1091 qmp_dump_guest_memory(paging
, prot
, has_begin
, begin
, has_length
, length
,
1093 hmp_handle_error(mon
, &errp
);
1097 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1102 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1103 if (error_is_set(&err
)) {
1107 netdev_add(opts
, &err
);
1108 if (error_is_set(&err
)) {
1109 qemu_opts_del(opts
);
1113 hmp_handle_error(mon
, &err
);
1116 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1118 const char *id
= qdict_get_str(qdict
, "id");
1121 qmp_netdev_del(id
, &err
);
1122 hmp_handle_error(mon
, &err
);
1125 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1127 const char *fdname
= qdict_get_str(qdict
, "fdname");
1130 qmp_getfd(fdname
, &errp
);
1131 hmp_handle_error(mon
, &errp
);
1134 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1136 const char *fdname
= qdict_get_str(qdict
, "fdname");
1139 qmp_closefd(fdname
, &errp
);
1140 hmp_handle_error(mon
, &errp
);
1143 void hmp_send_key(Monitor
*mon
, const QDict
*qdict
)
1145 const char *keys
= qdict_get_str(qdict
, "keys");
1146 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
1147 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1148 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1150 char keyname_buf
[16];
1155 separator
= strchr(keys
, '-');
1156 keyname_len
= separator
? separator
- keys
: strlen(keys
);
1157 pstrcpy(keyname_buf
, sizeof(keyname_buf
), keys
);
1159 /* Be compatible with old interface, convert user inputted "<" */
1160 if (!strncmp(keyname_buf
, "<", 1) && keyname_len
== 1) {
1161 pstrcpy(keyname_buf
, sizeof(keyname_buf
), "less");
1164 keyname_buf
[keyname_len
] = 0;
1166 keylist
= g_malloc0(sizeof(*keylist
));
1167 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
1173 tmp
->next
= keylist
;
1177 if (strstart(keyname_buf
, "0x", NULL
)) {
1179 int value
= strtoul(keyname_buf
, &endp
, 0);
1180 if (*endp
!= '\0') {
1183 keylist
->value
->kind
= KEY_VALUE_KIND_NUMBER
;
1184 keylist
->value
->number
= value
;
1186 int idx
= index_from_key(keyname_buf
);
1187 if (idx
== Q_KEY_CODE_MAX
) {
1190 keylist
->value
->kind
= KEY_VALUE_KIND_QCODE
;
1191 keylist
->value
->qcode
= idx
;
1197 keys
= separator
+ 1;
1200 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1201 hmp_handle_error(mon
, &err
);
1204 qapi_free_KeyValueList(head
);
1208 monitor_printf(mon
, "invalid parameter: %s\n", keyname_buf
);
1212 void hmp_screen_dump(Monitor
*mon
, const QDict
*qdict
)
1214 const char *filename
= qdict_get_str(qdict
, "filename");
1217 qmp_screendump(filename
, &err
);
1218 hmp_handle_error(mon
, &err
);