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