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