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