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