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