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