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