blob: 1e7cac02aca2e5c8804bdb11218502bb8054d3ce [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"
Scott Feldmanfafa4d52015-06-10 18:21:21 -070018#include "net/eth.h"
Paolo Bonzinidccfcd02013-04-08 16:55:25 +020019#include "sysemu/char.h"
Max Reitz4c7b7e92015-02-05 13:58:22 -050020#include "sysemu/block-backend.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010021#include "qemu/option.h"
22#include "qemu/timer.h"
Anthony Liguori48a32be2011-09-02 12:34:48 -050023#include "qmp-commands.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010024#include "qemu/sockets.h"
Paolo Bonzini83c90892012-12-17 18:19:49 +010025#include "monitor/monitor.h"
Markus Armbruster318660f2015-03-05 17:24:48 +010026#include "monitor/qdev.h"
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +010027#include "qapi/opts-visitor.h"
Hu Taoeb1539b2014-05-14 17:43:35 +080028#include "qapi/string-output-visitor.h"
29#include "qapi-visit.h"
Paolo Bonzini28ecbae2012-11-28 12:06:30 +010030#include "ui/console.h"
Wenchao Xiabd093a32013-06-06 12:28:00 +080031#include "block/qapi.h"
Kevin Wolf587da2c2013-06-05 14:19:41 +020032#include "qemu-io.h"
Anthony Liguori48a32be2011-09-02 12:34:48 -050033
Cole Robinson22fa7da2015-03-01 09:29:18 -050034#ifdef CONFIG_SPICE
35#include <spice/enums.h>
36#endif
37
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -020038static void hmp_handle_error(Monitor *mon, Error **errp)
39{
Markus Armbruster415168e2014-05-02 13:26:34 +020040 assert(errp);
41 if (*errp) {
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -020042 monitor_printf(mon, "%s\n", error_get_pretty(*errp));
43 error_free(*errp);
44 }
45}
46
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080047void hmp_info_name(Monitor *mon, const QDict *qdict)
Anthony Liguori48a32be2011-09-02 12:34:48 -050048{
49 NameInfo *info;
50
51 info = qmp_query_name(NULL);
52 if (info->has_name) {
53 monitor_printf(mon, "%s\n", info->name);
54 }
55 qapi_free_NameInfo(info);
56}
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030057
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080058void hmp_info_version(Monitor *mon, const QDict *qdict)
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030059{
60 VersionInfo *info;
61
62 info = qmp_query_version(NULL);
63
64 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
Eric Blake4752cdb2015-05-04 09:05:31 -060065 info->qemu->major, info->qemu->minor, info->qemu->micro,
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030066 info->package);
67
68 qapi_free_VersionInfo(info);
69}
Luiz Capitulino292a2602011-09-12 15:10:53 -030070
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080071void hmp_info_kvm(Monitor *mon, const QDict *qdict)
Luiz Capitulino292a2602011-09-12 15:10:53 -030072{
73 KvmInfo *info;
74
75 info = qmp_query_kvm(NULL);
76 monitor_printf(mon, "kvm support: ");
77 if (info->present) {
78 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
79 } else {
80 monitor_printf(mon, "not compiled\n");
81 }
82
83 qapi_free_KvmInfo(info);
84}
85
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080086void hmp_info_status(Monitor *mon, const QDict *qdict)
Luiz Capitulino1fa9a5e2011-09-12 17:54:20 -030087{
88 StatusInfo *info;
89
90 info = qmp_query_status(NULL);
91
92 monitor_printf(mon, "VM status: %s%s",
93 info->running ? "running" : "paused",
94 info->singlestep ? " (single step mode)" : "");
95
96 if (!info->running && info->status != RUN_STATE_PAUSED) {
97 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
98 }
99
100 monitor_printf(mon, "\n");
101
102 qapi_free_StatusInfo(info);
103}
104
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800105void hmp_info_uuid(Monitor *mon, const QDict *qdict)
Luiz Capitulinoefab7672011-09-13 17:16:25 -0300106{
107 UuidInfo *info;
108
109 info = qmp_query_uuid(NULL);
110 monitor_printf(mon, "%s\n", info->UUID);
111 qapi_free_UuidInfo(info);
112}
Luiz Capitulinoc5a415a2011-09-14 16:05:49 -0300113
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800114void hmp_info_chardev(Monitor *mon, const QDict *qdict)
Luiz Capitulinoc5a415a2011-09-14 16:05:49 -0300115{
116 ChardevInfoList *char_info, *info;
117
118 char_info = qmp_query_chardev(NULL);
119 for (info = char_info; info; info = info->next) {
120 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
121 info->value->filename);
122 }
123
124 qapi_free_ChardevInfoList(char_info);
125}
Luiz Capitulino7a7f3252011-09-15 14:20:28 -0300126
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800127void hmp_info_mice(Monitor *mon, const QDict *qdict)
Luiz Capitulinoe235cec2011-09-21 15:29:55 -0300128{
129 MouseInfoList *mice_list, *mouse;
130
131 mice_list = qmp_query_mice(NULL);
132 if (!mice_list) {
133 monitor_printf(mon, "No mouse devices connected\n");
134 return;
135 }
136
137 for (mouse = mice_list; mouse; mouse = mouse->next) {
138 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
139 mouse->value->current ? '*' : ' ',
140 mouse->value->index, mouse->value->name,
141 mouse->value->absolute ? " (absolute)" : "");
142 }
143
144 qapi_free_MouseInfoList(mice_list);
145}
146
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800147void hmp_info_migrate(Monitor *mon, const QDict *qdict)
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300148{
149 MigrationInfo *info;
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300150 MigrationCapabilityStatusList *caps, *cap;
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300151
152 info = qmp_query_migrate(NULL);
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300153 caps = qmp_query_migrate_capabilities(NULL);
154
155 /* do not display parameters during setup */
156 if (info->has_status && caps) {
157 monitor_printf(mon, "capabilities: ");
158 for (cap = caps; cap; cap = cap->next) {
159 monitor_printf(mon, "%s: %s ",
160 MigrationCapability_lookup[cap->value->capability],
161 cap->value->state ? "on" : "off");
162 }
163 monitor_printf(mon, "\n");
164 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300165
166 if (info->has_status) {
zhanghailiang24b8c392015-03-13 16:08:40 +0800167 monitor_printf(mon, "Migration status: %s\n",
168 MigrationStatus_lookup[info->status]);
Juan Quintela7aa939a2012-08-18 13:17:10 +0200169 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
170 info->total_time);
Juan Quintela2c52ddf2012-08-13 09:53:12 +0200171 if (info->has_expected_downtime) {
172 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
173 info->expected_downtime);
174 }
Juan Quintela9c5a9fc2012-08-13 09:35:16 +0200175 if (info->has_downtime) {
176 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
177 info->downtime);
178 }
Michael R. Hinesed4fbd12013-07-22 10:01:58 -0400179 if (info->has_setup_time) {
180 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
181 info->setup_time);
182 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300183 }
184
185 if (info->has_ram) {
186 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
187 info->ram->transferred >> 10);
Michael R. Hines7e114f82013-06-25 21:35:30 -0400188 monitor_printf(mon, "throughput: %0.2f mbps\n",
189 info->ram->mbps);
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300190 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
191 info->ram->remaining >> 10);
192 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
193 info->ram->total >> 10);
Orit Wasserman004d4c12012-08-06 21:42:56 +0300194 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
195 info->ram->duplicate);
Peter Lievenf1c72792013-03-26 10:58:37 +0100196 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
197 info->ram->skipped);
Orit Wasserman004d4c12012-08-06 21:42:56 +0300198 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
199 info->ram->normal);
200 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
201 info->ram->normal_bytes >> 10);
ChenLiang58570ed2014-04-04 17:57:55 +0800202 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
203 info->ram->dirty_sync_count);
Juan Quintela8d017192012-08-13 12:31:25 +0200204 if (info->ram->dirty_pages_rate) {
205 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
206 info->ram->dirty_pages_rate);
207 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300208 }
209
210 if (info->has_disk) {
211 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
212 info->disk->transferred >> 10);
213 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
214 info->disk->remaining >> 10);
215 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
216 info->disk->total >> 10);
217 }
218
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300219 if (info->has_xbzrle_cache) {
220 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
221 info->xbzrle_cache->cache_size);
222 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
223 info->xbzrle_cache->bytes >> 10);
224 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
225 info->xbzrle_cache->pages);
226 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
227 info->xbzrle_cache->cache_miss);
ChenLiang8bc39232014-04-04 17:57:56 +0800228 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
229 info->xbzrle_cache->cache_miss_rate);
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300230 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
231 info->xbzrle_cache->overflow);
232 }
233
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300234 qapi_free_MigrationInfo(info);
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300235 qapi_free_MigrationCapabilityStatusList(caps);
236}
237
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800238void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300239{
240 MigrationCapabilityStatusList *caps, *cap;
241
242 caps = qmp_query_migrate_capabilities(NULL);
243
244 if (caps) {
245 monitor_printf(mon, "capabilities: ");
246 for (cap = caps; cap; cap = cap->next) {
247 monitor_printf(mon, "%s: %s ",
248 MigrationCapability_lookup[cap->value->capability],
249 cap->value->state ? "on" : "off");
250 }
251 monitor_printf(mon, "\n");
252 }
253
254 qapi_free_MigrationCapabilityStatusList(caps);
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300255}
256
Liang Li50e9a622015-03-23 16:32:29 +0800257void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
258{
259 MigrationParameters *params;
260
261 params = qmp_query_migrate_parameters(NULL);
262
263 if (params) {
264 monitor_printf(mon, "parameters:");
265 monitor_printf(mon, " %s: %" PRId64,
266 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_LEVEL],
267 params->compress_level);
268 monitor_printf(mon, " %s: %" PRId64,
269 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_THREADS],
270 params->compress_threads);
271 monitor_printf(mon, " %s: %" PRId64,
272 MigrationParameter_lookup[MIGRATION_PARAMETER_DECOMPRESS_THREADS],
273 params->decompress_threads);
274 monitor_printf(mon, "\n");
275 }
276
277 qapi_free_MigrationParameters(params);
278}
279
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800280void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +0300281{
282 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
283 qmp_query_migrate_cache_size(NULL) >> 10);
284}
285
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800286void hmp_info_cpus(Monitor *mon, const QDict *qdict)
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300287{
288 CpuInfoList *cpu_list, *cpu;
289
290 cpu_list = qmp_query_cpus(NULL);
291
292 for (cpu = cpu_list; cpu; cpu = cpu->next) {
293 int active = ' ';
294
295 if (cpu->value->CPU == monitor_get_cpu_index()) {
296 active = '*';
297 }
298
Aurelien Jarno852bef02012-10-19 23:19:19 +0200299 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300300
301 if (cpu->value->has_pc) {
Aurelien Jarno852bef02012-10-19 23:19:19 +0200302 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->pc);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300303 }
304 if (cpu->value->has_nip) {
Aurelien Jarno852bef02012-10-19 23:19:19 +0200305 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->nip);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300306 }
307 if (cpu->value->has_npc) {
Aurelien Jarno852bef02012-10-19 23:19:19 +0200308 monitor_printf(mon, " npc=0x%016" PRIx64, cpu->value->npc);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300309 }
310 if (cpu->value->has_PC) {
Aurelien Jarno852bef02012-10-19 23:19:19 +0200311 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->PC);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300312 }
313
314 if (cpu->value->halted) {
315 monitor_printf(mon, " (halted)");
316 }
317
318 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
319 }
320
321 qapi_free_CpuInfoList(cpu_list);
322}
323
Kevin Wolf289b2762014-09-15 12:06:39 +0200324static void print_block_info(Monitor *mon, BlockInfo *info,
325 BlockDeviceInfo *inserted, bool verbose)
326{
327 ImageInfo *image_info;
328
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200329 assert(!info || !info->has_inserted || info->inserted == inserted);
330
331 if (info) {
332 monitor_printf(mon, "%s", info->device);
333 if (inserted && inserted->has_node_name) {
334 monitor_printf(mon, " (%s)", inserted->node_name);
335 }
336 } else {
337 assert(inserted);
338 monitor_printf(mon, "%s",
339 inserted->has_node_name
340 ? inserted->node_name
341 : "<anonymous>");
342 }
343
Kevin Wolf289b2762014-09-15 12:06:39 +0200344 if (inserted) {
345 monitor_printf(mon, ": %s (%s%s%s)\n",
346 inserted->file,
347 inserted->drv,
348 inserted->ro ? ", read-only" : "",
349 inserted->encrypted ? ", encrypted" : "");
350 } else {
351 monitor_printf(mon, ": [not inserted]\n");
352 }
353
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200354 if (info) {
355 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
356 monitor_printf(mon, " I/O status: %s\n",
357 BlockDeviceIoStatus_lookup[info->io_status]);
358 }
Kevin Wolf289b2762014-09-15 12:06:39 +0200359
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200360 if (info->removable) {
361 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
362 info->locked ? "" : "not ",
363 info->tray_open ? "open" : "closed");
364 }
Kevin Wolf289b2762014-09-15 12:06:39 +0200365 }
366
367
368 if (!inserted) {
369 return;
370 }
371
372 monitor_printf(mon, " Cache mode: %s%s%s\n",
373 inserted->cache->writeback ? "writeback" : "writethrough",
374 inserted->cache->direct ? ", direct" : "",
375 inserted->cache->no_flush ? ", ignore flushes" : "");
376
377 if (inserted->has_backing_file) {
378 monitor_printf(mon,
379 " Backing file: %s "
380 "(chain depth: %" PRId64 ")\n",
381 inserted->backing_file,
382 inserted->backing_file_depth);
383 }
384
385 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
386 monitor_printf(mon, " Detect zeroes: %s\n",
387 BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]);
388 }
389
390 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
391 inserted->iops || inserted->iops_rd || inserted->iops_wr)
392 {
393 monitor_printf(mon, " I/O throttling: bps=%" PRId64
394 " bps_rd=%" PRId64 " bps_wr=%" PRId64
395 " bps_max=%" PRId64
396 " bps_rd_max=%" PRId64
397 " bps_wr_max=%" PRId64
398 " iops=%" PRId64 " iops_rd=%" PRId64
399 " iops_wr=%" PRId64
400 " iops_max=%" PRId64
401 " iops_rd_max=%" PRId64
402 " iops_wr_max=%" PRId64
403 " iops_size=%" PRId64 "\n",
404 inserted->bps,
405 inserted->bps_rd,
406 inserted->bps_wr,
407 inserted->bps_max,
408 inserted->bps_rd_max,
409 inserted->bps_wr_max,
410 inserted->iops,
411 inserted->iops_rd,
412 inserted->iops_wr,
413 inserted->iops_max,
414 inserted->iops_rd_max,
415 inserted->iops_wr_max,
416 inserted->iops_size);
417 }
418
Stefan Hajnoczi94198742015-04-22 11:15:10 +0100419 if (verbose) {
Kevin Wolf289b2762014-09-15 12:06:39 +0200420 monitor_printf(mon, "\nImages:\n");
421 image_info = inserted->image;
422 while (1) {
423 bdrv_image_info_dump((fprintf_function)monitor_printf,
424 mon, image_info);
425 if (image_info->has_backing_image) {
426 image_info = image_info->backing_image;
427 } else {
428 break;
429 }
430 }
431 }
432}
433
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800434void hmp_info_block(Monitor *mon, const QDict *qdict)
Luiz Capitulinob2023812011-09-21 17:16:47 -0300435{
436 BlockInfoList *block_list, *info;
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200437 BlockDeviceInfoList *blockdev_list, *blockdev;
Wenchao Xiae73fe2b2013-06-06 12:28:01 +0800438 const char *device = qdict_get_try_str(qdict, "device");
439 bool verbose = qdict_get_try_bool(qdict, "verbose", 0);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200440 bool nodes = qdict_get_try_bool(qdict, "nodes", 0);
441 bool printed = false;
Luiz Capitulinob2023812011-09-21 17:16:47 -0300442
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200443 /* Print BlockBackend information */
444 if (!nodes) {
Stefan Weilf19e44b2015-02-08 15:40:48 +0100445 block_list = qmp_query_block(NULL);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200446 } else {
447 block_list = NULL;
448 }
Luiz Capitulinob2023812011-09-21 17:16:47 -0300449
450 for (info = block_list; info; info = info->next) {
Wenchao Xiae73fe2b2013-06-06 12:28:01 +0800451 if (device && strcmp(device, info->value->device)) {
452 continue;
453 }
Luiz Capitulinob2023812011-09-21 17:16:47 -0300454
Kevin Wolffbe2e262013-06-19 16:10:55 +0200455 if (info != block_list) {
456 monitor_printf(mon, "\n");
Luiz Capitulinob2023812011-09-21 17:16:47 -0300457 }
458
Kevin Wolf289b2762014-09-15 12:06:39 +0200459 print_block_info(mon, info->value, info->value->has_inserted
460 ? info->value->inserted : NULL,
461 verbose);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200462 printed = true;
Luiz Capitulinob2023812011-09-21 17:16:47 -0300463 }
464
465 qapi_free_BlockInfoList(block_list);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200466
467 if ((!device && !nodes) || printed) {
468 return;
469 }
470
471 /* Print node information */
472 blockdev_list = qmp_query_named_block_nodes(NULL);
473 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
474 assert(blockdev->value->has_node_name);
475 if (device && strcmp(device, blockdev->value->node_name)) {
476 continue;
477 }
478
479 if (blockdev != blockdev_list) {
480 monitor_printf(mon, "\n");
481 }
482
483 print_block_info(mon, NULL, blockdev->value, verbose);
484 }
485 qapi_free_BlockDeviceInfoList(blockdev_list);
Luiz Capitulinob2023812011-09-21 17:16:47 -0300486}
487
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800488void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300489{
490 BlockStatsList *stats_list, *stats;
491
Fam Zhengf71eaa72014-10-31 11:32:57 +0800492 stats_list = qmp_query_blockstats(false, false, NULL);
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300493
494 for (stats = stats_list; stats; stats = stats->next) {
495 if (!stats->value->has_device) {
496 continue;
497 }
498
499 monitor_printf(mon, "%s:", stats->value->device);
500 monitor_printf(mon, " rd_bytes=%" PRId64
501 " wr_bytes=%" PRId64
502 " rd_operations=%" PRId64
503 " wr_operations=%" PRId64
504 " flush_operations=%" PRId64
505 " wr_total_time_ns=%" PRId64
506 " rd_total_time_ns=%" PRId64
507 " flush_total_time_ns=%" PRId64
Peter Lievenf4564d52015-02-02 14:52:18 +0100508 " rd_merged=%" PRId64
509 " wr_merged=%" PRId64
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300510 "\n",
511 stats->value->stats->rd_bytes,
512 stats->value->stats->wr_bytes,
513 stats->value->stats->rd_operations,
514 stats->value->stats->wr_operations,
515 stats->value->stats->flush_operations,
516 stats->value->stats->wr_total_time_ns,
517 stats->value->stats->rd_total_time_ns,
Peter Lievenf4564d52015-02-02 14:52:18 +0100518 stats->value->stats->flush_total_time_ns,
519 stats->value->stats->rd_merged,
520 stats->value->stats->wr_merged);
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300521 }
522
523 qapi_free_BlockStatsList(stats_list);
524}
525
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800526void hmp_info_vnc(Monitor *mon, const QDict *qdict)
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200527{
528 VncInfo *info;
529 Error *err = NULL;
530 VncClientInfoList *client;
531
532 info = qmp_query_vnc(&err);
533 if (err) {
534 monitor_printf(mon, "%s\n", error_get_pretty(err));
535 error_free(err);
536 return;
537 }
538
539 if (!info->enabled) {
540 monitor_printf(mon, "Server: disabled\n");
541 goto out;
542 }
543
544 monitor_printf(mon, "Server:\n");
545 if (info->has_host && info->has_service) {
546 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
547 }
548 if (info->has_auth) {
549 monitor_printf(mon, " auth: %s\n", info->auth);
550 }
551
552 if (!info->has_clients || info->clients == NULL) {
553 monitor_printf(mon, "Client: none\n");
554 } else {
555 for (client = info->clients; client; client = client->next) {
556 monitor_printf(mon, "Client:\n");
557 monitor_printf(mon, " address: %s:%s\n",
Wenchao Xiaa5895692014-06-18 08:43:30 +0200558 client->value->base->host,
559 client->value->base->service);
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200560 monitor_printf(mon, " x509_dname: %s\n",
561 client->value->x509_dname ?
562 client->value->x509_dname : "none");
563 monitor_printf(mon, " username: %s\n",
564 client->value->has_sasl_username ?
565 client->value->sasl_username : "none");
566 }
567 }
568
569out:
570 qapi_free_VncInfo(info);
571}
572
Markus Armbruster206addd2015-01-13 15:46:39 +0100573#ifdef CONFIG_SPICE
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800574void hmp_info_spice(Monitor *mon, const QDict *qdict)
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200575{
576 SpiceChannelList *chan;
577 SpiceInfo *info;
Cole Robinson22fa7da2015-03-01 09:29:18 -0500578 const char *channel_name;
579 const char * const channel_names[] = {
580 [SPICE_CHANNEL_MAIN] = "main",
581 [SPICE_CHANNEL_DISPLAY] = "display",
582 [SPICE_CHANNEL_INPUTS] = "inputs",
583 [SPICE_CHANNEL_CURSOR] = "cursor",
584 [SPICE_CHANNEL_PLAYBACK] = "playback",
585 [SPICE_CHANNEL_RECORD] = "record",
586 [SPICE_CHANNEL_TUNNEL] = "tunnel",
587 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
588 [SPICE_CHANNEL_USBREDIR] = "usbredir",
589 [SPICE_CHANNEL_PORT] = "port",
Gerd Hoffmann7c6044a2015-03-03 09:27:28 +0100590#if 0
591 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
592 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
593 * as quick fix for build failures with older versions. */
Cole Robinson22fa7da2015-03-01 09:29:18 -0500594 [SPICE_CHANNEL_WEBDAV] = "webdav",
Gerd Hoffmann7c6044a2015-03-03 09:27:28 +0100595#endif
Cole Robinson22fa7da2015-03-01 09:29:18 -0500596 };
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200597
598 info = qmp_query_spice(NULL);
599
600 if (!info->enabled) {
601 monitor_printf(mon, "Server: disabled\n");
602 goto out;
603 }
604
605 monitor_printf(mon, "Server:\n");
606 if (info->has_port) {
607 monitor_printf(mon, " address: %s:%" PRId64 "\n",
608 info->host, info->port);
609 }
610 if (info->has_tls_port) {
611 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
612 info->host, info->tls_port);
613 }
Yonit Halperin61c4efe2012-08-21 11:51:58 +0300614 monitor_printf(mon, " migrated: %s\n",
615 info->migrated ? "true" : "false");
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200616 monitor_printf(mon, " auth: %s\n", info->auth);
617 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
Alon Levy4efee022012-03-29 23:23:14 +0200618 monitor_printf(mon, " mouse-mode: %s\n",
619 SpiceQueryMouseMode_lookup[info->mouse_mode]);
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200620
621 if (!info->has_channels || info->channels == NULL) {
622 monitor_printf(mon, "Channels: none\n");
623 } else {
624 for (chan = info->channels; chan; chan = chan->next) {
625 monitor_printf(mon, "Channel:\n");
626 monitor_printf(mon, " address: %s:%s%s\n",
Wenchao Xiaa5895692014-06-18 08:43:30 +0200627 chan->value->base->host, chan->value->base->port,
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200628 chan->value->tls ? " [tls]" : "");
629 monitor_printf(mon, " session: %" PRId64 "\n",
630 chan->value->connection_id);
631 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
632 chan->value->channel_type, chan->value->channel_id);
Cole Robinson22fa7da2015-03-01 09:29:18 -0500633
634 channel_name = "unknown";
635 if (chan->value->channel_type > 0 &&
636 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
637 channel_names[chan->value->channel_type]) {
638 channel_name = channel_names[chan->value->channel_type];
639 }
640
641 monitor_printf(mon, " channel name: %s\n", channel_name);
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200642 }
643 }
644
645out:
646 qapi_free_SpiceInfo(info);
647}
Markus Armbruster206addd2015-01-13 15:46:39 +0100648#endif
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200649
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800650void hmp_info_balloon(Monitor *mon, const QDict *qdict)
Luiz Capitulino96637bc2011-10-21 11:41:37 -0200651{
652 BalloonInfo *info;
653 Error *err = NULL;
654
655 info = qmp_query_balloon(&err);
656 if (err) {
657 monitor_printf(mon, "%s\n", error_get_pretty(err));
658 error_free(err);
659 return;
660 }
661
Luiz Capitulino01ceb972012-12-03 15:56:41 -0200662 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
Luiz Capitulino96637bc2011-10-21 11:41:37 -0200663
664 qapi_free_BalloonInfo(info);
665}
666
Luiz Capitulino79627472011-10-21 14:15:33 -0200667static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
668{
669 PciMemoryRegionList *region;
670
671 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
672 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
673 dev->slot, dev->function);
674 monitor_printf(mon, " ");
675
Eric Blake9fa02cd2015-05-04 09:05:32 -0600676 if (dev->class_info->has_desc) {
677 monitor_printf(mon, "%s", dev->class_info->desc);
Luiz Capitulino79627472011-10-21 14:15:33 -0200678 } else {
Eric Blake9fa02cd2015-05-04 09:05:32 -0600679 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
Luiz Capitulino79627472011-10-21 14:15:33 -0200680 }
681
682 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600683 dev->id->vendor, dev->id->device);
Luiz Capitulino79627472011-10-21 14:15:33 -0200684
685 if (dev->has_irq) {
686 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
687 }
688
689 if (dev->has_pci_bridge) {
690 monitor_printf(mon, " BUS %" PRId64 ".\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600691 dev->pci_bridge->bus->number);
Luiz Capitulino79627472011-10-21 14:15:33 -0200692 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600693 dev->pci_bridge->bus->secondary);
Luiz Capitulino79627472011-10-21 14:15:33 -0200694 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600695 dev->pci_bridge->bus->subordinate);
Luiz Capitulino79627472011-10-21 14:15:33 -0200696
697 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600698 dev->pci_bridge->bus->io_range->base,
699 dev->pci_bridge->bus->io_range->limit);
Luiz Capitulino79627472011-10-21 14:15:33 -0200700
701 monitor_printf(mon,
702 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600703 dev->pci_bridge->bus->memory_range->base,
704 dev->pci_bridge->bus->memory_range->limit);
Luiz Capitulino79627472011-10-21 14:15:33 -0200705
706 monitor_printf(mon, " prefetchable memory range "
707 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600708 dev->pci_bridge->bus->prefetchable_range->base,
709 dev->pci_bridge->bus->prefetchable_range->limit);
Luiz Capitulino79627472011-10-21 14:15:33 -0200710 }
711
712 for (region = dev->regions; region; region = region->next) {
713 uint64_t addr, size;
714
715 addr = region->value->address;
716 size = region->value->size;
717
718 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
719
720 if (!strcmp(region->value->type, "io")) {
721 monitor_printf(mon, "I/O at 0x%04" PRIx64
722 " [0x%04" PRIx64 "].\n",
723 addr, addr + size - 1);
724 } else {
725 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
726 " [0x%08" PRIx64 "].\n",
727 region->value->mem_type_64 ? 64 : 32,
728 region->value->prefetch ? " prefetchable" : "",
729 addr, addr + size - 1);
730 }
731 }
732
733 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
734
735 if (dev->has_pci_bridge) {
736 if (dev->pci_bridge->has_devices) {
737 PciDeviceInfoList *cdev;
738 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
739 hmp_info_pci_device(mon, cdev->value);
740 }
741 }
742 }
743}
744
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800745void hmp_info_pci(Monitor *mon, const QDict *qdict)
Luiz Capitulino79627472011-10-21 14:15:33 -0200746{
Stefan Bergerf46cee32012-01-11 10:51:52 -0500747 PciInfoList *info_list, *info;
Luiz Capitulino79627472011-10-21 14:15:33 -0200748 Error *err = NULL;
749
Stefan Bergerf46cee32012-01-11 10:51:52 -0500750 info_list = qmp_query_pci(&err);
Luiz Capitulino79627472011-10-21 14:15:33 -0200751 if (err) {
752 monitor_printf(mon, "PCI devices not supported\n");
753 error_free(err);
754 return;
755 }
756
Stefan Bergerf46cee32012-01-11 10:51:52 -0500757 for (info = info_list; info; info = info->next) {
Luiz Capitulino79627472011-10-21 14:15:33 -0200758 PciDeviceInfoList *dev;
759
760 for (dev = info->value->devices; dev; dev = dev->next) {
761 hmp_info_pci_device(mon, dev->value);
762 }
763 }
764
Stefan Bergerf46cee32012-01-11 10:51:52 -0500765 qapi_free_PciInfoList(info_list);
Luiz Capitulino79627472011-10-21 14:15:33 -0200766}
767
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800768void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
Stefan Hajnoczifb5458c2012-01-18 14:40:49 +0000769{
770 BlockJobInfoList *list;
771 Error *err = NULL;
772
773 list = qmp_query_block_jobs(&err);
774 assert(!err);
775
776 if (!list) {
777 monitor_printf(mon, "No active jobs\n");
778 return;
779 }
780
781 while (list) {
782 if (strcmp(list->value->type, "stream") == 0) {
783 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
784 " of %" PRId64 " bytes, speed limit %" PRId64
785 " bytes/s\n",
786 list->value->device,
787 list->value->offset,
788 list->value->len,
789 list->value->speed);
790 } else {
791 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
792 " of %" PRId64 " bytes, speed limit %" PRId64
793 " bytes/s\n",
794 list->value->type,
795 list->value->device,
796 list->value->offset,
797 list->value->len,
798 list->value->speed);
799 }
800 list = list->next;
801 }
Gonglei93bb1312014-09-16 21:36:55 +0800802
803 qapi_free_BlockJobInfoList(list);
Stefan Hajnoczifb5458c2012-01-18 14:40:49 +0000804}
805
Stefan Bergerd1a0cf72013-02-27 12:47:49 -0500806void hmp_info_tpm(Monitor *mon, const QDict *qdict)
807{
808 TPMInfoList *info_list, *info;
809 Error *err = NULL;
810 unsigned int c = 0;
811 TPMPassthroughOptions *tpo;
812
813 info_list = qmp_query_tpm(&err);
814 if (err) {
815 monitor_printf(mon, "TPM device not supported\n");
816 error_free(err);
817 return;
818 }
819
820 if (info_list) {
821 monitor_printf(mon, "TPM device:\n");
822 }
823
824 for (info = info_list; info; info = info->next) {
825 TPMInfo *ti = info->value;
826 monitor_printf(mon, " tpm%d: model=%s\n",
827 c, TpmModel_lookup[ti->model]);
828
829 monitor_printf(mon, " \\ %s: type=%s",
Corey Bryant88ca7bc2013-03-20 12:34:48 -0400830 ti->id, TpmTypeOptionsKind_lookup[ti->options->kind]);
Stefan Bergerd1a0cf72013-02-27 12:47:49 -0500831
Corey Bryant88ca7bc2013-03-20 12:34:48 -0400832 switch (ti->options->kind) {
833 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
834 tpo = ti->options->passthrough;
Stefan Bergerd1a0cf72013-02-27 12:47:49 -0500835 monitor_printf(mon, "%s%s%s%s",
836 tpo->has_path ? ",path=" : "",
837 tpo->has_path ? tpo->path : "",
838 tpo->has_cancel_path ? ",cancel-path=" : "",
839 tpo->has_cancel_path ? tpo->cancel_path : "");
840 break;
841 case TPM_TYPE_OPTIONS_KIND_MAX:
842 break;
843 }
844 monitor_printf(mon, "\n");
845 c++;
846 }
847 qapi_free_TPMInfoList(info_list);
848}
849
Luiz Capitulino7a7f3252011-09-15 14:20:28 -0300850void hmp_quit(Monitor *mon, const QDict *qdict)
851{
852 monitor_suspend(mon);
853 qmp_quit(NULL);
854}
Luiz Capitulino5f158f22011-09-15 14:34:39 -0300855
856void hmp_stop(Monitor *mon, const QDict *qdict)
857{
858 qmp_stop(NULL);
859}
Luiz Capitulino38d22652011-09-15 14:41:46 -0300860
861void hmp_system_reset(Monitor *mon, const QDict *qdict)
862{
863 qmp_system_reset(NULL);
864}
Luiz Capitulino5bc465e2011-09-28 11:06:15 -0300865
866void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
867{
868 qmp_system_powerdown(NULL);
869}
Luiz Capitulino755f1962011-10-06 14:31:39 -0300870
871void hmp_cpu(Monitor *mon, const QDict *qdict)
872{
873 int64_t cpu_index;
874
875 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
876 use it are converted to the QAPI */
877 cpu_index = qdict_get_int(qdict, "index");
878 if (monitor_set_cpu(cpu_index) < 0) {
879 monitor_printf(mon, "invalid CPU index\n");
880 }
881}
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -0200882
883void hmp_memsave(Monitor *mon, const QDict *qdict)
884{
885 uint32_t size = qdict_get_int(qdict, "size");
886 const char *filename = qdict_get_str(qdict, "filename");
887 uint64_t addr = qdict_get_int(qdict, "val");
Markus Armbrustere940f542014-05-02 13:26:29 +0200888 Error *err = NULL;
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -0200889
Markus Armbrustere940f542014-05-02 13:26:29 +0200890 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &err);
891 hmp_handle_error(mon, &err);
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -0200892}
Luiz Capitulino6d3962b2011-11-22 17:26:46 -0200893
894void hmp_pmemsave(Monitor *mon, const QDict *qdict)
895{
896 uint32_t size = qdict_get_int(qdict, "size");
897 const char *filename = qdict_get_str(qdict, "filename");
898 uint64_t addr = qdict_get_int(qdict, "val");
Markus Armbrustere940f542014-05-02 13:26:29 +0200899 Error *err = NULL;
Luiz Capitulino6d3962b2011-11-22 17:26:46 -0200900
Markus Armbrustere940f542014-05-02 13:26:29 +0200901 qmp_pmemsave(addr, size, filename, &err);
902 hmp_handle_error(mon, &err);
Luiz Capitulino6d3962b2011-11-22 17:26:46 -0200903}
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200904
Markus Armbruster3949e592013-02-06 21:27:24 +0100905void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
Lei Li1f590cf2013-01-25 00:03:20 +0800906{
Lei Li1f590cf2013-01-25 00:03:20 +0800907 const char *chardev = qdict_get_str(qdict, "device");
908 const char *data = qdict_get_str(qdict, "data");
Markus Armbrustere940f542014-05-02 13:26:29 +0200909 Error *err = NULL;
Lei Li1f590cf2013-01-25 00:03:20 +0800910
Markus Armbrustere940f542014-05-02 13:26:29 +0200911 qmp_ringbuf_write(chardev, data, false, 0, &err);
Lei Li1f590cf2013-01-25 00:03:20 +0800912
Markus Armbrustere940f542014-05-02 13:26:29 +0200913 hmp_handle_error(mon, &err);
Lei Li1f590cf2013-01-25 00:03:20 +0800914}
915
Markus Armbruster3949e592013-02-06 21:27:24 +0100916void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
Lei Li49b6d722013-01-25 00:03:21 +0800917{
918 uint32_t size = qdict_get_int(qdict, "size");
919 const char *chardev = qdict_get_str(qdict, "device");
Markus Armbruster3ab651f2013-02-06 21:27:15 +0100920 char *data;
Markus Armbrustere940f542014-05-02 13:26:29 +0200921 Error *err = NULL;
Markus Armbruster543f3412013-02-06 21:27:26 +0100922 int i;
Lei Li49b6d722013-01-25 00:03:21 +0800923
Markus Armbrustere940f542014-05-02 13:26:29 +0200924 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
925 if (err) {
926 monitor_printf(mon, "%s\n", error_get_pretty(err));
927 error_free(err);
Lei Li49b6d722013-01-25 00:03:21 +0800928 return;
929 }
930
Markus Armbruster543f3412013-02-06 21:27:26 +0100931 for (i = 0; data[i]; i++) {
932 unsigned char ch = data[i];
933
934 if (ch == '\\') {
935 monitor_printf(mon, "\\\\");
936 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
937 monitor_printf(mon, "\\u%04X", ch);
938 } else {
939 monitor_printf(mon, "%c", ch);
940 }
941
942 }
943 monitor_printf(mon, "\n");
Markus Armbruster3ab651f2013-02-06 21:27:15 +0100944 g_free(data);
Lei Li49b6d722013-01-25 00:03:21 +0800945}
946
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200947static void hmp_cont_cb(void *opaque, int err)
948{
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200949 if (!err) {
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300950 qmp_cont(NULL);
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200951 }
952}
953
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300954static bool key_is_missing(const BlockInfo *bdev)
955{
956 return (bdev->inserted && bdev->inserted->encryption_key_missing);
957}
958
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200959void hmp_cont(Monitor *mon, const QDict *qdict)
960{
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300961 BlockInfoList *bdev_list, *bdev;
Markus Armbrustere940f542014-05-02 13:26:29 +0200962 Error *err = NULL;
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200963
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300964 bdev_list = qmp_query_block(NULL);
965 for (bdev = bdev_list; bdev; bdev = bdev->next) {
966 if (key_is_missing(bdev->value)) {
967 monitor_read_block_device_key(mon, bdev->value->device,
968 hmp_cont_cb, NULL);
969 goto out;
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200970 }
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200971 }
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300972
Markus Armbrustere940f542014-05-02 13:26:29 +0200973 qmp_cont(&err);
974 hmp_handle_error(mon, &err);
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300975
976out:
977 qapi_free_BlockInfoList(bdev_list);
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200978}
Luiz Capitulinoab49ab52011-11-23 12:55:53 -0200979
Gerd Hoffmann9b9df252012-02-23 13:45:21 +0100980void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
981{
982 qmp_system_wakeup(NULL);
983}
984
Markus Armbruster3e5a50d2015-02-06 13:55:43 +0100985void hmp_nmi(Monitor *mon, const QDict *qdict)
Luiz Capitulinoab49ab52011-11-23 12:55:53 -0200986{
Markus Armbrustere940f542014-05-02 13:26:29 +0200987 Error *err = NULL;
Luiz Capitulinoab49ab52011-11-23 12:55:53 -0200988
Markus Armbrustere940f542014-05-02 13:26:29 +0200989 qmp_inject_nmi(&err);
990 hmp_handle_error(mon, &err);
Luiz Capitulinoab49ab52011-11-23 12:55:53 -0200991}
Luiz Capitulino4b371562011-11-23 13:11:55 -0200992
993void hmp_set_link(Monitor *mon, const QDict *qdict)
994{
995 const char *name = qdict_get_str(qdict, "name");
996 int up = qdict_get_bool(qdict, "up");
Markus Armbrustere940f542014-05-02 13:26:29 +0200997 Error *err = NULL;
Luiz Capitulino4b371562011-11-23 13:11:55 -0200998
Markus Armbrustere940f542014-05-02 13:26:29 +0200999 qmp_set_link(name, up, &err);
1000 hmp_handle_error(mon, &err);
Luiz Capitulino4b371562011-11-23 13:11:55 -02001001}
Luiz Capitulinoa4dea8a2011-11-23 13:28:21 -02001002
1003void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1004{
1005 const char *device = qdict_get_str(qdict, "device");
1006 const char *password = qdict_get_str(qdict, "password");
Markus Armbrustere940f542014-05-02 13:26:29 +02001007 Error *err = NULL;
Luiz Capitulinoa4dea8a2011-11-23 13:28:21 -02001008
Markus Armbrustere940f542014-05-02 13:26:29 +02001009 qmp_block_passwd(true, device, false, NULL, password, &err);
1010 hmp_handle_error(mon, &err);
Luiz Capitulinoa4dea8a2011-11-23 13:28:21 -02001011}
Luiz Capitulinod72f3262011-11-25 14:38:09 -02001012
1013void hmp_balloon(Monitor *mon, const QDict *qdict)
1014{
1015 int64_t value = qdict_get_int(qdict, "value");
Markus Armbrustere940f542014-05-02 13:26:29 +02001016 Error *err = NULL;
Luiz Capitulinod72f3262011-11-25 14:38:09 -02001017
Markus Armbrustere940f542014-05-02 13:26:29 +02001018 qmp_balloon(value, &err);
1019 if (err) {
1020 monitor_printf(mon, "balloon: %s\n", error_get_pretty(err));
1021 error_free(err);
Luiz Capitulinod72f3262011-11-25 14:38:09 -02001022 }
1023}
Luiz Capitulino5e7caac2011-11-25 14:57:10 -02001024
1025void hmp_block_resize(Monitor *mon, const QDict *qdict)
1026{
1027 const char *device = qdict_get_str(qdict, "device");
1028 int64_t size = qdict_get_int(qdict, "size");
Markus Armbrustere940f542014-05-02 13:26:29 +02001029 Error *err = NULL;
Luiz Capitulino5e7caac2011-11-25 14:57:10 -02001030
Markus Armbrustere940f542014-05-02 13:26:29 +02001031 qmp_block_resize(true, device, false, NULL, size, &err);
1032 hmp_handle_error(mon, &err);
Luiz Capitulino5e7caac2011-11-25 14:57:10 -02001033}
Luiz Capitulino6106e242011-11-25 16:15:19 -02001034
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001035void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1036{
1037 const char *device = qdict_get_str(qdict, "device");
1038 const char *filename = qdict_get_str(qdict, "target");
1039 const char *format = qdict_get_try_str(qdict, "format");
1040 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
1041 int full = qdict_get_try_bool(qdict, "full", 0);
1042 enum NewImageMode mode;
Markus Armbrustere940f542014-05-02 13:26:29 +02001043 Error *err = NULL;
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001044
1045 if (!filename) {
Markus Armbrustere940f542014-05-02 13:26:29 +02001046 error_set(&err, QERR_MISSING_PARAMETER, "target");
1047 hmp_handle_error(mon, &err);
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001048 return;
1049 }
1050
1051 if (reuse) {
1052 mode = NEW_IMAGE_MODE_EXISTING;
1053 } else {
1054 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1055 }
1056
1057 qmp_drive_mirror(device, filename, !!format, format,
Benoît Canet09158f02014-06-27 18:25:25 +02001058 false, NULL, false, NULL,
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001059 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
Paolo Bonzini08e4ed62013-01-22 09:03:13 +01001060 true, mode, false, 0, false, 0, false, 0,
Markus Armbrustere940f542014-05-02 13:26:29 +02001061 false, 0, false, 0, &err);
1062 hmp_handle_error(mon, &err);
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001063}
1064
Stefan Hajnoczide909302013-06-26 14:11:58 +02001065void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1066{
1067 const char *device = qdict_get_str(qdict, "device");
1068 const char *filename = qdict_get_str(qdict, "target");
1069 const char *format = qdict_get_try_str(qdict, "format");
1070 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
1071 int full = qdict_get_try_bool(qdict, "full", 0);
1072 enum NewImageMode mode;
Markus Armbrustere940f542014-05-02 13:26:29 +02001073 Error *err = NULL;
Stefan Hajnoczide909302013-06-26 14:11:58 +02001074
1075 if (!filename) {
Markus Armbrustere940f542014-05-02 13:26:29 +02001076 error_set(&err, QERR_MISSING_PARAMETER, "target");
1077 hmp_handle_error(mon, &err);
Stefan Hajnoczide909302013-06-26 14:11:58 +02001078 return;
1079 }
1080
1081 if (reuse) {
1082 mode = NEW_IMAGE_MODE_EXISTING;
1083 } else {
1084 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1085 }
1086
1087 qmp_drive_backup(device, filename, !!format, format,
1088 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
John Snowd58d8452015-04-17 19:49:58 -04001089 true, mode, false, 0, false, NULL,
1090 false, 0, false, 0, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +02001091 hmp_handle_error(mon, &err);
Stefan Hajnoczide909302013-06-26 14:11:58 +02001092}
1093
Luiz Capitulino6106e242011-11-25 16:15:19 -02001094void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1095{
1096 const char *device = qdict_get_str(qdict, "device");
1097 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1098 const char *format = qdict_get_try_str(qdict, "format");
Paolo Bonzini6cc2a412012-03-06 18:55:59 +01001099 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
1100 enum NewImageMode mode;
Markus Armbrustere940f542014-05-02 13:26:29 +02001101 Error *err = NULL;
Luiz Capitulino6106e242011-11-25 16:15:19 -02001102
1103 if (!filename) {
1104 /* In the future, if 'snapshot-file' is not specified, the snapshot
1105 will be taken internally. Today it's actually required. */
Markus Armbrustere940f542014-05-02 13:26:29 +02001106 error_set(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1107 hmp_handle_error(mon, &err);
Luiz Capitulino6106e242011-11-25 16:15:19 -02001108 return;
1109 }
1110
Paolo Bonzini6cc2a412012-03-06 18:55:59 +01001111 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
Benoît Canet0901f672014-01-23 21:31:38 +01001112 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1113 filename, false, NULL,
1114 !!format, format,
Markus Armbrustere940f542014-05-02 13:26:29 +02001115 true, mode, &err);
1116 hmp_handle_error(mon, &err);
Luiz Capitulino6106e242011-11-25 16:15:19 -02001117}
Luiz Capitulino6cdedb02011-11-27 22:54:09 -02001118
Wenchao Xia775ca882013-09-11 14:04:37 +08001119void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1120{
1121 const char *device = qdict_get_str(qdict, "device");
1122 const char *name = qdict_get_str(qdict, "name");
Markus Armbrustere940f542014-05-02 13:26:29 +02001123 Error *err = NULL;
Wenchao Xia775ca882013-09-11 14:04:37 +08001124
Markus Armbrustere940f542014-05-02 13:26:29 +02001125 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1126 hmp_handle_error(mon, &err);
Wenchao Xia775ca882013-09-11 14:04:37 +08001127}
1128
Wenchao Xia7a4ed2e2013-09-11 14:04:38 +08001129void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1130{
1131 const char *device = qdict_get_str(qdict, "device");
1132 const char *name = qdict_get_str(qdict, "name");
1133 const char *id = qdict_get_try_str(qdict, "id");
Markus Armbrustere940f542014-05-02 13:26:29 +02001134 Error *err = NULL;
Wenchao Xia7a4ed2e2013-09-11 14:04:38 +08001135
1136 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
Markus Armbrustere940f542014-05-02 13:26:29 +02001137 true, name, &err);
1138 hmp_handle_error(mon, &err);
Wenchao Xia7a4ed2e2013-09-11 14:04:38 +08001139}
1140
Luiz Capitulino6cdedb02011-11-27 22:54:09 -02001141void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1142{
1143 qmp_migrate_cancel(NULL);
1144}
Luiz Capitulino4f0a9932011-11-27 23:18:01 -02001145
Dr. David Alan Gilbertbf1ae1f2015-02-19 11:40:28 +00001146void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1147{
1148 Error *err = NULL;
1149 const char *uri = qdict_get_str(qdict, "uri");
1150
1151 qmp_migrate_incoming(uri, &err);
1152
Dr. David Alan Gilbert1fa57f52015-02-26 14:54:39 +00001153 hmp_handle_error(mon, &err);
Dr. David Alan Gilbertbf1ae1f2015-02-19 11:40:28 +00001154}
1155
Luiz Capitulino4f0a9932011-11-27 23:18:01 -02001156void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1157{
1158 double value = qdict_get_double(qdict, "value");
1159 qmp_migrate_set_downtime(value, NULL);
1160}
Luiz Capitulino3dc85382011-11-28 11:59:37 -02001161
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +03001162void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1163{
1164 int64_t value = qdict_get_int(qdict, "value");
1165 Error *err = NULL;
1166
1167 qmp_migrate_set_cache_size(value, &err);
1168 if (err) {
1169 monitor_printf(mon, "%s\n", error_get_pretty(err));
1170 error_free(err);
1171 return;
1172 }
1173}
1174
Luiz Capitulino3dc85382011-11-28 11:59:37 -02001175void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1176{
1177 int64_t value = qdict_get_int(qdict, "value");
1178 qmp_migrate_set_speed(value, NULL);
1179}
Luiz Capitulinofbf796f2011-12-07 11:17:51 -02001180
Orit Wasserman00458432012-08-06 21:42:48 +03001181void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1182{
1183 const char *cap = qdict_get_str(qdict, "capability");
1184 bool state = qdict_get_bool(qdict, "state");
1185 Error *err = NULL;
1186 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1187 int i;
1188
1189 for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
1190 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1191 caps->value = g_malloc0(sizeof(*caps->value));
1192 caps->value->capability = i;
1193 caps->value->state = state;
1194 caps->next = NULL;
1195 qmp_migrate_set_capabilities(caps, &err);
1196 break;
1197 }
1198 }
1199
1200 if (i == MIGRATION_CAPABILITY_MAX) {
1201 error_set(&err, QERR_INVALID_PARAMETER, cap);
1202 }
1203
1204 qapi_free_MigrationCapabilityStatusList(caps);
1205
1206 if (err) {
Orit Wassermana31ca012013-01-31 09:12:19 +02001207 monitor_printf(mon, "migrate_set_capability: %s\n",
Orit Wasserman00458432012-08-06 21:42:48 +03001208 error_get_pretty(err));
1209 error_free(err);
1210 }
1211}
1212
Liang Li50e9a622015-03-23 16:32:29 +08001213void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1214{
1215 const char *param = qdict_get_str(qdict, "parameter");
1216 int value = qdict_get_int(qdict, "value");
1217 Error *err = NULL;
1218 bool has_compress_level = false;
1219 bool has_compress_threads = false;
1220 bool has_decompress_threads = false;
1221 int i;
1222
1223 for (i = 0; i < MIGRATION_PARAMETER_MAX; i++) {
1224 if (strcmp(param, MigrationParameter_lookup[i]) == 0) {
1225 switch (i) {
1226 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1227 has_compress_level = true;
1228 break;
1229 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1230 has_compress_threads = true;
1231 break;
1232 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1233 has_decompress_threads = true;
1234 break;
1235 }
1236 qmp_migrate_set_parameters(has_compress_level, value,
1237 has_compress_threads, value,
1238 has_decompress_threads, value,
1239 &err);
1240 break;
1241 }
1242 }
1243
1244 if (i == MIGRATION_PARAMETER_MAX) {
1245 error_set(&err, QERR_INVALID_PARAMETER, param);
1246 }
1247
1248 if (err) {
1249 monitor_printf(mon, "migrate_set_parameter: %s\n",
1250 error_get_pretty(err));
1251 error_free(err);
1252 }
1253}
1254
Markus Armbrusterb8a185b2015-03-05 17:29:02 +01001255void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1256{
1257 Error *err = NULL;
1258 const char *protocol = qdict_get_str(qdict, "protocol");
1259 const char *hostname = qdict_get_str(qdict, "hostname");
1260 bool has_port = qdict_haskey(qdict, "port");
1261 int port = qdict_get_try_int(qdict, "port", -1);
1262 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1263 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1264 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1265
1266 qmp_client_migrate_info(protocol, hostname,
1267 has_port, port, has_tls_port, tls_port,
1268 !!cert_subject, cert_subject, &err);
1269 hmp_handle_error(mon, &err);
1270}
1271
Luiz Capitulinofbf796f2011-12-07 11:17:51 -02001272void hmp_set_password(Monitor *mon, const QDict *qdict)
1273{
1274 const char *protocol = qdict_get_str(qdict, "protocol");
1275 const char *password = qdict_get_str(qdict, "password");
1276 const char *connected = qdict_get_try_str(qdict, "connected");
1277 Error *err = NULL;
1278
1279 qmp_set_password(protocol, password, !!connected, connected, &err);
1280 hmp_handle_error(mon, &err);
1281}
Luiz Capitulino9ad53722011-12-07 11:47:57 -02001282
1283void hmp_expire_password(Monitor *mon, const QDict *qdict)
1284{
1285 const char *protocol = qdict_get_str(qdict, "protocol");
1286 const char *whenstr = qdict_get_str(qdict, "time");
1287 Error *err = NULL;
1288
1289 qmp_expire_password(protocol, whenstr, &err);
1290 hmp_handle_error(mon, &err);
1291}
Luiz Capitulinoc245b6a2011-12-07 16:02:36 -02001292
1293void hmp_eject(Monitor *mon, const QDict *qdict)
1294{
1295 int force = qdict_get_try_bool(qdict, "force", 0);
1296 const char *device = qdict_get_str(qdict, "device");
1297 Error *err = NULL;
1298
1299 qmp_eject(device, true, force, &err);
1300 hmp_handle_error(mon, &err);
1301}
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001302
Stefan Hajnoczic60bf332013-11-14 11:54:14 +01001303static void hmp_change_read_arg(void *opaque, const char *password,
1304 void *readline_opaque)
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001305{
1306 qmp_change_vnc_password(password, NULL);
Stefan Hajnoczic60bf332013-11-14 11:54:14 +01001307 monitor_read_command(opaque, 1);
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001308}
1309
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001310void hmp_change(Monitor *mon, const QDict *qdict)
1311{
1312 const char *device = qdict_get_str(qdict, "device");
1313 const char *target = qdict_get_str(qdict, "target");
1314 const char *arg = qdict_get_try_str(qdict, "arg");
1315 Error *err = NULL;
1316
1317 if (strcmp(device, "vnc") == 0 &&
1318 (strcmp(target, "passwd") == 0 ||
1319 strcmp(target, "password") == 0)) {
1320 if (!arg) {
1321 monitor_read_password(mon, hmp_change_read_arg, NULL);
1322 return;
1323 }
1324 }
1325
1326 qmp_change(device, target, !!arg, arg, &err);
Markus Armbruster84d18f02014-01-30 15:07:28 +01001327 if (err &&
Luiz Capitulinoab878dd2012-08-06 15:55:22 -03001328 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
Luiz Capitulinoeef5ad12012-08-06 15:49:34 -03001329 error_free(err);
1330 monitor_read_block_device_key(mon, device, NULL, NULL);
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001331 return;
1332 }
1333 hmp_handle_error(mon, &err);
1334}
Luiz Capitulino80047da2011-12-14 16:49:14 -02001335
1336void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1337{
1338 Error *err = NULL;
1339
1340 qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
1341 qdict_get_int(qdict, "bps"),
1342 qdict_get_int(qdict, "bps_rd"),
1343 qdict_get_int(qdict, "bps_wr"),
1344 qdict_get_int(qdict, "iops"),
1345 qdict_get_int(qdict, "iops_rd"),
Benoît Canet3e9fab62013-09-02 14:14:40 +02001346 qdict_get_int(qdict, "iops_wr"),
1347 false, /* no burst max via HMP */
1348 0,
1349 false,
1350 0,
1351 false,
1352 0,
1353 false,
1354 0,
1355 false,
1356 0,
1357 false,
Benoît Canet2024c1d2013-09-02 14:14:41 +02001358 0,
1359 false, /* No default I/O size */
Benoît Canet3e9fab62013-09-02 14:14:40 +02001360 0, &err);
Luiz Capitulino80047da2011-12-14 16:49:14 -02001361 hmp_handle_error(mon, &err);
1362}
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00001363
1364void hmp_block_stream(Monitor *mon, const QDict *qdict)
1365{
1366 Error *error = NULL;
1367 const char *device = qdict_get_str(qdict, "device");
1368 const char *base = qdict_get_try_str(qdict, "base");
Stefan Hajnoczic83c66c2012-04-25 16:51:03 +01001369 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00001370
Jeff Cody13d8cc52014-06-25 15:40:11 -04001371 qmp_block_stream(device, base != NULL, base, false, NULL,
Paolo Bonzini1d809092012-09-28 17:22:59 +02001372 qdict_haskey(qdict, "speed"), speed,
Anthony Liguori46663e52013-09-17 11:10:47 -05001373 true, BLOCKDEV_ON_ERROR_REPORT, &error);
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00001374
1375 hmp_handle_error(mon, &error);
1376}
Stefan Hajnoczi2d47c6e2012-01-18 14:40:47 +00001377
1378void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1379{
1380 Error *error = NULL;
1381 const char *device = qdict_get_str(qdict, "device");
Paolo Bonzinic6db2392012-05-08 16:51:56 +02001382 int64_t value = qdict_get_int(qdict, "speed");
Stefan Hajnoczi2d47c6e2012-01-18 14:40:47 +00001383
1384 qmp_block_job_set_speed(device, value, &error);
1385
1386 hmp_handle_error(mon, &error);
1387}
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00001388
1389void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1390{
1391 Error *error = NULL;
1392 const char *device = qdict_get_str(qdict, "device");
Paolo Bonzini6e37fb82012-09-28 17:22:51 +02001393 bool force = qdict_get_try_bool(qdict, "force", 0);
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00001394
Paolo Bonzini6e37fb82012-09-28 17:22:51 +02001395 qmp_block_job_cancel(device, true, force, &error);
1396
1397 hmp_handle_error(mon, &error);
1398}
1399
1400void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1401{
1402 Error *error = NULL;
1403 const char *device = qdict_get_str(qdict, "device");
1404
1405 qmp_block_job_pause(device, &error);
1406
1407 hmp_handle_error(mon, &error);
1408}
1409
1410void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1411{
1412 Error *error = NULL;
1413 const char *device = qdict_get_str(qdict, "device");
1414
1415 qmp_block_job_resume(device, &error);
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00001416
1417 hmp_handle_error(mon, &error);
1418}
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001419
Paolo Bonziniaeae8832012-10-18 16:49:21 +02001420void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1421{
1422 Error *error = NULL;
1423 const char *device = qdict_get_str(qdict, "device");
1424
1425 qmp_block_job_complete(device, &error);
1426
1427 hmp_handle_error(mon, &error);
1428}
1429
zhanghailiange49f35b2015-03-13 16:08:39 +08001430typedef struct HMPMigrationStatus
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001431{
1432 QEMUTimer *timer;
1433 Monitor *mon;
1434 bool is_block_migration;
zhanghailiange49f35b2015-03-13 16:08:39 +08001435} HMPMigrationStatus;
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001436
1437static void hmp_migrate_status_cb(void *opaque)
1438{
zhanghailiange49f35b2015-03-13 16:08:39 +08001439 HMPMigrationStatus *status = opaque;
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001440 MigrationInfo *info;
1441
1442 info = qmp_query_migrate(NULL);
zhanghailiang24b8c392015-03-13 16:08:40 +08001443 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1444 info->status == MIGRATION_STATUS_SETUP) {
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001445 if (info->has_disk) {
1446 int progress;
1447
1448 if (info->disk->remaining) {
1449 progress = info->disk->transferred * 100 / info->disk->total;
1450 } else {
1451 progress = 100;
1452 }
1453
1454 monitor_printf(status->mon, "Completed %d %%\r", progress);
1455 monitor_flush(status->mon);
1456 }
1457
Alex Blighbc72ad62013-08-21 16:03:08 +01001458 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001459 } else {
1460 if (status->is_block_migration) {
1461 monitor_printf(status->mon, "\n");
1462 }
1463 monitor_resume(status->mon);
Alex Blighbc72ad62013-08-21 16:03:08 +01001464 timer_del(status->timer);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001465 g_free(status);
1466 }
1467
1468 qapi_free_MigrationInfo(info);
1469}
1470
1471void hmp_migrate(Monitor *mon, const QDict *qdict)
1472{
1473 int detach = qdict_get_try_bool(qdict, "detach", 0);
1474 int blk = qdict_get_try_bool(qdict, "blk", 0);
1475 int inc = qdict_get_try_bool(qdict, "inc", 0);
1476 const char *uri = qdict_get_str(qdict, "uri");
1477 Error *err = NULL;
1478
1479 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1480 if (err) {
1481 monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
1482 error_free(err);
1483 return;
1484 }
1485
1486 if (!detach) {
zhanghailiange49f35b2015-03-13 16:08:39 +08001487 HMPMigrationStatus *status;
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001488
1489 if (monitor_suspend(mon) < 0) {
1490 monitor_printf(mon, "terminal does not allow synchronous "
1491 "migration, continuing detached\n");
1492 return;
1493 }
1494
1495 status = g_malloc0(sizeof(*status));
1496 status->mon = mon;
1497 status->is_block_migration = blk || inc;
Alex Blighbc72ad62013-08-21 16:03:08 +01001498 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001499 status);
Alex Blighbc72ad62013-08-21 16:03:08 +01001500 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001501 }
1502}
Luiz Capitulinoa15fef22012-03-29 12:38:50 -03001503
Markus Armbruster318660f2015-03-05 17:24:48 +01001504void hmp_device_add(Monitor *mon, const QDict *qdict)
1505{
1506 do_device_add(mon, qdict, NULL);
1507}
1508
Luiz Capitulinoa15fef22012-03-29 12:38:50 -03001509void hmp_device_del(Monitor *mon, const QDict *qdict)
1510{
1511 const char *id = qdict_get_str(qdict, "id");
1512 Error *err = NULL;
1513
1514 qmp_device_del(id, &err);
1515 hmp_handle_error(mon, &err);
1516}
Wen Congyang783e9b42012-05-07 12:10:47 +08001517
1518void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1519{
Markus Armbrustere940f542014-05-02 13:26:29 +02001520 Error *err = NULL;
Wen Congyang783e9b42012-05-07 12:10:47 +08001521 int paging = qdict_get_try_bool(qdict, "paging", 0);
Qiao Nuohan1b7a0f72014-04-17 16:15:07 +08001522 int zlib = qdict_get_try_bool(qdict, "zlib", 0);
1523 int lzo = qdict_get_try_bool(qdict, "lzo", 0);
1524 int snappy = qdict_get_try_bool(qdict, "snappy", 0);
Luiz Capitulino75363762012-09-21 13:53:00 -03001525 const char *file = qdict_get_str(qdict, "filename");
Wen Congyang783e9b42012-05-07 12:10:47 +08001526 bool has_begin = qdict_haskey(qdict, "begin");
1527 bool has_length = qdict_haskey(qdict, "length");
1528 int64_t begin = 0;
1529 int64_t length = 0;
qiaonuohanb53ccc32014-02-18 14:11:36 +08001530 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
Luiz Capitulino75363762012-09-21 13:53:00 -03001531 char *prot;
Wen Congyang783e9b42012-05-07 12:10:47 +08001532
Qiao Nuohan1b7a0f72014-04-17 16:15:07 +08001533 if (zlib + lzo + snappy > 1) {
Markus Armbrustere940f542014-05-02 13:26:29 +02001534 error_setg(&err, "only one of '-z|-l|-s' can be set");
1535 hmp_handle_error(mon, &err);
Qiao Nuohan1b7a0f72014-04-17 16:15:07 +08001536 return;
1537 }
1538
1539 if (zlib) {
1540 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1541 }
1542
1543 if (lzo) {
1544 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1545 }
1546
1547 if (snappy) {
1548 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1549 }
1550
Wen Congyang783e9b42012-05-07 12:10:47 +08001551 if (has_begin) {
1552 begin = qdict_get_int(qdict, "begin");
1553 }
1554 if (has_length) {
1555 length = qdict_get_int(qdict, "length");
1556 }
1557
Luiz Capitulino75363762012-09-21 13:53:00 -03001558 prot = g_strconcat("file:", file, NULL);
1559
1560 qmp_dump_guest_memory(paging, prot, has_begin, begin, has_length, length,
Markus Armbrustere940f542014-05-02 13:26:29 +02001561 true, dump_format, &err);
1562 hmp_handle_error(mon, &err);
Luiz Capitulino75363762012-09-21 13:53:00 -03001563 g_free(prot);
Wen Congyang783e9b42012-05-07 12:10:47 +08001564}
Luiz Capitulino928059a2012-04-18 17:34:15 -03001565
1566void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1567{
1568 Error *err = NULL;
1569 QemuOpts *opts;
1570
1571 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
Markus Armbruster84d18f02014-01-30 15:07:28 +01001572 if (err) {
Luiz Capitulino928059a2012-04-18 17:34:15 -03001573 goto out;
1574 }
1575
1576 netdev_add(opts, &err);
Markus Armbruster84d18f02014-01-30 15:07:28 +01001577 if (err) {
Luiz Capitulino928059a2012-04-18 17:34:15 -03001578 qemu_opts_del(opts);
1579 }
1580
1581out:
1582 hmp_handle_error(mon, &err);
1583}
Luiz Capitulino5f964152012-04-16 14:36:32 -03001584
1585void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1586{
1587 const char *id = qdict_get_str(qdict, "id");
1588 Error *err = NULL;
1589
1590 qmp_netdev_del(id, &err);
1591 hmp_handle_error(mon, &err);
1592}
Corey Bryant208c9d12012-06-22 14:36:09 -04001593
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01001594void hmp_object_add(Monitor *mon, const QDict *qdict)
1595{
1596 Error *err = NULL;
Markus Armbrusterf9f3a5e2014-05-07 09:53:51 +02001597 Error *err_end = NULL;
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01001598 QemuOpts *opts;
1599 char *type = NULL;
1600 char *id = NULL;
1601 void *dummy = NULL;
1602 OptsVisitor *ov;
1603 QDict *pdict;
1604
1605 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1606 if (err) {
1607 goto out;
1608 }
1609
1610 ov = opts_visitor_new(opts);
1611 pdict = qdict_clone_shallow(qdict);
1612
1613 visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err);
1614 if (err) {
1615 goto out_clean;
1616 }
1617
1618 qdict_del(pdict, "qom-type");
1619 visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
1620 if (err) {
Markus Armbrusterf9f3a5e2014-05-07 09:53:51 +02001621 goto out_end;
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01001622 }
1623
1624 qdict_del(pdict, "id");
1625 visit_type_str(opts_get_visitor(ov), &id, "id", &err);
1626 if (err) {
Markus Armbrusterf9f3a5e2014-05-07 09:53:51 +02001627 goto out_end;
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01001628 }
1629
1630 object_add(type, id, pdict, opts_get_visitor(ov), &err);
Markus Armbrusterf9f3a5e2014-05-07 09:53:51 +02001631
1632out_end:
1633 visit_end_struct(opts_get_visitor(ov), &err_end);
1634 if (!err && err_end) {
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01001635 qmp_object_del(id, NULL);
1636 }
Markus Armbrusterf9f3a5e2014-05-07 09:53:51 +02001637 error_propagate(&err, err_end);
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01001638out_clean:
1639 opts_visitor_cleanup(ov);
1640
1641 QDECREF(pdict);
1642 qemu_opts_del(opts);
1643 g_free(id);
1644 g_free(type);
1645 g_free(dummy);
1646
1647out:
1648 hmp_handle_error(mon, &err);
1649}
1650
Corey Bryant208c9d12012-06-22 14:36:09 -04001651void hmp_getfd(Monitor *mon, const QDict *qdict)
1652{
1653 const char *fdname = qdict_get_str(qdict, "fdname");
Markus Armbrustere940f542014-05-02 13:26:29 +02001654 Error *err = NULL;
Corey Bryant208c9d12012-06-22 14:36:09 -04001655
Markus Armbrustere940f542014-05-02 13:26:29 +02001656 qmp_getfd(fdname, &err);
1657 hmp_handle_error(mon, &err);
Corey Bryant208c9d12012-06-22 14:36:09 -04001658}
1659
1660void hmp_closefd(Monitor *mon, const QDict *qdict)
1661{
1662 const char *fdname = qdict_get_str(qdict, "fdname");
Markus Armbrustere940f542014-05-02 13:26:29 +02001663 Error *err = NULL;
Corey Bryant208c9d12012-06-22 14:36:09 -04001664
Markus Armbrustere940f542014-05-02 13:26:29 +02001665 qmp_closefd(fdname, &err);
1666 hmp_handle_error(mon, &err);
Corey Bryant208c9d12012-06-22 14:36:09 -04001667}
Amos Konge4c8f002012-08-31 10:56:26 +08001668
Markus Armbruster3e5a50d2015-02-06 13:55:43 +01001669void hmp_sendkey(Monitor *mon, const QDict *qdict)
Amos Konge4c8f002012-08-31 10:56:26 +08001670{
1671 const char *keys = qdict_get_str(qdict, "keys");
Luiz Capitulino9f328972012-09-20 14:19:47 -03001672 KeyValueList *keylist, *head = NULL, *tmp = NULL;
Amos Konge4c8f002012-08-31 10:56:26 +08001673 int has_hold_time = qdict_haskey(qdict, "hold-time");
1674 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1675 Error *err = NULL;
1676 char keyname_buf[16];
1677 char *separator;
Luiz Capitulino9f328972012-09-20 14:19:47 -03001678 int keyname_len;
Amos Konge4c8f002012-08-31 10:56:26 +08001679
1680 while (1) {
1681 separator = strchr(keys, '-');
1682 keyname_len = separator ? separator - keys : strlen(keys);
1683 pstrcpy(keyname_buf, sizeof(keyname_buf), keys);
1684
1685 /* Be compatible with old interface, convert user inputted "<" */
1686 if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) {
1687 pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
1688 keyname_len = 4;
1689 }
1690 keyname_buf[keyname_len] = 0;
1691
Amos Konge4c8f002012-08-31 10:56:26 +08001692 keylist = g_malloc0(sizeof(*keylist));
Luiz Capitulino9f328972012-09-20 14:19:47 -03001693 keylist->value = g_malloc0(sizeof(*keylist->value));
Amos Konge4c8f002012-08-31 10:56:26 +08001694
1695 if (!head) {
1696 head = keylist;
1697 }
1698 if (tmp) {
1699 tmp->next = keylist;
1700 }
1701 tmp = keylist;
1702
Luiz Capitulino9f328972012-09-20 14:19:47 -03001703 if (strstart(keyname_buf, "0x", NULL)) {
1704 char *endp;
1705 int value = strtoul(keyname_buf, &endp, 0);
1706 if (*endp != '\0') {
1707 goto err_out;
1708 }
1709 keylist->value->kind = KEY_VALUE_KIND_NUMBER;
1710 keylist->value->number = value;
1711 } else {
1712 int idx = index_from_key(keyname_buf);
1713 if (idx == Q_KEY_CODE_MAX) {
1714 goto err_out;
1715 }
1716 keylist->value->kind = KEY_VALUE_KIND_QCODE;
1717 keylist->value->qcode = idx;
1718 }
1719
Amos Konge4c8f002012-08-31 10:56:26 +08001720 if (!separator) {
1721 break;
1722 }
1723 keys = separator + 1;
1724 }
1725
Luiz Capitulino9f328972012-09-20 14:19:47 -03001726 qmp_send_key(head, has_hold_time, hold_time, &err);
Amos Konge4c8f002012-08-31 10:56:26 +08001727 hmp_handle_error(mon, &err);
Luiz Capitulino9f328972012-09-20 14:19:47 -03001728
1729out:
1730 qapi_free_KeyValueList(head);
1731 return;
1732
1733err_out:
1734 monitor_printf(mon, "invalid parameter: %s\n", keyname_buf);
1735 goto out;
Amos Konge4c8f002012-08-31 10:56:26 +08001736}
Luiz Capitulinoad39cf62012-05-24 13:48:23 -03001737
Markus Armbruster3e5a50d2015-02-06 13:55:43 +01001738void hmp_screendump(Monitor *mon, const QDict *qdict)
Luiz Capitulinoad39cf62012-05-24 13:48:23 -03001739{
1740 const char *filename = qdict_get_str(qdict, "filename");
1741 Error *err = NULL;
1742
1743 qmp_screendump(filename, &err);
1744 hmp_handle_error(mon, &err);
1745}
Paolo Bonzini40577252012-08-23 11:53:04 +02001746
1747void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1748{
1749 const char *uri = qdict_get_str(qdict, "uri");
1750 int writable = qdict_get_try_bool(qdict, "writable", 0);
1751 int all = qdict_get_try_bool(qdict, "all", 0);
1752 Error *local_err = NULL;
1753 BlockInfoList *block_list, *info;
1754 SocketAddress *addr;
1755
1756 if (writable && !all) {
1757 error_setg(&local_err, "-w only valid together with -a");
1758 goto exit;
1759 }
1760
1761 /* First check if the address is valid and start the server. */
1762 addr = socket_parse(uri, &local_err);
1763 if (local_err != NULL) {
1764 goto exit;
1765 }
1766
1767 qmp_nbd_server_start(addr, &local_err);
1768 qapi_free_SocketAddress(addr);
1769 if (local_err != NULL) {
1770 goto exit;
1771 }
1772
1773 if (!all) {
1774 return;
1775 }
1776
1777 /* Then try adding all block devices. If one fails, close all and
1778 * exit.
1779 */
1780 block_list = qmp_query_block(NULL);
1781
1782 for (info = block_list; info; info = info->next) {
1783 if (!info->value->has_inserted) {
1784 continue;
1785 }
1786
1787 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1788
1789 if (local_err != NULL) {
1790 qmp_nbd_server_stop(NULL);
1791 break;
1792 }
1793 }
1794
1795 qapi_free_BlockInfoList(block_list);
1796
1797exit:
1798 hmp_handle_error(mon, &local_err);
1799}
1800
1801void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1802{
1803 const char *device = qdict_get_str(qdict, "device");
1804 int writable = qdict_get_try_bool(qdict, "writable", 0);
1805 Error *local_err = NULL;
1806
1807 qmp_nbd_server_add(device, true, writable, &local_err);
1808
1809 if (local_err != NULL) {
1810 hmp_handle_error(mon, &local_err);
1811 }
1812}
1813
1814void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1815{
Markus Armbrustere940f542014-05-02 13:26:29 +02001816 Error *err = NULL;
Paolo Bonzini40577252012-08-23 11:53:04 +02001817
Markus Armbrustere940f542014-05-02 13:26:29 +02001818 qmp_nbd_server_stop(&err);
1819 hmp_handle_error(mon, &err);
Paolo Bonzini40577252012-08-23 11:53:04 +02001820}
Gerd Hoffmannf1088902012-12-19 10:33:40 +01001821
Jason J. Herneabf23322013-12-11 13:24:14 -05001822void hmp_cpu_add(Monitor *mon, const QDict *qdict)
1823{
1824 int cpuid;
1825 Error *err = NULL;
1826
1827 cpuid = qdict_get_int(qdict, "id");
1828 qmp_cpu_add(cpuid, &err);
1829 hmp_handle_error(mon, &err);
1830}
1831
Gerd Hoffmannf1088902012-12-19 10:33:40 +01001832void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1833{
1834 const char *args = qdict_get_str(qdict, "args");
1835 Error *err = NULL;
1836 QemuOpts *opts;
1837
1838 opts = qemu_opts_parse(qemu_find_opts("chardev"), args, 1);
1839 if (opts == NULL) {
Markus Armbruster312fd5f2013-02-08 21:22:16 +01001840 error_setg(&err, "Parsing chardev args failed");
Gerd Hoffmannf1088902012-12-19 10:33:40 +01001841 } else {
1842 qemu_chr_new_from_opts(opts, NULL, &err);
1843 }
1844 hmp_handle_error(mon, &err);
1845}
1846
1847void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1848{
1849 Error *local_err = NULL;
1850
1851 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1852 hmp_handle_error(mon, &local_err);
1853}
Kevin Wolf587da2c2013-06-05 14:19:41 +02001854
1855void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1856{
Max Reitz4c7b7e92015-02-05 13:58:22 -05001857 BlockBackend *blk;
Kevin Wolf587da2c2013-06-05 14:19:41 +02001858 const char* device = qdict_get_str(qdict, "device");
1859 const char* command = qdict_get_str(qdict, "command");
1860 Error *err = NULL;
1861
Max Reitz4c7b7e92015-02-05 13:58:22 -05001862 blk = blk_by_name(device);
1863 if (blk) {
1864 qemuio_command(blk, command);
Kevin Wolf587da2c2013-06-05 14:19:41 +02001865 } else {
1866 error_set(&err, QERR_DEVICE_NOT_FOUND, device);
1867 }
1868
1869 hmp_handle_error(mon, &err);
1870}
Paolo Bonziniab2d0532013-12-20 23:21:09 +01001871
1872void hmp_object_del(Monitor *mon, const QDict *qdict)
1873{
1874 const char *id = qdict_get_str(qdict, "id");
1875 Error *err = NULL;
1876
1877 qmp_object_del(id, &err);
1878 hmp_handle_error(mon, &err);
1879}
Hu Taoeb1539b2014-05-14 17:43:35 +08001880
1881void hmp_info_memdev(Monitor *mon, const QDict *qdict)
1882{
1883 Error *err = NULL;
1884 MemdevList *memdev_list = qmp_query_memdev(&err);
1885 MemdevList *m = memdev_list;
1886 StringOutputVisitor *ov;
Chen Fan976620a2014-08-18 14:46:34 +08001887 char *str;
Hu Taoeb1539b2014-05-14 17:43:35 +08001888 int i = 0;
1889
1890
1891 while (m) {
1892 ov = string_output_visitor_new(false);
1893 visit_type_uint16List(string_output_get_visitor(ov),
1894 &m->value->host_nodes, NULL, NULL);
Igor Mammedov8f4e5ac2014-06-19 16:14:43 +02001895 monitor_printf(mon, "memory backend: %d\n", i);
Hu Taoeb1539b2014-05-14 17:43:35 +08001896 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
1897 monitor_printf(mon, " merge: %s\n",
1898 m->value->merge ? "true" : "false");
1899 monitor_printf(mon, " dump: %s\n",
1900 m->value->dump ? "true" : "false");
1901 monitor_printf(mon, " prealloc: %s\n",
1902 m->value->prealloc ? "true" : "false");
1903 monitor_printf(mon, " policy: %s\n",
1904 HostMemPolicy_lookup[m->value->policy]);
Chen Fan976620a2014-08-18 14:46:34 +08001905 str = string_output_get_string(ov);
1906 monitor_printf(mon, " host nodes: %s\n", str);
Hu Taoeb1539b2014-05-14 17:43:35 +08001907
Chen Fan976620a2014-08-18 14:46:34 +08001908 g_free(str);
Hu Taoeb1539b2014-05-14 17:43:35 +08001909 string_output_visitor_cleanup(ov);
1910 m = m->next;
1911 i++;
1912 }
1913
1914 monitor_printf(mon, "\n");
Chen Fanecaf54a2014-08-18 14:46:35 +08001915
1916 qapi_free_MemdevList(memdev_list);
Hu Taoeb1539b2014-05-14 17:43:35 +08001917}
Zhu Guihuaa6318922014-09-23 13:35:19 +08001918
1919void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
1920{
1921 Error *err = NULL;
1922 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
1923 MemoryDeviceInfoList *info;
1924 MemoryDeviceInfo *value;
1925 PCDIMMDeviceInfo *di;
1926
1927 for (info = info_list; info; info = info->next) {
1928 value = info->value;
1929
1930 if (value) {
1931 switch (value->kind) {
1932 case MEMORY_DEVICE_INFO_KIND_DIMM:
1933 di = value->dimm;
1934
1935 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1936 MemoryDeviceInfoKind_lookup[value->kind],
1937 di->id ? di->id : "");
1938 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
1939 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
1940 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
1941 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
1942 monitor_printf(mon, " memdev: %s\n", di->memdev);
1943 monitor_printf(mon, " hotplugged: %s\n",
1944 di->hotplugged ? "true" : "false");
1945 monitor_printf(mon, " hotpluggable: %s\n",
1946 di->hotpluggable ? "true" : "false");
1947 break;
1948 default:
1949 break;
1950 }
1951 }
1952 }
1953
1954 qapi_free_MemoryDeviceInfoList(info_list);
1955}
Andreas Färber89d7fa92014-05-07 18:08:29 +02001956
1957void hmp_qom_list(Monitor *mon, const QDict *qdict)
1958{
1959 const char *path = qdict_get_try_str(qdict, "path");
1960 ObjectPropertyInfoList *list;
1961 Error *err = NULL;
1962
1963 if (path == NULL) {
1964 monitor_printf(mon, "/\n");
1965 return;
1966 }
1967
1968 list = qmp_qom_list(path, &err);
1969 if (err == NULL) {
1970 ObjectPropertyInfoList *start = list;
1971 while (list != NULL) {
1972 ObjectPropertyInfo *value = list->value;
1973
1974 monitor_printf(mon, "%s (%s)\n",
1975 value->name, value->type);
1976 list = list->next;
1977 }
1978 qapi_free_ObjectPropertyInfoList(start);
1979 }
1980 hmp_handle_error(mon, &err);
1981}
Andreas Färberc0e6ee92014-05-07 19:48:15 +02001982
1983void hmp_qom_set(Monitor *mon, const QDict *qdict)
1984{
1985 const char *path = qdict_get_str(qdict, "path");
1986 const char *property = qdict_get_str(qdict, "property");
1987 const char *value = qdict_get_str(qdict, "value");
1988 Error *err = NULL;
1989 bool ambiguous = false;
1990 Object *obj;
1991
1992 obj = object_resolve_path(path, &ambiguous);
1993 if (obj == NULL) {
1994 error_set(&err, QERR_DEVICE_NOT_FOUND, path);
1995 } else {
1996 if (ambiguous) {
1997 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
1998 }
1999 object_property_parse(obj, value, property, &err);
2000 }
2001 hmp_handle_error(mon, &err);
2002}
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002003
2004void hmp_rocker(Monitor *mon, const QDict *qdict)
2005{
2006 const char *name = qdict_get_str(qdict, "name");
2007 RockerSwitch *rocker;
2008 Error *errp = NULL;
2009
2010 rocker = qmp_query_rocker(name, &errp);
2011 if (errp != NULL) {
2012 hmp_handle_error(mon, &errp);
2013 return;
2014 }
2015
2016 monitor_printf(mon, "name: %s\n", rocker->name);
2017 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2018 monitor_printf(mon, "ports: %d\n", rocker->ports);
2019
2020 qapi_free_RockerSwitch(rocker);
2021}
2022
2023void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2024{
2025 RockerPortList *list, *port;
2026 const char *name = qdict_get_str(qdict, "name");
2027 Error *errp = NULL;
2028
2029 list = qmp_query_rocker_ports(name, &errp);
2030 if (errp != NULL) {
2031 hmp_handle_error(mon, &errp);
2032 return;
2033 }
2034
2035 monitor_printf(mon, " ena/ speed/ auto\n");
2036 monitor_printf(mon, " port link duplex neg?\n");
2037
2038 for (port = list; port; port = port->next) {
2039 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2040 port->value->name,
2041 port->value->enabled ? port->value->link_up ?
2042 "up" : "down" : "!ena",
2043 port->value->speed == 10000 ? "10G" : "??",
2044 port->value->duplex ? "FD" : "HD",
2045 port->value->autoneg ? "Yes" : "No");
2046 }
2047
2048 qapi_free_RockerPortList(list);
2049}
2050
2051void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2052{
2053 RockerOfDpaFlowList *list, *info;
2054 const char *name = qdict_get_str(qdict, "name");
2055 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2056 Error *errp = NULL;
2057
2058 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &errp);
2059 if (errp != NULL) {
2060 hmp_handle_error(mon, &errp);
2061 return;
2062 }
2063
2064 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2065
2066 for (info = list; info; info = info->next) {
2067 RockerOfDpaFlow *flow = info->value;
2068 RockerOfDpaFlowKey *key = flow->key;
2069 RockerOfDpaFlowMask *mask = flow->mask;
2070 RockerOfDpaFlowAction *action = flow->action;
2071
2072 if (flow->hits) {
2073 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2074 key->priority, key->tbl_id, flow->hits);
2075 } else {
2076 monitor_printf(mon, "%-4d %-3d ",
2077 key->priority, key->tbl_id);
2078 }
2079
2080 if (key->has_in_pport) {
2081 monitor_printf(mon, " pport %d", key->in_pport);
2082 if (mask->has_in_pport) {
2083 monitor_printf(mon, "(0x%x)", mask->in_pport);
2084 }
2085 }
2086
2087 if (key->has_vlan_id) {
2088 monitor_printf(mon, " vlan %d",
2089 key->vlan_id & VLAN_VID_MASK);
2090 if (mask->has_vlan_id) {
2091 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2092 }
2093 }
2094
2095 if (key->has_tunnel_id) {
2096 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2097 if (mask->has_tunnel_id) {
2098 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2099 }
2100 }
2101
2102 if (key->has_eth_type) {
2103 switch (key->eth_type) {
2104 case 0x0806:
2105 monitor_printf(mon, " ARP");
2106 break;
2107 case 0x0800:
2108 monitor_printf(mon, " IP");
2109 break;
2110 case 0x86dd:
2111 monitor_printf(mon, " IPv6");
2112 break;
2113 case 0x8809:
2114 monitor_printf(mon, " LACP");
2115 break;
2116 case 0x88cc:
2117 monitor_printf(mon, " LLDP");
2118 break;
2119 default:
2120 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2121 break;
2122 }
2123 }
2124
2125 if (key->has_eth_src) {
2126 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2127 (mask->has_eth_src) &&
2128 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2129 monitor_printf(mon, " src <any mcast/bcast>");
2130 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2131 (mask->has_eth_src) &&
2132 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2133 monitor_printf(mon, " src <any ucast>");
2134 } else {
2135 monitor_printf(mon, " src %s", key->eth_src);
2136 if (mask->has_eth_src) {
2137 monitor_printf(mon, "(%s)", mask->eth_src);
2138 }
2139 }
2140 }
2141
2142 if (key->has_eth_dst) {
2143 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2144 (mask->has_eth_dst) &&
2145 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2146 monitor_printf(mon, " dst <any mcast/bcast>");
2147 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2148 (mask->has_eth_dst) &&
2149 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2150 monitor_printf(mon, " dst <any ucast>");
2151 } else {
2152 monitor_printf(mon, " dst %s", key->eth_dst);
2153 if (mask->has_eth_dst) {
2154 monitor_printf(mon, "(%s)", mask->eth_dst);
2155 }
2156 }
2157 }
2158
2159 if (key->has_ip_proto) {
2160 monitor_printf(mon, " proto %d", key->ip_proto);
2161 if (mask->has_ip_proto) {
2162 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2163 }
2164 }
2165
2166 if (key->has_ip_tos) {
2167 monitor_printf(mon, " TOS %d", key->ip_tos);
2168 if (mask->has_ip_tos) {
2169 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2170 }
2171 }
2172
2173 if (key->has_ip_dst) {
2174 monitor_printf(mon, " dst %s", key->ip_dst);
2175 }
2176
2177 if (action->has_goto_tbl || action->has_group_id ||
2178 action->has_new_vlan_id) {
2179 monitor_printf(mon, " -->");
2180 }
2181
2182 if (action->has_new_vlan_id) {
2183 monitor_printf(mon, " apply new vlan %d",
2184 ntohs(action->new_vlan_id));
2185 }
2186
2187 if (action->has_group_id) {
2188 monitor_printf(mon, " write group 0x%08x", action->group_id);
2189 }
2190
2191 if (action->has_goto_tbl) {
2192 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2193 }
2194
2195 monitor_printf(mon, "\n");
2196 }
2197
2198 qapi_free_RockerOfDpaFlowList(list);
2199}
2200
2201void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2202{
2203 RockerOfDpaGroupList *list, *g;
2204 const char *name = qdict_get_str(qdict, "name");
2205 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2206 Error *errp = NULL;
2207 bool set = false;
2208
2209 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &errp);
2210 if (errp != NULL) {
2211 hmp_handle_error(mon, &errp);
2212 return;
2213 }
2214
2215 monitor_printf(mon, "id (decode) --> buckets\n");
2216
2217 for (g = list; g; g = g->next) {
2218 RockerOfDpaGroup *group = g->value;
2219
2220 monitor_printf(mon, "0x%08x", group->id);
2221
2222 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2223 group->type == 1 ? "L2 rewrite" :
2224 group->type == 2 ? "L3 unicast" :
2225 group->type == 3 ? "L2 multicast" :
2226 group->type == 4 ? "L2 flood" :
2227 group->type == 5 ? "L3 interface" :
2228 group->type == 6 ? "L3 multicast" :
2229 group->type == 7 ? "L3 ECMP" :
2230 group->type == 8 ? "L2 overlay" :
2231 "unknown");
2232
2233 if (group->has_vlan_id) {
2234 monitor_printf(mon, " vlan %d", group->vlan_id);
2235 }
2236
2237 if (group->has_pport) {
2238 monitor_printf(mon, " pport %d", group->pport);
2239 }
2240
2241 if (group->has_index) {
2242 monitor_printf(mon, " index %d", group->index);
2243 }
2244
2245 monitor_printf(mon, ") -->");
2246
2247 if (group->has_set_vlan_id && group->set_vlan_id) {
2248 set = true;
2249 monitor_printf(mon, " set vlan %d",
2250 group->set_vlan_id & VLAN_VID_MASK);
2251 }
2252
2253 if (group->has_set_eth_src) {
2254 if (!set) {
2255 set = true;
2256 monitor_printf(mon, " set");
2257 }
2258 monitor_printf(mon, " src %s", group->set_eth_src);
2259 }
2260
2261 if (group->has_set_eth_dst) {
2262 if (!set) {
2263 set = true;
2264 monitor_printf(mon, " set");
2265 }
2266 monitor_printf(mon, " dst %s", group->set_eth_dst);
2267 }
2268
2269 set = false;
2270
2271 if (group->has_ttl_check && group->ttl_check) {
2272 monitor_printf(mon, " check TTL");
2273 }
2274
2275 if (group->has_group_id && group->group_id) {
2276 monitor_printf(mon, " group id 0x%08x", group->group_id);
2277 }
2278
2279 if (group->has_pop_vlan && group->pop_vlan) {
2280 monitor_printf(mon, " pop vlan");
2281 }
2282
2283 if (group->has_out_pport) {
2284 monitor_printf(mon, " out pport %d", group->out_pport);
2285 }
2286
2287 if (group->has_group_ids) {
2288 struct uint32List *id;
2289
2290 monitor_printf(mon, " groups [");
2291 for (id = group->group_ids; id; id = id->next) {
2292 monitor_printf(mon, "0x%08x", id->value);
2293 if (id->next) {
2294 monitor_printf(mon, ",");
2295 }
2296 }
2297 monitor_printf(mon, "]");
2298 }
2299
2300 monitor_printf(mon, "\n");
2301 }
2302
2303 qapi_free_RockerOfDpaGroupList(list);
2304}