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 "sysemu/char.h"
19 #include "qemu/option.h"
20 #include "qemu/timer.h"
21 #include "qmp-commands.h"
22 #include "qemu/sockets.h"
23 #include "monitor/monitor.h"
24 #include "qapi/opts-visitor.h"
25 #include "ui/console.h"
26 #include "block/qapi.h"
29 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
33 monitor_printf(mon
, "%s\n", error_get_pretty(*errp
));
38 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
42 info
= qmp_query_name(NULL
);
44 monitor_printf(mon
, "%s\n", info
->name
);
46 qapi_free_NameInfo(info
);
49 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
53 info
= qmp_query_version(NULL
);
55 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
56 info
->qemu
.major
, info
->qemu
.minor
, info
->qemu
.micro
,
59 qapi_free_VersionInfo(info
);
62 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
66 info
= qmp_query_kvm(NULL
);
67 monitor_printf(mon
, "kvm support: ");
69 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
71 monitor_printf(mon
, "not compiled\n");
74 qapi_free_KvmInfo(info
);
77 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
81 info
= qmp_query_status(NULL
);
83 monitor_printf(mon
, "VM status: %s%s",
84 info
->running
? "running" : "paused",
85 info
->singlestep
? " (single step mode)" : "");
87 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
88 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
91 monitor_printf(mon
, "\n");
93 qapi_free_StatusInfo(info
);
96 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
100 info
= qmp_query_uuid(NULL
);
101 monitor_printf(mon
, "%s\n", info
->UUID
);
102 qapi_free_UuidInfo(info
);
105 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
107 ChardevInfoList
*char_info
, *info
;
109 char_info
= qmp_query_chardev(NULL
);
110 for (info
= char_info
; info
; info
= info
->next
) {
111 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
112 info
->value
->filename
);
115 qapi_free_ChardevInfoList(char_info
);
118 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
120 MouseInfoList
*mice_list
, *mouse
;
122 mice_list
= qmp_query_mice(NULL
);
124 monitor_printf(mon
, "No mouse devices connected\n");
128 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
129 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
130 mouse
->value
->current
? '*' : ' ',
131 mouse
->value
->index
, mouse
->value
->name
,
132 mouse
->value
->absolute
? " (absolute)" : "");
135 qapi_free_MouseInfoList(mice_list
);
138 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
141 MigrationCapabilityStatusList
*caps
, *cap
;
143 info
= qmp_query_migrate(NULL
);
144 caps
= qmp_query_migrate_capabilities(NULL
);
146 /* do not display parameters during setup */
147 if (info
->has_status
&& caps
) {
148 monitor_printf(mon
, "capabilities: ");
149 for (cap
= caps
; cap
; cap
= cap
->next
) {
150 monitor_printf(mon
, "%s: %s ",
151 MigrationCapability_lookup
[cap
->value
->capability
],
152 cap
->value
->state
? "on" : "off");
154 monitor_printf(mon
, "\n");
157 if (info
->has_status
) {
158 monitor_printf(mon
, "Migration status: %s\n", info
->status
);
159 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
161 if (info
->has_expected_downtime
) {
162 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
163 info
->expected_downtime
);
165 if (info
->has_downtime
) {
166 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
169 if (info
->has_setup_time
) {
170 monitor_printf(mon
, "setup: %" PRIu64
" milliseconds\n",
176 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
177 info
->ram
->transferred
>> 10);
178 monitor_printf(mon
, "throughput: %0.2f mbps\n",
180 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
181 info
->ram
->remaining
>> 10);
182 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
183 info
->ram
->total
>> 10);
184 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
185 info
->ram
->duplicate
);
186 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
188 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
190 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
191 info
->ram
->normal_bytes
>> 10);
192 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
193 info
->ram
->dirty_sync_count
);
194 if (info
->ram
->dirty_pages_rate
) {
195 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
196 info
->ram
->dirty_pages_rate
);
200 if (info
->has_disk
) {
201 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
202 info
->disk
->transferred
>> 10);
203 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
204 info
->disk
->remaining
>> 10);
205 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
206 info
->disk
->total
>> 10);
209 if (info
->has_xbzrle_cache
) {
210 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
211 info
->xbzrle_cache
->cache_size
);
212 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
213 info
->xbzrle_cache
->bytes
>> 10);
214 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
215 info
->xbzrle_cache
->pages
);
216 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
217 info
->xbzrle_cache
->cache_miss
);
218 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
219 info
->xbzrle_cache
->cache_miss_rate
);
220 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
221 info
->xbzrle_cache
->overflow
);
224 qapi_free_MigrationInfo(info
);
225 qapi_free_MigrationCapabilityStatusList(caps
);
228 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
230 MigrationCapabilityStatusList
*caps
, *cap
;
232 caps
= qmp_query_migrate_capabilities(NULL
);
235 monitor_printf(mon
, "capabilities: ");
236 for (cap
= caps
; cap
; cap
= cap
->next
) {
237 monitor_printf(mon
, "%s: %s ",
238 MigrationCapability_lookup
[cap
->value
->capability
],
239 cap
->value
->state
? "on" : "off");
241 monitor_printf(mon
, "\n");
244 qapi_free_MigrationCapabilityStatusList(caps
);
247 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
249 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
250 qmp_query_migrate_cache_size(NULL
) >> 10);
253 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
255 CpuInfoList
*cpu_list
, *cpu
;
257 cpu_list
= qmp_query_cpus(NULL
);
259 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
262 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
266 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
268 if (cpu
->value
->has_pc
) {
269 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->pc
);
271 if (cpu
->value
->has_nip
) {
272 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->nip
);
274 if (cpu
->value
->has_npc
) {
275 monitor_printf(mon
, " npc=0x%016" PRIx64
, cpu
->value
->npc
);
277 if (cpu
->value
->has_PC
) {
278 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->PC
);
281 if (cpu
->value
->halted
) {
282 monitor_printf(mon
, " (halted)");
285 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
288 qapi_free_CpuInfoList(cpu_list
);
291 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
293 BlockInfoList
*block_list
, *info
;
294 ImageInfo
*image_info
;
295 const char *device
= qdict_get_try_str(qdict
, "device");
296 bool verbose
= qdict_get_try_bool(qdict
, "verbose", 0);
298 block_list
= qmp_query_block(NULL
);
300 for (info
= block_list
; info
; info
= info
->next
) {
301 if (device
&& strcmp(device
, info
->value
->device
)) {
305 if (info
!= block_list
) {
306 monitor_printf(mon
, "\n");
309 monitor_printf(mon
, "%s", info
->value
->device
);
310 if (info
->value
->has_inserted
) {
311 monitor_printf(mon
, ": %s (%s%s%s)\n",
312 info
->value
->inserted
->file
,
313 info
->value
->inserted
->drv
,
314 info
->value
->inserted
->ro
? ", read-only" : "",
315 info
->value
->inserted
->encrypted
? ", encrypted" : "");
317 monitor_printf(mon
, ": [not inserted]\n");
320 if (info
->value
->has_io_status
&& info
->value
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
321 monitor_printf(mon
, " I/O status: %s\n",
322 BlockDeviceIoStatus_lookup
[info
->value
->io_status
]);
325 if (info
->value
->removable
) {
326 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
327 info
->value
->locked
? "" : "not ",
328 info
->value
->tray_open
? "open" : "closed");
332 if (!info
->value
->has_inserted
) {
336 if (info
->value
->inserted
->has_backing_file
) {
339 "(chain depth: %" PRId64
")\n",
340 info
->value
->inserted
->backing_file
,
341 info
->value
->inserted
->backing_file_depth
);
344 if (info
->value
->inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
345 monitor_printf(mon
, " Detect zeroes: %s\n",
346 BlockdevDetectZeroesOptions_lookup
[info
->value
->inserted
->detect_zeroes
]);
349 if (info
->value
->inserted
->bps
350 || info
->value
->inserted
->bps_rd
351 || info
->value
->inserted
->bps_wr
352 || info
->value
->inserted
->iops
353 || info
->value
->inserted
->iops_rd
354 || info
->value
->inserted
->iops_wr
)
356 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
357 " bps_rd=%" PRId64
" bps_wr=%" PRId64
359 " bps_rd_max=%" PRId64
360 " bps_wr_max=%" PRId64
361 " iops=%" PRId64
" iops_rd=%" PRId64
364 " iops_rd_max=%" PRId64
365 " iops_wr_max=%" PRId64
366 " iops_size=%" PRId64
"\n",
367 info
->value
->inserted
->bps
,
368 info
->value
->inserted
->bps_rd
,
369 info
->value
->inserted
->bps_wr
,
370 info
->value
->inserted
->bps_max
,
371 info
->value
->inserted
->bps_rd_max
,
372 info
->value
->inserted
->bps_wr_max
,
373 info
->value
->inserted
->iops
,
374 info
->value
->inserted
->iops_rd
,
375 info
->value
->inserted
->iops_wr
,
376 info
->value
->inserted
->iops_max
,
377 info
->value
->inserted
->iops_rd_max
,
378 info
->value
->inserted
->iops_wr_max
,
379 info
->value
->inserted
->iops_size
);
383 monitor_printf(mon
, "\nImages:\n");
384 image_info
= info
->value
->inserted
->image
;
386 bdrv_image_info_dump((fprintf_function
)monitor_printf
,
388 if (image_info
->has_backing_image
) {
389 image_info
= image_info
->backing_image
;
397 qapi_free_BlockInfoList(block_list
);
400 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
402 BlockStatsList
*stats_list
, *stats
;
404 stats_list
= qmp_query_blockstats(NULL
);
406 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
407 if (!stats
->value
->has_device
) {
411 monitor_printf(mon
, "%s:", stats
->value
->device
);
412 monitor_printf(mon
, " rd_bytes=%" PRId64
414 " rd_operations=%" PRId64
415 " wr_operations=%" PRId64
416 " flush_operations=%" PRId64
417 " wr_total_time_ns=%" PRId64
418 " rd_total_time_ns=%" PRId64
419 " flush_total_time_ns=%" PRId64
421 stats
->value
->stats
->rd_bytes
,
422 stats
->value
->stats
->wr_bytes
,
423 stats
->value
->stats
->rd_operations
,
424 stats
->value
->stats
->wr_operations
,
425 stats
->value
->stats
->flush_operations
,
426 stats
->value
->stats
->wr_total_time_ns
,
427 stats
->value
->stats
->rd_total_time_ns
,
428 stats
->value
->stats
->flush_total_time_ns
);
431 qapi_free_BlockStatsList(stats_list
);
434 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
438 VncClientInfoList
*client
;
440 info
= qmp_query_vnc(&err
);
442 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
447 if (!info
->enabled
) {
448 monitor_printf(mon
, "Server: disabled\n");
452 monitor_printf(mon
, "Server:\n");
453 if (info
->has_host
&& info
->has_service
) {
454 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
456 if (info
->has_auth
) {
457 monitor_printf(mon
, " auth: %s\n", info
->auth
);
460 if (!info
->has_clients
|| info
->clients
== NULL
) {
461 monitor_printf(mon
, "Client: none\n");
463 for (client
= info
->clients
; client
; client
= client
->next
) {
464 monitor_printf(mon
, "Client:\n");
465 monitor_printf(mon
, " address: %s:%s\n",
466 client
->value
->host
, client
->value
->service
);
467 monitor_printf(mon
, " x509_dname: %s\n",
468 client
->value
->x509_dname
?
469 client
->value
->x509_dname
: "none");
470 monitor_printf(mon
, " username: %s\n",
471 client
->value
->has_sasl_username
?
472 client
->value
->sasl_username
: "none");
477 qapi_free_VncInfo(info
);
480 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
482 SpiceChannelList
*chan
;
485 info
= qmp_query_spice(NULL
);
487 if (!info
->enabled
) {
488 monitor_printf(mon
, "Server: disabled\n");
492 monitor_printf(mon
, "Server:\n");
493 if (info
->has_port
) {
494 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
495 info
->host
, info
->port
);
497 if (info
->has_tls_port
) {
498 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
499 info
->host
, info
->tls_port
);
501 monitor_printf(mon
, " migrated: %s\n",
502 info
->migrated
? "true" : "false");
503 monitor_printf(mon
, " auth: %s\n", info
->auth
);
504 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
505 monitor_printf(mon
, " mouse-mode: %s\n",
506 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
508 if (!info
->has_channels
|| info
->channels
== NULL
) {
509 monitor_printf(mon
, "Channels: none\n");
511 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
512 monitor_printf(mon
, "Channel:\n");
513 monitor_printf(mon
, " address: %s:%s%s\n",
514 chan
->value
->host
, chan
->value
->port
,
515 chan
->value
->tls
? " [tls]" : "");
516 monitor_printf(mon
, " session: %" PRId64
"\n",
517 chan
->value
->connection_id
);
518 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
519 chan
->value
->channel_type
, chan
->value
->channel_id
);
524 qapi_free_SpiceInfo(info
);
527 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
532 info
= qmp_query_balloon(&err
);
534 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
539 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
541 qapi_free_BalloonInfo(info
);
544 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
546 PciMemoryRegionList
*region
;
548 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
549 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
550 dev
->slot
, dev
->function
);
551 monitor_printf(mon
, " ");
553 if (dev
->class_info
.has_desc
) {
554 monitor_printf(mon
, "%s", dev
->class_info
.desc
);
556 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
.q_class
);
559 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
560 dev
->id
.vendor
, dev
->id
.device
);
563 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
566 if (dev
->has_pci_bridge
) {
567 monitor_printf(mon
, " BUS %" PRId64
".\n",
568 dev
->pci_bridge
->bus
.number
);
569 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
570 dev
->pci_bridge
->bus
.secondary
);
571 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
572 dev
->pci_bridge
->bus
.subordinate
);
574 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
575 dev
->pci_bridge
->bus
.io_range
->base
,
576 dev
->pci_bridge
->bus
.io_range
->limit
);
579 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
580 dev
->pci_bridge
->bus
.memory_range
->base
,
581 dev
->pci_bridge
->bus
.memory_range
->limit
);
583 monitor_printf(mon
, " prefetchable memory range "
584 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
585 dev
->pci_bridge
->bus
.prefetchable_range
->base
,
586 dev
->pci_bridge
->bus
.prefetchable_range
->limit
);
589 for (region
= dev
->regions
; region
; region
= region
->next
) {
592 addr
= region
->value
->address
;
593 size
= region
->value
->size
;
595 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
597 if (!strcmp(region
->value
->type
, "io")) {
598 monitor_printf(mon
, "I/O at 0x%04" PRIx64
599 " [0x%04" PRIx64
"].\n",
600 addr
, addr
+ size
- 1);
602 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
603 " [0x%08" PRIx64
"].\n",
604 region
->value
->mem_type_64
? 64 : 32,
605 region
->value
->prefetch
? " prefetchable" : "",
606 addr
, addr
+ size
- 1);
610 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
612 if (dev
->has_pci_bridge
) {
613 if (dev
->pci_bridge
->has_devices
) {
614 PciDeviceInfoList
*cdev
;
615 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
616 hmp_info_pci_device(mon
, cdev
->value
);
622 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
624 PciInfoList
*info_list
, *info
;
627 info_list
= qmp_query_pci(&err
);
629 monitor_printf(mon
, "PCI devices not supported\n");
634 for (info
= info_list
; info
; info
= info
->next
) {
635 PciDeviceInfoList
*dev
;
637 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
638 hmp_info_pci_device(mon
, dev
->value
);
642 qapi_free_PciInfoList(info_list
);
645 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
647 BlockJobInfoList
*list
;
650 list
= qmp_query_block_jobs(&err
);
654 monitor_printf(mon
, "No active jobs\n");
659 if (strcmp(list
->value
->type
, "stream") == 0) {
660 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
661 " of %" PRId64
" bytes, speed limit %" PRId64
668 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
669 " of %" PRId64
" bytes, speed limit %" PRId64
681 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
683 TPMInfoList
*info_list
, *info
;
686 TPMPassthroughOptions
*tpo
;
688 info_list
= qmp_query_tpm(&err
);
690 monitor_printf(mon
, "TPM device not supported\n");
696 monitor_printf(mon
, "TPM device:\n");
699 for (info
= info_list
; info
; info
= info
->next
) {
700 TPMInfo
*ti
= info
->value
;
701 monitor_printf(mon
, " tpm%d: model=%s\n",
702 c
, TpmModel_lookup
[ti
->model
]);
704 monitor_printf(mon
, " \\ %s: type=%s",
705 ti
->id
, TpmTypeOptionsKind_lookup
[ti
->options
->kind
]);
707 switch (ti
->options
->kind
) {
708 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
709 tpo
= ti
->options
->passthrough
;
710 monitor_printf(mon
, "%s%s%s%s",
711 tpo
->has_path
? ",path=" : "",
712 tpo
->has_path
? tpo
->path
: "",
713 tpo
->has_cancel_path
? ",cancel-path=" : "",
714 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
716 case TPM_TYPE_OPTIONS_KIND_MAX
:
719 monitor_printf(mon
, "\n");
722 qapi_free_TPMInfoList(info_list
);
725 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
727 monitor_suspend(mon
);
731 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
736 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
738 qmp_system_reset(NULL
);
741 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
743 qmp_system_powerdown(NULL
);
746 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
750 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
751 use it are converted to the QAPI */
752 cpu_index
= qdict_get_int(qdict
, "index");
753 if (monitor_set_cpu(cpu_index
) < 0) {
754 monitor_printf(mon
, "invalid CPU index\n");
758 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
760 uint32_t size
= qdict_get_int(qdict
, "size");
761 const char *filename
= qdict_get_str(qdict
, "filename");
762 uint64_t addr
= qdict_get_int(qdict
, "val");
765 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &err
);
766 hmp_handle_error(mon
, &err
);
769 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
771 uint32_t size
= qdict_get_int(qdict
, "size");
772 const char *filename
= qdict_get_str(qdict
, "filename");
773 uint64_t addr
= qdict_get_int(qdict
, "val");
776 qmp_pmemsave(addr
, size
, filename
, &err
);
777 hmp_handle_error(mon
, &err
);
780 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
782 const char *chardev
= qdict_get_str(qdict
, "device");
783 const char *data
= qdict_get_str(qdict
, "data");
786 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
788 hmp_handle_error(mon
, &err
);
791 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
793 uint32_t size
= qdict_get_int(qdict
, "size");
794 const char *chardev
= qdict_get_str(qdict
, "device");
799 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
801 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
806 for (i
= 0; data
[i
]; i
++) {
807 unsigned char ch
= data
[i
];
810 monitor_printf(mon
, "\\\\");
811 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
812 monitor_printf(mon
, "\\u%04X", ch
);
814 monitor_printf(mon
, "%c", ch
);
818 monitor_printf(mon
, "\n");
822 static void hmp_cont_cb(void *opaque
, int err
)
829 static bool key_is_missing(const BlockInfo
*bdev
)
831 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
834 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
836 BlockInfoList
*bdev_list
, *bdev
;
839 bdev_list
= qmp_query_block(NULL
);
840 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
841 if (key_is_missing(bdev
->value
)) {
842 monitor_read_block_device_key(mon
, bdev
->value
->device
,
849 hmp_handle_error(mon
, &err
);
852 qapi_free_BlockInfoList(bdev_list
);
855 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
857 qmp_system_wakeup(NULL
);
860 void hmp_inject_nmi(Monitor
*mon
, const QDict
*qdict
)
864 qmp_inject_nmi(&err
);
865 hmp_handle_error(mon
, &err
);
868 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
870 const char *name
= qdict_get_str(qdict
, "name");
871 int up
= qdict_get_bool(qdict
, "up");
874 qmp_set_link(name
, up
, &err
);
875 hmp_handle_error(mon
, &err
);
878 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
880 const char *device
= qdict_get_str(qdict
, "device");
881 const char *password
= qdict_get_str(qdict
, "password");
884 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
885 hmp_handle_error(mon
, &err
);
888 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
890 int64_t value
= qdict_get_int(qdict
, "value");
893 qmp_balloon(value
, &err
);
895 monitor_printf(mon
, "balloon: %s\n", error_get_pretty(err
));
900 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
902 const char *device
= qdict_get_str(qdict
, "device");
903 int64_t size
= qdict_get_int(qdict
, "size");
906 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
907 hmp_handle_error(mon
, &err
);
910 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
912 const char *device
= qdict_get_str(qdict
, "device");
913 const char *filename
= qdict_get_str(qdict
, "target");
914 const char *format
= qdict_get_try_str(qdict
, "format");
915 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
916 int full
= qdict_get_try_bool(qdict
, "full", 0);
917 enum NewImageMode mode
;
921 error_set(&err
, QERR_MISSING_PARAMETER
, "target");
922 hmp_handle_error(mon
, &err
);
927 mode
= NEW_IMAGE_MODE_EXISTING
;
929 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
932 qmp_drive_mirror(device
, filename
, !!format
, format
,
933 full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
934 true, mode
, false, 0, false, 0, false, 0,
935 false, 0, false, 0, &err
);
936 hmp_handle_error(mon
, &err
);
939 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
941 const char *device
= qdict_get_str(qdict
, "device");
942 const char *filename
= qdict_get_str(qdict
, "target");
943 const char *format
= qdict_get_try_str(qdict
, "format");
944 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
945 int full
= qdict_get_try_bool(qdict
, "full", 0);
946 enum NewImageMode mode
;
950 error_set(&err
, QERR_MISSING_PARAMETER
, "target");
951 hmp_handle_error(mon
, &err
);
956 mode
= NEW_IMAGE_MODE_EXISTING
;
958 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
961 qmp_drive_backup(device
, filename
, !!format
, format
,
962 full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
963 true, mode
, false, 0, false, 0, false, 0, &err
);
964 hmp_handle_error(mon
, &err
);
967 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
969 const char *device
= qdict_get_str(qdict
, "device");
970 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
971 const char *format
= qdict_get_try_str(qdict
, "format");
972 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
973 enum NewImageMode mode
;
977 /* In the future, if 'snapshot-file' is not specified, the snapshot
978 will be taken internally. Today it's actually required. */
979 error_set(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
980 hmp_handle_error(mon
, &err
);
984 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
985 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
986 filename
, false, NULL
,
989 hmp_handle_error(mon
, &err
);
992 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
994 const char *device
= qdict_get_str(qdict
, "device");
995 const char *name
= qdict_get_str(qdict
, "name");
998 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
999 hmp_handle_error(mon
, &err
);
1002 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1004 const char *device
= qdict_get_str(qdict
, "device");
1005 const char *name
= qdict_get_str(qdict
, "name");
1006 const char *id
= qdict_get_try_str(qdict
, "id");
1009 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1011 hmp_handle_error(mon
, &err
);
1014 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1016 qmp_migrate_cancel(NULL
);
1019 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1021 double value
= qdict_get_double(qdict
, "value");
1022 qmp_migrate_set_downtime(value
, NULL
);
1025 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1027 int64_t value
= qdict_get_int(qdict
, "value");
1030 qmp_migrate_set_cache_size(value
, &err
);
1032 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
1038 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1040 int64_t value
= qdict_get_int(qdict
, "value");
1041 qmp_migrate_set_speed(value
, NULL
);
1044 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1046 const char *cap
= qdict_get_str(qdict
, "capability");
1047 bool state
= qdict_get_bool(qdict
, "state");
1049 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1052 for (i
= 0; i
< MIGRATION_CAPABILITY_MAX
; i
++) {
1053 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
1054 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1055 caps
->value
->capability
= i
;
1056 caps
->value
->state
= state
;
1058 qmp_migrate_set_capabilities(caps
, &err
);
1063 if (i
== MIGRATION_CAPABILITY_MAX
) {
1064 error_set(&err
, QERR_INVALID_PARAMETER
, cap
);
1067 qapi_free_MigrationCapabilityStatusList(caps
);
1070 monitor_printf(mon
, "migrate_set_capability: %s\n",
1071 error_get_pretty(err
));
1076 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1078 const char *protocol
= qdict_get_str(qdict
, "protocol");
1079 const char *password
= qdict_get_str(qdict
, "password");
1080 const char *connected
= qdict_get_try_str(qdict
, "connected");
1083 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1084 hmp_handle_error(mon
, &err
);
1087 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1089 const char *protocol
= qdict_get_str(qdict
, "protocol");
1090 const char *whenstr
= qdict_get_str(qdict
, "time");
1093 qmp_expire_password(protocol
, whenstr
, &err
);
1094 hmp_handle_error(mon
, &err
);
1097 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1099 int force
= qdict_get_try_bool(qdict
, "force", 0);
1100 const char *device
= qdict_get_str(qdict
, "device");
1103 qmp_eject(device
, true, force
, &err
);
1104 hmp_handle_error(mon
, &err
);
1107 static void hmp_change_read_arg(void *opaque
, const char *password
,
1108 void *readline_opaque
)
1110 qmp_change_vnc_password(password
, NULL
);
1111 monitor_read_command(opaque
, 1);
1114 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1116 const char *device
= qdict_get_str(qdict
, "device");
1117 const char *target
= qdict_get_str(qdict
, "target");
1118 const char *arg
= qdict_get_try_str(qdict
, "arg");
1121 if (strcmp(device
, "vnc") == 0 &&
1122 (strcmp(target
, "passwd") == 0 ||
1123 strcmp(target
, "password") == 0)) {
1125 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1130 qmp_change(device
, target
, !!arg
, arg
, &err
);
1132 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
1134 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
1137 hmp_handle_error(mon
, &err
);
1140 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1144 qmp_block_set_io_throttle(qdict_get_str(qdict
, "device"),
1145 qdict_get_int(qdict
, "bps"),
1146 qdict_get_int(qdict
, "bps_rd"),
1147 qdict_get_int(qdict
, "bps_wr"),
1148 qdict_get_int(qdict
, "iops"),
1149 qdict_get_int(qdict
, "iops_rd"),
1150 qdict_get_int(qdict
, "iops_wr"),
1151 false, /* no burst max via HMP */
1163 false, /* No default I/O size */
1165 hmp_handle_error(mon
, &err
);
1168 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1170 Error
*error
= NULL
;
1171 const char *device
= qdict_get_str(qdict
, "device");
1172 const char *base
= qdict_get_try_str(qdict
, "base");
1173 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1175 qmp_block_stream(device
, base
!= NULL
, base
,
1176 qdict_haskey(qdict
, "speed"), speed
,
1177 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1179 hmp_handle_error(mon
, &error
);
1182 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1184 Error
*error
= NULL
;
1185 const char *device
= qdict_get_str(qdict
, "device");
1186 int64_t value
= qdict_get_int(qdict
, "speed");
1188 qmp_block_job_set_speed(device
, value
, &error
);
1190 hmp_handle_error(mon
, &error
);
1193 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1195 Error
*error
= NULL
;
1196 const char *device
= qdict_get_str(qdict
, "device");
1197 bool force
= qdict_get_try_bool(qdict
, "force", 0);
1199 qmp_block_job_cancel(device
, true, force
, &error
);
1201 hmp_handle_error(mon
, &error
);
1204 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1206 Error
*error
= NULL
;
1207 const char *device
= qdict_get_str(qdict
, "device");
1209 qmp_block_job_pause(device
, &error
);
1211 hmp_handle_error(mon
, &error
);
1214 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1216 Error
*error
= NULL
;
1217 const char *device
= qdict_get_str(qdict
, "device");
1219 qmp_block_job_resume(device
, &error
);
1221 hmp_handle_error(mon
, &error
);
1224 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1226 Error
*error
= NULL
;
1227 const char *device
= qdict_get_str(qdict
, "device");
1229 qmp_block_job_complete(device
, &error
);
1231 hmp_handle_error(mon
, &error
);
1234 typedef struct MigrationStatus
1238 bool is_block_migration
;
1241 static void hmp_migrate_status_cb(void *opaque
)
1243 MigrationStatus
*status
= opaque
;
1244 MigrationInfo
*info
;
1246 info
= qmp_query_migrate(NULL
);
1247 if (!info
->has_status
|| strcmp(info
->status
, "active") == 0 ||
1248 strcmp(info
->status
, "setup") == 0) {
1249 if (info
->has_disk
) {
1252 if (info
->disk
->remaining
) {
1253 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1258 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1259 monitor_flush(status
->mon
);
1262 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1264 if (status
->is_block_migration
) {
1265 monitor_printf(status
->mon
, "\n");
1267 monitor_resume(status
->mon
);
1268 timer_del(status
->timer
);
1272 qapi_free_MigrationInfo(info
);
1275 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1277 int detach
= qdict_get_try_bool(qdict
, "detach", 0);
1278 int blk
= qdict_get_try_bool(qdict
, "blk", 0);
1279 int inc
= qdict_get_try_bool(qdict
, "inc", 0);
1280 const char *uri
= qdict_get_str(qdict
, "uri");
1283 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1285 monitor_printf(mon
, "migrate: %s\n", error_get_pretty(err
));
1291 MigrationStatus
*status
;
1293 if (monitor_suspend(mon
) < 0) {
1294 monitor_printf(mon
, "terminal does not allow synchronous "
1295 "migration, continuing detached\n");
1299 status
= g_malloc0(sizeof(*status
));
1301 status
->is_block_migration
= blk
|| inc
;
1302 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1304 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1308 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1310 const char *id
= qdict_get_str(qdict
, "id");
1313 qmp_device_del(id
, &err
);
1314 hmp_handle_error(mon
, &err
);
1317 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1320 int paging
= qdict_get_try_bool(qdict
, "paging", 0);
1321 int zlib
= qdict_get_try_bool(qdict
, "zlib", 0);
1322 int lzo
= qdict_get_try_bool(qdict
, "lzo", 0);
1323 int snappy
= qdict_get_try_bool(qdict
, "snappy", 0);
1324 const char *file
= qdict_get_str(qdict
, "filename");
1325 bool has_begin
= qdict_haskey(qdict
, "begin");
1326 bool has_length
= qdict_haskey(qdict
, "length");
1329 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
1332 if (zlib
+ lzo
+ snappy
> 1) {
1333 error_setg(&err
, "only one of '-z|-l|-s' can be set");
1334 hmp_handle_error(mon
, &err
);
1339 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
1343 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
1347 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
1351 begin
= qdict_get_int(qdict
, "begin");
1354 length
= qdict_get_int(qdict
, "length");
1357 prot
= g_strconcat("file:", file
, NULL
);
1359 qmp_dump_guest_memory(paging
, prot
, has_begin
, begin
, has_length
, length
,
1360 true, dump_format
, &err
);
1361 hmp_handle_error(mon
, &err
);
1365 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1370 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1375 netdev_add(opts
, &err
);
1377 qemu_opts_del(opts
);
1381 hmp_handle_error(mon
, &err
);
1384 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1386 const char *id
= qdict_get_str(qdict
, "id");
1389 qmp_netdev_del(id
, &err
);
1390 hmp_handle_error(mon
, &err
);
1393 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
1396 Error
*err_end
= NULL
;
1404 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
1409 ov
= opts_visitor_new(opts
);
1410 pdict
= qdict_clone_shallow(qdict
);
1412 visit_start_struct(opts_get_visitor(ov
), &dummy
, NULL
, NULL
, 0, &err
);
1417 qdict_del(pdict
, "qom-type");
1418 visit_type_str(opts_get_visitor(ov
), &type
, "qom-type", &err
);
1423 qdict_del(pdict
, "id");
1424 visit_type_str(opts_get_visitor(ov
), &id
, "id", &err
);
1429 object_add(type
, id
, pdict
, opts_get_visitor(ov
), &err
);
1432 visit_end_struct(opts_get_visitor(ov
), &err_end
);
1433 if (!err
&& err_end
) {
1434 qmp_object_del(id
, NULL
);
1436 error_propagate(&err
, err_end
);
1438 opts_visitor_cleanup(ov
);
1441 qemu_opts_del(opts
);
1447 hmp_handle_error(mon
, &err
);
1450 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1452 const char *fdname
= qdict_get_str(qdict
, "fdname");
1455 qmp_getfd(fdname
, &err
);
1456 hmp_handle_error(mon
, &err
);
1459 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1461 const char *fdname
= qdict_get_str(qdict
, "fdname");
1464 qmp_closefd(fdname
, &err
);
1465 hmp_handle_error(mon
, &err
);
1468 void hmp_send_key(Monitor
*mon
, const QDict
*qdict
)
1470 const char *keys
= qdict_get_str(qdict
, "keys");
1471 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
1472 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1473 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1475 char keyname_buf
[16];
1480 separator
= strchr(keys
, '-');
1481 keyname_len
= separator
? separator
- keys
: strlen(keys
);
1482 pstrcpy(keyname_buf
, sizeof(keyname_buf
), keys
);
1484 /* Be compatible with old interface, convert user inputted "<" */
1485 if (!strncmp(keyname_buf
, "<", 1) && keyname_len
== 1) {
1486 pstrcpy(keyname_buf
, sizeof(keyname_buf
), "less");
1489 keyname_buf
[keyname_len
] = 0;
1491 keylist
= g_malloc0(sizeof(*keylist
));
1492 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
1498 tmp
->next
= keylist
;
1502 if (strstart(keyname_buf
, "0x", NULL
)) {
1504 int value
= strtoul(keyname_buf
, &endp
, 0);
1505 if (*endp
!= '\0') {
1508 keylist
->value
->kind
= KEY_VALUE_KIND_NUMBER
;
1509 keylist
->value
->number
= value
;
1511 int idx
= index_from_key(keyname_buf
);
1512 if (idx
== Q_KEY_CODE_MAX
) {
1515 keylist
->value
->kind
= KEY_VALUE_KIND_QCODE
;
1516 keylist
->value
->qcode
= idx
;
1522 keys
= separator
+ 1;
1525 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1526 hmp_handle_error(mon
, &err
);
1529 qapi_free_KeyValueList(head
);
1533 monitor_printf(mon
, "invalid parameter: %s\n", keyname_buf
);
1537 void hmp_screen_dump(Monitor
*mon
, const QDict
*qdict
)
1539 const char *filename
= qdict_get_str(qdict
, "filename");
1542 qmp_screendump(filename
, &err
);
1543 hmp_handle_error(mon
, &err
);
1546 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
1548 const char *uri
= qdict_get_str(qdict
, "uri");
1549 int writable
= qdict_get_try_bool(qdict
, "writable", 0);
1550 int all
= qdict_get_try_bool(qdict
, "all", 0);
1551 Error
*local_err
= NULL
;
1552 BlockInfoList
*block_list
, *info
;
1553 SocketAddress
*addr
;
1555 if (writable
&& !all
) {
1556 error_setg(&local_err
, "-w only valid together with -a");
1560 /* First check if the address is valid and start the server. */
1561 addr
= socket_parse(uri
, &local_err
);
1562 if (local_err
!= NULL
) {
1566 qmp_nbd_server_start(addr
, &local_err
);
1567 qapi_free_SocketAddress(addr
);
1568 if (local_err
!= NULL
) {
1576 /* Then try adding all block devices. If one fails, close all and
1579 block_list
= qmp_query_block(NULL
);
1581 for (info
= block_list
; info
; info
= info
->next
) {
1582 if (!info
->value
->has_inserted
) {
1586 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
1588 if (local_err
!= NULL
) {
1589 qmp_nbd_server_stop(NULL
);
1594 qapi_free_BlockInfoList(block_list
);
1597 hmp_handle_error(mon
, &local_err
);
1600 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
1602 const char *device
= qdict_get_str(qdict
, "device");
1603 int writable
= qdict_get_try_bool(qdict
, "writable", 0);
1604 Error
*local_err
= NULL
;
1606 qmp_nbd_server_add(device
, true, writable
, &local_err
);
1608 if (local_err
!= NULL
) {
1609 hmp_handle_error(mon
, &local_err
);
1613 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
1617 qmp_nbd_server_stop(&err
);
1618 hmp_handle_error(mon
, &err
);
1621 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
1626 cpuid
= qdict_get_int(qdict
, "id");
1627 qmp_cpu_add(cpuid
, &err
);
1628 hmp_handle_error(mon
, &err
);
1631 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
1633 const char *args
= qdict_get_str(qdict
, "args");
1637 opts
= qemu_opts_parse(qemu_find_opts("chardev"), args
, 1);
1639 error_setg(&err
, "Parsing chardev args failed");
1641 qemu_chr_new_from_opts(opts
, NULL
, &err
);
1643 hmp_handle_error(mon
, &err
);
1646 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
1648 Error
*local_err
= NULL
;
1650 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
1651 hmp_handle_error(mon
, &local_err
);
1654 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
1656 BlockDriverState
*bs
;
1657 const char* device
= qdict_get_str(qdict
, "device");
1658 const char* command
= qdict_get_str(qdict
, "command");
1661 bs
= bdrv_find(device
);
1663 qemuio_command(bs
, command
);
1665 error_set(&err
, QERR_DEVICE_NOT_FOUND
, device
);
1668 hmp_handle_error(mon
, &err
);
1671 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
1673 const char *id
= qdict_get_str(qdict
, "id");
1676 qmp_object_del(id
, &err
);
1677 hmp_handle_error(mon
, &err
);