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