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