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