]> git.proxmox.com Git - mirror_qemu.git/blame - hmp.c
qmp/migration: new command migrate-recover
[mirror_qemu.git] / hmp.c
CommitLineData
48a32bed
AL
1/*
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 *
6b620ca3
PB
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
48a32bed
AL
14 */
15
d38ea87a 16#include "qemu/osdep.h"
48a32bed 17#include "hmp.h"
1422e32d 18#include "net/net.h"
fafa4d50 19#include "net/eth.h"
8228e353 20#include "chardev/char.h"
4c7b7e9b 21#include "sysemu/block-backend.h"
52b26205 22#include "sysemu/sysemu.h"
213dcb06 23#include "qemu/config-file.h"
1de7afc9
PB
24#include "qemu/option.h"
25#include "qemu/timer.h"
1de7afc9 26#include "qemu/sockets.h"
83c9089e 27#include "monitor/monitor.h"
318660f8 28#include "monitor/qdev.h"
e688df6b 29#include "qapi/error.h"
cff8b2c6 30#include "qapi/opts-visitor.h"
eb815e24 31#include "qapi/qapi-builtin-visit.h"
112ed241
MA
32#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"
452fcdbc 41#include "qapi/qmp/qdict.h"
cc7a8ea7 42#include "qapi/qmp/qerror.h"
f4a06d13 43#include "qapi/string-input-visitor.h"
eb1539b2 44#include "qapi/string-output-visitor.h"
90998d58 45#include "qom/object_interfaces.h"
28ecbaee 46#include "ui/console.h"
bd269ebc 47#include "block/nbd.h"
bd093a36 48#include "block/qapi.h"
587da2c3 49#include "qemu-io.h"
f348b6d1 50#include "qemu/cutils.h"
d59ce6f3 51#include "qemu/error-report.h"
be9b23c4 52#include "exec/ramlist.h"
61b97833 53#include "hw/intc/intc.h"
5e22479a 54#include "migration/snapshot.h"
9d18af93 55#include "migration/misc.h"
48a32bed 56
22fa7da0
CR
57#ifdef CONFIG_SPICE
58#include <spice/enums.h>
59#endif
60
0cfd6a9a
LC
61static void hmp_handle_error(Monitor *mon, Error **errp)
62{
415168e0
MA
63 assert(errp);
64 if (*errp) {
193227f9 65 error_report_err(*errp);
0cfd6a9a
LC
66 }
67}
68
84f2d0ea 69void hmp_info_name(Monitor *mon, const QDict *qdict)
48a32bed
AL
70{
71 NameInfo *info;
72
73 info = qmp_query_name(NULL);
74 if (info->has_name) {
75 monitor_printf(mon, "%s\n", info->name);
76 }
77 qapi_free_NameInfo(info);
78}
b9c15f16 79
84f2d0ea 80void hmp_info_version(Monitor *mon, const QDict *qdict)
b9c15f16
LC
81{
82 VersionInfo *info;
83
84 info = qmp_query_version(NULL);
85
86 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
4752cdbb 87 info->qemu->major, info->qemu->minor, info->qemu->micro,
b9c15f16
LC
88 info->package);
89
90 qapi_free_VersionInfo(info);
91}
292a2602 92
84f2d0ea 93void hmp_info_kvm(Monitor *mon, const QDict *qdict)
292a2602
LC
94{
95 KvmInfo *info;
96
97 info = qmp_query_kvm(NULL);
98 monitor_printf(mon, "kvm support: ");
99 if (info->present) {
100 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
101 } else {
102 monitor_printf(mon, "not compiled\n");
103 }
104
105 qapi_free_KvmInfo(info);
106}
107
84f2d0ea 108void hmp_info_status(Monitor *mon, const QDict *qdict)
1fa9a5e4
LC
109{
110 StatusInfo *info;
111
112 info = qmp_query_status(NULL);
113
114 monitor_printf(mon, "VM status: %s%s",
115 info->running ? "running" : "paused",
116 info->singlestep ? " (single step mode)" : "");
117
118 if (!info->running && info->status != RUN_STATE_PAUSED) {
977c736f 119 monitor_printf(mon, " (%s)", RunState_str(info->status));
1fa9a5e4
LC
120 }
121
122 monitor_printf(mon, "\n");
123
124 qapi_free_StatusInfo(info);
125}
126
84f2d0ea 127void hmp_info_uuid(Monitor *mon, const QDict *qdict)
efab767e
LC
128{
129 UuidInfo *info;
130
131 info = qmp_query_uuid(NULL);
132 monitor_printf(mon, "%s\n", info->UUID);
133 qapi_free_UuidInfo(info);
134}
c5a415a0 135
84f2d0ea 136void hmp_info_chardev(Monitor *mon, const QDict *qdict)
c5a415a0
LC
137{
138 ChardevInfoList *char_info, *info;
139
140 char_info = qmp_query_chardev(NULL);
141 for (info = char_info; info; info = info->next) {
142 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
143 info->value->filename);
144 }
145
146 qapi_free_ChardevInfoList(char_info);
147}
7a7f325e 148
84f2d0ea 149void hmp_info_mice(Monitor *mon, const QDict *qdict)
e235cec3
LC
150{
151 MouseInfoList *mice_list, *mouse;
152
153 mice_list = qmp_query_mice(NULL);
154 if (!mice_list) {
155 monitor_printf(mon, "No mouse devices connected\n");
156 return;
157 }
158
159 for (mouse = mice_list; mouse; mouse = mouse->next) {
160 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
161 mouse->value->current ? '*' : ' ',
162 mouse->value->index, mouse->value->name,
163 mouse->value->absolute ? " (absolute)" : "");
164 }
165
166 qapi_free_MouseInfoList(mice_list);
167}
168
84f2d0ea 169void hmp_info_migrate(Monitor *mon, const QDict *qdict)
791e7c82
LC
170{
171 MigrationInfo *info;
bbf6da32 172 MigrationCapabilityStatusList *caps, *cap;
791e7c82
LC
173
174 info = qmp_query_migrate(NULL);
bbf6da32
OW
175 caps = qmp_query_migrate_capabilities(NULL);
176
9d18af93
PX
177 migration_global_dump(mon);
178
bbf6da32
OW
179 /* do not display parameters during setup */
180 if (info->has_status && caps) {
181 monitor_printf(mon, "capabilities: ");
182 for (cap = caps; cap; cap = cap->next) {
183 monitor_printf(mon, "%s: %s ",
977c736f 184 MigrationCapability_str(cap->value->capability),
bbf6da32
OW
185 cap->value->state ? "on" : "off");
186 }
187 monitor_printf(mon, "\n");
188 }
791e7c82
LC
189
190 if (info->has_status) {
d59ce6f3 191 monitor_printf(mon, "Migration status: %s",
977c736f 192 MigrationStatus_str(info->status));
d59ce6f3
DB
193 if (info->status == MIGRATION_STATUS_FAILED &&
194 info->has_error_desc) {
195 monitor_printf(mon, " (%s)\n", info->error_desc);
196 } else {
197 monitor_printf(mon, "\n");
198 }
199
7aa939af
JQ
200 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
201 info->total_time);
2c52ddf1
JQ
202 if (info->has_expected_downtime) {
203 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
204 info->expected_downtime);
205 }
9c5a9fcf
JQ
206 if (info->has_downtime) {
207 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
208 info->downtime);
209 }
ed4fbd10
MH
210 if (info->has_setup_time) {
211 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
212 info->setup_time);
213 }
791e7c82
LC
214 }
215
216 if (info->has_ram) {
217 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
218 info->ram->transferred >> 10);
7e114f8c
MH
219 monitor_printf(mon, "throughput: %0.2f mbps\n",
220 info->ram->mbps);
791e7c82
LC
221 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
222 info->ram->remaining >> 10);
223 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
224 info->ram->total >> 10);
004d4c10
OW
225 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
226 info->ram->duplicate);
f1c72795
PL
227 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
228 info->ram->skipped);
004d4c10
OW
229 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
230 info->ram->normal);
231 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
232 info->ram->normal_bytes >> 10);
58570ed8
C
233 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
234 info->ram->dirty_sync_count);
030ce1f8
CF
235 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
236 info->ram->page_size >> 10);
237
8d017193
JQ
238 if (info->ram->dirty_pages_rate) {
239 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
240 info->ram->dirty_pages_rate);
241 }
d3bf5418
DDAG
242 if (info->ram->postcopy_requests) {
243 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
244 info->ram->postcopy_requests);
245 }
791e7c82
LC
246 }
247
248 if (info->has_disk) {
249 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
250 info->disk->transferred >> 10);
251 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
252 info->disk->remaining >> 10);
253 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
254 info->disk->total >> 10);
255 }
256
f36d55af
OW
257 if (info->has_xbzrle_cache) {
258 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
259 info->xbzrle_cache->cache_size);
260 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
261 info->xbzrle_cache->bytes >> 10);
262 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
263 info->xbzrle_cache->pages);
264 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
265 info->xbzrle_cache->cache_miss);
8bc39233
C
266 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
267 info->xbzrle_cache->cache_miss_rate);
f36d55af
OW
268 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
269 info->xbzrle_cache->overflow);
270 }
271
d85a31d1 272 if (info->has_cpu_throttle_percentage) {
4782893e 273 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
d85a31d1 274 info->cpu_throttle_percentage);
4782893e
JH
275 }
276
65ace060
AP
277 if (info->has_postcopy_blocktime) {
278 monitor_printf(mon, "postcopy blocktime: %u\n",
279 info->postcopy_blocktime);
280 }
281
282 if (info->has_postcopy_vcpu_blocktime) {
283 Visitor *v;
284 char *str;
285 v = string_output_visitor_new(false, &str);
286 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, NULL);
287 visit_complete(v, &str);
288 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
289 g_free(str);
290 visit_free(v);
291 }
791e7c82 292 qapi_free_MigrationInfo(info);
bbf6da32
OW
293 qapi_free_MigrationCapabilityStatusList(caps);
294}
295
84f2d0ea 296void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
bbf6da32
OW
297{
298 MigrationCapabilityStatusList *caps, *cap;
299
300 caps = qmp_query_migrate_capabilities(NULL);
301
302 if (caps) {
bbf6da32 303 for (cap = caps; cap; cap = cap->next) {
d80a0169 304 monitor_printf(mon, "%s: %s\n",
977c736f 305 MigrationCapability_str(cap->value->capability),
bbf6da32
OW
306 cap->value->state ? "on" : "off");
307 }
bbf6da32
OW
308 }
309
310 qapi_free_MigrationCapabilityStatusList(caps);
791e7c82
LC
311}
312
50e9a629
LL
313void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
314{
315 MigrationParameters *params;
316
317 params = qmp_query_migrate_parameters(NULL);
318
319 if (params) {
de63ab61 320 assert(params->has_compress_level);
741d4086 321 monitor_printf(mon, "%s: %u\n",
977c736f 322 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
50e9a629 323 params->compress_level);
de63ab61 324 assert(params->has_compress_threads);
741d4086 325 monitor_printf(mon, "%s: %u\n",
977c736f 326 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
50e9a629 327 params->compress_threads);
de63ab61 328 assert(params->has_decompress_threads);
741d4086 329 monitor_printf(mon, "%s: %u\n",
977c736f 330 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
50e9a629 331 params->decompress_threads);
de63ab61 332 assert(params->has_cpu_throttle_initial);
741d4086 333 monitor_printf(mon, "%s: %u\n",
977c736f 334 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
d85a31d1 335 params->cpu_throttle_initial);
de63ab61 336 assert(params->has_cpu_throttle_increment);
741d4086 337 monitor_printf(mon, "%s: %u\n",
977c736f 338 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
d85a31d1 339 params->cpu_throttle_increment);
8cc99dcd 340 assert(params->has_tls_creds);
2c02468c 341 monitor_printf(mon, "%s: '%s'\n",
977c736f 342 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
8cc99dcd
MA
343 params->tls_creds);
344 assert(params->has_tls_hostname);
2c02468c 345 monitor_printf(mon, "%s: '%s'\n",
977c736f 346 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
8cc99dcd 347 params->tls_hostname);
2ff30257 348 assert(params->has_max_bandwidth);
741d4086 349 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
977c736f 350 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
2ff30257
AA
351 params->max_bandwidth);
352 assert(params->has_downtime_limit);
741d4086 353 monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n",
977c736f 354 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
2ff30257 355 params->downtime_limit);
fe39a4d4 356 assert(params->has_x_checkpoint_delay);
741d4086 357 monitor_printf(mon, "%s: %u\n",
977c736f 358 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
68b53591 359 params->x_checkpoint_delay);
2833c59b
JQ
360 assert(params->has_block_incremental);
361 monitor_printf(mon, "%s: %s\n",
977c736f
MA
362 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
363 params->block_incremental ? "on" : "off");
741d4086 364 monitor_printf(mon, "%s: %u\n",
4075fb1c
JQ
365 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_CHANNELS),
366 params->x_multifd_channels);
741d4086 367 monitor_printf(mon, "%s: %u\n",
0fb86605
JQ
368 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT),
369 params->x_multifd_page_count);
741d4086 370 monitor_printf(mon, "%s: %" PRIu64 "\n",
73af8dd8
JQ
371 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
372 params->xbzrle_cache_size);
50e9a629
LL
373 }
374
375 qapi_free_MigrationParameters(params);
376}
377
84f2d0ea 378void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
9e1ba4cc
OW
379{
380 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
381 qmp_query_migrate_cache_size(NULL) >> 10);
382}
383
84f2d0ea 384void hmp_info_cpus(Monitor *mon, const QDict *qdict)
de0b36b6 385{
137b5cb6 386 CpuInfoFastList *cpu_list, *cpu;
de0b36b6 387
137b5cb6 388 cpu_list = qmp_query_cpus_fast(NULL);
de0b36b6
LC
389
390 for (cpu = cpu_list; cpu; cpu = cpu->next) {
391 int active = ' ';
392
137b5cb6 393 if (cpu->value->cpu_index == monitor_get_cpu_index()) {
de0b36b6
LC
394 active = '*';
395 }
396
137b5cb6
VM
397 monitor_printf(mon, "%c CPU #%" PRId64 ":", active,
398 cpu->value->cpu_index);
0dfddbb5 399 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
de0b36b6
LC
400 }
401
137b5cb6 402 qapi_free_CpuInfoFastList(cpu_list);
de0b36b6
LC
403}
404
289b276c
KW
405static void print_block_info(Monitor *mon, BlockInfo *info,
406 BlockDeviceInfo *inserted, bool verbose)
b2023818 407{
bd093a36 408 ImageInfo *image_info;
b2023818 409
8d6adccd
KW
410 assert(!info || !info->has_inserted || info->inserted == inserted);
411
ec18b0a9 412 if (info && *info->device) {
8d6adccd
KW
413 monitor_printf(mon, "%s", info->device);
414 if (inserted && inserted->has_node_name) {
415 monitor_printf(mon, " (%s)", inserted->node_name);
416 }
417 } else {
ec18b0a9 418 assert(info || inserted);
8d6adccd 419 monitor_printf(mon, "%s",
ec18b0a9
KW
420 inserted && inserted->has_node_name ? inserted->node_name
421 : info && info->has_qdev ? info->qdev
8d6adccd
KW
422 : "<anonymous>");
423 }
424
289b276c
KW
425 if (inserted) {
426 monitor_printf(mon, ": %s (%s%s%s)\n",
427 inserted->file,
428 inserted->drv,
429 inserted->ro ? ", read-only" : "",
430 inserted->encrypted ? ", encrypted" : "");
431 } else {
432 monitor_printf(mon, ": [not inserted]\n");
433 }
b2023818 434
8d6adccd 435 if (info) {
46eade7b
KW
436 if (info->has_qdev) {
437 monitor_printf(mon, " Attached to: %s\n", info->qdev);
438 }
8d6adccd
KW
439 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
440 monitor_printf(mon, " I/O status: %s\n",
977c736f 441 BlockDeviceIoStatus_str(info->io_status));
8d6adccd 442 }
b2023818 443
8d6adccd
KW
444 if (info->removable) {
445 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
446 info->locked ? "" : "not ",
447 info->tray_open ? "open" : "closed");
448 }
289b276c 449 }
fbe2e26c 450
b2023818 451
289b276c
KW
452 if (!inserted) {
453 return;
454 }
b2023818 455
289b276c
KW
456 monitor_printf(mon, " Cache mode: %s%s%s\n",
457 inserted->cache->writeback ? "writeback" : "writethrough",
458 inserted->cache->direct ? ", direct" : "",
459 inserted->cache->no_flush ? ", ignore flushes" : "");
460
461 if (inserted->has_backing_file) {
462 monitor_printf(mon,
463 " Backing file: %s "
464 "(chain depth: %" PRId64 ")\n",
465 inserted->backing_file,
466 inserted->backing_file_depth);
467 }
727f005e 468
289b276c
KW
469 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
470 monitor_printf(mon, " Detect zeroes: %s\n",
977c736f 471 BlockdevDetectZeroesOptions_str(inserted->detect_zeroes));
289b276c 472 }
fbe2e26c 473
289b276c
KW
474 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
475 inserted->iops || inserted->iops_rd || inserted->iops_wr)
476 {
477 monitor_printf(mon, " I/O throttling: bps=%" PRId64
478 " bps_rd=%" PRId64 " bps_wr=%" PRId64
479 " bps_max=%" PRId64
480 " bps_rd_max=%" PRId64
481 " bps_wr_max=%" PRId64
482 " iops=%" PRId64 " iops_rd=%" PRId64
483 " iops_wr=%" PRId64
484 " iops_max=%" PRId64
485 " iops_rd_max=%" PRId64
486 " iops_wr_max=%" PRId64
b8fe1694
AG
487 " iops_size=%" PRId64
488 " group=%s\n",
289b276c
KW
489 inserted->bps,
490 inserted->bps_rd,
491 inserted->bps_wr,
492 inserted->bps_max,
493 inserted->bps_rd_max,
494 inserted->bps_wr_max,
495 inserted->iops,
496 inserted->iops_rd,
497 inserted->iops_wr,
498 inserted->iops_max,
499 inserted->iops_rd_max,
500 inserted->iops_wr_max,
b8fe1694
AG
501 inserted->iops_size,
502 inserted->group);
289b276c 503 }
fbe2e26c 504
9419874f 505 if (verbose) {
289b276c
KW
506 monitor_printf(mon, "\nImages:\n");
507 image_info = inserted->image;
508 while (1) {
509 bdrv_image_info_dump((fprintf_function)monitor_printf,
510 mon, image_info);
511 if (image_info->has_backing_image) {
512 image_info = image_info->backing_image;
513 } else {
514 break;
515 }
516 }
517 }
518}
9e193c5a 519
289b276c
KW
520void hmp_info_block(Monitor *mon, const QDict *qdict)
521{
522 BlockInfoList *block_list, *info;
e6bb31ec 523 BlockDeviceInfoList *blockdev_list, *blockdev;
289b276c 524 const char *device = qdict_get_try_str(qdict, "device");
34acbc95
EB
525 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
526 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
e6bb31ec 527 bool printed = false;
9e193c5a 528
e6bb31ec
KW
529 /* Print BlockBackend information */
530 if (!nodes) {
f19e44bc 531 block_list = qmp_query_block(NULL);
e6bb31ec
KW
532 } else {
533 block_list = NULL;
534 }
fbe2e26c 535
289b276c
KW
536 for (info = block_list; info; info = info->next) {
537 if (device && strcmp(device, info->value->device)) {
538 continue;
465bee1d
PL
539 }
540
289b276c
KW
541 if (info != block_list) {
542 monitor_printf(mon, "\n");
fbe2e26c 543 }
bd093a36 544
289b276c
KW
545 print_block_info(mon, info->value, info->value->has_inserted
546 ? info->value->inserted : NULL,
547 verbose);
e6bb31ec 548 printed = true;
b2023818
LC
549 }
550
551 qapi_free_BlockInfoList(block_list);
e6bb31ec
KW
552
553 if ((!device && !nodes) || printed) {
554 return;
555 }
556
557 /* Print node information */
558 blockdev_list = qmp_query_named_block_nodes(NULL);
559 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
560 assert(blockdev->value->has_node_name);
561 if (device && strcmp(device, blockdev->value->node_name)) {
562 continue;
563 }
564
565 if (blockdev != blockdev_list) {
566 monitor_printf(mon, "\n");
567 }
568
569 print_block_info(mon, NULL, blockdev->value, verbose);
570 }
571 qapi_free_BlockDeviceInfoList(blockdev_list);
b2023818
LC
572}
573
84f2d0ea 574void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
f11f57e4
LC
575{
576 BlockStatsList *stats_list, *stats;
577
f71eaa74 578 stats_list = qmp_query_blockstats(false, false, NULL);
f11f57e4
LC
579
580 for (stats = stats_list; stats; stats = stats->next) {
581 if (!stats->value->has_device) {
582 continue;
583 }
584
585 monitor_printf(mon, "%s:", stats->value->device);
586 monitor_printf(mon, " rd_bytes=%" PRId64
587 " wr_bytes=%" PRId64
588 " rd_operations=%" PRId64
589 " wr_operations=%" PRId64
590 " flush_operations=%" PRId64
591 " wr_total_time_ns=%" PRId64
592 " rd_total_time_ns=%" PRId64
593 " flush_total_time_ns=%" PRId64
f4564d53
PL
594 " rd_merged=%" PRId64
595 " wr_merged=%" PRId64
cb38fffb 596 " idle_time_ns=%" PRId64
f11f57e4
LC
597 "\n",
598 stats->value->stats->rd_bytes,
599 stats->value->stats->wr_bytes,
600 stats->value->stats->rd_operations,
601 stats->value->stats->wr_operations,
602 stats->value->stats->flush_operations,
603 stats->value->stats->wr_total_time_ns,
604 stats->value->stats->rd_total_time_ns,
f4564d53
PL
605 stats->value->stats->flush_total_time_ns,
606 stats->value->stats->rd_merged,
cb38fffb
AG
607 stats->value->stats->wr_merged,
608 stats->value->stats->idle_time_ns);
f11f57e4
LC
609 }
610
611 qapi_free_BlockStatsList(stats_list);
612}
613
0a9667ec
DDAG
614/* Helper for hmp_info_vnc_clients, _servers */
615static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
616 const char *name)
617{
618 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
619 name,
620 info->host,
621 info->service,
977c736f 622 NetworkAddressFamily_str(info->family),
0a9667ec
DDAG
623 info->websocket ? " (Websocket)" : "");
624}
625
626/* Helper displaying and auth and crypt info */
627static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
628 VncPrimaryAuth auth,
629 VncVencryptSubAuth *vencrypt)
630{
631 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
977c736f
MA
632 VncPrimaryAuth_str(auth),
633 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
0a9667ec
DDAG
634}
635
636static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
637{
638 while (client) {
639 VncClientInfo *cinfo = client->value;
640
641 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
642 monitor_printf(mon, " x509_dname: %s\n",
643 cinfo->has_x509_dname ?
644 cinfo->x509_dname : "none");
645 monitor_printf(mon, " sasl_username: %s\n",
646 cinfo->has_sasl_username ?
647 cinfo->sasl_username : "none");
648
649 client = client->next;
650 }
651}
652
653static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
654{
655 while (server) {
656 VncServerInfo2 *sinfo = server->value;
657 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
658 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
659 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
660 server = server->next;
661 }
662}
663
84f2d0ea 664void hmp_info_vnc(Monitor *mon, const QDict *qdict)
2b54aa87 665{
0a9667ec 666 VncInfo2List *info2l;
2b54aa87 667 Error *err = NULL;
2b54aa87 668
0a9667ec 669 info2l = qmp_query_vnc_servers(&err);
2b54aa87 670 if (err) {
554a39eb 671 hmp_handle_error(mon, &err);
2b54aa87
LC
672 return;
673 }
0a9667ec
DDAG
674 if (!info2l) {
675 monitor_printf(mon, "None\n");
676 return;
2b54aa87
LC
677 }
678
0a9667ec
DDAG
679 while (info2l) {
680 VncInfo2 *info = info2l->value;
681 monitor_printf(mon, "%s:\n", info->id);
682 hmp_info_vnc_servers(mon, info->server);
683 hmp_info_vnc_clients(mon, info->clients);
684 if (!info->server) {
685 /* The server entry displays its auth, we only
686 * need to display in the case of 'reverse' connections
687 * where there's no server.
688 */
689 hmp_info_vnc_authcrypt(mon, " ", info->auth,
690 info->has_vencrypt ? &info->vencrypt : NULL);
691 }
692 if (info->has_display) {
693 monitor_printf(mon, " Display: %s\n", info->display);
2b54aa87 694 }
0a9667ec 695 info2l = info2l->next;
2b54aa87
LC
696 }
697
0a9667ec
DDAG
698 qapi_free_VncInfo2List(info2l);
699
2b54aa87
LC
700}
701
206addd5 702#ifdef CONFIG_SPICE
84f2d0ea 703void hmp_info_spice(Monitor *mon, const QDict *qdict)
d1f29646
LC
704{
705 SpiceChannelList *chan;
706 SpiceInfo *info;
22fa7da0
CR
707 const char *channel_name;
708 const char * const channel_names[] = {
709 [SPICE_CHANNEL_MAIN] = "main",
710 [SPICE_CHANNEL_DISPLAY] = "display",
711 [SPICE_CHANNEL_INPUTS] = "inputs",
712 [SPICE_CHANNEL_CURSOR] = "cursor",
713 [SPICE_CHANNEL_PLAYBACK] = "playback",
714 [SPICE_CHANNEL_RECORD] = "record",
715 [SPICE_CHANNEL_TUNNEL] = "tunnel",
716 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
717 [SPICE_CHANNEL_USBREDIR] = "usbredir",
718 [SPICE_CHANNEL_PORT] = "port",
7c6044a9
GH
719#if 0
720 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
721 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
722 * as quick fix for build failures with older versions. */
22fa7da0 723 [SPICE_CHANNEL_WEBDAV] = "webdav",
7c6044a9 724#endif
22fa7da0 725 };
d1f29646
LC
726
727 info = qmp_query_spice(NULL);
728
729 if (!info->enabled) {
730 monitor_printf(mon, "Server: disabled\n");
731 goto out;
732 }
733
734 monitor_printf(mon, "Server:\n");
735 if (info->has_port) {
736 monitor_printf(mon, " address: %s:%" PRId64 "\n",
737 info->host, info->port);
738 }
739 if (info->has_tls_port) {
740 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
741 info->host, info->tls_port);
742 }
61c4efe2
YH
743 monitor_printf(mon, " migrated: %s\n",
744 info->migrated ? "true" : "false");
d1f29646
LC
745 monitor_printf(mon, " auth: %s\n", info->auth);
746 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
4efee029 747 monitor_printf(mon, " mouse-mode: %s\n",
977c736f 748 SpiceQueryMouseMode_str(info->mouse_mode));
d1f29646
LC
749
750 if (!info->has_channels || info->channels == NULL) {
751 monitor_printf(mon, "Channels: none\n");
752 } else {
753 for (chan = info->channels; chan; chan = chan->next) {
754 monitor_printf(mon, "Channel:\n");
755 monitor_printf(mon, " address: %s:%s%s\n",
ddf21908 756 chan->value->host, chan->value->port,
d1f29646
LC
757 chan->value->tls ? " [tls]" : "");
758 monitor_printf(mon, " session: %" PRId64 "\n",
759 chan->value->connection_id);
760 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
761 chan->value->channel_type, chan->value->channel_id);
22fa7da0
CR
762
763 channel_name = "unknown";
764 if (chan->value->channel_type > 0 &&
765 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
766 channel_names[chan->value->channel_type]) {
767 channel_name = channel_names[chan->value->channel_type];
768 }
769
770 monitor_printf(mon, " channel name: %s\n", channel_name);
d1f29646
LC
771 }
772 }
773
774out:
775 qapi_free_SpiceInfo(info);
776}
206addd5 777#endif
d1f29646 778
84f2d0ea 779void hmp_info_balloon(Monitor *mon, const QDict *qdict)
96637bcd
LC
780{
781 BalloonInfo *info;
782 Error *err = NULL;
783
784 info = qmp_query_balloon(&err);
785 if (err) {
554a39eb 786 hmp_handle_error(mon, &err);
96637bcd
LC
787 return;
788 }
789
01ceb97e 790 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
96637bcd
LC
791
792 qapi_free_BalloonInfo(info);
793}
794
79627472
LC
795static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
796{
797 PciMemoryRegionList *region;
798
799 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
800 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
801 dev->slot, dev->function);
802 monitor_printf(mon, " ");
803
9fa02cd1
EB
804 if (dev->class_info->has_desc) {
805 monitor_printf(mon, "%s", dev->class_info->desc);
79627472 806 } else {
9fa02cd1 807 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
79627472
LC
808 }
809
810 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
9fa02cd1 811 dev->id->vendor, dev->id->device);
79627472
LC
812
813 if (dev->has_irq) {
814 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
815 }
816
817 if (dev->has_pci_bridge) {
818 monitor_printf(mon, " BUS %" PRId64 ".\n",
9fa02cd1 819 dev->pci_bridge->bus->number);
79627472 820 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
9fa02cd1 821 dev->pci_bridge->bus->secondary);
79627472 822 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
9fa02cd1 823 dev->pci_bridge->bus->subordinate);
79627472
LC
824
825 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
9fa02cd1
EB
826 dev->pci_bridge->bus->io_range->base,
827 dev->pci_bridge->bus->io_range->limit);
79627472
LC
828
829 monitor_printf(mon,
830 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
9fa02cd1
EB
831 dev->pci_bridge->bus->memory_range->base,
832 dev->pci_bridge->bus->memory_range->limit);
79627472
LC
833
834 monitor_printf(mon, " prefetchable memory range "
835 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
9fa02cd1
EB
836 dev->pci_bridge->bus->prefetchable_range->base,
837 dev->pci_bridge->bus->prefetchable_range->limit);
79627472
LC
838 }
839
840 for (region = dev->regions; region; region = region->next) {
841 uint64_t addr, size;
842
843 addr = region->value->address;
844 size = region->value->size;
845
846 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
847
848 if (!strcmp(region->value->type, "io")) {
849 monitor_printf(mon, "I/O at 0x%04" PRIx64
850 " [0x%04" PRIx64 "].\n",
851 addr, addr + size - 1);
852 } else {
853 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
854 " [0x%08" PRIx64 "].\n",
855 region->value->mem_type_64 ? 64 : 32,
856 region->value->prefetch ? " prefetchable" : "",
857 addr, addr + size - 1);
858 }
859 }
860
861 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
862
863 if (dev->has_pci_bridge) {
864 if (dev->pci_bridge->has_devices) {
865 PciDeviceInfoList *cdev;
866 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
867 hmp_info_pci_device(mon, cdev->value);
868 }
869 }
870 }
871}
872
61b97833
HP
873static int hmp_info_irq_foreach(Object *obj, void *opaque)
874{
875 InterruptStatsProvider *intc;
876 InterruptStatsProviderClass *k;
877 Monitor *mon = opaque;
878
879 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
880 intc = INTERRUPT_STATS_PROVIDER(obj);
881 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
882 uint64_t *irq_counts;
883 unsigned int nb_irqs, i;
884 if (k->get_statistics &&
885 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
886 if (nb_irqs > 0) {
887 monitor_printf(mon, "IRQ statistics for %s:\n",
888 object_get_typename(obj));
889 for (i = 0; i < nb_irqs; i++) {
890 if (irq_counts[i] > 0) {
891 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
892 irq_counts[i]);
893 }
894 }
895 }
896 } else {
897 monitor_printf(mon, "IRQ statistics not available for %s.\n",
898 object_get_typename(obj));
899 }
900 }
901
902 return 0;
903}
904
905void hmp_info_irq(Monitor *mon, const QDict *qdict)
906{
907 object_child_foreach_recursive(object_get_root(),
908 hmp_info_irq_foreach, mon);
909}
910
911static int hmp_info_pic_foreach(Object *obj, void *opaque)
912{
913 InterruptStatsProvider *intc;
914 InterruptStatsProviderClass *k;
915 Monitor *mon = opaque;
916
917 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
918 intc = INTERRUPT_STATS_PROVIDER(obj);
919 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
920 if (k->print_info) {
921 k->print_info(intc, mon);
922 } else {
923 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
924 object_get_typename(obj));
925 }
926 }
927
928 return 0;
929}
930
931void hmp_info_pic(Monitor *mon, const QDict *qdict)
932{
933 object_child_foreach_recursive(object_get_root(),
934 hmp_info_pic_foreach, mon);
935}
936
84f2d0ea 937void hmp_info_pci(Monitor *mon, const QDict *qdict)
79627472 938{
f46cee37 939 PciInfoList *info_list, *info;
79627472
LC
940 Error *err = NULL;
941
f46cee37 942 info_list = qmp_query_pci(&err);
79627472
LC
943 if (err) {
944 monitor_printf(mon, "PCI devices not supported\n");
945 error_free(err);
946 return;
947 }
948
f46cee37 949 for (info = info_list; info; info = info->next) {
79627472
LC
950 PciDeviceInfoList *dev;
951
952 for (dev = info->value->devices; dev; dev = dev->next) {
953 hmp_info_pci_device(mon, dev->value);
954 }
955 }
956
f46cee37 957 qapi_free_PciInfoList(info_list);
79627472
LC
958}
959
84f2d0ea 960void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
fb5458cd
SH
961{
962 BlockJobInfoList *list;
963 Error *err = NULL;
964
965 list = qmp_query_block_jobs(&err);
966 assert(!err);
967
968 if (!list) {
969 monitor_printf(mon, "No active jobs\n");
970 return;
971 }
972
973 while (list) {
974 if (strcmp(list->value->type, "stream") == 0) {
975 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
976 " of %" PRId64 " bytes, speed limit %" PRId64
977 " bytes/s\n",
978 list->value->device,
979 list->value->offset,
980 list->value->len,
981 list->value->speed);
982 } else {
983 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
984 " of %" PRId64 " bytes, speed limit %" PRId64
985 " bytes/s\n",
986 list->value->type,
987 list->value->device,
988 list->value->offset,
989 list->value->len,
990 list->value->speed);
991 }
992 list = list->next;
993 }
93bb1315
GA
994
995 qapi_free_BlockJobInfoList(list);
fb5458cd
SH
996}
997
d1a0cf73
SB
998void hmp_info_tpm(Monitor *mon, const QDict *qdict)
999{
1000 TPMInfoList *info_list, *info;
1001 Error *err = NULL;
1002 unsigned int c = 0;
1003 TPMPassthroughOptions *tpo;
f4ede81e 1004 TPMEmulatorOptions *teo;
d1a0cf73
SB
1005
1006 info_list = qmp_query_tpm(&err);
1007 if (err) {
1008 monitor_printf(mon, "TPM device not supported\n");
1009 error_free(err);
1010 return;
1011 }
1012
1013 if (info_list) {
1014 monitor_printf(mon, "TPM device:\n");
1015 }
1016
1017 for (info = info_list; info; info = info->next) {
1018 TPMInfo *ti = info->value;
1019 monitor_printf(mon, " tpm%d: model=%s\n",
977c736f 1020 c, TpmModel_str(ti->model));
d1a0cf73
SB
1021
1022 monitor_printf(mon, " \\ %s: type=%s",
977c736f 1023 ti->id, TpmTypeOptionsKind_str(ti->options->type));
d1a0cf73 1024
ce21131a 1025 switch (ti->options->type) {
88ca7bcf 1026 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
32bafa8f 1027 tpo = ti->options->u.passthrough.data;
d1a0cf73
SB
1028 monitor_printf(mon, "%s%s%s%s",
1029 tpo->has_path ? ",path=" : "",
1030 tpo->has_path ? tpo->path : "",
1031 tpo->has_cancel_path ? ",cancel-path=" : "",
1032 tpo->has_cancel_path ? tpo->cancel_path : "");
1033 break;
f4ede81e
AV
1034 case TPM_TYPE_OPTIONS_KIND_EMULATOR:
1035 teo = ti->options->u.emulator.data;
1036 monitor_printf(mon, ",chardev=%s", teo->chardev);
1037 break;
7fb1cf16 1038 case TPM_TYPE_OPTIONS_KIND__MAX:
d1a0cf73
SB
1039 break;
1040 }
1041 monitor_printf(mon, "\n");
1042 c++;
1043 }
1044 qapi_free_TPMInfoList(info_list);
1045}
1046
7a7f325e
LC
1047void hmp_quit(Monitor *mon, const QDict *qdict)
1048{
1049 monitor_suspend(mon);
1050 qmp_quit(NULL);
1051}
5f158f21
LC
1052
1053void hmp_stop(Monitor *mon, const QDict *qdict)
1054{
1055 qmp_stop(NULL);
1056}
38d22653
LC
1057
1058void hmp_system_reset(Monitor *mon, const QDict *qdict)
1059{
1060 qmp_system_reset(NULL);
1061}
5bc465e4
LC
1062
1063void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
1064{
1065 qmp_system_powerdown(NULL);
1066}
755f1968
LC
1067
1068void hmp_cpu(Monitor *mon, const QDict *qdict)
1069{
1070 int64_t cpu_index;
1071
1072 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1073 use it are converted to the QAPI */
1074 cpu_index = qdict_get_int(qdict, "index");
1075 if (monitor_set_cpu(cpu_index) < 0) {
1076 monitor_printf(mon, "invalid CPU index\n");
1077 }
1078}
0cfd6a9a
LC
1079
1080void hmp_memsave(Monitor *mon, const QDict *qdict)
1081{
1082 uint32_t size = qdict_get_int(qdict, "size");
1083 const char *filename = qdict_get_str(qdict, "filename");
1084 uint64_t addr = qdict_get_int(qdict, "val");
e940f543 1085 Error *err = NULL;
854e67fe 1086 int cpu_index = monitor_get_cpu_index();
0cfd6a9a 1087
854e67fe
TH
1088 if (cpu_index < 0) {
1089 monitor_printf(mon, "No CPU available\n");
1090 return;
1091 }
1092
1093 qmp_memsave(addr, size, filename, true, cpu_index, &err);
e940f543 1094 hmp_handle_error(mon, &err);
0cfd6a9a 1095}
6d3962bf
LC
1096
1097void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1098{
1099 uint32_t size = qdict_get_int(qdict, "size");
1100 const char *filename = qdict_get_str(qdict, "filename");
1101 uint64_t addr = qdict_get_int(qdict, "val");
e940f543 1102 Error *err = NULL;
6d3962bf 1103
e940f543
MA
1104 qmp_pmemsave(addr, size, filename, &err);
1105 hmp_handle_error(mon, &err);
1f590cf9
LL
1106}
1107
3949e594 1108void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1f590cf9 1109{
1f590cf9
LL
1110 const char *chardev = qdict_get_str(qdict, "device");
1111 const char *data = qdict_get_str(qdict, "data");
e940f543 1112 Error *err = NULL;
1f590cf9 1113
e940f543 1114 qmp_ringbuf_write(chardev, data, false, 0, &err);
1f590cf9 1115
e940f543 1116 hmp_handle_error(mon, &err);
6d3962bf 1117}
e42e818b 1118
3949e594 1119void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
49b6d722
LL
1120{
1121 uint32_t size = qdict_get_int(qdict, "size");
1122 const char *chardev = qdict_get_str(qdict, "device");
3ab651fc 1123 char *data;
e940f543 1124 Error *err = NULL;
543f3412 1125 int i;
49b6d722 1126
e940f543
MA
1127 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1128 if (err) {
554a39eb 1129 hmp_handle_error(mon, &err);
49b6d722
LL
1130 return;
1131 }
1132
543f3412
MA
1133 for (i = 0; data[i]; i++) {
1134 unsigned char ch = data[i];
1135
1136 if (ch == '\\') {
1137 monitor_printf(mon, "\\\\");
1138 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1139 monitor_printf(mon, "\\u%04X", ch);
1140 } else {
1141 monitor_printf(mon, "%c", ch);
1142 }
1143
1144 }
1145 monitor_printf(mon, "\n");
3ab651fc 1146 g_free(data);
49b6d722
LL
1147}
1148
e42e818b
LC
1149void hmp_cont(Monitor *mon, const QDict *qdict)
1150{
e940f543 1151 Error *err = NULL;
e42e818b 1152
e940f543
MA
1153 qmp_cont(&err);
1154 hmp_handle_error(mon, &err);
e42e818b 1155}
ab49ab5c 1156
9b9df25a
GH
1157void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1158{
1159 qmp_system_wakeup(NULL);
1160}
1161
3e5a50d6 1162void hmp_nmi(Monitor *mon, const QDict *qdict)
ab49ab5c 1163{
e940f543 1164 Error *err = NULL;
ab49ab5c 1165
e940f543
MA
1166 qmp_inject_nmi(&err);
1167 hmp_handle_error(mon, &err);
ab49ab5c 1168}
4b37156c
LC
1169
1170void hmp_set_link(Monitor *mon, const QDict *qdict)
1171{
1172 const char *name = qdict_get_str(qdict, "name");
34acbc95 1173 bool up = qdict_get_bool(qdict, "up");
e940f543 1174 Error *err = NULL;
4b37156c 1175
e940f543
MA
1176 qmp_set_link(name, up, &err);
1177 hmp_handle_error(mon, &err);
4b37156c 1178}
a4dea8a9
LC
1179
1180void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1181{
1182 const char *device = qdict_get_str(qdict, "device");
1183 const char *password = qdict_get_str(qdict, "password");
e940f543 1184 Error *err = NULL;
a4dea8a9 1185
e940f543
MA
1186 qmp_block_passwd(true, device, false, NULL, password, &err);
1187 hmp_handle_error(mon, &err);
a4dea8a9 1188}
d72f3264
LC
1189
1190void hmp_balloon(Monitor *mon, const QDict *qdict)
1191{
1192 int64_t value = qdict_get_int(qdict, "value");
e940f543 1193 Error *err = NULL;
d72f3264 1194
e940f543 1195 qmp_balloon(value, &err);
554a39eb 1196 hmp_handle_error(mon, &err);
d72f3264 1197}
5e7caacb
LC
1198
1199void hmp_block_resize(Monitor *mon, const QDict *qdict)
1200{
1201 const char *device = qdict_get_str(qdict, "device");
1202 int64_t size = qdict_get_int(qdict, "size");
e940f543 1203 Error *err = NULL;
5e7caacb 1204
e940f543
MA
1205 qmp_block_resize(true, device, false, NULL, size, &err);
1206 hmp_handle_error(mon, &err);
5e7caacb 1207}
6106e249 1208
d9b902db
PB
1209void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1210{
d9b902db
PB
1211 const char *filename = qdict_get_str(qdict, "target");
1212 const char *format = qdict_get_try_str(qdict, "format");
34acbc95
EB
1213 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1214 bool full = qdict_get_try_bool(qdict, "full", false);
e940f543 1215 Error *err = NULL;
faecd40a
EB
1216 DriveMirror mirror = {
1217 .device = (char *)qdict_get_str(qdict, "device"),
1218 .target = (char *)filename,
1219 .has_format = !!format,
1220 .format = (char *)format,
1221 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1222 .has_mode = true,
1223 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1224 .unmap = true,
1225 };
d9b902db
PB
1226
1227 if (!filename) {
c6bd8c70 1228 error_setg(&err, QERR_MISSING_PARAMETER, "target");
e940f543 1229 hmp_handle_error(mon, &err);
d9b902db
PB
1230 return;
1231 }
faecd40a 1232 qmp_drive_mirror(&mirror, &err);
e940f543 1233 hmp_handle_error(mon, &err);
d9b902db
PB
1234}
1235
de90930a
SH
1236void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1237{
1238 const char *device = qdict_get_str(qdict, "device");
1239 const char *filename = qdict_get_str(qdict, "target");
1240 const char *format = qdict_get_try_str(qdict, "format");
34acbc95
EB
1241 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1242 bool full = qdict_get_try_bool(qdict, "full", false);
13b9414b 1243 bool compress = qdict_get_try_bool(qdict, "compress", false);
e940f543 1244 Error *err = NULL;
81206a89
PB
1245 DriveBackup backup = {
1246 .device = (char *)device,
1247 .target = (char *)filename,
1248 .has_format = !!format,
1249 .format = (char *)format,
1250 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1251 .has_mode = true,
1252 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
13b9414b
PB
1253 .has_compress = !!compress,
1254 .compress = compress,
81206a89 1255 };
de90930a
SH
1256
1257 if (!filename) {
c6bd8c70 1258 error_setg(&err, QERR_MISSING_PARAMETER, "target");
e940f543 1259 hmp_handle_error(mon, &err);
de90930a
SH
1260 return;
1261 }
1262
81206a89 1263 qmp_drive_backup(&backup, &err);
e940f543 1264 hmp_handle_error(mon, &err);
de90930a
SH
1265}
1266
6106e249
LC
1267void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1268{
1269 const char *device = qdict_get_str(qdict, "device");
1270 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1271 const char *format = qdict_get_try_str(qdict, "format");
34acbc95 1272 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
6cc2a415 1273 enum NewImageMode mode;
e940f543 1274 Error *err = NULL;
6106e249
LC
1275
1276 if (!filename) {
1277 /* In the future, if 'snapshot-file' is not specified, the snapshot
1278 will be taken internally. Today it's actually required. */
c6bd8c70 1279 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
e940f543 1280 hmp_handle_error(mon, &err);
6106e249
LC
1281 return;
1282 }
1283
6cc2a415 1284 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
0901f67e
BC
1285 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1286 filename, false, NULL,
1287 !!format, format,
e940f543
MA
1288 true, mode, &err);
1289 hmp_handle_error(mon, &err);
6106e249 1290}
6cdedb07 1291
775ca88e
WX
1292void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1293{
1294 const char *device = qdict_get_str(qdict, "device");
1295 const char *name = qdict_get_str(qdict, "name");
e940f543 1296 Error *err = NULL;
775ca88e 1297
e940f543
MA
1298 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1299 hmp_handle_error(mon, &err);
775ca88e
WX
1300}
1301
7a4ed2ee
WX
1302void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1303{
1304 const char *device = qdict_get_str(qdict, "device");
1305 const char *name = qdict_get_str(qdict, "name");
1306 const char *id = qdict_get_try_str(qdict, "id");
e940f543 1307 Error *err = NULL;
7a4ed2ee
WX
1308
1309 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
e940f543
MA
1310 true, name, &err);
1311 hmp_handle_error(mon, &err);
7a4ed2ee
WX
1312}
1313
52b26205
JQ
1314void hmp_loadvm(Monitor *mon, const QDict *qdict)
1315{
1316 int saved_vm_running = runstate_is_running();
1317 const char *name = qdict_get_str(qdict, "name");
927d6638 1318 Error *err = NULL;
52b26205
JQ
1319
1320 vm_stop(RUN_STATE_RESTORE_VM);
1321
5e22479a 1322 if (load_snapshot(name, &err) == 0 && saved_vm_running) {
52b26205
JQ
1323 vm_start();
1324 }
927d6638 1325 hmp_handle_error(mon, &err);
52b26205
JQ
1326}
1327
d9c7d137
JQ
1328void hmp_savevm(Monitor *mon, const QDict *qdict)
1329{
927d6638
JQ
1330 Error *err = NULL;
1331
5e22479a 1332 save_snapshot(qdict_get_try_str(qdict, "name"), &err);
927d6638 1333 hmp_handle_error(mon, &err);
d9c7d137
JQ
1334}
1335
d905bb7b
JQ
1336void hmp_delvm(Monitor *mon, const QDict *qdict)
1337{
1338 BlockDriverState *bs;
32cd6550 1339 Error *err = NULL;
d905bb7b
JQ
1340 const char *name = qdict_get_str(qdict, "name");
1341
1342 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
1343 error_reportf_err(err,
1344 "Error while deleting snapshot on device '%s': ",
1345 bdrv_get_device_name(bs));
1346 }
1347}
1348
66830618
JQ
1349void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
1350{
1351 BlockDriverState *bs, *bs1;
1352 BdrvNextIterator it1;
1353 QEMUSnapshotInfo *sn_tab, *sn;
1354 bool no_snapshot = true;
1355 int nb_sns, i;
1356 int total;
1357 int *global_snapshots;
1358 AioContext *aio_context;
1359
1360 typedef struct SnapshotEntry {
1361 QEMUSnapshotInfo sn;
1362 QTAILQ_ENTRY(SnapshotEntry) next;
1363 } SnapshotEntry;
1364
1365 typedef struct ImageEntry {
1366 const char *imagename;
1367 QTAILQ_ENTRY(ImageEntry) next;
1368 QTAILQ_HEAD(, SnapshotEntry) snapshots;
1369 } ImageEntry;
1370
1371 QTAILQ_HEAD(, ImageEntry) image_list =
1372 QTAILQ_HEAD_INITIALIZER(image_list);
1373
1374 ImageEntry *image_entry, *next_ie;
1375 SnapshotEntry *snapshot_entry;
1376
1377 bs = bdrv_all_find_vmstate_bs();
1378 if (!bs) {
1379 monitor_printf(mon, "No available block device supports snapshots\n");
1380 return;
1381 }
1382 aio_context = bdrv_get_aio_context(bs);
1383
1384 aio_context_acquire(aio_context);
1385 nb_sns = bdrv_snapshot_list(bs, &sn_tab);
1386 aio_context_release(aio_context);
1387
1388 if (nb_sns < 0) {
1389 monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
1390 return;
1391 }
1392
1393 for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) {
1394 int bs1_nb_sns = 0;
1395 ImageEntry *ie;
1396 SnapshotEntry *se;
1397 AioContext *ctx = bdrv_get_aio_context(bs1);
1398
1399 aio_context_acquire(ctx);
1400 if (bdrv_can_snapshot(bs1)) {
1401 sn = NULL;
1402 bs1_nb_sns = bdrv_snapshot_list(bs1, &sn);
1403 if (bs1_nb_sns > 0) {
1404 no_snapshot = false;
1405 ie = g_new0(ImageEntry, 1);
1406 ie->imagename = bdrv_get_device_name(bs1);
1407 QTAILQ_INIT(&ie->snapshots);
1408 QTAILQ_INSERT_TAIL(&image_list, ie, next);
1409 for (i = 0; i < bs1_nb_sns; i++) {
1410 se = g_new0(SnapshotEntry, 1);
1411 se->sn = sn[i];
1412 QTAILQ_INSERT_TAIL(&ie->snapshots, se, next);
1413 }
1414 }
1415 g_free(sn);
1416 }
1417 aio_context_release(ctx);
1418 }
1419
1420 if (no_snapshot) {
1421 monitor_printf(mon, "There is no snapshot available.\n");
1422 return;
1423 }
1424
1425 global_snapshots = g_new0(int, nb_sns);
1426 total = 0;
1427 for (i = 0; i < nb_sns; i++) {
1428 SnapshotEntry *next_sn;
1429 if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) {
1430 global_snapshots[total] = i;
1431 total++;
1432 QTAILQ_FOREACH(image_entry, &image_list, next) {
1433 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots,
1434 next, next_sn) {
1435 if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) {
1436 QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry,
1437 next);
1438 g_free(snapshot_entry);
1439 }
1440 }
1441 }
1442 }
1443 }
1444
1445 monitor_printf(mon, "List of snapshots present on all disks:\n");
1446
1447 if (total > 0) {
1448 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1449 monitor_printf(mon, "\n");
1450 for (i = 0; i < total; i++) {
1451 sn = &sn_tab[global_snapshots[i]];
1452 /* The ID is not guaranteed to be the same on all images, so
1453 * overwrite it.
1454 */
1455 pstrcpy(sn->id_str, sizeof(sn->id_str), "--");
1456 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, sn);
1457 monitor_printf(mon, "\n");
1458 }
1459 } else {
1460 monitor_printf(mon, "None\n");
1461 }
1462
1463 QTAILQ_FOREACH(image_entry, &image_list, next) {
1464 if (QTAILQ_EMPTY(&image_entry->snapshots)) {
1465 continue;
1466 }
1467 monitor_printf(mon,
1468 "\nList of partial (non-loadable) snapshots on '%s':\n",
1469 image_entry->imagename);
1470 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1471 monitor_printf(mon, "\n");
1472 QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) {
1473 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon,
1474 &snapshot_entry->sn);
1475 monitor_printf(mon, "\n");
1476 }
1477 }
1478
1479 QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) {
1480 SnapshotEntry *next_sn;
1481 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next,
1482 next_sn) {
1483 g_free(snapshot_entry);
1484 }
1485 g_free(image_entry);
1486 }
1487 g_free(sn_tab);
1488 g_free(global_snapshots);
1489
1490}
1491
6cdedb07
LC
1492void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1493{
1494 qmp_migrate_cancel(NULL);
1495}
4f0a993b 1496
94ae12cb
DDAG
1497void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1498{
1499 Error *err = NULL;
1500 const char *state = qdict_get_str(qdict, "state");
1501 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1502
1503 if (val >= 0) {
1504 qmp_migrate_continue(val, &err);
1505 }
1506
1507 hmp_handle_error(mon, &err);
1508}
1509
bf1ae1f4
DDAG
1510void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1511{
1512 Error *err = NULL;
1513 const char *uri = qdict_get_str(qdict, "uri");
1514
1515 qmp_migrate_incoming(uri, &err);
1516
1fa57f55 1517 hmp_handle_error(mon, &err);
bf1ae1f4
DDAG
1518}
1519
2ff30257 1520/* Kept for backwards compatibility */
4f0a993b
LC
1521void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1522{
1523 double value = qdict_get_double(qdict, "value");
1524 qmp_migrate_set_downtime(value, NULL);
1525}
3dc85383 1526
9e1ba4cc
OW
1527void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1528{
1529 int64_t value = qdict_get_int(qdict, "value");
1530 Error *err = NULL;
1531
1532 qmp_migrate_set_cache_size(value, &err);
554a39eb 1533 hmp_handle_error(mon, &err);
9e1ba4cc
OW
1534}
1535
2ff30257 1536/* Kept for backwards compatibility */
3dc85383
LC
1537void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1538{
1539 int64_t value = qdict_get_int(qdict, "value");
1540 qmp_migrate_set_speed(value, NULL);
1541}
fbf796fd 1542
00458433
OW
1543void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1544{
1545 const char *cap = qdict_get_str(qdict, "capability");
1546 bool state = qdict_get_bool(qdict, "state");
1547 Error *err = NULL;
1548 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
8e615e34 1549 int val;
00458433 1550
f7abe0ec 1551 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
8e615e34
MAL
1552 if (val < 0) {
1553 goto end;
00458433
OW
1554 }
1555
8e615e34
MAL
1556 caps->value = g_malloc0(sizeof(*caps->value));
1557 caps->value->capability = val;
1558 caps->value->state = state;
1559 caps->next = NULL;
1560 qmp_migrate_set_capabilities(caps, &err);
00458433 1561
8e615e34 1562end:
00458433 1563 qapi_free_MigrationCapabilityStatusList(caps);
554a39eb 1564 hmp_handle_error(mon, &err);
00458433
OW
1565}
1566
50e9a629
LL
1567void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1568{
1569 const char *param = qdict_get_str(qdict, "parameter");
69ef1f36 1570 const char *valuestr = qdict_get_str(qdict, "value");
f4a06d13 1571 Visitor *v = string_input_visitor_new(valuestr);
1bda8b3c 1572 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
f46bfdbf 1573 uint64_t valuebw = 0;
73af8dd8 1574 uint64_t cache_size;
50e9a629 1575 Error *err = NULL;
262517b7 1576 int val, ret;
69ef1f36 1577
f7abe0ec 1578 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
262517b7
MAL
1579 if (val < 0) {
1580 goto cleanup;
1581 }
1582
1583 switch (val) {
1584 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1585 p->has_compress_level = true;
1586 visit_type_int(v, param, &p->compress_level, &err);
1587 break;
1588 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1589 p->has_compress_threads = true;
1590 visit_type_int(v, param, &p->compress_threads, &err);
1591 break;
1592 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1593 p->has_decompress_threads = true;
1594 visit_type_int(v, param, &p->decompress_threads, &err);
1595 break;
1596 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1597 p->has_cpu_throttle_initial = true;
1598 visit_type_int(v, param, &p->cpu_throttle_initial, &err);
1599 break;
1600 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1601 p->has_cpu_throttle_increment = true;
1602 visit_type_int(v, param, &p->cpu_throttle_increment, &err);
1603 break;
1604 case MIGRATION_PARAMETER_TLS_CREDS:
1605 p->has_tls_creds = true;
1606 p->tls_creds = g_new0(StrOrNull, 1);
1607 p->tls_creds->type = QTYPE_QSTRING;
1608 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1609 break;
1610 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1611 p->has_tls_hostname = true;
1612 p->tls_hostname = g_new0(StrOrNull, 1);
1613 p->tls_hostname->type = QTYPE_QSTRING;
1614 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1615 break;
1616 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1617 p->has_max_bandwidth = true;
1618 /*
1619 * Can't use visit_type_size() here, because it
1620 * defaults to Bytes rather than Mebibytes.
1621 */
1622 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1623 if (ret < 0 || valuebw > INT64_MAX
1624 || (size_t)valuebw != valuebw) {
1625 error_setg(&err, "Invalid size %s", valuestr);
50e9a629
LL
1626 break;
1627 }
262517b7
MAL
1628 p->max_bandwidth = valuebw;
1629 break;
1630 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1631 p->has_downtime_limit = true;
1632 visit_type_int(v, param, &p->downtime_limit, &err);
1633 break;
1634 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1635 p->has_x_checkpoint_delay = true;
1636 visit_type_int(v, param, &p->x_checkpoint_delay, &err);
1637 break;
1638 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1639 p->has_block_incremental = true;
1640 visit_type_bool(v, param, &p->block_incremental, &err);
1641 break;
4075fb1c
JQ
1642 case MIGRATION_PARAMETER_X_MULTIFD_CHANNELS:
1643 p->has_x_multifd_channels = true;
1644 visit_type_int(v, param, &p->x_multifd_channels, &err);
1645 break;
0fb86605
JQ
1646 case MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT:
1647 p->has_x_multifd_page_count = true;
1648 visit_type_int(v, param, &p->x_multifd_page_count, &err);
1649 break;
73af8dd8
JQ
1650 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1651 p->has_xbzrle_cache_size = true;
1652 visit_type_size(v, param, &cache_size, &err);
1653 if (err || cache_size > INT64_MAX
1654 || (size_t)cache_size != cache_size) {
1655 error_setg(&err, "Invalid size %s", valuestr);
1656 break;
1657 }
1658 p->xbzrle_cache_size = cache_size;
1659 break;
262517b7
MAL
1660 default:
1661 assert(0);
50e9a629
LL
1662 }
1663
262517b7
MAL
1664 if (err) {
1665 goto cleanup;
50e9a629
LL
1666 }
1667
262517b7
MAL
1668 qmp_migrate_set_parameters(p, &err);
1669
69ef1f36 1670 cleanup:
1bda8b3c 1671 qapi_free_MigrateSetParameters(p);
f4a06d13 1672 visit_free(v);
554a39eb 1673 hmp_handle_error(mon, &err);
50e9a629
LL
1674}
1675
b8a185bc
MA
1676void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1677{
1678 Error *err = NULL;
1679 const char *protocol = qdict_get_str(qdict, "protocol");
1680 const char *hostname = qdict_get_str(qdict, "hostname");
1681 bool has_port = qdict_haskey(qdict, "port");
1682 int port = qdict_get_try_int(qdict, "port", -1);
1683 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1684 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1685 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1686
1687 qmp_client_migrate_info(protocol, hostname,
1688 has_port, port, has_tls_port, tls_port,
1689 !!cert_subject, cert_subject, &err);
1690 hmp_handle_error(mon, &err);
1691}
1692
4886a1bc
DDAG
1693void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1694{
1695 Error *err = NULL;
1696 qmp_migrate_start_postcopy(&err);
1697 hmp_handle_error(mon, &err);
1698}
1699
d89e666e
HZ
1700void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1701{
1702 Error *err = NULL;
1703
1704 qmp_x_colo_lost_heartbeat(&err);
1705 hmp_handle_error(mon, &err);
1706}
1707
fbf796fd
LC
1708void hmp_set_password(Monitor *mon, const QDict *qdict)
1709{
1710 const char *protocol = qdict_get_str(qdict, "protocol");
1711 const char *password = qdict_get_str(qdict, "password");
1712 const char *connected = qdict_get_try_str(qdict, "connected");
1713 Error *err = NULL;
1714
1715 qmp_set_password(protocol, password, !!connected, connected, &err);
1716 hmp_handle_error(mon, &err);
1717}
9ad5372d
LC
1718
1719void hmp_expire_password(Monitor *mon, const QDict *qdict)
1720{
1721 const char *protocol = qdict_get_str(qdict, "protocol");
1722 const char *whenstr = qdict_get_str(qdict, "time");
1723 Error *err = NULL;
1724
1725 qmp_expire_password(protocol, whenstr, &err);
1726 hmp_handle_error(mon, &err);
1727}
c245b6a3
LC
1728
1729void hmp_eject(Monitor *mon, const QDict *qdict)
1730{
34acbc95 1731 bool force = qdict_get_try_bool(qdict, "force", false);
c245b6a3
LC
1732 const char *device = qdict_get_str(qdict, "device");
1733 Error *err = NULL;
1734
fbe2d816 1735 qmp_eject(true, device, false, NULL, true, force, &err);
c245b6a3
LC
1736 hmp_handle_error(mon, &err);
1737}
333a96ec 1738
c60bf339
SH
1739static void hmp_change_read_arg(void *opaque, const char *password,
1740 void *readline_opaque)
333a96ec
LC
1741{
1742 qmp_change_vnc_password(password, NULL);
c60bf339 1743 monitor_read_command(opaque, 1);
333a96ec
LC
1744}
1745
333a96ec
LC
1746void hmp_change(Monitor *mon, const QDict *qdict)
1747{
1748 const char *device = qdict_get_str(qdict, "device");
1749 const char *target = qdict_get_str(qdict, "target");
1750 const char *arg = qdict_get_try_str(qdict, "arg");
baead0ab
HR
1751 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1752 BlockdevChangeReadOnlyMode read_only_mode = 0;
333a96ec
LC
1753 Error *err = NULL;
1754
10686749 1755 if (strcmp(device, "vnc") == 0) {
baead0ab
HR
1756 if (read_only) {
1757 monitor_printf(mon,
1758 "Parameter 'read-only-mode' is invalid for VNC\n");
1759 return;
1760 }
10686749
HR
1761 if (strcmp(target, "passwd") == 0 ||
1762 strcmp(target, "password") == 0) {
1763 if (!arg) {
1764 monitor_read_password(mon, hmp_change_read_arg, NULL);
1765 return;
1766 }
1767 }
1768 qmp_change("vnc", target, !!arg, arg, &err);
1769 } else {
baead0ab
HR
1770 if (read_only) {
1771 read_only_mode =
f7abe0ec 1772 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
06c60b6c 1773 read_only,
baead0ab
HR
1774 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1775 if (err) {
1776 hmp_handle_error(mon, &err);
1777 return;
1778 }
1779 }
1780
70e2cb3b
KW
1781 qmp_blockdev_change_medium(true, device, false, NULL, target,
1782 !!arg, arg, !!read_only, read_only_mode,
1783 &err);
333a96ec
LC
1784 }
1785
333a96ec
LC
1786 hmp_handle_error(mon, &err);
1787}
80047da5
LC
1788
1789void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1790{
1791 Error *err = NULL;
83592184 1792 char *device = (char *) qdict_get_str(qdict, "device");
4dc9397b 1793 BlockIOThrottle throttle = {
4dc9397b
EB
1794 .bps = qdict_get_int(qdict, "bps"),
1795 .bps_rd = qdict_get_int(qdict, "bps_rd"),
1796 .bps_wr = qdict_get_int(qdict, "bps_wr"),
1797 .iops = qdict_get_int(qdict, "iops"),
1798 .iops_rd = qdict_get_int(qdict, "iops_rd"),
1799 .iops_wr = qdict_get_int(qdict, "iops_wr"),
1800 };
80047da5 1801
83592184
AG
1802 /* qmp_block_set_io_throttle has separate parameters for the
1803 * (deprecated) block device name and the qdev ID but the HMP
1804 * version has only one, so we must decide which one to pass. */
1805 if (blk_by_name(device)) {
1806 throttle.has_device = true;
1807 throttle.device = device;
1808 } else {
1809 throttle.has_id = true;
1810 throttle.id = device;
1811 }
1812
4dc9397b 1813 qmp_block_set_io_throttle(&throttle, &err);
80047da5
LC
1814 hmp_handle_error(mon, &err);
1815}
12bd451f
SH
1816
1817void hmp_block_stream(Monitor *mon, const QDict *qdict)
1818{
1819 Error *error = NULL;
1820 const char *device = qdict_get_str(qdict, "device");
1821 const char *base = qdict_get_try_str(qdict, "base");
c83c66c3 1822 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
12bd451f 1823
11d6fbe0 1824 qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
312fe09c 1825 false, NULL, qdict_haskey(qdict, "speed"), speed,
46663e5e 1826 true, BLOCKDEV_ON_ERROR_REPORT, &error);
12bd451f
SH
1827
1828 hmp_handle_error(mon, &error);
1829}
2d47c6e9
SH
1830
1831void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1832{
1833 Error *error = NULL;
1834 const char *device = qdict_get_str(qdict, "device");
c6db2395 1835 int64_t value = qdict_get_int(qdict, "speed");
2d47c6e9
SH
1836
1837 qmp_block_job_set_speed(device, value, &error);
1838
1839 hmp_handle_error(mon, &error);
1840}
370521a1
SH
1841
1842void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1843{
1844 Error *error = NULL;
1845 const char *device = qdict_get_str(qdict, "device");
34acbc95 1846 bool force = qdict_get_try_bool(qdict, "force", false);
370521a1 1847
6e37fb81
PB
1848 qmp_block_job_cancel(device, true, force, &error);
1849
1850 hmp_handle_error(mon, &error);
1851}
1852
1853void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1854{
1855 Error *error = NULL;
1856 const char *device = qdict_get_str(qdict, "device");
1857
1858 qmp_block_job_pause(device, &error);
1859
1860 hmp_handle_error(mon, &error);
1861}
1862
1863void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1864{
1865 Error *error = NULL;
1866 const char *device = qdict_get_str(qdict, "device");
1867
1868 qmp_block_job_resume(device, &error);
370521a1
SH
1869
1870 hmp_handle_error(mon, &error);
1871}
e1c37d0e 1872
aeae883b
PB
1873void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1874{
1875 Error *error = NULL;
1876 const char *device = qdict_get_str(qdict, "device");
1877
1878 qmp_block_job_complete(device, &error);
1879
1880 hmp_handle_error(mon, &error);
1881}
1882
e49f35bd 1883typedef struct HMPMigrationStatus
e1c37d0e
LC
1884{
1885 QEMUTimer *timer;
1886 Monitor *mon;
1887 bool is_block_migration;
e49f35bd 1888} HMPMigrationStatus;
e1c37d0e
LC
1889
1890static void hmp_migrate_status_cb(void *opaque)
1891{
e49f35bd 1892 HMPMigrationStatus *status = opaque;
e1c37d0e
LC
1893 MigrationInfo *info;
1894
1895 info = qmp_query_migrate(NULL);
24b8c39b
HZ
1896 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1897 info->status == MIGRATION_STATUS_SETUP) {
e1c37d0e
LC
1898 if (info->has_disk) {
1899 int progress;
1900
1901 if (info->disk->remaining) {
1902 progress = info->disk->transferred * 100 / info->disk->total;
1903 } else {
1904 progress = 100;
1905 }
1906
1907 monitor_printf(status->mon, "Completed %d %%\r", progress);
1908 monitor_flush(status->mon);
1909 }
1910
bc72ad67 1911 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
e1c37d0e
LC
1912 } else {
1913 if (status->is_block_migration) {
1914 monitor_printf(status->mon, "\n");
1915 }
d59ce6f3
DB
1916 if (info->has_error_desc) {
1917 error_report("%s", info->error_desc);
1918 }
e1c37d0e 1919 monitor_resume(status->mon);
bc72ad67 1920 timer_del(status->timer);
e1c37d0e
LC
1921 g_free(status);
1922 }
1923
1924 qapi_free_MigrationInfo(info);
1925}
1926
1927void hmp_migrate(Monitor *mon, const QDict *qdict)
1928{
34acbc95
EB
1929 bool detach = qdict_get_try_bool(qdict, "detach", false);
1930 bool blk = qdict_get_try_bool(qdict, "blk", false);
1931 bool inc = qdict_get_try_bool(qdict, "inc", false);
7a4da28b 1932 bool resume = qdict_get_try_bool(qdict, "resume", false);
e1c37d0e
LC
1933 const char *uri = qdict_get_str(qdict, "uri");
1934 Error *err = NULL;
1935
7a4da28b
PX
1936 qmp_migrate(uri, !!blk, blk, !!inc, inc,
1937 false, false, true, resume, &err);
e1c37d0e 1938 if (err) {
554a39eb 1939 hmp_handle_error(mon, &err);
e1c37d0e
LC
1940 return;
1941 }
1942
1943 if (!detach) {
e49f35bd 1944 HMPMigrationStatus *status;
e1c37d0e
LC
1945
1946 if (monitor_suspend(mon) < 0) {
1947 monitor_printf(mon, "terminal does not allow synchronous "
1948 "migration, continuing detached\n");
1949 return;
1950 }
1951
1952 status = g_malloc0(sizeof(*status));
1953 status->mon = mon;
1954 status->is_block_migration = blk || inc;
bc72ad67 1955 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
e1c37d0e 1956 status);
bc72ad67 1957 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
e1c37d0e
LC
1958 }
1959}
a15fef21 1960
318660f8
MA
1961void hmp_device_add(Monitor *mon, const QDict *qdict)
1962{
485febc6
MA
1963 Error *err = NULL;
1964
1965 qmp_device_add((QDict *)qdict, NULL, &err);
1966 hmp_handle_error(mon, &err);
318660f8
MA
1967}
1968
a15fef21
LC
1969void hmp_device_del(Monitor *mon, const QDict *qdict)
1970{
1971 const char *id = qdict_get_str(qdict, "id");
1972 Error *err = NULL;
1973
1974 qmp_device_del(id, &err);
1975 hmp_handle_error(mon, &err);
1976}
783e9b48
WC
1977
1978void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1979{
e940f543 1980 Error *err = NULL;
34acbc95
EB
1981 bool paging = qdict_get_try_bool(qdict, "paging", false);
1982 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
1983 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
1984 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
75363769 1985 const char *file = qdict_get_str(qdict, "filename");
783e9b48
WC
1986 bool has_begin = qdict_haskey(qdict, "begin");
1987 bool has_length = qdict_haskey(qdict, "length");
228de9cf 1988 bool has_detach = qdict_haskey(qdict, "detach");
783e9b48
WC
1989 int64_t begin = 0;
1990 int64_t length = 0;
228de9cf 1991 bool detach = false;
b53ccc30 1992 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
75363769 1993 char *prot;
783e9b48 1994
1b7a0f75 1995 if (zlib + lzo + snappy > 1) {
e940f543
MA
1996 error_setg(&err, "only one of '-z|-l|-s' can be set");
1997 hmp_handle_error(mon, &err);
1b7a0f75
QN
1998 return;
1999 }
2000
2001 if (zlib) {
2002 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
2003 }
2004
2005 if (lzo) {
2006 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
2007 }
2008
2009 if (snappy) {
2010 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
2011 }
2012
783e9b48
WC
2013 if (has_begin) {
2014 begin = qdict_get_int(qdict, "begin");
2015 }
2016 if (has_length) {
2017 length = qdict_get_int(qdict, "length");
2018 }
228de9cf
PX
2019 if (has_detach) {
2020 detach = qdict_get_bool(qdict, "detach");
2021 }
783e9b48 2022
75363769
LC
2023 prot = g_strconcat("file:", file, NULL);
2024
228de9cf
PX
2025 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
2026 has_length, length, true, dump_format, &err);
e940f543 2027 hmp_handle_error(mon, &err);
75363769 2028 g_free(prot);
783e9b48 2029}
928059a3
LC
2030
2031void hmp_netdev_add(Monitor *mon, const QDict *qdict)
2032{
2033 Error *err = NULL;
2034 QemuOpts *opts;
2035
2036 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
84d18f06 2037 if (err) {
928059a3
LC
2038 goto out;
2039 }
2040
2041 netdev_add(opts, &err);
84d18f06 2042 if (err) {
928059a3
LC
2043 qemu_opts_del(opts);
2044 }
2045
2046out:
2047 hmp_handle_error(mon, &err);
2048}
5f964155
LC
2049
2050void hmp_netdev_del(Monitor *mon, const QDict *qdict)
2051{
2052 const char *id = qdict_get_str(qdict, "id");
2053 Error *err = NULL;
2054
2055 qmp_netdev_del(id, &err);
2056 hmp_handle_error(mon, &err);
2057}
208c9d1b 2058
cff8b2c6
PB
2059void hmp_object_add(Monitor *mon, const QDict *qdict)
2060{
2061 Error *err = NULL;
2062 QemuOpts *opts;
90998d58 2063 Object *obj = NULL;
cff8b2c6
PB
2064
2065 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
2066 if (err) {
90998d58
DB
2067 hmp_handle_error(mon, &err);
2068 return;
cff8b2c6
PB
2069 }
2070
3a464105 2071 obj = user_creatable_add_opts(opts, &err);
90998d58 2072 qemu_opts_del(opts);
cff8b2c6 2073
cff8b2c6 2074 if (err) {
90998d58 2075 hmp_handle_error(mon, &err);
cff8b2c6 2076 }
90998d58
DB
2077 if (obj) {
2078 object_unref(obj);
cff8b2c6 2079 }
cff8b2c6
PB
2080}
2081
208c9d1b
CB
2082void hmp_getfd(Monitor *mon, const QDict *qdict)
2083{
2084 const char *fdname = qdict_get_str(qdict, "fdname");
e940f543 2085 Error *err = NULL;
208c9d1b 2086
e940f543
MA
2087 qmp_getfd(fdname, &err);
2088 hmp_handle_error(mon, &err);
208c9d1b
CB
2089}
2090
2091void hmp_closefd(Monitor *mon, const QDict *qdict)
2092{
2093 const char *fdname = qdict_get_str(qdict, "fdname");
e940f543 2094 Error *err = NULL;
208c9d1b 2095
e940f543
MA
2096 qmp_closefd(fdname, &err);
2097 hmp_handle_error(mon, &err);
208c9d1b 2098}
e4c8f004 2099
3e5a50d6 2100void hmp_sendkey(Monitor *mon, const QDict *qdict)
e4c8f004
AK
2101{
2102 const char *keys = qdict_get_str(qdict, "keys");
9f328977 2103 KeyValueList *keylist, *head = NULL, *tmp = NULL;
e4c8f004
AK
2104 int has_hold_time = qdict_haskey(qdict, "hold-time");
2105 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
2106 Error *err = NULL;
e4c8f004 2107 char *separator;
9f328977 2108 int keyname_len;
e4c8f004
AK
2109
2110 while (1) {
2111 separator = strchr(keys, '-');
2112 keyname_len = separator ? separator - keys : strlen(keys);
e4c8f004
AK
2113
2114 /* Be compatible with old interface, convert user inputted "<" */
64ffbe04
WB
2115 if (keys[0] == '<' && keyname_len == 1) {
2116 keys = "less";
e4c8f004
AK
2117 keyname_len = 4;
2118 }
e4c8f004 2119
e4c8f004 2120 keylist = g_malloc0(sizeof(*keylist));
9f328977 2121 keylist->value = g_malloc0(sizeof(*keylist->value));
e4c8f004
AK
2122
2123 if (!head) {
2124 head = keylist;
2125 }
2126 if (tmp) {
2127 tmp->next = keylist;
2128 }
2129 tmp = keylist;
2130
64ffbe04 2131 if (strstart(keys, "0x", NULL)) {
9f328977 2132 char *endp;
64ffbe04
WB
2133 int value = strtoul(keys, &endp, 0);
2134 assert(endp <= keys + keyname_len);
2135 if (endp != keys + keyname_len) {
9f328977
LC
2136 goto err_out;
2137 }
568c73a4 2138 keylist->value->type = KEY_VALUE_KIND_NUMBER;
32bafa8f 2139 keylist->value->u.number.data = value;
9f328977 2140 } else {
64ffbe04 2141 int idx = index_from_key(keys, keyname_len);
7fb1cf16 2142 if (idx == Q_KEY_CODE__MAX) {
9f328977
LC
2143 goto err_out;
2144 }
568c73a4 2145 keylist->value->type = KEY_VALUE_KIND_QCODE;
32bafa8f 2146 keylist->value->u.qcode.data = idx;
9f328977
LC
2147 }
2148
e4c8f004
AK
2149 if (!separator) {
2150 break;
2151 }
2152 keys = separator + 1;
2153 }
2154
9f328977 2155 qmp_send_key(head, has_hold_time, hold_time, &err);
e4c8f004 2156 hmp_handle_error(mon, &err);
9f328977
LC
2157
2158out:
2159 qapi_free_KeyValueList(head);
2160 return;
2161
2162err_out:
64ffbe04 2163 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
9f328977 2164 goto out;
e4c8f004 2165}
ad39cf6d 2166
3e5a50d6 2167void hmp_screendump(Monitor *mon, const QDict *qdict)
ad39cf6d
LC
2168{
2169 const char *filename = qdict_get_str(qdict, "filename");
f771c544
TH
2170 const char *id = qdict_get_try_str(qdict, "device");
2171 int64_t head = qdict_get_try_int(qdict, "head", 0);
ad39cf6d
LC
2172 Error *err = NULL;
2173
f771c544 2174 qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
ad39cf6d
LC
2175 hmp_handle_error(mon, &err);
2176}
4057725f
PB
2177
2178void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
2179{
2180 const char *uri = qdict_get_str(qdict, "uri");
34acbc95
EB
2181 bool writable = qdict_get_try_bool(qdict, "writable", false);
2182 bool all = qdict_get_try_bool(qdict, "all", false);
4057725f
PB
2183 Error *local_err = NULL;
2184 BlockInfoList *block_list, *info;
bd269ebc 2185 SocketAddress *addr;
4057725f
PB
2186
2187 if (writable && !all) {
2188 error_setg(&local_err, "-w only valid together with -a");
2189 goto exit;
2190 }
2191
2192 /* First check if the address is valid and start the server. */
2193 addr = socket_parse(uri, &local_err);
2194 if (local_err != NULL) {
2195 goto exit;
2196 }
2197
bd269ebc
MA
2198 nbd_server_start(addr, NULL, &local_err);
2199 qapi_free_SocketAddress(addr);
4057725f
PB
2200 if (local_err != NULL) {
2201 goto exit;
2202 }
2203
2204 if (!all) {
2205 return;
2206 }
2207
2208 /* Then try adding all block devices. If one fails, close all and
2209 * exit.
2210 */
2211 block_list = qmp_query_block(NULL);
2212
2213 for (info = block_list; info; info = info->next) {
2214 if (!info->value->has_inserted) {
2215 continue;
2216 }
2217
902a1f94
VSO
2218 qmp_nbd_server_add(info->value->device, false, NULL,
2219 true, writable, &local_err);
4057725f
PB
2220
2221 if (local_err != NULL) {
2222 qmp_nbd_server_stop(NULL);
2223 break;
2224 }
2225 }
2226
2227 qapi_free_BlockInfoList(block_list);
2228
2229exit:
2230 hmp_handle_error(mon, &local_err);
2231}
2232
2233void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
2234{
2235 const char *device = qdict_get_str(qdict, "device");
dba49323 2236 const char *name = qdict_get_try_str(qdict, "name");
34acbc95 2237 bool writable = qdict_get_try_bool(qdict, "writable", false);
4057725f
PB
2238 Error *local_err = NULL;
2239
dba49323 2240 qmp_nbd_server_add(device, !!name, name, true, writable, &local_err);
08fb10a7
EB
2241 hmp_handle_error(mon, &local_err);
2242}
4057725f 2243
08fb10a7
EB
2244void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict)
2245{
2246 const char *name = qdict_get_str(qdict, "name");
2247 bool force = qdict_get_try_bool(qdict, "force", false);
2248 Error *err = NULL;
2249
2250 /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
2251 qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err);
2252 hmp_handle_error(mon, &err);
4057725f
PB
2253}
2254
2255void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
2256{
e940f543 2257 Error *err = NULL;
4057725f 2258
e940f543
MA
2259 qmp_nbd_server_stop(&err);
2260 hmp_handle_error(mon, &err);
4057725f 2261}
f1088908 2262
abf23329
JH
2263void hmp_cpu_add(Monitor *mon, const QDict *qdict)
2264{
2265 int cpuid;
2266 Error *err = NULL;
2267
2268 cpuid = qdict_get_int(qdict, "id");
2269 qmp_cpu_add(cpuid, &err);
2270 hmp_handle_error(mon, &err);
2271}
2272
f1088908
GH
2273void hmp_chardev_add(Monitor *mon, const QDict *qdict)
2274{
2275 const char *args = qdict_get_str(qdict, "args");
2276 Error *err = NULL;
2277 QemuOpts *opts;
2278
70b94331 2279 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
f1088908 2280 if (opts == NULL) {
312fd5f2 2281 error_setg(&err, "Parsing chardev args failed");
f1088908 2282 } else {
b4948be9 2283 qemu_chr_new_from_opts(opts, &err);
0a73336d 2284 qemu_opts_del(opts);
f1088908
GH
2285 }
2286 hmp_handle_error(mon, &err);
2287}
2288
75b60160
AN
2289void hmp_chardev_change(Monitor *mon, const QDict *qdict)
2290{
2291 const char *args = qdict_get_str(qdict, "args");
2292 const char *id;
2293 Error *err = NULL;
2294 ChardevBackend *backend = NULL;
2295 ChardevReturn *ret = NULL;
2296 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
2297 true);
2298 if (!opts) {
2299 error_setg(&err, "Parsing chardev args failed");
2300 goto end;
2301 }
2302
2303 id = qdict_get_str(qdict, "id");
2304 if (qemu_opts_id(opts)) {
2305 error_setg(&err, "Unexpected 'id' parameter");
2306 goto end;
2307 }
2308
2309 backend = qemu_chr_parse_opts(opts, &err);
2310 if (!backend) {
2311 goto end;
2312 }
2313
2314 ret = qmp_chardev_change(id, backend, &err);
2315
2316end:
2317 qapi_free_ChardevReturn(ret);
2318 qapi_free_ChardevBackend(backend);
2319 qemu_opts_del(opts);
2320 hmp_handle_error(mon, &err);
2321}
2322
f1088908
GH
2323void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
2324{
2325 Error *local_err = NULL;
2326
2327 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
2328 hmp_handle_error(mon, &local_err);
2329}
587da2c3 2330
bd1d5ad9
SF
2331void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
2332{
2333 Error *local_err = NULL;
2334
2335 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
2336 hmp_handle_error(mon, &local_err);
2337}
2338
587da2c3
KW
2339void hmp_qemu_io(Monitor *mon, const QDict *qdict)
2340{
4c7b7e9b 2341 BlockBackend *blk;
e7f98f2f 2342 BlockBackend *local_blk = NULL;
587da2c3
KW
2343 const char* device = qdict_get_str(qdict, "device");
2344 const char* command = qdict_get_str(qdict, "command");
2345 Error *err = NULL;
d7086422 2346 int ret;
587da2c3 2347
4c7b7e9b 2348 blk = blk_by_name(device);
e7f98f2f
KW
2349 if (!blk) {
2350 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
2351 if (bs) {
6d0eb64d 2352 blk = local_blk = blk_new(0, BLK_PERM_ALL);
d7086422
KW
2353 ret = blk_insert_bs(blk, bs, &err);
2354 if (ret < 0) {
2355 goto fail;
2356 }
e7f98f2f
KW
2357 } else {
2358 goto fail;
2359 }
2360 }
2361
887354bd
KW
2362 /*
2363 * Notably absent: Proper permission management. This is sad, but it seems
2364 * almost impossible to achieve without changing the semantics and thereby
2365 * limiting the use cases of the qemu-io HMP command.
2366 *
2367 * In an ideal world we would unconditionally create a new BlockBackend for
2368 * qemuio_command(), but we have commands like 'reopen' and want them to
2369 * take effect on the exact BlockBackend whose name the user passed instead
2370 * of just on a temporary copy of it.
2371 *
2372 * Another problem is that deleting the temporary BlockBackend involves
2373 * draining all requests on it first, but some qemu-iotests cases want to
2374 * issue multiple aio_read/write requests and expect them to complete in
2375 * the background while the monitor has already returned.
2376 *
2377 * This is also what prevents us from saving the original permissions and
2378 * restoring them later: We can't revoke permissions until all requests
2379 * have completed, and we don't know when that is nor can we really let
2380 * anything else run before we have revoken them to avoid race conditions.
2381 *
2382 * What happens now is that command() in qemu-io-cmds.c can extend the
2383 * permissions if necessary for the qemu-io command. And they simply stay
2384 * extended, possibly resulting in a read-only guest device keeping write
2385 * permissions. Ugly, but it appears to be the lesser evil.
2386 */
1813d330 2387 qemuio_command(blk, command);
587da2c3 2388
e7f98f2f
KW
2389fail:
2390 blk_unref(local_blk);
587da2c3
KW
2391 hmp_handle_error(mon, &err);
2392}
ab2d0531
PB
2393
2394void hmp_object_del(Monitor *mon, const QDict *qdict)
2395{
2396 const char *id = qdict_get_str(qdict, "id");
2397 Error *err = NULL;
2398
90998d58 2399 user_creatable_del(id, &err);
ab2d0531
PB
2400 hmp_handle_error(mon, &err);
2401}
eb1539b2
HT
2402
2403void hmp_info_memdev(Monitor *mon, const QDict *qdict)
2404{
2405 Error *err = NULL;
2406 MemdevList *memdev_list = qmp_query_memdev(&err);
2407 MemdevList *m = memdev_list;
3b098d56 2408 Visitor *v;
976620ac 2409 char *str;
eb1539b2
HT
2410
2411 while (m) {
3b098d56
EB
2412 v = string_output_visitor_new(false, &str);
2413 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
e1ff3c67 2414 monitor_printf(mon, "memory backend: %s\n", m->value->id);
eb1539b2
HT
2415 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
2416 monitor_printf(mon, " merge: %s\n",
2417 m->value->merge ? "true" : "false");
2418 monitor_printf(mon, " dump: %s\n",
2419 m->value->dump ? "true" : "false");
2420 monitor_printf(mon, " prealloc: %s\n",
2421 m->value->prealloc ? "true" : "false");
2422 monitor_printf(mon, " policy: %s\n",
977c736f 2423 HostMemPolicy_str(m->value->policy));
3b098d56 2424 visit_complete(v, &str);
976620ac 2425 monitor_printf(mon, " host nodes: %s\n", str);
eb1539b2 2426
976620ac 2427 g_free(str);
3b098d56 2428 visit_free(v);
eb1539b2 2429 m = m->next;
eb1539b2
HT
2430 }
2431
2432 monitor_printf(mon, "\n");
ecaf54a0
CF
2433
2434 qapi_free_MemdevList(memdev_list);
40c71f63 2435 hmp_handle_error(mon, &err);
eb1539b2 2436}
a631892f
ZG
2437
2438void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2439{
2440 Error *err = NULL;
2441 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2442 MemoryDeviceInfoList *info;
2443 MemoryDeviceInfo *value;
2444 PCDIMMDeviceInfo *di;
2445
2446 for (info = info_list; info; info = info->next) {
2447 value = info->value;
2448
2449 if (value) {
1fd5d4fe 2450 switch (value->type) {
a631892f 2451 case MEMORY_DEVICE_INFO_KIND_DIMM:
32bafa8f 2452 di = value->u.dimm.data;
6388e18d
HZ
2453 break;
2454
2455 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
2456 di = value->u.nvdimm.data;
2457 break;
2458
2459 default:
2460 di = NULL;
2461 break;
2462 }
a631892f 2463
6388e18d 2464 if (di) {
a631892f 2465 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
977c736f 2466 MemoryDeviceInfoKind_str(value->type),
a631892f
ZG
2467 di->id ? di->id : "");
2468 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2469 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2470 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2471 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2472 monitor_printf(mon, " memdev: %s\n", di->memdev);
2473 monitor_printf(mon, " hotplugged: %s\n",
2474 di->hotplugged ? "true" : "false");
2475 monitor_printf(mon, " hotpluggable: %s\n",
2476 di->hotpluggable ? "true" : "false");
a631892f
ZG
2477 }
2478 }
2479 }
2480
2481 qapi_free_MemoryDeviceInfoList(info_list);
40c71f63 2482 hmp_handle_error(mon, &err);
a631892f 2483}
89d7fa9e 2484
62313160
TW
2485void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2486{
2487 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2488 IOThreadInfoList *info;
5fc00480 2489 IOThreadInfo *value;
62313160
TW
2490
2491 for (info = info_list; info; info = info->next) {
5fc00480
PH
2492 value = info->value;
2493 monitor_printf(mon, "%s:\n", value->id);
2494 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
2495 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
2496 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
2497 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
62313160
TW
2498 }
2499
2500 qapi_free_IOThreadInfoList(info_list);
2501}
2502
89d7fa9e
AF
2503void hmp_qom_list(Monitor *mon, const QDict *qdict)
2504{
2505 const char *path = qdict_get_try_str(qdict, "path");
2506 ObjectPropertyInfoList *list;
2507 Error *err = NULL;
2508
2509 if (path == NULL) {
2510 monitor_printf(mon, "/\n");
2511 return;
2512 }
2513
2514 list = qmp_qom_list(path, &err);
2515 if (err == NULL) {
2516 ObjectPropertyInfoList *start = list;
2517 while (list != NULL) {
2518 ObjectPropertyInfo *value = list->value;
2519
2520 monitor_printf(mon, "%s (%s)\n",
2521 value->name, value->type);
2522 list = list->next;
2523 }
2524 qapi_free_ObjectPropertyInfoList(start);
2525 }
2526 hmp_handle_error(mon, &err);
2527}
c0e6ee9e
AF
2528
2529void hmp_qom_set(Monitor *mon, const QDict *qdict)
2530{
2531 const char *path = qdict_get_str(qdict, "path");
2532 const char *property = qdict_get_str(qdict, "property");
2533 const char *value = qdict_get_str(qdict, "value");
2534 Error *err = NULL;
2535 bool ambiguous = false;
2536 Object *obj;
2537
2538 obj = object_resolve_path(path, &ambiguous);
2539 if (obj == NULL) {
75158ebb
MA
2540 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2541 "Device '%s' not found", path);
c0e6ee9e
AF
2542 } else {
2543 if (ambiguous) {
2544 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2545 }
2546 object_property_parse(obj, value, property, &err);
2547 }
2548 hmp_handle_error(mon, &err);
2549}
fafa4d50
SF
2550
2551void hmp_rocker(Monitor *mon, const QDict *qdict)
2552{
2553 const char *name = qdict_get_str(qdict, "name");
2554 RockerSwitch *rocker;
533fdaed 2555 Error *err = NULL;
fafa4d50 2556
533fdaed
MA
2557 rocker = qmp_query_rocker(name, &err);
2558 if (err != NULL) {
2559 hmp_handle_error(mon, &err);
fafa4d50
SF
2560 return;
2561 }
2562
2563 monitor_printf(mon, "name: %s\n", rocker->name);
2564 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2565 monitor_printf(mon, "ports: %d\n", rocker->ports);
2566
2567 qapi_free_RockerSwitch(rocker);
2568}
2569
2570void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2571{
2572 RockerPortList *list, *port;
2573 const char *name = qdict_get_str(qdict, "name");
533fdaed 2574 Error *err = NULL;
fafa4d50 2575
533fdaed
MA
2576 list = qmp_query_rocker_ports(name, &err);
2577 if (err != NULL) {
2578 hmp_handle_error(mon, &err);
fafa4d50
SF
2579 return;
2580 }
2581
2582 monitor_printf(mon, " ena/ speed/ auto\n");
2583 monitor_printf(mon, " port link duplex neg?\n");
2584
2585 for (port = list; port; port = port->next) {
2586 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2587 port->value->name,
2588 port->value->enabled ? port->value->link_up ?
2589 "up" : "down" : "!ena",
2590 port->value->speed == 10000 ? "10G" : "??",
2591 port->value->duplex ? "FD" : "HD",
2592 port->value->autoneg ? "Yes" : "No");
2593 }
2594
2595 qapi_free_RockerPortList(list);
2596}
2597
2598void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2599{
2600 RockerOfDpaFlowList *list, *info;
2601 const char *name = qdict_get_str(qdict, "name");
2602 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
533fdaed 2603 Error *err = NULL;
fafa4d50 2604
533fdaed
MA
2605 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2606 if (err != NULL) {
2607 hmp_handle_error(mon, &err);
fafa4d50
SF
2608 return;
2609 }
2610
2611 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2612
2613 for (info = list; info; info = info->next) {
2614 RockerOfDpaFlow *flow = info->value;
2615 RockerOfDpaFlowKey *key = flow->key;
2616 RockerOfDpaFlowMask *mask = flow->mask;
2617 RockerOfDpaFlowAction *action = flow->action;
2618
2619 if (flow->hits) {
2620 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2621 key->priority, key->tbl_id, flow->hits);
2622 } else {
2623 monitor_printf(mon, "%-4d %-3d ",
2624 key->priority, key->tbl_id);
2625 }
2626
2627 if (key->has_in_pport) {
2628 monitor_printf(mon, " pport %d", key->in_pport);
2629 if (mask->has_in_pport) {
2630 monitor_printf(mon, "(0x%x)", mask->in_pport);
2631 }
2632 }
2633
2634 if (key->has_vlan_id) {
2635 monitor_printf(mon, " vlan %d",
2636 key->vlan_id & VLAN_VID_MASK);
2637 if (mask->has_vlan_id) {
2638 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2639 }
2640 }
2641
2642 if (key->has_tunnel_id) {
2643 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2644 if (mask->has_tunnel_id) {
2645 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2646 }
2647 }
2648
2649 if (key->has_eth_type) {
2650 switch (key->eth_type) {
2651 case 0x0806:
2652 monitor_printf(mon, " ARP");
2653 break;
2654 case 0x0800:
2655 monitor_printf(mon, " IP");
2656 break;
2657 case 0x86dd:
2658 monitor_printf(mon, " IPv6");
2659 break;
2660 case 0x8809:
2661 monitor_printf(mon, " LACP");
2662 break;
2663 case 0x88cc:
2664 monitor_printf(mon, " LLDP");
2665 break;
2666 default:
2667 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2668 break;
2669 }
2670 }
2671
2672 if (key->has_eth_src) {
2673 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2674 (mask->has_eth_src) &&
2675 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2676 monitor_printf(mon, " src <any mcast/bcast>");
2677 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2678 (mask->has_eth_src) &&
2679 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2680 monitor_printf(mon, " src <any ucast>");
2681 } else {
2682 monitor_printf(mon, " src %s", key->eth_src);
2683 if (mask->has_eth_src) {
2684 monitor_printf(mon, "(%s)", mask->eth_src);
2685 }
2686 }
2687 }
2688
2689 if (key->has_eth_dst) {
2690 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2691 (mask->has_eth_dst) &&
2692 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2693 monitor_printf(mon, " dst <any mcast/bcast>");
2694 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2695 (mask->has_eth_dst) &&
2696 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2697 monitor_printf(mon, " dst <any ucast>");
2698 } else {
2699 monitor_printf(mon, " dst %s", key->eth_dst);
2700 if (mask->has_eth_dst) {
2701 monitor_printf(mon, "(%s)", mask->eth_dst);
2702 }
2703 }
2704 }
2705
2706 if (key->has_ip_proto) {
2707 monitor_printf(mon, " proto %d", key->ip_proto);
2708 if (mask->has_ip_proto) {
2709 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2710 }
2711 }
2712
2713 if (key->has_ip_tos) {
2714 monitor_printf(mon, " TOS %d", key->ip_tos);
2715 if (mask->has_ip_tos) {
2716 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2717 }
2718 }
2719
2720 if (key->has_ip_dst) {
2721 monitor_printf(mon, " dst %s", key->ip_dst);
2722 }
2723
2724 if (action->has_goto_tbl || action->has_group_id ||
2725 action->has_new_vlan_id) {
2726 monitor_printf(mon, " -->");
2727 }
2728
2729 if (action->has_new_vlan_id) {
2730 monitor_printf(mon, " apply new vlan %d",
2731 ntohs(action->new_vlan_id));
2732 }
2733
2734 if (action->has_group_id) {
2735 monitor_printf(mon, " write group 0x%08x", action->group_id);
2736 }
2737
2738 if (action->has_goto_tbl) {
2739 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2740 }
2741
2742 monitor_printf(mon, "\n");
2743 }
2744
2745 qapi_free_RockerOfDpaFlowList(list);
2746}
2747
2748void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2749{
2750 RockerOfDpaGroupList *list, *g;
2751 const char *name = qdict_get_str(qdict, "name");
2752 uint8_t type = qdict_get_try_int(qdict, "type", 9);
533fdaed 2753 Error *err = NULL;
fafa4d50
SF
2754 bool set = false;
2755
533fdaed
MA
2756 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2757 if (err != NULL) {
2758 hmp_handle_error(mon, &err);
fafa4d50
SF
2759 return;
2760 }
2761
2762 monitor_printf(mon, "id (decode) --> buckets\n");
2763
2764 for (g = list; g; g = g->next) {
2765 RockerOfDpaGroup *group = g->value;
2766
2767 monitor_printf(mon, "0x%08x", group->id);
2768
2769 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2770 group->type == 1 ? "L2 rewrite" :
2771 group->type == 2 ? "L3 unicast" :
2772 group->type == 3 ? "L2 multicast" :
2773 group->type == 4 ? "L2 flood" :
2774 group->type == 5 ? "L3 interface" :
2775 group->type == 6 ? "L3 multicast" :
2776 group->type == 7 ? "L3 ECMP" :
2777 group->type == 8 ? "L2 overlay" :
2778 "unknown");
2779
2780 if (group->has_vlan_id) {
2781 monitor_printf(mon, " vlan %d", group->vlan_id);
2782 }
2783
2784 if (group->has_pport) {
2785 monitor_printf(mon, " pport %d", group->pport);
2786 }
2787
2788 if (group->has_index) {
2789 monitor_printf(mon, " index %d", group->index);
2790 }
2791
2792 monitor_printf(mon, ") -->");
2793
2794 if (group->has_set_vlan_id && group->set_vlan_id) {
2795 set = true;
2796 monitor_printf(mon, " set vlan %d",
2797 group->set_vlan_id & VLAN_VID_MASK);
2798 }
2799
2800 if (group->has_set_eth_src) {
2801 if (!set) {
2802 set = true;
2803 monitor_printf(mon, " set");
2804 }
2805 monitor_printf(mon, " src %s", group->set_eth_src);
2806 }
2807
2808 if (group->has_set_eth_dst) {
2809 if (!set) {
2810 set = true;
2811 monitor_printf(mon, " set");
2812 }
2813 monitor_printf(mon, " dst %s", group->set_eth_dst);
2814 }
2815
2816 set = false;
2817
2818 if (group->has_ttl_check && group->ttl_check) {
2819 monitor_printf(mon, " check TTL");
2820 }
2821
2822 if (group->has_group_id && group->group_id) {
2823 monitor_printf(mon, " group id 0x%08x", group->group_id);
2824 }
2825
2826 if (group->has_pop_vlan && group->pop_vlan) {
2827 monitor_printf(mon, " pop vlan");
2828 }
2829
2830 if (group->has_out_pport) {
2831 monitor_printf(mon, " out pport %d", group->out_pport);
2832 }
2833
2834 if (group->has_group_ids) {
2835 struct uint32List *id;
2836
2837 monitor_printf(mon, " groups [");
2838 for (id = group->group_ids; id; id = id->next) {
2839 monitor_printf(mon, "0x%08x", id->value);
2840 if (id->next) {
2841 monitor_printf(mon, ",");
2842 }
2843 }
2844 monitor_printf(mon, "]");
2845 }
2846
2847 monitor_printf(mon, "\n");
2848 }
2849
2850 qapi_free_RockerOfDpaGroupList(list);
2851}
4a6b52d6
PX
2852
2853void hmp_info_dump(Monitor *mon, const QDict *qdict)
2854{
2855 DumpQueryResult *result = qmp_query_dump(NULL);
2856
2857 assert(result && result->status < DUMP_STATUS__MAX);
977c736f 2858 monitor_printf(mon, "Status: %s\n", DumpStatus_str(result->status));
4a6b52d6
PX
2859
2860 if (result->status == DUMP_STATUS_ACTIVE) {
2861 float percent = 0;
2862 assert(result->total != 0);
2863 percent = 100.0 * result->completed / result->total;
2864 monitor_printf(mon, "Finished: %.2f %%\n", percent);
2865 }
2866
2867 qapi_free_DumpQueryResult(result);
2868}
d2d8d46f 2869
be9b23c4
PX
2870void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
2871{
2872 ram_block_dump(mon);
2873}
2874
d2d8d46f
BR
2875void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
2876{
2877 Error *err = NULL;
2878 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
2879 HotpluggableCPUList *saved = l;
2880 CpuInstanceProperties *c;
2881
2882 if (err != NULL) {
2883 hmp_handle_error(mon, &err);
2884 return;
2885 }
2886
2887 monitor_printf(mon, "Hotpluggable CPUs:\n");
2888 while (l) {
2889 monitor_printf(mon, " type: \"%s\"\n", l->value->type);
2890 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
2891 l->value->vcpus_count);
2892 if (l->value->has_qom_path) {
2893 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
2894 }
2895
2896 c = l->value->props;
2897 monitor_printf(mon, " CPUInstance Properties:\n");
27393c33
PK
2898 if (c->has_node_id) {
2899 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
d2d8d46f 2900 }
27393c33
PK
2901 if (c->has_socket_id) {
2902 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
d2d8d46f 2903 }
27393c33
PK
2904 if (c->has_core_id) {
2905 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
d2d8d46f 2906 }
27393c33
PK
2907 if (c->has_thread_id) {
2908 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
d2d8d46f
BR
2909 }
2910
2911 l = l->next;
2912 }
2913
2914 qapi_free_HotpluggableCPUList(saved);
2915}
39164c13
IM
2916
2917void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
2918{
72d9196f
BW
2919 Error *err = NULL;
2920 GuidInfo *info = qmp_query_vm_generation_id(&err);
39164c13
IM
2921 if (info) {
2922 monitor_printf(mon, "%s\n", info->guid);
2923 }
72d9196f 2924 hmp_handle_error(mon, &err);
39164c13
IM
2925 qapi_free_GuidInfo(info);
2926}
d0f63c1e
VG
2927
2928void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
2929{
2930 Error *err = NULL;
2931 MemoryInfo *info = qmp_query_memory_size_summary(&err);
2932 if (info) {
2933 monitor_printf(mon, "base memory: %" PRIu64 "\n",
2934 info->base_memory);
2935
2936 if (info->has_plugged_memory) {
2937 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
2938 info->plugged_memory);
2939 }
2940
2941 qapi_free_MemoryInfo(info);
2942 }
2943 hmp_handle_error(mon, &err);
2944}