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