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