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