]> git.proxmox.com Git - qemu.git/blame - hmp.c
net: notify iothread after flushing queue
[qemu.git] / hmp.c
CommitLineData
48a32bed
AL
1/*
2 * Human Monitor Interface
3 *
4 * Copyright IBM, Corp. 2011
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
6b620ca3
PB
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
48a32bed
AL
14 */
15
16#include "hmp.h"
928059a3
LC
17#include "net.h"
18#include "qemu-option.h"
e1c37d0e 19#include "qemu-timer.h"
48a32bed 20#include "qmp-commands.h"
37003adf 21#include "monitor.h"
48a32bed 22
0cfd6a9a
LC
23static void hmp_handle_error(Monitor *mon, Error **errp)
24{
25 if (error_is_set(errp)) {
26 monitor_printf(mon, "%s\n", error_get_pretty(*errp));
27 error_free(*errp);
28 }
29}
30
48a32bed
AL
31void hmp_info_name(Monitor *mon)
32{
33 NameInfo *info;
34
35 info = qmp_query_name(NULL);
36 if (info->has_name) {
37 monitor_printf(mon, "%s\n", info->name);
38 }
39 qapi_free_NameInfo(info);
40}
b9c15f16
LC
41
42void hmp_info_version(Monitor *mon)
43{
44 VersionInfo *info;
45
46 info = qmp_query_version(NULL);
47
48 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
49 info->qemu.major, info->qemu.minor, info->qemu.micro,
50 info->package);
51
52 qapi_free_VersionInfo(info);
53}
292a2602
LC
54
55void hmp_info_kvm(Monitor *mon)
56{
57 KvmInfo *info;
58
59 info = qmp_query_kvm(NULL);
60 monitor_printf(mon, "kvm support: ");
61 if (info->present) {
62 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
63 } else {
64 monitor_printf(mon, "not compiled\n");
65 }
66
67 qapi_free_KvmInfo(info);
68}
69
1fa9a5e4
LC
70void hmp_info_status(Monitor *mon)
71{
72 StatusInfo *info;
73
74 info = qmp_query_status(NULL);
75
76 monitor_printf(mon, "VM status: %s%s",
77 info->running ? "running" : "paused",
78 info->singlestep ? " (single step mode)" : "");
79
80 if (!info->running && info->status != RUN_STATE_PAUSED) {
81 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
82 }
83
84 monitor_printf(mon, "\n");
85
86 qapi_free_StatusInfo(info);
87}
88
efab767e
LC
89void hmp_info_uuid(Monitor *mon)
90{
91 UuidInfo *info;
92
93 info = qmp_query_uuid(NULL);
94 monitor_printf(mon, "%s\n", info->UUID);
95 qapi_free_UuidInfo(info);
96}
c5a415a0
LC
97
98void hmp_info_chardev(Monitor *mon)
99{
100 ChardevInfoList *char_info, *info;
101
102 char_info = qmp_query_chardev(NULL);
103 for (info = char_info; info; info = info->next) {
104 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
105 info->value->filename);
106 }
107
108 qapi_free_ChardevInfoList(char_info);
109}
7a7f325e 110
e235cec3
LC
111void hmp_info_mice(Monitor *mon)
112{
113 MouseInfoList *mice_list, *mouse;
114
115 mice_list = qmp_query_mice(NULL);
116 if (!mice_list) {
117 monitor_printf(mon, "No mouse devices connected\n");
118 return;
119 }
120
121 for (mouse = mice_list; mouse; mouse = mouse->next) {
122 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
123 mouse->value->current ? '*' : ' ',
124 mouse->value->index, mouse->value->name,
125 mouse->value->absolute ? " (absolute)" : "");
126 }
127
128 qapi_free_MouseInfoList(mice_list);
129}
130
791e7c82
LC
131void hmp_info_migrate(Monitor *mon)
132{
133 MigrationInfo *info;
bbf6da32 134 MigrationCapabilityStatusList *caps, *cap;
791e7c82
LC
135
136 info = qmp_query_migrate(NULL);
bbf6da32
OW
137 caps = qmp_query_migrate_capabilities(NULL);
138
139 /* do not display parameters during setup */
140 if (info->has_status && caps) {
141 monitor_printf(mon, "capabilities: ");
142 for (cap = caps; cap; cap = cap->next) {
143 monitor_printf(mon, "%s: %s ",
144 MigrationCapability_lookup[cap->value->capability],
145 cap->value->state ? "on" : "off");
146 }
147 monitor_printf(mon, "\n");
148 }
791e7c82
LC
149
150 if (info->has_status) {
151 monitor_printf(mon, "Migration status: %s\n", info->status);
7aa939af
JQ
152 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
153 info->total_time);
791e7c82
LC
154 }
155
156 if (info->has_ram) {
157 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
158 info->ram->transferred >> 10);
159 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
160 info->ram->remaining >> 10);
161 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
162 info->ram->total >> 10);
004d4c10
OW
163 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
164 info->ram->duplicate);
165 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
166 info->ram->normal);
167 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
168 info->ram->normal_bytes >> 10);
791e7c82
LC
169 }
170
171 if (info->has_disk) {
172 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
173 info->disk->transferred >> 10);
174 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
175 info->disk->remaining >> 10);
176 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
177 info->disk->total >> 10);
178 }
179
f36d55af
OW
180 if (info->has_xbzrle_cache) {
181 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
182 info->xbzrle_cache->cache_size);
183 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
184 info->xbzrle_cache->bytes >> 10);
185 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
186 info->xbzrle_cache->pages);
187 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
188 info->xbzrle_cache->cache_miss);
189 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
190 info->xbzrle_cache->overflow);
191 }
192
791e7c82 193 qapi_free_MigrationInfo(info);
bbf6da32
OW
194 qapi_free_MigrationCapabilityStatusList(caps);
195}
196
197void hmp_info_migrate_capabilities(Monitor *mon)
198{
199 MigrationCapabilityStatusList *caps, *cap;
200
201 caps = qmp_query_migrate_capabilities(NULL);
202
203 if (caps) {
204 monitor_printf(mon, "capabilities: ");
205 for (cap = caps; cap; cap = cap->next) {
206 monitor_printf(mon, "%s: %s ",
207 MigrationCapability_lookup[cap->value->capability],
208 cap->value->state ? "on" : "off");
209 }
210 monitor_printf(mon, "\n");
211 }
212
213 qapi_free_MigrationCapabilityStatusList(caps);
791e7c82
LC
214}
215
9e1ba4cc
OW
216void hmp_info_migrate_cache_size(Monitor *mon)
217{
218 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
219 qmp_query_migrate_cache_size(NULL) >> 10);
220}
221
de0b36b6
LC
222void hmp_info_cpus(Monitor *mon)
223{
224 CpuInfoList *cpu_list, *cpu;
225
226 cpu_list = qmp_query_cpus(NULL);
227
228 for (cpu = cpu_list; cpu; cpu = cpu->next) {
229 int active = ' ';
230
231 if (cpu->value->CPU == monitor_get_cpu_index()) {
232 active = '*';
233 }
234
235 monitor_printf(mon, "%c CPU #%" PRId64 ": ", active, cpu->value->CPU);
236
237 if (cpu->value->has_pc) {
238 monitor_printf(mon, "pc=0x%016" PRIx64, cpu->value->pc);
239 }
240 if (cpu->value->has_nip) {
241 monitor_printf(mon, "nip=0x%016" PRIx64, cpu->value->nip);
242 }
243 if (cpu->value->has_npc) {
244 monitor_printf(mon, "pc=0x%016" PRIx64, cpu->value->pc);
245 monitor_printf(mon, "npc=0x%016" PRIx64, cpu->value->npc);
246 }
247 if (cpu->value->has_PC) {
248 monitor_printf(mon, "PC=0x%016" PRIx64, cpu->value->PC);
249 }
250
251 if (cpu->value->halted) {
252 monitor_printf(mon, " (halted)");
253 }
254
255 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
256 }
257
258 qapi_free_CpuInfoList(cpu_list);
259}
260
b2023818
LC
261void hmp_info_block(Monitor *mon)
262{
263 BlockInfoList *block_list, *info;
264
265 block_list = qmp_query_block(NULL);
266
267 for (info = block_list; info; info = info->next) {
268 monitor_printf(mon, "%s: removable=%d",
269 info->value->device, info->value->removable);
270
271 if (info->value->removable) {
272 monitor_printf(mon, " locked=%d", info->value->locked);
273 monitor_printf(mon, " tray-open=%d", info->value->tray_open);
274 }
275
276 if (info->value->has_io_status) {
277 monitor_printf(mon, " io-status=%s",
278 BlockDeviceIoStatus_lookup[info->value->io_status]);
279 }
280
281 if (info->value->has_inserted) {
282 monitor_printf(mon, " file=");
283 monitor_print_filename(mon, info->value->inserted->file);
284
285 if (info->value->inserted->has_backing_file) {
286 monitor_printf(mon, " backing_file=");
287 monitor_print_filename(mon, info->value->inserted->backing_file);
75115d95
BC
288 monitor_printf(mon, " backing_file_depth=%" PRId64,
289 info->value->inserted->backing_file_depth);
b2023818
LC
290 }
291 monitor_printf(mon, " ro=%d drv=%s encrypted=%d",
292 info->value->inserted->ro,
293 info->value->inserted->drv,
294 info->value->inserted->encrypted);
727f005e
ZYW
295
296 monitor_printf(mon, " bps=%" PRId64 " bps_rd=%" PRId64
297 " bps_wr=%" PRId64 " iops=%" PRId64
298 " iops_rd=%" PRId64 " iops_wr=%" PRId64,
299 info->value->inserted->bps,
300 info->value->inserted->bps_rd,
301 info->value->inserted->bps_wr,
302 info->value->inserted->iops,
303 info->value->inserted->iops_rd,
304 info->value->inserted->iops_wr);
b2023818
LC
305 } else {
306 monitor_printf(mon, " [not inserted]");
307 }
308
309 monitor_printf(mon, "\n");
310 }
311
312 qapi_free_BlockInfoList(block_list);
313}
314
f11f57e4
LC
315void hmp_info_blockstats(Monitor *mon)
316{
317 BlockStatsList *stats_list, *stats;
318
319 stats_list = qmp_query_blockstats(NULL);
320
321 for (stats = stats_list; stats; stats = stats->next) {
322 if (!stats->value->has_device) {
323 continue;
324 }
325
326 monitor_printf(mon, "%s:", stats->value->device);
327 monitor_printf(mon, " rd_bytes=%" PRId64
328 " wr_bytes=%" PRId64
329 " rd_operations=%" PRId64
330 " wr_operations=%" PRId64
331 " flush_operations=%" PRId64
332 " wr_total_time_ns=%" PRId64
333 " rd_total_time_ns=%" PRId64
334 " flush_total_time_ns=%" PRId64
335 "\n",
336 stats->value->stats->rd_bytes,
337 stats->value->stats->wr_bytes,
338 stats->value->stats->rd_operations,
339 stats->value->stats->wr_operations,
340 stats->value->stats->flush_operations,
341 stats->value->stats->wr_total_time_ns,
342 stats->value->stats->rd_total_time_ns,
343 stats->value->stats->flush_total_time_ns);
344 }
345
346 qapi_free_BlockStatsList(stats_list);
347}
348
2b54aa87
LC
349void hmp_info_vnc(Monitor *mon)
350{
351 VncInfo *info;
352 Error *err = NULL;
353 VncClientInfoList *client;
354
355 info = qmp_query_vnc(&err);
356 if (err) {
357 monitor_printf(mon, "%s\n", error_get_pretty(err));
358 error_free(err);
359 return;
360 }
361
362 if (!info->enabled) {
363 monitor_printf(mon, "Server: disabled\n");
364 goto out;
365 }
366
367 monitor_printf(mon, "Server:\n");
368 if (info->has_host && info->has_service) {
369 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
370 }
371 if (info->has_auth) {
372 monitor_printf(mon, " auth: %s\n", info->auth);
373 }
374
375 if (!info->has_clients || info->clients == NULL) {
376 monitor_printf(mon, "Client: none\n");
377 } else {
378 for (client = info->clients; client; client = client->next) {
379 monitor_printf(mon, "Client:\n");
380 monitor_printf(mon, " address: %s:%s\n",
381 client->value->host, client->value->service);
382 monitor_printf(mon, " x509_dname: %s\n",
383 client->value->x509_dname ?
384 client->value->x509_dname : "none");
385 monitor_printf(mon, " username: %s\n",
386 client->value->has_sasl_username ?
387 client->value->sasl_username : "none");
388 }
389 }
390
391out:
392 qapi_free_VncInfo(info);
393}
394
d1f29646
LC
395void hmp_info_spice(Monitor *mon)
396{
397 SpiceChannelList *chan;
398 SpiceInfo *info;
399
400 info = qmp_query_spice(NULL);
401
402 if (!info->enabled) {
403 monitor_printf(mon, "Server: disabled\n");
404 goto out;
405 }
406
407 monitor_printf(mon, "Server:\n");
408 if (info->has_port) {
409 monitor_printf(mon, " address: %s:%" PRId64 "\n",
410 info->host, info->port);
411 }
412 if (info->has_tls_port) {
413 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
414 info->host, info->tls_port);
415 }
38a01d68
YH
416 monitor_printf(mon, " migrated: %s\n",
417 info->migrated ? "true" : "false");
d1f29646
LC
418 monitor_printf(mon, " auth: %s\n", info->auth);
419 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
4efee029
AL
420 monitor_printf(mon, " mouse-mode: %s\n",
421 SpiceQueryMouseMode_lookup[info->mouse_mode]);
d1f29646
LC
422
423 if (!info->has_channels || info->channels == NULL) {
424 monitor_printf(mon, "Channels: none\n");
425 } else {
426 for (chan = info->channels; chan; chan = chan->next) {
427 monitor_printf(mon, "Channel:\n");
428 monitor_printf(mon, " address: %s:%s%s\n",
429 chan->value->host, chan->value->port,
430 chan->value->tls ? " [tls]" : "");
431 monitor_printf(mon, " session: %" PRId64 "\n",
432 chan->value->connection_id);
433 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
434 chan->value->channel_type, chan->value->channel_id);
435 }
436 }
437
438out:
439 qapi_free_SpiceInfo(info);
440}
441
96637bcd
LC
442void hmp_info_balloon(Monitor *mon)
443{
444 BalloonInfo *info;
445 Error *err = NULL;
446
447 info = qmp_query_balloon(&err);
448 if (err) {
449 monitor_printf(mon, "%s\n", error_get_pretty(err));
450 error_free(err);
451 return;
452 }
453
454 monitor_printf(mon, "balloon: actual=%" PRId64, info->actual >> 20);
455 if (info->has_mem_swapped_in) {
456 monitor_printf(mon, " mem_swapped_in=%" PRId64, info->mem_swapped_in);
457 }
458 if (info->has_mem_swapped_out) {
459 monitor_printf(mon, " mem_swapped_out=%" PRId64, info->mem_swapped_out);
460 }
461 if (info->has_major_page_faults) {
462 monitor_printf(mon, " major_page_faults=%" PRId64,
463 info->major_page_faults);
464 }
465 if (info->has_minor_page_faults) {
466 monitor_printf(mon, " minor_page_faults=%" PRId64,
467 info->minor_page_faults);
468 }
469 if (info->has_free_mem) {
470 monitor_printf(mon, " free_mem=%" PRId64, info->free_mem);
471 }
472 if (info->has_total_mem) {
473 monitor_printf(mon, " total_mem=%" PRId64, info->total_mem);
474 }
475
476 monitor_printf(mon, "\n");
477
478 qapi_free_BalloonInfo(info);
479}
480
79627472
LC
481static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
482{
483 PciMemoryRegionList *region;
484
485 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
486 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
487 dev->slot, dev->function);
488 monitor_printf(mon, " ");
489
490 if (dev->class_info.has_desc) {
491 monitor_printf(mon, "%s", dev->class_info.desc);
492 } else {
493 monitor_printf(mon, "Class %04" PRId64, dev->class_info.class);
494 }
495
496 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
497 dev->id.vendor, dev->id.device);
498
499 if (dev->has_irq) {
500 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
501 }
502
503 if (dev->has_pci_bridge) {
504 monitor_printf(mon, " BUS %" PRId64 ".\n",
505 dev->pci_bridge->bus.number);
506 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
507 dev->pci_bridge->bus.secondary);
508 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
509 dev->pci_bridge->bus.subordinate);
510
511 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
512 dev->pci_bridge->bus.io_range->base,
513 dev->pci_bridge->bus.io_range->limit);
514
515 monitor_printf(mon,
516 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
517 dev->pci_bridge->bus.memory_range->base,
518 dev->pci_bridge->bus.memory_range->limit);
519
520 monitor_printf(mon, " prefetchable memory range "
521 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
522 dev->pci_bridge->bus.prefetchable_range->base,
523 dev->pci_bridge->bus.prefetchable_range->limit);
524 }
525
526 for (region = dev->regions; region; region = region->next) {
527 uint64_t addr, size;
528
529 addr = region->value->address;
530 size = region->value->size;
531
532 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
533
534 if (!strcmp(region->value->type, "io")) {
535 monitor_printf(mon, "I/O at 0x%04" PRIx64
536 " [0x%04" PRIx64 "].\n",
537 addr, addr + size - 1);
538 } else {
539 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
540 " [0x%08" PRIx64 "].\n",
541 region->value->mem_type_64 ? 64 : 32,
542 region->value->prefetch ? " prefetchable" : "",
543 addr, addr + size - 1);
544 }
545 }
546
547 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
548
549 if (dev->has_pci_bridge) {
550 if (dev->pci_bridge->has_devices) {
551 PciDeviceInfoList *cdev;
552 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
553 hmp_info_pci_device(mon, cdev->value);
554 }
555 }
556 }
557}
558
559void hmp_info_pci(Monitor *mon)
560{
f46cee37 561 PciInfoList *info_list, *info;
79627472
LC
562 Error *err = NULL;
563
f46cee37 564 info_list = qmp_query_pci(&err);
79627472
LC
565 if (err) {
566 monitor_printf(mon, "PCI devices not supported\n");
567 error_free(err);
568 return;
569 }
570
f46cee37 571 for (info = info_list; info; info = info->next) {
79627472
LC
572 PciDeviceInfoList *dev;
573
574 for (dev = info->value->devices; dev; dev = dev->next) {
575 hmp_info_pci_device(mon, dev->value);
576 }
577 }
578
f46cee37 579 qapi_free_PciInfoList(info_list);
79627472
LC
580}
581
fb5458cd
SH
582void hmp_info_block_jobs(Monitor *mon)
583{
584 BlockJobInfoList *list;
585 Error *err = NULL;
586
587 list = qmp_query_block_jobs(&err);
588 assert(!err);
589
590 if (!list) {
591 monitor_printf(mon, "No active jobs\n");
592 return;
593 }
594
595 while (list) {
596 if (strcmp(list->value->type, "stream") == 0) {
597 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
598 " of %" PRId64 " bytes, speed limit %" PRId64
599 " bytes/s\n",
600 list->value->device,
601 list->value->offset,
602 list->value->len,
603 list->value->speed);
604 } else {
605 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
606 " of %" PRId64 " bytes, speed limit %" PRId64
607 " bytes/s\n",
608 list->value->type,
609 list->value->device,
610 list->value->offset,
611 list->value->len,
612 list->value->speed);
613 }
614 list = list->next;
615 }
616}
617
7a7f325e
LC
618void hmp_quit(Monitor *mon, const QDict *qdict)
619{
620 monitor_suspend(mon);
621 qmp_quit(NULL);
622}
5f158f21
LC
623
624void hmp_stop(Monitor *mon, const QDict *qdict)
625{
626 qmp_stop(NULL);
627}
38d22653
LC
628
629void hmp_system_reset(Monitor *mon, const QDict *qdict)
630{
631 qmp_system_reset(NULL);
632}
5bc465e4
LC
633
634void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
635{
636 qmp_system_powerdown(NULL);
637}
755f1968
LC
638
639void hmp_cpu(Monitor *mon, const QDict *qdict)
640{
641 int64_t cpu_index;
642
643 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
644 use it are converted to the QAPI */
645 cpu_index = qdict_get_int(qdict, "index");
646 if (monitor_set_cpu(cpu_index) < 0) {
647 monitor_printf(mon, "invalid CPU index\n");
648 }
649}
0cfd6a9a
LC
650
651void hmp_memsave(Monitor *mon, const QDict *qdict)
652{
653 uint32_t size = qdict_get_int(qdict, "size");
654 const char *filename = qdict_get_str(qdict, "filename");
655 uint64_t addr = qdict_get_int(qdict, "val");
656 Error *errp = NULL;
657
658 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &errp);
659 hmp_handle_error(mon, &errp);
660}
6d3962bf
LC
661
662void hmp_pmemsave(Monitor *mon, const QDict *qdict)
663{
664 uint32_t size = qdict_get_int(qdict, "size");
665 const char *filename = qdict_get_str(qdict, "filename");
666 uint64_t addr = qdict_get_int(qdict, "val");
667 Error *errp = NULL;
668
669 qmp_pmemsave(addr, size, filename, &errp);
670 hmp_handle_error(mon, &errp);
671}
e42e818b
LC
672
673static void hmp_cont_cb(void *opaque, int err)
674{
e42e818b 675 if (!err) {
8b7f6fbb 676 qmp_cont(NULL);
e42e818b
LC
677 }
678}
679
8b7f6fbb
LC
680static bool key_is_missing(const BlockInfo *bdev)
681{
682 return (bdev->inserted && bdev->inserted->encryption_key_missing);
683}
684
e42e818b
LC
685void hmp_cont(Monitor *mon, const QDict *qdict)
686{
8b7f6fbb 687 BlockInfoList *bdev_list, *bdev;
e42e818b
LC
688 Error *errp = NULL;
689
8b7f6fbb
LC
690 bdev_list = qmp_query_block(NULL);
691 for (bdev = bdev_list; bdev; bdev = bdev->next) {
692 if (key_is_missing(bdev->value)) {
693 monitor_read_block_device_key(mon, bdev->value->device,
694 hmp_cont_cb, NULL);
695 goto out;
e42e818b 696 }
e42e818b 697 }
8b7f6fbb
LC
698
699 qmp_cont(&errp);
700 hmp_handle_error(mon, &errp);
701
702out:
703 qapi_free_BlockInfoList(bdev_list);
e42e818b 704}
ab49ab5c 705
9b9df25a
GH
706void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
707{
708 qmp_system_wakeup(NULL);
709}
710
ab49ab5c
LC
711void hmp_inject_nmi(Monitor *mon, const QDict *qdict)
712{
713 Error *errp = NULL;
714
715 qmp_inject_nmi(&errp);
716 hmp_handle_error(mon, &errp);
717}
4b37156c
LC
718
719void hmp_set_link(Monitor *mon, const QDict *qdict)
720{
721 const char *name = qdict_get_str(qdict, "name");
722 int up = qdict_get_bool(qdict, "up");
723 Error *errp = NULL;
724
725 qmp_set_link(name, up, &errp);
726 hmp_handle_error(mon, &errp);
727}
a4dea8a9
LC
728
729void hmp_block_passwd(Monitor *mon, const QDict *qdict)
730{
731 const char *device = qdict_get_str(qdict, "device");
732 const char *password = qdict_get_str(qdict, "password");
733 Error *errp = NULL;
734
735 qmp_block_passwd(device, password, &errp);
736 hmp_handle_error(mon, &errp);
737}
d72f3264
LC
738
739void hmp_balloon(Monitor *mon, const QDict *qdict)
740{
741 int64_t value = qdict_get_int(qdict, "value");
742 Error *errp = NULL;
743
744 qmp_balloon(value, &errp);
745 if (error_is_set(&errp)) {
746 monitor_printf(mon, "balloon: %s\n", error_get_pretty(errp));
747 error_free(errp);
748 }
749}
5e7caacb
LC
750
751void hmp_block_resize(Monitor *mon, const QDict *qdict)
752{
753 const char *device = qdict_get_str(qdict, "device");
754 int64_t size = qdict_get_int(qdict, "size");
755 Error *errp = NULL;
756
757 qmp_block_resize(device, size, &errp);
758 hmp_handle_error(mon, &errp);
759}
6106e249
LC
760
761void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
762{
763 const char *device = qdict_get_str(qdict, "device");
764 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
765 const char *format = qdict_get_try_str(qdict, "format");
6cc2a415
PB
766 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
767 enum NewImageMode mode;
6106e249
LC
768 Error *errp = NULL;
769
770 if (!filename) {
771 /* In the future, if 'snapshot-file' is not specified, the snapshot
772 will be taken internally. Today it's actually required. */
773 error_set(&errp, QERR_MISSING_PARAMETER, "snapshot-file");
774 hmp_handle_error(mon, &errp);
775 return;
776 }
777
6cc2a415
PB
778 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
779 qmp_blockdev_snapshot_sync(device, filename, !!format, format,
780 true, mode, &errp);
6106e249
LC
781 hmp_handle_error(mon, &errp);
782}
6cdedb07
LC
783
784void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
785{
786 qmp_migrate_cancel(NULL);
787}
4f0a993b
LC
788
789void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
790{
791 double value = qdict_get_double(qdict, "value");
792 qmp_migrate_set_downtime(value, NULL);
793}
3dc85383 794
9e1ba4cc
OW
795void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
796{
797 int64_t value = qdict_get_int(qdict, "value");
798 Error *err = NULL;
799
800 qmp_migrate_set_cache_size(value, &err);
801 if (err) {
802 monitor_printf(mon, "%s\n", error_get_pretty(err));
803 error_free(err);
804 return;
805 }
806}
807
3dc85383
LC
808void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
809{
810 int64_t value = qdict_get_int(qdict, "value");
811 qmp_migrate_set_speed(value, NULL);
812}
fbf796fd 813
00458433
OW
814void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
815{
816 const char *cap = qdict_get_str(qdict, "capability");
817 bool state = qdict_get_bool(qdict, "state");
818 Error *err = NULL;
819 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
820 int i;
821
822 for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
823 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
824 caps->value = g_malloc0(sizeof(*caps->value));
825 caps->value->capability = i;
826 caps->value->state = state;
827 caps->next = NULL;
828 qmp_migrate_set_capabilities(caps, &err);
829 break;
830 }
831 }
832
833 if (i == MIGRATION_CAPABILITY_MAX) {
834 error_set(&err, QERR_INVALID_PARAMETER, cap);
835 }
836
837 qapi_free_MigrationCapabilityStatusList(caps);
838
839 if (err) {
840 monitor_printf(mon, "migrate_set_parameter: %s\n",
841 error_get_pretty(err));
842 error_free(err);
843 }
844}
845
fbf796fd
LC
846void hmp_set_password(Monitor *mon, const QDict *qdict)
847{
848 const char *protocol = qdict_get_str(qdict, "protocol");
849 const char *password = qdict_get_str(qdict, "password");
850 const char *connected = qdict_get_try_str(qdict, "connected");
851 Error *err = NULL;
852
853 qmp_set_password(protocol, password, !!connected, connected, &err);
854 hmp_handle_error(mon, &err);
855}
9ad5372d
LC
856
857void hmp_expire_password(Monitor *mon, const QDict *qdict)
858{
859 const char *protocol = qdict_get_str(qdict, "protocol");
860 const char *whenstr = qdict_get_str(qdict, "time");
861 Error *err = NULL;
862
863 qmp_expire_password(protocol, whenstr, &err);
864 hmp_handle_error(mon, &err);
865}
c245b6a3
LC
866
867void hmp_eject(Monitor *mon, const QDict *qdict)
868{
869 int force = qdict_get_try_bool(qdict, "force", 0);
870 const char *device = qdict_get_str(qdict, "device");
871 Error *err = NULL;
872
873 qmp_eject(device, true, force, &err);
874 hmp_handle_error(mon, &err);
875}
333a96ec
LC
876
877static void hmp_change_read_arg(Monitor *mon, const char *password,
878 void *opaque)
879{
880 qmp_change_vnc_password(password, NULL);
881 monitor_read_command(mon, 1);
882}
883
333a96ec
LC
884void hmp_change(Monitor *mon, const QDict *qdict)
885{
886 const char *device = qdict_get_str(qdict, "device");
887 const char *target = qdict_get_str(qdict, "target");
888 const char *arg = qdict_get_try_str(qdict, "arg");
889 Error *err = NULL;
890
891 if (strcmp(device, "vnc") == 0 &&
892 (strcmp(target, "passwd") == 0 ||
893 strcmp(target, "password") == 0)) {
894 if (!arg) {
895 monitor_read_password(mon, hmp_change_read_arg, NULL);
896 return;
897 }
898 }
899
900 qmp_change(device, target, !!arg, arg, &err);
ab878ddf
LC
901 if (error_is_set(&err) &&
902 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
eef5ad10
LC
903 error_free(err);
904 monitor_read_block_device_key(mon, device, NULL, NULL);
333a96ec
LC
905 return;
906 }
907 hmp_handle_error(mon, &err);
908}
80047da5
LC
909
910void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
911{
912 Error *err = NULL;
913
914 qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
915 qdict_get_int(qdict, "bps"),
916 qdict_get_int(qdict, "bps_rd"),
917 qdict_get_int(qdict, "bps_wr"),
918 qdict_get_int(qdict, "iops"),
919 qdict_get_int(qdict, "iops_rd"),
920 qdict_get_int(qdict, "iops_wr"), &err);
921 hmp_handle_error(mon, &err);
922}
12bd451f
SH
923
924void hmp_block_stream(Monitor *mon, const QDict *qdict)
925{
926 Error *error = NULL;
927 const char *device = qdict_get_str(qdict, "device");
928 const char *base = qdict_get_try_str(qdict, "base");
c83c66c3 929 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
12bd451f 930
c83c66c3
SH
931 qmp_block_stream(device, base != NULL, base,
932 qdict_haskey(qdict, "speed"), speed, &error);
12bd451f
SH
933
934 hmp_handle_error(mon, &error);
935}
2d47c6e9
SH
936
937void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
938{
939 Error *error = NULL;
940 const char *device = qdict_get_str(qdict, "device");
c6db2395 941 int64_t value = qdict_get_int(qdict, "speed");
2d47c6e9
SH
942
943 qmp_block_job_set_speed(device, value, &error);
944
945 hmp_handle_error(mon, &error);
946}
370521a1
SH
947
948void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
949{
950 Error *error = NULL;
951 const char *device = qdict_get_str(qdict, "device");
952
953 qmp_block_job_cancel(device, &error);
954
955 hmp_handle_error(mon, &error);
956}
e1c37d0e
LC
957
958typedef struct MigrationStatus
959{
960 QEMUTimer *timer;
961 Monitor *mon;
962 bool is_block_migration;
963} MigrationStatus;
964
965static void hmp_migrate_status_cb(void *opaque)
966{
967 MigrationStatus *status = opaque;
968 MigrationInfo *info;
969
970 info = qmp_query_migrate(NULL);
971 if (!info->has_status || strcmp(info->status, "active") == 0) {
972 if (info->has_disk) {
973 int progress;
974
975 if (info->disk->remaining) {
976 progress = info->disk->transferred * 100 / info->disk->total;
977 } else {
978 progress = 100;
979 }
980
981 monitor_printf(status->mon, "Completed %d %%\r", progress);
982 monitor_flush(status->mon);
983 }
984
985 qemu_mod_timer(status->timer, qemu_get_clock_ms(rt_clock) + 1000);
986 } else {
987 if (status->is_block_migration) {
988 monitor_printf(status->mon, "\n");
989 }
990 monitor_resume(status->mon);
991 qemu_del_timer(status->timer);
992 g_free(status);
993 }
994
995 qapi_free_MigrationInfo(info);
996}
997
998void hmp_migrate(Monitor *mon, const QDict *qdict)
999{
1000 int detach = qdict_get_try_bool(qdict, "detach", 0);
1001 int blk = qdict_get_try_bool(qdict, "blk", 0);
1002 int inc = qdict_get_try_bool(qdict, "inc", 0);
1003 const char *uri = qdict_get_str(qdict, "uri");
1004 Error *err = NULL;
1005
1006 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1007 if (err) {
1008 monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
1009 error_free(err);
1010 return;
1011 }
1012
1013 if (!detach) {
1014 MigrationStatus *status;
1015
1016 if (monitor_suspend(mon) < 0) {
1017 monitor_printf(mon, "terminal does not allow synchronous "
1018 "migration, continuing detached\n");
1019 return;
1020 }
1021
1022 status = g_malloc0(sizeof(*status));
1023 status->mon = mon;
1024 status->is_block_migration = blk || inc;
1025 status->timer = qemu_new_timer_ms(rt_clock, hmp_migrate_status_cb,
1026 status);
1027 qemu_mod_timer(status->timer, qemu_get_clock_ms(rt_clock));
1028 }
1029}
a15fef21
LC
1030
1031void hmp_device_del(Monitor *mon, const QDict *qdict)
1032{
1033 const char *id = qdict_get_str(qdict, "id");
1034 Error *err = NULL;
1035
1036 qmp_device_del(id, &err);
1037 hmp_handle_error(mon, &err);
1038}
783e9b48
WC
1039
1040void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1041{
1042 Error *errp = NULL;
1043 int paging = qdict_get_try_bool(qdict, "paging", 0);
1044 const char *file = qdict_get_str(qdict, "protocol");
1045 bool has_begin = qdict_haskey(qdict, "begin");
1046 bool has_length = qdict_haskey(qdict, "length");
1047 int64_t begin = 0;
1048 int64_t length = 0;
1049
1050 if (has_begin) {
1051 begin = qdict_get_int(qdict, "begin");
1052 }
1053 if (has_length) {
1054 length = qdict_get_int(qdict, "length");
1055 }
1056
1057 qmp_dump_guest_memory(paging, file, has_begin, begin, has_length, length,
1058 &errp);
1059 hmp_handle_error(mon, &errp);
1060}
928059a3
LC
1061
1062void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1063{
1064 Error *err = NULL;
1065 QemuOpts *opts;
1066
1067 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1068 if (error_is_set(&err)) {
1069 goto out;
1070 }
1071
1072 netdev_add(opts, &err);
1073 if (error_is_set(&err)) {
1074 qemu_opts_del(opts);
1075 }
1076
1077out:
1078 hmp_handle_error(mon, &err);
1079}
5f964155
LC
1080
1081void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1082{
1083 const char *id = qdict_get_str(qdict, "id");
1084 Error *err = NULL;
1085
1086 qmp_netdev_del(id, &err);
1087 hmp_handle_error(mon, &err);
1088}
208c9d1b
CB
1089
1090void hmp_getfd(Monitor *mon, const QDict *qdict)
1091{
1092 const char *fdname = qdict_get_str(qdict, "fdname");
1093 Error *errp = NULL;
1094
1095 qmp_getfd(fdname, &errp);
1096 hmp_handle_error(mon, &errp);
1097}
1098
1099void hmp_closefd(Monitor *mon, const QDict *qdict)
1100{
1101 const char *fdname = qdict_get_str(qdict, "fdname");
1102 Error *errp = NULL;
1103
1104 qmp_closefd(fdname, &errp);
1105 hmp_handle_error(mon, &errp);
1106}