]> git.proxmox.com Git - mirror_qemu.git/blame - hmp.c
hbitmap: add hbitmap_merge
[mirror_qemu.git] / hmp.c
CommitLineData
48a32bed
AL
1/*
2 * Human Monitor Interface
3 *
4 * Copyright IBM, Corp. 2011
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
6b620ca3
PB
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.
48a32bed
AL
14 */
15
16#include "hmp.h"
1422e32d 17#include "net/net.h"
dccfcd0e 18#include "sysemu/char.h"
4c7b7e9b 19#include "sysemu/block-backend.h"
1de7afc9
PB
20#include "qemu/option.h"
21#include "qemu/timer.h"
48a32bed 22#include "qmp-commands.h"
1de7afc9 23#include "qemu/sockets.h"
83c9089e 24#include "monitor/monitor.h"
cff8b2c6 25#include "qapi/opts-visitor.h"
eb1539b2
HT
26#include "qapi/string-output-visitor.h"
27#include "qapi-visit.h"
28ecbaee 28#include "ui/console.h"
bd093a36 29#include "block/qapi.h"
587da2c3 30#include "qemu-io.h"
48a32bed 31
22fa7da0
CR
32#ifdef CONFIG_SPICE
33#include <spice/enums.h>
34#endif
35
0cfd6a9a
LC
36static void hmp_handle_error(Monitor *mon, Error **errp)
37{
415168e0
MA
38 assert(errp);
39 if (*errp) {
0cfd6a9a
LC
40 monitor_printf(mon, "%s\n", error_get_pretty(*errp));
41 error_free(*errp);
42 }
43}
44
84f2d0ea 45void hmp_info_name(Monitor *mon, const QDict *qdict)
48a32bed
AL
46{
47 NameInfo *info;
48
49 info = qmp_query_name(NULL);
50 if (info->has_name) {
51 monitor_printf(mon, "%s\n", info->name);
52 }
53 qapi_free_NameInfo(info);
54}
b9c15f16 55
84f2d0ea 56void hmp_info_version(Monitor *mon, const QDict *qdict)
b9c15f16
LC
57{
58 VersionInfo *info;
59
60 info = qmp_query_version(NULL);
61
62 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
63 info->qemu.major, info->qemu.minor, info->qemu.micro,
64 info->package);
65
66 qapi_free_VersionInfo(info);
67}
292a2602 68
84f2d0ea 69void hmp_info_kvm(Monitor *mon, const QDict *qdict)
292a2602
LC
70{
71 KvmInfo *info;
72
73 info = qmp_query_kvm(NULL);
74 monitor_printf(mon, "kvm support: ");
75 if (info->present) {
76 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
77 } else {
78 monitor_printf(mon, "not compiled\n");
79 }
80
81 qapi_free_KvmInfo(info);
82}
83
84f2d0ea 84void hmp_info_status(Monitor *mon, const QDict *qdict)
1fa9a5e4
LC
85{
86 StatusInfo *info;
87
88 info = qmp_query_status(NULL);
89
90 monitor_printf(mon, "VM status: %s%s",
91 info->running ? "running" : "paused",
92 info->singlestep ? " (single step mode)" : "");
93
94 if (!info->running && info->status != RUN_STATE_PAUSED) {
95 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
96 }
97
98 monitor_printf(mon, "\n");
99
100 qapi_free_StatusInfo(info);
101}
102
84f2d0ea 103void hmp_info_uuid(Monitor *mon, const QDict *qdict)
efab767e
LC
104{
105 UuidInfo *info;
106
107 info = qmp_query_uuid(NULL);
108 monitor_printf(mon, "%s\n", info->UUID);
109 qapi_free_UuidInfo(info);
110}
c5a415a0 111
84f2d0ea 112void hmp_info_chardev(Monitor *mon, const QDict *qdict)
c5a415a0
LC
113{
114 ChardevInfoList *char_info, *info;
115
116 char_info = qmp_query_chardev(NULL);
117 for (info = char_info; info; info = info->next) {
118 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
119 info->value->filename);
120 }
121
122 qapi_free_ChardevInfoList(char_info);
123}
7a7f325e 124
84f2d0ea 125void hmp_info_mice(Monitor *mon, const QDict *qdict)
e235cec3
LC
126{
127 MouseInfoList *mice_list, *mouse;
128
129 mice_list = qmp_query_mice(NULL);
130 if (!mice_list) {
131 monitor_printf(mon, "No mouse devices connected\n");
132 return;
133 }
134
135 for (mouse = mice_list; mouse; mouse = mouse->next) {
136 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
137 mouse->value->current ? '*' : ' ',
138 mouse->value->index, mouse->value->name,
139 mouse->value->absolute ? " (absolute)" : "");
140 }
141
142 qapi_free_MouseInfoList(mice_list);
143}
144
84f2d0ea 145void hmp_info_migrate(Monitor *mon, const QDict *qdict)
791e7c82
LC
146{
147 MigrationInfo *info;
bbf6da32 148 MigrationCapabilityStatusList *caps, *cap;
791e7c82
LC
149
150 info = qmp_query_migrate(NULL);
bbf6da32
OW
151 caps = qmp_query_migrate_capabilities(NULL);
152
153 /* do not display parameters during setup */
154 if (info->has_status && caps) {
155 monitor_printf(mon, "capabilities: ");
156 for (cap = caps; cap; cap = cap->next) {
157 monitor_printf(mon, "%s: %s ",
158 MigrationCapability_lookup[cap->value->capability],
159 cap->value->state ? "on" : "off");
160 }
161 monitor_printf(mon, "\n");
162 }
791e7c82
LC
163
164 if (info->has_status) {
24b8c39b
HZ
165 monitor_printf(mon, "Migration status: %s\n",
166 MigrationStatus_lookup[info->status]);
7aa939af
JQ
167 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
168 info->total_time);
2c52ddf1
JQ
169 if (info->has_expected_downtime) {
170 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
171 info->expected_downtime);
172 }
9c5a9fcf
JQ
173 if (info->has_downtime) {
174 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
175 info->downtime);
176 }
ed4fbd10
MH
177 if (info->has_setup_time) {
178 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
179 info->setup_time);
180 }
791e7c82
LC
181 }
182
183 if (info->has_ram) {
184 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
185 info->ram->transferred >> 10);
7e114f8c
MH
186 monitor_printf(mon, "throughput: %0.2f mbps\n",
187 info->ram->mbps);
791e7c82
LC
188 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
189 info->ram->remaining >> 10);
190 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
191 info->ram->total >> 10);
004d4c10
OW
192 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
193 info->ram->duplicate);
f1c72795
PL
194 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
195 info->ram->skipped);
004d4c10
OW
196 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
197 info->ram->normal);
198 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
199 info->ram->normal_bytes >> 10);
58570ed8
C
200 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
201 info->ram->dirty_sync_count);
8d017193
JQ
202 if (info->ram->dirty_pages_rate) {
203 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
204 info->ram->dirty_pages_rate);
205 }
791e7c82
LC
206 }
207
208 if (info->has_disk) {
209 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
210 info->disk->transferred >> 10);
211 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
212 info->disk->remaining >> 10);
213 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
214 info->disk->total >> 10);
215 }
216
f36d55af
OW
217 if (info->has_xbzrle_cache) {
218 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
219 info->xbzrle_cache->cache_size);
220 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
221 info->xbzrle_cache->bytes >> 10);
222 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
223 info->xbzrle_cache->pages);
224 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
225 info->xbzrle_cache->cache_miss);
8bc39233
C
226 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
227 info->xbzrle_cache->cache_miss_rate);
f36d55af
OW
228 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
229 info->xbzrle_cache->overflow);
230 }
231
791e7c82 232 qapi_free_MigrationInfo(info);
bbf6da32
OW
233 qapi_free_MigrationCapabilityStatusList(caps);
234}
235
84f2d0ea 236void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
bbf6da32
OW
237{
238 MigrationCapabilityStatusList *caps, *cap;
239
240 caps = qmp_query_migrate_capabilities(NULL);
241
242 if (caps) {
243 monitor_printf(mon, "capabilities: ");
244 for (cap = caps; cap; cap = cap->next) {
245 monitor_printf(mon, "%s: %s ",
246 MigrationCapability_lookup[cap->value->capability],
247 cap->value->state ? "on" : "off");
248 }
249 monitor_printf(mon, "\n");
250 }
251
252 qapi_free_MigrationCapabilityStatusList(caps);
791e7c82
LC
253}
254
84f2d0ea 255void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
9e1ba4cc
OW
256{
257 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
258 qmp_query_migrate_cache_size(NULL) >> 10);
259}
260
84f2d0ea 261void hmp_info_cpus(Monitor *mon, const QDict *qdict)
de0b36b6
LC
262{
263 CpuInfoList *cpu_list, *cpu;
264
265 cpu_list = qmp_query_cpus(NULL);
266
267 for (cpu = cpu_list; cpu; cpu = cpu->next) {
268 int active = ' ';
269
270 if (cpu->value->CPU == monitor_get_cpu_index()) {
271 active = '*';
272 }
273
852bef0e 274 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
de0b36b6
LC
275
276 if (cpu->value->has_pc) {
852bef0e 277 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->pc);
de0b36b6
LC
278 }
279 if (cpu->value->has_nip) {
852bef0e 280 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->nip);
de0b36b6
LC
281 }
282 if (cpu->value->has_npc) {
852bef0e 283 monitor_printf(mon, " npc=0x%016" PRIx64, cpu->value->npc);
de0b36b6
LC
284 }
285 if (cpu->value->has_PC) {
852bef0e 286 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->PC);
de0b36b6
LC
287 }
288
289 if (cpu->value->halted) {
290 monitor_printf(mon, " (halted)");
291 }
292
293 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
294 }
295
296 qapi_free_CpuInfoList(cpu_list);
297}
298
289b276c
KW
299static void print_block_info(Monitor *mon, BlockInfo *info,
300 BlockDeviceInfo *inserted, bool verbose)
b2023818 301{
bd093a36 302 ImageInfo *image_info;
b2023818 303
8d6adccd
KW
304 assert(!info || !info->has_inserted || info->inserted == inserted);
305
306 if (info) {
307 monitor_printf(mon, "%s", info->device);
308 if (inserted && inserted->has_node_name) {
309 monitor_printf(mon, " (%s)", inserted->node_name);
310 }
311 } else {
312 assert(inserted);
313 monitor_printf(mon, "%s",
314 inserted->has_node_name
315 ? inserted->node_name
316 : "<anonymous>");
317 }
318
289b276c
KW
319 if (inserted) {
320 monitor_printf(mon, ": %s (%s%s%s)\n",
321 inserted->file,
322 inserted->drv,
323 inserted->ro ? ", read-only" : "",
324 inserted->encrypted ? ", encrypted" : "");
325 } else {
326 monitor_printf(mon, ": [not inserted]\n");
327 }
b2023818 328
8d6adccd
KW
329 if (info) {
330 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
331 monitor_printf(mon, " I/O status: %s\n",
332 BlockDeviceIoStatus_lookup[info->io_status]);
333 }
b2023818 334
8d6adccd
KW
335 if (info->removable) {
336 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
337 info->locked ? "" : "not ",
338 info->tray_open ? "open" : "closed");
339 }
289b276c 340 }
fbe2e26c 341
b2023818 342
289b276c
KW
343 if (!inserted) {
344 return;
345 }
b2023818 346
289b276c
KW
347 monitor_printf(mon, " Cache mode: %s%s%s\n",
348 inserted->cache->writeback ? "writeback" : "writethrough",
349 inserted->cache->direct ? ", direct" : "",
350 inserted->cache->no_flush ? ", ignore flushes" : "");
351
352 if (inserted->has_backing_file) {
353 monitor_printf(mon,
354 " Backing file: %s "
355 "(chain depth: %" PRId64 ")\n",
356 inserted->backing_file,
357 inserted->backing_file_depth);
358 }
727f005e 359
289b276c
KW
360 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
361 monitor_printf(mon, " Detect zeroes: %s\n",
362 BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]);
363 }
fbe2e26c 364
289b276c
KW
365 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
366 inserted->iops || inserted->iops_rd || inserted->iops_wr)
367 {
368 monitor_printf(mon, " I/O throttling: bps=%" PRId64
369 " bps_rd=%" PRId64 " bps_wr=%" PRId64
370 " bps_max=%" PRId64
371 " bps_rd_max=%" PRId64
372 " bps_wr_max=%" PRId64
373 " iops=%" PRId64 " iops_rd=%" PRId64
374 " iops_wr=%" PRId64
375 " iops_max=%" PRId64
376 " iops_rd_max=%" PRId64
377 " iops_wr_max=%" PRId64
378 " iops_size=%" PRId64 "\n",
379 inserted->bps,
380 inserted->bps_rd,
381 inserted->bps_wr,
382 inserted->bps_max,
383 inserted->bps_rd_max,
384 inserted->bps_wr_max,
385 inserted->iops,
386 inserted->iops_rd,
387 inserted->iops_wr,
388 inserted->iops_max,
389 inserted->iops_rd_max,
390 inserted->iops_wr_max,
391 inserted->iops_size);
392 }
fbe2e26c 393
9419874f 394 if (verbose) {
289b276c
KW
395 monitor_printf(mon, "\nImages:\n");
396 image_info = inserted->image;
397 while (1) {
398 bdrv_image_info_dump((fprintf_function)monitor_printf,
399 mon, image_info);
400 if (image_info->has_backing_image) {
401 image_info = image_info->backing_image;
402 } else {
403 break;
404 }
405 }
406 }
407}
9e193c5a 408
289b276c
KW
409void hmp_info_block(Monitor *mon, const QDict *qdict)
410{
411 BlockInfoList *block_list, *info;
e6bb31ec 412 BlockDeviceInfoList *blockdev_list, *blockdev;
289b276c
KW
413 const char *device = qdict_get_try_str(qdict, "device");
414 bool verbose = qdict_get_try_bool(qdict, "verbose", 0);
e6bb31ec
KW
415 bool nodes = qdict_get_try_bool(qdict, "nodes", 0);
416 bool printed = false;
9e193c5a 417
e6bb31ec
KW
418 /* Print BlockBackend information */
419 if (!nodes) {
f19e44bc 420 block_list = qmp_query_block(NULL);
e6bb31ec
KW
421 } else {
422 block_list = NULL;
423 }
fbe2e26c 424
289b276c
KW
425 for (info = block_list; info; info = info->next) {
426 if (device && strcmp(device, info->value->device)) {
427 continue;
465bee1d
PL
428 }
429
289b276c
KW
430 if (info != block_list) {
431 monitor_printf(mon, "\n");
fbe2e26c 432 }
bd093a36 433
289b276c
KW
434 print_block_info(mon, info->value, info->value->has_inserted
435 ? info->value->inserted : NULL,
436 verbose);
e6bb31ec 437 printed = true;
b2023818
LC
438 }
439
440 qapi_free_BlockInfoList(block_list);
e6bb31ec
KW
441
442 if ((!device && !nodes) || printed) {
443 return;
444 }
445
446 /* Print node information */
447 blockdev_list = qmp_query_named_block_nodes(NULL);
448 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
449 assert(blockdev->value->has_node_name);
450 if (device && strcmp(device, blockdev->value->node_name)) {
451 continue;
452 }
453
454 if (blockdev != blockdev_list) {
455 monitor_printf(mon, "\n");
456 }
457
458 print_block_info(mon, NULL, blockdev->value, verbose);
459 }
460 qapi_free_BlockDeviceInfoList(blockdev_list);
b2023818
LC
461}
462
84f2d0ea 463void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
f11f57e4
LC
464{
465 BlockStatsList *stats_list, *stats;
466
f71eaa74 467 stats_list = qmp_query_blockstats(false, false, NULL);
f11f57e4
LC
468
469 for (stats = stats_list; stats; stats = stats->next) {
470 if (!stats->value->has_device) {
471 continue;
472 }
473
474 monitor_printf(mon, "%s:", stats->value->device);
475 monitor_printf(mon, " rd_bytes=%" PRId64
476 " wr_bytes=%" PRId64
477 " rd_operations=%" PRId64
478 " wr_operations=%" PRId64
479 " flush_operations=%" PRId64
480 " wr_total_time_ns=%" PRId64
481 " rd_total_time_ns=%" PRId64
482 " flush_total_time_ns=%" PRId64
f4564d53
PL
483 " rd_merged=%" PRId64
484 " wr_merged=%" PRId64
f11f57e4
LC
485 "\n",
486 stats->value->stats->rd_bytes,
487 stats->value->stats->wr_bytes,
488 stats->value->stats->rd_operations,
489 stats->value->stats->wr_operations,
490 stats->value->stats->flush_operations,
491 stats->value->stats->wr_total_time_ns,
492 stats->value->stats->rd_total_time_ns,
f4564d53
PL
493 stats->value->stats->flush_total_time_ns,
494 stats->value->stats->rd_merged,
495 stats->value->stats->wr_merged);
f11f57e4
LC
496 }
497
498 qapi_free_BlockStatsList(stats_list);
499}
500
84f2d0ea 501void hmp_info_vnc(Monitor *mon, const QDict *qdict)
2b54aa87
LC
502{
503 VncInfo *info;
504 Error *err = NULL;
505 VncClientInfoList *client;
506
507 info = qmp_query_vnc(&err);
508 if (err) {
509 monitor_printf(mon, "%s\n", error_get_pretty(err));
510 error_free(err);
511 return;
512 }
513
514 if (!info->enabled) {
515 monitor_printf(mon, "Server: disabled\n");
516 goto out;
517 }
518
519 monitor_printf(mon, "Server:\n");
520 if (info->has_host && info->has_service) {
521 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
522 }
523 if (info->has_auth) {
524 monitor_printf(mon, " auth: %s\n", info->auth);
525 }
526
527 if (!info->has_clients || info->clients == NULL) {
528 monitor_printf(mon, "Client: none\n");
529 } else {
530 for (client = info->clients; client; client = client->next) {
531 monitor_printf(mon, "Client:\n");
532 monitor_printf(mon, " address: %s:%s\n",
a589569f
WX
533 client->value->base->host,
534 client->value->base->service);
2b54aa87
LC
535 monitor_printf(mon, " x509_dname: %s\n",
536 client->value->x509_dname ?
537 client->value->x509_dname : "none");
538 monitor_printf(mon, " username: %s\n",
539 client->value->has_sasl_username ?
540 client->value->sasl_username : "none");
541 }
542 }
543
544out:
545 qapi_free_VncInfo(info);
546}
547
206addd5 548#ifdef CONFIG_SPICE
84f2d0ea 549void hmp_info_spice(Monitor *mon, const QDict *qdict)
d1f29646
LC
550{
551 SpiceChannelList *chan;
552 SpiceInfo *info;
22fa7da0
CR
553 const char *channel_name;
554 const char * const channel_names[] = {
555 [SPICE_CHANNEL_MAIN] = "main",
556 [SPICE_CHANNEL_DISPLAY] = "display",
557 [SPICE_CHANNEL_INPUTS] = "inputs",
558 [SPICE_CHANNEL_CURSOR] = "cursor",
559 [SPICE_CHANNEL_PLAYBACK] = "playback",
560 [SPICE_CHANNEL_RECORD] = "record",
561 [SPICE_CHANNEL_TUNNEL] = "tunnel",
562 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
563 [SPICE_CHANNEL_USBREDIR] = "usbredir",
564 [SPICE_CHANNEL_PORT] = "port",
7c6044a9
GH
565#if 0
566 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
567 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
568 * as quick fix for build failures with older versions. */
22fa7da0 569 [SPICE_CHANNEL_WEBDAV] = "webdav",
7c6044a9 570#endif
22fa7da0 571 };
d1f29646
LC
572
573 info = qmp_query_spice(NULL);
574
575 if (!info->enabled) {
576 monitor_printf(mon, "Server: disabled\n");
577 goto out;
578 }
579
580 monitor_printf(mon, "Server:\n");
581 if (info->has_port) {
582 monitor_printf(mon, " address: %s:%" PRId64 "\n",
583 info->host, info->port);
584 }
585 if (info->has_tls_port) {
586 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
587 info->host, info->tls_port);
588 }
61c4efe2
YH
589 monitor_printf(mon, " migrated: %s\n",
590 info->migrated ? "true" : "false");
d1f29646
LC
591 monitor_printf(mon, " auth: %s\n", info->auth);
592 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
4efee029
AL
593 monitor_printf(mon, " mouse-mode: %s\n",
594 SpiceQueryMouseMode_lookup[info->mouse_mode]);
d1f29646
LC
595
596 if (!info->has_channels || info->channels == NULL) {
597 monitor_printf(mon, "Channels: none\n");
598 } else {
599 for (chan = info->channels; chan; chan = chan->next) {
600 monitor_printf(mon, "Channel:\n");
601 monitor_printf(mon, " address: %s:%s%s\n",
a589569f 602 chan->value->base->host, chan->value->base->port,
d1f29646
LC
603 chan->value->tls ? " [tls]" : "");
604 monitor_printf(mon, " session: %" PRId64 "\n",
605 chan->value->connection_id);
606 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
607 chan->value->channel_type, chan->value->channel_id);
22fa7da0
CR
608
609 channel_name = "unknown";
610 if (chan->value->channel_type > 0 &&
611 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
612 channel_names[chan->value->channel_type]) {
613 channel_name = channel_names[chan->value->channel_type];
614 }
615
616 monitor_printf(mon, " channel name: %s\n", channel_name);
d1f29646
LC
617 }
618 }
619
620out:
621 qapi_free_SpiceInfo(info);
622}
206addd5 623#endif
d1f29646 624
84f2d0ea 625void hmp_info_balloon(Monitor *mon, const QDict *qdict)
96637bcd
LC
626{
627 BalloonInfo *info;
628 Error *err = NULL;
629
630 info = qmp_query_balloon(&err);
631 if (err) {
632 monitor_printf(mon, "%s\n", error_get_pretty(err));
633 error_free(err);
634 return;
635 }
636
01ceb97e 637 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
96637bcd
LC
638
639 qapi_free_BalloonInfo(info);
640}
641
79627472
LC
642static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
643{
644 PciMemoryRegionList *region;
645
646 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
647 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
648 dev->slot, dev->function);
649 monitor_printf(mon, " ");
650
651 if (dev->class_info.has_desc) {
652 monitor_printf(mon, "%s", dev->class_info.desc);
653 } else {
6f88009e 654 monitor_printf(mon, "Class %04" PRId64, dev->class_info.q_class);
79627472
LC
655 }
656
657 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
658 dev->id.vendor, dev->id.device);
659
660 if (dev->has_irq) {
661 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
662 }
663
664 if (dev->has_pci_bridge) {
665 monitor_printf(mon, " BUS %" PRId64 ".\n",
666 dev->pci_bridge->bus.number);
667 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
668 dev->pci_bridge->bus.secondary);
669 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
670 dev->pci_bridge->bus.subordinate);
671
672 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
673 dev->pci_bridge->bus.io_range->base,
674 dev->pci_bridge->bus.io_range->limit);
675
676 monitor_printf(mon,
677 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
678 dev->pci_bridge->bus.memory_range->base,
679 dev->pci_bridge->bus.memory_range->limit);
680
681 monitor_printf(mon, " prefetchable memory range "
682 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
683 dev->pci_bridge->bus.prefetchable_range->base,
684 dev->pci_bridge->bus.prefetchable_range->limit);
685 }
686
687 for (region = dev->regions; region; region = region->next) {
688 uint64_t addr, size;
689
690 addr = region->value->address;
691 size = region->value->size;
692
693 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
694
695 if (!strcmp(region->value->type, "io")) {
696 monitor_printf(mon, "I/O at 0x%04" PRIx64
697 " [0x%04" PRIx64 "].\n",
698 addr, addr + size - 1);
699 } else {
700 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
701 " [0x%08" PRIx64 "].\n",
702 region->value->mem_type_64 ? 64 : 32,
703 region->value->prefetch ? " prefetchable" : "",
704 addr, addr + size - 1);
705 }
706 }
707
708 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
709
710 if (dev->has_pci_bridge) {
711 if (dev->pci_bridge->has_devices) {
712 PciDeviceInfoList *cdev;
713 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
714 hmp_info_pci_device(mon, cdev->value);
715 }
716 }
717 }
718}
719
84f2d0ea 720void hmp_info_pci(Monitor *mon, const QDict *qdict)
79627472 721{
f46cee37 722 PciInfoList *info_list, *info;
79627472
LC
723 Error *err = NULL;
724
f46cee37 725 info_list = qmp_query_pci(&err);
79627472
LC
726 if (err) {
727 monitor_printf(mon, "PCI devices not supported\n");
728 error_free(err);
729 return;
730 }
731
f46cee37 732 for (info = info_list; info; info = info->next) {
79627472
LC
733 PciDeviceInfoList *dev;
734
735 for (dev = info->value->devices; dev; dev = dev->next) {
736 hmp_info_pci_device(mon, dev->value);
737 }
738 }
739
f46cee37 740 qapi_free_PciInfoList(info_list);
79627472
LC
741}
742
84f2d0ea 743void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
fb5458cd
SH
744{
745 BlockJobInfoList *list;
746 Error *err = NULL;
747
748 list = qmp_query_block_jobs(&err);
749 assert(!err);
750
751 if (!list) {
752 monitor_printf(mon, "No active jobs\n");
753 return;
754 }
755
756 while (list) {
757 if (strcmp(list->value->type, "stream") == 0) {
758 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
759 " of %" PRId64 " bytes, speed limit %" PRId64
760 " bytes/s\n",
761 list->value->device,
762 list->value->offset,
763 list->value->len,
764 list->value->speed);
765 } else {
766 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
767 " of %" PRId64 " bytes, speed limit %" PRId64
768 " bytes/s\n",
769 list->value->type,
770 list->value->device,
771 list->value->offset,
772 list->value->len,
773 list->value->speed);
774 }
775 list = list->next;
776 }
93bb1315
GA
777
778 qapi_free_BlockJobInfoList(list);
fb5458cd
SH
779}
780
d1a0cf73
SB
781void hmp_info_tpm(Monitor *mon, const QDict *qdict)
782{
783 TPMInfoList *info_list, *info;
784 Error *err = NULL;
785 unsigned int c = 0;
786 TPMPassthroughOptions *tpo;
787
788 info_list = qmp_query_tpm(&err);
789 if (err) {
790 monitor_printf(mon, "TPM device not supported\n");
791 error_free(err);
792 return;
793 }
794
795 if (info_list) {
796 monitor_printf(mon, "TPM device:\n");
797 }
798
799 for (info = info_list; info; info = info->next) {
800 TPMInfo *ti = info->value;
801 monitor_printf(mon, " tpm%d: model=%s\n",
802 c, TpmModel_lookup[ti->model]);
803
804 monitor_printf(mon, " \\ %s: type=%s",
88ca7bcf 805 ti->id, TpmTypeOptionsKind_lookup[ti->options->kind]);
d1a0cf73 806
88ca7bcf
CB
807 switch (ti->options->kind) {
808 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
809 tpo = ti->options->passthrough;
d1a0cf73
SB
810 monitor_printf(mon, "%s%s%s%s",
811 tpo->has_path ? ",path=" : "",
812 tpo->has_path ? tpo->path : "",
813 tpo->has_cancel_path ? ",cancel-path=" : "",
814 tpo->has_cancel_path ? tpo->cancel_path : "");
815 break;
816 case TPM_TYPE_OPTIONS_KIND_MAX:
817 break;
818 }
819 monitor_printf(mon, "\n");
820 c++;
821 }
822 qapi_free_TPMInfoList(info_list);
823}
824
7a7f325e
LC
825void hmp_quit(Monitor *mon, const QDict *qdict)
826{
827 monitor_suspend(mon);
828 qmp_quit(NULL);
829}
5f158f21
LC
830
831void hmp_stop(Monitor *mon, const QDict *qdict)
832{
833 qmp_stop(NULL);
834}
38d22653
LC
835
836void hmp_system_reset(Monitor *mon, const QDict *qdict)
837{
838 qmp_system_reset(NULL);
839}
5bc465e4
LC
840
841void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
842{
843 qmp_system_powerdown(NULL);
844}
755f1968
LC
845
846void hmp_cpu(Monitor *mon, const QDict *qdict)
847{
848 int64_t cpu_index;
849
850 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
851 use it are converted to the QAPI */
852 cpu_index = qdict_get_int(qdict, "index");
853 if (monitor_set_cpu(cpu_index) < 0) {
854 monitor_printf(mon, "invalid CPU index\n");
855 }
856}
0cfd6a9a
LC
857
858void hmp_memsave(Monitor *mon, const QDict *qdict)
859{
860 uint32_t size = qdict_get_int(qdict, "size");
861 const char *filename = qdict_get_str(qdict, "filename");
862 uint64_t addr = qdict_get_int(qdict, "val");
e940f543 863 Error *err = NULL;
0cfd6a9a 864
e940f543
MA
865 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &err);
866 hmp_handle_error(mon, &err);
0cfd6a9a 867}
6d3962bf
LC
868
869void hmp_pmemsave(Monitor *mon, const QDict *qdict)
870{
871 uint32_t size = qdict_get_int(qdict, "size");
872 const char *filename = qdict_get_str(qdict, "filename");
873 uint64_t addr = qdict_get_int(qdict, "val");
e940f543 874 Error *err = NULL;
6d3962bf 875
e940f543
MA
876 qmp_pmemsave(addr, size, filename, &err);
877 hmp_handle_error(mon, &err);
1f590cf9
LL
878}
879
3949e594 880void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1f590cf9 881{
1f590cf9
LL
882 const char *chardev = qdict_get_str(qdict, "device");
883 const char *data = qdict_get_str(qdict, "data");
e940f543 884 Error *err = NULL;
1f590cf9 885
e940f543 886 qmp_ringbuf_write(chardev, data, false, 0, &err);
1f590cf9 887
e940f543 888 hmp_handle_error(mon, &err);
6d3962bf 889}
e42e818b 890
3949e594 891void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
49b6d722
LL
892{
893 uint32_t size = qdict_get_int(qdict, "size");
894 const char *chardev = qdict_get_str(qdict, "device");
3ab651fc 895 char *data;
e940f543 896 Error *err = NULL;
543f3412 897 int i;
49b6d722 898
e940f543
MA
899 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
900 if (err) {
901 monitor_printf(mon, "%s\n", error_get_pretty(err));
902 error_free(err);
49b6d722
LL
903 return;
904 }
905
543f3412
MA
906 for (i = 0; data[i]; i++) {
907 unsigned char ch = data[i];
908
909 if (ch == '\\') {
910 monitor_printf(mon, "\\\\");
911 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
912 monitor_printf(mon, "\\u%04X", ch);
913 } else {
914 monitor_printf(mon, "%c", ch);
915 }
916
917 }
918 monitor_printf(mon, "\n");
3ab651fc 919 g_free(data);
49b6d722
LL
920}
921
e42e818b
LC
922static void hmp_cont_cb(void *opaque, int err)
923{
e42e818b 924 if (!err) {
8b7f6fbb 925 qmp_cont(NULL);
e42e818b
LC
926 }
927}
928
8b7f6fbb
LC
929static bool key_is_missing(const BlockInfo *bdev)
930{
931 return (bdev->inserted && bdev->inserted->encryption_key_missing);
932}
933
e42e818b
LC
934void hmp_cont(Monitor *mon, const QDict *qdict)
935{
8b7f6fbb 936 BlockInfoList *bdev_list, *bdev;
e940f543 937 Error *err = NULL;
e42e818b 938
8b7f6fbb
LC
939 bdev_list = qmp_query_block(NULL);
940 for (bdev = bdev_list; bdev; bdev = bdev->next) {
941 if (key_is_missing(bdev->value)) {
942 monitor_read_block_device_key(mon, bdev->value->device,
943 hmp_cont_cb, NULL);
944 goto out;
e42e818b 945 }
e42e818b 946 }
8b7f6fbb 947
e940f543
MA
948 qmp_cont(&err);
949 hmp_handle_error(mon, &err);
8b7f6fbb
LC
950
951out:
952 qapi_free_BlockInfoList(bdev_list);
e42e818b 953}
ab49ab5c 954
9b9df25a
GH
955void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
956{
957 qmp_system_wakeup(NULL);
958}
959
3e5a50d6 960void hmp_nmi(Monitor *mon, const QDict *qdict)
ab49ab5c 961{
e940f543 962 Error *err = NULL;
ab49ab5c 963
e940f543
MA
964 qmp_inject_nmi(&err);
965 hmp_handle_error(mon, &err);
ab49ab5c 966}
4b37156c
LC
967
968void hmp_set_link(Monitor *mon, const QDict *qdict)
969{
970 const char *name = qdict_get_str(qdict, "name");
971 int up = qdict_get_bool(qdict, "up");
e940f543 972 Error *err = NULL;
4b37156c 973
e940f543
MA
974 qmp_set_link(name, up, &err);
975 hmp_handle_error(mon, &err);
4b37156c 976}
a4dea8a9
LC
977
978void hmp_block_passwd(Monitor *mon, const QDict *qdict)
979{
980 const char *device = qdict_get_str(qdict, "device");
981 const char *password = qdict_get_str(qdict, "password");
e940f543 982 Error *err = NULL;
a4dea8a9 983
e940f543
MA
984 qmp_block_passwd(true, device, false, NULL, password, &err);
985 hmp_handle_error(mon, &err);
a4dea8a9 986}
d72f3264
LC
987
988void hmp_balloon(Monitor *mon, const QDict *qdict)
989{
990 int64_t value = qdict_get_int(qdict, "value");
e940f543 991 Error *err = NULL;
d72f3264 992
e940f543
MA
993 qmp_balloon(value, &err);
994 if (err) {
995 monitor_printf(mon, "balloon: %s\n", error_get_pretty(err));
996 error_free(err);
d72f3264
LC
997 }
998}
5e7caacb
LC
999
1000void hmp_block_resize(Monitor *mon, const QDict *qdict)
1001{
1002 const char *device = qdict_get_str(qdict, "device");
1003 int64_t size = qdict_get_int(qdict, "size");
e940f543 1004 Error *err = NULL;
5e7caacb 1005
e940f543
MA
1006 qmp_block_resize(true, device, false, NULL, size, &err);
1007 hmp_handle_error(mon, &err);
5e7caacb 1008}
6106e249 1009
d9b902db
PB
1010void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1011{
1012 const char *device = qdict_get_str(qdict, "device");
1013 const char *filename = qdict_get_str(qdict, "target");
1014 const char *format = qdict_get_try_str(qdict, "format");
1015 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
1016 int full = qdict_get_try_bool(qdict, "full", 0);
1017 enum NewImageMode mode;
e940f543 1018 Error *err = NULL;
d9b902db
PB
1019
1020 if (!filename) {
e940f543
MA
1021 error_set(&err, QERR_MISSING_PARAMETER, "target");
1022 hmp_handle_error(mon, &err);
d9b902db
PB
1023 return;
1024 }
1025
1026 if (reuse) {
1027 mode = NEW_IMAGE_MODE_EXISTING;
1028 } else {
1029 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1030 }
1031
1032 qmp_drive_mirror(device, filename, !!format, format,
09158f00 1033 false, NULL, false, NULL,
d9b902db 1034 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
08e4ed6c 1035 true, mode, false, 0, false, 0, false, 0,
e940f543
MA
1036 false, 0, false, 0, &err);
1037 hmp_handle_error(mon, &err);
d9b902db
PB
1038}
1039
de90930a
SH
1040void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1041{
1042 const char *device = qdict_get_str(qdict, "device");
1043 const char *filename = qdict_get_str(qdict, "target");
1044 const char *format = qdict_get_try_str(qdict, "format");
1045 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
1046 int full = qdict_get_try_bool(qdict, "full", 0);
1047 enum NewImageMode mode;
e940f543 1048 Error *err = NULL;
de90930a
SH
1049
1050 if (!filename) {
e940f543
MA
1051 error_set(&err, QERR_MISSING_PARAMETER, "target");
1052 hmp_handle_error(mon, &err);
de90930a
SH
1053 return;
1054 }
1055
1056 if (reuse) {
1057 mode = NEW_IMAGE_MODE_EXISTING;
1058 } else {
1059 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1060 }
1061
1062 qmp_drive_backup(device, filename, !!format, format,
1063 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
e940f543
MA
1064 true, mode, false, 0, false, 0, false, 0, &err);
1065 hmp_handle_error(mon, &err);
de90930a
SH
1066}
1067
6106e249
LC
1068void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1069{
1070 const char *device = qdict_get_str(qdict, "device");
1071 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1072 const char *format = qdict_get_try_str(qdict, "format");
6cc2a415
PB
1073 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
1074 enum NewImageMode mode;
e940f543 1075 Error *err = NULL;
6106e249
LC
1076
1077 if (!filename) {
1078 /* In the future, if 'snapshot-file' is not specified, the snapshot
1079 will be taken internally. Today it's actually required. */
e940f543
MA
1080 error_set(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1081 hmp_handle_error(mon, &err);
6106e249
LC
1082 return;
1083 }
1084
6cc2a415 1085 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
0901f67e
BC
1086 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1087 filename, false, NULL,
1088 !!format, format,
e940f543
MA
1089 true, mode, &err);
1090 hmp_handle_error(mon, &err);
6106e249 1091}
6cdedb07 1092
775ca88e
WX
1093void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1094{
1095 const char *device = qdict_get_str(qdict, "device");
1096 const char *name = qdict_get_str(qdict, "name");
e940f543 1097 Error *err = NULL;
775ca88e 1098
e940f543
MA
1099 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1100 hmp_handle_error(mon, &err);
775ca88e
WX
1101}
1102
7a4ed2ee
WX
1103void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1104{
1105 const char *device = qdict_get_str(qdict, "device");
1106 const char *name = qdict_get_str(qdict, "name");
1107 const char *id = qdict_get_try_str(qdict, "id");
e940f543 1108 Error *err = NULL;
7a4ed2ee
WX
1109
1110 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
e940f543
MA
1111 true, name, &err);
1112 hmp_handle_error(mon, &err);
7a4ed2ee
WX
1113}
1114
6cdedb07
LC
1115void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1116{
1117 qmp_migrate_cancel(NULL);
1118}
4f0a993b 1119
bf1ae1f4
DDAG
1120void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1121{
1122 Error *err = NULL;
1123 const char *uri = qdict_get_str(qdict, "uri");
1124
1125 qmp_migrate_incoming(uri, &err);
1126
1fa57f55 1127 hmp_handle_error(mon, &err);
bf1ae1f4
DDAG
1128}
1129
4f0a993b
LC
1130void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1131{
1132 double value = qdict_get_double(qdict, "value");
1133 qmp_migrate_set_downtime(value, NULL);
1134}
3dc85383 1135
9e1ba4cc
OW
1136void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1137{
1138 int64_t value = qdict_get_int(qdict, "value");
1139 Error *err = NULL;
1140
1141 qmp_migrate_set_cache_size(value, &err);
1142 if (err) {
1143 monitor_printf(mon, "%s\n", error_get_pretty(err));
1144 error_free(err);
1145 return;
1146 }
1147}
1148
3dc85383
LC
1149void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1150{
1151 int64_t value = qdict_get_int(qdict, "value");
1152 qmp_migrate_set_speed(value, NULL);
1153}
fbf796fd 1154
00458433
OW
1155void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1156{
1157 const char *cap = qdict_get_str(qdict, "capability");
1158 bool state = qdict_get_bool(qdict, "state");
1159 Error *err = NULL;
1160 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1161 int i;
1162
1163 for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
1164 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1165 caps->value = g_malloc0(sizeof(*caps->value));
1166 caps->value->capability = i;
1167 caps->value->state = state;
1168 caps->next = NULL;
1169 qmp_migrate_set_capabilities(caps, &err);
1170 break;
1171 }
1172 }
1173
1174 if (i == MIGRATION_CAPABILITY_MAX) {
1175 error_set(&err, QERR_INVALID_PARAMETER, cap);
1176 }
1177
1178 qapi_free_MigrationCapabilityStatusList(caps);
1179
1180 if (err) {
a31ca017 1181 monitor_printf(mon, "migrate_set_capability: %s\n",
00458433
OW
1182 error_get_pretty(err));
1183 error_free(err);
1184 }
1185}
1186
fbf796fd
LC
1187void hmp_set_password(Monitor *mon, const QDict *qdict)
1188{
1189 const char *protocol = qdict_get_str(qdict, "protocol");
1190 const char *password = qdict_get_str(qdict, "password");
1191 const char *connected = qdict_get_try_str(qdict, "connected");
1192 Error *err = NULL;
1193
1194 qmp_set_password(protocol, password, !!connected, connected, &err);
1195 hmp_handle_error(mon, &err);
1196}
9ad5372d
LC
1197
1198void hmp_expire_password(Monitor *mon, const QDict *qdict)
1199{
1200 const char *protocol = qdict_get_str(qdict, "protocol");
1201 const char *whenstr = qdict_get_str(qdict, "time");
1202 Error *err = NULL;
1203
1204 qmp_expire_password(protocol, whenstr, &err);
1205 hmp_handle_error(mon, &err);
1206}
c245b6a3
LC
1207
1208void hmp_eject(Monitor *mon, const QDict *qdict)
1209{
1210 int force = qdict_get_try_bool(qdict, "force", 0);
1211 const char *device = qdict_get_str(qdict, "device");
1212 Error *err = NULL;
1213
1214 qmp_eject(device, true, force, &err);
1215 hmp_handle_error(mon, &err);
1216}
333a96ec 1217
c60bf339
SH
1218static void hmp_change_read_arg(void *opaque, const char *password,
1219 void *readline_opaque)
333a96ec
LC
1220{
1221 qmp_change_vnc_password(password, NULL);
c60bf339 1222 monitor_read_command(opaque, 1);
333a96ec
LC
1223}
1224
333a96ec
LC
1225void hmp_change(Monitor *mon, const QDict *qdict)
1226{
1227 const char *device = qdict_get_str(qdict, "device");
1228 const char *target = qdict_get_str(qdict, "target");
1229 const char *arg = qdict_get_try_str(qdict, "arg");
1230 Error *err = NULL;
1231
1232 if (strcmp(device, "vnc") == 0 &&
1233 (strcmp(target, "passwd") == 0 ||
1234 strcmp(target, "password") == 0)) {
1235 if (!arg) {
1236 monitor_read_password(mon, hmp_change_read_arg, NULL);
1237 return;
1238 }
1239 }
1240
1241 qmp_change(device, target, !!arg, arg, &err);
84d18f06 1242 if (err &&
ab878ddf 1243 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
eef5ad10
LC
1244 error_free(err);
1245 monitor_read_block_device_key(mon, device, NULL, NULL);
333a96ec
LC
1246 return;
1247 }
1248 hmp_handle_error(mon, &err);
1249}
80047da5
LC
1250
1251void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1252{
1253 Error *err = NULL;
1254
1255 qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
1256 qdict_get_int(qdict, "bps"),
1257 qdict_get_int(qdict, "bps_rd"),
1258 qdict_get_int(qdict, "bps_wr"),
1259 qdict_get_int(qdict, "iops"),
1260 qdict_get_int(qdict, "iops_rd"),
3e9fab69
BC
1261 qdict_get_int(qdict, "iops_wr"),
1262 false, /* no burst max via HMP */
1263 0,
1264 false,
1265 0,
1266 false,
1267 0,
1268 false,
1269 0,
1270 false,
1271 0,
1272 false,
2024c1df
BC
1273 0,
1274 false, /* No default I/O size */
3e9fab69 1275 0, &err);
80047da5
LC
1276 hmp_handle_error(mon, &err);
1277}
12bd451f
SH
1278
1279void hmp_block_stream(Monitor *mon, const QDict *qdict)
1280{
1281 Error *error = NULL;
1282 const char *device = qdict_get_str(qdict, "device");
1283 const char *base = qdict_get_try_str(qdict, "base");
c83c66c3 1284 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
12bd451f 1285
13d8cc51 1286 qmp_block_stream(device, base != NULL, base, false, NULL,
1d809098 1287 qdict_haskey(qdict, "speed"), speed,
46663e5e 1288 true, BLOCKDEV_ON_ERROR_REPORT, &error);
12bd451f
SH
1289
1290 hmp_handle_error(mon, &error);
1291}
2d47c6e9
SH
1292
1293void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1294{
1295 Error *error = NULL;
1296 const char *device = qdict_get_str(qdict, "device");
c6db2395 1297 int64_t value = qdict_get_int(qdict, "speed");
2d47c6e9
SH
1298
1299 qmp_block_job_set_speed(device, value, &error);
1300
1301 hmp_handle_error(mon, &error);
1302}
370521a1
SH
1303
1304void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1305{
1306 Error *error = NULL;
1307 const char *device = qdict_get_str(qdict, "device");
6e37fb81 1308 bool force = qdict_get_try_bool(qdict, "force", 0);
370521a1 1309
6e37fb81
PB
1310 qmp_block_job_cancel(device, true, force, &error);
1311
1312 hmp_handle_error(mon, &error);
1313}
1314
1315void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1316{
1317 Error *error = NULL;
1318 const char *device = qdict_get_str(qdict, "device");
1319
1320 qmp_block_job_pause(device, &error);
1321
1322 hmp_handle_error(mon, &error);
1323}
1324
1325void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1326{
1327 Error *error = NULL;
1328 const char *device = qdict_get_str(qdict, "device");
1329
1330 qmp_block_job_resume(device, &error);
370521a1
SH
1331
1332 hmp_handle_error(mon, &error);
1333}
e1c37d0e 1334
aeae883b
PB
1335void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1336{
1337 Error *error = NULL;
1338 const char *device = qdict_get_str(qdict, "device");
1339
1340 qmp_block_job_complete(device, &error);
1341
1342 hmp_handle_error(mon, &error);
1343}
1344
e49f35bd 1345typedef struct HMPMigrationStatus
e1c37d0e
LC
1346{
1347 QEMUTimer *timer;
1348 Monitor *mon;
1349 bool is_block_migration;
e49f35bd 1350} HMPMigrationStatus;
e1c37d0e
LC
1351
1352static void hmp_migrate_status_cb(void *opaque)
1353{
e49f35bd 1354 HMPMigrationStatus *status = opaque;
e1c37d0e
LC
1355 MigrationInfo *info;
1356
1357 info = qmp_query_migrate(NULL);
24b8c39b
HZ
1358 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1359 info->status == MIGRATION_STATUS_SETUP) {
e1c37d0e
LC
1360 if (info->has_disk) {
1361 int progress;
1362
1363 if (info->disk->remaining) {
1364 progress = info->disk->transferred * 100 / info->disk->total;
1365 } else {
1366 progress = 100;
1367 }
1368
1369 monitor_printf(status->mon, "Completed %d %%\r", progress);
1370 monitor_flush(status->mon);
1371 }
1372
bc72ad67 1373 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
e1c37d0e
LC
1374 } else {
1375 if (status->is_block_migration) {
1376 monitor_printf(status->mon, "\n");
1377 }
1378 monitor_resume(status->mon);
bc72ad67 1379 timer_del(status->timer);
e1c37d0e
LC
1380 g_free(status);
1381 }
1382
1383 qapi_free_MigrationInfo(info);
1384}
1385
1386void hmp_migrate(Monitor *mon, const QDict *qdict)
1387{
1388 int detach = qdict_get_try_bool(qdict, "detach", 0);
1389 int blk = qdict_get_try_bool(qdict, "blk", 0);
1390 int inc = qdict_get_try_bool(qdict, "inc", 0);
1391 const char *uri = qdict_get_str(qdict, "uri");
1392 Error *err = NULL;
1393
1394 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1395 if (err) {
1396 monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
1397 error_free(err);
1398 return;
1399 }
1400
1401 if (!detach) {
e49f35bd 1402 HMPMigrationStatus *status;
e1c37d0e
LC
1403
1404 if (monitor_suspend(mon) < 0) {
1405 monitor_printf(mon, "terminal does not allow synchronous "
1406 "migration, continuing detached\n");
1407 return;
1408 }
1409
1410 status = g_malloc0(sizeof(*status));
1411 status->mon = mon;
1412 status->is_block_migration = blk || inc;
bc72ad67 1413 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
e1c37d0e 1414 status);
bc72ad67 1415 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
e1c37d0e
LC
1416 }
1417}
a15fef21
LC
1418
1419void hmp_device_del(Monitor *mon, const QDict *qdict)
1420{
1421 const char *id = qdict_get_str(qdict, "id");
1422 Error *err = NULL;
1423
1424 qmp_device_del(id, &err);
1425 hmp_handle_error(mon, &err);
1426}
783e9b48
WC
1427
1428void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1429{
e940f543 1430 Error *err = NULL;
783e9b48 1431 int paging = qdict_get_try_bool(qdict, "paging", 0);
1b7a0f75
QN
1432 int zlib = qdict_get_try_bool(qdict, "zlib", 0);
1433 int lzo = qdict_get_try_bool(qdict, "lzo", 0);
1434 int snappy = qdict_get_try_bool(qdict, "snappy", 0);
75363769 1435 const char *file = qdict_get_str(qdict, "filename");
783e9b48
WC
1436 bool has_begin = qdict_haskey(qdict, "begin");
1437 bool has_length = qdict_haskey(qdict, "length");
1438 int64_t begin = 0;
1439 int64_t length = 0;
b53ccc30 1440 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
75363769 1441 char *prot;
783e9b48 1442
1b7a0f75 1443 if (zlib + lzo + snappy > 1) {
e940f543
MA
1444 error_setg(&err, "only one of '-z|-l|-s' can be set");
1445 hmp_handle_error(mon, &err);
1b7a0f75
QN
1446 return;
1447 }
1448
1449 if (zlib) {
1450 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1451 }
1452
1453 if (lzo) {
1454 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1455 }
1456
1457 if (snappy) {
1458 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1459 }
1460
783e9b48
WC
1461 if (has_begin) {
1462 begin = qdict_get_int(qdict, "begin");
1463 }
1464 if (has_length) {
1465 length = qdict_get_int(qdict, "length");
1466 }
1467
75363769
LC
1468 prot = g_strconcat("file:", file, NULL);
1469
1470 qmp_dump_guest_memory(paging, prot, has_begin, begin, has_length, length,
e940f543
MA
1471 true, dump_format, &err);
1472 hmp_handle_error(mon, &err);
75363769 1473 g_free(prot);
783e9b48 1474}
928059a3
LC
1475
1476void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1477{
1478 Error *err = NULL;
1479 QemuOpts *opts;
1480
1481 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
84d18f06 1482 if (err) {
928059a3
LC
1483 goto out;
1484 }
1485
1486 netdev_add(opts, &err);
84d18f06 1487 if (err) {
928059a3
LC
1488 qemu_opts_del(opts);
1489 }
1490
1491out:
1492 hmp_handle_error(mon, &err);
1493}
5f964155
LC
1494
1495void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1496{
1497 const char *id = qdict_get_str(qdict, "id");
1498 Error *err = NULL;
1499
1500 qmp_netdev_del(id, &err);
1501 hmp_handle_error(mon, &err);
1502}
208c9d1b 1503
cff8b2c6
PB
1504void hmp_object_add(Monitor *mon, const QDict *qdict)
1505{
1506 Error *err = NULL;
f9f3a5ec 1507 Error *err_end = NULL;
cff8b2c6
PB
1508 QemuOpts *opts;
1509 char *type = NULL;
1510 char *id = NULL;
1511 void *dummy = NULL;
1512 OptsVisitor *ov;
1513 QDict *pdict;
1514
1515 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1516 if (err) {
1517 goto out;
1518 }
1519
1520 ov = opts_visitor_new(opts);
1521 pdict = qdict_clone_shallow(qdict);
1522
1523 visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err);
1524 if (err) {
1525 goto out_clean;
1526 }
1527
1528 qdict_del(pdict, "qom-type");
1529 visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
1530 if (err) {
f9f3a5ec 1531 goto out_end;
cff8b2c6
PB
1532 }
1533
1534 qdict_del(pdict, "id");
1535 visit_type_str(opts_get_visitor(ov), &id, "id", &err);
1536 if (err) {
f9f3a5ec 1537 goto out_end;
cff8b2c6
PB
1538 }
1539
1540 object_add(type, id, pdict, opts_get_visitor(ov), &err);
f9f3a5ec
MA
1541
1542out_end:
1543 visit_end_struct(opts_get_visitor(ov), &err_end);
1544 if (!err && err_end) {
cff8b2c6
PB
1545 qmp_object_del(id, NULL);
1546 }
f9f3a5ec 1547 error_propagate(&err, err_end);
cff8b2c6
PB
1548out_clean:
1549 opts_visitor_cleanup(ov);
1550
1551 QDECREF(pdict);
1552 qemu_opts_del(opts);
1553 g_free(id);
1554 g_free(type);
1555 g_free(dummy);
1556
1557out:
1558 hmp_handle_error(mon, &err);
1559}
1560
208c9d1b
CB
1561void hmp_getfd(Monitor *mon, const QDict *qdict)
1562{
1563 const char *fdname = qdict_get_str(qdict, "fdname");
e940f543 1564 Error *err = NULL;
208c9d1b 1565
e940f543
MA
1566 qmp_getfd(fdname, &err);
1567 hmp_handle_error(mon, &err);
208c9d1b
CB
1568}
1569
1570void hmp_closefd(Monitor *mon, const QDict *qdict)
1571{
1572 const char *fdname = qdict_get_str(qdict, "fdname");
e940f543 1573 Error *err = NULL;
208c9d1b 1574
e940f543
MA
1575 qmp_closefd(fdname, &err);
1576 hmp_handle_error(mon, &err);
208c9d1b 1577}
e4c8f004 1578
3e5a50d6 1579void hmp_sendkey(Monitor *mon, const QDict *qdict)
e4c8f004
AK
1580{
1581 const char *keys = qdict_get_str(qdict, "keys");
9f328977 1582 KeyValueList *keylist, *head = NULL, *tmp = NULL;
e4c8f004
AK
1583 int has_hold_time = qdict_haskey(qdict, "hold-time");
1584 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1585 Error *err = NULL;
1586 char keyname_buf[16];
1587 char *separator;
9f328977 1588 int keyname_len;
e4c8f004
AK
1589
1590 while (1) {
1591 separator = strchr(keys, '-');
1592 keyname_len = separator ? separator - keys : strlen(keys);
1593 pstrcpy(keyname_buf, sizeof(keyname_buf), keys);
1594
1595 /* Be compatible with old interface, convert user inputted "<" */
1596 if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) {
1597 pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
1598 keyname_len = 4;
1599 }
1600 keyname_buf[keyname_len] = 0;
1601
e4c8f004 1602 keylist = g_malloc0(sizeof(*keylist));
9f328977 1603 keylist->value = g_malloc0(sizeof(*keylist->value));
e4c8f004
AK
1604
1605 if (!head) {
1606 head = keylist;
1607 }
1608 if (tmp) {
1609 tmp->next = keylist;
1610 }
1611 tmp = keylist;
1612
9f328977
LC
1613 if (strstart(keyname_buf, "0x", NULL)) {
1614 char *endp;
1615 int value = strtoul(keyname_buf, &endp, 0);
1616 if (*endp != '\0') {
1617 goto err_out;
1618 }
1619 keylist->value->kind = KEY_VALUE_KIND_NUMBER;
1620 keylist->value->number = value;
1621 } else {
1622 int idx = index_from_key(keyname_buf);
1623 if (idx == Q_KEY_CODE_MAX) {
1624 goto err_out;
1625 }
1626 keylist->value->kind = KEY_VALUE_KIND_QCODE;
1627 keylist->value->qcode = idx;
1628 }
1629
e4c8f004
AK
1630 if (!separator) {
1631 break;
1632 }
1633 keys = separator + 1;
1634 }
1635
9f328977 1636 qmp_send_key(head, has_hold_time, hold_time, &err);
e4c8f004 1637 hmp_handle_error(mon, &err);
9f328977
LC
1638
1639out:
1640 qapi_free_KeyValueList(head);
1641 return;
1642
1643err_out:
1644 monitor_printf(mon, "invalid parameter: %s\n", keyname_buf);
1645 goto out;
e4c8f004 1646}
ad39cf6d 1647
3e5a50d6 1648void hmp_screendump(Monitor *mon, const QDict *qdict)
ad39cf6d
LC
1649{
1650 const char *filename = qdict_get_str(qdict, "filename");
1651 Error *err = NULL;
1652
1653 qmp_screendump(filename, &err);
1654 hmp_handle_error(mon, &err);
1655}
4057725f
PB
1656
1657void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1658{
1659 const char *uri = qdict_get_str(qdict, "uri");
1660 int writable = qdict_get_try_bool(qdict, "writable", 0);
1661 int all = qdict_get_try_bool(qdict, "all", 0);
1662 Error *local_err = NULL;
1663 BlockInfoList *block_list, *info;
1664 SocketAddress *addr;
1665
1666 if (writable && !all) {
1667 error_setg(&local_err, "-w only valid together with -a");
1668 goto exit;
1669 }
1670
1671 /* First check if the address is valid and start the server. */
1672 addr = socket_parse(uri, &local_err);
1673 if (local_err != NULL) {
1674 goto exit;
1675 }
1676
1677 qmp_nbd_server_start(addr, &local_err);
1678 qapi_free_SocketAddress(addr);
1679 if (local_err != NULL) {
1680 goto exit;
1681 }
1682
1683 if (!all) {
1684 return;
1685 }
1686
1687 /* Then try adding all block devices. If one fails, close all and
1688 * exit.
1689 */
1690 block_list = qmp_query_block(NULL);
1691
1692 for (info = block_list; info; info = info->next) {
1693 if (!info->value->has_inserted) {
1694 continue;
1695 }
1696
1697 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1698
1699 if (local_err != NULL) {
1700 qmp_nbd_server_stop(NULL);
1701 break;
1702 }
1703 }
1704
1705 qapi_free_BlockInfoList(block_list);
1706
1707exit:
1708 hmp_handle_error(mon, &local_err);
1709}
1710
1711void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1712{
1713 const char *device = qdict_get_str(qdict, "device");
1714 int writable = qdict_get_try_bool(qdict, "writable", 0);
1715 Error *local_err = NULL;
1716
1717 qmp_nbd_server_add(device, true, writable, &local_err);
1718
1719 if (local_err != NULL) {
1720 hmp_handle_error(mon, &local_err);
1721 }
1722}
1723
1724void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1725{
e940f543 1726 Error *err = NULL;
4057725f 1727
e940f543
MA
1728 qmp_nbd_server_stop(&err);
1729 hmp_handle_error(mon, &err);
4057725f 1730}
f1088908 1731
abf23329
JH
1732void hmp_cpu_add(Monitor *mon, const QDict *qdict)
1733{
1734 int cpuid;
1735 Error *err = NULL;
1736
1737 cpuid = qdict_get_int(qdict, "id");
1738 qmp_cpu_add(cpuid, &err);
1739 hmp_handle_error(mon, &err);
1740}
1741
f1088908
GH
1742void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1743{
1744 const char *args = qdict_get_str(qdict, "args");
1745 Error *err = NULL;
1746 QemuOpts *opts;
1747
1748 opts = qemu_opts_parse(qemu_find_opts("chardev"), args, 1);
1749 if (opts == NULL) {
312fd5f2 1750 error_setg(&err, "Parsing chardev args failed");
f1088908
GH
1751 } else {
1752 qemu_chr_new_from_opts(opts, NULL, &err);
1753 }
1754 hmp_handle_error(mon, &err);
1755}
1756
1757void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1758{
1759 Error *local_err = NULL;
1760
1761 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1762 hmp_handle_error(mon, &local_err);
1763}
587da2c3
KW
1764
1765void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1766{
4c7b7e9b 1767 BlockBackend *blk;
587da2c3
KW
1768 const char* device = qdict_get_str(qdict, "device");
1769 const char* command = qdict_get_str(qdict, "command");
1770 Error *err = NULL;
1771
4c7b7e9b
HR
1772 blk = blk_by_name(device);
1773 if (blk) {
1774 qemuio_command(blk, command);
587da2c3
KW
1775 } else {
1776 error_set(&err, QERR_DEVICE_NOT_FOUND, device);
1777 }
1778
1779 hmp_handle_error(mon, &err);
1780}
ab2d0531
PB
1781
1782void hmp_object_del(Monitor *mon, const QDict *qdict)
1783{
1784 const char *id = qdict_get_str(qdict, "id");
1785 Error *err = NULL;
1786
1787 qmp_object_del(id, &err);
1788 hmp_handle_error(mon, &err);
1789}
eb1539b2
HT
1790
1791void hmp_info_memdev(Monitor *mon, const QDict *qdict)
1792{
1793 Error *err = NULL;
1794 MemdevList *memdev_list = qmp_query_memdev(&err);
1795 MemdevList *m = memdev_list;
1796 StringOutputVisitor *ov;
976620ac 1797 char *str;
eb1539b2
HT
1798 int i = 0;
1799
1800
1801 while (m) {
1802 ov = string_output_visitor_new(false);
1803 visit_type_uint16List(string_output_get_visitor(ov),
1804 &m->value->host_nodes, NULL, NULL);
8f4e5ac3 1805 monitor_printf(mon, "memory backend: %d\n", i);
eb1539b2
HT
1806 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
1807 monitor_printf(mon, " merge: %s\n",
1808 m->value->merge ? "true" : "false");
1809 monitor_printf(mon, " dump: %s\n",
1810 m->value->dump ? "true" : "false");
1811 monitor_printf(mon, " prealloc: %s\n",
1812 m->value->prealloc ? "true" : "false");
1813 monitor_printf(mon, " policy: %s\n",
1814 HostMemPolicy_lookup[m->value->policy]);
976620ac
CF
1815 str = string_output_get_string(ov);
1816 monitor_printf(mon, " host nodes: %s\n", str);
eb1539b2 1817
976620ac 1818 g_free(str);
eb1539b2
HT
1819 string_output_visitor_cleanup(ov);
1820 m = m->next;
1821 i++;
1822 }
1823
1824 monitor_printf(mon, "\n");
ecaf54a0
CF
1825
1826 qapi_free_MemdevList(memdev_list);
eb1539b2 1827}
a631892f
ZG
1828
1829void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
1830{
1831 Error *err = NULL;
1832 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
1833 MemoryDeviceInfoList *info;
1834 MemoryDeviceInfo *value;
1835 PCDIMMDeviceInfo *di;
1836
1837 for (info = info_list; info; info = info->next) {
1838 value = info->value;
1839
1840 if (value) {
1841 switch (value->kind) {
1842 case MEMORY_DEVICE_INFO_KIND_DIMM:
1843 di = value->dimm;
1844
1845 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1846 MemoryDeviceInfoKind_lookup[value->kind],
1847 di->id ? di->id : "");
1848 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
1849 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
1850 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
1851 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
1852 monitor_printf(mon, " memdev: %s\n", di->memdev);
1853 monitor_printf(mon, " hotplugged: %s\n",
1854 di->hotplugged ? "true" : "false");
1855 monitor_printf(mon, " hotpluggable: %s\n",
1856 di->hotpluggable ? "true" : "false");
1857 break;
1858 default:
1859 break;
1860 }
1861 }
1862 }
1863
1864 qapi_free_MemoryDeviceInfoList(info_list);
1865}
89d7fa9e
AF
1866
1867void hmp_qom_list(Monitor *mon, const QDict *qdict)
1868{
1869 const char *path = qdict_get_try_str(qdict, "path");
1870 ObjectPropertyInfoList *list;
1871 Error *err = NULL;
1872
1873 if (path == NULL) {
1874 monitor_printf(mon, "/\n");
1875 return;
1876 }
1877
1878 list = qmp_qom_list(path, &err);
1879 if (err == NULL) {
1880 ObjectPropertyInfoList *start = list;
1881 while (list != NULL) {
1882 ObjectPropertyInfo *value = list->value;
1883
1884 monitor_printf(mon, "%s (%s)\n",
1885 value->name, value->type);
1886 list = list->next;
1887 }
1888 qapi_free_ObjectPropertyInfoList(start);
1889 }
1890 hmp_handle_error(mon, &err);
1891}
c0e6ee9e
AF
1892
1893void hmp_qom_set(Monitor *mon, const QDict *qdict)
1894{
1895 const char *path = qdict_get_str(qdict, "path");
1896 const char *property = qdict_get_str(qdict, "property");
1897 const char *value = qdict_get_str(qdict, "value");
1898 Error *err = NULL;
1899 bool ambiguous = false;
1900 Object *obj;
1901
1902 obj = object_resolve_path(path, &ambiguous);
1903 if (obj == NULL) {
1904 error_set(&err, QERR_DEVICE_NOT_FOUND, path);
1905 } else {
1906 if (ambiguous) {
1907 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
1908 }
1909 object_property_parse(obj, value, property, &err);
1910 }
1911 hmp_handle_error(mon, &err);
1912}