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