blob: 32ee285a1e2b1cac31aada45c994418e3229a857 [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 Bonzini28ecbae2012-11-28 12:06:30 +010024#include "ui/console.h"
Wenchao Xiabd093a32013-06-06 12:28:00 +080025#include "block/qapi.h"
Kevin Wolf587da2c2013-06-05 14:19:41 +020026#include "qemu-io.h"
Anthony Liguori48a32be2011-09-02 12:34:48 -050027
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -020028static void hmp_handle_error(Monitor *mon, Error **errp)
29{
30 if (error_is_set(errp)) {
31 monitor_printf(mon, "%s\n", error_get_pretty(*errp));
32 error_free(*errp);
33 }
34}
35
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080036void hmp_info_name(Monitor *mon, const QDict *qdict)
Anthony Liguori48a32be2011-09-02 12:34:48 -050037{
38 NameInfo *info;
39
40 info = qmp_query_name(NULL);
41 if (info->has_name) {
42 monitor_printf(mon, "%s\n", info->name);
43 }
44 qapi_free_NameInfo(info);
45}
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030046
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080047void hmp_info_version(Monitor *mon, const QDict *qdict)
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030048{
49 VersionInfo *info;
50
51 info = qmp_query_version(NULL);
52
53 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
54 info->qemu.major, info->qemu.minor, info->qemu.micro,
55 info->package);
56
57 qapi_free_VersionInfo(info);
58}
Luiz Capitulino292a2602011-09-12 15:10:53 -030059
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080060void hmp_info_kvm(Monitor *mon, const QDict *qdict)
Luiz Capitulino292a2602011-09-12 15:10:53 -030061{
62 KvmInfo *info;
63
64 info = qmp_query_kvm(NULL);
65 monitor_printf(mon, "kvm support: ");
66 if (info->present) {
67 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
68 } else {
69 monitor_printf(mon, "not compiled\n");
70 }
71
72 qapi_free_KvmInfo(info);
73}
74
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080075void hmp_info_status(Monitor *mon, const QDict *qdict)
Luiz Capitulino1fa9a5e2011-09-12 17:54:20 -030076{
77 StatusInfo *info;
78
79 info = qmp_query_status(NULL);
80
81 monitor_printf(mon, "VM status: %s%s",
82 info->running ? "running" : "paused",
83 info->singlestep ? " (single step mode)" : "");
84
85 if (!info->running && info->status != RUN_STATE_PAUSED) {
86 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
87 }
88
89 monitor_printf(mon, "\n");
90
91 qapi_free_StatusInfo(info);
92}
93
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080094void hmp_info_uuid(Monitor *mon, const QDict *qdict)
Luiz Capitulinoefab7672011-09-13 17:16:25 -030095{
96 UuidInfo *info;
97
98 info = qmp_query_uuid(NULL);
99 monitor_printf(mon, "%s\n", info->UUID);
100 qapi_free_UuidInfo(info);
101}
Luiz Capitulinoc5a415a2011-09-14 16:05:49 -0300102
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800103void hmp_info_chardev(Monitor *mon, const QDict *qdict)
Luiz Capitulinoc5a415a2011-09-14 16:05:49 -0300104{
105 ChardevInfoList *char_info, *info;
106
107 char_info = qmp_query_chardev(NULL);
108 for (info = char_info; info; info = info->next) {
109 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
110 info->value->filename);
111 }
112
113 qapi_free_ChardevInfoList(char_info);
114}
Luiz Capitulino7a7f3252011-09-15 14:20:28 -0300115
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800116void hmp_info_mice(Monitor *mon, const QDict *qdict)
Luiz Capitulinoe235cec2011-09-21 15:29:55 -0300117{
118 MouseInfoList *mice_list, *mouse;
119
120 mice_list = qmp_query_mice(NULL);
121 if (!mice_list) {
122 monitor_printf(mon, "No mouse devices connected\n");
123 return;
124 }
125
126 for (mouse = mice_list; mouse; mouse = mouse->next) {
127 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
128 mouse->value->current ? '*' : ' ',
129 mouse->value->index, mouse->value->name,
130 mouse->value->absolute ? " (absolute)" : "");
131 }
132
133 qapi_free_MouseInfoList(mice_list);
134}
135
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800136void hmp_info_migrate(Monitor *mon, const QDict *qdict)
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300137{
138 MigrationInfo *info;
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300139 MigrationCapabilityStatusList *caps, *cap;
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300140
141 info = qmp_query_migrate(NULL);
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300142 caps = qmp_query_migrate_capabilities(NULL);
143
144 /* do not display parameters during setup */
145 if (info->has_status && caps) {
146 monitor_printf(mon, "capabilities: ");
147 for (cap = caps; cap; cap = cap->next) {
148 monitor_printf(mon, "%s: %s ",
149 MigrationCapability_lookup[cap->value->capability],
150 cap->value->state ? "on" : "off");
151 }
152 monitor_printf(mon, "\n");
153 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300154
155 if (info->has_status) {
156 monitor_printf(mon, "Migration status: %s\n", info->status);
Juan Quintela7aa939a2012-08-18 13:17:10 +0200157 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
158 info->total_time);
Juan Quintela2c52ddf2012-08-13 09:53:12 +0200159 if (info->has_expected_downtime) {
160 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
161 info->expected_downtime);
162 }
Juan Quintela9c5a9fc2012-08-13 09:35:16 +0200163 if (info->has_downtime) {
164 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
165 info->downtime);
166 }
Michael R. Hinesed4fbd12013-07-22 10:01:58 -0400167 if (info->has_setup_time) {
168 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
169 info->setup_time);
170 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300171 }
172
173 if (info->has_ram) {
174 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
175 info->ram->transferred >> 10);
Michael R. Hines7e114f82013-06-25 21:35:30 -0400176 monitor_printf(mon, "throughput: %0.2f mbps\n",
177 info->ram->mbps);
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300178 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
179 info->ram->remaining >> 10);
180 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
181 info->ram->total >> 10);
Orit Wasserman004d4c12012-08-06 21:42:56 +0300182 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
183 info->ram->duplicate);
Peter Lievenf1c72792013-03-26 10:58:37 +0100184 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
185 info->ram->skipped);
Orit Wasserman004d4c12012-08-06 21:42:56 +0300186 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
187 info->ram->normal);
188 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
189 info->ram->normal_bytes >> 10);
Juan Quintela8d017192012-08-13 12:31:25 +0200190 if (info->ram->dirty_pages_rate) {
191 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
192 info->ram->dirty_pages_rate);
193 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300194 }
195
196 if (info->has_disk) {
197 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
198 info->disk->transferred >> 10);
199 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
200 info->disk->remaining >> 10);
201 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
202 info->disk->total >> 10);
203 }
204
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300205 if (info->has_xbzrle_cache) {
206 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
207 info->xbzrle_cache->cache_size);
208 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
209 info->xbzrle_cache->bytes >> 10);
210 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
211 info->xbzrle_cache->pages);
212 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
213 info->xbzrle_cache->cache_miss);
214 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
215 info->xbzrle_cache->overflow);
216 }
217
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300218 qapi_free_MigrationInfo(info);
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300219 qapi_free_MigrationCapabilityStatusList(caps);
220}
221
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800222void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300223{
224 MigrationCapabilityStatusList *caps, *cap;
225
226 caps = qmp_query_migrate_capabilities(NULL);
227
228 if (caps) {
229 monitor_printf(mon, "capabilities: ");
230 for (cap = caps; cap; cap = cap->next) {
231 monitor_printf(mon, "%s: %s ",
232 MigrationCapability_lookup[cap->value->capability],
233 cap->value->state ? "on" : "off");
234 }
235 monitor_printf(mon, "\n");
236 }
237
238 qapi_free_MigrationCapabilityStatusList(caps);
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300239}
240
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800241void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +0300242{
243 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
244 qmp_query_migrate_cache_size(NULL) >> 10);
245}
246
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800247void hmp_info_cpus(Monitor *mon, const QDict *qdict)
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300248{
249 CpuInfoList *cpu_list, *cpu;
250
251 cpu_list = qmp_query_cpus(NULL);
252
253 for (cpu = cpu_list; cpu; cpu = cpu->next) {
254 int active = ' ';
255
256 if (cpu->value->CPU == monitor_get_cpu_index()) {
257 active = '*';
258 }
259
Aurelien Jarno852bef02012-10-19 23:19:19 +0200260 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300261
262 if (cpu->value->has_pc) {
Aurelien Jarno852bef02012-10-19 23:19:19 +0200263 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->pc);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300264 }
265 if (cpu->value->has_nip) {
Aurelien Jarno852bef02012-10-19 23:19:19 +0200266 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->nip);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300267 }
268 if (cpu->value->has_npc) {
Aurelien Jarno852bef02012-10-19 23:19:19 +0200269 monitor_printf(mon, " npc=0x%016" PRIx64, cpu->value->npc);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300270 }
271 if (cpu->value->has_PC) {
Aurelien Jarno852bef02012-10-19 23:19:19 +0200272 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->PC);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300273 }
274
275 if (cpu->value->halted) {
276 monitor_printf(mon, " (halted)");
277 }
278
279 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
280 }
281
282 qapi_free_CpuInfoList(cpu_list);
283}
284
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800285void hmp_info_block(Monitor *mon, const QDict *qdict)
Luiz Capitulinob2023812011-09-21 17:16:47 -0300286{
287 BlockInfoList *block_list, *info;
Wenchao Xiabd093a32013-06-06 12:28:00 +0800288 ImageInfo *image_info;
Wenchao Xiae73fe2b2013-06-06 12:28:01 +0800289 const char *device = qdict_get_try_str(qdict, "device");
290 bool verbose = qdict_get_try_bool(qdict, "verbose", 0);
Luiz Capitulinob2023812011-09-21 17:16:47 -0300291
292 block_list = qmp_query_block(NULL);
293
294 for (info = block_list; info; info = info->next) {
Wenchao Xiae73fe2b2013-06-06 12:28:01 +0800295 if (device && strcmp(device, info->value->device)) {
296 continue;
297 }
Luiz Capitulinob2023812011-09-21 17:16:47 -0300298
Kevin Wolffbe2e262013-06-19 16:10:55 +0200299 if (info != block_list) {
300 monitor_printf(mon, "\n");
Luiz Capitulinob2023812011-09-21 17:16:47 -0300301 }
302
Kevin Wolffbe2e262013-06-19 16:10:55 +0200303 monitor_printf(mon, "%s", info->value->device);
304 if (info->value->has_inserted) {
305 monitor_printf(mon, ": %s (%s%s%s)\n",
306 info->value->inserted->file,
307 info->value->inserted->drv,
308 info->value->inserted->ro ? ", read-only" : "",
309 info->value->inserted->encrypted ? ", encrypted" : "");
310 } else {
311 monitor_printf(mon, ": [not inserted]\n");
312 }
313
314 if (info->value->has_io_status && info->value->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
315 monitor_printf(mon, " I/O status: %s\n",
Luiz Capitulinob2023812011-09-21 17:16:47 -0300316 BlockDeviceIoStatus_lookup[info->value->io_status]);
317 }
318
Kevin Wolffbe2e262013-06-19 16:10:55 +0200319 if (info->value->removable) {
320 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
321 info->value->locked ? "" : "not ",
322 info->value->tray_open ? "open" : "closed");
323 }
Luiz Capitulinob2023812011-09-21 17:16:47 -0300324
Zhi Yong Wu727f0052011-11-08 13:00:31 +0800325
Kevin Wolffbe2e262013-06-19 16:10:55 +0200326 if (!info->value->has_inserted) {
327 continue;
328 }
329
330 if (info->value->inserted->has_backing_file) {
331 monitor_printf(mon,
332 " Backing file: %s "
333 "(chain depth: %" PRId64 ")\n",
334 info->value->inserted->backing_file,
335 info->value->inserted->backing_file_depth);
336 }
337
338 if (info->value->inserted->bps
339 || info->value->inserted->bps_rd
340 || info->value->inserted->bps_wr
341 || info->value->inserted->iops
342 || info->value->inserted->iops_rd
343 || info->value->inserted->iops_wr)
344 {
345 monitor_printf(mon, " I/O throttling: bps=%" PRId64
346 " bps_rd=%" PRId64 " bps_wr=%" PRId64
Benoît Canet3e9fab62013-09-02 14:14:40 +0200347 " bps_max=%" PRId64
348 " bps_rd_max=%" PRId64
349 " bps_wr_max=%" PRId64
Kevin Wolffbe2e262013-06-19 16:10:55 +0200350 " iops=%" PRId64 " iops_rd=%" PRId64
Benoît Canet3e9fab62013-09-02 14:14:40 +0200351 " iops_wr=%" PRId64
352 " iops_max=%" PRId64
353 " iops_rd_max=%" PRId64
Benoît Canet2024c1d2013-09-02 14:14:41 +0200354 " iops_wr_max=%" PRId64
355 " iops_size=%" PRId64 "\n",
Zhi Yong Wu727f0052011-11-08 13:00:31 +0800356 info->value->inserted->bps,
357 info->value->inserted->bps_rd,
358 info->value->inserted->bps_wr,
Benoît Canet3e9fab62013-09-02 14:14:40 +0200359 info->value->inserted->bps_max,
360 info->value->inserted->bps_rd_max,
361 info->value->inserted->bps_wr_max,
Zhi Yong Wu727f0052011-11-08 13:00:31 +0800362 info->value->inserted->iops,
363 info->value->inserted->iops_rd,
Benoît Canet3e9fab62013-09-02 14:14:40 +0200364 info->value->inserted->iops_wr,
365 info->value->inserted->iops_max,
366 info->value->inserted->iops_rd_max,
Benoît Canet2024c1d2013-09-02 14:14:41 +0200367 info->value->inserted->iops_wr_max,
368 info->value->inserted->iops_size);
Luiz Capitulinob2023812011-09-21 17:16:47 -0300369 }
370
Kevin Wolffbe2e262013-06-19 16:10:55 +0200371 if (verbose) {
372 monitor_printf(mon, "\nImages:\n");
373 image_info = info->value->inserted->image;
374 while (1) {
375 bdrv_image_info_dump((fprintf_function)monitor_printf,
376 mon, image_info);
377 if (image_info->has_backing_image) {
378 image_info = image_info->backing_image;
379 } else {
380 break;
381 }
382 }
383 }
Luiz Capitulinob2023812011-09-21 17:16:47 -0300384 }
385
386 qapi_free_BlockInfoList(block_list);
387}
388
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800389void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300390{
391 BlockStatsList *stats_list, *stats;
392
393 stats_list = qmp_query_blockstats(NULL);
394
395 for (stats = stats_list; stats; stats = stats->next) {
396 if (!stats->value->has_device) {
397 continue;
398 }
399
400 monitor_printf(mon, "%s:", stats->value->device);
401 monitor_printf(mon, " rd_bytes=%" PRId64
402 " wr_bytes=%" PRId64
403 " rd_operations=%" PRId64
404 " wr_operations=%" PRId64
405 " flush_operations=%" PRId64
406 " wr_total_time_ns=%" PRId64
407 " rd_total_time_ns=%" PRId64
408 " flush_total_time_ns=%" PRId64
409 "\n",
410 stats->value->stats->rd_bytes,
411 stats->value->stats->wr_bytes,
412 stats->value->stats->rd_operations,
413 stats->value->stats->wr_operations,
414 stats->value->stats->flush_operations,
415 stats->value->stats->wr_total_time_ns,
416 stats->value->stats->rd_total_time_ns,
417 stats->value->stats->flush_total_time_ns);
418 }
419
420 qapi_free_BlockStatsList(stats_list);
421}
422
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800423void hmp_info_vnc(Monitor *mon, const QDict *qdict)
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200424{
425 VncInfo *info;
426 Error *err = NULL;
427 VncClientInfoList *client;
428
429 info = qmp_query_vnc(&err);
430 if (err) {
431 monitor_printf(mon, "%s\n", error_get_pretty(err));
432 error_free(err);
433 return;
434 }
435
436 if (!info->enabled) {
437 monitor_printf(mon, "Server: disabled\n");
438 goto out;
439 }
440
441 monitor_printf(mon, "Server:\n");
442 if (info->has_host && info->has_service) {
443 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
444 }
445 if (info->has_auth) {
446 monitor_printf(mon, " auth: %s\n", info->auth);
447 }
448
449 if (!info->has_clients || info->clients == NULL) {
450 monitor_printf(mon, "Client: none\n");
451 } else {
452 for (client = info->clients; client; client = client->next) {
453 monitor_printf(mon, "Client:\n");
454 monitor_printf(mon, " address: %s:%s\n",
455 client->value->host, client->value->service);
456 monitor_printf(mon, " x509_dname: %s\n",
457 client->value->x509_dname ?
458 client->value->x509_dname : "none");
459 monitor_printf(mon, " username: %s\n",
460 client->value->has_sasl_username ?
461 client->value->sasl_username : "none");
462 }
463 }
464
465out:
466 qapi_free_VncInfo(info);
467}
468
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800469void hmp_info_spice(Monitor *mon, const QDict *qdict)
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200470{
471 SpiceChannelList *chan;
472 SpiceInfo *info;
473
474 info = qmp_query_spice(NULL);
475
476 if (!info->enabled) {
477 monitor_printf(mon, "Server: disabled\n");
478 goto out;
479 }
480
481 monitor_printf(mon, "Server:\n");
482 if (info->has_port) {
483 monitor_printf(mon, " address: %s:%" PRId64 "\n",
484 info->host, info->port);
485 }
486 if (info->has_tls_port) {
487 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
488 info->host, info->tls_port);
489 }
Yonit Halperin61c4efe2012-08-21 11:51:58 +0300490 monitor_printf(mon, " migrated: %s\n",
491 info->migrated ? "true" : "false");
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200492 monitor_printf(mon, " auth: %s\n", info->auth);
493 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
Alon Levy4efee022012-03-29 23:23:14 +0200494 monitor_printf(mon, " mouse-mode: %s\n",
495 SpiceQueryMouseMode_lookup[info->mouse_mode]);
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200496
497 if (!info->has_channels || info->channels == NULL) {
498 monitor_printf(mon, "Channels: none\n");
499 } else {
500 for (chan = info->channels; chan; chan = chan->next) {
501 monitor_printf(mon, "Channel:\n");
502 monitor_printf(mon, " address: %s:%s%s\n",
503 chan->value->host, chan->value->port,
504 chan->value->tls ? " [tls]" : "");
505 monitor_printf(mon, " session: %" PRId64 "\n",
506 chan->value->connection_id);
507 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
508 chan->value->channel_type, chan->value->channel_id);
509 }
510 }
511
512out:
513 qapi_free_SpiceInfo(info);
514}
515
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800516void hmp_info_balloon(Monitor *mon, const QDict *qdict)
Luiz Capitulino96637bc2011-10-21 11:41:37 -0200517{
518 BalloonInfo *info;
519 Error *err = NULL;
520
521 info = qmp_query_balloon(&err);
522 if (err) {
523 monitor_printf(mon, "%s\n", error_get_pretty(err));
524 error_free(err);
525 return;
526 }
527
Luiz Capitulino01ceb972012-12-03 15:56:41 -0200528 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
Luiz Capitulino96637bc2011-10-21 11:41:37 -0200529
530 qapi_free_BalloonInfo(info);
531}
532
Luiz Capitulino79627472011-10-21 14:15:33 -0200533static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
534{
535 PciMemoryRegionList *region;
536
537 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
538 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
539 dev->slot, dev->function);
540 monitor_printf(mon, " ");
541
542 if (dev->class_info.has_desc) {
543 monitor_printf(mon, "%s", dev->class_info.desc);
544 } else {
Tomoki Sekiyama6f880092013-08-07 11:39:43 -0400545 monitor_printf(mon, "Class %04" PRId64, dev->class_info.q_class);
Luiz Capitulino79627472011-10-21 14:15:33 -0200546 }
547
548 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
549 dev->id.vendor, dev->id.device);
550
551 if (dev->has_irq) {
552 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
553 }
554
555 if (dev->has_pci_bridge) {
556 monitor_printf(mon, " BUS %" PRId64 ".\n",
557 dev->pci_bridge->bus.number);
558 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
559 dev->pci_bridge->bus.secondary);
560 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
561 dev->pci_bridge->bus.subordinate);
562
563 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
564 dev->pci_bridge->bus.io_range->base,
565 dev->pci_bridge->bus.io_range->limit);
566
567 monitor_printf(mon,
568 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
569 dev->pci_bridge->bus.memory_range->base,
570 dev->pci_bridge->bus.memory_range->limit);
571
572 monitor_printf(mon, " prefetchable memory range "
573 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
574 dev->pci_bridge->bus.prefetchable_range->base,
575 dev->pci_bridge->bus.prefetchable_range->limit);
576 }
577
578 for (region = dev->regions; region; region = region->next) {
579 uint64_t addr, size;
580
581 addr = region->value->address;
582 size = region->value->size;
583
584 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
585
586 if (!strcmp(region->value->type, "io")) {
587 monitor_printf(mon, "I/O at 0x%04" PRIx64
588 " [0x%04" PRIx64 "].\n",
589 addr, addr + size - 1);
590 } else {
591 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
592 " [0x%08" PRIx64 "].\n",
593 region->value->mem_type_64 ? 64 : 32,
594 region->value->prefetch ? " prefetchable" : "",
595 addr, addr + size - 1);
596 }
597 }
598
599 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
600
601 if (dev->has_pci_bridge) {
602 if (dev->pci_bridge->has_devices) {
603 PciDeviceInfoList *cdev;
604 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
605 hmp_info_pci_device(mon, cdev->value);
606 }
607 }
608 }
609}
610
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800611void hmp_info_pci(Monitor *mon, const QDict *qdict)
Luiz Capitulino79627472011-10-21 14:15:33 -0200612{
Stefan Bergerf46cee32012-01-11 10:51:52 -0500613 PciInfoList *info_list, *info;
Luiz Capitulino79627472011-10-21 14:15:33 -0200614 Error *err = NULL;
615
Stefan Bergerf46cee32012-01-11 10:51:52 -0500616 info_list = qmp_query_pci(&err);
Luiz Capitulino79627472011-10-21 14:15:33 -0200617 if (err) {
618 monitor_printf(mon, "PCI devices not supported\n");
619 error_free(err);
620 return;
621 }
622
Stefan Bergerf46cee32012-01-11 10:51:52 -0500623 for (info = info_list; info; info = info->next) {
Luiz Capitulino79627472011-10-21 14:15:33 -0200624 PciDeviceInfoList *dev;
625
626 for (dev = info->value->devices; dev; dev = dev->next) {
627 hmp_info_pci_device(mon, dev->value);
628 }
629 }
630
Stefan Bergerf46cee32012-01-11 10:51:52 -0500631 qapi_free_PciInfoList(info_list);
Luiz Capitulino79627472011-10-21 14:15:33 -0200632}
633
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800634void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
Stefan Hajnoczifb5458c2012-01-18 14:40:49 +0000635{
636 BlockJobInfoList *list;
637 Error *err = NULL;
638
639 list = qmp_query_block_jobs(&err);
640 assert(!err);
641
642 if (!list) {
643 monitor_printf(mon, "No active jobs\n");
644 return;
645 }
646
647 while (list) {
648 if (strcmp(list->value->type, "stream") == 0) {
649 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
650 " of %" PRId64 " bytes, speed limit %" PRId64
651 " bytes/s\n",
652 list->value->device,
653 list->value->offset,
654 list->value->len,
655 list->value->speed);
656 } else {
657 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
658 " of %" PRId64 " bytes, speed limit %" PRId64
659 " bytes/s\n",
660 list->value->type,
661 list->value->device,
662 list->value->offset,
663 list->value->len,
664 list->value->speed);
665 }
666 list = list->next;
667 }
668}
669
Stefan Bergerd1a0cf72013-02-27 12:47:49 -0500670void hmp_info_tpm(Monitor *mon, const QDict *qdict)
671{
672 TPMInfoList *info_list, *info;
673 Error *err = NULL;
674 unsigned int c = 0;
675 TPMPassthroughOptions *tpo;
676
677 info_list = qmp_query_tpm(&err);
678 if (err) {
679 monitor_printf(mon, "TPM device not supported\n");
680 error_free(err);
681 return;
682 }
683
684 if (info_list) {
685 monitor_printf(mon, "TPM device:\n");
686 }
687
688 for (info = info_list; info; info = info->next) {
689 TPMInfo *ti = info->value;
690 monitor_printf(mon, " tpm%d: model=%s\n",
691 c, TpmModel_lookup[ti->model]);
692
693 monitor_printf(mon, " \\ %s: type=%s",
Corey Bryant88ca7bc2013-03-20 12:34:48 -0400694 ti->id, TpmTypeOptionsKind_lookup[ti->options->kind]);
Stefan Bergerd1a0cf72013-02-27 12:47:49 -0500695
Corey Bryant88ca7bc2013-03-20 12:34:48 -0400696 switch (ti->options->kind) {
697 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
698 tpo = ti->options->passthrough;
Stefan Bergerd1a0cf72013-02-27 12:47:49 -0500699 monitor_printf(mon, "%s%s%s%s",
700 tpo->has_path ? ",path=" : "",
701 tpo->has_path ? tpo->path : "",
702 tpo->has_cancel_path ? ",cancel-path=" : "",
703 tpo->has_cancel_path ? tpo->cancel_path : "");
704 break;
705 case TPM_TYPE_OPTIONS_KIND_MAX:
706 break;
707 }
708 monitor_printf(mon, "\n");
709 c++;
710 }
711 qapi_free_TPMInfoList(info_list);
712}
713
Luiz Capitulino7a7f3252011-09-15 14:20:28 -0300714void hmp_quit(Monitor *mon, const QDict *qdict)
715{
716 monitor_suspend(mon);
717 qmp_quit(NULL);
718}
Luiz Capitulino5f158f22011-09-15 14:34:39 -0300719
720void hmp_stop(Monitor *mon, const QDict *qdict)
721{
722 qmp_stop(NULL);
723}
Luiz Capitulino38d22652011-09-15 14:41:46 -0300724
725void hmp_system_reset(Monitor *mon, const QDict *qdict)
726{
727 qmp_system_reset(NULL);
728}
Luiz Capitulino5bc465e2011-09-28 11:06:15 -0300729
730void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
731{
732 qmp_system_powerdown(NULL);
733}
Luiz Capitulino755f1962011-10-06 14:31:39 -0300734
735void hmp_cpu(Monitor *mon, const QDict *qdict)
736{
737 int64_t cpu_index;
738
739 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
740 use it are converted to the QAPI */
741 cpu_index = qdict_get_int(qdict, "index");
742 if (monitor_set_cpu(cpu_index) < 0) {
743 monitor_printf(mon, "invalid CPU index\n");
744 }
745}
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -0200746
747void hmp_memsave(Monitor *mon, const QDict *qdict)
748{
749 uint32_t size = qdict_get_int(qdict, "size");
750 const char *filename = qdict_get_str(qdict, "filename");
751 uint64_t addr = qdict_get_int(qdict, "val");
752 Error *errp = NULL;
753
754 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &errp);
755 hmp_handle_error(mon, &errp);
756}
Luiz Capitulino6d3962b2011-11-22 17:26:46 -0200757
758void hmp_pmemsave(Monitor *mon, const QDict *qdict)
759{
760 uint32_t size = qdict_get_int(qdict, "size");
761 const char *filename = qdict_get_str(qdict, "filename");
762 uint64_t addr = qdict_get_int(qdict, "val");
763 Error *errp = NULL;
764
765 qmp_pmemsave(addr, size, filename, &errp);
766 hmp_handle_error(mon, &errp);
767}
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200768
Markus Armbruster3949e592013-02-06 21:27:24 +0100769void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
Lei Li1f590cf2013-01-25 00:03:20 +0800770{
Lei Li1f590cf2013-01-25 00:03:20 +0800771 const char *chardev = qdict_get_str(qdict, "device");
772 const char *data = qdict_get_str(qdict, "data");
773 Error *errp = NULL;
774
Markus Armbruster3949e592013-02-06 21:27:24 +0100775 qmp_ringbuf_write(chardev, data, false, 0, &errp);
Lei Li1f590cf2013-01-25 00:03:20 +0800776
777 hmp_handle_error(mon, &errp);
778}
779
Markus Armbruster3949e592013-02-06 21:27:24 +0100780void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
Lei Li49b6d722013-01-25 00:03:21 +0800781{
782 uint32_t size = qdict_get_int(qdict, "size");
783 const char *chardev = qdict_get_str(qdict, "device");
Markus Armbruster3ab651f2013-02-06 21:27:15 +0100784 char *data;
Lei Li49b6d722013-01-25 00:03:21 +0800785 Error *errp = NULL;
Markus Armbruster543f3412013-02-06 21:27:26 +0100786 int i;
Lei Li49b6d722013-01-25 00:03:21 +0800787
Markus Armbruster3949e592013-02-06 21:27:24 +0100788 data = qmp_ringbuf_read(chardev, size, false, 0, &errp);
Lei Li49b6d722013-01-25 00:03:21 +0800789 if (errp) {
790 monitor_printf(mon, "%s\n", error_get_pretty(errp));
791 error_free(errp);
792 return;
793 }
794
Markus Armbruster543f3412013-02-06 21:27:26 +0100795 for (i = 0; data[i]; i++) {
796 unsigned char ch = data[i];
797
798 if (ch == '\\') {
799 monitor_printf(mon, "\\\\");
800 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
801 monitor_printf(mon, "\\u%04X", ch);
802 } else {
803 monitor_printf(mon, "%c", ch);
804 }
805
806 }
807 monitor_printf(mon, "\n");
Markus Armbruster3ab651f2013-02-06 21:27:15 +0100808 g_free(data);
Lei Li49b6d722013-01-25 00:03:21 +0800809}
810
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200811static void hmp_cont_cb(void *opaque, int err)
812{
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200813 if (!err) {
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300814 qmp_cont(NULL);
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200815 }
816}
817
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300818static bool key_is_missing(const BlockInfo *bdev)
819{
820 return (bdev->inserted && bdev->inserted->encryption_key_missing);
821}
822
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200823void hmp_cont(Monitor *mon, const QDict *qdict)
824{
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300825 BlockInfoList *bdev_list, *bdev;
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200826 Error *errp = NULL;
827
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300828 bdev_list = qmp_query_block(NULL);
829 for (bdev = bdev_list; bdev; bdev = bdev->next) {
830 if (key_is_missing(bdev->value)) {
831 monitor_read_block_device_key(mon, bdev->value->device,
832 hmp_cont_cb, NULL);
833 goto out;
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200834 }
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200835 }
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300836
837 qmp_cont(&errp);
838 hmp_handle_error(mon, &errp);
839
840out:
841 qapi_free_BlockInfoList(bdev_list);
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200842}
Luiz Capitulinoab49ab52011-11-23 12:55:53 -0200843
Gerd Hoffmann9b9df252012-02-23 13:45:21 +0100844void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
845{
846 qmp_system_wakeup(NULL);
847}
848
Luiz Capitulinoab49ab52011-11-23 12:55:53 -0200849void hmp_inject_nmi(Monitor *mon, const QDict *qdict)
850{
851 Error *errp = NULL;
852
853 qmp_inject_nmi(&errp);
854 hmp_handle_error(mon, &errp);
855}
Luiz Capitulino4b371562011-11-23 13:11:55 -0200856
857void hmp_set_link(Monitor *mon, const QDict *qdict)
858{
859 const char *name = qdict_get_str(qdict, "name");
860 int up = qdict_get_bool(qdict, "up");
861 Error *errp = NULL;
862
863 qmp_set_link(name, up, &errp);
864 hmp_handle_error(mon, &errp);
865}
Luiz Capitulinoa4dea8a2011-11-23 13:28:21 -0200866
867void hmp_block_passwd(Monitor *mon, const QDict *qdict)
868{
869 const char *device = qdict_get_str(qdict, "device");
870 const char *password = qdict_get_str(qdict, "password");
871 Error *errp = NULL;
872
873 qmp_block_passwd(device, password, &errp);
874 hmp_handle_error(mon, &errp);
875}
Luiz Capitulinod72f3262011-11-25 14:38:09 -0200876
877void hmp_balloon(Monitor *mon, const QDict *qdict)
878{
879 int64_t value = qdict_get_int(qdict, "value");
880 Error *errp = NULL;
881
882 qmp_balloon(value, &errp);
883 if (error_is_set(&errp)) {
884 monitor_printf(mon, "balloon: %s\n", error_get_pretty(errp));
885 error_free(errp);
886 }
887}
Luiz Capitulino5e7caac2011-11-25 14:57:10 -0200888
889void hmp_block_resize(Monitor *mon, const QDict *qdict)
890{
891 const char *device = qdict_get_str(qdict, "device");
892 int64_t size = qdict_get_int(qdict, "size");
893 Error *errp = NULL;
894
895 qmp_block_resize(device, size, &errp);
896 hmp_handle_error(mon, &errp);
897}
Luiz Capitulino6106e242011-11-25 16:15:19 -0200898
Paolo Bonzinid9b902d2012-10-18 16:49:24 +0200899void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
900{
901 const char *device = qdict_get_str(qdict, "device");
902 const char *filename = qdict_get_str(qdict, "target");
903 const char *format = qdict_get_try_str(qdict, "format");
904 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
905 int full = qdict_get_try_bool(qdict, "full", 0);
906 enum NewImageMode mode;
907 Error *errp = NULL;
908
909 if (!filename) {
910 error_set(&errp, QERR_MISSING_PARAMETER, "target");
911 hmp_handle_error(mon, &errp);
912 return;
913 }
914
915 if (reuse) {
916 mode = NEW_IMAGE_MODE_EXISTING;
917 } else {
918 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
919 }
920
921 qmp_drive_mirror(device, filename, !!format, format,
922 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
Paolo Bonzini08e4ed62013-01-22 09:03:13 +0100923 true, mode, false, 0, false, 0, false, 0,
Paolo Bonzinib952b552012-10-18 16:49:28 +0200924 false, 0, false, 0, &errp);
Paolo Bonzinid9b902d2012-10-18 16:49:24 +0200925 hmp_handle_error(mon, &errp);
926}
927
Stefan Hajnoczide909302013-06-26 14:11:58 +0200928void hmp_drive_backup(Monitor *mon, const QDict *qdict)
929{
930 const char *device = qdict_get_str(qdict, "device");
931 const char *filename = qdict_get_str(qdict, "target");
932 const char *format = qdict_get_try_str(qdict, "format");
933 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
934 int full = qdict_get_try_bool(qdict, "full", 0);
935 enum NewImageMode mode;
936 Error *errp = NULL;
937
938 if (!filename) {
939 error_set(&errp, QERR_MISSING_PARAMETER, "target");
940 hmp_handle_error(mon, &errp);
941 return;
942 }
943
944 if (reuse) {
945 mode = NEW_IMAGE_MODE_EXISTING;
946 } else {
947 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
948 }
949
950 qmp_drive_backup(device, filename, !!format, format,
951 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
952 true, mode, false, 0, false, 0, false, 0, &errp);
953 hmp_handle_error(mon, &errp);
954}
955
Luiz Capitulino6106e242011-11-25 16:15:19 -0200956void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
957{
958 const char *device = qdict_get_str(qdict, "device");
959 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
960 const char *format = qdict_get_try_str(qdict, "format");
Paolo Bonzini6cc2a412012-03-06 18:55:59 +0100961 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
962 enum NewImageMode mode;
Luiz Capitulino6106e242011-11-25 16:15:19 -0200963 Error *errp = NULL;
964
965 if (!filename) {
966 /* In the future, if 'snapshot-file' is not specified, the snapshot
967 will be taken internally. Today it's actually required. */
968 error_set(&errp, QERR_MISSING_PARAMETER, "snapshot-file");
969 hmp_handle_error(mon, &errp);
970 return;
971 }
972
Paolo Bonzini6cc2a412012-03-06 18:55:59 +0100973 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
974 qmp_blockdev_snapshot_sync(device, filename, !!format, format,
975 true, mode, &errp);
Luiz Capitulino6106e242011-11-25 16:15:19 -0200976 hmp_handle_error(mon, &errp);
977}
Luiz Capitulino6cdedb02011-11-27 22:54:09 -0200978
Wenchao Xia775ca882013-09-11 14:04:37 +0800979void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
980{
981 const char *device = qdict_get_str(qdict, "device");
982 const char *name = qdict_get_str(qdict, "name");
983 Error *errp = NULL;
984
985 qmp_blockdev_snapshot_internal_sync(device, name, &errp);
986 hmp_handle_error(mon, &errp);
987}
988
Wenchao Xia7a4ed2e2013-09-11 14:04:38 +0800989void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
990{
991 const char *device = qdict_get_str(qdict, "device");
992 const char *name = qdict_get_str(qdict, "name");
993 const char *id = qdict_get_try_str(qdict, "id");
994 Error *errp = NULL;
995
996 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
997 true, name, &errp);
998 hmp_handle_error(mon, &errp);
999}
1000
Luiz Capitulino6cdedb02011-11-27 22:54:09 -02001001void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1002{
1003 qmp_migrate_cancel(NULL);
1004}
Luiz Capitulino4f0a9932011-11-27 23:18:01 -02001005
1006void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1007{
1008 double value = qdict_get_double(qdict, "value");
1009 qmp_migrate_set_downtime(value, NULL);
1010}
Luiz Capitulino3dc85382011-11-28 11:59:37 -02001011
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +03001012void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1013{
1014 int64_t value = qdict_get_int(qdict, "value");
1015 Error *err = NULL;
1016
1017 qmp_migrate_set_cache_size(value, &err);
1018 if (err) {
1019 monitor_printf(mon, "%s\n", error_get_pretty(err));
1020 error_free(err);
1021 return;
1022 }
1023}
1024
Luiz Capitulino3dc85382011-11-28 11:59:37 -02001025void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1026{
1027 int64_t value = qdict_get_int(qdict, "value");
1028 qmp_migrate_set_speed(value, NULL);
1029}
Luiz Capitulinofbf796f2011-12-07 11:17:51 -02001030
Orit Wasserman00458432012-08-06 21:42:48 +03001031void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1032{
1033 const char *cap = qdict_get_str(qdict, "capability");
1034 bool state = qdict_get_bool(qdict, "state");
1035 Error *err = NULL;
1036 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1037 int i;
1038
1039 for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
1040 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1041 caps->value = g_malloc0(sizeof(*caps->value));
1042 caps->value->capability = i;
1043 caps->value->state = state;
1044 caps->next = NULL;
1045 qmp_migrate_set_capabilities(caps, &err);
1046 break;
1047 }
1048 }
1049
1050 if (i == MIGRATION_CAPABILITY_MAX) {
1051 error_set(&err, QERR_INVALID_PARAMETER, cap);
1052 }
1053
1054 qapi_free_MigrationCapabilityStatusList(caps);
1055
1056 if (err) {
Orit Wassermana31ca012013-01-31 09:12:19 +02001057 monitor_printf(mon, "migrate_set_capability: %s\n",
Orit Wasserman00458432012-08-06 21:42:48 +03001058 error_get_pretty(err));
1059 error_free(err);
1060 }
1061}
1062
Luiz Capitulinofbf796f2011-12-07 11:17:51 -02001063void hmp_set_password(Monitor *mon, const QDict *qdict)
1064{
1065 const char *protocol = qdict_get_str(qdict, "protocol");
1066 const char *password = qdict_get_str(qdict, "password");
1067 const char *connected = qdict_get_try_str(qdict, "connected");
1068 Error *err = NULL;
1069
1070 qmp_set_password(protocol, password, !!connected, connected, &err);
1071 hmp_handle_error(mon, &err);
1072}
Luiz Capitulino9ad53722011-12-07 11:47:57 -02001073
1074void hmp_expire_password(Monitor *mon, const QDict *qdict)
1075{
1076 const char *protocol = qdict_get_str(qdict, "protocol");
1077 const char *whenstr = qdict_get_str(qdict, "time");
1078 Error *err = NULL;
1079
1080 qmp_expire_password(protocol, whenstr, &err);
1081 hmp_handle_error(mon, &err);
1082}
Luiz Capitulinoc245b6a2011-12-07 16:02:36 -02001083
1084void hmp_eject(Monitor *mon, const QDict *qdict)
1085{
1086 int force = qdict_get_try_bool(qdict, "force", 0);
1087 const char *device = qdict_get_str(qdict, "device");
1088 Error *err = NULL;
1089
1090 qmp_eject(device, true, force, &err);
1091 hmp_handle_error(mon, &err);
1092}
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001093
1094static void hmp_change_read_arg(Monitor *mon, const char *password,
1095 void *opaque)
1096{
1097 qmp_change_vnc_password(password, NULL);
1098 monitor_read_command(mon, 1);
1099}
1100
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001101void hmp_change(Monitor *mon, const QDict *qdict)
1102{
1103 const char *device = qdict_get_str(qdict, "device");
1104 const char *target = qdict_get_str(qdict, "target");
1105 const char *arg = qdict_get_try_str(qdict, "arg");
1106 Error *err = NULL;
1107
1108 if (strcmp(device, "vnc") == 0 &&
1109 (strcmp(target, "passwd") == 0 ||
1110 strcmp(target, "password") == 0)) {
1111 if (!arg) {
1112 monitor_read_password(mon, hmp_change_read_arg, NULL);
1113 return;
1114 }
1115 }
1116
1117 qmp_change(device, target, !!arg, arg, &err);
Luiz Capitulinoab878dd2012-08-06 15:55:22 -03001118 if (error_is_set(&err) &&
1119 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
Luiz Capitulinoeef5ad12012-08-06 15:49:34 -03001120 error_free(err);
1121 monitor_read_block_device_key(mon, device, NULL, NULL);
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001122 return;
1123 }
1124 hmp_handle_error(mon, &err);
1125}
Luiz Capitulino80047da2011-12-14 16:49:14 -02001126
1127void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1128{
1129 Error *err = NULL;
1130
1131 qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
1132 qdict_get_int(qdict, "bps"),
1133 qdict_get_int(qdict, "bps_rd"),
1134 qdict_get_int(qdict, "bps_wr"),
1135 qdict_get_int(qdict, "iops"),
1136 qdict_get_int(qdict, "iops_rd"),
Benoît Canet3e9fab62013-09-02 14:14:40 +02001137 qdict_get_int(qdict, "iops_wr"),
1138 false, /* no burst max via HMP */
1139 0,
1140 false,
1141 0,
1142 false,
1143 0,
1144 false,
1145 0,
1146 false,
1147 0,
1148 false,
Benoît Canet2024c1d2013-09-02 14:14:41 +02001149 0,
1150 false, /* No default I/O size */
Benoît Canet3e9fab62013-09-02 14:14:40 +02001151 0, &err);
Luiz Capitulino80047da2011-12-14 16:49:14 -02001152 hmp_handle_error(mon, &err);
1153}
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00001154
1155void hmp_block_stream(Monitor *mon, const QDict *qdict)
1156{
1157 Error *error = NULL;
1158 const char *device = qdict_get_str(qdict, "device");
1159 const char *base = qdict_get_try_str(qdict, "base");
Stefan Hajnoczic83c66c2012-04-25 16:51:03 +01001160 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00001161
Stefan Hajnoczic83c66c2012-04-25 16:51:03 +01001162 qmp_block_stream(device, base != NULL, base,
Paolo Bonzini1d809092012-09-28 17:22:59 +02001163 qdict_haskey(qdict, "speed"), speed,
Anthony Liguori46663e52013-09-17 11:10:47 -05001164 true, BLOCKDEV_ON_ERROR_REPORT, &error);
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00001165
1166 hmp_handle_error(mon, &error);
1167}
Stefan Hajnoczi2d47c6e2012-01-18 14:40:47 +00001168
1169void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1170{
1171 Error *error = NULL;
1172 const char *device = qdict_get_str(qdict, "device");
Paolo Bonzinic6db2392012-05-08 16:51:56 +02001173 int64_t value = qdict_get_int(qdict, "speed");
Stefan Hajnoczi2d47c6e2012-01-18 14:40:47 +00001174
1175 qmp_block_job_set_speed(device, value, &error);
1176
1177 hmp_handle_error(mon, &error);
1178}
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00001179
1180void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1181{
1182 Error *error = NULL;
1183 const char *device = qdict_get_str(qdict, "device");
Paolo Bonzini6e37fb82012-09-28 17:22:51 +02001184 bool force = qdict_get_try_bool(qdict, "force", 0);
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00001185
Paolo Bonzini6e37fb82012-09-28 17:22:51 +02001186 qmp_block_job_cancel(device, true, force, &error);
1187
1188 hmp_handle_error(mon, &error);
1189}
1190
1191void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1192{
1193 Error *error = NULL;
1194 const char *device = qdict_get_str(qdict, "device");
1195
1196 qmp_block_job_pause(device, &error);
1197
1198 hmp_handle_error(mon, &error);
1199}
1200
1201void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1202{
1203 Error *error = NULL;
1204 const char *device = qdict_get_str(qdict, "device");
1205
1206 qmp_block_job_resume(device, &error);
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00001207
1208 hmp_handle_error(mon, &error);
1209}
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001210
Paolo Bonziniaeae8832012-10-18 16:49:21 +02001211void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1212{
1213 Error *error = NULL;
1214 const char *device = qdict_get_str(qdict, "device");
1215
1216 qmp_block_job_complete(device, &error);
1217
1218 hmp_handle_error(mon, &error);
1219}
1220
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001221typedef struct MigrationStatus
1222{
1223 QEMUTimer *timer;
1224 Monitor *mon;
1225 bool is_block_migration;
1226} MigrationStatus;
1227
1228static void hmp_migrate_status_cb(void *opaque)
1229{
1230 MigrationStatus *status = opaque;
1231 MigrationInfo *info;
1232
1233 info = qmp_query_migrate(NULL);
1234 if (!info->has_status || strcmp(info->status, "active") == 0) {
1235 if (info->has_disk) {
1236 int progress;
1237
1238 if (info->disk->remaining) {
1239 progress = info->disk->transferred * 100 / info->disk->total;
1240 } else {
1241 progress = 100;
1242 }
1243
1244 monitor_printf(status->mon, "Completed %d %%\r", progress);
1245 monitor_flush(status->mon);
1246 }
1247
Alex Blighbc72ad62013-08-21 16:03:08 +01001248 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001249 } else {
1250 if (status->is_block_migration) {
1251 monitor_printf(status->mon, "\n");
1252 }
1253 monitor_resume(status->mon);
Alex Blighbc72ad62013-08-21 16:03:08 +01001254 timer_del(status->timer);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001255 g_free(status);
1256 }
1257
1258 qapi_free_MigrationInfo(info);
1259}
1260
1261void hmp_migrate(Monitor *mon, const QDict *qdict)
1262{
1263 int detach = qdict_get_try_bool(qdict, "detach", 0);
1264 int blk = qdict_get_try_bool(qdict, "blk", 0);
1265 int inc = qdict_get_try_bool(qdict, "inc", 0);
1266 const char *uri = qdict_get_str(qdict, "uri");
1267 Error *err = NULL;
1268
1269 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1270 if (err) {
1271 monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
1272 error_free(err);
1273 return;
1274 }
1275
1276 if (!detach) {
1277 MigrationStatus *status;
1278
1279 if (monitor_suspend(mon) < 0) {
1280 monitor_printf(mon, "terminal does not allow synchronous "
1281 "migration, continuing detached\n");
1282 return;
1283 }
1284
1285 status = g_malloc0(sizeof(*status));
1286 status->mon = mon;
1287 status->is_block_migration = blk || inc;
Alex Blighbc72ad62013-08-21 16:03:08 +01001288 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001289 status);
Alex Blighbc72ad62013-08-21 16:03:08 +01001290 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001291 }
1292}
Luiz Capitulinoa15fef22012-03-29 12:38:50 -03001293
1294void hmp_device_del(Monitor *mon, const QDict *qdict)
1295{
1296 const char *id = qdict_get_str(qdict, "id");
1297 Error *err = NULL;
1298
1299 qmp_device_del(id, &err);
1300 hmp_handle_error(mon, &err);
1301}
Wen Congyang783e9b42012-05-07 12:10:47 +08001302
1303void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1304{
1305 Error *errp = NULL;
1306 int paging = qdict_get_try_bool(qdict, "paging", 0);
Luiz Capitulino75363762012-09-21 13:53:00 -03001307 const char *file = qdict_get_str(qdict, "filename");
Wen Congyang783e9b42012-05-07 12:10:47 +08001308 bool has_begin = qdict_haskey(qdict, "begin");
1309 bool has_length = qdict_haskey(qdict, "length");
1310 int64_t begin = 0;
1311 int64_t length = 0;
Luiz Capitulino75363762012-09-21 13:53:00 -03001312 char *prot;
Wen Congyang783e9b42012-05-07 12:10:47 +08001313
1314 if (has_begin) {
1315 begin = qdict_get_int(qdict, "begin");
1316 }
1317 if (has_length) {
1318 length = qdict_get_int(qdict, "length");
1319 }
1320
Luiz Capitulino75363762012-09-21 13:53:00 -03001321 prot = g_strconcat("file:", file, NULL);
1322
1323 qmp_dump_guest_memory(paging, prot, has_begin, begin, has_length, length,
Wen Congyang783e9b42012-05-07 12:10:47 +08001324 &errp);
1325 hmp_handle_error(mon, &errp);
Luiz Capitulino75363762012-09-21 13:53:00 -03001326 g_free(prot);
Wen Congyang783e9b42012-05-07 12:10:47 +08001327}
Luiz Capitulino928059a2012-04-18 17:34:15 -03001328
1329void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1330{
1331 Error *err = NULL;
1332 QemuOpts *opts;
1333
1334 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1335 if (error_is_set(&err)) {
1336 goto out;
1337 }
1338
1339 netdev_add(opts, &err);
1340 if (error_is_set(&err)) {
1341 qemu_opts_del(opts);
1342 }
1343
1344out:
1345 hmp_handle_error(mon, &err);
1346}
Luiz Capitulino5f964152012-04-16 14:36:32 -03001347
1348void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1349{
1350 const char *id = qdict_get_str(qdict, "id");
1351 Error *err = NULL;
1352
1353 qmp_netdev_del(id, &err);
1354 hmp_handle_error(mon, &err);
1355}
Corey Bryant208c9d12012-06-22 14:36:09 -04001356
1357void hmp_getfd(Monitor *mon, const QDict *qdict)
1358{
1359 const char *fdname = qdict_get_str(qdict, "fdname");
1360 Error *errp = NULL;
1361
1362 qmp_getfd(fdname, &errp);
1363 hmp_handle_error(mon, &errp);
1364}
1365
1366void hmp_closefd(Monitor *mon, const QDict *qdict)
1367{
1368 const char *fdname = qdict_get_str(qdict, "fdname");
1369 Error *errp = NULL;
1370
1371 qmp_closefd(fdname, &errp);
1372 hmp_handle_error(mon, &errp);
1373}
Amos Konge4c8f002012-08-31 10:56:26 +08001374
1375void hmp_send_key(Monitor *mon, const QDict *qdict)
1376{
1377 const char *keys = qdict_get_str(qdict, "keys");
Luiz Capitulino9f328972012-09-20 14:19:47 -03001378 KeyValueList *keylist, *head = NULL, *tmp = NULL;
Amos Konge4c8f002012-08-31 10:56:26 +08001379 int has_hold_time = qdict_haskey(qdict, "hold-time");
1380 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1381 Error *err = NULL;
1382 char keyname_buf[16];
1383 char *separator;
Luiz Capitulino9f328972012-09-20 14:19:47 -03001384 int keyname_len;
Amos Konge4c8f002012-08-31 10:56:26 +08001385
1386 while (1) {
1387 separator = strchr(keys, '-');
1388 keyname_len = separator ? separator - keys : strlen(keys);
1389 pstrcpy(keyname_buf, sizeof(keyname_buf), keys);
1390
1391 /* Be compatible with old interface, convert user inputted "<" */
1392 if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) {
1393 pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
1394 keyname_len = 4;
1395 }
1396 keyname_buf[keyname_len] = 0;
1397
Amos Konge4c8f002012-08-31 10:56:26 +08001398 keylist = g_malloc0(sizeof(*keylist));
Luiz Capitulino9f328972012-09-20 14:19:47 -03001399 keylist->value = g_malloc0(sizeof(*keylist->value));
Amos Konge4c8f002012-08-31 10:56:26 +08001400
1401 if (!head) {
1402 head = keylist;
1403 }
1404 if (tmp) {
1405 tmp->next = keylist;
1406 }
1407 tmp = keylist;
1408
Luiz Capitulino9f328972012-09-20 14:19:47 -03001409 if (strstart(keyname_buf, "0x", NULL)) {
1410 char *endp;
1411 int value = strtoul(keyname_buf, &endp, 0);
1412 if (*endp != '\0') {
1413 goto err_out;
1414 }
1415 keylist->value->kind = KEY_VALUE_KIND_NUMBER;
1416 keylist->value->number = value;
1417 } else {
1418 int idx = index_from_key(keyname_buf);
1419 if (idx == Q_KEY_CODE_MAX) {
1420 goto err_out;
1421 }
1422 keylist->value->kind = KEY_VALUE_KIND_QCODE;
1423 keylist->value->qcode = idx;
1424 }
1425
Amos Konge4c8f002012-08-31 10:56:26 +08001426 if (!separator) {
1427 break;
1428 }
1429 keys = separator + 1;
1430 }
1431
Luiz Capitulino9f328972012-09-20 14:19:47 -03001432 qmp_send_key(head, has_hold_time, hold_time, &err);
Amos Konge4c8f002012-08-31 10:56:26 +08001433 hmp_handle_error(mon, &err);
Luiz Capitulino9f328972012-09-20 14:19:47 -03001434
1435out:
1436 qapi_free_KeyValueList(head);
1437 return;
1438
1439err_out:
1440 monitor_printf(mon, "invalid parameter: %s\n", keyname_buf);
1441 goto out;
Amos Konge4c8f002012-08-31 10:56:26 +08001442}
Luiz Capitulinoad39cf62012-05-24 13:48:23 -03001443
1444void hmp_screen_dump(Monitor *mon, const QDict *qdict)
1445{
1446 const char *filename = qdict_get_str(qdict, "filename");
1447 Error *err = NULL;
1448
1449 qmp_screendump(filename, &err);
1450 hmp_handle_error(mon, &err);
1451}
Paolo Bonzini40577252012-08-23 11:53:04 +02001452
1453void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1454{
1455 const char *uri = qdict_get_str(qdict, "uri");
1456 int writable = qdict_get_try_bool(qdict, "writable", 0);
1457 int all = qdict_get_try_bool(qdict, "all", 0);
1458 Error *local_err = NULL;
1459 BlockInfoList *block_list, *info;
1460 SocketAddress *addr;
1461
1462 if (writable && !all) {
1463 error_setg(&local_err, "-w only valid together with -a");
1464 goto exit;
1465 }
1466
1467 /* First check if the address is valid and start the server. */
1468 addr = socket_parse(uri, &local_err);
1469 if (local_err != NULL) {
1470 goto exit;
1471 }
1472
1473 qmp_nbd_server_start(addr, &local_err);
1474 qapi_free_SocketAddress(addr);
1475 if (local_err != NULL) {
1476 goto exit;
1477 }
1478
1479 if (!all) {
1480 return;
1481 }
1482
1483 /* Then try adding all block devices. If one fails, close all and
1484 * exit.
1485 */
1486 block_list = qmp_query_block(NULL);
1487
1488 for (info = block_list; info; info = info->next) {
1489 if (!info->value->has_inserted) {
1490 continue;
1491 }
1492
1493 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1494
1495 if (local_err != NULL) {
1496 qmp_nbd_server_stop(NULL);
1497 break;
1498 }
1499 }
1500
1501 qapi_free_BlockInfoList(block_list);
1502
1503exit:
1504 hmp_handle_error(mon, &local_err);
1505}
1506
1507void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1508{
1509 const char *device = qdict_get_str(qdict, "device");
1510 int writable = qdict_get_try_bool(qdict, "writable", 0);
1511 Error *local_err = NULL;
1512
1513 qmp_nbd_server_add(device, true, writable, &local_err);
1514
1515 if (local_err != NULL) {
1516 hmp_handle_error(mon, &local_err);
1517 }
1518}
1519
1520void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1521{
1522 Error *errp = NULL;
1523
1524 qmp_nbd_server_stop(&errp);
1525 hmp_handle_error(mon, &errp);
1526}
Gerd Hoffmannf1088902012-12-19 10:33:40 +01001527
1528void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1529{
1530 const char *args = qdict_get_str(qdict, "args");
1531 Error *err = NULL;
1532 QemuOpts *opts;
1533
1534 opts = qemu_opts_parse(qemu_find_opts("chardev"), args, 1);
1535 if (opts == NULL) {
Markus Armbruster312fd5f2013-02-08 21:22:16 +01001536 error_setg(&err, "Parsing chardev args failed");
Gerd Hoffmannf1088902012-12-19 10:33:40 +01001537 } else {
1538 qemu_chr_new_from_opts(opts, NULL, &err);
1539 }
1540 hmp_handle_error(mon, &err);
1541}
1542
1543void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1544{
1545 Error *local_err = NULL;
1546
1547 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1548 hmp_handle_error(mon, &local_err);
1549}
Kevin Wolf587da2c2013-06-05 14:19:41 +02001550
1551void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1552{
1553 BlockDriverState *bs;
1554 const char* device = qdict_get_str(qdict, "device");
1555 const char* command = qdict_get_str(qdict, "command");
1556 Error *err = NULL;
1557
1558 bs = bdrv_find(device);
1559 if (bs) {
1560 qemuio_command(bs, command);
1561 } else {
1562 error_set(&err, QERR_DEVICE_NOT_FOUND, device);
1563 }
1564
1565 hmp_handle_error(mon, &err);
1566}