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