]>
Commit | Line | Data |
---|---|---|
48a32bed AL |
1 | /* |
2 | * Human Monitor Interface | |
3 | * | |
4 | * Copyright IBM, Corp. 2011 | |
5 | * | |
6 | * Authors: | |
7 | * Anthony Liguori <[email protected]> | |
8 | * | |
9 | * This work is licensed under the terms of the GNU GPL, version 2. See | |
10 | * the COPYING file in the top-level directory. | |
11 | * | |
6b620ca3 PB |
12 | * Contributions after 2012-01-13 are licensed under the terms of the |
13 | * GNU GPL, version 2 or (at your option) any later version. | |
48a32bed AL |
14 | */ |
15 | ||
d38ea87a | 16 | #include "qemu/osdep.h" |
48a32bed | 17 | #include "hmp.h" |
1422e32d | 18 | #include "net/net.h" |
fafa4d50 | 19 | #include "net/eth.h" |
8228e353 | 20 | #include "chardev/char.h" |
4c7b7e9b | 21 | #include "sysemu/block-backend.h" |
52b26205 | 22 | #include "sysemu/sysemu.h" |
213dcb06 | 23 | #include "qemu/config-file.h" |
1de7afc9 PB |
24 | #include "qemu/option.h" |
25 | #include "qemu/timer.h" | |
1de7afc9 | 26 | #include "qemu/sockets.h" |
83c9089e | 27 | #include "monitor/monitor.h" |
318660f8 | 28 | #include "monitor/qdev.h" |
e688df6b | 29 | #include "qapi/error.h" |
cff8b2c6 | 30 | #include "qapi/opts-visitor.h" |
eb815e24 | 31 | #include "qapi/qapi-builtin-visit.h" |
112ed241 MA |
32 | #include "qapi/qapi-commands-block.h" |
33 | #include "qapi/qapi-commands-char.h" | |
34 | #include "qapi/qapi-commands-migration.h" | |
35 | #include "qapi/qapi-commands-misc.h" | |
36 | #include "qapi/qapi-commands-net.h" | |
37 | #include "qapi/qapi-commands-rocker.h" | |
38 | #include "qapi/qapi-commands-run-state.h" | |
39 | #include "qapi/qapi-commands-tpm.h" | |
40 | #include "qapi/qapi-commands-ui.h" | |
452fcdbc | 41 | #include "qapi/qmp/qdict.h" |
cc7a8ea7 | 42 | #include "qapi/qmp/qerror.h" |
f4a06d13 | 43 | #include "qapi/string-input-visitor.h" |
eb1539b2 | 44 | #include "qapi/string-output-visitor.h" |
90998d58 | 45 | #include "qom/object_interfaces.h" |
28ecbaee | 46 | #include "ui/console.h" |
bd269ebc | 47 | #include "block/nbd.h" |
bd093a36 | 48 | #include "block/qapi.h" |
587da2c3 | 49 | #include "qemu-io.h" |
f348b6d1 | 50 | #include "qemu/cutils.h" |
d59ce6f3 | 51 | #include "qemu/error-report.h" |
be9b23c4 | 52 | #include "exec/ramlist.h" |
61b97833 | 53 | #include "hw/intc/intc.h" |
5e22479a | 54 | #include "migration/snapshot.h" |
9d18af93 | 55 | #include "migration/misc.h" |
48a32bed | 56 | |
22fa7da0 CR |
57 | #ifdef CONFIG_SPICE |
58 | #include <spice/enums.h> | |
59 | #endif | |
60 | ||
0cfd6a9a LC |
61 | static void hmp_handle_error(Monitor *mon, Error **errp) |
62 | { | |
415168e0 MA |
63 | assert(errp); |
64 | if (*errp) { | |
193227f9 | 65 | error_report_err(*errp); |
0cfd6a9a LC |
66 | } |
67 | } | |
68 | ||
84f2d0ea | 69 | void hmp_info_name(Monitor *mon, const QDict *qdict) |
48a32bed AL |
70 | { |
71 | NameInfo *info; | |
72 | ||
73 | info = qmp_query_name(NULL); | |
74 | if (info->has_name) { | |
75 | monitor_printf(mon, "%s\n", info->name); | |
76 | } | |
77 | qapi_free_NameInfo(info); | |
78 | } | |
b9c15f16 | 79 | |
84f2d0ea | 80 | void hmp_info_version(Monitor *mon, const QDict *qdict) |
b9c15f16 LC |
81 | { |
82 | VersionInfo *info; | |
83 | ||
84 | info = qmp_query_version(NULL); | |
85 | ||
86 | monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n", | |
4752cdbb | 87 | info->qemu->major, info->qemu->minor, info->qemu->micro, |
b9c15f16 LC |
88 | info->package); |
89 | ||
90 | qapi_free_VersionInfo(info); | |
91 | } | |
292a2602 | 92 | |
84f2d0ea | 93 | void hmp_info_kvm(Monitor *mon, const QDict *qdict) |
292a2602 LC |
94 | { |
95 | KvmInfo *info; | |
96 | ||
97 | info = qmp_query_kvm(NULL); | |
98 | monitor_printf(mon, "kvm support: "); | |
99 | if (info->present) { | |
100 | monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled"); | |
101 | } else { | |
102 | monitor_printf(mon, "not compiled\n"); | |
103 | } | |
104 | ||
105 | qapi_free_KvmInfo(info); | |
106 | } | |
107 | ||
84f2d0ea | 108 | void hmp_info_status(Monitor *mon, const QDict *qdict) |
1fa9a5e4 LC |
109 | { |
110 | StatusInfo *info; | |
111 | ||
112 | info = qmp_query_status(NULL); | |
113 | ||
114 | monitor_printf(mon, "VM status: %s%s", | |
115 | info->running ? "running" : "paused", | |
116 | info->singlestep ? " (single step mode)" : ""); | |
117 | ||
118 | if (!info->running && info->status != RUN_STATE_PAUSED) { | |
977c736f | 119 | monitor_printf(mon, " (%s)", RunState_str(info->status)); |
1fa9a5e4 LC |
120 | } |
121 | ||
122 | monitor_printf(mon, "\n"); | |
123 | ||
124 | qapi_free_StatusInfo(info); | |
125 | } | |
126 | ||
84f2d0ea | 127 | void hmp_info_uuid(Monitor *mon, const QDict *qdict) |
efab767e LC |
128 | { |
129 | UuidInfo *info; | |
130 | ||
131 | info = qmp_query_uuid(NULL); | |
132 | monitor_printf(mon, "%s\n", info->UUID); | |
133 | qapi_free_UuidInfo(info); | |
134 | } | |
c5a415a0 | 135 | |
84f2d0ea | 136 | void hmp_info_chardev(Monitor *mon, const QDict *qdict) |
c5a415a0 LC |
137 | { |
138 | ChardevInfoList *char_info, *info; | |
139 | ||
140 | char_info = qmp_query_chardev(NULL); | |
141 | for (info = char_info; info; info = info->next) { | |
142 | monitor_printf(mon, "%s: filename=%s\n", info->value->label, | |
143 | info->value->filename); | |
144 | } | |
145 | ||
146 | qapi_free_ChardevInfoList(char_info); | |
147 | } | |
7a7f325e | 148 | |
84f2d0ea | 149 | void hmp_info_mice(Monitor *mon, const QDict *qdict) |
e235cec3 LC |
150 | { |
151 | MouseInfoList *mice_list, *mouse; | |
152 | ||
153 | mice_list = qmp_query_mice(NULL); | |
154 | if (!mice_list) { | |
155 | monitor_printf(mon, "No mouse devices connected\n"); | |
156 | return; | |
157 | } | |
158 | ||
159 | for (mouse = mice_list; mouse; mouse = mouse->next) { | |
160 | monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n", | |
161 | mouse->value->current ? '*' : ' ', | |
162 | mouse->value->index, mouse->value->name, | |
163 | mouse->value->absolute ? " (absolute)" : ""); | |
164 | } | |
165 | ||
166 | qapi_free_MouseInfoList(mice_list); | |
167 | } | |
168 | ||
84f2d0ea | 169 | void hmp_info_migrate(Monitor *mon, const QDict *qdict) |
791e7c82 LC |
170 | { |
171 | MigrationInfo *info; | |
bbf6da32 | 172 | MigrationCapabilityStatusList *caps, *cap; |
791e7c82 LC |
173 | |
174 | info = qmp_query_migrate(NULL); | |
bbf6da32 OW |
175 | caps = qmp_query_migrate_capabilities(NULL); |
176 | ||
9d18af93 PX |
177 | migration_global_dump(mon); |
178 | ||
bbf6da32 OW |
179 | /* do not display parameters during setup */ |
180 | if (info->has_status && caps) { | |
181 | monitor_printf(mon, "capabilities: "); | |
182 | for (cap = caps; cap; cap = cap->next) { | |
183 | monitor_printf(mon, "%s: %s ", | |
977c736f | 184 | MigrationCapability_str(cap->value->capability), |
bbf6da32 OW |
185 | cap->value->state ? "on" : "off"); |
186 | } | |
187 | monitor_printf(mon, "\n"); | |
188 | } | |
791e7c82 LC |
189 | |
190 | if (info->has_status) { | |
d59ce6f3 | 191 | monitor_printf(mon, "Migration status: %s", |
977c736f | 192 | MigrationStatus_str(info->status)); |
d59ce6f3 DB |
193 | if (info->status == MIGRATION_STATUS_FAILED && |
194 | info->has_error_desc) { | |
195 | monitor_printf(mon, " (%s)\n", info->error_desc); | |
196 | } else { | |
197 | monitor_printf(mon, "\n"); | |
198 | } | |
199 | ||
7aa939af JQ |
200 | monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n", |
201 | info->total_time); | |
2c52ddf1 JQ |
202 | if (info->has_expected_downtime) { |
203 | monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n", | |
204 | info->expected_downtime); | |
205 | } | |
9c5a9fcf JQ |
206 | if (info->has_downtime) { |
207 | monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n", | |
208 | info->downtime); | |
209 | } | |
ed4fbd10 MH |
210 | if (info->has_setup_time) { |
211 | monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n", | |
212 | info->setup_time); | |
213 | } | |
791e7c82 LC |
214 | } |
215 | ||
216 | if (info->has_ram) { | |
217 | monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n", | |
218 | info->ram->transferred >> 10); | |
7e114f8c MH |
219 | monitor_printf(mon, "throughput: %0.2f mbps\n", |
220 | info->ram->mbps); | |
791e7c82 LC |
221 | monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n", |
222 | info->ram->remaining >> 10); | |
223 | monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n", | |
224 | info->ram->total >> 10); | |
004d4c10 OW |
225 | monitor_printf(mon, "duplicate: %" PRIu64 " pages\n", |
226 | info->ram->duplicate); | |
f1c72795 PL |
227 | monitor_printf(mon, "skipped: %" PRIu64 " pages\n", |
228 | info->ram->skipped); | |
004d4c10 OW |
229 | monitor_printf(mon, "normal: %" PRIu64 " pages\n", |
230 | info->ram->normal); | |
231 | monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n", | |
232 | info->ram->normal_bytes >> 10); | |
58570ed8 C |
233 | monitor_printf(mon, "dirty sync count: %" PRIu64 "\n", |
234 | info->ram->dirty_sync_count); | |
030ce1f8 CF |
235 | monitor_printf(mon, "page size: %" PRIu64 " kbytes\n", |
236 | info->ram->page_size >> 10); | |
a61c45bd JQ |
237 | monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n", |
238 | info->ram->multifd_bytes >> 10); | |
030ce1f8 | 239 | |
8d017193 JQ |
240 | if (info->ram->dirty_pages_rate) { |
241 | monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n", | |
242 | info->ram->dirty_pages_rate); | |
243 | } | |
d3bf5418 DDAG |
244 | if (info->ram->postcopy_requests) { |
245 | monitor_printf(mon, "postcopy request count: %" PRIu64 "\n", | |
246 | info->ram->postcopy_requests); | |
247 | } | |
791e7c82 LC |
248 | } |
249 | ||
250 | if (info->has_disk) { | |
251 | monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n", | |
252 | info->disk->transferred >> 10); | |
253 | monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n", | |
254 | info->disk->remaining >> 10); | |
255 | monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n", | |
256 | info->disk->total >> 10); | |
257 | } | |
258 | ||
f36d55af OW |
259 | if (info->has_xbzrle_cache) { |
260 | monitor_printf(mon, "cache size: %" PRIu64 " bytes\n", | |
261 | info->xbzrle_cache->cache_size); | |
262 | monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n", | |
263 | info->xbzrle_cache->bytes >> 10); | |
264 | monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n", | |
265 | info->xbzrle_cache->pages); | |
266 | monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n", | |
267 | info->xbzrle_cache->cache_miss); | |
8bc39233 C |
268 | monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n", |
269 | info->xbzrle_cache->cache_miss_rate); | |
f36d55af OW |
270 | monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n", |
271 | info->xbzrle_cache->overflow); | |
272 | } | |
273 | ||
76e03000 XG |
274 | if (info->has_compression) { |
275 | monitor_printf(mon, "compression pages: %" PRIu64 " pages\n", | |
276 | info->compression->pages); | |
277 | monitor_printf(mon, "compression busy: %" PRIu64 "\n", | |
278 | info->compression->busy); | |
279 | monitor_printf(mon, "compression busy rate: %0.2f\n", | |
280 | info->compression->busy_rate); | |
281 | monitor_printf(mon, "compressed size: %" PRIu64 "\n", | |
282 | info->compression->compressed_size); | |
283 | monitor_printf(mon, "compression rate: %0.2f\n", | |
284 | info->compression->compression_rate); | |
285 | } | |
286 | ||
d85a31d1 | 287 | if (info->has_cpu_throttle_percentage) { |
4782893e | 288 | monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n", |
d85a31d1 | 289 | info->cpu_throttle_percentage); |
4782893e JH |
290 | } |
291 | ||
65ace060 AP |
292 | if (info->has_postcopy_blocktime) { |
293 | monitor_printf(mon, "postcopy blocktime: %u\n", | |
294 | info->postcopy_blocktime); | |
295 | } | |
296 | ||
297 | if (info->has_postcopy_vcpu_blocktime) { | |
298 | Visitor *v; | |
299 | char *str; | |
300 | v = string_output_visitor_new(false, &str); | |
301 | visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, NULL); | |
302 | visit_complete(v, &str); | |
303 | monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str); | |
304 | g_free(str); | |
305 | visit_free(v); | |
306 | } | |
791e7c82 | 307 | qapi_free_MigrationInfo(info); |
bbf6da32 OW |
308 | qapi_free_MigrationCapabilityStatusList(caps); |
309 | } | |
310 | ||
84f2d0ea | 311 | void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict) |
bbf6da32 OW |
312 | { |
313 | MigrationCapabilityStatusList *caps, *cap; | |
314 | ||
315 | caps = qmp_query_migrate_capabilities(NULL); | |
316 | ||
317 | if (caps) { | |
bbf6da32 | 318 | for (cap = caps; cap; cap = cap->next) { |
d80a0169 | 319 | monitor_printf(mon, "%s: %s\n", |
977c736f | 320 | MigrationCapability_str(cap->value->capability), |
bbf6da32 OW |
321 | cap->value->state ? "on" : "off"); |
322 | } | |
bbf6da32 OW |
323 | } |
324 | ||
325 | qapi_free_MigrationCapabilityStatusList(caps); | |
791e7c82 LC |
326 | } |
327 | ||
50e9a629 LL |
328 | void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) |
329 | { | |
330 | MigrationParameters *params; | |
331 | ||
332 | params = qmp_query_migrate_parameters(NULL); | |
333 | ||
334 | if (params) { | |
de63ab61 | 335 | assert(params->has_compress_level); |
741d4086 | 336 | monitor_printf(mon, "%s: %u\n", |
977c736f | 337 | MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL), |
50e9a629 | 338 | params->compress_level); |
de63ab61 | 339 | assert(params->has_compress_threads); |
741d4086 | 340 | monitor_printf(mon, "%s: %u\n", |
977c736f | 341 | MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS), |
50e9a629 | 342 | params->compress_threads); |
1d58872a XG |
343 | assert(params->has_compress_wait_thread); |
344 | monitor_printf(mon, "%s: %s\n", | |
345 | MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD), | |
346 | params->compress_wait_thread ? "on" : "off"); | |
de63ab61 | 347 | assert(params->has_decompress_threads); |
741d4086 | 348 | monitor_printf(mon, "%s: %u\n", |
977c736f | 349 | MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS), |
50e9a629 | 350 | params->decompress_threads); |
de63ab61 | 351 | assert(params->has_cpu_throttle_initial); |
741d4086 | 352 | monitor_printf(mon, "%s: %u\n", |
977c736f | 353 | MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL), |
d85a31d1 | 354 | params->cpu_throttle_initial); |
de63ab61 | 355 | assert(params->has_cpu_throttle_increment); |
741d4086 | 356 | monitor_printf(mon, "%s: %u\n", |
977c736f | 357 | MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT), |
d85a31d1 | 358 | params->cpu_throttle_increment); |
4cbc9c7f LQ |
359 | assert(params->has_max_cpu_throttle); |
360 | monitor_printf(mon, "%s: %u\n", | |
361 | MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE), | |
362 | params->max_cpu_throttle); | |
8cc99dcd | 363 | assert(params->has_tls_creds); |
2c02468c | 364 | monitor_printf(mon, "%s: '%s'\n", |
977c736f | 365 | MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS), |
8cc99dcd MA |
366 | params->tls_creds); |
367 | assert(params->has_tls_hostname); | |
2c02468c | 368 | monitor_printf(mon, "%s: '%s'\n", |
977c736f | 369 | MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME), |
8cc99dcd | 370 | params->tls_hostname); |
2ff30257 | 371 | assert(params->has_max_bandwidth); |
741d4086 | 372 | monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n", |
977c736f | 373 | MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH), |
2ff30257 AA |
374 | params->max_bandwidth); |
375 | assert(params->has_downtime_limit); | |
741d4086 | 376 | monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n", |
977c736f | 377 | MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT), |
2ff30257 | 378 | params->downtime_limit); |
fe39a4d4 | 379 | assert(params->has_x_checkpoint_delay); |
741d4086 | 380 | monitor_printf(mon, "%s: %u\n", |
977c736f | 381 | MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY), |
68b53591 | 382 | params->x_checkpoint_delay); |
2833c59b JQ |
383 | assert(params->has_block_incremental); |
384 | monitor_printf(mon, "%s: %s\n", | |
977c736f MA |
385 | MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL), |
386 | params->block_incremental ? "on" : "off"); | |
741d4086 | 387 | monitor_printf(mon, "%s: %u\n", |
4075fb1c JQ |
388 | MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_CHANNELS), |
389 | params->x_multifd_channels); | |
741d4086 | 390 | monitor_printf(mon, "%s: %u\n", |
0fb86605 JQ |
391 | MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT), |
392 | params->x_multifd_page_count); | |
741d4086 | 393 | monitor_printf(mon, "%s: %" PRIu64 "\n", |
73af8dd8 JQ |
394 | MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE), |
395 | params->xbzrle_cache_size); | |
7e555c6c DDAG |
396 | monitor_printf(mon, "%s: %" PRIu64 "\n", |
397 | MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH), | |
398 | params->max_postcopy_bandwidth); | |
50e9a629 LL |
399 | } |
400 | ||
401 | qapi_free_MigrationParameters(params); | |
402 | } | |
403 | ||
84f2d0ea | 404 | void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict) |
9e1ba4cc OW |
405 | { |
406 | monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n", | |
407 | qmp_query_migrate_cache_size(NULL) >> 10); | |
408 | } | |
409 | ||
84f2d0ea | 410 | void hmp_info_cpus(Monitor *mon, const QDict *qdict) |
de0b36b6 | 411 | { |
137b5cb6 | 412 | CpuInfoFastList *cpu_list, *cpu; |
de0b36b6 | 413 | |
137b5cb6 | 414 | cpu_list = qmp_query_cpus_fast(NULL); |
de0b36b6 LC |
415 | |
416 | for (cpu = cpu_list; cpu; cpu = cpu->next) { | |
417 | int active = ' '; | |
418 | ||
137b5cb6 | 419 | if (cpu->value->cpu_index == monitor_get_cpu_index()) { |
de0b36b6 LC |
420 | active = '*'; |
421 | } | |
422 | ||
137b5cb6 VM |
423 | monitor_printf(mon, "%c CPU #%" PRId64 ":", active, |
424 | cpu->value->cpu_index); | |
0dfddbb5 | 425 | monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id); |
de0b36b6 LC |
426 | } |
427 | ||
137b5cb6 | 428 | qapi_free_CpuInfoFastList(cpu_list); |
de0b36b6 LC |
429 | } |
430 | ||
289b276c KW |
431 | static void print_block_info(Monitor *mon, BlockInfo *info, |
432 | BlockDeviceInfo *inserted, bool verbose) | |
b2023818 | 433 | { |
bd093a36 | 434 | ImageInfo *image_info; |
b2023818 | 435 | |
8d6adccd KW |
436 | assert(!info || !info->has_inserted || info->inserted == inserted); |
437 | ||
ec18b0a9 | 438 | if (info && *info->device) { |
8d6adccd KW |
439 | monitor_printf(mon, "%s", info->device); |
440 | if (inserted && inserted->has_node_name) { | |
441 | monitor_printf(mon, " (%s)", inserted->node_name); | |
442 | } | |
443 | } else { | |
ec18b0a9 | 444 | assert(info || inserted); |
8d6adccd | 445 | monitor_printf(mon, "%s", |
ec18b0a9 KW |
446 | inserted && inserted->has_node_name ? inserted->node_name |
447 | : info && info->has_qdev ? info->qdev | |
8d6adccd KW |
448 | : "<anonymous>"); |
449 | } | |
450 | ||
289b276c KW |
451 | if (inserted) { |
452 | monitor_printf(mon, ": %s (%s%s%s)\n", | |
453 | inserted->file, | |
454 | inserted->drv, | |
455 | inserted->ro ? ", read-only" : "", | |
456 | inserted->encrypted ? ", encrypted" : ""); | |
457 | } else { | |
458 | monitor_printf(mon, ": [not inserted]\n"); | |
459 | } | |
b2023818 | 460 | |
8d6adccd | 461 | if (info) { |
46eade7b KW |
462 | if (info->has_qdev) { |
463 | monitor_printf(mon, " Attached to: %s\n", info->qdev); | |
464 | } | |
8d6adccd KW |
465 | if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) { |
466 | monitor_printf(mon, " I/O status: %s\n", | |
977c736f | 467 | BlockDeviceIoStatus_str(info->io_status)); |
8d6adccd | 468 | } |
b2023818 | 469 | |
8d6adccd KW |
470 | if (info->removable) { |
471 | monitor_printf(mon, " Removable device: %slocked, tray %s\n", | |
472 | info->locked ? "" : "not ", | |
473 | info->tray_open ? "open" : "closed"); | |
474 | } | |
289b276c | 475 | } |
fbe2e26c | 476 | |
b2023818 | 477 | |
289b276c KW |
478 | if (!inserted) { |
479 | return; | |
480 | } | |
b2023818 | 481 | |
289b276c KW |
482 | monitor_printf(mon, " Cache mode: %s%s%s\n", |
483 | inserted->cache->writeback ? "writeback" : "writethrough", | |
484 | inserted->cache->direct ? ", direct" : "", | |
485 | inserted->cache->no_flush ? ", ignore flushes" : ""); | |
486 | ||
487 | if (inserted->has_backing_file) { | |
488 | monitor_printf(mon, | |
489 | " Backing file: %s " | |
490 | "(chain depth: %" PRId64 ")\n", | |
491 | inserted->backing_file, | |
492 | inserted->backing_file_depth); | |
493 | } | |
727f005e | 494 | |
289b276c KW |
495 | if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) { |
496 | monitor_printf(mon, " Detect zeroes: %s\n", | |
977c736f | 497 | BlockdevDetectZeroesOptions_str(inserted->detect_zeroes)); |
289b276c | 498 | } |
fbe2e26c | 499 | |
289b276c KW |
500 | if (inserted->bps || inserted->bps_rd || inserted->bps_wr || |
501 | inserted->iops || inserted->iops_rd || inserted->iops_wr) | |
502 | { | |
503 | monitor_printf(mon, " I/O throttling: bps=%" PRId64 | |
504 | " bps_rd=%" PRId64 " bps_wr=%" PRId64 | |
505 | " bps_max=%" PRId64 | |
506 | " bps_rd_max=%" PRId64 | |
507 | " bps_wr_max=%" PRId64 | |
508 | " iops=%" PRId64 " iops_rd=%" PRId64 | |
509 | " iops_wr=%" PRId64 | |
510 | " iops_max=%" PRId64 | |
511 | " iops_rd_max=%" PRId64 | |
512 | " iops_wr_max=%" PRId64 | |
b8fe1694 AG |
513 | " iops_size=%" PRId64 |
514 | " group=%s\n", | |
289b276c KW |
515 | inserted->bps, |
516 | inserted->bps_rd, | |
517 | inserted->bps_wr, | |
518 | inserted->bps_max, | |
519 | inserted->bps_rd_max, | |
520 | inserted->bps_wr_max, | |
521 | inserted->iops, | |
522 | inserted->iops_rd, | |
523 | inserted->iops_wr, | |
524 | inserted->iops_max, | |
525 | inserted->iops_rd_max, | |
526 | inserted->iops_wr_max, | |
b8fe1694 AG |
527 | inserted->iops_size, |
528 | inserted->group); | |
289b276c | 529 | } |
fbe2e26c | 530 | |
9419874f | 531 | if (verbose) { |
289b276c KW |
532 | monitor_printf(mon, "\nImages:\n"); |
533 | image_info = inserted->image; | |
534 | while (1) { | |
535 | bdrv_image_info_dump((fprintf_function)monitor_printf, | |
536 | mon, image_info); | |
537 | if (image_info->has_backing_image) { | |
538 | image_info = image_info->backing_image; | |
539 | } else { | |
540 | break; | |
541 | } | |
542 | } | |
543 | } | |
544 | } | |
9e193c5a | 545 | |
289b276c KW |
546 | void hmp_info_block(Monitor *mon, const QDict *qdict) |
547 | { | |
548 | BlockInfoList *block_list, *info; | |
e6bb31ec | 549 | BlockDeviceInfoList *blockdev_list, *blockdev; |
289b276c | 550 | const char *device = qdict_get_try_str(qdict, "device"); |
34acbc95 EB |
551 | bool verbose = qdict_get_try_bool(qdict, "verbose", false); |
552 | bool nodes = qdict_get_try_bool(qdict, "nodes", false); | |
e6bb31ec | 553 | bool printed = false; |
9e193c5a | 554 | |
e6bb31ec KW |
555 | /* Print BlockBackend information */ |
556 | if (!nodes) { | |
f19e44bc | 557 | block_list = qmp_query_block(NULL); |
e6bb31ec KW |
558 | } else { |
559 | block_list = NULL; | |
560 | } | |
fbe2e26c | 561 | |
289b276c KW |
562 | for (info = block_list; info; info = info->next) { |
563 | if (device && strcmp(device, info->value->device)) { | |
564 | continue; | |
465bee1d PL |
565 | } |
566 | ||
289b276c KW |
567 | if (info != block_list) { |
568 | monitor_printf(mon, "\n"); | |
fbe2e26c | 569 | } |
bd093a36 | 570 | |
289b276c KW |
571 | print_block_info(mon, info->value, info->value->has_inserted |
572 | ? info->value->inserted : NULL, | |
573 | verbose); | |
e6bb31ec | 574 | printed = true; |
b2023818 LC |
575 | } |
576 | ||
577 | qapi_free_BlockInfoList(block_list); | |
e6bb31ec KW |
578 | |
579 | if ((!device && !nodes) || printed) { | |
580 | return; | |
581 | } | |
582 | ||
583 | /* Print node information */ | |
584 | blockdev_list = qmp_query_named_block_nodes(NULL); | |
585 | for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) { | |
586 | assert(blockdev->value->has_node_name); | |
587 | if (device && strcmp(device, blockdev->value->node_name)) { | |
588 | continue; | |
589 | } | |
590 | ||
591 | if (blockdev != blockdev_list) { | |
592 | monitor_printf(mon, "\n"); | |
593 | } | |
594 | ||
595 | print_block_info(mon, NULL, blockdev->value, verbose); | |
596 | } | |
597 | qapi_free_BlockDeviceInfoList(blockdev_list); | |
b2023818 LC |
598 | } |
599 | ||
84f2d0ea | 600 | void hmp_info_blockstats(Monitor *mon, const QDict *qdict) |
f11f57e4 LC |
601 | { |
602 | BlockStatsList *stats_list, *stats; | |
603 | ||
f71eaa74 | 604 | stats_list = qmp_query_blockstats(false, false, NULL); |
f11f57e4 LC |
605 | |
606 | for (stats = stats_list; stats; stats = stats->next) { | |
607 | if (!stats->value->has_device) { | |
608 | continue; | |
609 | } | |
610 | ||
611 | monitor_printf(mon, "%s:", stats->value->device); | |
612 | monitor_printf(mon, " rd_bytes=%" PRId64 | |
613 | " wr_bytes=%" PRId64 | |
614 | " rd_operations=%" PRId64 | |
615 | " wr_operations=%" PRId64 | |
616 | " flush_operations=%" PRId64 | |
617 | " wr_total_time_ns=%" PRId64 | |
618 | " rd_total_time_ns=%" PRId64 | |
619 | " flush_total_time_ns=%" PRId64 | |
f4564d53 PL |
620 | " rd_merged=%" PRId64 |
621 | " wr_merged=%" PRId64 | |
cb38fffb | 622 | " idle_time_ns=%" PRId64 |
f11f57e4 LC |
623 | "\n", |
624 | stats->value->stats->rd_bytes, | |
625 | stats->value->stats->wr_bytes, | |
626 | stats->value->stats->rd_operations, | |
627 | stats->value->stats->wr_operations, | |
628 | stats->value->stats->flush_operations, | |
629 | stats->value->stats->wr_total_time_ns, | |
630 | stats->value->stats->rd_total_time_ns, | |
f4564d53 PL |
631 | stats->value->stats->flush_total_time_ns, |
632 | stats->value->stats->rd_merged, | |
cb38fffb AG |
633 | stats->value->stats->wr_merged, |
634 | stats->value->stats->idle_time_ns); | |
f11f57e4 LC |
635 | } |
636 | ||
637 | qapi_free_BlockStatsList(stats_list); | |
638 | } | |
639 | ||
05eb4a25 | 640 | #ifdef CONFIG_VNC |
0a9667ec DDAG |
641 | /* Helper for hmp_info_vnc_clients, _servers */ |
642 | static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info, | |
643 | const char *name) | |
644 | { | |
645 | monitor_printf(mon, " %s: %s:%s (%s%s)\n", | |
646 | name, | |
647 | info->host, | |
648 | info->service, | |
977c736f | 649 | NetworkAddressFamily_str(info->family), |
0a9667ec DDAG |
650 | info->websocket ? " (Websocket)" : ""); |
651 | } | |
652 | ||
653 | /* Helper displaying and auth and crypt info */ | |
654 | static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent, | |
655 | VncPrimaryAuth auth, | |
656 | VncVencryptSubAuth *vencrypt) | |
657 | { | |
658 | monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent, | |
977c736f MA |
659 | VncPrimaryAuth_str(auth), |
660 | vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none"); | |
0a9667ec DDAG |
661 | } |
662 | ||
663 | static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client) | |
664 | { | |
665 | while (client) { | |
666 | VncClientInfo *cinfo = client->value; | |
667 | ||
668 | hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client"); | |
669 | monitor_printf(mon, " x509_dname: %s\n", | |
670 | cinfo->has_x509_dname ? | |
671 | cinfo->x509_dname : "none"); | |
672 | monitor_printf(mon, " sasl_username: %s\n", | |
673 | cinfo->has_sasl_username ? | |
674 | cinfo->sasl_username : "none"); | |
675 | ||
676 | client = client->next; | |
677 | } | |
678 | } | |
679 | ||
680 | static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server) | |
681 | { | |
682 | while (server) { | |
683 | VncServerInfo2 *sinfo = server->value; | |
684 | hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server"); | |
685 | hmp_info_vnc_authcrypt(mon, " ", sinfo->auth, | |
686 | sinfo->has_vencrypt ? &sinfo->vencrypt : NULL); | |
687 | server = server->next; | |
688 | } | |
689 | } | |
690 | ||
84f2d0ea | 691 | void hmp_info_vnc(Monitor *mon, const QDict *qdict) |
2b54aa87 | 692 | { |
0a9667ec | 693 | VncInfo2List *info2l; |
2b54aa87 | 694 | Error *err = NULL; |
2b54aa87 | 695 | |
0a9667ec | 696 | info2l = qmp_query_vnc_servers(&err); |
2b54aa87 | 697 | if (err) { |
554a39eb | 698 | hmp_handle_error(mon, &err); |
2b54aa87 LC |
699 | return; |
700 | } | |
0a9667ec DDAG |
701 | if (!info2l) { |
702 | monitor_printf(mon, "None\n"); | |
703 | return; | |
2b54aa87 LC |
704 | } |
705 | ||
0a9667ec DDAG |
706 | while (info2l) { |
707 | VncInfo2 *info = info2l->value; | |
708 | monitor_printf(mon, "%s:\n", info->id); | |
709 | hmp_info_vnc_servers(mon, info->server); | |
710 | hmp_info_vnc_clients(mon, info->clients); | |
711 | if (!info->server) { | |
712 | /* The server entry displays its auth, we only | |
713 | * need to display in the case of 'reverse' connections | |
714 | * where there's no server. | |
715 | */ | |
716 | hmp_info_vnc_authcrypt(mon, " ", info->auth, | |
717 | info->has_vencrypt ? &info->vencrypt : NULL); | |
718 | } | |
719 | if (info->has_display) { | |
720 | monitor_printf(mon, " Display: %s\n", info->display); | |
2b54aa87 | 721 | } |
0a9667ec | 722 | info2l = info2l->next; |
2b54aa87 LC |
723 | } |
724 | ||
0a9667ec DDAG |
725 | qapi_free_VncInfo2List(info2l); |
726 | ||
2b54aa87 | 727 | } |
05eb4a25 | 728 | #endif |
2b54aa87 | 729 | |
206addd5 | 730 | #ifdef CONFIG_SPICE |
84f2d0ea | 731 | void hmp_info_spice(Monitor *mon, const QDict *qdict) |
d1f29646 LC |
732 | { |
733 | SpiceChannelList *chan; | |
734 | SpiceInfo *info; | |
22fa7da0 CR |
735 | const char *channel_name; |
736 | const char * const channel_names[] = { | |
737 | [SPICE_CHANNEL_MAIN] = "main", | |
738 | [SPICE_CHANNEL_DISPLAY] = "display", | |
739 | [SPICE_CHANNEL_INPUTS] = "inputs", | |
740 | [SPICE_CHANNEL_CURSOR] = "cursor", | |
741 | [SPICE_CHANNEL_PLAYBACK] = "playback", | |
742 | [SPICE_CHANNEL_RECORD] = "record", | |
743 | [SPICE_CHANNEL_TUNNEL] = "tunnel", | |
744 | [SPICE_CHANNEL_SMARTCARD] = "smartcard", | |
745 | [SPICE_CHANNEL_USBREDIR] = "usbredir", | |
746 | [SPICE_CHANNEL_PORT] = "port", | |
7c6044a9 GH |
747 | #if 0 |
748 | /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7, | |
749 | * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable | |
750 | * as quick fix for build failures with older versions. */ | |
22fa7da0 | 751 | [SPICE_CHANNEL_WEBDAV] = "webdav", |
7c6044a9 | 752 | #endif |
22fa7da0 | 753 | }; |
d1f29646 LC |
754 | |
755 | info = qmp_query_spice(NULL); | |
756 | ||
757 | if (!info->enabled) { | |
758 | monitor_printf(mon, "Server: disabled\n"); | |
759 | goto out; | |
760 | } | |
761 | ||
762 | monitor_printf(mon, "Server:\n"); | |
763 | if (info->has_port) { | |
764 | monitor_printf(mon, " address: %s:%" PRId64 "\n", | |
765 | info->host, info->port); | |
766 | } | |
767 | if (info->has_tls_port) { | |
768 | monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n", | |
769 | info->host, info->tls_port); | |
770 | } | |
61c4efe2 YH |
771 | monitor_printf(mon, " migrated: %s\n", |
772 | info->migrated ? "true" : "false"); | |
d1f29646 LC |
773 | monitor_printf(mon, " auth: %s\n", info->auth); |
774 | monitor_printf(mon, " compiled: %s\n", info->compiled_version); | |
4efee029 | 775 | monitor_printf(mon, " mouse-mode: %s\n", |
977c736f | 776 | SpiceQueryMouseMode_str(info->mouse_mode)); |
d1f29646 LC |
777 | |
778 | if (!info->has_channels || info->channels == NULL) { | |
779 | monitor_printf(mon, "Channels: none\n"); | |
780 | } else { | |
781 | for (chan = info->channels; chan; chan = chan->next) { | |
782 | monitor_printf(mon, "Channel:\n"); | |
783 | monitor_printf(mon, " address: %s:%s%s\n", | |
ddf21908 | 784 | chan->value->host, chan->value->port, |
d1f29646 LC |
785 | chan->value->tls ? " [tls]" : ""); |
786 | monitor_printf(mon, " session: %" PRId64 "\n", | |
787 | chan->value->connection_id); | |
788 | monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n", | |
789 | chan->value->channel_type, chan->value->channel_id); | |
22fa7da0 CR |
790 | |
791 | channel_name = "unknown"; | |
792 | if (chan->value->channel_type > 0 && | |
793 | chan->value->channel_type < ARRAY_SIZE(channel_names) && | |
794 | channel_names[chan->value->channel_type]) { | |
795 | channel_name = channel_names[chan->value->channel_type]; | |
796 | } | |
797 | ||
798 | monitor_printf(mon, " channel name: %s\n", channel_name); | |
d1f29646 LC |
799 | } |
800 | } | |
801 | ||
802 | out: | |
803 | qapi_free_SpiceInfo(info); | |
804 | } | |
206addd5 | 805 | #endif |
d1f29646 | 806 | |
84f2d0ea | 807 | void hmp_info_balloon(Monitor *mon, const QDict *qdict) |
96637bcd LC |
808 | { |
809 | BalloonInfo *info; | |
810 | Error *err = NULL; | |
811 | ||
812 | info = qmp_query_balloon(&err); | |
813 | if (err) { | |
554a39eb | 814 | hmp_handle_error(mon, &err); |
96637bcd LC |
815 | return; |
816 | } | |
817 | ||
01ceb97e | 818 | monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20); |
96637bcd LC |
819 | |
820 | qapi_free_BalloonInfo(info); | |
821 | } | |
822 | ||
79627472 LC |
823 | static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) |
824 | { | |
825 | PciMemoryRegionList *region; | |
826 | ||
827 | monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus); | |
828 | monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n", | |
829 | dev->slot, dev->function); | |
830 | monitor_printf(mon, " "); | |
831 | ||
9fa02cd1 EB |
832 | if (dev->class_info->has_desc) { |
833 | monitor_printf(mon, "%s", dev->class_info->desc); | |
79627472 | 834 | } else { |
9fa02cd1 | 835 | monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class); |
79627472 LC |
836 | } |
837 | ||
838 | monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n", | |
9fa02cd1 | 839 | dev->id->vendor, dev->id->device); |
18613dc6 DL |
840 | if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) { |
841 | monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n", | |
842 | dev->id->subsystem_vendor, dev->id->subsystem); | |
843 | } | |
79627472 LC |
844 | |
845 | if (dev->has_irq) { | |
846 | monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq); | |
847 | } | |
848 | ||
849 | if (dev->has_pci_bridge) { | |
850 | monitor_printf(mon, " BUS %" PRId64 ".\n", | |
9fa02cd1 | 851 | dev->pci_bridge->bus->number); |
79627472 | 852 | monitor_printf(mon, " secondary bus %" PRId64 ".\n", |
9fa02cd1 | 853 | dev->pci_bridge->bus->secondary); |
79627472 | 854 | monitor_printf(mon, " subordinate bus %" PRId64 ".\n", |
9fa02cd1 | 855 | dev->pci_bridge->bus->subordinate); |
79627472 LC |
856 | |
857 | monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n", | |
9fa02cd1 EB |
858 | dev->pci_bridge->bus->io_range->base, |
859 | dev->pci_bridge->bus->io_range->limit); | |
79627472 LC |
860 | |
861 | monitor_printf(mon, | |
862 | " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n", | |
9fa02cd1 EB |
863 | dev->pci_bridge->bus->memory_range->base, |
864 | dev->pci_bridge->bus->memory_range->limit); | |
79627472 LC |
865 | |
866 | monitor_printf(mon, " prefetchable memory range " | |
867 | "[0x%08"PRIx64", 0x%08"PRIx64"]\n", | |
9fa02cd1 EB |
868 | dev->pci_bridge->bus->prefetchable_range->base, |
869 | dev->pci_bridge->bus->prefetchable_range->limit); | |
79627472 LC |
870 | } |
871 | ||
872 | for (region = dev->regions; region; region = region->next) { | |
873 | uint64_t addr, size; | |
874 | ||
875 | addr = region->value->address; | |
876 | size = region->value->size; | |
877 | ||
878 | monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar); | |
879 | ||
880 | if (!strcmp(region->value->type, "io")) { | |
881 | monitor_printf(mon, "I/O at 0x%04" PRIx64 | |
882 | " [0x%04" PRIx64 "].\n", | |
883 | addr, addr + size - 1); | |
884 | } else { | |
885 | monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64 | |
886 | " [0x%08" PRIx64 "].\n", | |
887 | region->value->mem_type_64 ? 64 : 32, | |
888 | region->value->prefetch ? " prefetchable" : "", | |
889 | addr, addr + size - 1); | |
890 | } | |
891 | } | |
892 | ||
893 | monitor_printf(mon, " id \"%s\"\n", dev->qdev_id); | |
894 | ||
895 | if (dev->has_pci_bridge) { | |
896 | if (dev->pci_bridge->has_devices) { | |
897 | PciDeviceInfoList *cdev; | |
898 | for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) { | |
899 | hmp_info_pci_device(mon, cdev->value); | |
900 | } | |
901 | } | |
902 | } | |
903 | } | |
904 | ||
61b97833 HP |
905 | static int hmp_info_irq_foreach(Object *obj, void *opaque) |
906 | { | |
907 | InterruptStatsProvider *intc; | |
908 | InterruptStatsProviderClass *k; | |
909 | Monitor *mon = opaque; | |
910 | ||
911 | if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) { | |
912 | intc = INTERRUPT_STATS_PROVIDER(obj); | |
913 | k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj); | |
914 | uint64_t *irq_counts; | |
915 | unsigned int nb_irqs, i; | |
916 | if (k->get_statistics && | |
917 | k->get_statistics(intc, &irq_counts, &nb_irqs)) { | |
918 | if (nb_irqs > 0) { | |
919 | monitor_printf(mon, "IRQ statistics for %s:\n", | |
920 | object_get_typename(obj)); | |
921 | for (i = 0; i < nb_irqs; i++) { | |
922 | if (irq_counts[i] > 0) { | |
923 | monitor_printf(mon, "%2d: %" PRId64 "\n", i, | |
924 | irq_counts[i]); | |
925 | } | |
926 | } | |
927 | } | |
928 | } else { | |
929 | monitor_printf(mon, "IRQ statistics not available for %s.\n", | |
930 | object_get_typename(obj)); | |
931 | } | |
932 | } | |
933 | ||
934 | return 0; | |
935 | } | |
936 | ||
937 | void hmp_info_irq(Monitor *mon, const QDict *qdict) | |
938 | { | |
939 | object_child_foreach_recursive(object_get_root(), | |
940 | hmp_info_irq_foreach, mon); | |
941 | } | |
942 | ||
943 | static int hmp_info_pic_foreach(Object *obj, void *opaque) | |
944 | { | |
945 | InterruptStatsProvider *intc; | |
946 | InterruptStatsProviderClass *k; | |
947 | Monitor *mon = opaque; | |
948 | ||
949 | if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) { | |
950 | intc = INTERRUPT_STATS_PROVIDER(obj); | |
951 | k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj); | |
952 | if (k->print_info) { | |
953 | k->print_info(intc, mon); | |
954 | } else { | |
955 | monitor_printf(mon, "Interrupt controller information not available for %s.\n", | |
956 | object_get_typename(obj)); | |
957 | } | |
958 | } | |
959 | ||
960 | return 0; | |
961 | } | |
962 | ||
963 | void hmp_info_pic(Monitor *mon, const QDict *qdict) | |
964 | { | |
965 | object_child_foreach_recursive(object_get_root(), | |
966 | hmp_info_pic_foreach, mon); | |
967 | } | |
968 | ||
84f2d0ea | 969 | void hmp_info_pci(Monitor *mon, const QDict *qdict) |
79627472 | 970 | { |
f46cee37 | 971 | PciInfoList *info_list, *info; |
79627472 LC |
972 | Error *err = NULL; |
973 | ||
f46cee37 | 974 | info_list = qmp_query_pci(&err); |
79627472 LC |
975 | if (err) { |
976 | monitor_printf(mon, "PCI devices not supported\n"); | |
977 | error_free(err); | |
978 | return; | |
979 | } | |
980 | ||
f46cee37 | 981 | for (info = info_list; info; info = info->next) { |
79627472 LC |
982 | PciDeviceInfoList *dev; |
983 | ||
984 | for (dev = info->value->devices; dev; dev = dev->next) { | |
985 | hmp_info_pci_device(mon, dev->value); | |
986 | } | |
987 | } | |
988 | ||
f46cee37 | 989 | qapi_free_PciInfoList(info_list); |
79627472 LC |
990 | } |
991 | ||
84f2d0ea | 992 | void hmp_info_block_jobs(Monitor *mon, const QDict *qdict) |
fb5458cd SH |
993 | { |
994 | BlockJobInfoList *list; | |
995 | Error *err = NULL; | |
996 | ||
997 | list = qmp_query_block_jobs(&err); | |
998 | assert(!err); | |
999 | ||
1000 | if (!list) { | |
1001 | monitor_printf(mon, "No active jobs\n"); | |
1002 | return; | |
1003 | } | |
1004 | ||
1005 | while (list) { | |
1006 | if (strcmp(list->value->type, "stream") == 0) { | |
1007 | monitor_printf(mon, "Streaming device %s: Completed %" PRId64 | |
1008 | " of %" PRId64 " bytes, speed limit %" PRId64 | |
1009 | " bytes/s\n", | |
1010 | list->value->device, | |
1011 | list->value->offset, | |
1012 | list->value->len, | |
1013 | list->value->speed); | |
1014 | } else { | |
1015 | monitor_printf(mon, "Type %s, device %s: Completed %" PRId64 | |
1016 | " of %" PRId64 " bytes, speed limit %" PRId64 | |
1017 | " bytes/s\n", | |
1018 | list->value->type, | |
1019 | list->value->device, | |
1020 | list->value->offset, | |
1021 | list->value->len, | |
1022 | list->value->speed); | |
1023 | } | |
1024 | list = list->next; | |
1025 | } | |
93bb1315 GA |
1026 | |
1027 | qapi_free_BlockJobInfoList(list); | |
fb5458cd SH |
1028 | } |
1029 | ||
d1a0cf73 SB |
1030 | void hmp_info_tpm(Monitor *mon, const QDict *qdict) |
1031 | { | |
1032 | TPMInfoList *info_list, *info; | |
1033 | Error *err = NULL; | |
1034 | unsigned int c = 0; | |
1035 | TPMPassthroughOptions *tpo; | |
f4ede81e | 1036 | TPMEmulatorOptions *teo; |
d1a0cf73 SB |
1037 | |
1038 | info_list = qmp_query_tpm(&err); | |
1039 | if (err) { | |
1040 | monitor_printf(mon, "TPM device not supported\n"); | |
1041 | error_free(err); | |
1042 | return; | |
1043 | } | |
1044 | ||
1045 | if (info_list) { | |
1046 | monitor_printf(mon, "TPM device:\n"); | |
1047 | } | |
1048 | ||
1049 | for (info = info_list; info; info = info->next) { | |
1050 | TPMInfo *ti = info->value; | |
1051 | monitor_printf(mon, " tpm%d: model=%s\n", | |
977c736f | 1052 | c, TpmModel_str(ti->model)); |
d1a0cf73 SB |
1053 | |
1054 | monitor_printf(mon, " \\ %s: type=%s", | |
977c736f | 1055 | ti->id, TpmTypeOptionsKind_str(ti->options->type)); |
d1a0cf73 | 1056 | |
ce21131a | 1057 | switch (ti->options->type) { |
88ca7bcf | 1058 | case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH: |
32bafa8f | 1059 | tpo = ti->options->u.passthrough.data; |
d1a0cf73 SB |
1060 | monitor_printf(mon, "%s%s%s%s", |
1061 | tpo->has_path ? ",path=" : "", | |
1062 | tpo->has_path ? tpo->path : "", | |
1063 | tpo->has_cancel_path ? ",cancel-path=" : "", | |
1064 | tpo->has_cancel_path ? tpo->cancel_path : ""); | |
1065 | break; | |
f4ede81e AV |
1066 | case TPM_TYPE_OPTIONS_KIND_EMULATOR: |
1067 | teo = ti->options->u.emulator.data; | |
1068 | monitor_printf(mon, ",chardev=%s", teo->chardev); | |
1069 | break; | |
7fb1cf16 | 1070 | case TPM_TYPE_OPTIONS_KIND__MAX: |
d1a0cf73 SB |
1071 | break; |
1072 | } | |
1073 | monitor_printf(mon, "\n"); | |
1074 | c++; | |
1075 | } | |
1076 | qapi_free_TPMInfoList(info_list); | |
1077 | } | |
1078 | ||
7a7f325e LC |
1079 | void hmp_quit(Monitor *mon, const QDict *qdict) |
1080 | { | |
1081 | monitor_suspend(mon); | |
1082 | qmp_quit(NULL); | |
1083 | } | |
5f158f21 LC |
1084 | |
1085 | void hmp_stop(Monitor *mon, const QDict *qdict) | |
1086 | { | |
1087 | qmp_stop(NULL); | |
1088 | } | |
38d22653 | 1089 | |
dd12e1bb EC |
1090 | void hmp_sync_profile(Monitor *mon, const QDict *qdict) |
1091 | { | |
1092 | const char *op = qdict_get_try_str(qdict, "op"); | |
1093 | ||
1094 | if (op == NULL) { | |
1095 | bool on = qsp_is_enabled(); | |
1096 | ||
1097 | monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off"); | |
1098 | return; | |
1099 | } | |
1100 | if (!strcmp(op, "on")) { | |
1101 | qsp_enable(); | |
1102 | } else if (!strcmp(op, "off")) { | |
1103 | qsp_disable(); | |
1104 | } else if (!strcmp(op, "reset")) { | |
1105 | qsp_reset(); | |
1106 | } else { | |
1107 | Error *err = NULL; | |
1108 | ||
1109 | error_setg(&err, QERR_INVALID_PARAMETER, op); | |
1110 | hmp_handle_error(mon, &err); | |
1111 | } | |
1112 | } | |
1113 | ||
38d22653 LC |
1114 | void hmp_system_reset(Monitor *mon, const QDict *qdict) |
1115 | { | |
1116 | qmp_system_reset(NULL); | |
1117 | } | |
5bc465e4 LC |
1118 | |
1119 | void hmp_system_powerdown(Monitor *mon, const QDict *qdict) | |
1120 | { | |
1121 | qmp_system_powerdown(NULL); | |
1122 | } | |
755f1968 | 1123 | |
8e8581e6 DDAG |
1124 | void hmp_exit_preconfig(Monitor *mon, const QDict *qdict) |
1125 | { | |
1126 | Error *err = NULL; | |
1127 | ||
361ac948 | 1128 | qmp_x_exit_preconfig(&err); |
8e8581e6 DDAG |
1129 | hmp_handle_error(mon, &err); |
1130 | } | |
1131 | ||
755f1968 LC |
1132 | void hmp_cpu(Monitor *mon, const QDict *qdict) |
1133 | { | |
1134 | int64_t cpu_index; | |
1135 | ||
1136 | /* XXX: drop the monitor_set_cpu() usage when all HMP commands that | |
1137 | use it are converted to the QAPI */ | |
1138 | cpu_index = qdict_get_int(qdict, "index"); | |
1139 | if (monitor_set_cpu(cpu_index) < 0) { | |
1140 | monitor_printf(mon, "invalid CPU index\n"); | |
1141 | } | |
1142 | } | |
0cfd6a9a LC |
1143 | |
1144 | void hmp_memsave(Monitor *mon, const QDict *qdict) | |
1145 | { | |
1146 | uint32_t size = qdict_get_int(qdict, "size"); | |
1147 | const char *filename = qdict_get_str(qdict, "filename"); | |
1148 | uint64_t addr = qdict_get_int(qdict, "val"); | |
e940f543 | 1149 | Error *err = NULL; |
854e67fe | 1150 | int cpu_index = monitor_get_cpu_index(); |
0cfd6a9a | 1151 | |
854e67fe TH |
1152 | if (cpu_index < 0) { |
1153 | monitor_printf(mon, "No CPU available\n"); | |
1154 | return; | |
1155 | } | |
1156 | ||
1157 | qmp_memsave(addr, size, filename, true, cpu_index, &err); | |
e940f543 | 1158 | hmp_handle_error(mon, &err); |
0cfd6a9a | 1159 | } |
6d3962bf LC |
1160 | |
1161 | void hmp_pmemsave(Monitor *mon, const QDict *qdict) | |
1162 | { | |
1163 | uint32_t size = qdict_get_int(qdict, "size"); | |
1164 | const char *filename = qdict_get_str(qdict, "filename"); | |
1165 | uint64_t addr = qdict_get_int(qdict, "val"); | |
e940f543 | 1166 | Error *err = NULL; |
6d3962bf | 1167 | |
e940f543 MA |
1168 | qmp_pmemsave(addr, size, filename, &err); |
1169 | hmp_handle_error(mon, &err); | |
1f590cf9 LL |
1170 | } |
1171 | ||
3949e594 | 1172 | void hmp_ringbuf_write(Monitor *mon, const QDict *qdict) |
1f590cf9 | 1173 | { |
1f590cf9 LL |
1174 | const char *chardev = qdict_get_str(qdict, "device"); |
1175 | const char *data = qdict_get_str(qdict, "data"); | |
e940f543 | 1176 | Error *err = NULL; |
1f590cf9 | 1177 | |
e940f543 | 1178 | qmp_ringbuf_write(chardev, data, false, 0, &err); |
1f590cf9 | 1179 | |
e940f543 | 1180 | hmp_handle_error(mon, &err); |
6d3962bf | 1181 | } |
e42e818b | 1182 | |
3949e594 | 1183 | void hmp_ringbuf_read(Monitor *mon, const QDict *qdict) |
49b6d722 LL |
1184 | { |
1185 | uint32_t size = qdict_get_int(qdict, "size"); | |
1186 | const char *chardev = qdict_get_str(qdict, "device"); | |
3ab651fc | 1187 | char *data; |
e940f543 | 1188 | Error *err = NULL; |
543f3412 | 1189 | int i; |
49b6d722 | 1190 | |
e940f543 MA |
1191 | data = qmp_ringbuf_read(chardev, size, false, 0, &err); |
1192 | if (err) { | |
554a39eb | 1193 | hmp_handle_error(mon, &err); |
49b6d722 LL |
1194 | return; |
1195 | } | |
1196 | ||
543f3412 MA |
1197 | for (i = 0; data[i]; i++) { |
1198 | unsigned char ch = data[i]; | |
1199 | ||
1200 | if (ch == '\\') { | |
1201 | monitor_printf(mon, "\\\\"); | |
1202 | } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) { | |
1203 | monitor_printf(mon, "\\u%04X", ch); | |
1204 | } else { | |
1205 | monitor_printf(mon, "%c", ch); | |
1206 | } | |
1207 | ||
1208 | } | |
1209 | monitor_printf(mon, "\n"); | |
3ab651fc | 1210 | g_free(data); |
49b6d722 LL |
1211 | } |
1212 | ||
e42e818b LC |
1213 | void hmp_cont(Monitor *mon, const QDict *qdict) |
1214 | { | |
e940f543 | 1215 | Error *err = NULL; |
e42e818b | 1216 | |
e940f543 MA |
1217 | qmp_cont(&err); |
1218 | hmp_handle_error(mon, &err); | |
e42e818b | 1219 | } |
ab49ab5c | 1220 | |
9b9df25a GH |
1221 | void hmp_system_wakeup(Monitor *mon, const QDict *qdict) |
1222 | { | |
1223 | qmp_system_wakeup(NULL); | |
1224 | } | |
1225 | ||
3e5a50d6 | 1226 | void hmp_nmi(Monitor *mon, const QDict *qdict) |
ab49ab5c | 1227 | { |
e940f543 | 1228 | Error *err = NULL; |
ab49ab5c | 1229 | |
e940f543 MA |
1230 | qmp_inject_nmi(&err); |
1231 | hmp_handle_error(mon, &err); | |
ab49ab5c | 1232 | } |
4b37156c LC |
1233 | |
1234 | void hmp_set_link(Monitor *mon, const QDict *qdict) | |
1235 | { | |
1236 | const char *name = qdict_get_str(qdict, "name"); | |
34acbc95 | 1237 | bool up = qdict_get_bool(qdict, "up"); |
e940f543 | 1238 | Error *err = NULL; |
4b37156c | 1239 | |
e940f543 MA |
1240 | qmp_set_link(name, up, &err); |
1241 | hmp_handle_error(mon, &err); | |
4b37156c | 1242 | } |
a4dea8a9 LC |
1243 | |
1244 | void hmp_block_passwd(Monitor *mon, const QDict *qdict) | |
1245 | { | |
1246 | const char *device = qdict_get_str(qdict, "device"); | |
1247 | const char *password = qdict_get_str(qdict, "password"); | |
e940f543 | 1248 | Error *err = NULL; |
a4dea8a9 | 1249 | |
e940f543 MA |
1250 | qmp_block_passwd(true, device, false, NULL, password, &err); |
1251 | hmp_handle_error(mon, &err); | |
a4dea8a9 | 1252 | } |
d72f3264 LC |
1253 | |
1254 | void hmp_balloon(Monitor *mon, const QDict *qdict) | |
1255 | { | |
1256 | int64_t value = qdict_get_int(qdict, "value"); | |
e940f543 | 1257 | Error *err = NULL; |
d72f3264 | 1258 | |
e940f543 | 1259 | qmp_balloon(value, &err); |
554a39eb | 1260 | hmp_handle_error(mon, &err); |
d72f3264 | 1261 | } |
5e7caacb LC |
1262 | |
1263 | void hmp_block_resize(Monitor *mon, const QDict *qdict) | |
1264 | { | |
1265 | const char *device = qdict_get_str(qdict, "device"); | |
1266 | int64_t size = qdict_get_int(qdict, "size"); | |
e940f543 | 1267 | Error *err = NULL; |
5e7caacb | 1268 | |
e940f543 MA |
1269 | qmp_block_resize(true, device, false, NULL, size, &err); |
1270 | hmp_handle_error(mon, &err); | |
5e7caacb | 1271 | } |
6106e249 | 1272 | |
d9b902db PB |
1273 | void hmp_drive_mirror(Monitor *mon, const QDict *qdict) |
1274 | { | |
d9b902db PB |
1275 | const char *filename = qdict_get_str(qdict, "target"); |
1276 | const char *format = qdict_get_try_str(qdict, "format"); | |
34acbc95 EB |
1277 | bool reuse = qdict_get_try_bool(qdict, "reuse", false); |
1278 | bool full = qdict_get_try_bool(qdict, "full", false); | |
e940f543 | 1279 | Error *err = NULL; |
faecd40a EB |
1280 | DriveMirror mirror = { |
1281 | .device = (char *)qdict_get_str(qdict, "device"), | |
1282 | .target = (char *)filename, | |
1283 | .has_format = !!format, | |
1284 | .format = (char *)format, | |
1285 | .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP, | |
1286 | .has_mode = true, | |
1287 | .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS, | |
1288 | .unmap = true, | |
1289 | }; | |
d9b902db PB |
1290 | |
1291 | if (!filename) { | |
c6bd8c70 | 1292 | error_setg(&err, QERR_MISSING_PARAMETER, "target"); |
e940f543 | 1293 | hmp_handle_error(mon, &err); |
d9b902db PB |
1294 | return; |
1295 | } | |
faecd40a | 1296 | qmp_drive_mirror(&mirror, &err); |
e940f543 | 1297 | hmp_handle_error(mon, &err); |
d9b902db PB |
1298 | } |
1299 | ||
de90930a SH |
1300 | void hmp_drive_backup(Monitor *mon, const QDict *qdict) |
1301 | { | |
1302 | const char *device = qdict_get_str(qdict, "device"); | |
1303 | const char *filename = qdict_get_str(qdict, "target"); | |
1304 | const char *format = qdict_get_try_str(qdict, "format"); | |
34acbc95 EB |
1305 | bool reuse = qdict_get_try_bool(qdict, "reuse", false); |
1306 | bool full = qdict_get_try_bool(qdict, "full", false); | |
13b9414b | 1307 | bool compress = qdict_get_try_bool(qdict, "compress", false); |
e940f543 | 1308 | Error *err = NULL; |
81206a89 PB |
1309 | DriveBackup backup = { |
1310 | .device = (char *)device, | |
1311 | .target = (char *)filename, | |
1312 | .has_format = !!format, | |
1313 | .format = (char *)format, | |
1314 | .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP, | |
1315 | .has_mode = true, | |
1316 | .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS, | |
13b9414b PB |
1317 | .has_compress = !!compress, |
1318 | .compress = compress, | |
81206a89 | 1319 | }; |
de90930a SH |
1320 | |
1321 | if (!filename) { | |
c6bd8c70 | 1322 | error_setg(&err, QERR_MISSING_PARAMETER, "target"); |
e940f543 | 1323 | hmp_handle_error(mon, &err); |
de90930a SH |
1324 | return; |
1325 | } | |
1326 | ||
81206a89 | 1327 | qmp_drive_backup(&backup, &err); |
e940f543 | 1328 | hmp_handle_error(mon, &err); |
de90930a SH |
1329 | } |
1330 | ||
6106e249 LC |
1331 | void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) |
1332 | { | |
1333 | const char *device = qdict_get_str(qdict, "device"); | |
1334 | const char *filename = qdict_get_try_str(qdict, "snapshot-file"); | |
1335 | const char *format = qdict_get_try_str(qdict, "format"); | |
34acbc95 | 1336 | bool reuse = qdict_get_try_bool(qdict, "reuse", false); |
6cc2a415 | 1337 | enum NewImageMode mode; |
e940f543 | 1338 | Error *err = NULL; |
6106e249 LC |
1339 | |
1340 | if (!filename) { | |
1341 | /* In the future, if 'snapshot-file' is not specified, the snapshot | |
1342 | will be taken internally. Today it's actually required. */ | |
c6bd8c70 | 1343 | error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file"); |
e940f543 | 1344 | hmp_handle_error(mon, &err); |
6106e249 LC |
1345 | return; |
1346 | } | |
1347 | ||
6cc2a415 | 1348 | mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS; |
0901f67e BC |
1349 | qmp_blockdev_snapshot_sync(true, device, false, NULL, |
1350 | filename, false, NULL, | |
1351 | !!format, format, | |
e940f543 MA |
1352 | true, mode, &err); |
1353 | hmp_handle_error(mon, &err); | |
6106e249 | 1354 | } |
6cdedb07 | 1355 | |
775ca88e WX |
1356 | void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict) |
1357 | { | |
1358 | const char *device = qdict_get_str(qdict, "device"); | |
1359 | const char *name = qdict_get_str(qdict, "name"); | |
e940f543 | 1360 | Error *err = NULL; |
775ca88e | 1361 | |
e940f543 MA |
1362 | qmp_blockdev_snapshot_internal_sync(device, name, &err); |
1363 | hmp_handle_error(mon, &err); | |
775ca88e WX |
1364 | } |
1365 | ||
7a4ed2ee WX |
1366 | void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict) |
1367 | { | |
1368 | const char *device = qdict_get_str(qdict, "device"); | |
1369 | const char *name = qdict_get_str(qdict, "name"); | |
1370 | const char *id = qdict_get_try_str(qdict, "id"); | |
e940f543 | 1371 | Error *err = NULL; |
7a4ed2ee WX |
1372 | |
1373 | qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id, | |
e940f543 MA |
1374 | true, name, &err); |
1375 | hmp_handle_error(mon, &err); | |
7a4ed2ee WX |
1376 | } |
1377 | ||
52b26205 JQ |
1378 | void hmp_loadvm(Monitor *mon, const QDict *qdict) |
1379 | { | |
1380 | int saved_vm_running = runstate_is_running(); | |
1381 | const char *name = qdict_get_str(qdict, "name"); | |
927d6638 | 1382 | Error *err = NULL; |
52b26205 JQ |
1383 | |
1384 | vm_stop(RUN_STATE_RESTORE_VM); | |
1385 | ||
5e22479a | 1386 | if (load_snapshot(name, &err) == 0 && saved_vm_running) { |
52b26205 JQ |
1387 | vm_start(); |
1388 | } | |
927d6638 | 1389 | hmp_handle_error(mon, &err); |
52b26205 JQ |
1390 | } |
1391 | ||
d9c7d137 JQ |
1392 | void hmp_savevm(Monitor *mon, const QDict *qdict) |
1393 | { | |
927d6638 JQ |
1394 | Error *err = NULL; |
1395 | ||
5e22479a | 1396 | save_snapshot(qdict_get_try_str(qdict, "name"), &err); |
927d6638 | 1397 | hmp_handle_error(mon, &err); |
d9c7d137 JQ |
1398 | } |
1399 | ||
d905bb7b JQ |
1400 | void hmp_delvm(Monitor *mon, const QDict *qdict) |
1401 | { | |
1402 | BlockDriverState *bs; | |
32cd6550 | 1403 | Error *err = NULL; |
d905bb7b JQ |
1404 | const char *name = qdict_get_str(qdict, "name"); |
1405 | ||
1406 | if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) { | |
1407 | error_reportf_err(err, | |
1408 | "Error while deleting snapshot on device '%s': ", | |
1409 | bdrv_get_device_name(bs)); | |
1410 | } | |
1411 | } | |
1412 | ||
66830618 JQ |
1413 | void hmp_info_snapshots(Monitor *mon, const QDict *qdict) |
1414 | { | |
1415 | BlockDriverState *bs, *bs1; | |
1416 | BdrvNextIterator it1; | |
1417 | QEMUSnapshotInfo *sn_tab, *sn; | |
1418 | bool no_snapshot = true; | |
1419 | int nb_sns, i; | |
1420 | int total; | |
1421 | int *global_snapshots; | |
1422 | AioContext *aio_context; | |
1423 | ||
1424 | typedef struct SnapshotEntry { | |
1425 | QEMUSnapshotInfo sn; | |
1426 | QTAILQ_ENTRY(SnapshotEntry) next; | |
1427 | } SnapshotEntry; | |
1428 | ||
1429 | typedef struct ImageEntry { | |
1430 | const char *imagename; | |
1431 | QTAILQ_ENTRY(ImageEntry) next; | |
1432 | QTAILQ_HEAD(, SnapshotEntry) snapshots; | |
1433 | } ImageEntry; | |
1434 | ||
1435 | QTAILQ_HEAD(, ImageEntry) image_list = | |
1436 | QTAILQ_HEAD_INITIALIZER(image_list); | |
1437 | ||
1438 | ImageEntry *image_entry, *next_ie; | |
1439 | SnapshotEntry *snapshot_entry; | |
1440 | ||
1441 | bs = bdrv_all_find_vmstate_bs(); | |
1442 | if (!bs) { | |
1443 | monitor_printf(mon, "No available block device supports snapshots\n"); | |
1444 | return; | |
1445 | } | |
1446 | aio_context = bdrv_get_aio_context(bs); | |
1447 | ||
1448 | aio_context_acquire(aio_context); | |
1449 | nb_sns = bdrv_snapshot_list(bs, &sn_tab); | |
1450 | aio_context_release(aio_context); | |
1451 | ||
1452 | if (nb_sns < 0) { | |
1453 | monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns); | |
1454 | return; | |
1455 | } | |
1456 | ||
1457 | for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) { | |
1458 | int bs1_nb_sns = 0; | |
1459 | ImageEntry *ie; | |
1460 | SnapshotEntry *se; | |
1461 | AioContext *ctx = bdrv_get_aio_context(bs1); | |
1462 | ||
1463 | aio_context_acquire(ctx); | |
1464 | if (bdrv_can_snapshot(bs1)) { | |
1465 | sn = NULL; | |
1466 | bs1_nb_sns = bdrv_snapshot_list(bs1, &sn); | |
1467 | if (bs1_nb_sns > 0) { | |
1468 | no_snapshot = false; | |
1469 | ie = g_new0(ImageEntry, 1); | |
1470 | ie->imagename = bdrv_get_device_name(bs1); | |
1471 | QTAILQ_INIT(&ie->snapshots); | |
1472 | QTAILQ_INSERT_TAIL(&image_list, ie, next); | |
1473 | for (i = 0; i < bs1_nb_sns; i++) { | |
1474 | se = g_new0(SnapshotEntry, 1); | |
1475 | se->sn = sn[i]; | |
1476 | QTAILQ_INSERT_TAIL(&ie->snapshots, se, next); | |
1477 | } | |
1478 | } | |
1479 | g_free(sn); | |
1480 | } | |
1481 | aio_context_release(ctx); | |
1482 | } | |
1483 | ||
1484 | if (no_snapshot) { | |
1485 | monitor_printf(mon, "There is no snapshot available.\n"); | |
1486 | return; | |
1487 | } | |
1488 | ||
1489 | global_snapshots = g_new0(int, nb_sns); | |
1490 | total = 0; | |
1491 | for (i = 0; i < nb_sns; i++) { | |
1492 | SnapshotEntry *next_sn; | |
1493 | if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) { | |
1494 | global_snapshots[total] = i; | |
1495 | total++; | |
1496 | QTAILQ_FOREACH(image_entry, &image_list, next) { | |
1497 | QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, | |
1498 | next, next_sn) { | |
1499 | if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) { | |
1500 | QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry, | |
1501 | next); | |
1502 | g_free(snapshot_entry); | |
1503 | } | |
1504 | } | |
1505 | } | |
1506 | } | |
1507 | } | |
1508 | ||
1509 | monitor_printf(mon, "List of snapshots present on all disks:\n"); | |
1510 | ||
1511 | if (total > 0) { | |
1512 | bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL); | |
1513 | monitor_printf(mon, "\n"); | |
1514 | for (i = 0; i < total; i++) { | |
1515 | sn = &sn_tab[global_snapshots[i]]; | |
1516 | /* The ID is not guaranteed to be the same on all images, so | |
1517 | * overwrite it. | |
1518 | */ | |
1519 | pstrcpy(sn->id_str, sizeof(sn->id_str), "--"); | |
1520 | bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, sn); | |
1521 | monitor_printf(mon, "\n"); | |
1522 | } | |
1523 | } else { | |
1524 | monitor_printf(mon, "None\n"); | |
1525 | } | |
1526 | ||
1527 | QTAILQ_FOREACH(image_entry, &image_list, next) { | |
1528 | if (QTAILQ_EMPTY(&image_entry->snapshots)) { | |
1529 | continue; | |
1530 | } | |
1531 | monitor_printf(mon, | |
1532 | "\nList of partial (non-loadable) snapshots on '%s':\n", | |
1533 | image_entry->imagename); | |
1534 | bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL); | |
1535 | monitor_printf(mon, "\n"); | |
1536 | QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) { | |
1537 | bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, | |
1538 | &snapshot_entry->sn); | |
1539 | monitor_printf(mon, "\n"); | |
1540 | } | |
1541 | } | |
1542 | ||
1543 | QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) { | |
1544 | SnapshotEntry *next_sn; | |
1545 | QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next, | |
1546 | next_sn) { | |
1547 | g_free(snapshot_entry); | |
1548 | } | |
1549 | g_free(image_entry); | |
1550 | } | |
1551 | g_free(sn_tab); | |
1552 | g_free(global_snapshots); | |
1553 | ||
1554 | } | |
1555 | ||
6cdedb07 LC |
1556 | void hmp_migrate_cancel(Monitor *mon, const QDict *qdict) |
1557 | { | |
1558 | qmp_migrate_cancel(NULL); | |
1559 | } | |
4f0a993b | 1560 | |
94ae12cb DDAG |
1561 | void hmp_migrate_continue(Monitor *mon, const QDict *qdict) |
1562 | { | |
1563 | Error *err = NULL; | |
1564 | const char *state = qdict_get_str(qdict, "state"); | |
1565 | int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err); | |
1566 | ||
1567 | if (val >= 0) { | |
1568 | qmp_migrate_continue(val, &err); | |
1569 | } | |
1570 | ||
1571 | hmp_handle_error(mon, &err); | |
1572 | } | |
1573 | ||
bf1ae1f4 DDAG |
1574 | void hmp_migrate_incoming(Monitor *mon, const QDict *qdict) |
1575 | { | |
1576 | Error *err = NULL; | |
1577 | const char *uri = qdict_get_str(qdict, "uri"); | |
1578 | ||
1579 | qmp_migrate_incoming(uri, &err); | |
1580 | ||
1fa57f55 | 1581 | hmp_handle_error(mon, &err); |
bf1ae1f4 DDAG |
1582 | } |
1583 | ||
3b563c4b PX |
1584 | void hmp_migrate_recover(Monitor *mon, const QDict *qdict) |
1585 | { | |
1586 | Error *err = NULL; | |
1587 | const char *uri = qdict_get_str(qdict, "uri"); | |
1588 | ||
1589 | qmp_migrate_recover(uri, &err); | |
1590 | ||
1591 | hmp_handle_error(mon, &err); | |
1592 | } | |
1593 | ||
d37297dc PX |
1594 | void hmp_migrate_pause(Monitor *mon, const QDict *qdict) |
1595 | { | |
1596 | Error *err = NULL; | |
1597 | ||
1598 | qmp_migrate_pause(&err); | |
1599 | ||
1600 | hmp_handle_error(mon, &err); | |
1601 | } | |
1602 | ||
2ff30257 | 1603 | /* Kept for backwards compatibility */ |
4f0a993b LC |
1604 | void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict) |
1605 | { | |
1606 | double value = qdict_get_double(qdict, "value"); | |
1607 | qmp_migrate_set_downtime(value, NULL); | |
1608 | } | |
3dc85383 | 1609 | |
9e1ba4cc OW |
1610 | void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict) |
1611 | { | |
1612 | int64_t value = qdict_get_int(qdict, "value"); | |
1613 | Error *err = NULL; | |
1614 | ||
1615 | qmp_migrate_set_cache_size(value, &err); | |
554a39eb | 1616 | hmp_handle_error(mon, &err); |
9e1ba4cc OW |
1617 | } |
1618 | ||
2ff30257 | 1619 | /* Kept for backwards compatibility */ |
3dc85383 LC |
1620 | void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict) |
1621 | { | |
1622 | int64_t value = qdict_get_int(qdict, "value"); | |
1623 | qmp_migrate_set_speed(value, NULL); | |
1624 | } | |
fbf796fd | 1625 | |
00458433 OW |
1626 | void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict) |
1627 | { | |
1628 | const char *cap = qdict_get_str(qdict, "capability"); | |
1629 | bool state = qdict_get_bool(qdict, "state"); | |
1630 | Error *err = NULL; | |
1631 | MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps)); | |
8e615e34 | 1632 | int val; |
00458433 | 1633 | |
f7abe0ec | 1634 | val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err); |
8e615e34 MAL |
1635 | if (val < 0) { |
1636 | goto end; | |
00458433 OW |
1637 | } |
1638 | ||
8e615e34 MAL |
1639 | caps->value = g_malloc0(sizeof(*caps->value)); |
1640 | caps->value->capability = val; | |
1641 | caps->value->state = state; | |
1642 | caps->next = NULL; | |
1643 | qmp_migrate_set_capabilities(caps, &err); | |
00458433 | 1644 | |
8e615e34 | 1645 | end: |
00458433 | 1646 | qapi_free_MigrationCapabilityStatusList(caps); |
554a39eb | 1647 | hmp_handle_error(mon, &err); |
00458433 OW |
1648 | } |
1649 | ||
50e9a629 LL |
1650 | void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) |
1651 | { | |
1652 | const char *param = qdict_get_str(qdict, "parameter"); | |
69ef1f36 | 1653 | const char *valuestr = qdict_get_str(qdict, "value"); |
f4a06d13 | 1654 | Visitor *v = string_input_visitor_new(valuestr); |
1bda8b3c | 1655 | MigrateSetParameters *p = g_new0(MigrateSetParameters, 1); |
f46bfdbf | 1656 | uint64_t valuebw = 0; |
73af8dd8 | 1657 | uint64_t cache_size; |
50e9a629 | 1658 | Error *err = NULL; |
262517b7 | 1659 | int val, ret; |
69ef1f36 | 1660 | |
f7abe0ec | 1661 | val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err); |
262517b7 MAL |
1662 | if (val < 0) { |
1663 | goto cleanup; | |
1664 | } | |
1665 | ||
1666 | switch (val) { | |
1667 | case MIGRATION_PARAMETER_COMPRESS_LEVEL: | |
1668 | p->has_compress_level = true; | |
1669 | visit_type_int(v, param, &p->compress_level, &err); | |
1670 | break; | |
1671 | case MIGRATION_PARAMETER_COMPRESS_THREADS: | |
1672 | p->has_compress_threads = true; | |
1673 | visit_type_int(v, param, &p->compress_threads, &err); | |
1674 | break; | |
1d58872a XG |
1675 | case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD: |
1676 | p->has_compress_wait_thread = true; | |
1677 | visit_type_bool(v, param, &p->compress_wait_thread, &err); | |
1678 | break; | |
262517b7 MAL |
1679 | case MIGRATION_PARAMETER_DECOMPRESS_THREADS: |
1680 | p->has_decompress_threads = true; | |
1681 | visit_type_int(v, param, &p->decompress_threads, &err); | |
1682 | break; | |
1683 | case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL: | |
1684 | p->has_cpu_throttle_initial = true; | |
1685 | visit_type_int(v, param, &p->cpu_throttle_initial, &err); | |
1686 | break; | |
1687 | case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT: | |
1688 | p->has_cpu_throttle_increment = true; | |
1689 | visit_type_int(v, param, &p->cpu_throttle_increment, &err); | |
1690 | break; | |
4cbc9c7f LQ |
1691 | case MIGRATION_PARAMETER_MAX_CPU_THROTTLE: |
1692 | p->has_max_cpu_throttle = true; | |
1693 | visit_type_int(v, param, &p->max_cpu_throttle, &err); | |
1694 | break; | |
262517b7 MAL |
1695 | case MIGRATION_PARAMETER_TLS_CREDS: |
1696 | p->has_tls_creds = true; | |
1697 | p->tls_creds = g_new0(StrOrNull, 1); | |
1698 | p->tls_creds->type = QTYPE_QSTRING; | |
1699 | visit_type_str(v, param, &p->tls_creds->u.s, &err); | |
1700 | break; | |
1701 | case MIGRATION_PARAMETER_TLS_HOSTNAME: | |
1702 | p->has_tls_hostname = true; | |
1703 | p->tls_hostname = g_new0(StrOrNull, 1); | |
1704 | p->tls_hostname->type = QTYPE_QSTRING; | |
1705 | visit_type_str(v, param, &p->tls_hostname->u.s, &err); | |
1706 | break; | |
1707 | case MIGRATION_PARAMETER_MAX_BANDWIDTH: | |
1708 | p->has_max_bandwidth = true; | |
1709 | /* | |
1710 | * Can't use visit_type_size() here, because it | |
1711 | * defaults to Bytes rather than Mebibytes. | |
1712 | */ | |
1713 | ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw); | |
1714 | if (ret < 0 || valuebw > INT64_MAX | |
1715 | || (size_t)valuebw != valuebw) { | |
1716 | error_setg(&err, "Invalid size %s", valuestr); | |
50e9a629 LL |
1717 | break; |
1718 | } | |
262517b7 MAL |
1719 | p->max_bandwidth = valuebw; |
1720 | break; | |
1721 | case MIGRATION_PARAMETER_DOWNTIME_LIMIT: | |
1722 | p->has_downtime_limit = true; | |
1723 | visit_type_int(v, param, &p->downtime_limit, &err); | |
1724 | break; | |
1725 | case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY: | |
1726 | p->has_x_checkpoint_delay = true; | |
1727 | visit_type_int(v, param, &p->x_checkpoint_delay, &err); | |
1728 | break; | |
1729 | case MIGRATION_PARAMETER_BLOCK_INCREMENTAL: | |
1730 | p->has_block_incremental = true; | |
1731 | visit_type_bool(v, param, &p->block_incremental, &err); | |
1732 | break; | |
4075fb1c JQ |
1733 | case MIGRATION_PARAMETER_X_MULTIFD_CHANNELS: |
1734 | p->has_x_multifd_channels = true; | |
1735 | visit_type_int(v, param, &p->x_multifd_channels, &err); | |
1736 | break; | |
0fb86605 JQ |
1737 | case MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT: |
1738 | p->has_x_multifd_page_count = true; | |
1739 | visit_type_int(v, param, &p->x_multifd_page_count, &err); | |
1740 | break; | |
73af8dd8 JQ |
1741 | case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE: |
1742 | p->has_xbzrle_cache_size = true; | |
1743 | visit_type_size(v, param, &cache_size, &err); | |
1744 | if (err || cache_size > INT64_MAX | |
1745 | || (size_t)cache_size != cache_size) { | |
1746 | error_setg(&err, "Invalid size %s", valuestr); | |
1747 | break; | |
1748 | } | |
1749 | p->xbzrle_cache_size = cache_size; | |
1750 | break; | |
7e555c6c DDAG |
1751 | case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH: |
1752 | p->has_max_postcopy_bandwidth = true; | |
1753 | visit_type_size(v, param, &p->max_postcopy_bandwidth, &err); | |
1754 | break; | |
262517b7 MAL |
1755 | default: |
1756 | assert(0); | |
50e9a629 LL |
1757 | } |
1758 | ||
262517b7 MAL |
1759 | if (err) { |
1760 | goto cleanup; | |
50e9a629 LL |
1761 | } |
1762 | ||
262517b7 MAL |
1763 | qmp_migrate_set_parameters(p, &err); |
1764 | ||
69ef1f36 | 1765 | cleanup: |
1bda8b3c | 1766 | qapi_free_MigrateSetParameters(p); |
f4a06d13 | 1767 | visit_free(v); |
554a39eb | 1768 | hmp_handle_error(mon, &err); |
50e9a629 LL |
1769 | } |
1770 | ||
b8a185bc MA |
1771 | void hmp_client_migrate_info(Monitor *mon, const QDict *qdict) |
1772 | { | |
1773 | Error *err = NULL; | |
1774 | const char *protocol = qdict_get_str(qdict, "protocol"); | |
1775 | const char *hostname = qdict_get_str(qdict, "hostname"); | |
1776 | bool has_port = qdict_haskey(qdict, "port"); | |
1777 | int port = qdict_get_try_int(qdict, "port", -1); | |
1778 | bool has_tls_port = qdict_haskey(qdict, "tls-port"); | |
1779 | int tls_port = qdict_get_try_int(qdict, "tls-port", -1); | |
1780 | const char *cert_subject = qdict_get_try_str(qdict, "cert-subject"); | |
1781 | ||
1782 | qmp_client_migrate_info(protocol, hostname, | |
1783 | has_port, port, has_tls_port, tls_port, | |
1784 | !!cert_subject, cert_subject, &err); | |
1785 | hmp_handle_error(mon, &err); | |
1786 | } | |
1787 | ||
4886a1bc DDAG |
1788 | void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict) |
1789 | { | |
1790 | Error *err = NULL; | |
1791 | qmp_migrate_start_postcopy(&err); | |
1792 | hmp_handle_error(mon, &err); | |
1793 | } | |
1794 | ||
d89e666e HZ |
1795 | void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict) |
1796 | { | |
1797 | Error *err = NULL; | |
1798 | ||
1799 | qmp_x_colo_lost_heartbeat(&err); | |
1800 | hmp_handle_error(mon, &err); | |
1801 | } | |
1802 | ||
fbf796fd LC |
1803 | void hmp_set_password(Monitor *mon, const QDict *qdict) |
1804 | { | |
1805 | const char *protocol = qdict_get_str(qdict, "protocol"); | |
1806 | const char *password = qdict_get_str(qdict, "password"); | |
1807 | const char *connected = qdict_get_try_str(qdict, "connected"); | |
1808 | Error *err = NULL; | |
1809 | ||
1810 | qmp_set_password(protocol, password, !!connected, connected, &err); | |
1811 | hmp_handle_error(mon, &err); | |
1812 | } | |
9ad5372d LC |
1813 | |
1814 | void hmp_expire_password(Monitor *mon, const QDict *qdict) | |
1815 | { | |
1816 | const char *protocol = qdict_get_str(qdict, "protocol"); | |
1817 | const char *whenstr = qdict_get_str(qdict, "time"); | |
1818 | Error *err = NULL; | |
1819 | ||
1820 | qmp_expire_password(protocol, whenstr, &err); | |
1821 | hmp_handle_error(mon, &err); | |
1822 | } | |
c245b6a3 LC |
1823 | |
1824 | void hmp_eject(Monitor *mon, const QDict *qdict) | |
1825 | { | |
34acbc95 | 1826 | bool force = qdict_get_try_bool(qdict, "force", false); |
c245b6a3 LC |
1827 | const char *device = qdict_get_str(qdict, "device"); |
1828 | Error *err = NULL; | |
1829 | ||
fbe2d816 | 1830 | qmp_eject(true, device, false, NULL, true, force, &err); |
c245b6a3 LC |
1831 | hmp_handle_error(mon, &err); |
1832 | } | |
333a96ec | 1833 | |
05eb4a25 | 1834 | #ifdef CONFIG_VNC |
c60bf339 SH |
1835 | static void hmp_change_read_arg(void *opaque, const char *password, |
1836 | void *readline_opaque) | |
333a96ec LC |
1837 | { |
1838 | qmp_change_vnc_password(password, NULL); | |
c60bf339 | 1839 | monitor_read_command(opaque, 1); |
333a96ec | 1840 | } |
05eb4a25 | 1841 | #endif |
333a96ec | 1842 | |
333a96ec LC |
1843 | void hmp_change(Monitor *mon, const QDict *qdict) |
1844 | { | |
1845 | const char *device = qdict_get_str(qdict, "device"); | |
1846 | const char *target = qdict_get_str(qdict, "target"); | |
1847 | const char *arg = qdict_get_try_str(qdict, "arg"); | |
baead0ab HR |
1848 | const char *read_only = qdict_get_try_str(qdict, "read-only-mode"); |
1849 | BlockdevChangeReadOnlyMode read_only_mode = 0; | |
333a96ec LC |
1850 | Error *err = NULL; |
1851 | ||
05eb4a25 | 1852 | #ifdef CONFIG_VNC |
10686749 | 1853 | if (strcmp(device, "vnc") == 0) { |
baead0ab HR |
1854 | if (read_only) { |
1855 | monitor_printf(mon, | |
1856 | "Parameter 'read-only-mode' is invalid for VNC\n"); | |
1857 | return; | |
1858 | } | |
10686749 HR |
1859 | if (strcmp(target, "passwd") == 0 || |
1860 | strcmp(target, "password") == 0) { | |
1861 | if (!arg) { | |
1862 | monitor_read_password(mon, hmp_change_read_arg, NULL); | |
1863 | return; | |
1864 | } | |
1865 | } | |
1866 | qmp_change("vnc", target, !!arg, arg, &err); | |
05eb4a25 MAL |
1867 | } else |
1868 | #endif | |
1869 | { | |
baead0ab HR |
1870 | if (read_only) { |
1871 | read_only_mode = | |
f7abe0ec | 1872 | qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup, |
06c60b6c | 1873 | read_only, |
baead0ab HR |
1874 | BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err); |
1875 | if (err) { | |
1876 | hmp_handle_error(mon, &err); | |
1877 | return; | |
1878 | } | |
1879 | } | |
1880 | ||
70e2cb3b KW |
1881 | qmp_blockdev_change_medium(true, device, false, NULL, target, |
1882 | !!arg, arg, !!read_only, read_only_mode, | |
1883 | &err); | |
333a96ec LC |
1884 | } |
1885 | ||
333a96ec LC |
1886 | hmp_handle_error(mon, &err); |
1887 | } | |
80047da5 LC |
1888 | |
1889 | void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) | |
1890 | { | |
1891 | Error *err = NULL; | |
83592184 | 1892 | char *device = (char *) qdict_get_str(qdict, "device"); |
4dc9397b | 1893 | BlockIOThrottle throttle = { |
4dc9397b EB |
1894 | .bps = qdict_get_int(qdict, "bps"), |
1895 | .bps_rd = qdict_get_int(qdict, "bps_rd"), | |
1896 | .bps_wr = qdict_get_int(qdict, "bps_wr"), | |
1897 | .iops = qdict_get_int(qdict, "iops"), | |
1898 | .iops_rd = qdict_get_int(qdict, "iops_rd"), | |
1899 | .iops_wr = qdict_get_int(qdict, "iops_wr"), | |
1900 | }; | |
80047da5 | 1901 | |
83592184 AG |
1902 | /* qmp_block_set_io_throttle has separate parameters for the |
1903 | * (deprecated) block device name and the qdev ID but the HMP | |
1904 | * version has only one, so we must decide which one to pass. */ | |
1905 | if (blk_by_name(device)) { | |
1906 | throttle.has_device = true; | |
1907 | throttle.device = device; | |
1908 | } else { | |
1909 | throttle.has_id = true; | |
1910 | throttle.id = device; | |
1911 | } | |
1912 | ||
4dc9397b | 1913 | qmp_block_set_io_throttle(&throttle, &err); |
80047da5 LC |
1914 | hmp_handle_error(mon, &err); |
1915 | } | |
12bd451f SH |
1916 | |
1917 | void hmp_block_stream(Monitor *mon, const QDict *qdict) | |
1918 | { | |
1919 | Error *error = NULL; | |
1920 | const char *device = qdict_get_str(qdict, "device"); | |
1921 | const char *base = qdict_get_try_str(qdict, "base"); | |
c83c66c3 | 1922 | int64_t speed = qdict_get_try_int(qdict, "speed", 0); |
12bd451f | 1923 | |
11d6fbe0 | 1924 | qmp_block_stream(true, device, device, base != NULL, base, false, NULL, |
241ca1ab JS |
1925 | false, NULL, qdict_haskey(qdict, "speed"), speed, true, |
1926 | BLOCKDEV_ON_ERROR_REPORT, false, false, false, false, | |
1927 | &error); | |
12bd451f SH |
1928 | |
1929 | hmp_handle_error(mon, &error); | |
1930 | } | |
2d47c6e9 SH |
1931 | |
1932 | void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict) | |
1933 | { | |
1934 | Error *error = NULL; | |
1935 | const char *device = qdict_get_str(qdict, "device"); | |
c6db2395 | 1936 | int64_t value = qdict_get_int(qdict, "speed"); |
2d47c6e9 SH |
1937 | |
1938 | qmp_block_job_set_speed(device, value, &error); | |
1939 | ||
1940 | hmp_handle_error(mon, &error); | |
1941 | } | |
370521a1 SH |
1942 | |
1943 | void hmp_block_job_cancel(Monitor *mon, const QDict *qdict) | |
1944 | { | |
1945 | Error *error = NULL; | |
1946 | const char *device = qdict_get_str(qdict, "device"); | |
34acbc95 | 1947 | bool force = qdict_get_try_bool(qdict, "force", false); |
370521a1 | 1948 | |
6e37fb81 PB |
1949 | qmp_block_job_cancel(device, true, force, &error); |
1950 | ||
1951 | hmp_handle_error(mon, &error); | |
1952 | } | |
1953 | ||
1954 | void hmp_block_job_pause(Monitor *mon, const QDict *qdict) | |
1955 | { | |
1956 | Error *error = NULL; | |
1957 | const char *device = qdict_get_str(qdict, "device"); | |
1958 | ||
1959 | qmp_block_job_pause(device, &error); | |
1960 | ||
1961 | hmp_handle_error(mon, &error); | |
1962 | } | |
1963 | ||
1964 | void hmp_block_job_resume(Monitor *mon, const QDict *qdict) | |
1965 | { | |
1966 | Error *error = NULL; | |
1967 | const char *device = qdict_get_str(qdict, "device"); | |
1968 | ||
1969 | qmp_block_job_resume(device, &error); | |
370521a1 SH |
1970 | |
1971 | hmp_handle_error(mon, &error); | |
1972 | } | |
e1c37d0e | 1973 | |
aeae883b PB |
1974 | void hmp_block_job_complete(Monitor *mon, const QDict *qdict) |
1975 | { | |
1976 | Error *error = NULL; | |
1977 | const char *device = qdict_get_str(qdict, "device"); | |
1978 | ||
1979 | qmp_block_job_complete(device, &error); | |
1980 | ||
1981 | hmp_handle_error(mon, &error); | |
1982 | } | |
1983 | ||
e49f35bd | 1984 | typedef struct HMPMigrationStatus |
e1c37d0e LC |
1985 | { |
1986 | QEMUTimer *timer; | |
1987 | Monitor *mon; | |
1988 | bool is_block_migration; | |
e49f35bd | 1989 | } HMPMigrationStatus; |
e1c37d0e LC |
1990 | |
1991 | static void hmp_migrate_status_cb(void *opaque) | |
1992 | { | |
e49f35bd | 1993 | HMPMigrationStatus *status = opaque; |
e1c37d0e LC |
1994 | MigrationInfo *info; |
1995 | ||
1996 | info = qmp_query_migrate(NULL); | |
24b8c39b HZ |
1997 | if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE || |
1998 | info->status == MIGRATION_STATUS_SETUP) { | |
e1c37d0e LC |
1999 | if (info->has_disk) { |
2000 | int progress; | |
2001 | ||
2002 | if (info->disk->remaining) { | |
2003 | progress = info->disk->transferred * 100 / info->disk->total; | |
2004 | } else { | |
2005 | progress = 100; | |
2006 | } | |
2007 | ||
2008 | monitor_printf(status->mon, "Completed %d %%\r", progress); | |
2009 | monitor_flush(status->mon); | |
2010 | } | |
2011 | ||
bc72ad67 | 2012 | timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000); |
e1c37d0e LC |
2013 | } else { |
2014 | if (status->is_block_migration) { | |
2015 | monitor_printf(status->mon, "\n"); | |
2016 | } | |
d59ce6f3 DB |
2017 | if (info->has_error_desc) { |
2018 | error_report("%s", info->error_desc); | |
2019 | } | |
e1c37d0e | 2020 | monitor_resume(status->mon); |
bc72ad67 | 2021 | timer_del(status->timer); |
d34a10af | 2022 | timer_free(status->timer); |
e1c37d0e LC |
2023 | g_free(status); |
2024 | } | |
2025 | ||
2026 | qapi_free_MigrationInfo(info); | |
2027 | } | |
2028 | ||
2029 | void hmp_migrate(Monitor *mon, const QDict *qdict) | |
2030 | { | |
34acbc95 EB |
2031 | bool detach = qdict_get_try_bool(qdict, "detach", false); |
2032 | bool blk = qdict_get_try_bool(qdict, "blk", false); | |
2033 | bool inc = qdict_get_try_bool(qdict, "inc", false); | |
7a4da28b | 2034 | bool resume = qdict_get_try_bool(qdict, "resume", false); |
e1c37d0e LC |
2035 | const char *uri = qdict_get_str(qdict, "uri"); |
2036 | Error *err = NULL; | |
2037 | ||
7a4da28b PX |
2038 | qmp_migrate(uri, !!blk, blk, !!inc, inc, |
2039 | false, false, true, resume, &err); | |
e1c37d0e | 2040 | if (err) { |
554a39eb | 2041 | hmp_handle_error(mon, &err); |
e1c37d0e LC |
2042 | return; |
2043 | } | |
2044 | ||
2045 | if (!detach) { | |
e49f35bd | 2046 | HMPMigrationStatus *status; |
e1c37d0e LC |
2047 | |
2048 | if (monitor_suspend(mon) < 0) { | |
2049 | monitor_printf(mon, "terminal does not allow synchronous " | |
2050 | "migration, continuing detached\n"); | |
2051 | return; | |
2052 | } | |
2053 | ||
2054 | status = g_malloc0(sizeof(*status)); | |
2055 | status->mon = mon; | |
2056 | status->is_block_migration = blk || inc; | |
bc72ad67 | 2057 | status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb, |
e1c37d0e | 2058 | status); |
bc72ad67 | 2059 | timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME)); |
e1c37d0e LC |
2060 | } |
2061 | } | |
a15fef21 | 2062 | |
318660f8 MA |
2063 | void hmp_device_add(Monitor *mon, const QDict *qdict) |
2064 | { | |
485febc6 MA |
2065 | Error *err = NULL; |
2066 | ||
2067 | qmp_device_add((QDict *)qdict, NULL, &err); | |
2068 | hmp_handle_error(mon, &err); | |
318660f8 MA |
2069 | } |
2070 | ||
a15fef21 LC |
2071 | void hmp_device_del(Monitor *mon, const QDict *qdict) |
2072 | { | |
2073 | const char *id = qdict_get_str(qdict, "id"); | |
2074 | Error *err = NULL; | |
2075 | ||
2076 | qmp_device_del(id, &err); | |
2077 | hmp_handle_error(mon, &err); | |
2078 | } | |
783e9b48 WC |
2079 | |
2080 | void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) | |
2081 | { | |
e940f543 | 2082 | Error *err = NULL; |
2da91b54 | 2083 | bool win_dmp = qdict_get_try_bool(qdict, "windmp", false); |
34acbc95 EB |
2084 | bool paging = qdict_get_try_bool(qdict, "paging", false); |
2085 | bool zlib = qdict_get_try_bool(qdict, "zlib", false); | |
2086 | bool lzo = qdict_get_try_bool(qdict, "lzo", false); | |
2087 | bool snappy = qdict_get_try_bool(qdict, "snappy", false); | |
75363769 | 2088 | const char *file = qdict_get_str(qdict, "filename"); |
783e9b48 WC |
2089 | bool has_begin = qdict_haskey(qdict, "begin"); |
2090 | bool has_length = qdict_haskey(qdict, "length"); | |
228de9cf | 2091 | bool has_detach = qdict_haskey(qdict, "detach"); |
783e9b48 WC |
2092 | int64_t begin = 0; |
2093 | int64_t length = 0; | |
228de9cf | 2094 | bool detach = false; |
b53ccc30 | 2095 | enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF; |
75363769 | 2096 | char *prot; |
783e9b48 | 2097 | |
2da91b54 VP |
2098 | if (zlib + lzo + snappy + win_dmp > 1) { |
2099 | error_setg(&err, "only one of '-z|-l|-s|-w' can be set"); | |
e940f543 | 2100 | hmp_handle_error(mon, &err); |
1b7a0f75 QN |
2101 | return; |
2102 | } | |
2103 | ||
2da91b54 VP |
2104 | if (win_dmp) { |
2105 | dump_format = DUMP_GUEST_MEMORY_FORMAT_WIN_DMP; | |
2106 | } | |
2107 | ||
1b7a0f75 QN |
2108 | if (zlib) { |
2109 | dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB; | |
2110 | } | |
2111 | ||
2112 | if (lzo) { | |
2113 | dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO; | |
2114 | } | |
2115 | ||
2116 | if (snappy) { | |
2117 | dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY; | |
2118 | } | |
2119 | ||
783e9b48 WC |
2120 | if (has_begin) { |
2121 | begin = qdict_get_int(qdict, "begin"); | |
2122 | } | |
2123 | if (has_length) { | |
2124 | length = qdict_get_int(qdict, "length"); | |
2125 | } | |
228de9cf PX |
2126 | if (has_detach) { |
2127 | detach = qdict_get_bool(qdict, "detach"); | |
2128 | } | |
783e9b48 | 2129 | |
75363769 LC |
2130 | prot = g_strconcat("file:", file, NULL); |
2131 | ||
228de9cf PX |
2132 | qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin, |
2133 | has_length, length, true, dump_format, &err); | |
e940f543 | 2134 | hmp_handle_error(mon, &err); |
75363769 | 2135 | g_free(prot); |
783e9b48 | 2136 | } |
928059a3 LC |
2137 | |
2138 | void hmp_netdev_add(Monitor *mon, const QDict *qdict) | |
2139 | { | |
2140 | Error *err = NULL; | |
2141 | QemuOpts *opts; | |
2142 | ||
2143 | opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err); | |
84d18f06 | 2144 | if (err) { |
928059a3 LC |
2145 | goto out; |
2146 | } | |
2147 | ||
2148 | netdev_add(opts, &err); | |
84d18f06 | 2149 | if (err) { |
928059a3 LC |
2150 | qemu_opts_del(opts); |
2151 | } | |
2152 | ||
2153 | out: | |
2154 | hmp_handle_error(mon, &err); | |
2155 | } | |
5f964155 LC |
2156 | |
2157 | void hmp_netdev_del(Monitor *mon, const QDict *qdict) | |
2158 | { | |
2159 | const char *id = qdict_get_str(qdict, "id"); | |
2160 | Error *err = NULL; | |
2161 | ||
2162 | qmp_netdev_del(id, &err); | |
2163 | hmp_handle_error(mon, &err); | |
2164 | } | |
208c9d1b | 2165 | |
cff8b2c6 PB |
2166 | void hmp_object_add(Monitor *mon, const QDict *qdict) |
2167 | { | |
2168 | Error *err = NULL; | |
2169 | QemuOpts *opts; | |
90998d58 | 2170 | Object *obj = NULL; |
cff8b2c6 PB |
2171 | |
2172 | opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err); | |
2173 | if (err) { | |
90998d58 DB |
2174 | hmp_handle_error(mon, &err); |
2175 | return; | |
cff8b2c6 PB |
2176 | } |
2177 | ||
3a464105 | 2178 | obj = user_creatable_add_opts(opts, &err); |
90998d58 | 2179 | qemu_opts_del(opts); |
cff8b2c6 | 2180 | |
cff8b2c6 | 2181 | if (err) { |
90998d58 | 2182 | hmp_handle_error(mon, &err); |
cff8b2c6 | 2183 | } |
90998d58 DB |
2184 | if (obj) { |
2185 | object_unref(obj); | |
cff8b2c6 | 2186 | } |
cff8b2c6 PB |
2187 | } |
2188 | ||
208c9d1b CB |
2189 | void hmp_getfd(Monitor *mon, const QDict *qdict) |
2190 | { | |
2191 | const char *fdname = qdict_get_str(qdict, "fdname"); | |
e940f543 | 2192 | Error *err = NULL; |
208c9d1b | 2193 | |
e940f543 MA |
2194 | qmp_getfd(fdname, &err); |
2195 | hmp_handle_error(mon, &err); | |
208c9d1b CB |
2196 | } |
2197 | ||
2198 | void hmp_closefd(Monitor *mon, const QDict *qdict) | |
2199 | { | |
2200 | const char *fdname = qdict_get_str(qdict, "fdname"); | |
e940f543 | 2201 | Error *err = NULL; |
208c9d1b | 2202 | |
e940f543 MA |
2203 | qmp_closefd(fdname, &err); |
2204 | hmp_handle_error(mon, &err); | |
208c9d1b | 2205 | } |
e4c8f004 | 2206 | |
3e5a50d6 | 2207 | void hmp_sendkey(Monitor *mon, const QDict *qdict) |
e4c8f004 AK |
2208 | { |
2209 | const char *keys = qdict_get_str(qdict, "keys"); | |
9f328977 | 2210 | KeyValueList *keylist, *head = NULL, *tmp = NULL; |
e4c8f004 AK |
2211 | int has_hold_time = qdict_haskey(qdict, "hold-time"); |
2212 | int hold_time = qdict_get_try_int(qdict, "hold-time", -1); | |
2213 | Error *err = NULL; | |
5c99fa37 | 2214 | const char *separator; |
9f328977 | 2215 | int keyname_len; |
e4c8f004 AK |
2216 | |
2217 | while (1) { | |
5c99fa37 KF |
2218 | separator = qemu_strchrnul(keys, '-'); |
2219 | keyname_len = separator - keys; | |
e4c8f004 AK |
2220 | |
2221 | /* Be compatible with old interface, convert user inputted "<" */ | |
64ffbe04 WB |
2222 | if (keys[0] == '<' && keyname_len == 1) { |
2223 | keys = "less"; | |
e4c8f004 AK |
2224 | keyname_len = 4; |
2225 | } | |
e4c8f004 | 2226 | |
e4c8f004 | 2227 | keylist = g_malloc0(sizeof(*keylist)); |
9f328977 | 2228 | keylist->value = g_malloc0(sizeof(*keylist->value)); |
e4c8f004 AK |
2229 | |
2230 | if (!head) { | |
2231 | head = keylist; | |
2232 | } | |
2233 | if (tmp) { | |
2234 | tmp->next = keylist; | |
2235 | } | |
2236 | tmp = keylist; | |
2237 | ||
64ffbe04 | 2238 | if (strstart(keys, "0x", NULL)) { |
9f328977 | 2239 | char *endp; |
64ffbe04 WB |
2240 | int value = strtoul(keys, &endp, 0); |
2241 | assert(endp <= keys + keyname_len); | |
2242 | if (endp != keys + keyname_len) { | |
9f328977 LC |
2243 | goto err_out; |
2244 | } | |
568c73a4 | 2245 | keylist->value->type = KEY_VALUE_KIND_NUMBER; |
32bafa8f | 2246 | keylist->value->u.number.data = value; |
9f328977 | 2247 | } else { |
64ffbe04 | 2248 | int idx = index_from_key(keys, keyname_len); |
7fb1cf16 | 2249 | if (idx == Q_KEY_CODE__MAX) { |
9f328977 LC |
2250 | goto err_out; |
2251 | } | |
568c73a4 | 2252 | keylist->value->type = KEY_VALUE_KIND_QCODE; |
32bafa8f | 2253 | keylist->value->u.qcode.data = idx; |
9f328977 LC |
2254 | } |
2255 | ||
5c99fa37 | 2256 | if (!*separator) { |
e4c8f004 AK |
2257 | break; |
2258 | } | |
2259 | keys = separator + 1; | |
2260 | } | |
2261 | ||
9f328977 | 2262 | qmp_send_key(head, has_hold_time, hold_time, &err); |
e4c8f004 | 2263 | hmp_handle_error(mon, &err); |
9f328977 LC |
2264 | |
2265 | out: | |
2266 | qapi_free_KeyValueList(head); | |
2267 | return; | |
2268 | ||
2269 | err_out: | |
64ffbe04 | 2270 | monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys); |
9f328977 | 2271 | goto out; |
e4c8f004 | 2272 | } |
ad39cf6d | 2273 | |
3e5a50d6 | 2274 | void hmp_screendump(Monitor *mon, const QDict *qdict) |
ad39cf6d LC |
2275 | { |
2276 | const char *filename = qdict_get_str(qdict, "filename"); | |
f771c544 TH |
2277 | const char *id = qdict_get_try_str(qdict, "device"); |
2278 | int64_t head = qdict_get_try_int(qdict, "head", 0); | |
ad39cf6d LC |
2279 | Error *err = NULL; |
2280 | ||
f771c544 | 2281 | qmp_screendump(filename, id != NULL, id, id != NULL, head, &err); |
ad39cf6d LC |
2282 | hmp_handle_error(mon, &err); |
2283 | } | |
4057725f PB |
2284 | |
2285 | void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) | |
2286 | { | |
2287 | const char *uri = qdict_get_str(qdict, "uri"); | |
34acbc95 EB |
2288 | bool writable = qdict_get_try_bool(qdict, "writable", false); |
2289 | bool all = qdict_get_try_bool(qdict, "all", false); | |
4057725f PB |
2290 | Error *local_err = NULL; |
2291 | BlockInfoList *block_list, *info; | |
bd269ebc | 2292 | SocketAddress *addr; |
4057725f PB |
2293 | |
2294 | if (writable && !all) { | |
2295 | error_setg(&local_err, "-w only valid together with -a"); | |
2296 | goto exit; | |
2297 | } | |
2298 | ||
2299 | /* First check if the address is valid and start the server. */ | |
2300 | addr = socket_parse(uri, &local_err); | |
2301 | if (local_err != NULL) { | |
2302 | goto exit; | |
2303 | } | |
2304 | ||
bd269ebc MA |
2305 | nbd_server_start(addr, NULL, &local_err); |
2306 | qapi_free_SocketAddress(addr); | |
4057725f PB |
2307 | if (local_err != NULL) { |
2308 | goto exit; | |
2309 | } | |
2310 | ||
2311 | if (!all) { | |
2312 | return; | |
2313 | } | |
2314 | ||
2315 | /* Then try adding all block devices. If one fails, close all and | |
2316 | * exit. | |
2317 | */ | |
2318 | block_list = qmp_query_block(NULL); | |
2319 | ||
2320 | for (info = block_list; info; info = info->next) { | |
2321 | if (!info->value->has_inserted) { | |
2322 | continue; | |
2323 | } | |
2324 | ||
902a1f94 VSO |
2325 | qmp_nbd_server_add(info->value->device, false, NULL, |
2326 | true, writable, &local_err); | |
4057725f PB |
2327 | |
2328 | if (local_err != NULL) { | |
2329 | qmp_nbd_server_stop(NULL); | |
2330 | break; | |
2331 | } | |
2332 | } | |
2333 | ||
2334 | qapi_free_BlockInfoList(block_list); | |
2335 | ||
2336 | exit: | |
2337 | hmp_handle_error(mon, &local_err); | |
2338 | } | |
2339 | ||
2340 | void hmp_nbd_server_add(Monitor *mon, const QDict *qdict) | |
2341 | { | |
2342 | const char *device = qdict_get_str(qdict, "device"); | |
dba49323 | 2343 | const char *name = qdict_get_try_str(qdict, "name"); |
34acbc95 | 2344 | bool writable = qdict_get_try_bool(qdict, "writable", false); |
4057725f PB |
2345 | Error *local_err = NULL; |
2346 | ||
dba49323 | 2347 | qmp_nbd_server_add(device, !!name, name, true, writable, &local_err); |
08fb10a7 EB |
2348 | hmp_handle_error(mon, &local_err); |
2349 | } | |
4057725f | 2350 | |
08fb10a7 EB |
2351 | void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict) |
2352 | { | |
2353 | const char *name = qdict_get_str(qdict, "name"); | |
2354 | bool force = qdict_get_try_bool(qdict, "force", false); | |
2355 | Error *err = NULL; | |
2356 | ||
2357 | /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */ | |
2358 | qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err); | |
2359 | hmp_handle_error(mon, &err); | |
4057725f PB |
2360 | } |
2361 | ||
2362 | void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict) | |
2363 | { | |
e940f543 | 2364 | Error *err = NULL; |
4057725f | 2365 | |
e940f543 MA |
2366 | qmp_nbd_server_stop(&err); |
2367 | hmp_handle_error(mon, &err); | |
4057725f | 2368 | } |
f1088908 | 2369 | |
abf23329 JH |
2370 | void hmp_cpu_add(Monitor *mon, const QDict *qdict) |
2371 | { | |
2372 | int cpuid; | |
2373 | Error *err = NULL; | |
2374 | ||
2375 | cpuid = qdict_get_int(qdict, "id"); | |
2376 | qmp_cpu_add(cpuid, &err); | |
2377 | hmp_handle_error(mon, &err); | |
2378 | } | |
2379 | ||
f1088908 GH |
2380 | void hmp_chardev_add(Monitor *mon, const QDict *qdict) |
2381 | { | |
2382 | const char *args = qdict_get_str(qdict, "args"); | |
2383 | Error *err = NULL; | |
2384 | QemuOpts *opts; | |
2385 | ||
70b94331 | 2386 | opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true); |
f1088908 | 2387 | if (opts == NULL) { |
312fd5f2 | 2388 | error_setg(&err, "Parsing chardev args failed"); |
f1088908 | 2389 | } else { |
b4948be9 | 2390 | qemu_chr_new_from_opts(opts, &err); |
0a73336d | 2391 | qemu_opts_del(opts); |
f1088908 GH |
2392 | } |
2393 | hmp_handle_error(mon, &err); | |
2394 | } | |
2395 | ||
75b60160 AN |
2396 | void hmp_chardev_change(Monitor *mon, const QDict *qdict) |
2397 | { | |
2398 | const char *args = qdict_get_str(qdict, "args"); | |
2399 | const char *id; | |
2400 | Error *err = NULL; | |
2401 | ChardevBackend *backend = NULL; | |
2402 | ChardevReturn *ret = NULL; | |
2403 | QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, | |
2404 | true); | |
2405 | if (!opts) { | |
2406 | error_setg(&err, "Parsing chardev args failed"); | |
2407 | goto end; | |
2408 | } | |
2409 | ||
2410 | id = qdict_get_str(qdict, "id"); | |
2411 | if (qemu_opts_id(opts)) { | |
2412 | error_setg(&err, "Unexpected 'id' parameter"); | |
2413 | goto end; | |
2414 | } | |
2415 | ||
2416 | backend = qemu_chr_parse_opts(opts, &err); | |
2417 | if (!backend) { | |
2418 | goto end; | |
2419 | } | |
2420 | ||
2421 | ret = qmp_chardev_change(id, backend, &err); | |
2422 | ||
2423 | end: | |
2424 | qapi_free_ChardevReturn(ret); | |
2425 | qapi_free_ChardevBackend(backend); | |
2426 | qemu_opts_del(opts); | |
2427 | hmp_handle_error(mon, &err); | |
2428 | } | |
2429 | ||
f1088908 GH |
2430 | void hmp_chardev_remove(Monitor *mon, const QDict *qdict) |
2431 | { | |
2432 | Error *local_err = NULL; | |
2433 | ||
2434 | qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err); | |
2435 | hmp_handle_error(mon, &local_err); | |
2436 | } | |
587da2c3 | 2437 | |
bd1d5ad9 SF |
2438 | void hmp_chardev_send_break(Monitor *mon, const QDict *qdict) |
2439 | { | |
2440 | Error *local_err = NULL; | |
2441 | ||
2442 | qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err); | |
2443 | hmp_handle_error(mon, &local_err); | |
2444 | } | |
2445 | ||
587da2c3 KW |
2446 | void hmp_qemu_io(Monitor *mon, const QDict *qdict) |
2447 | { | |
4c7b7e9b | 2448 | BlockBackend *blk; |
e7f98f2f | 2449 | BlockBackend *local_blk = NULL; |
587da2c3 KW |
2450 | const char* device = qdict_get_str(qdict, "device"); |
2451 | const char* command = qdict_get_str(qdict, "command"); | |
2452 | Error *err = NULL; | |
d7086422 | 2453 | int ret; |
587da2c3 | 2454 | |
4c7b7e9b | 2455 | blk = blk_by_name(device); |
e7f98f2f KW |
2456 | if (!blk) { |
2457 | BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err); | |
2458 | if (bs) { | |
6d0eb64d | 2459 | blk = local_blk = blk_new(0, BLK_PERM_ALL); |
d7086422 KW |
2460 | ret = blk_insert_bs(blk, bs, &err); |
2461 | if (ret < 0) { | |
2462 | goto fail; | |
2463 | } | |
e7f98f2f KW |
2464 | } else { |
2465 | goto fail; | |
2466 | } | |
2467 | } | |
2468 | ||
887354bd KW |
2469 | /* |
2470 | * Notably absent: Proper permission management. This is sad, but it seems | |
2471 | * almost impossible to achieve without changing the semantics and thereby | |
2472 | * limiting the use cases of the qemu-io HMP command. | |
2473 | * | |
2474 | * In an ideal world we would unconditionally create a new BlockBackend for | |
2475 | * qemuio_command(), but we have commands like 'reopen' and want them to | |
2476 | * take effect on the exact BlockBackend whose name the user passed instead | |
2477 | * of just on a temporary copy of it. | |
2478 | * | |
2479 | * Another problem is that deleting the temporary BlockBackend involves | |
2480 | * draining all requests on it first, but some qemu-iotests cases want to | |
2481 | * issue multiple aio_read/write requests and expect them to complete in | |
2482 | * the background while the monitor has already returned. | |
2483 | * | |
2484 | * This is also what prevents us from saving the original permissions and | |
2485 | * restoring them later: We can't revoke permissions until all requests | |
2486 | * have completed, and we don't know when that is nor can we really let | |
2487 | * anything else run before we have revoken them to avoid race conditions. | |
2488 | * | |
2489 | * What happens now is that command() in qemu-io-cmds.c can extend the | |
2490 | * permissions if necessary for the qemu-io command. And they simply stay | |
2491 | * extended, possibly resulting in a read-only guest device keeping write | |
2492 | * permissions. Ugly, but it appears to be the lesser evil. | |
2493 | */ | |
1813d330 | 2494 | qemuio_command(blk, command); |
587da2c3 | 2495 | |
e7f98f2f KW |
2496 | fail: |
2497 | blk_unref(local_blk); | |
587da2c3 KW |
2498 | hmp_handle_error(mon, &err); |
2499 | } | |
ab2d0531 PB |
2500 | |
2501 | void hmp_object_del(Monitor *mon, const QDict *qdict) | |
2502 | { | |
2503 | const char *id = qdict_get_str(qdict, "id"); | |
2504 | Error *err = NULL; | |
2505 | ||
90998d58 | 2506 | user_creatable_del(id, &err); |
ab2d0531 PB |
2507 | hmp_handle_error(mon, &err); |
2508 | } | |
eb1539b2 HT |
2509 | |
2510 | void hmp_info_memdev(Monitor *mon, const QDict *qdict) | |
2511 | { | |
2512 | Error *err = NULL; | |
2513 | MemdevList *memdev_list = qmp_query_memdev(&err); | |
2514 | MemdevList *m = memdev_list; | |
3b098d56 | 2515 | Visitor *v; |
976620ac | 2516 | char *str; |
eb1539b2 HT |
2517 | |
2518 | while (m) { | |
3b098d56 EB |
2519 | v = string_output_visitor_new(false, &str); |
2520 | visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL); | |
e1ff3c67 | 2521 | monitor_printf(mon, "memory backend: %s\n", m->value->id); |
eb1539b2 HT |
2522 | monitor_printf(mon, " size: %" PRId64 "\n", m->value->size); |
2523 | monitor_printf(mon, " merge: %s\n", | |
2524 | m->value->merge ? "true" : "false"); | |
2525 | monitor_printf(mon, " dump: %s\n", | |
2526 | m->value->dump ? "true" : "false"); | |
2527 | monitor_printf(mon, " prealloc: %s\n", | |
2528 | m->value->prealloc ? "true" : "false"); | |
2529 | monitor_printf(mon, " policy: %s\n", | |
977c736f | 2530 | HostMemPolicy_str(m->value->policy)); |
3b098d56 | 2531 | visit_complete(v, &str); |
976620ac | 2532 | monitor_printf(mon, " host nodes: %s\n", str); |
eb1539b2 | 2533 | |
976620ac | 2534 | g_free(str); |
3b098d56 | 2535 | visit_free(v); |
eb1539b2 | 2536 | m = m->next; |
eb1539b2 HT |
2537 | } |
2538 | ||
2539 | monitor_printf(mon, "\n"); | |
ecaf54a0 CF |
2540 | |
2541 | qapi_free_MemdevList(memdev_list); | |
40c71f63 | 2542 | hmp_handle_error(mon, &err); |
eb1539b2 | 2543 | } |
a631892f ZG |
2544 | |
2545 | void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) | |
2546 | { | |
2547 | Error *err = NULL; | |
2548 | MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err); | |
2549 | MemoryDeviceInfoList *info; | |
2550 | MemoryDeviceInfo *value; | |
2551 | PCDIMMDeviceInfo *di; | |
2552 | ||
2553 | for (info = info_list; info; info = info->next) { | |
2554 | value = info->value; | |
2555 | ||
2556 | if (value) { | |
1fd5d4fe | 2557 | switch (value->type) { |
a631892f | 2558 | case MEMORY_DEVICE_INFO_KIND_DIMM: |
32bafa8f | 2559 | di = value->u.dimm.data; |
6388e18d HZ |
2560 | break; |
2561 | ||
2562 | case MEMORY_DEVICE_INFO_KIND_NVDIMM: | |
2563 | di = value->u.nvdimm.data; | |
2564 | break; | |
2565 | ||
2566 | default: | |
2567 | di = NULL; | |
2568 | break; | |
2569 | } | |
a631892f | 2570 | |
6388e18d | 2571 | if (di) { |
a631892f | 2572 | monitor_printf(mon, "Memory device [%s]: \"%s\"\n", |
977c736f | 2573 | MemoryDeviceInfoKind_str(value->type), |
a631892f ZG |
2574 | di->id ? di->id : ""); |
2575 | monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr); | |
2576 | monitor_printf(mon, " slot: %" PRId64 "\n", di->slot); | |
2577 | monitor_printf(mon, " node: %" PRId64 "\n", di->node); | |
2578 | monitor_printf(mon, " size: %" PRIu64 "\n", di->size); | |
2579 | monitor_printf(mon, " memdev: %s\n", di->memdev); | |
2580 | monitor_printf(mon, " hotplugged: %s\n", | |
2581 | di->hotplugged ? "true" : "false"); | |
2582 | monitor_printf(mon, " hotpluggable: %s\n", | |
2583 | di->hotpluggable ? "true" : "false"); | |
a631892f ZG |
2584 | } |
2585 | } | |
2586 | } | |
2587 | ||
2588 | qapi_free_MemoryDeviceInfoList(info_list); | |
40c71f63 | 2589 | hmp_handle_error(mon, &err); |
a631892f | 2590 | } |
89d7fa9e | 2591 | |
62313160 TW |
2592 | void hmp_info_iothreads(Monitor *mon, const QDict *qdict) |
2593 | { | |
2594 | IOThreadInfoList *info_list = qmp_query_iothreads(NULL); | |
2595 | IOThreadInfoList *info; | |
5fc00480 | 2596 | IOThreadInfo *value; |
62313160 TW |
2597 | |
2598 | for (info = info_list; info; info = info->next) { | |
5fc00480 PH |
2599 | value = info->value; |
2600 | monitor_printf(mon, "%s:\n", value->id); | |
2601 | monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id); | |
2602 | monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns); | |
2603 | monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow); | |
2604 | monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink); | |
62313160 TW |
2605 | } |
2606 | ||
2607 | qapi_free_IOThreadInfoList(info_list); | |
2608 | } | |
2609 | ||
89d7fa9e AF |
2610 | void hmp_qom_list(Monitor *mon, const QDict *qdict) |
2611 | { | |
2612 | const char *path = qdict_get_try_str(qdict, "path"); | |
2613 | ObjectPropertyInfoList *list; | |
2614 | Error *err = NULL; | |
2615 | ||
2616 | if (path == NULL) { | |
2617 | monitor_printf(mon, "/\n"); | |
2618 | return; | |
2619 | } | |
2620 | ||
2621 | list = qmp_qom_list(path, &err); | |
2622 | if (err == NULL) { | |
2623 | ObjectPropertyInfoList *start = list; | |
2624 | while (list != NULL) { | |
2625 | ObjectPropertyInfo *value = list->value; | |
2626 | ||
2627 | monitor_printf(mon, "%s (%s)\n", | |
2628 | value->name, value->type); | |
2629 | list = list->next; | |
2630 | } | |
2631 | qapi_free_ObjectPropertyInfoList(start); | |
2632 | } | |
2633 | hmp_handle_error(mon, &err); | |
2634 | } | |
c0e6ee9e AF |
2635 | |
2636 | void hmp_qom_set(Monitor *mon, const QDict *qdict) | |
2637 | { | |
2638 | const char *path = qdict_get_str(qdict, "path"); | |
2639 | const char *property = qdict_get_str(qdict, "property"); | |
2640 | const char *value = qdict_get_str(qdict, "value"); | |
2641 | Error *err = NULL; | |
2642 | bool ambiguous = false; | |
2643 | Object *obj; | |
2644 | ||
2645 | obj = object_resolve_path(path, &ambiguous); | |
2646 | if (obj == NULL) { | |
75158ebb MA |
2647 | error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND, |
2648 | "Device '%s' not found", path); | |
c0e6ee9e AF |
2649 | } else { |
2650 | if (ambiguous) { | |
2651 | monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path); | |
2652 | } | |
2653 | object_property_parse(obj, value, property, &err); | |
2654 | } | |
2655 | hmp_handle_error(mon, &err); | |
2656 | } | |
fafa4d50 SF |
2657 | |
2658 | void hmp_rocker(Monitor *mon, const QDict *qdict) | |
2659 | { | |
2660 | const char *name = qdict_get_str(qdict, "name"); | |
2661 | RockerSwitch *rocker; | |
533fdaed | 2662 | Error *err = NULL; |
fafa4d50 | 2663 | |
533fdaed MA |
2664 | rocker = qmp_query_rocker(name, &err); |
2665 | if (err != NULL) { | |
2666 | hmp_handle_error(mon, &err); | |
fafa4d50 SF |
2667 | return; |
2668 | } | |
2669 | ||
2670 | monitor_printf(mon, "name: %s\n", rocker->name); | |
2671 | monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id); | |
2672 | monitor_printf(mon, "ports: %d\n", rocker->ports); | |
2673 | ||
2674 | qapi_free_RockerSwitch(rocker); | |
2675 | } | |
2676 | ||
2677 | void hmp_rocker_ports(Monitor *mon, const QDict *qdict) | |
2678 | { | |
2679 | RockerPortList *list, *port; | |
2680 | const char *name = qdict_get_str(qdict, "name"); | |
533fdaed | 2681 | Error *err = NULL; |
fafa4d50 | 2682 | |
533fdaed MA |
2683 | list = qmp_query_rocker_ports(name, &err); |
2684 | if (err != NULL) { | |
2685 | hmp_handle_error(mon, &err); | |
fafa4d50 SF |
2686 | return; |
2687 | } | |
2688 | ||
2689 | monitor_printf(mon, " ena/ speed/ auto\n"); | |
2690 | monitor_printf(mon, " port link duplex neg?\n"); | |
2691 | ||
2692 | for (port = list; port; port = port->next) { | |
2693 | monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n", | |
2694 | port->value->name, | |
2695 | port->value->enabled ? port->value->link_up ? | |
2696 | "up" : "down" : "!ena", | |
2697 | port->value->speed == 10000 ? "10G" : "??", | |
2698 | port->value->duplex ? "FD" : "HD", | |
2699 | port->value->autoneg ? "Yes" : "No"); | |
2700 | } | |
2701 | ||
2702 | qapi_free_RockerPortList(list); | |
2703 | } | |
2704 | ||
2705 | void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict) | |
2706 | { | |
2707 | RockerOfDpaFlowList *list, *info; | |
2708 | const char *name = qdict_get_str(qdict, "name"); | |
2709 | uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1); | |
533fdaed | 2710 | Error *err = NULL; |
fafa4d50 | 2711 | |
533fdaed MA |
2712 | list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err); |
2713 | if (err != NULL) { | |
2714 | hmp_handle_error(mon, &err); | |
fafa4d50 SF |
2715 | return; |
2716 | } | |
2717 | ||
2718 | monitor_printf(mon, "prio tbl hits key(mask) --> actions\n"); | |
2719 | ||
2720 | for (info = list; info; info = info->next) { | |
2721 | RockerOfDpaFlow *flow = info->value; | |
2722 | RockerOfDpaFlowKey *key = flow->key; | |
2723 | RockerOfDpaFlowMask *mask = flow->mask; | |
2724 | RockerOfDpaFlowAction *action = flow->action; | |
2725 | ||
2726 | if (flow->hits) { | |
2727 | monitor_printf(mon, "%-4d %-3d %-4" PRIu64, | |
2728 | key->priority, key->tbl_id, flow->hits); | |
2729 | } else { | |
2730 | monitor_printf(mon, "%-4d %-3d ", | |
2731 | key->priority, key->tbl_id); | |
2732 | } | |
2733 | ||
2734 | if (key->has_in_pport) { | |
2735 | monitor_printf(mon, " pport %d", key->in_pport); | |
2736 | if (mask->has_in_pport) { | |
2737 | monitor_printf(mon, "(0x%x)", mask->in_pport); | |
2738 | } | |
2739 | } | |
2740 | ||
2741 | if (key->has_vlan_id) { | |
2742 | monitor_printf(mon, " vlan %d", | |
2743 | key->vlan_id & VLAN_VID_MASK); | |
2744 | if (mask->has_vlan_id) { | |
2745 | monitor_printf(mon, "(0x%x)", mask->vlan_id); | |
2746 | } | |
2747 | } | |
2748 | ||
2749 | if (key->has_tunnel_id) { | |
2750 | monitor_printf(mon, " tunnel %d", key->tunnel_id); | |
2751 | if (mask->has_tunnel_id) { | |
2752 | monitor_printf(mon, "(0x%x)", mask->tunnel_id); | |
2753 | } | |
2754 | } | |
2755 | ||
2756 | if (key->has_eth_type) { | |
2757 | switch (key->eth_type) { | |
2758 | case 0x0806: | |
2759 | monitor_printf(mon, " ARP"); | |
2760 | break; | |
2761 | case 0x0800: | |
2762 | monitor_printf(mon, " IP"); | |
2763 | break; | |
2764 | case 0x86dd: | |
2765 | monitor_printf(mon, " IPv6"); | |
2766 | break; | |
2767 | case 0x8809: | |
2768 | monitor_printf(mon, " LACP"); | |
2769 | break; | |
2770 | case 0x88cc: | |
2771 | monitor_printf(mon, " LLDP"); | |
2772 | break; | |
2773 | default: | |
2774 | monitor_printf(mon, " eth type 0x%04x", key->eth_type); | |
2775 | break; | |
2776 | } | |
2777 | } | |
2778 | ||
2779 | if (key->has_eth_src) { | |
2780 | if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) && | |
2781 | (mask->has_eth_src) && | |
2782 | (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { | |
2783 | monitor_printf(mon, " src <any mcast/bcast>"); | |
2784 | } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) && | |
2785 | (mask->has_eth_src) && | |
2786 | (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { | |
2787 | monitor_printf(mon, " src <any ucast>"); | |
2788 | } else { | |
2789 | monitor_printf(mon, " src %s", key->eth_src); | |
2790 | if (mask->has_eth_src) { | |
2791 | monitor_printf(mon, "(%s)", mask->eth_src); | |
2792 | } | |
2793 | } | |
2794 | } | |
2795 | ||
2796 | if (key->has_eth_dst) { | |
2797 | if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) && | |
2798 | (mask->has_eth_dst) && | |
2799 | (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { | |
2800 | monitor_printf(mon, " dst <any mcast/bcast>"); | |
2801 | } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) && | |
2802 | (mask->has_eth_dst) && | |
2803 | (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { | |
2804 | monitor_printf(mon, " dst <any ucast>"); | |
2805 | } else { | |
2806 | monitor_printf(mon, " dst %s", key->eth_dst); | |
2807 | if (mask->has_eth_dst) { | |
2808 | monitor_printf(mon, "(%s)", mask->eth_dst); | |
2809 | } | |
2810 | } | |
2811 | } | |
2812 | ||
2813 | if (key->has_ip_proto) { | |
2814 | monitor_printf(mon, " proto %d", key->ip_proto); | |
2815 | if (mask->has_ip_proto) { | |
2816 | monitor_printf(mon, "(0x%x)", mask->ip_proto); | |
2817 | } | |
2818 | } | |
2819 | ||
2820 | if (key->has_ip_tos) { | |
2821 | monitor_printf(mon, " TOS %d", key->ip_tos); | |
2822 | if (mask->has_ip_tos) { | |
2823 | monitor_printf(mon, "(0x%x)", mask->ip_tos); | |
2824 | } | |
2825 | } | |
2826 | ||
2827 | if (key->has_ip_dst) { | |
2828 | monitor_printf(mon, " dst %s", key->ip_dst); | |
2829 | } | |
2830 | ||
2831 | if (action->has_goto_tbl || action->has_group_id || | |
2832 | action->has_new_vlan_id) { | |
2833 | monitor_printf(mon, " -->"); | |
2834 | } | |
2835 | ||
2836 | if (action->has_new_vlan_id) { | |
2837 | monitor_printf(mon, " apply new vlan %d", | |
2838 | ntohs(action->new_vlan_id)); | |
2839 | } | |
2840 | ||
2841 | if (action->has_group_id) { | |
2842 | monitor_printf(mon, " write group 0x%08x", action->group_id); | |
2843 | } | |
2844 | ||
2845 | if (action->has_goto_tbl) { | |
2846 | monitor_printf(mon, " goto tbl %d", action->goto_tbl); | |
2847 | } | |
2848 | ||
2849 | monitor_printf(mon, "\n"); | |
2850 | } | |
2851 | ||
2852 | qapi_free_RockerOfDpaFlowList(list); | |
2853 | } | |
2854 | ||
2855 | void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict) | |
2856 | { | |
2857 | RockerOfDpaGroupList *list, *g; | |
2858 | const char *name = qdict_get_str(qdict, "name"); | |
2859 | uint8_t type = qdict_get_try_int(qdict, "type", 9); | |
533fdaed | 2860 | Error *err = NULL; |
fafa4d50 SF |
2861 | bool set = false; |
2862 | ||
533fdaed MA |
2863 | list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err); |
2864 | if (err != NULL) { | |
2865 | hmp_handle_error(mon, &err); | |
fafa4d50 SF |
2866 | return; |
2867 | } | |
2868 | ||
2869 | monitor_printf(mon, "id (decode) --> buckets\n"); | |
2870 | ||
2871 | for (g = list; g; g = g->next) { | |
2872 | RockerOfDpaGroup *group = g->value; | |
2873 | ||
2874 | monitor_printf(mon, "0x%08x", group->id); | |
2875 | ||
2876 | monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" : | |
2877 | group->type == 1 ? "L2 rewrite" : | |
2878 | group->type == 2 ? "L3 unicast" : | |
2879 | group->type == 3 ? "L2 multicast" : | |
2880 | group->type == 4 ? "L2 flood" : | |
2881 | group->type == 5 ? "L3 interface" : | |
2882 | group->type == 6 ? "L3 multicast" : | |
2883 | group->type == 7 ? "L3 ECMP" : | |
2884 | group->type == 8 ? "L2 overlay" : | |
2885 | "unknown"); | |
2886 | ||
2887 | if (group->has_vlan_id) { | |
2888 | monitor_printf(mon, " vlan %d", group->vlan_id); | |
2889 | } | |
2890 | ||
2891 | if (group->has_pport) { | |
2892 | monitor_printf(mon, " pport %d", group->pport); | |
2893 | } | |
2894 | ||
2895 | if (group->has_index) { | |
2896 | monitor_printf(mon, " index %d", group->index); | |
2897 | } | |
2898 | ||
2899 | monitor_printf(mon, ") -->"); | |
2900 | ||
2901 | if (group->has_set_vlan_id && group->set_vlan_id) { | |
2902 | set = true; | |
2903 | monitor_printf(mon, " set vlan %d", | |
2904 | group->set_vlan_id & VLAN_VID_MASK); | |
2905 | } | |
2906 | ||
2907 | if (group->has_set_eth_src) { | |
2908 | if (!set) { | |
2909 | set = true; | |
2910 | monitor_printf(mon, " set"); | |
2911 | } | |
2912 | monitor_printf(mon, " src %s", group->set_eth_src); | |
2913 | } | |
2914 | ||
2915 | if (group->has_set_eth_dst) { | |
2916 | if (!set) { | |
2917 | set = true; | |
2918 | monitor_printf(mon, " set"); | |
2919 | } | |
2920 | monitor_printf(mon, " dst %s", group->set_eth_dst); | |
2921 | } | |
2922 | ||
2923 | set = false; | |
2924 | ||
2925 | if (group->has_ttl_check && group->ttl_check) { | |
2926 | monitor_printf(mon, " check TTL"); | |
2927 | } | |
2928 | ||
2929 | if (group->has_group_id && group->group_id) { | |
2930 | monitor_printf(mon, " group id 0x%08x", group->group_id); | |
2931 | } | |
2932 | ||
2933 | if (group->has_pop_vlan && group->pop_vlan) { | |
2934 | monitor_printf(mon, " pop vlan"); | |
2935 | } | |
2936 | ||
2937 | if (group->has_out_pport) { | |
2938 | monitor_printf(mon, " out pport %d", group->out_pport); | |
2939 | } | |
2940 | ||
2941 | if (group->has_group_ids) { | |
2942 | struct uint32List *id; | |
2943 | ||
2944 | monitor_printf(mon, " groups ["); | |
2945 | for (id = group->group_ids; id; id = id->next) { | |
2946 | monitor_printf(mon, "0x%08x", id->value); | |
2947 | if (id->next) { | |
2948 | monitor_printf(mon, ","); | |
2949 | } | |
2950 | } | |
2951 | monitor_printf(mon, "]"); | |
2952 | } | |
2953 | ||
2954 | monitor_printf(mon, "\n"); | |
2955 | } | |
2956 | ||
2957 | qapi_free_RockerOfDpaGroupList(list); | |
2958 | } | |
4a6b52d6 PX |
2959 | |
2960 | void hmp_info_dump(Monitor *mon, const QDict *qdict) | |
2961 | { | |
2962 | DumpQueryResult *result = qmp_query_dump(NULL); | |
2963 | ||
2964 | assert(result && result->status < DUMP_STATUS__MAX); | |
977c736f | 2965 | monitor_printf(mon, "Status: %s\n", DumpStatus_str(result->status)); |
4a6b52d6 PX |
2966 | |
2967 | if (result->status == DUMP_STATUS_ACTIVE) { | |
2968 | float percent = 0; | |
2969 | assert(result->total != 0); | |
2970 | percent = 100.0 * result->completed / result->total; | |
2971 | monitor_printf(mon, "Finished: %.2f %%\n", percent); | |
2972 | } | |
2973 | ||
2974 | qapi_free_DumpQueryResult(result); | |
2975 | } | |
d2d8d46f | 2976 | |
be9b23c4 PX |
2977 | void hmp_info_ramblock(Monitor *mon, const QDict *qdict) |
2978 | { | |
2979 | ram_block_dump(mon); | |
2980 | } | |
2981 | ||
d2d8d46f BR |
2982 | void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict) |
2983 | { | |
2984 | Error *err = NULL; | |
2985 | HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err); | |
2986 | HotpluggableCPUList *saved = l; | |
2987 | CpuInstanceProperties *c; | |
2988 | ||
2989 | if (err != NULL) { | |
2990 | hmp_handle_error(mon, &err); | |
2991 | return; | |
2992 | } | |
2993 | ||
2994 | monitor_printf(mon, "Hotpluggable CPUs:\n"); | |
2995 | while (l) { | |
2996 | monitor_printf(mon, " type: \"%s\"\n", l->value->type); | |
2997 | monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n", | |
2998 | l->value->vcpus_count); | |
2999 | if (l->value->has_qom_path) { | |
3000 | monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path); | |
3001 | } | |
3002 | ||
3003 | c = l->value->props; | |
3004 | monitor_printf(mon, " CPUInstance Properties:\n"); | |
27393c33 PK |
3005 | if (c->has_node_id) { |
3006 | monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id); | |
d2d8d46f | 3007 | } |
27393c33 PK |
3008 | if (c->has_socket_id) { |
3009 | monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id); | |
d2d8d46f | 3010 | } |
27393c33 PK |
3011 | if (c->has_core_id) { |
3012 | monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id); | |
d2d8d46f | 3013 | } |
27393c33 PK |
3014 | if (c->has_thread_id) { |
3015 | monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id); | |
d2d8d46f BR |
3016 | } |
3017 | ||
3018 | l = l->next; | |
3019 | } | |
3020 | ||
3021 | qapi_free_HotpluggableCPUList(saved); | |
3022 | } | |
39164c13 IM |
3023 | |
3024 | void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict) | |
3025 | { | |
72d9196f BW |
3026 | Error *err = NULL; |
3027 | GuidInfo *info = qmp_query_vm_generation_id(&err); | |
39164c13 IM |
3028 | if (info) { |
3029 | monitor_printf(mon, "%s\n", info->guid); | |
3030 | } | |
72d9196f | 3031 | hmp_handle_error(mon, &err); |
39164c13 IM |
3032 | qapi_free_GuidInfo(info); |
3033 | } | |
d0f63c1e VG |
3034 | |
3035 | void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict) | |
3036 | { | |
3037 | Error *err = NULL; | |
3038 | MemoryInfo *info = qmp_query_memory_size_summary(&err); | |
3039 | if (info) { | |
3040 | monitor_printf(mon, "base memory: %" PRIu64 "\n", | |
3041 | info->base_memory); | |
3042 | ||
3043 | if (info->has_plugged_memory) { | |
3044 | monitor_printf(mon, "plugged memory: %" PRIu64 "\n", | |
3045 | info->plugged_memory); | |
3046 | } | |
3047 | ||
3048 | qapi_free_MemoryInfo(info); | |
3049 | } | |
3050 | hmp_handle_error(mon, &err); | |
3051 | } |