]> Git Repo - qemu.git/blob - hmp.c
gdbstub: fix for commit 87f25c12bfeaaa0c41fb857713bbc7e8a9b757dc
[qemu.git] / hmp.c
1 /*
2  * Human Monitor Interface
3  *
4  * Copyright IBM, Corp. 2011
5  *
6  * Authors:
7  *  Anthony Liguori   <[email protected]>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2.  See
10  * the COPYING file in the top-level directory.
11  *
12  * Contributions after 2012-01-13 are licensed under the terms of the
13  * GNU GPL, version 2 or (at your option) any later version.
14  */
15
16 #include "hmp.h"
17 #include "net/net.h"
18 #include "sysemu/char.h"
19 #include "qemu/option.h"
20 #include "qemu/timer.h"
21 #include "qmp-commands.h"
22 #include "qemu/sockets.h"
23 #include "monitor/monitor.h"
24 #include "ui/console.h"
25 #include "block/qapi.h"
26 #include "qemu-io.h"
27
28 static void hmp_handle_error(Monitor *mon, Error **errp)
29 {
30     if (error_is_set(errp)) {
31         monitor_printf(mon, "%s\n", error_get_pretty(*errp));
32         error_free(*errp);
33     }
34 }
35
36 void hmp_info_name(Monitor *mon, const QDict *qdict)
37 {
38     NameInfo *info;
39
40     info = qmp_query_name(NULL);
41     if (info->has_name) {
42         monitor_printf(mon, "%s\n", info->name);
43     }
44     qapi_free_NameInfo(info);
45 }
46
47 void hmp_info_version(Monitor *mon, const QDict *qdict)
48 {
49     VersionInfo *info;
50
51     info = qmp_query_version(NULL);
52
53     monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
54                    info->qemu.major, info->qemu.minor, info->qemu.micro,
55                    info->package);
56
57     qapi_free_VersionInfo(info);
58 }
59
60 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
61 {
62     KvmInfo *info;
63
64     info = qmp_query_kvm(NULL);
65     monitor_printf(mon, "kvm support: ");
66     if (info->present) {
67         monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
68     } else {
69         monitor_printf(mon, "not compiled\n");
70     }
71
72     qapi_free_KvmInfo(info);
73 }
74
75 void hmp_info_status(Monitor *mon, const QDict *qdict)
76 {
77     StatusInfo *info;
78
79     info = qmp_query_status(NULL);
80
81     monitor_printf(mon, "VM status: %s%s",
82                    info->running ? "running" : "paused",
83                    info->singlestep ? " (single step mode)" : "");
84
85     if (!info->running && info->status != RUN_STATE_PAUSED) {
86         monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
87     }
88
89     monitor_printf(mon, "\n");
90
91     qapi_free_StatusInfo(info);
92 }
93
94 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
95 {
96     UuidInfo *info;
97
98     info = qmp_query_uuid(NULL);
99     monitor_printf(mon, "%s\n", info->UUID);
100     qapi_free_UuidInfo(info);
101 }
102
103 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
104 {
105     ChardevInfoList *char_info, *info;
106
107     char_info = qmp_query_chardev(NULL);
108     for (info = char_info; info; info = info->next) {
109         monitor_printf(mon, "%s: filename=%s\n", info->value->label,
110                                                  info->value->filename);
111     }
112
113     qapi_free_ChardevInfoList(char_info);
114 }
115
116 void hmp_info_mice(Monitor *mon, const QDict *qdict)
117 {
118     MouseInfoList *mice_list, *mouse;
119
120     mice_list = qmp_query_mice(NULL);
121     if (!mice_list) {
122         monitor_printf(mon, "No mouse devices connected\n");
123         return;
124     }
125
126     for (mouse = mice_list; mouse; mouse = mouse->next) {
127         monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
128                        mouse->value->current ? '*' : ' ',
129                        mouse->value->index, mouse->value->name,
130                        mouse->value->absolute ? " (absolute)" : "");
131     }
132
133     qapi_free_MouseInfoList(mice_list);
134 }
135
136 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
137 {
138     MigrationInfo *info;
139     MigrationCapabilityStatusList *caps, *cap;
140
141     info = qmp_query_migrate(NULL);
142     caps = qmp_query_migrate_capabilities(NULL);
143
144     /* do not display parameters during setup */
145     if (info->has_status && caps) {
146         monitor_printf(mon, "capabilities: ");
147         for (cap = caps; cap; cap = cap->next) {
148             monitor_printf(mon, "%s: %s ",
149                            MigrationCapability_lookup[cap->value->capability],
150                            cap->value->state ? "on" : "off");
151         }
152         monitor_printf(mon, "\n");
153     }
154
155     if (info->has_status) {
156         monitor_printf(mon, "Migration status: %s\n", info->status);
157         monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
158                        info->total_time);
159         if (info->has_expected_downtime) {
160             monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
161                            info->expected_downtime);
162         }
163         if (info->has_downtime) {
164             monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
165                            info->downtime);
166         }
167     }
168
169     if (info->has_ram) {
170         monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
171                        info->ram->transferred >> 10);
172         monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
173                        info->ram->remaining >> 10);
174         monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
175                        info->ram->total >> 10);
176         monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
177                        info->ram->duplicate);
178         monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
179                        info->ram->skipped);
180         monitor_printf(mon, "normal: %" PRIu64 " pages\n",
181                        info->ram->normal);
182         monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
183                        info->ram->normal_bytes >> 10);
184         if (info->ram->dirty_pages_rate) {
185             monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
186                            info->ram->dirty_pages_rate);
187         }
188     }
189
190     if (info->has_disk) {
191         monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
192                        info->disk->transferred >> 10);
193         monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
194                        info->disk->remaining >> 10);
195         monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
196                        info->disk->total >> 10);
197     }
198
199     if (info->has_xbzrle_cache) {
200         monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
201                        info->xbzrle_cache->cache_size);
202         monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
203                        info->xbzrle_cache->bytes >> 10);
204         monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
205                        info->xbzrle_cache->pages);
206         monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
207                        info->xbzrle_cache->cache_miss);
208         monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
209                        info->xbzrle_cache->overflow);
210     }
211
212     qapi_free_MigrationInfo(info);
213     qapi_free_MigrationCapabilityStatusList(caps);
214 }
215
216 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
217 {
218     MigrationCapabilityStatusList *caps, *cap;
219
220     caps = qmp_query_migrate_capabilities(NULL);
221
222     if (caps) {
223         monitor_printf(mon, "capabilities: ");
224         for (cap = caps; cap; cap = cap->next) {
225             monitor_printf(mon, "%s: %s ",
226                            MigrationCapability_lookup[cap->value->capability],
227                            cap->value->state ? "on" : "off");
228         }
229         monitor_printf(mon, "\n");
230     }
231
232     qapi_free_MigrationCapabilityStatusList(caps);
233 }
234
235 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
236 {
237     monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
238                    qmp_query_migrate_cache_size(NULL) >> 10);
239 }
240
241 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
242 {
243     CpuInfoList *cpu_list, *cpu;
244
245     cpu_list = qmp_query_cpus(NULL);
246
247     for (cpu = cpu_list; cpu; cpu = cpu->next) {
248         int active = ' ';
249
250         if (cpu->value->CPU == monitor_get_cpu_index()) {
251             active = '*';
252         }
253
254         monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
255
256         if (cpu->value->has_pc) {
257             monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->pc);
258         }
259         if (cpu->value->has_nip) {
260             monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->nip);
261         }
262         if (cpu->value->has_npc) {
263             monitor_printf(mon, " npc=0x%016" PRIx64, cpu->value->npc);
264         }
265         if (cpu->value->has_PC) {
266             monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->PC);
267         }
268
269         if (cpu->value->halted) {
270             monitor_printf(mon, " (halted)");
271         }
272
273         monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
274     }
275
276     qapi_free_CpuInfoList(cpu_list);
277 }
278
279 void hmp_info_block(Monitor *mon, const QDict *qdict)
280 {
281     BlockInfoList *block_list, *info;
282     ImageInfo *image_info;
283     const char *device = qdict_get_try_str(qdict, "device");
284     bool verbose = qdict_get_try_bool(qdict, "verbose", 0);
285
286     block_list = qmp_query_block(NULL);
287
288     for (info = block_list; info; info = info->next) {
289         if (device && strcmp(device, info->value->device)) {
290             continue;
291         }
292         monitor_printf(mon, "%s: removable=%d",
293                        info->value->device, info->value->removable);
294
295         if (info->value->removable) {
296             monitor_printf(mon, " locked=%d", info->value->locked);
297             monitor_printf(mon, " tray-open=%d", info->value->tray_open);
298         }
299
300         if (info->value->has_io_status) {
301             monitor_printf(mon, " io-status=%s",
302                            BlockDeviceIoStatus_lookup[info->value->io_status]);
303         }
304
305         if (info->value->has_inserted) {
306             monitor_printf(mon, " file=");
307             monitor_print_filename(mon, info->value->inserted->file);
308
309             if (info->value->inserted->has_backing_file) {
310                 monitor_printf(mon, " backing_file=");
311                 monitor_print_filename(mon, info->value->inserted->backing_file);
312                 monitor_printf(mon, " backing_file_depth=%" PRId64,
313                     info->value->inserted->backing_file_depth);
314             }
315             monitor_printf(mon, " ro=%d drv=%s encrypted=%d",
316                            info->value->inserted->ro,
317                            info->value->inserted->drv,
318                            info->value->inserted->encrypted);
319
320             monitor_printf(mon, " bps=%" PRId64 " bps_rd=%" PRId64
321                             " bps_wr=%" PRId64 " iops=%" PRId64
322                             " iops_rd=%" PRId64 " iops_wr=%" PRId64,
323                             info->value->inserted->bps,
324                             info->value->inserted->bps_rd,
325                             info->value->inserted->bps_wr,
326                             info->value->inserted->iops,
327                             info->value->inserted->iops_rd,
328                             info->value->inserted->iops_wr);
329
330             if (verbose) {
331                 monitor_printf(mon, " images:\n");
332                 image_info = info->value->inserted->image;
333                 while (1) {
334                         bdrv_image_info_dump((fprintf_function)monitor_printf,
335                                              mon, image_info);
336                     if (image_info->has_backing_image) {
337                         image_info = image_info->backing_image;
338                     } else {
339                         break;
340                     }
341                 }
342             }
343         } else {
344             monitor_printf(mon, " [not inserted]");
345         }
346
347         monitor_printf(mon, "\n");
348     }
349
350     qapi_free_BlockInfoList(block_list);
351 }
352
353 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
354 {
355     BlockStatsList *stats_list, *stats;
356
357     stats_list = qmp_query_blockstats(NULL);
358
359     for (stats = stats_list; stats; stats = stats->next) {
360         if (!stats->value->has_device) {
361             continue;
362         }
363
364         monitor_printf(mon, "%s:", stats->value->device);
365         monitor_printf(mon, " rd_bytes=%" PRId64
366                        " wr_bytes=%" PRId64
367                        " rd_operations=%" PRId64
368                        " wr_operations=%" PRId64
369                        " flush_operations=%" PRId64
370                        " wr_total_time_ns=%" PRId64
371                        " rd_total_time_ns=%" PRId64
372                        " flush_total_time_ns=%" PRId64
373                        "\n",
374                        stats->value->stats->rd_bytes,
375                        stats->value->stats->wr_bytes,
376                        stats->value->stats->rd_operations,
377                        stats->value->stats->wr_operations,
378                        stats->value->stats->flush_operations,
379                        stats->value->stats->wr_total_time_ns,
380                        stats->value->stats->rd_total_time_ns,
381                        stats->value->stats->flush_total_time_ns);
382     }
383
384     qapi_free_BlockStatsList(stats_list);
385 }
386
387 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
388 {
389     VncInfo *info;
390     Error *err = NULL;
391     VncClientInfoList *client;
392
393     info = qmp_query_vnc(&err);
394     if (err) {
395         monitor_printf(mon, "%s\n", error_get_pretty(err));
396         error_free(err);
397         return;
398     }
399
400     if (!info->enabled) {
401         monitor_printf(mon, "Server: disabled\n");
402         goto out;
403     }
404
405     monitor_printf(mon, "Server:\n");
406     if (info->has_host && info->has_service) {
407         monitor_printf(mon, "     address: %s:%s\n", info->host, info->service);
408     }
409     if (info->has_auth) {
410         monitor_printf(mon, "        auth: %s\n", info->auth);
411     }
412
413     if (!info->has_clients || info->clients == NULL) {
414         monitor_printf(mon, "Client: none\n");
415     } else {
416         for (client = info->clients; client; client = client->next) {
417             monitor_printf(mon, "Client:\n");
418             monitor_printf(mon, "     address: %s:%s\n",
419                            client->value->host, client->value->service);
420             monitor_printf(mon, "  x509_dname: %s\n",
421                            client->value->x509_dname ?
422                            client->value->x509_dname : "none");
423             monitor_printf(mon, "    username: %s\n",
424                            client->value->has_sasl_username ?
425                            client->value->sasl_username : "none");
426         }
427     }
428
429 out:
430     qapi_free_VncInfo(info);
431 }
432
433 void hmp_info_spice(Monitor *mon, const QDict *qdict)
434 {
435     SpiceChannelList *chan;
436     SpiceInfo *info;
437
438     info = qmp_query_spice(NULL);
439
440     if (!info->enabled) {
441         monitor_printf(mon, "Server: disabled\n");
442         goto out;
443     }
444
445     monitor_printf(mon, "Server:\n");
446     if (info->has_port) {
447         monitor_printf(mon, "     address: %s:%" PRId64 "\n",
448                        info->host, info->port);
449     }
450     if (info->has_tls_port) {
451         monitor_printf(mon, "     address: %s:%" PRId64 " [tls]\n",
452                        info->host, info->tls_port);
453     }
454     monitor_printf(mon, "    migrated: %s\n",
455                    info->migrated ? "true" : "false");
456     monitor_printf(mon, "        auth: %s\n", info->auth);
457     monitor_printf(mon, "    compiled: %s\n", info->compiled_version);
458     monitor_printf(mon, "  mouse-mode: %s\n",
459                    SpiceQueryMouseMode_lookup[info->mouse_mode]);
460
461     if (!info->has_channels || info->channels == NULL) {
462         monitor_printf(mon, "Channels: none\n");
463     } else {
464         for (chan = info->channels; chan; chan = chan->next) {
465             monitor_printf(mon, "Channel:\n");
466             monitor_printf(mon, "     address: %s:%s%s\n",
467                            chan->value->host, chan->value->port,
468                            chan->value->tls ? " [tls]" : "");
469             monitor_printf(mon, "     session: %" PRId64 "\n",
470                            chan->value->connection_id);
471             monitor_printf(mon, "     channel: %" PRId64 ":%" PRId64 "\n",
472                            chan->value->channel_type, chan->value->channel_id);
473         }
474     }
475
476 out:
477     qapi_free_SpiceInfo(info);
478 }
479
480 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
481 {
482     BalloonInfo *info;
483     Error *err = NULL;
484
485     info = qmp_query_balloon(&err);
486     if (err) {
487         monitor_printf(mon, "%s\n", error_get_pretty(err));
488         error_free(err);
489         return;
490     }
491
492     monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
493
494     qapi_free_BalloonInfo(info);
495 }
496
497 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
498 {
499     PciMemoryRegionList *region;
500
501     monitor_printf(mon, "  Bus %2" PRId64 ", ", dev->bus);
502     monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
503                    dev->slot, dev->function);
504     monitor_printf(mon, "    ");
505
506     if (dev->class_info.has_desc) {
507         monitor_printf(mon, "%s", dev->class_info.desc);
508     } else {
509         monitor_printf(mon, "Class %04" PRId64, dev->class_info.class);
510     }
511
512     monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
513                    dev->id.vendor, dev->id.device);
514
515     if (dev->has_irq) {
516         monitor_printf(mon, "      IRQ %" PRId64 ".\n", dev->irq);
517     }
518
519     if (dev->has_pci_bridge) {
520         monitor_printf(mon, "      BUS %" PRId64 ".\n",
521                        dev->pci_bridge->bus.number);
522         monitor_printf(mon, "      secondary bus %" PRId64 ".\n",
523                        dev->pci_bridge->bus.secondary);
524         monitor_printf(mon, "      subordinate bus %" PRId64 ".\n",
525                        dev->pci_bridge->bus.subordinate);
526
527         monitor_printf(mon, "      IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
528                        dev->pci_bridge->bus.io_range->base,
529                        dev->pci_bridge->bus.io_range->limit);
530
531         monitor_printf(mon,
532                        "      memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
533                        dev->pci_bridge->bus.memory_range->base,
534                        dev->pci_bridge->bus.memory_range->limit);
535
536         monitor_printf(mon, "      prefetchable memory range "
537                        "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
538                        dev->pci_bridge->bus.prefetchable_range->base,
539                        dev->pci_bridge->bus.prefetchable_range->limit);
540     }
541
542     for (region = dev->regions; region; region = region->next) {
543         uint64_t addr, size;
544
545         addr = region->value->address;
546         size = region->value->size;
547
548         monitor_printf(mon, "      BAR%" PRId64 ": ", region->value->bar);
549
550         if (!strcmp(region->value->type, "io")) {
551             monitor_printf(mon, "I/O at 0x%04" PRIx64
552                                 " [0x%04" PRIx64 "].\n",
553                            addr, addr + size - 1);
554         } else {
555             monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
556                                " [0x%08" PRIx64 "].\n",
557                            region->value->mem_type_64 ? 64 : 32,
558                            region->value->prefetch ? " prefetchable" : "",
559                            addr, addr + size - 1);
560         }
561     }
562
563     monitor_printf(mon, "      id \"%s\"\n", dev->qdev_id);
564
565     if (dev->has_pci_bridge) {
566         if (dev->pci_bridge->has_devices) {
567             PciDeviceInfoList *cdev;
568             for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
569                 hmp_info_pci_device(mon, cdev->value);
570             }
571         }
572     }
573 }
574
575 void hmp_info_pci(Monitor *mon, const QDict *qdict)
576 {
577     PciInfoList *info_list, *info;
578     Error *err = NULL;
579
580     info_list = qmp_query_pci(&err);
581     if (err) {
582         monitor_printf(mon, "PCI devices not supported\n");
583         error_free(err);
584         return;
585     }
586
587     for (info = info_list; info; info = info->next) {
588         PciDeviceInfoList *dev;
589
590         for (dev = info->value->devices; dev; dev = dev->next) {
591             hmp_info_pci_device(mon, dev->value);
592         }
593     }
594
595     qapi_free_PciInfoList(info_list);
596 }
597
598 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
599 {
600     BlockJobInfoList *list;
601     Error *err = NULL;
602
603     list = qmp_query_block_jobs(&err);
604     assert(!err);
605
606     if (!list) {
607         monitor_printf(mon, "No active jobs\n");
608         return;
609     }
610
611     while (list) {
612         if (strcmp(list->value->type, "stream") == 0) {
613             monitor_printf(mon, "Streaming device %s: Completed %" PRId64
614                            " of %" PRId64 " bytes, speed limit %" PRId64
615                            " bytes/s\n",
616                            list->value->device,
617                            list->value->offset,
618                            list->value->len,
619                            list->value->speed);
620         } else {
621             monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
622                            " of %" PRId64 " bytes, speed limit %" PRId64
623                            " bytes/s\n",
624                            list->value->type,
625                            list->value->device,
626                            list->value->offset,
627                            list->value->len,
628                            list->value->speed);
629         }
630         list = list->next;
631     }
632 }
633
634 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
635 {
636     TPMInfoList *info_list, *info;
637     Error *err = NULL;
638     unsigned int c = 0;
639     TPMPassthroughOptions *tpo;
640
641     info_list = qmp_query_tpm(&err);
642     if (err) {
643         monitor_printf(mon, "TPM device not supported\n");
644         error_free(err);
645         return;
646     }
647
648     if (info_list) {
649         monitor_printf(mon, "TPM device:\n");
650     }
651
652     for (info = info_list; info; info = info->next) {
653         TPMInfo *ti = info->value;
654         monitor_printf(mon, " tpm%d: model=%s\n",
655                        c, TpmModel_lookup[ti->model]);
656
657         monitor_printf(mon, "  \\ %s: type=%s",
658                        ti->id, TpmTypeOptionsKind_lookup[ti->options->kind]);
659
660         switch (ti->options->kind) {
661         case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
662             tpo = ti->options->passthrough;
663             monitor_printf(mon, "%s%s%s%s",
664                            tpo->has_path ? ",path=" : "",
665                            tpo->has_path ? tpo->path : "",
666                            tpo->has_cancel_path ? ",cancel-path=" : "",
667                            tpo->has_cancel_path ? tpo->cancel_path : "");
668             break;
669         case TPM_TYPE_OPTIONS_KIND_MAX:
670             break;
671         }
672         monitor_printf(mon, "\n");
673         c++;
674     }
675     qapi_free_TPMInfoList(info_list);
676 }
677
678 void hmp_quit(Monitor *mon, const QDict *qdict)
679 {
680     monitor_suspend(mon);
681     qmp_quit(NULL);
682 }
683
684 void hmp_stop(Monitor *mon, const QDict *qdict)
685 {
686     qmp_stop(NULL);
687 }
688
689 void hmp_system_reset(Monitor *mon, const QDict *qdict)
690 {
691     qmp_system_reset(NULL);
692 }
693
694 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
695 {
696     qmp_system_powerdown(NULL);
697 }
698
699 void hmp_cpu(Monitor *mon, const QDict *qdict)
700 {
701     int64_t cpu_index;
702
703     /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
704             use it are converted to the QAPI */
705     cpu_index = qdict_get_int(qdict, "index");
706     if (monitor_set_cpu(cpu_index) < 0) {
707         monitor_printf(mon, "invalid CPU index\n");
708     }
709 }
710
711 void hmp_memsave(Monitor *mon, const QDict *qdict)
712 {
713     uint32_t size = qdict_get_int(qdict, "size");
714     const char *filename = qdict_get_str(qdict, "filename");
715     uint64_t addr = qdict_get_int(qdict, "val");
716     Error *errp = NULL;
717
718     qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &errp);
719     hmp_handle_error(mon, &errp);
720 }
721
722 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
723 {
724     uint32_t size = qdict_get_int(qdict, "size");
725     const char *filename = qdict_get_str(qdict, "filename");
726     uint64_t addr = qdict_get_int(qdict, "val");
727     Error *errp = NULL;
728
729     qmp_pmemsave(addr, size, filename, &errp);
730     hmp_handle_error(mon, &errp);
731 }
732
733 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
734 {
735     const char *chardev = qdict_get_str(qdict, "device");
736     const char *data = qdict_get_str(qdict, "data");
737     Error *errp = NULL;
738
739     qmp_ringbuf_write(chardev, data, false, 0, &errp);
740
741     hmp_handle_error(mon, &errp);
742 }
743
744 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
745 {
746     uint32_t size = qdict_get_int(qdict, "size");
747     const char *chardev = qdict_get_str(qdict, "device");
748     char *data;
749     Error *errp = NULL;
750     int i;
751
752     data = qmp_ringbuf_read(chardev, size, false, 0, &errp);
753     if (errp) {
754         monitor_printf(mon, "%s\n", error_get_pretty(errp));
755         error_free(errp);
756         return;
757     }
758
759     for (i = 0; data[i]; i++) {
760         unsigned char ch = data[i];
761
762         if (ch == '\\') {
763             monitor_printf(mon, "\\\\");
764         } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
765             monitor_printf(mon, "\\u%04X", ch);
766         } else {
767             monitor_printf(mon, "%c", ch);
768         }
769
770     }
771     monitor_printf(mon, "\n");
772     g_free(data);
773 }
774
775 static void hmp_cont_cb(void *opaque, int err)
776 {
777     if (!err) {
778         qmp_cont(NULL);
779     }
780 }
781
782 static bool key_is_missing(const BlockInfo *bdev)
783 {
784     return (bdev->inserted && bdev->inserted->encryption_key_missing);
785 }
786
787 void hmp_cont(Monitor *mon, const QDict *qdict)
788 {
789     BlockInfoList *bdev_list, *bdev;
790     Error *errp = NULL;
791
792     bdev_list = qmp_query_block(NULL);
793     for (bdev = bdev_list; bdev; bdev = bdev->next) {
794         if (key_is_missing(bdev->value)) {
795             monitor_read_block_device_key(mon, bdev->value->device,
796                                           hmp_cont_cb, NULL);
797             goto out;
798         }
799     }
800
801     qmp_cont(&errp);
802     hmp_handle_error(mon, &errp);
803
804 out:
805     qapi_free_BlockInfoList(bdev_list);
806 }
807
808 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
809 {
810     qmp_system_wakeup(NULL);
811 }
812
813 void hmp_inject_nmi(Monitor *mon, const QDict *qdict)
814 {
815     Error *errp = NULL;
816
817     qmp_inject_nmi(&errp);
818     hmp_handle_error(mon, &errp);
819 }
820
821 void hmp_set_link(Monitor *mon, const QDict *qdict)
822 {
823     const char *name = qdict_get_str(qdict, "name");
824     int up = qdict_get_bool(qdict, "up");
825     Error *errp = NULL;
826
827     qmp_set_link(name, up, &errp);
828     hmp_handle_error(mon, &errp);
829 }
830
831 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
832 {
833     const char *device = qdict_get_str(qdict, "device");
834     const char *password = qdict_get_str(qdict, "password");
835     Error *errp = NULL;
836
837     qmp_block_passwd(device, password, &errp);
838     hmp_handle_error(mon, &errp);
839 }
840
841 void hmp_balloon(Monitor *mon, const QDict *qdict)
842 {
843     int64_t value = qdict_get_int(qdict, "value");
844     Error *errp = NULL;
845
846     qmp_balloon(value, &errp);
847     if (error_is_set(&errp)) {
848         monitor_printf(mon, "balloon: %s\n", error_get_pretty(errp));
849         error_free(errp);
850     }
851 }
852
853 void hmp_block_resize(Monitor *mon, const QDict *qdict)
854 {
855     const char *device = qdict_get_str(qdict, "device");
856     int64_t size = qdict_get_int(qdict, "size");
857     Error *errp = NULL;
858
859     qmp_block_resize(device, size, &errp);
860     hmp_handle_error(mon, &errp);
861 }
862
863 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
864 {
865     const char *device = qdict_get_str(qdict, "device");
866     const char *filename = qdict_get_str(qdict, "target");
867     const char *format = qdict_get_try_str(qdict, "format");
868     int reuse = qdict_get_try_bool(qdict, "reuse", 0);
869     int full = qdict_get_try_bool(qdict, "full", 0);
870     enum NewImageMode mode;
871     Error *errp = NULL;
872
873     if (!filename) {
874         error_set(&errp, QERR_MISSING_PARAMETER, "target");
875         hmp_handle_error(mon, &errp);
876         return;
877     }
878
879     if (reuse) {
880         mode = NEW_IMAGE_MODE_EXISTING;
881     } else {
882         mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
883     }
884
885     qmp_drive_mirror(device, filename, !!format, format,
886                      full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
887                      true, mode, false, 0, false, 0, false, 0,
888                      false, 0, false, 0, &errp);
889     hmp_handle_error(mon, &errp);
890 }
891
892 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
893 {
894     const char *device = qdict_get_str(qdict, "device");
895     const char *filename = qdict_get_try_str(qdict, "snapshot-file");
896     const char *format = qdict_get_try_str(qdict, "format");
897     int reuse = qdict_get_try_bool(qdict, "reuse", 0);
898     enum NewImageMode mode;
899     Error *errp = NULL;
900
901     if (!filename) {
902         /* In the future, if 'snapshot-file' is not specified, the snapshot
903            will be taken internally. Today it's actually required. */
904         error_set(&errp, QERR_MISSING_PARAMETER, "snapshot-file");
905         hmp_handle_error(mon, &errp);
906         return;
907     }
908
909     mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
910     qmp_blockdev_snapshot_sync(device, filename, !!format, format,
911                                true, mode, &errp);
912     hmp_handle_error(mon, &errp);
913 }
914
915 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
916 {
917     qmp_migrate_cancel(NULL);
918 }
919
920 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
921 {
922     double value = qdict_get_double(qdict, "value");
923     qmp_migrate_set_downtime(value, NULL);
924 }
925
926 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
927 {
928     int64_t value = qdict_get_int(qdict, "value");
929     Error *err = NULL;
930
931     qmp_migrate_set_cache_size(value, &err);
932     if (err) {
933         monitor_printf(mon, "%s\n", error_get_pretty(err));
934         error_free(err);
935         return;
936     }
937 }
938
939 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
940 {
941     int64_t value = qdict_get_int(qdict, "value");
942     qmp_migrate_set_speed(value, NULL);
943 }
944
945 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
946 {
947     const char *cap = qdict_get_str(qdict, "capability");
948     bool state = qdict_get_bool(qdict, "state");
949     Error *err = NULL;
950     MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
951     int i;
952
953     for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
954         if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
955             caps->value = g_malloc0(sizeof(*caps->value));
956             caps->value->capability = i;
957             caps->value->state = state;
958             caps->next = NULL;
959             qmp_migrate_set_capabilities(caps, &err);
960             break;
961         }
962     }
963
964     if (i == MIGRATION_CAPABILITY_MAX) {
965         error_set(&err, QERR_INVALID_PARAMETER, cap);
966     }
967
968     qapi_free_MigrationCapabilityStatusList(caps);
969
970     if (err) {
971         monitor_printf(mon, "migrate_set_capability: %s\n",
972                        error_get_pretty(err));
973         error_free(err);
974     }
975 }
976
977 void hmp_set_password(Monitor *mon, const QDict *qdict)
978 {
979     const char *protocol  = qdict_get_str(qdict, "protocol");
980     const char *password  = qdict_get_str(qdict, "password");
981     const char *connected = qdict_get_try_str(qdict, "connected");
982     Error *err = NULL;
983
984     qmp_set_password(protocol, password, !!connected, connected, &err);
985     hmp_handle_error(mon, &err);
986 }
987
988 void hmp_expire_password(Monitor *mon, const QDict *qdict)
989 {
990     const char *protocol  = qdict_get_str(qdict, "protocol");
991     const char *whenstr = qdict_get_str(qdict, "time");
992     Error *err = NULL;
993
994     qmp_expire_password(protocol, whenstr, &err);
995     hmp_handle_error(mon, &err);
996 }
997
998 void hmp_eject(Monitor *mon, const QDict *qdict)
999 {
1000     int force = qdict_get_try_bool(qdict, "force", 0);
1001     const char *device = qdict_get_str(qdict, "device");
1002     Error *err = NULL;
1003
1004     qmp_eject(device, true, force, &err);
1005     hmp_handle_error(mon, &err);
1006 }
1007
1008 static void hmp_change_read_arg(Monitor *mon, const char *password,
1009                                 void *opaque)
1010 {
1011     qmp_change_vnc_password(password, NULL);
1012     monitor_read_command(mon, 1);
1013 }
1014
1015 void hmp_change(Monitor *mon, const QDict *qdict)
1016 {
1017     const char *device = qdict_get_str(qdict, "device");
1018     const char *target = qdict_get_str(qdict, "target");
1019     const char *arg = qdict_get_try_str(qdict, "arg");
1020     Error *err = NULL;
1021
1022     if (strcmp(device, "vnc") == 0 &&
1023             (strcmp(target, "passwd") == 0 ||
1024              strcmp(target, "password") == 0)) {
1025         if (!arg) {
1026             monitor_read_password(mon, hmp_change_read_arg, NULL);
1027             return;
1028         }
1029     }
1030
1031     qmp_change(device, target, !!arg, arg, &err);
1032     if (error_is_set(&err) &&
1033         error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
1034         error_free(err);
1035         monitor_read_block_device_key(mon, device, NULL, NULL);
1036         return;
1037     }
1038     hmp_handle_error(mon, &err);
1039 }
1040
1041 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1042 {
1043     Error *err = NULL;
1044
1045     qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
1046                               qdict_get_int(qdict, "bps"),
1047                               qdict_get_int(qdict, "bps_rd"),
1048                               qdict_get_int(qdict, "bps_wr"),
1049                               qdict_get_int(qdict, "iops"),
1050                               qdict_get_int(qdict, "iops_rd"),
1051                               qdict_get_int(qdict, "iops_wr"), &err);
1052     hmp_handle_error(mon, &err);
1053 }
1054
1055 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1056 {
1057     Error *error = NULL;
1058     const char *device = qdict_get_str(qdict, "device");
1059     const char *base = qdict_get_try_str(qdict, "base");
1060     int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1061
1062     qmp_block_stream(device, base != NULL, base,
1063                      qdict_haskey(qdict, "speed"), speed,
1064                      BLOCKDEV_ON_ERROR_REPORT, true, &error);
1065
1066     hmp_handle_error(mon, &error);
1067 }
1068
1069 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1070 {
1071     Error *error = NULL;
1072     const char *device = qdict_get_str(qdict, "device");
1073     int64_t value = qdict_get_int(qdict, "speed");
1074
1075     qmp_block_job_set_speed(device, value, &error);
1076
1077     hmp_handle_error(mon, &error);
1078 }
1079
1080 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1081 {
1082     Error *error = NULL;
1083     const char *device = qdict_get_str(qdict, "device");
1084     bool force = qdict_get_try_bool(qdict, "force", 0);
1085
1086     qmp_block_job_cancel(device, true, force, &error);
1087
1088     hmp_handle_error(mon, &error);
1089 }
1090
1091 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1092 {
1093     Error *error = NULL;
1094     const char *device = qdict_get_str(qdict, "device");
1095
1096     qmp_block_job_pause(device, &error);
1097
1098     hmp_handle_error(mon, &error);
1099 }
1100
1101 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1102 {
1103     Error *error = NULL;
1104     const char *device = qdict_get_str(qdict, "device");
1105
1106     qmp_block_job_resume(device, &error);
1107
1108     hmp_handle_error(mon, &error);
1109 }
1110
1111 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1112 {
1113     Error *error = NULL;
1114     const char *device = qdict_get_str(qdict, "device");
1115
1116     qmp_block_job_complete(device, &error);
1117
1118     hmp_handle_error(mon, &error);
1119 }
1120
1121 typedef struct MigrationStatus
1122 {
1123     QEMUTimer *timer;
1124     Monitor *mon;
1125     bool is_block_migration;
1126 } MigrationStatus;
1127
1128 static void hmp_migrate_status_cb(void *opaque)
1129 {
1130     MigrationStatus *status = opaque;
1131     MigrationInfo *info;
1132
1133     info = qmp_query_migrate(NULL);
1134     if (!info->has_status || strcmp(info->status, "active") == 0) {
1135         if (info->has_disk) {
1136             int progress;
1137
1138             if (info->disk->remaining) {
1139                 progress = info->disk->transferred * 100 / info->disk->total;
1140             } else {
1141                 progress = 100;
1142             }
1143
1144             monitor_printf(status->mon, "Completed %d %%\r", progress);
1145             monitor_flush(status->mon);
1146         }
1147
1148         qemu_mod_timer(status->timer, qemu_get_clock_ms(rt_clock) + 1000);
1149     } else {
1150         if (status->is_block_migration) {
1151             monitor_printf(status->mon, "\n");
1152         }
1153         monitor_resume(status->mon);
1154         qemu_del_timer(status->timer);
1155         g_free(status);
1156     }
1157
1158     qapi_free_MigrationInfo(info);
1159 }
1160
1161 void hmp_migrate(Monitor *mon, const QDict *qdict)
1162 {
1163     int detach = qdict_get_try_bool(qdict, "detach", 0);
1164     int blk = qdict_get_try_bool(qdict, "blk", 0);
1165     int inc = qdict_get_try_bool(qdict, "inc", 0);
1166     const char *uri = qdict_get_str(qdict, "uri");
1167     Error *err = NULL;
1168
1169     qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1170     if (err) {
1171         monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
1172         error_free(err);
1173         return;
1174     }
1175
1176     if (!detach) {
1177         MigrationStatus *status;
1178
1179         if (monitor_suspend(mon) < 0) {
1180             monitor_printf(mon, "terminal does not allow synchronous "
1181                            "migration, continuing detached\n");
1182             return;
1183         }
1184
1185         status = g_malloc0(sizeof(*status));
1186         status->mon = mon;
1187         status->is_block_migration = blk || inc;
1188         status->timer = qemu_new_timer_ms(rt_clock, hmp_migrate_status_cb,
1189                                           status);
1190         qemu_mod_timer(status->timer, qemu_get_clock_ms(rt_clock));
1191     }
1192 }
1193
1194 void hmp_device_del(Monitor *mon, const QDict *qdict)
1195 {
1196     const char *id = qdict_get_str(qdict, "id");
1197     Error *err = NULL;
1198
1199     qmp_device_del(id, &err);
1200     hmp_handle_error(mon, &err);
1201 }
1202
1203 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1204 {
1205     Error *errp = NULL;
1206     int paging = qdict_get_try_bool(qdict, "paging", 0);
1207     const char *file = qdict_get_str(qdict, "filename");
1208     bool has_begin = qdict_haskey(qdict, "begin");
1209     bool has_length = qdict_haskey(qdict, "length");
1210     int64_t begin = 0;
1211     int64_t length = 0;
1212     char *prot;
1213
1214     if (has_begin) {
1215         begin = qdict_get_int(qdict, "begin");
1216     }
1217     if (has_length) {
1218         length = qdict_get_int(qdict, "length");
1219     }
1220
1221     prot = g_strconcat("file:", file, NULL);
1222
1223     qmp_dump_guest_memory(paging, prot, has_begin, begin, has_length, length,
1224                           &errp);
1225     hmp_handle_error(mon, &errp);
1226     g_free(prot);
1227 }
1228
1229 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1230 {
1231     Error *err = NULL;
1232     QemuOpts *opts;
1233
1234     opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1235     if (error_is_set(&err)) {
1236         goto out;
1237     }
1238
1239     netdev_add(opts, &err);
1240     if (error_is_set(&err)) {
1241         qemu_opts_del(opts);
1242     }
1243
1244 out:
1245     hmp_handle_error(mon, &err);
1246 }
1247
1248 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1249 {
1250     const char *id = qdict_get_str(qdict, "id");
1251     Error *err = NULL;
1252
1253     qmp_netdev_del(id, &err);
1254     hmp_handle_error(mon, &err);
1255 }
1256
1257 void hmp_getfd(Monitor *mon, const QDict *qdict)
1258 {
1259     const char *fdname = qdict_get_str(qdict, "fdname");
1260     Error *errp = NULL;
1261
1262     qmp_getfd(fdname, &errp);
1263     hmp_handle_error(mon, &errp);
1264 }
1265
1266 void hmp_closefd(Monitor *mon, const QDict *qdict)
1267 {
1268     const char *fdname = qdict_get_str(qdict, "fdname");
1269     Error *errp = NULL;
1270
1271     qmp_closefd(fdname, &errp);
1272     hmp_handle_error(mon, &errp);
1273 }
1274
1275 void hmp_send_key(Monitor *mon, const QDict *qdict)
1276 {
1277     const char *keys = qdict_get_str(qdict, "keys");
1278     KeyValueList *keylist, *head = NULL, *tmp = NULL;
1279     int has_hold_time = qdict_haskey(qdict, "hold-time");
1280     int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1281     Error *err = NULL;
1282     char keyname_buf[16];
1283     char *separator;
1284     int keyname_len;
1285
1286     while (1) {
1287         separator = strchr(keys, '-');
1288         keyname_len = separator ? separator - keys : strlen(keys);
1289         pstrcpy(keyname_buf, sizeof(keyname_buf), keys);
1290
1291         /* Be compatible with old interface, convert user inputted "<" */
1292         if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) {
1293             pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
1294             keyname_len = 4;
1295         }
1296         keyname_buf[keyname_len] = 0;
1297
1298         keylist = g_malloc0(sizeof(*keylist));
1299         keylist->value = g_malloc0(sizeof(*keylist->value));
1300
1301         if (!head) {
1302             head = keylist;
1303         }
1304         if (tmp) {
1305             tmp->next = keylist;
1306         }
1307         tmp = keylist;
1308
1309         if (strstart(keyname_buf, "0x", NULL)) {
1310             char *endp;
1311             int value = strtoul(keyname_buf, &endp, 0);
1312             if (*endp != '\0') {
1313                 goto err_out;
1314             }
1315             keylist->value->kind = KEY_VALUE_KIND_NUMBER;
1316             keylist->value->number = value;
1317         } else {
1318             int idx = index_from_key(keyname_buf);
1319             if (idx == Q_KEY_CODE_MAX) {
1320                 goto err_out;
1321             }
1322             keylist->value->kind = KEY_VALUE_KIND_QCODE;
1323             keylist->value->qcode = idx;
1324         }
1325
1326         if (!separator) {
1327             break;
1328         }
1329         keys = separator + 1;
1330     }
1331
1332     qmp_send_key(head, has_hold_time, hold_time, &err);
1333     hmp_handle_error(mon, &err);
1334
1335 out:
1336     qapi_free_KeyValueList(head);
1337     return;
1338
1339 err_out:
1340     monitor_printf(mon, "invalid parameter: %s\n", keyname_buf);
1341     goto out;
1342 }
1343
1344 void hmp_screen_dump(Monitor *mon, const QDict *qdict)
1345 {
1346     const char *filename = qdict_get_str(qdict, "filename");
1347     Error *err = NULL;
1348
1349     qmp_screendump(filename, &err);
1350     hmp_handle_error(mon, &err);
1351 }
1352
1353 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1354 {
1355     const char *uri = qdict_get_str(qdict, "uri");
1356     int writable = qdict_get_try_bool(qdict, "writable", 0);
1357     int all = qdict_get_try_bool(qdict, "all", 0);
1358     Error *local_err = NULL;
1359     BlockInfoList *block_list, *info;
1360     SocketAddress *addr;
1361
1362     if (writable && !all) {
1363         error_setg(&local_err, "-w only valid together with -a");
1364         goto exit;
1365     }
1366
1367     /* First check if the address is valid and start the server.  */
1368     addr = socket_parse(uri, &local_err);
1369     if (local_err != NULL) {
1370         goto exit;
1371     }
1372
1373     qmp_nbd_server_start(addr, &local_err);
1374     qapi_free_SocketAddress(addr);
1375     if (local_err != NULL) {
1376         goto exit;
1377     }
1378
1379     if (!all) {
1380         return;
1381     }
1382
1383     /* Then try adding all block devices.  If one fails, close all and
1384      * exit.
1385      */
1386     block_list = qmp_query_block(NULL);
1387
1388     for (info = block_list; info; info = info->next) {
1389         if (!info->value->has_inserted) {
1390             continue;
1391         }
1392
1393         qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1394
1395         if (local_err != NULL) {
1396             qmp_nbd_server_stop(NULL);
1397             break;
1398         }
1399     }
1400
1401     qapi_free_BlockInfoList(block_list);
1402
1403 exit:
1404     hmp_handle_error(mon, &local_err);
1405 }
1406
1407 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1408 {
1409     const char *device = qdict_get_str(qdict, "device");
1410     int writable = qdict_get_try_bool(qdict, "writable", 0);
1411     Error *local_err = NULL;
1412
1413     qmp_nbd_server_add(device, true, writable, &local_err);
1414
1415     if (local_err != NULL) {
1416         hmp_handle_error(mon, &local_err);
1417     }
1418 }
1419
1420 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1421 {
1422     Error *errp = NULL;
1423
1424     qmp_nbd_server_stop(&errp);
1425     hmp_handle_error(mon, &errp);
1426 }
1427
1428 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1429 {
1430     const char *args = qdict_get_str(qdict, "args");
1431     Error *err = NULL;
1432     QemuOpts *opts;
1433
1434     opts = qemu_opts_parse(qemu_find_opts("chardev"), args, 1);
1435     if (opts == NULL) {
1436         error_setg(&err, "Parsing chardev args failed");
1437     } else {
1438         qemu_chr_new_from_opts(opts, NULL, &err);
1439     }
1440     hmp_handle_error(mon, &err);
1441 }
1442
1443 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1444 {
1445     Error *local_err = NULL;
1446
1447     qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1448     hmp_handle_error(mon, &local_err);
1449 }
1450
1451 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1452 {
1453     BlockDriverState *bs;
1454     const char* device = qdict_get_str(qdict, "device");
1455     const char* command = qdict_get_str(qdict, "command");
1456     Error *err = NULL;
1457
1458     bs = bdrv_find(device);
1459     if (bs) {
1460         qemuio_command(bs, command);
1461     } else {
1462         error_set(&err, QERR_DEVICE_NOT_FOUND, device);
1463     }
1464
1465     hmp_handle_error(mon, &err);
1466 }
This page took 0.127095 seconds and 4 git commands to generate.