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