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