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