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