]> git.proxmox.com Git - mirror_qemu.git/blob - hmp.c
migration: add reporting of errors for outgoing migration
[mirror_qemu.git] / hmp.c
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 *
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.
14 */
15
16 #include "qemu/osdep.h"
17 #include "hmp.h"
18 #include "net/net.h"
19 #include "net/eth.h"
20 #include "sysemu/char.h"
21 #include "sysemu/block-backend.h"
22 #include "qemu/option.h"
23 #include "qemu/timer.h"
24 #include "qmp-commands.h"
25 #include "qemu/sockets.h"
26 #include "monitor/monitor.h"
27 #include "monitor/qdev.h"
28 #include "qapi/opts-visitor.h"
29 #include "qapi/qmp/qerror.h"
30 #include "qapi/string-output-visitor.h"
31 #include "qapi/util.h"
32 #include "qapi-visit.h"
33 #include "qom/object_interfaces.h"
34 #include "ui/console.h"
35 #include "block/qapi.h"
36 #include "qemu-io.h"
37 #include "qemu/cutils.h"
38 #include "qemu/error-report.h"
39
40 #ifdef CONFIG_SPICE
41 #include <spice/enums.h>
42 #endif
43
44 static void hmp_handle_error(Monitor *mon, Error **errp)
45 {
46 assert(errp);
47 if (*errp) {
48 error_report_err(*errp);
49 }
50 }
51
52 void hmp_info_name(Monitor *mon, const QDict *qdict)
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 }
62
63 void hmp_info_version(Monitor *mon, const QDict *qdict)
64 {
65 VersionInfo *info;
66
67 info = qmp_query_version(NULL);
68
69 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
70 info->qemu->major, info->qemu->minor, info->qemu->micro,
71 info->package);
72
73 qapi_free_VersionInfo(info);
74 }
75
76 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
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
91 void hmp_info_status(Monitor *mon, const QDict *qdict)
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
110 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
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 }
118
119 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
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 }
131
132 void hmp_info_mice(Monitor *mon, const QDict *qdict)
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
152 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
153 {
154 MigrationInfo *info;
155 MigrationCapabilityStatusList *caps, *cap;
156
157 info = qmp_query_migrate(NULL);
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 }
170
171 if (info->has_status) {
172 monitor_printf(mon, "Migration status: %s",
173 MigrationStatus_lookup[info->status]);
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
181 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
182 info->total_time);
183 if (info->has_expected_downtime) {
184 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
185 info->expected_downtime);
186 }
187 if (info->has_downtime) {
188 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
189 info->downtime);
190 }
191 if (info->has_setup_time) {
192 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
193 info->setup_time);
194 }
195 }
196
197 if (info->has_ram) {
198 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
199 info->ram->transferred >> 10);
200 monitor_printf(mon, "throughput: %0.2f mbps\n",
201 info->ram->mbps);
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);
206 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
207 info->ram->duplicate);
208 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
209 info->ram->skipped);
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);
214 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
215 info->ram->dirty_sync_count);
216 if (info->ram->dirty_pages_rate) {
217 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
218 info->ram->dirty_pages_rate);
219 }
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
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);
240 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
241 info->xbzrle_cache->cache_miss_rate);
242 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
243 info->xbzrle_cache->overflow);
244 }
245
246 if (info->has_cpu_throttle_percentage) {
247 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
248 info->cpu_throttle_percentage);
249 }
250
251 qapi_free_MigrationInfo(info);
252 qapi_free_MigrationCapabilityStatusList(caps);
253 }
254
255 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
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);
272 }
273
274 void 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);
291 monitor_printf(mon, " %s: %" PRId64,
292 MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL],
293 params->cpu_throttle_initial);
294 monitor_printf(mon, " %s: %" PRId64,
295 MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT],
296 params->cpu_throttle_increment);
297 monitor_printf(mon, "\n");
298 }
299
300 qapi_free_MigrationParameters(params);
301 }
302
303 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
304 {
305 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
306 qmp_query_migrate_cache_size(NULL) >> 10);
307 }
308
309 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
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
322 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
323
324 switch (cpu->value->arch) {
325 case CPU_INFO_ARCH_X86:
326 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->u.x86.pc);
327 break;
328 case CPU_INFO_ARCH_PPC:
329 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->u.ppc.nip);
330 break;
331 case CPU_INFO_ARCH_SPARC:
332 monitor_printf(mon, " pc=0x%016" PRIx64,
333 cpu->value->u.q_sparc.pc);
334 monitor_printf(mon, " npc=0x%016" PRIx64,
335 cpu->value->u.q_sparc.npc);
336 break;
337 case CPU_INFO_ARCH_MIPS:
338 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.q_mips.PC);
339 break;
340 case CPU_INFO_ARCH_TRICORE:
341 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.tricore.PC);
342 break;
343 default:
344 break;
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
357 static void print_block_info(Monitor *mon, BlockInfo *info,
358 BlockDeviceInfo *inserted, bool verbose)
359 {
360 ImageInfo *image_info;
361
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
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 }
386
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 }
392
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 }
398 }
399
400
401 if (!inserted) {
402 return;
403 }
404
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 }
417
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 }
422
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
436 " iops_size=%" PRId64
437 " group=%s\n",
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,
450 inserted->iops_size,
451 inserted->group);
452 }
453
454 if (verbose) {
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 }
468
469 void hmp_info_block(Monitor *mon, const QDict *qdict)
470 {
471 BlockInfoList *block_list, *info;
472 BlockDeviceInfoList *blockdev_list, *blockdev;
473 const char *device = qdict_get_try_str(qdict, "device");
474 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
475 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
476 bool printed = false;
477
478 /* Print BlockBackend information */
479 if (!nodes) {
480 block_list = qmp_query_block(NULL);
481 } else {
482 block_list = NULL;
483 }
484
485 for (info = block_list; info; info = info->next) {
486 if (device && strcmp(device, info->value->device)) {
487 continue;
488 }
489
490 if (info != block_list) {
491 monitor_printf(mon, "\n");
492 }
493
494 print_block_info(mon, info->value, info->value->has_inserted
495 ? info->value->inserted : NULL,
496 verbose);
497 printed = true;
498 }
499
500 qapi_free_BlockInfoList(block_list);
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);
521 }
522
523 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
524 {
525 BlockStatsList *stats_list, *stats;
526
527 stats_list = qmp_query_blockstats(false, false, NULL);
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
543 " rd_merged=%" PRId64
544 " wr_merged=%" PRId64
545 " idle_time_ns=%" PRId64
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,
554 stats->value->stats->flush_total_time_ns,
555 stats->value->stats->rd_merged,
556 stats->value->stats->wr_merged,
557 stats->value->stats->idle_time_ns);
558 }
559
560 qapi_free_BlockStatsList(stats_list);
561 }
562
563 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
564 {
565 VncInfo *info;
566 Error *err = NULL;
567 VncClientInfoList *client;
568
569 info = qmp_query_vnc(&err);
570 if (err) {
571 error_report_err(err);
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",
594 client->value->host,
595 client->value->service);
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
605 out:
606 qapi_free_VncInfo(info);
607 }
608
609 #ifdef CONFIG_SPICE
610 void hmp_info_spice(Monitor *mon, const QDict *qdict)
611 {
612 SpiceChannelList *chan;
613 SpiceInfo *info;
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",
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. */
630 [SPICE_CHANNEL_WEBDAV] = "webdav",
631 #endif
632 };
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 }
650 monitor_printf(mon, " migrated: %s\n",
651 info->migrated ? "true" : "false");
652 monitor_printf(mon, " auth: %s\n", info->auth);
653 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
654 monitor_printf(mon, " mouse-mode: %s\n",
655 SpiceQueryMouseMode_lookup[info->mouse_mode]);
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",
663 chan->value->host, chan->value->port,
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);
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);
678 }
679 }
680
681 out:
682 qapi_free_SpiceInfo(info);
683 }
684 #endif
685
686 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
687 {
688 BalloonInfo *info;
689 Error *err = NULL;
690
691 info = qmp_query_balloon(&err);
692 if (err) {
693 error_report_err(err);
694 return;
695 }
696
697 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
698
699 qapi_free_BalloonInfo(info);
700 }
701
702 static 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
711 if (dev->class_info->has_desc) {
712 monitor_printf(mon, "%s", dev->class_info->desc);
713 } else {
714 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
715 }
716
717 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
718 dev->id->vendor, dev->id->device);
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",
726 dev->pci_bridge->bus->number);
727 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
728 dev->pci_bridge->bus->secondary);
729 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
730 dev->pci_bridge->bus->subordinate);
731
732 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
733 dev->pci_bridge->bus->io_range->base,
734 dev->pci_bridge->bus->io_range->limit);
735
736 monitor_printf(mon,
737 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
738 dev->pci_bridge->bus->memory_range->base,
739 dev->pci_bridge->bus->memory_range->limit);
740
741 monitor_printf(mon, " prefetchable memory range "
742 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
743 dev->pci_bridge->bus->prefetchable_range->base,
744 dev->pci_bridge->bus->prefetchable_range->limit);
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
780 void hmp_info_pci(Monitor *mon, const QDict *qdict)
781 {
782 PciInfoList *info_list, *info;
783 Error *err = NULL;
784
785 info_list = qmp_query_pci(&err);
786 if (err) {
787 monitor_printf(mon, "PCI devices not supported\n");
788 error_free(err);
789 return;
790 }
791
792 for (info = info_list; info; info = info->next) {
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
800 qapi_free_PciInfoList(info_list);
801 }
802
803 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
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 }
837
838 qapi_free_BlockJobInfoList(list);
839 }
840
841 void 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",
865 ti->id, TpmTypeOptionsKind_lookup[ti->options->type]);
866
867 switch (ti->options->type) {
868 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
869 tpo = ti->options->u.passthrough.data;
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;
876 case TPM_TYPE_OPTIONS_KIND__MAX:
877 break;
878 }
879 monitor_printf(mon, "\n");
880 c++;
881 }
882 qapi_free_TPMInfoList(info_list);
883 }
884
885 void hmp_quit(Monitor *mon, const QDict *qdict)
886 {
887 monitor_suspend(mon);
888 qmp_quit(NULL);
889 }
890
891 void hmp_stop(Monitor *mon, const QDict *qdict)
892 {
893 qmp_stop(NULL);
894 }
895
896 void hmp_system_reset(Monitor *mon, const QDict *qdict)
897 {
898 qmp_system_reset(NULL);
899 }
900
901 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
902 {
903 qmp_system_powerdown(NULL);
904 }
905
906 void 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 }
917
918 void 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");
923 Error *err = NULL;
924
925 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &err);
926 hmp_handle_error(mon, &err);
927 }
928
929 void 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");
934 Error *err = NULL;
935
936 qmp_pmemsave(addr, size, filename, &err);
937 hmp_handle_error(mon, &err);
938 }
939
940 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
941 {
942 const char *chardev = qdict_get_str(qdict, "device");
943 const char *data = qdict_get_str(qdict, "data");
944 Error *err = NULL;
945
946 qmp_ringbuf_write(chardev, data, false, 0, &err);
947
948 hmp_handle_error(mon, &err);
949 }
950
951 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
952 {
953 uint32_t size = qdict_get_int(qdict, "size");
954 const char *chardev = qdict_get_str(qdict, "device");
955 char *data;
956 Error *err = NULL;
957 int i;
958
959 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
960 if (err) {
961 error_report_err(err);
962 return;
963 }
964
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");
978 g_free(data);
979 }
980
981 static void hmp_cont_cb(void *opaque, int err)
982 {
983 if (!err) {
984 qmp_cont(NULL);
985 }
986 }
987
988 static bool key_is_missing(const BlockInfo *bdev)
989 {
990 return (bdev->inserted && bdev->inserted->encryption_key_missing);
991 }
992
993 void hmp_cont(Monitor *mon, const QDict *qdict)
994 {
995 BlockInfoList *bdev_list, *bdev;
996 Error *err = NULL;
997
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;
1004 }
1005 }
1006
1007 qmp_cont(&err);
1008 hmp_handle_error(mon, &err);
1009
1010 out:
1011 qapi_free_BlockInfoList(bdev_list);
1012 }
1013
1014 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1015 {
1016 qmp_system_wakeup(NULL);
1017 }
1018
1019 void hmp_nmi(Monitor *mon, const QDict *qdict)
1020 {
1021 Error *err = NULL;
1022
1023 qmp_inject_nmi(&err);
1024 hmp_handle_error(mon, &err);
1025 }
1026
1027 void hmp_set_link(Monitor *mon, const QDict *qdict)
1028 {
1029 const char *name = qdict_get_str(qdict, "name");
1030 bool up = qdict_get_bool(qdict, "up");
1031 Error *err = NULL;
1032
1033 qmp_set_link(name, up, &err);
1034 hmp_handle_error(mon, &err);
1035 }
1036
1037 void 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");
1041 Error *err = NULL;
1042
1043 qmp_block_passwd(true, device, false, NULL, password, &err);
1044 hmp_handle_error(mon, &err);
1045 }
1046
1047 void hmp_balloon(Monitor *mon, const QDict *qdict)
1048 {
1049 int64_t value = qdict_get_int(qdict, "value");
1050 Error *err = NULL;
1051
1052 qmp_balloon(value, &err);
1053 if (err) {
1054 error_report_err(err);
1055 }
1056 }
1057
1058 void 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");
1062 Error *err = NULL;
1063
1064 qmp_block_resize(true, device, false, NULL, size, &err);
1065 hmp_handle_error(mon, &err);
1066 }
1067
1068 void 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");
1073 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1074 bool full = qdict_get_try_bool(qdict, "full", false);
1075 enum NewImageMode mode;
1076 Error *err = NULL;
1077
1078 if (!filename) {
1079 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1080 hmp_handle_error(mon, &err);
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,
1091 false, NULL, false, NULL,
1092 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1093 true, mode, false, 0, false, 0, false, 0,
1094 false, 0, false, 0, false, true, &err);
1095 hmp_handle_error(mon, &err);
1096 }
1097
1098 void 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");
1103 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1104 bool full = qdict_get_try_bool(qdict, "full", false);
1105 enum NewImageMode mode;
1106 Error *err = NULL;
1107
1108 if (!filename) {
1109 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1110 hmp_handle_error(mon, &err);
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,
1122 true, mode, false, 0, false, NULL,
1123 false, 0, false, 0, &err);
1124 hmp_handle_error(mon, &err);
1125 }
1126
1127 void 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");
1132 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1133 enum NewImageMode mode;
1134 Error *err = NULL;
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. */
1139 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1140 hmp_handle_error(mon, &err);
1141 return;
1142 }
1143
1144 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1145 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1146 filename, false, NULL,
1147 !!format, format,
1148 true, mode, &err);
1149 hmp_handle_error(mon, &err);
1150 }
1151
1152 void 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");
1156 Error *err = NULL;
1157
1158 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1159 hmp_handle_error(mon, &err);
1160 }
1161
1162 void 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");
1167 Error *err = NULL;
1168
1169 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1170 true, name, &err);
1171 hmp_handle_error(mon, &err);
1172 }
1173
1174 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1175 {
1176 qmp_migrate_cancel(NULL);
1177 }
1178
1179 void 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
1186 hmp_handle_error(mon, &err);
1187 }
1188
1189 void 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 }
1194
1195 void 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) {
1202 error_report_err(err);
1203 return;
1204 }
1205 }
1206
1207 void 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 }
1212
1213 void 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
1221 for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
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
1232 if (i == MIGRATION_CAPABILITY__MAX) {
1233 error_setg(&err, QERR_INVALID_PARAMETER, cap);
1234 }
1235
1236 qapi_free_MigrationCapabilityStatusList(caps);
1237
1238 if (err) {
1239 error_report_err(err);
1240 }
1241 }
1242
1243 void 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;
1251 bool has_cpu_throttle_initial = false;
1252 bool has_cpu_throttle_increment = false;
1253 int i;
1254
1255 for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
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;
1267 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1268 has_cpu_throttle_initial = true;
1269 break;
1270 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1271 has_cpu_throttle_increment = true;
1272 break;
1273 }
1274 qmp_migrate_set_parameters(has_compress_level, value,
1275 has_compress_threads, value,
1276 has_decompress_threads, value,
1277 has_cpu_throttle_initial, value,
1278 has_cpu_throttle_increment, value,
1279 &err);
1280 break;
1281 }
1282 }
1283
1284 if (i == MIGRATION_PARAMETER__MAX) {
1285 error_setg(&err, QERR_INVALID_PARAMETER, param);
1286 }
1287
1288 if (err) {
1289 error_report_err(err);
1290 }
1291 }
1292
1293 void 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
1310 void 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
1317 void 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 }
1327
1328 void 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 }
1337
1338 void hmp_eject(Monitor *mon, const QDict *qdict)
1339 {
1340 bool force = qdict_get_try_bool(qdict, "force", false);
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 }
1347
1348 static void hmp_change_read_arg(void *opaque, const char *password,
1349 void *readline_opaque)
1350 {
1351 qmp_change_vnc_password(password, NULL);
1352 monitor_read_command(opaque, 1);
1353 }
1354
1355 void 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");
1360 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1361 BlockdevChangeReadOnlyMode read_only_mode = 0;
1362 Error *err = NULL;
1363
1364 if (strcmp(device, "vnc") == 0) {
1365 if (read_only) {
1366 monitor_printf(mon,
1367 "Parameter 'read-only-mode' is invalid for VNC\n");
1368 return;
1369 }
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 {
1379 if (read_only) {
1380 read_only_mode =
1381 qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup,
1382 read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX,
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);
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);
1396 return;
1397 }
1398 }
1399
1400 hmp_handle_error(mon, &err);
1401 }
1402
1403 void 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"),
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,
1425 0,
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,
1438 false, /* No default I/O size */
1439 0,
1440 false,
1441 NULL, &err);
1442 hmp_handle_error(mon, &err);
1443 }
1444
1445 void 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");
1450 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1451
1452 qmp_block_stream(device, base != NULL, base, false, NULL,
1453 qdict_haskey(qdict, "speed"), speed,
1454 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1455
1456 hmp_handle_error(mon, &error);
1457 }
1458
1459 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1460 {
1461 Error *error = NULL;
1462 const char *device = qdict_get_str(qdict, "device");
1463 int64_t value = qdict_get_int(qdict, "speed");
1464
1465 qmp_block_job_set_speed(device, value, &error);
1466
1467 hmp_handle_error(mon, &error);
1468 }
1469
1470 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1471 {
1472 Error *error = NULL;
1473 const char *device = qdict_get_str(qdict, "device");
1474 bool force = qdict_get_try_bool(qdict, "force", false);
1475
1476 qmp_block_job_cancel(device, true, force, &error);
1477
1478 hmp_handle_error(mon, &error);
1479 }
1480
1481 void 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
1491 void 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);
1497
1498 hmp_handle_error(mon, &error);
1499 }
1500
1501 void 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
1511 typedef struct HMPMigrationStatus
1512 {
1513 QEMUTimer *timer;
1514 Monitor *mon;
1515 bool is_block_migration;
1516 } HMPMigrationStatus;
1517
1518 static void hmp_migrate_status_cb(void *opaque)
1519 {
1520 HMPMigrationStatus *status = opaque;
1521 MigrationInfo *info;
1522
1523 info = qmp_query_migrate(NULL);
1524 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1525 info->status == MIGRATION_STATUS_SETUP) {
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
1539 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1540 } else {
1541 if (status->is_block_migration) {
1542 monitor_printf(status->mon, "\n");
1543 }
1544 if (info->has_error_desc) {
1545 error_report("%s", info->error_desc);
1546 }
1547 monitor_resume(status->mon);
1548 timer_del(status->timer);
1549 g_free(status);
1550 }
1551
1552 qapi_free_MigrationInfo(info);
1553 }
1554
1555 void hmp_migrate(Monitor *mon, const QDict *qdict)
1556 {
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);
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) {
1565 error_report_err(err);
1566 return;
1567 }
1568
1569 if (!detach) {
1570 HMPMigrationStatus *status;
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;
1581 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1582 status);
1583 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1584 }
1585 }
1586
1587 void hmp_device_add(Monitor *mon, const QDict *qdict)
1588 {
1589 Error *err = NULL;
1590
1591 qmp_device_add((QDict *)qdict, NULL, &err);
1592 hmp_handle_error(mon, &err);
1593 }
1594
1595 void 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 }
1603
1604 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1605 {
1606 Error *err = NULL;
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);
1611 const char *file = qdict_get_str(qdict, "filename");
1612 bool has_begin = qdict_haskey(qdict, "begin");
1613 bool has_length = qdict_haskey(qdict, "length");
1614 bool has_detach = qdict_haskey(qdict, "detach");
1615 int64_t begin = 0;
1616 int64_t length = 0;
1617 bool detach = false;
1618 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
1619 char *prot;
1620
1621 if (zlib + lzo + snappy > 1) {
1622 error_setg(&err, "only one of '-z|-l|-s' can be set");
1623 hmp_handle_error(mon, &err);
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
1639 if (has_begin) {
1640 begin = qdict_get_int(qdict, "begin");
1641 }
1642 if (has_length) {
1643 length = qdict_get_int(qdict, "length");
1644 }
1645 if (has_detach) {
1646 detach = qdict_get_bool(qdict, "detach");
1647 }
1648
1649 prot = g_strconcat("file:", file, NULL);
1650
1651 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
1652 has_length, length, true, dump_format, &err);
1653 hmp_handle_error(mon, &err);
1654 g_free(prot);
1655 }
1656
1657 void 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);
1663 if (err) {
1664 goto out;
1665 }
1666
1667 netdev_add(opts, &err);
1668 if (err) {
1669 qemu_opts_del(opts);
1670 }
1671
1672 out:
1673 hmp_handle_error(mon, &err);
1674 }
1675
1676 void 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 }
1684
1685 void hmp_object_add(Monitor *mon, const QDict *qdict)
1686 {
1687 Error *err = NULL;
1688 QemuOpts *opts;
1689 OptsVisitor *ov;
1690 Object *obj = NULL;
1691
1692 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1693 if (err) {
1694 hmp_handle_error(mon, &err);
1695 return;
1696 }
1697
1698 ov = opts_visitor_new(opts);
1699 obj = user_creatable_add(qdict, opts_get_visitor(ov), &err);
1700 opts_visitor_cleanup(ov);
1701 qemu_opts_del(opts);
1702
1703 if (err) {
1704 hmp_handle_error(mon, &err);
1705 }
1706 if (obj) {
1707 object_unref(obj);
1708 }
1709 }
1710
1711 void hmp_getfd(Monitor *mon, const QDict *qdict)
1712 {
1713 const char *fdname = qdict_get_str(qdict, "fdname");
1714 Error *err = NULL;
1715
1716 qmp_getfd(fdname, &err);
1717 hmp_handle_error(mon, &err);
1718 }
1719
1720 void hmp_closefd(Monitor *mon, const QDict *qdict)
1721 {
1722 const char *fdname = qdict_get_str(qdict, "fdname");
1723 Error *err = NULL;
1724
1725 qmp_closefd(fdname, &err);
1726 hmp_handle_error(mon, &err);
1727 }
1728
1729 void hmp_sendkey(Monitor *mon, const QDict *qdict)
1730 {
1731 const char *keys = qdict_get_str(qdict, "keys");
1732 KeyValueList *keylist, *head = NULL, *tmp = NULL;
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;
1736 char *separator;
1737 int keyname_len;
1738
1739 while (1) {
1740 separator = strchr(keys, '-');
1741 keyname_len = separator ? separator - keys : strlen(keys);
1742
1743 /* Be compatible with old interface, convert user inputted "<" */
1744 if (keys[0] == '<' && keyname_len == 1) {
1745 keys = "less";
1746 keyname_len = 4;
1747 }
1748
1749 keylist = g_malloc0(sizeof(*keylist));
1750 keylist->value = g_malloc0(sizeof(*keylist->value));
1751
1752 if (!head) {
1753 head = keylist;
1754 }
1755 if (tmp) {
1756 tmp->next = keylist;
1757 }
1758 tmp = keylist;
1759
1760 if (strstart(keys, "0x", NULL)) {
1761 char *endp;
1762 int value = strtoul(keys, &endp, 0);
1763 assert(endp <= keys + keyname_len);
1764 if (endp != keys + keyname_len) {
1765 goto err_out;
1766 }
1767 keylist->value->type = KEY_VALUE_KIND_NUMBER;
1768 keylist->value->u.number.data = value;
1769 } else {
1770 int idx = index_from_key(keys, keyname_len);
1771 if (idx == Q_KEY_CODE__MAX) {
1772 goto err_out;
1773 }
1774 keylist->value->type = KEY_VALUE_KIND_QCODE;
1775 keylist->value->u.qcode.data = idx;
1776 }
1777
1778 if (!separator) {
1779 break;
1780 }
1781 keys = separator + 1;
1782 }
1783
1784 qmp_send_key(head, has_hold_time, hold_time, &err);
1785 hmp_handle_error(mon, &err);
1786
1787 out:
1788 qapi_free_KeyValueList(head);
1789 return;
1790
1791 err_out:
1792 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
1793 goto out;
1794 }
1795
1796 void hmp_screendump(Monitor *mon, const QDict *qdict)
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 }
1804
1805 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1806 {
1807 const char *uri = qdict_get_str(qdict, "uri");
1808 bool writable = qdict_get_try_bool(qdict, "writable", false);
1809 bool all = qdict_get_try_bool(qdict, "all", false);
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
1825 qmp_nbd_server_start(addr, false, NULL, &local_err);
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
1855 exit:
1856 hmp_handle_error(mon, &local_err);
1857 }
1858
1859 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1860 {
1861 const char *device = qdict_get_str(qdict, "device");
1862 bool writable = qdict_get_try_bool(qdict, "writable", false);
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
1872 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1873 {
1874 Error *err = NULL;
1875
1876 qmp_nbd_server_stop(&err);
1877 hmp_handle_error(mon, &err);
1878 }
1879
1880 void 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
1890 void 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
1896 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
1897 if (opts == NULL) {
1898 error_setg(&err, "Parsing chardev args failed");
1899 } else {
1900 qemu_chr_new_from_opts(opts, NULL, &err);
1901 }
1902 hmp_handle_error(mon, &err);
1903 }
1904
1905 void 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 }
1912
1913 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1914 {
1915 BlockBackend *blk;
1916 const char* device = qdict_get_str(qdict, "device");
1917 const char* command = qdict_get_str(qdict, "command");
1918 Error *err = NULL;
1919
1920 blk = blk_by_name(device);
1921 if (blk) {
1922 qemuio_command(blk, command);
1923 } else {
1924 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
1925 "Device '%s' not found", device);
1926 }
1927
1928 hmp_handle_error(mon, &err);
1929 }
1930
1931 void hmp_object_del(Monitor *mon, const QDict *qdict)
1932 {
1933 const char *id = qdict_get_str(qdict, "id");
1934 Error *err = NULL;
1935
1936 user_creatable_del(id, &err);
1937 hmp_handle_error(mon, &err);
1938 }
1939
1940 void 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;
1946 char *str;
1947 int i = 0;
1948
1949
1950 while (m) {
1951 ov = string_output_visitor_new(false);
1952 visit_type_uint16List(string_output_get_visitor(ov), NULL,
1953 &m->value->host_nodes, NULL);
1954 monitor_printf(mon, "memory backend: %d\n", i);
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]);
1964 str = string_output_get_string(ov);
1965 monitor_printf(mon, " host nodes: %s\n", str);
1966
1967 g_free(str);
1968 string_output_visitor_cleanup(ov);
1969 m = m->next;
1970 i++;
1971 }
1972
1973 monitor_printf(mon, "\n");
1974
1975 qapi_free_MemdevList(memdev_list);
1976 }
1977
1978 void 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) {
1990 switch (value->type) {
1991 case MEMORY_DEVICE_INFO_KIND_DIMM:
1992 di = value->u.dimm.data;
1993
1994 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1995 MemoryDeviceInfoKind_lookup[value->type],
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 }
2015
2016 void 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
2029 void 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 }
2054
2055 void 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) {
2066 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2067 "Device '%s' not found", path);
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 }
2076
2077 void hmp_rocker(Monitor *mon, const QDict *qdict)
2078 {
2079 const char *name = qdict_get_str(qdict, "name");
2080 RockerSwitch *rocker;
2081 Error *err = NULL;
2082
2083 rocker = qmp_query_rocker(name, &err);
2084 if (err != NULL) {
2085 hmp_handle_error(mon, &err);
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
2096 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2097 {
2098 RockerPortList *list, *port;
2099 const char *name = qdict_get_str(qdict, "name");
2100 Error *err = NULL;
2101
2102 list = qmp_query_rocker_ports(name, &err);
2103 if (err != NULL) {
2104 hmp_handle_error(mon, &err);
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
2124 void 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);
2129 Error *err = NULL;
2130
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);
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
2274 void 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);
2279 Error *err = NULL;
2280 bool set = false;
2281
2282 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2283 if (err != NULL) {
2284 hmp_handle_error(mon, &err);
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 }
2378
2379 void 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 }