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