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