blob: 54c37d72542d89957e491890dde26bcc826505bd [file] [log] [blame]
Anthony Liguori48a32be2011-09-02 12:34:48 -05001/*
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 *
Paolo Bonzini6b620ca2012-01-13 17:44:23 +010012 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
Anthony Liguori48a32be2011-09-02 12:34:48 -050014 */
15
16#include "hmp.h"
Luiz Capitulino928059a2012-04-18 17:34:15 -030017#include "net.h"
18#include "qemu-option.h"
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -020019#include "qemu-timer.h"
Anthony Liguori48a32be2011-09-02 12:34:48 -050020#include "qmp-commands.h"
Paolo Bonzini37003ad2012-06-07 04:02:21 +020021#include "monitor.h"
Anthony Liguori48a32be2011-09-02 12:34:48 -050022
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -020023static 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
Anthony Liguori48a32be2011-09-02 12:34:48 -050031void 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}
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030041
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}
Luiz Capitulino292a2602011-09-12 15:10:53 -030054
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
Luiz Capitulino1fa9a5e2011-09-12 17:54:20 -030070void 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
Luiz Capitulinoefab7672011-09-13 17:16:25 -030089void 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}
Luiz Capitulinoc5a415a2011-09-14 16:05:49 -030097
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}
Luiz Capitulino7a7f3252011-09-15 14:20:28 -0300110
Luiz Capitulinoe235cec2011-09-21 15:29:55 -0300111void 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
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300131void hmp_info_migrate(Monitor *mon)
132{
133 MigrationInfo *info;
134
135 info = qmp_query_migrate(NULL);
136
137 if (info->has_status) {
138 monitor_printf(mon, "Migration status: %s\n", info->status);
139 }
140
141 if (info->has_ram) {
142 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
143 info->ram->transferred >> 10);
144 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
145 info->ram->remaining >> 10);
146 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
147 info->ram->total >> 10);
Juan Quintelad5f8a572012-05-21 22:01:07 +0200148 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
149 info->ram->total_time);
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300150 }
151
152 if (info->has_disk) {
153 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
154 info->disk->transferred >> 10);
155 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
156 info->disk->remaining >> 10);
157 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
158 info->disk->total >> 10);
159 }
160
161 qapi_free_MigrationInfo(info);
162}
163
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300164void hmp_info_cpus(Monitor *mon)
165{
166 CpuInfoList *cpu_list, *cpu;
167
168 cpu_list = qmp_query_cpus(NULL);
169
170 for (cpu = cpu_list; cpu; cpu = cpu->next) {
171 int active = ' ';
172
173 if (cpu->value->CPU == monitor_get_cpu_index()) {
174 active = '*';
175 }
176
177 monitor_printf(mon, "%c CPU #%" PRId64 ": ", active, cpu->value->CPU);
178
179 if (cpu->value->has_pc) {
180 monitor_printf(mon, "pc=0x%016" PRIx64, cpu->value->pc);
181 }
182 if (cpu->value->has_nip) {
183 monitor_printf(mon, "nip=0x%016" PRIx64, cpu->value->nip);
184 }
185 if (cpu->value->has_npc) {
186 monitor_printf(mon, "pc=0x%016" PRIx64, cpu->value->pc);
187 monitor_printf(mon, "npc=0x%016" PRIx64, cpu->value->npc);
188 }
189 if (cpu->value->has_PC) {
190 monitor_printf(mon, "PC=0x%016" PRIx64, cpu->value->PC);
191 }
192
193 if (cpu->value->halted) {
194 monitor_printf(mon, " (halted)");
195 }
196
197 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
198 }
199
200 qapi_free_CpuInfoList(cpu_list);
201}
202
Luiz Capitulinob2023812011-09-21 17:16:47 -0300203void hmp_info_block(Monitor *mon)
204{
205 BlockInfoList *block_list, *info;
206
207 block_list = qmp_query_block(NULL);
208
209 for (info = block_list; info; info = info->next) {
210 monitor_printf(mon, "%s: removable=%d",
211 info->value->device, info->value->removable);
212
213 if (info->value->removable) {
214 monitor_printf(mon, " locked=%d", info->value->locked);
215 monitor_printf(mon, " tray-open=%d", info->value->tray_open);
216 }
217
218 if (info->value->has_io_status) {
219 monitor_printf(mon, " io-status=%s",
220 BlockDeviceIoStatus_lookup[info->value->io_status]);
221 }
222
223 if (info->value->has_inserted) {
224 monitor_printf(mon, " file=");
225 monitor_print_filename(mon, info->value->inserted->file);
226
227 if (info->value->inserted->has_backing_file) {
228 monitor_printf(mon, " backing_file=");
229 monitor_print_filename(mon, info->value->inserted->backing_file);
Benoît Canet75115d92012-08-02 10:22:49 +0200230 monitor_printf(mon, " backing_file_depth=%" PRId64,
231 info->value->inserted->backing_file_depth);
Luiz Capitulinob2023812011-09-21 17:16:47 -0300232 }
233 monitor_printf(mon, " ro=%d drv=%s encrypted=%d",
234 info->value->inserted->ro,
235 info->value->inserted->drv,
236 info->value->inserted->encrypted);
Zhi Yong Wu727f0052011-11-08 13:00:31 +0800237
238 monitor_printf(mon, " bps=%" PRId64 " bps_rd=%" PRId64
239 " bps_wr=%" PRId64 " iops=%" PRId64
240 " iops_rd=%" PRId64 " iops_wr=%" PRId64,
241 info->value->inserted->bps,
242 info->value->inserted->bps_rd,
243 info->value->inserted->bps_wr,
244 info->value->inserted->iops,
245 info->value->inserted->iops_rd,
246 info->value->inserted->iops_wr);
Luiz Capitulinob2023812011-09-21 17:16:47 -0300247 } else {
248 monitor_printf(mon, " [not inserted]");
249 }
250
251 monitor_printf(mon, "\n");
252 }
253
254 qapi_free_BlockInfoList(block_list);
255}
256
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300257void hmp_info_blockstats(Monitor *mon)
258{
259 BlockStatsList *stats_list, *stats;
260
261 stats_list = qmp_query_blockstats(NULL);
262
263 for (stats = stats_list; stats; stats = stats->next) {
264 if (!stats->value->has_device) {
265 continue;
266 }
267
268 monitor_printf(mon, "%s:", stats->value->device);
269 monitor_printf(mon, " rd_bytes=%" PRId64
270 " wr_bytes=%" PRId64
271 " rd_operations=%" PRId64
272 " wr_operations=%" PRId64
273 " flush_operations=%" PRId64
274 " wr_total_time_ns=%" PRId64
275 " rd_total_time_ns=%" PRId64
276 " flush_total_time_ns=%" PRId64
277 "\n",
278 stats->value->stats->rd_bytes,
279 stats->value->stats->wr_bytes,
280 stats->value->stats->rd_operations,
281 stats->value->stats->wr_operations,
282 stats->value->stats->flush_operations,
283 stats->value->stats->wr_total_time_ns,
284 stats->value->stats->rd_total_time_ns,
285 stats->value->stats->flush_total_time_ns);
286 }
287
288 qapi_free_BlockStatsList(stats_list);
289}
290
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200291void hmp_info_vnc(Monitor *mon)
292{
293 VncInfo *info;
294 Error *err = NULL;
295 VncClientInfoList *client;
296
297 info = qmp_query_vnc(&err);
298 if (err) {
299 monitor_printf(mon, "%s\n", error_get_pretty(err));
300 error_free(err);
301 return;
302 }
303
304 if (!info->enabled) {
305 monitor_printf(mon, "Server: disabled\n");
306 goto out;
307 }
308
309 monitor_printf(mon, "Server:\n");
310 if (info->has_host && info->has_service) {
311 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
312 }
313 if (info->has_auth) {
314 monitor_printf(mon, " auth: %s\n", info->auth);
315 }
316
317 if (!info->has_clients || info->clients == NULL) {
318 monitor_printf(mon, "Client: none\n");
319 } else {
320 for (client = info->clients; client; client = client->next) {
321 monitor_printf(mon, "Client:\n");
322 monitor_printf(mon, " address: %s:%s\n",
323 client->value->host, client->value->service);
324 monitor_printf(mon, " x509_dname: %s\n",
325 client->value->x509_dname ?
326 client->value->x509_dname : "none");
327 monitor_printf(mon, " username: %s\n",
328 client->value->has_sasl_username ?
329 client->value->sasl_username : "none");
330 }
331 }
332
333out:
334 qapi_free_VncInfo(info);
335}
336
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200337void hmp_info_spice(Monitor *mon)
338{
339 SpiceChannelList *chan;
340 SpiceInfo *info;
341
342 info = qmp_query_spice(NULL);
343
344 if (!info->enabled) {
345 monitor_printf(mon, "Server: disabled\n");
346 goto out;
347 }
348
349 monitor_printf(mon, "Server:\n");
350 if (info->has_port) {
351 monitor_printf(mon, " address: %s:%" PRId64 "\n",
352 info->host, info->port);
353 }
354 if (info->has_tls_port) {
355 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
356 info->host, info->tls_port);
357 }
358 monitor_printf(mon, " auth: %s\n", info->auth);
359 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
Alon Levy4efee022012-03-29 23:23:14 +0200360 monitor_printf(mon, " mouse-mode: %s\n",
361 SpiceQueryMouseMode_lookup[info->mouse_mode]);
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200362
363 if (!info->has_channels || info->channels == NULL) {
364 monitor_printf(mon, "Channels: none\n");
365 } else {
366 for (chan = info->channels; chan; chan = chan->next) {
367 monitor_printf(mon, "Channel:\n");
368 monitor_printf(mon, " address: %s:%s%s\n",
369 chan->value->host, chan->value->port,
370 chan->value->tls ? " [tls]" : "");
371 monitor_printf(mon, " session: %" PRId64 "\n",
372 chan->value->connection_id);
373 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
374 chan->value->channel_type, chan->value->channel_id);
375 }
376 }
377
378out:
379 qapi_free_SpiceInfo(info);
380}
381
Luiz Capitulino96637bc2011-10-21 11:41:37 -0200382void hmp_info_balloon(Monitor *mon)
383{
384 BalloonInfo *info;
385 Error *err = NULL;
386
387 info = qmp_query_balloon(&err);
388 if (err) {
389 monitor_printf(mon, "%s\n", error_get_pretty(err));
390 error_free(err);
391 return;
392 }
393
394 monitor_printf(mon, "balloon: actual=%" PRId64, info->actual >> 20);
395 if (info->has_mem_swapped_in) {
396 monitor_printf(mon, " mem_swapped_in=%" PRId64, info->mem_swapped_in);
397 }
398 if (info->has_mem_swapped_out) {
399 monitor_printf(mon, " mem_swapped_out=%" PRId64, info->mem_swapped_out);
400 }
401 if (info->has_major_page_faults) {
402 monitor_printf(mon, " major_page_faults=%" PRId64,
403 info->major_page_faults);
404 }
405 if (info->has_minor_page_faults) {
406 monitor_printf(mon, " minor_page_faults=%" PRId64,
407 info->minor_page_faults);
408 }
409 if (info->has_free_mem) {
410 monitor_printf(mon, " free_mem=%" PRId64, info->free_mem);
411 }
412 if (info->has_total_mem) {
413 monitor_printf(mon, " total_mem=%" PRId64, info->total_mem);
414 }
415
416 monitor_printf(mon, "\n");
417
418 qapi_free_BalloonInfo(info);
419}
420
Luiz Capitulino79627472011-10-21 14:15:33 -0200421static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
422{
423 PciMemoryRegionList *region;
424
425 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
426 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
427 dev->slot, dev->function);
428 monitor_printf(mon, " ");
429
430 if (dev->class_info.has_desc) {
431 monitor_printf(mon, "%s", dev->class_info.desc);
432 } else {
433 monitor_printf(mon, "Class %04" PRId64, dev->class_info.class);
434 }
435
436 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
437 dev->id.vendor, dev->id.device);
438
439 if (dev->has_irq) {
440 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
441 }
442
443 if (dev->has_pci_bridge) {
444 monitor_printf(mon, " BUS %" PRId64 ".\n",
445 dev->pci_bridge->bus.number);
446 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
447 dev->pci_bridge->bus.secondary);
448 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
449 dev->pci_bridge->bus.subordinate);
450
451 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
452 dev->pci_bridge->bus.io_range->base,
453 dev->pci_bridge->bus.io_range->limit);
454
455 monitor_printf(mon,
456 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
457 dev->pci_bridge->bus.memory_range->base,
458 dev->pci_bridge->bus.memory_range->limit);
459
460 monitor_printf(mon, " prefetchable memory range "
461 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
462 dev->pci_bridge->bus.prefetchable_range->base,
463 dev->pci_bridge->bus.prefetchable_range->limit);
464 }
465
466 for (region = dev->regions; region; region = region->next) {
467 uint64_t addr, size;
468
469 addr = region->value->address;
470 size = region->value->size;
471
472 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
473
474 if (!strcmp(region->value->type, "io")) {
475 monitor_printf(mon, "I/O at 0x%04" PRIx64
476 " [0x%04" PRIx64 "].\n",
477 addr, addr + size - 1);
478 } else {
479 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
480 " [0x%08" PRIx64 "].\n",
481 region->value->mem_type_64 ? 64 : 32,
482 region->value->prefetch ? " prefetchable" : "",
483 addr, addr + size - 1);
484 }
485 }
486
487 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
488
489 if (dev->has_pci_bridge) {
490 if (dev->pci_bridge->has_devices) {
491 PciDeviceInfoList *cdev;
492 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
493 hmp_info_pci_device(mon, cdev->value);
494 }
495 }
496 }
497}
498
499void hmp_info_pci(Monitor *mon)
500{
Stefan Bergerf46cee32012-01-11 10:51:52 -0500501 PciInfoList *info_list, *info;
Luiz Capitulino79627472011-10-21 14:15:33 -0200502 Error *err = NULL;
503
Stefan Bergerf46cee32012-01-11 10:51:52 -0500504 info_list = qmp_query_pci(&err);
Luiz Capitulino79627472011-10-21 14:15:33 -0200505 if (err) {
506 monitor_printf(mon, "PCI devices not supported\n");
507 error_free(err);
508 return;
509 }
510
Stefan Bergerf46cee32012-01-11 10:51:52 -0500511 for (info = info_list; info; info = info->next) {
Luiz Capitulino79627472011-10-21 14:15:33 -0200512 PciDeviceInfoList *dev;
513
514 for (dev = info->value->devices; dev; dev = dev->next) {
515 hmp_info_pci_device(mon, dev->value);
516 }
517 }
518
Stefan Bergerf46cee32012-01-11 10:51:52 -0500519 qapi_free_PciInfoList(info_list);
Luiz Capitulino79627472011-10-21 14:15:33 -0200520}
521
Stefan Hajnoczifb5458c2012-01-18 14:40:49 +0000522void hmp_info_block_jobs(Monitor *mon)
523{
524 BlockJobInfoList *list;
525 Error *err = NULL;
526
527 list = qmp_query_block_jobs(&err);
528 assert(!err);
529
530 if (!list) {
531 monitor_printf(mon, "No active jobs\n");
532 return;
533 }
534
535 while (list) {
536 if (strcmp(list->value->type, "stream") == 0) {
537 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
538 " of %" PRId64 " bytes, speed limit %" PRId64
539 " bytes/s\n",
540 list->value->device,
541 list->value->offset,
542 list->value->len,
543 list->value->speed);
544 } else {
545 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
546 " of %" PRId64 " bytes, speed limit %" PRId64
547 " bytes/s\n",
548 list->value->type,
549 list->value->device,
550 list->value->offset,
551 list->value->len,
552 list->value->speed);
553 }
554 list = list->next;
555 }
556}
557
Luiz Capitulino7a7f3252011-09-15 14:20:28 -0300558void hmp_quit(Monitor *mon, const QDict *qdict)
559{
560 monitor_suspend(mon);
561 qmp_quit(NULL);
562}
Luiz Capitulino5f158f22011-09-15 14:34:39 -0300563
564void hmp_stop(Monitor *mon, const QDict *qdict)
565{
566 qmp_stop(NULL);
567}
Luiz Capitulino38d22652011-09-15 14:41:46 -0300568
569void hmp_system_reset(Monitor *mon, const QDict *qdict)
570{
571 qmp_system_reset(NULL);
572}
Luiz Capitulino5bc465e2011-09-28 11:06:15 -0300573
574void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
575{
576 qmp_system_powerdown(NULL);
577}
Luiz Capitulino755f1962011-10-06 14:31:39 -0300578
579void hmp_cpu(Monitor *mon, const QDict *qdict)
580{
581 int64_t cpu_index;
582
583 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
584 use it are converted to the QAPI */
585 cpu_index = qdict_get_int(qdict, "index");
586 if (monitor_set_cpu(cpu_index) < 0) {
587 monitor_printf(mon, "invalid CPU index\n");
588 }
589}
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -0200590
591void hmp_memsave(Monitor *mon, const QDict *qdict)
592{
593 uint32_t size = qdict_get_int(qdict, "size");
594 const char *filename = qdict_get_str(qdict, "filename");
595 uint64_t addr = qdict_get_int(qdict, "val");
596 Error *errp = NULL;
597
598 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &errp);
599 hmp_handle_error(mon, &errp);
600}
Luiz Capitulino6d3962b2011-11-22 17:26:46 -0200601
602void hmp_pmemsave(Monitor *mon, const QDict *qdict)
603{
604 uint32_t size = qdict_get_int(qdict, "size");
605 const char *filename = qdict_get_str(qdict, "filename");
606 uint64_t addr = qdict_get_int(qdict, "val");
607 Error *errp = NULL;
608
609 qmp_pmemsave(addr, size, filename, &errp);
610 hmp_handle_error(mon, &errp);
611}
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200612
613static void hmp_cont_cb(void *opaque, int err)
614{
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200615 if (!err) {
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300616 qmp_cont(NULL);
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200617 }
618}
619
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300620static bool key_is_missing(const BlockInfo *bdev)
621{
622 return (bdev->inserted && bdev->inserted->encryption_key_missing);
623}
624
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200625void hmp_cont(Monitor *mon, const QDict *qdict)
626{
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300627 BlockInfoList *bdev_list, *bdev;
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200628 Error *errp = NULL;
629
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300630 bdev_list = qmp_query_block(NULL);
631 for (bdev = bdev_list; bdev; bdev = bdev->next) {
632 if (key_is_missing(bdev->value)) {
633 monitor_read_block_device_key(mon, bdev->value->device,
634 hmp_cont_cb, NULL);
635 goto out;
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200636 }
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200637 }
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300638
639 qmp_cont(&errp);
640 hmp_handle_error(mon, &errp);
641
642out:
643 qapi_free_BlockInfoList(bdev_list);
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200644}
Luiz Capitulinoab49ab52011-11-23 12:55:53 -0200645
Gerd Hoffmann9b9df252012-02-23 13:45:21 +0100646void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
647{
648 qmp_system_wakeup(NULL);
649}
650
Luiz Capitulinoab49ab52011-11-23 12:55:53 -0200651void hmp_inject_nmi(Monitor *mon, const QDict *qdict)
652{
653 Error *errp = NULL;
654
655 qmp_inject_nmi(&errp);
656 hmp_handle_error(mon, &errp);
657}
Luiz Capitulino4b371562011-11-23 13:11:55 -0200658
659void hmp_set_link(Monitor *mon, const QDict *qdict)
660{
661 const char *name = qdict_get_str(qdict, "name");
662 int up = qdict_get_bool(qdict, "up");
663 Error *errp = NULL;
664
665 qmp_set_link(name, up, &errp);
666 hmp_handle_error(mon, &errp);
667}
Luiz Capitulinoa4dea8a2011-11-23 13:28:21 -0200668
669void hmp_block_passwd(Monitor *mon, const QDict *qdict)
670{
671 const char *device = qdict_get_str(qdict, "device");
672 const char *password = qdict_get_str(qdict, "password");
673 Error *errp = NULL;
674
675 qmp_block_passwd(device, password, &errp);
676 hmp_handle_error(mon, &errp);
677}
Luiz Capitulinod72f3262011-11-25 14:38:09 -0200678
679void hmp_balloon(Monitor *mon, const QDict *qdict)
680{
681 int64_t value = qdict_get_int(qdict, "value");
682 Error *errp = NULL;
683
684 qmp_balloon(value, &errp);
685 if (error_is_set(&errp)) {
686 monitor_printf(mon, "balloon: %s\n", error_get_pretty(errp));
687 error_free(errp);
688 }
689}
Luiz Capitulino5e7caac2011-11-25 14:57:10 -0200690
691void hmp_block_resize(Monitor *mon, const QDict *qdict)
692{
693 const char *device = qdict_get_str(qdict, "device");
694 int64_t size = qdict_get_int(qdict, "size");
695 Error *errp = NULL;
696
697 qmp_block_resize(device, size, &errp);
698 hmp_handle_error(mon, &errp);
699}
Luiz Capitulino6106e242011-11-25 16:15:19 -0200700
701void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
702{
703 const char *device = qdict_get_str(qdict, "device");
704 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
705 const char *format = qdict_get_try_str(qdict, "format");
Paolo Bonzini6cc2a412012-03-06 18:55:59 +0100706 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
707 enum NewImageMode mode;
Luiz Capitulino6106e242011-11-25 16:15:19 -0200708 Error *errp = NULL;
709
710 if (!filename) {
711 /* In the future, if 'snapshot-file' is not specified, the snapshot
712 will be taken internally. Today it's actually required. */
713 error_set(&errp, QERR_MISSING_PARAMETER, "snapshot-file");
714 hmp_handle_error(mon, &errp);
715 return;
716 }
717
Paolo Bonzini6cc2a412012-03-06 18:55:59 +0100718 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
719 qmp_blockdev_snapshot_sync(device, filename, !!format, format,
720 true, mode, &errp);
Luiz Capitulino6106e242011-11-25 16:15:19 -0200721 hmp_handle_error(mon, &errp);
722}
Luiz Capitulino6cdedb02011-11-27 22:54:09 -0200723
724void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
725{
726 qmp_migrate_cancel(NULL);
727}
Luiz Capitulino4f0a9932011-11-27 23:18:01 -0200728
729void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
730{
731 double value = qdict_get_double(qdict, "value");
732 qmp_migrate_set_downtime(value, NULL);
733}
Luiz Capitulino3dc85382011-11-28 11:59:37 -0200734
735void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
736{
737 int64_t value = qdict_get_int(qdict, "value");
738 qmp_migrate_set_speed(value, NULL);
739}
Luiz Capitulinofbf796f2011-12-07 11:17:51 -0200740
741void hmp_set_password(Monitor *mon, const QDict *qdict)
742{
743 const char *protocol = qdict_get_str(qdict, "protocol");
744 const char *password = qdict_get_str(qdict, "password");
745 const char *connected = qdict_get_try_str(qdict, "connected");
746 Error *err = NULL;
747
748 qmp_set_password(protocol, password, !!connected, connected, &err);
749 hmp_handle_error(mon, &err);
750}
Luiz Capitulino9ad53722011-12-07 11:47:57 -0200751
752void hmp_expire_password(Monitor *mon, const QDict *qdict)
753{
754 const char *protocol = qdict_get_str(qdict, "protocol");
755 const char *whenstr = qdict_get_str(qdict, "time");
756 Error *err = NULL;
757
758 qmp_expire_password(protocol, whenstr, &err);
759 hmp_handle_error(mon, &err);
760}
Luiz Capitulinoc245b6a2011-12-07 16:02:36 -0200761
762void hmp_eject(Monitor *mon, const QDict *qdict)
763{
764 int force = qdict_get_try_bool(qdict, "force", 0);
765 const char *device = qdict_get_str(qdict, "device");
766 Error *err = NULL;
767
768 qmp_eject(device, true, force, &err);
769 hmp_handle_error(mon, &err);
770}
Luiz Capitulino333a96e2011-12-08 11:13:50 -0200771
772static void hmp_change_read_arg(Monitor *mon, const char *password,
773 void *opaque)
774{
775 qmp_change_vnc_password(password, NULL);
776 monitor_read_command(mon, 1);
777}
778
Luiz Capitulino333a96e2011-12-08 11:13:50 -0200779void hmp_change(Monitor *mon, const QDict *qdict)
780{
781 const char *device = qdict_get_str(qdict, "device");
782 const char *target = qdict_get_str(qdict, "target");
783 const char *arg = qdict_get_try_str(qdict, "arg");
784 Error *err = NULL;
785
786 if (strcmp(device, "vnc") == 0 &&
787 (strcmp(target, "passwd") == 0 ||
788 strcmp(target, "password") == 0)) {
789 if (!arg) {
790 monitor_read_password(mon, hmp_change_read_arg, NULL);
791 return;
792 }
793 }
794
795 qmp_change(device, target, !!arg, arg, &err);
796 if (error_is_type(err, QERR_DEVICE_ENCRYPTED)) {
Luiz Capitulinoeef5ad12012-08-06 15:49:34 -0300797 error_free(err);
798 monitor_read_block_device_key(mon, device, NULL, NULL);
Luiz Capitulino333a96e2011-12-08 11:13:50 -0200799 return;
800 }
801 hmp_handle_error(mon, &err);
802}
Luiz Capitulino80047da2011-12-14 16:49:14 -0200803
804void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
805{
806 Error *err = NULL;
807
808 qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
809 qdict_get_int(qdict, "bps"),
810 qdict_get_int(qdict, "bps_rd"),
811 qdict_get_int(qdict, "bps_wr"),
812 qdict_get_int(qdict, "iops"),
813 qdict_get_int(qdict, "iops_rd"),
814 qdict_get_int(qdict, "iops_wr"), &err);
815 hmp_handle_error(mon, &err);
816}
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +0000817
818void hmp_block_stream(Monitor *mon, const QDict *qdict)
819{
820 Error *error = NULL;
821 const char *device = qdict_get_str(qdict, "device");
822 const char *base = qdict_get_try_str(qdict, "base");
Stefan Hajnoczic83c66c2012-04-25 16:51:03 +0100823 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +0000824
Stefan Hajnoczic83c66c2012-04-25 16:51:03 +0100825 qmp_block_stream(device, base != NULL, base,
826 qdict_haskey(qdict, "speed"), speed, &error);
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +0000827
828 hmp_handle_error(mon, &error);
829}
Stefan Hajnoczi2d47c6e2012-01-18 14:40:47 +0000830
831void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
832{
833 Error *error = NULL;
834 const char *device = qdict_get_str(qdict, "device");
Paolo Bonzinic6db2392012-05-08 16:51:56 +0200835 int64_t value = qdict_get_int(qdict, "speed");
Stefan Hajnoczi2d47c6e2012-01-18 14:40:47 +0000836
837 qmp_block_job_set_speed(device, value, &error);
838
839 hmp_handle_error(mon, &error);
840}
Stefan Hajnoczi370521a2012-01-18 14:40:48 +0000841
842void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
843{
844 Error *error = NULL;
845 const char *device = qdict_get_str(qdict, "device");
846
847 qmp_block_job_cancel(device, &error);
848
849 hmp_handle_error(mon, &error);
850}
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -0200851
852typedef struct MigrationStatus
853{
854 QEMUTimer *timer;
855 Monitor *mon;
856 bool is_block_migration;
857} MigrationStatus;
858
859static void hmp_migrate_status_cb(void *opaque)
860{
861 MigrationStatus *status = opaque;
862 MigrationInfo *info;
863
864 info = qmp_query_migrate(NULL);
865 if (!info->has_status || strcmp(info->status, "active") == 0) {
866 if (info->has_disk) {
867 int progress;
868
869 if (info->disk->remaining) {
870 progress = info->disk->transferred * 100 / info->disk->total;
871 } else {
872 progress = 100;
873 }
874
875 monitor_printf(status->mon, "Completed %d %%\r", progress);
876 monitor_flush(status->mon);
877 }
878
879 qemu_mod_timer(status->timer, qemu_get_clock_ms(rt_clock) + 1000);
880 } else {
881 if (status->is_block_migration) {
882 monitor_printf(status->mon, "\n");
883 }
884 monitor_resume(status->mon);
885 qemu_del_timer(status->timer);
886 g_free(status);
887 }
888
889 qapi_free_MigrationInfo(info);
890}
891
892void hmp_migrate(Monitor *mon, const QDict *qdict)
893{
894 int detach = qdict_get_try_bool(qdict, "detach", 0);
895 int blk = qdict_get_try_bool(qdict, "blk", 0);
896 int inc = qdict_get_try_bool(qdict, "inc", 0);
897 const char *uri = qdict_get_str(qdict, "uri");
898 Error *err = NULL;
899
900 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
901 if (err) {
902 monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
903 error_free(err);
904 return;
905 }
906
907 if (!detach) {
908 MigrationStatus *status;
909
910 if (monitor_suspend(mon) < 0) {
911 monitor_printf(mon, "terminal does not allow synchronous "
912 "migration, continuing detached\n");
913 return;
914 }
915
916 status = g_malloc0(sizeof(*status));
917 status->mon = mon;
918 status->is_block_migration = blk || inc;
919 status->timer = qemu_new_timer_ms(rt_clock, hmp_migrate_status_cb,
920 status);
921 qemu_mod_timer(status->timer, qemu_get_clock_ms(rt_clock));
922 }
923}
Luiz Capitulinoa15fef22012-03-29 12:38:50 -0300924
925void hmp_device_del(Monitor *mon, const QDict *qdict)
926{
927 const char *id = qdict_get_str(qdict, "id");
928 Error *err = NULL;
929
930 qmp_device_del(id, &err);
931 hmp_handle_error(mon, &err);
932}
Wen Congyang783e9b42012-05-07 12:10:47 +0800933
934void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
935{
936 Error *errp = NULL;
937 int paging = qdict_get_try_bool(qdict, "paging", 0);
938 const char *file = qdict_get_str(qdict, "protocol");
939 bool has_begin = qdict_haskey(qdict, "begin");
940 bool has_length = qdict_haskey(qdict, "length");
941 int64_t begin = 0;
942 int64_t length = 0;
943
944 if (has_begin) {
945 begin = qdict_get_int(qdict, "begin");
946 }
947 if (has_length) {
948 length = qdict_get_int(qdict, "length");
949 }
950
951 qmp_dump_guest_memory(paging, file, has_begin, begin, has_length, length,
952 &errp);
953 hmp_handle_error(mon, &errp);
954}
Luiz Capitulino928059a2012-04-18 17:34:15 -0300955
956void hmp_netdev_add(Monitor *mon, const QDict *qdict)
957{
958 Error *err = NULL;
959 QemuOpts *opts;
960
961 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
962 if (error_is_set(&err)) {
963 goto out;
964 }
965
966 netdev_add(opts, &err);
967 if (error_is_set(&err)) {
968 qemu_opts_del(opts);
969 }
970
971out:
972 hmp_handle_error(mon, &err);
973}
Luiz Capitulino5f964152012-04-16 14:36:32 -0300974
975void hmp_netdev_del(Monitor *mon, const QDict *qdict)
976{
977 const char *id = qdict_get_str(qdict, "id");
978 Error *err = NULL;
979
980 qmp_netdev_del(id, &err);
981 hmp_handle_error(mon, &err);
982}
Corey Bryant208c9d12012-06-22 14:36:09 -0400983
984void hmp_getfd(Monitor *mon, const QDict *qdict)
985{
986 const char *fdname = qdict_get_str(qdict, "fdname");
987 Error *errp = NULL;
988
989 qmp_getfd(fdname, &errp);
990 hmp_handle_error(mon, &errp);
991}
992
993void hmp_closefd(Monitor *mon, const QDict *qdict)
994{
995 const char *fdname = qdict_get_str(qdict, "fdname");
996 Error *errp = NULL;
997
998 qmp_closefd(fdname, &errp);
999 hmp_handle_error(mon, &errp);
1000}