]> Git Repo - qemu.git/blame - hmp.c
kvm_stat: Add kvm_exit reasons for aarch64
[qemu.git] / hmp.c
CommitLineData
48a32bed
AL
1/*
2 * Human Monitor Interface
3 *
4 * Copyright IBM, Corp. 2011
5 *
6 * Authors:
7 * Anthony Liguori <[email protected]>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
6b620ca3
PB
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
48a32bed
AL
14 */
15
16#include "hmp.h"
1422e32d 17#include "net/net.h"
dccfcd0e 18#include "sysemu/char.h"
1de7afc9
PB
19#include "qemu/option.h"
20#include "qemu/timer.h"
48a32bed 21#include "qmp-commands.h"
1de7afc9 22#include "qemu/sockets.h"
83c9089e 23#include "monitor/monitor.h"
cff8b2c6 24#include "qapi/opts-visitor.h"
eb1539b2
HT
25#include "qapi/string-output-visitor.h"
26#include "qapi-visit.h"
28ecbaee 27#include "ui/console.h"
bd093a36 28#include "block/qapi.h"
587da2c3 29#include "qemu-io.h"
48a32bed 30
0cfd6a9a
LC
31static void hmp_handle_error(Monitor *mon, Error **errp)
32{
415168e0
MA
33 assert(errp);
34 if (*errp) {
0cfd6a9a
LC
35 monitor_printf(mon, "%s\n", error_get_pretty(*errp));
36 error_free(*errp);
37 }
38}
39
84f2d0ea 40void hmp_info_name(Monitor *mon, const QDict *qdict)
48a32bed
AL
41{
42 NameInfo *info;
43
44 info = qmp_query_name(NULL);
45 if (info->has_name) {
46 monitor_printf(mon, "%s\n", info->name);
47 }
48 qapi_free_NameInfo(info);
49}
b9c15f16 50
84f2d0ea 51void hmp_info_version(Monitor *mon, const QDict *qdict)
b9c15f16
LC
52{
53 VersionInfo *info;
54
55 info = qmp_query_version(NULL);
56
57 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
58 info->qemu.major, info->qemu.minor, info->qemu.micro,
59 info->package);
60
61 qapi_free_VersionInfo(info);
62}
292a2602 63
84f2d0ea 64void hmp_info_kvm(Monitor *mon, const QDict *qdict)
292a2602
LC
65{
66 KvmInfo *info;
67
68 info = qmp_query_kvm(NULL);
69 monitor_printf(mon, "kvm support: ");
70 if (info->present) {
71 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
72 } else {
73 monitor_printf(mon, "not compiled\n");
74 }
75
76 qapi_free_KvmInfo(info);
77}
78
84f2d0ea 79void hmp_info_status(Monitor *mon, const QDict *qdict)
1fa9a5e4
LC
80{
81 StatusInfo *info;
82
83 info = qmp_query_status(NULL);
84
85 monitor_printf(mon, "VM status: %s%s",
86 info->running ? "running" : "paused",
87 info->singlestep ? " (single step mode)" : "");
88
89 if (!info->running && info->status != RUN_STATE_PAUSED) {
90 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
91 }
92
93 monitor_printf(mon, "\n");
94
95 qapi_free_StatusInfo(info);
96}
97
84f2d0ea 98void hmp_info_uuid(Monitor *mon, const QDict *qdict)
efab767e
LC
99{
100 UuidInfo *info;
101
102 info = qmp_query_uuid(NULL);
103 monitor_printf(mon, "%s\n", info->UUID);
104 qapi_free_UuidInfo(info);
105}
c5a415a0 106
84f2d0ea 107void hmp_info_chardev(Monitor *mon, const QDict *qdict)
c5a415a0
LC
108{
109 ChardevInfoList *char_info, *info;
110
111 char_info = qmp_query_chardev(NULL);
112 for (info = char_info; info; info = info->next) {
113 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
114 info->value->filename);
115 }
116
117 qapi_free_ChardevInfoList(char_info);
118}
7a7f325e 119
84f2d0ea 120void hmp_info_mice(Monitor *mon, const QDict *qdict)
e235cec3
LC
121{
122 MouseInfoList *mice_list, *mouse;
123
124 mice_list = qmp_query_mice(NULL);
125 if (!mice_list) {
126 monitor_printf(mon, "No mouse devices connected\n");
127 return;
128 }
129
130 for (mouse = mice_list; mouse; mouse = mouse->next) {
131 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
132 mouse->value->current ? '*' : ' ',
133 mouse->value->index, mouse->value->name,
134 mouse->value->absolute ? " (absolute)" : "");
135 }
136
137 qapi_free_MouseInfoList(mice_list);
138}
139
84f2d0ea 140void hmp_info_migrate(Monitor *mon, const QDict *qdict)
791e7c82
LC
141{
142 MigrationInfo *info;
bbf6da32 143 MigrationCapabilityStatusList *caps, *cap;
791e7c82
LC
144
145 info = qmp_query_migrate(NULL);
bbf6da32
OW
146 caps = qmp_query_migrate_capabilities(NULL);
147
148 /* do not display parameters during setup */
149 if (info->has_status && caps) {
150 monitor_printf(mon, "capabilities: ");
151 for (cap = caps; cap; cap = cap->next) {
152 monitor_printf(mon, "%s: %s ",
153 MigrationCapability_lookup[cap->value->capability],
154 cap->value->state ? "on" : "off");
155 }
156 monitor_printf(mon, "\n");
157 }
791e7c82
LC
158
159 if (info->has_status) {
160 monitor_printf(mon, "Migration status: %s\n", info->status);
7aa939af
JQ
161 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
162 info->total_time);
2c52ddf1
JQ
163 if (info->has_expected_downtime) {
164 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
165 info->expected_downtime);
166 }
9c5a9fcf
JQ
167 if (info->has_downtime) {
168 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
169 info->downtime);
170 }
ed4fbd10
MH
171 if (info->has_setup_time) {
172 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
173 info->setup_time);
174 }
791e7c82
LC
175 }
176
177 if (info->has_ram) {
178 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
179 info->ram->transferred >> 10);
7e114f8c
MH
180 monitor_printf(mon, "throughput: %0.2f mbps\n",
181 info->ram->mbps);
791e7c82
LC
182 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
183 info->ram->remaining >> 10);
184 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
185 info->ram->total >> 10);
004d4c10
OW
186 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
187 info->ram->duplicate);
f1c72795
PL
188 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
189 info->ram->skipped);
004d4c10
OW
190 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
191 info->ram->normal);
192 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
193 info->ram->normal_bytes >> 10);
58570ed8
C
194 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
195 info->ram->dirty_sync_count);
8d017193
JQ
196 if (info->ram->dirty_pages_rate) {
197 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
198 info->ram->dirty_pages_rate);
199 }
791e7c82
LC
200 }
201
202 if (info->has_disk) {
203 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
204 info->disk->transferred >> 10);
205 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
206 info->disk->remaining >> 10);
207 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
208 info->disk->total >> 10);
209 }
210
f36d55af
OW
211 if (info->has_xbzrle_cache) {
212 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
213 info->xbzrle_cache->cache_size);
214 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
215 info->xbzrle_cache->bytes >> 10);
216 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
217 info->xbzrle_cache->pages);
218 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
219 info->xbzrle_cache->cache_miss);
8bc39233
C
220 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
221 info->xbzrle_cache->cache_miss_rate);
f36d55af
OW
222 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
223 info->xbzrle_cache->overflow);
224 }
225
791e7c82 226 qapi_free_MigrationInfo(info);
bbf6da32
OW
227 qapi_free_MigrationCapabilityStatusList(caps);
228}
229
84f2d0ea 230void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
bbf6da32
OW
231{
232 MigrationCapabilityStatusList *caps, *cap;
233
234 caps = qmp_query_migrate_capabilities(NULL);
235
236 if (caps) {
237 monitor_printf(mon, "capabilities: ");
238 for (cap = caps; cap; cap = cap->next) {
239 monitor_printf(mon, "%s: %s ",
240 MigrationCapability_lookup[cap->value->capability],
241 cap->value->state ? "on" : "off");
242 }
243 monitor_printf(mon, "\n");
244 }
245
246 qapi_free_MigrationCapabilityStatusList(caps);
791e7c82
LC
247}
248
84f2d0ea 249void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
9e1ba4cc
OW
250{
251 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
252 qmp_query_migrate_cache_size(NULL) >> 10);
253}
254
84f2d0ea 255void hmp_info_cpus(Monitor *mon, const QDict *qdict)
de0b36b6
LC
256{
257 CpuInfoList *cpu_list, *cpu;
258
259 cpu_list = qmp_query_cpus(NULL);
260
261 for (cpu = cpu_list; cpu; cpu = cpu->next) {
262 int active = ' ';
263
264 if (cpu->value->CPU == monitor_get_cpu_index()) {
265 active = '*';
266 }
267
852bef0e 268 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
de0b36b6
LC
269
270 if (cpu->value->has_pc) {
852bef0e 271 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->pc);
de0b36b6
LC
272 }
273 if (cpu->value->has_nip) {
852bef0e 274 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->nip);
de0b36b6
LC
275 }
276 if (cpu->value->has_npc) {
852bef0e 277 monitor_printf(mon, " npc=0x%016" PRIx64, cpu->value->npc);
de0b36b6
LC
278 }
279 if (cpu->value->has_PC) {
852bef0e 280 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->PC);
de0b36b6
LC
281 }
282
283 if (cpu->value->halted) {
284 monitor_printf(mon, " (halted)");
285 }
286
287 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
288 }
289
290 qapi_free_CpuInfoList(cpu_list);
291}
292
289b276c
KW
293static void print_block_info(Monitor *mon, BlockInfo *info,
294 BlockDeviceInfo *inserted, bool verbose)
b2023818 295{
bd093a36 296 ImageInfo *image_info;
b2023818 297
8d6adccd
KW
298 assert(!info || !info->has_inserted || info->inserted == inserted);
299
300 if (info) {
301 monitor_printf(mon, "%s", info->device);
302 if (inserted && inserted->has_node_name) {
303 monitor_printf(mon, " (%s)", inserted->node_name);
304 }
305 } else {
306 assert(inserted);
307 monitor_printf(mon, "%s",
308 inserted->has_node_name
309 ? inserted->node_name
310 : "<anonymous>");
311 }
312
289b276c
KW
313 if (inserted) {
314 monitor_printf(mon, ": %s (%s%s%s)\n",
315 inserted->file,
316 inserted->drv,
317 inserted->ro ? ", read-only" : "",
318 inserted->encrypted ? ", encrypted" : "");
319 } else {
320 monitor_printf(mon, ": [not inserted]\n");
321 }
b2023818 322
8d6adccd
KW
323 if (info) {
324 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
325 monitor_printf(mon, " I/O status: %s\n",
326 BlockDeviceIoStatus_lookup[info->io_status]);
327 }
b2023818 328
8d6adccd
KW
329 if (info->removable) {
330 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
331 info->locked ? "" : "not ",
332 info->tray_open ? "open" : "closed");
333 }
289b276c 334 }
fbe2e26c 335
b2023818 336
289b276c
KW
337 if (!inserted) {
338 return;
339 }
b2023818 340
289b276c
KW
341 monitor_printf(mon, " Cache mode: %s%s%s\n",
342 inserted->cache->writeback ? "writeback" : "writethrough",
343 inserted->cache->direct ? ", direct" : "",
344 inserted->cache->no_flush ? ", ignore flushes" : "");
345
346 if (inserted->has_backing_file) {
347 monitor_printf(mon,
348 " Backing file: %s "
349 "(chain depth: %" PRId64 ")\n",
350 inserted->backing_file,
351 inserted->backing_file_depth);
352 }
727f005e 353
289b276c
KW
354 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
355 monitor_printf(mon, " Detect zeroes: %s\n",
356 BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]);
357 }
fbe2e26c 358
289b276c
KW
359 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
360 inserted->iops || inserted->iops_rd || inserted->iops_wr)
361 {
362 monitor_printf(mon, " I/O throttling: bps=%" PRId64
363 " bps_rd=%" PRId64 " bps_wr=%" PRId64
364 " bps_max=%" PRId64
365 " bps_rd_max=%" PRId64
366 " bps_wr_max=%" PRId64
367 " iops=%" PRId64 " iops_rd=%" PRId64
368 " iops_wr=%" PRId64
369 " iops_max=%" PRId64
370 " iops_rd_max=%" PRId64
371 " iops_wr_max=%" PRId64
372 " iops_size=%" PRId64 "\n",
373 inserted->bps,
374 inserted->bps_rd,
375 inserted->bps_wr,
376 inserted->bps_max,
377 inserted->bps_rd_max,
378 inserted->bps_wr_max,
379 inserted->iops,
380 inserted->iops_rd,
381 inserted->iops_wr,
382 inserted->iops_max,
383 inserted->iops_rd_max,
384 inserted->iops_wr_max,
385 inserted->iops_size);
386 }
fbe2e26c 387
289b276c
KW
388 if (verbose) {
389 monitor_printf(mon, "\nImages:\n");
390 image_info = inserted->image;
391 while (1) {
392 bdrv_image_info_dump((fprintf_function)monitor_printf,
393 mon, image_info);
394 if (image_info->has_backing_image) {
395 image_info = image_info->backing_image;
396 } else {
397 break;
398 }
399 }
400 }
401}
9e193c5a 402
289b276c
KW
403void hmp_info_block(Monitor *mon, const QDict *qdict)
404{
405 BlockInfoList *block_list, *info;
e6bb31ec 406 BlockDeviceInfoList *blockdev_list, *blockdev;
289b276c
KW
407 const char *device = qdict_get_try_str(qdict, "device");
408 bool verbose = qdict_get_try_bool(qdict, "verbose", 0);
e6bb31ec
KW
409 bool nodes = qdict_get_try_bool(qdict, "nodes", 0);
410 bool printed = false;
9e193c5a 411
e6bb31ec
KW
412 /* Print BlockBackend information */
413 if (!nodes) {
414 block_list = qmp_query_block(false);
415 } else {
416 block_list = NULL;
417 }
fbe2e26c 418
289b276c
KW
419 for (info = block_list; info; info = info->next) {
420 if (device && strcmp(device, info->value->device)) {
421 continue;
465bee1d
PL
422 }
423
289b276c
KW
424 if (info != block_list) {
425 monitor_printf(mon, "\n");
fbe2e26c 426 }
bd093a36 427
289b276c
KW
428 print_block_info(mon, info->value, info->value->has_inserted
429 ? info->value->inserted : NULL,
430 verbose);
e6bb31ec 431 printed = true;
b2023818
LC
432 }
433
434 qapi_free_BlockInfoList(block_list);
e6bb31ec
KW
435
436 if ((!device && !nodes) || printed) {
437 return;
438 }
439
440 /* Print node information */
441 blockdev_list = qmp_query_named_block_nodes(NULL);
442 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
443 assert(blockdev->value->has_node_name);
444 if (device && strcmp(device, blockdev->value->node_name)) {
445 continue;
446 }
447
448 if (blockdev != blockdev_list) {
449 monitor_printf(mon, "\n");
450 }
451
452 print_block_info(mon, NULL, blockdev->value, verbose);
453 }
454 qapi_free_BlockDeviceInfoList(blockdev_list);
b2023818
LC
455}
456
84f2d0ea 457void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
f11f57e4
LC
458{
459 BlockStatsList *stats_list, *stats;
460
f71eaa74 461 stats_list = qmp_query_blockstats(false, false, NULL);
f11f57e4
LC
462
463 for (stats = stats_list; stats; stats = stats->next) {
464 if (!stats->value->has_device) {
465 continue;
466 }
467
468 monitor_printf(mon, "%s:", stats->value->device);
469 monitor_printf(mon, " rd_bytes=%" PRId64
470 " wr_bytes=%" PRId64
471 " rd_operations=%" PRId64
472 " wr_operations=%" PRId64
473 " flush_operations=%" PRId64
474 " wr_total_time_ns=%" PRId64
475 " rd_total_time_ns=%" PRId64
476 " flush_total_time_ns=%" PRId64
477 "\n",
478 stats->value->stats->rd_bytes,
479 stats->value->stats->wr_bytes,
480 stats->value->stats->rd_operations,
481 stats->value->stats->wr_operations,
482 stats->value->stats->flush_operations,
483 stats->value->stats->wr_total_time_ns,
484 stats->value->stats->rd_total_time_ns,
485 stats->value->stats->flush_total_time_ns);
486 }
487
488 qapi_free_BlockStatsList(stats_list);
489}
490
84f2d0ea 491void hmp_info_vnc(Monitor *mon, const QDict *qdict)
2b54aa87
LC
492{
493 VncInfo *info;
494 Error *err = NULL;
495 VncClientInfoList *client;
496
497 info = qmp_query_vnc(&err);
498 if (err) {
499 monitor_printf(mon, "%s\n", error_get_pretty(err));
500 error_free(err);
501 return;
502 }
503
504 if (!info->enabled) {
505 monitor_printf(mon, "Server: disabled\n");
506 goto out;
507 }
508
509 monitor_printf(mon, "Server:\n");
510 if (info->has_host && info->has_service) {
511 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
512 }
513 if (info->has_auth) {
514 monitor_printf(mon, " auth: %s\n", info->auth);
515 }
516
517 if (!info->has_clients || info->clients == NULL) {
518 monitor_printf(mon, "Client: none\n");
519 } else {
520 for (client = info->clients; client; client = client->next) {
521 monitor_printf(mon, "Client:\n");
522 monitor_printf(mon, " address: %s:%s\n",
a589569f
WX
523 client->value->base->host,
524 client->value->base->service);
2b54aa87
LC
525 monitor_printf(mon, " x509_dname: %s\n",
526 client->value->x509_dname ?
527 client->value->x509_dname : "none");
528 monitor_printf(mon, " username: %s\n",
529 client->value->has_sasl_username ?
530 client->value->sasl_username : "none");
531 }
532 }
533
534out:
535 qapi_free_VncInfo(info);
536}
537
206addd5 538#ifdef CONFIG_SPICE
84f2d0ea 539void hmp_info_spice(Monitor *mon, const QDict *qdict)
d1f29646
LC
540{
541 SpiceChannelList *chan;
542 SpiceInfo *info;
543
544 info = qmp_query_spice(NULL);
545
546 if (!info->enabled) {
547 monitor_printf(mon, "Server: disabled\n");
548 goto out;
549 }
550
551 monitor_printf(mon, "Server:\n");
552 if (info->has_port) {
553 monitor_printf(mon, " address: %s:%" PRId64 "\n",
554 info->host, info->port);
555 }
556 if (info->has_tls_port) {
557 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
558 info->host, info->tls_port);
559 }
61c4efe2
YH
560 monitor_printf(mon, " migrated: %s\n",
561 info->migrated ? "true" : "false");
d1f29646
LC
562 monitor_printf(mon, " auth: %s\n", info->auth);
563 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
4efee029
AL
564 monitor_printf(mon, " mouse-mode: %s\n",
565 SpiceQueryMouseMode_lookup[info->mouse_mode]);
d1f29646
LC
566
567 if (!info->has_channels || info->channels == NULL) {
568 monitor_printf(mon, "Channels: none\n");
569 } else {
570 for (chan = info->channels; chan; chan = chan->next) {
571 monitor_printf(mon, "Channel:\n");
572 monitor_printf(mon, " address: %s:%s%s\n",
a589569f 573 chan->value->base->host, chan->value->base->port,
d1f29646
LC
574 chan->value->tls ? " [tls]" : "");
575 monitor_printf(mon, " session: %" PRId64 "\n",
576 chan->value->connection_id);
577 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
578 chan->value->channel_type, chan->value->channel_id);
579 }
580 }
581
582out:
583 qapi_free_SpiceInfo(info);
584}
206addd5 585#endif
d1f29646 586
84f2d0ea 587void hmp_info_balloon(Monitor *mon, const QDict *qdict)
96637bcd
LC
588{
589 BalloonInfo *info;
590 Error *err = NULL;
591
592 info = qmp_query_balloon(&err);
593 if (err) {
594 monitor_printf(mon, "%s\n", error_get_pretty(err));
595 error_free(err);
596 return;
597 }
598
01ceb97e 599 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
96637bcd
LC
600
601 qapi_free_BalloonInfo(info);
602}
603
79627472
LC
604static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
605{
606 PciMemoryRegionList *region;
607
608 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
609 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
610 dev->slot, dev->function);
611 monitor_printf(mon, " ");
612
613 if (dev->class_info.has_desc) {
614 monitor_printf(mon, "%s", dev->class_info.desc);
615 } else {
6f88009e 616 monitor_printf(mon, "Class %04" PRId64, dev->class_info.q_class);
79627472
LC
617 }
618
619 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
620 dev->id.vendor, dev->id.device);
621
622 if (dev->has_irq) {
623 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
624 }
625
626 if (dev->has_pci_bridge) {
627 monitor_printf(mon, " BUS %" PRId64 ".\n",
628 dev->pci_bridge->bus.number);
629 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
630 dev->pci_bridge->bus.secondary);
631 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
632 dev->pci_bridge->bus.subordinate);
633
634 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
635 dev->pci_bridge->bus.io_range->base,
636 dev->pci_bridge->bus.io_range->limit);
637
638 monitor_printf(mon,
639 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
640 dev->pci_bridge->bus.memory_range->base,
641 dev->pci_bridge->bus.memory_range->limit);
642
643 monitor_printf(mon, " prefetchable memory range "
644 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
645 dev->pci_bridge->bus.prefetchable_range->base,
646 dev->pci_bridge->bus.prefetchable_range->limit);
647 }
648
649 for (region = dev->regions; region; region = region->next) {
650 uint64_t addr, size;
651
652 addr = region->value->address;
653 size = region->value->size;
654
655 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
656
657 if (!strcmp(region->value->type, "io")) {
658 monitor_printf(mon, "I/O at 0x%04" PRIx64
659 " [0x%04" PRIx64 "].\n",
660 addr, addr + size - 1);
661 } else {
662 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
663 " [0x%08" PRIx64 "].\n",
664 region->value->mem_type_64 ? 64 : 32,
665 region->value->prefetch ? " prefetchable" : "",
666 addr, addr + size - 1);
667 }
668 }
669
670 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
671
672 if (dev->has_pci_bridge) {
673 if (dev->pci_bridge->has_devices) {
674 PciDeviceInfoList *cdev;
675 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
676 hmp_info_pci_device(mon, cdev->value);
677 }
678 }
679 }
680}
681
84f2d0ea 682void hmp_info_pci(Monitor *mon, const QDict *qdict)
79627472 683{
f46cee37 684 PciInfoList *info_list, *info;
79627472
LC
685 Error *err = NULL;
686
f46cee37 687 info_list = qmp_query_pci(&err);
79627472
LC
688 if (err) {
689 monitor_printf(mon, "PCI devices not supported\n");
690 error_free(err);
691 return;
692 }
693
f46cee37 694 for (info = info_list; info; info = info->next) {
79627472
LC
695 PciDeviceInfoList *dev;
696
697 for (dev = info->value->devices; dev; dev = dev->next) {
698 hmp_info_pci_device(mon, dev->value);
699 }
700 }
701
f46cee37 702 qapi_free_PciInfoList(info_list);
79627472
LC
703}
704
84f2d0ea 705void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
fb5458cd
SH
706{
707 BlockJobInfoList *list;
708 Error *err = NULL;
709
710 list = qmp_query_block_jobs(&err);
711 assert(!err);
712
713 if (!list) {
714 monitor_printf(mon, "No active jobs\n");
715 return;
716 }
717
718 while (list) {
719 if (strcmp(list->value->type, "stream") == 0) {
720 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
721 " of %" PRId64 " bytes, speed limit %" PRId64
722 " bytes/s\n",
723 list->value->device,
724 list->value->offset,
725 list->value->len,
726 list->value->speed);
727 } else {
728 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
729 " of %" PRId64 " bytes, speed limit %" PRId64
730 " bytes/s\n",
731 list->value->type,
732 list->value->device,
733 list->value->offset,
734 list->value->len,
735 list->value->speed);
736 }
737 list = list->next;
738 }
93bb1315
GA
739
740 qapi_free_BlockJobInfoList(list);
fb5458cd
SH
741}
742
d1a0cf73
SB
743void hmp_info_tpm(Monitor *mon, const QDict *qdict)
744{
745 TPMInfoList *info_list, *info;
746 Error *err = NULL;
747 unsigned int c = 0;
748 TPMPassthroughOptions *tpo;
749
750 info_list = qmp_query_tpm(&err);
751 if (err) {
752 monitor_printf(mon, "TPM device not supported\n");
753 error_free(err);
754 return;
755 }
756
757 if (info_list) {
758 monitor_printf(mon, "TPM device:\n");
759 }
760
761 for (info = info_list; info; info = info->next) {
762 TPMInfo *ti = info->value;
763 monitor_printf(mon, " tpm%d: model=%s\n",
764 c, TpmModel_lookup[ti->model]);
765
766 monitor_printf(mon, " \\ %s: type=%s",
88ca7bcf 767 ti->id, TpmTypeOptionsKind_lookup[ti->options->kind]);
d1a0cf73 768
88ca7bcf
CB
769 switch (ti->options->kind) {
770 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
771 tpo = ti->options->passthrough;
d1a0cf73
SB
772 monitor_printf(mon, "%s%s%s%s",
773 tpo->has_path ? ",path=" : "",
774 tpo->has_path ? tpo->path : "",
775 tpo->has_cancel_path ? ",cancel-path=" : "",
776 tpo->has_cancel_path ? tpo->cancel_path : "");
777 break;
778 case TPM_TYPE_OPTIONS_KIND_MAX:
779 break;
780 }
781 monitor_printf(mon, "\n");
782 c++;
783 }
784 qapi_free_TPMInfoList(info_list);
785}
786
7a7f325e
LC
787void hmp_quit(Monitor *mon, const QDict *qdict)
788{
789 monitor_suspend(mon);
790 qmp_quit(NULL);
791}
5f158f21
LC
792
793void hmp_stop(Monitor *mon, const QDict *qdict)
794{
795 qmp_stop(NULL);
796}
38d22653
LC
797
798void hmp_system_reset(Monitor *mon, const QDict *qdict)
799{
800 qmp_system_reset(NULL);
801}
5bc465e4
LC
802
803void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
804{
805 qmp_system_powerdown(NULL);
806}
755f1968
LC
807
808void hmp_cpu(Monitor *mon, const QDict *qdict)
809{
810 int64_t cpu_index;
811
812 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
813 use it are converted to the QAPI */
814 cpu_index = qdict_get_int(qdict, "index");
815 if (monitor_set_cpu(cpu_index) < 0) {
816 monitor_printf(mon, "invalid CPU index\n");
817 }
818}
0cfd6a9a
LC
819
820void hmp_memsave(Monitor *mon, const QDict *qdict)
821{
822 uint32_t size = qdict_get_int(qdict, "size");
823 const char *filename = qdict_get_str(qdict, "filename");
824 uint64_t addr = qdict_get_int(qdict, "val");
e940f543 825 Error *err = NULL;
0cfd6a9a 826
e940f543
MA
827 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &err);
828 hmp_handle_error(mon, &err);
0cfd6a9a 829}
6d3962bf
LC
830
831void hmp_pmemsave(Monitor *mon, const QDict *qdict)
832{
833 uint32_t size = qdict_get_int(qdict, "size");
834 const char *filename = qdict_get_str(qdict, "filename");
835 uint64_t addr = qdict_get_int(qdict, "val");
e940f543 836 Error *err = NULL;
6d3962bf 837
e940f543
MA
838 qmp_pmemsave(addr, size, filename, &err);
839 hmp_handle_error(mon, &err);
1f590cf9
LL
840}
841
3949e594 842void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1f590cf9 843{
1f590cf9
LL
844 const char *chardev = qdict_get_str(qdict, "device");
845 const char *data = qdict_get_str(qdict, "data");
e940f543 846 Error *err = NULL;
1f590cf9 847
e940f543 848 qmp_ringbuf_write(chardev, data, false, 0, &err);
1f590cf9 849
e940f543 850 hmp_handle_error(mon, &err);
6d3962bf 851}
e42e818b 852
3949e594 853void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
49b6d722
LL
854{
855 uint32_t size = qdict_get_int(qdict, "size");
856 const char *chardev = qdict_get_str(qdict, "device");
3ab651fc 857 char *data;
e940f543 858 Error *err = NULL;
543f3412 859 int i;
49b6d722 860
e940f543
MA
861 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
862 if (err) {
863 monitor_printf(mon, "%s\n", error_get_pretty(err));
864 error_free(err);
49b6d722
LL
865 return;
866 }
867
543f3412
MA
868 for (i = 0; data[i]; i++) {
869 unsigned char ch = data[i];
870
871 if (ch == '\\') {
872 monitor_printf(mon, "\\\\");
873 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
874 monitor_printf(mon, "\\u%04X", ch);
875 } else {
876 monitor_printf(mon, "%c", ch);
877 }
878
879 }
880 monitor_printf(mon, "\n");
3ab651fc 881 g_free(data);
49b6d722
LL
882}
883
e42e818b
LC
884static void hmp_cont_cb(void *opaque, int err)
885{
e42e818b 886 if (!err) {
8b7f6fbb 887 qmp_cont(NULL);
e42e818b
LC
888 }
889}
890
8b7f6fbb
LC
891static bool key_is_missing(const BlockInfo *bdev)
892{
893 return (bdev->inserted && bdev->inserted->encryption_key_missing);
894}
895
e42e818b
LC
896void hmp_cont(Monitor *mon, const QDict *qdict)
897{
8b7f6fbb 898 BlockInfoList *bdev_list, *bdev;
e940f543 899 Error *err = NULL;
e42e818b 900
8b7f6fbb
LC
901 bdev_list = qmp_query_block(NULL);
902 for (bdev = bdev_list; bdev; bdev = bdev->next) {
903 if (key_is_missing(bdev->value)) {
904 monitor_read_block_device_key(mon, bdev->value->device,
905 hmp_cont_cb, NULL);
906 goto out;
e42e818b 907 }
e42e818b 908 }
8b7f6fbb 909
e940f543
MA
910 qmp_cont(&err);
911 hmp_handle_error(mon, &err);
8b7f6fbb
LC
912
913out:
914 qapi_free_BlockInfoList(bdev_list);
e42e818b 915}
ab49ab5c 916
9b9df25a
GH
917void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
918{
919 qmp_system_wakeup(NULL);
920}
921
ab49ab5c
LC
922void hmp_inject_nmi(Monitor *mon, const QDict *qdict)
923{
e940f543 924 Error *err = NULL;
ab49ab5c 925
e940f543
MA
926 qmp_inject_nmi(&err);
927 hmp_handle_error(mon, &err);
ab49ab5c 928}
4b37156c
LC
929
930void hmp_set_link(Monitor *mon, const QDict *qdict)
931{
932 const char *name = qdict_get_str(qdict, "name");
933 int up = qdict_get_bool(qdict, "up");
e940f543 934 Error *err = NULL;
4b37156c 935
e940f543
MA
936 qmp_set_link(name, up, &err);
937 hmp_handle_error(mon, &err);
4b37156c 938}
a4dea8a9
LC
939
940void hmp_block_passwd(Monitor *mon, const QDict *qdict)
941{
942 const char *device = qdict_get_str(qdict, "device");
943 const char *password = qdict_get_str(qdict, "password");
e940f543 944 Error *err = NULL;
a4dea8a9 945
e940f543
MA
946 qmp_block_passwd(true, device, false, NULL, password, &err);
947 hmp_handle_error(mon, &err);
a4dea8a9 948}
d72f3264
LC
949
950void hmp_balloon(Monitor *mon, const QDict *qdict)
951{
952 int64_t value = qdict_get_int(qdict, "value");
e940f543 953 Error *err = NULL;
d72f3264 954
e940f543
MA
955 qmp_balloon(value, &err);
956 if (err) {
957 monitor_printf(mon, "balloon: %s\n", error_get_pretty(err));
958 error_free(err);
d72f3264
LC
959 }
960}
5e7caacb
LC
961
962void hmp_block_resize(Monitor *mon, const QDict *qdict)
963{
964 const char *device = qdict_get_str(qdict, "device");
965 int64_t size = qdict_get_int(qdict, "size");
e940f543 966 Error *err = NULL;
5e7caacb 967
e940f543
MA
968 qmp_block_resize(true, device, false, NULL, size, &err);
969 hmp_handle_error(mon, &err);
5e7caacb 970}
6106e249 971
d9b902db
PB
972void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
973{
974 const char *device = qdict_get_str(qdict, "device");
975 const char *filename = qdict_get_str(qdict, "target");
976 const char *format = qdict_get_try_str(qdict, "format");
977 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
978 int full = qdict_get_try_bool(qdict, "full", 0);
979 enum NewImageMode mode;
e940f543 980 Error *err = NULL;
d9b902db
PB
981
982 if (!filename) {
e940f543
MA
983 error_set(&err, QERR_MISSING_PARAMETER, "target");
984 hmp_handle_error(mon, &err);
d9b902db
PB
985 return;
986 }
987
988 if (reuse) {
989 mode = NEW_IMAGE_MODE_EXISTING;
990 } else {
991 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
992 }
993
994 qmp_drive_mirror(device, filename, !!format, format,
09158f00 995 false, NULL, false, NULL,
d9b902db 996 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
08e4ed6c 997 true, mode, false, 0, false, 0, false, 0,
e940f543
MA
998 false, 0, false, 0, &err);
999 hmp_handle_error(mon, &err);
d9b902db
PB
1000}
1001
de90930a
SH
1002void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1003{
1004 const char *device = qdict_get_str(qdict, "device");
1005 const char *filename = qdict_get_str(qdict, "target");
1006 const char *format = qdict_get_try_str(qdict, "format");
1007 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
1008 int full = qdict_get_try_bool(qdict, "full", 0);
1009 enum NewImageMode mode;
e940f543 1010 Error *err = NULL;
de90930a
SH
1011
1012 if (!filename) {
e940f543
MA
1013 error_set(&err, QERR_MISSING_PARAMETER, "target");
1014 hmp_handle_error(mon, &err);
de90930a
SH
1015 return;
1016 }
1017
1018 if (reuse) {
1019 mode = NEW_IMAGE_MODE_EXISTING;
1020 } else {
1021 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1022 }
1023
1024 qmp_drive_backup(device, filename, !!format, format,
1025 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
e940f543
MA
1026 true, mode, false, 0, false, 0, false, 0, &err);
1027 hmp_handle_error(mon, &err);
de90930a
SH
1028}
1029
6106e249
LC
1030void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1031{
1032 const char *device = qdict_get_str(qdict, "device");
1033 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1034 const char *format = qdict_get_try_str(qdict, "format");
6cc2a415
PB
1035 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
1036 enum NewImageMode mode;
e940f543 1037 Error *err = NULL;
6106e249
LC
1038
1039 if (!filename) {
1040 /* In the future, if 'snapshot-file' is not specified, the snapshot
1041 will be taken internally. Today it's actually required. */
e940f543
MA
1042 error_set(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1043 hmp_handle_error(mon, &err);
6106e249
LC
1044 return;
1045 }
1046
6cc2a415 1047 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
0901f67e
BC
1048 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1049 filename, false, NULL,
1050 !!format, format,
e940f543
MA
1051 true, mode, &err);
1052 hmp_handle_error(mon, &err);
6106e249 1053}
6cdedb07 1054
775ca88e
WX
1055void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1056{
1057 const char *device = qdict_get_str(qdict, "device");
1058 const char *name = qdict_get_str(qdict, "name");
e940f543 1059 Error *err = NULL;
775ca88e 1060
e940f543
MA
1061 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1062 hmp_handle_error(mon, &err);
775ca88e
WX
1063}
1064
7a4ed2ee
WX
1065void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1066{
1067 const char *device = qdict_get_str(qdict, "device");
1068 const char *name = qdict_get_str(qdict, "name");
1069 const char *id = qdict_get_try_str(qdict, "id");
e940f543 1070 Error *err = NULL;
7a4ed2ee
WX
1071
1072 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
e940f543
MA
1073 true, name, &err);
1074 hmp_handle_error(mon, &err);
7a4ed2ee
WX
1075}
1076
6cdedb07
LC
1077void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1078{
1079 qmp_migrate_cancel(NULL);
1080}
4f0a993b
LC
1081
1082void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1083{
1084 double value = qdict_get_double(qdict, "value");
1085 qmp_migrate_set_downtime(value, NULL);
1086}
3dc85383 1087
9e1ba4cc
OW
1088void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1089{
1090 int64_t value = qdict_get_int(qdict, "value");
1091 Error *err = NULL;
1092
1093 qmp_migrate_set_cache_size(value, &err);
1094 if (err) {
1095 monitor_printf(mon, "%s\n", error_get_pretty(err));
1096 error_free(err);
1097 return;
1098 }
1099}
1100
3dc85383
LC
1101void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1102{
1103 int64_t value = qdict_get_int(qdict, "value");
1104 qmp_migrate_set_speed(value, NULL);
1105}
fbf796fd 1106
00458433
OW
1107void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1108{
1109 const char *cap = qdict_get_str(qdict, "capability");
1110 bool state = qdict_get_bool(qdict, "state");
1111 Error *err = NULL;
1112 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1113 int i;
1114
1115 for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
1116 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1117 caps->value = g_malloc0(sizeof(*caps->value));
1118 caps->value->capability = i;
1119 caps->value->state = state;
1120 caps->next = NULL;
1121 qmp_migrate_set_capabilities(caps, &err);
1122 break;
1123 }
1124 }
1125
1126 if (i == MIGRATION_CAPABILITY_MAX) {
1127 error_set(&err, QERR_INVALID_PARAMETER, cap);
1128 }
1129
1130 qapi_free_MigrationCapabilityStatusList(caps);
1131
1132 if (err) {
a31ca017 1133 monitor_printf(mon, "migrate_set_capability: %s\n",
00458433
OW
1134 error_get_pretty(err));
1135 error_free(err);
1136 }
1137}
1138
fbf796fd
LC
1139void hmp_set_password(Monitor *mon, const QDict *qdict)
1140{
1141 const char *protocol = qdict_get_str(qdict, "protocol");
1142 const char *password = qdict_get_str(qdict, "password");
1143 const char *connected = qdict_get_try_str(qdict, "connected");
1144 Error *err = NULL;
1145
1146 qmp_set_password(protocol, password, !!connected, connected, &err);
1147 hmp_handle_error(mon, &err);
1148}
9ad5372d
LC
1149
1150void hmp_expire_password(Monitor *mon, const QDict *qdict)
1151{
1152 const char *protocol = qdict_get_str(qdict, "protocol");
1153 const char *whenstr = qdict_get_str(qdict, "time");
1154 Error *err = NULL;
1155
1156 qmp_expire_password(protocol, whenstr, &err);
1157 hmp_handle_error(mon, &err);
1158}
c245b6a3
LC
1159
1160void hmp_eject(Monitor *mon, const QDict *qdict)
1161{
1162 int force = qdict_get_try_bool(qdict, "force", 0);
1163 const char *device = qdict_get_str(qdict, "device");
1164 Error *err = NULL;
1165
1166 qmp_eject(device, true, force, &err);
1167 hmp_handle_error(mon, &err);
1168}
333a96ec 1169
c60bf339
SH
1170static void hmp_change_read_arg(void *opaque, const char *password,
1171 void *readline_opaque)
333a96ec
LC
1172{
1173 qmp_change_vnc_password(password, NULL);
c60bf339 1174 monitor_read_command(opaque, 1);
333a96ec
LC
1175}
1176
333a96ec
LC
1177void hmp_change(Monitor *mon, const QDict *qdict)
1178{
1179 const char *device = qdict_get_str(qdict, "device");
1180 const char *target = qdict_get_str(qdict, "target");
1181 const char *arg = qdict_get_try_str(qdict, "arg");
1182 Error *err = NULL;
1183
1184 if (strcmp(device, "vnc") == 0 &&
1185 (strcmp(target, "passwd") == 0 ||
1186 strcmp(target, "password") == 0)) {
1187 if (!arg) {
1188 monitor_read_password(mon, hmp_change_read_arg, NULL);
1189 return;
1190 }
1191 }
1192
1193 qmp_change(device, target, !!arg, arg, &err);
84d18f06 1194 if (err &&
ab878ddf 1195 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
eef5ad10
LC
1196 error_free(err);
1197 monitor_read_block_device_key(mon, device, NULL, NULL);
333a96ec
LC
1198 return;
1199 }
1200 hmp_handle_error(mon, &err);
1201}
80047da5
LC
1202
1203void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1204{
1205 Error *err = NULL;
1206
1207 qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
1208 qdict_get_int(qdict, "bps"),
1209 qdict_get_int(qdict, "bps_rd"),
1210 qdict_get_int(qdict, "bps_wr"),
1211 qdict_get_int(qdict, "iops"),
1212 qdict_get_int(qdict, "iops_rd"),
3e9fab69
BC
1213 qdict_get_int(qdict, "iops_wr"),
1214 false, /* no burst max via HMP */
1215 0,
1216 false,
1217 0,
1218 false,
1219 0,
1220 false,
1221 0,
1222 false,
1223 0,
1224 false,
2024c1df
BC
1225 0,
1226 false, /* No default I/O size */
3e9fab69 1227 0, &err);
80047da5
LC
1228 hmp_handle_error(mon, &err);
1229}
12bd451f
SH
1230
1231void hmp_block_stream(Monitor *mon, const QDict *qdict)
1232{
1233 Error *error = NULL;
1234 const char *device = qdict_get_str(qdict, "device");
1235 const char *base = qdict_get_try_str(qdict, "base");
c83c66c3 1236 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
12bd451f 1237
13d8cc51 1238 qmp_block_stream(device, base != NULL, base, false, NULL,
1d809098 1239 qdict_haskey(qdict, "speed"), speed,
46663e5e 1240 true, BLOCKDEV_ON_ERROR_REPORT, &error);
12bd451f
SH
1241
1242 hmp_handle_error(mon, &error);
1243}
2d47c6e9
SH
1244
1245void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1246{
1247 Error *error = NULL;
1248 const char *device = qdict_get_str(qdict, "device");
c6db2395 1249 int64_t value = qdict_get_int(qdict, "speed");
2d47c6e9
SH
1250
1251 qmp_block_job_set_speed(device, value, &error);
1252
1253 hmp_handle_error(mon, &error);
1254}
370521a1
SH
1255
1256void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1257{
1258 Error *error = NULL;
1259 const char *device = qdict_get_str(qdict, "device");
6e37fb81 1260 bool force = qdict_get_try_bool(qdict, "force", 0);
370521a1 1261
6e37fb81
PB
1262 qmp_block_job_cancel(device, true, force, &error);
1263
1264 hmp_handle_error(mon, &error);
1265}
1266
1267void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1268{
1269 Error *error = NULL;
1270 const char *device = qdict_get_str(qdict, "device");
1271
1272 qmp_block_job_pause(device, &error);
1273
1274 hmp_handle_error(mon, &error);
1275}
1276
1277void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1278{
1279 Error *error = NULL;
1280 const char *device = qdict_get_str(qdict, "device");
1281
1282 qmp_block_job_resume(device, &error);
370521a1
SH
1283
1284 hmp_handle_error(mon, &error);
1285}
e1c37d0e 1286
aeae883b
PB
1287void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1288{
1289 Error *error = NULL;
1290 const char *device = qdict_get_str(qdict, "device");
1291
1292 qmp_block_job_complete(device, &error);
1293
1294 hmp_handle_error(mon, &error);
1295}
1296
e1c37d0e
LC
1297typedef struct MigrationStatus
1298{
1299 QEMUTimer *timer;
1300 Monitor *mon;
1301 bool is_block_migration;
1302} MigrationStatus;
1303
1304static void hmp_migrate_status_cb(void *opaque)
1305{
1306 MigrationStatus *status = opaque;
1307 MigrationInfo *info;
1308
1309 info = qmp_query_migrate(NULL);
dde3a218
SA
1310 if (!info->has_status || strcmp(info->status, "active") == 0 ||
1311 strcmp(info->status, "setup") == 0) {
e1c37d0e
LC
1312 if (info->has_disk) {
1313 int progress;
1314
1315 if (info->disk->remaining) {
1316 progress = info->disk->transferred * 100 / info->disk->total;
1317 } else {
1318 progress = 100;
1319 }
1320
1321 monitor_printf(status->mon, "Completed %d %%\r", progress);
1322 monitor_flush(status->mon);
1323 }
1324
bc72ad67 1325 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
e1c37d0e
LC
1326 } else {
1327 if (status->is_block_migration) {
1328 monitor_printf(status->mon, "\n");
1329 }
1330 monitor_resume(status->mon);
bc72ad67 1331 timer_del(status->timer);
e1c37d0e
LC
1332 g_free(status);
1333 }
1334
1335 qapi_free_MigrationInfo(info);
1336}
1337
1338void hmp_migrate(Monitor *mon, const QDict *qdict)
1339{
1340 int detach = qdict_get_try_bool(qdict, "detach", 0);
1341 int blk = qdict_get_try_bool(qdict, "blk", 0);
1342 int inc = qdict_get_try_bool(qdict, "inc", 0);
1343 const char *uri = qdict_get_str(qdict, "uri");
1344 Error *err = NULL;
1345
1346 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1347 if (err) {
1348 monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
1349 error_free(err);
1350 return;
1351 }
1352
1353 if (!detach) {
1354 MigrationStatus *status;
1355
1356 if (monitor_suspend(mon) < 0) {
1357 monitor_printf(mon, "terminal does not allow synchronous "
1358 "migration, continuing detached\n");
1359 return;
1360 }
1361
1362 status = g_malloc0(sizeof(*status));
1363 status->mon = mon;
1364 status->is_block_migration = blk || inc;
bc72ad67 1365 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
e1c37d0e 1366 status);
bc72ad67 1367 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
e1c37d0e
LC
1368 }
1369}
a15fef21
LC
1370
1371void hmp_device_del(Monitor *mon, const QDict *qdict)
1372{
1373 const char *id = qdict_get_str(qdict, "id");
1374 Error *err = NULL;
1375
1376 qmp_device_del(id, &err);
1377 hmp_handle_error(mon, &err);
1378}
783e9b48
WC
1379
1380void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1381{
e940f543 1382 Error *err = NULL;
783e9b48 1383 int paging = qdict_get_try_bool(qdict, "paging", 0);
1b7a0f75
QN
1384 int zlib = qdict_get_try_bool(qdict, "zlib", 0);
1385 int lzo = qdict_get_try_bool(qdict, "lzo", 0);
1386 int snappy = qdict_get_try_bool(qdict, "snappy", 0);
75363769 1387 const char *file = qdict_get_str(qdict, "filename");
783e9b48
WC
1388 bool has_begin = qdict_haskey(qdict, "begin");
1389 bool has_length = qdict_haskey(qdict, "length");
1390 int64_t begin = 0;
1391 int64_t length = 0;
b53ccc30 1392 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
75363769 1393 char *prot;
783e9b48 1394
1b7a0f75 1395 if (zlib + lzo + snappy > 1) {
e940f543
MA
1396 error_setg(&err, "only one of '-z|-l|-s' can be set");
1397 hmp_handle_error(mon, &err);
1b7a0f75
QN
1398 return;
1399 }
1400
1401 if (zlib) {
1402 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1403 }
1404
1405 if (lzo) {
1406 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1407 }
1408
1409 if (snappy) {
1410 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1411 }
1412
783e9b48
WC
1413 if (has_begin) {
1414 begin = qdict_get_int(qdict, "begin");
1415 }
1416 if (has_length) {
1417 length = qdict_get_int(qdict, "length");
1418 }
1419
75363769
LC
1420 prot = g_strconcat("file:", file, NULL);
1421
1422 qmp_dump_guest_memory(paging, prot, has_begin, begin, has_length, length,
e940f543
MA
1423 true, dump_format, &err);
1424 hmp_handle_error(mon, &err);
75363769 1425 g_free(prot);
783e9b48 1426}
928059a3
LC
1427
1428void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1429{
1430 Error *err = NULL;
1431 QemuOpts *opts;
1432
1433 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
84d18f06 1434 if (err) {
928059a3
LC
1435 goto out;
1436 }
1437
1438 netdev_add(opts, &err);
84d18f06 1439 if (err) {
928059a3
LC
1440 qemu_opts_del(opts);
1441 }
1442
1443out:
1444 hmp_handle_error(mon, &err);
1445}
5f964155
LC
1446
1447void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1448{
1449 const char *id = qdict_get_str(qdict, "id");
1450 Error *err = NULL;
1451
1452 qmp_netdev_del(id, &err);
1453 hmp_handle_error(mon, &err);
1454}
208c9d1b 1455
cff8b2c6
PB
1456void hmp_object_add(Monitor *mon, const QDict *qdict)
1457{
1458 Error *err = NULL;
f9f3a5ec 1459 Error *err_end = NULL;
cff8b2c6
PB
1460 QemuOpts *opts;
1461 char *type = NULL;
1462 char *id = NULL;
1463 void *dummy = NULL;
1464 OptsVisitor *ov;
1465 QDict *pdict;
1466
1467 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1468 if (err) {
1469 goto out;
1470 }
1471
1472 ov = opts_visitor_new(opts);
1473 pdict = qdict_clone_shallow(qdict);
1474
1475 visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err);
1476 if (err) {
1477 goto out_clean;
1478 }
1479
1480 qdict_del(pdict, "qom-type");
1481 visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
1482 if (err) {
f9f3a5ec 1483 goto out_end;
cff8b2c6
PB
1484 }
1485
1486 qdict_del(pdict, "id");
1487 visit_type_str(opts_get_visitor(ov), &id, "id", &err);
1488 if (err) {
f9f3a5ec 1489 goto out_end;
cff8b2c6
PB
1490 }
1491
1492 object_add(type, id, pdict, opts_get_visitor(ov), &err);
f9f3a5ec
MA
1493
1494out_end:
1495 visit_end_struct(opts_get_visitor(ov), &err_end);
1496 if (!err && err_end) {
cff8b2c6
PB
1497 qmp_object_del(id, NULL);
1498 }
f9f3a5ec 1499 error_propagate(&err, err_end);
cff8b2c6
PB
1500out_clean:
1501 opts_visitor_cleanup(ov);
1502
1503 QDECREF(pdict);
1504 qemu_opts_del(opts);
1505 g_free(id);
1506 g_free(type);
1507 g_free(dummy);
1508
1509out:
1510 hmp_handle_error(mon, &err);
1511}
1512
208c9d1b
CB
1513void hmp_getfd(Monitor *mon, const QDict *qdict)
1514{
1515 const char *fdname = qdict_get_str(qdict, "fdname");
e940f543 1516 Error *err = NULL;
208c9d1b 1517
e940f543
MA
1518 qmp_getfd(fdname, &err);
1519 hmp_handle_error(mon, &err);
208c9d1b
CB
1520}
1521
1522void hmp_closefd(Monitor *mon, const QDict *qdict)
1523{
1524 const char *fdname = qdict_get_str(qdict, "fdname");
e940f543 1525 Error *err = NULL;
208c9d1b 1526
e940f543
MA
1527 qmp_closefd(fdname, &err);
1528 hmp_handle_error(mon, &err);
208c9d1b 1529}
e4c8f004
AK
1530
1531void hmp_send_key(Monitor *mon, const QDict *qdict)
1532{
1533 const char *keys = qdict_get_str(qdict, "keys");
9f328977 1534 KeyValueList *keylist, *head = NULL, *tmp = NULL;
e4c8f004
AK
1535 int has_hold_time = qdict_haskey(qdict, "hold-time");
1536 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1537 Error *err = NULL;
1538 char keyname_buf[16];
1539 char *separator;
9f328977 1540 int keyname_len;
e4c8f004
AK
1541
1542 while (1) {
1543 separator = strchr(keys, '-');
1544 keyname_len = separator ? separator - keys : strlen(keys);
1545 pstrcpy(keyname_buf, sizeof(keyname_buf), keys);
1546
1547 /* Be compatible with old interface, convert user inputted "<" */
1548 if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) {
1549 pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
1550 keyname_len = 4;
1551 }
1552 keyname_buf[keyname_len] = 0;
1553
e4c8f004 1554 keylist = g_malloc0(sizeof(*keylist));
9f328977 1555 keylist->value = g_malloc0(sizeof(*keylist->value));
e4c8f004
AK
1556
1557 if (!head) {
1558 head = keylist;
1559 }
1560 if (tmp) {
1561 tmp->next = keylist;
1562 }
1563 tmp = keylist;
1564
9f328977
LC
1565 if (strstart(keyname_buf, "0x", NULL)) {
1566 char *endp;
1567 int value = strtoul(keyname_buf, &endp, 0);
1568 if (*endp != '\0') {
1569 goto err_out;
1570 }
1571 keylist->value->kind = KEY_VALUE_KIND_NUMBER;
1572 keylist->value->number = value;
1573 } else {
1574 int idx = index_from_key(keyname_buf);
1575 if (idx == Q_KEY_CODE_MAX) {
1576 goto err_out;
1577 }
1578 keylist->value->kind = KEY_VALUE_KIND_QCODE;
1579 keylist->value->qcode = idx;
1580 }
1581
e4c8f004
AK
1582 if (!separator) {
1583 break;
1584 }
1585 keys = separator + 1;
1586 }
1587
9f328977 1588 qmp_send_key(head, has_hold_time, hold_time, &err);
e4c8f004 1589 hmp_handle_error(mon, &err);
9f328977
LC
1590
1591out:
1592 qapi_free_KeyValueList(head);
1593 return;
1594
1595err_out:
1596 monitor_printf(mon, "invalid parameter: %s\n", keyname_buf);
1597 goto out;
e4c8f004 1598}
ad39cf6d
LC
1599
1600void hmp_screen_dump(Monitor *mon, const QDict *qdict)
1601{
1602 const char *filename = qdict_get_str(qdict, "filename");
1603 Error *err = NULL;
1604
1605 qmp_screendump(filename, &err);
1606 hmp_handle_error(mon, &err);
1607}
4057725f
PB
1608
1609void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1610{
1611 const char *uri = qdict_get_str(qdict, "uri");
1612 int writable = qdict_get_try_bool(qdict, "writable", 0);
1613 int all = qdict_get_try_bool(qdict, "all", 0);
1614 Error *local_err = NULL;
1615 BlockInfoList *block_list, *info;
1616 SocketAddress *addr;
1617
1618 if (writable && !all) {
1619 error_setg(&local_err, "-w only valid together with -a");
1620 goto exit;
1621 }
1622
1623 /* First check if the address is valid and start the server. */
1624 addr = socket_parse(uri, &local_err);
1625 if (local_err != NULL) {
1626 goto exit;
1627 }
1628
1629 qmp_nbd_server_start(addr, &local_err);
1630 qapi_free_SocketAddress(addr);
1631 if (local_err != NULL) {
1632 goto exit;
1633 }
1634
1635 if (!all) {
1636 return;
1637 }
1638
1639 /* Then try adding all block devices. If one fails, close all and
1640 * exit.
1641 */
1642 block_list = qmp_query_block(NULL);
1643
1644 for (info = block_list; info; info = info->next) {
1645 if (!info->value->has_inserted) {
1646 continue;
1647 }
1648
1649 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1650
1651 if (local_err != NULL) {
1652 qmp_nbd_server_stop(NULL);
1653 break;
1654 }
1655 }
1656
1657 qapi_free_BlockInfoList(block_list);
1658
1659exit:
1660 hmp_handle_error(mon, &local_err);
1661}
1662
1663void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1664{
1665 const char *device = qdict_get_str(qdict, "device");
1666 int writable = qdict_get_try_bool(qdict, "writable", 0);
1667 Error *local_err = NULL;
1668
1669 qmp_nbd_server_add(device, true, writable, &local_err);
1670
1671 if (local_err != NULL) {
1672 hmp_handle_error(mon, &local_err);
1673 }
1674}
1675
1676void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1677{
e940f543 1678 Error *err = NULL;
4057725f 1679
e940f543
MA
1680 qmp_nbd_server_stop(&err);
1681 hmp_handle_error(mon, &err);
4057725f 1682}
f1088908 1683
abf23329
JH
1684void hmp_cpu_add(Monitor *mon, const QDict *qdict)
1685{
1686 int cpuid;
1687 Error *err = NULL;
1688
1689 cpuid = qdict_get_int(qdict, "id");
1690 qmp_cpu_add(cpuid, &err);
1691 hmp_handle_error(mon, &err);
1692}
1693
f1088908
GH
1694void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1695{
1696 const char *args = qdict_get_str(qdict, "args");
1697 Error *err = NULL;
1698 QemuOpts *opts;
1699
1700 opts = qemu_opts_parse(qemu_find_opts("chardev"), args, 1);
1701 if (opts == NULL) {
312fd5f2 1702 error_setg(&err, "Parsing chardev args failed");
f1088908
GH
1703 } else {
1704 qemu_chr_new_from_opts(opts, NULL, &err);
1705 }
1706 hmp_handle_error(mon, &err);
1707}
1708
1709void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1710{
1711 Error *local_err = NULL;
1712
1713 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1714 hmp_handle_error(mon, &local_err);
1715}
587da2c3
KW
1716
1717void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1718{
1719 BlockDriverState *bs;
1720 const char* device = qdict_get_str(qdict, "device");
1721 const char* command = qdict_get_str(qdict, "command");
1722 Error *err = NULL;
1723
1724 bs = bdrv_find(device);
1725 if (bs) {
1726 qemuio_command(bs, command);
1727 } else {
1728 error_set(&err, QERR_DEVICE_NOT_FOUND, device);
1729 }
1730
1731 hmp_handle_error(mon, &err);
1732}
ab2d0531
PB
1733
1734void hmp_object_del(Monitor *mon, const QDict *qdict)
1735{
1736 const char *id = qdict_get_str(qdict, "id");
1737 Error *err = NULL;
1738
1739 qmp_object_del(id, &err);
1740 hmp_handle_error(mon, &err);
1741}
eb1539b2
HT
1742
1743void hmp_info_memdev(Monitor *mon, const QDict *qdict)
1744{
1745 Error *err = NULL;
1746 MemdevList *memdev_list = qmp_query_memdev(&err);
1747 MemdevList *m = memdev_list;
1748 StringOutputVisitor *ov;
976620ac 1749 char *str;
eb1539b2
HT
1750 int i = 0;
1751
1752
1753 while (m) {
1754 ov = string_output_visitor_new(false);
1755 visit_type_uint16List(string_output_get_visitor(ov),
1756 &m->value->host_nodes, NULL, NULL);
8f4e5ac3 1757 monitor_printf(mon, "memory backend: %d\n", i);
eb1539b2
HT
1758 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
1759 monitor_printf(mon, " merge: %s\n",
1760 m->value->merge ? "true" : "false");
1761 monitor_printf(mon, " dump: %s\n",
1762 m->value->dump ? "true" : "false");
1763 monitor_printf(mon, " prealloc: %s\n",
1764 m->value->prealloc ? "true" : "false");
1765 monitor_printf(mon, " policy: %s\n",
1766 HostMemPolicy_lookup[m->value->policy]);
976620ac
CF
1767 str = string_output_get_string(ov);
1768 monitor_printf(mon, " host nodes: %s\n", str);
eb1539b2 1769
976620ac 1770 g_free(str);
eb1539b2
HT
1771 string_output_visitor_cleanup(ov);
1772 m = m->next;
1773 i++;
1774 }
1775
1776 monitor_printf(mon, "\n");
ecaf54a0
CF
1777
1778 qapi_free_MemdevList(memdev_list);
eb1539b2 1779}
a631892f
ZG
1780
1781void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
1782{
1783 Error *err = NULL;
1784 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
1785 MemoryDeviceInfoList *info;
1786 MemoryDeviceInfo *value;
1787 PCDIMMDeviceInfo *di;
1788
1789 for (info = info_list; info; info = info->next) {
1790 value = info->value;
1791
1792 if (value) {
1793 switch (value->kind) {
1794 case MEMORY_DEVICE_INFO_KIND_DIMM:
1795 di = value->dimm;
1796
1797 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1798 MemoryDeviceInfoKind_lookup[value->kind],
1799 di->id ? di->id : "");
1800 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
1801 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
1802 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
1803 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
1804 monitor_printf(mon, " memdev: %s\n", di->memdev);
1805 monitor_printf(mon, " hotplugged: %s\n",
1806 di->hotplugged ? "true" : "false");
1807 monitor_printf(mon, " hotpluggable: %s\n",
1808 di->hotpluggable ? "true" : "false");
1809 break;
1810 default:
1811 break;
1812 }
1813 }
1814 }
1815
1816 qapi_free_MemoryDeviceInfoList(info_list);
1817}
This page took 0.462926 seconds and 4 git commands to generate.