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