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