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