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