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