Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 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 | * |
| 12 | */ |
| 13 | |
| 14 | #include "hmp.h" |
| 15 | #include "qmp-commands.h" |
| 16 | |
| 17 | void hmp_info_name(Monitor *mon) |
| 18 | { |
| 19 | NameInfo *info; |
| 20 | |
| 21 | info = qmp_query_name(NULL); |
| 22 | if (info->has_name) { |
| 23 | monitor_printf(mon, "%s\n", info->name); |
| 24 | } |
| 25 | qapi_free_NameInfo(info); |
| 26 | } |
Luiz Capitulino | b9c15f1 | 2011-08-26 17:38:13 -0300 | [diff] [blame] | 27 | |
| 28 | void hmp_info_version(Monitor *mon) |
| 29 | { |
| 30 | VersionInfo *info; |
| 31 | |
| 32 | info = qmp_query_version(NULL); |
| 33 | |
| 34 | monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n", |
| 35 | info->qemu.major, info->qemu.minor, info->qemu.micro, |
| 36 | info->package); |
| 37 | |
| 38 | qapi_free_VersionInfo(info); |
| 39 | } |
Luiz Capitulino | 292a260 | 2011-09-12 15:10:53 -0300 | [diff] [blame] | 40 | |
| 41 | void hmp_info_kvm(Monitor *mon) |
| 42 | { |
| 43 | KvmInfo *info; |
| 44 | |
| 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"); |
| 51 | } |
| 52 | |
| 53 | qapi_free_KvmInfo(info); |
| 54 | } |
| 55 | |
Luiz Capitulino | 1fa9a5e | 2011-09-12 17:54:20 -0300 | [diff] [blame] | 56 | void hmp_info_status(Monitor *mon) |
| 57 | { |
| 58 | StatusInfo *info; |
| 59 | |
| 60 | info = qmp_query_status(NULL); |
| 61 | |
| 62 | monitor_printf(mon, "VM status: %s%s", |
| 63 | info->running ? "running" : "paused", |
| 64 | info->singlestep ? " (single step mode)" : ""); |
| 65 | |
| 66 | if (!info->running && info->status != RUN_STATE_PAUSED) { |
| 67 | monitor_printf(mon, " (%s)", RunState_lookup[info->status]); |
| 68 | } |
| 69 | |
| 70 | monitor_printf(mon, "\n"); |
| 71 | |
| 72 | qapi_free_StatusInfo(info); |
| 73 | } |
| 74 | |
Luiz Capitulino | efab767 | 2011-09-13 17:16:25 -0300 | [diff] [blame] | 75 | void hmp_info_uuid(Monitor *mon) |
| 76 | { |
| 77 | UuidInfo *info; |
| 78 | |
| 79 | info = qmp_query_uuid(NULL); |
| 80 | monitor_printf(mon, "%s\n", info->UUID); |
| 81 | qapi_free_UuidInfo(info); |
| 82 | } |
Luiz Capitulino | c5a415a | 2011-09-14 16:05:49 -0300 | [diff] [blame] | 83 | |
| 84 | void hmp_info_chardev(Monitor *mon) |
| 85 | { |
| 86 | ChardevInfoList *char_info, *info; |
| 87 | |
| 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); |
| 92 | } |
| 93 | |
| 94 | qapi_free_ChardevInfoList(char_info); |
| 95 | } |
Luiz Capitulino | 7a7f325 | 2011-09-15 14:20:28 -0300 | [diff] [blame] | 96 | |
Luiz Capitulino | e235cec | 2011-09-21 15:29:55 -0300 | [diff] [blame] | 97 | void hmp_info_mice(Monitor *mon) |
| 98 | { |
| 99 | MouseInfoList *mice_list, *mouse; |
| 100 | |
| 101 | mice_list = qmp_query_mice(NULL); |
| 102 | if (!mice_list) { |
| 103 | monitor_printf(mon, "No mouse devices connected\n"); |
| 104 | return; |
| 105 | } |
| 106 | |
| 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)" : ""); |
| 112 | } |
| 113 | |
| 114 | qapi_free_MouseInfoList(mice_list); |
| 115 | } |
| 116 | |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 117 | void hmp_info_migrate(Monitor *mon) |
| 118 | { |
| 119 | MigrationInfo *info; |
| 120 | |
| 121 | info = qmp_query_migrate(NULL); |
| 122 | |
| 123 | if (info->has_status) { |
| 124 | monitor_printf(mon, "Migration status: %s\n", info->status); |
| 125 | } |
| 126 | |
| 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); |
| 134 | } |
| 135 | |
| 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); |
| 143 | } |
| 144 | |
| 145 | qapi_free_MigrationInfo(info); |
| 146 | } |
| 147 | |
Luiz Capitulino | de0b36b | 2011-09-21 16:38:35 -0300 | [diff] [blame] | 148 | void hmp_info_cpus(Monitor *mon) |
| 149 | { |
| 150 | CpuInfoList *cpu_list, *cpu; |
| 151 | |
| 152 | cpu_list = qmp_query_cpus(NULL); |
| 153 | |
| 154 | for (cpu = cpu_list; cpu; cpu = cpu->next) { |
| 155 | int active = ' '; |
| 156 | |
| 157 | if (cpu->value->CPU == monitor_get_cpu_index()) { |
| 158 | active = '*'; |
| 159 | } |
| 160 | |
| 161 | monitor_printf(mon, "%c CPU #%" PRId64 ": ", active, cpu->value->CPU); |
| 162 | |
| 163 | if (cpu->value->has_pc) { |
| 164 | monitor_printf(mon, "pc=0x%016" PRIx64, cpu->value->pc); |
| 165 | } |
| 166 | if (cpu->value->has_nip) { |
| 167 | monitor_printf(mon, "nip=0x%016" PRIx64, cpu->value->nip); |
| 168 | } |
| 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); |
| 172 | } |
| 173 | if (cpu->value->has_PC) { |
| 174 | monitor_printf(mon, "PC=0x%016" PRIx64, cpu->value->PC); |
| 175 | } |
| 176 | |
| 177 | if (cpu->value->halted) { |
| 178 | monitor_printf(mon, " (halted)"); |
| 179 | } |
| 180 | |
| 181 | monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id); |
| 182 | } |
| 183 | |
| 184 | qapi_free_CpuInfoList(cpu_list); |
| 185 | } |
| 186 | |
Luiz Capitulino | b202381 | 2011-09-21 17:16:47 -0300 | [diff] [blame] | 187 | void hmp_info_block(Monitor *mon) |
| 188 | { |
| 189 | BlockInfoList *block_list, *info; |
| 190 | |
| 191 | block_list = qmp_query_block(NULL); |
| 192 | |
| 193 | for (info = block_list; info; info = info->next) { |
| 194 | monitor_printf(mon, "%s: removable=%d", |
| 195 | info->value->device, info->value->removable); |
| 196 | |
| 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); |
| 200 | } |
| 201 | |
| 202 | if (info->value->has_io_status) { |
| 203 | monitor_printf(mon, " io-status=%s", |
| 204 | BlockDeviceIoStatus_lookup[info->value->io_status]); |
| 205 | } |
| 206 | |
| 207 | if (info->value->has_inserted) { |
| 208 | monitor_printf(mon, " file="); |
| 209 | monitor_print_filename(mon, info->value->inserted->file); |
| 210 | |
| 211 | if (info->value->inserted->has_backing_file) { |
| 212 | monitor_printf(mon, " backing_file="); |
| 213 | monitor_print_filename(mon, info->value->inserted->backing_file); |
| 214 | } |
| 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]"); |
| 221 | } |
| 222 | |
| 223 | monitor_printf(mon, "\n"); |
| 224 | } |
| 225 | |
| 226 | qapi_free_BlockInfoList(block_list); |
| 227 | } |
| 228 | |
Luiz Capitulino | f11f57e | 2011-09-22 15:56:36 -0300 | [diff] [blame^] | 229 | void hmp_info_blockstats(Monitor *mon) |
| 230 | { |
| 231 | BlockStatsList *stats_list, *stats; |
| 232 | |
| 233 | stats_list = qmp_query_blockstats(NULL); |
| 234 | |
| 235 | for (stats = stats_list; stats; stats = stats->next) { |
| 236 | if (!stats->value->has_device) { |
| 237 | continue; |
| 238 | } |
| 239 | |
| 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); |
| 258 | } |
| 259 | |
| 260 | qapi_free_BlockStatsList(stats_list); |
| 261 | } |
| 262 | |
Luiz Capitulino | 7a7f325 | 2011-09-15 14:20:28 -0300 | [diff] [blame] | 263 | void hmp_quit(Monitor *mon, const QDict *qdict) |
| 264 | { |
| 265 | monitor_suspend(mon); |
| 266 | qmp_quit(NULL); |
| 267 | } |
Luiz Capitulino | 5f158f2 | 2011-09-15 14:34:39 -0300 | [diff] [blame] | 268 | |
| 269 | void hmp_stop(Monitor *mon, const QDict *qdict) |
| 270 | { |
| 271 | qmp_stop(NULL); |
| 272 | } |
Luiz Capitulino | 38d2265 | 2011-09-15 14:41:46 -0300 | [diff] [blame] | 273 | |
| 274 | void hmp_system_reset(Monitor *mon, const QDict *qdict) |
| 275 | { |
| 276 | qmp_system_reset(NULL); |
| 277 | } |
Luiz Capitulino | 5bc465e | 2011-09-28 11:06:15 -0300 | [diff] [blame] | 278 | |
| 279 | void hmp_system_powerdown(Monitor *mon, const QDict *qdict) |
| 280 | { |
| 281 | qmp_system_powerdown(NULL); |
| 282 | } |
Luiz Capitulino | 755f196 | 2011-10-06 14:31:39 -0300 | [diff] [blame] | 283 | |
| 284 | void hmp_cpu(Monitor *mon, const QDict *qdict) |
| 285 | { |
| 286 | int64_t cpu_index; |
| 287 | |
| 288 | /* XXX: drop the monitor_set_cpu() usage when all HMP commands that |
| 289 | use it are converted to the QAPI */ |
| 290 | cpu_index = qdict_get_int(qdict, "index"); |
| 291 | if (monitor_set_cpu(cpu_index) < 0) { |
| 292 | monitor_printf(mon, "invalid CPU index\n"); |
| 293 | } |
| 294 | } |