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