]>
Commit | Line | Data |
---|---|---|
48a32bed AL |
1 | /* |
2 | * Human Monitor Interface | |
3 | * | |
4 | * Copyright IBM, Corp. 2011 | |
5 | * | |
6 | * Authors: | |
7 | * Anthony Liguori <[email protected]> | |
8 | * | |
9 | * This work is licensed under the terms of the GNU GPL, version 2. See | |
10 | * the COPYING file in the top-level directory. | |
11 | * | |
6b620ca3 PB |
12 | * Contributions after 2012-01-13 are licensed under the terms of the |
13 | * GNU GPL, version 2 or (at your option) any later version. | |
48a32bed AL |
14 | */ |
15 | ||
d38ea87a | 16 | #include "qemu/osdep.h" |
48a32bed | 17 | #include "hmp.h" |
1422e32d | 18 | #include "net/net.h" |
fafa4d50 | 19 | #include "net/eth.h" |
dccfcd0e | 20 | #include "sysemu/char.h" |
4c7b7e9b | 21 | #include "sysemu/block-backend.h" |
1de7afc9 PB |
22 | #include "qemu/option.h" |
23 | #include "qemu/timer.h" | |
48a32bed | 24 | #include "qmp-commands.h" |
1de7afc9 | 25 | #include "qemu/sockets.h" |
83c9089e | 26 | #include "monitor/monitor.h" |
318660f8 | 27 | #include "monitor/qdev.h" |
cff8b2c6 | 28 | #include "qapi/opts-visitor.h" |
cc7a8ea7 | 29 | #include "qapi/qmp/qerror.h" |
eb1539b2 | 30 | #include "qapi/string-output-visitor.h" |
baead0ab | 31 | #include "qapi/util.h" |
eb1539b2 | 32 | #include "qapi-visit.h" |
90998d58 | 33 | #include "qom/object_interfaces.h" |
28ecbaee | 34 | #include "ui/console.h" |
bd093a36 | 35 | #include "block/qapi.h" |
587da2c3 | 36 | #include "qemu-io.h" |
f348b6d1 | 37 | #include "qemu/cutils.h" |
d59ce6f3 | 38 | #include "qemu/error-report.h" |
48a32bed | 39 | |
22fa7da0 CR |
40 | #ifdef CONFIG_SPICE |
41 | #include <spice/enums.h> | |
42 | #endif | |
43 | ||
0cfd6a9a LC |
44 | static void hmp_handle_error(Monitor *mon, Error **errp) |
45 | { | |
415168e0 MA |
46 | assert(errp); |
47 | if (*errp) { | |
193227f9 | 48 | error_report_err(*errp); |
0cfd6a9a LC |
49 | } |
50 | } | |
51 | ||
84f2d0ea | 52 | void hmp_info_name(Monitor *mon, const QDict *qdict) |
48a32bed AL |
53 | { |
54 | NameInfo *info; | |
55 | ||
56 | info = qmp_query_name(NULL); | |
57 | if (info->has_name) { | |
58 | monitor_printf(mon, "%s\n", info->name); | |
59 | } | |
60 | qapi_free_NameInfo(info); | |
61 | } | |
b9c15f16 | 62 | |
84f2d0ea | 63 | void hmp_info_version(Monitor *mon, const QDict *qdict) |
b9c15f16 LC |
64 | { |
65 | VersionInfo *info; | |
66 | ||
67 | info = qmp_query_version(NULL); | |
68 | ||
69 | monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n", | |
4752cdbb | 70 | info->qemu->major, info->qemu->minor, info->qemu->micro, |
b9c15f16 LC |
71 | info->package); |
72 | ||
73 | qapi_free_VersionInfo(info); | |
74 | } | |
292a2602 | 75 | |
84f2d0ea | 76 | void hmp_info_kvm(Monitor *mon, const QDict *qdict) |
292a2602 LC |
77 | { |
78 | KvmInfo *info; | |
79 | ||
80 | info = qmp_query_kvm(NULL); | |
81 | monitor_printf(mon, "kvm support: "); | |
82 | if (info->present) { | |
83 | monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled"); | |
84 | } else { | |
85 | monitor_printf(mon, "not compiled\n"); | |
86 | } | |
87 | ||
88 | qapi_free_KvmInfo(info); | |
89 | } | |
90 | ||
84f2d0ea | 91 | void hmp_info_status(Monitor *mon, const QDict *qdict) |
1fa9a5e4 LC |
92 | { |
93 | StatusInfo *info; | |
94 | ||
95 | info = qmp_query_status(NULL); | |
96 | ||
97 | monitor_printf(mon, "VM status: %s%s", | |
98 | info->running ? "running" : "paused", | |
99 | info->singlestep ? " (single step mode)" : ""); | |
100 | ||
101 | if (!info->running && info->status != RUN_STATE_PAUSED) { | |
102 | monitor_printf(mon, " (%s)", RunState_lookup[info->status]); | |
103 | } | |
104 | ||
105 | monitor_printf(mon, "\n"); | |
106 | ||
107 | qapi_free_StatusInfo(info); | |
108 | } | |
109 | ||
84f2d0ea | 110 | void hmp_info_uuid(Monitor *mon, const QDict *qdict) |
efab767e LC |
111 | { |
112 | UuidInfo *info; | |
113 | ||
114 | info = qmp_query_uuid(NULL); | |
115 | monitor_printf(mon, "%s\n", info->UUID); | |
116 | qapi_free_UuidInfo(info); | |
117 | } | |
c5a415a0 | 118 | |
84f2d0ea | 119 | void hmp_info_chardev(Monitor *mon, const QDict *qdict) |
c5a415a0 LC |
120 | { |
121 | ChardevInfoList *char_info, *info; | |
122 | ||
123 | char_info = qmp_query_chardev(NULL); | |
124 | for (info = char_info; info; info = info->next) { | |
125 | monitor_printf(mon, "%s: filename=%s\n", info->value->label, | |
126 | info->value->filename); | |
127 | } | |
128 | ||
129 | qapi_free_ChardevInfoList(char_info); | |
130 | } | |
7a7f325e | 131 | |
84f2d0ea | 132 | void hmp_info_mice(Monitor *mon, const QDict *qdict) |
e235cec3 LC |
133 | { |
134 | MouseInfoList *mice_list, *mouse; | |
135 | ||
136 | mice_list = qmp_query_mice(NULL); | |
137 | if (!mice_list) { | |
138 | monitor_printf(mon, "No mouse devices connected\n"); | |
139 | return; | |
140 | } | |
141 | ||
142 | for (mouse = mice_list; mouse; mouse = mouse->next) { | |
143 | monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n", | |
144 | mouse->value->current ? '*' : ' ', | |
145 | mouse->value->index, mouse->value->name, | |
146 | mouse->value->absolute ? " (absolute)" : ""); | |
147 | } | |
148 | ||
149 | qapi_free_MouseInfoList(mice_list); | |
150 | } | |
151 | ||
84f2d0ea | 152 | void hmp_info_migrate(Monitor *mon, const QDict *qdict) |
791e7c82 LC |
153 | { |
154 | MigrationInfo *info; | |
bbf6da32 | 155 | MigrationCapabilityStatusList *caps, *cap; |
791e7c82 LC |
156 | |
157 | info = qmp_query_migrate(NULL); | |
bbf6da32 OW |
158 | caps = qmp_query_migrate_capabilities(NULL); |
159 | ||
160 | /* do not display parameters during setup */ | |
161 | if (info->has_status && caps) { | |
162 | monitor_printf(mon, "capabilities: "); | |
163 | for (cap = caps; cap; cap = cap->next) { | |
164 | monitor_printf(mon, "%s: %s ", | |
165 | MigrationCapability_lookup[cap->value->capability], | |
166 | cap->value->state ? "on" : "off"); | |
167 | } | |
168 | monitor_printf(mon, "\n"); | |
169 | } | |
791e7c82 LC |
170 | |
171 | if (info->has_status) { | |
d59ce6f3 | 172 | monitor_printf(mon, "Migration status: %s", |
24b8c39b | 173 | MigrationStatus_lookup[info->status]); |
d59ce6f3 DB |
174 | if (info->status == MIGRATION_STATUS_FAILED && |
175 | info->has_error_desc) { | |
176 | monitor_printf(mon, " (%s)\n", info->error_desc); | |
177 | } else { | |
178 | monitor_printf(mon, "\n"); | |
179 | } | |
180 | ||
7aa939af JQ |
181 | monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n", |
182 | info->total_time); | |
2c52ddf1 JQ |
183 | if (info->has_expected_downtime) { |
184 | monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n", | |
185 | info->expected_downtime); | |
186 | } | |
9c5a9fcf JQ |
187 | if (info->has_downtime) { |
188 | monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n", | |
189 | info->downtime); | |
190 | } | |
ed4fbd10 MH |
191 | if (info->has_setup_time) { |
192 | monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n", | |
193 | info->setup_time); | |
194 | } | |
791e7c82 LC |
195 | } |
196 | ||
197 | if (info->has_ram) { | |
198 | monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n", | |
199 | info->ram->transferred >> 10); | |
7e114f8c MH |
200 | monitor_printf(mon, "throughput: %0.2f mbps\n", |
201 | info->ram->mbps); | |
791e7c82 LC |
202 | monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n", |
203 | info->ram->remaining >> 10); | |
204 | monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n", | |
205 | info->ram->total >> 10); | |
004d4c10 OW |
206 | monitor_printf(mon, "duplicate: %" PRIu64 " pages\n", |
207 | info->ram->duplicate); | |
f1c72795 PL |
208 | monitor_printf(mon, "skipped: %" PRIu64 " pages\n", |
209 | info->ram->skipped); | |
004d4c10 OW |
210 | monitor_printf(mon, "normal: %" PRIu64 " pages\n", |
211 | info->ram->normal); | |
212 | monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n", | |
213 | info->ram->normal_bytes >> 10); | |
58570ed8 C |
214 | monitor_printf(mon, "dirty sync count: %" PRIu64 "\n", |
215 | info->ram->dirty_sync_count); | |
8d017193 JQ |
216 | if (info->ram->dirty_pages_rate) { |
217 | monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n", | |
218 | info->ram->dirty_pages_rate); | |
219 | } | |
791e7c82 LC |
220 | } |
221 | ||
222 | if (info->has_disk) { | |
223 | monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n", | |
224 | info->disk->transferred >> 10); | |
225 | monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n", | |
226 | info->disk->remaining >> 10); | |
227 | monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n", | |
228 | info->disk->total >> 10); | |
229 | } | |
230 | ||
f36d55af OW |
231 | if (info->has_xbzrle_cache) { |
232 | monitor_printf(mon, "cache size: %" PRIu64 " bytes\n", | |
233 | info->xbzrle_cache->cache_size); | |
234 | monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n", | |
235 | info->xbzrle_cache->bytes >> 10); | |
236 | monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n", | |
237 | info->xbzrle_cache->pages); | |
238 | monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n", | |
239 | info->xbzrle_cache->cache_miss); | |
8bc39233 C |
240 | monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n", |
241 | info->xbzrle_cache->cache_miss_rate); | |
f36d55af OW |
242 | monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n", |
243 | info->xbzrle_cache->overflow); | |
244 | } | |
245 | ||
d85a31d1 | 246 | if (info->has_cpu_throttle_percentage) { |
4782893e | 247 | monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n", |
d85a31d1 | 248 | info->cpu_throttle_percentage); |
4782893e JH |
249 | } |
250 | ||
791e7c82 | 251 | qapi_free_MigrationInfo(info); |
bbf6da32 OW |
252 | qapi_free_MigrationCapabilityStatusList(caps); |
253 | } | |
254 | ||
84f2d0ea | 255 | void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict) |
bbf6da32 OW |
256 | { |
257 | MigrationCapabilityStatusList *caps, *cap; | |
258 | ||
259 | caps = qmp_query_migrate_capabilities(NULL); | |
260 | ||
261 | if (caps) { | |
262 | monitor_printf(mon, "capabilities: "); | |
263 | for (cap = caps; cap; cap = cap->next) { | |
264 | monitor_printf(mon, "%s: %s ", | |
265 | MigrationCapability_lookup[cap->value->capability], | |
266 | cap->value->state ? "on" : "off"); | |
267 | } | |
268 | monitor_printf(mon, "\n"); | |
269 | } | |
270 | ||
271 | qapi_free_MigrationCapabilityStatusList(caps); | |
791e7c82 LC |
272 | } |
273 | ||
50e9a629 LL |
274 | void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) |
275 | { | |
276 | MigrationParameters *params; | |
277 | ||
278 | params = qmp_query_migrate_parameters(NULL); | |
279 | ||
280 | if (params) { | |
281 | monitor_printf(mon, "parameters:"); | |
282 | monitor_printf(mon, " %s: %" PRId64, | |
283 | MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_LEVEL], | |
284 | params->compress_level); | |
285 | monitor_printf(mon, " %s: %" PRId64, | |
286 | MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_THREADS], | |
287 | params->compress_threads); | |
288 | monitor_printf(mon, " %s: %" PRId64, | |
289 | MigrationParameter_lookup[MIGRATION_PARAMETER_DECOMPRESS_THREADS], | |
290 | params->decompress_threads); | |
1626fee3 | 291 | monitor_printf(mon, " %s: %" PRId64, |
d85a31d1 JH |
292 | MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL], |
293 | params->cpu_throttle_initial); | |
1626fee3 | 294 | monitor_printf(mon, " %s: %" PRId64, |
d85a31d1 JH |
295 | MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT], |
296 | params->cpu_throttle_increment); | |
69ef1f36 DB |
297 | monitor_printf(mon, " %s: '%s'", |
298 | MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_CREDS], | |
299 | params->tls_creds ? : ""); | |
300 | monitor_printf(mon, " %s: '%s'", | |
301 | MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_HOSTNAME], | |
302 | params->tls_hostname ? : ""); | |
50e9a629 LL |
303 | monitor_printf(mon, "\n"); |
304 | } | |
305 | ||
306 | qapi_free_MigrationParameters(params); | |
307 | } | |
308 | ||
84f2d0ea | 309 | void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict) |
9e1ba4cc OW |
310 | { |
311 | monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n", | |
312 | qmp_query_migrate_cache_size(NULL) >> 10); | |
313 | } | |
314 | ||
84f2d0ea | 315 | void hmp_info_cpus(Monitor *mon, const QDict *qdict) |
de0b36b6 LC |
316 | { |
317 | CpuInfoList *cpu_list, *cpu; | |
318 | ||
319 | cpu_list = qmp_query_cpus(NULL); | |
320 | ||
321 | for (cpu = cpu_list; cpu; cpu = cpu->next) { | |
322 | int active = ' '; | |
323 | ||
324 | if (cpu->value->CPU == monitor_get_cpu_index()) { | |
325 | active = '*'; | |
326 | } | |
327 | ||
852bef0e | 328 | monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU); |
de0b36b6 | 329 | |
86f4b687 EB |
330 | switch (cpu->value->arch) { |
331 | case CPU_INFO_ARCH_X86: | |
544a3731 | 332 | monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->u.x86.pc); |
86f4b687 EB |
333 | break; |
334 | case CPU_INFO_ARCH_PPC: | |
544a3731 | 335 | monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->u.ppc.nip); |
86f4b687 EB |
336 | break; |
337 | case CPU_INFO_ARCH_SPARC: | |
86ae1911 | 338 | monitor_printf(mon, " pc=0x%016" PRIx64, |
544a3731 | 339 | cpu->value->u.q_sparc.pc); |
86ae1911 | 340 | monitor_printf(mon, " npc=0x%016" PRIx64, |
544a3731 | 341 | cpu->value->u.q_sparc.npc); |
86f4b687 EB |
342 | break; |
343 | case CPU_INFO_ARCH_MIPS: | |
544a3731 | 344 | monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.q_mips.PC); |
86f4b687 EB |
345 | break; |
346 | case CPU_INFO_ARCH_TRICORE: | |
544a3731 | 347 | monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.tricore.PC); |
86f4b687 EB |
348 | break; |
349 | default: | |
350 | break; | |
de0b36b6 LC |
351 | } |
352 | ||
353 | if (cpu->value->halted) { | |
354 | monitor_printf(mon, " (halted)"); | |
355 | } | |
356 | ||
357 | monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id); | |
358 | } | |
359 | ||
360 | qapi_free_CpuInfoList(cpu_list); | |
361 | } | |
362 | ||
289b276c KW |
363 | static void print_block_info(Monitor *mon, BlockInfo *info, |
364 | BlockDeviceInfo *inserted, bool verbose) | |
b2023818 | 365 | { |
bd093a36 | 366 | ImageInfo *image_info; |
b2023818 | 367 | |
8d6adccd KW |
368 | assert(!info || !info->has_inserted || info->inserted == inserted); |
369 | ||
370 | if (info) { | |
371 | monitor_printf(mon, "%s", info->device); | |
372 | if (inserted && inserted->has_node_name) { | |
373 | monitor_printf(mon, " (%s)", inserted->node_name); | |
374 | } | |
375 | } else { | |
376 | assert(inserted); | |
377 | monitor_printf(mon, "%s", | |
378 | inserted->has_node_name | |
379 | ? inserted->node_name | |
380 | : "<anonymous>"); | |
381 | } | |
382 | ||
289b276c KW |
383 | if (inserted) { |
384 | monitor_printf(mon, ": %s (%s%s%s)\n", | |
385 | inserted->file, | |
386 | inserted->drv, | |
387 | inserted->ro ? ", read-only" : "", | |
388 | inserted->encrypted ? ", encrypted" : ""); | |
389 | } else { | |
390 | monitor_printf(mon, ": [not inserted]\n"); | |
391 | } | |
b2023818 | 392 | |
8d6adccd KW |
393 | if (info) { |
394 | if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) { | |
395 | monitor_printf(mon, " I/O status: %s\n", | |
396 | BlockDeviceIoStatus_lookup[info->io_status]); | |
397 | } | |
b2023818 | 398 | |
8d6adccd KW |
399 | if (info->removable) { |
400 | monitor_printf(mon, " Removable device: %slocked, tray %s\n", | |
401 | info->locked ? "" : "not ", | |
402 | info->tray_open ? "open" : "closed"); | |
403 | } | |
289b276c | 404 | } |
fbe2e26c | 405 | |
b2023818 | 406 | |
289b276c KW |
407 | if (!inserted) { |
408 | return; | |
409 | } | |
b2023818 | 410 | |
289b276c KW |
411 | monitor_printf(mon, " Cache mode: %s%s%s\n", |
412 | inserted->cache->writeback ? "writeback" : "writethrough", | |
413 | inserted->cache->direct ? ", direct" : "", | |
414 | inserted->cache->no_flush ? ", ignore flushes" : ""); | |
415 | ||
416 | if (inserted->has_backing_file) { | |
417 | monitor_printf(mon, | |
418 | " Backing file: %s " | |
419 | "(chain depth: %" PRId64 ")\n", | |
420 | inserted->backing_file, | |
421 | inserted->backing_file_depth); | |
422 | } | |
727f005e | 423 | |
289b276c KW |
424 | if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) { |
425 | monitor_printf(mon, " Detect zeroes: %s\n", | |
426 | BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]); | |
427 | } | |
fbe2e26c | 428 | |
289b276c KW |
429 | if (inserted->bps || inserted->bps_rd || inserted->bps_wr || |
430 | inserted->iops || inserted->iops_rd || inserted->iops_wr) | |
431 | { | |
432 | monitor_printf(mon, " I/O throttling: bps=%" PRId64 | |
433 | " bps_rd=%" PRId64 " bps_wr=%" PRId64 | |
434 | " bps_max=%" PRId64 | |
435 | " bps_rd_max=%" PRId64 | |
436 | " bps_wr_max=%" PRId64 | |
437 | " iops=%" PRId64 " iops_rd=%" PRId64 | |
438 | " iops_wr=%" PRId64 | |
439 | " iops_max=%" PRId64 | |
440 | " iops_rd_max=%" PRId64 | |
441 | " iops_wr_max=%" PRId64 | |
b8fe1694 AG |
442 | " iops_size=%" PRId64 |
443 | " group=%s\n", | |
289b276c KW |
444 | inserted->bps, |
445 | inserted->bps_rd, | |
446 | inserted->bps_wr, | |
447 | inserted->bps_max, | |
448 | inserted->bps_rd_max, | |
449 | inserted->bps_wr_max, | |
450 | inserted->iops, | |
451 | inserted->iops_rd, | |
452 | inserted->iops_wr, | |
453 | inserted->iops_max, | |
454 | inserted->iops_rd_max, | |
455 | inserted->iops_wr_max, | |
b8fe1694 AG |
456 | inserted->iops_size, |
457 | inserted->group); | |
289b276c | 458 | } |
fbe2e26c | 459 | |
9419874f | 460 | if (verbose) { |
289b276c KW |
461 | monitor_printf(mon, "\nImages:\n"); |
462 | image_info = inserted->image; | |
463 | while (1) { | |
464 | bdrv_image_info_dump((fprintf_function)monitor_printf, | |
465 | mon, image_info); | |
466 | if (image_info->has_backing_image) { | |
467 | image_info = image_info->backing_image; | |
468 | } else { | |
469 | break; | |
470 | } | |
471 | } | |
472 | } | |
473 | } | |
9e193c5a | 474 | |
289b276c KW |
475 | void hmp_info_block(Monitor *mon, const QDict *qdict) |
476 | { | |
477 | BlockInfoList *block_list, *info; | |
e6bb31ec | 478 | BlockDeviceInfoList *blockdev_list, *blockdev; |
289b276c | 479 | const char *device = qdict_get_try_str(qdict, "device"); |
34acbc95 EB |
480 | bool verbose = qdict_get_try_bool(qdict, "verbose", false); |
481 | bool nodes = qdict_get_try_bool(qdict, "nodes", false); | |
e6bb31ec | 482 | bool printed = false; |
9e193c5a | 483 | |
e6bb31ec KW |
484 | /* Print BlockBackend information */ |
485 | if (!nodes) { | |
f19e44bc | 486 | block_list = qmp_query_block(NULL); |
e6bb31ec KW |
487 | } else { |
488 | block_list = NULL; | |
489 | } | |
fbe2e26c | 490 | |
289b276c KW |
491 | for (info = block_list; info; info = info->next) { |
492 | if (device && strcmp(device, info->value->device)) { | |
493 | continue; | |
465bee1d PL |
494 | } |
495 | ||
289b276c KW |
496 | if (info != block_list) { |
497 | monitor_printf(mon, "\n"); | |
fbe2e26c | 498 | } |
bd093a36 | 499 | |
289b276c KW |
500 | print_block_info(mon, info->value, info->value->has_inserted |
501 | ? info->value->inserted : NULL, | |
502 | verbose); | |
e6bb31ec | 503 | printed = true; |
b2023818 LC |
504 | } |
505 | ||
506 | qapi_free_BlockInfoList(block_list); | |
e6bb31ec KW |
507 | |
508 | if ((!device && !nodes) || printed) { | |
509 | return; | |
510 | } | |
511 | ||
512 | /* Print node information */ | |
513 | blockdev_list = qmp_query_named_block_nodes(NULL); | |
514 | for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) { | |
515 | assert(blockdev->value->has_node_name); | |
516 | if (device && strcmp(device, blockdev->value->node_name)) { | |
517 | continue; | |
518 | } | |
519 | ||
520 | if (blockdev != blockdev_list) { | |
521 | monitor_printf(mon, "\n"); | |
522 | } | |
523 | ||
524 | print_block_info(mon, NULL, blockdev->value, verbose); | |
525 | } | |
526 | qapi_free_BlockDeviceInfoList(blockdev_list); | |
b2023818 LC |
527 | } |
528 | ||
84f2d0ea | 529 | void hmp_info_blockstats(Monitor *mon, const QDict *qdict) |
f11f57e4 LC |
530 | { |
531 | BlockStatsList *stats_list, *stats; | |
532 | ||
f71eaa74 | 533 | stats_list = qmp_query_blockstats(false, false, NULL); |
f11f57e4 LC |
534 | |
535 | for (stats = stats_list; stats; stats = stats->next) { | |
536 | if (!stats->value->has_device) { | |
537 | continue; | |
538 | } | |
539 | ||
540 | monitor_printf(mon, "%s:", stats->value->device); | |
541 | monitor_printf(mon, " rd_bytes=%" PRId64 | |
542 | " wr_bytes=%" PRId64 | |
543 | " rd_operations=%" PRId64 | |
544 | " wr_operations=%" PRId64 | |
545 | " flush_operations=%" PRId64 | |
546 | " wr_total_time_ns=%" PRId64 | |
547 | " rd_total_time_ns=%" PRId64 | |
548 | " flush_total_time_ns=%" PRId64 | |
f4564d53 PL |
549 | " rd_merged=%" PRId64 |
550 | " wr_merged=%" PRId64 | |
cb38fffb | 551 | " idle_time_ns=%" PRId64 |
f11f57e4 LC |
552 | "\n", |
553 | stats->value->stats->rd_bytes, | |
554 | stats->value->stats->wr_bytes, | |
555 | stats->value->stats->rd_operations, | |
556 | stats->value->stats->wr_operations, | |
557 | stats->value->stats->flush_operations, | |
558 | stats->value->stats->wr_total_time_ns, | |
559 | stats->value->stats->rd_total_time_ns, | |
f4564d53 PL |
560 | stats->value->stats->flush_total_time_ns, |
561 | stats->value->stats->rd_merged, | |
cb38fffb AG |
562 | stats->value->stats->wr_merged, |
563 | stats->value->stats->idle_time_ns); | |
f11f57e4 LC |
564 | } |
565 | ||
566 | qapi_free_BlockStatsList(stats_list); | |
567 | } | |
568 | ||
84f2d0ea | 569 | void hmp_info_vnc(Monitor *mon, const QDict *qdict) |
2b54aa87 LC |
570 | { |
571 | VncInfo *info; | |
572 | Error *err = NULL; | |
573 | VncClientInfoList *client; | |
574 | ||
575 | info = qmp_query_vnc(&err); | |
576 | if (err) { | |
193227f9 | 577 | error_report_err(err); |
2b54aa87 LC |
578 | return; |
579 | } | |
580 | ||
581 | if (!info->enabled) { | |
582 | monitor_printf(mon, "Server: disabled\n"); | |
583 | goto out; | |
584 | } | |
585 | ||
586 | monitor_printf(mon, "Server:\n"); | |
587 | if (info->has_host && info->has_service) { | |
588 | monitor_printf(mon, " address: %s:%s\n", info->host, info->service); | |
589 | } | |
590 | if (info->has_auth) { | |
591 | monitor_printf(mon, " auth: %s\n", info->auth); | |
592 | } | |
593 | ||
594 | if (!info->has_clients || info->clients == NULL) { | |
595 | monitor_printf(mon, "Client: none\n"); | |
596 | } else { | |
597 | for (client = info->clients; client; client = client->next) { | |
598 | monitor_printf(mon, "Client:\n"); | |
599 | monitor_printf(mon, " address: %s:%s\n", | |
ddf21908 EB |
600 | client->value->host, |
601 | client->value->service); | |
2b54aa87 LC |
602 | monitor_printf(mon, " x509_dname: %s\n", |
603 | client->value->x509_dname ? | |
604 | client->value->x509_dname : "none"); | |
605 | monitor_printf(mon, " username: %s\n", | |
606 | client->value->has_sasl_username ? | |
607 | client->value->sasl_username : "none"); | |
608 | } | |
609 | } | |
610 | ||
611 | out: | |
612 | qapi_free_VncInfo(info); | |
613 | } | |
614 | ||
206addd5 | 615 | #ifdef CONFIG_SPICE |
84f2d0ea | 616 | void hmp_info_spice(Monitor *mon, const QDict *qdict) |
d1f29646 LC |
617 | { |
618 | SpiceChannelList *chan; | |
619 | SpiceInfo *info; | |
22fa7da0 CR |
620 | const char *channel_name; |
621 | const char * const channel_names[] = { | |
622 | [SPICE_CHANNEL_MAIN] = "main", | |
623 | [SPICE_CHANNEL_DISPLAY] = "display", | |
624 | [SPICE_CHANNEL_INPUTS] = "inputs", | |
625 | [SPICE_CHANNEL_CURSOR] = "cursor", | |
626 | [SPICE_CHANNEL_PLAYBACK] = "playback", | |
627 | [SPICE_CHANNEL_RECORD] = "record", | |
628 | [SPICE_CHANNEL_TUNNEL] = "tunnel", | |
629 | [SPICE_CHANNEL_SMARTCARD] = "smartcard", | |
630 | [SPICE_CHANNEL_USBREDIR] = "usbredir", | |
631 | [SPICE_CHANNEL_PORT] = "port", | |
7c6044a9 GH |
632 | #if 0 |
633 | /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7, | |
634 | * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable | |
635 | * as quick fix for build failures with older versions. */ | |
22fa7da0 | 636 | [SPICE_CHANNEL_WEBDAV] = "webdav", |
7c6044a9 | 637 | #endif |
22fa7da0 | 638 | }; |
d1f29646 LC |
639 | |
640 | info = qmp_query_spice(NULL); | |
641 | ||
642 | if (!info->enabled) { | |
643 | monitor_printf(mon, "Server: disabled\n"); | |
644 | goto out; | |
645 | } | |
646 | ||
647 | monitor_printf(mon, "Server:\n"); | |
648 | if (info->has_port) { | |
649 | monitor_printf(mon, " address: %s:%" PRId64 "\n", | |
650 | info->host, info->port); | |
651 | } | |
652 | if (info->has_tls_port) { | |
653 | monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n", | |
654 | info->host, info->tls_port); | |
655 | } | |
61c4efe2 YH |
656 | monitor_printf(mon, " migrated: %s\n", |
657 | info->migrated ? "true" : "false"); | |
d1f29646 LC |
658 | monitor_printf(mon, " auth: %s\n", info->auth); |
659 | monitor_printf(mon, " compiled: %s\n", info->compiled_version); | |
4efee029 AL |
660 | monitor_printf(mon, " mouse-mode: %s\n", |
661 | SpiceQueryMouseMode_lookup[info->mouse_mode]); | |
d1f29646 LC |
662 | |
663 | if (!info->has_channels || info->channels == NULL) { | |
664 | monitor_printf(mon, "Channels: none\n"); | |
665 | } else { | |
666 | for (chan = info->channels; chan; chan = chan->next) { | |
667 | monitor_printf(mon, "Channel:\n"); | |
668 | monitor_printf(mon, " address: %s:%s%s\n", | |
ddf21908 | 669 | chan->value->host, chan->value->port, |
d1f29646 LC |
670 | chan->value->tls ? " [tls]" : ""); |
671 | monitor_printf(mon, " session: %" PRId64 "\n", | |
672 | chan->value->connection_id); | |
673 | monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n", | |
674 | chan->value->channel_type, chan->value->channel_id); | |
22fa7da0 CR |
675 | |
676 | channel_name = "unknown"; | |
677 | if (chan->value->channel_type > 0 && | |
678 | chan->value->channel_type < ARRAY_SIZE(channel_names) && | |
679 | channel_names[chan->value->channel_type]) { | |
680 | channel_name = channel_names[chan->value->channel_type]; | |
681 | } | |
682 | ||
683 | monitor_printf(mon, " channel name: %s\n", channel_name); | |
d1f29646 LC |
684 | } |
685 | } | |
686 | ||
687 | out: | |
688 | qapi_free_SpiceInfo(info); | |
689 | } | |
206addd5 | 690 | #endif |
d1f29646 | 691 | |
84f2d0ea | 692 | void hmp_info_balloon(Monitor *mon, const QDict *qdict) |
96637bcd LC |
693 | { |
694 | BalloonInfo *info; | |
695 | Error *err = NULL; | |
696 | ||
697 | info = qmp_query_balloon(&err); | |
698 | if (err) { | |
193227f9 | 699 | error_report_err(err); |
96637bcd LC |
700 | return; |
701 | } | |
702 | ||
01ceb97e | 703 | monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20); |
96637bcd LC |
704 | |
705 | qapi_free_BalloonInfo(info); | |
706 | } | |
707 | ||
79627472 LC |
708 | static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) |
709 | { | |
710 | PciMemoryRegionList *region; | |
711 | ||
712 | monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus); | |
713 | monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n", | |
714 | dev->slot, dev->function); | |
715 | monitor_printf(mon, " "); | |
716 | ||
9fa02cd1 EB |
717 | if (dev->class_info->has_desc) { |
718 | monitor_printf(mon, "%s", dev->class_info->desc); | |
79627472 | 719 | } else { |
9fa02cd1 | 720 | monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class); |
79627472 LC |
721 | } |
722 | ||
723 | monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n", | |
9fa02cd1 | 724 | dev->id->vendor, dev->id->device); |
79627472 LC |
725 | |
726 | if (dev->has_irq) { | |
727 | monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq); | |
728 | } | |
729 | ||
730 | if (dev->has_pci_bridge) { | |
731 | monitor_printf(mon, " BUS %" PRId64 ".\n", | |
9fa02cd1 | 732 | dev->pci_bridge->bus->number); |
79627472 | 733 | monitor_printf(mon, " secondary bus %" PRId64 ".\n", |
9fa02cd1 | 734 | dev->pci_bridge->bus->secondary); |
79627472 | 735 | monitor_printf(mon, " subordinate bus %" PRId64 ".\n", |
9fa02cd1 | 736 | dev->pci_bridge->bus->subordinate); |
79627472 LC |
737 | |
738 | monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n", | |
9fa02cd1 EB |
739 | dev->pci_bridge->bus->io_range->base, |
740 | dev->pci_bridge->bus->io_range->limit); | |
79627472 LC |
741 | |
742 | monitor_printf(mon, | |
743 | " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n", | |
9fa02cd1 EB |
744 | dev->pci_bridge->bus->memory_range->base, |
745 | dev->pci_bridge->bus->memory_range->limit); | |
79627472 LC |
746 | |
747 | monitor_printf(mon, " prefetchable memory range " | |
748 | "[0x%08"PRIx64", 0x%08"PRIx64"]\n", | |
9fa02cd1 EB |
749 | dev->pci_bridge->bus->prefetchable_range->base, |
750 | dev->pci_bridge->bus->prefetchable_range->limit); | |
79627472 LC |
751 | } |
752 | ||
753 | for (region = dev->regions; region; region = region->next) { | |
754 | uint64_t addr, size; | |
755 | ||
756 | addr = region->value->address; | |
757 | size = region->value->size; | |
758 | ||
759 | monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar); | |
760 | ||
761 | if (!strcmp(region->value->type, "io")) { | |
762 | monitor_printf(mon, "I/O at 0x%04" PRIx64 | |
763 | " [0x%04" PRIx64 "].\n", | |
764 | addr, addr + size - 1); | |
765 | } else { | |
766 | monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64 | |
767 | " [0x%08" PRIx64 "].\n", | |
768 | region->value->mem_type_64 ? 64 : 32, | |
769 | region->value->prefetch ? " prefetchable" : "", | |
770 | addr, addr + size - 1); | |
771 | } | |
772 | } | |
773 | ||
774 | monitor_printf(mon, " id \"%s\"\n", dev->qdev_id); | |
775 | ||
776 | if (dev->has_pci_bridge) { | |
777 | if (dev->pci_bridge->has_devices) { | |
778 | PciDeviceInfoList *cdev; | |
779 | for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) { | |
780 | hmp_info_pci_device(mon, cdev->value); | |
781 | } | |
782 | } | |
783 | } | |
784 | } | |
785 | ||
84f2d0ea | 786 | void hmp_info_pci(Monitor *mon, const QDict *qdict) |
79627472 | 787 | { |
f46cee37 | 788 | PciInfoList *info_list, *info; |
79627472 LC |
789 | Error *err = NULL; |
790 | ||
f46cee37 | 791 | info_list = qmp_query_pci(&err); |
79627472 LC |
792 | if (err) { |
793 | monitor_printf(mon, "PCI devices not supported\n"); | |
794 | error_free(err); | |
795 | return; | |
796 | } | |
797 | ||
f46cee37 | 798 | for (info = info_list; info; info = info->next) { |
79627472 LC |
799 | PciDeviceInfoList *dev; |
800 | ||
801 | for (dev = info->value->devices; dev; dev = dev->next) { | |
802 | hmp_info_pci_device(mon, dev->value); | |
803 | } | |
804 | } | |
805 | ||
f46cee37 | 806 | qapi_free_PciInfoList(info_list); |
79627472 LC |
807 | } |
808 | ||
84f2d0ea | 809 | void hmp_info_block_jobs(Monitor *mon, const QDict *qdict) |
fb5458cd SH |
810 | { |
811 | BlockJobInfoList *list; | |
812 | Error *err = NULL; | |
813 | ||
814 | list = qmp_query_block_jobs(&err); | |
815 | assert(!err); | |
816 | ||
817 | if (!list) { | |
818 | monitor_printf(mon, "No active jobs\n"); | |
819 | return; | |
820 | } | |
821 | ||
822 | while (list) { | |
823 | if (strcmp(list->value->type, "stream") == 0) { | |
824 | monitor_printf(mon, "Streaming device %s: Completed %" PRId64 | |
825 | " of %" PRId64 " bytes, speed limit %" PRId64 | |
826 | " bytes/s\n", | |
827 | list->value->device, | |
828 | list->value->offset, | |
829 | list->value->len, | |
830 | list->value->speed); | |
831 | } else { | |
832 | monitor_printf(mon, "Type %s, device %s: Completed %" PRId64 | |
833 | " of %" PRId64 " bytes, speed limit %" PRId64 | |
834 | " bytes/s\n", | |
835 | list->value->type, | |
836 | list->value->device, | |
837 | list->value->offset, | |
838 | list->value->len, | |
839 | list->value->speed); | |
840 | } | |
841 | list = list->next; | |
842 | } | |
93bb1315 GA |
843 | |
844 | qapi_free_BlockJobInfoList(list); | |
fb5458cd SH |
845 | } |
846 | ||
d1a0cf73 SB |
847 | void hmp_info_tpm(Monitor *mon, const QDict *qdict) |
848 | { | |
849 | TPMInfoList *info_list, *info; | |
850 | Error *err = NULL; | |
851 | unsigned int c = 0; | |
852 | TPMPassthroughOptions *tpo; | |
853 | ||
854 | info_list = qmp_query_tpm(&err); | |
855 | if (err) { | |
856 | monitor_printf(mon, "TPM device not supported\n"); | |
857 | error_free(err); | |
858 | return; | |
859 | } | |
860 | ||
861 | if (info_list) { | |
862 | monitor_printf(mon, "TPM device:\n"); | |
863 | } | |
864 | ||
865 | for (info = info_list; info; info = info->next) { | |
866 | TPMInfo *ti = info->value; | |
867 | monitor_printf(mon, " tpm%d: model=%s\n", | |
868 | c, TpmModel_lookup[ti->model]); | |
869 | ||
870 | monitor_printf(mon, " \\ %s: type=%s", | |
ce21131a | 871 | ti->id, TpmTypeOptionsKind_lookup[ti->options->type]); |
d1a0cf73 | 872 | |
ce21131a | 873 | switch (ti->options->type) { |
88ca7bcf | 874 | case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH: |
32bafa8f | 875 | tpo = ti->options->u.passthrough.data; |
d1a0cf73 SB |
876 | monitor_printf(mon, "%s%s%s%s", |
877 | tpo->has_path ? ",path=" : "", | |
878 | tpo->has_path ? tpo->path : "", | |
879 | tpo->has_cancel_path ? ",cancel-path=" : "", | |
880 | tpo->has_cancel_path ? tpo->cancel_path : ""); | |
881 | break; | |
7fb1cf16 | 882 | case TPM_TYPE_OPTIONS_KIND__MAX: |
d1a0cf73 SB |
883 | break; |
884 | } | |
885 | monitor_printf(mon, "\n"); | |
886 | c++; | |
887 | } | |
888 | qapi_free_TPMInfoList(info_list); | |
889 | } | |
890 | ||
7a7f325e LC |
891 | void hmp_quit(Monitor *mon, const QDict *qdict) |
892 | { | |
893 | monitor_suspend(mon); | |
894 | qmp_quit(NULL); | |
895 | } | |
5f158f21 LC |
896 | |
897 | void hmp_stop(Monitor *mon, const QDict *qdict) | |
898 | { | |
899 | qmp_stop(NULL); | |
900 | } | |
38d22653 LC |
901 | |
902 | void hmp_system_reset(Monitor *mon, const QDict *qdict) | |
903 | { | |
904 | qmp_system_reset(NULL); | |
905 | } | |
5bc465e4 LC |
906 | |
907 | void hmp_system_powerdown(Monitor *mon, const QDict *qdict) | |
908 | { | |
909 | qmp_system_powerdown(NULL); | |
910 | } | |
755f1968 LC |
911 | |
912 | void hmp_cpu(Monitor *mon, const QDict *qdict) | |
913 | { | |
914 | int64_t cpu_index; | |
915 | ||
916 | /* XXX: drop the monitor_set_cpu() usage when all HMP commands that | |
917 | use it are converted to the QAPI */ | |
918 | cpu_index = qdict_get_int(qdict, "index"); | |
919 | if (monitor_set_cpu(cpu_index) < 0) { | |
920 | monitor_printf(mon, "invalid CPU index\n"); | |
921 | } | |
922 | } | |
0cfd6a9a LC |
923 | |
924 | void hmp_memsave(Monitor *mon, const QDict *qdict) | |
925 | { | |
926 | uint32_t size = qdict_get_int(qdict, "size"); | |
927 | const char *filename = qdict_get_str(qdict, "filename"); | |
928 | uint64_t addr = qdict_get_int(qdict, "val"); | |
e940f543 | 929 | Error *err = NULL; |
0cfd6a9a | 930 | |
e940f543 MA |
931 | qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &err); |
932 | hmp_handle_error(mon, &err); | |
0cfd6a9a | 933 | } |
6d3962bf LC |
934 | |
935 | void hmp_pmemsave(Monitor *mon, const QDict *qdict) | |
936 | { | |
937 | uint32_t size = qdict_get_int(qdict, "size"); | |
938 | const char *filename = qdict_get_str(qdict, "filename"); | |
939 | uint64_t addr = qdict_get_int(qdict, "val"); | |
e940f543 | 940 | Error *err = NULL; |
6d3962bf | 941 | |
e940f543 MA |
942 | qmp_pmemsave(addr, size, filename, &err); |
943 | hmp_handle_error(mon, &err); | |
1f590cf9 LL |
944 | } |
945 | ||
3949e594 | 946 | void hmp_ringbuf_write(Monitor *mon, const QDict *qdict) |
1f590cf9 | 947 | { |
1f590cf9 LL |
948 | const char *chardev = qdict_get_str(qdict, "device"); |
949 | const char *data = qdict_get_str(qdict, "data"); | |
e940f543 | 950 | Error *err = NULL; |
1f590cf9 | 951 | |
e940f543 | 952 | qmp_ringbuf_write(chardev, data, false, 0, &err); |
1f590cf9 | 953 | |
e940f543 | 954 | hmp_handle_error(mon, &err); |
6d3962bf | 955 | } |
e42e818b | 956 | |
3949e594 | 957 | void hmp_ringbuf_read(Monitor *mon, const QDict *qdict) |
49b6d722 LL |
958 | { |
959 | uint32_t size = qdict_get_int(qdict, "size"); | |
960 | const char *chardev = qdict_get_str(qdict, "device"); | |
3ab651fc | 961 | char *data; |
e940f543 | 962 | Error *err = NULL; |
543f3412 | 963 | int i; |
49b6d722 | 964 | |
e940f543 MA |
965 | data = qmp_ringbuf_read(chardev, size, false, 0, &err); |
966 | if (err) { | |
193227f9 | 967 | error_report_err(err); |
49b6d722 LL |
968 | return; |
969 | } | |
970 | ||
543f3412 MA |
971 | for (i = 0; data[i]; i++) { |
972 | unsigned char ch = data[i]; | |
973 | ||
974 | if (ch == '\\') { | |
975 | monitor_printf(mon, "\\\\"); | |
976 | } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) { | |
977 | monitor_printf(mon, "\\u%04X", ch); | |
978 | } else { | |
979 | monitor_printf(mon, "%c", ch); | |
980 | } | |
981 | ||
982 | } | |
983 | monitor_printf(mon, "\n"); | |
3ab651fc | 984 | g_free(data); |
49b6d722 LL |
985 | } |
986 | ||
e42e818b LC |
987 | static void hmp_cont_cb(void *opaque, int err) |
988 | { | |
e42e818b | 989 | if (!err) { |
8b7f6fbb | 990 | qmp_cont(NULL); |
e42e818b LC |
991 | } |
992 | } | |
993 | ||
8b7f6fbb LC |
994 | static bool key_is_missing(const BlockInfo *bdev) |
995 | { | |
996 | return (bdev->inserted && bdev->inserted->encryption_key_missing); | |
997 | } | |
998 | ||
e42e818b LC |
999 | void hmp_cont(Monitor *mon, const QDict *qdict) |
1000 | { | |
8b7f6fbb | 1001 | BlockInfoList *bdev_list, *bdev; |
e940f543 | 1002 | Error *err = NULL; |
e42e818b | 1003 | |
8b7f6fbb LC |
1004 | bdev_list = qmp_query_block(NULL); |
1005 | for (bdev = bdev_list; bdev; bdev = bdev->next) { | |
1006 | if (key_is_missing(bdev->value)) { | |
1007 | monitor_read_block_device_key(mon, bdev->value->device, | |
1008 | hmp_cont_cb, NULL); | |
1009 | goto out; | |
e42e818b | 1010 | } |
e42e818b | 1011 | } |
8b7f6fbb | 1012 | |
e940f543 MA |
1013 | qmp_cont(&err); |
1014 | hmp_handle_error(mon, &err); | |
8b7f6fbb LC |
1015 | |
1016 | out: | |
1017 | qapi_free_BlockInfoList(bdev_list); | |
e42e818b | 1018 | } |
ab49ab5c | 1019 | |
9b9df25a GH |
1020 | void hmp_system_wakeup(Monitor *mon, const QDict *qdict) |
1021 | { | |
1022 | qmp_system_wakeup(NULL); | |
1023 | } | |
1024 | ||
3e5a50d6 | 1025 | void hmp_nmi(Monitor *mon, const QDict *qdict) |
ab49ab5c | 1026 | { |
e940f543 | 1027 | Error *err = NULL; |
ab49ab5c | 1028 | |
e940f543 MA |
1029 | qmp_inject_nmi(&err); |
1030 | hmp_handle_error(mon, &err); | |
ab49ab5c | 1031 | } |
4b37156c LC |
1032 | |
1033 | void hmp_set_link(Monitor *mon, const QDict *qdict) | |
1034 | { | |
1035 | const char *name = qdict_get_str(qdict, "name"); | |
34acbc95 | 1036 | bool up = qdict_get_bool(qdict, "up"); |
e940f543 | 1037 | Error *err = NULL; |
4b37156c | 1038 | |
e940f543 MA |
1039 | qmp_set_link(name, up, &err); |
1040 | hmp_handle_error(mon, &err); | |
4b37156c | 1041 | } |
a4dea8a9 LC |
1042 | |
1043 | void hmp_block_passwd(Monitor *mon, const QDict *qdict) | |
1044 | { | |
1045 | const char *device = qdict_get_str(qdict, "device"); | |
1046 | const char *password = qdict_get_str(qdict, "password"); | |
e940f543 | 1047 | Error *err = NULL; |
a4dea8a9 | 1048 | |
e940f543 MA |
1049 | qmp_block_passwd(true, device, false, NULL, password, &err); |
1050 | hmp_handle_error(mon, &err); | |
a4dea8a9 | 1051 | } |
d72f3264 LC |
1052 | |
1053 | void hmp_balloon(Monitor *mon, const QDict *qdict) | |
1054 | { | |
1055 | int64_t value = qdict_get_int(qdict, "value"); | |
e940f543 | 1056 | Error *err = NULL; |
d72f3264 | 1057 | |
e940f543 MA |
1058 | qmp_balloon(value, &err); |
1059 | if (err) { | |
193227f9 | 1060 | error_report_err(err); |
d72f3264 LC |
1061 | } |
1062 | } | |
5e7caacb LC |
1063 | |
1064 | void hmp_block_resize(Monitor *mon, const QDict *qdict) | |
1065 | { | |
1066 | const char *device = qdict_get_str(qdict, "device"); | |
1067 | int64_t size = qdict_get_int(qdict, "size"); | |
e940f543 | 1068 | Error *err = NULL; |
5e7caacb | 1069 | |
e940f543 MA |
1070 | qmp_block_resize(true, device, false, NULL, size, &err); |
1071 | hmp_handle_error(mon, &err); | |
5e7caacb | 1072 | } |
6106e249 | 1073 | |
d9b902db PB |
1074 | void hmp_drive_mirror(Monitor *mon, const QDict *qdict) |
1075 | { | |
1076 | const char *device = qdict_get_str(qdict, "device"); | |
1077 | const char *filename = qdict_get_str(qdict, "target"); | |
1078 | const char *format = qdict_get_try_str(qdict, "format"); | |
34acbc95 EB |
1079 | bool reuse = qdict_get_try_bool(qdict, "reuse", false); |
1080 | bool full = qdict_get_try_bool(qdict, "full", false); | |
d9b902db | 1081 | enum NewImageMode mode; |
e940f543 | 1082 | Error *err = NULL; |
d9b902db PB |
1083 | |
1084 | if (!filename) { | |
c6bd8c70 | 1085 | error_setg(&err, QERR_MISSING_PARAMETER, "target"); |
e940f543 | 1086 | hmp_handle_error(mon, &err); |
d9b902db PB |
1087 | return; |
1088 | } | |
1089 | ||
1090 | if (reuse) { | |
1091 | mode = NEW_IMAGE_MODE_EXISTING; | |
1092 | } else { | |
1093 | mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS; | |
1094 | } | |
1095 | ||
1096 | qmp_drive_mirror(device, filename, !!format, format, | |
09158f00 | 1097 | false, NULL, false, NULL, |
d9b902db | 1098 | full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP, |
08e4ed6c | 1099 | true, mode, false, 0, false, 0, false, 0, |
0fc9f8ea | 1100 | false, 0, false, 0, false, true, &err); |
e940f543 | 1101 | hmp_handle_error(mon, &err); |
d9b902db PB |
1102 | } |
1103 | ||
de90930a SH |
1104 | void hmp_drive_backup(Monitor *mon, const QDict *qdict) |
1105 | { | |
1106 | const char *device = qdict_get_str(qdict, "device"); | |
1107 | const char *filename = qdict_get_str(qdict, "target"); | |
1108 | const char *format = qdict_get_try_str(qdict, "format"); | |
34acbc95 EB |
1109 | bool reuse = qdict_get_try_bool(qdict, "reuse", false); |
1110 | bool full = qdict_get_try_bool(qdict, "full", false); | |
de90930a | 1111 | enum NewImageMode mode; |
e940f543 | 1112 | Error *err = NULL; |
de90930a SH |
1113 | |
1114 | if (!filename) { | |
c6bd8c70 | 1115 | error_setg(&err, QERR_MISSING_PARAMETER, "target"); |
e940f543 | 1116 | hmp_handle_error(mon, &err); |
de90930a SH |
1117 | return; |
1118 | } | |
1119 | ||
1120 | if (reuse) { | |
1121 | mode = NEW_IMAGE_MODE_EXISTING; | |
1122 | } else { | |
1123 | mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS; | |
1124 | } | |
1125 | ||
1126 | qmp_drive_backup(device, filename, !!format, format, | |
1127 | full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP, | |
d58d8453 JS |
1128 | true, mode, false, 0, false, NULL, |
1129 | false, 0, false, 0, &err); | |
e940f543 | 1130 | hmp_handle_error(mon, &err); |
de90930a SH |
1131 | } |
1132 | ||
6106e249 LC |
1133 | void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) |
1134 | { | |
1135 | const char *device = qdict_get_str(qdict, "device"); | |
1136 | const char *filename = qdict_get_try_str(qdict, "snapshot-file"); | |
1137 | const char *format = qdict_get_try_str(qdict, "format"); | |
34acbc95 | 1138 | bool reuse = qdict_get_try_bool(qdict, "reuse", false); |
6cc2a415 | 1139 | enum NewImageMode mode; |
e940f543 | 1140 | Error *err = NULL; |
6106e249 LC |
1141 | |
1142 | if (!filename) { | |
1143 | /* In the future, if 'snapshot-file' is not specified, the snapshot | |
1144 | will be taken internally. Today it's actually required. */ | |
c6bd8c70 | 1145 | error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file"); |
e940f543 | 1146 | hmp_handle_error(mon, &err); |
6106e249 LC |
1147 | return; |
1148 | } | |
1149 | ||
6cc2a415 | 1150 | mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS; |
0901f67e BC |
1151 | qmp_blockdev_snapshot_sync(true, device, false, NULL, |
1152 | filename, false, NULL, | |
1153 | !!format, format, | |
e940f543 MA |
1154 | true, mode, &err); |
1155 | hmp_handle_error(mon, &err); | |
6106e249 | 1156 | } |
6cdedb07 | 1157 | |
775ca88e WX |
1158 | void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict) |
1159 | { | |
1160 | const char *device = qdict_get_str(qdict, "device"); | |
1161 | const char *name = qdict_get_str(qdict, "name"); | |
e940f543 | 1162 | Error *err = NULL; |
775ca88e | 1163 | |
e940f543 MA |
1164 | qmp_blockdev_snapshot_internal_sync(device, name, &err); |
1165 | hmp_handle_error(mon, &err); | |
775ca88e WX |
1166 | } |
1167 | ||
7a4ed2ee WX |
1168 | void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict) |
1169 | { | |
1170 | const char *device = qdict_get_str(qdict, "device"); | |
1171 | const char *name = qdict_get_str(qdict, "name"); | |
1172 | const char *id = qdict_get_try_str(qdict, "id"); | |
e940f543 | 1173 | Error *err = NULL; |
7a4ed2ee WX |
1174 | |
1175 | qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id, | |
e940f543 MA |
1176 | true, name, &err); |
1177 | hmp_handle_error(mon, &err); | |
7a4ed2ee WX |
1178 | } |
1179 | ||
6cdedb07 LC |
1180 | void hmp_migrate_cancel(Monitor *mon, const QDict *qdict) |
1181 | { | |
1182 | qmp_migrate_cancel(NULL); | |
1183 | } | |
4f0a993b | 1184 | |
bf1ae1f4 DDAG |
1185 | void hmp_migrate_incoming(Monitor *mon, const QDict *qdict) |
1186 | { | |
1187 | Error *err = NULL; | |
1188 | const char *uri = qdict_get_str(qdict, "uri"); | |
1189 | ||
1190 | qmp_migrate_incoming(uri, &err); | |
1191 | ||
1fa57f55 | 1192 | hmp_handle_error(mon, &err); |
bf1ae1f4 DDAG |
1193 | } |
1194 | ||
4f0a993b LC |
1195 | void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict) |
1196 | { | |
1197 | double value = qdict_get_double(qdict, "value"); | |
1198 | qmp_migrate_set_downtime(value, NULL); | |
1199 | } | |
3dc85383 | 1200 | |
9e1ba4cc OW |
1201 | void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict) |
1202 | { | |
1203 | int64_t value = qdict_get_int(qdict, "value"); | |
1204 | Error *err = NULL; | |
1205 | ||
1206 | qmp_migrate_set_cache_size(value, &err); | |
1207 | if (err) { | |
193227f9 | 1208 | error_report_err(err); |
9e1ba4cc OW |
1209 | return; |
1210 | } | |
1211 | } | |
1212 | ||
3dc85383 LC |
1213 | void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict) |
1214 | { | |
1215 | int64_t value = qdict_get_int(qdict, "value"); | |
1216 | qmp_migrate_set_speed(value, NULL); | |
1217 | } | |
fbf796fd | 1218 | |
00458433 OW |
1219 | void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict) |
1220 | { | |
1221 | const char *cap = qdict_get_str(qdict, "capability"); | |
1222 | bool state = qdict_get_bool(qdict, "state"); | |
1223 | Error *err = NULL; | |
1224 | MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps)); | |
1225 | int i; | |
1226 | ||
7fb1cf16 | 1227 | for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) { |
00458433 OW |
1228 | if (strcmp(cap, MigrationCapability_lookup[i]) == 0) { |
1229 | caps->value = g_malloc0(sizeof(*caps->value)); | |
1230 | caps->value->capability = i; | |
1231 | caps->value->state = state; | |
1232 | caps->next = NULL; | |
1233 | qmp_migrate_set_capabilities(caps, &err); | |
1234 | break; | |
1235 | } | |
1236 | } | |
1237 | ||
7fb1cf16 | 1238 | if (i == MIGRATION_CAPABILITY__MAX) { |
c6bd8c70 | 1239 | error_setg(&err, QERR_INVALID_PARAMETER, cap); |
00458433 OW |
1240 | } |
1241 | ||
1242 | qapi_free_MigrationCapabilityStatusList(caps); | |
1243 | ||
1244 | if (err) { | |
193227f9 | 1245 | error_report_err(err); |
00458433 OW |
1246 | } |
1247 | } | |
1248 | ||
50e9a629 LL |
1249 | void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) |
1250 | { | |
1251 | const char *param = qdict_get_str(qdict, "parameter"); | |
69ef1f36 DB |
1252 | const char *valuestr = qdict_get_str(qdict, "value"); |
1253 | long valueint = 0; | |
50e9a629 LL |
1254 | Error *err = NULL; |
1255 | bool has_compress_level = false; | |
1256 | bool has_compress_threads = false; | |
1257 | bool has_decompress_threads = false; | |
d85a31d1 JH |
1258 | bool has_cpu_throttle_initial = false; |
1259 | bool has_cpu_throttle_increment = false; | |
69ef1f36 DB |
1260 | bool has_tls_creds = false; |
1261 | bool has_tls_hostname = false; | |
1262 | bool use_int_value = false; | |
50e9a629 LL |
1263 | int i; |
1264 | ||
7fb1cf16 | 1265 | for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) { |
50e9a629 LL |
1266 | if (strcmp(param, MigrationParameter_lookup[i]) == 0) { |
1267 | switch (i) { | |
1268 | case MIGRATION_PARAMETER_COMPRESS_LEVEL: | |
1269 | has_compress_level = true; | |
69ef1f36 | 1270 | use_int_value = true; |
50e9a629 LL |
1271 | break; |
1272 | case MIGRATION_PARAMETER_COMPRESS_THREADS: | |
1273 | has_compress_threads = true; | |
69ef1f36 | 1274 | use_int_value = true; |
50e9a629 LL |
1275 | break; |
1276 | case MIGRATION_PARAMETER_DECOMPRESS_THREADS: | |
1277 | has_decompress_threads = true; | |
69ef1f36 | 1278 | use_int_value = true; |
50e9a629 | 1279 | break; |
d85a31d1 JH |
1280 | case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL: |
1281 | has_cpu_throttle_initial = true; | |
69ef1f36 | 1282 | use_int_value = true; |
1626fee3 | 1283 | break; |
d85a31d1 JH |
1284 | case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT: |
1285 | has_cpu_throttle_increment = true; | |
1626fee3 | 1286 | break; |
69ef1f36 DB |
1287 | case MIGRATION_PARAMETER_TLS_CREDS: |
1288 | has_tls_creds = true; | |
1289 | break; | |
1290 | case MIGRATION_PARAMETER_TLS_HOSTNAME: | |
1291 | has_tls_hostname = true; | |
1292 | break; | |
50e9a629 | 1293 | } |
69ef1f36 DB |
1294 | |
1295 | if (use_int_value) { | |
1296 | if (qemu_strtol(valuestr, NULL, 10, &valueint) < 0) { | |
1297 | error_setg(&err, "Unable to parse '%s' as an int", | |
1298 | valuestr); | |
1299 | goto cleanup; | |
1300 | } | |
1301 | } | |
1302 | ||
1303 | qmp_migrate_set_parameters(has_compress_level, valueint, | |
1304 | has_compress_threads, valueint, | |
1305 | has_decompress_threads, valueint, | |
1306 | has_cpu_throttle_initial, valueint, | |
1307 | has_cpu_throttle_increment, valueint, | |
1308 | has_tls_creds, valuestr, | |
1309 | has_tls_hostname, valuestr, | |
50e9a629 LL |
1310 | &err); |
1311 | break; | |
1312 | } | |
1313 | } | |
1314 | ||
7fb1cf16 | 1315 | if (i == MIGRATION_PARAMETER__MAX) { |
c6bd8c70 | 1316 | error_setg(&err, QERR_INVALID_PARAMETER, param); |
50e9a629 LL |
1317 | } |
1318 | ||
69ef1f36 | 1319 | cleanup: |
50e9a629 | 1320 | if (err) { |
193227f9 | 1321 | error_report_err(err); |
50e9a629 LL |
1322 | } |
1323 | } | |
1324 | ||
b8a185bc MA |
1325 | void hmp_client_migrate_info(Monitor *mon, const QDict *qdict) |
1326 | { | |
1327 | Error *err = NULL; | |
1328 | const char *protocol = qdict_get_str(qdict, "protocol"); | |
1329 | const char *hostname = qdict_get_str(qdict, "hostname"); | |
1330 | bool has_port = qdict_haskey(qdict, "port"); | |
1331 | int port = qdict_get_try_int(qdict, "port", -1); | |
1332 | bool has_tls_port = qdict_haskey(qdict, "tls-port"); | |
1333 | int tls_port = qdict_get_try_int(qdict, "tls-port", -1); | |
1334 | const char *cert_subject = qdict_get_try_str(qdict, "cert-subject"); | |
1335 | ||
1336 | qmp_client_migrate_info(protocol, hostname, | |
1337 | has_port, port, has_tls_port, tls_port, | |
1338 | !!cert_subject, cert_subject, &err); | |
1339 | hmp_handle_error(mon, &err); | |
1340 | } | |
1341 | ||
4886a1bc DDAG |
1342 | void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict) |
1343 | { | |
1344 | Error *err = NULL; | |
1345 | qmp_migrate_start_postcopy(&err); | |
1346 | hmp_handle_error(mon, &err); | |
1347 | } | |
1348 | ||
fbf796fd LC |
1349 | void hmp_set_password(Monitor *mon, const QDict *qdict) |
1350 | { | |
1351 | const char *protocol = qdict_get_str(qdict, "protocol"); | |
1352 | const char *password = qdict_get_str(qdict, "password"); | |
1353 | const char *connected = qdict_get_try_str(qdict, "connected"); | |
1354 | Error *err = NULL; | |
1355 | ||
1356 | qmp_set_password(protocol, password, !!connected, connected, &err); | |
1357 | hmp_handle_error(mon, &err); | |
1358 | } | |
9ad5372d LC |
1359 | |
1360 | void hmp_expire_password(Monitor *mon, const QDict *qdict) | |
1361 | { | |
1362 | const char *protocol = qdict_get_str(qdict, "protocol"); | |
1363 | const char *whenstr = qdict_get_str(qdict, "time"); | |
1364 | Error *err = NULL; | |
1365 | ||
1366 | qmp_expire_password(protocol, whenstr, &err); | |
1367 | hmp_handle_error(mon, &err); | |
1368 | } | |
c245b6a3 LC |
1369 | |
1370 | void hmp_eject(Monitor *mon, const QDict *qdict) | |
1371 | { | |
34acbc95 | 1372 | bool force = qdict_get_try_bool(qdict, "force", false); |
c245b6a3 LC |
1373 | const char *device = qdict_get_str(qdict, "device"); |
1374 | Error *err = NULL; | |
1375 | ||
1376 | qmp_eject(device, true, force, &err); | |
1377 | hmp_handle_error(mon, &err); | |
1378 | } | |
333a96ec | 1379 | |
c60bf339 SH |
1380 | static void hmp_change_read_arg(void *opaque, const char *password, |
1381 | void *readline_opaque) | |
333a96ec LC |
1382 | { |
1383 | qmp_change_vnc_password(password, NULL); | |
c60bf339 | 1384 | monitor_read_command(opaque, 1); |
333a96ec LC |
1385 | } |
1386 | ||
333a96ec LC |
1387 | void hmp_change(Monitor *mon, const QDict *qdict) |
1388 | { | |
1389 | const char *device = qdict_get_str(qdict, "device"); | |
1390 | const char *target = qdict_get_str(qdict, "target"); | |
1391 | const char *arg = qdict_get_try_str(qdict, "arg"); | |
baead0ab HR |
1392 | const char *read_only = qdict_get_try_str(qdict, "read-only-mode"); |
1393 | BlockdevChangeReadOnlyMode read_only_mode = 0; | |
333a96ec LC |
1394 | Error *err = NULL; |
1395 | ||
10686749 | 1396 | if (strcmp(device, "vnc") == 0) { |
baead0ab HR |
1397 | if (read_only) { |
1398 | monitor_printf(mon, | |
1399 | "Parameter 'read-only-mode' is invalid for VNC\n"); | |
1400 | return; | |
1401 | } | |
10686749 HR |
1402 | if (strcmp(target, "passwd") == 0 || |
1403 | strcmp(target, "password") == 0) { | |
1404 | if (!arg) { | |
1405 | monitor_read_password(mon, hmp_change_read_arg, NULL); | |
1406 | return; | |
1407 | } | |
1408 | } | |
1409 | qmp_change("vnc", target, !!arg, arg, &err); | |
1410 | } else { | |
baead0ab HR |
1411 | if (read_only) { |
1412 | read_only_mode = | |
1413 | qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup, | |
7fb1cf16 | 1414 | read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX, |
baead0ab HR |
1415 | BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err); |
1416 | if (err) { | |
1417 | hmp_handle_error(mon, &err); | |
1418 | return; | |
1419 | } | |
1420 | } | |
1421 | ||
1422 | qmp_blockdev_change_medium(device, target, !!arg, arg, | |
1423 | !!read_only, read_only_mode, &err); | |
10686749 HR |
1424 | if (err && |
1425 | error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) { | |
1426 | error_free(err); | |
1427 | monitor_read_block_device_key(mon, device, NULL, NULL); | |
333a96ec LC |
1428 | return; |
1429 | } | |
1430 | } | |
1431 | ||
333a96ec LC |
1432 | hmp_handle_error(mon, &err); |
1433 | } | |
80047da5 LC |
1434 | |
1435 | void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) | |
1436 | { | |
1437 | Error *err = NULL; | |
1438 | ||
1439 | qmp_block_set_io_throttle(qdict_get_str(qdict, "device"), | |
1440 | qdict_get_int(qdict, "bps"), | |
1441 | qdict_get_int(qdict, "bps_rd"), | |
1442 | qdict_get_int(qdict, "bps_wr"), | |
1443 | qdict_get_int(qdict, "iops"), | |
1444 | qdict_get_int(qdict, "iops_rd"), | |
3e9fab69 BC |
1445 | qdict_get_int(qdict, "iops_wr"), |
1446 | false, /* no burst max via HMP */ | |
1447 | 0, | |
1448 | false, | |
1449 | 0, | |
1450 | false, | |
1451 | 0, | |
1452 | false, | |
1453 | 0, | |
1454 | false, | |
1455 | 0, | |
1456 | false, | |
2024c1df | 1457 | 0, |
dce13204 AG |
1458 | false, /* no burst length via HMP */ |
1459 | 0, | |
1460 | false, | |
1461 | 0, | |
1462 | false, | |
1463 | 0, | |
1464 | false, | |
1465 | 0, | |
1466 | false, | |
1467 | 0, | |
1468 | false, | |
1469 | 0, | |
2024c1df | 1470 | false, /* No default I/O size */ |
76f4afb4 AG |
1471 | 0, |
1472 | false, | |
1473 | NULL, &err); | |
80047da5 LC |
1474 | hmp_handle_error(mon, &err); |
1475 | } | |
12bd451f SH |
1476 | |
1477 | void hmp_block_stream(Monitor *mon, const QDict *qdict) | |
1478 | { | |
1479 | Error *error = NULL; | |
1480 | const char *device = qdict_get_str(qdict, "device"); | |
1481 | const char *base = qdict_get_try_str(qdict, "base"); | |
c83c66c3 | 1482 | int64_t speed = qdict_get_try_int(qdict, "speed", 0); |
12bd451f | 1483 | |
13d8cc51 | 1484 | qmp_block_stream(device, base != NULL, base, false, NULL, |
1d809098 | 1485 | qdict_haskey(qdict, "speed"), speed, |
46663e5e | 1486 | true, BLOCKDEV_ON_ERROR_REPORT, &error); |
12bd451f SH |
1487 | |
1488 | hmp_handle_error(mon, &error); | |
1489 | } | |
2d47c6e9 SH |
1490 | |
1491 | void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict) | |
1492 | { | |
1493 | Error *error = NULL; | |
1494 | const char *device = qdict_get_str(qdict, "device"); | |
c6db2395 | 1495 | int64_t value = qdict_get_int(qdict, "speed"); |
2d47c6e9 SH |
1496 | |
1497 | qmp_block_job_set_speed(device, value, &error); | |
1498 | ||
1499 | hmp_handle_error(mon, &error); | |
1500 | } | |
370521a1 SH |
1501 | |
1502 | void hmp_block_job_cancel(Monitor *mon, const QDict *qdict) | |
1503 | { | |
1504 | Error *error = NULL; | |
1505 | const char *device = qdict_get_str(qdict, "device"); | |
34acbc95 | 1506 | bool force = qdict_get_try_bool(qdict, "force", false); |
370521a1 | 1507 | |
6e37fb81 PB |
1508 | qmp_block_job_cancel(device, true, force, &error); |
1509 | ||
1510 | hmp_handle_error(mon, &error); | |
1511 | } | |
1512 | ||
1513 | void hmp_block_job_pause(Monitor *mon, const QDict *qdict) | |
1514 | { | |
1515 | Error *error = NULL; | |
1516 | const char *device = qdict_get_str(qdict, "device"); | |
1517 | ||
1518 | qmp_block_job_pause(device, &error); | |
1519 | ||
1520 | hmp_handle_error(mon, &error); | |
1521 | } | |
1522 | ||
1523 | void hmp_block_job_resume(Monitor *mon, const QDict *qdict) | |
1524 | { | |
1525 | Error *error = NULL; | |
1526 | const char *device = qdict_get_str(qdict, "device"); | |
1527 | ||
1528 | qmp_block_job_resume(device, &error); | |
370521a1 SH |
1529 | |
1530 | hmp_handle_error(mon, &error); | |
1531 | } | |
e1c37d0e | 1532 | |
aeae883b PB |
1533 | void hmp_block_job_complete(Monitor *mon, const QDict *qdict) |
1534 | { | |
1535 | Error *error = NULL; | |
1536 | const char *device = qdict_get_str(qdict, "device"); | |
1537 | ||
1538 | qmp_block_job_complete(device, &error); | |
1539 | ||
1540 | hmp_handle_error(mon, &error); | |
1541 | } | |
1542 | ||
e49f35bd | 1543 | typedef struct HMPMigrationStatus |
e1c37d0e LC |
1544 | { |
1545 | QEMUTimer *timer; | |
1546 | Monitor *mon; | |
1547 | bool is_block_migration; | |
e49f35bd | 1548 | } HMPMigrationStatus; |
e1c37d0e LC |
1549 | |
1550 | static void hmp_migrate_status_cb(void *opaque) | |
1551 | { | |
e49f35bd | 1552 | HMPMigrationStatus *status = opaque; |
e1c37d0e LC |
1553 | MigrationInfo *info; |
1554 | ||
1555 | info = qmp_query_migrate(NULL); | |
24b8c39b HZ |
1556 | if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE || |
1557 | info->status == MIGRATION_STATUS_SETUP) { | |
e1c37d0e LC |
1558 | if (info->has_disk) { |
1559 | int progress; | |
1560 | ||
1561 | if (info->disk->remaining) { | |
1562 | progress = info->disk->transferred * 100 / info->disk->total; | |
1563 | } else { | |
1564 | progress = 100; | |
1565 | } | |
1566 | ||
1567 | monitor_printf(status->mon, "Completed %d %%\r", progress); | |
1568 | monitor_flush(status->mon); | |
1569 | } | |
1570 | ||
bc72ad67 | 1571 | timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000); |
e1c37d0e LC |
1572 | } else { |
1573 | if (status->is_block_migration) { | |
1574 | monitor_printf(status->mon, "\n"); | |
1575 | } | |
d59ce6f3 DB |
1576 | if (info->has_error_desc) { |
1577 | error_report("%s", info->error_desc); | |
1578 | } | |
e1c37d0e | 1579 | monitor_resume(status->mon); |
bc72ad67 | 1580 | timer_del(status->timer); |
e1c37d0e LC |
1581 | g_free(status); |
1582 | } | |
1583 | ||
1584 | qapi_free_MigrationInfo(info); | |
1585 | } | |
1586 | ||
1587 | void hmp_migrate(Monitor *mon, const QDict *qdict) | |
1588 | { | |
34acbc95 EB |
1589 | bool detach = qdict_get_try_bool(qdict, "detach", false); |
1590 | bool blk = qdict_get_try_bool(qdict, "blk", false); | |
1591 | bool inc = qdict_get_try_bool(qdict, "inc", false); | |
e1c37d0e LC |
1592 | const char *uri = qdict_get_str(qdict, "uri"); |
1593 | Error *err = NULL; | |
1594 | ||
1595 | qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err); | |
1596 | if (err) { | |
193227f9 | 1597 | error_report_err(err); |
e1c37d0e LC |
1598 | return; |
1599 | } | |
1600 | ||
1601 | if (!detach) { | |
e49f35bd | 1602 | HMPMigrationStatus *status; |
e1c37d0e LC |
1603 | |
1604 | if (monitor_suspend(mon) < 0) { | |
1605 | monitor_printf(mon, "terminal does not allow synchronous " | |
1606 | "migration, continuing detached\n"); | |
1607 | return; | |
1608 | } | |
1609 | ||
1610 | status = g_malloc0(sizeof(*status)); | |
1611 | status->mon = mon; | |
1612 | status->is_block_migration = blk || inc; | |
bc72ad67 | 1613 | status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb, |
e1c37d0e | 1614 | status); |
bc72ad67 | 1615 | timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME)); |
e1c37d0e LC |
1616 | } |
1617 | } | |
a15fef21 | 1618 | |
318660f8 MA |
1619 | void hmp_device_add(Monitor *mon, const QDict *qdict) |
1620 | { | |
485febc6 MA |
1621 | Error *err = NULL; |
1622 | ||
1623 | qmp_device_add((QDict *)qdict, NULL, &err); | |
1624 | hmp_handle_error(mon, &err); | |
318660f8 MA |
1625 | } |
1626 | ||
a15fef21 LC |
1627 | void hmp_device_del(Monitor *mon, const QDict *qdict) |
1628 | { | |
1629 | const char *id = qdict_get_str(qdict, "id"); | |
1630 | Error *err = NULL; | |
1631 | ||
1632 | qmp_device_del(id, &err); | |
1633 | hmp_handle_error(mon, &err); | |
1634 | } | |
783e9b48 WC |
1635 | |
1636 | void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) | |
1637 | { | |
e940f543 | 1638 | Error *err = NULL; |
34acbc95 EB |
1639 | bool paging = qdict_get_try_bool(qdict, "paging", false); |
1640 | bool zlib = qdict_get_try_bool(qdict, "zlib", false); | |
1641 | bool lzo = qdict_get_try_bool(qdict, "lzo", false); | |
1642 | bool snappy = qdict_get_try_bool(qdict, "snappy", false); | |
75363769 | 1643 | const char *file = qdict_get_str(qdict, "filename"); |
783e9b48 WC |
1644 | bool has_begin = qdict_haskey(qdict, "begin"); |
1645 | bool has_length = qdict_haskey(qdict, "length"); | |
228de9cf | 1646 | bool has_detach = qdict_haskey(qdict, "detach"); |
783e9b48 WC |
1647 | int64_t begin = 0; |
1648 | int64_t length = 0; | |
228de9cf | 1649 | bool detach = false; |
b53ccc30 | 1650 | enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF; |
75363769 | 1651 | char *prot; |
783e9b48 | 1652 | |
1b7a0f75 | 1653 | if (zlib + lzo + snappy > 1) { |
e940f543 MA |
1654 | error_setg(&err, "only one of '-z|-l|-s' can be set"); |
1655 | hmp_handle_error(mon, &err); | |
1b7a0f75 QN |
1656 | return; |
1657 | } | |
1658 | ||
1659 | if (zlib) { | |
1660 | dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB; | |
1661 | } | |
1662 | ||
1663 | if (lzo) { | |
1664 | dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO; | |
1665 | } | |
1666 | ||
1667 | if (snappy) { | |
1668 | dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY; | |
1669 | } | |
1670 | ||
783e9b48 WC |
1671 | if (has_begin) { |
1672 | begin = qdict_get_int(qdict, "begin"); | |
1673 | } | |
1674 | if (has_length) { | |
1675 | length = qdict_get_int(qdict, "length"); | |
1676 | } | |
228de9cf PX |
1677 | if (has_detach) { |
1678 | detach = qdict_get_bool(qdict, "detach"); | |
1679 | } | |
783e9b48 | 1680 | |
75363769 LC |
1681 | prot = g_strconcat("file:", file, NULL); |
1682 | ||
228de9cf PX |
1683 | qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin, |
1684 | has_length, length, true, dump_format, &err); | |
e940f543 | 1685 | hmp_handle_error(mon, &err); |
75363769 | 1686 | g_free(prot); |
783e9b48 | 1687 | } |
928059a3 LC |
1688 | |
1689 | void hmp_netdev_add(Monitor *mon, const QDict *qdict) | |
1690 | { | |
1691 | Error *err = NULL; | |
1692 | QemuOpts *opts; | |
1693 | ||
1694 | opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err); | |
84d18f06 | 1695 | if (err) { |
928059a3 LC |
1696 | goto out; |
1697 | } | |
1698 | ||
1699 | netdev_add(opts, &err); | |
84d18f06 | 1700 | if (err) { |
928059a3 LC |
1701 | qemu_opts_del(opts); |
1702 | } | |
1703 | ||
1704 | out: | |
1705 | hmp_handle_error(mon, &err); | |
1706 | } | |
5f964155 LC |
1707 | |
1708 | void hmp_netdev_del(Monitor *mon, const QDict *qdict) | |
1709 | { | |
1710 | const char *id = qdict_get_str(qdict, "id"); | |
1711 | Error *err = NULL; | |
1712 | ||
1713 | qmp_netdev_del(id, &err); | |
1714 | hmp_handle_error(mon, &err); | |
1715 | } | |
208c9d1b | 1716 | |
cff8b2c6 PB |
1717 | void hmp_object_add(Monitor *mon, const QDict *qdict) |
1718 | { | |
1719 | Error *err = NULL; | |
1720 | QemuOpts *opts; | |
cff8b2c6 | 1721 | OptsVisitor *ov; |
90998d58 | 1722 | Object *obj = NULL; |
cff8b2c6 PB |
1723 | |
1724 | opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err); | |
1725 | if (err) { | |
90998d58 DB |
1726 | hmp_handle_error(mon, &err); |
1727 | return; | |
cff8b2c6 PB |
1728 | } |
1729 | ||
1730 | ov = opts_visitor_new(opts); | |
90998d58 DB |
1731 | obj = user_creatable_add(qdict, opts_get_visitor(ov), &err); |
1732 | opts_visitor_cleanup(ov); | |
1733 | qemu_opts_del(opts); | |
cff8b2c6 | 1734 | |
cff8b2c6 | 1735 | if (err) { |
90998d58 | 1736 | hmp_handle_error(mon, &err); |
cff8b2c6 | 1737 | } |
90998d58 DB |
1738 | if (obj) { |
1739 | object_unref(obj); | |
cff8b2c6 | 1740 | } |
cff8b2c6 PB |
1741 | } |
1742 | ||
208c9d1b CB |
1743 | void hmp_getfd(Monitor *mon, const QDict *qdict) |
1744 | { | |
1745 | const char *fdname = qdict_get_str(qdict, "fdname"); | |
e940f543 | 1746 | Error *err = NULL; |
208c9d1b | 1747 | |
e940f543 MA |
1748 | qmp_getfd(fdname, &err); |
1749 | hmp_handle_error(mon, &err); | |
208c9d1b CB |
1750 | } |
1751 | ||
1752 | void hmp_closefd(Monitor *mon, const QDict *qdict) | |
1753 | { | |
1754 | const char *fdname = qdict_get_str(qdict, "fdname"); | |
e940f543 | 1755 | Error *err = NULL; |
208c9d1b | 1756 | |
e940f543 MA |
1757 | qmp_closefd(fdname, &err); |
1758 | hmp_handle_error(mon, &err); | |
208c9d1b | 1759 | } |
e4c8f004 | 1760 | |
3e5a50d6 | 1761 | void hmp_sendkey(Monitor *mon, const QDict *qdict) |
e4c8f004 AK |
1762 | { |
1763 | const char *keys = qdict_get_str(qdict, "keys"); | |
9f328977 | 1764 | KeyValueList *keylist, *head = NULL, *tmp = NULL; |
e4c8f004 AK |
1765 | int has_hold_time = qdict_haskey(qdict, "hold-time"); |
1766 | int hold_time = qdict_get_try_int(qdict, "hold-time", -1); | |
1767 | Error *err = NULL; | |
e4c8f004 | 1768 | char *separator; |
9f328977 | 1769 | int keyname_len; |
e4c8f004 AK |
1770 | |
1771 | while (1) { | |
1772 | separator = strchr(keys, '-'); | |
1773 | keyname_len = separator ? separator - keys : strlen(keys); | |
e4c8f004 AK |
1774 | |
1775 | /* Be compatible with old interface, convert user inputted "<" */ | |
64ffbe04 WB |
1776 | if (keys[0] == '<' && keyname_len == 1) { |
1777 | keys = "less"; | |
e4c8f004 AK |
1778 | keyname_len = 4; |
1779 | } | |
e4c8f004 | 1780 | |
e4c8f004 | 1781 | keylist = g_malloc0(sizeof(*keylist)); |
9f328977 | 1782 | keylist->value = g_malloc0(sizeof(*keylist->value)); |
e4c8f004 AK |
1783 | |
1784 | if (!head) { | |
1785 | head = keylist; | |
1786 | } | |
1787 | if (tmp) { | |
1788 | tmp->next = keylist; | |
1789 | } | |
1790 | tmp = keylist; | |
1791 | ||
64ffbe04 | 1792 | if (strstart(keys, "0x", NULL)) { |
9f328977 | 1793 | char *endp; |
64ffbe04 WB |
1794 | int value = strtoul(keys, &endp, 0); |
1795 | assert(endp <= keys + keyname_len); | |
1796 | if (endp != keys + keyname_len) { | |
9f328977 LC |
1797 | goto err_out; |
1798 | } | |
568c73a4 | 1799 | keylist->value->type = KEY_VALUE_KIND_NUMBER; |
32bafa8f | 1800 | keylist->value->u.number.data = value; |
9f328977 | 1801 | } else { |
64ffbe04 | 1802 | int idx = index_from_key(keys, keyname_len); |
7fb1cf16 | 1803 | if (idx == Q_KEY_CODE__MAX) { |
9f328977 LC |
1804 | goto err_out; |
1805 | } | |
568c73a4 | 1806 | keylist->value->type = KEY_VALUE_KIND_QCODE; |
32bafa8f | 1807 | keylist->value->u.qcode.data = idx; |
9f328977 LC |
1808 | } |
1809 | ||
e4c8f004 AK |
1810 | if (!separator) { |
1811 | break; | |
1812 | } | |
1813 | keys = separator + 1; | |
1814 | } | |
1815 | ||
9f328977 | 1816 | qmp_send_key(head, has_hold_time, hold_time, &err); |
e4c8f004 | 1817 | hmp_handle_error(mon, &err); |
9f328977 LC |
1818 | |
1819 | out: | |
1820 | qapi_free_KeyValueList(head); | |
1821 | return; | |
1822 | ||
1823 | err_out: | |
64ffbe04 | 1824 | monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys); |
9f328977 | 1825 | goto out; |
e4c8f004 | 1826 | } |
ad39cf6d | 1827 | |
3e5a50d6 | 1828 | void hmp_screendump(Monitor *mon, const QDict *qdict) |
ad39cf6d LC |
1829 | { |
1830 | const char *filename = qdict_get_str(qdict, "filename"); | |
1831 | Error *err = NULL; | |
1832 | ||
1833 | qmp_screendump(filename, &err); | |
1834 | hmp_handle_error(mon, &err); | |
1835 | } | |
4057725f PB |
1836 | |
1837 | void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) | |
1838 | { | |
1839 | const char *uri = qdict_get_str(qdict, "uri"); | |
34acbc95 EB |
1840 | bool writable = qdict_get_try_bool(qdict, "writable", false); |
1841 | bool all = qdict_get_try_bool(qdict, "all", false); | |
4057725f PB |
1842 | Error *local_err = NULL; |
1843 | BlockInfoList *block_list, *info; | |
1844 | SocketAddress *addr; | |
1845 | ||
1846 | if (writable && !all) { | |
1847 | error_setg(&local_err, "-w only valid together with -a"); | |
1848 | goto exit; | |
1849 | } | |
1850 | ||
1851 | /* First check if the address is valid and start the server. */ | |
1852 | addr = socket_parse(uri, &local_err); | |
1853 | if (local_err != NULL) { | |
1854 | goto exit; | |
1855 | } | |
1856 | ||
ddffee39 | 1857 | qmp_nbd_server_start(addr, false, NULL, &local_err); |
4057725f PB |
1858 | qapi_free_SocketAddress(addr); |
1859 | if (local_err != NULL) { | |
1860 | goto exit; | |
1861 | } | |
1862 | ||
1863 | if (!all) { | |
1864 | return; | |
1865 | } | |
1866 | ||
1867 | /* Then try adding all block devices. If one fails, close all and | |
1868 | * exit. | |
1869 | */ | |
1870 | block_list = qmp_query_block(NULL); | |
1871 | ||
1872 | for (info = block_list; info; info = info->next) { | |
1873 | if (!info->value->has_inserted) { | |
1874 | continue; | |
1875 | } | |
1876 | ||
1877 | qmp_nbd_server_add(info->value->device, true, writable, &local_err); | |
1878 | ||
1879 | if (local_err != NULL) { | |
1880 | qmp_nbd_server_stop(NULL); | |
1881 | break; | |
1882 | } | |
1883 | } | |
1884 | ||
1885 | qapi_free_BlockInfoList(block_list); | |
1886 | ||
1887 | exit: | |
1888 | hmp_handle_error(mon, &local_err); | |
1889 | } | |
1890 | ||
1891 | void hmp_nbd_server_add(Monitor *mon, const QDict *qdict) | |
1892 | { | |
1893 | const char *device = qdict_get_str(qdict, "device"); | |
34acbc95 | 1894 | bool writable = qdict_get_try_bool(qdict, "writable", false); |
4057725f PB |
1895 | Error *local_err = NULL; |
1896 | ||
1897 | qmp_nbd_server_add(device, true, writable, &local_err); | |
1898 | ||
1899 | if (local_err != NULL) { | |
1900 | hmp_handle_error(mon, &local_err); | |
1901 | } | |
1902 | } | |
1903 | ||
1904 | void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict) | |
1905 | { | |
e940f543 | 1906 | Error *err = NULL; |
4057725f | 1907 | |
e940f543 MA |
1908 | qmp_nbd_server_stop(&err); |
1909 | hmp_handle_error(mon, &err); | |
4057725f | 1910 | } |
f1088908 | 1911 | |
abf23329 JH |
1912 | void hmp_cpu_add(Monitor *mon, const QDict *qdict) |
1913 | { | |
1914 | int cpuid; | |
1915 | Error *err = NULL; | |
1916 | ||
1917 | cpuid = qdict_get_int(qdict, "id"); | |
1918 | qmp_cpu_add(cpuid, &err); | |
1919 | hmp_handle_error(mon, &err); | |
1920 | } | |
1921 | ||
f1088908 GH |
1922 | void hmp_chardev_add(Monitor *mon, const QDict *qdict) |
1923 | { | |
1924 | const char *args = qdict_get_str(qdict, "args"); | |
1925 | Error *err = NULL; | |
1926 | QemuOpts *opts; | |
1927 | ||
70b94331 | 1928 | opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true); |
f1088908 | 1929 | if (opts == NULL) { |
312fd5f2 | 1930 | error_setg(&err, "Parsing chardev args failed"); |
f1088908 GH |
1931 | } else { |
1932 | qemu_chr_new_from_opts(opts, NULL, &err); | |
1933 | } | |
1934 | hmp_handle_error(mon, &err); | |
1935 | } | |
1936 | ||
1937 | void hmp_chardev_remove(Monitor *mon, const QDict *qdict) | |
1938 | { | |
1939 | Error *local_err = NULL; | |
1940 | ||
1941 | qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err); | |
1942 | hmp_handle_error(mon, &local_err); | |
1943 | } | |
587da2c3 KW |
1944 | |
1945 | void hmp_qemu_io(Monitor *mon, const QDict *qdict) | |
1946 | { | |
4c7b7e9b | 1947 | BlockBackend *blk; |
587da2c3 KW |
1948 | const char* device = qdict_get_str(qdict, "device"); |
1949 | const char* command = qdict_get_str(qdict, "command"); | |
1950 | Error *err = NULL; | |
1951 | ||
4c7b7e9b HR |
1952 | blk = blk_by_name(device); |
1953 | if (blk) { | |
1954 | qemuio_command(blk, command); | |
587da2c3 | 1955 | } else { |
75158ebb MA |
1956 | error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND, |
1957 | "Device '%s' not found", device); | |
587da2c3 KW |
1958 | } |
1959 | ||
1960 | hmp_handle_error(mon, &err); | |
1961 | } | |
ab2d0531 PB |
1962 | |
1963 | void hmp_object_del(Monitor *mon, const QDict *qdict) | |
1964 | { | |
1965 | const char *id = qdict_get_str(qdict, "id"); | |
1966 | Error *err = NULL; | |
1967 | ||
90998d58 | 1968 | user_creatable_del(id, &err); |
ab2d0531 PB |
1969 | hmp_handle_error(mon, &err); |
1970 | } | |
eb1539b2 HT |
1971 | |
1972 | void hmp_info_memdev(Monitor *mon, const QDict *qdict) | |
1973 | { | |
1974 | Error *err = NULL; | |
1975 | MemdevList *memdev_list = qmp_query_memdev(&err); | |
1976 | MemdevList *m = memdev_list; | |
1977 | StringOutputVisitor *ov; | |
976620ac | 1978 | char *str; |
eb1539b2 HT |
1979 | int i = 0; |
1980 | ||
1981 | ||
1982 | while (m) { | |
1983 | ov = string_output_visitor_new(false); | |
51e72bc1 EB |
1984 | visit_type_uint16List(string_output_get_visitor(ov), NULL, |
1985 | &m->value->host_nodes, NULL); | |
8f4e5ac3 | 1986 | monitor_printf(mon, "memory backend: %d\n", i); |
eb1539b2 HT |
1987 | monitor_printf(mon, " size: %" PRId64 "\n", m->value->size); |
1988 | monitor_printf(mon, " merge: %s\n", | |
1989 | m->value->merge ? "true" : "false"); | |
1990 | monitor_printf(mon, " dump: %s\n", | |
1991 | m->value->dump ? "true" : "false"); | |
1992 | monitor_printf(mon, " prealloc: %s\n", | |
1993 | m->value->prealloc ? "true" : "false"); | |
1994 | monitor_printf(mon, " policy: %s\n", | |
1995 | HostMemPolicy_lookup[m->value->policy]); | |
976620ac CF |
1996 | str = string_output_get_string(ov); |
1997 | monitor_printf(mon, " host nodes: %s\n", str); | |
eb1539b2 | 1998 | |
976620ac | 1999 | g_free(str); |
eb1539b2 HT |
2000 | string_output_visitor_cleanup(ov); |
2001 | m = m->next; | |
2002 | i++; | |
2003 | } | |
2004 | ||
2005 | monitor_printf(mon, "\n"); | |
ecaf54a0 CF |
2006 | |
2007 | qapi_free_MemdevList(memdev_list); | |
eb1539b2 | 2008 | } |
a631892f ZG |
2009 | |
2010 | void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) | |
2011 | { | |
2012 | Error *err = NULL; | |
2013 | MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err); | |
2014 | MemoryDeviceInfoList *info; | |
2015 | MemoryDeviceInfo *value; | |
2016 | PCDIMMDeviceInfo *di; | |
2017 | ||
2018 | for (info = info_list; info; info = info->next) { | |
2019 | value = info->value; | |
2020 | ||
2021 | if (value) { | |
1fd5d4fe | 2022 | switch (value->type) { |
a631892f | 2023 | case MEMORY_DEVICE_INFO_KIND_DIMM: |
32bafa8f | 2024 | di = value->u.dimm.data; |
a631892f ZG |
2025 | |
2026 | monitor_printf(mon, "Memory device [%s]: \"%s\"\n", | |
1fd5d4fe | 2027 | MemoryDeviceInfoKind_lookup[value->type], |
a631892f ZG |
2028 | di->id ? di->id : ""); |
2029 | monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr); | |
2030 | monitor_printf(mon, " slot: %" PRId64 "\n", di->slot); | |
2031 | monitor_printf(mon, " node: %" PRId64 "\n", di->node); | |
2032 | monitor_printf(mon, " size: %" PRIu64 "\n", di->size); | |
2033 | monitor_printf(mon, " memdev: %s\n", di->memdev); | |
2034 | monitor_printf(mon, " hotplugged: %s\n", | |
2035 | di->hotplugged ? "true" : "false"); | |
2036 | monitor_printf(mon, " hotpluggable: %s\n", | |
2037 | di->hotpluggable ? "true" : "false"); | |
2038 | break; | |
2039 | default: | |
2040 | break; | |
2041 | } | |
2042 | } | |
2043 | } | |
2044 | ||
2045 | qapi_free_MemoryDeviceInfoList(info_list); | |
2046 | } | |
89d7fa9e | 2047 | |
62313160 TW |
2048 | void hmp_info_iothreads(Monitor *mon, const QDict *qdict) |
2049 | { | |
2050 | IOThreadInfoList *info_list = qmp_query_iothreads(NULL); | |
2051 | IOThreadInfoList *info; | |
2052 | ||
2053 | for (info = info_list; info; info = info->next) { | |
2054 | monitor_printf(mon, "%s: thread_id=%" PRId64 "\n", | |
2055 | info->value->id, info->value->thread_id); | |
2056 | } | |
2057 | ||
2058 | qapi_free_IOThreadInfoList(info_list); | |
2059 | } | |
2060 | ||
89d7fa9e AF |
2061 | void hmp_qom_list(Monitor *mon, const QDict *qdict) |
2062 | { | |
2063 | const char *path = qdict_get_try_str(qdict, "path"); | |
2064 | ObjectPropertyInfoList *list; | |
2065 | Error *err = NULL; | |
2066 | ||
2067 | if (path == NULL) { | |
2068 | monitor_printf(mon, "/\n"); | |
2069 | return; | |
2070 | } | |
2071 | ||
2072 | list = qmp_qom_list(path, &err); | |
2073 | if (err == NULL) { | |
2074 | ObjectPropertyInfoList *start = list; | |
2075 | while (list != NULL) { | |
2076 | ObjectPropertyInfo *value = list->value; | |
2077 | ||
2078 | monitor_printf(mon, "%s (%s)\n", | |
2079 | value->name, value->type); | |
2080 | list = list->next; | |
2081 | } | |
2082 | qapi_free_ObjectPropertyInfoList(start); | |
2083 | } | |
2084 | hmp_handle_error(mon, &err); | |
2085 | } | |
c0e6ee9e AF |
2086 | |
2087 | void hmp_qom_set(Monitor *mon, const QDict *qdict) | |
2088 | { | |
2089 | const char *path = qdict_get_str(qdict, "path"); | |
2090 | const char *property = qdict_get_str(qdict, "property"); | |
2091 | const char *value = qdict_get_str(qdict, "value"); | |
2092 | Error *err = NULL; | |
2093 | bool ambiguous = false; | |
2094 | Object *obj; | |
2095 | ||
2096 | obj = object_resolve_path(path, &ambiguous); | |
2097 | if (obj == NULL) { | |
75158ebb MA |
2098 | error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND, |
2099 | "Device '%s' not found", path); | |
c0e6ee9e AF |
2100 | } else { |
2101 | if (ambiguous) { | |
2102 | monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path); | |
2103 | } | |
2104 | object_property_parse(obj, value, property, &err); | |
2105 | } | |
2106 | hmp_handle_error(mon, &err); | |
2107 | } | |
fafa4d50 SF |
2108 | |
2109 | void hmp_rocker(Monitor *mon, const QDict *qdict) | |
2110 | { | |
2111 | const char *name = qdict_get_str(qdict, "name"); | |
2112 | RockerSwitch *rocker; | |
533fdaed | 2113 | Error *err = NULL; |
fafa4d50 | 2114 | |
533fdaed MA |
2115 | rocker = qmp_query_rocker(name, &err); |
2116 | if (err != NULL) { | |
2117 | hmp_handle_error(mon, &err); | |
fafa4d50 SF |
2118 | return; |
2119 | } | |
2120 | ||
2121 | monitor_printf(mon, "name: %s\n", rocker->name); | |
2122 | monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id); | |
2123 | monitor_printf(mon, "ports: %d\n", rocker->ports); | |
2124 | ||
2125 | qapi_free_RockerSwitch(rocker); | |
2126 | } | |
2127 | ||
2128 | void hmp_rocker_ports(Monitor *mon, const QDict *qdict) | |
2129 | { | |
2130 | RockerPortList *list, *port; | |
2131 | const char *name = qdict_get_str(qdict, "name"); | |
533fdaed | 2132 | Error *err = NULL; |
fafa4d50 | 2133 | |
533fdaed MA |
2134 | list = qmp_query_rocker_ports(name, &err); |
2135 | if (err != NULL) { | |
2136 | hmp_handle_error(mon, &err); | |
fafa4d50 SF |
2137 | return; |
2138 | } | |
2139 | ||
2140 | monitor_printf(mon, " ena/ speed/ auto\n"); | |
2141 | monitor_printf(mon, " port link duplex neg?\n"); | |
2142 | ||
2143 | for (port = list; port; port = port->next) { | |
2144 | monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n", | |
2145 | port->value->name, | |
2146 | port->value->enabled ? port->value->link_up ? | |
2147 | "up" : "down" : "!ena", | |
2148 | port->value->speed == 10000 ? "10G" : "??", | |
2149 | port->value->duplex ? "FD" : "HD", | |
2150 | port->value->autoneg ? "Yes" : "No"); | |
2151 | } | |
2152 | ||
2153 | qapi_free_RockerPortList(list); | |
2154 | } | |
2155 | ||
2156 | void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict) | |
2157 | { | |
2158 | RockerOfDpaFlowList *list, *info; | |
2159 | const char *name = qdict_get_str(qdict, "name"); | |
2160 | uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1); | |
533fdaed | 2161 | Error *err = NULL; |
fafa4d50 | 2162 | |
533fdaed MA |
2163 | list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err); |
2164 | if (err != NULL) { | |
2165 | hmp_handle_error(mon, &err); | |
fafa4d50 SF |
2166 | return; |
2167 | } | |
2168 | ||
2169 | monitor_printf(mon, "prio tbl hits key(mask) --> actions\n"); | |
2170 | ||
2171 | for (info = list; info; info = info->next) { | |
2172 | RockerOfDpaFlow *flow = info->value; | |
2173 | RockerOfDpaFlowKey *key = flow->key; | |
2174 | RockerOfDpaFlowMask *mask = flow->mask; | |
2175 | RockerOfDpaFlowAction *action = flow->action; | |
2176 | ||
2177 | if (flow->hits) { | |
2178 | monitor_printf(mon, "%-4d %-3d %-4" PRIu64, | |
2179 | key->priority, key->tbl_id, flow->hits); | |
2180 | } else { | |
2181 | monitor_printf(mon, "%-4d %-3d ", | |
2182 | key->priority, key->tbl_id); | |
2183 | } | |
2184 | ||
2185 | if (key->has_in_pport) { | |
2186 | monitor_printf(mon, " pport %d", key->in_pport); | |
2187 | if (mask->has_in_pport) { | |
2188 | monitor_printf(mon, "(0x%x)", mask->in_pport); | |
2189 | } | |
2190 | } | |
2191 | ||
2192 | if (key->has_vlan_id) { | |
2193 | monitor_printf(mon, " vlan %d", | |
2194 | key->vlan_id & VLAN_VID_MASK); | |
2195 | if (mask->has_vlan_id) { | |
2196 | monitor_printf(mon, "(0x%x)", mask->vlan_id); | |
2197 | } | |
2198 | } | |
2199 | ||
2200 | if (key->has_tunnel_id) { | |
2201 | monitor_printf(mon, " tunnel %d", key->tunnel_id); | |
2202 | if (mask->has_tunnel_id) { | |
2203 | monitor_printf(mon, "(0x%x)", mask->tunnel_id); | |
2204 | } | |
2205 | } | |
2206 | ||
2207 | if (key->has_eth_type) { | |
2208 | switch (key->eth_type) { | |
2209 | case 0x0806: | |
2210 | monitor_printf(mon, " ARP"); | |
2211 | break; | |
2212 | case 0x0800: | |
2213 | monitor_printf(mon, " IP"); | |
2214 | break; | |
2215 | case 0x86dd: | |
2216 | monitor_printf(mon, " IPv6"); | |
2217 | break; | |
2218 | case 0x8809: | |
2219 | monitor_printf(mon, " LACP"); | |
2220 | break; | |
2221 | case 0x88cc: | |
2222 | monitor_printf(mon, " LLDP"); | |
2223 | break; | |
2224 | default: | |
2225 | monitor_printf(mon, " eth type 0x%04x", key->eth_type); | |
2226 | break; | |
2227 | } | |
2228 | } | |
2229 | ||
2230 | if (key->has_eth_src) { | |
2231 | if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) && | |
2232 | (mask->has_eth_src) && | |
2233 | (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { | |
2234 | monitor_printf(mon, " src <any mcast/bcast>"); | |
2235 | } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) && | |
2236 | (mask->has_eth_src) && | |
2237 | (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { | |
2238 | monitor_printf(mon, " src <any ucast>"); | |
2239 | } else { | |
2240 | monitor_printf(mon, " src %s", key->eth_src); | |
2241 | if (mask->has_eth_src) { | |
2242 | monitor_printf(mon, "(%s)", mask->eth_src); | |
2243 | } | |
2244 | } | |
2245 | } | |
2246 | ||
2247 | if (key->has_eth_dst) { | |
2248 | if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) && | |
2249 | (mask->has_eth_dst) && | |
2250 | (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { | |
2251 | monitor_printf(mon, " dst <any mcast/bcast>"); | |
2252 | } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) && | |
2253 | (mask->has_eth_dst) && | |
2254 | (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { | |
2255 | monitor_printf(mon, " dst <any ucast>"); | |
2256 | } else { | |
2257 | monitor_printf(mon, " dst %s", key->eth_dst); | |
2258 | if (mask->has_eth_dst) { | |
2259 | monitor_printf(mon, "(%s)", mask->eth_dst); | |
2260 | } | |
2261 | } | |
2262 | } | |
2263 | ||
2264 | if (key->has_ip_proto) { | |
2265 | monitor_printf(mon, " proto %d", key->ip_proto); | |
2266 | if (mask->has_ip_proto) { | |
2267 | monitor_printf(mon, "(0x%x)", mask->ip_proto); | |
2268 | } | |
2269 | } | |
2270 | ||
2271 | if (key->has_ip_tos) { | |
2272 | monitor_printf(mon, " TOS %d", key->ip_tos); | |
2273 | if (mask->has_ip_tos) { | |
2274 | monitor_printf(mon, "(0x%x)", mask->ip_tos); | |
2275 | } | |
2276 | } | |
2277 | ||
2278 | if (key->has_ip_dst) { | |
2279 | monitor_printf(mon, " dst %s", key->ip_dst); | |
2280 | } | |
2281 | ||
2282 | if (action->has_goto_tbl || action->has_group_id || | |
2283 | action->has_new_vlan_id) { | |
2284 | monitor_printf(mon, " -->"); | |
2285 | } | |
2286 | ||
2287 | if (action->has_new_vlan_id) { | |
2288 | monitor_printf(mon, " apply new vlan %d", | |
2289 | ntohs(action->new_vlan_id)); | |
2290 | } | |
2291 | ||
2292 | if (action->has_group_id) { | |
2293 | monitor_printf(mon, " write group 0x%08x", action->group_id); | |
2294 | } | |
2295 | ||
2296 | if (action->has_goto_tbl) { | |
2297 | monitor_printf(mon, " goto tbl %d", action->goto_tbl); | |
2298 | } | |
2299 | ||
2300 | monitor_printf(mon, "\n"); | |
2301 | } | |
2302 | ||
2303 | qapi_free_RockerOfDpaFlowList(list); | |
2304 | } | |
2305 | ||
2306 | void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict) | |
2307 | { | |
2308 | RockerOfDpaGroupList *list, *g; | |
2309 | const char *name = qdict_get_str(qdict, "name"); | |
2310 | uint8_t type = qdict_get_try_int(qdict, "type", 9); | |
533fdaed | 2311 | Error *err = NULL; |
fafa4d50 SF |
2312 | bool set = false; |
2313 | ||
533fdaed MA |
2314 | list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err); |
2315 | if (err != NULL) { | |
2316 | hmp_handle_error(mon, &err); | |
fafa4d50 SF |
2317 | return; |
2318 | } | |
2319 | ||
2320 | monitor_printf(mon, "id (decode) --> buckets\n"); | |
2321 | ||
2322 | for (g = list; g; g = g->next) { | |
2323 | RockerOfDpaGroup *group = g->value; | |
2324 | ||
2325 | monitor_printf(mon, "0x%08x", group->id); | |
2326 | ||
2327 | monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" : | |
2328 | group->type == 1 ? "L2 rewrite" : | |
2329 | group->type == 2 ? "L3 unicast" : | |
2330 | group->type == 3 ? "L2 multicast" : | |
2331 | group->type == 4 ? "L2 flood" : | |
2332 | group->type == 5 ? "L3 interface" : | |
2333 | group->type == 6 ? "L3 multicast" : | |
2334 | group->type == 7 ? "L3 ECMP" : | |
2335 | group->type == 8 ? "L2 overlay" : | |
2336 | "unknown"); | |
2337 | ||
2338 | if (group->has_vlan_id) { | |
2339 | monitor_printf(mon, " vlan %d", group->vlan_id); | |
2340 | } | |
2341 | ||
2342 | if (group->has_pport) { | |
2343 | monitor_printf(mon, " pport %d", group->pport); | |
2344 | } | |
2345 | ||
2346 | if (group->has_index) { | |
2347 | monitor_printf(mon, " index %d", group->index); | |
2348 | } | |
2349 | ||
2350 | monitor_printf(mon, ") -->"); | |
2351 | ||
2352 | if (group->has_set_vlan_id && group->set_vlan_id) { | |
2353 | set = true; | |
2354 | monitor_printf(mon, " set vlan %d", | |
2355 | group->set_vlan_id & VLAN_VID_MASK); | |
2356 | } | |
2357 | ||
2358 | if (group->has_set_eth_src) { | |
2359 | if (!set) { | |
2360 | set = true; | |
2361 | monitor_printf(mon, " set"); | |
2362 | } | |
2363 | monitor_printf(mon, " src %s", group->set_eth_src); | |
2364 | } | |
2365 | ||
2366 | if (group->has_set_eth_dst) { | |
2367 | if (!set) { | |
2368 | set = true; | |
2369 | monitor_printf(mon, " set"); | |
2370 | } | |
2371 | monitor_printf(mon, " dst %s", group->set_eth_dst); | |
2372 | } | |
2373 | ||
2374 | set = false; | |
2375 | ||
2376 | if (group->has_ttl_check && group->ttl_check) { | |
2377 | monitor_printf(mon, " check TTL"); | |
2378 | } | |
2379 | ||
2380 | if (group->has_group_id && group->group_id) { | |
2381 | monitor_printf(mon, " group id 0x%08x", group->group_id); | |
2382 | } | |
2383 | ||
2384 | if (group->has_pop_vlan && group->pop_vlan) { | |
2385 | monitor_printf(mon, " pop vlan"); | |
2386 | } | |
2387 | ||
2388 | if (group->has_out_pport) { | |
2389 | monitor_printf(mon, " out pport %d", group->out_pport); | |
2390 | } | |
2391 | ||
2392 | if (group->has_group_ids) { | |
2393 | struct uint32List *id; | |
2394 | ||
2395 | monitor_printf(mon, " groups ["); | |
2396 | for (id = group->group_ids; id; id = id->next) { | |
2397 | monitor_printf(mon, "0x%08x", id->value); | |
2398 | if (id->next) { | |
2399 | monitor_printf(mon, ","); | |
2400 | } | |
2401 | } | |
2402 | monitor_printf(mon, "]"); | |
2403 | } | |
2404 | ||
2405 | monitor_printf(mon, "\n"); | |
2406 | } | |
2407 | ||
2408 | qapi_free_RockerOfDpaGroupList(list); | |
2409 | } | |
4a6b52d6 PX |
2410 | |
2411 | void hmp_info_dump(Monitor *mon, const QDict *qdict) | |
2412 | { | |
2413 | DumpQueryResult *result = qmp_query_dump(NULL); | |
2414 | ||
2415 | assert(result && result->status < DUMP_STATUS__MAX); | |
2416 | monitor_printf(mon, "Status: %s\n", DumpStatus_lookup[result->status]); | |
2417 | ||
2418 | if (result->status == DUMP_STATUS_ACTIVE) { | |
2419 | float percent = 0; | |
2420 | assert(result->total != 0); | |
2421 | percent = 100.0 * result->completed / result->total; | |
2422 | monitor_printf(mon, "Finished: %.2f %%\n", percent); | |
2423 | } | |
2424 | ||
2425 | qapi_free_DumpQueryResult(result); | |
2426 | } |