fix spelling in linux-user sub directory
[qemu.git] / hmp.c
blob443d3a7ff44f737ef5f91879e70e252accef7e8e
1 /*
2 * Human Monitor Interface
4 * Copyright IBM, Corp. 2011
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
14 #include "hmp.h"
15 #include "qmp-commands.h"
17 void hmp_info_name(Monitor *mon)
19 NameInfo *info;
21 info = qmp_query_name(NULL);
22 if (info->has_name) {
23 monitor_printf(mon, "%s\n", info->name);
25 qapi_free_NameInfo(info);
28 void hmp_info_version(Monitor *mon)
30 VersionInfo *info;
32 info = qmp_query_version(NULL);
34 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
35 info->qemu.major, info->qemu.minor, info->qemu.micro,
36 info->package);
38 qapi_free_VersionInfo(info);
41 void hmp_info_kvm(Monitor *mon)
43 KvmInfo *info;
45 info = qmp_query_kvm(NULL);
46 monitor_printf(mon, "kvm support: ");
47 if (info->present) {
48 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
49 } else {
50 monitor_printf(mon, "not compiled\n");
53 qapi_free_KvmInfo(info);
56 void hmp_info_status(Monitor *mon)
58 StatusInfo *info;
60 info = qmp_query_status(NULL);
62 monitor_printf(mon, "VM status: %s%s",
63 info->running ? "running" : "paused",
64 info->singlestep ? " (single step mode)" : "");
66 if (!info->running && info->status != RUN_STATE_PAUSED) {
67 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
70 monitor_printf(mon, "\n");
72 qapi_free_StatusInfo(info);
75 void hmp_info_uuid(Monitor *mon)
77 UuidInfo *info;
79 info = qmp_query_uuid(NULL);
80 monitor_printf(mon, "%s\n", info->UUID);
81 qapi_free_UuidInfo(info);
84 void hmp_info_chardev(Monitor *mon)
86 ChardevInfoList *char_info, *info;
88 char_info = qmp_query_chardev(NULL);
89 for (info = char_info; info; info = info->next) {
90 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
91 info->value->filename);
94 qapi_free_ChardevInfoList(char_info);
97 void hmp_info_mice(Monitor *mon)
99 MouseInfoList *mice_list, *mouse;
101 mice_list = qmp_query_mice(NULL);
102 if (!mice_list) {
103 monitor_printf(mon, "No mouse devices connected\n");
104 return;
107 for (mouse = mice_list; mouse; mouse = mouse->next) {
108 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
109 mouse->value->current ? '*' : ' ',
110 mouse->value->index, mouse->value->name,
111 mouse->value->absolute ? " (absolute)" : "");
114 qapi_free_MouseInfoList(mice_list);
117 void hmp_info_migrate(Monitor *mon)
119 MigrationInfo *info;
121 info = qmp_query_migrate(NULL);
123 if (info->has_status) {
124 monitor_printf(mon, "Migration status: %s\n", info->status);
127 if (info->has_ram) {
128 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
129 info->ram->transferred >> 10);
130 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
131 info->ram->remaining >> 10);
132 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
133 info->ram->total >> 10);
136 if (info->has_disk) {
137 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
138 info->disk->transferred >> 10);
139 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
140 info->disk->remaining >> 10);
141 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
142 info->disk->total >> 10);
145 qapi_free_MigrationInfo(info);
148 void hmp_info_cpus(Monitor *mon)
150 CpuInfoList *cpu_list, *cpu;
152 cpu_list = qmp_query_cpus(NULL);
154 for (cpu = cpu_list; cpu; cpu = cpu->next) {
155 int active = ' ';
157 if (cpu->value->CPU == monitor_get_cpu_index()) {
158 active = '*';
161 monitor_printf(mon, "%c CPU #%" PRId64 ": ", active, cpu->value->CPU);
163 if (cpu->value->has_pc) {
164 monitor_printf(mon, "pc=0x%016" PRIx64, cpu->value->pc);
166 if (cpu->value->has_nip) {
167 monitor_printf(mon, "nip=0x%016" PRIx64, cpu->value->nip);
169 if (cpu->value->has_npc) {
170 monitor_printf(mon, "pc=0x%016" PRIx64, cpu->value->pc);
171 monitor_printf(mon, "npc=0x%016" PRIx64, cpu->value->npc);
173 if (cpu->value->has_PC) {
174 monitor_printf(mon, "PC=0x%016" PRIx64, cpu->value->PC);
177 if (cpu->value->halted) {
178 monitor_printf(mon, " (halted)");
181 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
184 qapi_free_CpuInfoList(cpu_list);
187 void hmp_info_block(Monitor *mon)
189 BlockInfoList *block_list, *info;
191 block_list = qmp_query_block(NULL);
193 for (info = block_list; info; info = info->next) {
194 monitor_printf(mon, "%s: removable=%d",
195 info->value->device, info->value->removable);
197 if (info->value->removable) {
198 monitor_printf(mon, " locked=%d", info->value->locked);
199 monitor_printf(mon, " tray-open=%d", info->value->tray_open);
202 if (info->value->has_io_status) {
203 monitor_printf(mon, " io-status=%s",
204 BlockDeviceIoStatus_lookup[info->value->io_status]);
207 if (info->value->has_inserted) {
208 monitor_printf(mon, " file=");
209 monitor_print_filename(mon, info->value->inserted->file);
211 if (info->value->inserted->has_backing_file) {
212 monitor_printf(mon, " backing_file=");
213 monitor_print_filename(mon, info->value->inserted->backing_file);
215 monitor_printf(mon, " ro=%d drv=%s encrypted=%d",
216 info->value->inserted->ro,
217 info->value->inserted->drv,
218 info->value->inserted->encrypted);
219 } else {
220 monitor_printf(mon, " [not inserted]");
223 monitor_printf(mon, "\n");
226 qapi_free_BlockInfoList(block_list);
229 void hmp_info_blockstats(Monitor *mon)
231 BlockStatsList *stats_list, *stats;
233 stats_list = qmp_query_blockstats(NULL);
235 for (stats = stats_list; stats; stats = stats->next) {
236 if (!stats->value->has_device) {
237 continue;
240 monitor_printf(mon, "%s:", stats->value->device);
241 monitor_printf(mon, " rd_bytes=%" PRId64
242 " wr_bytes=%" PRId64
243 " rd_operations=%" PRId64
244 " wr_operations=%" PRId64
245 " flush_operations=%" PRId64
246 " wr_total_time_ns=%" PRId64
247 " rd_total_time_ns=%" PRId64
248 " flush_total_time_ns=%" PRId64
249 "\n",
250 stats->value->stats->rd_bytes,
251 stats->value->stats->wr_bytes,
252 stats->value->stats->rd_operations,
253 stats->value->stats->wr_operations,
254 stats->value->stats->flush_operations,
255 stats->value->stats->wr_total_time_ns,
256 stats->value->stats->rd_total_time_ns,
257 stats->value->stats->flush_total_time_ns);
260 qapi_free_BlockStatsList(stats_list);
263 void hmp_info_vnc(Monitor *mon)
265 VncInfo *info;
266 Error *err = NULL;
267 VncClientInfoList *client;
269 info = qmp_query_vnc(&err);
270 if (err) {
271 monitor_printf(mon, "%s\n", error_get_pretty(err));
272 error_free(err);
273 return;
276 if (!info->enabled) {
277 monitor_printf(mon, "Server: disabled\n");
278 goto out;
281 monitor_printf(mon, "Server:\n");
282 if (info->has_host && info->has_service) {
283 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
285 if (info->has_auth) {
286 monitor_printf(mon, " auth: %s\n", info->auth);
289 if (!info->has_clients || info->clients == NULL) {
290 monitor_printf(mon, "Client: none\n");
291 } else {
292 for (client = info->clients; client; client = client->next) {
293 monitor_printf(mon, "Client:\n");
294 monitor_printf(mon, " address: %s:%s\n",
295 client->value->host, client->value->service);
296 monitor_printf(mon, " x509_dname: %s\n",
297 client->value->x509_dname ?
298 client->value->x509_dname : "none");
299 monitor_printf(mon, " username: %s\n",
300 client->value->has_sasl_username ?
301 client->value->sasl_username : "none");
305 out:
306 qapi_free_VncInfo(info);
309 void hmp_info_spice(Monitor *mon)
311 SpiceChannelList *chan;
312 SpiceInfo *info;
314 info = qmp_query_spice(NULL);
316 if (!info->enabled) {
317 monitor_printf(mon, "Server: disabled\n");
318 goto out;
321 monitor_printf(mon, "Server:\n");
322 if (info->has_port) {
323 monitor_printf(mon, " address: %s:%" PRId64 "\n",
324 info->host, info->port);
326 if (info->has_tls_port) {
327 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
328 info->host, info->tls_port);
330 monitor_printf(mon, " auth: %s\n", info->auth);
331 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
333 if (!info->has_channels || info->channels == NULL) {
334 monitor_printf(mon, "Channels: none\n");
335 } else {
336 for (chan = info->channels; chan; chan = chan->next) {
337 monitor_printf(mon, "Channel:\n");
338 monitor_printf(mon, " address: %s:%s%s\n",
339 chan->value->host, chan->value->port,
340 chan->value->tls ? " [tls]" : "");
341 monitor_printf(mon, " session: %" PRId64 "\n",
342 chan->value->connection_id);
343 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
344 chan->value->channel_type, chan->value->channel_id);
348 out:
349 qapi_free_SpiceInfo(info);
352 void hmp_info_balloon(Monitor *mon)
354 BalloonInfo *info;
355 Error *err = NULL;
357 info = qmp_query_balloon(&err);
358 if (err) {
359 monitor_printf(mon, "%s\n", error_get_pretty(err));
360 error_free(err);
361 return;
364 monitor_printf(mon, "balloon: actual=%" PRId64, info->actual >> 20);
365 if (info->has_mem_swapped_in) {
366 monitor_printf(mon, " mem_swapped_in=%" PRId64, info->mem_swapped_in);
368 if (info->has_mem_swapped_out) {
369 monitor_printf(mon, " mem_swapped_out=%" PRId64, info->mem_swapped_out);
371 if (info->has_major_page_faults) {
372 monitor_printf(mon, " major_page_faults=%" PRId64,
373 info->major_page_faults);
375 if (info->has_minor_page_faults) {
376 monitor_printf(mon, " minor_page_faults=%" PRId64,
377 info->minor_page_faults);
379 if (info->has_free_mem) {
380 monitor_printf(mon, " free_mem=%" PRId64, info->free_mem);
382 if (info->has_total_mem) {
383 monitor_printf(mon, " total_mem=%" PRId64, info->total_mem);
386 monitor_printf(mon, "\n");
388 qapi_free_BalloonInfo(info);
391 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
393 PciMemoryRegionList *region;
395 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
396 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
397 dev->slot, dev->function);
398 monitor_printf(mon, " ");
400 if (dev->class_info.has_desc) {
401 monitor_printf(mon, "%s", dev->class_info.desc);
402 } else {
403 monitor_printf(mon, "Class %04" PRId64, dev->class_info.class);
406 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
407 dev->id.vendor, dev->id.device);
409 if (dev->has_irq) {
410 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
413 if (dev->has_pci_bridge) {
414 monitor_printf(mon, " BUS %" PRId64 ".\n",
415 dev->pci_bridge->bus.number);
416 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
417 dev->pci_bridge->bus.secondary);
418 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
419 dev->pci_bridge->bus.subordinate);
421 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
422 dev->pci_bridge->bus.io_range->base,
423 dev->pci_bridge->bus.io_range->limit);
425 monitor_printf(mon,
426 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
427 dev->pci_bridge->bus.memory_range->base,
428 dev->pci_bridge->bus.memory_range->limit);
430 monitor_printf(mon, " prefetchable memory range "
431 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
432 dev->pci_bridge->bus.prefetchable_range->base,
433 dev->pci_bridge->bus.prefetchable_range->limit);
436 for (region = dev->regions; region; region = region->next) {
437 uint64_t addr, size;
439 addr = region->value->address;
440 size = region->value->size;
442 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
444 if (!strcmp(region->value->type, "io")) {
445 monitor_printf(mon, "I/O at 0x%04" PRIx64
446 " [0x%04" PRIx64 "].\n",
447 addr, addr + size - 1);
448 } else {
449 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
450 " [0x%08" PRIx64 "].\n",
451 region->value->mem_type_64 ? 64 : 32,
452 region->value->prefetch ? " prefetchable" : "",
453 addr, addr + size - 1);
457 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
459 if (dev->has_pci_bridge) {
460 if (dev->pci_bridge->has_devices) {
461 PciDeviceInfoList *cdev;
462 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
463 hmp_info_pci_device(mon, cdev->value);
469 void hmp_info_pci(Monitor *mon)
471 PciInfoList *info;
472 Error *err = NULL;
474 info = qmp_query_pci(&err);
475 if (err) {
476 monitor_printf(mon, "PCI devices not supported\n");
477 error_free(err);
478 return;
481 for (; info; info = info->next) {
482 PciDeviceInfoList *dev;
484 for (dev = info->value->devices; dev; dev = dev->next) {
485 hmp_info_pci_device(mon, dev->value);
489 qapi_free_PciInfoList(info);
492 void hmp_quit(Monitor *mon, const QDict *qdict)
494 monitor_suspend(mon);
495 qmp_quit(NULL);
498 void hmp_stop(Monitor *mon, const QDict *qdict)
500 qmp_stop(NULL);
503 void hmp_system_reset(Monitor *mon, const QDict *qdict)
505 qmp_system_reset(NULL);
508 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
510 qmp_system_powerdown(NULL);
513 void hmp_cpu(Monitor *mon, const QDict *qdict)
515 int64_t cpu_index;
517 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
518 use it are converted to the QAPI */
519 cpu_index = qdict_get_int(qdict, "index");
520 if (monitor_set_cpu(cpu_index) < 0) {
521 monitor_printf(mon, "invalid CPU index\n");