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