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