blob: 2f279c4ff26b1d4956e06b34cee0a75d740e5b65 [file] [log] [blame]
Anthony Liguori48a32be2011-09-02 12:34:48 -05001/*
2 * Human Monitor Interface
3 *
4 * Copyright IBM, Corp. 2011
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
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 *
Paolo Bonzini6b620ca2012-01-13 17:44:23 +010012 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
Anthony Liguori48a32be2011-09-02 12:34:48 -050014 */
15
16#include "hmp.h"
Paolo Bonzini1422e322012-10-24 08:43:34 +020017#include "net/net.h"
Paolo Bonzinidccfcd02013-04-08 16:55:25 +020018#include "sysemu/char.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010019#include "qemu/option.h"
20#include "qemu/timer.h"
Anthony Liguori48a32be2011-09-02 12:34:48 -050021#include "qmp-commands.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010022#include "qemu/sockets.h"
Paolo Bonzini83c90892012-12-17 18:19:49 +010023#include "monitor/monitor.h"
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +010024#include "qapi/opts-visitor.h"
Paolo Bonzini28ecbae2012-11-28 12:06:30 +010025#include "ui/console.h"
Wenchao Xiabd093a32013-06-06 12:28:00 +080026#include "block/qapi.h"
Kevin Wolf587da2c2013-06-05 14:19:41 +020027#include "qemu-io.h"
Anthony Liguori48a32be2011-09-02 12:34:48 -050028
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -020029static 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
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080037void hmp_info_name(Monitor *mon, const QDict *qdict)
Anthony Liguori48a32be2011-09-02 12:34:48 -050038{
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}
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030047
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080048void hmp_info_version(Monitor *mon, const QDict *qdict)
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030049{
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}
Luiz Capitulino292a2602011-09-12 15:10:53 -030060
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080061void hmp_info_kvm(Monitor *mon, const QDict *qdict)
Luiz Capitulino292a2602011-09-12 15:10:53 -030062{
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
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080076void hmp_info_status(Monitor *mon, const QDict *qdict)
Luiz Capitulino1fa9a5e2011-09-12 17:54:20 -030077{
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
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080095void hmp_info_uuid(Monitor *mon, const QDict *qdict)
Luiz Capitulinoefab7672011-09-13 17:16:25 -030096{
97 UuidInfo *info;
98
99 info = qmp_query_uuid(NULL);
100 monitor_printf(mon, "%s\n", info->UUID);
101 qapi_free_UuidInfo(info);
102}
Luiz Capitulinoc5a415a2011-09-14 16:05:49 -0300103
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800104void hmp_info_chardev(Monitor *mon, const QDict *qdict)
Luiz Capitulinoc5a415a2011-09-14 16:05:49 -0300105{
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}
Luiz Capitulino7a7f3252011-09-15 14:20:28 -0300116
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800117void hmp_info_mice(Monitor *mon, const QDict *qdict)
Luiz Capitulinoe235cec2011-09-21 15:29:55 -0300118{
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
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800137void hmp_info_migrate(Monitor *mon, const QDict *qdict)
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300138{
139 MigrationInfo *info;
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300140 MigrationCapabilityStatusList *caps, *cap;
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300141
142 info = qmp_query_migrate(NULL);
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300143 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 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300155
156 if (info->has_status) {
157 monitor_printf(mon, "Migration status: %s\n", info->status);
Juan Quintela7aa939a2012-08-18 13:17:10 +0200158 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
159 info->total_time);
Juan Quintela2c52ddf2012-08-13 09:53:12 +0200160 if (info->has_expected_downtime) {
161 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
162 info->expected_downtime);
163 }
Juan Quintela9c5a9fc2012-08-13 09:35:16 +0200164 if (info->has_downtime) {
165 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
166 info->downtime);
167 }
Michael R. Hinesed4fbd12013-07-22 10:01:58 -0400168 if (info->has_setup_time) {
169 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
170 info->setup_time);
171 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300172 }
173
174 if (info->has_ram) {
175 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
176 info->ram->transferred >> 10);
Michael R. Hines7e114f82013-06-25 21:35:30 -0400177 monitor_printf(mon, "throughput: %0.2f mbps\n",
178 info->ram->mbps);
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300179 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);
Orit Wasserman004d4c12012-08-06 21:42:56 +0300183 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
184 info->ram->duplicate);
Peter Lievenf1c72792013-03-26 10:58:37 +0100185 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
186 info->ram->skipped);
Orit Wasserman004d4c12012-08-06 21:42:56 +0300187 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);
Juan Quintela8d017192012-08-13 12:31:25 +0200191 if (info->ram->dirty_pages_rate) {
192 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
193 info->ram->dirty_pages_rate);
194 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300195 }
196
197 if (info->has_disk) {
198 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
199 info->disk->transferred >> 10);
200 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
201 info->disk->remaining >> 10);
202 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
203 info->disk->total >> 10);
204 }
205
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300206 if (info->has_xbzrle_cache) {
207 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
208 info->xbzrle_cache->cache_size);
209 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
210 info->xbzrle_cache->bytes >> 10);
211 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
212 info->xbzrle_cache->pages);
213 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
214 info->xbzrle_cache->cache_miss);
215 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
216 info->xbzrle_cache->overflow);
217 }
218
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300219 qapi_free_MigrationInfo(info);
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300220 qapi_free_MigrationCapabilityStatusList(caps);
221}
222
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800223void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300224{
225 MigrationCapabilityStatusList *caps, *cap;
226
227 caps = qmp_query_migrate_capabilities(NULL);
228
229 if (caps) {
230 monitor_printf(mon, "capabilities: ");
231 for (cap = caps; cap; cap = cap->next) {
232 monitor_printf(mon, "%s: %s ",
233 MigrationCapability_lookup[cap->value->capability],
234 cap->value->state ? "on" : "off");
235 }
236 monitor_printf(mon, "\n");
237 }
238
239 qapi_free_MigrationCapabilityStatusList(caps);
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300240}
241
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800242void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +0300243{
244 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
245 qmp_query_migrate_cache_size(NULL) >> 10);
246}
247
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800248void hmp_info_cpus(Monitor *mon, const QDict *qdict)
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300249{
250 CpuInfoList *cpu_list, *cpu;
251
252 cpu_list = qmp_query_cpus(NULL);
253
254 for (cpu = cpu_list; cpu; cpu = cpu->next) {
255 int active = ' ';
256
257 if (cpu->value->CPU == monitor_get_cpu_index()) {
258 active = '*';
259 }
260
Aurelien Jarno852bef02012-10-19 23:19:19 +0200261 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300262
263 if (cpu->value->has_pc) {
Aurelien Jarno852bef02012-10-19 23:19:19 +0200264 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->pc);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300265 }
266 if (cpu->value->has_nip) {
Aurelien Jarno852bef02012-10-19 23:19:19 +0200267 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->nip);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300268 }
269 if (cpu->value->has_npc) {
Aurelien Jarno852bef02012-10-19 23:19:19 +0200270 monitor_printf(mon, " npc=0x%016" PRIx64, cpu->value->npc);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300271 }
272 if (cpu->value->has_PC) {
Aurelien Jarno852bef02012-10-19 23:19:19 +0200273 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->PC);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300274 }
275
276 if (cpu->value->halted) {
277 monitor_printf(mon, " (halted)");
278 }
279
280 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
281 }
282
283 qapi_free_CpuInfoList(cpu_list);
284}
285
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800286void hmp_info_block(Monitor *mon, const QDict *qdict)
Luiz Capitulinob2023812011-09-21 17:16:47 -0300287{
288 BlockInfoList *block_list, *info;
Wenchao Xiabd093a32013-06-06 12:28:00 +0800289 ImageInfo *image_info;
Wenchao Xiae73fe2b2013-06-06 12:28:01 +0800290 const char *device = qdict_get_try_str(qdict, "device");
291 bool verbose = qdict_get_try_bool(qdict, "verbose", 0);
Luiz Capitulinob2023812011-09-21 17:16:47 -0300292
293 block_list = qmp_query_block(NULL);
294
295 for (info = block_list; info; info = info->next) {
Wenchao Xiae73fe2b2013-06-06 12:28:01 +0800296 if (device && strcmp(device, info->value->device)) {
297 continue;
298 }
Luiz Capitulinob2023812011-09-21 17:16:47 -0300299
Kevin Wolffbe2e262013-06-19 16:10:55 +0200300 if (info != block_list) {
301 monitor_printf(mon, "\n");
Luiz Capitulinob2023812011-09-21 17:16:47 -0300302 }
303
Kevin Wolffbe2e262013-06-19 16:10:55 +0200304 monitor_printf(mon, "%s", info->value->device);
305 if (info->value->has_inserted) {
306 monitor_printf(mon, ": %s (%s%s%s)\n",
307 info->value->inserted->file,
308 info->value->inserted->drv,
309 info->value->inserted->ro ? ", read-only" : "",
310 info->value->inserted->encrypted ? ", encrypted" : "");
311 } else {
312 monitor_printf(mon, ": [not inserted]\n");
313 }
314
315 if (info->value->has_io_status && info->value->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
316 monitor_printf(mon, " I/O status: %s\n",
Luiz Capitulinob2023812011-09-21 17:16:47 -0300317 BlockDeviceIoStatus_lookup[info->value->io_status]);
318 }
319
Kevin Wolffbe2e262013-06-19 16:10:55 +0200320 if (info->value->removable) {
321 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
322 info->value->locked ? "" : "not ",
323 info->value->tray_open ? "open" : "closed");
324 }
Luiz Capitulinob2023812011-09-21 17:16:47 -0300325
Zhi Yong Wu727f0052011-11-08 13:00:31 +0800326
Kevin Wolffbe2e262013-06-19 16:10:55 +0200327 if (!info->value->has_inserted) {
328 continue;
329 }
330
331 if (info->value->inserted->has_backing_file) {
332 monitor_printf(mon,
333 " Backing file: %s "
334 "(chain depth: %" PRId64 ")\n",
335 info->value->inserted->backing_file,
336 info->value->inserted->backing_file_depth);
337 }
338
339 if (info->value->inserted->bps
340 || info->value->inserted->bps_rd
341 || info->value->inserted->bps_wr
342 || info->value->inserted->iops
343 || info->value->inserted->iops_rd
344 || info->value->inserted->iops_wr)
345 {
346 monitor_printf(mon, " I/O throttling: bps=%" PRId64
347 " bps_rd=%" PRId64 " bps_wr=%" PRId64
Benoît Canet3e9fab62013-09-02 14:14:40 +0200348 " bps_max=%" PRId64
349 " bps_rd_max=%" PRId64
350 " bps_wr_max=%" PRId64
Kevin Wolffbe2e262013-06-19 16:10:55 +0200351 " iops=%" PRId64 " iops_rd=%" PRId64
Benoît Canet3e9fab62013-09-02 14:14:40 +0200352 " iops_wr=%" PRId64
353 " iops_max=%" PRId64
354 " iops_rd_max=%" PRId64
Benoît Canet2024c1d2013-09-02 14:14:41 +0200355 " iops_wr_max=%" PRId64
356 " iops_size=%" PRId64 "\n",
Zhi Yong Wu727f0052011-11-08 13:00:31 +0800357 info->value->inserted->bps,
358 info->value->inserted->bps_rd,
359 info->value->inserted->bps_wr,
Benoît Canet3e9fab62013-09-02 14:14:40 +0200360 info->value->inserted->bps_max,
361 info->value->inserted->bps_rd_max,
362 info->value->inserted->bps_wr_max,
Zhi Yong Wu727f0052011-11-08 13:00:31 +0800363 info->value->inserted->iops,
364 info->value->inserted->iops_rd,
Benoît Canet3e9fab62013-09-02 14:14:40 +0200365 info->value->inserted->iops_wr,
366 info->value->inserted->iops_max,
367 info->value->inserted->iops_rd_max,
Benoît Canet2024c1d2013-09-02 14:14:41 +0200368 info->value->inserted->iops_wr_max,
369 info->value->inserted->iops_size);
Luiz Capitulinob2023812011-09-21 17:16:47 -0300370 }
371
Kevin Wolffbe2e262013-06-19 16:10:55 +0200372 if (verbose) {
373 monitor_printf(mon, "\nImages:\n");
374 image_info = info->value->inserted->image;
375 while (1) {
376 bdrv_image_info_dump((fprintf_function)monitor_printf,
377 mon, image_info);
378 if (image_info->has_backing_image) {
379 image_info = image_info->backing_image;
380 } else {
381 break;
382 }
383 }
384 }
Luiz Capitulinob2023812011-09-21 17:16:47 -0300385 }
386
387 qapi_free_BlockInfoList(block_list);
388}
389
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800390void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300391{
392 BlockStatsList *stats_list, *stats;
393
394 stats_list = qmp_query_blockstats(NULL);
395
396 for (stats = stats_list; stats; stats = stats->next) {
397 if (!stats->value->has_device) {
398 continue;
399 }
400
401 monitor_printf(mon, "%s:", stats->value->device);
402 monitor_printf(mon, " rd_bytes=%" PRId64
403 " wr_bytes=%" PRId64
404 " rd_operations=%" PRId64
405 " wr_operations=%" PRId64
406 " flush_operations=%" PRId64
407 " wr_total_time_ns=%" PRId64
408 " rd_total_time_ns=%" PRId64
409 " flush_total_time_ns=%" PRId64
410 "\n",
411 stats->value->stats->rd_bytes,
412 stats->value->stats->wr_bytes,
413 stats->value->stats->rd_operations,
414 stats->value->stats->wr_operations,
415 stats->value->stats->flush_operations,
416 stats->value->stats->wr_total_time_ns,
417 stats->value->stats->rd_total_time_ns,
418 stats->value->stats->flush_total_time_ns);
419 }
420
421 qapi_free_BlockStatsList(stats_list);
422}
423
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800424void hmp_info_vnc(Monitor *mon, const QDict *qdict)
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200425{
426 VncInfo *info;
427 Error *err = NULL;
428 VncClientInfoList *client;
429
430 info = qmp_query_vnc(&err);
431 if (err) {
432 monitor_printf(mon, "%s\n", error_get_pretty(err));
433 error_free(err);
434 return;
435 }
436
437 if (!info->enabled) {
438 monitor_printf(mon, "Server: disabled\n");
439 goto out;
440 }
441
442 monitor_printf(mon, "Server:\n");
443 if (info->has_host && info->has_service) {
444 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
445 }
446 if (info->has_auth) {
447 monitor_printf(mon, " auth: %s\n", info->auth);
448 }
449
450 if (!info->has_clients || info->clients == NULL) {
451 monitor_printf(mon, "Client: none\n");
452 } else {
453 for (client = info->clients; client; client = client->next) {
454 monitor_printf(mon, "Client:\n");
455 monitor_printf(mon, " address: %s:%s\n",
456 client->value->host, client->value->service);
457 monitor_printf(mon, " x509_dname: %s\n",
458 client->value->x509_dname ?
459 client->value->x509_dname : "none");
460 monitor_printf(mon, " username: %s\n",
461 client->value->has_sasl_username ?
462 client->value->sasl_username : "none");
463 }
464 }
465
466out:
467 qapi_free_VncInfo(info);
468}
469
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800470void hmp_info_spice(Monitor *mon, const QDict *qdict)
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200471{
472 SpiceChannelList *chan;
473 SpiceInfo *info;
474
475 info = qmp_query_spice(NULL);
476
477 if (!info->enabled) {
478 monitor_printf(mon, "Server: disabled\n");
479 goto out;
480 }
481
482 monitor_printf(mon, "Server:\n");
483 if (info->has_port) {
484 monitor_printf(mon, " address: %s:%" PRId64 "\n",
485 info->host, info->port);
486 }
487 if (info->has_tls_port) {
488 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
489 info->host, info->tls_port);
490 }
Yonit Halperin61c4efe2012-08-21 11:51:58 +0300491 monitor_printf(mon, " migrated: %s\n",
492 info->migrated ? "true" : "false");
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200493 monitor_printf(mon, " auth: %s\n", info->auth);
494 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
Alon Levy4efee022012-03-29 23:23:14 +0200495 monitor_printf(mon, " mouse-mode: %s\n",
496 SpiceQueryMouseMode_lookup[info->mouse_mode]);
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200497
498 if (!info->has_channels || info->channels == NULL) {
499 monitor_printf(mon, "Channels: none\n");
500 } else {
501 for (chan = info->channels; chan; chan = chan->next) {
502 monitor_printf(mon, "Channel:\n");
503 monitor_printf(mon, " address: %s:%s%s\n",
504 chan->value->host, chan->value->port,
505 chan->value->tls ? " [tls]" : "");
506 monitor_printf(mon, " session: %" PRId64 "\n",
507 chan->value->connection_id);
508 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
509 chan->value->channel_type, chan->value->channel_id);
510 }
511 }
512
513out:
514 qapi_free_SpiceInfo(info);
515}
516
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800517void hmp_info_balloon(Monitor *mon, const QDict *qdict)
Luiz Capitulino96637bc2011-10-21 11:41:37 -0200518{
519 BalloonInfo *info;
520 Error *err = NULL;
521
522 info = qmp_query_balloon(&err);
523 if (err) {
524 monitor_printf(mon, "%s\n", error_get_pretty(err));
525 error_free(err);
526 return;
527 }
528
Luiz Capitulino01ceb972012-12-03 15:56:41 -0200529 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
Luiz Capitulino96637bc2011-10-21 11:41:37 -0200530
531 qapi_free_BalloonInfo(info);
532}
533
Luiz Capitulino79627472011-10-21 14:15:33 -0200534static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
535{
536 PciMemoryRegionList *region;
537
538 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
539 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
540 dev->slot, dev->function);
541 monitor_printf(mon, " ");
542
543 if (dev->class_info.has_desc) {
544 monitor_printf(mon, "%s", dev->class_info.desc);
545 } else {
Tomoki Sekiyama6f880092013-08-07 11:39:43 -0400546 monitor_printf(mon, "Class %04" PRId64, dev->class_info.q_class);
Luiz Capitulino79627472011-10-21 14:15:33 -0200547 }
548
549 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
550 dev->id.vendor, dev->id.device);
551
552 if (dev->has_irq) {
553 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
554 }
555
556 if (dev->has_pci_bridge) {
557 monitor_printf(mon, " BUS %" PRId64 ".\n",
558 dev->pci_bridge->bus.number);
559 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
560 dev->pci_bridge->bus.secondary);
561 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
562 dev->pci_bridge->bus.subordinate);
563
564 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
565 dev->pci_bridge->bus.io_range->base,
566 dev->pci_bridge->bus.io_range->limit);
567
568 monitor_printf(mon,
569 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
570 dev->pci_bridge->bus.memory_range->base,
571 dev->pci_bridge->bus.memory_range->limit);
572
573 monitor_printf(mon, " prefetchable memory range "
574 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
575 dev->pci_bridge->bus.prefetchable_range->base,
576 dev->pci_bridge->bus.prefetchable_range->limit);
577 }
578
579 for (region = dev->regions; region; region = region->next) {
580 uint64_t addr, size;
581
582 addr = region->value->address;
583 size = region->value->size;
584
585 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
586
587 if (!strcmp(region->value->type, "io")) {
588 monitor_printf(mon, "I/O at 0x%04" PRIx64
589 " [0x%04" PRIx64 "].\n",
590 addr, addr + size - 1);
591 } else {
592 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
593 " [0x%08" PRIx64 "].\n",
594 region->value->mem_type_64 ? 64 : 32,
595 region->value->prefetch ? " prefetchable" : "",
596 addr, addr + size - 1);
597 }
598 }
599
600 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
601
602 if (dev->has_pci_bridge) {
603 if (dev->pci_bridge->has_devices) {
604 PciDeviceInfoList *cdev;
605 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
606 hmp_info_pci_device(mon, cdev->value);
607 }
608 }
609 }
610}
611
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800612void hmp_info_pci(Monitor *mon, const QDict *qdict)
Luiz Capitulino79627472011-10-21 14:15:33 -0200613{
Stefan Bergerf46cee32012-01-11 10:51:52 -0500614 PciInfoList *info_list, *info;
Luiz Capitulino79627472011-10-21 14:15:33 -0200615 Error *err = NULL;
616
Stefan Bergerf46cee32012-01-11 10:51:52 -0500617 info_list = qmp_query_pci(&err);
Luiz Capitulino79627472011-10-21 14:15:33 -0200618 if (err) {
619 monitor_printf(mon, "PCI devices not supported\n");
620 error_free(err);
621 return;
622 }
623
Stefan Bergerf46cee32012-01-11 10:51:52 -0500624 for (info = info_list; info; info = info->next) {
Luiz Capitulino79627472011-10-21 14:15:33 -0200625 PciDeviceInfoList *dev;
626
627 for (dev = info->value->devices; dev; dev = dev->next) {
628 hmp_info_pci_device(mon, dev->value);
629 }
630 }
631
Stefan Bergerf46cee32012-01-11 10:51:52 -0500632 qapi_free_PciInfoList(info_list);
Luiz Capitulino79627472011-10-21 14:15:33 -0200633}
634
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800635void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
Stefan Hajnoczifb5458c2012-01-18 14:40:49 +0000636{
637 BlockJobInfoList *list;
638 Error *err = NULL;
639
640 list = qmp_query_block_jobs(&err);
641 assert(!err);
642
643 if (!list) {
644 monitor_printf(mon, "No active jobs\n");
645 return;
646 }
647
648 while (list) {
649 if (strcmp(list->value->type, "stream") == 0) {
650 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
651 " of %" PRId64 " bytes, speed limit %" PRId64
652 " bytes/s\n",
653 list->value->device,
654 list->value->offset,
655 list->value->len,
656 list->value->speed);
657 } else {
658 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
659 " of %" PRId64 " bytes, speed limit %" PRId64
660 " bytes/s\n",
661 list->value->type,
662 list->value->device,
663 list->value->offset,
664 list->value->len,
665 list->value->speed);
666 }
667 list = list->next;
668 }
669}
670
Stefan Bergerd1a0cf72013-02-27 12:47:49 -0500671void hmp_info_tpm(Monitor *mon, const QDict *qdict)
672{
673 TPMInfoList *info_list, *info;
674 Error *err = NULL;
675 unsigned int c = 0;
676 TPMPassthroughOptions *tpo;
677
678 info_list = qmp_query_tpm(&err);
679 if (err) {
680 monitor_printf(mon, "TPM device not supported\n");
681 error_free(err);
682 return;
683 }
684
685 if (info_list) {
686 monitor_printf(mon, "TPM device:\n");
687 }
688
689 for (info = info_list; info; info = info->next) {
690 TPMInfo *ti = info->value;
691 monitor_printf(mon, " tpm%d: model=%s\n",
692 c, TpmModel_lookup[ti->model]);
693
694 monitor_printf(mon, " \\ %s: type=%s",
Corey Bryant88ca7bc2013-03-20 12:34:48 -0400695 ti->id, TpmTypeOptionsKind_lookup[ti->options->kind]);
Stefan Bergerd1a0cf72013-02-27 12:47:49 -0500696
Corey Bryant88ca7bc2013-03-20 12:34:48 -0400697 switch (ti->options->kind) {
698 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
699 tpo = ti->options->passthrough;
Stefan Bergerd1a0cf72013-02-27 12:47:49 -0500700 monitor_printf(mon, "%s%s%s%s",
701 tpo->has_path ? ",path=" : "",
702 tpo->has_path ? tpo->path : "",
703 tpo->has_cancel_path ? ",cancel-path=" : "",
704 tpo->has_cancel_path ? tpo->cancel_path : "");
705 break;
706 case TPM_TYPE_OPTIONS_KIND_MAX:
707 break;
708 }
709 monitor_printf(mon, "\n");
710 c++;
711 }
712 qapi_free_TPMInfoList(info_list);
713}
714
Luiz Capitulino7a7f3252011-09-15 14:20:28 -0300715void hmp_quit(Monitor *mon, const QDict *qdict)
716{
717 monitor_suspend(mon);
718 qmp_quit(NULL);
719}
Luiz Capitulino5f158f22011-09-15 14:34:39 -0300720
721void hmp_stop(Monitor *mon, const QDict *qdict)
722{
723 qmp_stop(NULL);
724}
Luiz Capitulino38d22652011-09-15 14:41:46 -0300725
726void hmp_system_reset(Monitor *mon, const QDict *qdict)
727{
728 qmp_system_reset(NULL);
729}
Luiz Capitulino5bc465e2011-09-28 11:06:15 -0300730
731void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
732{
733 qmp_system_powerdown(NULL);
734}
Luiz Capitulino755f1962011-10-06 14:31:39 -0300735
736void hmp_cpu(Monitor *mon, const QDict *qdict)
737{
738 int64_t cpu_index;
739
740 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
741 use it are converted to the QAPI */
742 cpu_index = qdict_get_int(qdict, "index");
743 if (monitor_set_cpu(cpu_index) < 0) {
744 monitor_printf(mon, "invalid CPU index\n");
745 }
746}
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -0200747
748void hmp_memsave(Monitor *mon, const QDict *qdict)
749{
750 uint32_t size = qdict_get_int(qdict, "size");
751 const char *filename = qdict_get_str(qdict, "filename");
752 uint64_t addr = qdict_get_int(qdict, "val");
753 Error *errp = NULL;
754
755 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &errp);
756 hmp_handle_error(mon, &errp);
757}
Luiz Capitulino6d3962b2011-11-22 17:26:46 -0200758
759void hmp_pmemsave(Monitor *mon, const QDict *qdict)
760{
761 uint32_t size = qdict_get_int(qdict, "size");
762 const char *filename = qdict_get_str(qdict, "filename");
763 uint64_t addr = qdict_get_int(qdict, "val");
764 Error *errp = NULL;
765
766 qmp_pmemsave(addr, size, filename, &errp);
767 hmp_handle_error(mon, &errp);
768}
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200769
Markus Armbruster3949e592013-02-06 21:27:24 +0100770void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
Lei Li1f590cf2013-01-25 00:03:20 +0800771{
Lei Li1f590cf2013-01-25 00:03:20 +0800772 const char *chardev = qdict_get_str(qdict, "device");
773 const char *data = qdict_get_str(qdict, "data");
774 Error *errp = NULL;
775
Markus Armbruster3949e592013-02-06 21:27:24 +0100776 qmp_ringbuf_write(chardev, data, false, 0, &errp);
Lei Li1f590cf2013-01-25 00:03:20 +0800777
778 hmp_handle_error(mon, &errp);
779}
780
Markus Armbruster3949e592013-02-06 21:27:24 +0100781void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
Lei Li49b6d722013-01-25 00:03:21 +0800782{
783 uint32_t size = qdict_get_int(qdict, "size");
784 const char *chardev = qdict_get_str(qdict, "device");
Markus Armbruster3ab651f2013-02-06 21:27:15 +0100785 char *data;
Lei Li49b6d722013-01-25 00:03:21 +0800786 Error *errp = NULL;
Markus Armbruster543f3412013-02-06 21:27:26 +0100787 int i;
Lei Li49b6d722013-01-25 00:03:21 +0800788
Markus Armbruster3949e592013-02-06 21:27:24 +0100789 data = qmp_ringbuf_read(chardev, size, false, 0, &errp);
Lei Li49b6d722013-01-25 00:03:21 +0800790 if (errp) {
791 monitor_printf(mon, "%s\n", error_get_pretty(errp));
792 error_free(errp);
793 return;
794 }
795
Markus Armbruster543f3412013-02-06 21:27:26 +0100796 for (i = 0; data[i]; i++) {
797 unsigned char ch = data[i];
798
799 if (ch == '\\') {
800 monitor_printf(mon, "\\\\");
801 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
802 monitor_printf(mon, "\\u%04X", ch);
803 } else {
804 monitor_printf(mon, "%c", ch);
805 }
806
807 }
808 monitor_printf(mon, "\n");
Markus Armbruster3ab651f2013-02-06 21:27:15 +0100809 g_free(data);
Lei Li49b6d722013-01-25 00:03:21 +0800810}
811
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200812static void hmp_cont_cb(void *opaque, int err)
813{
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200814 if (!err) {
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300815 qmp_cont(NULL);
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200816 }
817}
818
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300819static bool key_is_missing(const BlockInfo *bdev)
820{
821 return (bdev->inserted && bdev->inserted->encryption_key_missing);
822}
823
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200824void hmp_cont(Monitor *mon, const QDict *qdict)
825{
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300826 BlockInfoList *bdev_list, *bdev;
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200827 Error *errp = NULL;
828
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300829 bdev_list = qmp_query_block(NULL);
830 for (bdev = bdev_list; bdev; bdev = bdev->next) {
831 if (key_is_missing(bdev->value)) {
832 monitor_read_block_device_key(mon, bdev->value->device,
833 hmp_cont_cb, NULL);
834 goto out;
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200835 }
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200836 }
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300837
838 qmp_cont(&errp);
839 hmp_handle_error(mon, &errp);
840
841out:
842 qapi_free_BlockInfoList(bdev_list);
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200843}
Luiz Capitulinoab49ab52011-11-23 12:55:53 -0200844
Gerd Hoffmann9b9df252012-02-23 13:45:21 +0100845void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
846{
847 qmp_system_wakeup(NULL);
848}
849
Luiz Capitulinoab49ab52011-11-23 12:55:53 -0200850void hmp_inject_nmi(Monitor *mon, const QDict *qdict)
851{
852 Error *errp = NULL;
853
854 qmp_inject_nmi(&errp);
855 hmp_handle_error(mon, &errp);
856}
Luiz Capitulino4b371562011-11-23 13:11:55 -0200857
858void hmp_set_link(Monitor *mon, const QDict *qdict)
859{
860 const char *name = qdict_get_str(qdict, "name");
861 int up = qdict_get_bool(qdict, "up");
862 Error *errp = NULL;
863
864 qmp_set_link(name, up, &errp);
865 hmp_handle_error(mon, &errp);
866}
Luiz Capitulinoa4dea8a2011-11-23 13:28:21 -0200867
868void hmp_block_passwd(Monitor *mon, const QDict *qdict)
869{
870 const char *device = qdict_get_str(qdict, "device");
871 const char *password = qdict_get_str(qdict, "password");
872 Error *errp = NULL;
873
Benoît Canet12d3ba82014-01-23 21:31:35 +0100874 qmp_block_passwd(true, device, false, NULL, password, &errp);
Luiz Capitulinoa4dea8a2011-11-23 13:28:21 -0200875 hmp_handle_error(mon, &errp);
876}
Luiz Capitulinod72f3262011-11-25 14:38:09 -0200877
878void hmp_balloon(Monitor *mon, const QDict *qdict)
879{
880 int64_t value = qdict_get_int(qdict, "value");
881 Error *errp = NULL;
882
883 qmp_balloon(value, &errp);
Markus Armbruster84d18f02014-01-30 15:07:28 +0100884 if (errp) {
Luiz Capitulinod72f3262011-11-25 14:38:09 -0200885 monitor_printf(mon, "balloon: %s\n", error_get_pretty(errp));
886 error_free(errp);
887 }
888}
Luiz Capitulino5e7caac2011-11-25 14:57:10 -0200889
890void hmp_block_resize(Monitor *mon, const QDict *qdict)
891{
892 const char *device = qdict_get_str(qdict, "device");
893 int64_t size = qdict_get_int(qdict, "size");
894 Error *errp = NULL;
895
Benoît Canet3b1dbd12014-01-23 21:31:37 +0100896 qmp_block_resize(true, device, false, NULL, size, &errp);
Luiz Capitulino5e7caac2011-11-25 14:57:10 -0200897 hmp_handle_error(mon, &errp);
898}
Luiz Capitulino6106e242011-11-25 16:15:19 -0200899
Paolo Bonzinid9b902d2012-10-18 16:49:24 +0200900void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
901{
902 const char *device = qdict_get_str(qdict, "device");
903 const char *filename = qdict_get_str(qdict, "target");
904 const char *format = qdict_get_try_str(qdict, "format");
905 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
906 int full = qdict_get_try_bool(qdict, "full", 0);
907 enum NewImageMode mode;
908 Error *errp = NULL;
909
910 if (!filename) {
911 error_set(&errp, QERR_MISSING_PARAMETER, "target");
912 hmp_handle_error(mon, &errp);
913 return;
914 }
915
916 if (reuse) {
917 mode = NEW_IMAGE_MODE_EXISTING;
918 } else {
919 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
920 }
921
922 qmp_drive_mirror(device, filename, !!format, format,
923 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
Paolo Bonzini08e4ed62013-01-22 09:03:13 +0100924 true, mode, false, 0, false, 0, false, 0,
Paolo Bonzinib952b552012-10-18 16:49:28 +0200925 false, 0, false, 0, &errp);
Paolo Bonzinid9b902d2012-10-18 16:49:24 +0200926 hmp_handle_error(mon, &errp);
927}
928
Stefan Hajnoczide909302013-06-26 14:11:58 +0200929void hmp_drive_backup(Monitor *mon, const QDict *qdict)
930{
931 const char *device = qdict_get_str(qdict, "device");
932 const char *filename = qdict_get_str(qdict, "target");
933 const char *format = qdict_get_try_str(qdict, "format");
934 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
935 int full = qdict_get_try_bool(qdict, "full", 0);
936 enum NewImageMode mode;
937 Error *errp = NULL;
938
939 if (!filename) {
940 error_set(&errp, QERR_MISSING_PARAMETER, "target");
941 hmp_handle_error(mon, &errp);
942 return;
943 }
944
945 if (reuse) {
946 mode = NEW_IMAGE_MODE_EXISTING;
947 } else {
948 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
949 }
950
951 qmp_drive_backup(device, filename, !!format, format,
952 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
953 true, mode, false, 0, false, 0, false, 0, &errp);
954 hmp_handle_error(mon, &errp);
955}
956
Luiz Capitulino6106e242011-11-25 16:15:19 -0200957void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
958{
959 const char *device = qdict_get_str(qdict, "device");
960 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
961 const char *format = qdict_get_try_str(qdict, "format");
Paolo Bonzini6cc2a412012-03-06 18:55:59 +0100962 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
963 enum NewImageMode mode;
Luiz Capitulino6106e242011-11-25 16:15:19 -0200964 Error *errp = NULL;
965
966 if (!filename) {
967 /* In the future, if 'snapshot-file' is not specified, the snapshot
968 will be taken internally. Today it's actually required. */
969 error_set(&errp, QERR_MISSING_PARAMETER, "snapshot-file");
970 hmp_handle_error(mon, &errp);
971 return;
972 }
973
Paolo Bonzini6cc2a412012-03-06 18:55:59 +0100974 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
Benoît Canet0901f672014-01-23 21:31:38 +0100975 qmp_blockdev_snapshot_sync(true, device, false, NULL,
976 filename, false, NULL,
977 !!format, format,
Paolo Bonzini6cc2a412012-03-06 18:55:59 +0100978 true, mode, &errp);
Luiz Capitulino6106e242011-11-25 16:15:19 -0200979 hmp_handle_error(mon, &errp);
980}
Luiz Capitulino6cdedb02011-11-27 22:54:09 -0200981
Wenchao Xia775ca882013-09-11 14:04:37 +0800982void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
983{
984 const char *device = qdict_get_str(qdict, "device");
985 const char *name = qdict_get_str(qdict, "name");
986 Error *errp = NULL;
987
988 qmp_blockdev_snapshot_internal_sync(device, name, &errp);
989 hmp_handle_error(mon, &errp);
990}
991
Wenchao Xia7a4ed2e2013-09-11 14:04:38 +0800992void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
993{
994 const char *device = qdict_get_str(qdict, "device");
995 const char *name = qdict_get_str(qdict, "name");
996 const char *id = qdict_get_try_str(qdict, "id");
997 Error *errp = NULL;
998
999 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1000 true, name, &errp);
1001 hmp_handle_error(mon, &errp);
1002}
1003
Luiz Capitulino6cdedb02011-11-27 22:54:09 -02001004void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1005{
1006 qmp_migrate_cancel(NULL);
1007}
Luiz Capitulino4f0a9932011-11-27 23:18:01 -02001008
1009void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1010{
1011 double value = qdict_get_double(qdict, "value");
1012 qmp_migrate_set_downtime(value, NULL);
1013}
Luiz Capitulino3dc85382011-11-28 11:59:37 -02001014
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +03001015void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1016{
1017 int64_t value = qdict_get_int(qdict, "value");
1018 Error *err = NULL;
1019
1020 qmp_migrate_set_cache_size(value, &err);
1021 if (err) {
1022 monitor_printf(mon, "%s\n", error_get_pretty(err));
1023 error_free(err);
1024 return;
1025 }
1026}
1027
Luiz Capitulino3dc85382011-11-28 11:59:37 -02001028void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1029{
1030 int64_t value = qdict_get_int(qdict, "value");
1031 qmp_migrate_set_speed(value, NULL);
1032}
Luiz Capitulinofbf796f2011-12-07 11:17:51 -02001033
Orit Wasserman00458432012-08-06 21:42:48 +03001034void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1035{
1036 const char *cap = qdict_get_str(qdict, "capability");
1037 bool state = qdict_get_bool(qdict, "state");
1038 Error *err = NULL;
1039 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1040 int i;
1041
1042 for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
1043 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1044 caps->value = g_malloc0(sizeof(*caps->value));
1045 caps->value->capability = i;
1046 caps->value->state = state;
1047 caps->next = NULL;
1048 qmp_migrate_set_capabilities(caps, &err);
1049 break;
1050 }
1051 }
1052
1053 if (i == MIGRATION_CAPABILITY_MAX) {
1054 error_set(&err, QERR_INVALID_PARAMETER, cap);
1055 }
1056
1057 qapi_free_MigrationCapabilityStatusList(caps);
1058
1059 if (err) {
Orit Wassermana31ca012013-01-31 09:12:19 +02001060 monitor_printf(mon, "migrate_set_capability: %s\n",
Orit Wasserman00458432012-08-06 21:42:48 +03001061 error_get_pretty(err));
1062 error_free(err);
1063 }
1064}
1065
Luiz Capitulinofbf796f2011-12-07 11:17:51 -02001066void hmp_set_password(Monitor *mon, const QDict *qdict)
1067{
1068 const char *protocol = qdict_get_str(qdict, "protocol");
1069 const char *password = qdict_get_str(qdict, "password");
1070 const char *connected = qdict_get_try_str(qdict, "connected");
1071 Error *err = NULL;
1072
1073 qmp_set_password(protocol, password, !!connected, connected, &err);
1074 hmp_handle_error(mon, &err);
1075}
Luiz Capitulino9ad53722011-12-07 11:47:57 -02001076
1077void hmp_expire_password(Monitor *mon, const QDict *qdict)
1078{
1079 const char *protocol = qdict_get_str(qdict, "protocol");
1080 const char *whenstr = qdict_get_str(qdict, "time");
1081 Error *err = NULL;
1082
1083 qmp_expire_password(protocol, whenstr, &err);
1084 hmp_handle_error(mon, &err);
1085}
Luiz Capitulinoc245b6a2011-12-07 16:02:36 -02001086
1087void hmp_eject(Monitor *mon, const QDict *qdict)
1088{
1089 int force = qdict_get_try_bool(qdict, "force", 0);
1090 const char *device = qdict_get_str(qdict, "device");
1091 Error *err = NULL;
1092
1093 qmp_eject(device, true, force, &err);
1094 hmp_handle_error(mon, &err);
1095}
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001096
Stefan Hajnoczic60bf332013-11-14 11:54:14 +01001097static void hmp_change_read_arg(void *opaque, const char *password,
1098 void *readline_opaque)
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001099{
1100 qmp_change_vnc_password(password, NULL);
Stefan Hajnoczic60bf332013-11-14 11:54:14 +01001101 monitor_read_command(opaque, 1);
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001102}
1103
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001104void hmp_change(Monitor *mon, const QDict *qdict)
1105{
1106 const char *device = qdict_get_str(qdict, "device");
1107 const char *target = qdict_get_str(qdict, "target");
1108 const char *arg = qdict_get_try_str(qdict, "arg");
1109 Error *err = NULL;
1110
1111 if (strcmp(device, "vnc") == 0 &&
1112 (strcmp(target, "passwd") == 0 ||
1113 strcmp(target, "password") == 0)) {
1114 if (!arg) {
1115 monitor_read_password(mon, hmp_change_read_arg, NULL);
1116 return;
1117 }
1118 }
1119
1120 qmp_change(device, target, !!arg, arg, &err);
Markus Armbruster84d18f02014-01-30 15:07:28 +01001121 if (err &&
Luiz Capitulinoab878dd2012-08-06 15:55:22 -03001122 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
Luiz Capitulinoeef5ad12012-08-06 15:49:34 -03001123 error_free(err);
1124 monitor_read_block_device_key(mon, device, NULL, NULL);
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001125 return;
1126 }
1127 hmp_handle_error(mon, &err);
1128}
Luiz Capitulino80047da2011-12-14 16:49:14 -02001129
1130void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1131{
1132 Error *err = NULL;
1133
1134 qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
1135 qdict_get_int(qdict, "bps"),
1136 qdict_get_int(qdict, "bps_rd"),
1137 qdict_get_int(qdict, "bps_wr"),
1138 qdict_get_int(qdict, "iops"),
1139 qdict_get_int(qdict, "iops_rd"),
Benoît Canet3e9fab62013-09-02 14:14:40 +02001140 qdict_get_int(qdict, "iops_wr"),
1141 false, /* no burst max via HMP */
1142 0,
1143 false,
1144 0,
1145 false,
1146 0,
1147 false,
1148 0,
1149 false,
1150 0,
1151 false,
Benoît Canet2024c1d2013-09-02 14:14:41 +02001152 0,
1153 false, /* No default I/O size */
Benoît Canet3e9fab62013-09-02 14:14:40 +02001154 0, &err);
Luiz Capitulino80047da2011-12-14 16:49:14 -02001155 hmp_handle_error(mon, &err);
1156}
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00001157
1158void hmp_block_stream(Monitor *mon, const QDict *qdict)
1159{
1160 Error *error = NULL;
1161 const char *device = qdict_get_str(qdict, "device");
1162 const char *base = qdict_get_try_str(qdict, "base");
Stefan Hajnoczic83c66c2012-04-25 16:51:03 +01001163 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00001164
Stefan Hajnoczic83c66c2012-04-25 16:51:03 +01001165 qmp_block_stream(device, base != NULL, base,
Paolo Bonzini1d809092012-09-28 17:22:59 +02001166 qdict_haskey(qdict, "speed"), speed,
Anthony Liguori46663e52013-09-17 11:10:47 -05001167 true, BLOCKDEV_ON_ERROR_REPORT, &error);
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00001168
1169 hmp_handle_error(mon, &error);
1170}
Stefan Hajnoczi2d47c6e2012-01-18 14:40:47 +00001171
1172void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1173{
1174 Error *error = NULL;
1175 const char *device = qdict_get_str(qdict, "device");
Paolo Bonzinic6db2392012-05-08 16:51:56 +02001176 int64_t value = qdict_get_int(qdict, "speed");
Stefan Hajnoczi2d47c6e2012-01-18 14:40:47 +00001177
1178 qmp_block_job_set_speed(device, value, &error);
1179
1180 hmp_handle_error(mon, &error);
1181}
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00001182
1183void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1184{
1185 Error *error = NULL;
1186 const char *device = qdict_get_str(qdict, "device");
Paolo Bonzini6e37fb82012-09-28 17:22:51 +02001187 bool force = qdict_get_try_bool(qdict, "force", 0);
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00001188
Paolo Bonzini6e37fb82012-09-28 17:22:51 +02001189 qmp_block_job_cancel(device, true, force, &error);
1190
1191 hmp_handle_error(mon, &error);
1192}
1193
1194void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1195{
1196 Error *error = NULL;
1197 const char *device = qdict_get_str(qdict, "device");
1198
1199 qmp_block_job_pause(device, &error);
1200
1201 hmp_handle_error(mon, &error);
1202}
1203
1204void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1205{
1206 Error *error = NULL;
1207 const char *device = qdict_get_str(qdict, "device");
1208
1209 qmp_block_job_resume(device, &error);
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00001210
1211 hmp_handle_error(mon, &error);
1212}
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001213
Paolo Bonziniaeae8832012-10-18 16:49:21 +02001214void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1215{
1216 Error *error = NULL;
1217 const char *device = qdict_get_str(qdict, "device");
1218
1219 qmp_block_job_complete(device, &error);
1220
1221 hmp_handle_error(mon, &error);
1222}
1223
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001224typedef struct MigrationStatus
1225{
1226 QEMUTimer *timer;
1227 Monitor *mon;
1228 bool is_block_migration;
1229} MigrationStatus;
1230
1231static void hmp_migrate_status_cb(void *opaque)
1232{
1233 MigrationStatus *status = opaque;
1234 MigrationInfo *info;
1235
1236 info = qmp_query_migrate(NULL);
Soramichi AKIYAMAdde3a212014-01-27 19:46:11 +09001237 if (!info->has_status || strcmp(info->status, "active") == 0 ||
1238 strcmp(info->status, "setup") == 0) {
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001239 if (info->has_disk) {
1240 int progress;
1241
1242 if (info->disk->remaining) {
1243 progress = info->disk->transferred * 100 / info->disk->total;
1244 } else {
1245 progress = 100;
1246 }
1247
1248 monitor_printf(status->mon, "Completed %d %%\r", progress);
1249 monitor_flush(status->mon);
1250 }
1251
Alex Blighbc72ad62013-08-21 16:03:08 +01001252 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001253 } else {
1254 if (status->is_block_migration) {
1255 monitor_printf(status->mon, "\n");
1256 }
1257 monitor_resume(status->mon);
Alex Blighbc72ad62013-08-21 16:03:08 +01001258 timer_del(status->timer);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001259 g_free(status);
1260 }
1261
1262 qapi_free_MigrationInfo(info);
1263}
1264
1265void hmp_migrate(Monitor *mon, const QDict *qdict)
1266{
1267 int detach = qdict_get_try_bool(qdict, "detach", 0);
1268 int blk = qdict_get_try_bool(qdict, "blk", 0);
1269 int inc = qdict_get_try_bool(qdict, "inc", 0);
1270 const char *uri = qdict_get_str(qdict, "uri");
1271 Error *err = NULL;
1272
1273 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1274 if (err) {
1275 monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
1276 error_free(err);
1277 return;
1278 }
1279
1280 if (!detach) {
1281 MigrationStatus *status;
1282
1283 if (monitor_suspend(mon) < 0) {
1284 monitor_printf(mon, "terminal does not allow synchronous "
1285 "migration, continuing detached\n");
1286 return;
1287 }
1288
1289 status = g_malloc0(sizeof(*status));
1290 status->mon = mon;
1291 status->is_block_migration = blk || inc;
Alex Blighbc72ad62013-08-21 16:03:08 +01001292 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001293 status);
Alex Blighbc72ad62013-08-21 16:03:08 +01001294 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001295 }
1296}
Luiz Capitulinoa15fef22012-03-29 12:38:50 -03001297
1298void hmp_device_del(Monitor *mon, const QDict *qdict)
1299{
1300 const char *id = qdict_get_str(qdict, "id");
1301 Error *err = NULL;
1302
1303 qmp_device_del(id, &err);
1304 hmp_handle_error(mon, &err);
1305}
Wen Congyang783e9b42012-05-07 12:10:47 +08001306
1307void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1308{
1309 Error *errp = NULL;
1310 int paging = qdict_get_try_bool(qdict, "paging", 0);
Luiz Capitulino75363762012-09-21 13:53:00 -03001311 const char *file = qdict_get_str(qdict, "filename");
Wen Congyang783e9b42012-05-07 12:10:47 +08001312 bool has_begin = qdict_haskey(qdict, "begin");
1313 bool has_length = qdict_haskey(qdict, "length");
qiaonuohanb53ccc32014-02-18 14:11:36 +08001314 /* kdump-compressed format is not supported for HMP */
1315 bool has_format = false;
Wen Congyang783e9b42012-05-07 12:10:47 +08001316 int64_t begin = 0;
1317 int64_t length = 0;
qiaonuohanb53ccc32014-02-18 14:11:36 +08001318 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
Luiz Capitulino75363762012-09-21 13:53:00 -03001319 char *prot;
Wen Congyang783e9b42012-05-07 12:10:47 +08001320
1321 if (has_begin) {
1322 begin = qdict_get_int(qdict, "begin");
1323 }
1324 if (has_length) {
1325 length = qdict_get_int(qdict, "length");
1326 }
1327
Luiz Capitulino75363762012-09-21 13:53:00 -03001328 prot = g_strconcat("file:", file, NULL);
1329
1330 qmp_dump_guest_memory(paging, prot, has_begin, begin, has_length, length,
qiaonuohanb53ccc32014-02-18 14:11:36 +08001331 has_format, dump_format, &errp);
Wen Congyang783e9b42012-05-07 12:10:47 +08001332 hmp_handle_error(mon, &errp);
Luiz Capitulino75363762012-09-21 13:53:00 -03001333 g_free(prot);
Wen Congyang783e9b42012-05-07 12:10:47 +08001334}
Luiz Capitulino928059a2012-04-18 17:34:15 -03001335
1336void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1337{
1338 Error *err = NULL;
1339 QemuOpts *opts;
1340
1341 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
Markus Armbruster84d18f02014-01-30 15:07:28 +01001342 if (err) {
Luiz Capitulino928059a2012-04-18 17:34:15 -03001343 goto out;
1344 }
1345
1346 netdev_add(opts, &err);
Markus Armbruster84d18f02014-01-30 15:07:28 +01001347 if (err) {
Luiz Capitulino928059a2012-04-18 17:34:15 -03001348 qemu_opts_del(opts);
1349 }
1350
1351out:
1352 hmp_handle_error(mon, &err);
1353}
Luiz Capitulino5f964152012-04-16 14:36:32 -03001354
1355void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1356{
1357 const char *id = qdict_get_str(qdict, "id");
1358 Error *err = NULL;
1359
1360 qmp_netdev_del(id, &err);
1361 hmp_handle_error(mon, &err);
1362}
Corey Bryant208c9d12012-06-22 14:36:09 -04001363
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01001364void hmp_object_add(Monitor *mon, const QDict *qdict)
1365{
1366 Error *err = NULL;
1367 QemuOpts *opts;
1368 char *type = NULL;
1369 char *id = NULL;
1370 void *dummy = NULL;
1371 OptsVisitor *ov;
1372 QDict *pdict;
1373
1374 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1375 if (err) {
1376 goto out;
1377 }
1378
1379 ov = opts_visitor_new(opts);
1380 pdict = qdict_clone_shallow(qdict);
1381
1382 visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err);
1383 if (err) {
1384 goto out_clean;
1385 }
1386
1387 qdict_del(pdict, "qom-type");
1388 visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
1389 if (err) {
1390 goto out_clean;
1391 }
1392
1393 qdict_del(pdict, "id");
1394 visit_type_str(opts_get_visitor(ov), &id, "id", &err);
1395 if (err) {
1396 goto out_clean;
1397 }
1398
1399 object_add(type, id, pdict, opts_get_visitor(ov), &err);
1400 if (err) {
1401 goto out_clean;
1402 }
1403 visit_end_struct(opts_get_visitor(ov), &err);
1404 if (err) {
1405 qmp_object_del(id, NULL);
1406 }
1407
1408out_clean:
1409 opts_visitor_cleanup(ov);
1410
1411 QDECREF(pdict);
1412 qemu_opts_del(opts);
1413 g_free(id);
1414 g_free(type);
1415 g_free(dummy);
1416
1417out:
1418 hmp_handle_error(mon, &err);
1419}
1420
Corey Bryant208c9d12012-06-22 14:36:09 -04001421void hmp_getfd(Monitor *mon, const QDict *qdict)
1422{
1423 const char *fdname = qdict_get_str(qdict, "fdname");
1424 Error *errp = NULL;
1425
1426 qmp_getfd(fdname, &errp);
1427 hmp_handle_error(mon, &errp);
1428}
1429
1430void hmp_closefd(Monitor *mon, const QDict *qdict)
1431{
1432 const char *fdname = qdict_get_str(qdict, "fdname");
1433 Error *errp = NULL;
1434
1435 qmp_closefd(fdname, &errp);
1436 hmp_handle_error(mon, &errp);
1437}
Amos Konge4c8f002012-08-31 10:56:26 +08001438
1439void hmp_send_key(Monitor *mon, const QDict *qdict)
1440{
1441 const char *keys = qdict_get_str(qdict, "keys");
Luiz Capitulino9f328972012-09-20 14:19:47 -03001442 KeyValueList *keylist, *head = NULL, *tmp = NULL;
Amos Konge4c8f002012-08-31 10:56:26 +08001443 int has_hold_time = qdict_haskey(qdict, "hold-time");
1444 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1445 Error *err = NULL;
1446 char keyname_buf[16];
1447 char *separator;
Luiz Capitulino9f328972012-09-20 14:19:47 -03001448 int keyname_len;
Amos Konge4c8f002012-08-31 10:56:26 +08001449
1450 while (1) {
1451 separator = strchr(keys, '-');
1452 keyname_len = separator ? separator - keys : strlen(keys);
1453 pstrcpy(keyname_buf, sizeof(keyname_buf), keys);
1454
1455 /* Be compatible with old interface, convert user inputted "<" */
1456 if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) {
1457 pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
1458 keyname_len = 4;
1459 }
1460 keyname_buf[keyname_len] = 0;
1461
Amos Konge4c8f002012-08-31 10:56:26 +08001462 keylist = g_malloc0(sizeof(*keylist));
Luiz Capitulino9f328972012-09-20 14:19:47 -03001463 keylist->value = g_malloc0(sizeof(*keylist->value));
Amos Konge4c8f002012-08-31 10:56:26 +08001464
1465 if (!head) {
1466 head = keylist;
1467 }
1468 if (tmp) {
1469 tmp->next = keylist;
1470 }
1471 tmp = keylist;
1472
Luiz Capitulino9f328972012-09-20 14:19:47 -03001473 if (strstart(keyname_buf, "0x", NULL)) {
1474 char *endp;
1475 int value = strtoul(keyname_buf, &endp, 0);
1476 if (*endp != '\0') {
1477 goto err_out;
1478 }
1479 keylist->value->kind = KEY_VALUE_KIND_NUMBER;
1480 keylist->value->number = value;
1481 } else {
1482 int idx = index_from_key(keyname_buf);
1483 if (idx == Q_KEY_CODE_MAX) {
1484 goto err_out;
1485 }
1486 keylist->value->kind = KEY_VALUE_KIND_QCODE;
1487 keylist->value->qcode = idx;
1488 }
1489
Amos Konge4c8f002012-08-31 10:56:26 +08001490 if (!separator) {
1491 break;
1492 }
1493 keys = separator + 1;
1494 }
1495
Luiz Capitulino9f328972012-09-20 14:19:47 -03001496 qmp_send_key(head, has_hold_time, hold_time, &err);
Amos Konge4c8f002012-08-31 10:56:26 +08001497 hmp_handle_error(mon, &err);
Luiz Capitulino9f328972012-09-20 14:19:47 -03001498
1499out:
1500 qapi_free_KeyValueList(head);
1501 return;
1502
1503err_out:
1504 monitor_printf(mon, "invalid parameter: %s\n", keyname_buf);
1505 goto out;
Amos Konge4c8f002012-08-31 10:56:26 +08001506}
Luiz Capitulinoad39cf62012-05-24 13:48:23 -03001507
1508void hmp_screen_dump(Monitor *mon, const QDict *qdict)
1509{
1510 const char *filename = qdict_get_str(qdict, "filename");
1511 Error *err = NULL;
1512
1513 qmp_screendump(filename, &err);
1514 hmp_handle_error(mon, &err);
1515}
Paolo Bonzini40577252012-08-23 11:53:04 +02001516
1517void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1518{
1519 const char *uri = qdict_get_str(qdict, "uri");
1520 int writable = qdict_get_try_bool(qdict, "writable", 0);
1521 int all = qdict_get_try_bool(qdict, "all", 0);
1522 Error *local_err = NULL;
1523 BlockInfoList *block_list, *info;
1524 SocketAddress *addr;
1525
1526 if (writable && !all) {
1527 error_setg(&local_err, "-w only valid together with -a");
1528 goto exit;
1529 }
1530
1531 /* First check if the address is valid and start the server. */
1532 addr = socket_parse(uri, &local_err);
1533 if (local_err != NULL) {
1534 goto exit;
1535 }
1536
1537 qmp_nbd_server_start(addr, &local_err);
1538 qapi_free_SocketAddress(addr);
1539 if (local_err != NULL) {
1540 goto exit;
1541 }
1542
1543 if (!all) {
1544 return;
1545 }
1546
1547 /* Then try adding all block devices. If one fails, close all and
1548 * exit.
1549 */
1550 block_list = qmp_query_block(NULL);
1551
1552 for (info = block_list; info; info = info->next) {
1553 if (!info->value->has_inserted) {
1554 continue;
1555 }
1556
1557 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1558
1559 if (local_err != NULL) {
1560 qmp_nbd_server_stop(NULL);
1561 break;
1562 }
1563 }
1564
1565 qapi_free_BlockInfoList(block_list);
1566
1567exit:
1568 hmp_handle_error(mon, &local_err);
1569}
1570
1571void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1572{
1573 const char *device = qdict_get_str(qdict, "device");
1574 int writable = qdict_get_try_bool(qdict, "writable", 0);
1575 Error *local_err = NULL;
1576
1577 qmp_nbd_server_add(device, true, writable, &local_err);
1578
1579 if (local_err != NULL) {
1580 hmp_handle_error(mon, &local_err);
1581 }
1582}
1583
1584void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1585{
1586 Error *errp = NULL;
1587
1588 qmp_nbd_server_stop(&errp);
1589 hmp_handle_error(mon, &errp);
1590}
Gerd Hoffmannf1088902012-12-19 10:33:40 +01001591
Jason J. Herneabf23322013-12-11 13:24:14 -05001592void hmp_cpu_add(Monitor *mon, const QDict *qdict)
1593{
1594 int cpuid;
1595 Error *err = NULL;
1596
1597 cpuid = qdict_get_int(qdict, "id");
1598 qmp_cpu_add(cpuid, &err);
1599 hmp_handle_error(mon, &err);
1600}
1601
Gerd Hoffmannf1088902012-12-19 10:33:40 +01001602void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1603{
1604 const char *args = qdict_get_str(qdict, "args");
1605 Error *err = NULL;
1606 QemuOpts *opts;
1607
1608 opts = qemu_opts_parse(qemu_find_opts("chardev"), args, 1);
1609 if (opts == NULL) {
Markus Armbruster312fd5f2013-02-08 21:22:16 +01001610 error_setg(&err, "Parsing chardev args failed");
Gerd Hoffmannf1088902012-12-19 10:33:40 +01001611 } else {
1612 qemu_chr_new_from_opts(opts, NULL, &err);
1613 }
1614 hmp_handle_error(mon, &err);
1615}
1616
1617void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1618{
1619 Error *local_err = NULL;
1620
1621 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1622 hmp_handle_error(mon, &local_err);
1623}
Kevin Wolf587da2c2013-06-05 14:19:41 +02001624
1625void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1626{
1627 BlockDriverState *bs;
1628 const char* device = qdict_get_str(qdict, "device");
1629 const char* command = qdict_get_str(qdict, "command");
1630 Error *err = NULL;
1631
1632 bs = bdrv_find(device);
1633 if (bs) {
1634 qemuio_command(bs, command);
1635 } else {
1636 error_set(&err, QERR_DEVICE_NOT_FOUND, device);
1637 }
1638
1639 hmp_handle_error(mon, &err);
1640}
Paolo Bonziniab2d0532013-12-20 23:21:09 +01001641
1642void hmp_object_del(Monitor *mon, const QDict *qdict)
1643{
1644 const char *id = qdict_get_str(qdict, "id");
1645 Error *err = NULL;
1646
1647 qmp_object_del(id, &err);
1648 hmp_handle_error(mon, &err);
1649}