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