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