]> git.proxmox.com Git - qemu.git/blob - hmp.c
hmp: show ImageInfo in 'info block'
[qemu.git] / hmp.c
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 *
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
284 block_list = qmp_query_block(NULL);
285
286 for (info = block_list; info; info = info->next) {
287 monitor_printf(mon, "%s: removable=%d",
288 info->value->device, info->value->removable);
289
290 if (info->value->removable) {
291 monitor_printf(mon, " locked=%d", info->value->locked);
292 monitor_printf(mon, " tray-open=%d", info->value->tray_open);
293 }
294
295 if (info->value->has_io_status) {
296 monitor_printf(mon, " io-status=%s",
297 BlockDeviceIoStatus_lookup[info->value->io_status]);
298 }
299
300 if (info->value->has_inserted) {
301 monitor_printf(mon, " file=");
302 monitor_print_filename(mon, info->value->inserted->file);
303
304 if (info->value->inserted->has_backing_file) {
305 monitor_printf(mon, " backing_file=");
306 monitor_print_filename(mon, info->value->inserted->backing_file);
307 monitor_printf(mon, " backing_file_depth=%" PRId64,
308 info->value->inserted->backing_file_depth);
309 }
310 monitor_printf(mon, " ro=%d drv=%s encrypted=%d",
311 info->value->inserted->ro,
312 info->value->inserted->drv,
313 info->value->inserted->encrypted);
314
315 monitor_printf(mon, " bps=%" PRId64 " bps_rd=%" PRId64
316 " bps_wr=%" PRId64 " iops=%" PRId64
317 " iops_rd=%" PRId64 " iops_wr=%" PRId64,
318 info->value->inserted->bps,
319 info->value->inserted->bps_rd,
320 info->value->inserted->bps_wr,
321 info->value->inserted->iops,
322 info->value->inserted->iops_rd,
323 info->value->inserted->iops_wr);
324
325 monitor_printf(mon, " images:\n");
326 image_info = info->value->inserted->image;
327 while (1) {
328 bdrv_image_info_dump((fprintf_function)monitor_printf, mon,
329 image_info);
330 if (image_info->has_backing_image) {
331 image_info = image_info->backing_image;
332 } else {
333 break;
334 }
335 }
336 } else {
337 monitor_printf(mon, " [not inserted]");
338 }
339
340 monitor_printf(mon, "\n");
341 }
342
343 qapi_free_BlockInfoList(block_list);
344 }
345
346 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
347 {
348 BlockStatsList *stats_list, *stats;
349
350 stats_list = qmp_query_blockstats(NULL);
351
352 for (stats = stats_list; stats; stats = stats->next) {
353 if (!stats->value->has_device) {
354 continue;
355 }
356
357 monitor_printf(mon, "%s:", stats->value->device);
358 monitor_printf(mon, " rd_bytes=%" PRId64
359 " wr_bytes=%" PRId64
360 " rd_operations=%" PRId64
361 " wr_operations=%" PRId64
362 " flush_operations=%" PRId64
363 " wr_total_time_ns=%" PRId64
364 " rd_total_time_ns=%" PRId64
365 " flush_total_time_ns=%" PRId64
366 "\n",
367 stats->value->stats->rd_bytes,
368 stats->value->stats->wr_bytes,
369 stats->value->stats->rd_operations,
370 stats->value->stats->wr_operations,
371 stats->value->stats->flush_operations,
372 stats->value->stats->wr_total_time_ns,
373 stats->value->stats->rd_total_time_ns,
374 stats->value->stats->flush_total_time_ns);
375 }
376
377 qapi_free_BlockStatsList(stats_list);
378 }
379
380 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
381 {
382 VncInfo *info;
383 Error *err = NULL;
384 VncClientInfoList *client;
385
386 info = qmp_query_vnc(&err);
387 if (err) {
388 monitor_printf(mon, "%s\n", error_get_pretty(err));
389 error_free(err);
390 return;
391 }
392
393 if (!info->enabled) {
394 monitor_printf(mon, "Server: disabled\n");
395 goto out;
396 }
397
398 monitor_printf(mon, "Server:\n");
399 if (info->has_host && info->has_service) {
400 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
401 }
402 if (info->has_auth) {
403 monitor_printf(mon, " auth: %s\n", info->auth);
404 }
405
406 if (!info->has_clients || info->clients == NULL) {
407 monitor_printf(mon, "Client: none\n");
408 } else {
409 for (client = info->clients; client; client = client->next) {
410 monitor_printf(mon, "Client:\n");
411 monitor_printf(mon, " address: %s:%s\n",
412 client->value->host, client->value->service);
413 monitor_printf(mon, " x509_dname: %s\n",
414 client->value->x509_dname ?
415 client->value->x509_dname : "none");
416 monitor_printf(mon, " username: %s\n",
417 client->value->has_sasl_username ?
418 client->value->sasl_username : "none");
419 }
420 }
421
422 out:
423 qapi_free_VncInfo(info);
424 }
425
426 void hmp_info_spice(Monitor *mon, const QDict *qdict)
427 {
428 SpiceChannelList *chan;
429 SpiceInfo *info;
430
431 info = qmp_query_spice(NULL);
432
433 if (!info->enabled) {
434 monitor_printf(mon, "Server: disabled\n");
435 goto out;
436 }
437
438 monitor_printf(mon, "Server:\n");
439 if (info->has_port) {
440 monitor_printf(mon, " address: %s:%" PRId64 "\n",
441 info->host, info->port);
442 }
443 if (info->has_tls_port) {
444 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
445 info->host, info->tls_port);
446 }
447 monitor_printf(mon, " migrated: %s\n",
448 info->migrated ? "true" : "false");
449 monitor_printf(mon, " auth: %s\n", info->auth);
450 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
451 monitor_printf(mon, " mouse-mode: %s\n",
452 SpiceQueryMouseMode_lookup[info->mouse_mode]);
453
454 if (!info->has_channels || info->channels == NULL) {
455 monitor_printf(mon, "Channels: none\n");
456 } else {
457 for (chan = info->channels; chan; chan = chan->next) {
458 monitor_printf(mon, "Channel:\n");
459 monitor_printf(mon, " address: %s:%s%s\n",
460 chan->value->host, chan->value->port,
461 chan->value->tls ? " [tls]" : "");
462 monitor_printf(mon, " session: %" PRId64 "\n",
463 chan->value->connection_id);
464 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
465 chan->value->channel_type, chan->value->channel_id);
466 }
467 }
468
469 out:
470 qapi_free_SpiceInfo(info);
471 }
472
473 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
474 {
475 BalloonInfo *info;
476 Error *err = NULL;
477
478 info = qmp_query_balloon(&err);
479 if (err) {
480 monitor_printf(mon, "%s\n", error_get_pretty(err));
481 error_free(err);
482 return;
483 }
484
485 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
486
487 qapi_free_BalloonInfo(info);
488 }
489
490 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
491 {
492 PciMemoryRegionList *region;
493
494 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
495 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
496 dev->slot, dev->function);
497 monitor_printf(mon, " ");
498
499 if (dev->class_info.has_desc) {
500 monitor_printf(mon, "%s", dev->class_info.desc);
501 } else {
502 monitor_printf(mon, "Class %04" PRId64, dev->class_info.class);
503 }
504
505 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
506 dev->id.vendor, dev->id.device);
507
508 if (dev->has_irq) {
509 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
510 }
511
512 if (dev->has_pci_bridge) {
513 monitor_printf(mon, " BUS %" PRId64 ".\n",
514 dev->pci_bridge->bus.number);
515 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
516 dev->pci_bridge->bus.secondary);
517 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
518 dev->pci_bridge->bus.subordinate);
519
520 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
521 dev->pci_bridge->bus.io_range->base,
522 dev->pci_bridge->bus.io_range->limit);
523
524 monitor_printf(mon,
525 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
526 dev->pci_bridge->bus.memory_range->base,
527 dev->pci_bridge->bus.memory_range->limit);
528
529 monitor_printf(mon, " prefetchable memory range "
530 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
531 dev->pci_bridge->bus.prefetchable_range->base,
532 dev->pci_bridge->bus.prefetchable_range->limit);
533 }
534
535 for (region = dev->regions; region; region = region->next) {
536 uint64_t addr, size;
537
538 addr = region->value->address;
539 size = region->value->size;
540
541 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
542
543 if (!strcmp(region->value->type, "io")) {
544 monitor_printf(mon, "I/O at 0x%04" PRIx64
545 " [0x%04" PRIx64 "].\n",
546 addr, addr + size - 1);
547 } else {
548 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
549 " [0x%08" PRIx64 "].\n",
550 region->value->mem_type_64 ? 64 : 32,
551 region->value->prefetch ? " prefetchable" : "",
552 addr, addr + size - 1);
553 }
554 }
555
556 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
557
558 if (dev->has_pci_bridge) {
559 if (dev->pci_bridge->has_devices) {
560 PciDeviceInfoList *cdev;
561 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
562 hmp_info_pci_device(mon, cdev->value);
563 }
564 }
565 }
566 }
567
568 void hmp_info_pci(Monitor *mon, const QDict *qdict)
569 {
570 PciInfoList *info_list, *info;
571 Error *err = NULL;
572
573 info_list = qmp_query_pci(&err);
574 if (err) {
575 monitor_printf(mon, "PCI devices not supported\n");
576 error_free(err);
577 return;
578 }
579
580 for (info = info_list; info; info = info->next) {
581 PciDeviceInfoList *dev;
582
583 for (dev = info->value->devices; dev; dev = dev->next) {
584 hmp_info_pci_device(mon, dev->value);
585 }
586 }
587
588 qapi_free_PciInfoList(info_list);
589 }
590
591 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
592 {
593 BlockJobInfoList *list;
594 Error *err = NULL;
595
596 list = qmp_query_block_jobs(&err);
597 assert(!err);
598
599 if (!list) {
600 monitor_printf(mon, "No active jobs\n");
601 return;
602 }
603
604 while (list) {
605 if (strcmp(list->value->type, "stream") == 0) {
606 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
607 " of %" PRId64 " bytes, speed limit %" PRId64
608 " bytes/s\n",
609 list->value->device,
610 list->value->offset,
611 list->value->len,
612 list->value->speed);
613 } else {
614 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
615 " of %" PRId64 " bytes, speed limit %" PRId64
616 " bytes/s\n",
617 list->value->type,
618 list->value->device,
619 list->value->offset,
620 list->value->len,
621 list->value->speed);
622 }
623 list = list->next;
624 }
625 }
626
627 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
628 {
629 TPMInfoList *info_list, *info;
630 Error *err = NULL;
631 unsigned int c = 0;
632 TPMPassthroughOptions *tpo;
633
634 info_list = qmp_query_tpm(&err);
635 if (err) {
636 monitor_printf(mon, "TPM device not supported\n");
637 error_free(err);
638 return;
639 }
640
641 if (info_list) {
642 monitor_printf(mon, "TPM device:\n");
643 }
644
645 for (info = info_list; info; info = info->next) {
646 TPMInfo *ti = info->value;
647 monitor_printf(mon, " tpm%d: model=%s\n",
648 c, TpmModel_lookup[ti->model]);
649
650 monitor_printf(mon, " \\ %s: type=%s",
651 ti->id, TpmTypeOptionsKind_lookup[ti->options->kind]);
652
653 switch (ti->options->kind) {
654 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
655 tpo = ti->options->passthrough;
656 monitor_printf(mon, "%s%s%s%s",
657 tpo->has_path ? ",path=" : "",
658 tpo->has_path ? tpo->path : "",
659 tpo->has_cancel_path ? ",cancel-path=" : "",
660 tpo->has_cancel_path ? tpo->cancel_path : "");
661 break;
662 case TPM_TYPE_OPTIONS_KIND_MAX:
663 break;
664 }
665 monitor_printf(mon, "\n");
666 c++;
667 }
668 qapi_free_TPMInfoList(info_list);
669 }
670
671 void hmp_quit(Monitor *mon, const QDict *qdict)
672 {
673 monitor_suspend(mon);
674 qmp_quit(NULL);
675 }
676
677 void hmp_stop(Monitor *mon, const QDict *qdict)
678 {
679 qmp_stop(NULL);
680 }
681
682 void hmp_system_reset(Monitor *mon, const QDict *qdict)
683 {
684 qmp_system_reset(NULL);
685 }
686
687 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
688 {
689 qmp_system_powerdown(NULL);
690 }
691
692 void hmp_cpu(Monitor *mon, const QDict *qdict)
693 {
694 int64_t cpu_index;
695
696 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
697 use it are converted to the QAPI */
698 cpu_index = qdict_get_int(qdict, "index");
699 if (monitor_set_cpu(cpu_index) < 0) {
700 monitor_printf(mon, "invalid CPU index\n");
701 }
702 }
703
704 void hmp_memsave(Monitor *mon, const QDict *qdict)
705 {
706 uint32_t size = qdict_get_int(qdict, "size");
707 const char *filename = qdict_get_str(qdict, "filename");
708 uint64_t addr = qdict_get_int(qdict, "val");
709 Error *errp = NULL;
710
711 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &errp);
712 hmp_handle_error(mon, &errp);
713 }
714
715 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
716 {
717 uint32_t size = qdict_get_int(qdict, "size");
718 const char *filename = qdict_get_str(qdict, "filename");
719 uint64_t addr = qdict_get_int(qdict, "val");
720 Error *errp = NULL;
721
722 qmp_pmemsave(addr, size, filename, &errp);
723 hmp_handle_error(mon, &errp);
724 }
725
726 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
727 {
728 const char *chardev = qdict_get_str(qdict, "device");
729 const char *data = qdict_get_str(qdict, "data");
730 Error *errp = NULL;
731
732 qmp_ringbuf_write(chardev, data, false, 0, &errp);
733
734 hmp_handle_error(mon, &errp);
735 }
736
737 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
738 {
739 uint32_t size = qdict_get_int(qdict, "size");
740 const char *chardev = qdict_get_str(qdict, "device");
741 char *data;
742 Error *errp = NULL;
743 int i;
744
745 data = qmp_ringbuf_read(chardev, size, false, 0, &errp);
746 if (errp) {
747 monitor_printf(mon, "%s\n", error_get_pretty(errp));
748 error_free(errp);
749 return;
750 }
751
752 for (i = 0; data[i]; i++) {
753 unsigned char ch = data[i];
754
755 if (ch == '\\') {
756 monitor_printf(mon, "\\\\");
757 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
758 monitor_printf(mon, "\\u%04X", ch);
759 } else {
760 monitor_printf(mon, "%c", ch);
761 }
762
763 }
764 monitor_printf(mon, "\n");
765 g_free(data);
766 }
767
768 static void hmp_cont_cb(void *opaque, int err)
769 {
770 if (!err) {
771 qmp_cont(NULL);
772 }
773 }
774
775 static bool key_is_missing(const BlockInfo *bdev)
776 {
777 return (bdev->inserted && bdev->inserted->encryption_key_missing);
778 }
779
780 void hmp_cont(Monitor *mon, const QDict *qdict)
781 {
782 BlockInfoList *bdev_list, *bdev;
783 Error *errp = NULL;
784
785 bdev_list = qmp_query_block(NULL);
786 for (bdev = bdev_list; bdev; bdev = bdev->next) {
787 if (key_is_missing(bdev->value)) {
788 monitor_read_block_device_key(mon, bdev->value->device,
789 hmp_cont_cb, NULL);
790 goto out;
791 }
792 }
793
794 qmp_cont(&errp);
795 hmp_handle_error(mon, &errp);
796
797 out:
798 qapi_free_BlockInfoList(bdev_list);
799 }
800
801 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
802 {
803 qmp_system_wakeup(NULL);
804 }
805
806 void hmp_inject_nmi(Monitor *mon, const QDict *qdict)
807 {
808 Error *errp = NULL;
809
810 qmp_inject_nmi(&errp);
811 hmp_handle_error(mon, &errp);
812 }
813
814 void hmp_set_link(Monitor *mon, const QDict *qdict)
815 {
816 const char *name = qdict_get_str(qdict, "name");
817 int up = qdict_get_bool(qdict, "up");
818 Error *errp = NULL;
819
820 qmp_set_link(name, up, &errp);
821 hmp_handle_error(mon, &errp);
822 }
823
824 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
825 {
826 const char *device = qdict_get_str(qdict, "device");
827 const char *password = qdict_get_str(qdict, "password");
828 Error *errp = NULL;
829
830 qmp_block_passwd(device, password, &errp);
831 hmp_handle_error(mon, &errp);
832 }
833
834 void hmp_balloon(Monitor *mon, const QDict *qdict)
835 {
836 int64_t value = qdict_get_int(qdict, "value");
837 Error *errp = NULL;
838
839 qmp_balloon(value, &errp);
840 if (error_is_set(&errp)) {
841 monitor_printf(mon, "balloon: %s\n", error_get_pretty(errp));
842 error_free(errp);
843 }
844 }
845
846 void hmp_block_resize(Monitor *mon, const QDict *qdict)
847 {
848 const char *device = qdict_get_str(qdict, "device");
849 int64_t size = qdict_get_int(qdict, "size");
850 Error *errp = NULL;
851
852 qmp_block_resize(device, size, &errp);
853 hmp_handle_error(mon, &errp);
854 }
855
856 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
857 {
858 const char *device = qdict_get_str(qdict, "device");
859 const char *filename = qdict_get_str(qdict, "target");
860 const char *format = qdict_get_try_str(qdict, "format");
861 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
862 int full = qdict_get_try_bool(qdict, "full", 0);
863 enum NewImageMode mode;
864 Error *errp = NULL;
865
866 if (!filename) {
867 error_set(&errp, QERR_MISSING_PARAMETER, "target");
868 hmp_handle_error(mon, &errp);
869 return;
870 }
871
872 if (reuse) {
873 mode = NEW_IMAGE_MODE_EXISTING;
874 } else {
875 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
876 }
877
878 qmp_drive_mirror(device, filename, !!format, format,
879 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
880 true, mode, false, 0, false, 0, false, 0,
881 false, 0, false, 0, &errp);
882 hmp_handle_error(mon, &errp);
883 }
884
885 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
886 {
887 const char *device = qdict_get_str(qdict, "device");
888 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
889 const char *format = qdict_get_try_str(qdict, "format");
890 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
891 enum NewImageMode mode;
892 Error *errp = NULL;
893
894 if (!filename) {
895 /* In the future, if 'snapshot-file' is not specified, the snapshot
896 will be taken internally. Today it's actually required. */
897 error_set(&errp, QERR_MISSING_PARAMETER, "snapshot-file");
898 hmp_handle_error(mon, &errp);
899 return;
900 }
901
902 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
903 qmp_blockdev_snapshot_sync(device, filename, !!format, format,
904 true, mode, &errp);
905 hmp_handle_error(mon, &errp);
906 }
907
908 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
909 {
910 qmp_migrate_cancel(NULL);
911 }
912
913 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
914 {
915 double value = qdict_get_double(qdict, "value");
916 qmp_migrate_set_downtime(value, NULL);
917 }
918
919 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
920 {
921 int64_t value = qdict_get_int(qdict, "value");
922 Error *err = NULL;
923
924 qmp_migrate_set_cache_size(value, &err);
925 if (err) {
926 monitor_printf(mon, "%s\n", error_get_pretty(err));
927 error_free(err);
928 return;
929 }
930 }
931
932 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
933 {
934 int64_t value = qdict_get_int(qdict, "value");
935 qmp_migrate_set_speed(value, NULL);
936 }
937
938 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
939 {
940 const char *cap = qdict_get_str(qdict, "capability");
941 bool state = qdict_get_bool(qdict, "state");
942 Error *err = NULL;
943 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
944 int i;
945
946 for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
947 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
948 caps->value = g_malloc0(sizeof(*caps->value));
949 caps->value->capability = i;
950 caps->value->state = state;
951 caps->next = NULL;
952 qmp_migrate_set_capabilities(caps, &err);
953 break;
954 }
955 }
956
957 if (i == MIGRATION_CAPABILITY_MAX) {
958 error_set(&err, QERR_INVALID_PARAMETER, cap);
959 }
960
961 qapi_free_MigrationCapabilityStatusList(caps);
962
963 if (err) {
964 monitor_printf(mon, "migrate_set_capability: %s\n",
965 error_get_pretty(err));
966 error_free(err);
967 }
968 }
969
970 void hmp_set_password(Monitor *mon, const QDict *qdict)
971 {
972 const char *protocol = qdict_get_str(qdict, "protocol");
973 const char *password = qdict_get_str(qdict, "password");
974 const char *connected = qdict_get_try_str(qdict, "connected");
975 Error *err = NULL;
976
977 qmp_set_password(protocol, password, !!connected, connected, &err);
978 hmp_handle_error(mon, &err);
979 }
980
981 void hmp_expire_password(Monitor *mon, const QDict *qdict)
982 {
983 const char *protocol = qdict_get_str(qdict, "protocol");
984 const char *whenstr = qdict_get_str(qdict, "time");
985 Error *err = NULL;
986
987 qmp_expire_password(protocol, whenstr, &err);
988 hmp_handle_error(mon, &err);
989 }
990
991 void hmp_eject(Monitor *mon, const QDict *qdict)
992 {
993 int force = qdict_get_try_bool(qdict, "force", 0);
994 const char *device = qdict_get_str(qdict, "device");
995 Error *err = NULL;
996
997 qmp_eject(device, true, force, &err);
998 hmp_handle_error(mon, &err);
999 }
1000
1001 static void hmp_change_read_arg(Monitor *mon, const char *password,
1002 void *opaque)
1003 {
1004 qmp_change_vnc_password(password, NULL);
1005 monitor_read_command(mon, 1);
1006 }
1007
1008 void hmp_change(Monitor *mon, const QDict *qdict)
1009 {
1010 const char *device = qdict_get_str(qdict, "device");
1011 const char *target = qdict_get_str(qdict, "target");
1012 const char *arg = qdict_get_try_str(qdict, "arg");
1013 Error *err = NULL;
1014
1015 if (strcmp(device, "vnc") == 0 &&
1016 (strcmp(target, "passwd") == 0 ||
1017 strcmp(target, "password") == 0)) {
1018 if (!arg) {
1019 monitor_read_password(mon, hmp_change_read_arg, NULL);
1020 return;
1021 }
1022 }
1023
1024 qmp_change(device, target, !!arg, arg, &err);
1025 if (error_is_set(&err) &&
1026 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
1027 error_free(err);
1028 monitor_read_block_device_key(mon, device, NULL, NULL);
1029 return;
1030 }
1031 hmp_handle_error(mon, &err);
1032 }
1033
1034 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1035 {
1036 Error *err = NULL;
1037
1038 qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
1039 qdict_get_int(qdict, "bps"),
1040 qdict_get_int(qdict, "bps_rd"),
1041 qdict_get_int(qdict, "bps_wr"),
1042 qdict_get_int(qdict, "iops"),
1043 qdict_get_int(qdict, "iops_rd"),
1044 qdict_get_int(qdict, "iops_wr"), &err);
1045 hmp_handle_error(mon, &err);
1046 }
1047
1048 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1049 {
1050 Error *error = NULL;
1051 const char *device = qdict_get_str(qdict, "device");
1052 const char *base = qdict_get_try_str(qdict, "base");
1053 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1054
1055 qmp_block_stream(device, base != NULL, base,
1056 qdict_haskey(qdict, "speed"), speed,
1057 BLOCKDEV_ON_ERROR_REPORT, true, &error);
1058
1059 hmp_handle_error(mon, &error);
1060 }
1061
1062 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1063 {
1064 Error *error = NULL;
1065 const char *device = qdict_get_str(qdict, "device");
1066 int64_t value = qdict_get_int(qdict, "speed");
1067
1068 qmp_block_job_set_speed(device, value, &error);
1069
1070 hmp_handle_error(mon, &error);
1071 }
1072
1073 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1074 {
1075 Error *error = NULL;
1076 const char *device = qdict_get_str(qdict, "device");
1077 bool force = qdict_get_try_bool(qdict, "force", 0);
1078
1079 qmp_block_job_cancel(device, true, force, &error);
1080
1081 hmp_handle_error(mon, &error);
1082 }
1083
1084 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1085 {
1086 Error *error = NULL;
1087 const char *device = qdict_get_str(qdict, "device");
1088
1089 qmp_block_job_pause(device, &error);
1090
1091 hmp_handle_error(mon, &error);
1092 }
1093
1094 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1095 {
1096 Error *error = NULL;
1097 const char *device = qdict_get_str(qdict, "device");
1098
1099 qmp_block_job_resume(device, &error);
1100
1101 hmp_handle_error(mon, &error);
1102 }
1103
1104 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1105 {
1106 Error *error = NULL;
1107 const char *device = qdict_get_str(qdict, "device");
1108
1109 qmp_block_job_complete(device, &error);
1110
1111 hmp_handle_error(mon, &error);
1112 }
1113
1114 typedef struct MigrationStatus
1115 {
1116 QEMUTimer *timer;
1117 Monitor *mon;
1118 bool is_block_migration;
1119 } MigrationStatus;
1120
1121 static void hmp_migrate_status_cb(void *opaque)
1122 {
1123 MigrationStatus *status = opaque;
1124 MigrationInfo *info;
1125
1126 info = qmp_query_migrate(NULL);
1127 if (!info->has_status || strcmp(info->status, "active") == 0) {
1128 if (info->has_disk) {
1129 int progress;
1130
1131 if (info->disk->remaining) {
1132 progress = info->disk->transferred * 100 / info->disk->total;
1133 } else {
1134 progress = 100;
1135 }
1136
1137 monitor_printf(status->mon, "Completed %d %%\r", progress);
1138 monitor_flush(status->mon);
1139 }
1140
1141 qemu_mod_timer(status->timer, qemu_get_clock_ms(rt_clock) + 1000);
1142 } else {
1143 if (status->is_block_migration) {
1144 monitor_printf(status->mon, "\n");
1145 }
1146 monitor_resume(status->mon);
1147 qemu_del_timer(status->timer);
1148 g_free(status);
1149 }
1150
1151 qapi_free_MigrationInfo(info);
1152 }
1153
1154 void hmp_migrate(Monitor *mon, const QDict *qdict)
1155 {
1156 int detach = qdict_get_try_bool(qdict, "detach", 0);
1157 int blk = qdict_get_try_bool(qdict, "blk", 0);
1158 int inc = qdict_get_try_bool(qdict, "inc", 0);
1159 const char *uri = qdict_get_str(qdict, "uri");
1160 Error *err = NULL;
1161
1162 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1163 if (err) {
1164 monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
1165 error_free(err);
1166 return;
1167 }
1168
1169 if (!detach) {
1170 MigrationStatus *status;
1171
1172 if (monitor_suspend(mon) < 0) {
1173 monitor_printf(mon, "terminal does not allow synchronous "
1174 "migration, continuing detached\n");
1175 return;
1176 }
1177
1178 status = g_malloc0(sizeof(*status));
1179 status->mon = mon;
1180 status->is_block_migration = blk || inc;
1181 status->timer = qemu_new_timer_ms(rt_clock, hmp_migrate_status_cb,
1182 status);
1183 qemu_mod_timer(status->timer, qemu_get_clock_ms(rt_clock));
1184 }
1185 }
1186
1187 void hmp_device_del(Monitor *mon, const QDict *qdict)
1188 {
1189 const char *id = qdict_get_str(qdict, "id");
1190 Error *err = NULL;
1191
1192 qmp_device_del(id, &err);
1193 hmp_handle_error(mon, &err);
1194 }
1195
1196 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1197 {
1198 Error *errp = NULL;
1199 int paging = qdict_get_try_bool(qdict, "paging", 0);
1200 const char *file = qdict_get_str(qdict, "filename");
1201 bool has_begin = qdict_haskey(qdict, "begin");
1202 bool has_length = qdict_haskey(qdict, "length");
1203 int64_t begin = 0;
1204 int64_t length = 0;
1205 char *prot;
1206
1207 if (has_begin) {
1208 begin = qdict_get_int(qdict, "begin");
1209 }
1210 if (has_length) {
1211 length = qdict_get_int(qdict, "length");
1212 }
1213
1214 prot = g_strconcat("file:", file, NULL);
1215
1216 qmp_dump_guest_memory(paging, prot, has_begin, begin, has_length, length,
1217 &errp);
1218 hmp_handle_error(mon, &errp);
1219 g_free(prot);
1220 }
1221
1222 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1223 {
1224 Error *err = NULL;
1225 QemuOpts *opts;
1226
1227 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1228 if (error_is_set(&err)) {
1229 goto out;
1230 }
1231
1232 netdev_add(opts, &err);
1233 if (error_is_set(&err)) {
1234 qemu_opts_del(opts);
1235 }
1236
1237 out:
1238 hmp_handle_error(mon, &err);
1239 }
1240
1241 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1242 {
1243 const char *id = qdict_get_str(qdict, "id");
1244 Error *err = NULL;
1245
1246 qmp_netdev_del(id, &err);
1247 hmp_handle_error(mon, &err);
1248 }
1249
1250 void hmp_getfd(Monitor *mon, const QDict *qdict)
1251 {
1252 const char *fdname = qdict_get_str(qdict, "fdname");
1253 Error *errp = NULL;
1254
1255 qmp_getfd(fdname, &errp);
1256 hmp_handle_error(mon, &errp);
1257 }
1258
1259 void hmp_closefd(Monitor *mon, const QDict *qdict)
1260 {
1261 const char *fdname = qdict_get_str(qdict, "fdname");
1262 Error *errp = NULL;
1263
1264 qmp_closefd(fdname, &errp);
1265 hmp_handle_error(mon, &errp);
1266 }
1267
1268 void hmp_send_key(Monitor *mon, const QDict *qdict)
1269 {
1270 const char *keys = qdict_get_str(qdict, "keys");
1271 KeyValueList *keylist, *head = NULL, *tmp = NULL;
1272 int has_hold_time = qdict_haskey(qdict, "hold-time");
1273 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1274 Error *err = NULL;
1275 char keyname_buf[16];
1276 char *separator;
1277 int keyname_len;
1278
1279 while (1) {
1280 separator = strchr(keys, '-');
1281 keyname_len = separator ? separator - keys : strlen(keys);
1282 pstrcpy(keyname_buf, sizeof(keyname_buf), keys);
1283
1284 /* Be compatible with old interface, convert user inputted "<" */
1285 if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) {
1286 pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
1287 keyname_len = 4;
1288 }
1289 keyname_buf[keyname_len] = 0;
1290
1291 keylist = g_malloc0(sizeof(*keylist));
1292 keylist->value = g_malloc0(sizeof(*keylist->value));
1293
1294 if (!head) {
1295 head = keylist;
1296 }
1297 if (tmp) {
1298 tmp->next = keylist;
1299 }
1300 tmp = keylist;
1301
1302 if (strstart(keyname_buf, "0x", NULL)) {
1303 char *endp;
1304 int value = strtoul(keyname_buf, &endp, 0);
1305 if (*endp != '\0') {
1306 goto err_out;
1307 }
1308 keylist->value->kind = KEY_VALUE_KIND_NUMBER;
1309 keylist->value->number = value;
1310 } else {
1311 int idx = index_from_key(keyname_buf);
1312 if (idx == Q_KEY_CODE_MAX) {
1313 goto err_out;
1314 }
1315 keylist->value->kind = KEY_VALUE_KIND_QCODE;
1316 keylist->value->qcode = idx;
1317 }
1318
1319 if (!separator) {
1320 break;
1321 }
1322 keys = separator + 1;
1323 }
1324
1325 qmp_send_key(head, has_hold_time, hold_time, &err);
1326 hmp_handle_error(mon, &err);
1327
1328 out:
1329 qapi_free_KeyValueList(head);
1330 return;
1331
1332 err_out:
1333 monitor_printf(mon, "invalid parameter: %s\n", keyname_buf);
1334 goto out;
1335 }
1336
1337 void hmp_screen_dump(Monitor *mon, const QDict *qdict)
1338 {
1339 const char *filename = qdict_get_str(qdict, "filename");
1340 Error *err = NULL;
1341
1342 qmp_screendump(filename, &err);
1343 hmp_handle_error(mon, &err);
1344 }
1345
1346 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1347 {
1348 const char *uri = qdict_get_str(qdict, "uri");
1349 int writable = qdict_get_try_bool(qdict, "writable", 0);
1350 int all = qdict_get_try_bool(qdict, "all", 0);
1351 Error *local_err = NULL;
1352 BlockInfoList *block_list, *info;
1353 SocketAddress *addr;
1354
1355 if (writable && !all) {
1356 error_setg(&local_err, "-w only valid together with -a");
1357 goto exit;
1358 }
1359
1360 /* First check if the address is valid and start the server. */
1361 addr = socket_parse(uri, &local_err);
1362 if (local_err != NULL) {
1363 goto exit;
1364 }
1365
1366 qmp_nbd_server_start(addr, &local_err);
1367 qapi_free_SocketAddress(addr);
1368 if (local_err != NULL) {
1369 goto exit;
1370 }
1371
1372 if (!all) {
1373 return;
1374 }
1375
1376 /* Then try adding all block devices. If one fails, close all and
1377 * exit.
1378 */
1379 block_list = qmp_query_block(NULL);
1380
1381 for (info = block_list; info; info = info->next) {
1382 if (!info->value->has_inserted) {
1383 continue;
1384 }
1385
1386 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1387
1388 if (local_err != NULL) {
1389 qmp_nbd_server_stop(NULL);
1390 break;
1391 }
1392 }
1393
1394 qapi_free_BlockInfoList(block_list);
1395
1396 exit:
1397 hmp_handle_error(mon, &local_err);
1398 }
1399
1400 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1401 {
1402 const char *device = qdict_get_str(qdict, "device");
1403 int writable = qdict_get_try_bool(qdict, "writable", 0);
1404 Error *local_err = NULL;
1405
1406 qmp_nbd_server_add(device, true, writable, &local_err);
1407
1408 if (local_err != NULL) {
1409 hmp_handle_error(mon, &local_err);
1410 }
1411 }
1412
1413 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1414 {
1415 Error *errp = NULL;
1416
1417 qmp_nbd_server_stop(&errp);
1418 hmp_handle_error(mon, &errp);
1419 }
1420
1421 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1422 {
1423 const char *args = qdict_get_str(qdict, "args");
1424 Error *err = NULL;
1425 QemuOpts *opts;
1426
1427 opts = qemu_opts_parse(qemu_find_opts("chardev"), args, 1);
1428 if (opts == NULL) {
1429 error_setg(&err, "Parsing chardev args failed");
1430 } else {
1431 qemu_chr_new_from_opts(opts, NULL, &err);
1432 }
1433 hmp_handle_error(mon, &err);
1434 }
1435
1436 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1437 {
1438 Error *local_err = NULL;
1439
1440 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1441 hmp_handle_error(mon, &local_err);
1442 }
1443
1444 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1445 {
1446 BlockDriverState *bs;
1447 const char* device = qdict_get_str(qdict, "device");
1448 const char* command = qdict_get_str(qdict, "command");
1449 Error *err = NULL;
1450
1451 bs = bdrv_find(device);
1452 if (bs) {
1453 qemuio_command(bs, command);
1454 } else {
1455 error_set(&err, QERR_DEVICE_NOT_FOUND, device);
1456 }
1457
1458 hmp_handle_error(mon, &err);
1459 }