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