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