blob: 39d581569719b346845a889e8c9632916e387eeb [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"
Markus Armbrustercc7a8ea2015-03-17 17:22:46 +010028#include "qapi/qmp/qerror.h"
Hu Taoeb1539b2014-05-14 17:43:35 +080029#include "qapi/string-output-visitor.h"
30#include "qapi-visit.h"
Paolo Bonzini28ecbae2012-11-28 12:06:30 +010031#include "ui/console.h"
Wenchao Xiabd093a32013-06-06 12:28:00 +080032#include "block/qapi.h"
Kevin Wolf587da2c2013-06-05 14:19:41 +020033#include "qemu-io.h"
Anthony Liguori48a32be2011-09-02 12:34:48 -050034
Cole Robinson22fa7da2015-03-01 09:29:18 -050035#ifdef CONFIG_SPICE
36#include <spice/enums.h>
37#endif
38
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -020039static void hmp_handle_error(Monitor *mon, Error **errp)
40{
Markus Armbruster415168e2014-05-02 13:26:34 +020041 assert(errp);
42 if (*errp) {
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -020043 monitor_printf(mon, "%s\n", error_get_pretty(*errp));
44 error_free(*errp);
45 }
46}
47
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080048void hmp_info_name(Monitor *mon, const QDict *qdict)
Anthony Liguori48a32be2011-09-02 12:34:48 -050049{
50 NameInfo *info;
51
52 info = qmp_query_name(NULL);
53 if (info->has_name) {
54 monitor_printf(mon, "%s\n", info->name);
55 }
56 qapi_free_NameInfo(info);
57}
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030058
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080059void hmp_info_version(Monitor *mon, const QDict *qdict)
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030060{
61 VersionInfo *info;
62
63 info = qmp_query_version(NULL);
64
65 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
Eric Blake4752cdb2015-05-04 09:05:31 -060066 info->qemu->major, info->qemu->minor, info->qemu->micro,
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030067 info->package);
68
69 qapi_free_VersionInfo(info);
70}
Luiz Capitulino292a2602011-09-12 15:10:53 -030071
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080072void hmp_info_kvm(Monitor *mon, const QDict *qdict)
Luiz Capitulino292a2602011-09-12 15:10:53 -030073{
74 KvmInfo *info;
75
76 info = qmp_query_kvm(NULL);
77 monitor_printf(mon, "kvm support: ");
78 if (info->present) {
79 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
80 } else {
81 monitor_printf(mon, "not compiled\n");
82 }
83
84 qapi_free_KvmInfo(info);
85}
86
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080087void hmp_info_status(Monitor *mon, const QDict *qdict)
Luiz Capitulino1fa9a5e2011-09-12 17:54:20 -030088{
89 StatusInfo *info;
90
91 info = qmp_query_status(NULL);
92
93 monitor_printf(mon, "VM status: %s%s",
94 info->running ? "running" : "paused",
95 info->singlestep ? " (single step mode)" : "");
96
97 if (!info->running && info->status != RUN_STATE_PAUSED) {
98 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
99 }
100
101 monitor_printf(mon, "\n");
102
103 qapi_free_StatusInfo(info);
104}
105
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800106void hmp_info_uuid(Monitor *mon, const QDict *qdict)
Luiz Capitulinoefab7672011-09-13 17:16:25 -0300107{
108 UuidInfo *info;
109
110 info = qmp_query_uuid(NULL);
111 monitor_printf(mon, "%s\n", info->UUID);
112 qapi_free_UuidInfo(info);
113}
Luiz Capitulinoc5a415a2011-09-14 16:05:49 -0300114
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800115void hmp_info_chardev(Monitor *mon, const QDict *qdict)
Luiz Capitulinoc5a415a2011-09-14 16:05:49 -0300116{
117 ChardevInfoList *char_info, *info;
118
119 char_info = qmp_query_chardev(NULL);
120 for (info = char_info; info; info = info->next) {
121 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
122 info->value->filename);
123 }
124
125 qapi_free_ChardevInfoList(char_info);
126}
Luiz Capitulino7a7f3252011-09-15 14:20:28 -0300127
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800128void hmp_info_mice(Monitor *mon, const QDict *qdict)
Luiz Capitulinoe235cec2011-09-21 15:29:55 -0300129{
130 MouseInfoList *mice_list, *mouse;
131
132 mice_list = qmp_query_mice(NULL);
133 if (!mice_list) {
134 monitor_printf(mon, "No mouse devices connected\n");
135 return;
136 }
137
138 for (mouse = mice_list; mouse; mouse = mouse->next) {
139 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
140 mouse->value->current ? '*' : ' ',
141 mouse->value->index, mouse->value->name,
142 mouse->value->absolute ? " (absolute)" : "");
143 }
144
145 qapi_free_MouseInfoList(mice_list);
146}
147
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800148void hmp_info_migrate(Monitor *mon, const QDict *qdict)
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300149{
150 MigrationInfo *info;
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300151 MigrationCapabilityStatusList *caps, *cap;
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300152
153 info = qmp_query_migrate(NULL);
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300154 caps = qmp_query_migrate_capabilities(NULL);
155
156 /* do not display parameters during setup */
157 if (info->has_status && caps) {
158 monitor_printf(mon, "capabilities: ");
159 for (cap = caps; cap; cap = cap->next) {
160 monitor_printf(mon, "%s: %s ",
161 MigrationCapability_lookup[cap->value->capability],
162 cap->value->state ? "on" : "off");
163 }
164 monitor_printf(mon, "\n");
165 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300166
167 if (info->has_status) {
zhanghailiang24b8c392015-03-13 16:08:40 +0800168 monitor_printf(mon, "Migration status: %s\n",
169 MigrationStatus_lookup[info->status]);
Juan Quintela7aa939a2012-08-18 13:17:10 +0200170 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
171 info->total_time);
Juan Quintela2c52ddf2012-08-13 09:53:12 +0200172 if (info->has_expected_downtime) {
173 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
174 info->expected_downtime);
175 }
Juan Quintela9c5a9fc2012-08-13 09:35:16 +0200176 if (info->has_downtime) {
177 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
178 info->downtime);
179 }
Michael R. Hinesed4fbd12013-07-22 10:01:58 -0400180 if (info->has_setup_time) {
181 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
182 info->setup_time);
183 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300184 }
185
186 if (info->has_ram) {
187 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
188 info->ram->transferred >> 10);
Michael R. Hines7e114f82013-06-25 21:35:30 -0400189 monitor_printf(mon, "throughput: %0.2f mbps\n",
190 info->ram->mbps);
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300191 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
192 info->ram->remaining >> 10);
193 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
194 info->ram->total >> 10);
Orit Wasserman004d4c12012-08-06 21:42:56 +0300195 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
196 info->ram->duplicate);
Peter Lievenf1c72792013-03-26 10:58:37 +0100197 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
198 info->ram->skipped);
Orit Wasserman004d4c12012-08-06 21:42:56 +0300199 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
200 info->ram->normal);
201 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
202 info->ram->normal_bytes >> 10);
ChenLiang58570ed2014-04-04 17:57:55 +0800203 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
204 info->ram->dirty_sync_count);
Juan Quintela8d017192012-08-13 12:31:25 +0200205 if (info->ram->dirty_pages_rate) {
206 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
207 info->ram->dirty_pages_rate);
208 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300209 }
210
211 if (info->has_disk) {
212 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
213 info->disk->transferred >> 10);
214 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
215 info->disk->remaining >> 10);
216 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
217 info->disk->total >> 10);
218 }
219
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300220 if (info->has_xbzrle_cache) {
221 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
222 info->xbzrle_cache->cache_size);
223 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
224 info->xbzrle_cache->bytes >> 10);
225 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
226 info->xbzrle_cache->pages);
227 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
228 info->xbzrle_cache->cache_miss);
ChenLiang8bc39232014-04-04 17:57:56 +0800229 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
230 info->xbzrle_cache->cache_miss_rate);
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300231 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
232 info->xbzrle_cache->overflow);
233 }
234
Jason J. Herne47828932015-09-08 13:12:36 -0400235 if (info->has_x_cpu_throttle_percentage) {
236 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
237 info->x_cpu_throttle_percentage);
238 }
239
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300240 qapi_free_MigrationInfo(info);
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300241 qapi_free_MigrationCapabilityStatusList(caps);
242}
243
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800244void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300245{
246 MigrationCapabilityStatusList *caps, *cap;
247
248 caps = qmp_query_migrate_capabilities(NULL);
249
250 if (caps) {
251 monitor_printf(mon, "capabilities: ");
252 for (cap = caps; cap; cap = cap->next) {
253 monitor_printf(mon, "%s: %s ",
254 MigrationCapability_lookup[cap->value->capability],
255 cap->value->state ? "on" : "off");
256 }
257 monitor_printf(mon, "\n");
258 }
259
260 qapi_free_MigrationCapabilityStatusList(caps);
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300261}
262
Liang Li50e9a622015-03-23 16:32:29 +0800263void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
264{
265 MigrationParameters *params;
266
267 params = qmp_query_migrate_parameters(NULL);
268
269 if (params) {
270 monitor_printf(mon, "parameters:");
271 monitor_printf(mon, " %s: %" PRId64,
272 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_LEVEL],
273 params->compress_level);
274 monitor_printf(mon, " %s: %" PRId64,
275 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_THREADS],
276 params->compress_threads);
277 monitor_printf(mon, " %s: %" PRId64,
278 MigrationParameter_lookup[MIGRATION_PARAMETER_DECOMPRESS_THREADS],
279 params->decompress_threads);
Jason J. Herne1626fee2015-09-08 13:12:34 -0400280 monitor_printf(mon, " %s: %" PRId64,
281 MigrationParameter_lookup[MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL],
282 params->x_cpu_throttle_initial);
283 monitor_printf(mon, " %s: %" PRId64,
284 MigrationParameter_lookup[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT],
285 params->x_cpu_throttle_increment);
Liang Li50e9a622015-03-23 16:32:29 +0800286 monitor_printf(mon, "\n");
287 }
288
289 qapi_free_MigrationParameters(params);
290}
291
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800292void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +0300293{
294 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
295 qmp_query_migrate_cache_size(NULL) >> 10);
296}
297
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800298void hmp_info_cpus(Monitor *mon, const QDict *qdict)
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300299{
300 CpuInfoList *cpu_list, *cpu;
301
302 cpu_list = qmp_query_cpus(NULL);
303
304 for (cpu = cpu_list; cpu; cpu = cpu->next) {
305 int active = ' ';
306
307 if (cpu->value->CPU == monitor_get_cpu_index()) {
308 active = '*';
309 }
310
Aurelien Jarno852bef02012-10-19 23:19:19 +0200311 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300312
313 if (cpu->value->has_pc) {
Aurelien Jarno852bef02012-10-19 23:19:19 +0200314 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->pc);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300315 }
316 if (cpu->value->has_nip) {
Aurelien Jarno852bef02012-10-19 23:19:19 +0200317 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->nip);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300318 }
319 if (cpu->value->has_npc) {
Aurelien Jarno852bef02012-10-19 23:19:19 +0200320 monitor_printf(mon, " npc=0x%016" PRIx64, cpu->value->npc);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300321 }
322 if (cpu->value->has_PC) {
Aurelien Jarno852bef02012-10-19 23:19:19 +0200323 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->PC);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300324 }
325
326 if (cpu->value->halted) {
327 monitor_printf(mon, " (halted)");
328 }
329
330 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
331 }
332
333 qapi_free_CpuInfoList(cpu_list);
334}
335
Kevin Wolf289b2762014-09-15 12:06:39 +0200336static void print_block_info(Monitor *mon, BlockInfo *info,
337 BlockDeviceInfo *inserted, bool verbose)
338{
339 ImageInfo *image_info;
340
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200341 assert(!info || !info->has_inserted || info->inserted == inserted);
342
343 if (info) {
344 monitor_printf(mon, "%s", info->device);
345 if (inserted && inserted->has_node_name) {
346 monitor_printf(mon, " (%s)", inserted->node_name);
347 }
348 } else {
349 assert(inserted);
350 monitor_printf(mon, "%s",
351 inserted->has_node_name
352 ? inserted->node_name
353 : "<anonymous>");
354 }
355
Kevin Wolf289b2762014-09-15 12:06:39 +0200356 if (inserted) {
357 monitor_printf(mon, ": %s (%s%s%s)\n",
358 inserted->file,
359 inserted->drv,
360 inserted->ro ? ", read-only" : "",
361 inserted->encrypted ? ", encrypted" : "");
362 } else {
363 monitor_printf(mon, ": [not inserted]\n");
364 }
365
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200366 if (info) {
367 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
368 monitor_printf(mon, " I/O status: %s\n",
369 BlockDeviceIoStatus_lookup[info->io_status]);
370 }
Kevin Wolf289b2762014-09-15 12:06:39 +0200371
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200372 if (info->removable) {
373 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
374 info->locked ? "" : "not ",
375 info->tray_open ? "open" : "closed");
376 }
Kevin Wolf289b2762014-09-15 12:06:39 +0200377 }
378
379
380 if (!inserted) {
381 return;
382 }
383
384 monitor_printf(mon, " Cache mode: %s%s%s\n",
385 inserted->cache->writeback ? "writeback" : "writethrough",
386 inserted->cache->direct ? ", direct" : "",
387 inserted->cache->no_flush ? ", ignore flushes" : "");
388
389 if (inserted->has_backing_file) {
390 monitor_printf(mon,
391 " Backing file: %s "
392 "(chain depth: %" PRId64 ")\n",
393 inserted->backing_file,
394 inserted->backing_file_depth);
395 }
396
397 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
398 monitor_printf(mon, " Detect zeroes: %s\n",
399 BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]);
400 }
401
402 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
403 inserted->iops || inserted->iops_rd || inserted->iops_wr)
404 {
405 monitor_printf(mon, " I/O throttling: bps=%" PRId64
406 " bps_rd=%" PRId64 " bps_wr=%" PRId64
407 " bps_max=%" PRId64
408 " bps_rd_max=%" PRId64
409 " bps_wr_max=%" PRId64
410 " iops=%" PRId64 " iops_rd=%" PRId64
411 " iops_wr=%" PRId64
412 " iops_max=%" PRId64
413 " iops_rd_max=%" PRId64
414 " iops_wr_max=%" PRId64
Alberto Garciab8fe1692015-06-08 18:17:46 +0200415 " iops_size=%" PRId64
416 " group=%s\n",
Kevin Wolf289b2762014-09-15 12:06:39 +0200417 inserted->bps,
418 inserted->bps_rd,
419 inserted->bps_wr,
420 inserted->bps_max,
421 inserted->bps_rd_max,
422 inserted->bps_wr_max,
423 inserted->iops,
424 inserted->iops_rd,
425 inserted->iops_wr,
426 inserted->iops_max,
427 inserted->iops_rd_max,
428 inserted->iops_wr_max,
Alberto Garciab8fe1692015-06-08 18:17:46 +0200429 inserted->iops_size,
430 inserted->group);
Kevin Wolf289b2762014-09-15 12:06:39 +0200431 }
432
Stefan Hajnoczi94198742015-04-22 11:15:10 +0100433 if (verbose) {
Kevin Wolf289b2762014-09-15 12:06:39 +0200434 monitor_printf(mon, "\nImages:\n");
435 image_info = inserted->image;
436 while (1) {
437 bdrv_image_info_dump((fprintf_function)monitor_printf,
438 mon, image_info);
439 if (image_info->has_backing_image) {
440 image_info = image_info->backing_image;
441 } else {
442 break;
443 }
444 }
445 }
446}
447
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800448void hmp_info_block(Monitor *mon, const QDict *qdict)
Luiz Capitulinob2023812011-09-21 17:16:47 -0300449{
450 BlockInfoList *block_list, *info;
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200451 BlockDeviceInfoList *blockdev_list, *blockdev;
Wenchao Xiae73fe2b2013-06-06 12:28:01 +0800452 const char *device = qdict_get_try_str(qdict, "device");
Eric Blake34acbc92015-05-15 16:25:00 -0600453 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
454 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200455 bool printed = false;
Luiz Capitulinob2023812011-09-21 17:16:47 -0300456
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200457 /* Print BlockBackend information */
458 if (!nodes) {
Stefan Weilf19e44b2015-02-08 15:40:48 +0100459 block_list = qmp_query_block(NULL);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200460 } else {
461 block_list = NULL;
462 }
Luiz Capitulinob2023812011-09-21 17:16:47 -0300463
464 for (info = block_list; info; info = info->next) {
Wenchao Xiae73fe2b2013-06-06 12:28:01 +0800465 if (device && strcmp(device, info->value->device)) {
466 continue;
467 }
Luiz Capitulinob2023812011-09-21 17:16:47 -0300468
Kevin Wolffbe2e262013-06-19 16:10:55 +0200469 if (info != block_list) {
470 monitor_printf(mon, "\n");
Luiz Capitulinob2023812011-09-21 17:16:47 -0300471 }
472
Kevin Wolf289b2762014-09-15 12:06:39 +0200473 print_block_info(mon, info->value, info->value->has_inserted
474 ? info->value->inserted : NULL,
475 verbose);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200476 printed = true;
Luiz Capitulinob2023812011-09-21 17:16:47 -0300477 }
478
479 qapi_free_BlockInfoList(block_list);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200480
481 if ((!device && !nodes) || printed) {
482 return;
483 }
484
485 /* Print node information */
486 blockdev_list = qmp_query_named_block_nodes(NULL);
487 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
488 assert(blockdev->value->has_node_name);
489 if (device && strcmp(device, blockdev->value->node_name)) {
490 continue;
491 }
492
493 if (blockdev != blockdev_list) {
494 monitor_printf(mon, "\n");
495 }
496
497 print_block_info(mon, NULL, blockdev->value, verbose);
498 }
499 qapi_free_BlockDeviceInfoList(blockdev_list);
Luiz Capitulinob2023812011-09-21 17:16:47 -0300500}
501
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800502void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300503{
504 BlockStatsList *stats_list, *stats;
505
Fam Zhengf71eaa72014-10-31 11:32:57 +0800506 stats_list = qmp_query_blockstats(false, false, NULL);
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300507
508 for (stats = stats_list; stats; stats = stats->next) {
509 if (!stats->value->has_device) {
510 continue;
511 }
512
513 monitor_printf(mon, "%s:", stats->value->device);
514 monitor_printf(mon, " rd_bytes=%" PRId64
515 " wr_bytes=%" PRId64
516 " rd_operations=%" PRId64
517 " wr_operations=%" PRId64
518 " flush_operations=%" PRId64
519 " wr_total_time_ns=%" PRId64
520 " rd_total_time_ns=%" PRId64
521 " flush_total_time_ns=%" PRId64
Peter Lievenf4564d52015-02-02 14:52:18 +0100522 " rd_merged=%" PRId64
523 " wr_merged=%" PRId64
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300524 "\n",
525 stats->value->stats->rd_bytes,
526 stats->value->stats->wr_bytes,
527 stats->value->stats->rd_operations,
528 stats->value->stats->wr_operations,
529 stats->value->stats->flush_operations,
530 stats->value->stats->wr_total_time_ns,
531 stats->value->stats->rd_total_time_ns,
Peter Lievenf4564d52015-02-02 14:52:18 +0100532 stats->value->stats->flush_total_time_ns,
533 stats->value->stats->rd_merged,
534 stats->value->stats->wr_merged);
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300535 }
536
537 qapi_free_BlockStatsList(stats_list);
538}
539
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800540void hmp_info_vnc(Monitor *mon, const QDict *qdict)
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200541{
542 VncInfo *info;
543 Error *err = NULL;
544 VncClientInfoList *client;
545
546 info = qmp_query_vnc(&err);
547 if (err) {
548 monitor_printf(mon, "%s\n", error_get_pretty(err));
549 error_free(err);
550 return;
551 }
552
553 if (!info->enabled) {
554 monitor_printf(mon, "Server: disabled\n");
555 goto out;
556 }
557
558 monitor_printf(mon, "Server:\n");
559 if (info->has_host && info->has_service) {
560 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
561 }
562 if (info->has_auth) {
563 monitor_printf(mon, " auth: %s\n", info->auth);
564 }
565
566 if (!info->has_clients || info->clients == NULL) {
567 monitor_printf(mon, "Client: none\n");
568 } else {
569 for (client = info->clients; client; client = client->next) {
570 monitor_printf(mon, "Client:\n");
571 monitor_printf(mon, " address: %s:%s\n",
Eric Blakeddf21902015-10-26 16:34:49 -0600572 client->value->host,
573 client->value->service);
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200574 monitor_printf(mon, " x509_dname: %s\n",
575 client->value->x509_dname ?
576 client->value->x509_dname : "none");
577 monitor_printf(mon, " username: %s\n",
578 client->value->has_sasl_username ?
579 client->value->sasl_username : "none");
580 }
581 }
582
583out:
584 qapi_free_VncInfo(info);
585}
586
Markus Armbruster206addd2015-01-13 15:46:39 +0100587#ifdef CONFIG_SPICE
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800588void hmp_info_spice(Monitor *mon, const QDict *qdict)
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200589{
590 SpiceChannelList *chan;
591 SpiceInfo *info;
Cole Robinson22fa7da2015-03-01 09:29:18 -0500592 const char *channel_name;
593 const char * const channel_names[] = {
594 [SPICE_CHANNEL_MAIN] = "main",
595 [SPICE_CHANNEL_DISPLAY] = "display",
596 [SPICE_CHANNEL_INPUTS] = "inputs",
597 [SPICE_CHANNEL_CURSOR] = "cursor",
598 [SPICE_CHANNEL_PLAYBACK] = "playback",
599 [SPICE_CHANNEL_RECORD] = "record",
600 [SPICE_CHANNEL_TUNNEL] = "tunnel",
601 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
602 [SPICE_CHANNEL_USBREDIR] = "usbredir",
603 [SPICE_CHANNEL_PORT] = "port",
Gerd Hoffmann7c6044a2015-03-03 09:27:28 +0100604#if 0
605 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
606 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
607 * as quick fix for build failures with older versions. */
Cole Robinson22fa7da2015-03-01 09:29:18 -0500608 [SPICE_CHANNEL_WEBDAV] = "webdav",
Gerd Hoffmann7c6044a2015-03-03 09:27:28 +0100609#endif
Cole Robinson22fa7da2015-03-01 09:29:18 -0500610 };
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200611
612 info = qmp_query_spice(NULL);
613
614 if (!info->enabled) {
615 monitor_printf(mon, "Server: disabled\n");
616 goto out;
617 }
618
619 monitor_printf(mon, "Server:\n");
620 if (info->has_port) {
621 monitor_printf(mon, " address: %s:%" PRId64 "\n",
622 info->host, info->port);
623 }
624 if (info->has_tls_port) {
625 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
626 info->host, info->tls_port);
627 }
Yonit Halperin61c4efe2012-08-21 11:51:58 +0300628 monitor_printf(mon, " migrated: %s\n",
629 info->migrated ? "true" : "false");
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200630 monitor_printf(mon, " auth: %s\n", info->auth);
631 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
Alon Levy4efee022012-03-29 23:23:14 +0200632 monitor_printf(mon, " mouse-mode: %s\n",
633 SpiceQueryMouseMode_lookup[info->mouse_mode]);
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200634
635 if (!info->has_channels || info->channels == NULL) {
636 monitor_printf(mon, "Channels: none\n");
637 } else {
638 for (chan = info->channels; chan; chan = chan->next) {
639 monitor_printf(mon, "Channel:\n");
640 monitor_printf(mon, " address: %s:%s%s\n",
Eric Blakeddf21902015-10-26 16:34:49 -0600641 chan->value->host, chan->value->port,
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200642 chan->value->tls ? " [tls]" : "");
643 monitor_printf(mon, " session: %" PRId64 "\n",
644 chan->value->connection_id);
645 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
646 chan->value->channel_type, chan->value->channel_id);
Cole Robinson22fa7da2015-03-01 09:29:18 -0500647
648 channel_name = "unknown";
649 if (chan->value->channel_type > 0 &&
650 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
651 channel_names[chan->value->channel_type]) {
652 channel_name = channel_names[chan->value->channel_type];
653 }
654
655 monitor_printf(mon, " channel name: %s\n", channel_name);
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200656 }
657 }
658
659out:
660 qapi_free_SpiceInfo(info);
661}
Markus Armbruster206addd2015-01-13 15:46:39 +0100662#endif
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200663
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800664void hmp_info_balloon(Monitor *mon, const QDict *qdict)
Luiz Capitulino96637bc2011-10-21 11:41:37 -0200665{
666 BalloonInfo *info;
667 Error *err = NULL;
668
669 info = qmp_query_balloon(&err);
670 if (err) {
671 monitor_printf(mon, "%s\n", error_get_pretty(err));
672 error_free(err);
673 return;
674 }
675
Luiz Capitulino01ceb972012-12-03 15:56:41 -0200676 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
Luiz Capitulino96637bc2011-10-21 11:41:37 -0200677
678 qapi_free_BalloonInfo(info);
679}
680
Luiz Capitulino79627472011-10-21 14:15:33 -0200681static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
682{
683 PciMemoryRegionList *region;
684
685 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
686 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
687 dev->slot, dev->function);
688 monitor_printf(mon, " ");
689
Eric Blake9fa02cd2015-05-04 09:05:32 -0600690 if (dev->class_info->has_desc) {
691 monitor_printf(mon, "%s", dev->class_info->desc);
Luiz Capitulino79627472011-10-21 14:15:33 -0200692 } else {
Eric Blake9fa02cd2015-05-04 09:05:32 -0600693 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
Luiz Capitulino79627472011-10-21 14:15:33 -0200694 }
695
696 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600697 dev->id->vendor, dev->id->device);
Luiz Capitulino79627472011-10-21 14:15:33 -0200698
699 if (dev->has_irq) {
700 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
701 }
702
703 if (dev->has_pci_bridge) {
704 monitor_printf(mon, " BUS %" PRId64 ".\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600705 dev->pci_bridge->bus->number);
Luiz Capitulino79627472011-10-21 14:15:33 -0200706 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600707 dev->pci_bridge->bus->secondary);
Luiz Capitulino79627472011-10-21 14:15:33 -0200708 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600709 dev->pci_bridge->bus->subordinate);
Luiz Capitulino79627472011-10-21 14:15:33 -0200710
711 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600712 dev->pci_bridge->bus->io_range->base,
713 dev->pci_bridge->bus->io_range->limit);
Luiz Capitulino79627472011-10-21 14:15:33 -0200714
715 monitor_printf(mon,
716 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600717 dev->pci_bridge->bus->memory_range->base,
718 dev->pci_bridge->bus->memory_range->limit);
Luiz Capitulino79627472011-10-21 14:15:33 -0200719
720 monitor_printf(mon, " prefetchable memory range "
721 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600722 dev->pci_bridge->bus->prefetchable_range->base,
723 dev->pci_bridge->bus->prefetchable_range->limit);
Luiz Capitulino79627472011-10-21 14:15:33 -0200724 }
725
726 for (region = dev->regions; region; region = region->next) {
727 uint64_t addr, size;
728
729 addr = region->value->address;
730 size = region->value->size;
731
732 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
733
734 if (!strcmp(region->value->type, "io")) {
735 monitor_printf(mon, "I/O at 0x%04" PRIx64
736 " [0x%04" PRIx64 "].\n",
737 addr, addr + size - 1);
738 } else {
739 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
740 " [0x%08" PRIx64 "].\n",
741 region->value->mem_type_64 ? 64 : 32,
742 region->value->prefetch ? " prefetchable" : "",
743 addr, addr + size - 1);
744 }
745 }
746
747 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
748
749 if (dev->has_pci_bridge) {
750 if (dev->pci_bridge->has_devices) {
751 PciDeviceInfoList *cdev;
752 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
753 hmp_info_pci_device(mon, cdev->value);
754 }
755 }
756 }
757}
758
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800759void hmp_info_pci(Monitor *mon, const QDict *qdict)
Luiz Capitulino79627472011-10-21 14:15:33 -0200760{
Stefan Bergerf46cee32012-01-11 10:51:52 -0500761 PciInfoList *info_list, *info;
Luiz Capitulino79627472011-10-21 14:15:33 -0200762 Error *err = NULL;
763
Stefan Bergerf46cee32012-01-11 10:51:52 -0500764 info_list = qmp_query_pci(&err);
Luiz Capitulino79627472011-10-21 14:15:33 -0200765 if (err) {
766 monitor_printf(mon, "PCI devices not supported\n");
767 error_free(err);
768 return;
769 }
770
Stefan Bergerf46cee32012-01-11 10:51:52 -0500771 for (info = info_list; info; info = info->next) {
Luiz Capitulino79627472011-10-21 14:15:33 -0200772 PciDeviceInfoList *dev;
773
774 for (dev = info->value->devices; dev; dev = dev->next) {
775 hmp_info_pci_device(mon, dev->value);
776 }
777 }
778
Stefan Bergerf46cee32012-01-11 10:51:52 -0500779 qapi_free_PciInfoList(info_list);
Luiz Capitulino79627472011-10-21 14:15:33 -0200780}
781
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800782void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
Stefan Hajnoczifb5458c2012-01-18 14:40:49 +0000783{
784 BlockJobInfoList *list;
785 Error *err = NULL;
786
787 list = qmp_query_block_jobs(&err);
788 assert(!err);
789
790 if (!list) {
791 monitor_printf(mon, "No active jobs\n");
792 return;
793 }
794
795 while (list) {
796 if (strcmp(list->value->type, "stream") == 0) {
797 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
798 " of %" PRId64 " bytes, speed limit %" PRId64
799 " bytes/s\n",
800 list->value->device,
801 list->value->offset,
802 list->value->len,
803 list->value->speed);
804 } else {
805 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
806 " of %" PRId64 " bytes, speed limit %" PRId64
807 " bytes/s\n",
808 list->value->type,
809 list->value->device,
810 list->value->offset,
811 list->value->len,
812 list->value->speed);
813 }
814 list = list->next;
815 }
Gonglei93bb1312014-09-16 21:36:55 +0800816
817 qapi_free_BlockJobInfoList(list);
Stefan Hajnoczifb5458c2012-01-18 14:40:49 +0000818}
819
Stefan Bergerd1a0cf72013-02-27 12:47:49 -0500820void hmp_info_tpm(Monitor *mon, const QDict *qdict)
821{
822 TPMInfoList *info_list, *info;
823 Error *err = NULL;
824 unsigned int c = 0;
825 TPMPassthroughOptions *tpo;
826
827 info_list = qmp_query_tpm(&err);
828 if (err) {
829 monitor_printf(mon, "TPM device not supported\n");
830 error_free(err);
831 return;
832 }
833
834 if (info_list) {
835 monitor_printf(mon, "TPM device:\n");
836 }
837
838 for (info = info_list; info; info = info->next) {
839 TPMInfo *ti = info->value;
840 monitor_printf(mon, " tpm%d: model=%s\n",
841 c, TpmModel_lookup[ti->model]);
842
843 monitor_printf(mon, " \\ %s: type=%s",
Corey Bryant88ca7bc2013-03-20 12:34:48 -0400844 ti->id, TpmTypeOptionsKind_lookup[ti->options->kind]);
Stefan Bergerd1a0cf72013-02-27 12:47:49 -0500845
Corey Bryant88ca7bc2013-03-20 12:34:48 -0400846 switch (ti->options->kind) {
847 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
848 tpo = ti->options->passthrough;
Stefan Bergerd1a0cf72013-02-27 12:47:49 -0500849 monitor_printf(mon, "%s%s%s%s",
850 tpo->has_path ? ",path=" : "",
851 tpo->has_path ? tpo->path : "",
852 tpo->has_cancel_path ? ",cancel-path=" : "",
853 tpo->has_cancel_path ? tpo->cancel_path : "");
854 break;
855 case TPM_TYPE_OPTIONS_KIND_MAX:
856 break;
857 }
858 monitor_printf(mon, "\n");
859 c++;
860 }
861 qapi_free_TPMInfoList(info_list);
862}
863
Luiz Capitulino7a7f3252011-09-15 14:20:28 -0300864void hmp_quit(Monitor *mon, const QDict *qdict)
865{
866 monitor_suspend(mon);
867 qmp_quit(NULL);
868}
Luiz Capitulino5f158f22011-09-15 14:34:39 -0300869
870void hmp_stop(Monitor *mon, const QDict *qdict)
871{
872 qmp_stop(NULL);
873}
Luiz Capitulino38d22652011-09-15 14:41:46 -0300874
875void hmp_system_reset(Monitor *mon, const QDict *qdict)
876{
877 qmp_system_reset(NULL);
878}
Luiz Capitulino5bc465e2011-09-28 11:06:15 -0300879
880void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
881{
882 qmp_system_powerdown(NULL);
883}
Luiz Capitulino755f1962011-10-06 14:31:39 -0300884
885void hmp_cpu(Monitor *mon, const QDict *qdict)
886{
887 int64_t cpu_index;
888
889 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
890 use it are converted to the QAPI */
891 cpu_index = qdict_get_int(qdict, "index");
892 if (monitor_set_cpu(cpu_index) < 0) {
893 monitor_printf(mon, "invalid CPU index\n");
894 }
895}
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -0200896
897void hmp_memsave(Monitor *mon, const QDict *qdict)
898{
899 uint32_t size = qdict_get_int(qdict, "size");
900 const char *filename = qdict_get_str(qdict, "filename");
901 uint64_t addr = qdict_get_int(qdict, "val");
Markus Armbrustere940f542014-05-02 13:26:29 +0200902 Error *err = NULL;
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -0200903
Markus Armbrustere940f542014-05-02 13:26:29 +0200904 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &err);
905 hmp_handle_error(mon, &err);
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -0200906}
Luiz Capitulino6d3962b2011-11-22 17:26:46 -0200907
908void hmp_pmemsave(Monitor *mon, const QDict *qdict)
909{
910 uint32_t size = qdict_get_int(qdict, "size");
911 const char *filename = qdict_get_str(qdict, "filename");
912 uint64_t addr = qdict_get_int(qdict, "val");
Markus Armbrustere940f542014-05-02 13:26:29 +0200913 Error *err = NULL;
Luiz Capitulino6d3962b2011-11-22 17:26:46 -0200914
Markus Armbrustere940f542014-05-02 13:26:29 +0200915 qmp_pmemsave(addr, size, filename, &err);
916 hmp_handle_error(mon, &err);
Luiz Capitulino6d3962b2011-11-22 17:26:46 -0200917}
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200918
Markus Armbruster3949e592013-02-06 21:27:24 +0100919void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
Lei Li1f590cf2013-01-25 00:03:20 +0800920{
Lei Li1f590cf2013-01-25 00:03:20 +0800921 const char *chardev = qdict_get_str(qdict, "device");
922 const char *data = qdict_get_str(qdict, "data");
Markus Armbrustere940f542014-05-02 13:26:29 +0200923 Error *err = NULL;
Lei Li1f590cf2013-01-25 00:03:20 +0800924
Markus Armbrustere940f542014-05-02 13:26:29 +0200925 qmp_ringbuf_write(chardev, data, false, 0, &err);
Lei Li1f590cf2013-01-25 00:03:20 +0800926
Markus Armbrustere940f542014-05-02 13:26:29 +0200927 hmp_handle_error(mon, &err);
Lei Li1f590cf2013-01-25 00:03:20 +0800928}
929
Markus Armbruster3949e592013-02-06 21:27:24 +0100930void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
Lei Li49b6d722013-01-25 00:03:21 +0800931{
932 uint32_t size = qdict_get_int(qdict, "size");
933 const char *chardev = qdict_get_str(qdict, "device");
Markus Armbruster3ab651f2013-02-06 21:27:15 +0100934 char *data;
Markus Armbrustere940f542014-05-02 13:26:29 +0200935 Error *err = NULL;
Markus Armbruster543f3412013-02-06 21:27:26 +0100936 int i;
Lei Li49b6d722013-01-25 00:03:21 +0800937
Markus Armbrustere940f542014-05-02 13:26:29 +0200938 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
939 if (err) {
940 monitor_printf(mon, "%s\n", error_get_pretty(err));
941 error_free(err);
Lei Li49b6d722013-01-25 00:03:21 +0800942 return;
943 }
944
Markus Armbruster543f3412013-02-06 21:27:26 +0100945 for (i = 0; data[i]; i++) {
946 unsigned char ch = data[i];
947
948 if (ch == '\\') {
949 monitor_printf(mon, "\\\\");
950 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
951 monitor_printf(mon, "\\u%04X", ch);
952 } else {
953 monitor_printf(mon, "%c", ch);
954 }
955
956 }
957 monitor_printf(mon, "\n");
Markus Armbruster3ab651f2013-02-06 21:27:15 +0100958 g_free(data);
Lei Li49b6d722013-01-25 00:03:21 +0800959}
960
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200961static void hmp_cont_cb(void *opaque, int err)
962{
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200963 if (!err) {
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300964 qmp_cont(NULL);
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200965 }
966}
967
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300968static bool key_is_missing(const BlockInfo *bdev)
969{
970 return (bdev->inserted && bdev->inserted->encryption_key_missing);
971}
972
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200973void hmp_cont(Monitor *mon, const QDict *qdict)
974{
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300975 BlockInfoList *bdev_list, *bdev;
Markus Armbrustere940f542014-05-02 13:26:29 +0200976 Error *err = NULL;
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200977
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300978 bdev_list = qmp_query_block(NULL);
979 for (bdev = bdev_list; bdev; bdev = bdev->next) {
980 if (key_is_missing(bdev->value)) {
981 monitor_read_block_device_key(mon, bdev->value->device,
982 hmp_cont_cb, NULL);
983 goto out;
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200984 }
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200985 }
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300986
Markus Armbrustere940f542014-05-02 13:26:29 +0200987 qmp_cont(&err);
988 hmp_handle_error(mon, &err);
Luiz Capitulino8b7f6fb2012-07-26 20:41:53 -0300989
990out:
991 qapi_free_BlockInfoList(bdev_list);
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200992}
Luiz Capitulinoab49ab52011-11-23 12:55:53 -0200993
Gerd Hoffmann9b9df252012-02-23 13:45:21 +0100994void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
995{
996 qmp_system_wakeup(NULL);
997}
998
Markus Armbruster3e5a50d2015-02-06 13:55:43 +0100999void hmp_nmi(Monitor *mon, const QDict *qdict)
Luiz Capitulinoab49ab52011-11-23 12:55:53 -02001000{
Markus Armbrustere940f542014-05-02 13:26:29 +02001001 Error *err = NULL;
Luiz Capitulinoab49ab52011-11-23 12:55:53 -02001002
Markus Armbrustere940f542014-05-02 13:26:29 +02001003 qmp_inject_nmi(&err);
1004 hmp_handle_error(mon, &err);
Luiz Capitulinoab49ab52011-11-23 12:55:53 -02001005}
Luiz Capitulino4b371562011-11-23 13:11:55 -02001006
1007void hmp_set_link(Monitor *mon, const QDict *qdict)
1008{
1009 const char *name = qdict_get_str(qdict, "name");
Eric Blake34acbc92015-05-15 16:25:00 -06001010 bool up = qdict_get_bool(qdict, "up");
Markus Armbrustere940f542014-05-02 13:26:29 +02001011 Error *err = NULL;
Luiz Capitulino4b371562011-11-23 13:11:55 -02001012
Markus Armbrustere940f542014-05-02 13:26:29 +02001013 qmp_set_link(name, up, &err);
1014 hmp_handle_error(mon, &err);
Luiz Capitulino4b371562011-11-23 13:11:55 -02001015}
Luiz Capitulinoa4dea8a2011-11-23 13:28:21 -02001016
1017void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1018{
1019 const char *device = qdict_get_str(qdict, "device");
1020 const char *password = qdict_get_str(qdict, "password");
Markus Armbrustere940f542014-05-02 13:26:29 +02001021 Error *err = NULL;
Luiz Capitulinoa4dea8a2011-11-23 13:28:21 -02001022
Markus Armbrustere940f542014-05-02 13:26:29 +02001023 qmp_block_passwd(true, device, false, NULL, password, &err);
1024 hmp_handle_error(mon, &err);
Luiz Capitulinoa4dea8a2011-11-23 13:28:21 -02001025}
Luiz Capitulinod72f3262011-11-25 14:38:09 -02001026
1027void hmp_balloon(Monitor *mon, const QDict *qdict)
1028{
1029 int64_t value = qdict_get_int(qdict, "value");
Markus Armbrustere940f542014-05-02 13:26:29 +02001030 Error *err = NULL;
Luiz Capitulinod72f3262011-11-25 14:38:09 -02001031
Markus Armbrustere940f542014-05-02 13:26:29 +02001032 qmp_balloon(value, &err);
1033 if (err) {
1034 monitor_printf(mon, "balloon: %s\n", error_get_pretty(err));
1035 error_free(err);
Luiz Capitulinod72f3262011-11-25 14:38:09 -02001036 }
1037}
Luiz Capitulino5e7caac2011-11-25 14:57:10 -02001038
1039void hmp_block_resize(Monitor *mon, const QDict *qdict)
1040{
1041 const char *device = qdict_get_str(qdict, "device");
1042 int64_t size = qdict_get_int(qdict, "size");
Markus Armbrustere940f542014-05-02 13:26:29 +02001043 Error *err = NULL;
Luiz Capitulino5e7caac2011-11-25 14:57:10 -02001044
Markus Armbrustere940f542014-05-02 13:26:29 +02001045 qmp_block_resize(true, device, false, NULL, size, &err);
1046 hmp_handle_error(mon, &err);
Luiz Capitulino5e7caac2011-11-25 14:57:10 -02001047}
Luiz Capitulino6106e242011-11-25 16:15:19 -02001048
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001049void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1050{
1051 const char *device = qdict_get_str(qdict, "device");
1052 const char *filename = qdict_get_str(qdict, "target");
1053 const char *format = qdict_get_try_str(qdict, "format");
Eric Blake34acbc92015-05-15 16:25:00 -06001054 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1055 bool full = qdict_get_try_bool(qdict, "full", false);
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001056 enum NewImageMode mode;
Markus Armbrustere940f542014-05-02 13:26:29 +02001057 Error *err = NULL;
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001058
1059 if (!filename) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +01001060 error_setg(&err, QERR_MISSING_PARAMETER, "target");
Markus Armbrustere940f542014-05-02 13:26:29 +02001061 hmp_handle_error(mon, &err);
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001062 return;
1063 }
1064
1065 if (reuse) {
1066 mode = NEW_IMAGE_MODE_EXISTING;
1067 } else {
1068 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1069 }
1070
1071 qmp_drive_mirror(device, filename, !!format, format,
Benoît Canet09158f02014-06-27 18:25:25 +02001072 false, NULL, false, NULL,
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001073 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
Paolo Bonzini08e4ed62013-01-22 09:03:13 +01001074 true, mode, false, 0, false, 0, false, 0,
Fam Zheng0fc9f8e2015-06-08 13:56:08 +08001075 false, 0, false, 0, false, true, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +02001076 hmp_handle_error(mon, &err);
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001077}
1078
Stefan Hajnoczide909302013-06-26 14:11:58 +02001079void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1080{
1081 const char *device = qdict_get_str(qdict, "device");
1082 const char *filename = qdict_get_str(qdict, "target");
1083 const char *format = qdict_get_try_str(qdict, "format");
Eric Blake34acbc92015-05-15 16:25:00 -06001084 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1085 bool full = qdict_get_try_bool(qdict, "full", false);
Stefan Hajnoczide909302013-06-26 14:11:58 +02001086 enum NewImageMode mode;
Markus Armbrustere940f542014-05-02 13:26:29 +02001087 Error *err = NULL;
Stefan Hajnoczide909302013-06-26 14:11:58 +02001088
1089 if (!filename) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +01001090 error_setg(&err, QERR_MISSING_PARAMETER, "target");
Markus Armbrustere940f542014-05-02 13:26:29 +02001091 hmp_handle_error(mon, &err);
Stefan Hajnoczide909302013-06-26 14:11:58 +02001092 return;
1093 }
1094
1095 if (reuse) {
1096 mode = NEW_IMAGE_MODE_EXISTING;
1097 } else {
1098 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1099 }
1100
1101 qmp_drive_backup(device, filename, !!format, format,
1102 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
John Snowd58d8452015-04-17 19:49:58 -04001103 true, mode, false, 0, false, NULL,
1104 false, 0, false, 0, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +02001105 hmp_handle_error(mon, &err);
Stefan Hajnoczide909302013-06-26 14:11:58 +02001106}
1107
Luiz Capitulino6106e242011-11-25 16:15:19 -02001108void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1109{
1110 const char *device = qdict_get_str(qdict, "device");
1111 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1112 const char *format = qdict_get_try_str(qdict, "format");
Eric Blake34acbc92015-05-15 16:25:00 -06001113 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
Paolo Bonzini6cc2a412012-03-06 18:55:59 +01001114 enum NewImageMode mode;
Markus Armbrustere940f542014-05-02 13:26:29 +02001115 Error *err = NULL;
Luiz Capitulino6106e242011-11-25 16:15:19 -02001116
1117 if (!filename) {
1118 /* In the future, if 'snapshot-file' is not specified, the snapshot
1119 will be taken internally. Today it's actually required. */
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +01001120 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
Markus Armbrustere940f542014-05-02 13:26:29 +02001121 hmp_handle_error(mon, &err);
Luiz Capitulino6106e242011-11-25 16:15:19 -02001122 return;
1123 }
1124
Paolo Bonzini6cc2a412012-03-06 18:55:59 +01001125 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
Benoît Canet0901f672014-01-23 21:31:38 +01001126 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1127 filename, false, NULL,
1128 !!format, format,
Markus Armbrustere940f542014-05-02 13:26:29 +02001129 true, mode, &err);
1130 hmp_handle_error(mon, &err);
Luiz Capitulino6106e242011-11-25 16:15:19 -02001131}
Luiz Capitulino6cdedb02011-11-27 22:54:09 -02001132
Wenchao Xia775ca882013-09-11 14:04:37 +08001133void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1134{
1135 const char *device = qdict_get_str(qdict, "device");
1136 const char *name = qdict_get_str(qdict, "name");
Markus Armbrustere940f542014-05-02 13:26:29 +02001137 Error *err = NULL;
Wenchao Xia775ca882013-09-11 14:04:37 +08001138
Markus Armbrustere940f542014-05-02 13:26:29 +02001139 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1140 hmp_handle_error(mon, &err);
Wenchao Xia775ca882013-09-11 14:04:37 +08001141}
1142
Wenchao Xia7a4ed2e2013-09-11 14:04:38 +08001143void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1144{
1145 const char *device = qdict_get_str(qdict, "device");
1146 const char *name = qdict_get_str(qdict, "name");
1147 const char *id = qdict_get_try_str(qdict, "id");
Markus Armbrustere940f542014-05-02 13:26:29 +02001148 Error *err = NULL;
Wenchao Xia7a4ed2e2013-09-11 14:04:38 +08001149
1150 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
Markus Armbrustere940f542014-05-02 13:26:29 +02001151 true, name, &err);
1152 hmp_handle_error(mon, &err);
Wenchao Xia7a4ed2e2013-09-11 14:04:38 +08001153}
1154
Luiz Capitulino6cdedb02011-11-27 22:54:09 -02001155void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1156{
1157 qmp_migrate_cancel(NULL);
1158}
Luiz Capitulino4f0a9932011-11-27 23:18:01 -02001159
Dr. David Alan Gilbertbf1ae1f2015-02-19 11:40:28 +00001160void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1161{
1162 Error *err = NULL;
1163 const char *uri = qdict_get_str(qdict, "uri");
1164
1165 qmp_migrate_incoming(uri, &err);
1166
Dr. David Alan Gilbert1fa57f52015-02-26 14:54:39 +00001167 hmp_handle_error(mon, &err);
Dr. David Alan Gilbertbf1ae1f2015-02-19 11:40:28 +00001168}
1169
Luiz Capitulino4f0a9932011-11-27 23:18:01 -02001170void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1171{
1172 double value = qdict_get_double(qdict, "value");
1173 qmp_migrate_set_downtime(value, NULL);
1174}
Luiz Capitulino3dc85382011-11-28 11:59:37 -02001175
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +03001176void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1177{
1178 int64_t value = qdict_get_int(qdict, "value");
1179 Error *err = NULL;
1180
1181 qmp_migrate_set_cache_size(value, &err);
1182 if (err) {
1183 monitor_printf(mon, "%s\n", error_get_pretty(err));
1184 error_free(err);
1185 return;
1186 }
1187}
1188
Luiz Capitulino3dc85382011-11-28 11:59:37 -02001189void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1190{
1191 int64_t value = qdict_get_int(qdict, "value");
1192 qmp_migrate_set_speed(value, NULL);
1193}
Luiz Capitulinofbf796f2011-12-07 11:17:51 -02001194
Orit Wasserman00458432012-08-06 21:42:48 +03001195void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1196{
1197 const char *cap = qdict_get_str(qdict, "capability");
1198 bool state = qdict_get_bool(qdict, "state");
1199 Error *err = NULL;
1200 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1201 int i;
1202
1203 for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
1204 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1205 caps->value = g_malloc0(sizeof(*caps->value));
1206 caps->value->capability = i;
1207 caps->value->state = state;
1208 caps->next = NULL;
1209 qmp_migrate_set_capabilities(caps, &err);
1210 break;
1211 }
1212 }
1213
1214 if (i == MIGRATION_CAPABILITY_MAX) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +01001215 error_setg(&err, QERR_INVALID_PARAMETER, cap);
Orit Wasserman00458432012-08-06 21:42:48 +03001216 }
1217
1218 qapi_free_MigrationCapabilityStatusList(caps);
1219
1220 if (err) {
Orit Wassermana31ca012013-01-31 09:12:19 +02001221 monitor_printf(mon, "migrate_set_capability: %s\n",
Orit Wasserman00458432012-08-06 21:42:48 +03001222 error_get_pretty(err));
1223 error_free(err);
1224 }
1225}
1226
Liang Li50e9a622015-03-23 16:32:29 +08001227void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1228{
1229 const char *param = qdict_get_str(qdict, "parameter");
1230 int value = qdict_get_int(qdict, "value");
1231 Error *err = NULL;
1232 bool has_compress_level = false;
1233 bool has_compress_threads = false;
1234 bool has_decompress_threads = false;
Jason J. Herne1626fee2015-09-08 13:12:34 -04001235 bool has_x_cpu_throttle_initial = false;
1236 bool has_x_cpu_throttle_increment = false;
Liang Li50e9a622015-03-23 16:32:29 +08001237 int i;
1238
1239 for (i = 0; i < MIGRATION_PARAMETER_MAX; i++) {
1240 if (strcmp(param, MigrationParameter_lookup[i]) == 0) {
1241 switch (i) {
1242 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1243 has_compress_level = true;
1244 break;
1245 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1246 has_compress_threads = true;
1247 break;
1248 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1249 has_decompress_threads = true;
1250 break;
Jason J. Herne1626fee2015-09-08 13:12:34 -04001251 case MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL:
1252 has_x_cpu_throttle_initial = true;
1253 break;
1254 case MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT:
1255 has_x_cpu_throttle_increment = true;
1256 break;
Liang Li50e9a622015-03-23 16:32:29 +08001257 }
1258 qmp_migrate_set_parameters(has_compress_level, value,
1259 has_compress_threads, value,
1260 has_decompress_threads, value,
Jason J. Herne1626fee2015-09-08 13:12:34 -04001261 has_x_cpu_throttle_initial, value,
1262 has_x_cpu_throttle_increment, value,
Liang Li50e9a622015-03-23 16:32:29 +08001263 &err);
1264 break;
1265 }
1266 }
1267
1268 if (i == MIGRATION_PARAMETER_MAX) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +01001269 error_setg(&err, QERR_INVALID_PARAMETER, param);
Liang Li50e9a622015-03-23 16:32:29 +08001270 }
1271
1272 if (err) {
1273 monitor_printf(mon, "migrate_set_parameter: %s\n",
1274 error_get_pretty(err));
1275 error_free(err);
1276 }
1277}
1278
Markus Armbrusterb8a185b2015-03-05 17:29:02 +01001279void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1280{
1281 Error *err = NULL;
1282 const char *protocol = qdict_get_str(qdict, "protocol");
1283 const char *hostname = qdict_get_str(qdict, "hostname");
1284 bool has_port = qdict_haskey(qdict, "port");
1285 int port = qdict_get_try_int(qdict, "port", -1);
1286 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1287 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1288 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1289
1290 qmp_client_migrate_info(protocol, hostname,
1291 has_port, port, has_tls_port, tls_port,
1292 !!cert_subject, cert_subject, &err);
1293 hmp_handle_error(mon, &err);
1294}
1295
Luiz Capitulinofbf796f2011-12-07 11:17:51 -02001296void hmp_set_password(Monitor *mon, const QDict *qdict)
1297{
1298 const char *protocol = qdict_get_str(qdict, "protocol");
1299 const char *password = qdict_get_str(qdict, "password");
1300 const char *connected = qdict_get_try_str(qdict, "connected");
1301 Error *err = NULL;
1302
1303 qmp_set_password(protocol, password, !!connected, connected, &err);
1304 hmp_handle_error(mon, &err);
1305}
Luiz Capitulino9ad53722011-12-07 11:47:57 -02001306
1307void hmp_expire_password(Monitor *mon, const QDict *qdict)
1308{
1309 const char *protocol = qdict_get_str(qdict, "protocol");
1310 const char *whenstr = qdict_get_str(qdict, "time");
1311 Error *err = NULL;
1312
1313 qmp_expire_password(protocol, whenstr, &err);
1314 hmp_handle_error(mon, &err);
1315}
Luiz Capitulinoc245b6a2011-12-07 16:02:36 -02001316
1317void hmp_eject(Monitor *mon, const QDict *qdict)
1318{
Eric Blake34acbc92015-05-15 16:25:00 -06001319 bool force = qdict_get_try_bool(qdict, "force", false);
Luiz Capitulinoc245b6a2011-12-07 16:02:36 -02001320 const char *device = qdict_get_str(qdict, "device");
1321 Error *err = NULL;
1322
1323 qmp_eject(device, true, force, &err);
1324 hmp_handle_error(mon, &err);
1325}
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001326
Stefan Hajnoczic60bf332013-11-14 11:54:14 +01001327static void hmp_change_read_arg(void *opaque, const char *password,
1328 void *readline_opaque)
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001329{
1330 qmp_change_vnc_password(password, NULL);
Stefan Hajnoczic60bf332013-11-14 11:54:14 +01001331 monitor_read_command(opaque, 1);
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001332}
1333
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001334void hmp_change(Monitor *mon, const QDict *qdict)
1335{
1336 const char *device = qdict_get_str(qdict, "device");
1337 const char *target = qdict_get_str(qdict, "target");
1338 const char *arg = qdict_get_try_str(qdict, "arg");
1339 Error *err = NULL;
1340
1341 if (strcmp(device, "vnc") == 0 &&
1342 (strcmp(target, "passwd") == 0 ||
1343 strcmp(target, "password") == 0)) {
1344 if (!arg) {
1345 monitor_read_password(mon, hmp_change_read_arg, NULL);
1346 return;
1347 }
1348 }
1349
1350 qmp_change(device, target, !!arg, arg, &err);
Markus Armbruster84d18f02014-01-30 15:07:28 +01001351 if (err &&
Luiz Capitulinoab878dd2012-08-06 15:55:22 -03001352 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
Luiz Capitulinoeef5ad12012-08-06 15:49:34 -03001353 error_free(err);
1354 monitor_read_block_device_key(mon, device, NULL, NULL);
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001355 return;
1356 }
1357 hmp_handle_error(mon, &err);
1358}
Luiz Capitulino80047da2011-12-14 16:49:14 -02001359
1360void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1361{
1362 Error *err = NULL;
1363
1364 qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
1365 qdict_get_int(qdict, "bps"),
1366 qdict_get_int(qdict, "bps_rd"),
1367 qdict_get_int(qdict, "bps_wr"),
1368 qdict_get_int(qdict, "iops"),
1369 qdict_get_int(qdict, "iops_rd"),
Benoît Canet3e9fab62013-09-02 14:14:40 +02001370 qdict_get_int(qdict, "iops_wr"),
1371 false, /* no burst max via HMP */
1372 0,
1373 false,
1374 0,
1375 false,
1376 0,
1377 false,
1378 0,
1379 false,
1380 0,
1381 false,
Benoît Canet2024c1d2013-09-02 14:14:41 +02001382 0,
1383 false, /* No default I/O size */
Alberto Garcia76f4afb2015-06-08 18:17:44 +02001384 0,
1385 false,
1386 NULL, &err);
Luiz Capitulino80047da2011-12-14 16:49:14 -02001387 hmp_handle_error(mon, &err);
1388}
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00001389
1390void hmp_block_stream(Monitor *mon, const QDict *qdict)
1391{
1392 Error *error = NULL;
1393 const char *device = qdict_get_str(qdict, "device");
1394 const char *base = qdict_get_try_str(qdict, "base");
Stefan Hajnoczic83c66c2012-04-25 16:51:03 +01001395 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00001396
Jeff Cody13d8cc52014-06-25 15:40:11 -04001397 qmp_block_stream(device, base != NULL, base, false, NULL,
Paolo Bonzini1d809092012-09-28 17:22:59 +02001398 qdict_haskey(qdict, "speed"), speed,
Anthony Liguori46663e52013-09-17 11:10:47 -05001399 true, BLOCKDEV_ON_ERROR_REPORT, &error);
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00001400
1401 hmp_handle_error(mon, &error);
1402}
Stefan Hajnoczi2d47c6e2012-01-18 14:40:47 +00001403
1404void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1405{
1406 Error *error = NULL;
1407 const char *device = qdict_get_str(qdict, "device");
Paolo Bonzinic6db2392012-05-08 16:51:56 +02001408 int64_t value = qdict_get_int(qdict, "speed");
Stefan Hajnoczi2d47c6e2012-01-18 14:40:47 +00001409
1410 qmp_block_job_set_speed(device, value, &error);
1411
1412 hmp_handle_error(mon, &error);
1413}
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00001414
1415void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1416{
1417 Error *error = NULL;
1418 const char *device = qdict_get_str(qdict, "device");
Eric Blake34acbc92015-05-15 16:25:00 -06001419 bool force = qdict_get_try_bool(qdict, "force", false);
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00001420
Paolo Bonzini6e37fb82012-09-28 17:22:51 +02001421 qmp_block_job_cancel(device, true, force, &error);
1422
1423 hmp_handle_error(mon, &error);
1424}
1425
1426void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1427{
1428 Error *error = NULL;
1429 const char *device = qdict_get_str(qdict, "device");
1430
1431 qmp_block_job_pause(device, &error);
1432
1433 hmp_handle_error(mon, &error);
1434}
1435
1436void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1437{
1438 Error *error = NULL;
1439 const char *device = qdict_get_str(qdict, "device");
1440
1441 qmp_block_job_resume(device, &error);
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00001442
1443 hmp_handle_error(mon, &error);
1444}
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001445
Paolo Bonziniaeae8832012-10-18 16:49:21 +02001446void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1447{
1448 Error *error = NULL;
1449 const char *device = qdict_get_str(qdict, "device");
1450
1451 qmp_block_job_complete(device, &error);
1452
1453 hmp_handle_error(mon, &error);
1454}
1455
zhanghailiange49f35b2015-03-13 16:08:39 +08001456typedef struct HMPMigrationStatus
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001457{
1458 QEMUTimer *timer;
1459 Monitor *mon;
1460 bool is_block_migration;
zhanghailiange49f35b2015-03-13 16:08:39 +08001461} HMPMigrationStatus;
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001462
1463static void hmp_migrate_status_cb(void *opaque)
1464{
zhanghailiange49f35b2015-03-13 16:08:39 +08001465 HMPMigrationStatus *status = opaque;
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001466 MigrationInfo *info;
1467
1468 info = qmp_query_migrate(NULL);
zhanghailiang24b8c392015-03-13 16:08:40 +08001469 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1470 info->status == MIGRATION_STATUS_SETUP) {
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001471 if (info->has_disk) {
1472 int progress;
1473
1474 if (info->disk->remaining) {
1475 progress = info->disk->transferred * 100 / info->disk->total;
1476 } else {
1477 progress = 100;
1478 }
1479
1480 monitor_printf(status->mon, "Completed %d %%\r", progress);
1481 monitor_flush(status->mon);
1482 }
1483
Alex Blighbc72ad62013-08-21 16:03:08 +01001484 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001485 } else {
1486 if (status->is_block_migration) {
1487 monitor_printf(status->mon, "\n");
1488 }
1489 monitor_resume(status->mon);
Alex Blighbc72ad62013-08-21 16:03:08 +01001490 timer_del(status->timer);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001491 g_free(status);
1492 }
1493
1494 qapi_free_MigrationInfo(info);
1495}
1496
1497void hmp_migrate(Monitor *mon, const QDict *qdict)
1498{
Eric Blake34acbc92015-05-15 16:25:00 -06001499 bool detach = qdict_get_try_bool(qdict, "detach", false);
1500 bool blk = qdict_get_try_bool(qdict, "blk", false);
1501 bool inc = qdict_get_try_bool(qdict, "inc", false);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001502 const char *uri = qdict_get_str(qdict, "uri");
1503 Error *err = NULL;
1504
1505 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1506 if (err) {
1507 monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
1508 error_free(err);
1509 return;
1510 }
1511
1512 if (!detach) {
zhanghailiange49f35b2015-03-13 16:08:39 +08001513 HMPMigrationStatus *status;
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001514
1515 if (monitor_suspend(mon) < 0) {
1516 monitor_printf(mon, "terminal does not allow synchronous "
1517 "migration, continuing detached\n");
1518 return;
1519 }
1520
1521 status = g_malloc0(sizeof(*status));
1522 status->mon = mon;
1523 status->is_block_migration = blk || inc;
Alex Blighbc72ad62013-08-21 16:03:08 +01001524 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001525 status);
Alex Blighbc72ad62013-08-21 16:03:08 +01001526 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02001527 }
1528}
Luiz Capitulinoa15fef22012-03-29 12:38:50 -03001529
Markus Armbruster318660f2015-03-05 17:24:48 +01001530void hmp_device_add(Monitor *mon, const QDict *qdict)
1531{
Markus Armbruster485febc2015-03-13 17:25:50 +01001532 Error *err = NULL;
1533
1534 qmp_device_add((QDict *)qdict, NULL, &err);
1535 hmp_handle_error(mon, &err);
Markus Armbruster318660f2015-03-05 17:24:48 +01001536}
1537
Luiz Capitulinoa15fef22012-03-29 12:38:50 -03001538void hmp_device_del(Monitor *mon, const QDict *qdict)
1539{
1540 const char *id = qdict_get_str(qdict, "id");
1541 Error *err = NULL;
1542
1543 qmp_device_del(id, &err);
1544 hmp_handle_error(mon, &err);
1545}
Wen Congyang783e9b42012-05-07 12:10:47 +08001546
1547void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1548{
Markus Armbrustere940f542014-05-02 13:26:29 +02001549 Error *err = NULL;
Eric Blake34acbc92015-05-15 16:25:00 -06001550 bool paging = qdict_get_try_bool(qdict, "paging", false);
1551 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
1552 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
1553 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
Luiz Capitulino75363762012-09-21 13:53:00 -03001554 const char *file = qdict_get_str(qdict, "filename");
Wen Congyang783e9b42012-05-07 12:10:47 +08001555 bool has_begin = qdict_haskey(qdict, "begin");
1556 bool has_length = qdict_haskey(qdict, "length");
1557 int64_t begin = 0;
1558 int64_t length = 0;
qiaonuohanb53ccc32014-02-18 14:11:36 +08001559 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
Luiz Capitulino75363762012-09-21 13:53:00 -03001560 char *prot;
Wen Congyang783e9b42012-05-07 12:10:47 +08001561
Qiao Nuohan1b7a0f72014-04-17 16:15:07 +08001562 if (zlib + lzo + snappy > 1) {
Markus Armbrustere940f542014-05-02 13:26:29 +02001563 error_setg(&err, "only one of '-z|-l|-s' can be set");
1564 hmp_handle_error(mon, &err);
Qiao Nuohan1b7a0f72014-04-17 16:15:07 +08001565 return;
1566 }
1567
1568 if (zlib) {
1569 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1570 }
1571
1572 if (lzo) {
1573 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1574 }
1575
1576 if (snappy) {
1577 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1578 }
1579
Wen Congyang783e9b42012-05-07 12:10:47 +08001580 if (has_begin) {
1581 begin = qdict_get_int(qdict, "begin");
1582 }
1583 if (has_length) {
1584 length = qdict_get_int(qdict, "length");
1585 }
1586
Luiz Capitulino75363762012-09-21 13:53:00 -03001587 prot = g_strconcat("file:", file, NULL);
1588
1589 qmp_dump_guest_memory(paging, prot, has_begin, begin, has_length, length,
Markus Armbrustere940f542014-05-02 13:26:29 +02001590 true, dump_format, &err);
1591 hmp_handle_error(mon, &err);
Luiz Capitulino75363762012-09-21 13:53:00 -03001592 g_free(prot);
Wen Congyang783e9b42012-05-07 12:10:47 +08001593}
Luiz Capitulino928059a2012-04-18 17:34:15 -03001594
1595void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1596{
1597 Error *err = NULL;
1598 QemuOpts *opts;
1599
1600 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
Markus Armbruster84d18f02014-01-30 15:07:28 +01001601 if (err) {
Luiz Capitulino928059a2012-04-18 17:34:15 -03001602 goto out;
1603 }
1604
1605 netdev_add(opts, &err);
Markus Armbruster84d18f02014-01-30 15:07:28 +01001606 if (err) {
Luiz Capitulino928059a2012-04-18 17:34:15 -03001607 qemu_opts_del(opts);
1608 }
1609
1610out:
1611 hmp_handle_error(mon, &err);
1612}
Luiz Capitulino5f964152012-04-16 14:36:32 -03001613
1614void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1615{
1616 const char *id = qdict_get_str(qdict, "id");
1617 Error *err = NULL;
1618
1619 qmp_netdev_del(id, &err);
1620 hmp_handle_error(mon, &err);
1621}
Corey Bryant208c9d12012-06-22 14:36:09 -04001622
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01001623void hmp_object_add(Monitor *mon, const QDict *qdict)
1624{
1625 Error *err = NULL;
Markus Armbrusterf9f3a5e2014-05-07 09:53:51 +02001626 Error *err_end = NULL;
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01001627 QemuOpts *opts;
1628 char *type = NULL;
1629 char *id = NULL;
1630 void *dummy = NULL;
1631 OptsVisitor *ov;
1632 QDict *pdict;
1633
1634 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1635 if (err) {
1636 goto out;
1637 }
1638
1639 ov = opts_visitor_new(opts);
1640 pdict = qdict_clone_shallow(qdict);
1641
1642 visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err);
1643 if (err) {
1644 goto out_clean;
1645 }
1646
1647 qdict_del(pdict, "qom-type");
1648 visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
1649 if (err) {
Markus Armbrusterf9f3a5e2014-05-07 09:53:51 +02001650 goto out_end;
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01001651 }
1652
1653 qdict_del(pdict, "id");
1654 visit_type_str(opts_get_visitor(ov), &id, "id", &err);
1655 if (err) {
Markus Armbrusterf9f3a5e2014-05-07 09:53:51 +02001656 goto out_end;
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01001657 }
1658
1659 object_add(type, id, pdict, opts_get_visitor(ov), &err);
Markus Armbrusterf9f3a5e2014-05-07 09:53:51 +02001660
1661out_end:
1662 visit_end_struct(opts_get_visitor(ov), &err_end);
1663 if (!err && err_end) {
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01001664 qmp_object_del(id, NULL);
1665 }
Markus Armbrusterf9f3a5e2014-05-07 09:53:51 +02001666 error_propagate(&err, err_end);
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01001667out_clean:
1668 opts_visitor_cleanup(ov);
1669
1670 QDECREF(pdict);
1671 qemu_opts_del(opts);
1672 g_free(id);
1673 g_free(type);
1674 g_free(dummy);
1675
1676out:
1677 hmp_handle_error(mon, &err);
1678}
1679
Corey Bryant208c9d12012-06-22 14:36:09 -04001680void hmp_getfd(Monitor *mon, const QDict *qdict)
1681{
1682 const char *fdname = qdict_get_str(qdict, "fdname");
Markus Armbrustere940f542014-05-02 13:26:29 +02001683 Error *err = NULL;
Corey Bryant208c9d12012-06-22 14:36:09 -04001684
Markus Armbrustere940f542014-05-02 13:26:29 +02001685 qmp_getfd(fdname, &err);
1686 hmp_handle_error(mon, &err);
Corey Bryant208c9d12012-06-22 14:36:09 -04001687}
1688
1689void hmp_closefd(Monitor *mon, const QDict *qdict)
1690{
1691 const char *fdname = qdict_get_str(qdict, "fdname");
Markus Armbrustere940f542014-05-02 13:26:29 +02001692 Error *err = NULL;
Corey Bryant208c9d12012-06-22 14:36:09 -04001693
Markus Armbrustere940f542014-05-02 13:26:29 +02001694 qmp_closefd(fdname, &err);
1695 hmp_handle_error(mon, &err);
Corey Bryant208c9d12012-06-22 14:36:09 -04001696}
Amos Konge4c8f002012-08-31 10:56:26 +08001697
Markus Armbruster3e5a50d2015-02-06 13:55:43 +01001698void hmp_sendkey(Monitor *mon, const QDict *qdict)
Amos Konge4c8f002012-08-31 10:56:26 +08001699{
1700 const char *keys = qdict_get_str(qdict, "keys");
Luiz Capitulino9f328972012-09-20 14:19:47 -03001701 KeyValueList *keylist, *head = NULL, *tmp = NULL;
Amos Konge4c8f002012-08-31 10:56:26 +08001702 int has_hold_time = qdict_haskey(qdict, "hold-time");
1703 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1704 Error *err = NULL;
1705 char keyname_buf[16];
1706 char *separator;
Luiz Capitulino9f328972012-09-20 14:19:47 -03001707 int keyname_len;
Amos Konge4c8f002012-08-31 10:56:26 +08001708
1709 while (1) {
1710 separator = strchr(keys, '-');
1711 keyname_len = separator ? separator - keys : strlen(keys);
1712 pstrcpy(keyname_buf, sizeof(keyname_buf), keys);
1713
1714 /* Be compatible with old interface, convert user inputted "<" */
1715 if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) {
1716 pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
1717 keyname_len = 4;
1718 }
1719 keyname_buf[keyname_len] = 0;
1720
Amos Konge4c8f002012-08-31 10:56:26 +08001721 keylist = g_malloc0(sizeof(*keylist));
Luiz Capitulino9f328972012-09-20 14:19:47 -03001722 keylist->value = g_malloc0(sizeof(*keylist->value));
Amos Konge4c8f002012-08-31 10:56:26 +08001723
1724 if (!head) {
1725 head = keylist;
1726 }
1727 if (tmp) {
1728 tmp->next = keylist;
1729 }
1730 tmp = keylist;
1731
Luiz Capitulino9f328972012-09-20 14:19:47 -03001732 if (strstart(keyname_buf, "0x", NULL)) {
1733 char *endp;
1734 int value = strtoul(keyname_buf, &endp, 0);
1735 if (*endp != '\0') {
1736 goto err_out;
1737 }
Eric Blake568c73a2015-10-26 16:34:58 -06001738 keylist->value->type = KEY_VALUE_KIND_NUMBER;
1739 keylist->value->u.number = value;
Luiz Capitulino9f328972012-09-20 14:19:47 -03001740 } else {
1741 int idx = index_from_key(keyname_buf);
1742 if (idx == Q_KEY_CODE_MAX) {
1743 goto err_out;
1744 }
Eric Blake568c73a2015-10-26 16:34:58 -06001745 keylist->value->type = KEY_VALUE_KIND_QCODE;
1746 keylist->value->u.qcode = idx;
Luiz Capitulino9f328972012-09-20 14:19:47 -03001747 }
1748
Amos Konge4c8f002012-08-31 10:56:26 +08001749 if (!separator) {
1750 break;
1751 }
1752 keys = separator + 1;
1753 }
1754
Luiz Capitulino9f328972012-09-20 14:19:47 -03001755 qmp_send_key(head, has_hold_time, hold_time, &err);
Amos Konge4c8f002012-08-31 10:56:26 +08001756 hmp_handle_error(mon, &err);
Luiz Capitulino9f328972012-09-20 14:19:47 -03001757
1758out:
1759 qapi_free_KeyValueList(head);
1760 return;
1761
1762err_out:
1763 monitor_printf(mon, "invalid parameter: %s\n", keyname_buf);
1764 goto out;
Amos Konge4c8f002012-08-31 10:56:26 +08001765}
Luiz Capitulinoad39cf62012-05-24 13:48:23 -03001766
Markus Armbruster3e5a50d2015-02-06 13:55:43 +01001767void hmp_screendump(Monitor *mon, const QDict *qdict)
Luiz Capitulinoad39cf62012-05-24 13:48:23 -03001768{
1769 const char *filename = qdict_get_str(qdict, "filename");
1770 Error *err = NULL;
1771
1772 qmp_screendump(filename, &err);
1773 hmp_handle_error(mon, &err);
1774}
Paolo Bonzini40577252012-08-23 11:53:04 +02001775
1776void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1777{
1778 const char *uri = qdict_get_str(qdict, "uri");
Eric Blake34acbc92015-05-15 16:25:00 -06001779 bool writable = qdict_get_try_bool(qdict, "writable", false);
1780 bool all = qdict_get_try_bool(qdict, "all", false);
Paolo Bonzini40577252012-08-23 11:53:04 +02001781 Error *local_err = NULL;
1782 BlockInfoList *block_list, *info;
1783 SocketAddress *addr;
1784
1785 if (writable && !all) {
1786 error_setg(&local_err, "-w only valid together with -a");
1787 goto exit;
1788 }
1789
1790 /* First check if the address is valid and start the server. */
1791 addr = socket_parse(uri, &local_err);
1792 if (local_err != NULL) {
1793 goto exit;
1794 }
1795
1796 qmp_nbd_server_start(addr, &local_err);
1797 qapi_free_SocketAddress(addr);
1798 if (local_err != NULL) {
1799 goto exit;
1800 }
1801
1802 if (!all) {
1803 return;
1804 }
1805
1806 /* Then try adding all block devices. If one fails, close all and
1807 * exit.
1808 */
1809 block_list = qmp_query_block(NULL);
1810
1811 for (info = block_list; info; info = info->next) {
1812 if (!info->value->has_inserted) {
1813 continue;
1814 }
1815
1816 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1817
1818 if (local_err != NULL) {
1819 qmp_nbd_server_stop(NULL);
1820 break;
1821 }
1822 }
1823
1824 qapi_free_BlockInfoList(block_list);
1825
1826exit:
1827 hmp_handle_error(mon, &local_err);
1828}
1829
1830void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1831{
1832 const char *device = qdict_get_str(qdict, "device");
Eric Blake34acbc92015-05-15 16:25:00 -06001833 bool writable = qdict_get_try_bool(qdict, "writable", false);
Paolo Bonzini40577252012-08-23 11:53:04 +02001834 Error *local_err = NULL;
1835
1836 qmp_nbd_server_add(device, true, writable, &local_err);
1837
1838 if (local_err != NULL) {
1839 hmp_handle_error(mon, &local_err);
1840 }
1841}
1842
1843void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1844{
Markus Armbrustere940f542014-05-02 13:26:29 +02001845 Error *err = NULL;
Paolo Bonzini40577252012-08-23 11:53:04 +02001846
Markus Armbrustere940f542014-05-02 13:26:29 +02001847 qmp_nbd_server_stop(&err);
1848 hmp_handle_error(mon, &err);
Paolo Bonzini40577252012-08-23 11:53:04 +02001849}
Gerd Hoffmannf1088902012-12-19 10:33:40 +01001850
Jason J. Herneabf23322013-12-11 13:24:14 -05001851void hmp_cpu_add(Monitor *mon, const QDict *qdict)
1852{
1853 int cpuid;
1854 Error *err = NULL;
1855
1856 cpuid = qdict_get_int(qdict, "id");
1857 qmp_cpu_add(cpuid, &err);
1858 hmp_handle_error(mon, &err);
1859}
1860
Gerd Hoffmannf1088902012-12-19 10:33:40 +01001861void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1862{
1863 const char *args = qdict_get_str(qdict, "args");
1864 Error *err = NULL;
1865 QemuOpts *opts;
1866
Markus Armbruster70b94332015-02-13 12:50:26 +01001867 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
Gerd Hoffmannf1088902012-12-19 10:33:40 +01001868 if (opts == NULL) {
Markus Armbruster312fd5f2013-02-08 21:22:16 +01001869 error_setg(&err, "Parsing chardev args failed");
Gerd Hoffmannf1088902012-12-19 10:33:40 +01001870 } else {
1871 qemu_chr_new_from_opts(opts, NULL, &err);
1872 }
1873 hmp_handle_error(mon, &err);
1874}
1875
1876void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1877{
1878 Error *local_err = NULL;
1879
1880 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1881 hmp_handle_error(mon, &local_err);
1882}
Kevin Wolf587da2c2013-06-05 14:19:41 +02001883
1884void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1885{
Max Reitz4c7b7e92015-02-05 13:58:22 -05001886 BlockBackend *blk;
Kevin Wolf587da2c2013-06-05 14:19:41 +02001887 const char* device = qdict_get_str(qdict, "device");
1888 const char* command = qdict_get_str(qdict, "command");
1889 Error *err = NULL;
1890
Max Reitz4c7b7e92015-02-05 13:58:22 -05001891 blk = blk_by_name(device);
1892 if (blk) {
1893 qemuio_command(blk, command);
Kevin Wolf587da2c2013-06-05 14:19:41 +02001894 } else {
Markus Armbruster75158eb2015-03-16 08:57:47 +01001895 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
1896 "Device '%s' not found", device);
Kevin Wolf587da2c2013-06-05 14:19:41 +02001897 }
1898
1899 hmp_handle_error(mon, &err);
1900}
Paolo Bonziniab2d0532013-12-20 23:21:09 +01001901
1902void hmp_object_del(Monitor *mon, const QDict *qdict)
1903{
1904 const char *id = qdict_get_str(qdict, "id");
1905 Error *err = NULL;
1906
1907 qmp_object_del(id, &err);
1908 hmp_handle_error(mon, &err);
1909}
Hu Taoeb1539b2014-05-14 17:43:35 +08001910
1911void hmp_info_memdev(Monitor *mon, const QDict *qdict)
1912{
1913 Error *err = NULL;
1914 MemdevList *memdev_list = qmp_query_memdev(&err);
1915 MemdevList *m = memdev_list;
1916 StringOutputVisitor *ov;
Chen Fan976620a2014-08-18 14:46:34 +08001917 char *str;
Hu Taoeb1539b2014-05-14 17:43:35 +08001918 int i = 0;
1919
1920
1921 while (m) {
1922 ov = string_output_visitor_new(false);
1923 visit_type_uint16List(string_output_get_visitor(ov),
1924 &m->value->host_nodes, NULL, NULL);
Igor Mammedov8f4e5ac2014-06-19 16:14:43 +02001925 monitor_printf(mon, "memory backend: %d\n", i);
Hu Taoeb1539b2014-05-14 17:43:35 +08001926 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
1927 monitor_printf(mon, " merge: %s\n",
1928 m->value->merge ? "true" : "false");
1929 monitor_printf(mon, " dump: %s\n",
1930 m->value->dump ? "true" : "false");
1931 monitor_printf(mon, " prealloc: %s\n",
1932 m->value->prealloc ? "true" : "false");
1933 monitor_printf(mon, " policy: %s\n",
1934 HostMemPolicy_lookup[m->value->policy]);
Chen Fan976620a2014-08-18 14:46:34 +08001935 str = string_output_get_string(ov);
1936 monitor_printf(mon, " host nodes: %s\n", str);
Hu Taoeb1539b2014-05-14 17:43:35 +08001937
Chen Fan976620a2014-08-18 14:46:34 +08001938 g_free(str);
Hu Taoeb1539b2014-05-14 17:43:35 +08001939 string_output_visitor_cleanup(ov);
1940 m = m->next;
1941 i++;
1942 }
1943
1944 monitor_printf(mon, "\n");
Chen Fanecaf54a2014-08-18 14:46:35 +08001945
1946 qapi_free_MemdevList(memdev_list);
Hu Taoeb1539b2014-05-14 17:43:35 +08001947}
Zhu Guihuaa6318922014-09-23 13:35:19 +08001948
1949void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
1950{
1951 Error *err = NULL;
1952 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
1953 MemoryDeviceInfoList *info;
1954 MemoryDeviceInfo *value;
1955 PCDIMMDeviceInfo *di;
1956
1957 for (info = info_list; info; info = info->next) {
1958 value = info->value;
1959
1960 if (value) {
Eric Blake1fd5d4f2015-10-26 16:34:59 -06001961 switch (value->type) {
Zhu Guihuaa6318922014-09-23 13:35:19 +08001962 case MEMORY_DEVICE_INFO_KIND_DIMM:
Eric Blake1fd5d4f2015-10-26 16:34:59 -06001963 di = value->u.dimm;
Zhu Guihuaa6318922014-09-23 13:35:19 +08001964
1965 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
Eric Blake1fd5d4f2015-10-26 16:34:59 -06001966 MemoryDeviceInfoKind_lookup[value->type],
Zhu Guihuaa6318922014-09-23 13:35:19 +08001967 di->id ? di->id : "");
1968 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
1969 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
1970 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
1971 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
1972 monitor_printf(mon, " memdev: %s\n", di->memdev);
1973 monitor_printf(mon, " hotplugged: %s\n",
1974 di->hotplugged ? "true" : "false");
1975 monitor_printf(mon, " hotpluggable: %s\n",
1976 di->hotpluggable ? "true" : "false");
1977 break;
1978 default:
1979 break;
1980 }
1981 }
1982 }
1983
1984 qapi_free_MemoryDeviceInfoList(info_list);
1985}
Andreas Färber89d7fa92014-05-07 18:08:29 +02001986
Ting Wang62313162015-06-26 16:07:13 +08001987void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
1988{
1989 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
1990 IOThreadInfoList *info;
1991
1992 for (info = info_list; info; info = info->next) {
1993 monitor_printf(mon, "%s: thread_id=%" PRId64 "\n",
1994 info->value->id, info->value->thread_id);
1995 }
1996
1997 qapi_free_IOThreadInfoList(info_list);
1998}
1999
Andreas Färber89d7fa92014-05-07 18:08:29 +02002000void hmp_qom_list(Monitor *mon, const QDict *qdict)
2001{
2002 const char *path = qdict_get_try_str(qdict, "path");
2003 ObjectPropertyInfoList *list;
2004 Error *err = NULL;
2005
2006 if (path == NULL) {
2007 monitor_printf(mon, "/\n");
2008 return;
2009 }
2010
2011 list = qmp_qom_list(path, &err);
2012 if (err == NULL) {
2013 ObjectPropertyInfoList *start = list;
2014 while (list != NULL) {
2015 ObjectPropertyInfo *value = list->value;
2016
2017 monitor_printf(mon, "%s (%s)\n",
2018 value->name, value->type);
2019 list = list->next;
2020 }
2021 qapi_free_ObjectPropertyInfoList(start);
2022 }
2023 hmp_handle_error(mon, &err);
2024}
Andreas Färberc0e6ee92014-05-07 19:48:15 +02002025
2026void hmp_qom_set(Monitor *mon, const QDict *qdict)
2027{
2028 const char *path = qdict_get_str(qdict, "path");
2029 const char *property = qdict_get_str(qdict, "property");
2030 const char *value = qdict_get_str(qdict, "value");
2031 Error *err = NULL;
2032 bool ambiguous = false;
2033 Object *obj;
2034
2035 obj = object_resolve_path(path, &ambiguous);
2036 if (obj == NULL) {
Markus Armbruster75158eb2015-03-16 08:57:47 +01002037 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2038 "Device '%s' not found", path);
Andreas Färberc0e6ee92014-05-07 19:48:15 +02002039 } else {
2040 if (ambiguous) {
2041 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2042 }
2043 object_property_parse(obj, value, property, &err);
2044 }
2045 hmp_handle_error(mon, &err);
2046}
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002047
2048void hmp_rocker(Monitor *mon, const QDict *qdict)
2049{
2050 const char *name = qdict_get_str(qdict, "name");
2051 RockerSwitch *rocker;
2052 Error *errp = NULL;
2053
2054 rocker = qmp_query_rocker(name, &errp);
2055 if (errp != NULL) {
2056 hmp_handle_error(mon, &errp);
2057 return;
2058 }
2059
2060 monitor_printf(mon, "name: %s\n", rocker->name);
2061 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2062 monitor_printf(mon, "ports: %d\n", rocker->ports);
2063
2064 qapi_free_RockerSwitch(rocker);
2065}
2066
2067void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2068{
2069 RockerPortList *list, *port;
2070 const char *name = qdict_get_str(qdict, "name");
2071 Error *errp = NULL;
2072
2073 list = qmp_query_rocker_ports(name, &errp);
2074 if (errp != NULL) {
2075 hmp_handle_error(mon, &errp);
2076 return;
2077 }
2078
2079 monitor_printf(mon, " ena/ speed/ auto\n");
2080 monitor_printf(mon, " port link duplex neg?\n");
2081
2082 for (port = list; port; port = port->next) {
2083 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2084 port->value->name,
2085 port->value->enabled ? port->value->link_up ?
2086 "up" : "down" : "!ena",
2087 port->value->speed == 10000 ? "10G" : "??",
2088 port->value->duplex ? "FD" : "HD",
2089 port->value->autoneg ? "Yes" : "No");
2090 }
2091
2092 qapi_free_RockerPortList(list);
2093}
2094
2095void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2096{
2097 RockerOfDpaFlowList *list, *info;
2098 const char *name = qdict_get_str(qdict, "name");
2099 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2100 Error *errp = NULL;
2101
2102 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &errp);
2103 if (errp != NULL) {
2104 hmp_handle_error(mon, &errp);
2105 return;
2106 }
2107
2108 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2109
2110 for (info = list; info; info = info->next) {
2111 RockerOfDpaFlow *flow = info->value;
2112 RockerOfDpaFlowKey *key = flow->key;
2113 RockerOfDpaFlowMask *mask = flow->mask;
2114 RockerOfDpaFlowAction *action = flow->action;
2115
2116 if (flow->hits) {
2117 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2118 key->priority, key->tbl_id, flow->hits);
2119 } else {
2120 monitor_printf(mon, "%-4d %-3d ",
2121 key->priority, key->tbl_id);
2122 }
2123
2124 if (key->has_in_pport) {
2125 monitor_printf(mon, " pport %d", key->in_pport);
2126 if (mask->has_in_pport) {
2127 monitor_printf(mon, "(0x%x)", mask->in_pport);
2128 }
2129 }
2130
2131 if (key->has_vlan_id) {
2132 monitor_printf(mon, " vlan %d",
2133 key->vlan_id & VLAN_VID_MASK);
2134 if (mask->has_vlan_id) {
2135 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2136 }
2137 }
2138
2139 if (key->has_tunnel_id) {
2140 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2141 if (mask->has_tunnel_id) {
2142 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2143 }
2144 }
2145
2146 if (key->has_eth_type) {
2147 switch (key->eth_type) {
2148 case 0x0806:
2149 monitor_printf(mon, " ARP");
2150 break;
2151 case 0x0800:
2152 monitor_printf(mon, " IP");
2153 break;
2154 case 0x86dd:
2155 monitor_printf(mon, " IPv6");
2156 break;
2157 case 0x8809:
2158 monitor_printf(mon, " LACP");
2159 break;
2160 case 0x88cc:
2161 monitor_printf(mon, " LLDP");
2162 break;
2163 default:
2164 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2165 break;
2166 }
2167 }
2168
2169 if (key->has_eth_src) {
2170 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2171 (mask->has_eth_src) &&
2172 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2173 monitor_printf(mon, " src <any mcast/bcast>");
2174 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2175 (mask->has_eth_src) &&
2176 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2177 monitor_printf(mon, " src <any ucast>");
2178 } else {
2179 monitor_printf(mon, " src %s", key->eth_src);
2180 if (mask->has_eth_src) {
2181 monitor_printf(mon, "(%s)", mask->eth_src);
2182 }
2183 }
2184 }
2185
2186 if (key->has_eth_dst) {
2187 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2188 (mask->has_eth_dst) &&
2189 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2190 monitor_printf(mon, " dst <any mcast/bcast>");
2191 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2192 (mask->has_eth_dst) &&
2193 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2194 monitor_printf(mon, " dst <any ucast>");
2195 } else {
2196 monitor_printf(mon, " dst %s", key->eth_dst);
2197 if (mask->has_eth_dst) {
2198 monitor_printf(mon, "(%s)", mask->eth_dst);
2199 }
2200 }
2201 }
2202
2203 if (key->has_ip_proto) {
2204 monitor_printf(mon, " proto %d", key->ip_proto);
2205 if (mask->has_ip_proto) {
2206 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2207 }
2208 }
2209
2210 if (key->has_ip_tos) {
2211 monitor_printf(mon, " TOS %d", key->ip_tos);
2212 if (mask->has_ip_tos) {
2213 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2214 }
2215 }
2216
2217 if (key->has_ip_dst) {
2218 monitor_printf(mon, " dst %s", key->ip_dst);
2219 }
2220
2221 if (action->has_goto_tbl || action->has_group_id ||
2222 action->has_new_vlan_id) {
2223 monitor_printf(mon, " -->");
2224 }
2225
2226 if (action->has_new_vlan_id) {
2227 monitor_printf(mon, " apply new vlan %d",
2228 ntohs(action->new_vlan_id));
2229 }
2230
2231 if (action->has_group_id) {
2232 monitor_printf(mon, " write group 0x%08x", action->group_id);
2233 }
2234
2235 if (action->has_goto_tbl) {
2236 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2237 }
2238
2239 monitor_printf(mon, "\n");
2240 }
2241
2242 qapi_free_RockerOfDpaFlowList(list);
2243}
2244
2245void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2246{
2247 RockerOfDpaGroupList *list, *g;
2248 const char *name = qdict_get_str(qdict, "name");
2249 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2250 Error *errp = NULL;
2251 bool set = false;
2252
2253 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &errp);
2254 if (errp != NULL) {
2255 hmp_handle_error(mon, &errp);
2256 return;
2257 }
2258
2259 monitor_printf(mon, "id (decode) --> buckets\n");
2260
2261 for (g = list; g; g = g->next) {
2262 RockerOfDpaGroup *group = g->value;
2263
2264 monitor_printf(mon, "0x%08x", group->id);
2265
2266 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2267 group->type == 1 ? "L2 rewrite" :
2268 group->type == 2 ? "L3 unicast" :
2269 group->type == 3 ? "L2 multicast" :
2270 group->type == 4 ? "L2 flood" :
2271 group->type == 5 ? "L3 interface" :
2272 group->type == 6 ? "L3 multicast" :
2273 group->type == 7 ? "L3 ECMP" :
2274 group->type == 8 ? "L2 overlay" :
2275 "unknown");
2276
2277 if (group->has_vlan_id) {
2278 monitor_printf(mon, " vlan %d", group->vlan_id);
2279 }
2280
2281 if (group->has_pport) {
2282 monitor_printf(mon, " pport %d", group->pport);
2283 }
2284
2285 if (group->has_index) {
2286 monitor_printf(mon, " index %d", group->index);
2287 }
2288
2289 monitor_printf(mon, ") -->");
2290
2291 if (group->has_set_vlan_id && group->set_vlan_id) {
2292 set = true;
2293 monitor_printf(mon, " set vlan %d",
2294 group->set_vlan_id & VLAN_VID_MASK);
2295 }
2296
2297 if (group->has_set_eth_src) {
2298 if (!set) {
2299 set = true;
2300 monitor_printf(mon, " set");
2301 }
2302 monitor_printf(mon, " src %s", group->set_eth_src);
2303 }
2304
2305 if (group->has_set_eth_dst) {
2306 if (!set) {
2307 set = true;
2308 monitor_printf(mon, " set");
2309 }
2310 monitor_printf(mon, " dst %s", group->set_eth_dst);
2311 }
2312
2313 set = false;
2314
2315 if (group->has_ttl_check && group->ttl_check) {
2316 monitor_printf(mon, " check TTL");
2317 }
2318
2319 if (group->has_group_id && group->group_id) {
2320 monitor_printf(mon, " group id 0x%08x", group->group_id);
2321 }
2322
2323 if (group->has_pop_vlan && group->pop_vlan) {
2324 monitor_printf(mon, " pop vlan");
2325 }
2326
2327 if (group->has_out_pport) {
2328 monitor_printf(mon, " out pport %d", group->out_pport);
2329 }
2330
2331 if (group->has_group_ids) {
2332 struct uint32List *id;
2333
2334 monitor_printf(mon, " groups [");
2335 for (id = group->group_ids; id; id = id->next) {
2336 monitor_printf(mon, "0x%08x", id->value);
2337 if (id->next) {
2338 monitor_printf(mon, ",");
2339 }
2340 }
2341 monitor_printf(mon, "]");
2342 }
2343
2344 monitor_printf(mon, "\n");
2345 }
2346
2347 qapi_free_RockerOfDpaGroupList(list);
2348}