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" |
54d31236 | 22 | #include "sysemu/runstate.h" |
213dcb06 | 23 | #include "qemu/config-file.h" |
1de7afc9 PB |
24 | #include "qemu/option.h" |
25 | #include "qemu/timer.h" | |
1de7afc9 | 26 | #include "qemu/sockets.h" |
ad6f932f | 27 | #include "qemu/help_option.h" |
5bce308a | 28 | #include "monitor/monitor-internal.h" |
e688df6b | 29 | #include "qapi/error.h" |
08528271 | 30 | #include "qapi/clone-visitor.h" |
cff8b2c6 | 31 | #include "qapi/opts-visitor.h" |
eb815e24 | 32 | #include "qapi/qapi-builtin-visit.h" |
112ed241 MA |
33 | #include "qapi/qapi-commands-block.h" |
34 | #include "qapi/qapi-commands-char.h" | |
fa4dcf57 | 35 | #include "qapi/qapi-commands-control.h" |
a83e24ba | 36 | #include "qapi/qapi-commands-machine.h" |
112ed241 MA |
37 | #include "qapi/qapi-commands-migration.h" |
38 | #include "qapi/qapi-commands-misc.h" | |
39 | #include "qapi/qapi-commands-net.h" | |
40 | #include "qapi/qapi-commands-rocker.h" | |
41 | #include "qapi/qapi-commands-run-state.h" | |
433815f5 | 42 | #include "qapi/qapi-commands-stats.h" |
112ed241 MA |
43 | #include "qapi/qapi-commands-tpm.h" |
44 | #include "qapi/qapi-commands-ui.h" | |
8a828798 LV |
45 | #include "qapi/qapi-commands-virtio.h" |
46 | #include "qapi/qapi-visit-virtio.h" | |
08528271 | 47 | #include "qapi/qapi-visit-net.h" |
96eef042 | 48 | #include "qapi/qapi-visit-migration.h" |
452fcdbc | 49 | #include "qapi/qmp/qdict.h" |
cc7a8ea7 | 50 | #include "qapi/qmp/qerror.h" |
f4a06d13 | 51 | #include "qapi/string-input-visitor.h" |
eb1539b2 | 52 | #include "qapi/string-output-visitor.h" |
90998d58 | 53 | #include "qom/object_interfaces.h" |
28ecbaee | 54 | #include "ui/console.h" |
f348b6d1 | 55 | #include "qemu/cutils.h" |
d59ce6f3 | 56 | #include "qemu/error-report.h" |
433815f5 | 57 | #include "hw/core/cpu.h" |
61b97833 | 58 | #include "hw/intc/intc.h" |
5e22479a | 59 | #include "migration/snapshot.h" |
9d18af93 | 60 | #include "migration/misc.h" |
48a32bed | 61 | |
22fa7da0 CR |
62 | #ifdef CONFIG_SPICE |
63 | #include <spice/enums.h> | |
64 | #endif | |
65 | ||
0ca117a7 | 66 | bool hmp_handle_error(Monitor *mon, Error *err) |
0cfd6a9a | 67 | { |
187c6147 VSO |
68 | if (err) { |
69 | error_reportf_err(err, "Error: "); | |
0ca117a7 | 70 | return true; |
0cfd6a9a | 71 | } |
0ca117a7 | 72 | return false; |
0cfd6a9a LC |
73 | } |
74 | ||
08528271 DDAG |
75 | /* |
76 | * Produce a strList from a comma separated list. | |
77 | * A NULL or empty input string return NULL. | |
78 | */ | |
79 | static strList *strList_from_comma_list(const char *in) | |
80 | { | |
81 | strList *res = NULL; | |
c3033fd3 | 82 | strList **tail = &res; |
08528271 DDAG |
83 | |
84 | while (in && in[0]) { | |
85 | char *comma = strchr(in, ','); | |
c3033fd3 | 86 | char *value; |
08528271 DDAG |
87 | |
88 | if (comma) { | |
c3033fd3 | 89 | value = g_strndup(in, comma - in); |
08528271 DDAG |
90 | in = comma + 1; /* skip the , */ |
91 | } else { | |
c3033fd3 | 92 | value = g_strdup(in); |
08528271 DDAG |
93 | in = NULL; |
94 | } | |
c3033fd3 | 95 | QAPI_LIST_APPEND(tail, value); |
08528271 DDAG |
96 | } |
97 | ||
98 | return res; | |
99 | } | |
100 | ||
84f2d0ea | 101 | void hmp_info_name(Monitor *mon, const QDict *qdict) |
48a32bed AL |
102 | { |
103 | NameInfo *info; | |
104 | ||
105 | info = qmp_query_name(NULL); | |
9492718b | 106 | if (info->name) { |
48a32bed AL |
107 | monitor_printf(mon, "%s\n", info->name); |
108 | } | |
109 | qapi_free_NameInfo(info); | |
110 | } | |
b9c15f16 | 111 | |
84f2d0ea | 112 | void hmp_info_version(Monitor *mon, const QDict *qdict) |
b9c15f16 LC |
113 | { |
114 | VersionInfo *info; | |
115 | ||
116 | info = qmp_query_version(NULL); | |
117 | ||
118 | monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n", | |
4752cdbb | 119 | info->qemu->major, info->qemu->minor, info->qemu->micro, |
b9c15f16 LC |
120 | info->package); |
121 | ||
122 | qapi_free_VersionInfo(info); | |
123 | } | |
292a2602 | 124 | |
84f2d0ea | 125 | void hmp_info_kvm(Monitor *mon, const QDict *qdict) |
292a2602 LC |
126 | { |
127 | KvmInfo *info; | |
128 | ||
129 | info = qmp_query_kvm(NULL); | |
130 | monitor_printf(mon, "kvm support: "); | |
131 | if (info->present) { | |
132 | monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled"); | |
133 | } else { | |
134 | monitor_printf(mon, "not compiled\n"); | |
135 | } | |
136 | ||
137 | qapi_free_KvmInfo(info); | |
138 | } | |
139 | ||
84f2d0ea | 140 | void hmp_info_status(Monitor *mon, const QDict *qdict) |
1fa9a5e4 LC |
141 | { |
142 | StatusInfo *info; | |
143 | ||
144 | info = qmp_query_status(NULL); | |
145 | ||
146 | monitor_printf(mon, "VM status: %s%s", | |
147 | info->running ? "running" : "paused", | |
148 | info->singlestep ? " (single step mode)" : ""); | |
149 | ||
150 | if (!info->running && info->status != RUN_STATE_PAUSED) { | |
977c736f | 151 | monitor_printf(mon, " (%s)", RunState_str(info->status)); |
1fa9a5e4 LC |
152 | } |
153 | ||
154 | monitor_printf(mon, "\n"); | |
155 | ||
156 | qapi_free_StatusInfo(info); | |
157 | } | |
158 | ||
84f2d0ea | 159 | void hmp_info_uuid(Monitor *mon, const QDict *qdict) |
efab767e LC |
160 | { |
161 | UuidInfo *info; | |
162 | ||
163 | info = qmp_query_uuid(NULL); | |
164 | monitor_printf(mon, "%s\n", info->UUID); | |
165 | qapi_free_UuidInfo(info); | |
166 | } | |
c5a415a0 | 167 | |
84f2d0ea | 168 | void hmp_info_chardev(Monitor *mon, const QDict *qdict) |
c5a415a0 LC |
169 | { |
170 | ChardevInfoList *char_info, *info; | |
171 | ||
172 | char_info = qmp_query_chardev(NULL); | |
173 | for (info = char_info; info; info = info->next) { | |
174 | monitor_printf(mon, "%s: filename=%s\n", info->value->label, | |
175 | info->value->filename); | |
176 | } | |
177 | ||
178 | qapi_free_ChardevInfoList(char_info); | |
179 | } | |
7a7f325e | 180 | |
84f2d0ea | 181 | void hmp_info_mice(Monitor *mon, const QDict *qdict) |
e235cec3 LC |
182 | { |
183 | MouseInfoList *mice_list, *mouse; | |
184 | ||
185 | mice_list = qmp_query_mice(NULL); | |
186 | if (!mice_list) { | |
187 | monitor_printf(mon, "No mouse devices connected\n"); | |
188 | return; | |
189 | } | |
190 | ||
191 | for (mouse = mice_list; mouse; mouse = mouse->next) { | |
192 | monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n", | |
193 | mouse->value->current ? '*' : ' ', | |
194 | mouse->value->index, mouse->value->name, | |
195 | mouse->value->absolute ? " (absolute)" : ""); | |
196 | } | |
197 | ||
198 | qapi_free_MouseInfoList(mice_list); | |
199 | } | |
200 | ||
84f2d0ea | 201 | void hmp_info_migrate(Monitor *mon, const QDict *qdict) |
791e7c82 LC |
202 | { |
203 | MigrationInfo *info; | |
204 | ||
205 | info = qmp_query_migrate(NULL); | |
bbf6da32 | 206 | |
9d18af93 PX |
207 | migration_global_dump(mon); |
208 | ||
372043f3 | 209 | if (info->blocked_reasons) { |
a64aec72 DDAG |
210 | strList *reasons = info->blocked_reasons; |
211 | monitor_printf(mon, "Outgoing migration blocked:\n"); | |
212 | while (reasons) { | |
213 | monitor_printf(mon, " %s\n", reasons->value); | |
214 | reasons = reasons->next; | |
215 | } | |
216 | } | |
217 | ||
791e7c82 | 218 | if (info->has_status) { |
d59ce6f3 | 219 | monitor_printf(mon, "Migration status: %s", |
977c736f | 220 | MigrationStatus_str(info->status)); |
720a252c | 221 | if (info->status == MIGRATION_STATUS_FAILED && info->error_desc) { |
d59ce6f3 DB |
222 | monitor_printf(mon, " (%s)\n", info->error_desc); |
223 | } else { | |
224 | monitor_printf(mon, "\n"); | |
225 | } | |
226 | ||
7ac5529a | 227 | monitor_printf(mon, "total time: %" PRIu64 " ms\n", |
7aa939af | 228 | info->total_time); |
2c52ddf1 | 229 | if (info->has_expected_downtime) { |
7ac5529a | 230 | monitor_printf(mon, "expected downtime: %" PRIu64 " ms\n", |
2c52ddf1 JQ |
231 | info->expected_downtime); |
232 | } | |
9c5a9fcf | 233 | if (info->has_downtime) { |
7ac5529a | 234 | monitor_printf(mon, "downtime: %" PRIu64 " ms\n", |
9c5a9fcf JQ |
235 | info->downtime); |
236 | } | |
ed4fbd10 | 237 | if (info->has_setup_time) { |
7ac5529a | 238 | monitor_printf(mon, "setup: %" PRIu64 " ms\n", |
ed4fbd10 MH |
239 | info->setup_time); |
240 | } | |
791e7c82 LC |
241 | } |
242 | ||
720a252c | 243 | if (info->ram) { |
791e7c82 LC |
244 | monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n", |
245 | info->ram->transferred >> 10); | |
7e114f8c MH |
246 | monitor_printf(mon, "throughput: %0.2f mbps\n", |
247 | info->ram->mbps); | |
791e7c82 LC |
248 | monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n", |
249 | info->ram->remaining >> 10); | |
250 | monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n", | |
251 | info->ram->total >> 10); | |
004d4c10 OW |
252 | monitor_printf(mon, "duplicate: %" PRIu64 " pages\n", |
253 | info->ram->duplicate); | |
f1c72795 PL |
254 | monitor_printf(mon, "skipped: %" PRIu64 " pages\n", |
255 | info->ram->skipped); | |
004d4c10 OW |
256 | monitor_printf(mon, "normal: %" PRIu64 " pages\n", |
257 | info->ram->normal); | |
258 | monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n", | |
259 | info->ram->normal_bytes >> 10); | |
58570ed8 C |
260 | monitor_printf(mon, "dirty sync count: %" PRIu64 "\n", |
261 | info->ram->dirty_sync_count); | |
030ce1f8 CF |
262 | monitor_printf(mon, "page size: %" PRIu64 " kbytes\n", |
263 | info->ram->page_size >> 10); | |
a61c45bd JQ |
264 | monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n", |
265 | info->ram->multifd_bytes >> 10); | |
aecbfe9c XG |
266 | monitor_printf(mon, "pages-per-second: %" PRIu64 "\n", |
267 | info->ram->pages_per_second); | |
030ce1f8 | 268 | |
8d017193 JQ |
269 | if (info->ram->dirty_pages_rate) { |
270 | monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n", | |
271 | info->ram->dirty_pages_rate); | |
272 | } | |
d3bf5418 DDAG |
273 | if (info->ram->postcopy_requests) { |
274 | monitor_printf(mon, "postcopy request count: %" PRIu64 "\n", | |
275 | info->ram->postcopy_requests); | |
276 | } | |
ae680668 DE |
277 | if (info->ram->precopy_bytes) { |
278 | monitor_printf(mon, "precopy ram: %" PRIu64 " kbytes\n", | |
279 | info->ram->precopy_bytes >> 10); | |
280 | } | |
281 | if (info->ram->downtime_bytes) { | |
282 | monitor_printf(mon, "downtime ram: %" PRIu64 " kbytes\n", | |
283 | info->ram->downtime_bytes >> 10); | |
284 | } | |
285 | if (info->ram->postcopy_bytes) { | |
286 | monitor_printf(mon, "postcopy ram: %" PRIu64 " kbytes\n", | |
287 | info->ram->postcopy_bytes >> 10); | |
288 | } | |
cf20c897 LB |
289 | if (info->ram->dirty_sync_missed_zero_copy) { |
290 | monitor_printf(mon, | |
291 | "Zero-copy-send fallbacks happened: %" PRIu64 " times\n", | |
292 | info->ram->dirty_sync_missed_zero_copy); | |
293 | } | |
791e7c82 LC |
294 | } |
295 | ||
720a252c | 296 | if (info->disk) { |
791e7c82 LC |
297 | monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n", |
298 | info->disk->transferred >> 10); | |
299 | monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n", | |
300 | info->disk->remaining >> 10); | |
301 | monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n", | |
302 | info->disk->total >> 10); | |
303 | } | |
304 | ||
720a252c | 305 | if (info->xbzrle_cache) { |
f36d55af OW |
306 | monitor_printf(mon, "cache size: %" PRIu64 " bytes\n", |
307 | info->xbzrle_cache->cache_size); | |
308 | monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n", | |
309 | info->xbzrle_cache->bytes >> 10); | |
310 | monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n", | |
311 | info->xbzrle_cache->pages); | |
afb5d01c | 312 | monitor_printf(mon, "xbzrle cache miss: %" PRIu64 " pages\n", |
f36d55af | 313 | info->xbzrle_cache->cache_miss); |
8bc39233 C |
314 | monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n", |
315 | info->xbzrle_cache->cache_miss_rate); | |
e460a4b1 WW |
316 | monitor_printf(mon, "xbzrle encoding rate: %0.2f\n", |
317 | info->xbzrle_cache->encoding_rate); | |
06b1c6f8 | 318 | monitor_printf(mon, "xbzrle overflow: %" PRIu64 "\n", |
f36d55af OW |
319 | info->xbzrle_cache->overflow); |
320 | } | |
321 | ||
720a252c | 322 | if (info->compression) { |
76e03000 XG |
323 | monitor_printf(mon, "compression pages: %" PRIu64 " pages\n", |
324 | info->compression->pages); | |
325 | monitor_printf(mon, "compression busy: %" PRIu64 "\n", | |
326 | info->compression->busy); | |
327 | monitor_printf(mon, "compression busy rate: %0.2f\n", | |
328 | info->compression->busy_rate); | |
afb5d01c MZ |
329 | monitor_printf(mon, "compressed size: %" PRIu64 " kbytes\n", |
330 | info->compression->compressed_size >> 10); | |
76e03000 XG |
331 | monitor_printf(mon, "compression rate: %0.2f\n", |
332 | info->compression->compression_rate); | |
333 | } | |
334 | ||
d85a31d1 | 335 | if (info->has_cpu_throttle_percentage) { |
4782893e | 336 | monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n", |
d85a31d1 | 337 | info->cpu_throttle_percentage); |
4782893e JH |
338 | } |
339 | ||
65ace060 AP |
340 | if (info->has_postcopy_blocktime) { |
341 | monitor_printf(mon, "postcopy blocktime: %u\n", | |
342 | info->postcopy_blocktime); | |
343 | } | |
344 | ||
345 | if (info->has_postcopy_vcpu_blocktime) { | |
346 | Visitor *v; | |
347 | char *str; | |
348 | v = string_output_visitor_new(false, &str); | |
1f584248 MA |
349 | visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, |
350 | &error_abort); | |
65ace060 AP |
351 | visit_complete(v, &str); |
352 | monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str); | |
353 | g_free(str); | |
354 | visit_free(v); | |
355 | } | |
9aca82ba JQ |
356 | if (info->has_socket_address) { |
357 | SocketAddressList *addr; | |
358 | ||
359 | monitor_printf(mon, "socket address: [\n"); | |
360 | ||
361 | for (addr = info->socket_address; addr; addr = addr->next) { | |
18bf1c94 | 362 | char *s = socket_uri(addr->value); |
9aca82ba JQ |
363 | monitor_printf(mon, "\t%s\n", s); |
364 | g_free(s); | |
365 | } | |
366 | monitor_printf(mon, "]\n"); | |
367 | } | |
3710586c | 368 | |
720a252c | 369 | if (info->vfio) { |
3710586c KW |
370 | monitor_printf(mon, "vfio device transferred: %" PRIu64 " kbytes\n", |
371 | info->vfio->transferred >> 10); | |
372 | } | |
373 | ||
791e7c82 | 374 | qapi_free_MigrationInfo(info); |
bbf6da32 OW |
375 | } |
376 | ||
84f2d0ea | 377 | void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict) |
bbf6da32 OW |
378 | { |
379 | MigrationCapabilityStatusList *caps, *cap; | |
380 | ||
381 | caps = qmp_query_migrate_capabilities(NULL); | |
382 | ||
383 | if (caps) { | |
bbf6da32 | 384 | for (cap = caps; cap; cap = cap->next) { |
d80a0169 | 385 | monitor_printf(mon, "%s: %s\n", |
977c736f | 386 | MigrationCapability_str(cap->value->capability), |
bbf6da32 OW |
387 | cap->value->state ? "on" : "off"); |
388 | } | |
bbf6da32 OW |
389 | } |
390 | ||
391 | qapi_free_MigrationCapabilityStatusList(caps); | |
791e7c82 LC |
392 | } |
393 | ||
50e9a629 LL |
394 | void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) |
395 | { | |
396 | MigrationParameters *params; | |
397 | ||
398 | params = qmp_query_migrate_parameters(NULL); | |
399 | ||
400 | if (params) { | |
ee3d96ba DDAG |
401 | monitor_printf(mon, "%s: %" PRIu64 " ms\n", |
402 | MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL), | |
403 | params->announce_initial); | |
404 | monitor_printf(mon, "%s: %" PRIu64 " ms\n", | |
405 | MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX), | |
406 | params->announce_max); | |
407 | monitor_printf(mon, "%s: %" PRIu64 "\n", | |
408 | MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS), | |
409 | params->announce_rounds); | |
410 | monitor_printf(mon, "%s: %" PRIu64 " ms\n", | |
411 | MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP), | |
412 | params->announce_step); | |
de63ab61 | 413 | assert(params->has_compress_level); |
741d4086 | 414 | monitor_printf(mon, "%s: %u\n", |
977c736f | 415 | MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL), |
50e9a629 | 416 | params->compress_level); |
de63ab61 | 417 | assert(params->has_compress_threads); |
741d4086 | 418 | monitor_printf(mon, "%s: %u\n", |
977c736f | 419 | MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS), |
50e9a629 | 420 | params->compress_threads); |
1d58872a XG |
421 | assert(params->has_compress_wait_thread); |
422 | monitor_printf(mon, "%s: %s\n", | |
423 | MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD), | |
424 | params->compress_wait_thread ? "on" : "off"); | |
de63ab61 | 425 | assert(params->has_decompress_threads); |
741d4086 | 426 | monitor_printf(mon, "%s: %u\n", |
977c736f | 427 | MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS), |
50e9a629 | 428 | params->decompress_threads); |
dc14a470 KZ |
429 | assert(params->has_throttle_trigger_threshold); |
430 | monitor_printf(mon, "%s: %u\n", | |
431 | MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD), | |
432 | params->throttle_trigger_threshold); | |
de63ab61 | 433 | assert(params->has_cpu_throttle_initial); |
741d4086 | 434 | monitor_printf(mon, "%s: %u\n", |
977c736f | 435 | MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL), |
d85a31d1 | 436 | params->cpu_throttle_initial); |
de63ab61 | 437 | assert(params->has_cpu_throttle_increment); |
741d4086 | 438 | monitor_printf(mon, "%s: %u\n", |
977c736f | 439 | MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT), |
d85a31d1 | 440 | params->cpu_throttle_increment); |
cbbf8182 KZ |
441 | assert(params->has_cpu_throttle_tailslow); |
442 | monitor_printf(mon, "%s: %s\n", | |
443 | MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW), | |
444 | params->cpu_throttle_tailslow ? "on" : "off"); | |
4cbc9c7f LQ |
445 | assert(params->has_max_cpu_throttle); |
446 | monitor_printf(mon, "%s: %u\n", | |
447 | MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE), | |
448 | params->max_cpu_throttle); | |
720a252c | 449 | assert(params->tls_creds); |
2c02468c | 450 | monitor_printf(mon, "%s: '%s'\n", |
977c736f | 451 | MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS), |
8cc99dcd | 452 | params->tls_creds); |
720a252c | 453 | assert(params->tls_hostname); |
2c02468c | 454 | monitor_printf(mon, "%s: '%s'\n", |
977c736f | 455 | MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME), |
8cc99dcd | 456 | params->tls_hostname); |
2ff30257 | 457 | assert(params->has_max_bandwidth); |
741d4086 | 458 | monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n", |
977c736f | 459 | MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH), |
2ff30257 AA |
460 | params->max_bandwidth); |
461 | assert(params->has_downtime_limit); | |
39337f12 | 462 | monitor_printf(mon, "%s: %" PRIu64 " ms\n", |
977c736f | 463 | MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT), |
2ff30257 | 464 | params->downtime_limit); |
fe39a4d4 | 465 | assert(params->has_x_checkpoint_delay); |
39337f12 | 466 | monitor_printf(mon, "%s: %u ms\n", |
977c736f | 467 | MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY), |
68b53591 | 468 | params->x_checkpoint_delay); |
2833c59b JQ |
469 | assert(params->has_block_incremental); |
470 | monitor_printf(mon, "%s: %s\n", | |
977c736f MA |
471 | MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL), |
472 | params->block_incremental ? "on" : "off"); | |
741d4086 | 473 | monitor_printf(mon, "%s: %u\n", |
cbfd6c95 JQ |
474 | MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS), |
475 | params->multifd_channels); | |
96eef042 JQ |
476 | monitor_printf(mon, "%s: %s\n", |
477 | MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION), | |
478 | MultiFDCompression_str(params->multifd_compression)); | |
39337f12 | 479 | monitor_printf(mon, "%s: %" PRIu64 " bytes\n", |
73af8dd8 JQ |
480 | MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE), |
481 | params->xbzrle_cache_size); | |
7e555c6c DDAG |
482 | monitor_printf(mon, "%s: %" PRIu64 "\n", |
483 | MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH), | |
484 | params->max_postcopy_bandwidth); | |
7cd75cbd | 485 | monitor_printf(mon, "%s: '%s'\n", |
d2f1d29b | 486 | MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ), |
7cd75cbd | 487 | params->tls_authz); |
31e4c354 HR |
488 | |
489 | if (params->has_block_bitmap_mapping) { | |
490 | const BitmapMigrationNodeAliasList *bmnal; | |
491 | ||
492 | monitor_printf(mon, "%s:\n", | |
493 | MigrationParameter_str( | |
494 | MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING)); | |
495 | ||
496 | for (bmnal = params->block_bitmap_mapping; | |
497 | bmnal; | |
498 | bmnal = bmnal->next) | |
499 | { | |
500 | const BitmapMigrationNodeAlias *bmna = bmnal->value; | |
501 | const BitmapMigrationBitmapAliasList *bmbal; | |
502 | ||
503 | monitor_printf(mon, " '%s' -> '%s'\n", | |
504 | bmna->node_name, bmna->alias); | |
505 | ||
506 | for (bmbal = bmna->bitmaps; bmbal; bmbal = bmbal->next) { | |
507 | const BitmapMigrationBitmapAlias *bmba = bmbal->value; | |
508 | ||
509 | monitor_printf(mon, " '%s' -> '%s'\n", | |
510 | bmba->name, bmba->alias); | |
511 | } | |
512 | } | |
513 | } | |
50e9a629 LL |
514 | } |
515 | ||
516 | qapi_free_MigrationParameters(params); | |
517 | } | |
518 | ||
f11f57e4 | 519 | |
05eb4a25 | 520 | #ifdef CONFIG_VNC |
0a9667ec DDAG |
521 | /* Helper for hmp_info_vnc_clients, _servers */ |
522 | static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info, | |
523 | const char *name) | |
524 | { | |
525 | monitor_printf(mon, " %s: %s:%s (%s%s)\n", | |
526 | name, | |
527 | info->host, | |
528 | info->service, | |
977c736f | 529 | NetworkAddressFamily_str(info->family), |
0a9667ec DDAG |
530 | info->websocket ? " (Websocket)" : ""); |
531 | } | |
532 | ||
533 | /* Helper displaying and auth and crypt info */ | |
534 | static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent, | |
535 | VncPrimaryAuth auth, | |
536 | VncVencryptSubAuth *vencrypt) | |
537 | { | |
538 | monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent, | |
977c736f MA |
539 | VncPrimaryAuth_str(auth), |
540 | vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none"); | |
0a9667ec DDAG |
541 | } |
542 | ||
543 | static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client) | |
544 | { | |
545 | while (client) { | |
546 | VncClientInfo *cinfo = client->value; | |
547 | ||
548 | hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client"); | |
549 | monitor_printf(mon, " x509_dname: %s\n", | |
3f41a3ad | 550 | cinfo->x509_dname ?: "none"); |
0a9667ec | 551 | monitor_printf(mon, " sasl_username: %s\n", |
3f41a3ad | 552 | cinfo->sasl_username ?: "none"); |
0a9667ec DDAG |
553 | |
554 | client = client->next; | |
555 | } | |
556 | } | |
557 | ||
558 | static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server) | |
559 | { | |
560 | while (server) { | |
561 | VncServerInfo2 *sinfo = server->value; | |
562 | hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server"); | |
563 | hmp_info_vnc_authcrypt(mon, " ", sinfo->auth, | |
564 | sinfo->has_vencrypt ? &sinfo->vencrypt : NULL); | |
565 | server = server->next; | |
566 | } | |
567 | } | |
568 | ||
84f2d0ea | 569 | void hmp_info_vnc(Monitor *mon, const QDict *qdict) |
2b54aa87 | 570 | { |
d4ff1093 | 571 | VncInfo2List *info2l, *info2l_head; |
2b54aa87 | 572 | Error *err = NULL; |
2b54aa87 | 573 | |
0a9667ec | 574 | info2l = qmp_query_vnc_servers(&err); |
d4ff1093 | 575 | info2l_head = info2l; |
0ca117a7 | 576 | if (hmp_handle_error(mon, err)) { |
2b54aa87 LC |
577 | return; |
578 | } | |
0a9667ec DDAG |
579 | if (!info2l) { |
580 | monitor_printf(mon, "None\n"); | |
581 | return; | |
2b54aa87 LC |
582 | } |
583 | ||
0a9667ec DDAG |
584 | while (info2l) { |
585 | VncInfo2 *info = info2l->value; | |
586 | monitor_printf(mon, "%s:\n", info->id); | |
587 | hmp_info_vnc_servers(mon, info->server); | |
588 | hmp_info_vnc_clients(mon, info->clients); | |
589 | if (!info->server) { | |
590 | /* The server entry displays its auth, we only | |
591 | * need to display in the case of 'reverse' connections | |
592 | * where there's no server. | |
593 | */ | |
594 | hmp_info_vnc_authcrypt(mon, " ", info->auth, | |
595 | info->has_vencrypt ? &info->vencrypt : NULL); | |
596 | } | |
3f41a3ad | 597 | if (info->display) { |
0a9667ec | 598 | monitor_printf(mon, " Display: %s\n", info->display); |
2b54aa87 | 599 | } |
0a9667ec | 600 | info2l = info2l->next; |
2b54aa87 LC |
601 | } |
602 | ||
d4ff1093 | 603 | qapi_free_VncInfo2List(info2l_head); |
0a9667ec | 604 | |
2b54aa87 | 605 | } |
05eb4a25 | 606 | #endif |
2b54aa87 | 607 | |
206addd5 | 608 | #ifdef CONFIG_SPICE |
84f2d0ea | 609 | void hmp_info_spice(Monitor *mon, const QDict *qdict) |
d1f29646 LC |
610 | { |
611 | SpiceChannelList *chan; | |
612 | SpiceInfo *info; | |
22fa7da0 CR |
613 | const char *channel_name; |
614 | const char * const channel_names[] = { | |
615 | [SPICE_CHANNEL_MAIN] = "main", | |
616 | [SPICE_CHANNEL_DISPLAY] = "display", | |
617 | [SPICE_CHANNEL_INPUTS] = "inputs", | |
618 | [SPICE_CHANNEL_CURSOR] = "cursor", | |
619 | [SPICE_CHANNEL_PLAYBACK] = "playback", | |
620 | [SPICE_CHANNEL_RECORD] = "record", | |
621 | [SPICE_CHANNEL_TUNNEL] = "tunnel", | |
622 | [SPICE_CHANNEL_SMARTCARD] = "smartcard", | |
623 | [SPICE_CHANNEL_USBREDIR] = "usbredir", | |
624 | [SPICE_CHANNEL_PORT] = "port", | |
7c6044a9 GH |
625 | #if 0 |
626 | /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7, | |
627 | * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable | |
628 | * as quick fix for build failures with older versions. */ | |
22fa7da0 | 629 | [SPICE_CHANNEL_WEBDAV] = "webdav", |
7c6044a9 | 630 | #endif |
22fa7da0 | 631 | }; |
d1f29646 LC |
632 | |
633 | info = qmp_query_spice(NULL); | |
634 | ||
635 | if (!info->enabled) { | |
636 | monitor_printf(mon, "Server: disabled\n"); | |
637 | goto out; | |
638 | } | |
639 | ||
640 | monitor_printf(mon, "Server:\n"); | |
641 | if (info->has_port) { | |
642 | monitor_printf(mon, " address: %s:%" PRId64 "\n", | |
643 | info->host, info->port); | |
644 | } | |
645 | if (info->has_tls_port) { | |
646 | monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n", | |
647 | info->host, info->tls_port); | |
648 | } | |
61c4efe2 YH |
649 | monitor_printf(mon, " migrated: %s\n", |
650 | info->migrated ? "true" : "false"); | |
d1f29646 LC |
651 | monitor_printf(mon, " auth: %s\n", info->auth); |
652 | monitor_printf(mon, " compiled: %s\n", info->compiled_version); | |
4efee029 | 653 | monitor_printf(mon, " mouse-mode: %s\n", |
977c736f | 654 | SpiceQueryMouseMode_str(info->mouse_mode)); |
d1f29646 LC |
655 | |
656 | if (!info->has_channels || info->channels == NULL) { | |
657 | monitor_printf(mon, "Channels: none\n"); | |
658 | } else { | |
659 | for (chan = info->channels; chan; chan = chan->next) { | |
660 | monitor_printf(mon, "Channel:\n"); | |
661 | monitor_printf(mon, " address: %s:%s%s\n", | |
ddf21908 | 662 | chan->value->host, chan->value->port, |
d1f29646 LC |
663 | chan->value->tls ? " [tls]" : ""); |
664 | monitor_printf(mon, " session: %" PRId64 "\n", | |
665 | chan->value->connection_id); | |
666 | monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n", | |
667 | chan->value->channel_type, chan->value->channel_id); | |
22fa7da0 CR |
668 | |
669 | channel_name = "unknown"; | |
670 | if (chan->value->channel_type > 0 && | |
671 | chan->value->channel_type < ARRAY_SIZE(channel_names) && | |
672 | channel_names[chan->value->channel_type]) { | |
673 | channel_name = channel_names[chan->value->channel_type]; | |
674 | } | |
675 | ||
676 | monitor_printf(mon, " channel name: %s\n", channel_name); | |
d1f29646 LC |
677 | } |
678 | } | |
679 | ||
680 | out: | |
681 | qapi_free_SpiceInfo(info); | |
682 | } | |
206addd5 | 683 | #endif |
d1f29646 | 684 | |
84f2d0ea | 685 | void hmp_info_balloon(Monitor *mon, const QDict *qdict) |
96637bcd LC |
686 | { |
687 | BalloonInfo *info; | |
688 | Error *err = NULL; | |
689 | ||
690 | info = qmp_query_balloon(&err); | |
0ca117a7 | 691 | if (hmp_handle_error(mon, err)) { |
96637bcd LC |
692 | return; |
693 | } | |
694 | ||
01ceb97e | 695 | monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20); |
96637bcd LC |
696 | |
697 | qapi_free_BalloonInfo(info); | |
698 | } | |
699 | ||
61b97833 HP |
700 | static int hmp_info_pic_foreach(Object *obj, void *opaque) |
701 | { | |
702 | InterruptStatsProvider *intc; | |
703 | InterruptStatsProviderClass *k; | |
704 | Monitor *mon = opaque; | |
705 | ||
706 | if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) { | |
707 | intc = INTERRUPT_STATS_PROVIDER(obj); | |
708 | k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj); | |
709 | if (k->print_info) { | |
710 | k->print_info(intc, mon); | |
711 | } else { | |
712 | monitor_printf(mon, "Interrupt controller information not available for %s.\n", | |
713 | object_get_typename(obj)); | |
714 | } | |
715 | } | |
716 | ||
717 | return 0; | |
718 | } | |
719 | ||
720 | void hmp_info_pic(Monitor *mon, const QDict *qdict) | |
721 | { | |
722 | object_child_foreach_recursive(object_get_root(), | |
723 | hmp_info_pic_foreach, mon); | |
724 | } | |
725 | ||
d1a0cf73 SB |
726 | void hmp_info_tpm(Monitor *mon, const QDict *qdict) |
727 | { | |
caff255a | 728 | #ifdef CONFIG_TPM |
d1a0cf73 SB |
729 | TPMInfoList *info_list, *info; |
730 | Error *err = NULL; | |
731 | unsigned int c = 0; | |
732 | TPMPassthroughOptions *tpo; | |
f4ede81e | 733 | TPMEmulatorOptions *teo; |
d1a0cf73 SB |
734 | |
735 | info_list = qmp_query_tpm(&err); | |
736 | if (err) { | |
737 | monitor_printf(mon, "TPM device not supported\n"); | |
738 | error_free(err); | |
739 | return; | |
740 | } | |
741 | ||
742 | if (info_list) { | |
743 | monitor_printf(mon, "TPM device:\n"); | |
744 | } | |
745 | ||
746 | for (info = info_list; info; info = info->next) { | |
747 | TPMInfo *ti = info->value; | |
748 | monitor_printf(mon, " tpm%d: model=%s\n", | |
977c736f | 749 | c, TpmModel_str(ti->model)); |
d1a0cf73 SB |
750 | |
751 | monitor_printf(mon, " \\ %s: type=%s", | |
39dc3e4a | 752 | ti->id, TpmType_str(ti->options->type)); |
d1a0cf73 | 753 | |
ce21131a | 754 | switch (ti->options->type) { |
39dc3e4a | 755 | case TPM_TYPE_PASSTHROUGH: |
32bafa8f | 756 | tpo = ti->options->u.passthrough.data; |
d1a0cf73 | 757 | monitor_printf(mon, "%s%s%s%s", |
ced29396 MA |
758 | tpo->path ? ",path=" : "", |
759 | tpo->path ?: "", | |
760 | tpo->cancel_path ? ",cancel-path=" : "", | |
761 | tpo->cancel_path ?: ""); | |
d1a0cf73 | 762 | break; |
39dc3e4a | 763 | case TPM_TYPE_EMULATOR: |
f4ede81e AV |
764 | teo = ti->options->u.emulator.data; |
765 | monitor_printf(mon, ",chardev=%s", teo->chardev); | |
766 | break; | |
39dc3e4a | 767 | case TPM_TYPE__MAX: |
d1a0cf73 SB |
768 | break; |
769 | } | |
770 | monitor_printf(mon, "\n"); | |
771 | c++; | |
772 | } | |
773 | qapi_free_TPMInfoList(info_list); | |
caff255a PMD |
774 | #else |
775 | monitor_printf(mon, "TPM device not supported\n"); | |
776 | #endif /* CONFIG_TPM */ | |
d1a0cf73 SB |
777 | } |
778 | ||
7a7f325e LC |
779 | void hmp_quit(Monitor *mon, const QDict *qdict) |
780 | { | |
781 | monitor_suspend(mon); | |
782 | qmp_quit(NULL); | |
783 | } | |
5f158f21 LC |
784 | |
785 | void hmp_stop(Monitor *mon, const QDict *qdict) | |
786 | { | |
787 | qmp_stop(NULL); | |
788 | } | |
38d22653 | 789 | |
dd12e1bb EC |
790 | void hmp_sync_profile(Monitor *mon, const QDict *qdict) |
791 | { | |
792 | const char *op = qdict_get_try_str(qdict, "op"); | |
793 | ||
794 | if (op == NULL) { | |
795 | bool on = qsp_is_enabled(); | |
796 | ||
797 | monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off"); | |
798 | return; | |
799 | } | |
800 | if (!strcmp(op, "on")) { | |
801 | qsp_enable(); | |
802 | } else if (!strcmp(op, "off")) { | |
803 | qsp_disable(); | |
804 | } else if (!strcmp(op, "reset")) { | |
805 | qsp_reset(); | |
806 | } else { | |
807 | Error *err = NULL; | |
808 | ||
809 | error_setg(&err, QERR_INVALID_PARAMETER, op); | |
187c6147 | 810 | hmp_handle_error(mon, err); |
dd12e1bb EC |
811 | } |
812 | } | |
813 | ||
38d22653 LC |
814 | void hmp_system_reset(Monitor *mon, const QDict *qdict) |
815 | { | |
816 | qmp_system_reset(NULL); | |
817 | } | |
5bc465e4 LC |
818 | |
819 | void hmp_system_powerdown(Monitor *mon, const QDict *qdict) | |
820 | { | |
821 | qmp_system_powerdown(NULL); | |
822 | } | |
755f1968 | 823 | |
8e8581e6 DDAG |
824 | void hmp_exit_preconfig(Monitor *mon, const QDict *qdict) |
825 | { | |
826 | Error *err = NULL; | |
827 | ||
361ac948 | 828 | qmp_x_exit_preconfig(&err); |
187c6147 | 829 | hmp_handle_error(mon, err); |
8e8581e6 DDAG |
830 | } |
831 | ||
755f1968 LC |
832 | void hmp_cpu(Monitor *mon, const QDict *qdict) |
833 | { | |
834 | int64_t cpu_index; | |
835 | ||
836 | /* XXX: drop the monitor_set_cpu() usage when all HMP commands that | |
837 | use it are converted to the QAPI */ | |
838 | cpu_index = qdict_get_int(qdict, "index"); | |
dcba65f8 | 839 | if (monitor_set_cpu(mon, cpu_index) < 0) { |
755f1968 LC |
840 | monitor_printf(mon, "invalid CPU index\n"); |
841 | } | |
842 | } | |
0cfd6a9a LC |
843 | |
844 | void hmp_memsave(Monitor *mon, const QDict *qdict) | |
845 | { | |
846 | uint32_t size = qdict_get_int(qdict, "size"); | |
847 | const char *filename = qdict_get_str(qdict, "filename"); | |
848 | uint64_t addr = qdict_get_int(qdict, "val"); | |
e940f543 | 849 | Error *err = NULL; |
87e6f4a4 | 850 | int cpu_index = monitor_get_cpu_index(mon); |
0cfd6a9a | 851 | |
854e67fe TH |
852 | if (cpu_index < 0) { |
853 | monitor_printf(mon, "No CPU available\n"); | |
854 | return; | |
855 | } | |
856 | ||
857 | qmp_memsave(addr, size, filename, true, cpu_index, &err); | |
187c6147 | 858 | hmp_handle_error(mon, err); |
0cfd6a9a | 859 | } |
6d3962bf LC |
860 | |
861 | void hmp_pmemsave(Monitor *mon, const QDict *qdict) | |
862 | { | |
863 | uint32_t size = qdict_get_int(qdict, "size"); | |
864 | const char *filename = qdict_get_str(qdict, "filename"); | |
865 | uint64_t addr = qdict_get_int(qdict, "val"); | |
e940f543 | 866 | Error *err = NULL; |
6d3962bf | 867 | |
e940f543 | 868 | qmp_pmemsave(addr, size, filename, &err); |
187c6147 | 869 | hmp_handle_error(mon, err); |
1f590cf9 LL |
870 | } |
871 | ||
3949e594 | 872 | void hmp_ringbuf_write(Monitor *mon, const QDict *qdict) |
1f590cf9 | 873 | { |
1f590cf9 LL |
874 | const char *chardev = qdict_get_str(qdict, "device"); |
875 | const char *data = qdict_get_str(qdict, "data"); | |
e940f543 | 876 | Error *err = NULL; |
1f590cf9 | 877 | |
e940f543 | 878 | qmp_ringbuf_write(chardev, data, false, 0, &err); |
1f590cf9 | 879 | |
187c6147 | 880 | hmp_handle_error(mon, err); |
6d3962bf | 881 | } |
e42e818b | 882 | |
3949e594 | 883 | void hmp_ringbuf_read(Monitor *mon, const QDict *qdict) |
49b6d722 LL |
884 | { |
885 | uint32_t size = qdict_get_int(qdict, "size"); | |
886 | const char *chardev = qdict_get_str(qdict, "device"); | |
3ab651fc | 887 | char *data; |
e940f543 | 888 | Error *err = NULL; |
543f3412 | 889 | int i; |
49b6d722 | 890 | |
e940f543 | 891 | data = qmp_ringbuf_read(chardev, size, false, 0, &err); |
0ca117a7 | 892 | if (hmp_handle_error(mon, err)) { |
49b6d722 LL |
893 | return; |
894 | } | |
895 | ||
543f3412 MA |
896 | for (i = 0; data[i]; i++) { |
897 | unsigned char ch = data[i]; | |
898 | ||
899 | if (ch == '\\') { | |
900 | monitor_printf(mon, "\\\\"); | |
901 | } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) { | |
902 | monitor_printf(mon, "\\u%04X", ch); | |
903 | } else { | |
904 | monitor_printf(mon, "%c", ch); | |
905 | } | |
906 | ||
907 | } | |
908 | monitor_printf(mon, "\n"); | |
3ab651fc | 909 | g_free(data); |
49b6d722 LL |
910 | } |
911 | ||
e42e818b LC |
912 | void hmp_cont(Monitor *mon, const QDict *qdict) |
913 | { | |
e940f543 | 914 | Error *err = NULL; |
e42e818b | 915 | |
e940f543 | 916 | qmp_cont(&err); |
187c6147 | 917 | hmp_handle_error(mon, err); |
e42e818b | 918 | } |
ab49ab5c | 919 | |
9b9df25a GH |
920 | void hmp_system_wakeup(Monitor *mon, const QDict *qdict) |
921 | { | |
fb064112 DHB |
922 | Error *err = NULL; |
923 | ||
924 | qmp_system_wakeup(&err); | |
187c6147 | 925 | hmp_handle_error(mon, err); |
9b9df25a GH |
926 | } |
927 | ||
3e5a50d6 | 928 | void hmp_nmi(Monitor *mon, const QDict *qdict) |
ab49ab5c | 929 | { |
e940f543 | 930 | Error *err = NULL; |
ab49ab5c | 931 | |
e940f543 | 932 | qmp_inject_nmi(&err); |
187c6147 | 933 | hmp_handle_error(mon, err); |
ab49ab5c | 934 | } |
4b37156c LC |
935 | |
936 | void hmp_set_link(Monitor *mon, const QDict *qdict) | |
937 | { | |
938 | const char *name = qdict_get_str(qdict, "name"); | |
34acbc95 | 939 | bool up = qdict_get_bool(qdict, "up"); |
e940f543 | 940 | Error *err = NULL; |
4b37156c | 941 | |
e940f543 | 942 | qmp_set_link(name, up, &err); |
187c6147 | 943 | hmp_handle_error(mon, err); |
4b37156c | 944 | } |
a4dea8a9 | 945 | |
d72f3264 LC |
946 | void hmp_balloon(Monitor *mon, const QDict *qdict) |
947 | { | |
948 | int64_t value = qdict_get_int(qdict, "value"); | |
e940f543 | 949 | Error *err = NULL; |
d72f3264 | 950 | |
e940f543 | 951 | qmp_balloon(value, &err); |
187c6147 | 952 | hmp_handle_error(mon, err); |
d72f3264 | 953 | } |
5e7caacb | 954 | |
52b26205 JQ |
955 | void hmp_loadvm(Monitor *mon, const QDict *qdict) |
956 | { | |
957 | int saved_vm_running = runstate_is_running(); | |
958 | const char *name = qdict_get_str(qdict, "name"); | |
927d6638 | 959 | Error *err = NULL; |
52b26205 JQ |
960 | |
961 | vm_stop(RUN_STATE_RESTORE_VM); | |
962 | ||
c53cd04e | 963 | if (load_snapshot(name, NULL, false, NULL, &err) && saved_vm_running) { |
52b26205 JQ |
964 | vm_start(); |
965 | } | |
187c6147 | 966 | hmp_handle_error(mon, err); |
52b26205 JQ |
967 | } |
968 | ||
d9c7d137 JQ |
969 | void hmp_savevm(Monitor *mon, const QDict *qdict) |
970 | { | |
927d6638 JQ |
971 | Error *err = NULL; |
972 | ||
f1a9fcdd DB |
973 | save_snapshot(qdict_get_try_str(qdict, "name"), |
974 | true, NULL, false, NULL, &err); | |
187c6147 | 975 | hmp_handle_error(mon, err); |
d9c7d137 JQ |
976 | } |
977 | ||
d905bb7b JQ |
978 | void hmp_delvm(Monitor *mon, const QDict *qdict) |
979 | { | |
32cd6550 | 980 | Error *err = NULL; |
d905bb7b JQ |
981 | const char *name = qdict_get_str(qdict, "name"); |
982 | ||
bef7e9e2 | 983 | delete_snapshot(name, false, NULL, &err); |
187c6147 | 984 | hmp_handle_error(mon, err); |
d905bb7b JQ |
985 | } |
986 | ||
544f6ea3 DDAG |
987 | void hmp_announce_self(Monitor *mon, const QDict *qdict) |
988 | { | |
08528271 | 989 | const char *interfaces_str = qdict_get_try_str(qdict, "interfaces"); |
c6644548 | 990 | const char *id = qdict_get_try_str(qdict, "id"); |
08528271 DDAG |
991 | AnnounceParameters *params = QAPI_CLONE(AnnounceParameters, |
992 | migrate_announce_params()); | |
993 | ||
994 | qapi_free_strList(params->interfaces); | |
995 | params->interfaces = strList_from_comma_list(interfaces_str); | |
996 | params->has_interfaces = params->interfaces != NULL; | |
c6644548 | 997 | params->id = g_strdup(id); |
08528271 DDAG |
998 | qmp_announce_self(params, NULL); |
999 | qapi_free_AnnounceParameters(params); | |
544f6ea3 DDAG |
1000 | } |
1001 | ||
6cdedb07 LC |
1002 | void hmp_migrate_cancel(Monitor *mon, const QDict *qdict) |
1003 | { | |
1004 | qmp_migrate_cancel(NULL); | |
1005 | } | |
4f0a993b | 1006 | |
94ae12cb DDAG |
1007 | void hmp_migrate_continue(Monitor *mon, const QDict *qdict) |
1008 | { | |
1009 | Error *err = NULL; | |
1010 | const char *state = qdict_get_str(qdict, "state"); | |
1011 | int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err); | |
1012 | ||
1013 | if (val >= 0) { | |
1014 | qmp_migrate_continue(val, &err); | |
1015 | } | |
1016 | ||
187c6147 | 1017 | hmp_handle_error(mon, err); |
94ae12cb DDAG |
1018 | } |
1019 | ||
bf1ae1f4 DDAG |
1020 | void hmp_migrate_incoming(Monitor *mon, const QDict *qdict) |
1021 | { | |
1022 | Error *err = NULL; | |
1023 | const char *uri = qdict_get_str(qdict, "uri"); | |
1024 | ||
1025 | qmp_migrate_incoming(uri, &err); | |
1026 | ||
187c6147 | 1027 | hmp_handle_error(mon, err); |
bf1ae1f4 DDAG |
1028 | } |
1029 | ||
3b563c4b PX |
1030 | void hmp_migrate_recover(Monitor *mon, const QDict *qdict) |
1031 | { | |
1032 | Error *err = NULL; | |
1033 | const char *uri = qdict_get_str(qdict, "uri"); | |
1034 | ||
1035 | qmp_migrate_recover(uri, &err); | |
1036 | ||
187c6147 | 1037 | hmp_handle_error(mon, err); |
3b563c4b PX |
1038 | } |
1039 | ||
d37297dc PX |
1040 | void hmp_migrate_pause(Monitor *mon, const QDict *qdict) |
1041 | { | |
1042 | Error *err = NULL; | |
1043 | ||
1044 | qmp_migrate_pause(&err); | |
1045 | ||
187c6147 | 1046 | hmp_handle_error(mon, err); |
d37297dc PX |
1047 | } |
1048 | ||
fbf796fd | 1049 | |
00458433 OW |
1050 | void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict) |
1051 | { | |
1052 | const char *cap = qdict_get_str(qdict, "capability"); | |
1053 | bool state = qdict_get_bool(qdict, "state"); | |
1054 | Error *err = NULL; | |
54aa3de7 EB |
1055 | MigrationCapabilityStatusList *caps = NULL; |
1056 | MigrationCapabilityStatus *value; | |
8e615e34 | 1057 | int val; |
00458433 | 1058 | |
f7abe0ec | 1059 | val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err); |
8e615e34 MAL |
1060 | if (val < 0) { |
1061 | goto end; | |
00458433 OW |
1062 | } |
1063 | ||
54aa3de7 EB |
1064 | value = g_malloc0(sizeof(*value)); |
1065 | value->capability = val; | |
1066 | value->state = state; | |
1067 | QAPI_LIST_PREPEND(caps, value); | |
8e615e34 | 1068 | qmp_migrate_set_capabilities(caps, &err); |
54aa3de7 | 1069 | qapi_free_MigrationCapabilityStatusList(caps); |
00458433 | 1070 | |
8e615e34 | 1071 | end: |
187c6147 | 1072 | hmp_handle_error(mon, err); |
00458433 OW |
1073 | } |
1074 | ||
50e9a629 LL |
1075 | void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) |
1076 | { | |
1077 | const char *param = qdict_get_str(qdict, "parameter"); | |
69ef1f36 | 1078 | const char *valuestr = qdict_get_str(qdict, "value"); |
f4a06d13 | 1079 | Visitor *v = string_input_visitor_new(valuestr); |
1bda8b3c | 1080 | MigrateSetParameters *p = g_new0(MigrateSetParameters, 1); |
f46bfdbf | 1081 | uint64_t valuebw = 0; |
73af8dd8 | 1082 | uint64_t cache_size; |
50e9a629 | 1083 | Error *err = NULL; |
262517b7 | 1084 | int val, ret; |
69ef1f36 | 1085 | |
f7abe0ec | 1086 | val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err); |
262517b7 MAL |
1087 | if (val < 0) { |
1088 | goto cleanup; | |
1089 | } | |
1090 | ||
1091 | switch (val) { | |
1092 | case MIGRATION_PARAMETER_COMPRESS_LEVEL: | |
1093 | p->has_compress_level = true; | |
ec17de0a | 1094 | visit_type_uint8(v, param, &p->compress_level, &err); |
262517b7 MAL |
1095 | break; |
1096 | case MIGRATION_PARAMETER_COMPRESS_THREADS: | |
1097 | p->has_compress_threads = true; | |
ec17de0a | 1098 | visit_type_uint8(v, param, &p->compress_threads, &err); |
262517b7 | 1099 | break; |
1d58872a XG |
1100 | case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD: |
1101 | p->has_compress_wait_thread = true; | |
1102 | visit_type_bool(v, param, &p->compress_wait_thread, &err); | |
1103 | break; | |
262517b7 MAL |
1104 | case MIGRATION_PARAMETER_DECOMPRESS_THREADS: |
1105 | p->has_decompress_threads = true; | |
ec17de0a | 1106 | visit_type_uint8(v, param, &p->decompress_threads, &err); |
262517b7 | 1107 | break; |
dc14a470 KZ |
1108 | case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD: |
1109 | p->has_throttle_trigger_threshold = true; | |
ec17de0a | 1110 | visit_type_uint8(v, param, &p->throttle_trigger_threshold, &err); |
33ee3d96 | 1111 | break; |
262517b7 MAL |
1112 | case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL: |
1113 | p->has_cpu_throttle_initial = true; | |
ec17de0a | 1114 | visit_type_uint8(v, param, &p->cpu_throttle_initial, &err); |
262517b7 MAL |
1115 | break; |
1116 | case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT: | |
1117 | p->has_cpu_throttle_increment = true; | |
ec17de0a | 1118 | visit_type_uint8(v, param, &p->cpu_throttle_increment, &err); |
262517b7 | 1119 | break; |
cbbf8182 KZ |
1120 | case MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW: |
1121 | p->has_cpu_throttle_tailslow = true; | |
1122 | visit_type_bool(v, param, &p->cpu_throttle_tailslow, &err); | |
1123 | break; | |
4cbc9c7f LQ |
1124 | case MIGRATION_PARAMETER_MAX_CPU_THROTTLE: |
1125 | p->has_max_cpu_throttle = true; | |
ec17de0a | 1126 | visit_type_uint8(v, param, &p->max_cpu_throttle, &err); |
4cbc9c7f | 1127 | break; |
262517b7 | 1128 | case MIGRATION_PARAMETER_TLS_CREDS: |
262517b7 MAL |
1129 | p->tls_creds = g_new0(StrOrNull, 1); |
1130 | p->tls_creds->type = QTYPE_QSTRING; | |
1131 | visit_type_str(v, param, &p->tls_creds->u.s, &err); | |
1132 | break; | |
1133 | case MIGRATION_PARAMETER_TLS_HOSTNAME: | |
262517b7 MAL |
1134 | p->tls_hostname = g_new0(StrOrNull, 1); |
1135 | p->tls_hostname->type = QTYPE_QSTRING; | |
1136 | visit_type_str(v, param, &p->tls_hostname->u.s, &err); | |
1137 | break; | |
d2f1d29b | 1138 | case MIGRATION_PARAMETER_TLS_AUTHZ: |
d2f1d29b DB |
1139 | p->tls_authz = g_new0(StrOrNull, 1); |
1140 | p->tls_authz->type = QTYPE_QSTRING; | |
1141 | visit_type_str(v, param, &p->tls_authz->u.s, &err); | |
1142 | break; | |
262517b7 MAL |
1143 | case MIGRATION_PARAMETER_MAX_BANDWIDTH: |
1144 | p->has_max_bandwidth = true; | |
1145 | /* | |
1146 | * Can't use visit_type_size() here, because it | |
1147 | * defaults to Bytes rather than Mebibytes. | |
1148 | */ | |
1149 | ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw); | |
1150 | if (ret < 0 || valuebw > INT64_MAX | |
1151 | || (size_t)valuebw != valuebw) { | |
1152 | error_setg(&err, "Invalid size %s", valuestr); | |
50e9a629 LL |
1153 | break; |
1154 | } | |
262517b7 MAL |
1155 | p->max_bandwidth = valuebw; |
1156 | break; | |
1157 | case MIGRATION_PARAMETER_DOWNTIME_LIMIT: | |
1158 | p->has_downtime_limit = true; | |
ec17de0a | 1159 | visit_type_size(v, param, &p->downtime_limit, &err); |
262517b7 MAL |
1160 | break; |
1161 | case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY: | |
1162 | p->has_x_checkpoint_delay = true; | |
ec17de0a | 1163 | visit_type_uint32(v, param, &p->x_checkpoint_delay, &err); |
262517b7 MAL |
1164 | break; |
1165 | case MIGRATION_PARAMETER_BLOCK_INCREMENTAL: | |
1166 | p->has_block_incremental = true; | |
1167 | visit_type_bool(v, param, &p->block_incremental, &err); | |
1168 | break; | |
cbfd6c95 JQ |
1169 | case MIGRATION_PARAMETER_MULTIFD_CHANNELS: |
1170 | p->has_multifd_channels = true; | |
ec17de0a | 1171 | visit_type_uint8(v, param, &p->multifd_channels, &err); |
4075fb1c | 1172 | break; |
96eef042 JQ |
1173 | case MIGRATION_PARAMETER_MULTIFD_COMPRESSION: |
1174 | p->has_multifd_compression = true; | |
3c4b89c3 MA |
1175 | visit_type_MultiFDCompression(v, param, &p->multifd_compression, |
1176 | &err); | |
96eef042 | 1177 | break; |
9004db48 JQ |
1178 | case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL: |
1179 | p->has_multifd_zlib_level = true; | |
ec17de0a | 1180 | visit_type_uint8(v, param, &p->multifd_zlib_level, &err); |
9004db48 | 1181 | break; |
6a9ad154 JQ |
1182 | case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL: |
1183 | p->has_multifd_zstd_level = true; | |
ec17de0a | 1184 | visit_type_uint8(v, param, &p->multifd_zstd_level, &err); |
6a9ad154 | 1185 | break; |
73af8dd8 JQ |
1186 | case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE: |
1187 | p->has_xbzrle_cache_size = true; | |
62a35aaa | 1188 | if (!visit_type_size(v, param, &cache_size, &err)) { |
d013283a JQ |
1189 | break; |
1190 | } | |
1191 | if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) { | |
73af8dd8 JQ |
1192 | error_setg(&err, "Invalid size %s", valuestr); |
1193 | break; | |
1194 | } | |
1195 | p->xbzrle_cache_size = cache_size; | |
1196 | break; | |
7e555c6c DDAG |
1197 | case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH: |
1198 | p->has_max_postcopy_bandwidth = true; | |
1199 | visit_type_size(v, param, &p->max_postcopy_bandwidth, &err); | |
1200 | break; | |
ee3d96ba DDAG |
1201 | case MIGRATION_PARAMETER_ANNOUNCE_INITIAL: |
1202 | p->has_announce_initial = true; | |
1203 | visit_type_size(v, param, &p->announce_initial, &err); | |
1204 | break; | |
1205 | case MIGRATION_PARAMETER_ANNOUNCE_MAX: | |
1206 | p->has_announce_max = true; | |
1207 | visit_type_size(v, param, &p->announce_max, &err); | |
1208 | break; | |
1209 | case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS: | |
1210 | p->has_announce_rounds = true; | |
1211 | visit_type_size(v, param, &p->announce_rounds, &err); | |
1212 | break; | |
1213 | case MIGRATION_PARAMETER_ANNOUNCE_STEP: | |
1214 | p->has_announce_step = true; | |
1215 | visit_type_size(v, param, &p->announce_step, &err); | |
1216 | break; | |
31e4c354 HR |
1217 | case MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING: |
1218 | error_setg(&err, "The block-bitmap-mapping parameter can only be set " | |
1219 | "through QMP"); | |
1220 | break; | |
262517b7 MAL |
1221 | default: |
1222 | assert(0); | |
50e9a629 LL |
1223 | } |
1224 | ||
262517b7 MAL |
1225 | if (err) { |
1226 | goto cleanup; | |
50e9a629 LL |
1227 | } |
1228 | ||
262517b7 MAL |
1229 | qmp_migrate_set_parameters(p, &err); |
1230 | ||
69ef1f36 | 1231 | cleanup: |
1bda8b3c | 1232 | qapi_free_MigrateSetParameters(p); |
f4a06d13 | 1233 | visit_free(v); |
187c6147 | 1234 | hmp_handle_error(mon, err); |
50e9a629 LL |
1235 | } |
1236 | ||
b8a185bc MA |
1237 | void hmp_client_migrate_info(Monitor *mon, const QDict *qdict) |
1238 | { | |
1239 | Error *err = NULL; | |
1240 | const char *protocol = qdict_get_str(qdict, "protocol"); | |
1241 | const char *hostname = qdict_get_str(qdict, "hostname"); | |
1242 | bool has_port = qdict_haskey(qdict, "port"); | |
1243 | int port = qdict_get_try_int(qdict, "port", -1); | |
1244 | bool has_tls_port = qdict_haskey(qdict, "tls-port"); | |
1245 | int tls_port = qdict_get_try_int(qdict, "tls-port", -1); | |
1246 | const char *cert_subject = qdict_get_try_str(qdict, "cert-subject"); | |
1247 | ||
1248 | qmp_client_migrate_info(protocol, hostname, | |
1249 | has_port, port, has_tls_port, tls_port, | |
720a252c | 1250 | cert_subject, &err); |
187c6147 | 1251 | hmp_handle_error(mon, err); |
b8a185bc MA |
1252 | } |
1253 | ||
4886a1bc DDAG |
1254 | void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict) |
1255 | { | |
1256 | Error *err = NULL; | |
1257 | qmp_migrate_start_postcopy(&err); | |
187c6147 | 1258 | hmp_handle_error(mon, err); |
4886a1bc DDAG |
1259 | } |
1260 | ||
d89e666e HZ |
1261 | void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict) |
1262 | { | |
1263 | Error *err = NULL; | |
1264 | ||
1265 | qmp_x_colo_lost_heartbeat(&err); | |
187c6147 | 1266 | hmp_handle_error(mon, err); |
d89e666e HZ |
1267 | } |
1268 | ||
fbf796fd LC |
1269 | void hmp_set_password(Monitor *mon, const QDict *qdict) |
1270 | { | |
1271 | const char *protocol = qdict_get_str(qdict, "protocol"); | |
1272 | const char *password = qdict_get_str(qdict, "password"); | |
675fd3c9 | 1273 | const char *display = qdict_get_try_str(qdict, "display"); |
fbf796fd LC |
1274 | const char *connected = qdict_get_try_str(qdict, "connected"); |
1275 | Error *err = NULL; | |
1276 | ||
675fd3c9 SR |
1277 | SetPasswordOptions opts = { |
1278 | .password = (char *)password, | |
1279 | .has_connected = !!connected, | |
1280 | }; | |
1281 | ||
1282 | opts.connected = qapi_enum_parse(&SetPasswordAction_lookup, connected, | |
1283 | SET_PASSWORD_ACTION_KEEP, &err); | |
7277db91 SR |
1284 | if (err) { |
1285 | goto out; | |
1286 | } | |
1287 | ||
675fd3c9 SR |
1288 | opts.protocol = qapi_enum_parse(&DisplayProtocol_lookup, protocol, |
1289 | DISPLAY_PROTOCOL_VNC, &err); | |
7277db91 SR |
1290 | if (err) { |
1291 | goto out; | |
1292 | } | |
1293 | ||
675fd3c9 | 1294 | if (opts.protocol == DISPLAY_PROTOCOL_VNC) { |
675fd3c9 SR |
1295 | opts.u.vnc.display = (char *)display; |
1296 | } | |
1297 | ||
1298 | qmp_set_password(&opts, &err); | |
7277db91 SR |
1299 | |
1300 | out: | |
187c6147 | 1301 | hmp_handle_error(mon, err); |
fbf796fd | 1302 | } |
9ad5372d LC |
1303 | |
1304 | void hmp_expire_password(Monitor *mon, const QDict *qdict) | |
1305 | { | |
1306 | const char *protocol = qdict_get_str(qdict, "protocol"); | |
1307 | const char *whenstr = qdict_get_str(qdict, "time"); | |
675fd3c9 | 1308 | const char *display = qdict_get_try_str(qdict, "display"); |
9ad5372d | 1309 | Error *err = NULL; |
7277db91 | 1310 | |
675fd3c9 SR |
1311 | ExpirePasswordOptions opts = { |
1312 | .time = (char *)whenstr, | |
1313 | }; | |
1314 | ||
1315 | opts.protocol = qapi_enum_parse(&DisplayProtocol_lookup, protocol, | |
1316 | DISPLAY_PROTOCOL_VNC, &err); | |
7277db91 SR |
1317 | if (err) { |
1318 | goto out; | |
1319 | } | |
9ad5372d | 1320 | |
675fd3c9 | 1321 | if (opts.protocol == DISPLAY_PROTOCOL_VNC) { |
675fd3c9 SR |
1322 | opts.u.vnc.display = (char *)display; |
1323 | } | |
1324 | ||
1325 | qmp_expire_password(&opts, &err); | |
7277db91 SR |
1326 | |
1327 | out: | |
187c6147 | 1328 | hmp_handle_error(mon, err); |
9ad5372d | 1329 | } |
c245b6a3 | 1330 | |
333a96ec | 1331 | |
05eb4a25 | 1332 | #ifdef CONFIG_VNC |
c60bf339 SH |
1333 | static void hmp_change_read_arg(void *opaque, const char *password, |
1334 | void *readline_opaque) | |
333a96ec LC |
1335 | { |
1336 | qmp_change_vnc_password(password, NULL); | |
c60bf339 | 1337 | monitor_read_command(opaque, 1); |
333a96ec | 1338 | } |
05eb4a25 | 1339 | #endif |
333a96ec | 1340 | |
333a96ec LC |
1341 | void hmp_change(Monitor *mon, const QDict *qdict) |
1342 | { | |
1343 | const char *device = qdict_get_str(qdict, "device"); | |
1344 | const char *target = qdict_get_str(qdict, "target"); | |
1345 | const char *arg = qdict_get_try_str(qdict, "arg"); | |
baead0ab | 1346 | const char *read_only = qdict_get_try_str(qdict, "read-only-mode"); |
80dd5aff | 1347 | bool force = qdict_get_try_bool(qdict, "force", false); |
baead0ab | 1348 | BlockdevChangeReadOnlyMode read_only_mode = 0; |
333a96ec LC |
1349 | Error *err = NULL; |
1350 | ||
05eb4a25 | 1351 | #ifdef CONFIG_VNC |
10686749 | 1352 | if (strcmp(device, "vnc") == 0) { |
baead0ab HR |
1353 | if (read_only) { |
1354 | monitor_printf(mon, | |
1355 | "Parameter 'read-only-mode' is invalid for VNC\n"); | |
1356 | return; | |
1357 | } | |
10686749 HR |
1358 | if (strcmp(target, "passwd") == 0 || |
1359 | strcmp(target, "password") == 0) { | |
6193344f | 1360 | if (!arg) { |
ea73f370 | 1361 | MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common); |
5f9dba16 | 1362 | monitor_read_password(hmp_mon, hmp_change_read_arg, NULL); |
10686749 | 1363 | return; |
cfb5387a PB |
1364 | } else { |
1365 | qmp_change_vnc_password(arg, &err); | |
10686749 | 1366 | } |
cfb5387a PB |
1367 | } else { |
1368 | monitor_printf(mon, "Expected 'password' after 'vnc'\n"); | |
10686749 | 1369 | } |
05eb4a25 MAL |
1370 | } else |
1371 | #endif | |
1372 | { | |
baead0ab HR |
1373 | if (read_only) { |
1374 | read_only_mode = | |
f7abe0ec | 1375 | qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup, |
06c60b6c | 1376 | read_only, |
baead0ab HR |
1377 | BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err); |
1378 | if (err) { | |
ac9c95b1 | 1379 | goto end; |
baead0ab HR |
1380 | } |
1381 | } | |
1382 | ||
54fde4ff | 1383 | qmp_blockdev_change_medium(device, NULL, target, arg, true, force, |
80dd5aff | 1384 | !!read_only, read_only_mode, |
70e2cb3b | 1385 | &err); |
333a96ec LC |
1386 | } |
1387 | ||
ac9c95b1 | 1388 | end: |
187c6147 | 1389 | hmp_handle_error(mon, err); |
333a96ec | 1390 | } |
80047da5 | 1391 | |
d22b854d | 1392 | typedef struct HMPMigrationStatus { |
e1c37d0e LC |
1393 | QEMUTimer *timer; |
1394 | Monitor *mon; | |
1395 | bool is_block_migration; | |
e49f35bd | 1396 | } HMPMigrationStatus; |
e1c37d0e LC |
1397 | |
1398 | static void hmp_migrate_status_cb(void *opaque) | |
1399 | { | |
e49f35bd | 1400 | HMPMigrationStatus *status = opaque; |
e1c37d0e LC |
1401 | MigrationInfo *info; |
1402 | ||
1403 | info = qmp_query_migrate(NULL); | |
24b8c39b HZ |
1404 | if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE || |
1405 | info->status == MIGRATION_STATUS_SETUP) { | |
720a252c | 1406 | if (info->disk) { |
e1c37d0e LC |
1407 | int progress; |
1408 | ||
1409 | if (info->disk->remaining) { | |
1410 | progress = info->disk->transferred * 100 / info->disk->total; | |
1411 | } else { | |
1412 | progress = 100; | |
1413 | } | |
1414 | ||
1415 | monitor_printf(status->mon, "Completed %d %%\r", progress); | |
1416 | monitor_flush(status->mon); | |
1417 | } | |
1418 | ||
bc72ad67 | 1419 | timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000); |
e1c37d0e LC |
1420 | } else { |
1421 | if (status->is_block_migration) { | |
1422 | monitor_printf(status->mon, "\n"); | |
1423 | } | |
720a252c | 1424 | if (info->error_desc) { |
d59ce6f3 DB |
1425 | error_report("%s", info->error_desc); |
1426 | } | |
e1c37d0e | 1427 | monitor_resume(status->mon); |
d34a10af | 1428 | timer_free(status->timer); |
e1c37d0e LC |
1429 | g_free(status); |
1430 | } | |
1431 | ||
1432 | qapi_free_MigrationInfo(info); | |
1433 | } | |
1434 | ||
1435 | void hmp_migrate(Monitor *mon, const QDict *qdict) | |
1436 | { | |
34acbc95 EB |
1437 | bool detach = qdict_get_try_bool(qdict, "detach", false); |
1438 | bool blk = qdict_get_try_bool(qdict, "blk", false); | |
1439 | bool inc = qdict_get_try_bool(qdict, "inc", false); | |
7a4da28b | 1440 | bool resume = qdict_get_try_bool(qdict, "resume", false); |
e1c37d0e LC |
1441 | const char *uri = qdict_get_str(qdict, "uri"); |
1442 | Error *err = NULL; | |
1443 | ||
7a4da28b PX |
1444 | qmp_migrate(uri, !!blk, blk, !!inc, inc, |
1445 | false, false, true, resume, &err); | |
0ca117a7 | 1446 | if (hmp_handle_error(mon, err)) { |
e1c37d0e LC |
1447 | return; |
1448 | } | |
1449 | ||
1450 | if (!detach) { | |
e49f35bd | 1451 | HMPMigrationStatus *status; |
e1c37d0e LC |
1452 | |
1453 | if (monitor_suspend(mon) < 0) { | |
1454 | monitor_printf(mon, "terminal does not allow synchronous " | |
1455 | "migration, continuing detached\n"); | |
1456 | return; | |
1457 | } | |
1458 | ||
1459 | status = g_malloc0(sizeof(*status)); | |
1460 | status->mon = mon; | |
1461 | status->is_block_migration = blk || inc; | |
bc72ad67 | 1462 | status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb, |
e1c37d0e | 1463 | status); |
bc72ad67 | 1464 | timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME)); |
e1c37d0e LC |
1465 | } |
1466 | } | |
a15fef21 | 1467 | |
928059a3 LC |
1468 | void hmp_netdev_add(Monitor *mon, const QDict *qdict) |
1469 | { | |
1470 | Error *err = NULL; | |
1471 | QemuOpts *opts; | |
ad6f932f | 1472 | const char *type = qdict_get_try_str(qdict, "type"); |
928059a3 | 1473 | |
ad6f932f PB |
1474 | if (type && is_help_option(type)) { |
1475 | show_netdevs(); | |
1476 | return; | |
1477 | } | |
928059a3 | 1478 | opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err); |
84d18f06 | 1479 | if (err) { |
928059a3 LC |
1480 | goto out; |
1481 | } | |
1482 | ||
1483 | netdev_add(opts, &err); | |
84d18f06 | 1484 | if (err) { |
928059a3 LC |
1485 | qemu_opts_del(opts); |
1486 | } | |
1487 | ||
1488 | out: | |
187c6147 | 1489 | hmp_handle_error(mon, err); |
928059a3 | 1490 | } |
5f964155 LC |
1491 | |
1492 | void hmp_netdev_del(Monitor *mon, const QDict *qdict) | |
1493 | { | |
1494 | const char *id = qdict_get_str(qdict, "id"); | |
1495 | Error *err = NULL; | |
1496 | ||
1497 | qmp_netdev_del(id, &err); | |
187c6147 | 1498 | hmp_handle_error(mon, err); |
5f964155 | 1499 | } |
208c9d1b | 1500 | |
cff8b2c6 PB |
1501 | void hmp_object_add(Monitor *mon, const QDict *qdict) |
1502 | { | |
da0a932b | 1503 | const char *options = qdict_get_str(qdict, "object"); |
cff8b2c6 | 1504 | Error *err = NULL; |
cff8b2c6 | 1505 | |
da0a932b | 1506 | user_creatable_add_from_str(options, &err); |
0705ecc4 | 1507 | hmp_handle_error(mon, err); |
cff8b2c6 PB |
1508 | } |
1509 | ||
208c9d1b CB |
1510 | void hmp_getfd(Monitor *mon, const QDict *qdict) |
1511 | { | |
1512 | const char *fdname = qdict_get_str(qdict, "fdname"); | |
e940f543 | 1513 | Error *err = NULL; |
208c9d1b | 1514 | |
e940f543 | 1515 | qmp_getfd(fdname, &err); |
187c6147 | 1516 | hmp_handle_error(mon, err); |
208c9d1b CB |
1517 | } |
1518 | ||
1519 | void hmp_closefd(Monitor *mon, const QDict *qdict) | |
1520 | { | |
1521 | const char *fdname = qdict_get_str(qdict, "fdname"); | |
e940f543 | 1522 | Error *err = NULL; |
208c9d1b | 1523 | |
e940f543 | 1524 | qmp_closefd(fdname, &err); |
187c6147 | 1525 | hmp_handle_error(mon, err); |
208c9d1b | 1526 | } |
e4c8f004 | 1527 | |
3e5a50d6 | 1528 | void hmp_sendkey(Monitor *mon, const QDict *qdict) |
e4c8f004 AK |
1529 | { |
1530 | const char *keys = qdict_get_str(qdict, "keys"); | |
95b3a8c8 EB |
1531 | KeyValue *v = NULL; |
1532 | KeyValueList *head = NULL, **tail = &head; | |
e4c8f004 AK |
1533 | int has_hold_time = qdict_haskey(qdict, "hold-time"); |
1534 | int hold_time = qdict_get_try_int(qdict, "hold-time", -1); | |
1535 | Error *err = NULL; | |
5c99fa37 | 1536 | const char *separator; |
9f328977 | 1537 | int keyname_len; |
e4c8f004 AK |
1538 | |
1539 | while (1) { | |
5c99fa37 KF |
1540 | separator = qemu_strchrnul(keys, '-'); |
1541 | keyname_len = separator - keys; | |
e4c8f004 AK |
1542 | |
1543 | /* Be compatible with old interface, convert user inputted "<" */ | |
64ffbe04 WB |
1544 | if (keys[0] == '<' && keyname_len == 1) { |
1545 | keys = "less"; | |
e4c8f004 AK |
1546 | keyname_len = 4; |
1547 | } | |
e4c8f004 | 1548 | |
95b3a8c8 | 1549 | v = g_malloc0(sizeof(*v)); |
e4c8f004 | 1550 | |
64ffbe04 | 1551 | if (strstart(keys, "0x", NULL)) { |
9f328977 | 1552 | char *endp; |
64ffbe04 WB |
1553 | int value = strtoul(keys, &endp, 0); |
1554 | assert(endp <= keys + keyname_len); | |
1555 | if (endp != keys + keyname_len) { | |
9f328977 LC |
1556 | goto err_out; |
1557 | } | |
95b3a8c8 EB |
1558 | v->type = KEY_VALUE_KIND_NUMBER; |
1559 | v->u.number.data = value; | |
9f328977 | 1560 | } else { |
64ffbe04 | 1561 | int idx = index_from_key(keys, keyname_len); |
7fb1cf16 | 1562 | if (idx == Q_KEY_CODE__MAX) { |
9f328977 LC |
1563 | goto err_out; |
1564 | } | |
95b3a8c8 EB |
1565 | v->type = KEY_VALUE_KIND_QCODE; |
1566 | v->u.qcode.data = idx; | |
9f328977 | 1567 | } |
95b3a8c8 EB |
1568 | QAPI_LIST_APPEND(tail, v); |
1569 | v = NULL; | |
9f328977 | 1570 | |
5c99fa37 | 1571 | if (!*separator) { |
e4c8f004 AK |
1572 | break; |
1573 | } | |
1574 | keys = separator + 1; | |
1575 | } | |
1576 | ||
9f328977 | 1577 | qmp_send_key(head, has_hold_time, hold_time, &err); |
187c6147 | 1578 | hmp_handle_error(mon, err); |
9f328977 LC |
1579 | |
1580 | out: | |
95b3a8c8 | 1581 | qapi_free_KeyValue(v); |
9f328977 LC |
1582 | qapi_free_KeyValueList(head); |
1583 | return; | |
1584 | ||
1585 | err_out: | |
64ffbe04 | 1586 | monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys); |
9f328977 | 1587 | goto out; |
e4c8f004 | 1588 | } |
ad39cf6d | 1589 | |
0d9b90ce MAL |
1590 | void coroutine_fn |
1591 | hmp_screendump(Monitor *mon, const QDict *qdict) | |
ad39cf6d LC |
1592 | { |
1593 | const char *filename = qdict_get_str(qdict, "filename"); | |
f771c544 TH |
1594 | const char *id = qdict_get_try_str(qdict, "device"); |
1595 | int64_t head = qdict_get_try_int(qdict, "head", 0); | |
9a0a119a | 1596 | const char *input_format = qdict_get_try_str(qdict, "format"); |
ad39cf6d | 1597 | Error *err = NULL; |
9a0a119a | 1598 | ImageFormat format; |
ad39cf6d | 1599 | |
9a0a119a KS |
1600 | format = qapi_enum_parse(&ImageFormat_lookup, input_format, |
1601 | IMAGE_FORMAT_PPM, &err); | |
1602 | if (err) { | |
1603 | goto end; | |
1604 | } | |
1605 | ||
3f41a3ad | 1606 | qmp_screendump(filename, id, id != NULL, head, |
9a0a119a KS |
1607 | input_format != NULL, format, &err); |
1608 | end: | |
187c6147 | 1609 | hmp_handle_error(mon, err); |
ad39cf6d | 1610 | } |
4057725f | 1611 | |
f1088908 GH |
1612 | void hmp_chardev_add(Monitor *mon, const QDict *qdict) |
1613 | { | |
1614 | const char *args = qdict_get_str(qdict, "args"); | |
1615 | Error *err = NULL; | |
1616 | QemuOpts *opts; | |
1617 | ||
70b94331 | 1618 | opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true); |
f1088908 | 1619 | if (opts == NULL) { |
312fd5f2 | 1620 | error_setg(&err, "Parsing chardev args failed"); |
f1088908 | 1621 | } else { |
4ad6f6cb | 1622 | qemu_chr_new_from_opts(opts, NULL, &err); |
0a73336d | 1623 | qemu_opts_del(opts); |
f1088908 | 1624 | } |
187c6147 | 1625 | hmp_handle_error(mon, err); |
f1088908 GH |
1626 | } |
1627 | ||
75b60160 AN |
1628 | void hmp_chardev_change(Monitor *mon, const QDict *qdict) |
1629 | { | |
1630 | const char *args = qdict_get_str(qdict, "args"); | |
1631 | const char *id; | |
1632 | Error *err = NULL; | |
1633 | ChardevBackend *backend = NULL; | |
1634 | ChardevReturn *ret = NULL; | |
1635 | QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, | |
1636 | true); | |
1637 | if (!opts) { | |
1638 | error_setg(&err, "Parsing chardev args failed"); | |
1639 | goto end; | |
1640 | } | |
1641 | ||
1642 | id = qdict_get_str(qdict, "id"); | |
1643 | if (qemu_opts_id(opts)) { | |
1644 | error_setg(&err, "Unexpected 'id' parameter"); | |
1645 | goto end; | |
1646 | } | |
1647 | ||
1648 | backend = qemu_chr_parse_opts(opts, &err); | |
1649 | if (!backend) { | |
1650 | goto end; | |
1651 | } | |
1652 | ||
1653 | ret = qmp_chardev_change(id, backend, &err); | |
1654 | ||
1655 | end: | |
1656 | qapi_free_ChardevReturn(ret); | |
1657 | qapi_free_ChardevBackend(backend); | |
1658 | qemu_opts_del(opts); | |
187c6147 | 1659 | hmp_handle_error(mon, err); |
75b60160 AN |
1660 | } |
1661 | ||
f1088908 GH |
1662 | void hmp_chardev_remove(Monitor *mon, const QDict *qdict) |
1663 | { | |
1664 | Error *local_err = NULL; | |
1665 | ||
1666 | qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err); | |
187c6147 | 1667 | hmp_handle_error(mon, local_err); |
f1088908 | 1668 | } |
587da2c3 | 1669 | |
bd1d5ad9 SF |
1670 | void hmp_chardev_send_break(Monitor *mon, const QDict *qdict) |
1671 | { | |
1672 | Error *local_err = NULL; | |
1673 | ||
1674 | qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err); | |
187c6147 | 1675 | hmp_handle_error(mon, local_err); |
bd1d5ad9 SF |
1676 | } |
1677 | ||
ab2d0531 PB |
1678 | void hmp_object_del(Monitor *mon, const QDict *qdict) |
1679 | { | |
1680 | const char *id = qdict_get_str(qdict, "id"); | |
1681 | Error *err = NULL; | |
1682 | ||
90998d58 | 1683 | user_creatable_del(id, &err); |
187c6147 | 1684 | hmp_handle_error(mon, err); |
ab2d0531 | 1685 | } |
eb1539b2 | 1686 | |
a631892f ZG |
1687 | void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) |
1688 | { | |
1689 | Error *err = NULL; | |
1690 | MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err); | |
1691 | MemoryDeviceInfoList *info; | |
d766b22b | 1692 | VirtioPMEMDeviceInfo *vpi; |
2e70874b | 1693 | VirtioMEMDeviceInfo *vmi; |
a631892f ZG |
1694 | MemoryDeviceInfo *value; |
1695 | PCDIMMDeviceInfo *di; | |
a7c565a9 | 1696 | SgxEPCDeviceInfo *se; |
a631892f ZG |
1697 | |
1698 | for (info = info_list; info; info = info->next) { | |
1699 | value = info->value; | |
1700 | ||
1701 | if (value) { | |
1fd5d4fe | 1702 | switch (value->type) { |
a631892f | 1703 | case MEMORY_DEVICE_INFO_KIND_DIMM: |
6388e18d | 1704 | case MEMORY_DEVICE_INFO_KIND_NVDIMM: |
d766b22b DH |
1705 | di = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ? |
1706 | value->u.dimm.data : value->u.nvdimm.data; | |
a631892f | 1707 | monitor_printf(mon, "Memory device [%s]: \"%s\"\n", |
977c736f | 1708 | MemoryDeviceInfoKind_str(value->type), |
a631892f ZG |
1709 | di->id ? di->id : ""); |
1710 | monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr); | |
1711 | monitor_printf(mon, " slot: %" PRId64 "\n", di->slot); | |
1712 | monitor_printf(mon, " node: %" PRId64 "\n", di->node); | |
1713 | monitor_printf(mon, " size: %" PRIu64 "\n", di->size); | |
1714 | monitor_printf(mon, " memdev: %s\n", di->memdev); | |
1715 | monitor_printf(mon, " hotplugged: %s\n", | |
1716 | di->hotplugged ? "true" : "false"); | |
1717 | monitor_printf(mon, " hotpluggable: %s\n", | |
1718 | di->hotpluggable ? "true" : "false"); | |
d766b22b DH |
1719 | break; |
1720 | case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM: | |
1721 | vpi = value->u.virtio_pmem.data; | |
1722 | monitor_printf(mon, "Memory device [%s]: \"%s\"\n", | |
1723 | MemoryDeviceInfoKind_str(value->type), | |
1724 | vpi->id ? vpi->id : ""); | |
1725 | monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->memaddr); | |
1726 | monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size); | |
1727 | monitor_printf(mon, " memdev: %s\n", vpi->memdev); | |
1728 | break; | |
2e70874b DH |
1729 | case MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM: |
1730 | vmi = value->u.virtio_mem.data; | |
1731 | monitor_printf(mon, "Memory device [%s]: \"%s\"\n", | |
1732 | MemoryDeviceInfoKind_str(value->type), | |
1733 | vmi->id ? vmi->id : ""); | |
1734 | monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vmi->memaddr); | |
1735 | monitor_printf(mon, " node: %" PRId64 "\n", vmi->node); | |
1736 | monitor_printf(mon, " requested-size: %" PRIu64 "\n", | |
1737 | vmi->requested_size); | |
1738 | monitor_printf(mon, " size: %" PRIu64 "\n", vmi->size); | |
1739 | monitor_printf(mon, " max-size: %" PRIu64 "\n", vmi->max_size); | |
1740 | monitor_printf(mon, " block-size: %" PRIu64 "\n", | |
1741 | vmi->block_size); | |
1742 | monitor_printf(mon, " memdev: %s\n", vmi->memdev); | |
1743 | break; | |
a7c565a9 YZ |
1744 | case MEMORY_DEVICE_INFO_KIND_SGX_EPC: |
1745 | se = value->u.sgx_epc.data; | |
1746 | monitor_printf(mon, "Memory device [%s]: \"%s\"\n", | |
1747 | MemoryDeviceInfoKind_str(value->type), | |
1748 | se->id ? se->id : ""); | |
1749 | monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", se->memaddr); | |
1750 | monitor_printf(mon, " size: %" PRIu64 "\n", se->size); | |
11058123 | 1751 | monitor_printf(mon, " node: %" PRId64 "\n", se->node); |
a7c565a9 YZ |
1752 | monitor_printf(mon, " memdev: %s\n", se->memdev); |
1753 | break; | |
d766b22b DH |
1754 | default: |
1755 | g_assert_not_reached(); | |
a631892f ZG |
1756 | } |
1757 | } | |
1758 | } | |
1759 | ||
1760 | qapi_free_MemoryDeviceInfoList(info_list); | |
187c6147 | 1761 | hmp_handle_error(mon, err); |
a631892f | 1762 | } |
89d7fa9e | 1763 | |
62313160 TW |
1764 | void hmp_info_iothreads(Monitor *mon, const QDict *qdict) |
1765 | { | |
1766 | IOThreadInfoList *info_list = qmp_query_iothreads(NULL); | |
1767 | IOThreadInfoList *info; | |
5fc00480 | 1768 | IOThreadInfo *value; |
62313160 TW |
1769 | |
1770 | for (info = info_list; info; info = info->next) { | |
5fc00480 PH |
1771 | value = info->value; |
1772 | monitor_printf(mon, "%s:\n", value->id); | |
1773 | monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id); | |
1774 | monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns); | |
1775 | monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow); | |
1776 | monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink); | |
1793ad02 SG |
1777 | monitor_printf(mon, " aio-max-batch=%" PRId64 "\n", |
1778 | value->aio_max_batch); | |
62313160 TW |
1779 | } |
1780 | ||
1781 | qapi_free_IOThreadInfoList(info_list); | |
1782 | } | |
1783 | ||
fafa4d50 SF |
1784 | void hmp_rocker(Monitor *mon, const QDict *qdict) |
1785 | { | |
1786 | const char *name = qdict_get_str(qdict, "name"); | |
1787 | RockerSwitch *rocker; | |
533fdaed | 1788 | Error *err = NULL; |
fafa4d50 | 1789 | |
533fdaed | 1790 | rocker = qmp_query_rocker(name, &err); |
0ca117a7 | 1791 | if (hmp_handle_error(mon, err)) { |
fafa4d50 SF |
1792 | return; |
1793 | } | |
1794 | ||
1795 | monitor_printf(mon, "name: %s\n", rocker->name); | |
1796 | monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id); | |
1797 | monitor_printf(mon, "ports: %d\n", rocker->ports); | |
1798 | ||
1799 | qapi_free_RockerSwitch(rocker); | |
1800 | } | |
1801 | ||
1802 | void hmp_rocker_ports(Monitor *mon, const QDict *qdict) | |
1803 | { | |
1804 | RockerPortList *list, *port; | |
1805 | const char *name = qdict_get_str(qdict, "name"); | |
533fdaed | 1806 | Error *err = NULL; |
fafa4d50 | 1807 | |
533fdaed | 1808 | list = qmp_query_rocker_ports(name, &err); |
0ca117a7 | 1809 | if (hmp_handle_error(mon, err)) { |
fafa4d50 SF |
1810 | return; |
1811 | } | |
1812 | ||
1813 | monitor_printf(mon, " ena/ speed/ auto\n"); | |
1814 | monitor_printf(mon, " port link duplex neg?\n"); | |
1815 | ||
1816 | for (port = list; port; port = port->next) { | |
61848717 | 1817 | monitor_printf(mon, "%10s %-4s %-3s %2s %s\n", |
fafa4d50 SF |
1818 | port->value->name, |
1819 | port->value->enabled ? port->value->link_up ? | |
1820 | "up" : "down" : "!ena", | |
1821 | port->value->speed == 10000 ? "10G" : "??", | |
1822 | port->value->duplex ? "FD" : "HD", | |
1823 | port->value->autoneg ? "Yes" : "No"); | |
1824 | } | |
1825 | ||
1826 | qapi_free_RockerPortList(list); | |
1827 | } | |
1828 | ||
1829 | void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict) | |
1830 | { | |
1831 | RockerOfDpaFlowList *list, *info; | |
1832 | const char *name = qdict_get_str(qdict, "name"); | |
1833 | uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1); | |
533fdaed | 1834 | Error *err = NULL; |
fafa4d50 | 1835 | |
533fdaed | 1836 | list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err); |
0ca117a7 | 1837 | if (hmp_handle_error(mon, err)) { |
fafa4d50 SF |
1838 | return; |
1839 | } | |
1840 | ||
1841 | monitor_printf(mon, "prio tbl hits key(mask) --> actions\n"); | |
1842 | ||
1843 | for (info = list; info; info = info->next) { | |
1844 | RockerOfDpaFlow *flow = info->value; | |
1845 | RockerOfDpaFlowKey *key = flow->key; | |
1846 | RockerOfDpaFlowMask *mask = flow->mask; | |
1847 | RockerOfDpaFlowAction *action = flow->action; | |
1848 | ||
1849 | if (flow->hits) { | |
1850 | monitor_printf(mon, "%-4d %-3d %-4" PRIu64, | |
1851 | key->priority, key->tbl_id, flow->hits); | |
1852 | } else { | |
1853 | monitor_printf(mon, "%-4d %-3d ", | |
1854 | key->priority, key->tbl_id); | |
1855 | } | |
1856 | ||
1857 | if (key->has_in_pport) { | |
1858 | monitor_printf(mon, " pport %d", key->in_pport); | |
1859 | if (mask->has_in_pport) { | |
1860 | monitor_printf(mon, "(0x%x)", mask->in_pport); | |
1861 | } | |
1862 | } | |
1863 | ||
1864 | if (key->has_vlan_id) { | |
1865 | monitor_printf(mon, " vlan %d", | |
1866 | key->vlan_id & VLAN_VID_MASK); | |
1867 | if (mask->has_vlan_id) { | |
1868 | monitor_printf(mon, "(0x%x)", mask->vlan_id); | |
1869 | } | |
1870 | } | |
1871 | ||
1872 | if (key->has_tunnel_id) { | |
1873 | monitor_printf(mon, " tunnel %d", key->tunnel_id); | |
1874 | if (mask->has_tunnel_id) { | |
1875 | monitor_printf(mon, "(0x%x)", mask->tunnel_id); | |
1876 | } | |
1877 | } | |
1878 | ||
1879 | if (key->has_eth_type) { | |
1880 | switch (key->eth_type) { | |
1881 | case 0x0806: | |
1882 | monitor_printf(mon, " ARP"); | |
1883 | break; | |
1884 | case 0x0800: | |
1885 | monitor_printf(mon, " IP"); | |
1886 | break; | |
1887 | case 0x86dd: | |
1888 | monitor_printf(mon, " IPv6"); | |
1889 | break; | |
1890 | case 0x8809: | |
1891 | monitor_printf(mon, " LACP"); | |
1892 | break; | |
1893 | case 0x88cc: | |
1894 | monitor_printf(mon, " LLDP"); | |
1895 | break; | |
1896 | default: | |
1897 | monitor_printf(mon, " eth type 0x%04x", key->eth_type); | |
1898 | break; | |
1899 | } | |
1900 | } | |
1901 | ||
05e07488 | 1902 | if (key->eth_src) { |
fafa4d50 | 1903 | if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) && |
05e07488 | 1904 | mask->eth_src && |
fafa4d50 SF |
1905 | (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { |
1906 | monitor_printf(mon, " src <any mcast/bcast>"); | |
1907 | } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) && | |
05e07488 | 1908 | mask->eth_src && |
fafa4d50 SF |
1909 | (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { |
1910 | monitor_printf(mon, " src <any ucast>"); | |
1911 | } else { | |
1912 | monitor_printf(mon, " src %s", key->eth_src); | |
05e07488 | 1913 | if (mask->eth_src) { |
fafa4d50 SF |
1914 | monitor_printf(mon, "(%s)", mask->eth_src); |
1915 | } | |
1916 | } | |
1917 | } | |
1918 | ||
05e07488 | 1919 | if (key->eth_dst) { |
fafa4d50 | 1920 | if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) && |
05e07488 | 1921 | mask->eth_dst && |
fafa4d50 SF |
1922 | (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { |
1923 | monitor_printf(mon, " dst <any mcast/bcast>"); | |
1924 | } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) && | |
05e07488 | 1925 | mask->eth_dst && |
fafa4d50 SF |
1926 | (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { |
1927 | monitor_printf(mon, " dst <any ucast>"); | |
1928 | } else { | |
1929 | monitor_printf(mon, " dst %s", key->eth_dst); | |
05e07488 | 1930 | if (mask->eth_dst) { |
fafa4d50 SF |
1931 | monitor_printf(mon, "(%s)", mask->eth_dst); |
1932 | } | |
1933 | } | |
1934 | } | |
1935 | ||
1936 | if (key->has_ip_proto) { | |
1937 | monitor_printf(mon, " proto %d", key->ip_proto); | |
1938 | if (mask->has_ip_proto) { | |
1939 | monitor_printf(mon, "(0x%x)", mask->ip_proto); | |
1940 | } | |
1941 | } | |
1942 | ||
1943 | if (key->has_ip_tos) { | |
1944 | monitor_printf(mon, " TOS %d", key->ip_tos); | |
1945 | if (mask->has_ip_tos) { | |
1946 | monitor_printf(mon, "(0x%x)", mask->ip_tos); | |
1947 | } | |
1948 | } | |
1949 | ||
05e07488 | 1950 | if (key->ip_dst) { |
fafa4d50 SF |
1951 | monitor_printf(mon, " dst %s", key->ip_dst); |
1952 | } | |
1953 | ||
1954 | if (action->has_goto_tbl || action->has_group_id || | |
1955 | action->has_new_vlan_id) { | |
1956 | monitor_printf(mon, " -->"); | |
1957 | } | |
1958 | ||
1959 | if (action->has_new_vlan_id) { | |
1960 | monitor_printf(mon, " apply new vlan %d", | |
1961 | ntohs(action->new_vlan_id)); | |
1962 | } | |
1963 | ||
1964 | if (action->has_group_id) { | |
1965 | monitor_printf(mon, " write group 0x%08x", action->group_id); | |
1966 | } | |
1967 | ||
1968 | if (action->has_goto_tbl) { | |
1969 | monitor_printf(mon, " goto tbl %d", action->goto_tbl); | |
1970 | } | |
1971 | ||
1972 | monitor_printf(mon, "\n"); | |
1973 | } | |
1974 | ||
1975 | qapi_free_RockerOfDpaFlowList(list); | |
1976 | } | |
1977 | ||
1978 | void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict) | |
1979 | { | |
1980 | RockerOfDpaGroupList *list, *g; | |
1981 | const char *name = qdict_get_str(qdict, "name"); | |
1982 | uint8_t type = qdict_get_try_int(qdict, "type", 9); | |
533fdaed | 1983 | Error *err = NULL; |
fafa4d50 | 1984 | |
533fdaed | 1985 | list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err); |
0ca117a7 | 1986 | if (hmp_handle_error(mon, err)) { |
fafa4d50 SF |
1987 | return; |
1988 | } | |
1989 | ||
1990 | monitor_printf(mon, "id (decode) --> buckets\n"); | |
1991 | ||
1992 | for (g = list; g; g = g->next) { | |
1993 | RockerOfDpaGroup *group = g->value; | |
916c9250 | 1994 | bool set = false; |
fafa4d50 SF |
1995 | |
1996 | monitor_printf(mon, "0x%08x", group->id); | |
1997 | ||
1998 | monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" : | |
1999 | group->type == 1 ? "L2 rewrite" : | |
2000 | group->type == 2 ? "L3 unicast" : | |
2001 | group->type == 3 ? "L2 multicast" : | |
2002 | group->type == 4 ? "L2 flood" : | |
2003 | group->type == 5 ? "L3 interface" : | |
2004 | group->type == 6 ? "L3 multicast" : | |
2005 | group->type == 7 ? "L3 ECMP" : | |
2006 | group->type == 8 ? "L2 overlay" : | |
2007 | "unknown"); | |
2008 | ||
2009 | if (group->has_vlan_id) { | |
2010 | monitor_printf(mon, " vlan %d", group->vlan_id); | |
2011 | } | |
2012 | ||
2013 | if (group->has_pport) { | |
2014 | monitor_printf(mon, " pport %d", group->pport); | |
2015 | } | |
2016 | ||
2017 | if (group->has_index) { | |
2018 | monitor_printf(mon, " index %d", group->index); | |
2019 | } | |
2020 | ||
2021 | monitor_printf(mon, ") -->"); | |
2022 | ||
2023 | if (group->has_set_vlan_id && group->set_vlan_id) { | |
2024 | set = true; | |
2025 | monitor_printf(mon, " set vlan %d", | |
2026 | group->set_vlan_id & VLAN_VID_MASK); | |
2027 | } | |
2028 | ||
05e07488 | 2029 | if (group->set_eth_src) { |
fafa4d50 SF |
2030 | if (!set) { |
2031 | set = true; | |
2032 | monitor_printf(mon, " set"); | |
2033 | } | |
2034 | monitor_printf(mon, " src %s", group->set_eth_src); | |
2035 | } | |
2036 | ||
05e07488 | 2037 | if (group->set_eth_dst) { |
fafa4d50 | 2038 | if (!set) { |
fafa4d50 SF |
2039 | monitor_printf(mon, " set"); |
2040 | } | |
2041 | monitor_printf(mon, " dst %s", group->set_eth_dst); | |
2042 | } | |
2043 | ||
fafa4d50 SF |
2044 | if (group->has_ttl_check && group->ttl_check) { |
2045 | monitor_printf(mon, " check TTL"); | |
2046 | } | |
2047 | ||
2048 | if (group->has_group_id && group->group_id) { | |
2049 | monitor_printf(mon, " group id 0x%08x", group->group_id); | |
2050 | } | |
2051 | ||
2052 | if (group->has_pop_vlan && group->pop_vlan) { | |
2053 | monitor_printf(mon, " pop vlan"); | |
2054 | } | |
2055 | ||
2056 | if (group->has_out_pport) { | |
2057 | monitor_printf(mon, " out pport %d", group->out_pport); | |
2058 | } | |
2059 | ||
2060 | if (group->has_group_ids) { | |
2061 | struct uint32List *id; | |
2062 | ||
2063 | monitor_printf(mon, " groups ["); | |
2064 | for (id = group->group_ids; id; id = id->next) { | |
2065 | monitor_printf(mon, "0x%08x", id->value); | |
2066 | if (id->next) { | |
2067 | monitor_printf(mon, ","); | |
2068 | } | |
2069 | } | |
2070 | monitor_printf(mon, "]"); | |
2071 | } | |
2072 | ||
2073 | monitor_printf(mon, "\n"); | |
2074 | } | |
2075 | ||
2076 | qapi_free_RockerOfDpaGroupList(list); | |
2077 | } | |
4a6b52d6 | 2078 | |
39164c13 IM |
2079 | void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict) |
2080 | { | |
72d9196f BW |
2081 | Error *err = NULL; |
2082 | GuidInfo *info = qmp_query_vm_generation_id(&err); | |
39164c13 IM |
2083 | if (info) { |
2084 | monitor_printf(mon, "%s\n", info->guid); | |
2085 | } | |
187c6147 | 2086 | hmp_handle_error(mon, err); |
39164c13 IM |
2087 | qapi_free_GuidInfo(info); |
2088 | } | |
d0f63c1e VG |
2089 | |
2090 | void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict) | |
2091 | { | |
2092 | Error *err = NULL; | |
2093 | MemoryInfo *info = qmp_query_memory_size_summary(&err); | |
2094 | if (info) { | |
2095 | monitor_printf(mon, "base memory: %" PRIu64 "\n", | |
2096 | info->base_memory); | |
2097 | ||
2098 | if (info->has_plugged_memory) { | |
2099 | monitor_printf(mon, "plugged memory: %" PRIu64 "\n", | |
2100 | info->plugged_memory); | |
2101 | } | |
2102 | ||
2103 | qapi_free_MemoryInfo(info); | |
2104 | } | |
187c6147 | 2105 | hmp_handle_error(mon, err); |
d0f63c1e | 2106 | } |
433815f5 MK |
2107 | |
2108 | static void print_stats_schema_value(Monitor *mon, StatsSchemaValue *value) | |
2109 | { | |
2110 | const char *unit = NULL; | |
2111 | monitor_printf(mon, " %s (%s%s", value->name, StatsType_str(value->type), | |
2112 | value->has_unit || value->exponent ? ", " : ""); | |
2113 | ||
2114 | if (value->has_unit) { | |
2115 | if (value->unit == STATS_UNIT_SECONDS) { | |
2116 | unit = "s"; | |
2117 | } else if (value->unit == STATS_UNIT_BYTES) { | |
2118 | unit = "B"; | |
2119 | } | |
2120 | } | |
2121 | ||
2122 | if (unit && value->base == 10 && | |
2123 | value->exponent >= -18 && value->exponent <= 18 && | |
2124 | value->exponent % 3 == 0) { | |
bf0c50d4 | 2125 | monitor_puts(mon, si_prefix(value->exponent)); |
433815f5 MK |
2126 | } else if (unit && value->base == 2 && |
2127 | value->exponent >= 0 && value->exponent <= 60 && | |
2128 | value->exponent % 10 == 0) { | |
2129 | ||
bf0c50d4 | 2130 | monitor_puts(mon, iec_binary_prefix(value->exponent)); |
433815f5 MK |
2131 | } else if (value->exponent) { |
2132 | /* Use exponential notation and write the unit's English name */ | |
2133 | monitor_printf(mon, "* %d^%d%s", | |
2134 | value->base, value->exponent, | |
2135 | value->has_unit ? " " : ""); | |
2136 | unit = NULL; | |
2137 | } | |
2138 | ||
2139 | if (value->has_unit) { | |
bf0c50d4 | 2140 | monitor_puts(mon, unit ? unit : StatsUnit_str(value->unit)); |
433815f5 MK |
2141 | } |
2142 | ||
2143 | /* Print bucket size for linear histograms */ | |
2144 | if (value->type == STATS_TYPE_LINEAR_HISTOGRAM && value->has_bucket_size) { | |
2145 | monitor_printf(mon, ", bucket size=%d", value->bucket_size); | |
2146 | } | |
2147 | monitor_printf(mon, ")"); | |
2148 | } | |
2149 | ||
2150 | static StatsSchemaValueList *find_schema_value_list( | |
2151 | StatsSchemaList *list, StatsProvider provider, | |
2152 | StatsTarget target) | |
2153 | { | |
2154 | StatsSchemaList *node; | |
2155 | ||
2156 | for (node = list; node; node = node->next) { | |
2157 | if (node->value->provider == provider && | |
2158 | node->value->target == target) { | |
2159 | return node->value->stats; | |
2160 | } | |
2161 | } | |
2162 | return NULL; | |
2163 | } | |
2164 | ||
2165 | static void print_stats_results(Monitor *mon, StatsTarget target, | |
7716417e | 2166 | bool show_provider, |
433815f5 MK |
2167 | StatsResult *result, |
2168 | StatsSchemaList *schema) | |
2169 | { | |
2170 | /* Find provider schema */ | |
2171 | StatsSchemaValueList *schema_value_list = | |
2172 | find_schema_value_list(schema, result->provider, target); | |
2173 | StatsList *stats_list; | |
2174 | ||
2175 | if (!schema_value_list) { | |
2176 | monitor_printf(mon, "failed to find schema list for %s\n", | |
2177 | StatsProvider_str(result->provider)); | |
2178 | return; | |
2179 | } | |
2180 | ||
7716417e PB |
2181 | if (show_provider) { |
2182 | monitor_printf(mon, "provider: %s\n", | |
2183 | StatsProvider_str(result->provider)); | |
2184 | } | |
433815f5 MK |
2185 | |
2186 | for (stats_list = result->stats; stats_list; | |
2187 | stats_list = stats_list->next, | |
2188 | schema_value_list = schema_value_list->next) { | |
2189 | ||
2190 | Stats *stats = stats_list->value; | |
2191 | StatsValue *stats_value = stats->value; | |
2192 | StatsSchemaValue *schema_value = schema_value_list->value; | |
2193 | ||
2194 | /* Find schema entry */ | |
2195 | while (!g_str_equal(stats->name, schema_value->name)) { | |
2196 | if (!schema_value_list->next) { | |
2197 | monitor_printf(mon, "failed to find schema entry for %s\n", | |
2198 | stats->name); | |
2199 | return; | |
2200 | } | |
2201 | schema_value_list = schema_value_list->next; | |
2202 | schema_value = schema_value_list->value; | |
2203 | } | |
2204 | ||
2205 | print_stats_schema_value(mon, schema_value); | |
2206 | ||
2207 | if (stats_value->type == QTYPE_QNUM) { | |
2208 | monitor_printf(mon, ": %" PRId64 "\n", stats_value->u.scalar); | |
1ca1a7ec PB |
2209 | } else if (stats_value->type == QTYPE_QBOOL) { |
2210 | monitor_printf(mon, ": %s\n", stats_value->u.boolean ? "yes" : "no"); | |
433815f5 MK |
2211 | } else if (stats_value->type == QTYPE_QLIST) { |
2212 | uint64List *list; | |
2213 | int i; | |
2214 | ||
2215 | monitor_printf(mon, ": "); | |
2216 | for (list = stats_value->u.list, i = 1; | |
2217 | list; | |
2218 | list = list->next, i++) { | |
2219 | monitor_printf(mon, "[%d]=%" PRId64 " ", i, list->value); | |
2220 | } | |
2221 | monitor_printf(mon, "\n"); | |
2222 | } | |
2223 | } | |
2224 | } | |
2225 | ||
2226 | /* Create the StatsFilter that is needed for an "info stats" invocation. */ | |
39cd0c7f PB |
2227 | static StatsFilter *stats_filter(StatsTarget target, const char *names, |
2228 | int cpu_index, StatsProvider provider) | |
433815f5 MK |
2229 | { |
2230 | StatsFilter *filter = g_malloc0(sizeof(*filter)); | |
39cd0c7f PB |
2231 | StatsProvider provider_idx; |
2232 | StatsRequestList *request_list = NULL; | |
433815f5 MK |
2233 | |
2234 | filter->target = target; | |
2235 | switch (target) { | |
2236 | case STATS_TARGET_VM: | |
2237 | break; | |
2238 | case STATS_TARGET_VCPU: | |
2239 | { | |
2240 | strList *vcpu_list = NULL; | |
2241 | CPUState *cpu = qemu_get_cpu(cpu_index); | |
2242 | char *canonical_path = object_get_canonical_path(OBJECT(cpu)); | |
2243 | ||
2244 | QAPI_LIST_PREPEND(vcpu_list, canonical_path); | |
2245 | filter->u.vcpu.has_vcpus = true; | |
2246 | filter->u.vcpu.vcpus = vcpu_list; | |
2247 | break; | |
2248 | } | |
2249 | default: | |
2250 | break; | |
2251 | } | |
7716417e | 2252 | |
39cd0c7f | 2253 | if (!names && provider == STATS_PROVIDER__MAX) { |
7716417e PB |
2254 | return filter; |
2255 | } | |
2256 | ||
39cd0c7f PB |
2257 | /* |
2258 | * "info stats" can only query either one or all the providers. Querying | |
2259 | * by name, but not by provider, requires the creation of one filter per | |
2260 | * provider. | |
2261 | */ | |
2262 | for (provider_idx = 0; provider_idx < STATS_PROVIDER__MAX; provider_idx++) { | |
2263 | if (provider == STATS_PROVIDER__MAX || provider == provider_idx) { | |
2264 | StatsRequest *request = g_new0(StatsRequest, 1); | |
2265 | request->provider = provider_idx; | |
2266 | if (names && !g_str_equal(names, "*")) { | |
2267 | request->has_names = true; | |
2268 | request->names = strList_from_comma_list(names); | |
2269 | } | |
2270 | QAPI_LIST_PREPEND(request_list, request); | |
2271 | } | |
2272 | } | |
2273 | ||
7716417e | 2274 | filter->has_providers = true; |
39cd0c7f | 2275 | filter->providers = request_list; |
433815f5 MK |
2276 | return filter; |
2277 | } | |
2278 | ||
2279 | void hmp_info_stats(Monitor *mon, const QDict *qdict) | |
2280 | { | |
2281 | const char *target_str = qdict_get_str(qdict, "target"); | |
7716417e | 2282 | const char *provider_str = qdict_get_try_str(qdict, "provider"); |
39cd0c7f | 2283 | const char *names = qdict_get_try_str(qdict, "names"); |
7716417e PB |
2284 | |
2285 | StatsProvider provider = STATS_PROVIDER__MAX; | |
433815f5 MK |
2286 | StatsTarget target; |
2287 | Error *err = NULL; | |
2288 | g_autoptr(StatsSchemaList) schema = NULL; | |
2289 | g_autoptr(StatsResultList) stats = NULL; | |
2290 | g_autoptr(StatsFilter) filter = NULL; | |
2291 | StatsResultList *entry; | |
2292 | ||
2293 | target = qapi_enum_parse(&StatsTarget_lookup, target_str, -1, &err); | |
2294 | if (err) { | |
2295 | monitor_printf(mon, "invalid stats target %s\n", target_str); | |
2296 | goto exit_no_print; | |
2297 | } | |
7716417e PB |
2298 | if (provider_str) { |
2299 | provider = qapi_enum_parse(&StatsProvider_lookup, provider_str, -1, &err); | |
2300 | if (err) { | |
2301 | monitor_printf(mon, "invalid stats provider %s\n", provider_str); | |
2302 | goto exit_no_print; | |
2303 | } | |
2304 | } | |
433815f5 | 2305 | |
7716417e PB |
2306 | schema = qmp_query_stats_schemas(provider_str ? true : false, |
2307 | provider, &err); | |
433815f5 MK |
2308 | if (err) { |
2309 | goto exit; | |
2310 | } | |
2311 | ||
2312 | switch (target) { | |
2313 | case STATS_TARGET_VM: | |
39cd0c7f | 2314 | filter = stats_filter(target, names, -1, provider); |
433815f5 MK |
2315 | break; |
2316 | case STATS_TARGET_VCPU: {} | |
2317 | int cpu_index = monitor_get_cpu_index(mon); | |
39cd0c7f | 2318 | filter = stats_filter(target, names, cpu_index, provider); |
433815f5 MK |
2319 | break; |
2320 | default: | |
2321 | abort(); | |
2322 | } | |
2323 | ||
2324 | stats = qmp_query_stats(filter, &err); | |
2325 | if (err) { | |
2326 | goto exit; | |
2327 | } | |
2328 | for (entry = stats; entry; entry = entry->next) { | |
7716417e | 2329 | print_stats_results(mon, target, provider_str == NULL, entry->value, schema); |
433815f5 MK |
2330 | } |
2331 | ||
2332 | exit: | |
2333 | if (err) { | |
2334 | monitor_printf(mon, "%s\n", error_get_pretty(err)); | |
2335 | } | |
2336 | exit_no_print: | |
2337 | error_free(err); | |
2338 | } | |
8a828798 LV |
2339 | |
2340 | static void hmp_virtio_dump_protocols(Monitor *mon, | |
2341 | VhostDeviceProtocols *pcol) | |
2342 | { | |
2343 | strList *pcol_list = pcol->protocols; | |
2344 | while (pcol_list) { | |
2345 | monitor_printf(mon, "\t%s", pcol_list->value); | |
2346 | pcol_list = pcol_list->next; | |
2347 | if (pcol_list != NULL) { | |
2348 | monitor_printf(mon, ",\n"); | |
2349 | } | |
2350 | } | |
2351 | monitor_printf(mon, "\n"); | |
2352 | if (pcol->has_unknown_protocols) { | |
2353 | monitor_printf(mon, " unknown-protocols(0x%016"PRIx64")\n", | |
2354 | pcol->unknown_protocols); | |
2355 | } | |
2356 | } | |
2357 | ||
2358 | static void hmp_virtio_dump_status(Monitor *mon, | |
2359 | VirtioDeviceStatus *status) | |
2360 | { | |
2361 | strList *status_list = status->statuses; | |
2362 | while (status_list) { | |
2363 | monitor_printf(mon, "\t%s", status_list->value); | |
2364 | status_list = status_list->next; | |
2365 | if (status_list != NULL) { | |
2366 | monitor_printf(mon, ",\n"); | |
2367 | } | |
2368 | } | |
2369 | monitor_printf(mon, "\n"); | |
2370 | if (status->has_unknown_statuses) { | |
2371 | monitor_printf(mon, " unknown-statuses(0x%016"PRIx32")\n", | |
2372 | status->unknown_statuses); | |
2373 | } | |
2374 | } | |
2375 | ||
2376 | static void hmp_virtio_dump_features(Monitor *mon, | |
2377 | VirtioDeviceFeatures *features) | |
2378 | { | |
2379 | strList *transport_list = features->transports; | |
2380 | while (transport_list) { | |
2381 | monitor_printf(mon, "\t%s", transport_list->value); | |
2382 | transport_list = transport_list->next; | |
2383 | if (transport_list != NULL) { | |
2384 | monitor_printf(mon, ",\n"); | |
2385 | } | |
2386 | } | |
2387 | ||
2388 | monitor_printf(mon, "\n"); | |
2389 | strList *list = features->dev_features; | |
2390 | if (list) { | |
2391 | while (list) { | |
2392 | monitor_printf(mon, "\t%s", list->value); | |
2393 | list = list->next; | |
2394 | if (list != NULL) { | |
2395 | monitor_printf(mon, ",\n"); | |
2396 | } | |
2397 | } | |
2398 | monitor_printf(mon, "\n"); | |
2399 | } | |
2400 | ||
2401 | if (features->has_unknown_dev_features) { | |
2402 | monitor_printf(mon, " unknown-features(0x%016"PRIx64")\n", | |
2403 | features->unknown_dev_features); | |
2404 | } | |
2405 | } | |
2406 | ||
2407 | void hmp_virtio_query(Monitor *mon, const QDict *qdict) | |
2408 | { | |
2409 | Error *err = NULL; | |
2410 | VirtioInfoList *list = qmp_x_query_virtio(&err); | |
2411 | VirtioInfoList *node; | |
2412 | ||
2413 | if (err != NULL) { | |
2414 | hmp_handle_error(mon, err); | |
2415 | return; | |
2416 | } | |
2417 | ||
2418 | if (list == NULL) { | |
2419 | monitor_printf(mon, "No VirtIO devices\n"); | |
2420 | return; | |
2421 | } | |
2422 | ||
2423 | node = list; | |
2424 | while (node) { | |
2425 | monitor_printf(mon, "%s [%s]\n", node->value->path, | |
2426 | node->value->name); | |
2427 | node = node->next; | |
2428 | } | |
2429 | qapi_free_VirtioInfoList(list); | |
2430 | } | |
2431 | ||
2432 | void hmp_virtio_status(Monitor *mon, const QDict *qdict) | |
2433 | { | |
2434 | Error *err = NULL; | |
2435 | const char *path = qdict_get_try_str(qdict, "path"); | |
2436 | VirtioStatus *s = qmp_x_query_virtio_status(path, &err); | |
2437 | ||
2438 | if (err != NULL) { | |
2439 | hmp_handle_error(mon, err); | |
2440 | return; | |
2441 | } | |
2442 | ||
2443 | monitor_printf(mon, "%s:\n", path); | |
2444 | monitor_printf(mon, " device_name: %s %s\n", | |
41462e41 | 2445 | s->name, s->vhost_dev ? "(vhost)" : ""); |
8a828798 LV |
2446 | monitor_printf(mon, " device_id: %d\n", s->device_id); |
2447 | monitor_printf(mon, " vhost_started: %s\n", | |
2448 | s->vhost_started ? "true" : "false"); | |
2449 | monitor_printf(mon, " bus_name: %s\n", s->bus_name); | |
2450 | monitor_printf(mon, " broken: %s\n", | |
2451 | s->broken ? "true" : "false"); | |
2452 | monitor_printf(mon, " disabled: %s\n", | |
2453 | s->disabled ? "true" : "false"); | |
2454 | monitor_printf(mon, " disable_legacy_check: %s\n", | |
2455 | s->disable_legacy_check ? "true" : "false"); | |
2456 | monitor_printf(mon, " started: %s\n", | |
2457 | s->started ? "true" : "false"); | |
2458 | monitor_printf(mon, " use_started: %s\n", | |
2459 | s->use_started ? "true" : "false"); | |
2460 | monitor_printf(mon, " start_on_kick: %s\n", | |
2461 | s->start_on_kick ? "true" : "false"); | |
2462 | monitor_printf(mon, " use_guest_notifier_mask: %s\n", | |
2463 | s->use_guest_notifier_mask ? "true" : "false"); | |
2464 | monitor_printf(mon, " vm_running: %s\n", | |
2465 | s->vm_running ? "true" : "false"); | |
2466 | monitor_printf(mon, " num_vqs: %"PRId64"\n", s->num_vqs); | |
2467 | monitor_printf(mon, " queue_sel: %d\n", | |
2468 | s->queue_sel); | |
2469 | monitor_printf(mon, " isr: %d\n", s->isr); | |
2470 | monitor_printf(mon, " endianness: %s\n", | |
2471 | s->device_endian); | |
2472 | monitor_printf(mon, " status:\n"); | |
2473 | hmp_virtio_dump_status(mon, s->status); | |
2474 | monitor_printf(mon, " Guest features:\n"); | |
2475 | hmp_virtio_dump_features(mon, s->guest_features); | |
2476 | monitor_printf(mon, " Host features:\n"); | |
2477 | hmp_virtio_dump_features(mon, s->host_features); | |
2478 | monitor_printf(mon, " Backend features:\n"); | |
2479 | hmp_virtio_dump_features(mon, s->backend_features); | |
2480 | ||
41462e41 | 2481 | if (s->vhost_dev) { |
8a828798 LV |
2482 | monitor_printf(mon, " VHost:\n"); |
2483 | monitor_printf(mon, " nvqs: %d\n", | |
2484 | s->vhost_dev->nvqs); | |
2485 | monitor_printf(mon, " vq_index: %"PRId64"\n", | |
2486 | s->vhost_dev->vq_index); | |
2487 | monitor_printf(mon, " max_queues: %"PRId64"\n", | |
2488 | s->vhost_dev->max_queues); | |
2489 | monitor_printf(mon, " n_mem_sections: %"PRId64"\n", | |
2490 | s->vhost_dev->n_mem_sections); | |
2491 | monitor_printf(mon, " n_tmp_sections: %"PRId64"\n", | |
2492 | s->vhost_dev->n_tmp_sections); | |
2493 | monitor_printf(mon, " backend_cap: %"PRId64"\n", | |
2494 | s->vhost_dev->backend_cap); | |
2495 | monitor_printf(mon, " log_enabled: %s\n", | |
2496 | s->vhost_dev->log_enabled ? "true" : "false"); | |
2497 | monitor_printf(mon, " log_size: %"PRId64"\n", | |
2498 | s->vhost_dev->log_size); | |
2499 | monitor_printf(mon, " Features:\n"); | |
2500 | hmp_virtio_dump_features(mon, s->vhost_dev->features); | |
2501 | monitor_printf(mon, " Acked features:\n"); | |
2502 | hmp_virtio_dump_features(mon, s->vhost_dev->acked_features); | |
2503 | monitor_printf(mon, " Backend features:\n"); | |
2504 | hmp_virtio_dump_features(mon, s->vhost_dev->backend_features); | |
2505 | monitor_printf(mon, " Protocol features:\n"); | |
2506 | hmp_virtio_dump_protocols(mon, s->vhost_dev->protocol_features); | |
2507 | } | |
2508 | ||
2509 | qapi_free_VirtioStatus(s); | |
2510 | } | |
2511 | ||
2512 | void hmp_vhost_queue_status(Monitor *mon, const QDict *qdict) | |
2513 | { | |
2514 | Error *err = NULL; | |
2515 | const char *path = qdict_get_try_str(qdict, "path"); | |
2516 | int queue = qdict_get_int(qdict, "queue"); | |
2517 | VirtVhostQueueStatus *s = | |
2518 | qmp_x_query_virtio_vhost_queue_status(path, queue, &err); | |
2519 | ||
2520 | if (err != NULL) { | |
2521 | hmp_handle_error(mon, err); | |
2522 | return; | |
2523 | } | |
2524 | ||
2525 | monitor_printf(mon, "%s:\n", path); | |
2526 | monitor_printf(mon, " device_name: %s (vhost)\n", | |
2527 | s->name); | |
2528 | monitor_printf(mon, " kick: %"PRId64"\n", s->kick); | |
2529 | monitor_printf(mon, " call: %"PRId64"\n", s->call); | |
2530 | monitor_printf(mon, " VRing:\n"); | |
2531 | monitor_printf(mon, " num: %"PRId64"\n", s->num); | |
2532 | monitor_printf(mon, " desc: 0x%016"PRIx64"\n", s->desc); | |
2533 | monitor_printf(mon, " desc_phys: 0x%016"PRIx64"\n", | |
2534 | s->desc_phys); | |
2535 | monitor_printf(mon, " desc_size: %"PRId32"\n", s->desc_size); | |
2536 | monitor_printf(mon, " avail: 0x%016"PRIx64"\n", s->avail); | |
2537 | monitor_printf(mon, " avail_phys: 0x%016"PRIx64"\n", | |
2538 | s->avail_phys); | |
2539 | monitor_printf(mon, " avail_size: %"PRId32"\n", s->avail_size); | |
2540 | monitor_printf(mon, " used: 0x%016"PRIx64"\n", s->used); | |
2541 | monitor_printf(mon, " used_phys: 0x%016"PRIx64"\n", | |
2542 | s->used_phys); | |
2543 | monitor_printf(mon, " used_size: %"PRId32"\n", s->used_size); | |
2544 | ||
2545 | qapi_free_VirtVhostQueueStatus(s); | |
2546 | } | |
2547 | ||
2548 | void hmp_virtio_queue_status(Monitor *mon, const QDict *qdict) | |
2549 | { | |
2550 | Error *err = NULL; | |
2551 | const char *path = qdict_get_try_str(qdict, "path"); | |
2552 | int queue = qdict_get_int(qdict, "queue"); | |
2553 | VirtQueueStatus *s = qmp_x_query_virtio_queue_status(path, queue, &err); | |
2554 | ||
2555 | if (err != NULL) { | |
2556 | hmp_handle_error(mon, err); | |
2557 | return; | |
2558 | } | |
2559 | ||
2560 | monitor_printf(mon, "%s:\n", path); | |
2561 | monitor_printf(mon, " device_name: %s\n", s->name); | |
2562 | monitor_printf(mon, " queue_index: %d\n", s->queue_index); | |
2563 | monitor_printf(mon, " inuse: %d\n", s->inuse); | |
2564 | monitor_printf(mon, " used_idx: %d\n", s->used_idx); | |
2565 | monitor_printf(mon, " signalled_used: %d\n", | |
2566 | s->signalled_used); | |
2567 | monitor_printf(mon, " signalled_used_valid: %s\n", | |
2568 | s->signalled_used_valid ? "true" : "false"); | |
2569 | if (s->has_last_avail_idx) { | |
2570 | monitor_printf(mon, " last_avail_idx: %d\n", | |
2571 | s->last_avail_idx); | |
2572 | } | |
2573 | if (s->has_shadow_avail_idx) { | |
2574 | monitor_printf(mon, " shadow_avail_idx: %d\n", | |
2575 | s->shadow_avail_idx); | |
2576 | } | |
2577 | monitor_printf(mon, " VRing:\n"); | |
2578 | monitor_printf(mon, " num: %"PRId32"\n", s->vring_num); | |
2579 | monitor_printf(mon, " num_default: %"PRId32"\n", | |
2580 | s->vring_num_default); | |
2581 | monitor_printf(mon, " align: %"PRId32"\n", | |
2582 | s->vring_align); | |
2583 | monitor_printf(mon, " desc: 0x%016"PRIx64"\n", | |
2584 | s->vring_desc); | |
2585 | monitor_printf(mon, " avail: 0x%016"PRIx64"\n", | |
2586 | s->vring_avail); | |
2587 | monitor_printf(mon, " used: 0x%016"PRIx64"\n", | |
2588 | s->vring_used); | |
2589 | ||
2590 | qapi_free_VirtQueueStatus(s); | |
2591 | } | |
2592 | ||
2593 | void hmp_virtio_queue_element(Monitor *mon, const QDict *qdict) | |
2594 | { | |
2595 | Error *err = NULL; | |
2596 | const char *path = qdict_get_try_str(qdict, "path"); | |
2597 | int queue = qdict_get_int(qdict, "queue"); | |
2598 | int index = qdict_get_try_int(qdict, "index", -1); | |
2599 | VirtioQueueElement *e; | |
2600 | VirtioRingDescList *list; | |
2601 | ||
2602 | e = qmp_x_query_virtio_queue_element(path, queue, index != -1, | |
2603 | index, &err); | |
2604 | if (err != NULL) { | |
2605 | hmp_handle_error(mon, err); | |
2606 | return; | |
2607 | } | |
2608 | ||
2609 | monitor_printf(mon, "%s:\n", path); | |
2610 | monitor_printf(mon, " device_name: %s\n", e->name); | |
2611 | monitor_printf(mon, " index: %d\n", e->index); | |
2612 | monitor_printf(mon, " desc:\n"); | |
2613 | monitor_printf(mon, " descs:\n"); | |
2614 | ||
2615 | list = e->descs; | |
2616 | while (list) { | |
2617 | monitor_printf(mon, " addr 0x%"PRIx64" len %d", | |
2618 | list->value->addr, list->value->len); | |
2619 | if (list->value->flags) { | |
2620 | strList *flag = list->value->flags; | |
2621 | monitor_printf(mon, " ("); | |
2622 | while (flag) { | |
2623 | monitor_printf(mon, "%s", flag->value); | |
2624 | flag = flag->next; | |
2625 | if (flag) { | |
2626 | monitor_printf(mon, ", "); | |
2627 | } | |
2628 | } | |
2629 | monitor_printf(mon, ")"); | |
2630 | } | |
2631 | list = list->next; | |
2632 | if (list) { | |
2633 | monitor_printf(mon, ",\n"); | |
2634 | } | |
2635 | } | |
2636 | monitor_printf(mon, "\n"); | |
2637 | monitor_printf(mon, " avail:\n"); | |
2638 | monitor_printf(mon, " flags: %d\n", e->avail->flags); | |
2639 | monitor_printf(mon, " idx: %d\n", e->avail->idx); | |
2640 | monitor_printf(mon, " ring: %d\n", e->avail->ring); | |
2641 | monitor_printf(mon, " used:\n"); | |
2642 | monitor_printf(mon, " flags: %d\n", e->used->flags); | |
2643 | monitor_printf(mon, " idx: %d\n", e->used->idx); | |
2644 | ||
2645 | qapi_free_VirtioQueueElement(e); | |
2646 | } |