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