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