]>
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" | |
1422e32d | 17 | #include "net/net.h" |
dccfcd0e | 18 | #include "sysemu/char.h" |
1de7afc9 PB |
19 | #include "qemu/option.h" |
20 | #include "qemu/timer.h" | |
48a32bed | 21 | #include "qmp-commands.h" |
1de7afc9 | 22 | #include "qemu/sockets.h" |
83c9089e | 23 | #include "monitor/monitor.h" |
28ecbaee | 24 | #include "ui/console.h" |
587da2c3 | 25 | #include "qemu-io.h" |
48a32bed | 26 | |
0cfd6a9a LC |
27 | static void hmp_handle_error(Monitor *mon, Error **errp) |
28 | { | |
29 | if (error_is_set(errp)) { | |
30 | monitor_printf(mon, "%s\n", error_get_pretty(*errp)); | |
31 | error_free(*errp); | |
32 | } | |
33 | } | |
34 | ||
84f2d0ea | 35 | void hmp_info_name(Monitor *mon, const QDict *qdict) |
48a32bed AL |
36 | { |
37 | NameInfo *info; | |
38 | ||
39 | info = qmp_query_name(NULL); | |
40 | if (info->has_name) { | |
41 | monitor_printf(mon, "%s\n", info->name); | |
42 | } | |
43 | qapi_free_NameInfo(info); | |
44 | } | |
b9c15f16 | 45 | |
84f2d0ea | 46 | void hmp_info_version(Monitor *mon, const QDict *qdict) |
b9c15f16 LC |
47 | { |
48 | VersionInfo *info; | |
49 | ||
50 | info = qmp_query_version(NULL); | |
51 | ||
52 | monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n", | |
53 | info->qemu.major, info->qemu.minor, info->qemu.micro, | |
54 | info->package); | |
55 | ||
56 | qapi_free_VersionInfo(info); | |
57 | } | |
292a2602 | 58 | |
84f2d0ea | 59 | void hmp_info_kvm(Monitor *mon, const QDict *qdict) |
292a2602 LC |
60 | { |
61 | KvmInfo *info; | |
62 | ||
63 | info = qmp_query_kvm(NULL); | |
64 | monitor_printf(mon, "kvm support: "); | |
65 | if (info->present) { | |
66 | monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled"); | |
67 | } else { | |
68 | monitor_printf(mon, "not compiled\n"); | |
69 | } | |
70 | ||
71 | qapi_free_KvmInfo(info); | |
72 | } | |
73 | ||
84f2d0ea | 74 | void hmp_info_status(Monitor *mon, const QDict *qdict) |
1fa9a5e4 LC |
75 | { |
76 | StatusInfo *info; | |
77 | ||
78 | info = qmp_query_status(NULL); | |
79 | ||
80 | monitor_printf(mon, "VM status: %s%s", | |
81 | info->running ? "running" : "paused", | |
82 | info->singlestep ? " (single step mode)" : ""); | |
83 | ||
84 | if (!info->running && info->status != RUN_STATE_PAUSED) { | |
85 | monitor_printf(mon, " (%s)", RunState_lookup[info->status]); | |
86 | } | |
87 | ||
88 | monitor_printf(mon, "\n"); | |
89 | ||
90 | qapi_free_StatusInfo(info); | |
91 | } | |
92 | ||
84f2d0ea | 93 | void hmp_info_uuid(Monitor *mon, const QDict *qdict) |
efab767e LC |
94 | { |
95 | UuidInfo *info; | |
96 | ||
97 | info = qmp_query_uuid(NULL); | |
98 | monitor_printf(mon, "%s\n", info->UUID); | |
99 | qapi_free_UuidInfo(info); | |
100 | } | |
c5a415a0 | 101 | |
84f2d0ea | 102 | void hmp_info_chardev(Monitor *mon, const QDict *qdict) |
c5a415a0 LC |
103 | { |
104 | ChardevInfoList *char_info, *info; | |
105 | ||
106 | char_info = qmp_query_chardev(NULL); | |
107 | for (info = char_info; info; info = info->next) { | |
108 | monitor_printf(mon, "%s: filename=%s\n", info->value->label, | |
109 | info->value->filename); | |
110 | } | |
111 | ||
112 | qapi_free_ChardevInfoList(char_info); | |
113 | } | |
7a7f325e | 114 | |
84f2d0ea | 115 | void hmp_info_mice(Monitor *mon, const QDict *qdict) |
e235cec3 LC |
116 | { |
117 | MouseInfoList *mice_list, *mouse; | |
118 | ||
119 | mice_list = qmp_query_mice(NULL); | |
120 | if (!mice_list) { | |
121 | monitor_printf(mon, "No mouse devices connected\n"); | |
122 | return; | |
123 | } | |
124 | ||
125 | for (mouse = mice_list; mouse; mouse = mouse->next) { | |
126 | monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n", | |
127 | mouse->value->current ? '*' : ' ', | |
128 | mouse->value->index, mouse->value->name, | |
129 | mouse->value->absolute ? " (absolute)" : ""); | |
130 | } | |
131 | ||
132 | qapi_free_MouseInfoList(mice_list); | |
133 | } | |
134 | ||
84f2d0ea | 135 | void hmp_info_migrate(Monitor *mon, const QDict *qdict) |
791e7c82 LC |
136 | { |
137 | MigrationInfo *info; | |
bbf6da32 | 138 | MigrationCapabilityStatusList *caps, *cap; |
791e7c82 LC |
139 | |
140 | info = qmp_query_migrate(NULL); | |
bbf6da32 OW |
141 | caps = qmp_query_migrate_capabilities(NULL); |
142 | ||
143 | /* do not display parameters during setup */ | |
144 | if (info->has_status && caps) { | |
145 | monitor_printf(mon, "capabilities: "); | |
146 | for (cap = caps; cap; cap = cap->next) { | |
147 | monitor_printf(mon, "%s: %s ", | |
148 | MigrationCapability_lookup[cap->value->capability], | |
149 | cap->value->state ? "on" : "off"); | |
150 | } | |
151 | monitor_printf(mon, "\n"); | |
152 | } | |
791e7c82 LC |
153 | |
154 | if (info->has_status) { | |
155 | monitor_printf(mon, "Migration status: %s\n", info->status); | |
7aa939af JQ |
156 | monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n", |
157 | info->total_time); | |
2c52ddf1 JQ |
158 | if (info->has_expected_downtime) { |
159 | monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n", | |
160 | info->expected_downtime); | |
161 | } | |
9c5a9fcf JQ |
162 | if (info->has_downtime) { |
163 | monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n", | |
164 | info->downtime); | |
165 | } | |
791e7c82 LC |
166 | } |
167 | ||
168 | if (info->has_ram) { | |
169 | monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n", | |
170 | info->ram->transferred >> 10); | |
171 | monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n", | |
172 | info->ram->remaining >> 10); | |
173 | monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n", | |
174 | info->ram->total >> 10); | |
004d4c10 OW |
175 | monitor_printf(mon, "duplicate: %" PRIu64 " pages\n", |
176 | info->ram->duplicate); | |
f1c72795 PL |
177 | monitor_printf(mon, "skipped: %" PRIu64 " pages\n", |
178 | info->ram->skipped); | |
004d4c10 OW |
179 | monitor_printf(mon, "normal: %" PRIu64 " pages\n", |
180 | info->ram->normal); | |
181 | monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n", | |
182 | info->ram->normal_bytes >> 10); | |
8d017193 JQ |
183 | if (info->ram->dirty_pages_rate) { |
184 | monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n", | |
185 | info->ram->dirty_pages_rate); | |
186 | } | |
791e7c82 LC |
187 | } |
188 | ||
189 | if (info->has_disk) { | |
190 | monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n", | |
191 | info->disk->transferred >> 10); | |
192 | monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n", | |
193 | info->disk->remaining >> 10); | |
194 | monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n", | |
195 | info->disk->total >> 10); | |
196 | } | |
197 | ||
f36d55af OW |
198 | if (info->has_xbzrle_cache) { |
199 | monitor_printf(mon, "cache size: %" PRIu64 " bytes\n", | |
200 | info->xbzrle_cache->cache_size); | |
201 | monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n", | |
202 | info->xbzrle_cache->bytes >> 10); | |
203 | monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n", | |
204 | info->xbzrle_cache->pages); | |
205 | monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n", | |
206 | info->xbzrle_cache->cache_miss); | |
207 | monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n", | |
208 | info->xbzrle_cache->overflow); | |
209 | } | |
210 | ||
791e7c82 | 211 | qapi_free_MigrationInfo(info); |
bbf6da32 OW |
212 | qapi_free_MigrationCapabilityStatusList(caps); |
213 | } | |
214 | ||
84f2d0ea | 215 | void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict) |
bbf6da32 OW |
216 | { |
217 | MigrationCapabilityStatusList *caps, *cap; | |
218 | ||
219 | caps = qmp_query_migrate_capabilities(NULL); | |
220 | ||
221 | if (caps) { | |
222 | monitor_printf(mon, "capabilities: "); | |
223 | for (cap = caps; cap; cap = cap->next) { | |
224 | monitor_printf(mon, "%s: %s ", | |
225 | MigrationCapability_lookup[cap->value->capability], | |
226 | cap->value->state ? "on" : "off"); | |
227 | } | |
228 | monitor_printf(mon, "\n"); | |
229 | } | |
230 | ||
231 | qapi_free_MigrationCapabilityStatusList(caps); | |
791e7c82 LC |
232 | } |
233 | ||
84f2d0ea | 234 | void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict) |
9e1ba4cc OW |
235 | { |
236 | monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n", | |
237 | qmp_query_migrate_cache_size(NULL) >> 10); | |
238 | } | |
239 | ||
84f2d0ea | 240 | void hmp_info_cpus(Monitor *mon, const QDict *qdict) |
de0b36b6 LC |
241 | { |
242 | CpuInfoList *cpu_list, *cpu; | |
243 | ||
244 | cpu_list = qmp_query_cpus(NULL); | |
245 | ||
246 | for (cpu = cpu_list; cpu; cpu = cpu->next) { | |
247 | int active = ' '; | |
248 | ||
249 | if (cpu->value->CPU == monitor_get_cpu_index()) { | |
250 | active = '*'; | |
251 | } | |
252 | ||
852bef0e | 253 | monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU); |
de0b36b6 LC |
254 | |
255 | if (cpu->value->has_pc) { | |
852bef0e | 256 | monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->pc); |
de0b36b6 LC |
257 | } |
258 | if (cpu->value->has_nip) { | |
852bef0e | 259 | monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->nip); |
de0b36b6 LC |
260 | } |
261 | if (cpu->value->has_npc) { | |
852bef0e | 262 | monitor_printf(mon, " npc=0x%016" PRIx64, cpu->value->npc); |
de0b36b6 LC |
263 | } |
264 | if (cpu->value->has_PC) { | |
852bef0e | 265 | monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->PC); |
de0b36b6 LC |
266 | } |
267 | ||
268 | if (cpu->value->halted) { | |
269 | monitor_printf(mon, " (halted)"); | |
270 | } | |
271 | ||
272 | monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id); | |
273 | } | |
274 | ||
275 | qapi_free_CpuInfoList(cpu_list); | |
276 | } | |
277 | ||
84f2d0ea | 278 | void hmp_info_block(Monitor *mon, const QDict *qdict) |
b2023818 LC |
279 | { |
280 | BlockInfoList *block_list, *info; | |
281 | ||
282 | block_list = qmp_query_block(NULL); | |
283 | ||
284 | for (info = block_list; info; info = info->next) { | |
285 | monitor_printf(mon, "%s: removable=%d", | |
286 | info->value->device, info->value->removable); | |
287 | ||
288 | if (info->value->removable) { | |
289 | monitor_printf(mon, " locked=%d", info->value->locked); | |
290 | monitor_printf(mon, " tray-open=%d", info->value->tray_open); | |
291 | } | |
292 | ||
293 | if (info->value->has_io_status) { | |
294 | monitor_printf(mon, " io-status=%s", | |
295 | BlockDeviceIoStatus_lookup[info->value->io_status]); | |
296 | } | |
297 | ||
298 | if (info->value->has_inserted) { | |
299 | monitor_printf(mon, " file="); | |
300 | monitor_print_filename(mon, info->value->inserted->file); | |
301 | ||
302 | if (info->value->inserted->has_backing_file) { | |
303 | monitor_printf(mon, " backing_file="); | |
304 | monitor_print_filename(mon, info->value->inserted->backing_file); | |
75115d95 BC |
305 | monitor_printf(mon, " backing_file_depth=%" PRId64, |
306 | info->value->inserted->backing_file_depth); | |
b2023818 LC |
307 | } |
308 | monitor_printf(mon, " ro=%d drv=%s encrypted=%d", | |
309 | info->value->inserted->ro, | |
310 | info->value->inserted->drv, | |
311 | info->value->inserted->encrypted); | |
727f005e ZYW |
312 | |
313 | monitor_printf(mon, " bps=%" PRId64 " bps_rd=%" PRId64 | |
314 | " bps_wr=%" PRId64 " iops=%" PRId64 | |
315 | " iops_rd=%" PRId64 " iops_wr=%" PRId64, | |
316 | info->value->inserted->bps, | |
317 | info->value->inserted->bps_rd, | |
318 | info->value->inserted->bps_wr, | |
319 | info->value->inserted->iops, | |
320 | info->value->inserted->iops_rd, | |
321 | info->value->inserted->iops_wr); | |
b2023818 LC |
322 | } else { |
323 | monitor_printf(mon, " [not inserted]"); | |
324 | } | |
325 | ||
326 | monitor_printf(mon, "\n"); | |
327 | } | |
328 | ||
329 | qapi_free_BlockInfoList(block_list); | |
330 | } | |
331 | ||
84f2d0ea | 332 | void hmp_info_blockstats(Monitor *mon, const QDict *qdict) |
f11f57e4 LC |
333 | { |
334 | BlockStatsList *stats_list, *stats; | |
335 | ||
336 | stats_list = qmp_query_blockstats(NULL); | |
337 | ||
338 | for (stats = stats_list; stats; stats = stats->next) { | |
339 | if (!stats->value->has_device) { | |
340 | continue; | |
341 | } | |
342 | ||
343 | monitor_printf(mon, "%s:", stats->value->device); | |
344 | monitor_printf(mon, " rd_bytes=%" PRId64 | |
345 | " wr_bytes=%" PRId64 | |
346 | " rd_operations=%" PRId64 | |
347 | " wr_operations=%" PRId64 | |
348 | " flush_operations=%" PRId64 | |
349 | " wr_total_time_ns=%" PRId64 | |
350 | " rd_total_time_ns=%" PRId64 | |
351 | " flush_total_time_ns=%" PRId64 | |
352 | "\n", | |
353 | stats->value->stats->rd_bytes, | |
354 | stats->value->stats->wr_bytes, | |
355 | stats->value->stats->rd_operations, | |
356 | stats->value->stats->wr_operations, | |
357 | stats->value->stats->flush_operations, | |
358 | stats->value->stats->wr_total_time_ns, | |
359 | stats->value->stats->rd_total_time_ns, | |
360 | stats->value->stats->flush_total_time_ns); | |
361 | } | |
362 | ||
363 | qapi_free_BlockStatsList(stats_list); | |
364 | } | |
365 | ||
84f2d0ea | 366 | void hmp_info_vnc(Monitor *mon, const QDict *qdict) |
2b54aa87 LC |
367 | { |
368 | VncInfo *info; | |
369 | Error *err = NULL; | |
370 | VncClientInfoList *client; | |
371 | ||
372 | info = qmp_query_vnc(&err); | |
373 | if (err) { | |
374 | monitor_printf(mon, "%s\n", error_get_pretty(err)); | |
375 | error_free(err); | |
376 | return; | |
377 | } | |
378 | ||
379 | if (!info->enabled) { | |
380 | monitor_printf(mon, "Server: disabled\n"); | |
381 | goto out; | |
382 | } | |
383 | ||
384 | monitor_printf(mon, "Server:\n"); | |
385 | if (info->has_host && info->has_service) { | |
386 | monitor_printf(mon, " address: %s:%s\n", info->host, info->service); | |
387 | } | |
388 | if (info->has_auth) { | |
389 | monitor_printf(mon, " auth: %s\n", info->auth); | |
390 | } | |
391 | ||
392 | if (!info->has_clients || info->clients == NULL) { | |
393 | monitor_printf(mon, "Client: none\n"); | |
394 | } else { | |
395 | for (client = info->clients; client; client = client->next) { | |
396 | monitor_printf(mon, "Client:\n"); | |
397 | monitor_printf(mon, " address: %s:%s\n", | |
398 | client->value->host, client->value->service); | |
399 | monitor_printf(mon, " x509_dname: %s\n", | |
400 | client->value->x509_dname ? | |
401 | client->value->x509_dname : "none"); | |
402 | monitor_printf(mon, " username: %s\n", | |
403 | client->value->has_sasl_username ? | |
404 | client->value->sasl_username : "none"); | |
405 | } | |
406 | } | |
407 | ||
408 | out: | |
409 | qapi_free_VncInfo(info); | |
410 | } | |
411 | ||
84f2d0ea | 412 | void hmp_info_spice(Monitor *mon, const QDict *qdict) |
d1f29646 LC |
413 | { |
414 | SpiceChannelList *chan; | |
415 | SpiceInfo *info; | |
416 | ||
417 | info = qmp_query_spice(NULL); | |
418 | ||
419 | if (!info->enabled) { | |
420 | monitor_printf(mon, "Server: disabled\n"); | |
421 | goto out; | |
422 | } | |
423 | ||
424 | monitor_printf(mon, "Server:\n"); | |
425 | if (info->has_port) { | |
426 | monitor_printf(mon, " address: %s:%" PRId64 "\n", | |
427 | info->host, info->port); | |
428 | } | |
429 | if (info->has_tls_port) { | |
430 | monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n", | |
431 | info->host, info->tls_port); | |
432 | } | |
61c4efe2 YH |
433 | monitor_printf(mon, " migrated: %s\n", |
434 | info->migrated ? "true" : "false"); | |
d1f29646 LC |
435 | monitor_printf(mon, " auth: %s\n", info->auth); |
436 | monitor_printf(mon, " compiled: %s\n", info->compiled_version); | |
4efee029 AL |
437 | monitor_printf(mon, " mouse-mode: %s\n", |
438 | SpiceQueryMouseMode_lookup[info->mouse_mode]); | |
d1f29646 LC |
439 | |
440 | if (!info->has_channels || info->channels == NULL) { | |
441 | monitor_printf(mon, "Channels: none\n"); | |
442 | } else { | |
443 | for (chan = info->channels; chan; chan = chan->next) { | |
444 | monitor_printf(mon, "Channel:\n"); | |
445 | monitor_printf(mon, " address: %s:%s%s\n", | |
446 | chan->value->host, chan->value->port, | |
447 | chan->value->tls ? " [tls]" : ""); | |
448 | monitor_printf(mon, " session: %" PRId64 "\n", | |
449 | chan->value->connection_id); | |
450 | monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n", | |
451 | chan->value->channel_type, chan->value->channel_id); | |
452 | } | |
453 | } | |
454 | ||
455 | out: | |
456 | qapi_free_SpiceInfo(info); | |
457 | } | |
458 | ||
84f2d0ea | 459 | void hmp_info_balloon(Monitor *mon, const QDict *qdict) |
96637bcd LC |
460 | { |
461 | BalloonInfo *info; | |
462 | Error *err = NULL; | |
463 | ||
464 | info = qmp_query_balloon(&err); | |
465 | if (err) { | |
466 | monitor_printf(mon, "%s\n", error_get_pretty(err)); | |
467 | error_free(err); | |
468 | return; | |
469 | } | |
470 | ||
01ceb97e | 471 | monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20); |
96637bcd LC |
472 | |
473 | qapi_free_BalloonInfo(info); | |
474 | } | |
475 | ||
79627472 LC |
476 | static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) |
477 | { | |
478 | PciMemoryRegionList *region; | |
479 | ||
480 | monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus); | |
481 | monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n", | |
482 | dev->slot, dev->function); | |
483 | monitor_printf(mon, " "); | |
484 | ||
485 | if (dev->class_info.has_desc) { | |
486 | monitor_printf(mon, "%s", dev->class_info.desc); | |
487 | } else { | |
488 | monitor_printf(mon, "Class %04" PRId64, dev->class_info.class); | |
489 | } | |
490 | ||
491 | monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n", | |
492 | dev->id.vendor, dev->id.device); | |
493 | ||
494 | if (dev->has_irq) { | |
495 | monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq); | |
496 | } | |
497 | ||
498 | if (dev->has_pci_bridge) { | |
499 | monitor_printf(mon, " BUS %" PRId64 ".\n", | |
500 | dev->pci_bridge->bus.number); | |
501 | monitor_printf(mon, " secondary bus %" PRId64 ".\n", | |
502 | dev->pci_bridge->bus.secondary); | |
503 | monitor_printf(mon, " subordinate bus %" PRId64 ".\n", | |
504 | dev->pci_bridge->bus.subordinate); | |
505 | ||
506 | monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n", | |
507 | dev->pci_bridge->bus.io_range->base, | |
508 | dev->pci_bridge->bus.io_range->limit); | |
509 | ||
510 | monitor_printf(mon, | |
511 | " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n", | |
512 | dev->pci_bridge->bus.memory_range->base, | |
513 | dev->pci_bridge->bus.memory_range->limit); | |
514 | ||
515 | monitor_printf(mon, " prefetchable memory range " | |
516 | "[0x%08"PRIx64", 0x%08"PRIx64"]\n", | |
517 | dev->pci_bridge->bus.prefetchable_range->base, | |
518 | dev->pci_bridge->bus.prefetchable_range->limit); | |
519 | } | |
520 | ||
521 | for (region = dev->regions; region; region = region->next) { | |
522 | uint64_t addr, size; | |
523 | ||
524 | addr = region->value->address; | |
525 | size = region->value->size; | |
526 | ||
527 | monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar); | |
528 | ||
529 | if (!strcmp(region->value->type, "io")) { | |
530 | monitor_printf(mon, "I/O at 0x%04" PRIx64 | |
531 | " [0x%04" PRIx64 "].\n", | |
532 | addr, addr + size - 1); | |
533 | } else { | |
534 | monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64 | |
535 | " [0x%08" PRIx64 "].\n", | |
536 | region->value->mem_type_64 ? 64 : 32, | |
537 | region->value->prefetch ? " prefetchable" : "", | |
538 | addr, addr + size - 1); | |
539 | } | |
540 | } | |
541 | ||
542 | monitor_printf(mon, " id \"%s\"\n", dev->qdev_id); | |
543 | ||
544 | if (dev->has_pci_bridge) { | |
545 | if (dev->pci_bridge->has_devices) { | |
546 | PciDeviceInfoList *cdev; | |
547 | for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) { | |
548 | hmp_info_pci_device(mon, cdev->value); | |
549 | } | |
550 | } | |
551 | } | |
552 | } | |
553 | ||
84f2d0ea | 554 | void hmp_info_pci(Monitor *mon, const QDict *qdict) |
79627472 | 555 | { |
f46cee37 | 556 | PciInfoList *info_list, *info; |
79627472 LC |
557 | Error *err = NULL; |
558 | ||
f46cee37 | 559 | info_list = qmp_query_pci(&err); |
79627472 LC |
560 | if (err) { |
561 | monitor_printf(mon, "PCI devices not supported\n"); | |
562 | error_free(err); | |
563 | return; | |
564 | } | |
565 | ||
f46cee37 | 566 | for (info = info_list; info; info = info->next) { |
79627472 LC |
567 | PciDeviceInfoList *dev; |
568 | ||
569 | for (dev = info->value->devices; dev; dev = dev->next) { | |
570 | hmp_info_pci_device(mon, dev->value); | |
571 | } | |
572 | } | |
573 | ||
f46cee37 | 574 | qapi_free_PciInfoList(info_list); |
79627472 LC |
575 | } |
576 | ||
84f2d0ea | 577 | void hmp_info_block_jobs(Monitor *mon, const QDict *qdict) |
fb5458cd SH |
578 | { |
579 | BlockJobInfoList *list; | |
580 | Error *err = NULL; | |
581 | ||
582 | list = qmp_query_block_jobs(&err); | |
583 | assert(!err); | |
584 | ||
585 | if (!list) { | |
586 | monitor_printf(mon, "No active jobs\n"); | |
587 | return; | |
588 | } | |
589 | ||
590 | while (list) { | |
591 | if (strcmp(list->value->type, "stream") == 0) { | |
592 | monitor_printf(mon, "Streaming device %s: Completed %" PRId64 | |
593 | " of %" PRId64 " bytes, speed limit %" PRId64 | |
594 | " bytes/s\n", | |
595 | list->value->device, | |
596 | list->value->offset, | |
597 | list->value->len, | |
598 | list->value->speed); | |
599 | } else { | |
600 | monitor_printf(mon, "Type %s, device %s: Completed %" PRId64 | |
601 | " of %" PRId64 " bytes, speed limit %" PRId64 | |
602 | " bytes/s\n", | |
603 | list->value->type, | |
604 | list->value->device, | |
605 | list->value->offset, | |
606 | list->value->len, | |
607 | list->value->speed); | |
608 | } | |
609 | list = list->next; | |
610 | } | |
611 | } | |
612 | ||
d1a0cf73 SB |
613 | void hmp_info_tpm(Monitor *mon, const QDict *qdict) |
614 | { | |
615 | TPMInfoList *info_list, *info; | |
616 | Error *err = NULL; | |
617 | unsigned int c = 0; | |
618 | TPMPassthroughOptions *tpo; | |
619 | ||
620 | info_list = qmp_query_tpm(&err); | |
621 | if (err) { | |
622 | monitor_printf(mon, "TPM device not supported\n"); | |
623 | error_free(err); | |
624 | return; | |
625 | } | |
626 | ||
627 | if (info_list) { | |
628 | monitor_printf(mon, "TPM device:\n"); | |
629 | } | |
630 | ||
631 | for (info = info_list; info; info = info->next) { | |
632 | TPMInfo *ti = info->value; | |
633 | monitor_printf(mon, " tpm%d: model=%s\n", | |
634 | c, TpmModel_lookup[ti->model]); | |
635 | ||
636 | monitor_printf(mon, " \\ %s: type=%s", | |
88ca7bcf | 637 | ti->id, TpmTypeOptionsKind_lookup[ti->options->kind]); |
d1a0cf73 | 638 | |
88ca7bcf CB |
639 | switch (ti->options->kind) { |
640 | case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH: | |
641 | tpo = ti->options->passthrough; | |
d1a0cf73 SB |
642 | monitor_printf(mon, "%s%s%s%s", |
643 | tpo->has_path ? ",path=" : "", | |
644 | tpo->has_path ? tpo->path : "", | |
645 | tpo->has_cancel_path ? ",cancel-path=" : "", | |
646 | tpo->has_cancel_path ? tpo->cancel_path : ""); | |
647 | break; | |
648 | case TPM_TYPE_OPTIONS_KIND_MAX: | |
649 | break; | |
650 | } | |
651 | monitor_printf(mon, "\n"); | |
652 | c++; | |
653 | } | |
654 | qapi_free_TPMInfoList(info_list); | |
655 | } | |
656 | ||
7a7f325e LC |
657 | void hmp_quit(Monitor *mon, const QDict *qdict) |
658 | { | |
659 | monitor_suspend(mon); | |
660 | qmp_quit(NULL); | |
661 | } | |
5f158f21 LC |
662 | |
663 | void hmp_stop(Monitor *mon, const QDict *qdict) | |
664 | { | |
665 | qmp_stop(NULL); | |
666 | } | |
38d22653 LC |
667 | |
668 | void hmp_system_reset(Monitor *mon, const QDict *qdict) | |
669 | { | |
670 | qmp_system_reset(NULL); | |
671 | } | |
5bc465e4 LC |
672 | |
673 | void hmp_system_powerdown(Monitor *mon, const QDict *qdict) | |
674 | { | |
675 | qmp_system_powerdown(NULL); | |
676 | } | |
755f1968 LC |
677 | |
678 | void hmp_cpu(Monitor *mon, const QDict *qdict) | |
679 | { | |
680 | int64_t cpu_index; | |
681 | ||
682 | /* XXX: drop the monitor_set_cpu() usage when all HMP commands that | |
683 | use it are converted to the QAPI */ | |
684 | cpu_index = qdict_get_int(qdict, "index"); | |
685 | if (monitor_set_cpu(cpu_index) < 0) { | |
686 | monitor_printf(mon, "invalid CPU index\n"); | |
687 | } | |
688 | } | |
0cfd6a9a LC |
689 | |
690 | void hmp_memsave(Monitor *mon, const QDict *qdict) | |
691 | { | |
692 | uint32_t size = qdict_get_int(qdict, "size"); | |
693 | const char *filename = qdict_get_str(qdict, "filename"); | |
694 | uint64_t addr = qdict_get_int(qdict, "val"); | |
695 | Error *errp = NULL; | |
696 | ||
697 | qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &errp); | |
698 | hmp_handle_error(mon, &errp); | |
699 | } | |
6d3962bf LC |
700 | |
701 | void hmp_pmemsave(Monitor *mon, const QDict *qdict) | |
702 | { | |
703 | uint32_t size = qdict_get_int(qdict, "size"); | |
704 | const char *filename = qdict_get_str(qdict, "filename"); | |
705 | uint64_t addr = qdict_get_int(qdict, "val"); | |
706 | Error *errp = NULL; | |
707 | ||
708 | qmp_pmemsave(addr, size, filename, &errp); | |
709 | hmp_handle_error(mon, &errp); | |
1f590cf9 LL |
710 | } |
711 | ||
3949e594 | 712 | void hmp_ringbuf_write(Monitor *mon, const QDict *qdict) |
1f590cf9 | 713 | { |
1f590cf9 LL |
714 | const char *chardev = qdict_get_str(qdict, "device"); |
715 | const char *data = qdict_get_str(qdict, "data"); | |
716 | Error *errp = NULL; | |
717 | ||
3949e594 | 718 | qmp_ringbuf_write(chardev, data, false, 0, &errp); |
1f590cf9 LL |
719 | |
720 | hmp_handle_error(mon, &errp); | |
6d3962bf | 721 | } |
e42e818b | 722 | |
3949e594 | 723 | void hmp_ringbuf_read(Monitor *mon, const QDict *qdict) |
49b6d722 LL |
724 | { |
725 | uint32_t size = qdict_get_int(qdict, "size"); | |
726 | const char *chardev = qdict_get_str(qdict, "device"); | |
3ab651fc | 727 | char *data; |
49b6d722 | 728 | Error *errp = NULL; |
543f3412 | 729 | int i; |
49b6d722 | 730 | |
3949e594 | 731 | data = qmp_ringbuf_read(chardev, size, false, 0, &errp); |
49b6d722 LL |
732 | if (errp) { |
733 | monitor_printf(mon, "%s\n", error_get_pretty(errp)); | |
734 | error_free(errp); | |
735 | return; | |
736 | } | |
737 | ||
543f3412 MA |
738 | for (i = 0; data[i]; i++) { |
739 | unsigned char ch = data[i]; | |
740 | ||
741 | if (ch == '\\') { | |
742 | monitor_printf(mon, "\\\\"); | |
743 | } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) { | |
744 | monitor_printf(mon, "\\u%04X", ch); | |
745 | } else { | |
746 | monitor_printf(mon, "%c", ch); | |
747 | } | |
748 | ||
749 | } | |
750 | monitor_printf(mon, "\n"); | |
3ab651fc | 751 | g_free(data); |
49b6d722 LL |
752 | } |
753 | ||
e42e818b LC |
754 | static void hmp_cont_cb(void *opaque, int err) |
755 | { | |
e42e818b | 756 | if (!err) { |
8b7f6fbb | 757 | qmp_cont(NULL); |
e42e818b LC |
758 | } |
759 | } | |
760 | ||
8b7f6fbb LC |
761 | static bool key_is_missing(const BlockInfo *bdev) |
762 | { | |
763 | return (bdev->inserted && bdev->inserted->encryption_key_missing); | |
764 | } | |
765 | ||
e42e818b LC |
766 | void hmp_cont(Monitor *mon, const QDict *qdict) |
767 | { | |
8b7f6fbb | 768 | BlockInfoList *bdev_list, *bdev; |
e42e818b LC |
769 | Error *errp = NULL; |
770 | ||
8b7f6fbb LC |
771 | bdev_list = qmp_query_block(NULL); |
772 | for (bdev = bdev_list; bdev; bdev = bdev->next) { | |
773 | if (key_is_missing(bdev->value)) { | |
774 | monitor_read_block_device_key(mon, bdev->value->device, | |
775 | hmp_cont_cb, NULL); | |
776 | goto out; | |
e42e818b | 777 | } |
e42e818b | 778 | } |
8b7f6fbb LC |
779 | |
780 | qmp_cont(&errp); | |
781 | hmp_handle_error(mon, &errp); | |
782 | ||
783 | out: | |
784 | qapi_free_BlockInfoList(bdev_list); | |
e42e818b | 785 | } |
ab49ab5c | 786 | |
9b9df25a GH |
787 | void hmp_system_wakeup(Monitor *mon, const QDict *qdict) |
788 | { | |
789 | qmp_system_wakeup(NULL); | |
790 | } | |
791 | ||
ab49ab5c LC |
792 | void hmp_inject_nmi(Monitor *mon, const QDict *qdict) |
793 | { | |
794 | Error *errp = NULL; | |
795 | ||
796 | qmp_inject_nmi(&errp); | |
797 | hmp_handle_error(mon, &errp); | |
798 | } | |
4b37156c LC |
799 | |
800 | void hmp_set_link(Monitor *mon, const QDict *qdict) | |
801 | { | |
802 | const char *name = qdict_get_str(qdict, "name"); | |
803 | int up = qdict_get_bool(qdict, "up"); | |
804 | Error *errp = NULL; | |
805 | ||
806 | qmp_set_link(name, up, &errp); | |
807 | hmp_handle_error(mon, &errp); | |
808 | } | |
a4dea8a9 LC |
809 | |
810 | void hmp_block_passwd(Monitor *mon, const QDict *qdict) | |
811 | { | |
812 | const char *device = qdict_get_str(qdict, "device"); | |
813 | const char *password = qdict_get_str(qdict, "password"); | |
814 | Error *errp = NULL; | |
815 | ||
816 | qmp_block_passwd(device, password, &errp); | |
817 | hmp_handle_error(mon, &errp); | |
818 | } | |
d72f3264 LC |
819 | |
820 | void hmp_balloon(Monitor *mon, const QDict *qdict) | |
821 | { | |
822 | int64_t value = qdict_get_int(qdict, "value"); | |
823 | Error *errp = NULL; | |
824 | ||
825 | qmp_balloon(value, &errp); | |
826 | if (error_is_set(&errp)) { | |
827 | monitor_printf(mon, "balloon: %s\n", error_get_pretty(errp)); | |
828 | error_free(errp); | |
829 | } | |
830 | } | |
5e7caacb LC |
831 | |
832 | void hmp_block_resize(Monitor *mon, const QDict *qdict) | |
833 | { | |
834 | const char *device = qdict_get_str(qdict, "device"); | |
835 | int64_t size = qdict_get_int(qdict, "size"); | |
836 | Error *errp = NULL; | |
837 | ||
838 | qmp_block_resize(device, size, &errp); | |
839 | hmp_handle_error(mon, &errp); | |
840 | } | |
6106e249 | 841 | |
d9b902db PB |
842 | void hmp_drive_mirror(Monitor *mon, const QDict *qdict) |
843 | { | |
844 | const char *device = qdict_get_str(qdict, "device"); | |
845 | const char *filename = qdict_get_str(qdict, "target"); | |
846 | const char *format = qdict_get_try_str(qdict, "format"); | |
847 | int reuse = qdict_get_try_bool(qdict, "reuse", 0); | |
848 | int full = qdict_get_try_bool(qdict, "full", 0); | |
849 | enum NewImageMode mode; | |
850 | Error *errp = NULL; | |
851 | ||
852 | if (!filename) { | |
853 | error_set(&errp, QERR_MISSING_PARAMETER, "target"); | |
854 | hmp_handle_error(mon, &errp); | |
855 | return; | |
856 | } | |
857 | ||
858 | if (reuse) { | |
859 | mode = NEW_IMAGE_MODE_EXISTING; | |
860 | } else { | |
861 | mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS; | |
862 | } | |
863 | ||
864 | qmp_drive_mirror(device, filename, !!format, format, | |
865 | full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP, | |
08e4ed6c | 866 | true, mode, false, 0, false, 0, false, 0, |
b952b558 | 867 | false, 0, false, 0, &errp); |
d9b902db PB |
868 | hmp_handle_error(mon, &errp); |
869 | } | |
870 | ||
6106e249 LC |
871 | void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) |
872 | { | |
873 | const char *device = qdict_get_str(qdict, "device"); | |
874 | const char *filename = qdict_get_try_str(qdict, "snapshot-file"); | |
875 | const char *format = qdict_get_try_str(qdict, "format"); | |
6cc2a415 PB |
876 | int reuse = qdict_get_try_bool(qdict, "reuse", 0); |
877 | enum NewImageMode mode; | |
6106e249 LC |
878 | Error *errp = NULL; |
879 | ||
880 | if (!filename) { | |
881 | /* In the future, if 'snapshot-file' is not specified, the snapshot | |
882 | will be taken internally. Today it's actually required. */ | |
883 | error_set(&errp, QERR_MISSING_PARAMETER, "snapshot-file"); | |
884 | hmp_handle_error(mon, &errp); | |
885 | return; | |
886 | } | |
887 | ||
6cc2a415 PB |
888 | mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS; |
889 | qmp_blockdev_snapshot_sync(device, filename, !!format, format, | |
890 | true, mode, &errp); | |
6106e249 LC |
891 | hmp_handle_error(mon, &errp); |
892 | } | |
6cdedb07 LC |
893 | |
894 | void hmp_migrate_cancel(Monitor *mon, const QDict *qdict) | |
895 | { | |
896 | qmp_migrate_cancel(NULL); | |
897 | } | |
4f0a993b LC |
898 | |
899 | void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict) | |
900 | { | |
901 | double value = qdict_get_double(qdict, "value"); | |
902 | qmp_migrate_set_downtime(value, NULL); | |
903 | } | |
3dc85383 | 904 | |
9e1ba4cc OW |
905 | void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict) |
906 | { | |
907 | int64_t value = qdict_get_int(qdict, "value"); | |
908 | Error *err = NULL; | |
909 | ||
910 | qmp_migrate_set_cache_size(value, &err); | |
911 | if (err) { | |
912 | monitor_printf(mon, "%s\n", error_get_pretty(err)); | |
913 | error_free(err); | |
914 | return; | |
915 | } | |
916 | } | |
917 | ||
3dc85383 LC |
918 | void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict) |
919 | { | |
920 | int64_t value = qdict_get_int(qdict, "value"); | |
921 | qmp_migrate_set_speed(value, NULL); | |
922 | } | |
fbf796fd | 923 | |
00458433 OW |
924 | void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict) |
925 | { | |
926 | const char *cap = qdict_get_str(qdict, "capability"); | |
927 | bool state = qdict_get_bool(qdict, "state"); | |
928 | Error *err = NULL; | |
929 | MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps)); | |
930 | int i; | |
931 | ||
932 | for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) { | |
933 | if (strcmp(cap, MigrationCapability_lookup[i]) == 0) { | |
934 | caps->value = g_malloc0(sizeof(*caps->value)); | |
935 | caps->value->capability = i; | |
936 | caps->value->state = state; | |
937 | caps->next = NULL; | |
938 | qmp_migrate_set_capabilities(caps, &err); | |
939 | break; | |
940 | } | |
941 | } | |
942 | ||
943 | if (i == MIGRATION_CAPABILITY_MAX) { | |
944 | error_set(&err, QERR_INVALID_PARAMETER, cap); | |
945 | } | |
946 | ||
947 | qapi_free_MigrationCapabilityStatusList(caps); | |
948 | ||
949 | if (err) { | |
a31ca017 | 950 | monitor_printf(mon, "migrate_set_capability: %s\n", |
00458433 OW |
951 | error_get_pretty(err)); |
952 | error_free(err); | |
953 | } | |
954 | } | |
955 | ||
fbf796fd LC |
956 | void hmp_set_password(Monitor *mon, const QDict *qdict) |
957 | { | |
958 | const char *protocol = qdict_get_str(qdict, "protocol"); | |
959 | const char *password = qdict_get_str(qdict, "password"); | |
960 | const char *connected = qdict_get_try_str(qdict, "connected"); | |
961 | Error *err = NULL; | |
962 | ||
963 | qmp_set_password(protocol, password, !!connected, connected, &err); | |
964 | hmp_handle_error(mon, &err); | |
965 | } | |
9ad5372d LC |
966 | |
967 | void hmp_expire_password(Monitor *mon, const QDict *qdict) | |
968 | { | |
969 | const char *protocol = qdict_get_str(qdict, "protocol"); | |
970 | const char *whenstr = qdict_get_str(qdict, "time"); | |
971 | Error *err = NULL; | |
972 | ||
973 | qmp_expire_password(protocol, whenstr, &err); | |
974 | hmp_handle_error(mon, &err); | |
975 | } | |
c245b6a3 LC |
976 | |
977 | void hmp_eject(Monitor *mon, const QDict *qdict) | |
978 | { | |
979 | int force = qdict_get_try_bool(qdict, "force", 0); | |
980 | const char *device = qdict_get_str(qdict, "device"); | |
981 | Error *err = NULL; | |
982 | ||
983 | qmp_eject(device, true, force, &err); | |
984 | hmp_handle_error(mon, &err); | |
985 | } | |
333a96ec LC |
986 | |
987 | static void hmp_change_read_arg(Monitor *mon, const char *password, | |
988 | void *opaque) | |
989 | { | |
990 | qmp_change_vnc_password(password, NULL); | |
991 | monitor_read_command(mon, 1); | |
992 | } | |
993 | ||
333a96ec LC |
994 | void hmp_change(Monitor *mon, const QDict *qdict) |
995 | { | |
996 | const char *device = qdict_get_str(qdict, "device"); | |
997 | const char *target = qdict_get_str(qdict, "target"); | |
998 | const char *arg = qdict_get_try_str(qdict, "arg"); | |
999 | Error *err = NULL; | |
1000 | ||
1001 | if (strcmp(device, "vnc") == 0 && | |
1002 | (strcmp(target, "passwd") == 0 || | |
1003 | strcmp(target, "password") == 0)) { | |
1004 | if (!arg) { | |
1005 | monitor_read_password(mon, hmp_change_read_arg, NULL); | |
1006 | return; | |
1007 | } | |
1008 | } | |
1009 | ||
1010 | qmp_change(device, target, !!arg, arg, &err); | |
ab878ddf LC |
1011 | if (error_is_set(&err) && |
1012 | error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) { | |
eef5ad10 LC |
1013 | error_free(err); |
1014 | monitor_read_block_device_key(mon, device, NULL, NULL); | |
333a96ec LC |
1015 | return; |
1016 | } | |
1017 | hmp_handle_error(mon, &err); | |
1018 | } | |
80047da5 LC |
1019 | |
1020 | void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) | |
1021 | { | |
1022 | Error *err = NULL; | |
1023 | ||
1024 | qmp_block_set_io_throttle(qdict_get_str(qdict, "device"), | |
1025 | qdict_get_int(qdict, "bps"), | |
1026 | qdict_get_int(qdict, "bps_rd"), | |
1027 | qdict_get_int(qdict, "bps_wr"), | |
1028 | qdict_get_int(qdict, "iops"), | |
1029 | qdict_get_int(qdict, "iops_rd"), | |
1030 | qdict_get_int(qdict, "iops_wr"), &err); | |
1031 | hmp_handle_error(mon, &err); | |
1032 | } | |
12bd451f SH |
1033 | |
1034 | void hmp_block_stream(Monitor *mon, const QDict *qdict) | |
1035 | { | |
1036 | Error *error = NULL; | |
1037 | const char *device = qdict_get_str(qdict, "device"); | |
1038 | const char *base = qdict_get_try_str(qdict, "base"); | |
c83c66c3 | 1039 | int64_t speed = qdict_get_try_int(qdict, "speed", 0); |
12bd451f | 1040 | |
c83c66c3 | 1041 | qmp_block_stream(device, base != NULL, base, |
1d809098 PB |
1042 | qdict_haskey(qdict, "speed"), speed, |
1043 | BLOCKDEV_ON_ERROR_REPORT, true, &error); | |
12bd451f SH |
1044 | |
1045 | hmp_handle_error(mon, &error); | |
1046 | } | |
2d47c6e9 SH |
1047 | |
1048 | void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict) | |
1049 | { | |
1050 | Error *error = NULL; | |
1051 | const char *device = qdict_get_str(qdict, "device"); | |
c6db2395 | 1052 | int64_t value = qdict_get_int(qdict, "speed"); |
2d47c6e9 SH |
1053 | |
1054 | qmp_block_job_set_speed(device, value, &error); | |
1055 | ||
1056 | hmp_handle_error(mon, &error); | |
1057 | } | |
370521a1 SH |
1058 | |
1059 | void hmp_block_job_cancel(Monitor *mon, const QDict *qdict) | |
1060 | { | |
1061 | Error *error = NULL; | |
1062 | const char *device = qdict_get_str(qdict, "device"); | |
6e37fb81 | 1063 | bool force = qdict_get_try_bool(qdict, "force", 0); |
370521a1 | 1064 | |
6e37fb81 PB |
1065 | qmp_block_job_cancel(device, true, force, &error); |
1066 | ||
1067 | hmp_handle_error(mon, &error); | |
1068 | } | |
1069 | ||
1070 | void hmp_block_job_pause(Monitor *mon, const QDict *qdict) | |
1071 | { | |
1072 | Error *error = NULL; | |
1073 | const char *device = qdict_get_str(qdict, "device"); | |
1074 | ||
1075 | qmp_block_job_pause(device, &error); | |
1076 | ||
1077 | hmp_handle_error(mon, &error); | |
1078 | } | |
1079 | ||
1080 | void hmp_block_job_resume(Monitor *mon, const QDict *qdict) | |
1081 | { | |
1082 | Error *error = NULL; | |
1083 | const char *device = qdict_get_str(qdict, "device"); | |
1084 | ||
1085 | qmp_block_job_resume(device, &error); | |
370521a1 SH |
1086 | |
1087 | hmp_handle_error(mon, &error); | |
1088 | } | |
e1c37d0e | 1089 | |
aeae883b PB |
1090 | void hmp_block_job_complete(Monitor *mon, const QDict *qdict) |
1091 | { | |
1092 | Error *error = NULL; | |
1093 | const char *device = qdict_get_str(qdict, "device"); | |
1094 | ||
1095 | qmp_block_job_complete(device, &error); | |
1096 | ||
1097 | hmp_handle_error(mon, &error); | |
1098 | } | |
1099 | ||
e1c37d0e LC |
1100 | typedef struct MigrationStatus |
1101 | { | |
1102 | QEMUTimer *timer; | |
1103 | Monitor *mon; | |
1104 | bool is_block_migration; | |
1105 | } MigrationStatus; | |
1106 | ||
1107 | static void hmp_migrate_status_cb(void *opaque) | |
1108 | { | |
1109 | MigrationStatus *status = opaque; | |
1110 | MigrationInfo *info; | |
1111 | ||
1112 | info = qmp_query_migrate(NULL); | |
1113 | if (!info->has_status || strcmp(info->status, "active") == 0) { | |
1114 | if (info->has_disk) { | |
1115 | int progress; | |
1116 | ||
1117 | if (info->disk->remaining) { | |
1118 | progress = info->disk->transferred * 100 / info->disk->total; | |
1119 | } else { | |
1120 | progress = 100; | |
1121 | } | |
1122 | ||
1123 | monitor_printf(status->mon, "Completed %d %%\r", progress); | |
1124 | monitor_flush(status->mon); | |
1125 | } | |
1126 | ||
1127 | qemu_mod_timer(status->timer, qemu_get_clock_ms(rt_clock) + 1000); | |
1128 | } else { | |
1129 | if (status->is_block_migration) { | |
1130 | monitor_printf(status->mon, "\n"); | |
1131 | } | |
1132 | monitor_resume(status->mon); | |
1133 | qemu_del_timer(status->timer); | |
1134 | g_free(status); | |
1135 | } | |
1136 | ||
1137 | qapi_free_MigrationInfo(info); | |
1138 | } | |
1139 | ||
1140 | void hmp_migrate(Monitor *mon, const QDict *qdict) | |
1141 | { | |
1142 | int detach = qdict_get_try_bool(qdict, "detach", 0); | |
1143 | int blk = qdict_get_try_bool(qdict, "blk", 0); | |
1144 | int inc = qdict_get_try_bool(qdict, "inc", 0); | |
1145 | const char *uri = qdict_get_str(qdict, "uri"); | |
1146 | Error *err = NULL; | |
1147 | ||
1148 | qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err); | |
1149 | if (err) { | |
1150 | monitor_printf(mon, "migrate: %s\n", error_get_pretty(err)); | |
1151 | error_free(err); | |
1152 | return; | |
1153 | } | |
1154 | ||
1155 | if (!detach) { | |
1156 | MigrationStatus *status; | |
1157 | ||
1158 | if (monitor_suspend(mon) < 0) { | |
1159 | monitor_printf(mon, "terminal does not allow synchronous " | |
1160 | "migration, continuing detached\n"); | |
1161 | return; | |
1162 | } | |
1163 | ||
1164 | status = g_malloc0(sizeof(*status)); | |
1165 | status->mon = mon; | |
1166 | status->is_block_migration = blk || inc; | |
1167 | status->timer = qemu_new_timer_ms(rt_clock, hmp_migrate_status_cb, | |
1168 | status); | |
1169 | qemu_mod_timer(status->timer, qemu_get_clock_ms(rt_clock)); | |
1170 | } | |
1171 | } | |
a15fef21 LC |
1172 | |
1173 | void hmp_device_del(Monitor *mon, const QDict *qdict) | |
1174 | { | |
1175 | const char *id = qdict_get_str(qdict, "id"); | |
1176 | Error *err = NULL; | |
1177 | ||
1178 | qmp_device_del(id, &err); | |
1179 | hmp_handle_error(mon, &err); | |
1180 | } | |
783e9b48 WC |
1181 | |
1182 | void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) | |
1183 | { | |
1184 | Error *errp = NULL; | |
1185 | int paging = qdict_get_try_bool(qdict, "paging", 0); | |
75363769 | 1186 | const char *file = qdict_get_str(qdict, "filename"); |
783e9b48 WC |
1187 | bool has_begin = qdict_haskey(qdict, "begin"); |
1188 | bool has_length = qdict_haskey(qdict, "length"); | |
1189 | int64_t begin = 0; | |
1190 | int64_t length = 0; | |
75363769 | 1191 | char *prot; |
783e9b48 WC |
1192 | |
1193 | if (has_begin) { | |
1194 | begin = qdict_get_int(qdict, "begin"); | |
1195 | } | |
1196 | if (has_length) { | |
1197 | length = qdict_get_int(qdict, "length"); | |
1198 | } | |
1199 | ||
75363769 LC |
1200 | prot = g_strconcat("file:", file, NULL); |
1201 | ||
1202 | qmp_dump_guest_memory(paging, prot, has_begin, begin, has_length, length, | |
783e9b48 WC |
1203 | &errp); |
1204 | hmp_handle_error(mon, &errp); | |
75363769 | 1205 | g_free(prot); |
783e9b48 | 1206 | } |
928059a3 LC |
1207 | |
1208 | void hmp_netdev_add(Monitor *mon, const QDict *qdict) | |
1209 | { | |
1210 | Error *err = NULL; | |
1211 | QemuOpts *opts; | |
1212 | ||
1213 | opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err); | |
1214 | if (error_is_set(&err)) { | |
1215 | goto out; | |
1216 | } | |
1217 | ||
1218 | netdev_add(opts, &err); | |
1219 | if (error_is_set(&err)) { | |
1220 | qemu_opts_del(opts); | |
1221 | } | |
1222 | ||
1223 | out: | |
1224 | hmp_handle_error(mon, &err); | |
1225 | } | |
5f964155 LC |
1226 | |
1227 | void hmp_netdev_del(Monitor *mon, const QDict *qdict) | |
1228 | { | |
1229 | const char *id = qdict_get_str(qdict, "id"); | |
1230 | Error *err = NULL; | |
1231 | ||
1232 | qmp_netdev_del(id, &err); | |
1233 | hmp_handle_error(mon, &err); | |
1234 | } | |
208c9d1b CB |
1235 | |
1236 | void hmp_getfd(Monitor *mon, const QDict *qdict) | |
1237 | { | |
1238 | const char *fdname = qdict_get_str(qdict, "fdname"); | |
1239 | Error *errp = NULL; | |
1240 | ||
1241 | qmp_getfd(fdname, &errp); | |
1242 | hmp_handle_error(mon, &errp); | |
1243 | } | |
1244 | ||
1245 | void hmp_closefd(Monitor *mon, const QDict *qdict) | |
1246 | { | |
1247 | const char *fdname = qdict_get_str(qdict, "fdname"); | |
1248 | Error *errp = NULL; | |
1249 | ||
1250 | qmp_closefd(fdname, &errp); | |
1251 | hmp_handle_error(mon, &errp); | |
1252 | } | |
e4c8f004 AK |
1253 | |
1254 | void hmp_send_key(Monitor *mon, const QDict *qdict) | |
1255 | { | |
1256 | const char *keys = qdict_get_str(qdict, "keys"); | |
9f328977 | 1257 | KeyValueList *keylist, *head = NULL, *tmp = NULL; |
e4c8f004 AK |
1258 | int has_hold_time = qdict_haskey(qdict, "hold-time"); |
1259 | int hold_time = qdict_get_try_int(qdict, "hold-time", -1); | |
1260 | Error *err = NULL; | |
1261 | char keyname_buf[16]; | |
1262 | char *separator; | |
9f328977 | 1263 | int keyname_len; |
e4c8f004 AK |
1264 | |
1265 | while (1) { | |
1266 | separator = strchr(keys, '-'); | |
1267 | keyname_len = separator ? separator - keys : strlen(keys); | |
1268 | pstrcpy(keyname_buf, sizeof(keyname_buf), keys); | |
1269 | ||
1270 | /* Be compatible with old interface, convert user inputted "<" */ | |
1271 | if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) { | |
1272 | pstrcpy(keyname_buf, sizeof(keyname_buf), "less"); | |
1273 | keyname_len = 4; | |
1274 | } | |
1275 | keyname_buf[keyname_len] = 0; | |
1276 | ||
e4c8f004 | 1277 | keylist = g_malloc0(sizeof(*keylist)); |
9f328977 | 1278 | keylist->value = g_malloc0(sizeof(*keylist->value)); |
e4c8f004 AK |
1279 | |
1280 | if (!head) { | |
1281 | head = keylist; | |
1282 | } | |
1283 | if (tmp) { | |
1284 | tmp->next = keylist; | |
1285 | } | |
1286 | tmp = keylist; | |
1287 | ||
9f328977 LC |
1288 | if (strstart(keyname_buf, "0x", NULL)) { |
1289 | char *endp; | |
1290 | int value = strtoul(keyname_buf, &endp, 0); | |
1291 | if (*endp != '\0') { | |
1292 | goto err_out; | |
1293 | } | |
1294 | keylist->value->kind = KEY_VALUE_KIND_NUMBER; | |
1295 | keylist->value->number = value; | |
1296 | } else { | |
1297 | int idx = index_from_key(keyname_buf); | |
1298 | if (idx == Q_KEY_CODE_MAX) { | |
1299 | goto err_out; | |
1300 | } | |
1301 | keylist->value->kind = KEY_VALUE_KIND_QCODE; | |
1302 | keylist->value->qcode = idx; | |
1303 | } | |
1304 | ||
e4c8f004 AK |
1305 | if (!separator) { |
1306 | break; | |
1307 | } | |
1308 | keys = separator + 1; | |
1309 | } | |
1310 | ||
9f328977 | 1311 | qmp_send_key(head, has_hold_time, hold_time, &err); |
e4c8f004 | 1312 | hmp_handle_error(mon, &err); |
9f328977 LC |
1313 | |
1314 | out: | |
1315 | qapi_free_KeyValueList(head); | |
1316 | return; | |
1317 | ||
1318 | err_out: | |
1319 | monitor_printf(mon, "invalid parameter: %s\n", keyname_buf); | |
1320 | goto out; | |
e4c8f004 | 1321 | } |
ad39cf6d LC |
1322 | |
1323 | void hmp_screen_dump(Monitor *mon, const QDict *qdict) | |
1324 | { | |
1325 | const char *filename = qdict_get_str(qdict, "filename"); | |
1326 | Error *err = NULL; | |
1327 | ||
1328 | qmp_screendump(filename, &err); | |
1329 | hmp_handle_error(mon, &err); | |
1330 | } | |
4057725f PB |
1331 | |
1332 | void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) | |
1333 | { | |
1334 | const char *uri = qdict_get_str(qdict, "uri"); | |
1335 | int writable = qdict_get_try_bool(qdict, "writable", 0); | |
1336 | int all = qdict_get_try_bool(qdict, "all", 0); | |
1337 | Error *local_err = NULL; | |
1338 | BlockInfoList *block_list, *info; | |
1339 | SocketAddress *addr; | |
1340 | ||
1341 | if (writable && !all) { | |
1342 | error_setg(&local_err, "-w only valid together with -a"); | |
1343 | goto exit; | |
1344 | } | |
1345 | ||
1346 | /* First check if the address is valid and start the server. */ | |
1347 | addr = socket_parse(uri, &local_err); | |
1348 | if (local_err != NULL) { | |
1349 | goto exit; | |
1350 | } | |
1351 | ||
1352 | qmp_nbd_server_start(addr, &local_err); | |
1353 | qapi_free_SocketAddress(addr); | |
1354 | if (local_err != NULL) { | |
1355 | goto exit; | |
1356 | } | |
1357 | ||
1358 | if (!all) { | |
1359 | return; | |
1360 | } | |
1361 | ||
1362 | /* Then try adding all block devices. If one fails, close all and | |
1363 | * exit. | |
1364 | */ | |
1365 | block_list = qmp_query_block(NULL); | |
1366 | ||
1367 | for (info = block_list; info; info = info->next) { | |
1368 | if (!info->value->has_inserted) { | |
1369 | continue; | |
1370 | } | |
1371 | ||
1372 | qmp_nbd_server_add(info->value->device, true, writable, &local_err); | |
1373 | ||
1374 | if (local_err != NULL) { | |
1375 | qmp_nbd_server_stop(NULL); | |
1376 | break; | |
1377 | } | |
1378 | } | |
1379 | ||
1380 | qapi_free_BlockInfoList(block_list); | |
1381 | ||
1382 | exit: | |
1383 | hmp_handle_error(mon, &local_err); | |
1384 | } | |
1385 | ||
1386 | void hmp_nbd_server_add(Monitor *mon, const QDict *qdict) | |
1387 | { | |
1388 | const char *device = qdict_get_str(qdict, "device"); | |
1389 | int writable = qdict_get_try_bool(qdict, "writable", 0); | |
1390 | Error *local_err = NULL; | |
1391 | ||
1392 | qmp_nbd_server_add(device, true, writable, &local_err); | |
1393 | ||
1394 | if (local_err != NULL) { | |
1395 | hmp_handle_error(mon, &local_err); | |
1396 | } | |
1397 | } | |
1398 | ||
1399 | void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict) | |
1400 | { | |
1401 | Error *errp = NULL; | |
1402 | ||
1403 | qmp_nbd_server_stop(&errp); | |
1404 | hmp_handle_error(mon, &errp); | |
1405 | } | |
f1088908 GH |
1406 | |
1407 | void hmp_chardev_add(Monitor *mon, const QDict *qdict) | |
1408 | { | |
1409 | const char *args = qdict_get_str(qdict, "args"); | |
1410 | Error *err = NULL; | |
1411 | QemuOpts *opts; | |
1412 | ||
1413 | opts = qemu_opts_parse(qemu_find_opts("chardev"), args, 1); | |
1414 | if (opts == NULL) { | |
312fd5f2 | 1415 | error_setg(&err, "Parsing chardev args failed"); |
f1088908 GH |
1416 | } else { |
1417 | qemu_chr_new_from_opts(opts, NULL, &err); | |
1418 | } | |
1419 | hmp_handle_error(mon, &err); | |
1420 | } | |
1421 | ||
1422 | void hmp_chardev_remove(Monitor *mon, const QDict *qdict) | |
1423 | { | |
1424 | Error *local_err = NULL; | |
1425 | ||
1426 | qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err); | |
1427 | hmp_handle_error(mon, &local_err); | |
1428 | } | |
587da2c3 KW |
1429 | |
1430 | void hmp_qemu_io(Monitor *mon, const QDict *qdict) | |
1431 | { | |
1432 | BlockDriverState *bs; | |
1433 | const char* device = qdict_get_str(qdict, "device"); | |
1434 | const char* command = qdict_get_str(qdict, "command"); | |
1435 | Error *err = NULL; | |
1436 | ||
1437 | bs = bdrv_find(device); | |
1438 | if (bs) { | |
1439 | qemuio_command(bs, command); | |
1440 | } else { | |
1441 | error_set(&err, QERR_DEVICE_NOT_FOUND, device); | |
1442 | } | |
1443 | ||
1444 | hmp_handle_error(mon, &err); | |
1445 | } |