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