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