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