blob: fa1e59a2fcc2aef3dfacb78f0dd1cbd4a6dc21f1 [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
Peter Maydelld38ea872016-01-29 17:50:05 +000016#include "qemu/osdep.h"
Anthony Liguori48a32be2011-09-02 12:34:48 -050017#include "hmp.h"
Paolo Bonzini1422e322012-10-24 08:43:34 +020018#include "net/net.h"
Scott Feldmanfafa4d52015-06-10 18:21:21 -070019#include "net/eth.h"
Marc-André Lureau8228e352017-01-26 17:19:46 +040020#include "chardev/char.h"
Max Reitz4c7b7e92015-02-05 13:58:22 -050021#include "sysemu/block-backend.h"
Juan Quintela52b26202017-04-18 11:40:56 +020022#include "sysemu/sysemu.h"
Marc-André Lureau213dcb02016-12-12 20:22:24 +030023#include "qemu/config-file.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010024#include "qemu/option.h"
25#include "qemu/timer.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010026#include "qemu/sockets.h"
Paolo Bonzini83c90892012-12-17 18:19:49 +010027#include "monitor/monitor.h"
Markus Armbruster318660f2015-03-05 17:24:48 +010028#include "monitor/qdev.h"
Markus Armbrustere688df62018-02-01 12:18:31 +010029#include "qapi/error.h"
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +010030#include "qapi/opts-visitor.h"
Markus Armbrustereb815e22018-02-11 10:36:05 +010031#include "qapi/qapi-builtin-visit.h"
Markus Armbruster112ed242018-02-26 17:13:27 -060032#include "qapi/qapi-commands-block.h"
33#include "qapi/qapi-commands-char.h"
34#include "qapi/qapi-commands-migration.h"
35#include "qapi/qapi-commands-misc.h"
36#include "qapi/qapi-commands-net.h"
37#include "qapi/qapi-commands-rocker.h"
38#include "qapi/qapi-commands-run-state.h"
39#include "qapi/qapi-commands-tpm.h"
40#include "qapi/qapi-commands-ui.h"
Markus Armbruster452fcdb2018-02-01 12:18:39 +010041#include "qapi/qmp/qdict.h"
Markus Armbrustercc7a8ea2015-03-17 17:22:46 +010042#include "qapi/qmp/qerror.h"
Juan Quintelaf4a06d12017-05-16 11:37:45 +020043#include "qapi/string-input-visitor.h"
Hu Taoeb1539b2014-05-14 17:43:35 +080044#include "qapi/string-output-visitor.h"
Daniel P. Berrange90998d52016-02-10 18:40:59 +000045#include "qom/object_interfaces.h"
Paolo Bonzini28ecbae2012-11-28 12:06:30 +010046#include "ui/console.h"
Markus Armbrusterbd269eb2017-04-26 09:36:41 +020047#include "block/nbd.h"
Wenchao Xiabd093a32013-06-06 12:28:00 +080048#include "block/qapi.h"
Kevin Wolf587da2c2013-06-05 14:19:41 +020049#include "qemu-io.h"
Veronia Bahaaf348b6d2016-03-20 19:16:19 +020050#include "qemu/cutils.h"
Daniel P. Berranged59ce6f2016-04-27 11:05:00 +010051#include "qemu/error-report.h"
Peter Xube9b23c2017-05-12 12:17:41 +080052#include "exec/ramlist.h"
Hervé Poussineau61b97832016-09-26 22:23:27 +020053#include "hw/intc/intc.h"
Yuval Shaiaf4b2c022019-03-11 03:29:09 -070054#include "hw/rdma/rdma.h"
Juan Quintela5e224792017-04-20 14:25:55 +020055#include "migration/snapshot.h"
Peter Xu9d18af92017-06-27 12:10:19 +080056#include "migration/misc.h"
Anthony Liguori48a32be2011-09-02 12:34:48 -050057
Cole Robinson22fa7da2015-03-01 09:29:18 -050058#ifdef CONFIG_SPICE
59#include <spice/enums.h>
60#endif
61
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -020062static void hmp_handle_error(Monitor *mon, Error **errp)
63{
Markus Armbruster415168e2014-05-02 13:26:34 +020064 assert(errp);
65 if (*errp) {
Dr. David Alan Gilbert66363e92019-02-12 13:47:56 +000066 error_reportf_err(*errp, "Error: ");
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -020067 }
68}
69
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080070void hmp_info_name(Monitor *mon, const QDict *qdict)
Anthony Liguori48a32be2011-09-02 12:34:48 -050071{
72 NameInfo *info;
73
74 info = qmp_query_name(NULL);
75 if (info->has_name) {
76 monitor_printf(mon, "%s\n", info->name);
77 }
78 qapi_free_NameInfo(info);
79}
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030080
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080081void hmp_info_version(Monitor *mon, const QDict *qdict)
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030082{
83 VersionInfo *info;
84
85 info = qmp_query_version(NULL);
86
87 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
Eric Blake4752cdb2015-05-04 09:05:31 -060088 info->qemu->major, info->qemu->minor, info->qemu->micro,
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030089 info->package);
90
91 qapi_free_VersionInfo(info);
92}
Luiz Capitulino292a2602011-09-12 15:10:53 -030093
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080094void hmp_info_kvm(Monitor *mon, const QDict *qdict)
Luiz Capitulino292a2602011-09-12 15:10:53 -030095{
96 KvmInfo *info;
97
98 info = qmp_query_kvm(NULL);
99 monitor_printf(mon, "kvm support: ");
100 if (info->present) {
101 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
102 } else {
103 monitor_printf(mon, "not compiled\n");
104 }
105
106 qapi_free_KvmInfo(info);
107}
108
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800109void hmp_info_status(Monitor *mon, const QDict *qdict)
Luiz Capitulino1fa9a5e2011-09-12 17:54:20 -0300110{
111 StatusInfo *info;
112
113 info = qmp_query_status(NULL);
114
115 monitor_printf(mon, "VM status: %s%s",
116 info->running ? "running" : "paused",
117 info->singlestep ? " (single step mode)" : "");
118
119 if (!info->running && info->status != RUN_STATE_PAUSED) {
Markus Armbruster977c7362017-08-24 10:46:08 +0200120 monitor_printf(mon, " (%s)", RunState_str(info->status));
Luiz Capitulino1fa9a5e2011-09-12 17:54:20 -0300121 }
122
123 monitor_printf(mon, "\n");
124
125 qapi_free_StatusInfo(info);
126}
127
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800128void hmp_info_uuid(Monitor *mon, const QDict *qdict)
Luiz Capitulinoefab7672011-09-13 17:16:25 -0300129{
130 UuidInfo *info;
131
132 info = qmp_query_uuid(NULL);
133 monitor_printf(mon, "%s\n", info->UUID);
134 qapi_free_UuidInfo(info);
135}
Luiz Capitulinoc5a415a2011-09-14 16:05:49 -0300136
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800137void hmp_info_chardev(Monitor *mon, const QDict *qdict)
Luiz Capitulinoc5a415a2011-09-14 16:05:49 -0300138{
139 ChardevInfoList *char_info, *info;
140
141 char_info = qmp_query_chardev(NULL);
142 for (info = char_info; info; info = info->next) {
143 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
144 info->value->filename);
145 }
146
147 qapi_free_ChardevInfoList(char_info);
148}
Luiz Capitulino7a7f3252011-09-15 14:20:28 -0300149
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800150void hmp_info_mice(Monitor *mon, const QDict *qdict)
Luiz Capitulinoe235cec2011-09-21 15:29:55 -0300151{
152 MouseInfoList *mice_list, *mouse;
153
154 mice_list = qmp_query_mice(NULL);
155 if (!mice_list) {
156 monitor_printf(mon, "No mouse devices connected\n");
157 return;
158 }
159
160 for (mouse = mice_list; mouse; mouse = mouse->next) {
161 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
162 mouse->value->current ? '*' : ' ',
163 mouse->value->index, mouse->value->name,
164 mouse->value->absolute ? " (absolute)" : "");
165 }
166
167 qapi_free_MouseInfoList(mice_list);
168}
169
Juan Quintela9aca82b2019-02-27 11:51:27 +0100170static char *SocketAddress_to_str(SocketAddress *addr)
171{
172 switch (addr->type) {
173 case SOCKET_ADDRESS_TYPE_INET:
174 return g_strdup_printf("tcp:%s:%s",
175 addr->u.inet.host,
176 addr->u.inet.port);
177 case SOCKET_ADDRESS_TYPE_UNIX:
178 return g_strdup_printf("unix:%s",
179 addr->u.q_unix.path);
180 case SOCKET_ADDRESS_TYPE_FD:
181 return g_strdup_printf("fd:%s", addr->u.fd.str);
182 case SOCKET_ADDRESS_TYPE_VSOCK:
183 return g_strdup_printf("tcp:%s:%s",
184 addr->u.vsock.cid,
185 addr->u.vsock.port);
186 default:
187 return g_strdup("unknown address type");
188 }
189}
190
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800191void hmp_info_migrate(Monitor *mon, const QDict *qdict)
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300192{
193 MigrationInfo *info;
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300194 MigrationCapabilityStatusList *caps, *cap;
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300195
196 info = qmp_query_migrate(NULL);
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300197 caps = qmp_query_migrate_capabilities(NULL);
198
Peter Xu9d18af92017-06-27 12:10:19 +0800199 migration_global_dump(mon);
200
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300201 /* do not display parameters during setup */
202 if (info->has_status && caps) {
203 monitor_printf(mon, "capabilities: ");
204 for (cap = caps; cap; cap = cap->next) {
205 monitor_printf(mon, "%s: %s ",
Markus Armbruster977c7362017-08-24 10:46:08 +0200206 MigrationCapability_str(cap->value->capability),
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300207 cap->value->state ? "on" : "off");
208 }
209 monitor_printf(mon, "\n");
210 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300211
212 if (info->has_status) {
Daniel P. Berranged59ce6f2016-04-27 11:05:00 +0100213 monitor_printf(mon, "Migration status: %s",
Markus Armbruster977c7362017-08-24 10:46:08 +0200214 MigrationStatus_str(info->status));
Daniel P. Berranged59ce6f2016-04-27 11:05:00 +0100215 if (info->status == MIGRATION_STATUS_FAILED &&
216 info->has_error_desc) {
217 monitor_printf(mon, " (%s)\n", info->error_desc);
218 } else {
219 monitor_printf(mon, "\n");
220 }
221
Juan Quintela7aa939a2012-08-18 13:17:10 +0200222 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
223 info->total_time);
Juan Quintela2c52ddf2012-08-13 09:53:12 +0200224 if (info->has_expected_downtime) {
225 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
226 info->expected_downtime);
227 }
Juan Quintela9c5a9fc2012-08-13 09:35:16 +0200228 if (info->has_downtime) {
229 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
230 info->downtime);
231 }
Michael R. Hinesed4fbd12013-07-22 10:01:58 -0400232 if (info->has_setup_time) {
233 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
234 info->setup_time);
235 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300236 }
237
238 if (info->has_ram) {
239 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
240 info->ram->transferred >> 10);
Michael R. Hines7e114f82013-06-25 21:35:30 -0400241 monitor_printf(mon, "throughput: %0.2f mbps\n",
242 info->ram->mbps);
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300243 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
244 info->ram->remaining >> 10);
245 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
246 info->ram->total >> 10);
Orit Wasserman004d4c12012-08-06 21:42:56 +0300247 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
248 info->ram->duplicate);
Peter Lievenf1c72792013-03-26 10:58:37 +0100249 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
250 info->ram->skipped);
Orit Wasserman004d4c12012-08-06 21:42:56 +0300251 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
252 info->ram->normal);
253 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
254 info->ram->normal_bytes >> 10);
ChenLiang58570ed2014-04-04 17:57:55 +0800255 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
256 info->ram->dirty_sync_count);
Chao Fan030ce1f2017-03-21 10:22:43 +0800257 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
258 info->ram->page_size >> 10);
Juan Quintelaa61c45b2018-06-26 15:20:11 +0200259 monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n",
260 info->ram->multifd_bytes >> 10);
Xiao Guangrongaecbfe92019-01-11 14:37:30 +0800261 monitor_printf(mon, "pages-per-second: %" PRIu64 "\n",
262 info->ram->pages_per_second);
Chao Fan030ce1f2017-03-21 10:22:43 +0800263
Juan Quintela8d017192012-08-13 12:31:25 +0200264 if (info->ram->dirty_pages_rate) {
265 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
266 info->ram->dirty_pages_rate);
267 }
Dr. David Alan Gilbertd3bf5412016-06-13 12:16:42 +0100268 if (info->ram->postcopy_requests) {
269 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
270 info->ram->postcopy_requests);
271 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300272 }
273
274 if (info->has_disk) {
275 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
276 info->disk->transferred >> 10);
277 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
278 info->disk->remaining >> 10);
279 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
280 info->disk->total >> 10);
281 }
282
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300283 if (info->has_xbzrle_cache) {
284 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
285 info->xbzrle_cache->cache_size);
286 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
287 info->xbzrle_cache->bytes >> 10);
288 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
289 info->xbzrle_cache->pages);
290 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
291 info->xbzrle_cache->cache_miss);
ChenLiang8bc39232014-04-04 17:57:56 +0800292 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
293 info->xbzrle_cache->cache_miss_rate);
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300294 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
295 info->xbzrle_cache->overflow);
296 }
297
Xiao Guangrong76e03002018-09-06 15:01:00 +0800298 if (info->has_compression) {
299 monitor_printf(mon, "compression pages: %" PRIu64 " pages\n",
300 info->compression->pages);
301 monitor_printf(mon, "compression busy: %" PRIu64 "\n",
302 info->compression->busy);
303 monitor_printf(mon, "compression busy rate: %0.2f\n",
304 info->compression->busy_rate);
305 monitor_printf(mon, "compressed size: %" PRIu64 "\n",
306 info->compression->compressed_size);
307 monitor_printf(mon, "compression rate: %0.2f\n",
308 info->compression->compression_rate);
309 }
310
Jason J. Herned85a31d2016-04-21 14:07:18 -0400311 if (info->has_cpu_throttle_percentage) {
Jason J. Herne47828932015-09-08 13:12:36 -0400312 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
Jason J. Herned85a31d2016-04-21 14:07:18 -0400313 info->cpu_throttle_percentage);
Jason J. Herne47828932015-09-08 13:12:36 -0400314 }
315
Alexey Perevalov65ace062018-03-22 21:17:27 +0300316 if (info->has_postcopy_blocktime) {
317 monitor_printf(mon, "postcopy blocktime: %u\n",
318 info->postcopy_blocktime);
319 }
320
321 if (info->has_postcopy_vcpu_blocktime) {
322 Visitor *v;
323 char *str;
324 v = string_output_visitor_new(false, &str);
325 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, NULL);
326 visit_complete(v, &str);
327 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
328 g_free(str);
329 visit_free(v);
330 }
Juan Quintela9aca82b2019-02-27 11:51:27 +0100331 if (info->has_socket_address) {
332 SocketAddressList *addr;
333
334 monitor_printf(mon, "socket address: [\n");
335
336 for (addr = info->socket_address; addr; addr = addr->next) {
337 char *s = SocketAddress_to_str(addr->value);
338 monitor_printf(mon, "\t%s\n", s);
339 g_free(s);
340 }
341 monitor_printf(mon, "]\n");
342 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300343 qapi_free_MigrationInfo(info);
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300344 qapi_free_MigrationCapabilityStatusList(caps);
345}
346
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800347void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300348{
349 MigrationCapabilityStatusList *caps, *cap;
350
351 caps = qmp_query_migrate_capabilities(NULL);
352
353 if (caps) {
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300354 for (cap = caps; cap; cap = cap->next) {
Peter Xud80a0162017-04-01 16:18:44 +0800355 monitor_printf(mon, "%s: %s\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200356 MigrationCapability_str(cap->value->capability),
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300357 cap->value->state ? "on" : "off");
358 }
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300359 }
360
361 qapi_free_MigrationCapabilityStatusList(caps);
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300362}
363
Liang Li50e9a622015-03-23 16:32:29 +0800364void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
365{
366 MigrationParameters *params;
367
368 params = qmp_query_migrate_parameters(NULL);
369
370 if (params) {
Dr. David Alan Gilbertee3d96b2019-02-27 13:24:06 +0000371 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
372 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL),
373 params->announce_initial);
374 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
375 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX),
376 params->announce_max);
377 monitor_printf(mon, "%s: %" PRIu64 "\n",
378 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS),
379 params->announce_rounds);
380 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
381 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP),
382 params->announce_step);
Eric Blakede63ab62016-09-08 22:14:15 -0500383 assert(params->has_compress_level);
Juan Quintela741d4082017-12-01 13:08:38 +0100384 monitor_printf(mon, "%s: %u\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200385 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
Liang Li50e9a622015-03-23 16:32:29 +0800386 params->compress_level);
Eric Blakede63ab62016-09-08 22:14:15 -0500387 assert(params->has_compress_threads);
Juan Quintela741d4082017-12-01 13:08:38 +0100388 monitor_printf(mon, "%s: %u\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200389 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
Liang Li50e9a622015-03-23 16:32:29 +0800390 params->compress_threads);
Xiao Guangrong1d588722018-08-21 16:10:20 +0800391 assert(params->has_compress_wait_thread);
392 monitor_printf(mon, "%s: %s\n",
393 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD),
394 params->compress_wait_thread ? "on" : "off");
Eric Blakede63ab62016-09-08 22:14:15 -0500395 assert(params->has_decompress_threads);
Juan Quintela741d4082017-12-01 13:08:38 +0100396 monitor_printf(mon, "%s: %u\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200397 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
Liang Li50e9a622015-03-23 16:32:29 +0800398 params->decompress_threads);
Eric Blakede63ab62016-09-08 22:14:15 -0500399 assert(params->has_cpu_throttle_initial);
Juan Quintela741d4082017-12-01 13:08:38 +0100400 monitor_printf(mon, "%s: %u\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200401 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
Jason J. Herned85a31d2016-04-21 14:07:18 -0400402 params->cpu_throttle_initial);
Eric Blakede63ab62016-09-08 22:14:15 -0500403 assert(params->has_cpu_throttle_increment);
Juan Quintela741d4082017-12-01 13:08:38 +0100404 monitor_printf(mon, "%s: %u\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200405 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
Jason J. Herned85a31d2016-04-21 14:07:18 -0400406 params->cpu_throttle_increment);
Li Qiang4cbc9c72018-08-01 06:00:20 -0700407 assert(params->has_max_cpu_throttle);
408 monitor_printf(mon, "%s: %u\n",
409 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE),
410 params->max_cpu_throttle);
Markus Armbruster8cc99dc2017-07-18 12:04:54 +0200411 assert(params->has_tls_creds);
Peter Xu2c024682017-04-01 16:18:45 +0800412 monitor_printf(mon, "%s: '%s'\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200413 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
Markus Armbruster8cc99dc2017-07-18 12:04:54 +0200414 params->tls_creds);
415 assert(params->has_tls_hostname);
Peter Xu2c024682017-04-01 16:18:45 +0800416 monitor_printf(mon, "%s: '%s'\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200417 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
Markus Armbruster8cc99dc2017-07-18 12:04:54 +0200418 params->tls_hostname);
Ashijeet Acharya2ff30252016-09-15 21:50:28 +0530419 assert(params->has_max_bandwidth);
Juan Quintela741d4082017-12-01 13:08:38 +0100420 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200421 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
Ashijeet Acharya2ff30252016-09-15 21:50:28 +0530422 params->max_bandwidth);
423 assert(params->has_downtime_limit);
Juan Quintela741d4082017-12-01 13:08:38 +0100424 monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200425 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
Ashijeet Acharya2ff30252016-09-15 21:50:28 +0530426 params->downtime_limit);
zhanghailiangfe39a4d2016-11-02 15:42:09 +0800427 assert(params->has_x_checkpoint_delay);
Juan Quintela741d4082017-12-01 13:08:38 +0100428 monitor_printf(mon, "%s: %u\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200429 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
zhanghailiang68b53592016-10-27 14:43:01 +0800430 params->x_checkpoint_delay);
Juan Quintela2833c592017-04-05 18:32:37 +0200431 assert(params->has_block_incremental);
432 monitor_printf(mon, "%s: %s\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200433 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
434 params->block_incremental ? "on" : "off");
Juan Quintela741d4082017-12-01 13:08:38 +0100435 monitor_printf(mon, "%s: %u\n",
Juan Quintela4075fb12016-01-15 08:56:17 +0100436 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_CHANNELS),
437 params->x_multifd_channels);
Juan Quintela741d4082017-12-01 13:08:38 +0100438 monitor_printf(mon, "%s: %u\n",
Juan Quintela0fb86602017-04-27 10:48:25 +0200439 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT),
440 params->x_multifd_page_count);
Juan Quintela741d4082017-12-01 13:08:38 +0100441 monitor_printf(mon, "%s: %" PRIu64 "\n",
Juan Quintela73af8dd2017-10-05 21:30:10 +0200442 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
443 params->xbzrle_cache_size);
Dr. David Alan Gilbert7e555c62018-06-13 11:26:40 +0100444 monitor_printf(mon, "%s: %" PRIu64 "\n",
445 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
446 params->max_postcopy_bandwidth);
Liang Li50e9a622015-03-23 16:32:29 +0800447 }
448
449 qapi_free_MigrationParameters(params);
450}
451
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800452void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +0300453{
454 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
455 qmp_query_migrate_cache_size(NULL) >> 10);
456}
457
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800458void hmp_info_cpus(Monitor *mon, const QDict *qdict)
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300459{
Viktor Mihajlovski137b5cb2018-02-16 17:08:41 +0100460 CpuInfoFastList *cpu_list, *cpu;
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300461
Viktor Mihajlovski137b5cb2018-02-16 17:08:41 +0100462 cpu_list = qmp_query_cpus_fast(NULL);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300463
464 for (cpu = cpu_list; cpu; cpu = cpu->next) {
465 int active = ' ';
466
Viktor Mihajlovski137b5cb2018-02-16 17:08:41 +0100467 if (cpu->value->cpu_index == monitor_get_cpu_index()) {
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300468 active = '*';
469 }
470
Viktor Mihajlovski137b5cb2018-02-16 17:08:41 +0100471 monitor_printf(mon, "%c CPU #%" PRId64 ":", active,
472 cpu->value->cpu_index);
Satheesh Rajendran0dfddbb2018-03-27 18:08:00 +0530473 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300474 }
475
Viktor Mihajlovski137b5cb2018-02-16 17:08:41 +0100476 qapi_free_CpuInfoFastList(cpu_list);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300477}
478
Kevin Wolf289b2762014-09-15 12:06:39 +0200479static void print_block_info(Monitor *mon, BlockInfo *info,
480 BlockDeviceInfo *inserted, bool verbose)
481{
482 ImageInfo *image_info;
483
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200484 assert(!info || !info->has_inserted || info->inserted == inserted);
485
Kevin Wolfec18b0a2017-07-11 14:00:57 +0200486 if (info && *info->device) {
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200487 monitor_printf(mon, "%s", info->device);
488 if (inserted && inserted->has_node_name) {
489 monitor_printf(mon, " (%s)", inserted->node_name);
490 }
491 } else {
Kevin Wolfec18b0a2017-07-11 14:00:57 +0200492 assert(info || inserted);
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200493 monitor_printf(mon, "%s",
Kevin Wolfec18b0a2017-07-11 14:00:57 +0200494 inserted && inserted->has_node_name ? inserted->node_name
495 : info && info->has_qdev ? info->qdev
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200496 : "<anonymous>");
497 }
498
Kevin Wolf289b2762014-09-15 12:06:39 +0200499 if (inserted) {
500 monitor_printf(mon, ": %s (%s%s%s)\n",
501 inserted->file,
502 inserted->drv,
503 inserted->ro ? ", read-only" : "",
504 inserted->encrypted ? ", encrypted" : "");
505 } else {
506 monitor_printf(mon, ": [not inserted]\n");
507 }
508
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200509 if (info) {
Kevin Wolf46eade72017-07-11 13:27:38 +0200510 if (info->has_qdev) {
511 monitor_printf(mon, " Attached to: %s\n", info->qdev);
512 }
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200513 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
514 monitor_printf(mon, " I/O status: %s\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200515 BlockDeviceIoStatus_str(info->io_status));
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200516 }
Kevin Wolf289b2762014-09-15 12:06:39 +0200517
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200518 if (info->removable) {
519 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
520 info->locked ? "" : "not ",
521 info->tray_open ? "open" : "closed");
522 }
Kevin Wolf289b2762014-09-15 12:06:39 +0200523 }
524
525
526 if (!inserted) {
527 return;
528 }
529
530 monitor_printf(mon, " Cache mode: %s%s%s\n",
531 inserted->cache->writeback ? "writeback" : "writethrough",
532 inserted->cache->direct ? ", direct" : "",
533 inserted->cache->no_flush ? ", ignore flushes" : "");
534
535 if (inserted->has_backing_file) {
536 monitor_printf(mon,
537 " Backing file: %s "
538 "(chain depth: %" PRId64 ")\n",
539 inserted->backing_file,
540 inserted->backing_file_depth);
541 }
542
543 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
544 monitor_printf(mon, " Detect zeroes: %s\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200545 BlockdevDetectZeroesOptions_str(inserted->detect_zeroes));
Kevin Wolf289b2762014-09-15 12:06:39 +0200546 }
547
548 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
549 inserted->iops || inserted->iops_rd || inserted->iops_wr)
550 {
551 monitor_printf(mon, " I/O throttling: bps=%" PRId64
552 " bps_rd=%" PRId64 " bps_wr=%" PRId64
553 " bps_max=%" PRId64
554 " bps_rd_max=%" PRId64
555 " bps_wr_max=%" PRId64
556 " iops=%" PRId64 " iops_rd=%" PRId64
557 " iops_wr=%" PRId64
558 " iops_max=%" PRId64
559 " iops_rd_max=%" PRId64
560 " iops_wr_max=%" PRId64
Alberto Garciab8fe1692015-06-08 18:17:46 +0200561 " iops_size=%" PRId64
562 " group=%s\n",
Kevin Wolf289b2762014-09-15 12:06:39 +0200563 inserted->bps,
564 inserted->bps_rd,
565 inserted->bps_wr,
566 inserted->bps_max,
567 inserted->bps_rd_max,
568 inserted->bps_wr_max,
569 inserted->iops,
570 inserted->iops_rd,
571 inserted->iops_wr,
572 inserted->iops_max,
573 inserted->iops_rd_max,
574 inserted->iops_wr_max,
Alberto Garciab8fe1692015-06-08 18:17:46 +0200575 inserted->iops_size,
576 inserted->group);
Kevin Wolf289b2762014-09-15 12:06:39 +0200577 }
578
Stefan Hajnoczi94198742015-04-22 11:15:10 +0100579 if (verbose) {
Kevin Wolf289b2762014-09-15 12:06:39 +0200580 monitor_printf(mon, "\nImages:\n");
581 image_info = inserted->image;
582 while (1) {
583 bdrv_image_info_dump((fprintf_function)monitor_printf,
584 mon, image_info);
585 if (image_info->has_backing_image) {
586 image_info = image_info->backing_image;
587 } else {
588 break;
589 }
590 }
591 }
592}
593
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800594void hmp_info_block(Monitor *mon, const QDict *qdict)
Luiz Capitulinob2023812011-09-21 17:16:47 -0300595{
596 BlockInfoList *block_list, *info;
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200597 BlockDeviceInfoList *blockdev_list, *blockdev;
Wenchao Xiae73fe2b2013-06-06 12:28:01 +0800598 const char *device = qdict_get_try_str(qdict, "device");
Eric Blake34acbc92015-05-15 16:25:00 -0600599 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
600 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200601 bool printed = false;
Luiz Capitulinob2023812011-09-21 17:16:47 -0300602
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200603 /* Print BlockBackend information */
604 if (!nodes) {
Stefan Weilf19e44b2015-02-08 15:40:48 +0100605 block_list = qmp_query_block(NULL);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200606 } else {
607 block_list = NULL;
608 }
Luiz Capitulinob2023812011-09-21 17:16:47 -0300609
610 for (info = block_list; info; info = info->next) {
Wenchao Xiae73fe2b2013-06-06 12:28:01 +0800611 if (device && strcmp(device, info->value->device)) {
612 continue;
613 }
Luiz Capitulinob2023812011-09-21 17:16:47 -0300614
Kevin Wolffbe2e262013-06-19 16:10:55 +0200615 if (info != block_list) {
616 monitor_printf(mon, "\n");
Luiz Capitulinob2023812011-09-21 17:16:47 -0300617 }
618
Kevin Wolf289b2762014-09-15 12:06:39 +0200619 print_block_info(mon, info->value, info->value->has_inserted
620 ? info->value->inserted : NULL,
621 verbose);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200622 printed = true;
Luiz Capitulinob2023812011-09-21 17:16:47 -0300623 }
624
625 qapi_free_BlockInfoList(block_list);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200626
627 if ((!device && !nodes) || printed) {
628 return;
629 }
630
631 /* Print node information */
632 blockdev_list = qmp_query_named_block_nodes(NULL);
633 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
634 assert(blockdev->value->has_node_name);
635 if (device && strcmp(device, blockdev->value->node_name)) {
636 continue;
637 }
638
639 if (blockdev != blockdev_list) {
640 monitor_printf(mon, "\n");
641 }
642
643 print_block_info(mon, NULL, blockdev->value, verbose);
644 }
645 qapi_free_BlockDeviceInfoList(blockdev_list);
Luiz Capitulinob2023812011-09-21 17:16:47 -0300646}
647
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800648void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300649{
650 BlockStatsList *stats_list, *stats;
651
Fam Zhengf71eaa72014-10-31 11:32:57 +0800652 stats_list = qmp_query_blockstats(false, false, NULL);
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300653
654 for (stats = stats_list; stats; stats = stats->next) {
655 if (!stats->value->has_device) {
656 continue;
657 }
658
659 monitor_printf(mon, "%s:", stats->value->device);
660 monitor_printf(mon, " rd_bytes=%" PRId64
661 " wr_bytes=%" PRId64
662 " rd_operations=%" PRId64
663 " wr_operations=%" PRId64
664 " flush_operations=%" PRId64
665 " wr_total_time_ns=%" PRId64
666 " rd_total_time_ns=%" PRId64
667 " flush_total_time_ns=%" PRId64
Peter Lievenf4564d52015-02-02 14:52:18 +0100668 " rd_merged=%" PRId64
669 " wr_merged=%" PRId64
Alberto Garciacb38fff2015-10-28 17:33:02 +0200670 " idle_time_ns=%" PRId64
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300671 "\n",
672 stats->value->stats->rd_bytes,
673 stats->value->stats->wr_bytes,
674 stats->value->stats->rd_operations,
675 stats->value->stats->wr_operations,
676 stats->value->stats->flush_operations,
677 stats->value->stats->wr_total_time_ns,
678 stats->value->stats->rd_total_time_ns,
Peter Lievenf4564d52015-02-02 14:52:18 +0100679 stats->value->stats->flush_total_time_ns,
680 stats->value->stats->rd_merged,
Alberto Garciacb38fff2015-10-28 17:33:02 +0200681 stats->value->stats->wr_merged,
682 stats->value->stats->idle_time_ns);
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300683 }
684
685 qapi_free_BlockStatsList(stats_list);
686}
687
Marc-André Lureau05eb4a22018-07-03 17:56:47 +0200688#ifdef CONFIG_VNC
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100689/* Helper for hmp_info_vnc_clients, _servers */
690static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
691 const char *name)
692{
693 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
694 name,
695 info->host,
696 info->service,
Markus Armbruster977c7362017-08-24 10:46:08 +0200697 NetworkAddressFamily_str(info->family),
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100698 info->websocket ? " (Websocket)" : "");
699}
700
701/* Helper displaying and auth and crypt info */
702static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
703 VncPrimaryAuth auth,
704 VncVencryptSubAuth *vencrypt)
705{
706 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
Markus Armbruster977c7362017-08-24 10:46:08 +0200707 VncPrimaryAuth_str(auth),
708 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100709}
710
711static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
712{
713 while (client) {
714 VncClientInfo *cinfo = client->value;
715
716 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
717 monitor_printf(mon, " x509_dname: %s\n",
718 cinfo->has_x509_dname ?
719 cinfo->x509_dname : "none");
720 monitor_printf(mon, " sasl_username: %s\n",
721 cinfo->has_sasl_username ?
722 cinfo->sasl_username : "none");
723
724 client = client->next;
725 }
726}
727
728static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
729{
730 while (server) {
731 VncServerInfo2 *sinfo = server->value;
732 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
733 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
734 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
735 server = server->next;
736 }
737}
738
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800739void hmp_info_vnc(Monitor *mon, const QDict *qdict)
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200740{
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100741 VncInfo2List *info2l;
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200742 Error *err = NULL;
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200743
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100744 info2l = qmp_query_vnc_servers(&err);
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200745 if (err) {
ZhiPeng Lu554a39e2017-10-19 19:16:33 +0800746 hmp_handle_error(mon, &err);
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200747 return;
748 }
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100749 if (!info2l) {
750 monitor_printf(mon, "None\n");
751 return;
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200752 }
753
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100754 while (info2l) {
755 VncInfo2 *info = info2l->value;
756 monitor_printf(mon, "%s:\n", info->id);
757 hmp_info_vnc_servers(mon, info->server);
758 hmp_info_vnc_clients(mon, info->clients);
759 if (!info->server) {
760 /* The server entry displays its auth, we only
761 * need to display in the case of 'reverse' connections
762 * where there's no server.
763 */
764 hmp_info_vnc_authcrypt(mon, " ", info->auth,
765 info->has_vencrypt ? &info->vencrypt : NULL);
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200766 }
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100767 if (info->has_display) {
768 monitor_printf(mon, " Display: %s\n", info->display);
769 }
770 info2l = info2l->next;
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200771 }
772
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100773 qapi_free_VncInfo2List(info2l);
774
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200775}
Marc-André Lureau05eb4a22018-07-03 17:56:47 +0200776#endif
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200777
Markus Armbruster206addd2015-01-13 15:46:39 +0100778#ifdef CONFIG_SPICE
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800779void hmp_info_spice(Monitor *mon, const QDict *qdict)
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200780{
781 SpiceChannelList *chan;
782 SpiceInfo *info;
Cole Robinson22fa7da2015-03-01 09:29:18 -0500783 const char *channel_name;
784 const char * const channel_names[] = {
785 [SPICE_CHANNEL_MAIN] = "main",
786 [SPICE_CHANNEL_DISPLAY] = "display",
787 [SPICE_CHANNEL_INPUTS] = "inputs",
788 [SPICE_CHANNEL_CURSOR] = "cursor",
789 [SPICE_CHANNEL_PLAYBACK] = "playback",
790 [SPICE_CHANNEL_RECORD] = "record",
791 [SPICE_CHANNEL_TUNNEL] = "tunnel",
792 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
793 [SPICE_CHANNEL_USBREDIR] = "usbredir",
794 [SPICE_CHANNEL_PORT] = "port",
Gerd Hoffmann7c6044a2015-03-03 09:27:28 +0100795#if 0
796 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
797 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
798 * as quick fix for build failures with older versions. */
Cole Robinson22fa7da2015-03-01 09:29:18 -0500799 [SPICE_CHANNEL_WEBDAV] = "webdav",
Gerd Hoffmann7c6044a2015-03-03 09:27:28 +0100800#endif
Cole Robinson22fa7da2015-03-01 09:29:18 -0500801 };
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200802
803 info = qmp_query_spice(NULL);
804
805 if (!info->enabled) {
806 monitor_printf(mon, "Server: disabled\n");
807 goto out;
808 }
809
810 monitor_printf(mon, "Server:\n");
811 if (info->has_port) {
812 monitor_printf(mon, " address: %s:%" PRId64 "\n",
813 info->host, info->port);
814 }
815 if (info->has_tls_port) {
816 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
817 info->host, info->tls_port);
818 }
Yonit Halperin61c4efe2012-08-21 11:51:58 +0300819 monitor_printf(mon, " migrated: %s\n",
820 info->migrated ? "true" : "false");
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200821 monitor_printf(mon, " auth: %s\n", info->auth);
822 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
Alon Levy4efee022012-03-29 23:23:14 +0200823 monitor_printf(mon, " mouse-mode: %s\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200824 SpiceQueryMouseMode_str(info->mouse_mode));
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200825
826 if (!info->has_channels || info->channels == NULL) {
827 monitor_printf(mon, "Channels: none\n");
828 } else {
829 for (chan = info->channels; chan; chan = chan->next) {
830 monitor_printf(mon, "Channel:\n");
831 monitor_printf(mon, " address: %s:%s%s\n",
Eric Blakeddf21902015-10-26 16:34:49 -0600832 chan->value->host, chan->value->port,
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200833 chan->value->tls ? " [tls]" : "");
834 monitor_printf(mon, " session: %" PRId64 "\n",
835 chan->value->connection_id);
836 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
837 chan->value->channel_type, chan->value->channel_id);
Cole Robinson22fa7da2015-03-01 09:29:18 -0500838
839 channel_name = "unknown";
840 if (chan->value->channel_type > 0 &&
841 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
842 channel_names[chan->value->channel_type]) {
843 channel_name = channel_names[chan->value->channel_type];
844 }
845
846 monitor_printf(mon, " channel name: %s\n", channel_name);
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200847 }
848 }
849
850out:
851 qapi_free_SpiceInfo(info);
852}
Markus Armbruster206addd2015-01-13 15:46:39 +0100853#endif
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200854
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800855void hmp_info_balloon(Monitor *mon, const QDict *qdict)
Luiz Capitulino96637bc2011-10-21 11:41:37 -0200856{
857 BalloonInfo *info;
858 Error *err = NULL;
859
860 info = qmp_query_balloon(&err);
861 if (err) {
ZhiPeng Lu554a39e2017-10-19 19:16:33 +0800862 hmp_handle_error(mon, &err);
Luiz Capitulino96637bc2011-10-21 11:41:37 -0200863 return;
864 }
865
Luiz Capitulino01ceb972012-12-03 15:56:41 -0200866 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
Luiz Capitulino96637bc2011-10-21 11:41:37 -0200867
868 qapi_free_BalloonInfo(info);
869}
870
Luiz Capitulino79627472011-10-21 14:15:33 -0200871static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
872{
873 PciMemoryRegionList *region;
874
875 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
876 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
877 dev->slot, dev->function);
878 monitor_printf(mon, " ");
879
Eric Blake9fa02cd2015-05-04 09:05:32 -0600880 if (dev->class_info->has_desc) {
881 monitor_printf(mon, "%s", dev->class_info->desc);
Luiz Capitulino79627472011-10-21 14:15:33 -0200882 } else {
Eric Blake9fa02cd2015-05-04 09:05:32 -0600883 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
Luiz Capitulino79627472011-10-21 14:15:33 -0200884 }
885
886 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600887 dev->id->vendor, dev->id->device);
Denis V. Lunev18613dc2018-10-02 16:55:38 +0300888 if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) {
889 monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n",
890 dev->id->subsystem_vendor, dev->id->subsystem);
891 }
Luiz Capitulino79627472011-10-21 14:15:33 -0200892
893 if (dev->has_irq) {
894 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
895 }
896
897 if (dev->has_pci_bridge) {
898 monitor_printf(mon, " BUS %" PRId64 ".\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600899 dev->pci_bridge->bus->number);
Luiz Capitulino79627472011-10-21 14:15:33 -0200900 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600901 dev->pci_bridge->bus->secondary);
Luiz Capitulino79627472011-10-21 14:15:33 -0200902 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600903 dev->pci_bridge->bus->subordinate);
Luiz Capitulino79627472011-10-21 14:15:33 -0200904
905 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600906 dev->pci_bridge->bus->io_range->base,
907 dev->pci_bridge->bus->io_range->limit);
Luiz Capitulino79627472011-10-21 14:15:33 -0200908
909 monitor_printf(mon,
910 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600911 dev->pci_bridge->bus->memory_range->base,
912 dev->pci_bridge->bus->memory_range->limit);
Luiz Capitulino79627472011-10-21 14:15:33 -0200913
914 monitor_printf(mon, " prefetchable memory range "
915 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600916 dev->pci_bridge->bus->prefetchable_range->base,
917 dev->pci_bridge->bus->prefetchable_range->limit);
Luiz Capitulino79627472011-10-21 14:15:33 -0200918 }
919
920 for (region = dev->regions; region; region = region->next) {
921 uint64_t addr, size;
922
923 addr = region->value->address;
924 size = region->value->size;
925
926 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
927
928 if (!strcmp(region->value->type, "io")) {
929 monitor_printf(mon, "I/O at 0x%04" PRIx64
930 " [0x%04" PRIx64 "].\n",
931 addr, addr + size - 1);
932 } else {
933 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
934 " [0x%08" PRIx64 "].\n",
935 region->value->mem_type_64 ? 64 : 32,
936 region->value->prefetch ? " prefetchable" : "",
937 addr, addr + size - 1);
938 }
939 }
940
941 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
942
943 if (dev->has_pci_bridge) {
944 if (dev->pci_bridge->has_devices) {
945 PciDeviceInfoList *cdev;
946 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
947 hmp_info_pci_device(mon, cdev->value);
948 }
949 }
950 }
951}
952
Hervé Poussineau61b97832016-09-26 22:23:27 +0200953static int hmp_info_irq_foreach(Object *obj, void *opaque)
954{
955 InterruptStatsProvider *intc;
956 InterruptStatsProviderClass *k;
957 Monitor *mon = opaque;
958
959 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
960 intc = INTERRUPT_STATS_PROVIDER(obj);
961 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
962 uint64_t *irq_counts;
963 unsigned int nb_irqs, i;
964 if (k->get_statistics &&
965 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
966 if (nb_irqs > 0) {
967 monitor_printf(mon, "IRQ statistics for %s:\n",
968 object_get_typename(obj));
969 for (i = 0; i < nb_irqs; i++) {
970 if (irq_counts[i] > 0) {
971 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
972 irq_counts[i]);
973 }
974 }
975 }
976 } else {
977 monitor_printf(mon, "IRQ statistics not available for %s.\n",
978 object_get_typename(obj));
979 }
980 }
981
982 return 0;
983}
984
985void hmp_info_irq(Monitor *mon, const QDict *qdict)
986{
987 object_child_foreach_recursive(object_get_root(),
988 hmp_info_irq_foreach, mon);
989}
990
991static int hmp_info_pic_foreach(Object *obj, void *opaque)
992{
993 InterruptStatsProvider *intc;
994 InterruptStatsProviderClass *k;
995 Monitor *mon = opaque;
996
997 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
998 intc = INTERRUPT_STATS_PROVIDER(obj);
999 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
1000 if (k->print_info) {
1001 k->print_info(intc, mon);
1002 } else {
1003 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
1004 object_get_typename(obj));
1005 }
1006 }
1007
1008 return 0;
1009}
1010
1011void hmp_info_pic(Monitor *mon, const QDict *qdict)
1012{
1013 object_child_foreach_recursive(object_get_root(),
1014 hmp_info_pic_foreach, mon);
1015}
1016
Yuval Shaiaf4b2c022019-03-11 03:29:09 -07001017static int hmp_info_rdma_foreach(Object *obj, void *opaque)
1018{
1019 RdmaProvider *rdma;
1020 RdmaProviderClass *k;
1021 Monitor *mon = opaque;
1022
1023 if (object_dynamic_cast(obj, INTERFACE_RDMA_PROVIDER)) {
1024 rdma = RDMA_PROVIDER(obj);
1025 k = RDMA_PROVIDER_GET_CLASS(obj);
1026 if (k->print_statistics) {
1027 k->print_statistics(mon, rdma);
1028 } else {
1029 monitor_printf(mon, "RDMA statistics not available for %s.\n",
1030 object_get_typename(obj));
1031 }
1032 }
1033
1034 return 0;
1035}
1036
1037void hmp_info_rdma(Monitor *mon, const QDict *qdict)
1038{
1039 object_child_foreach_recursive(object_get_root(),
1040 hmp_info_rdma_foreach, mon);
1041}
1042
Wenchao Xia84f2d0e2013-01-14 14:06:25 +08001043void hmp_info_pci(Monitor *mon, const QDict *qdict)
Luiz Capitulino79627472011-10-21 14:15:33 -02001044{
Stefan Bergerf46cee32012-01-11 10:51:52 -05001045 PciInfoList *info_list, *info;
Luiz Capitulino79627472011-10-21 14:15:33 -02001046 Error *err = NULL;
1047
Stefan Bergerf46cee32012-01-11 10:51:52 -05001048 info_list = qmp_query_pci(&err);
Luiz Capitulino79627472011-10-21 14:15:33 -02001049 if (err) {
1050 monitor_printf(mon, "PCI devices not supported\n");
1051 error_free(err);
1052 return;
1053 }
1054
Stefan Bergerf46cee32012-01-11 10:51:52 -05001055 for (info = info_list; info; info = info->next) {
Luiz Capitulino79627472011-10-21 14:15:33 -02001056 PciDeviceInfoList *dev;
1057
1058 for (dev = info->value->devices; dev; dev = dev->next) {
1059 hmp_info_pci_device(mon, dev->value);
1060 }
1061 }
1062
Stefan Bergerf46cee32012-01-11 10:51:52 -05001063 qapi_free_PciInfoList(info_list);
Luiz Capitulino79627472011-10-21 14:15:33 -02001064}
1065
Wenchao Xia84f2d0e2013-01-14 14:06:25 +08001066void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
Stefan Hajnoczifb5458c2012-01-18 14:40:49 +00001067{
1068 BlockJobInfoList *list;
1069 Error *err = NULL;
1070
1071 list = qmp_query_block_jobs(&err);
1072 assert(!err);
1073
1074 if (!list) {
1075 monitor_printf(mon, "No active jobs\n");
1076 return;
1077 }
1078
1079 while (list) {
1080 if (strcmp(list->value->type, "stream") == 0) {
1081 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
1082 " of %" PRId64 " bytes, speed limit %" PRId64
1083 " bytes/s\n",
1084 list->value->device,
1085 list->value->offset,
1086 list->value->len,
1087 list->value->speed);
1088 } else {
1089 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
1090 " of %" PRId64 " bytes, speed limit %" PRId64
1091 " bytes/s\n",
1092 list->value->type,
1093 list->value->device,
1094 list->value->offset,
1095 list->value->len,
1096 list->value->speed);
1097 }
1098 list = list->next;
1099 }
Gonglei93bb1312014-09-16 21:36:55 +08001100
1101 qapi_free_BlockJobInfoList(list);
Stefan Hajnoczifb5458c2012-01-18 14:40:49 +00001102}
1103
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05001104void hmp_info_tpm(Monitor *mon, const QDict *qdict)
1105{
1106 TPMInfoList *info_list, *info;
1107 Error *err = NULL;
1108 unsigned int c = 0;
1109 TPMPassthroughOptions *tpo;
Amarnath Vallurif4ede812017-09-29 14:10:20 +03001110 TPMEmulatorOptions *teo;
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05001111
1112 info_list = qmp_query_tpm(&err);
1113 if (err) {
1114 monitor_printf(mon, "TPM device not supported\n");
1115 error_free(err);
1116 return;
1117 }
1118
1119 if (info_list) {
1120 monitor_printf(mon, "TPM device:\n");
1121 }
1122
1123 for (info = info_list; info; info = info->next) {
1124 TPMInfo *ti = info->value;
1125 monitor_printf(mon, " tpm%d: model=%s\n",
Markus Armbruster977c7362017-08-24 10:46:08 +02001126 c, TpmModel_str(ti->model));
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05001127
1128 monitor_printf(mon, " \\ %s: type=%s",
Markus Armbruster977c7362017-08-24 10:46:08 +02001129 ti->id, TpmTypeOptionsKind_str(ti->options->type));
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05001130
Eric Blakece211312015-10-26 16:35:00 -06001131 switch (ti->options->type) {
Corey Bryant88ca7bc2013-03-20 12:34:48 -04001132 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
Eric Blake32bafa82016-03-17 16:48:37 -06001133 tpo = ti->options->u.passthrough.data;
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05001134 monitor_printf(mon, "%s%s%s%s",
1135 tpo->has_path ? ",path=" : "",
1136 tpo->has_path ? tpo->path : "",
1137 tpo->has_cancel_path ? ",cancel-path=" : "",
1138 tpo->has_cancel_path ? tpo->cancel_path : "");
1139 break;
Amarnath Vallurif4ede812017-09-29 14:10:20 +03001140 case TPM_TYPE_OPTIONS_KIND_EMULATOR:
1141 teo = ti->options->u.emulator.data;
1142 monitor_printf(mon, ",chardev=%s", teo->chardev);
1143 break;
Eric Blake7fb1cf12015-11-18 01:52:57 -07001144 case TPM_TYPE_OPTIONS_KIND__MAX:
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05001145 break;
1146 }
1147 monitor_printf(mon, "\n");
1148 c++;
1149 }
1150 qapi_free_TPMInfoList(info_list);
1151}
1152
Luiz Capitulino7a7f3252011-09-15 14:20:28 -03001153void hmp_quit(Monitor *mon, const QDict *qdict)
1154{
1155 monitor_suspend(mon);
1156 qmp_quit(NULL);
1157}
Luiz Capitulino5f158f22011-09-15 14:34:39 -03001158
1159void hmp_stop(Monitor *mon, const QDict *qdict)
1160{
1161 qmp_stop(NULL);
1162}
Luiz Capitulino38d22652011-09-15 14:41:46 -03001163
Emilio G. Cotadd12e1b2018-08-15 16:00:03 -04001164void hmp_sync_profile(Monitor *mon, const QDict *qdict)
1165{
1166 const char *op = qdict_get_try_str(qdict, "op");
1167
1168 if (op == NULL) {
1169 bool on = qsp_is_enabled();
1170
1171 monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off");
1172 return;
1173 }
1174 if (!strcmp(op, "on")) {
1175 qsp_enable();
1176 } else if (!strcmp(op, "off")) {
1177 qsp_disable();
1178 } else if (!strcmp(op, "reset")) {
1179 qsp_reset();
1180 } else {
1181 Error *err = NULL;
1182
1183 error_setg(&err, QERR_INVALID_PARAMETER, op);
1184 hmp_handle_error(mon, &err);
1185 }
1186}
1187
Luiz Capitulino38d22652011-09-15 14:41:46 -03001188void hmp_system_reset(Monitor *mon, const QDict *qdict)
1189{
1190 qmp_system_reset(NULL);
1191}
Luiz Capitulino5bc465e2011-09-28 11:06:15 -03001192
1193void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
1194{
1195 qmp_system_powerdown(NULL);
1196}
Luiz Capitulino755f1962011-10-06 14:31:39 -03001197
Dr. David Alan Gilbert8e8581e2018-06-20 16:39:46 +01001198void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
1199{
1200 Error *err = NULL;
1201
Markus Armbruster361ac942018-07-05 11:14:02 +02001202 qmp_x_exit_preconfig(&err);
Dr. David Alan Gilbert8e8581e2018-06-20 16:39:46 +01001203 hmp_handle_error(mon, &err);
1204}
1205
Luiz Capitulino755f1962011-10-06 14:31:39 -03001206void hmp_cpu(Monitor *mon, const QDict *qdict)
1207{
1208 int64_t cpu_index;
1209
1210 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1211 use it are converted to the QAPI */
1212 cpu_index = qdict_get_int(qdict, "index");
1213 if (monitor_set_cpu(cpu_index) < 0) {
1214 monitor_printf(mon, "invalid CPU index\n");
1215 }
1216}
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -02001217
1218void hmp_memsave(Monitor *mon, const QDict *qdict)
1219{
1220 uint32_t size = qdict_get_int(qdict, "size");
1221 const char *filename = qdict_get_str(qdict, "filename");
1222 uint64_t addr = qdict_get_int(qdict, "val");
Markus Armbrustere940f542014-05-02 13:26:29 +02001223 Error *err = NULL;
Thomas Huth854e67f2017-01-13 13:12:35 +01001224 int cpu_index = monitor_get_cpu_index();
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -02001225
Thomas Huth854e67f2017-01-13 13:12:35 +01001226 if (cpu_index < 0) {
1227 monitor_printf(mon, "No CPU available\n");
1228 return;
1229 }
1230
1231 qmp_memsave(addr, size, filename, true, cpu_index, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +02001232 hmp_handle_error(mon, &err);
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -02001233}
Luiz Capitulino6d3962b2011-11-22 17:26:46 -02001234
1235void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1236{
1237 uint32_t size = qdict_get_int(qdict, "size");
1238 const char *filename = qdict_get_str(qdict, "filename");
1239 uint64_t addr = qdict_get_int(qdict, "val");
Markus Armbrustere940f542014-05-02 13:26:29 +02001240 Error *err = NULL;
Luiz Capitulino6d3962b2011-11-22 17:26:46 -02001241
Markus Armbrustere940f542014-05-02 13:26:29 +02001242 qmp_pmemsave(addr, size, filename, &err);
1243 hmp_handle_error(mon, &err);
Luiz Capitulino6d3962b2011-11-22 17:26:46 -02001244}
Luiz Capitulinoe42e8182011-11-22 17:58:31 -02001245
Markus Armbruster3949e592013-02-06 21:27:24 +01001246void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
Lei Li1f590cf2013-01-25 00:03:20 +08001247{
Lei Li1f590cf2013-01-25 00:03:20 +08001248 const char *chardev = qdict_get_str(qdict, "device");
1249 const char *data = qdict_get_str(qdict, "data");
Markus Armbrustere940f542014-05-02 13:26:29 +02001250 Error *err = NULL;
Lei Li1f590cf2013-01-25 00:03:20 +08001251
Markus Armbrustere940f542014-05-02 13:26:29 +02001252 qmp_ringbuf_write(chardev, data, false, 0, &err);
Lei Li1f590cf2013-01-25 00:03:20 +08001253
Markus Armbrustere940f542014-05-02 13:26:29 +02001254 hmp_handle_error(mon, &err);
Lei Li1f590cf2013-01-25 00:03:20 +08001255}
1256
Markus Armbruster3949e592013-02-06 21:27:24 +01001257void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
Lei Li49b6d722013-01-25 00:03:21 +08001258{
1259 uint32_t size = qdict_get_int(qdict, "size");
1260 const char *chardev = qdict_get_str(qdict, "device");
Markus Armbruster3ab651f2013-02-06 21:27:15 +01001261 char *data;
Markus Armbrustere940f542014-05-02 13:26:29 +02001262 Error *err = NULL;
Markus Armbruster543f3412013-02-06 21:27:26 +01001263 int i;
Lei Li49b6d722013-01-25 00:03:21 +08001264
Markus Armbrustere940f542014-05-02 13:26:29 +02001265 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1266 if (err) {
ZhiPeng Lu554a39e2017-10-19 19:16:33 +08001267 hmp_handle_error(mon, &err);
Lei Li49b6d722013-01-25 00:03:21 +08001268 return;
1269 }
1270
Markus Armbruster543f3412013-02-06 21:27:26 +01001271 for (i = 0; data[i]; i++) {
1272 unsigned char ch = data[i];
1273
1274 if (ch == '\\') {
1275 monitor_printf(mon, "\\\\");
1276 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1277 monitor_printf(mon, "\\u%04X", ch);
1278 } else {
1279 monitor_printf(mon, "%c", ch);
1280 }
1281
1282 }
1283 monitor_printf(mon, "\n");
Markus Armbruster3ab651f2013-02-06 21:27:15 +01001284 g_free(data);
Lei Li49b6d722013-01-25 00:03:21 +08001285}
1286
Luiz Capitulinoe42e8182011-11-22 17:58:31 -02001287void hmp_cont(Monitor *mon, const QDict *qdict)
1288{
Markus Armbrustere940f542014-05-02 13:26:29 +02001289 Error *err = NULL;
Luiz Capitulinoe42e8182011-11-22 17:58:31 -02001290
Markus Armbrustere940f542014-05-02 13:26:29 +02001291 qmp_cont(&err);
1292 hmp_handle_error(mon, &err);
Luiz Capitulinoe42e8182011-11-22 17:58:31 -02001293}
Luiz Capitulinoab49ab52011-11-23 12:55:53 -02001294
Gerd Hoffmann9b9df252012-02-23 13:45:21 +01001295void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1296{
Daniel Henrique Barbozafb064112018-12-05 17:47:01 -02001297 Error *err = NULL;
1298
1299 qmp_system_wakeup(&err);
1300 hmp_handle_error(mon, &err);
Gerd Hoffmann9b9df252012-02-23 13:45:21 +01001301}
1302
Markus Armbruster3e5a50d2015-02-06 13:55:43 +01001303void hmp_nmi(Monitor *mon, const QDict *qdict)
Luiz Capitulinoab49ab52011-11-23 12:55:53 -02001304{
Markus Armbrustere940f542014-05-02 13:26:29 +02001305 Error *err = NULL;
Luiz Capitulinoab49ab52011-11-23 12:55:53 -02001306
Markus Armbrustere940f542014-05-02 13:26:29 +02001307 qmp_inject_nmi(&err);
1308 hmp_handle_error(mon, &err);
Luiz Capitulinoab49ab52011-11-23 12:55:53 -02001309}
Luiz Capitulino4b371562011-11-23 13:11:55 -02001310
1311void hmp_set_link(Monitor *mon, const QDict *qdict)
1312{
1313 const char *name = qdict_get_str(qdict, "name");
Eric Blake34acbc92015-05-15 16:25:00 -06001314 bool up = qdict_get_bool(qdict, "up");
Markus Armbrustere940f542014-05-02 13:26:29 +02001315 Error *err = NULL;
Luiz Capitulino4b371562011-11-23 13:11:55 -02001316
Markus Armbrustere940f542014-05-02 13:26:29 +02001317 qmp_set_link(name, up, &err);
1318 hmp_handle_error(mon, &err);
Luiz Capitulino4b371562011-11-23 13:11:55 -02001319}
Luiz Capitulinoa4dea8a2011-11-23 13:28:21 -02001320
1321void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1322{
1323 const char *device = qdict_get_str(qdict, "device");
1324 const char *password = qdict_get_str(qdict, "password");
Markus Armbrustere940f542014-05-02 13:26:29 +02001325 Error *err = NULL;
Luiz Capitulinoa4dea8a2011-11-23 13:28:21 -02001326
Markus Armbrustere940f542014-05-02 13:26:29 +02001327 qmp_block_passwd(true, device, false, NULL, password, &err);
1328 hmp_handle_error(mon, &err);
Luiz Capitulinoa4dea8a2011-11-23 13:28:21 -02001329}
Luiz Capitulinod72f3262011-11-25 14:38:09 -02001330
1331void hmp_balloon(Monitor *mon, const QDict *qdict)
1332{
1333 int64_t value = qdict_get_int(qdict, "value");
Markus Armbrustere940f542014-05-02 13:26:29 +02001334 Error *err = NULL;
Luiz Capitulinod72f3262011-11-25 14:38:09 -02001335
Markus Armbrustere940f542014-05-02 13:26:29 +02001336 qmp_balloon(value, &err);
ZhiPeng Lu554a39e2017-10-19 19:16:33 +08001337 hmp_handle_error(mon, &err);
Luiz Capitulinod72f3262011-11-25 14:38:09 -02001338}
Luiz Capitulino5e7caac2011-11-25 14:57:10 -02001339
1340void hmp_block_resize(Monitor *mon, const QDict *qdict)
1341{
1342 const char *device = qdict_get_str(qdict, "device");
1343 int64_t size = qdict_get_int(qdict, "size");
Markus Armbrustere940f542014-05-02 13:26:29 +02001344 Error *err = NULL;
Luiz Capitulino5e7caac2011-11-25 14:57:10 -02001345
Markus Armbrustere940f542014-05-02 13:26:29 +02001346 qmp_block_resize(true, device, false, NULL, size, &err);
1347 hmp_handle_error(mon, &err);
Luiz Capitulino5e7caac2011-11-25 14:57:10 -02001348}
Luiz Capitulino6106e242011-11-25 16:15:19 -02001349
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001350void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1351{
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001352 const char *filename = qdict_get_str(qdict, "target");
1353 const char *format = qdict_get_try_str(qdict, "format");
Eric Blake34acbc92015-05-15 16:25:00 -06001354 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1355 bool full = qdict_get_try_bool(qdict, "full", false);
Markus Armbrustere940f542014-05-02 13:26:29 +02001356 Error *err = NULL;
Eric Blakefaecd402016-07-14 16:37:58 -06001357 DriveMirror mirror = {
1358 .device = (char *)qdict_get_str(qdict, "device"),
1359 .target = (char *)filename,
1360 .has_format = !!format,
1361 .format = (char *)format,
1362 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1363 .has_mode = true,
1364 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1365 .unmap = true,
1366 };
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001367
1368 if (!filename) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +01001369 error_setg(&err, QERR_MISSING_PARAMETER, "target");
Markus Armbrustere940f542014-05-02 13:26:29 +02001370 hmp_handle_error(mon, &err);
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001371 return;
1372 }
Eric Blakefaecd402016-07-14 16:37:58 -06001373 qmp_drive_mirror(&mirror, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +02001374 hmp_handle_error(mon, &err);
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001375}
1376
Stefan Hajnoczide909302013-06-26 14:11:58 +02001377void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1378{
1379 const char *device = qdict_get_str(qdict, "device");
1380 const char *filename = qdict_get_str(qdict, "target");
1381 const char *format = qdict_get_try_str(qdict, "format");
Eric Blake34acbc92015-05-15 16:25:00 -06001382 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1383 bool full = qdict_get_try_bool(qdict, "full", false);
Pavel Butsykin13b94142016-07-22 11:17:52 +03001384 bool compress = qdict_get_try_bool(qdict, "compress", false);
Markus Armbrustere940f542014-05-02 13:26:29 +02001385 Error *err = NULL;
Pavel Butsykin81206a82016-07-22 11:17:50 +03001386 DriveBackup backup = {
1387 .device = (char *)device,
1388 .target = (char *)filename,
1389 .has_format = !!format,
1390 .format = (char *)format,
1391 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1392 .has_mode = true,
1393 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
Pavel Butsykin13b94142016-07-22 11:17:52 +03001394 .has_compress = !!compress,
1395 .compress = compress,
Pavel Butsykin81206a82016-07-22 11:17:50 +03001396 };
Stefan Hajnoczide909302013-06-26 14:11:58 +02001397
1398 if (!filename) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +01001399 error_setg(&err, QERR_MISSING_PARAMETER, "target");
Markus Armbrustere940f542014-05-02 13:26:29 +02001400 hmp_handle_error(mon, &err);
Stefan Hajnoczide909302013-06-26 14:11:58 +02001401 return;
1402 }
1403
Pavel Butsykin81206a82016-07-22 11:17:50 +03001404 qmp_drive_backup(&backup, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +02001405 hmp_handle_error(mon, &err);
Stefan Hajnoczide909302013-06-26 14:11:58 +02001406}
1407
Luiz Capitulino6106e242011-11-25 16:15:19 -02001408void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1409{
1410 const char *device = qdict_get_str(qdict, "device");
1411 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1412 const char *format = qdict_get_try_str(qdict, "format");
Eric Blake34acbc92015-05-15 16:25:00 -06001413 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
Paolo Bonzini6cc2a412012-03-06 18:55:59 +01001414 enum NewImageMode mode;
Markus Armbrustere940f542014-05-02 13:26:29 +02001415 Error *err = NULL;
Luiz Capitulino6106e242011-11-25 16:15:19 -02001416
1417 if (!filename) {
1418 /* In the future, if 'snapshot-file' is not specified, the snapshot
1419 will be taken internally. Today it's actually required. */
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +01001420 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
Markus Armbrustere940f542014-05-02 13:26:29 +02001421 hmp_handle_error(mon, &err);
Luiz Capitulino6106e242011-11-25 16:15:19 -02001422 return;
1423 }
1424
Paolo Bonzini6cc2a412012-03-06 18:55:59 +01001425 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
Benoît Canet0901f672014-01-23 21:31:38 +01001426 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1427 filename, false, NULL,
1428 !!format, format,
Markus Armbrustere940f542014-05-02 13:26:29 +02001429 true, mode, &err);
1430 hmp_handle_error(mon, &err);
Luiz Capitulino6106e242011-11-25 16:15:19 -02001431}
Luiz Capitulino6cdedb02011-11-27 22:54:09 -02001432
Wenchao Xia775ca882013-09-11 14:04:37 +08001433void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1434{
1435 const char *device = qdict_get_str(qdict, "device");
1436 const char *name = qdict_get_str(qdict, "name");
Markus Armbrustere940f542014-05-02 13:26:29 +02001437 Error *err = NULL;
Wenchao Xia775ca882013-09-11 14:04:37 +08001438
Markus Armbrustere940f542014-05-02 13:26:29 +02001439 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1440 hmp_handle_error(mon, &err);
Wenchao Xia775ca882013-09-11 14:04:37 +08001441}
1442
Wenchao Xia7a4ed2e2013-09-11 14:04:38 +08001443void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1444{
1445 const char *device = qdict_get_str(qdict, "device");
1446 const char *name = qdict_get_str(qdict, "name");
1447 const char *id = qdict_get_try_str(qdict, "id");
Markus Armbrustere940f542014-05-02 13:26:29 +02001448 Error *err = NULL;
Wenchao Xia7a4ed2e2013-09-11 14:04:38 +08001449
1450 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
Markus Armbrustere940f542014-05-02 13:26:29 +02001451 true, name, &err);
1452 hmp_handle_error(mon, &err);
Wenchao Xia7a4ed2e2013-09-11 14:04:38 +08001453}
1454
Juan Quintela52b26202017-04-18 11:40:56 +02001455void hmp_loadvm(Monitor *mon, const QDict *qdict)
1456{
1457 int saved_vm_running = runstate_is_running();
1458 const char *name = qdict_get_str(qdict, "name");
Juan Quintela927d6632017-04-18 18:12:35 +02001459 Error *err = NULL;
Juan Quintela52b26202017-04-18 11:40:56 +02001460
1461 vm_stop(RUN_STATE_RESTORE_VM);
1462
Juan Quintela5e224792017-04-20 14:25:55 +02001463 if (load_snapshot(name, &err) == 0 && saved_vm_running) {
Juan Quintela52b26202017-04-18 11:40:56 +02001464 vm_start();
1465 }
Juan Quintela927d6632017-04-18 18:12:35 +02001466 hmp_handle_error(mon, &err);
Juan Quintela52b26202017-04-18 11:40:56 +02001467}
1468
Juan Quintelad9c7d132017-04-18 11:44:16 +02001469void hmp_savevm(Monitor *mon, const QDict *qdict)
1470{
Juan Quintela927d6632017-04-18 18:12:35 +02001471 Error *err = NULL;
1472
Juan Quintela5e224792017-04-20 14:25:55 +02001473 save_snapshot(qdict_get_try_str(qdict, "name"), &err);
Juan Quintela927d6632017-04-18 18:12:35 +02001474 hmp_handle_error(mon, &err);
Juan Quintelad9c7d132017-04-18 11:44:16 +02001475}
1476
Juan Quintelad905bb72017-04-18 11:46:23 +02001477void hmp_delvm(Monitor *mon, const QDict *qdict)
1478{
1479 BlockDriverState *bs;
zhangjixiang32cd6552018-02-25 09:47:51 +08001480 Error *err = NULL;
Juan Quintelad905bb72017-04-18 11:46:23 +02001481 const char *name = qdict_get_str(qdict, "name");
1482
1483 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
1484 error_reportf_err(err,
1485 "Error while deleting snapshot on device '%s': ",
1486 bdrv_get_device_name(bs));
1487 }
1488}
1489
Juan Quintela66830612017-04-18 11:51:06 +02001490void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
1491{
1492 BlockDriverState *bs, *bs1;
1493 BdrvNextIterator it1;
1494 QEMUSnapshotInfo *sn_tab, *sn;
1495 bool no_snapshot = true;
1496 int nb_sns, i;
1497 int total;
1498 int *global_snapshots;
1499 AioContext *aio_context;
1500
1501 typedef struct SnapshotEntry {
1502 QEMUSnapshotInfo sn;
1503 QTAILQ_ENTRY(SnapshotEntry) next;
1504 } SnapshotEntry;
1505
1506 typedef struct ImageEntry {
1507 const char *imagename;
1508 QTAILQ_ENTRY(ImageEntry) next;
1509 QTAILQ_HEAD(, SnapshotEntry) snapshots;
1510 } ImageEntry;
1511
1512 QTAILQ_HEAD(, ImageEntry) image_list =
1513 QTAILQ_HEAD_INITIALIZER(image_list);
1514
1515 ImageEntry *image_entry, *next_ie;
1516 SnapshotEntry *snapshot_entry;
1517
1518 bs = bdrv_all_find_vmstate_bs();
1519 if (!bs) {
1520 monitor_printf(mon, "No available block device supports snapshots\n");
1521 return;
1522 }
1523 aio_context = bdrv_get_aio_context(bs);
1524
1525 aio_context_acquire(aio_context);
1526 nb_sns = bdrv_snapshot_list(bs, &sn_tab);
1527 aio_context_release(aio_context);
1528
1529 if (nb_sns < 0) {
1530 monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
1531 return;
1532 }
1533
1534 for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) {
1535 int bs1_nb_sns = 0;
1536 ImageEntry *ie;
1537 SnapshotEntry *se;
1538 AioContext *ctx = bdrv_get_aio_context(bs1);
1539
1540 aio_context_acquire(ctx);
1541 if (bdrv_can_snapshot(bs1)) {
1542 sn = NULL;
1543 bs1_nb_sns = bdrv_snapshot_list(bs1, &sn);
1544 if (bs1_nb_sns > 0) {
1545 no_snapshot = false;
1546 ie = g_new0(ImageEntry, 1);
1547 ie->imagename = bdrv_get_device_name(bs1);
1548 QTAILQ_INIT(&ie->snapshots);
1549 QTAILQ_INSERT_TAIL(&image_list, ie, next);
1550 for (i = 0; i < bs1_nb_sns; i++) {
1551 se = g_new0(SnapshotEntry, 1);
1552 se->sn = sn[i];
1553 QTAILQ_INSERT_TAIL(&ie->snapshots, se, next);
1554 }
1555 }
1556 g_free(sn);
1557 }
1558 aio_context_release(ctx);
1559 }
1560
1561 if (no_snapshot) {
1562 monitor_printf(mon, "There is no snapshot available.\n");
1563 return;
1564 }
1565
1566 global_snapshots = g_new0(int, nb_sns);
1567 total = 0;
1568 for (i = 0; i < nb_sns; i++) {
1569 SnapshotEntry *next_sn;
1570 if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) {
1571 global_snapshots[total] = i;
1572 total++;
1573 QTAILQ_FOREACH(image_entry, &image_list, next) {
1574 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots,
1575 next, next_sn) {
1576 if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) {
1577 QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry,
1578 next);
1579 g_free(snapshot_entry);
1580 }
1581 }
1582 }
1583 }
1584 }
1585
1586 monitor_printf(mon, "List of snapshots present on all disks:\n");
1587
1588 if (total > 0) {
1589 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1590 monitor_printf(mon, "\n");
1591 for (i = 0; i < total; i++) {
1592 sn = &sn_tab[global_snapshots[i]];
1593 /* The ID is not guaranteed to be the same on all images, so
1594 * overwrite it.
1595 */
1596 pstrcpy(sn->id_str, sizeof(sn->id_str), "--");
1597 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, sn);
1598 monitor_printf(mon, "\n");
1599 }
1600 } else {
1601 monitor_printf(mon, "None\n");
1602 }
1603
1604 QTAILQ_FOREACH(image_entry, &image_list, next) {
1605 if (QTAILQ_EMPTY(&image_entry->snapshots)) {
1606 continue;
1607 }
1608 monitor_printf(mon,
1609 "\nList of partial (non-loadable) snapshots on '%s':\n",
1610 image_entry->imagename);
1611 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1612 monitor_printf(mon, "\n");
1613 QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) {
1614 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon,
1615 &snapshot_entry->sn);
1616 monitor_printf(mon, "\n");
1617 }
1618 }
1619
1620 QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) {
1621 SnapshotEntry *next_sn;
1622 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next,
1623 next_sn) {
1624 g_free(snapshot_entry);
1625 }
1626 g_free(image_entry);
1627 }
1628 g_free(sn_tab);
1629 g_free(global_snapshots);
1630
1631}
1632
Dr. David Alan Gilbert544f6ea2019-02-27 13:24:12 +00001633void hmp_announce_self(Monitor *mon, const QDict *qdict)
1634{
1635 qmp_announce_self(migrate_announce_params(), NULL);
1636}
1637
Luiz Capitulino6cdedb02011-11-27 22:54:09 -02001638void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1639{
1640 qmp_migrate_cancel(NULL);
1641}
Luiz Capitulino4f0a9932011-11-27 23:18:01 -02001642
Dr. David Alan Gilbert94ae12c2017-10-20 10:05:54 +01001643void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1644{
1645 Error *err = NULL;
1646 const char *state = qdict_get_str(qdict, "state");
1647 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1648
1649 if (val >= 0) {
1650 qmp_migrate_continue(val, &err);
1651 }
1652
1653 hmp_handle_error(mon, &err);
1654}
1655
Dr. David Alan Gilbertbf1ae1f2015-02-19 11:40:28 +00001656void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1657{
1658 Error *err = NULL;
1659 const char *uri = qdict_get_str(qdict, "uri");
1660
1661 qmp_migrate_incoming(uri, &err);
1662
Dr. David Alan Gilbert1fa57f52015-02-26 14:54:39 +00001663 hmp_handle_error(mon, &err);
Dr. David Alan Gilbertbf1ae1f2015-02-19 11:40:28 +00001664}
1665
Peter Xu3b563c42018-05-02 18:47:37 +08001666void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
1667{
1668 Error *err = NULL;
1669 const char *uri = qdict_get_str(qdict, "uri");
1670
1671 qmp_migrate_recover(uri, &err);
1672
1673 hmp_handle_error(mon, &err);
1674}
1675
Peter Xud37297d2018-05-02 18:47:40 +08001676void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
1677{
1678 Error *err = NULL;
1679
1680 qmp_migrate_pause(&err);
1681
1682 hmp_handle_error(mon, &err);
1683}
1684
Ashijeet Acharya2ff30252016-09-15 21:50:28 +05301685/* Kept for backwards compatibility */
Luiz Capitulino4f0a9932011-11-27 23:18:01 -02001686void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1687{
1688 double value = qdict_get_double(qdict, "value");
1689 qmp_migrate_set_downtime(value, NULL);
1690}
Luiz Capitulino3dc85382011-11-28 11:59:37 -02001691
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +03001692void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1693{
1694 int64_t value = qdict_get_int(qdict, "value");
1695 Error *err = NULL;
1696
1697 qmp_migrate_set_cache_size(value, &err);
ZhiPeng Lu554a39e2017-10-19 19:16:33 +08001698 hmp_handle_error(mon, &err);
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +03001699}
1700
Ashijeet Acharya2ff30252016-09-15 21:50:28 +05301701/* Kept for backwards compatibility */
Luiz Capitulino3dc85382011-11-28 11:59:37 -02001702void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1703{
1704 int64_t value = qdict_get_int(qdict, "value");
1705 qmp_migrate_set_speed(value, NULL);
1706}
Luiz Capitulinofbf796f2011-12-07 11:17:51 -02001707
Orit Wasserman00458432012-08-06 21:42:48 +03001708void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1709{
1710 const char *cap = qdict_get_str(qdict, "capability");
1711 bool state = qdict_get_bool(qdict, "state");
1712 Error *err = NULL;
1713 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
Marc-André Lureau8e615e32017-08-24 10:46:00 +02001714 int val;
Orit Wasserman00458432012-08-06 21:42:48 +03001715
Marc-André Lureauf7abe0e2017-08-24 10:46:10 +02001716 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
Marc-André Lureau8e615e32017-08-24 10:46:00 +02001717 if (val < 0) {
1718 goto end;
Orit Wasserman00458432012-08-06 21:42:48 +03001719 }
1720
Marc-André Lureau8e615e32017-08-24 10:46:00 +02001721 caps->value = g_malloc0(sizeof(*caps->value));
1722 caps->value->capability = val;
1723 caps->value->state = state;
1724 caps->next = NULL;
1725 qmp_migrate_set_capabilities(caps, &err);
Orit Wasserman00458432012-08-06 21:42:48 +03001726
Marc-André Lureau8e615e32017-08-24 10:46:00 +02001727end:
Orit Wasserman00458432012-08-06 21:42:48 +03001728 qapi_free_MigrationCapabilityStatusList(caps);
ZhiPeng Lu554a39e2017-10-19 19:16:33 +08001729 hmp_handle_error(mon, &err);
Orit Wasserman00458432012-08-06 21:42:48 +03001730}
1731
Liang Li50e9a622015-03-23 16:32:29 +08001732void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1733{
1734 const char *param = qdict_get_str(qdict, "parameter");
Daniel P. Berrange69ef1f32016-04-27 11:05:15 +01001735 const char *valuestr = qdict_get_str(qdict, "value");
Juan Quintelaf4a06d12017-05-16 11:37:45 +02001736 Visitor *v = string_input_visitor_new(valuestr);
Markus Armbruster1bda8b32017-07-18 13:42:11 +02001737 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
Markus Armbrusterf46bfdb2017-02-21 21:14:07 +01001738 uint64_t valuebw = 0;
Juan Quintela73af8dd2017-10-05 21:30:10 +02001739 uint64_t cache_size;
Liang Li50e9a622015-03-23 16:32:29 +08001740 Error *err = NULL;
Marc-André Lureau262517b2017-08-24 10:46:01 +02001741 int val, ret;
Liang Li50e9a622015-03-23 16:32:29 +08001742
Marc-André Lureauf7abe0e2017-08-24 10:46:10 +02001743 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
Marc-André Lureau262517b2017-08-24 10:46:01 +02001744 if (val < 0) {
1745 goto cleanup;
1746 }
Daniel P. Berrange69ef1f32016-04-27 11:05:15 +01001747
Marc-André Lureau262517b2017-08-24 10:46:01 +02001748 switch (val) {
1749 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1750 p->has_compress_level = true;
1751 visit_type_int(v, param, &p->compress_level, &err);
1752 break;
1753 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1754 p->has_compress_threads = true;
1755 visit_type_int(v, param, &p->compress_threads, &err);
1756 break;
Xiao Guangrong1d588722018-08-21 16:10:20 +08001757 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD:
1758 p->has_compress_wait_thread = true;
1759 visit_type_bool(v, param, &p->compress_wait_thread, &err);
1760 break;
Marc-André Lureau262517b2017-08-24 10:46:01 +02001761 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1762 p->has_decompress_threads = true;
1763 visit_type_int(v, param, &p->decompress_threads, &err);
1764 break;
1765 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1766 p->has_cpu_throttle_initial = true;
1767 visit_type_int(v, param, &p->cpu_throttle_initial, &err);
1768 break;
1769 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1770 p->has_cpu_throttle_increment = true;
1771 visit_type_int(v, param, &p->cpu_throttle_increment, &err);
1772 break;
Li Qiang4cbc9c72018-08-01 06:00:20 -07001773 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE:
1774 p->has_max_cpu_throttle = true;
1775 visit_type_int(v, param, &p->max_cpu_throttle, &err);
1776 break;
Marc-André Lureau262517b2017-08-24 10:46:01 +02001777 case MIGRATION_PARAMETER_TLS_CREDS:
1778 p->has_tls_creds = true;
1779 p->tls_creds = g_new0(StrOrNull, 1);
1780 p->tls_creds->type = QTYPE_QSTRING;
1781 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1782 break;
1783 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1784 p->has_tls_hostname = true;
1785 p->tls_hostname = g_new0(StrOrNull, 1);
1786 p->tls_hostname->type = QTYPE_QSTRING;
1787 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1788 break;
1789 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1790 p->has_max_bandwidth = true;
1791 /*
1792 * Can't use visit_type_size() here, because it
1793 * defaults to Bytes rather than Mebibytes.
1794 */
1795 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1796 if (ret < 0 || valuebw > INT64_MAX
1797 || (size_t)valuebw != valuebw) {
1798 error_setg(&err, "Invalid size %s", valuestr);
Liang Li50e9a622015-03-23 16:32:29 +08001799 break;
1800 }
Marc-André Lureau262517b2017-08-24 10:46:01 +02001801 p->max_bandwidth = valuebw;
1802 break;
1803 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1804 p->has_downtime_limit = true;
1805 visit_type_int(v, param, &p->downtime_limit, &err);
1806 break;
1807 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1808 p->has_x_checkpoint_delay = true;
1809 visit_type_int(v, param, &p->x_checkpoint_delay, &err);
1810 break;
1811 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1812 p->has_block_incremental = true;
1813 visit_type_bool(v, param, &p->block_incremental, &err);
1814 break;
Juan Quintela4075fb12016-01-15 08:56:17 +01001815 case MIGRATION_PARAMETER_X_MULTIFD_CHANNELS:
1816 p->has_x_multifd_channels = true;
1817 visit_type_int(v, param, &p->x_multifd_channels, &err);
1818 break;
Juan Quintela0fb86602017-04-27 10:48:25 +02001819 case MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT:
1820 p->has_x_multifd_page_count = true;
1821 visit_type_int(v, param, &p->x_multifd_page_count, &err);
1822 break;
Juan Quintela73af8dd2017-10-05 21:30:10 +02001823 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1824 p->has_xbzrle_cache_size = true;
1825 visit_type_size(v, param, &cache_size, &err);
1826 if (err || cache_size > INT64_MAX
1827 || (size_t)cache_size != cache_size) {
1828 error_setg(&err, "Invalid size %s", valuestr);
1829 break;
1830 }
1831 p->xbzrle_cache_size = cache_size;
1832 break;
Dr. David Alan Gilbert7e555c62018-06-13 11:26:40 +01001833 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH:
1834 p->has_max_postcopy_bandwidth = true;
1835 visit_type_size(v, param, &p->max_postcopy_bandwidth, &err);
1836 break;
Dr. David Alan Gilbertee3d96b2019-02-27 13:24:06 +00001837 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL:
1838 p->has_announce_initial = true;
1839 visit_type_size(v, param, &p->announce_initial, &err);
1840 break;
1841 case MIGRATION_PARAMETER_ANNOUNCE_MAX:
1842 p->has_announce_max = true;
1843 visit_type_size(v, param, &p->announce_max, &err);
1844 break;
1845 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS:
1846 p->has_announce_rounds = true;
1847 visit_type_size(v, param, &p->announce_rounds, &err);
1848 break;
1849 case MIGRATION_PARAMETER_ANNOUNCE_STEP:
1850 p->has_announce_step = true;
1851 visit_type_size(v, param, &p->announce_step, &err);
1852 break;
Marc-André Lureau262517b2017-08-24 10:46:01 +02001853 default:
1854 assert(0);
Liang Li50e9a622015-03-23 16:32:29 +08001855 }
1856
Marc-André Lureau262517b2017-08-24 10:46:01 +02001857 if (err) {
1858 goto cleanup;
Liang Li50e9a622015-03-23 16:32:29 +08001859 }
1860
Marc-André Lureau262517b2017-08-24 10:46:01 +02001861 qmp_migrate_set_parameters(p, &err);
1862
Daniel P. Berrange69ef1f32016-04-27 11:05:15 +01001863 cleanup:
Markus Armbruster1bda8b32017-07-18 13:42:11 +02001864 qapi_free_MigrateSetParameters(p);
Juan Quintelaf4a06d12017-05-16 11:37:45 +02001865 visit_free(v);
ZhiPeng Lu554a39e2017-10-19 19:16:33 +08001866 hmp_handle_error(mon, &err);
Liang Li50e9a622015-03-23 16:32:29 +08001867}
1868
Markus Armbrusterb8a185b2015-03-05 17:29:02 +01001869void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1870{
1871 Error *err = NULL;
1872 const char *protocol = qdict_get_str(qdict, "protocol");
1873 const char *hostname = qdict_get_str(qdict, "hostname");
1874 bool has_port = qdict_haskey(qdict, "port");
1875 int port = qdict_get_try_int(qdict, "port", -1);
1876 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1877 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1878 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1879
1880 qmp_client_migrate_info(protocol, hostname,
1881 has_port, port, has_tls_port, tls_port,
1882 !!cert_subject, cert_subject, &err);
1883 hmp_handle_error(mon, &err);
1884}
1885
Dr. David Alan Gilbert4886a1b2015-11-05 18:10:56 +00001886void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1887{
1888 Error *err = NULL;
1889 qmp_migrate_start_postcopy(&err);
1890 hmp_handle_error(mon, &err);
1891}
1892
zhanghailiangd89e6662016-10-27 14:43:03 +08001893void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1894{
1895 Error *err = NULL;
1896
1897 qmp_x_colo_lost_heartbeat(&err);
1898 hmp_handle_error(mon, &err);
1899}
1900
Luiz Capitulinofbf796f2011-12-07 11:17:51 -02001901void hmp_set_password(Monitor *mon, const QDict *qdict)
1902{
1903 const char *protocol = qdict_get_str(qdict, "protocol");
1904 const char *password = qdict_get_str(qdict, "password");
1905 const char *connected = qdict_get_try_str(qdict, "connected");
1906 Error *err = NULL;
1907
1908 qmp_set_password(protocol, password, !!connected, connected, &err);
1909 hmp_handle_error(mon, &err);
1910}
Luiz Capitulino9ad53722011-12-07 11:47:57 -02001911
1912void hmp_expire_password(Monitor *mon, const QDict *qdict)
1913{
1914 const char *protocol = qdict_get_str(qdict, "protocol");
1915 const char *whenstr = qdict_get_str(qdict, "time");
1916 Error *err = NULL;
1917
1918 qmp_expire_password(protocol, whenstr, &err);
1919 hmp_handle_error(mon, &err);
1920}
Luiz Capitulinoc245b6a2011-12-07 16:02:36 -02001921
1922void hmp_eject(Monitor *mon, const QDict *qdict)
1923{
Eric Blake34acbc92015-05-15 16:25:00 -06001924 bool force = qdict_get_try_bool(qdict, "force", false);
Luiz Capitulinoc245b6a2011-12-07 16:02:36 -02001925 const char *device = qdict_get_str(qdict, "device");
1926 Error *err = NULL;
1927
Kevin Wolffbe2d812016-09-20 13:38:46 +02001928 qmp_eject(true, device, false, NULL, true, force, &err);
Luiz Capitulinoc245b6a2011-12-07 16:02:36 -02001929 hmp_handle_error(mon, &err);
1930}
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001931
Marc-André Lureau05eb4a22018-07-03 17:56:47 +02001932#ifdef CONFIG_VNC
Stefan Hajnoczic60bf332013-11-14 11:54:14 +01001933static void hmp_change_read_arg(void *opaque, const char *password,
1934 void *readline_opaque)
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001935{
1936 qmp_change_vnc_password(password, NULL);
Stefan Hajnoczic60bf332013-11-14 11:54:14 +01001937 monitor_read_command(opaque, 1);
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001938}
Marc-André Lureau05eb4a22018-07-03 17:56:47 +02001939#endif
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001940
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001941void hmp_change(Monitor *mon, const QDict *qdict)
1942{
1943 const char *device = qdict_get_str(qdict, "device");
1944 const char *target = qdict_get_str(qdict, "target");
1945 const char *arg = qdict_get_try_str(qdict, "arg");
Max Reitzbaead0a2015-10-26 21:39:18 +01001946 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1947 BlockdevChangeReadOnlyMode read_only_mode = 0;
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001948 Error *err = NULL;
1949
Marc-André Lureau05eb4a22018-07-03 17:56:47 +02001950#ifdef CONFIG_VNC
Max Reitz10686742015-10-26 21:39:16 +01001951 if (strcmp(device, "vnc") == 0) {
Max Reitzbaead0a2015-10-26 21:39:18 +01001952 if (read_only) {
1953 monitor_printf(mon,
1954 "Parameter 'read-only-mode' is invalid for VNC\n");
1955 return;
1956 }
Max Reitz10686742015-10-26 21:39:16 +01001957 if (strcmp(target, "passwd") == 0 ||
1958 strcmp(target, "password") == 0) {
1959 if (!arg) {
1960 monitor_read_password(mon, hmp_change_read_arg, NULL);
1961 return;
1962 }
1963 }
1964 qmp_change("vnc", target, !!arg, arg, &err);
Marc-André Lureau05eb4a22018-07-03 17:56:47 +02001965 } else
1966#endif
1967 {
Max Reitzbaead0a2015-10-26 21:39:18 +01001968 if (read_only) {
1969 read_only_mode =
Marc-André Lureauf7abe0e2017-08-24 10:46:10 +02001970 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
Markus Armbruster06c60b62017-08-24 10:45:57 +02001971 read_only,
Max Reitzbaead0a2015-10-26 21:39:18 +01001972 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1973 if (err) {
1974 hmp_handle_error(mon, &err);
1975 return;
1976 }
1977 }
1978
Kevin Wolf70e2cb32016-09-20 13:38:47 +02001979 qmp_blockdev_change_medium(true, device, false, NULL, target,
1980 !!arg, arg, !!read_only, read_only_mode,
1981 &err);
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001982 }
1983
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001984 hmp_handle_error(mon, &err);
1985}
Luiz Capitulino80047da2011-12-14 16:49:14 -02001986
1987void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1988{
1989 Error *err = NULL;
Alberto Garcia83592182018-03-09 16:11:07 +02001990 char *device = (char *) qdict_get_str(qdict, "device");
Eric Blake4dc93972016-07-13 21:50:21 -06001991 BlockIOThrottle throttle = {
Eric Blake4dc93972016-07-13 21:50:21 -06001992 .bps = qdict_get_int(qdict, "bps"),
1993 .bps_rd = qdict_get_int(qdict, "bps_rd"),
1994 .bps_wr = qdict_get_int(qdict, "bps_wr"),
1995 .iops = qdict_get_int(qdict, "iops"),
1996 .iops_rd = qdict_get_int(qdict, "iops_rd"),
1997 .iops_wr = qdict_get_int(qdict, "iops_wr"),
1998 };
Luiz Capitulino80047da2011-12-14 16:49:14 -02001999
Alberto Garcia83592182018-03-09 16:11:07 +02002000 /* qmp_block_set_io_throttle has separate parameters for the
2001 * (deprecated) block device name and the qdev ID but the HMP
2002 * version has only one, so we must decide which one to pass. */
2003 if (blk_by_name(device)) {
2004 throttle.has_device = true;
2005 throttle.device = device;
2006 } else {
2007 throttle.has_id = true;
2008 throttle.id = device;
2009 }
2010
Eric Blake4dc93972016-07-13 21:50:21 -06002011 qmp_block_set_io_throttle(&throttle, &err);
Luiz Capitulino80047da2011-12-14 16:49:14 -02002012 hmp_handle_error(mon, &err);
2013}
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00002014
2015void hmp_block_stream(Monitor *mon, const QDict *qdict)
2016{
2017 Error *error = NULL;
2018 const char *device = qdict_get_str(qdict, "device");
2019 const char *base = qdict_get_try_str(qdict, "base");
Stefan Hajnoczic83c66c2012-04-25 16:51:03 +01002020 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00002021
Alberto Garcia11d6fbe2016-11-04 15:44:43 +02002022 qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
John Snow241ca1a2018-09-06 09:02:23 -04002023 false, NULL, qdict_haskey(qdict, "speed"), speed, true,
2024 BLOCKDEV_ON_ERROR_REPORT, false, false, false, false,
2025 &error);
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00002026
2027 hmp_handle_error(mon, &error);
2028}
Stefan Hajnoczi2d47c6e2012-01-18 14:40:47 +00002029
2030void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
2031{
2032 Error *error = NULL;
2033 const char *device = qdict_get_str(qdict, "device");
Paolo Bonzinic6db2392012-05-08 16:51:56 +02002034 int64_t value = qdict_get_int(qdict, "speed");
Stefan Hajnoczi2d47c6e2012-01-18 14:40:47 +00002035
2036 qmp_block_job_set_speed(device, value, &error);
2037
2038 hmp_handle_error(mon, &error);
2039}
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00002040
2041void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
2042{
2043 Error *error = NULL;
2044 const char *device = qdict_get_str(qdict, "device");
Eric Blake34acbc92015-05-15 16:25:00 -06002045 bool force = qdict_get_try_bool(qdict, "force", false);
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00002046
Paolo Bonzini6e37fb82012-09-28 17:22:51 +02002047 qmp_block_job_cancel(device, true, force, &error);
2048
2049 hmp_handle_error(mon, &error);
2050}
2051
2052void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
2053{
2054 Error *error = NULL;
2055 const char *device = qdict_get_str(qdict, "device");
2056
2057 qmp_block_job_pause(device, &error);
2058
2059 hmp_handle_error(mon, &error);
2060}
2061
2062void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
2063{
2064 Error *error = NULL;
2065 const char *device = qdict_get_str(qdict, "device");
2066
2067 qmp_block_job_resume(device, &error);
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00002068
2069 hmp_handle_error(mon, &error);
2070}
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002071
Paolo Bonziniaeae8832012-10-18 16:49:21 +02002072void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
2073{
2074 Error *error = NULL;
2075 const char *device = qdict_get_str(qdict, "device");
2076
2077 qmp_block_job_complete(device, &error);
2078
2079 hmp_handle_error(mon, &error);
2080}
2081
zhanghailiange49f35b2015-03-13 16:08:39 +08002082typedef struct HMPMigrationStatus
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002083{
2084 QEMUTimer *timer;
2085 Monitor *mon;
2086 bool is_block_migration;
zhanghailiange49f35b2015-03-13 16:08:39 +08002087} HMPMigrationStatus;
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002088
2089static void hmp_migrate_status_cb(void *opaque)
2090{
zhanghailiange49f35b2015-03-13 16:08:39 +08002091 HMPMigrationStatus *status = opaque;
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002092 MigrationInfo *info;
2093
2094 info = qmp_query_migrate(NULL);
zhanghailiang24b8c392015-03-13 16:08:40 +08002095 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
2096 info->status == MIGRATION_STATUS_SETUP) {
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002097 if (info->has_disk) {
2098 int progress;
2099
2100 if (info->disk->remaining) {
2101 progress = info->disk->transferred * 100 / info->disk->total;
2102 } else {
2103 progress = 100;
2104 }
2105
2106 monitor_printf(status->mon, "Completed %d %%\r", progress);
2107 monitor_flush(status->mon);
2108 }
2109
Alex Blighbc72ad62013-08-21 16:03:08 +01002110 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002111 } else {
2112 if (status->is_block_migration) {
2113 monitor_printf(status->mon, "\n");
2114 }
Daniel P. Berranged59ce6f2016-04-27 11:05:00 +01002115 if (info->has_error_desc) {
2116 error_report("%s", info->error_desc);
2117 }
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002118 monitor_resume(status->mon);
Alex Blighbc72ad62013-08-21 16:03:08 +01002119 timer_del(status->timer);
Marc-André Lureaud34a10a2018-09-01 15:46:52 +02002120 timer_free(status->timer);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002121 g_free(status);
2122 }
2123
2124 qapi_free_MigrationInfo(info);
2125}
2126
2127void hmp_migrate(Monitor *mon, const QDict *qdict)
2128{
Eric Blake34acbc92015-05-15 16:25:00 -06002129 bool detach = qdict_get_try_bool(qdict, "detach", false);
2130 bool blk = qdict_get_try_bool(qdict, "blk", false);
2131 bool inc = qdict_get_try_bool(qdict, "inc", false);
Peter Xu7a4da282018-05-02 18:47:23 +08002132 bool resume = qdict_get_try_bool(qdict, "resume", false);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002133 const char *uri = qdict_get_str(qdict, "uri");
2134 Error *err = NULL;
2135
Peter Xu7a4da282018-05-02 18:47:23 +08002136 qmp_migrate(uri, !!blk, blk, !!inc, inc,
2137 false, false, true, resume, &err);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002138 if (err) {
ZhiPeng Lu554a39e2017-10-19 19:16:33 +08002139 hmp_handle_error(mon, &err);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002140 return;
2141 }
2142
2143 if (!detach) {
zhanghailiange49f35b2015-03-13 16:08:39 +08002144 HMPMigrationStatus *status;
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002145
2146 if (monitor_suspend(mon) < 0) {
2147 monitor_printf(mon, "terminal does not allow synchronous "
2148 "migration, continuing detached\n");
2149 return;
2150 }
2151
2152 status = g_malloc0(sizeof(*status));
2153 status->mon = mon;
2154 status->is_block_migration = blk || inc;
Alex Blighbc72ad62013-08-21 16:03:08 +01002155 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002156 status);
Alex Blighbc72ad62013-08-21 16:03:08 +01002157 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002158 }
2159}
Luiz Capitulinoa15fef22012-03-29 12:38:50 -03002160
Markus Armbruster318660f2015-03-05 17:24:48 +01002161void hmp_device_add(Monitor *mon, const QDict *qdict)
2162{
Markus Armbruster485febc2015-03-13 17:25:50 +01002163 Error *err = NULL;
2164
2165 qmp_device_add((QDict *)qdict, NULL, &err);
2166 hmp_handle_error(mon, &err);
Markus Armbruster318660f2015-03-05 17:24:48 +01002167}
2168
Luiz Capitulinoa15fef22012-03-29 12:38:50 -03002169void hmp_device_del(Monitor *mon, const QDict *qdict)
2170{
2171 const char *id = qdict_get_str(qdict, "id");
2172 Error *err = NULL;
2173
2174 qmp_device_del(id, &err);
2175 hmp_handle_error(mon, &err);
2176}
Wen Congyang783e9b42012-05-07 12:10:47 +08002177
2178void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
2179{
Markus Armbrustere940f542014-05-02 13:26:29 +02002180 Error *err = NULL;
Viktor Prutyanov2da91b52018-05-17 19:23:39 +03002181 bool win_dmp = qdict_get_try_bool(qdict, "windmp", false);
Eric Blake34acbc92015-05-15 16:25:00 -06002182 bool paging = qdict_get_try_bool(qdict, "paging", false);
2183 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
2184 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
2185 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
Luiz Capitulino75363762012-09-21 13:53:00 -03002186 const char *file = qdict_get_str(qdict, "filename");
Wen Congyang783e9b42012-05-07 12:10:47 +08002187 bool has_begin = qdict_haskey(qdict, "begin");
2188 bool has_length = qdict_haskey(qdict, "length");
Peter Xu228de9c2016-02-18 13:16:47 +08002189 bool has_detach = qdict_haskey(qdict, "detach");
Wen Congyang783e9b42012-05-07 12:10:47 +08002190 int64_t begin = 0;
2191 int64_t length = 0;
Peter Xu228de9c2016-02-18 13:16:47 +08002192 bool detach = false;
qiaonuohanb53ccc32014-02-18 14:11:36 +08002193 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
Luiz Capitulino75363762012-09-21 13:53:00 -03002194 char *prot;
Wen Congyang783e9b42012-05-07 12:10:47 +08002195
Viktor Prutyanov2da91b52018-05-17 19:23:39 +03002196 if (zlib + lzo + snappy + win_dmp > 1) {
2197 error_setg(&err, "only one of '-z|-l|-s|-w' can be set");
Markus Armbrustere940f542014-05-02 13:26:29 +02002198 hmp_handle_error(mon, &err);
Qiao Nuohan1b7a0f72014-04-17 16:15:07 +08002199 return;
2200 }
2201
Viktor Prutyanov2da91b52018-05-17 19:23:39 +03002202 if (win_dmp) {
2203 dump_format = DUMP_GUEST_MEMORY_FORMAT_WIN_DMP;
2204 }
2205
Qiao Nuohan1b7a0f72014-04-17 16:15:07 +08002206 if (zlib) {
2207 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
2208 }
2209
2210 if (lzo) {
2211 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
2212 }
2213
2214 if (snappy) {
2215 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
2216 }
2217
Wen Congyang783e9b42012-05-07 12:10:47 +08002218 if (has_begin) {
2219 begin = qdict_get_int(qdict, "begin");
2220 }
2221 if (has_length) {
2222 length = qdict_get_int(qdict, "length");
2223 }
Peter Xu228de9c2016-02-18 13:16:47 +08002224 if (has_detach) {
2225 detach = qdict_get_bool(qdict, "detach");
2226 }
Wen Congyang783e9b42012-05-07 12:10:47 +08002227
Luiz Capitulino75363762012-09-21 13:53:00 -03002228 prot = g_strconcat("file:", file, NULL);
2229
Peter Xu228de9c2016-02-18 13:16:47 +08002230 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
2231 has_length, length, true, dump_format, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +02002232 hmp_handle_error(mon, &err);
Luiz Capitulino75363762012-09-21 13:53:00 -03002233 g_free(prot);
Wen Congyang783e9b42012-05-07 12:10:47 +08002234}
Luiz Capitulino928059a2012-04-18 17:34:15 -03002235
2236void hmp_netdev_add(Monitor *mon, const QDict *qdict)
2237{
2238 Error *err = NULL;
2239 QemuOpts *opts;
2240
2241 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
Markus Armbruster84d18f02014-01-30 15:07:28 +01002242 if (err) {
Luiz Capitulino928059a2012-04-18 17:34:15 -03002243 goto out;
2244 }
2245
2246 netdev_add(opts, &err);
Markus Armbruster84d18f02014-01-30 15:07:28 +01002247 if (err) {
Luiz Capitulino928059a2012-04-18 17:34:15 -03002248 qemu_opts_del(opts);
2249 }
2250
2251out:
2252 hmp_handle_error(mon, &err);
2253}
Luiz Capitulino5f964152012-04-16 14:36:32 -03002254
2255void hmp_netdev_del(Monitor *mon, const QDict *qdict)
2256{
2257 const char *id = qdict_get_str(qdict, "id");
2258 Error *err = NULL;
2259
2260 qmp_netdev_del(id, &err);
2261 hmp_handle_error(mon, &err);
2262}
Corey Bryant208c9d12012-06-22 14:36:09 -04002263
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01002264void hmp_object_add(Monitor *mon, const QDict *qdict)
2265{
2266 Error *err = NULL;
2267 QemuOpts *opts;
Daniel P. Berrange90998d52016-02-10 18:40:59 +00002268 Object *obj = NULL;
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01002269
2270 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
2271 if (err) {
Daniel P. Berrange90998d52016-02-10 18:40:59 +00002272 hmp_handle_error(mon, &err);
2273 return;
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01002274 }
2275
Igor Mammedov3a464102017-01-10 13:53:14 +01002276 obj = user_creatable_add_opts(opts, &err);
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01002277 qemu_opts_del(opts);
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01002278
Daniel P. Berrange90998d52016-02-10 18:40:59 +00002279 if (err) {
2280 hmp_handle_error(mon, &err);
2281 }
2282 if (obj) {
2283 object_unref(obj);
2284 }
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01002285}
2286
Corey Bryant208c9d12012-06-22 14:36:09 -04002287void hmp_getfd(Monitor *mon, const QDict *qdict)
2288{
2289 const char *fdname = qdict_get_str(qdict, "fdname");
Markus Armbrustere940f542014-05-02 13:26:29 +02002290 Error *err = NULL;
Corey Bryant208c9d12012-06-22 14:36:09 -04002291
Markus Armbrustere940f542014-05-02 13:26:29 +02002292 qmp_getfd(fdname, &err);
2293 hmp_handle_error(mon, &err);
Corey Bryant208c9d12012-06-22 14:36:09 -04002294}
2295
2296void hmp_closefd(Monitor *mon, const QDict *qdict)
2297{
2298 const char *fdname = qdict_get_str(qdict, "fdname");
Markus Armbrustere940f542014-05-02 13:26:29 +02002299 Error *err = NULL;
Corey Bryant208c9d12012-06-22 14:36:09 -04002300
Markus Armbrustere940f542014-05-02 13:26:29 +02002301 qmp_closefd(fdname, &err);
2302 hmp_handle_error(mon, &err);
Corey Bryant208c9d12012-06-22 14:36:09 -04002303}
Amos Konge4c8f002012-08-31 10:56:26 +08002304
Markus Armbruster3e5a50d2015-02-06 13:55:43 +01002305void hmp_sendkey(Monitor *mon, const QDict *qdict)
Amos Konge4c8f002012-08-31 10:56:26 +08002306{
2307 const char *keys = qdict_get_str(qdict, "keys");
Luiz Capitulino9f328972012-09-20 14:19:47 -03002308 KeyValueList *keylist, *head = NULL, *tmp = NULL;
Amos Konge4c8f002012-08-31 10:56:26 +08002309 int has_hold_time = qdict_haskey(qdict, "hold-time");
2310 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
2311 Error *err = NULL;
Keno Fischer5c99fa32018-06-29 12:32:10 +02002312 const char *separator;
Luiz Capitulino9f328972012-09-20 14:19:47 -03002313 int keyname_len;
Amos Konge4c8f002012-08-31 10:56:26 +08002314
2315 while (1) {
Keno Fischer5c99fa32018-06-29 12:32:10 +02002316 separator = qemu_strchrnul(keys, '-');
2317 keyname_len = separator - keys;
Amos Konge4c8f002012-08-31 10:56:26 +08002318
2319 /* Be compatible with old interface, convert user inputted "<" */
Wolfgang Bumiller64ffbe02016-01-13 09:09:58 +01002320 if (keys[0] == '<' && keyname_len == 1) {
2321 keys = "less";
Amos Konge4c8f002012-08-31 10:56:26 +08002322 keyname_len = 4;
2323 }
Amos Konge4c8f002012-08-31 10:56:26 +08002324
Amos Konge4c8f002012-08-31 10:56:26 +08002325 keylist = g_malloc0(sizeof(*keylist));
Luiz Capitulino9f328972012-09-20 14:19:47 -03002326 keylist->value = g_malloc0(sizeof(*keylist->value));
Amos Konge4c8f002012-08-31 10:56:26 +08002327
2328 if (!head) {
2329 head = keylist;
2330 }
2331 if (tmp) {
2332 tmp->next = keylist;
2333 }
2334 tmp = keylist;
2335
Wolfgang Bumiller64ffbe02016-01-13 09:09:58 +01002336 if (strstart(keys, "0x", NULL)) {
Luiz Capitulino9f328972012-09-20 14:19:47 -03002337 char *endp;
Wolfgang Bumiller64ffbe02016-01-13 09:09:58 +01002338 int value = strtoul(keys, &endp, 0);
2339 assert(endp <= keys + keyname_len);
2340 if (endp != keys + keyname_len) {
Luiz Capitulino9f328972012-09-20 14:19:47 -03002341 goto err_out;
2342 }
Eric Blake568c73a2015-10-26 16:34:58 -06002343 keylist->value->type = KEY_VALUE_KIND_NUMBER;
Eric Blake32bafa82016-03-17 16:48:37 -06002344 keylist->value->u.number.data = value;
Luiz Capitulino9f328972012-09-20 14:19:47 -03002345 } else {
Wolfgang Bumiller64ffbe02016-01-13 09:09:58 +01002346 int idx = index_from_key(keys, keyname_len);
Eric Blake7fb1cf12015-11-18 01:52:57 -07002347 if (idx == Q_KEY_CODE__MAX) {
Luiz Capitulino9f328972012-09-20 14:19:47 -03002348 goto err_out;
2349 }
Eric Blake568c73a2015-10-26 16:34:58 -06002350 keylist->value->type = KEY_VALUE_KIND_QCODE;
Eric Blake32bafa82016-03-17 16:48:37 -06002351 keylist->value->u.qcode.data = idx;
Luiz Capitulino9f328972012-09-20 14:19:47 -03002352 }
2353
Keno Fischer5c99fa32018-06-29 12:32:10 +02002354 if (!*separator) {
Amos Konge4c8f002012-08-31 10:56:26 +08002355 break;
2356 }
2357 keys = separator + 1;
2358 }
2359
Luiz Capitulino9f328972012-09-20 14:19:47 -03002360 qmp_send_key(head, has_hold_time, hold_time, &err);
Amos Konge4c8f002012-08-31 10:56:26 +08002361 hmp_handle_error(mon, &err);
Luiz Capitulino9f328972012-09-20 14:19:47 -03002362
2363out:
2364 qapi_free_KeyValueList(head);
2365 return;
2366
2367err_out:
Wolfgang Bumiller64ffbe02016-01-13 09:09:58 +01002368 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
Luiz Capitulino9f328972012-09-20 14:19:47 -03002369 goto out;
Amos Konge4c8f002012-08-31 10:56:26 +08002370}
Luiz Capitulinoad39cf62012-05-24 13:48:23 -03002371
Markus Armbruster3e5a50d2015-02-06 13:55:43 +01002372void hmp_screendump(Monitor *mon, const QDict *qdict)
Luiz Capitulinoad39cf62012-05-24 13:48:23 -03002373{
2374 const char *filename = qdict_get_str(qdict, "filename");
Thomas Huthf771c542018-03-05 17:37:48 +01002375 const char *id = qdict_get_try_str(qdict, "device");
2376 int64_t head = qdict_get_try_int(qdict, "head", 0);
Luiz Capitulinoad39cf62012-05-24 13:48:23 -03002377 Error *err = NULL;
2378
Thomas Huthf771c542018-03-05 17:37:48 +01002379 qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
Luiz Capitulinoad39cf62012-05-24 13:48:23 -03002380 hmp_handle_error(mon, &err);
2381}
Paolo Bonzini40577252012-08-23 11:53:04 +02002382
2383void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
2384{
2385 const char *uri = qdict_get_str(qdict, "uri");
Eric Blake34acbc92015-05-15 16:25:00 -06002386 bool writable = qdict_get_try_bool(qdict, "writable", false);
2387 bool all = qdict_get_try_bool(qdict, "all", false);
Paolo Bonzini40577252012-08-23 11:53:04 +02002388 Error *local_err = NULL;
2389 BlockInfoList *block_list, *info;
Markus Armbrusterbd269eb2017-04-26 09:36:41 +02002390 SocketAddress *addr;
Paolo Bonzini40577252012-08-23 11:53:04 +02002391
2392 if (writable && !all) {
2393 error_setg(&local_err, "-w only valid together with -a");
2394 goto exit;
2395 }
2396
2397 /* First check if the address is valid and start the server. */
2398 addr = socket_parse(uri, &local_err);
2399 if (local_err != NULL) {
2400 goto exit;
2401 }
2402
Daniel P. Berrange00019452019-02-27 16:20:34 +00002403 nbd_server_start(addr, NULL, NULL, &local_err);
Markus Armbrusterbd269eb2017-04-26 09:36:41 +02002404 qapi_free_SocketAddress(addr);
Paolo Bonzini40577252012-08-23 11:53:04 +02002405 if (local_err != NULL) {
2406 goto exit;
2407 }
2408
2409 if (!all) {
2410 return;
2411 }
2412
2413 /* Then try adding all block devices. If one fails, close all and
2414 * exit.
2415 */
2416 block_list = qmp_query_block(NULL);
2417
2418 for (info = block_list; info; info = info->next) {
2419 if (!info->value->has_inserted) {
2420 continue;
2421 }
2422
Vladimir Sementsov-Ogievskiy902a1f92018-01-19 16:57:15 +03002423 qmp_nbd_server_add(info->value->device, false, NULL,
Eric Blake5fcbeb02019-01-11 13:47:17 -06002424 true, writable, false, NULL, &local_err);
Paolo Bonzini40577252012-08-23 11:53:04 +02002425
2426 if (local_err != NULL) {
2427 qmp_nbd_server_stop(NULL);
2428 break;
2429 }
2430 }
2431
2432 qapi_free_BlockInfoList(block_list);
2433
2434exit:
2435 hmp_handle_error(mon, &local_err);
2436}
2437
2438void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
2439{
2440 const char *device = qdict_get_str(qdict, "device");
Eric Blakedba49322018-01-09 13:28:02 -06002441 const char *name = qdict_get_try_str(qdict, "name");
Eric Blake34acbc92015-05-15 16:25:00 -06002442 bool writable = qdict_get_try_bool(qdict, "writable", false);
Paolo Bonzini40577252012-08-23 11:53:04 +02002443 Error *local_err = NULL;
2444
Eric Blake5fcbeb02019-01-11 13:47:17 -06002445 qmp_nbd_server_add(device, !!name, name, true, writable,
2446 false, NULL, &local_err);
Eric Blake08fb10a2018-01-25 08:45:57 -06002447 hmp_handle_error(mon, &local_err);
2448}
Paolo Bonzini40577252012-08-23 11:53:04 +02002449
Eric Blake08fb10a2018-01-25 08:45:57 -06002450void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict)
2451{
2452 const char *name = qdict_get_str(qdict, "name");
2453 bool force = qdict_get_try_bool(qdict, "force", false);
2454 Error *err = NULL;
2455
2456 /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
2457 qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err);
2458 hmp_handle_error(mon, &err);
Paolo Bonzini40577252012-08-23 11:53:04 +02002459}
2460
2461void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
2462{
Markus Armbrustere940f542014-05-02 13:26:29 +02002463 Error *err = NULL;
Paolo Bonzini40577252012-08-23 11:53:04 +02002464
Markus Armbrustere940f542014-05-02 13:26:29 +02002465 qmp_nbd_server_stop(&err);
2466 hmp_handle_error(mon, &err);
Paolo Bonzini40577252012-08-23 11:53:04 +02002467}
Gerd Hoffmannf1088902012-12-19 10:33:40 +01002468
Jason J. Herneabf23322013-12-11 13:24:14 -05002469void hmp_cpu_add(Monitor *mon, const QDict *qdict)
2470{
2471 int cpuid;
2472 Error *err = NULL;
2473
Kashyap Chamarthye25701b2018-10-30 13:35:25 +01002474 error_report("cpu_add is deprecated, please use device_add instead");
2475
Jason J. Herneabf23322013-12-11 13:24:14 -05002476 cpuid = qdict_get_int(qdict, "id");
2477 qmp_cpu_add(cpuid, &err);
2478 hmp_handle_error(mon, &err);
2479}
2480
Gerd Hoffmannf1088902012-12-19 10:33:40 +01002481void hmp_chardev_add(Monitor *mon, const QDict *qdict)
2482{
2483 const char *args = qdict_get_str(qdict, "args");
2484 Error *err = NULL;
2485 QemuOpts *opts;
2486
Markus Armbruster70b94332015-02-13 12:50:26 +01002487 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
Gerd Hoffmannf1088902012-12-19 10:33:40 +01002488 if (opts == NULL) {
Markus Armbruster312fd5f2013-02-08 21:22:16 +01002489 error_setg(&err, "Parsing chardev args failed");
Gerd Hoffmannf1088902012-12-19 10:33:40 +01002490 } else {
Paolo Bonzini4ad6f6c2019-02-13 14:18:13 +01002491 qemu_chr_new_from_opts(opts, NULL, &err);
Daniel P. Berrange0a733362016-10-07 13:18:34 +01002492 qemu_opts_del(opts);
Gerd Hoffmannf1088902012-12-19 10:33:40 +01002493 }
2494 hmp_handle_error(mon, &err);
2495}
2496
Anton Nefedov75b60162017-07-06 15:08:57 +03002497void hmp_chardev_change(Monitor *mon, const QDict *qdict)
2498{
2499 const char *args = qdict_get_str(qdict, "args");
2500 const char *id;
2501 Error *err = NULL;
2502 ChardevBackend *backend = NULL;
2503 ChardevReturn *ret = NULL;
2504 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
2505 true);
2506 if (!opts) {
2507 error_setg(&err, "Parsing chardev args failed");
2508 goto end;
2509 }
2510
2511 id = qdict_get_str(qdict, "id");
2512 if (qemu_opts_id(opts)) {
2513 error_setg(&err, "Unexpected 'id' parameter");
2514 goto end;
2515 }
2516
2517 backend = qemu_chr_parse_opts(opts, &err);
2518 if (!backend) {
2519 goto end;
2520 }
2521
2522 ret = qmp_chardev_change(id, backend, &err);
2523
2524end:
2525 qapi_free_ChardevReturn(ret);
2526 qapi_free_ChardevBackend(backend);
2527 qemu_opts_del(opts);
2528 hmp_handle_error(mon, &err);
2529}
2530
Gerd Hoffmannf1088902012-12-19 10:33:40 +01002531void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
2532{
2533 Error *local_err = NULL;
2534
2535 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
2536 hmp_handle_error(mon, &local_err);
2537}
Kevin Wolf587da2c2013-06-05 14:19:41 +02002538
Stefan Fritschbd1d5ad2017-06-11 09:48:17 +02002539void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
2540{
2541 Error *local_err = NULL;
2542
2543 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
2544 hmp_handle_error(mon, &local_err);
2545}
2546
Kevin Wolf587da2c2013-06-05 14:19:41 +02002547void hmp_qemu_io(Monitor *mon, const QDict *qdict)
2548{
Max Reitz4c7b7e92015-02-05 13:58:22 -05002549 BlockBackend *blk;
Kevin Wolfe7f98f22016-07-13 17:27:51 +02002550 BlockBackend *local_blk = NULL;
Kevin Wolf587da2c2013-06-05 14:19:41 +02002551 const char* device = qdict_get_str(qdict, "device");
2552 const char* command = qdict_get_str(qdict, "command");
2553 Error *err = NULL;
Kevin Wolfd7086422017-01-13 19:02:32 +01002554 int ret;
Kevin Wolf587da2c2013-06-05 14:19:41 +02002555
Max Reitz4c7b7e92015-02-05 13:58:22 -05002556 blk = blk_by_name(device);
Kevin Wolfe7f98f22016-07-13 17:27:51 +02002557 if (!blk) {
2558 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
2559 if (bs) {
Kevin Wolf6d0eb642017-01-20 17:07:26 +01002560 blk = local_blk = blk_new(0, BLK_PERM_ALL);
Kevin Wolfd7086422017-01-13 19:02:32 +01002561 ret = blk_insert_bs(blk, bs, &err);
2562 if (ret < 0) {
2563 goto fail;
2564 }
Kevin Wolfe7f98f22016-07-13 17:27:51 +02002565 } else {
2566 goto fail;
2567 }
2568 }
2569
Kevin Wolf887354b2017-02-10 16:24:56 +01002570 /*
2571 * Notably absent: Proper permission management. This is sad, but it seems
2572 * almost impossible to achieve without changing the semantics and thereby
2573 * limiting the use cases of the qemu-io HMP command.
2574 *
2575 * In an ideal world we would unconditionally create a new BlockBackend for
2576 * qemuio_command(), but we have commands like 'reopen' and want them to
2577 * take effect on the exact BlockBackend whose name the user passed instead
2578 * of just on a temporary copy of it.
2579 *
2580 * Another problem is that deleting the temporary BlockBackend involves
2581 * draining all requests on it first, but some qemu-iotests cases want to
2582 * issue multiple aio_read/write requests and expect them to complete in
2583 * the background while the monitor has already returned.
2584 *
2585 * This is also what prevents us from saving the original permissions and
2586 * restoring them later: We can't revoke permissions until all requests
2587 * have completed, and we don't know when that is nor can we really let
2588 * anything else run before we have revoken them to avoid race conditions.
2589 *
2590 * What happens now is that command() in qemu-io-cmds.c can extend the
2591 * permissions if necessary for the qemu-io command. And they simply stay
2592 * extended, possibly resulting in a read-only guest device keeping write
2593 * permissions. Ugly, but it appears to be the lesser evil.
2594 */
Kevin Wolf1813d332016-09-15 17:44:16 +02002595 qemuio_command(blk, command);
Vladimir Sementsov-Ogievskiy479b5992016-06-08 12:39:17 +03002596
Kevin Wolfe7f98f22016-07-13 17:27:51 +02002597fail:
2598 blk_unref(local_blk);
Kevin Wolf587da2c2013-06-05 14:19:41 +02002599 hmp_handle_error(mon, &err);
2600}
Paolo Bonziniab2d0532013-12-20 23:21:09 +01002601
2602void hmp_object_del(Monitor *mon, const QDict *qdict)
2603{
2604 const char *id = qdict_get_str(qdict, "id");
2605 Error *err = NULL;
2606
Daniel P. Berrange90998d52016-02-10 18:40:59 +00002607 user_creatable_del(id, &err);
Paolo Bonziniab2d0532013-12-20 23:21:09 +01002608 hmp_handle_error(mon, &err);
2609}
Hu Taoeb1539b2014-05-14 17:43:35 +08002610
2611void hmp_info_memdev(Monitor *mon, const QDict *qdict)
2612{
2613 Error *err = NULL;
2614 MemdevList *memdev_list = qmp_query_memdev(&err);
2615 MemdevList *m = memdev_list;
Eric Blake3b098d52016-06-09 10:48:43 -06002616 Visitor *v;
Chen Fan976620a2014-08-18 14:46:34 +08002617 char *str;
Hu Taoeb1539b2014-05-14 17:43:35 +08002618
2619 while (m) {
Eric Blake3b098d52016-06-09 10:48:43 -06002620 v = string_output_visitor_new(false, &str);
2621 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
Igor Mammedove1ff3c62017-01-10 13:53:15 +01002622 monitor_printf(mon, "memory backend: %s\n", m->value->id);
Hu Taoeb1539b2014-05-14 17:43:35 +08002623 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
2624 monitor_printf(mon, " merge: %s\n",
2625 m->value->merge ? "true" : "false");
2626 monitor_printf(mon, " dump: %s\n",
2627 m->value->dump ? "true" : "false");
2628 monitor_printf(mon, " prealloc: %s\n",
2629 m->value->prealloc ? "true" : "false");
2630 monitor_printf(mon, " policy: %s\n",
Markus Armbruster977c7362017-08-24 10:46:08 +02002631 HostMemPolicy_str(m->value->policy));
Eric Blake3b098d52016-06-09 10:48:43 -06002632 visit_complete(v, &str);
Chen Fan976620a2014-08-18 14:46:34 +08002633 monitor_printf(mon, " host nodes: %s\n", str);
Hu Taoeb1539b2014-05-14 17:43:35 +08002634
Chen Fan976620a2014-08-18 14:46:34 +08002635 g_free(str);
Eric Blake3b098d52016-06-09 10:48:43 -06002636 visit_free(v);
Hu Taoeb1539b2014-05-14 17:43:35 +08002637 m = m->next;
Hu Taoeb1539b2014-05-14 17:43:35 +08002638 }
2639
2640 monitor_printf(mon, "\n");
Chen Fanecaf54a2014-08-18 14:46:35 +08002641
2642 qapi_free_MemdevList(memdev_list);
Dr. David Alan Gilbert40c71f62017-08-17 11:42:15 +01002643 hmp_handle_error(mon, &err);
Hu Taoeb1539b2014-05-14 17:43:35 +08002644}
Zhu Guihuaa6318922014-09-23 13:35:19 +08002645
2646void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2647{
2648 Error *err = NULL;
2649 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2650 MemoryDeviceInfoList *info;
2651 MemoryDeviceInfo *value;
2652 PCDIMMDeviceInfo *di;
2653
2654 for (info = info_list; info; info = info->next) {
2655 value = info->value;
2656
2657 if (value) {
Eric Blake1fd5d4f2015-10-26 16:34:59 -06002658 switch (value->type) {
Zhu Guihuaa6318922014-09-23 13:35:19 +08002659 case MEMORY_DEVICE_INFO_KIND_DIMM:
Eric Blake32bafa82016-03-17 16:48:37 -06002660 di = value->u.dimm.data;
Haozhong Zhang6388e182018-03-11 11:02:12 +08002661 break;
Zhu Guihuaa6318922014-09-23 13:35:19 +08002662
Haozhong Zhang6388e182018-03-11 11:02:12 +08002663 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
2664 di = value->u.nvdimm.data;
2665 break;
2666
2667 default:
2668 di = NULL;
2669 break;
2670 }
2671
2672 if (di) {
Zhu Guihuaa6318922014-09-23 13:35:19 +08002673 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
Markus Armbruster977c7362017-08-24 10:46:08 +02002674 MemoryDeviceInfoKind_str(value->type),
Zhu Guihuaa6318922014-09-23 13:35:19 +08002675 di->id ? di->id : "");
2676 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2677 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2678 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2679 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2680 monitor_printf(mon, " memdev: %s\n", di->memdev);
2681 monitor_printf(mon, " hotplugged: %s\n",
2682 di->hotplugged ? "true" : "false");
2683 monitor_printf(mon, " hotpluggable: %s\n",
2684 di->hotpluggable ? "true" : "false");
Zhu Guihuaa6318922014-09-23 13:35:19 +08002685 }
2686 }
2687 }
2688
2689 qapi_free_MemoryDeviceInfoList(info_list);
Dr. David Alan Gilbert40c71f62017-08-17 11:42:15 +01002690 hmp_handle_error(mon, &err);
Zhu Guihuaa6318922014-09-23 13:35:19 +08002691}
Andreas Färber89d7fa92014-05-07 18:08:29 +02002692
Ting Wang62313162015-06-26 16:07:13 +08002693void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2694{
2695 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2696 IOThreadInfoList *info;
Pavel Hrdina5fc00482017-02-10 10:41:17 +01002697 IOThreadInfo *value;
Ting Wang62313162015-06-26 16:07:13 +08002698
2699 for (info = info_list; info; info = info->next) {
Pavel Hrdina5fc00482017-02-10 10:41:17 +01002700 value = info->value;
2701 monitor_printf(mon, "%s:\n", value->id);
2702 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
2703 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
2704 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
2705 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
Ting Wang62313162015-06-26 16:07:13 +08002706 }
2707
2708 qapi_free_IOThreadInfoList(info_list);
2709}
2710
Andreas Färber89d7fa92014-05-07 18:08:29 +02002711void hmp_qom_list(Monitor *mon, const QDict *qdict)
2712{
2713 const char *path = qdict_get_try_str(qdict, "path");
2714 ObjectPropertyInfoList *list;
2715 Error *err = NULL;
2716
2717 if (path == NULL) {
2718 monitor_printf(mon, "/\n");
2719 return;
2720 }
2721
2722 list = qmp_qom_list(path, &err);
2723 if (err == NULL) {
2724 ObjectPropertyInfoList *start = list;
2725 while (list != NULL) {
2726 ObjectPropertyInfo *value = list->value;
2727
2728 monitor_printf(mon, "%s (%s)\n",
2729 value->name, value->type);
2730 list = list->next;
2731 }
2732 qapi_free_ObjectPropertyInfoList(start);
2733 }
2734 hmp_handle_error(mon, &err);
2735}
Andreas Färberc0e6ee92014-05-07 19:48:15 +02002736
2737void hmp_qom_set(Monitor *mon, const QDict *qdict)
2738{
2739 const char *path = qdict_get_str(qdict, "path");
2740 const char *property = qdict_get_str(qdict, "property");
2741 const char *value = qdict_get_str(qdict, "value");
2742 Error *err = NULL;
2743 bool ambiguous = false;
2744 Object *obj;
2745
2746 obj = object_resolve_path(path, &ambiguous);
2747 if (obj == NULL) {
Markus Armbruster75158eb2015-03-16 08:57:47 +01002748 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2749 "Device '%s' not found", path);
Andreas Färberc0e6ee92014-05-07 19:48:15 +02002750 } else {
2751 if (ambiguous) {
2752 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2753 }
2754 object_property_parse(obj, value, property, &err);
2755 }
2756 hmp_handle_error(mon, &err);
2757}
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002758
2759void hmp_rocker(Monitor *mon, const QDict *qdict)
2760{
2761 const char *name = qdict_get_str(qdict, "name");
2762 RockerSwitch *rocker;
Markus Armbruster533fdae2015-12-18 16:35:27 +01002763 Error *err = NULL;
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002764
Markus Armbruster533fdae2015-12-18 16:35:27 +01002765 rocker = qmp_query_rocker(name, &err);
2766 if (err != NULL) {
2767 hmp_handle_error(mon, &err);
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002768 return;
2769 }
2770
2771 monitor_printf(mon, "name: %s\n", rocker->name);
2772 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2773 monitor_printf(mon, "ports: %d\n", rocker->ports);
2774
2775 qapi_free_RockerSwitch(rocker);
2776}
2777
2778void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2779{
2780 RockerPortList *list, *port;
2781 const char *name = qdict_get_str(qdict, "name");
Markus Armbruster533fdae2015-12-18 16:35:27 +01002782 Error *err = NULL;
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002783
Markus Armbruster533fdae2015-12-18 16:35:27 +01002784 list = qmp_query_rocker_ports(name, &err);
2785 if (err != NULL) {
2786 hmp_handle_error(mon, &err);
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002787 return;
2788 }
2789
2790 monitor_printf(mon, " ena/ speed/ auto\n");
2791 monitor_printf(mon, " port link duplex neg?\n");
2792
2793 for (port = list; port; port = port->next) {
2794 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2795 port->value->name,
2796 port->value->enabled ? port->value->link_up ?
2797 "up" : "down" : "!ena",
2798 port->value->speed == 10000 ? "10G" : "??",
2799 port->value->duplex ? "FD" : "HD",
2800 port->value->autoneg ? "Yes" : "No");
2801 }
2802
2803 qapi_free_RockerPortList(list);
2804}
2805
2806void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2807{
2808 RockerOfDpaFlowList *list, *info;
2809 const char *name = qdict_get_str(qdict, "name");
2810 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
Markus Armbruster533fdae2015-12-18 16:35:27 +01002811 Error *err = NULL;
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002812
Markus Armbruster533fdae2015-12-18 16:35:27 +01002813 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2814 if (err != NULL) {
2815 hmp_handle_error(mon, &err);
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002816 return;
2817 }
2818
2819 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2820
2821 for (info = list; info; info = info->next) {
2822 RockerOfDpaFlow *flow = info->value;
2823 RockerOfDpaFlowKey *key = flow->key;
2824 RockerOfDpaFlowMask *mask = flow->mask;
2825 RockerOfDpaFlowAction *action = flow->action;
2826
2827 if (flow->hits) {
2828 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2829 key->priority, key->tbl_id, flow->hits);
2830 } else {
2831 monitor_printf(mon, "%-4d %-3d ",
2832 key->priority, key->tbl_id);
2833 }
2834
2835 if (key->has_in_pport) {
2836 monitor_printf(mon, " pport %d", key->in_pport);
2837 if (mask->has_in_pport) {
2838 monitor_printf(mon, "(0x%x)", mask->in_pport);
2839 }
2840 }
2841
2842 if (key->has_vlan_id) {
2843 monitor_printf(mon, " vlan %d",
2844 key->vlan_id & VLAN_VID_MASK);
2845 if (mask->has_vlan_id) {
2846 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2847 }
2848 }
2849
2850 if (key->has_tunnel_id) {
2851 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2852 if (mask->has_tunnel_id) {
2853 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2854 }
2855 }
2856
2857 if (key->has_eth_type) {
2858 switch (key->eth_type) {
2859 case 0x0806:
2860 monitor_printf(mon, " ARP");
2861 break;
2862 case 0x0800:
2863 monitor_printf(mon, " IP");
2864 break;
2865 case 0x86dd:
2866 monitor_printf(mon, " IPv6");
2867 break;
2868 case 0x8809:
2869 monitor_printf(mon, " LACP");
2870 break;
2871 case 0x88cc:
2872 monitor_printf(mon, " LLDP");
2873 break;
2874 default:
2875 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2876 break;
2877 }
2878 }
2879
2880 if (key->has_eth_src) {
2881 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2882 (mask->has_eth_src) &&
2883 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2884 monitor_printf(mon, " src <any mcast/bcast>");
2885 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2886 (mask->has_eth_src) &&
2887 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2888 monitor_printf(mon, " src <any ucast>");
2889 } else {
2890 monitor_printf(mon, " src %s", key->eth_src);
2891 if (mask->has_eth_src) {
2892 monitor_printf(mon, "(%s)", mask->eth_src);
2893 }
2894 }
2895 }
2896
2897 if (key->has_eth_dst) {
2898 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2899 (mask->has_eth_dst) &&
2900 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2901 monitor_printf(mon, " dst <any mcast/bcast>");
2902 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2903 (mask->has_eth_dst) &&
2904 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2905 monitor_printf(mon, " dst <any ucast>");
2906 } else {
2907 monitor_printf(mon, " dst %s", key->eth_dst);
2908 if (mask->has_eth_dst) {
2909 monitor_printf(mon, "(%s)", mask->eth_dst);
2910 }
2911 }
2912 }
2913
2914 if (key->has_ip_proto) {
2915 monitor_printf(mon, " proto %d", key->ip_proto);
2916 if (mask->has_ip_proto) {
2917 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2918 }
2919 }
2920
2921 if (key->has_ip_tos) {
2922 monitor_printf(mon, " TOS %d", key->ip_tos);
2923 if (mask->has_ip_tos) {
2924 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2925 }
2926 }
2927
2928 if (key->has_ip_dst) {
2929 monitor_printf(mon, " dst %s", key->ip_dst);
2930 }
2931
2932 if (action->has_goto_tbl || action->has_group_id ||
2933 action->has_new_vlan_id) {
2934 monitor_printf(mon, " -->");
2935 }
2936
2937 if (action->has_new_vlan_id) {
2938 monitor_printf(mon, " apply new vlan %d",
2939 ntohs(action->new_vlan_id));
2940 }
2941
2942 if (action->has_group_id) {
2943 monitor_printf(mon, " write group 0x%08x", action->group_id);
2944 }
2945
2946 if (action->has_goto_tbl) {
2947 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2948 }
2949
2950 monitor_printf(mon, "\n");
2951 }
2952
2953 qapi_free_RockerOfDpaFlowList(list);
2954}
2955
2956void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2957{
2958 RockerOfDpaGroupList *list, *g;
2959 const char *name = qdict_get_str(qdict, "name");
2960 uint8_t type = qdict_get_try_int(qdict, "type", 9);
Markus Armbruster533fdae2015-12-18 16:35:27 +01002961 Error *err = NULL;
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002962 bool set = false;
2963
Markus Armbruster533fdae2015-12-18 16:35:27 +01002964 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2965 if (err != NULL) {
2966 hmp_handle_error(mon, &err);
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002967 return;
2968 }
2969
2970 monitor_printf(mon, "id (decode) --> buckets\n");
2971
2972 for (g = list; g; g = g->next) {
2973 RockerOfDpaGroup *group = g->value;
2974
2975 monitor_printf(mon, "0x%08x", group->id);
2976
2977 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2978 group->type == 1 ? "L2 rewrite" :
2979 group->type == 2 ? "L3 unicast" :
2980 group->type == 3 ? "L2 multicast" :
2981 group->type == 4 ? "L2 flood" :
2982 group->type == 5 ? "L3 interface" :
2983 group->type == 6 ? "L3 multicast" :
2984 group->type == 7 ? "L3 ECMP" :
2985 group->type == 8 ? "L2 overlay" :
2986 "unknown");
2987
2988 if (group->has_vlan_id) {
2989 monitor_printf(mon, " vlan %d", group->vlan_id);
2990 }
2991
2992 if (group->has_pport) {
2993 monitor_printf(mon, " pport %d", group->pport);
2994 }
2995
2996 if (group->has_index) {
2997 monitor_printf(mon, " index %d", group->index);
2998 }
2999
3000 monitor_printf(mon, ") -->");
3001
3002 if (group->has_set_vlan_id && group->set_vlan_id) {
3003 set = true;
3004 monitor_printf(mon, " set vlan %d",
3005 group->set_vlan_id & VLAN_VID_MASK);
3006 }
3007
3008 if (group->has_set_eth_src) {
3009 if (!set) {
3010 set = true;
3011 monitor_printf(mon, " set");
3012 }
3013 monitor_printf(mon, " src %s", group->set_eth_src);
3014 }
3015
3016 if (group->has_set_eth_dst) {
3017 if (!set) {
3018 set = true;
3019 monitor_printf(mon, " set");
3020 }
3021 monitor_printf(mon, " dst %s", group->set_eth_dst);
3022 }
3023
3024 set = false;
3025
3026 if (group->has_ttl_check && group->ttl_check) {
3027 monitor_printf(mon, " check TTL");
3028 }
3029
3030 if (group->has_group_id && group->group_id) {
3031 monitor_printf(mon, " group id 0x%08x", group->group_id);
3032 }
3033
3034 if (group->has_pop_vlan && group->pop_vlan) {
3035 monitor_printf(mon, " pop vlan");
3036 }
3037
3038 if (group->has_out_pport) {
3039 monitor_printf(mon, " out pport %d", group->out_pport);
3040 }
3041
3042 if (group->has_group_ids) {
3043 struct uint32List *id;
3044
3045 monitor_printf(mon, " groups [");
3046 for (id = group->group_ids; id; id = id->next) {
3047 monitor_printf(mon, "0x%08x", id->value);
3048 if (id->next) {
3049 monitor_printf(mon, ",");
3050 }
3051 }
3052 monitor_printf(mon, "]");
3053 }
3054
3055 monitor_printf(mon, "\n");
3056 }
3057
3058 qapi_free_RockerOfDpaGroupList(list);
3059}
Peter Xu4a6b52d2016-02-18 13:16:55 +08003060
3061void hmp_info_dump(Monitor *mon, const QDict *qdict)
3062{
3063 DumpQueryResult *result = qmp_query_dump(NULL);
3064
3065 assert(result && result->status < DUMP_STATUS__MAX);
Markus Armbruster977c7362017-08-24 10:46:08 +02003066 monitor_printf(mon, "Status: %s\n", DumpStatus_str(result->status));
Peter Xu4a6b52d2016-02-18 13:16:55 +08003067
3068 if (result->status == DUMP_STATUS_ACTIVE) {
3069 float percent = 0;
3070 assert(result->total != 0);
3071 percent = 100.0 * result->completed / result->total;
3072 monitor_printf(mon, "Finished: %.2f %%\n", percent);
3073 }
3074
3075 qapi_free_DumpQueryResult(result);
3076}
Bharata B Raod2d8d462016-06-10 06:29:07 +05303077
Peter Xube9b23c2017-05-12 12:17:41 +08003078void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
3079{
3080 ram_block_dump(mon);
3081}
3082
Bharata B Raod2d8d462016-06-10 06:29:07 +05303083void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
3084{
3085 Error *err = NULL;
3086 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
3087 HotpluggableCPUList *saved = l;
3088 CpuInstanceProperties *c;
3089
3090 if (err != NULL) {
3091 hmp_handle_error(mon, &err);
3092 return;
3093 }
3094
3095 monitor_printf(mon, "Hotpluggable CPUs:\n");
3096 while (l) {
3097 monitor_printf(mon, " type: \"%s\"\n", l->value->type);
3098 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
3099 l->value->vcpus_count);
3100 if (l->value->has_qom_path) {
3101 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
3102 }
3103
3104 c = l->value->props;
3105 monitor_printf(mon, " CPUInstance Properties:\n");
Peter Krempa27393c32016-06-23 23:23:34 +02003106 if (c->has_node_id) {
3107 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
Bharata B Raod2d8d462016-06-10 06:29:07 +05303108 }
Peter Krempa27393c32016-06-23 23:23:34 +02003109 if (c->has_socket_id) {
3110 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
Bharata B Raod2d8d462016-06-10 06:29:07 +05303111 }
Peter Krempa27393c32016-06-23 23:23:34 +02003112 if (c->has_core_id) {
3113 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
Bharata B Raod2d8d462016-06-10 06:29:07 +05303114 }
Peter Krempa27393c32016-06-23 23:23:34 +02003115 if (c->has_thread_id) {
3116 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
Bharata B Raod2d8d462016-06-10 06:29:07 +05303117 }
3118
3119 l = l->next;
3120 }
3121
3122 qapi_free_HotpluggableCPUList(saved);
3123}
Igor Mammedov39164c12017-02-16 15:15:37 -08003124
3125void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
3126{
Ben Warren72d91962017-03-02 13:36:50 -08003127 Error *err = NULL;
3128 GuidInfo *info = qmp_query_vm_generation_id(&err);
Igor Mammedov39164c12017-02-16 15:15:37 -08003129 if (info) {
3130 monitor_printf(mon, "%s\n", info->guid);
3131 }
Ben Warren72d91962017-03-02 13:36:50 -08003132 hmp_handle_error(mon, &err);
Igor Mammedov39164c12017-02-16 15:15:37 -08003133 qapi_free_GuidInfo(info);
3134}
Vadim Galitsynd0f63c12017-08-29 17:30:22 +02003135
3136void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
3137{
3138 Error *err = NULL;
3139 MemoryInfo *info = qmp_query_memory_size_summary(&err);
3140 if (info) {
3141 monitor_printf(mon, "base memory: %" PRIu64 "\n",
3142 info->base_memory);
3143
3144 if (info->has_plugged_memory) {
3145 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
3146 info->plugged_memory);
3147 }
3148
3149 qapi_free_MemoryInfo(info);
3150 }
3151 hmp_handle_error(mon, &err);
3152}