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