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