]>
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 | ||
d38ea87a | 16 | #include "qemu/osdep.h" |
48a32bed | 17 | #include "hmp.h" |
1422e32d | 18 | #include "net/net.h" |
fafa4d50 | 19 | #include "net/eth.h" |
8228e353 | 20 | #include "chardev/char.h" |
4c7b7e9b | 21 | #include "sysemu/block-backend.h" |
52b26205 | 22 | #include "sysemu/sysemu.h" |
213dcb06 | 23 | #include "qemu/config-file.h" |
1de7afc9 PB |
24 | #include "qemu/option.h" |
25 | #include "qemu/timer.h" | |
48a32bed | 26 | #include "qmp-commands.h" |
1de7afc9 | 27 | #include "qemu/sockets.h" |
83c9089e | 28 | #include "monitor/monitor.h" |
318660f8 | 29 | #include "monitor/qdev.h" |
cff8b2c6 | 30 | #include "qapi/opts-visitor.h" |
cc7a8ea7 | 31 | #include "qapi/qmp/qerror.h" |
f4a06d13 | 32 | #include "qapi/string-input-visitor.h" |
eb1539b2 | 33 | #include "qapi/string-output-visitor.h" |
baead0ab | 34 | #include "qapi/util.h" |
eb1539b2 | 35 | #include "qapi-visit.h" |
90998d58 | 36 | #include "qom/object_interfaces.h" |
28ecbaee | 37 | #include "ui/console.h" |
bd269ebc | 38 | #include "block/nbd.h" |
bd093a36 | 39 | #include "block/qapi.h" |
587da2c3 | 40 | #include "qemu-io.h" |
f348b6d1 | 41 | #include "qemu/cutils.h" |
d59ce6f3 | 42 | #include "qemu/error-report.h" |
be9b23c4 | 43 | #include "exec/ramlist.h" |
61b97833 | 44 | #include "hw/intc/intc.h" |
5e22479a | 45 | #include "migration/snapshot.h" |
9d18af93 | 46 | #include "migration/misc.h" |
48a32bed | 47 | |
22fa7da0 CR |
48 | #ifdef CONFIG_SPICE |
49 | #include <spice/enums.h> | |
50 | #endif | |
51 | ||
0cfd6a9a LC |
52 | static void hmp_handle_error(Monitor *mon, Error **errp) |
53 | { | |
415168e0 MA |
54 | assert(errp); |
55 | if (*errp) { | |
193227f9 | 56 | error_report_err(*errp); |
0cfd6a9a LC |
57 | } |
58 | } | |
59 | ||
84f2d0ea | 60 | void hmp_info_name(Monitor *mon, const QDict *qdict) |
48a32bed AL |
61 | { |
62 | NameInfo *info; | |
63 | ||
64 | info = qmp_query_name(NULL); | |
65 | if (info->has_name) { | |
66 | monitor_printf(mon, "%s\n", info->name); | |
67 | } | |
68 | qapi_free_NameInfo(info); | |
69 | } | |
b9c15f16 | 70 | |
84f2d0ea | 71 | void hmp_info_version(Monitor *mon, const QDict *qdict) |
b9c15f16 LC |
72 | { |
73 | VersionInfo *info; | |
74 | ||
75 | info = qmp_query_version(NULL); | |
76 | ||
77 | monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n", | |
4752cdbb | 78 | info->qemu->major, info->qemu->minor, info->qemu->micro, |
b9c15f16 LC |
79 | info->package); |
80 | ||
81 | qapi_free_VersionInfo(info); | |
82 | } | |
292a2602 | 83 | |
84f2d0ea | 84 | void hmp_info_kvm(Monitor *mon, const QDict *qdict) |
292a2602 LC |
85 | { |
86 | KvmInfo *info; | |
87 | ||
88 | info = qmp_query_kvm(NULL); | |
89 | monitor_printf(mon, "kvm support: "); | |
90 | if (info->present) { | |
91 | monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled"); | |
92 | } else { | |
93 | monitor_printf(mon, "not compiled\n"); | |
94 | } | |
95 | ||
96 | qapi_free_KvmInfo(info); | |
97 | } | |
98 | ||
84f2d0ea | 99 | void hmp_info_status(Monitor *mon, const QDict *qdict) |
1fa9a5e4 LC |
100 | { |
101 | StatusInfo *info; | |
102 | ||
103 | info = qmp_query_status(NULL); | |
104 | ||
105 | monitor_printf(mon, "VM status: %s%s", | |
106 | info->running ? "running" : "paused", | |
107 | info->singlestep ? " (single step mode)" : ""); | |
108 | ||
109 | if (!info->running && info->status != RUN_STATE_PAUSED) { | |
110 | monitor_printf(mon, " (%s)", RunState_lookup[info->status]); | |
111 | } | |
112 | ||
113 | monitor_printf(mon, "\n"); | |
114 | ||
115 | qapi_free_StatusInfo(info); | |
116 | } | |
117 | ||
84f2d0ea | 118 | void hmp_info_uuid(Monitor *mon, const QDict *qdict) |
efab767e LC |
119 | { |
120 | UuidInfo *info; | |
121 | ||
122 | info = qmp_query_uuid(NULL); | |
123 | monitor_printf(mon, "%s\n", info->UUID); | |
124 | qapi_free_UuidInfo(info); | |
125 | } | |
c5a415a0 | 126 | |
84f2d0ea | 127 | void hmp_info_chardev(Monitor *mon, const QDict *qdict) |
c5a415a0 LC |
128 | { |
129 | ChardevInfoList *char_info, *info; | |
130 | ||
131 | char_info = qmp_query_chardev(NULL); | |
132 | for (info = char_info; info; info = info->next) { | |
133 | monitor_printf(mon, "%s: filename=%s\n", info->value->label, | |
134 | info->value->filename); | |
135 | } | |
136 | ||
137 | qapi_free_ChardevInfoList(char_info); | |
138 | } | |
7a7f325e | 139 | |
84f2d0ea | 140 | void hmp_info_mice(Monitor *mon, const QDict *qdict) |
e235cec3 LC |
141 | { |
142 | MouseInfoList *mice_list, *mouse; | |
143 | ||
144 | mice_list = qmp_query_mice(NULL); | |
145 | if (!mice_list) { | |
146 | monitor_printf(mon, "No mouse devices connected\n"); | |
147 | return; | |
148 | } | |
149 | ||
150 | for (mouse = mice_list; mouse; mouse = mouse->next) { | |
151 | monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n", | |
152 | mouse->value->current ? '*' : ' ', | |
153 | mouse->value->index, mouse->value->name, | |
154 | mouse->value->absolute ? " (absolute)" : ""); | |
155 | } | |
156 | ||
157 | qapi_free_MouseInfoList(mice_list); | |
158 | } | |
159 | ||
84f2d0ea | 160 | void hmp_info_migrate(Monitor *mon, const QDict *qdict) |
791e7c82 LC |
161 | { |
162 | MigrationInfo *info; | |
bbf6da32 | 163 | MigrationCapabilityStatusList *caps, *cap; |
791e7c82 LC |
164 | |
165 | info = qmp_query_migrate(NULL); | |
bbf6da32 OW |
166 | caps = qmp_query_migrate_capabilities(NULL); |
167 | ||
9d18af93 PX |
168 | migration_global_dump(mon); |
169 | ||
bbf6da32 OW |
170 | /* do not display parameters during setup */ |
171 | if (info->has_status && caps) { | |
172 | monitor_printf(mon, "capabilities: "); | |
173 | for (cap = caps; cap; cap = cap->next) { | |
174 | monitor_printf(mon, "%s: %s ", | |
175 | MigrationCapability_lookup[cap->value->capability], | |
176 | cap->value->state ? "on" : "off"); | |
177 | } | |
178 | monitor_printf(mon, "\n"); | |
179 | } | |
791e7c82 LC |
180 | |
181 | if (info->has_status) { | |
d59ce6f3 | 182 | monitor_printf(mon, "Migration status: %s", |
24b8c39b | 183 | MigrationStatus_lookup[info->status]); |
d59ce6f3 DB |
184 | if (info->status == MIGRATION_STATUS_FAILED && |
185 | info->has_error_desc) { | |
186 | monitor_printf(mon, " (%s)\n", info->error_desc); | |
187 | } else { | |
188 | monitor_printf(mon, "\n"); | |
189 | } | |
190 | ||
7aa939af JQ |
191 | monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n", |
192 | info->total_time); | |
2c52ddf1 JQ |
193 | if (info->has_expected_downtime) { |
194 | monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n", | |
195 | info->expected_downtime); | |
196 | } | |
9c5a9fcf JQ |
197 | if (info->has_downtime) { |
198 | monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n", | |
199 | info->downtime); | |
200 | } | |
ed4fbd10 MH |
201 | if (info->has_setup_time) { |
202 | monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n", | |
203 | info->setup_time); | |
204 | } | |
791e7c82 LC |
205 | } |
206 | ||
207 | if (info->has_ram) { | |
208 | monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n", | |
209 | info->ram->transferred >> 10); | |
7e114f8c MH |
210 | monitor_printf(mon, "throughput: %0.2f mbps\n", |
211 | info->ram->mbps); | |
791e7c82 LC |
212 | monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n", |
213 | info->ram->remaining >> 10); | |
214 | monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n", | |
215 | info->ram->total >> 10); | |
004d4c10 OW |
216 | monitor_printf(mon, "duplicate: %" PRIu64 " pages\n", |
217 | info->ram->duplicate); | |
f1c72795 PL |
218 | monitor_printf(mon, "skipped: %" PRIu64 " pages\n", |
219 | info->ram->skipped); | |
004d4c10 OW |
220 | monitor_printf(mon, "normal: %" PRIu64 " pages\n", |
221 | info->ram->normal); | |
222 | monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n", | |
223 | info->ram->normal_bytes >> 10); | |
58570ed8 C |
224 | monitor_printf(mon, "dirty sync count: %" PRIu64 "\n", |
225 | info->ram->dirty_sync_count); | |
030ce1f8 CF |
226 | monitor_printf(mon, "page size: %" PRIu64 " kbytes\n", |
227 | info->ram->page_size >> 10); | |
228 | ||
8d017193 JQ |
229 | if (info->ram->dirty_pages_rate) { |
230 | monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n", | |
231 | info->ram->dirty_pages_rate); | |
232 | } | |
d3bf5418 DDAG |
233 | if (info->ram->postcopy_requests) { |
234 | monitor_printf(mon, "postcopy request count: %" PRIu64 "\n", | |
235 | info->ram->postcopy_requests); | |
236 | } | |
791e7c82 LC |
237 | } |
238 | ||
239 | if (info->has_disk) { | |
240 | monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n", | |
241 | info->disk->transferred >> 10); | |
242 | monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n", | |
243 | info->disk->remaining >> 10); | |
244 | monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n", | |
245 | info->disk->total >> 10); | |
246 | } | |
247 | ||
f36d55af OW |
248 | if (info->has_xbzrle_cache) { |
249 | monitor_printf(mon, "cache size: %" PRIu64 " bytes\n", | |
250 | info->xbzrle_cache->cache_size); | |
251 | monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n", | |
252 | info->xbzrle_cache->bytes >> 10); | |
253 | monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n", | |
254 | info->xbzrle_cache->pages); | |
255 | monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n", | |
256 | info->xbzrle_cache->cache_miss); | |
8bc39233 C |
257 | monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n", |
258 | info->xbzrle_cache->cache_miss_rate); | |
f36d55af OW |
259 | monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n", |
260 | info->xbzrle_cache->overflow); | |
261 | } | |
262 | ||
d85a31d1 | 263 | if (info->has_cpu_throttle_percentage) { |
4782893e | 264 | monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n", |
d85a31d1 | 265 | info->cpu_throttle_percentage); |
4782893e JH |
266 | } |
267 | ||
791e7c82 | 268 | qapi_free_MigrationInfo(info); |
bbf6da32 OW |
269 | qapi_free_MigrationCapabilityStatusList(caps); |
270 | } | |
271 | ||
84f2d0ea | 272 | void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict) |
bbf6da32 OW |
273 | { |
274 | MigrationCapabilityStatusList *caps, *cap; | |
275 | ||
276 | caps = qmp_query_migrate_capabilities(NULL); | |
277 | ||
278 | if (caps) { | |
bbf6da32 | 279 | for (cap = caps; cap; cap = cap->next) { |
d80a0169 | 280 | monitor_printf(mon, "%s: %s\n", |
bbf6da32 OW |
281 | MigrationCapability_lookup[cap->value->capability], |
282 | cap->value->state ? "on" : "off"); | |
283 | } | |
bbf6da32 OW |
284 | } |
285 | ||
286 | qapi_free_MigrationCapabilityStatusList(caps); | |
791e7c82 LC |
287 | } |
288 | ||
50e9a629 LL |
289 | void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) |
290 | { | |
291 | MigrationParameters *params; | |
292 | ||
293 | params = qmp_query_migrate_parameters(NULL); | |
294 | ||
295 | if (params) { | |
de63ab61 | 296 | assert(params->has_compress_level); |
2c02468c | 297 | monitor_printf(mon, "%s: %" PRId64 "\n", |
50e9a629 LL |
298 | MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_LEVEL], |
299 | params->compress_level); | |
de63ab61 | 300 | assert(params->has_compress_threads); |
2c02468c | 301 | monitor_printf(mon, "%s: %" PRId64 "\n", |
50e9a629 LL |
302 | MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_THREADS], |
303 | params->compress_threads); | |
de63ab61 | 304 | assert(params->has_decompress_threads); |
2c02468c | 305 | monitor_printf(mon, "%s: %" PRId64 "\n", |
50e9a629 LL |
306 | MigrationParameter_lookup[MIGRATION_PARAMETER_DECOMPRESS_THREADS], |
307 | params->decompress_threads); | |
de63ab61 | 308 | assert(params->has_cpu_throttle_initial); |
2c02468c | 309 | monitor_printf(mon, "%s: %" PRId64 "\n", |
d85a31d1 JH |
310 | MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL], |
311 | params->cpu_throttle_initial); | |
de63ab61 | 312 | assert(params->has_cpu_throttle_increment); |
2c02468c | 313 | monitor_printf(mon, "%s: %" PRId64 "\n", |
d85a31d1 JH |
314 | MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT], |
315 | params->cpu_throttle_increment); | |
2c02468c | 316 | monitor_printf(mon, "%s: '%s'\n", |
69ef1f36 | 317 | MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_CREDS], |
de63ab61 | 318 | params->has_tls_creds ? params->tls_creds : ""); |
2c02468c | 319 | monitor_printf(mon, "%s: '%s'\n", |
69ef1f36 | 320 | MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_HOSTNAME], |
de63ab61 | 321 | params->has_tls_hostname ? params->tls_hostname : ""); |
2ff30257 | 322 | assert(params->has_max_bandwidth); |
2c02468c | 323 | monitor_printf(mon, "%s: %" PRId64 " bytes/second\n", |
2ff30257 AA |
324 | MigrationParameter_lookup[MIGRATION_PARAMETER_MAX_BANDWIDTH], |
325 | params->max_bandwidth); | |
326 | assert(params->has_downtime_limit); | |
2c02468c | 327 | monitor_printf(mon, "%s: %" PRId64 " milliseconds\n", |
2ff30257 AA |
328 | MigrationParameter_lookup[MIGRATION_PARAMETER_DOWNTIME_LIMIT], |
329 | params->downtime_limit); | |
fe39a4d4 | 330 | assert(params->has_x_checkpoint_delay); |
2c02468c | 331 | monitor_printf(mon, "%s: %" PRId64 "\n", |
68b53591 HZ |
332 | MigrationParameter_lookup[MIGRATION_PARAMETER_X_CHECKPOINT_DELAY], |
333 | params->x_checkpoint_delay); | |
2833c59b JQ |
334 | assert(params->has_block_incremental); |
335 | monitor_printf(mon, "%s: %s\n", | |
336 | MigrationParameter_lookup[MIGRATION_PARAMETER_BLOCK_INCREMENTAL], | |
337 | params->block_incremental ? "on" : "off"); | |
50e9a629 LL |
338 | } |
339 | ||
340 | qapi_free_MigrationParameters(params); | |
341 | } | |
342 | ||
84f2d0ea | 343 | void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict) |
9e1ba4cc OW |
344 | { |
345 | monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n", | |
346 | qmp_query_migrate_cache_size(NULL) >> 10); | |
347 | } | |
348 | ||
84f2d0ea | 349 | void hmp_info_cpus(Monitor *mon, const QDict *qdict) |
de0b36b6 LC |
350 | { |
351 | CpuInfoList *cpu_list, *cpu; | |
352 | ||
353 | cpu_list = qmp_query_cpus(NULL); | |
354 | ||
355 | for (cpu = cpu_list; cpu; cpu = cpu->next) { | |
356 | int active = ' '; | |
357 | ||
358 | if (cpu->value->CPU == monitor_get_cpu_index()) { | |
359 | active = '*'; | |
360 | } | |
361 | ||
852bef0e | 362 | monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU); |
de0b36b6 | 363 | |
86f4b687 EB |
364 | switch (cpu->value->arch) { |
365 | case CPU_INFO_ARCH_X86: | |
544a3731 | 366 | monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->u.x86.pc); |
86f4b687 EB |
367 | break; |
368 | case CPU_INFO_ARCH_PPC: | |
544a3731 | 369 | monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->u.ppc.nip); |
86f4b687 EB |
370 | break; |
371 | case CPU_INFO_ARCH_SPARC: | |
86ae1911 | 372 | monitor_printf(mon, " pc=0x%016" PRIx64, |
544a3731 | 373 | cpu->value->u.q_sparc.pc); |
86ae1911 | 374 | monitor_printf(mon, " npc=0x%016" PRIx64, |
544a3731 | 375 | cpu->value->u.q_sparc.npc); |
86f4b687 EB |
376 | break; |
377 | case CPU_INFO_ARCH_MIPS: | |
544a3731 | 378 | monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.q_mips.PC); |
86f4b687 EB |
379 | break; |
380 | case CPU_INFO_ARCH_TRICORE: | |
544a3731 | 381 | monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.tricore.PC); |
86f4b687 EB |
382 | break; |
383 | default: | |
384 | break; | |
de0b36b6 LC |
385 | } |
386 | ||
387 | if (cpu->value->halted) { | |
388 | monitor_printf(mon, " (halted)"); | |
389 | } | |
390 | ||
391 | monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id); | |
392 | } | |
393 | ||
394 | qapi_free_CpuInfoList(cpu_list); | |
395 | } | |
396 | ||
289b276c KW |
397 | static void print_block_info(Monitor *mon, BlockInfo *info, |
398 | BlockDeviceInfo *inserted, bool verbose) | |
b2023818 | 399 | { |
bd093a36 | 400 | ImageInfo *image_info; |
b2023818 | 401 | |
8d6adccd KW |
402 | assert(!info || !info->has_inserted || info->inserted == inserted); |
403 | ||
ec18b0a9 | 404 | if (info && *info->device) { |
8d6adccd KW |
405 | monitor_printf(mon, "%s", info->device); |
406 | if (inserted && inserted->has_node_name) { | |
407 | monitor_printf(mon, " (%s)", inserted->node_name); | |
408 | } | |
409 | } else { | |
ec18b0a9 | 410 | assert(info || inserted); |
8d6adccd | 411 | monitor_printf(mon, "%s", |
ec18b0a9 KW |
412 | inserted && inserted->has_node_name ? inserted->node_name |
413 | : info && info->has_qdev ? info->qdev | |
8d6adccd KW |
414 | : "<anonymous>"); |
415 | } | |
416 | ||
289b276c KW |
417 | if (inserted) { |
418 | monitor_printf(mon, ": %s (%s%s%s)\n", | |
419 | inserted->file, | |
420 | inserted->drv, | |
421 | inserted->ro ? ", read-only" : "", | |
422 | inserted->encrypted ? ", encrypted" : ""); | |
423 | } else { | |
424 | monitor_printf(mon, ": [not inserted]\n"); | |
425 | } | |
b2023818 | 426 | |
8d6adccd | 427 | if (info) { |
46eade7b KW |
428 | if (info->has_qdev) { |
429 | monitor_printf(mon, " Attached to: %s\n", info->qdev); | |
430 | } | |
8d6adccd KW |
431 | if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) { |
432 | monitor_printf(mon, " I/O status: %s\n", | |
433 | BlockDeviceIoStatus_lookup[info->io_status]); | |
434 | } | |
b2023818 | 435 | |
8d6adccd KW |
436 | if (info->removable) { |
437 | monitor_printf(mon, " Removable device: %slocked, tray %s\n", | |
438 | info->locked ? "" : "not ", | |
439 | info->tray_open ? "open" : "closed"); | |
440 | } | |
289b276c | 441 | } |
fbe2e26c | 442 | |
b2023818 | 443 | |
289b276c KW |
444 | if (!inserted) { |
445 | return; | |
446 | } | |
b2023818 | 447 | |
289b276c KW |
448 | monitor_printf(mon, " Cache mode: %s%s%s\n", |
449 | inserted->cache->writeback ? "writeback" : "writethrough", | |
450 | inserted->cache->direct ? ", direct" : "", | |
451 | inserted->cache->no_flush ? ", ignore flushes" : ""); | |
452 | ||
453 | if (inserted->has_backing_file) { | |
454 | monitor_printf(mon, | |
455 | " Backing file: %s " | |
456 | "(chain depth: %" PRId64 ")\n", | |
457 | inserted->backing_file, | |
458 | inserted->backing_file_depth); | |
459 | } | |
727f005e | 460 | |
289b276c KW |
461 | if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) { |
462 | monitor_printf(mon, " Detect zeroes: %s\n", | |
463 | BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]); | |
464 | } | |
fbe2e26c | 465 | |
289b276c KW |
466 | if (inserted->bps || inserted->bps_rd || inserted->bps_wr || |
467 | inserted->iops || inserted->iops_rd || inserted->iops_wr) | |
468 | { | |
469 | monitor_printf(mon, " I/O throttling: bps=%" PRId64 | |
470 | " bps_rd=%" PRId64 " bps_wr=%" PRId64 | |
471 | " bps_max=%" PRId64 | |
472 | " bps_rd_max=%" PRId64 | |
473 | " bps_wr_max=%" PRId64 | |
474 | " iops=%" PRId64 " iops_rd=%" PRId64 | |
475 | " iops_wr=%" PRId64 | |
476 | " iops_max=%" PRId64 | |
477 | " iops_rd_max=%" PRId64 | |
478 | " iops_wr_max=%" PRId64 | |
b8fe1694 AG |
479 | " iops_size=%" PRId64 |
480 | " group=%s\n", | |
289b276c KW |
481 | inserted->bps, |
482 | inserted->bps_rd, | |
483 | inserted->bps_wr, | |
484 | inserted->bps_max, | |
485 | inserted->bps_rd_max, | |
486 | inserted->bps_wr_max, | |
487 | inserted->iops, | |
488 | inserted->iops_rd, | |
489 | inserted->iops_wr, | |
490 | inserted->iops_max, | |
491 | inserted->iops_rd_max, | |
492 | inserted->iops_wr_max, | |
b8fe1694 AG |
493 | inserted->iops_size, |
494 | inserted->group); | |
289b276c | 495 | } |
fbe2e26c | 496 | |
9419874f | 497 | if (verbose) { |
289b276c KW |
498 | monitor_printf(mon, "\nImages:\n"); |
499 | image_info = inserted->image; | |
500 | while (1) { | |
501 | bdrv_image_info_dump((fprintf_function)monitor_printf, | |
502 | mon, image_info); | |
503 | if (image_info->has_backing_image) { | |
504 | image_info = image_info->backing_image; | |
505 | } else { | |
506 | break; | |
507 | } | |
508 | } | |
509 | } | |
510 | } | |
9e193c5a | 511 | |
289b276c KW |
512 | void hmp_info_block(Monitor *mon, const QDict *qdict) |
513 | { | |
514 | BlockInfoList *block_list, *info; | |
e6bb31ec | 515 | BlockDeviceInfoList *blockdev_list, *blockdev; |
289b276c | 516 | const char *device = qdict_get_try_str(qdict, "device"); |
34acbc95 EB |
517 | bool verbose = qdict_get_try_bool(qdict, "verbose", false); |
518 | bool nodes = qdict_get_try_bool(qdict, "nodes", false); | |
e6bb31ec | 519 | bool printed = false; |
9e193c5a | 520 | |
e6bb31ec KW |
521 | /* Print BlockBackend information */ |
522 | if (!nodes) { | |
f19e44bc | 523 | block_list = qmp_query_block(NULL); |
e6bb31ec KW |
524 | } else { |
525 | block_list = NULL; | |
526 | } | |
fbe2e26c | 527 | |
289b276c KW |
528 | for (info = block_list; info; info = info->next) { |
529 | if (device && strcmp(device, info->value->device)) { | |
530 | continue; | |
465bee1d PL |
531 | } |
532 | ||
289b276c KW |
533 | if (info != block_list) { |
534 | monitor_printf(mon, "\n"); | |
fbe2e26c | 535 | } |
bd093a36 | 536 | |
289b276c KW |
537 | print_block_info(mon, info->value, info->value->has_inserted |
538 | ? info->value->inserted : NULL, | |
539 | verbose); | |
e6bb31ec | 540 | printed = true; |
b2023818 LC |
541 | } |
542 | ||
543 | qapi_free_BlockInfoList(block_list); | |
e6bb31ec KW |
544 | |
545 | if ((!device && !nodes) || printed) { | |
546 | return; | |
547 | } | |
548 | ||
549 | /* Print node information */ | |
550 | blockdev_list = qmp_query_named_block_nodes(NULL); | |
551 | for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) { | |
552 | assert(blockdev->value->has_node_name); | |
553 | if (device && strcmp(device, blockdev->value->node_name)) { | |
554 | continue; | |
555 | } | |
556 | ||
557 | if (blockdev != blockdev_list) { | |
558 | monitor_printf(mon, "\n"); | |
559 | } | |
560 | ||
561 | print_block_info(mon, NULL, blockdev->value, verbose); | |
562 | } | |
563 | qapi_free_BlockDeviceInfoList(blockdev_list); | |
b2023818 LC |
564 | } |
565 | ||
84f2d0ea | 566 | void hmp_info_blockstats(Monitor *mon, const QDict *qdict) |
f11f57e4 LC |
567 | { |
568 | BlockStatsList *stats_list, *stats; | |
569 | ||
f71eaa74 | 570 | stats_list = qmp_query_blockstats(false, false, NULL); |
f11f57e4 LC |
571 | |
572 | for (stats = stats_list; stats; stats = stats->next) { | |
573 | if (!stats->value->has_device) { | |
574 | continue; | |
575 | } | |
576 | ||
577 | monitor_printf(mon, "%s:", stats->value->device); | |
578 | monitor_printf(mon, " rd_bytes=%" PRId64 | |
579 | " wr_bytes=%" PRId64 | |
580 | " rd_operations=%" PRId64 | |
581 | " wr_operations=%" PRId64 | |
582 | " flush_operations=%" PRId64 | |
583 | " wr_total_time_ns=%" PRId64 | |
584 | " rd_total_time_ns=%" PRId64 | |
585 | " flush_total_time_ns=%" PRId64 | |
f4564d53 PL |
586 | " rd_merged=%" PRId64 |
587 | " wr_merged=%" PRId64 | |
cb38fffb | 588 | " idle_time_ns=%" PRId64 |
f11f57e4 LC |
589 | "\n", |
590 | stats->value->stats->rd_bytes, | |
591 | stats->value->stats->wr_bytes, | |
592 | stats->value->stats->rd_operations, | |
593 | stats->value->stats->wr_operations, | |
594 | stats->value->stats->flush_operations, | |
595 | stats->value->stats->wr_total_time_ns, | |
596 | stats->value->stats->rd_total_time_ns, | |
f4564d53 PL |
597 | stats->value->stats->flush_total_time_ns, |
598 | stats->value->stats->rd_merged, | |
cb38fffb AG |
599 | stats->value->stats->wr_merged, |
600 | stats->value->stats->idle_time_ns); | |
f11f57e4 LC |
601 | } |
602 | ||
603 | qapi_free_BlockStatsList(stats_list); | |
604 | } | |
605 | ||
0a9667ec DDAG |
606 | /* Helper for hmp_info_vnc_clients, _servers */ |
607 | static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info, | |
608 | const char *name) | |
609 | { | |
610 | monitor_printf(mon, " %s: %s:%s (%s%s)\n", | |
611 | name, | |
612 | info->host, | |
613 | info->service, | |
614 | NetworkAddressFamily_lookup[info->family], | |
615 | info->websocket ? " (Websocket)" : ""); | |
616 | } | |
617 | ||
618 | /* Helper displaying and auth and crypt info */ | |
619 | static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent, | |
620 | VncPrimaryAuth auth, | |
621 | VncVencryptSubAuth *vencrypt) | |
622 | { | |
623 | monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent, | |
624 | VncPrimaryAuth_lookup[auth], | |
625 | vencrypt ? VncVencryptSubAuth_lookup[*vencrypt] : "none"); | |
626 | } | |
627 | ||
628 | static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client) | |
629 | { | |
630 | while (client) { | |
631 | VncClientInfo *cinfo = client->value; | |
632 | ||
633 | hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client"); | |
634 | monitor_printf(mon, " x509_dname: %s\n", | |
635 | cinfo->has_x509_dname ? | |
636 | cinfo->x509_dname : "none"); | |
637 | monitor_printf(mon, " sasl_username: %s\n", | |
638 | cinfo->has_sasl_username ? | |
639 | cinfo->sasl_username : "none"); | |
640 | ||
641 | client = client->next; | |
642 | } | |
643 | } | |
644 | ||
645 | static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server) | |
646 | { | |
647 | while (server) { | |
648 | VncServerInfo2 *sinfo = server->value; | |
649 | hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server"); | |
650 | hmp_info_vnc_authcrypt(mon, " ", sinfo->auth, | |
651 | sinfo->has_vencrypt ? &sinfo->vencrypt : NULL); | |
652 | server = server->next; | |
653 | } | |
654 | } | |
655 | ||
84f2d0ea | 656 | void hmp_info_vnc(Monitor *mon, const QDict *qdict) |
2b54aa87 | 657 | { |
0a9667ec | 658 | VncInfo2List *info2l; |
2b54aa87 | 659 | Error *err = NULL; |
2b54aa87 | 660 | |
0a9667ec | 661 | info2l = qmp_query_vnc_servers(&err); |
2b54aa87 | 662 | if (err) { |
193227f9 | 663 | error_report_err(err); |
2b54aa87 LC |
664 | return; |
665 | } | |
0a9667ec DDAG |
666 | if (!info2l) { |
667 | monitor_printf(mon, "None\n"); | |
668 | return; | |
2b54aa87 LC |
669 | } |
670 | ||
0a9667ec DDAG |
671 | while (info2l) { |
672 | VncInfo2 *info = info2l->value; | |
673 | monitor_printf(mon, "%s:\n", info->id); | |
674 | hmp_info_vnc_servers(mon, info->server); | |
675 | hmp_info_vnc_clients(mon, info->clients); | |
676 | if (!info->server) { | |
677 | /* The server entry displays its auth, we only | |
678 | * need to display in the case of 'reverse' connections | |
679 | * where there's no server. | |
680 | */ | |
681 | hmp_info_vnc_authcrypt(mon, " ", info->auth, | |
682 | info->has_vencrypt ? &info->vencrypt : NULL); | |
683 | } | |
684 | if (info->has_display) { | |
685 | monitor_printf(mon, " Display: %s\n", info->display); | |
2b54aa87 | 686 | } |
0a9667ec | 687 | info2l = info2l->next; |
2b54aa87 LC |
688 | } |
689 | ||
0a9667ec DDAG |
690 | qapi_free_VncInfo2List(info2l); |
691 | ||
2b54aa87 LC |
692 | } |
693 | ||
206addd5 | 694 | #ifdef CONFIG_SPICE |
84f2d0ea | 695 | void hmp_info_spice(Monitor *mon, const QDict *qdict) |
d1f29646 LC |
696 | { |
697 | SpiceChannelList *chan; | |
698 | SpiceInfo *info; | |
22fa7da0 CR |
699 | const char *channel_name; |
700 | const char * const channel_names[] = { | |
701 | [SPICE_CHANNEL_MAIN] = "main", | |
702 | [SPICE_CHANNEL_DISPLAY] = "display", | |
703 | [SPICE_CHANNEL_INPUTS] = "inputs", | |
704 | [SPICE_CHANNEL_CURSOR] = "cursor", | |
705 | [SPICE_CHANNEL_PLAYBACK] = "playback", | |
706 | [SPICE_CHANNEL_RECORD] = "record", | |
707 | [SPICE_CHANNEL_TUNNEL] = "tunnel", | |
708 | [SPICE_CHANNEL_SMARTCARD] = "smartcard", | |
709 | [SPICE_CHANNEL_USBREDIR] = "usbredir", | |
710 | [SPICE_CHANNEL_PORT] = "port", | |
7c6044a9 GH |
711 | #if 0 |
712 | /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7, | |
713 | * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable | |
714 | * as quick fix for build failures with older versions. */ | |
22fa7da0 | 715 | [SPICE_CHANNEL_WEBDAV] = "webdav", |
7c6044a9 | 716 | #endif |
22fa7da0 | 717 | }; |
d1f29646 LC |
718 | |
719 | info = qmp_query_spice(NULL); | |
720 | ||
721 | if (!info->enabled) { | |
722 | monitor_printf(mon, "Server: disabled\n"); | |
723 | goto out; | |
724 | } | |
725 | ||
726 | monitor_printf(mon, "Server:\n"); | |
727 | if (info->has_port) { | |
728 | monitor_printf(mon, " address: %s:%" PRId64 "\n", | |
729 | info->host, info->port); | |
730 | } | |
731 | if (info->has_tls_port) { | |
732 | monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n", | |
733 | info->host, info->tls_port); | |
734 | } | |
61c4efe2 YH |
735 | monitor_printf(mon, " migrated: %s\n", |
736 | info->migrated ? "true" : "false"); | |
d1f29646 LC |
737 | monitor_printf(mon, " auth: %s\n", info->auth); |
738 | monitor_printf(mon, " compiled: %s\n", info->compiled_version); | |
4efee029 AL |
739 | monitor_printf(mon, " mouse-mode: %s\n", |
740 | SpiceQueryMouseMode_lookup[info->mouse_mode]); | |
d1f29646 LC |
741 | |
742 | if (!info->has_channels || info->channels == NULL) { | |
743 | monitor_printf(mon, "Channels: none\n"); | |
744 | } else { | |
745 | for (chan = info->channels; chan; chan = chan->next) { | |
746 | monitor_printf(mon, "Channel:\n"); | |
747 | monitor_printf(mon, " address: %s:%s%s\n", | |
ddf21908 | 748 | chan->value->host, chan->value->port, |
d1f29646 LC |
749 | chan->value->tls ? " [tls]" : ""); |
750 | monitor_printf(mon, " session: %" PRId64 "\n", | |
751 | chan->value->connection_id); | |
752 | monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n", | |
753 | chan->value->channel_type, chan->value->channel_id); | |
22fa7da0 CR |
754 | |
755 | channel_name = "unknown"; | |
756 | if (chan->value->channel_type > 0 && | |
757 | chan->value->channel_type < ARRAY_SIZE(channel_names) && | |
758 | channel_names[chan->value->channel_type]) { | |
759 | channel_name = channel_names[chan->value->channel_type]; | |
760 | } | |
761 | ||
762 | monitor_printf(mon, " channel name: %s\n", channel_name); | |
d1f29646 LC |
763 | } |
764 | } | |
765 | ||
766 | out: | |
767 | qapi_free_SpiceInfo(info); | |
768 | } | |
206addd5 | 769 | #endif |
d1f29646 | 770 | |
84f2d0ea | 771 | void hmp_info_balloon(Monitor *mon, const QDict *qdict) |
96637bcd LC |
772 | { |
773 | BalloonInfo *info; | |
774 | Error *err = NULL; | |
775 | ||
776 | info = qmp_query_balloon(&err); | |
777 | if (err) { | |
193227f9 | 778 | error_report_err(err); |
96637bcd LC |
779 | return; |
780 | } | |
781 | ||
01ceb97e | 782 | monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20); |
96637bcd LC |
783 | |
784 | qapi_free_BalloonInfo(info); | |
785 | } | |
786 | ||
79627472 LC |
787 | static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) |
788 | { | |
789 | PciMemoryRegionList *region; | |
790 | ||
791 | monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus); | |
792 | monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n", | |
793 | dev->slot, dev->function); | |
794 | monitor_printf(mon, " "); | |
795 | ||
9fa02cd1 EB |
796 | if (dev->class_info->has_desc) { |
797 | monitor_printf(mon, "%s", dev->class_info->desc); | |
79627472 | 798 | } else { |
9fa02cd1 | 799 | monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class); |
79627472 LC |
800 | } |
801 | ||
802 | monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n", | |
9fa02cd1 | 803 | dev->id->vendor, dev->id->device); |
79627472 LC |
804 | |
805 | if (dev->has_irq) { | |
806 | monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq); | |
807 | } | |
808 | ||
809 | if (dev->has_pci_bridge) { | |
810 | monitor_printf(mon, " BUS %" PRId64 ".\n", | |
9fa02cd1 | 811 | dev->pci_bridge->bus->number); |
79627472 | 812 | monitor_printf(mon, " secondary bus %" PRId64 ".\n", |
9fa02cd1 | 813 | dev->pci_bridge->bus->secondary); |
79627472 | 814 | monitor_printf(mon, " subordinate bus %" PRId64 ".\n", |
9fa02cd1 | 815 | dev->pci_bridge->bus->subordinate); |
79627472 LC |
816 | |
817 | monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n", | |
9fa02cd1 EB |
818 | dev->pci_bridge->bus->io_range->base, |
819 | dev->pci_bridge->bus->io_range->limit); | |
79627472 LC |
820 | |
821 | monitor_printf(mon, | |
822 | " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n", | |
9fa02cd1 EB |
823 | dev->pci_bridge->bus->memory_range->base, |
824 | dev->pci_bridge->bus->memory_range->limit); | |
79627472 LC |
825 | |
826 | monitor_printf(mon, " prefetchable memory range " | |
827 | "[0x%08"PRIx64", 0x%08"PRIx64"]\n", | |
9fa02cd1 EB |
828 | dev->pci_bridge->bus->prefetchable_range->base, |
829 | dev->pci_bridge->bus->prefetchable_range->limit); | |
79627472 LC |
830 | } |
831 | ||
832 | for (region = dev->regions; region; region = region->next) { | |
833 | uint64_t addr, size; | |
834 | ||
835 | addr = region->value->address; | |
836 | size = region->value->size; | |
837 | ||
838 | monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar); | |
839 | ||
840 | if (!strcmp(region->value->type, "io")) { | |
841 | monitor_printf(mon, "I/O at 0x%04" PRIx64 | |
842 | " [0x%04" PRIx64 "].\n", | |
843 | addr, addr + size - 1); | |
844 | } else { | |
845 | monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64 | |
846 | " [0x%08" PRIx64 "].\n", | |
847 | region->value->mem_type_64 ? 64 : 32, | |
848 | region->value->prefetch ? " prefetchable" : "", | |
849 | addr, addr + size - 1); | |
850 | } | |
851 | } | |
852 | ||
853 | monitor_printf(mon, " id \"%s\"\n", dev->qdev_id); | |
854 | ||
855 | if (dev->has_pci_bridge) { | |
856 | if (dev->pci_bridge->has_devices) { | |
857 | PciDeviceInfoList *cdev; | |
858 | for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) { | |
859 | hmp_info_pci_device(mon, cdev->value); | |
860 | } | |
861 | } | |
862 | } | |
863 | } | |
864 | ||
61b97833 HP |
865 | static int hmp_info_irq_foreach(Object *obj, void *opaque) |
866 | { | |
867 | InterruptStatsProvider *intc; | |
868 | InterruptStatsProviderClass *k; | |
869 | Monitor *mon = opaque; | |
870 | ||
871 | if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) { | |
872 | intc = INTERRUPT_STATS_PROVIDER(obj); | |
873 | k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj); | |
874 | uint64_t *irq_counts; | |
875 | unsigned int nb_irqs, i; | |
876 | if (k->get_statistics && | |
877 | k->get_statistics(intc, &irq_counts, &nb_irqs)) { | |
878 | if (nb_irqs > 0) { | |
879 | monitor_printf(mon, "IRQ statistics for %s:\n", | |
880 | object_get_typename(obj)); | |
881 | for (i = 0; i < nb_irqs; i++) { | |
882 | if (irq_counts[i] > 0) { | |
883 | monitor_printf(mon, "%2d: %" PRId64 "\n", i, | |
884 | irq_counts[i]); | |
885 | } | |
886 | } | |
887 | } | |
888 | } else { | |
889 | monitor_printf(mon, "IRQ statistics not available for %s.\n", | |
890 | object_get_typename(obj)); | |
891 | } | |
892 | } | |
893 | ||
894 | return 0; | |
895 | } | |
896 | ||
897 | void hmp_info_irq(Monitor *mon, const QDict *qdict) | |
898 | { | |
899 | object_child_foreach_recursive(object_get_root(), | |
900 | hmp_info_irq_foreach, mon); | |
901 | } | |
902 | ||
903 | static int hmp_info_pic_foreach(Object *obj, void *opaque) | |
904 | { | |
905 | InterruptStatsProvider *intc; | |
906 | InterruptStatsProviderClass *k; | |
907 | Monitor *mon = opaque; | |
908 | ||
909 | if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) { | |
910 | intc = INTERRUPT_STATS_PROVIDER(obj); | |
911 | k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj); | |
912 | if (k->print_info) { | |
913 | k->print_info(intc, mon); | |
914 | } else { | |
915 | monitor_printf(mon, "Interrupt controller information not available for %s.\n", | |
916 | object_get_typename(obj)); | |
917 | } | |
918 | } | |
919 | ||
920 | return 0; | |
921 | } | |
922 | ||
923 | void hmp_info_pic(Monitor *mon, const QDict *qdict) | |
924 | { | |
925 | object_child_foreach_recursive(object_get_root(), | |
926 | hmp_info_pic_foreach, mon); | |
927 | } | |
928 | ||
84f2d0ea | 929 | void hmp_info_pci(Monitor *mon, const QDict *qdict) |
79627472 | 930 | { |
f46cee37 | 931 | PciInfoList *info_list, *info; |
79627472 LC |
932 | Error *err = NULL; |
933 | ||
f46cee37 | 934 | info_list = qmp_query_pci(&err); |
79627472 LC |
935 | if (err) { |
936 | monitor_printf(mon, "PCI devices not supported\n"); | |
937 | error_free(err); | |
938 | return; | |
939 | } | |
940 | ||
f46cee37 | 941 | for (info = info_list; info; info = info->next) { |
79627472 LC |
942 | PciDeviceInfoList *dev; |
943 | ||
944 | for (dev = info->value->devices; dev; dev = dev->next) { | |
945 | hmp_info_pci_device(mon, dev->value); | |
946 | } | |
947 | } | |
948 | ||
f46cee37 | 949 | qapi_free_PciInfoList(info_list); |
79627472 LC |
950 | } |
951 | ||
84f2d0ea | 952 | void hmp_info_block_jobs(Monitor *mon, const QDict *qdict) |
fb5458cd SH |
953 | { |
954 | BlockJobInfoList *list; | |
955 | Error *err = NULL; | |
956 | ||
957 | list = qmp_query_block_jobs(&err); | |
958 | assert(!err); | |
959 | ||
960 | if (!list) { | |
961 | monitor_printf(mon, "No active jobs\n"); | |
962 | return; | |
963 | } | |
964 | ||
965 | while (list) { | |
966 | if (strcmp(list->value->type, "stream") == 0) { | |
967 | monitor_printf(mon, "Streaming device %s: Completed %" PRId64 | |
968 | " of %" PRId64 " bytes, speed limit %" PRId64 | |
969 | " bytes/s\n", | |
970 | list->value->device, | |
971 | list->value->offset, | |
972 | list->value->len, | |
973 | list->value->speed); | |
974 | } else { | |
975 | monitor_printf(mon, "Type %s, device %s: Completed %" PRId64 | |
976 | " of %" PRId64 " bytes, speed limit %" PRId64 | |
977 | " bytes/s\n", | |
978 | list->value->type, | |
979 | list->value->device, | |
980 | list->value->offset, | |
981 | list->value->len, | |
982 | list->value->speed); | |
983 | } | |
984 | list = list->next; | |
985 | } | |
93bb1315 GA |
986 | |
987 | qapi_free_BlockJobInfoList(list); | |
fb5458cd SH |
988 | } |
989 | ||
d1a0cf73 SB |
990 | void hmp_info_tpm(Monitor *mon, const QDict *qdict) |
991 | { | |
992 | TPMInfoList *info_list, *info; | |
993 | Error *err = NULL; | |
994 | unsigned int c = 0; | |
995 | TPMPassthroughOptions *tpo; | |
996 | ||
997 | info_list = qmp_query_tpm(&err); | |
998 | if (err) { | |
999 | monitor_printf(mon, "TPM device not supported\n"); | |
1000 | error_free(err); | |
1001 | return; | |
1002 | } | |
1003 | ||
1004 | if (info_list) { | |
1005 | monitor_printf(mon, "TPM device:\n"); | |
1006 | } | |
1007 | ||
1008 | for (info = info_list; info; info = info->next) { | |
1009 | TPMInfo *ti = info->value; | |
1010 | monitor_printf(mon, " tpm%d: model=%s\n", | |
1011 | c, TpmModel_lookup[ti->model]); | |
1012 | ||
1013 | monitor_printf(mon, " \\ %s: type=%s", | |
ce21131a | 1014 | ti->id, TpmTypeOptionsKind_lookup[ti->options->type]); |
d1a0cf73 | 1015 | |
ce21131a | 1016 | switch (ti->options->type) { |
88ca7bcf | 1017 | case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH: |
32bafa8f | 1018 | tpo = ti->options->u.passthrough.data; |
d1a0cf73 SB |
1019 | monitor_printf(mon, "%s%s%s%s", |
1020 | tpo->has_path ? ",path=" : "", | |
1021 | tpo->has_path ? tpo->path : "", | |
1022 | tpo->has_cancel_path ? ",cancel-path=" : "", | |
1023 | tpo->has_cancel_path ? tpo->cancel_path : ""); | |
1024 | break; | |
7fb1cf16 | 1025 | case TPM_TYPE_OPTIONS_KIND__MAX: |
d1a0cf73 SB |
1026 | break; |
1027 | } | |
1028 | monitor_printf(mon, "\n"); | |
1029 | c++; | |
1030 | } | |
1031 | qapi_free_TPMInfoList(info_list); | |
1032 | } | |
1033 | ||
7a7f325e LC |
1034 | void hmp_quit(Monitor *mon, const QDict *qdict) |
1035 | { | |
1036 | monitor_suspend(mon); | |
1037 | qmp_quit(NULL); | |
1038 | } | |
5f158f21 LC |
1039 | |
1040 | void hmp_stop(Monitor *mon, const QDict *qdict) | |
1041 | { | |
1042 | qmp_stop(NULL); | |
1043 | } | |
38d22653 LC |
1044 | |
1045 | void hmp_system_reset(Monitor *mon, const QDict *qdict) | |
1046 | { | |
1047 | qmp_system_reset(NULL); | |
1048 | } | |
5bc465e4 LC |
1049 | |
1050 | void hmp_system_powerdown(Monitor *mon, const QDict *qdict) | |
1051 | { | |
1052 | qmp_system_powerdown(NULL); | |
1053 | } | |
755f1968 LC |
1054 | |
1055 | void hmp_cpu(Monitor *mon, const QDict *qdict) | |
1056 | { | |
1057 | int64_t cpu_index; | |
1058 | ||
1059 | /* XXX: drop the monitor_set_cpu() usage when all HMP commands that | |
1060 | use it are converted to the QAPI */ | |
1061 | cpu_index = qdict_get_int(qdict, "index"); | |
1062 | if (monitor_set_cpu(cpu_index) < 0) { | |
1063 | monitor_printf(mon, "invalid CPU index\n"); | |
1064 | } | |
1065 | } | |
0cfd6a9a LC |
1066 | |
1067 | void hmp_memsave(Monitor *mon, const QDict *qdict) | |
1068 | { | |
1069 | uint32_t size = qdict_get_int(qdict, "size"); | |
1070 | const char *filename = qdict_get_str(qdict, "filename"); | |
1071 | uint64_t addr = qdict_get_int(qdict, "val"); | |
e940f543 | 1072 | Error *err = NULL; |
854e67fe | 1073 | int cpu_index = monitor_get_cpu_index(); |
0cfd6a9a | 1074 | |
854e67fe TH |
1075 | if (cpu_index < 0) { |
1076 | monitor_printf(mon, "No CPU available\n"); | |
1077 | return; | |
1078 | } | |
1079 | ||
1080 | qmp_memsave(addr, size, filename, true, cpu_index, &err); | |
e940f543 | 1081 | hmp_handle_error(mon, &err); |
0cfd6a9a | 1082 | } |
6d3962bf LC |
1083 | |
1084 | void hmp_pmemsave(Monitor *mon, const QDict *qdict) | |
1085 | { | |
1086 | uint32_t size = qdict_get_int(qdict, "size"); | |
1087 | const char *filename = qdict_get_str(qdict, "filename"); | |
1088 | uint64_t addr = qdict_get_int(qdict, "val"); | |
e940f543 | 1089 | Error *err = NULL; |
6d3962bf | 1090 | |
e940f543 MA |
1091 | qmp_pmemsave(addr, size, filename, &err); |
1092 | hmp_handle_error(mon, &err); | |
1f590cf9 LL |
1093 | } |
1094 | ||
3949e594 | 1095 | void hmp_ringbuf_write(Monitor *mon, const QDict *qdict) |
1f590cf9 | 1096 | { |
1f590cf9 LL |
1097 | const char *chardev = qdict_get_str(qdict, "device"); |
1098 | const char *data = qdict_get_str(qdict, "data"); | |
e940f543 | 1099 | Error *err = NULL; |
1f590cf9 | 1100 | |
e940f543 | 1101 | qmp_ringbuf_write(chardev, data, false, 0, &err); |
1f590cf9 | 1102 | |
e940f543 | 1103 | hmp_handle_error(mon, &err); |
6d3962bf | 1104 | } |
e42e818b | 1105 | |
3949e594 | 1106 | void hmp_ringbuf_read(Monitor *mon, const QDict *qdict) |
49b6d722 LL |
1107 | { |
1108 | uint32_t size = qdict_get_int(qdict, "size"); | |
1109 | const char *chardev = qdict_get_str(qdict, "device"); | |
3ab651fc | 1110 | char *data; |
e940f543 | 1111 | Error *err = NULL; |
543f3412 | 1112 | int i; |
49b6d722 | 1113 | |
e940f543 MA |
1114 | data = qmp_ringbuf_read(chardev, size, false, 0, &err); |
1115 | if (err) { | |
193227f9 | 1116 | error_report_err(err); |
49b6d722 LL |
1117 | return; |
1118 | } | |
1119 | ||
543f3412 MA |
1120 | for (i = 0; data[i]; i++) { |
1121 | unsigned char ch = data[i]; | |
1122 | ||
1123 | if (ch == '\\') { | |
1124 | monitor_printf(mon, "\\\\"); | |
1125 | } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) { | |
1126 | monitor_printf(mon, "\\u%04X", ch); | |
1127 | } else { | |
1128 | monitor_printf(mon, "%c", ch); | |
1129 | } | |
1130 | ||
1131 | } | |
1132 | monitor_printf(mon, "\n"); | |
3ab651fc | 1133 | g_free(data); |
49b6d722 LL |
1134 | } |
1135 | ||
e42e818b LC |
1136 | void hmp_cont(Monitor *mon, const QDict *qdict) |
1137 | { | |
e940f543 | 1138 | Error *err = NULL; |
e42e818b | 1139 | |
e940f543 MA |
1140 | qmp_cont(&err); |
1141 | hmp_handle_error(mon, &err); | |
e42e818b | 1142 | } |
ab49ab5c | 1143 | |
9b9df25a GH |
1144 | void hmp_system_wakeup(Monitor *mon, const QDict *qdict) |
1145 | { | |
1146 | qmp_system_wakeup(NULL); | |
1147 | } | |
1148 | ||
3e5a50d6 | 1149 | void hmp_nmi(Monitor *mon, const QDict *qdict) |
ab49ab5c | 1150 | { |
e940f543 | 1151 | Error *err = NULL; |
ab49ab5c | 1152 | |
e940f543 MA |
1153 | qmp_inject_nmi(&err); |
1154 | hmp_handle_error(mon, &err); | |
ab49ab5c | 1155 | } |
4b37156c LC |
1156 | |
1157 | void hmp_set_link(Monitor *mon, const QDict *qdict) | |
1158 | { | |
1159 | const char *name = qdict_get_str(qdict, "name"); | |
34acbc95 | 1160 | bool up = qdict_get_bool(qdict, "up"); |
e940f543 | 1161 | Error *err = NULL; |
4b37156c | 1162 | |
e940f543 MA |
1163 | qmp_set_link(name, up, &err); |
1164 | hmp_handle_error(mon, &err); | |
4b37156c | 1165 | } |
a4dea8a9 LC |
1166 | |
1167 | void hmp_block_passwd(Monitor *mon, const QDict *qdict) | |
1168 | { | |
1169 | const char *device = qdict_get_str(qdict, "device"); | |
1170 | const char *password = qdict_get_str(qdict, "password"); | |
e940f543 | 1171 | Error *err = NULL; |
a4dea8a9 | 1172 | |
e940f543 MA |
1173 | qmp_block_passwd(true, device, false, NULL, password, &err); |
1174 | hmp_handle_error(mon, &err); | |
a4dea8a9 | 1175 | } |
d72f3264 LC |
1176 | |
1177 | void hmp_balloon(Monitor *mon, const QDict *qdict) | |
1178 | { | |
1179 | int64_t value = qdict_get_int(qdict, "value"); | |
e940f543 | 1180 | Error *err = NULL; |
d72f3264 | 1181 | |
e940f543 MA |
1182 | qmp_balloon(value, &err); |
1183 | if (err) { | |
193227f9 | 1184 | error_report_err(err); |
d72f3264 LC |
1185 | } |
1186 | } | |
5e7caacb LC |
1187 | |
1188 | void hmp_block_resize(Monitor *mon, const QDict *qdict) | |
1189 | { | |
1190 | const char *device = qdict_get_str(qdict, "device"); | |
1191 | int64_t size = qdict_get_int(qdict, "size"); | |
e940f543 | 1192 | Error *err = NULL; |
5e7caacb | 1193 | |
e940f543 MA |
1194 | qmp_block_resize(true, device, false, NULL, size, &err); |
1195 | hmp_handle_error(mon, &err); | |
5e7caacb | 1196 | } |
6106e249 | 1197 | |
d9b902db PB |
1198 | void hmp_drive_mirror(Monitor *mon, const QDict *qdict) |
1199 | { | |
d9b902db PB |
1200 | const char *filename = qdict_get_str(qdict, "target"); |
1201 | const char *format = qdict_get_try_str(qdict, "format"); | |
34acbc95 EB |
1202 | bool reuse = qdict_get_try_bool(qdict, "reuse", false); |
1203 | bool full = qdict_get_try_bool(qdict, "full", false); | |
e940f543 | 1204 | Error *err = NULL; |
faecd40a EB |
1205 | DriveMirror mirror = { |
1206 | .device = (char *)qdict_get_str(qdict, "device"), | |
1207 | .target = (char *)filename, | |
1208 | .has_format = !!format, | |
1209 | .format = (char *)format, | |
1210 | .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP, | |
1211 | .has_mode = true, | |
1212 | .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS, | |
1213 | .unmap = true, | |
1214 | }; | |
d9b902db PB |
1215 | |
1216 | if (!filename) { | |
c6bd8c70 | 1217 | error_setg(&err, QERR_MISSING_PARAMETER, "target"); |
e940f543 | 1218 | hmp_handle_error(mon, &err); |
d9b902db PB |
1219 | return; |
1220 | } | |
faecd40a | 1221 | qmp_drive_mirror(&mirror, &err); |
e940f543 | 1222 | hmp_handle_error(mon, &err); |
d9b902db PB |
1223 | } |
1224 | ||
de90930a SH |
1225 | void hmp_drive_backup(Monitor *mon, const QDict *qdict) |
1226 | { | |
1227 | const char *device = qdict_get_str(qdict, "device"); | |
1228 | const char *filename = qdict_get_str(qdict, "target"); | |
1229 | const char *format = qdict_get_try_str(qdict, "format"); | |
34acbc95 EB |
1230 | bool reuse = qdict_get_try_bool(qdict, "reuse", false); |
1231 | bool full = qdict_get_try_bool(qdict, "full", false); | |
13b9414b | 1232 | bool compress = qdict_get_try_bool(qdict, "compress", false); |
e940f543 | 1233 | Error *err = NULL; |
81206a89 PB |
1234 | DriveBackup backup = { |
1235 | .device = (char *)device, | |
1236 | .target = (char *)filename, | |
1237 | .has_format = !!format, | |
1238 | .format = (char *)format, | |
1239 | .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP, | |
1240 | .has_mode = true, | |
1241 | .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS, | |
13b9414b PB |
1242 | .has_compress = !!compress, |
1243 | .compress = compress, | |
81206a89 | 1244 | }; |
de90930a SH |
1245 | |
1246 | if (!filename) { | |
c6bd8c70 | 1247 | error_setg(&err, QERR_MISSING_PARAMETER, "target"); |
e940f543 | 1248 | hmp_handle_error(mon, &err); |
de90930a SH |
1249 | return; |
1250 | } | |
1251 | ||
81206a89 | 1252 | qmp_drive_backup(&backup, &err); |
e940f543 | 1253 | hmp_handle_error(mon, &err); |
de90930a SH |
1254 | } |
1255 | ||
6106e249 LC |
1256 | void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) |
1257 | { | |
1258 | const char *device = qdict_get_str(qdict, "device"); | |
1259 | const char *filename = qdict_get_try_str(qdict, "snapshot-file"); | |
1260 | const char *format = qdict_get_try_str(qdict, "format"); | |
34acbc95 | 1261 | bool reuse = qdict_get_try_bool(qdict, "reuse", false); |
6cc2a415 | 1262 | enum NewImageMode mode; |
e940f543 | 1263 | Error *err = NULL; |
6106e249 LC |
1264 | |
1265 | if (!filename) { | |
1266 | /* In the future, if 'snapshot-file' is not specified, the snapshot | |
1267 | will be taken internally. Today it's actually required. */ | |
c6bd8c70 | 1268 | error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file"); |
e940f543 | 1269 | hmp_handle_error(mon, &err); |
6106e249 LC |
1270 | return; |
1271 | } | |
1272 | ||
6cc2a415 | 1273 | mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS; |
0901f67e BC |
1274 | qmp_blockdev_snapshot_sync(true, device, false, NULL, |
1275 | filename, false, NULL, | |
1276 | !!format, format, | |
e940f543 MA |
1277 | true, mode, &err); |
1278 | hmp_handle_error(mon, &err); | |
6106e249 | 1279 | } |
6cdedb07 | 1280 | |
775ca88e WX |
1281 | void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict) |
1282 | { | |
1283 | const char *device = qdict_get_str(qdict, "device"); | |
1284 | const char *name = qdict_get_str(qdict, "name"); | |
e940f543 | 1285 | Error *err = NULL; |
775ca88e | 1286 | |
e940f543 MA |
1287 | qmp_blockdev_snapshot_internal_sync(device, name, &err); |
1288 | hmp_handle_error(mon, &err); | |
775ca88e WX |
1289 | } |
1290 | ||
7a4ed2ee WX |
1291 | void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict) |
1292 | { | |
1293 | const char *device = qdict_get_str(qdict, "device"); | |
1294 | const char *name = qdict_get_str(qdict, "name"); | |
1295 | const char *id = qdict_get_try_str(qdict, "id"); | |
e940f543 | 1296 | Error *err = NULL; |
7a4ed2ee WX |
1297 | |
1298 | qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id, | |
e940f543 MA |
1299 | true, name, &err); |
1300 | hmp_handle_error(mon, &err); | |
7a4ed2ee WX |
1301 | } |
1302 | ||
52b26205 JQ |
1303 | void hmp_loadvm(Monitor *mon, const QDict *qdict) |
1304 | { | |
1305 | int saved_vm_running = runstate_is_running(); | |
1306 | const char *name = qdict_get_str(qdict, "name"); | |
927d6638 | 1307 | Error *err = NULL; |
52b26205 JQ |
1308 | |
1309 | vm_stop(RUN_STATE_RESTORE_VM); | |
1310 | ||
5e22479a | 1311 | if (load_snapshot(name, &err) == 0 && saved_vm_running) { |
52b26205 JQ |
1312 | vm_start(); |
1313 | } | |
927d6638 | 1314 | hmp_handle_error(mon, &err); |
52b26205 JQ |
1315 | } |
1316 | ||
d9c7d137 JQ |
1317 | void hmp_savevm(Monitor *mon, const QDict *qdict) |
1318 | { | |
927d6638 JQ |
1319 | Error *err = NULL; |
1320 | ||
5e22479a | 1321 | save_snapshot(qdict_get_try_str(qdict, "name"), &err); |
927d6638 | 1322 | hmp_handle_error(mon, &err); |
d9c7d137 JQ |
1323 | } |
1324 | ||
d905bb7b JQ |
1325 | void hmp_delvm(Monitor *mon, const QDict *qdict) |
1326 | { | |
1327 | BlockDriverState *bs; | |
1328 | Error *err; | |
1329 | const char *name = qdict_get_str(qdict, "name"); | |
1330 | ||
1331 | if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) { | |
1332 | error_reportf_err(err, | |
1333 | "Error while deleting snapshot on device '%s': ", | |
1334 | bdrv_get_device_name(bs)); | |
1335 | } | |
1336 | } | |
1337 | ||
66830618 JQ |
1338 | void hmp_info_snapshots(Monitor *mon, const QDict *qdict) |
1339 | { | |
1340 | BlockDriverState *bs, *bs1; | |
1341 | BdrvNextIterator it1; | |
1342 | QEMUSnapshotInfo *sn_tab, *sn; | |
1343 | bool no_snapshot = true; | |
1344 | int nb_sns, i; | |
1345 | int total; | |
1346 | int *global_snapshots; | |
1347 | AioContext *aio_context; | |
1348 | ||
1349 | typedef struct SnapshotEntry { | |
1350 | QEMUSnapshotInfo sn; | |
1351 | QTAILQ_ENTRY(SnapshotEntry) next; | |
1352 | } SnapshotEntry; | |
1353 | ||
1354 | typedef struct ImageEntry { | |
1355 | const char *imagename; | |
1356 | QTAILQ_ENTRY(ImageEntry) next; | |
1357 | QTAILQ_HEAD(, SnapshotEntry) snapshots; | |
1358 | } ImageEntry; | |
1359 | ||
1360 | QTAILQ_HEAD(, ImageEntry) image_list = | |
1361 | QTAILQ_HEAD_INITIALIZER(image_list); | |
1362 | ||
1363 | ImageEntry *image_entry, *next_ie; | |
1364 | SnapshotEntry *snapshot_entry; | |
1365 | ||
1366 | bs = bdrv_all_find_vmstate_bs(); | |
1367 | if (!bs) { | |
1368 | monitor_printf(mon, "No available block device supports snapshots\n"); | |
1369 | return; | |
1370 | } | |
1371 | aio_context = bdrv_get_aio_context(bs); | |
1372 | ||
1373 | aio_context_acquire(aio_context); | |
1374 | nb_sns = bdrv_snapshot_list(bs, &sn_tab); | |
1375 | aio_context_release(aio_context); | |
1376 | ||
1377 | if (nb_sns < 0) { | |
1378 | monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns); | |
1379 | return; | |
1380 | } | |
1381 | ||
1382 | for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) { | |
1383 | int bs1_nb_sns = 0; | |
1384 | ImageEntry *ie; | |
1385 | SnapshotEntry *se; | |
1386 | AioContext *ctx = bdrv_get_aio_context(bs1); | |
1387 | ||
1388 | aio_context_acquire(ctx); | |
1389 | if (bdrv_can_snapshot(bs1)) { | |
1390 | sn = NULL; | |
1391 | bs1_nb_sns = bdrv_snapshot_list(bs1, &sn); | |
1392 | if (bs1_nb_sns > 0) { | |
1393 | no_snapshot = false; | |
1394 | ie = g_new0(ImageEntry, 1); | |
1395 | ie->imagename = bdrv_get_device_name(bs1); | |
1396 | QTAILQ_INIT(&ie->snapshots); | |
1397 | QTAILQ_INSERT_TAIL(&image_list, ie, next); | |
1398 | for (i = 0; i < bs1_nb_sns; i++) { | |
1399 | se = g_new0(SnapshotEntry, 1); | |
1400 | se->sn = sn[i]; | |
1401 | QTAILQ_INSERT_TAIL(&ie->snapshots, se, next); | |
1402 | } | |
1403 | } | |
1404 | g_free(sn); | |
1405 | } | |
1406 | aio_context_release(ctx); | |
1407 | } | |
1408 | ||
1409 | if (no_snapshot) { | |
1410 | monitor_printf(mon, "There is no snapshot available.\n"); | |
1411 | return; | |
1412 | } | |
1413 | ||
1414 | global_snapshots = g_new0(int, nb_sns); | |
1415 | total = 0; | |
1416 | for (i = 0; i < nb_sns; i++) { | |
1417 | SnapshotEntry *next_sn; | |
1418 | if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) { | |
1419 | global_snapshots[total] = i; | |
1420 | total++; | |
1421 | QTAILQ_FOREACH(image_entry, &image_list, next) { | |
1422 | QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, | |
1423 | next, next_sn) { | |
1424 | if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) { | |
1425 | QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry, | |
1426 | next); | |
1427 | g_free(snapshot_entry); | |
1428 | } | |
1429 | } | |
1430 | } | |
1431 | } | |
1432 | } | |
1433 | ||
1434 | monitor_printf(mon, "List of snapshots present on all disks:\n"); | |
1435 | ||
1436 | if (total > 0) { | |
1437 | bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL); | |
1438 | monitor_printf(mon, "\n"); | |
1439 | for (i = 0; i < total; i++) { | |
1440 | sn = &sn_tab[global_snapshots[i]]; | |
1441 | /* The ID is not guaranteed to be the same on all images, so | |
1442 | * overwrite it. | |
1443 | */ | |
1444 | pstrcpy(sn->id_str, sizeof(sn->id_str), "--"); | |
1445 | bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, sn); | |
1446 | monitor_printf(mon, "\n"); | |
1447 | } | |
1448 | } else { | |
1449 | monitor_printf(mon, "None\n"); | |
1450 | } | |
1451 | ||
1452 | QTAILQ_FOREACH(image_entry, &image_list, next) { | |
1453 | if (QTAILQ_EMPTY(&image_entry->snapshots)) { | |
1454 | continue; | |
1455 | } | |
1456 | monitor_printf(mon, | |
1457 | "\nList of partial (non-loadable) snapshots on '%s':\n", | |
1458 | image_entry->imagename); | |
1459 | bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL); | |
1460 | monitor_printf(mon, "\n"); | |
1461 | QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) { | |
1462 | bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, | |
1463 | &snapshot_entry->sn); | |
1464 | monitor_printf(mon, "\n"); | |
1465 | } | |
1466 | } | |
1467 | ||
1468 | QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) { | |
1469 | SnapshotEntry *next_sn; | |
1470 | QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next, | |
1471 | next_sn) { | |
1472 | g_free(snapshot_entry); | |
1473 | } | |
1474 | g_free(image_entry); | |
1475 | } | |
1476 | g_free(sn_tab); | |
1477 | g_free(global_snapshots); | |
1478 | ||
1479 | } | |
1480 | ||
6cdedb07 LC |
1481 | void hmp_migrate_cancel(Monitor *mon, const QDict *qdict) |
1482 | { | |
1483 | qmp_migrate_cancel(NULL); | |
1484 | } | |
4f0a993b | 1485 | |
bf1ae1f4 DDAG |
1486 | void hmp_migrate_incoming(Monitor *mon, const QDict *qdict) |
1487 | { | |
1488 | Error *err = NULL; | |
1489 | const char *uri = qdict_get_str(qdict, "uri"); | |
1490 | ||
1491 | qmp_migrate_incoming(uri, &err); | |
1492 | ||
1fa57f55 | 1493 | hmp_handle_error(mon, &err); |
bf1ae1f4 DDAG |
1494 | } |
1495 | ||
2ff30257 | 1496 | /* Kept for backwards compatibility */ |
4f0a993b LC |
1497 | void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict) |
1498 | { | |
1499 | double value = qdict_get_double(qdict, "value"); | |
1500 | qmp_migrate_set_downtime(value, NULL); | |
1501 | } | |
3dc85383 | 1502 | |
9e1ba4cc OW |
1503 | void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict) |
1504 | { | |
1505 | int64_t value = qdict_get_int(qdict, "value"); | |
1506 | Error *err = NULL; | |
1507 | ||
1508 | qmp_migrate_set_cache_size(value, &err); | |
1509 | if (err) { | |
193227f9 | 1510 | error_report_err(err); |
9e1ba4cc OW |
1511 | return; |
1512 | } | |
1513 | } | |
1514 | ||
2ff30257 | 1515 | /* Kept for backwards compatibility */ |
3dc85383 LC |
1516 | void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict) |
1517 | { | |
1518 | int64_t value = qdict_get_int(qdict, "value"); | |
1519 | qmp_migrate_set_speed(value, NULL); | |
1520 | } | |
fbf796fd | 1521 | |
00458433 OW |
1522 | void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict) |
1523 | { | |
1524 | const char *cap = qdict_get_str(qdict, "capability"); | |
1525 | bool state = qdict_get_bool(qdict, "state"); | |
1526 | Error *err = NULL; | |
1527 | MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps)); | |
1528 | int i; | |
1529 | ||
7fb1cf16 | 1530 | for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) { |
00458433 OW |
1531 | if (strcmp(cap, MigrationCapability_lookup[i]) == 0) { |
1532 | caps->value = g_malloc0(sizeof(*caps->value)); | |
1533 | caps->value->capability = i; | |
1534 | caps->value->state = state; | |
1535 | caps->next = NULL; | |
1536 | qmp_migrate_set_capabilities(caps, &err); | |
1537 | break; | |
1538 | } | |
1539 | } | |
1540 | ||
7fb1cf16 | 1541 | if (i == MIGRATION_CAPABILITY__MAX) { |
c6bd8c70 | 1542 | error_setg(&err, QERR_INVALID_PARAMETER, cap); |
00458433 OW |
1543 | } |
1544 | ||
1545 | qapi_free_MigrationCapabilityStatusList(caps); | |
1546 | ||
1547 | if (err) { | |
193227f9 | 1548 | error_report_err(err); |
00458433 OW |
1549 | } |
1550 | } | |
1551 | ||
50e9a629 LL |
1552 | void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) |
1553 | { | |
1554 | const char *param = qdict_get_str(qdict, "parameter"); | |
69ef1f36 | 1555 | const char *valuestr = qdict_get_str(qdict, "value"); |
f4a06d13 | 1556 | Visitor *v = string_input_visitor_new(valuestr); |
f46bfdbf | 1557 | uint64_t valuebw = 0; |
f4a06d13 | 1558 | int64_t valueint = 0; |
2833c59b | 1559 | bool valuebool = false; |
50e9a629 | 1560 | Error *err = NULL; |
69ef1f36 | 1561 | bool use_int_value = false; |
f17fd4fd | 1562 | int i, ret; |
50e9a629 | 1563 | |
7fb1cf16 | 1564 | for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) { |
50e9a629 | 1565 | if (strcmp(param, MigrationParameter_lookup[i]) == 0) { |
7f375e04 | 1566 | MigrationParameters p = { 0 }; |
50e9a629 LL |
1567 | switch (i) { |
1568 | case MIGRATION_PARAMETER_COMPRESS_LEVEL: | |
7f375e04 | 1569 | p.has_compress_level = true; |
69ef1f36 | 1570 | use_int_value = true; |
50e9a629 LL |
1571 | break; |
1572 | case MIGRATION_PARAMETER_COMPRESS_THREADS: | |
7f375e04 | 1573 | p.has_compress_threads = true; |
69ef1f36 | 1574 | use_int_value = true; |
50e9a629 LL |
1575 | break; |
1576 | case MIGRATION_PARAMETER_DECOMPRESS_THREADS: | |
7f375e04 | 1577 | p.has_decompress_threads = true; |
69ef1f36 | 1578 | use_int_value = true; |
50e9a629 | 1579 | break; |
d85a31d1 | 1580 | case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL: |
7f375e04 | 1581 | p.has_cpu_throttle_initial = true; |
69ef1f36 | 1582 | use_int_value = true; |
1626fee3 | 1583 | break; |
d85a31d1 | 1584 | case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT: |
7f375e04 | 1585 | p.has_cpu_throttle_increment = true; |
bb2b777c | 1586 | use_int_value = true; |
1626fee3 | 1587 | break; |
69ef1f36 | 1588 | case MIGRATION_PARAMETER_TLS_CREDS: |
7f375e04 EB |
1589 | p.has_tls_creds = true; |
1590 | p.tls_creds = (char *) valuestr; | |
69ef1f36 DB |
1591 | break; |
1592 | case MIGRATION_PARAMETER_TLS_HOSTNAME: | |
7f375e04 EB |
1593 | p.has_tls_hostname = true; |
1594 | p.tls_hostname = (char *) valuestr; | |
69ef1f36 | 1595 | break; |
2ff30257 AA |
1596 | case MIGRATION_PARAMETER_MAX_BANDWIDTH: |
1597 | p.has_max_bandwidth = true; | |
f17fd4fd | 1598 | ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw); |
f46bfdbf MA |
1599 | if (ret < 0 || valuebw > INT64_MAX |
1600 | || (size_t)valuebw != valuebw) { | |
2ff30257 AA |
1601 | error_setg(&err, "Invalid size %s", valuestr); |
1602 | goto cleanup; | |
1603 | } | |
1604 | p.max_bandwidth = valuebw; | |
1605 | break; | |
1606 | case MIGRATION_PARAMETER_DOWNTIME_LIMIT: | |
1607 | p.has_downtime_limit = true; | |
1608 | use_int_value = true; | |
1609 | break; | |
68b53591 HZ |
1610 | case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY: |
1611 | p.has_x_checkpoint_delay = true; | |
1612 | use_int_value = true; | |
1613 | break; | |
2833c59b JQ |
1614 | case MIGRATION_PARAMETER_BLOCK_INCREMENTAL: |
1615 | p.has_block_incremental = true; | |
1616 | visit_type_bool(v, param, &valuebool, &err); | |
1617 | if (err) { | |
1618 | goto cleanup; | |
1619 | } | |
1620 | p.block_incremental = valuebool; | |
1621 | break; | |
50e9a629 | 1622 | } |
69ef1f36 DB |
1623 | |
1624 | if (use_int_value) { | |
f4a06d13 JQ |
1625 | visit_type_int(v, param, &valueint, &err); |
1626 | if (err) { | |
69ef1f36 DB |
1627 | goto cleanup; |
1628 | } | |
7f375e04 EB |
1629 | /* Set all integers; only one has_FOO will be set, and |
1630 | * the code ignores the remaining values */ | |
1631 | p.compress_level = valueint; | |
1632 | p.compress_threads = valueint; | |
1633 | p.decompress_threads = valueint; | |
1634 | p.cpu_throttle_initial = valueint; | |
1635 | p.cpu_throttle_increment = valueint; | |
2ff30257 | 1636 | p.downtime_limit = valueint; |
68b53591 | 1637 | p.x_checkpoint_delay = valueint; |
69ef1f36 DB |
1638 | } |
1639 | ||
7f375e04 | 1640 | qmp_migrate_set_parameters(&p, &err); |
50e9a629 LL |
1641 | break; |
1642 | } | |
1643 | } | |
1644 | ||
7fb1cf16 | 1645 | if (i == MIGRATION_PARAMETER__MAX) { |
c6bd8c70 | 1646 | error_setg(&err, QERR_INVALID_PARAMETER, param); |
50e9a629 LL |
1647 | } |
1648 | ||
69ef1f36 | 1649 | cleanup: |
f4a06d13 | 1650 | visit_free(v); |
50e9a629 | 1651 | if (err) { |
193227f9 | 1652 | error_report_err(err); |
50e9a629 LL |
1653 | } |
1654 | } | |
1655 | ||
b8a185bc MA |
1656 | void hmp_client_migrate_info(Monitor *mon, const QDict *qdict) |
1657 | { | |
1658 | Error *err = NULL; | |
1659 | const char *protocol = qdict_get_str(qdict, "protocol"); | |
1660 | const char *hostname = qdict_get_str(qdict, "hostname"); | |
1661 | bool has_port = qdict_haskey(qdict, "port"); | |
1662 | int port = qdict_get_try_int(qdict, "port", -1); | |
1663 | bool has_tls_port = qdict_haskey(qdict, "tls-port"); | |
1664 | int tls_port = qdict_get_try_int(qdict, "tls-port", -1); | |
1665 | const char *cert_subject = qdict_get_try_str(qdict, "cert-subject"); | |
1666 | ||
1667 | qmp_client_migrate_info(protocol, hostname, | |
1668 | has_port, port, has_tls_port, tls_port, | |
1669 | !!cert_subject, cert_subject, &err); | |
1670 | hmp_handle_error(mon, &err); | |
1671 | } | |
1672 | ||
4886a1bc DDAG |
1673 | void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict) |
1674 | { | |
1675 | Error *err = NULL; | |
1676 | qmp_migrate_start_postcopy(&err); | |
1677 | hmp_handle_error(mon, &err); | |
1678 | } | |
1679 | ||
d89e666e HZ |
1680 | void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict) |
1681 | { | |
1682 | Error *err = NULL; | |
1683 | ||
1684 | qmp_x_colo_lost_heartbeat(&err); | |
1685 | hmp_handle_error(mon, &err); | |
1686 | } | |
1687 | ||
fbf796fd LC |
1688 | void hmp_set_password(Monitor *mon, const QDict *qdict) |
1689 | { | |
1690 | const char *protocol = qdict_get_str(qdict, "protocol"); | |
1691 | const char *password = qdict_get_str(qdict, "password"); | |
1692 | const char *connected = qdict_get_try_str(qdict, "connected"); | |
1693 | Error *err = NULL; | |
1694 | ||
1695 | qmp_set_password(protocol, password, !!connected, connected, &err); | |
1696 | hmp_handle_error(mon, &err); | |
1697 | } | |
9ad5372d LC |
1698 | |
1699 | void hmp_expire_password(Monitor *mon, const QDict *qdict) | |
1700 | { | |
1701 | const char *protocol = qdict_get_str(qdict, "protocol"); | |
1702 | const char *whenstr = qdict_get_str(qdict, "time"); | |
1703 | Error *err = NULL; | |
1704 | ||
1705 | qmp_expire_password(protocol, whenstr, &err); | |
1706 | hmp_handle_error(mon, &err); | |
1707 | } | |
c245b6a3 LC |
1708 | |
1709 | void hmp_eject(Monitor *mon, const QDict *qdict) | |
1710 | { | |
34acbc95 | 1711 | bool force = qdict_get_try_bool(qdict, "force", false); |
c245b6a3 LC |
1712 | const char *device = qdict_get_str(qdict, "device"); |
1713 | Error *err = NULL; | |
1714 | ||
fbe2d816 | 1715 | qmp_eject(true, device, false, NULL, true, force, &err); |
c245b6a3 LC |
1716 | hmp_handle_error(mon, &err); |
1717 | } | |
333a96ec | 1718 | |
c60bf339 SH |
1719 | static void hmp_change_read_arg(void *opaque, const char *password, |
1720 | void *readline_opaque) | |
333a96ec LC |
1721 | { |
1722 | qmp_change_vnc_password(password, NULL); | |
c60bf339 | 1723 | monitor_read_command(opaque, 1); |
333a96ec LC |
1724 | } |
1725 | ||
333a96ec LC |
1726 | void hmp_change(Monitor *mon, const QDict *qdict) |
1727 | { | |
1728 | const char *device = qdict_get_str(qdict, "device"); | |
1729 | const char *target = qdict_get_str(qdict, "target"); | |
1730 | const char *arg = qdict_get_try_str(qdict, "arg"); | |
baead0ab HR |
1731 | const char *read_only = qdict_get_try_str(qdict, "read-only-mode"); |
1732 | BlockdevChangeReadOnlyMode read_only_mode = 0; | |
333a96ec LC |
1733 | Error *err = NULL; |
1734 | ||
10686749 | 1735 | if (strcmp(device, "vnc") == 0) { |
baead0ab HR |
1736 | if (read_only) { |
1737 | monitor_printf(mon, | |
1738 | "Parameter 'read-only-mode' is invalid for VNC\n"); | |
1739 | return; | |
1740 | } | |
10686749 HR |
1741 | if (strcmp(target, "passwd") == 0 || |
1742 | strcmp(target, "password") == 0) { | |
1743 | if (!arg) { | |
1744 | monitor_read_password(mon, hmp_change_read_arg, NULL); | |
1745 | return; | |
1746 | } | |
1747 | } | |
1748 | qmp_change("vnc", target, !!arg, arg, &err); | |
1749 | } else { | |
baead0ab HR |
1750 | if (read_only) { |
1751 | read_only_mode = | |
1752 | qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup, | |
7fb1cf16 | 1753 | read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX, |
baead0ab HR |
1754 | BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err); |
1755 | if (err) { | |
1756 | hmp_handle_error(mon, &err); | |
1757 | return; | |
1758 | } | |
1759 | } | |
1760 | ||
70e2cb3b KW |
1761 | qmp_blockdev_change_medium(true, device, false, NULL, target, |
1762 | !!arg, arg, !!read_only, read_only_mode, | |
1763 | &err); | |
333a96ec LC |
1764 | } |
1765 | ||
333a96ec LC |
1766 | hmp_handle_error(mon, &err); |
1767 | } | |
80047da5 LC |
1768 | |
1769 | void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) | |
1770 | { | |
1771 | Error *err = NULL; | |
4dc9397b | 1772 | BlockIOThrottle throttle = { |
3f35c3b1 | 1773 | .has_device = true, |
4dc9397b EB |
1774 | .device = (char *) qdict_get_str(qdict, "device"), |
1775 | .bps = qdict_get_int(qdict, "bps"), | |
1776 | .bps_rd = qdict_get_int(qdict, "bps_rd"), | |
1777 | .bps_wr = qdict_get_int(qdict, "bps_wr"), | |
1778 | .iops = qdict_get_int(qdict, "iops"), | |
1779 | .iops_rd = qdict_get_int(qdict, "iops_rd"), | |
1780 | .iops_wr = qdict_get_int(qdict, "iops_wr"), | |
1781 | }; | |
80047da5 | 1782 | |
4dc9397b | 1783 | qmp_block_set_io_throttle(&throttle, &err); |
80047da5 LC |
1784 | hmp_handle_error(mon, &err); |
1785 | } | |
12bd451f SH |
1786 | |
1787 | void hmp_block_stream(Monitor *mon, const QDict *qdict) | |
1788 | { | |
1789 | Error *error = NULL; | |
1790 | const char *device = qdict_get_str(qdict, "device"); | |
1791 | const char *base = qdict_get_try_str(qdict, "base"); | |
c83c66c3 | 1792 | int64_t speed = qdict_get_try_int(qdict, "speed", 0); |
12bd451f | 1793 | |
11d6fbe0 | 1794 | qmp_block_stream(true, device, device, base != NULL, base, false, NULL, |
312fe09c | 1795 | false, NULL, qdict_haskey(qdict, "speed"), speed, |
46663e5e | 1796 | true, BLOCKDEV_ON_ERROR_REPORT, &error); |
12bd451f SH |
1797 | |
1798 | hmp_handle_error(mon, &error); | |
1799 | } | |
2d47c6e9 SH |
1800 | |
1801 | void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict) | |
1802 | { | |
1803 | Error *error = NULL; | |
1804 | const char *device = qdict_get_str(qdict, "device"); | |
c6db2395 | 1805 | int64_t value = qdict_get_int(qdict, "speed"); |
2d47c6e9 SH |
1806 | |
1807 | qmp_block_job_set_speed(device, value, &error); | |
1808 | ||
1809 | hmp_handle_error(mon, &error); | |
1810 | } | |
370521a1 SH |
1811 | |
1812 | void hmp_block_job_cancel(Monitor *mon, const QDict *qdict) | |
1813 | { | |
1814 | Error *error = NULL; | |
1815 | const char *device = qdict_get_str(qdict, "device"); | |
34acbc95 | 1816 | bool force = qdict_get_try_bool(qdict, "force", false); |
370521a1 | 1817 | |
6e37fb81 PB |
1818 | qmp_block_job_cancel(device, true, force, &error); |
1819 | ||
1820 | hmp_handle_error(mon, &error); | |
1821 | } | |
1822 | ||
1823 | void hmp_block_job_pause(Monitor *mon, const QDict *qdict) | |
1824 | { | |
1825 | Error *error = NULL; | |
1826 | const char *device = qdict_get_str(qdict, "device"); | |
1827 | ||
1828 | qmp_block_job_pause(device, &error); | |
1829 | ||
1830 | hmp_handle_error(mon, &error); | |
1831 | } | |
1832 | ||
1833 | void hmp_block_job_resume(Monitor *mon, const QDict *qdict) | |
1834 | { | |
1835 | Error *error = NULL; | |
1836 | const char *device = qdict_get_str(qdict, "device"); | |
1837 | ||
1838 | qmp_block_job_resume(device, &error); | |
370521a1 SH |
1839 | |
1840 | hmp_handle_error(mon, &error); | |
1841 | } | |
e1c37d0e | 1842 | |
aeae883b PB |
1843 | void hmp_block_job_complete(Monitor *mon, const QDict *qdict) |
1844 | { | |
1845 | Error *error = NULL; | |
1846 | const char *device = qdict_get_str(qdict, "device"); | |
1847 | ||
1848 | qmp_block_job_complete(device, &error); | |
1849 | ||
1850 | hmp_handle_error(mon, &error); | |
1851 | } | |
1852 | ||
e49f35bd | 1853 | typedef struct HMPMigrationStatus |
e1c37d0e LC |
1854 | { |
1855 | QEMUTimer *timer; | |
1856 | Monitor *mon; | |
1857 | bool is_block_migration; | |
e49f35bd | 1858 | } HMPMigrationStatus; |
e1c37d0e LC |
1859 | |
1860 | static void hmp_migrate_status_cb(void *opaque) | |
1861 | { | |
e49f35bd | 1862 | HMPMigrationStatus *status = opaque; |
e1c37d0e LC |
1863 | MigrationInfo *info; |
1864 | ||
1865 | info = qmp_query_migrate(NULL); | |
24b8c39b HZ |
1866 | if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE || |
1867 | info->status == MIGRATION_STATUS_SETUP) { | |
e1c37d0e LC |
1868 | if (info->has_disk) { |
1869 | int progress; | |
1870 | ||
1871 | if (info->disk->remaining) { | |
1872 | progress = info->disk->transferred * 100 / info->disk->total; | |
1873 | } else { | |
1874 | progress = 100; | |
1875 | } | |
1876 | ||
1877 | monitor_printf(status->mon, "Completed %d %%\r", progress); | |
1878 | monitor_flush(status->mon); | |
1879 | } | |
1880 | ||
bc72ad67 | 1881 | timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000); |
e1c37d0e LC |
1882 | } else { |
1883 | if (status->is_block_migration) { | |
1884 | monitor_printf(status->mon, "\n"); | |
1885 | } | |
d59ce6f3 DB |
1886 | if (info->has_error_desc) { |
1887 | error_report("%s", info->error_desc); | |
1888 | } | |
e1c37d0e | 1889 | monitor_resume(status->mon); |
bc72ad67 | 1890 | timer_del(status->timer); |
e1c37d0e LC |
1891 | g_free(status); |
1892 | } | |
1893 | ||
1894 | qapi_free_MigrationInfo(info); | |
1895 | } | |
1896 | ||
1897 | void hmp_migrate(Monitor *mon, const QDict *qdict) | |
1898 | { | |
34acbc95 EB |
1899 | bool detach = qdict_get_try_bool(qdict, "detach", false); |
1900 | bool blk = qdict_get_try_bool(qdict, "blk", false); | |
1901 | bool inc = qdict_get_try_bool(qdict, "inc", false); | |
e1c37d0e LC |
1902 | const char *uri = qdict_get_str(qdict, "uri"); |
1903 | Error *err = NULL; | |
1904 | ||
1905 | qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err); | |
1906 | if (err) { | |
193227f9 | 1907 | error_report_err(err); |
e1c37d0e LC |
1908 | return; |
1909 | } | |
1910 | ||
1911 | if (!detach) { | |
e49f35bd | 1912 | HMPMigrationStatus *status; |
e1c37d0e LC |
1913 | |
1914 | if (monitor_suspend(mon) < 0) { | |
1915 | monitor_printf(mon, "terminal does not allow synchronous " | |
1916 | "migration, continuing detached\n"); | |
1917 | return; | |
1918 | } | |
1919 | ||
1920 | status = g_malloc0(sizeof(*status)); | |
1921 | status->mon = mon; | |
1922 | status->is_block_migration = blk || inc; | |
bc72ad67 | 1923 | status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb, |
e1c37d0e | 1924 | status); |
bc72ad67 | 1925 | timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME)); |
e1c37d0e LC |
1926 | } |
1927 | } | |
a15fef21 | 1928 | |
318660f8 MA |
1929 | void hmp_device_add(Monitor *mon, const QDict *qdict) |
1930 | { | |
485febc6 MA |
1931 | Error *err = NULL; |
1932 | ||
1933 | qmp_device_add((QDict *)qdict, NULL, &err); | |
1934 | hmp_handle_error(mon, &err); | |
318660f8 MA |
1935 | } |
1936 | ||
a15fef21 LC |
1937 | void hmp_device_del(Monitor *mon, const QDict *qdict) |
1938 | { | |
1939 | const char *id = qdict_get_str(qdict, "id"); | |
1940 | Error *err = NULL; | |
1941 | ||
1942 | qmp_device_del(id, &err); | |
1943 | hmp_handle_error(mon, &err); | |
1944 | } | |
783e9b48 WC |
1945 | |
1946 | void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) | |
1947 | { | |
e940f543 | 1948 | Error *err = NULL; |
34acbc95 EB |
1949 | bool paging = qdict_get_try_bool(qdict, "paging", false); |
1950 | bool zlib = qdict_get_try_bool(qdict, "zlib", false); | |
1951 | bool lzo = qdict_get_try_bool(qdict, "lzo", false); | |
1952 | bool snappy = qdict_get_try_bool(qdict, "snappy", false); | |
75363769 | 1953 | const char *file = qdict_get_str(qdict, "filename"); |
783e9b48 WC |
1954 | bool has_begin = qdict_haskey(qdict, "begin"); |
1955 | bool has_length = qdict_haskey(qdict, "length"); | |
228de9cf | 1956 | bool has_detach = qdict_haskey(qdict, "detach"); |
783e9b48 WC |
1957 | int64_t begin = 0; |
1958 | int64_t length = 0; | |
228de9cf | 1959 | bool detach = false; |
b53ccc30 | 1960 | enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF; |
75363769 | 1961 | char *prot; |
783e9b48 | 1962 | |
1b7a0f75 | 1963 | if (zlib + lzo + snappy > 1) { |
e940f543 MA |
1964 | error_setg(&err, "only one of '-z|-l|-s' can be set"); |
1965 | hmp_handle_error(mon, &err); | |
1b7a0f75 QN |
1966 | return; |
1967 | } | |
1968 | ||
1969 | if (zlib) { | |
1970 | dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB; | |
1971 | } | |
1972 | ||
1973 | if (lzo) { | |
1974 | dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO; | |
1975 | } | |
1976 | ||
1977 | if (snappy) { | |
1978 | dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY; | |
1979 | } | |
1980 | ||
783e9b48 WC |
1981 | if (has_begin) { |
1982 | begin = qdict_get_int(qdict, "begin"); | |
1983 | } | |
1984 | if (has_length) { | |
1985 | length = qdict_get_int(qdict, "length"); | |
1986 | } | |
228de9cf PX |
1987 | if (has_detach) { |
1988 | detach = qdict_get_bool(qdict, "detach"); | |
1989 | } | |
783e9b48 | 1990 | |
75363769 LC |
1991 | prot = g_strconcat("file:", file, NULL); |
1992 | ||
228de9cf PX |
1993 | qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin, |
1994 | has_length, length, true, dump_format, &err); | |
e940f543 | 1995 | hmp_handle_error(mon, &err); |
75363769 | 1996 | g_free(prot); |
783e9b48 | 1997 | } |
928059a3 LC |
1998 | |
1999 | void hmp_netdev_add(Monitor *mon, const QDict *qdict) | |
2000 | { | |
2001 | Error *err = NULL; | |
2002 | QemuOpts *opts; | |
2003 | ||
2004 | opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err); | |
84d18f06 | 2005 | if (err) { |
928059a3 LC |
2006 | goto out; |
2007 | } | |
2008 | ||
2009 | netdev_add(opts, &err); | |
84d18f06 | 2010 | if (err) { |
928059a3 LC |
2011 | qemu_opts_del(opts); |
2012 | } | |
2013 | ||
2014 | out: | |
2015 | hmp_handle_error(mon, &err); | |
2016 | } | |
5f964155 LC |
2017 | |
2018 | void hmp_netdev_del(Monitor *mon, const QDict *qdict) | |
2019 | { | |
2020 | const char *id = qdict_get_str(qdict, "id"); | |
2021 | Error *err = NULL; | |
2022 | ||
2023 | qmp_netdev_del(id, &err); | |
2024 | hmp_handle_error(mon, &err); | |
2025 | } | |
208c9d1b | 2026 | |
cff8b2c6 PB |
2027 | void hmp_object_add(Monitor *mon, const QDict *qdict) |
2028 | { | |
2029 | Error *err = NULL; | |
2030 | QemuOpts *opts; | |
90998d58 | 2031 | Object *obj = NULL; |
cff8b2c6 PB |
2032 | |
2033 | opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err); | |
2034 | if (err) { | |
90998d58 DB |
2035 | hmp_handle_error(mon, &err); |
2036 | return; | |
cff8b2c6 PB |
2037 | } |
2038 | ||
3a464105 | 2039 | obj = user_creatable_add_opts(opts, &err); |
90998d58 | 2040 | qemu_opts_del(opts); |
cff8b2c6 | 2041 | |
cff8b2c6 | 2042 | if (err) { |
90998d58 | 2043 | hmp_handle_error(mon, &err); |
cff8b2c6 | 2044 | } |
90998d58 DB |
2045 | if (obj) { |
2046 | object_unref(obj); | |
cff8b2c6 | 2047 | } |
cff8b2c6 PB |
2048 | } |
2049 | ||
208c9d1b CB |
2050 | void hmp_getfd(Monitor *mon, const QDict *qdict) |
2051 | { | |
2052 | const char *fdname = qdict_get_str(qdict, "fdname"); | |
e940f543 | 2053 | Error *err = NULL; |
208c9d1b | 2054 | |
e940f543 MA |
2055 | qmp_getfd(fdname, &err); |
2056 | hmp_handle_error(mon, &err); | |
208c9d1b CB |
2057 | } |
2058 | ||
2059 | void hmp_closefd(Monitor *mon, const QDict *qdict) | |
2060 | { | |
2061 | const char *fdname = qdict_get_str(qdict, "fdname"); | |
e940f543 | 2062 | Error *err = NULL; |
208c9d1b | 2063 | |
e940f543 MA |
2064 | qmp_closefd(fdname, &err); |
2065 | hmp_handle_error(mon, &err); | |
208c9d1b | 2066 | } |
e4c8f004 | 2067 | |
3e5a50d6 | 2068 | void hmp_sendkey(Monitor *mon, const QDict *qdict) |
e4c8f004 AK |
2069 | { |
2070 | const char *keys = qdict_get_str(qdict, "keys"); | |
9f328977 | 2071 | KeyValueList *keylist, *head = NULL, *tmp = NULL; |
e4c8f004 AK |
2072 | int has_hold_time = qdict_haskey(qdict, "hold-time"); |
2073 | int hold_time = qdict_get_try_int(qdict, "hold-time", -1); | |
2074 | Error *err = NULL; | |
e4c8f004 | 2075 | char *separator; |
9f328977 | 2076 | int keyname_len; |
e4c8f004 AK |
2077 | |
2078 | while (1) { | |
2079 | separator = strchr(keys, '-'); | |
2080 | keyname_len = separator ? separator - keys : strlen(keys); | |
e4c8f004 AK |
2081 | |
2082 | /* Be compatible with old interface, convert user inputted "<" */ | |
64ffbe04 WB |
2083 | if (keys[0] == '<' && keyname_len == 1) { |
2084 | keys = "less"; | |
e4c8f004 AK |
2085 | keyname_len = 4; |
2086 | } | |
e4c8f004 | 2087 | |
e4c8f004 | 2088 | keylist = g_malloc0(sizeof(*keylist)); |
9f328977 | 2089 | keylist->value = g_malloc0(sizeof(*keylist->value)); |
e4c8f004 AK |
2090 | |
2091 | if (!head) { | |
2092 | head = keylist; | |
2093 | } | |
2094 | if (tmp) { | |
2095 | tmp->next = keylist; | |
2096 | } | |
2097 | tmp = keylist; | |
2098 | ||
64ffbe04 | 2099 | if (strstart(keys, "0x", NULL)) { |
9f328977 | 2100 | char *endp; |
64ffbe04 WB |
2101 | int value = strtoul(keys, &endp, 0); |
2102 | assert(endp <= keys + keyname_len); | |
2103 | if (endp != keys + keyname_len) { | |
9f328977 LC |
2104 | goto err_out; |
2105 | } | |
568c73a4 | 2106 | keylist->value->type = KEY_VALUE_KIND_NUMBER; |
32bafa8f | 2107 | keylist->value->u.number.data = value; |
9f328977 | 2108 | } else { |
64ffbe04 | 2109 | int idx = index_from_key(keys, keyname_len); |
7fb1cf16 | 2110 | if (idx == Q_KEY_CODE__MAX) { |
9f328977 LC |
2111 | goto err_out; |
2112 | } | |
568c73a4 | 2113 | keylist->value->type = KEY_VALUE_KIND_QCODE; |
32bafa8f | 2114 | keylist->value->u.qcode.data = idx; |
9f328977 LC |
2115 | } |
2116 | ||
e4c8f004 AK |
2117 | if (!separator) { |
2118 | break; | |
2119 | } | |
2120 | keys = separator + 1; | |
2121 | } | |
2122 | ||
9f328977 | 2123 | qmp_send_key(head, has_hold_time, hold_time, &err); |
e4c8f004 | 2124 | hmp_handle_error(mon, &err); |
9f328977 LC |
2125 | |
2126 | out: | |
2127 | qapi_free_KeyValueList(head); | |
2128 | return; | |
2129 | ||
2130 | err_out: | |
64ffbe04 | 2131 | monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys); |
9f328977 | 2132 | goto out; |
e4c8f004 | 2133 | } |
ad39cf6d | 2134 | |
3e5a50d6 | 2135 | void hmp_screendump(Monitor *mon, const QDict *qdict) |
ad39cf6d LC |
2136 | { |
2137 | const char *filename = qdict_get_str(qdict, "filename"); | |
2138 | Error *err = NULL; | |
2139 | ||
2140 | qmp_screendump(filename, &err); | |
2141 | hmp_handle_error(mon, &err); | |
2142 | } | |
4057725f PB |
2143 | |
2144 | void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) | |
2145 | { | |
2146 | const char *uri = qdict_get_str(qdict, "uri"); | |
34acbc95 EB |
2147 | bool writable = qdict_get_try_bool(qdict, "writable", false); |
2148 | bool all = qdict_get_try_bool(qdict, "all", false); | |
4057725f PB |
2149 | Error *local_err = NULL; |
2150 | BlockInfoList *block_list, *info; | |
bd269ebc | 2151 | SocketAddress *addr; |
4057725f PB |
2152 | |
2153 | if (writable && !all) { | |
2154 | error_setg(&local_err, "-w only valid together with -a"); | |
2155 | goto exit; | |
2156 | } | |
2157 | ||
2158 | /* First check if the address is valid and start the server. */ | |
2159 | addr = socket_parse(uri, &local_err); | |
2160 | if (local_err != NULL) { | |
2161 | goto exit; | |
2162 | } | |
2163 | ||
bd269ebc MA |
2164 | nbd_server_start(addr, NULL, &local_err); |
2165 | qapi_free_SocketAddress(addr); | |
4057725f PB |
2166 | if (local_err != NULL) { |
2167 | goto exit; | |
2168 | } | |
2169 | ||
2170 | if (!all) { | |
2171 | return; | |
2172 | } | |
2173 | ||
2174 | /* Then try adding all block devices. If one fails, close all and | |
2175 | * exit. | |
2176 | */ | |
2177 | block_list = qmp_query_block(NULL); | |
2178 | ||
2179 | for (info = block_list; info; info = info->next) { | |
2180 | if (!info->value->has_inserted) { | |
2181 | continue; | |
2182 | } | |
2183 | ||
2184 | qmp_nbd_server_add(info->value->device, true, writable, &local_err); | |
2185 | ||
2186 | if (local_err != NULL) { | |
2187 | qmp_nbd_server_stop(NULL); | |
2188 | break; | |
2189 | } | |
2190 | } | |
2191 | ||
2192 | qapi_free_BlockInfoList(block_list); | |
2193 | ||
2194 | exit: | |
2195 | hmp_handle_error(mon, &local_err); | |
2196 | } | |
2197 | ||
2198 | void hmp_nbd_server_add(Monitor *mon, const QDict *qdict) | |
2199 | { | |
2200 | const char *device = qdict_get_str(qdict, "device"); | |
34acbc95 | 2201 | bool writable = qdict_get_try_bool(qdict, "writable", false); |
4057725f PB |
2202 | Error *local_err = NULL; |
2203 | ||
2204 | qmp_nbd_server_add(device, true, writable, &local_err); | |
2205 | ||
2206 | if (local_err != NULL) { | |
2207 | hmp_handle_error(mon, &local_err); | |
2208 | } | |
2209 | } | |
2210 | ||
2211 | void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict) | |
2212 | { | |
e940f543 | 2213 | Error *err = NULL; |
4057725f | 2214 | |
e940f543 MA |
2215 | qmp_nbd_server_stop(&err); |
2216 | hmp_handle_error(mon, &err); | |
4057725f | 2217 | } |
f1088908 | 2218 | |
abf23329 JH |
2219 | void hmp_cpu_add(Monitor *mon, const QDict *qdict) |
2220 | { | |
2221 | int cpuid; | |
2222 | Error *err = NULL; | |
2223 | ||
2224 | cpuid = qdict_get_int(qdict, "id"); | |
2225 | qmp_cpu_add(cpuid, &err); | |
2226 | hmp_handle_error(mon, &err); | |
2227 | } | |
2228 | ||
f1088908 GH |
2229 | void hmp_chardev_add(Monitor *mon, const QDict *qdict) |
2230 | { | |
2231 | const char *args = qdict_get_str(qdict, "args"); | |
2232 | Error *err = NULL; | |
2233 | QemuOpts *opts; | |
2234 | ||
70b94331 | 2235 | opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true); |
f1088908 | 2236 | if (opts == NULL) { |
312fd5f2 | 2237 | error_setg(&err, "Parsing chardev args failed"); |
f1088908 | 2238 | } else { |
b4948be9 | 2239 | qemu_chr_new_from_opts(opts, &err); |
0a73336d | 2240 | qemu_opts_del(opts); |
f1088908 GH |
2241 | } |
2242 | hmp_handle_error(mon, &err); | |
2243 | } | |
2244 | ||
75b60160 AN |
2245 | void hmp_chardev_change(Monitor *mon, const QDict *qdict) |
2246 | { | |
2247 | const char *args = qdict_get_str(qdict, "args"); | |
2248 | const char *id; | |
2249 | Error *err = NULL; | |
2250 | ChardevBackend *backend = NULL; | |
2251 | ChardevReturn *ret = NULL; | |
2252 | QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, | |
2253 | true); | |
2254 | if (!opts) { | |
2255 | error_setg(&err, "Parsing chardev args failed"); | |
2256 | goto end; | |
2257 | } | |
2258 | ||
2259 | id = qdict_get_str(qdict, "id"); | |
2260 | if (qemu_opts_id(opts)) { | |
2261 | error_setg(&err, "Unexpected 'id' parameter"); | |
2262 | goto end; | |
2263 | } | |
2264 | ||
2265 | backend = qemu_chr_parse_opts(opts, &err); | |
2266 | if (!backend) { | |
2267 | goto end; | |
2268 | } | |
2269 | ||
2270 | ret = qmp_chardev_change(id, backend, &err); | |
2271 | ||
2272 | end: | |
2273 | qapi_free_ChardevReturn(ret); | |
2274 | qapi_free_ChardevBackend(backend); | |
2275 | qemu_opts_del(opts); | |
2276 | hmp_handle_error(mon, &err); | |
2277 | } | |
2278 | ||
f1088908 GH |
2279 | void hmp_chardev_remove(Monitor *mon, const QDict *qdict) |
2280 | { | |
2281 | Error *local_err = NULL; | |
2282 | ||
2283 | qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err); | |
2284 | hmp_handle_error(mon, &local_err); | |
2285 | } | |
587da2c3 | 2286 | |
bd1d5ad9 SF |
2287 | void hmp_chardev_send_break(Monitor *mon, const QDict *qdict) |
2288 | { | |
2289 | Error *local_err = NULL; | |
2290 | ||
2291 | qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err); | |
2292 | hmp_handle_error(mon, &local_err); | |
2293 | } | |
2294 | ||
587da2c3 KW |
2295 | void hmp_qemu_io(Monitor *mon, const QDict *qdict) |
2296 | { | |
4c7b7e9b | 2297 | BlockBackend *blk; |
e7f98f2f | 2298 | BlockBackend *local_blk = NULL; |
1813d330 | 2299 | AioContext *aio_context; |
587da2c3 KW |
2300 | const char* device = qdict_get_str(qdict, "device"); |
2301 | const char* command = qdict_get_str(qdict, "command"); | |
2302 | Error *err = NULL; | |
d7086422 | 2303 | int ret; |
587da2c3 | 2304 | |
4c7b7e9b | 2305 | blk = blk_by_name(device); |
e7f98f2f KW |
2306 | if (!blk) { |
2307 | BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err); | |
2308 | if (bs) { | |
6d0eb64d | 2309 | blk = local_blk = blk_new(0, BLK_PERM_ALL); |
d7086422 KW |
2310 | ret = blk_insert_bs(blk, bs, &err); |
2311 | if (ret < 0) { | |
2312 | goto fail; | |
2313 | } | |
e7f98f2f KW |
2314 | } else { |
2315 | goto fail; | |
2316 | } | |
2317 | } | |
2318 | ||
1813d330 KW |
2319 | aio_context = blk_get_aio_context(blk); |
2320 | aio_context_acquire(aio_context); | |
479b5998 | 2321 | |
887354bd KW |
2322 | /* |
2323 | * Notably absent: Proper permission management. This is sad, but it seems | |
2324 | * almost impossible to achieve without changing the semantics and thereby | |
2325 | * limiting the use cases of the qemu-io HMP command. | |
2326 | * | |
2327 | * In an ideal world we would unconditionally create a new BlockBackend for | |
2328 | * qemuio_command(), but we have commands like 'reopen' and want them to | |
2329 | * take effect on the exact BlockBackend whose name the user passed instead | |
2330 | * of just on a temporary copy of it. | |
2331 | * | |
2332 | * Another problem is that deleting the temporary BlockBackend involves | |
2333 | * draining all requests on it first, but some qemu-iotests cases want to | |
2334 | * issue multiple aio_read/write requests and expect them to complete in | |
2335 | * the background while the monitor has already returned. | |
2336 | * | |
2337 | * This is also what prevents us from saving the original permissions and | |
2338 | * restoring them later: We can't revoke permissions until all requests | |
2339 | * have completed, and we don't know when that is nor can we really let | |
2340 | * anything else run before we have revoken them to avoid race conditions. | |
2341 | * | |
2342 | * What happens now is that command() in qemu-io-cmds.c can extend the | |
2343 | * permissions if necessary for the qemu-io command. And they simply stay | |
2344 | * extended, possibly resulting in a read-only guest device keeping write | |
2345 | * permissions. Ugly, but it appears to be the lesser evil. | |
2346 | */ | |
1813d330 | 2347 | qemuio_command(blk, command); |
479b5998 | 2348 | |
1813d330 | 2349 | aio_context_release(aio_context); |
587da2c3 | 2350 | |
e7f98f2f KW |
2351 | fail: |
2352 | blk_unref(local_blk); | |
587da2c3 KW |
2353 | hmp_handle_error(mon, &err); |
2354 | } | |
ab2d0531 PB |
2355 | |
2356 | void hmp_object_del(Monitor *mon, const QDict *qdict) | |
2357 | { | |
2358 | const char *id = qdict_get_str(qdict, "id"); | |
2359 | Error *err = NULL; | |
2360 | ||
90998d58 | 2361 | user_creatable_del(id, &err); |
ab2d0531 PB |
2362 | hmp_handle_error(mon, &err); |
2363 | } | |
eb1539b2 HT |
2364 | |
2365 | void hmp_info_memdev(Monitor *mon, const QDict *qdict) | |
2366 | { | |
2367 | Error *err = NULL; | |
2368 | MemdevList *memdev_list = qmp_query_memdev(&err); | |
2369 | MemdevList *m = memdev_list; | |
3b098d56 | 2370 | Visitor *v; |
976620ac | 2371 | char *str; |
eb1539b2 HT |
2372 | |
2373 | while (m) { | |
3b098d56 EB |
2374 | v = string_output_visitor_new(false, &str); |
2375 | visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL); | |
e1ff3c67 | 2376 | monitor_printf(mon, "memory backend: %s\n", m->value->id); |
eb1539b2 HT |
2377 | monitor_printf(mon, " size: %" PRId64 "\n", m->value->size); |
2378 | monitor_printf(mon, " merge: %s\n", | |
2379 | m->value->merge ? "true" : "false"); | |
2380 | monitor_printf(mon, " dump: %s\n", | |
2381 | m->value->dump ? "true" : "false"); | |
2382 | monitor_printf(mon, " prealloc: %s\n", | |
2383 | m->value->prealloc ? "true" : "false"); | |
2384 | monitor_printf(mon, " policy: %s\n", | |
2385 | HostMemPolicy_lookup[m->value->policy]); | |
3b098d56 | 2386 | visit_complete(v, &str); |
976620ac | 2387 | monitor_printf(mon, " host nodes: %s\n", str); |
eb1539b2 | 2388 | |
976620ac | 2389 | g_free(str); |
3b098d56 | 2390 | visit_free(v); |
eb1539b2 | 2391 | m = m->next; |
eb1539b2 HT |
2392 | } |
2393 | ||
2394 | monitor_printf(mon, "\n"); | |
ecaf54a0 CF |
2395 | |
2396 | qapi_free_MemdevList(memdev_list); | |
eb1539b2 | 2397 | } |
a631892f ZG |
2398 | |
2399 | void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) | |
2400 | { | |
2401 | Error *err = NULL; | |
2402 | MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err); | |
2403 | MemoryDeviceInfoList *info; | |
2404 | MemoryDeviceInfo *value; | |
2405 | PCDIMMDeviceInfo *di; | |
2406 | ||
2407 | for (info = info_list; info; info = info->next) { | |
2408 | value = info->value; | |
2409 | ||
2410 | if (value) { | |
1fd5d4fe | 2411 | switch (value->type) { |
a631892f | 2412 | case MEMORY_DEVICE_INFO_KIND_DIMM: |
32bafa8f | 2413 | di = value->u.dimm.data; |
a631892f ZG |
2414 | |
2415 | monitor_printf(mon, "Memory device [%s]: \"%s\"\n", | |
1fd5d4fe | 2416 | MemoryDeviceInfoKind_lookup[value->type], |
a631892f ZG |
2417 | di->id ? di->id : ""); |
2418 | monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr); | |
2419 | monitor_printf(mon, " slot: %" PRId64 "\n", di->slot); | |
2420 | monitor_printf(mon, " node: %" PRId64 "\n", di->node); | |
2421 | monitor_printf(mon, " size: %" PRIu64 "\n", di->size); | |
2422 | monitor_printf(mon, " memdev: %s\n", di->memdev); | |
2423 | monitor_printf(mon, " hotplugged: %s\n", | |
2424 | di->hotplugged ? "true" : "false"); | |
2425 | monitor_printf(mon, " hotpluggable: %s\n", | |
2426 | di->hotpluggable ? "true" : "false"); | |
2427 | break; | |
2428 | default: | |
2429 | break; | |
2430 | } | |
2431 | } | |
2432 | } | |
2433 | ||
2434 | qapi_free_MemoryDeviceInfoList(info_list); | |
2435 | } | |
89d7fa9e | 2436 | |
62313160 TW |
2437 | void hmp_info_iothreads(Monitor *mon, const QDict *qdict) |
2438 | { | |
2439 | IOThreadInfoList *info_list = qmp_query_iothreads(NULL); | |
2440 | IOThreadInfoList *info; | |
5fc00480 | 2441 | IOThreadInfo *value; |
62313160 TW |
2442 | |
2443 | for (info = info_list; info; info = info->next) { | |
5fc00480 PH |
2444 | value = info->value; |
2445 | monitor_printf(mon, "%s:\n", value->id); | |
2446 | monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id); | |
2447 | monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns); | |
2448 | monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow); | |
2449 | monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink); | |
62313160 TW |
2450 | } |
2451 | ||
2452 | qapi_free_IOThreadInfoList(info_list); | |
2453 | } | |
2454 | ||
89d7fa9e AF |
2455 | void hmp_qom_list(Monitor *mon, const QDict *qdict) |
2456 | { | |
2457 | const char *path = qdict_get_try_str(qdict, "path"); | |
2458 | ObjectPropertyInfoList *list; | |
2459 | Error *err = NULL; | |
2460 | ||
2461 | if (path == NULL) { | |
2462 | monitor_printf(mon, "/\n"); | |
2463 | return; | |
2464 | } | |
2465 | ||
2466 | list = qmp_qom_list(path, &err); | |
2467 | if (err == NULL) { | |
2468 | ObjectPropertyInfoList *start = list; | |
2469 | while (list != NULL) { | |
2470 | ObjectPropertyInfo *value = list->value; | |
2471 | ||
2472 | monitor_printf(mon, "%s (%s)\n", | |
2473 | value->name, value->type); | |
2474 | list = list->next; | |
2475 | } | |
2476 | qapi_free_ObjectPropertyInfoList(start); | |
2477 | } | |
2478 | hmp_handle_error(mon, &err); | |
2479 | } | |
c0e6ee9e AF |
2480 | |
2481 | void hmp_qom_set(Monitor *mon, const QDict *qdict) | |
2482 | { | |
2483 | const char *path = qdict_get_str(qdict, "path"); | |
2484 | const char *property = qdict_get_str(qdict, "property"); | |
2485 | const char *value = qdict_get_str(qdict, "value"); | |
2486 | Error *err = NULL; | |
2487 | bool ambiguous = false; | |
2488 | Object *obj; | |
2489 | ||
2490 | obj = object_resolve_path(path, &ambiguous); | |
2491 | if (obj == NULL) { | |
75158ebb MA |
2492 | error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND, |
2493 | "Device '%s' not found", path); | |
c0e6ee9e AF |
2494 | } else { |
2495 | if (ambiguous) { | |
2496 | monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path); | |
2497 | } | |
2498 | object_property_parse(obj, value, property, &err); | |
2499 | } | |
2500 | hmp_handle_error(mon, &err); | |
2501 | } | |
fafa4d50 SF |
2502 | |
2503 | void hmp_rocker(Monitor *mon, const QDict *qdict) | |
2504 | { | |
2505 | const char *name = qdict_get_str(qdict, "name"); | |
2506 | RockerSwitch *rocker; | |
533fdaed | 2507 | Error *err = NULL; |
fafa4d50 | 2508 | |
533fdaed MA |
2509 | rocker = qmp_query_rocker(name, &err); |
2510 | if (err != NULL) { | |
2511 | hmp_handle_error(mon, &err); | |
fafa4d50 SF |
2512 | return; |
2513 | } | |
2514 | ||
2515 | monitor_printf(mon, "name: %s\n", rocker->name); | |
2516 | monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id); | |
2517 | monitor_printf(mon, "ports: %d\n", rocker->ports); | |
2518 | ||
2519 | qapi_free_RockerSwitch(rocker); | |
2520 | } | |
2521 | ||
2522 | void hmp_rocker_ports(Monitor *mon, const QDict *qdict) | |
2523 | { | |
2524 | RockerPortList *list, *port; | |
2525 | const char *name = qdict_get_str(qdict, "name"); | |
533fdaed | 2526 | Error *err = NULL; |
fafa4d50 | 2527 | |
533fdaed MA |
2528 | list = qmp_query_rocker_ports(name, &err); |
2529 | if (err != NULL) { | |
2530 | hmp_handle_error(mon, &err); | |
fafa4d50 SF |
2531 | return; |
2532 | } | |
2533 | ||
2534 | monitor_printf(mon, " ena/ speed/ auto\n"); | |
2535 | monitor_printf(mon, " port link duplex neg?\n"); | |
2536 | ||
2537 | for (port = list; port; port = port->next) { | |
2538 | monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n", | |
2539 | port->value->name, | |
2540 | port->value->enabled ? port->value->link_up ? | |
2541 | "up" : "down" : "!ena", | |
2542 | port->value->speed == 10000 ? "10G" : "??", | |
2543 | port->value->duplex ? "FD" : "HD", | |
2544 | port->value->autoneg ? "Yes" : "No"); | |
2545 | } | |
2546 | ||
2547 | qapi_free_RockerPortList(list); | |
2548 | } | |
2549 | ||
2550 | void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict) | |
2551 | { | |
2552 | RockerOfDpaFlowList *list, *info; | |
2553 | const char *name = qdict_get_str(qdict, "name"); | |
2554 | uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1); | |
533fdaed | 2555 | Error *err = NULL; |
fafa4d50 | 2556 | |
533fdaed MA |
2557 | list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err); |
2558 | if (err != NULL) { | |
2559 | hmp_handle_error(mon, &err); | |
fafa4d50 SF |
2560 | return; |
2561 | } | |
2562 | ||
2563 | monitor_printf(mon, "prio tbl hits key(mask) --> actions\n"); | |
2564 | ||
2565 | for (info = list; info; info = info->next) { | |
2566 | RockerOfDpaFlow *flow = info->value; | |
2567 | RockerOfDpaFlowKey *key = flow->key; | |
2568 | RockerOfDpaFlowMask *mask = flow->mask; | |
2569 | RockerOfDpaFlowAction *action = flow->action; | |
2570 | ||
2571 | if (flow->hits) { | |
2572 | monitor_printf(mon, "%-4d %-3d %-4" PRIu64, | |
2573 | key->priority, key->tbl_id, flow->hits); | |
2574 | } else { | |
2575 | monitor_printf(mon, "%-4d %-3d ", | |
2576 | key->priority, key->tbl_id); | |
2577 | } | |
2578 | ||
2579 | if (key->has_in_pport) { | |
2580 | monitor_printf(mon, " pport %d", key->in_pport); | |
2581 | if (mask->has_in_pport) { | |
2582 | monitor_printf(mon, "(0x%x)", mask->in_pport); | |
2583 | } | |
2584 | } | |
2585 | ||
2586 | if (key->has_vlan_id) { | |
2587 | monitor_printf(mon, " vlan %d", | |
2588 | key->vlan_id & VLAN_VID_MASK); | |
2589 | if (mask->has_vlan_id) { | |
2590 | monitor_printf(mon, "(0x%x)", mask->vlan_id); | |
2591 | } | |
2592 | } | |
2593 | ||
2594 | if (key->has_tunnel_id) { | |
2595 | monitor_printf(mon, " tunnel %d", key->tunnel_id); | |
2596 | if (mask->has_tunnel_id) { | |
2597 | monitor_printf(mon, "(0x%x)", mask->tunnel_id); | |
2598 | } | |
2599 | } | |
2600 | ||
2601 | if (key->has_eth_type) { | |
2602 | switch (key->eth_type) { | |
2603 | case 0x0806: | |
2604 | monitor_printf(mon, " ARP"); | |
2605 | break; | |
2606 | case 0x0800: | |
2607 | monitor_printf(mon, " IP"); | |
2608 | break; | |
2609 | case 0x86dd: | |
2610 | monitor_printf(mon, " IPv6"); | |
2611 | break; | |
2612 | case 0x8809: | |
2613 | monitor_printf(mon, " LACP"); | |
2614 | break; | |
2615 | case 0x88cc: | |
2616 | monitor_printf(mon, " LLDP"); | |
2617 | break; | |
2618 | default: | |
2619 | monitor_printf(mon, " eth type 0x%04x", key->eth_type); | |
2620 | break; | |
2621 | } | |
2622 | } | |
2623 | ||
2624 | if (key->has_eth_src) { | |
2625 | if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) && | |
2626 | (mask->has_eth_src) && | |
2627 | (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { | |
2628 | monitor_printf(mon, " src <any mcast/bcast>"); | |
2629 | } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) && | |
2630 | (mask->has_eth_src) && | |
2631 | (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { | |
2632 | monitor_printf(mon, " src <any ucast>"); | |
2633 | } else { | |
2634 | monitor_printf(mon, " src %s", key->eth_src); | |
2635 | if (mask->has_eth_src) { | |
2636 | monitor_printf(mon, "(%s)", mask->eth_src); | |
2637 | } | |
2638 | } | |
2639 | } | |
2640 | ||
2641 | if (key->has_eth_dst) { | |
2642 | if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) && | |
2643 | (mask->has_eth_dst) && | |
2644 | (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { | |
2645 | monitor_printf(mon, " dst <any mcast/bcast>"); | |
2646 | } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) && | |
2647 | (mask->has_eth_dst) && | |
2648 | (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { | |
2649 | monitor_printf(mon, " dst <any ucast>"); | |
2650 | } else { | |
2651 | monitor_printf(mon, " dst %s", key->eth_dst); | |
2652 | if (mask->has_eth_dst) { | |
2653 | monitor_printf(mon, "(%s)", mask->eth_dst); | |
2654 | } | |
2655 | } | |
2656 | } | |
2657 | ||
2658 | if (key->has_ip_proto) { | |
2659 | monitor_printf(mon, " proto %d", key->ip_proto); | |
2660 | if (mask->has_ip_proto) { | |
2661 | monitor_printf(mon, "(0x%x)", mask->ip_proto); | |
2662 | } | |
2663 | } | |
2664 | ||
2665 | if (key->has_ip_tos) { | |
2666 | monitor_printf(mon, " TOS %d", key->ip_tos); | |
2667 | if (mask->has_ip_tos) { | |
2668 | monitor_printf(mon, "(0x%x)", mask->ip_tos); | |
2669 | } | |
2670 | } | |
2671 | ||
2672 | if (key->has_ip_dst) { | |
2673 | monitor_printf(mon, " dst %s", key->ip_dst); | |
2674 | } | |
2675 | ||
2676 | if (action->has_goto_tbl || action->has_group_id || | |
2677 | action->has_new_vlan_id) { | |
2678 | monitor_printf(mon, " -->"); | |
2679 | } | |
2680 | ||
2681 | if (action->has_new_vlan_id) { | |
2682 | monitor_printf(mon, " apply new vlan %d", | |
2683 | ntohs(action->new_vlan_id)); | |
2684 | } | |
2685 | ||
2686 | if (action->has_group_id) { | |
2687 | monitor_printf(mon, " write group 0x%08x", action->group_id); | |
2688 | } | |
2689 | ||
2690 | if (action->has_goto_tbl) { | |
2691 | monitor_printf(mon, " goto tbl %d", action->goto_tbl); | |
2692 | } | |
2693 | ||
2694 | monitor_printf(mon, "\n"); | |
2695 | } | |
2696 | ||
2697 | qapi_free_RockerOfDpaFlowList(list); | |
2698 | } | |
2699 | ||
2700 | void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict) | |
2701 | { | |
2702 | RockerOfDpaGroupList *list, *g; | |
2703 | const char *name = qdict_get_str(qdict, "name"); | |
2704 | uint8_t type = qdict_get_try_int(qdict, "type", 9); | |
533fdaed | 2705 | Error *err = NULL; |
fafa4d50 SF |
2706 | bool set = false; |
2707 | ||
533fdaed MA |
2708 | list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err); |
2709 | if (err != NULL) { | |
2710 | hmp_handle_error(mon, &err); | |
fafa4d50 SF |
2711 | return; |
2712 | } | |
2713 | ||
2714 | monitor_printf(mon, "id (decode) --> buckets\n"); | |
2715 | ||
2716 | for (g = list; g; g = g->next) { | |
2717 | RockerOfDpaGroup *group = g->value; | |
2718 | ||
2719 | monitor_printf(mon, "0x%08x", group->id); | |
2720 | ||
2721 | monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" : | |
2722 | group->type == 1 ? "L2 rewrite" : | |
2723 | group->type == 2 ? "L3 unicast" : | |
2724 | group->type == 3 ? "L2 multicast" : | |
2725 | group->type == 4 ? "L2 flood" : | |
2726 | group->type == 5 ? "L3 interface" : | |
2727 | group->type == 6 ? "L3 multicast" : | |
2728 | group->type == 7 ? "L3 ECMP" : | |
2729 | group->type == 8 ? "L2 overlay" : | |
2730 | "unknown"); | |
2731 | ||
2732 | if (group->has_vlan_id) { | |
2733 | monitor_printf(mon, " vlan %d", group->vlan_id); | |
2734 | } | |
2735 | ||
2736 | if (group->has_pport) { | |
2737 | monitor_printf(mon, " pport %d", group->pport); | |
2738 | } | |
2739 | ||
2740 | if (group->has_index) { | |
2741 | monitor_printf(mon, " index %d", group->index); | |
2742 | } | |
2743 | ||
2744 | monitor_printf(mon, ") -->"); | |
2745 | ||
2746 | if (group->has_set_vlan_id && group->set_vlan_id) { | |
2747 | set = true; | |
2748 | monitor_printf(mon, " set vlan %d", | |
2749 | group->set_vlan_id & VLAN_VID_MASK); | |
2750 | } | |
2751 | ||
2752 | if (group->has_set_eth_src) { | |
2753 | if (!set) { | |
2754 | set = true; | |
2755 | monitor_printf(mon, " set"); | |
2756 | } | |
2757 | monitor_printf(mon, " src %s", group->set_eth_src); | |
2758 | } | |
2759 | ||
2760 | if (group->has_set_eth_dst) { | |
2761 | if (!set) { | |
2762 | set = true; | |
2763 | monitor_printf(mon, " set"); | |
2764 | } | |
2765 | monitor_printf(mon, " dst %s", group->set_eth_dst); | |
2766 | } | |
2767 | ||
2768 | set = false; | |
2769 | ||
2770 | if (group->has_ttl_check && group->ttl_check) { | |
2771 | monitor_printf(mon, " check TTL"); | |
2772 | } | |
2773 | ||
2774 | if (group->has_group_id && group->group_id) { | |
2775 | monitor_printf(mon, " group id 0x%08x", group->group_id); | |
2776 | } | |
2777 | ||
2778 | if (group->has_pop_vlan && group->pop_vlan) { | |
2779 | monitor_printf(mon, " pop vlan"); | |
2780 | } | |
2781 | ||
2782 | if (group->has_out_pport) { | |
2783 | monitor_printf(mon, " out pport %d", group->out_pport); | |
2784 | } | |
2785 | ||
2786 | if (group->has_group_ids) { | |
2787 | struct uint32List *id; | |
2788 | ||
2789 | monitor_printf(mon, " groups ["); | |
2790 | for (id = group->group_ids; id; id = id->next) { | |
2791 | monitor_printf(mon, "0x%08x", id->value); | |
2792 | if (id->next) { | |
2793 | monitor_printf(mon, ","); | |
2794 | } | |
2795 | } | |
2796 | monitor_printf(mon, "]"); | |
2797 | } | |
2798 | ||
2799 | monitor_printf(mon, "\n"); | |
2800 | } | |
2801 | ||
2802 | qapi_free_RockerOfDpaGroupList(list); | |
2803 | } | |
4a6b52d6 PX |
2804 | |
2805 | void hmp_info_dump(Monitor *mon, const QDict *qdict) | |
2806 | { | |
2807 | DumpQueryResult *result = qmp_query_dump(NULL); | |
2808 | ||
2809 | assert(result && result->status < DUMP_STATUS__MAX); | |
2810 | monitor_printf(mon, "Status: %s\n", DumpStatus_lookup[result->status]); | |
2811 | ||
2812 | if (result->status == DUMP_STATUS_ACTIVE) { | |
2813 | float percent = 0; | |
2814 | assert(result->total != 0); | |
2815 | percent = 100.0 * result->completed / result->total; | |
2816 | monitor_printf(mon, "Finished: %.2f %%\n", percent); | |
2817 | } | |
2818 | ||
2819 | qapi_free_DumpQueryResult(result); | |
2820 | } | |
d2d8d46f | 2821 | |
be9b23c4 PX |
2822 | void hmp_info_ramblock(Monitor *mon, const QDict *qdict) |
2823 | { | |
2824 | ram_block_dump(mon); | |
2825 | } | |
2826 | ||
d2d8d46f BR |
2827 | void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict) |
2828 | { | |
2829 | Error *err = NULL; | |
2830 | HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err); | |
2831 | HotpluggableCPUList *saved = l; | |
2832 | CpuInstanceProperties *c; | |
2833 | ||
2834 | if (err != NULL) { | |
2835 | hmp_handle_error(mon, &err); | |
2836 | return; | |
2837 | } | |
2838 | ||
2839 | monitor_printf(mon, "Hotpluggable CPUs:\n"); | |
2840 | while (l) { | |
2841 | monitor_printf(mon, " type: \"%s\"\n", l->value->type); | |
2842 | monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n", | |
2843 | l->value->vcpus_count); | |
2844 | if (l->value->has_qom_path) { | |
2845 | monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path); | |
2846 | } | |
2847 | ||
2848 | c = l->value->props; | |
2849 | monitor_printf(mon, " CPUInstance Properties:\n"); | |
27393c33 PK |
2850 | if (c->has_node_id) { |
2851 | monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id); | |
d2d8d46f | 2852 | } |
27393c33 PK |
2853 | if (c->has_socket_id) { |
2854 | monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id); | |
d2d8d46f | 2855 | } |
27393c33 PK |
2856 | if (c->has_core_id) { |
2857 | monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id); | |
d2d8d46f | 2858 | } |
27393c33 PK |
2859 | if (c->has_thread_id) { |
2860 | monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id); | |
d2d8d46f BR |
2861 | } |
2862 | ||
2863 | l = l->next; | |
2864 | } | |
2865 | ||
2866 | qapi_free_HotpluggableCPUList(saved); | |
2867 | } | |
39164c13 IM |
2868 | |
2869 | void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict) | |
2870 | { | |
72d9196f BW |
2871 | Error *err = NULL; |
2872 | GuidInfo *info = qmp_query_vm_generation_id(&err); | |
39164c13 IM |
2873 | if (info) { |
2874 | monitor_printf(mon, "%s\n", info->guid); | |
2875 | } | |
72d9196f | 2876 | hmp_handle_error(mon, &err); |
39164c13 IM |
2877 | qapi_free_GuidInfo(info); |
2878 | } |