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