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 | * |
Paolo Bonzini | 6b620ca | 2012-01-13 17:44:23 +0100 | [diff] [blame] | 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. |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include "hmp.h" |
Luiz Capitulino | 928059a | 2012-04-18 17:34:15 -0300 | [diff] [blame] | 17 | #include "net.h" |
| 18 | #include "qemu-option.h" |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 19 | #include "qemu-timer.h" |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 20 | #include "qmp-commands.h" |
Paolo Bonzini | 37003ad | 2012-06-07 04:02:21 +0200 | [diff] [blame] | 21 | #include "monitor.h" |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 22 | #include "console.h" |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 23 | |
Luiz Capitulino | 0cfd6a9 | 2011-11-22 16:32:37 -0200 | [diff] [blame] | 24 | static void hmp_handle_error(Monitor *mon, Error **errp) |
| 25 | { |
| 26 | if (error_is_set(errp)) { |
| 27 | monitor_printf(mon, "%s\n", error_get_pretty(*errp)); |
| 28 | error_free(*errp); |
| 29 | } |
| 30 | } |
| 31 | |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 32 | void hmp_info_name(Monitor *mon) |
| 33 | { |
| 34 | NameInfo *info; |
| 35 | |
| 36 | info = qmp_query_name(NULL); |
| 37 | if (info->has_name) { |
| 38 | monitor_printf(mon, "%s\n", info->name); |
| 39 | } |
| 40 | qapi_free_NameInfo(info); |
| 41 | } |
Luiz Capitulino | b9c15f1 | 2011-08-26 17:38:13 -0300 | [diff] [blame] | 42 | |
| 43 | void hmp_info_version(Monitor *mon) |
| 44 | { |
| 45 | VersionInfo *info; |
| 46 | |
| 47 | info = qmp_query_version(NULL); |
| 48 | |
| 49 | monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n", |
| 50 | info->qemu.major, info->qemu.minor, info->qemu.micro, |
| 51 | info->package); |
| 52 | |
| 53 | qapi_free_VersionInfo(info); |
| 54 | } |
Luiz Capitulino | 292a260 | 2011-09-12 15:10:53 -0300 | [diff] [blame] | 55 | |
| 56 | void hmp_info_kvm(Monitor *mon) |
| 57 | { |
| 58 | KvmInfo *info; |
| 59 | |
| 60 | info = qmp_query_kvm(NULL); |
| 61 | monitor_printf(mon, "kvm support: "); |
| 62 | if (info->present) { |
| 63 | monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled"); |
| 64 | } else { |
| 65 | monitor_printf(mon, "not compiled\n"); |
| 66 | } |
| 67 | |
| 68 | qapi_free_KvmInfo(info); |
| 69 | } |
| 70 | |
Luiz Capitulino | 1fa9a5e | 2011-09-12 17:54:20 -0300 | [diff] [blame] | 71 | void hmp_info_status(Monitor *mon) |
| 72 | { |
| 73 | StatusInfo *info; |
| 74 | |
| 75 | info = qmp_query_status(NULL); |
| 76 | |
| 77 | monitor_printf(mon, "VM status: %s%s", |
| 78 | info->running ? "running" : "paused", |
| 79 | info->singlestep ? " (single step mode)" : ""); |
| 80 | |
| 81 | if (!info->running && info->status != RUN_STATE_PAUSED) { |
| 82 | monitor_printf(mon, " (%s)", RunState_lookup[info->status]); |
| 83 | } |
| 84 | |
| 85 | monitor_printf(mon, "\n"); |
| 86 | |
| 87 | qapi_free_StatusInfo(info); |
| 88 | } |
| 89 | |
Luiz Capitulino | efab767 | 2011-09-13 17:16:25 -0300 | [diff] [blame] | 90 | void hmp_info_uuid(Monitor *mon) |
| 91 | { |
| 92 | UuidInfo *info; |
| 93 | |
| 94 | info = qmp_query_uuid(NULL); |
| 95 | monitor_printf(mon, "%s\n", info->UUID); |
| 96 | qapi_free_UuidInfo(info); |
| 97 | } |
Luiz Capitulino | c5a415a | 2011-09-14 16:05:49 -0300 | [diff] [blame] | 98 | |
| 99 | void hmp_info_chardev(Monitor *mon) |
| 100 | { |
| 101 | ChardevInfoList *char_info, *info; |
| 102 | |
| 103 | char_info = qmp_query_chardev(NULL); |
| 104 | for (info = char_info; info; info = info->next) { |
| 105 | monitor_printf(mon, "%s: filename=%s\n", info->value->label, |
| 106 | info->value->filename); |
| 107 | } |
| 108 | |
| 109 | qapi_free_ChardevInfoList(char_info); |
| 110 | } |
Luiz Capitulino | 7a7f325 | 2011-09-15 14:20:28 -0300 | [diff] [blame] | 111 | |
Luiz Capitulino | e235cec | 2011-09-21 15:29:55 -0300 | [diff] [blame] | 112 | void hmp_info_mice(Monitor *mon) |
| 113 | { |
| 114 | MouseInfoList *mice_list, *mouse; |
| 115 | |
| 116 | mice_list = qmp_query_mice(NULL); |
| 117 | if (!mice_list) { |
| 118 | monitor_printf(mon, "No mouse devices connected\n"); |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | for (mouse = mice_list; mouse; mouse = mouse->next) { |
| 123 | monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n", |
| 124 | mouse->value->current ? '*' : ' ', |
| 125 | mouse->value->index, mouse->value->name, |
| 126 | mouse->value->absolute ? " (absolute)" : ""); |
| 127 | } |
| 128 | |
| 129 | qapi_free_MouseInfoList(mice_list); |
| 130 | } |
| 131 | |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 132 | void hmp_info_migrate(Monitor *mon) |
| 133 | { |
| 134 | MigrationInfo *info; |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 135 | MigrationCapabilityStatusList *caps, *cap; |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 136 | |
| 137 | info = qmp_query_migrate(NULL); |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 138 | caps = qmp_query_migrate_capabilities(NULL); |
| 139 | |
| 140 | /* do not display parameters during setup */ |
| 141 | if (info->has_status && caps) { |
| 142 | monitor_printf(mon, "capabilities: "); |
| 143 | for (cap = caps; cap; cap = cap->next) { |
| 144 | monitor_printf(mon, "%s: %s ", |
| 145 | MigrationCapability_lookup[cap->value->capability], |
| 146 | cap->value->state ? "on" : "off"); |
| 147 | } |
| 148 | monitor_printf(mon, "\n"); |
| 149 | } |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 150 | |
| 151 | if (info->has_status) { |
| 152 | monitor_printf(mon, "Migration status: %s\n", info->status); |
Juan Quintela | 7aa939a | 2012-08-18 13:17:10 +0200 | [diff] [blame] | 153 | monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n", |
| 154 | info->total_time); |
Juan Quintela | 2c52ddf | 2012-08-13 09:53:12 +0200 | [diff] [blame] | 155 | if (info->has_expected_downtime) { |
| 156 | monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n", |
| 157 | info->expected_downtime); |
| 158 | } |
Juan Quintela | 9c5a9fc | 2012-08-13 09:35:16 +0200 | [diff] [blame] | 159 | if (info->has_downtime) { |
| 160 | monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n", |
| 161 | info->downtime); |
| 162 | } |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | if (info->has_ram) { |
| 166 | monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n", |
| 167 | info->ram->transferred >> 10); |
| 168 | monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n", |
| 169 | info->ram->remaining >> 10); |
| 170 | monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n", |
| 171 | info->ram->total >> 10); |
Orit Wasserman | 004d4c1 | 2012-08-06 21:42:56 +0300 | [diff] [blame] | 172 | monitor_printf(mon, "duplicate: %" PRIu64 " pages\n", |
| 173 | info->ram->duplicate); |
| 174 | monitor_printf(mon, "normal: %" PRIu64 " pages\n", |
| 175 | info->ram->normal); |
| 176 | monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n", |
| 177 | info->ram->normal_bytes >> 10); |
Juan Quintela | 8d01719 | 2012-08-13 12:31:25 +0200 | [diff] [blame^] | 178 | if (info->ram->dirty_pages_rate) { |
| 179 | monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n", |
| 180 | info->ram->dirty_pages_rate); |
| 181 | } |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | if (info->has_disk) { |
| 185 | monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n", |
| 186 | info->disk->transferred >> 10); |
| 187 | monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n", |
| 188 | info->disk->remaining >> 10); |
| 189 | monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n", |
| 190 | info->disk->total >> 10); |
| 191 | } |
| 192 | |
Orit Wasserman | f36d55a | 2012-08-06 21:42:57 +0300 | [diff] [blame] | 193 | if (info->has_xbzrle_cache) { |
| 194 | monitor_printf(mon, "cache size: %" PRIu64 " bytes\n", |
| 195 | info->xbzrle_cache->cache_size); |
| 196 | monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n", |
| 197 | info->xbzrle_cache->bytes >> 10); |
| 198 | monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n", |
| 199 | info->xbzrle_cache->pages); |
| 200 | monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n", |
| 201 | info->xbzrle_cache->cache_miss); |
| 202 | monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n", |
| 203 | info->xbzrle_cache->overflow); |
| 204 | } |
| 205 | |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 206 | qapi_free_MigrationInfo(info); |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 207 | qapi_free_MigrationCapabilityStatusList(caps); |
| 208 | } |
| 209 | |
| 210 | void hmp_info_migrate_capabilities(Monitor *mon) |
| 211 | { |
| 212 | MigrationCapabilityStatusList *caps, *cap; |
| 213 | |
| 214 | caps = qmp_query_migrate_capabilities(NULL); |
| 215 | |
| 216 | if (caps) { |
| 217 | monitor_printf(mon, "capabilities: "); |
| 218 | for (cap = caps; cap; cap = cap->next) { |
| 219 | monitor_printf(mon, "%s: %s ", |
| 220 | MigrationCapability_lookup[cap->value->capability], |
| 221 | cap->value->state ? "on" : "off"); |
| 222 | } |
| 223 | monitor_printf(mon, "\n"); |
| 224 | } |
| 225 | |
| 226 | qapi_free_MigrationCapabilityStatusList(caps); |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 227 | } |
| 228 | |
Orit Wasserman | 9e1ba4c | 2012-08-06 21:42:54 +0300 | [diff] [blame] | 229 | void hmp_info_migrate_cache_size(Monitor *mon) |
| 230 | { |
| 231 | monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n", |
| 232 | qmp_query_migrate_cache_size(NULL) >> 10); |
| 233 | } |
| 234 | |
Luiz Capitulino | de0b36b | 2011-09-21 16:38:35 -0300 | [diff] [blame] | 235 | void hmp_info_cpus(Monitor *mon) |
| 236 | { |
| 237 | CpuInfoList *cpu_list, *cpu; |
| 238 | |
| 239 | cpu_list = qmp_query_cpus(NULL); |
| 240 | |
| 241 | for (cpu = cpu_list; cpu; cpu = cpu->next) { |
| 242 | int active = ' '; |
| 243 | |
| 244 | if (cpu->value->CPU == monitor_get_cpu_index()) { |
| 245 | active = '*'; |
| 246 | } |
| 247 | |
| 248 | monitor_printf(mon, "%c CPU #%" PRId64 ": ", active, cpu->value->CPU); |
| 249 | |
| 250 | if (cpu->value->has_pc) { |
| 251 | monitor_printf(mon, "pc=0x%016" PRIx64, cpu->value->pc); |
| 252 | } |
| 253 | if (cpu->value->has_nip) { |
| 254 | monitor_printf(mon, "nip=0x%016" PRIx64, cpu->value->nip); |
| 255 | } |
| 256 | if (cpu->value->has_npc) { |
| 257 | monitor_printf(mon, "pc=0x%016" PRIx64, cpu->value->pc); |
| 258 | monitor_printf(mon, "npc=0x%016" PRIx64, cpu->value->npc); |
| 259 | } |
| 260 | if (cpu->value->has_PC) { |
| 261 | monitor_printf(mon, "PC=0x%016" PRIx64, cpu->value->PC); |
| 262 | } |
| 263 | |
| 264 | if (cpu->value->halted) { |
| 265 | monitor_printf(mon, " (halted)"); |
| 266 | } |
| 267 | |
| 268 | monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id); |
| 269 | } |
| 270 | |
| 271 | qapi_free_CpuInfoList(cpu_list); |
| 272 | } |
| 273 | |
Luiz Capitulino | b202381 | 2011-09-21 17:16:47 -0300 | [diff] [blame] | 274 | void hmp_info_block(Monitor *mon) |
| 275 | { |
| 276 | BlockInfoList *block_list, *info; |
| 277 | |
| 278 | block_list = qmp_query_block(NULL); |
| 279 | |
| 280 | for (info = block_list; info; info = info->next) { |
| 281 | monitor_printf(mon, "%s: removable=%d", |
| 282 | info->value->device, info->value->removable); |
| 283 | |
| 284 | if (info->value->removable) { |
| 285 | monitor_printf(mon, " locked=%d", info->value->locked); |
| 286 | monitor_printf(mon, " tray-open=%d", info->value->tray_open); |
| 287 | } |
| 288 | |
| 289 | if (info->value->has_io_status) { |
| 290 | monitor_printf(mon, " io-status=%s", |
| 291 | BlockDeviceIoStatus_lookup[info->value->io_status]); |
| 292 | } |
| 293 | |
| 294 | if (info->value->has_inserted) { |
| 295 | monitor_printf(mon, " file="); |
| 296 | monitor_print_filename(mon, info->value->inserted->file); |
| 297 | |
| 298 | if (info->value->inserted->has_backing_file) { |
| 299 | monitor_printf(mon, " backing_file="); |
| 300 | monitor_print_filename(mon, info->value->inserted->backing_file); |
Benoît Canet | 75115d9 | 2012-08-02 10:22:49 +0200 | [diff] [blame] | 301 | monitor_printf(mon, " backing_file_depth=%" PRId64, |
| 302 | info->value->inserted->backing_file_depth); |
Luiz Capitulino | b202381 | 2011-09-21 17:16:47 -0300 | [diff] [blame] | 303 | } |
| 304 | monitor_printf(mon, " ro=%d drv=%s encrypted=%d", |
| 305 | info->value->inserted->ro, |
| 306 | info->value->inserted->drv, |
| 307 | info->value->inserted->encrypted); |
Zhi Yong Wu | 727f005 | 2011-11-08 13:00:31 +0800 | [diff] [blame] | 308 | |
| 309 | monitor_printf(mon, " bps=%" PRId64 " bps_rd=%" PRId64 |
| 310 | " bps_wr=%" PRId64 " iops=%" PRId64 |
| 311 | " iops_rd=%" PRId64 " iops_wr=%" PRId64, |
| 312 | info->value->inserted->bps, |
| 313 | info->value->inserted->bps_rd, |
| 314 | info->value->inserted->bps_wr, |
| 315 | info->value->inserted->iops, |
| 316 | info->value->inserted->iops_rd, |
| 317 | info->value->inserted->iops_wr); |
Luiz Capitulino | b202381 | 2011-09-21 17:16:47 -0300 | [diff] [blame] | 318 | } else { |
| 319 | monitor_printf(mon, " [not inserted]"); |
| 320 | } |
| 321 | |
| 322 | monitor_printf(mon, "\n"); |
| 323 | } |
| 324 | |
| 325 | qapi_free_BlockInfoList(block_list); |
| 326 | } |
| 327 | |
Luiz Capitulino | f11f57e | 2011-09-22 15:56:36 -0300 | [diff] [blame] | 328 | void hmp_info_blockstats(Monitor *mon) |
| 329 | { |
| 330 | BlockStatsList *stats_list, *stats; |
| 331 | |
| 332 | stats_list = qmp_query_blockstats(NULL); |
| 333 | |
| 334 | for (stats = stats_list; stats; stats = stats->next) { |
| 335 | if (!stats->value->has_device) { |
| 336 | continue; |
| 337 | } |
| 338 | |
| 339 | monitor_printf(mon, "%s:", stats->value->device); |
| 340 | monitor_printf(mon, " rd_bytes=%" PRId64 |
| 341 | " wr_bytes=%" PRId64 |
| 342 | " rd_operations=%" PRId64 |
| 343 | " wr_operations=%" PRId64 |
| 344 | " flush_operations=%" PRId64 |
| 345 | " wr_total_time_ns=%" PRId64 |
| 346 | " rd_total_time_ns=%" PRId64 |
| 347 | " flush_total_time_ns=%" PRId64 |
| 348 | "\n", |
| 349 | stats->value->stats->rd_bytes, |
| 350 | stats->value->stats->wr_bytes, |
| 351 | stats->value->stats->rd_operations, |
| 352 | stats->value->stats->wr_operations, |
| 353 | stats->value->stats->flush_operations, |
| 354 | stats->value->stats->wr_total_time_ns, |
| 355 | stats->value->stats->rd_total_time_ns, |
| 356 | stats->value->stats->flush_total_time_ns); |
| 357 | } |
| 358 | |
| 359 | qapi_free_BlockStatsList(stats_list); |
| 360 | } |
| 361 | |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 362 | void hmp_info_vnc(Monitor *mon) |
| 363 | { |
| 364 | VncInfo *info; |
| 365 | Error *err = NULL; |
| 366 | VncClientInfoList *client; |
| 367 | |
| 368 | info = qmp_query_vnc(&err); |
| 369 | if (err) { |
| 370 | monitor_printf(mon, "%s\n", error_get_pretty(err)); |
| 371 | error_free(err); |
| 372 | return; |
| 373 | } |
| 374 | |
| 375 | if (!info->enabled) { |
| 376 | monitor_printf(mon, "Server: disabled\n"); |
| 377 | goto out; |
| 378 | } |
| 379 | |
| 380 | monitor_printf(mon, "Server:\n"); |
| 381 | if (info->has_host && info->has_service) { |
| 382 | monitor_printf(mon, " address: %s:%s\n", info->host, info->service); |
| 383 | } |
| 384 | if (info->has_auth) { |
| 385 | monitor_printf(mon, " auth: %s\n", info->auth); |
| 386 | } |
| 387 | |
| 388 | if (!info->has_clients || info->clients == NULL) { |
| 389 | monitor_printf(mon, "Client: none\n"); |
| 390 | } else { |
| 391 | for (client = info->clients; client; client = client->next) { |
| 392 | monitor_printf(mon, "Client:\n"); |
| 393 | monitor_printf(mon, " address: %s:%s\n", |
| 394 | client->value->host, client->value->service); |
| 395 | monitor_printf(mon, " x509_dname: %s\n", |
| 396 | client->value->x509_dname ? |
| 397 | client->value->x509_dname : "none"); |
| 398 | monitor_printf(mon, " username: %s\n", |
| 399 | client->value->has_sasl_username ? |
| 400 | client->value->sasl_username : "none"); |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | out: |
| 405 | qapi_free_VncInfo(info); |
| 406 | } |
| 407 | |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 408 | void hmp_info_spice(Monitor *mon) |
| 409 | { |
| 410 | SpiceChannelList *chan; |
| 411 | SpiceInfo *info; |
| 412 | |
| 413 | info = qmp_query_spice(NULL); |
| 414 | |
| 415 | if (!info->enabled) { |
| 416 | monitor_printf(mon, "Server: disabled\n"); |
| 417 | goto out; |
| 418 | } |
| 419 | |
| 420 | monitor_printf(mon, "Server:\n"); |
| 421 | if (info->has_port) { |
| 422 | monitor_printf(mon, " address: %s:%" PRId64 "\n", |
| 423 | info->host, info->port); |
| 424 | } |
| 425 | if (info->has_tls_port) { |
| 426 | monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n", |
| 427 | info->host, info->tls_port); |
| 428 | } |
Yonit Halperin | 61c4efe | 2012-08-21 11:51:58 +0300 | [diff] [blame] | 429 | monitor_printf(mon, " migrated: %s\n", |
| 430 | info->migrated ? "true" : "false"); |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 431 | monitor_printf(mon, " auth: %s\n", info->auth); |
| 432 | monitor_printf(mon, " compiled: %s\n", info->compiled_version); |
Alon Levy | 4efee02 | 2012-03-29 23:23:14 +0200 | [diff] [blame] | 433 | monitor_printf(mon, " mouse-mode: %s\n", |
| 434 | SpiceQueryMouseMode_lookup[info->mouse_mode]); |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 435 | |
| 436 | if (!info->has_channels || info->channels == NULL) { |
| 437 | monitor_printf(mon, "Channels: none\n"); |
| 438 | } else { |
| 439 | for (chan = info->channels; chan; chan = chan->next) { |
| 440 | monitor_printf(mon, "Channel:\n"); |
| 441 | monitor_printf(mon, " address: %s:%s%s\n", |
| 442 | chan->value->host, chan->value->port, |
| 443 | chan->value->tls ? " [tls]" : ""); |
| 444 | monitor_printf(mon, " session: %" PRId64 "\n", |
| 445 | chan->value->connection_id); |
| 446 | monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n", |
| 447 | chan->value->channel_type, chan->value->channel_id); |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | out: |
| 452 | qapi_free_SpiceInfo(info); |
| 453 | } |
| 454 | |
Luiz Capitulino | 96637bc | 2011-10-21 11:41:37 -0200 | [diff] [blame] | 455 | void hmp_info_balloon(Monitor *mon) |
| 456 | { |
| 457 | BalloonInfo *info; |
| 458 | Error *err = NULL; |
| 459 | |
| 460 | info = qmp_query_balloon(&err); |
| 461 | if (err) { |
| 462 | monitor_printf(mon, "%s\n", error_get_pretty(err)); |
| 463 | error_free(err); |
| 464 | return; |
| 465 | } |
| 466 | |
| 467 | monitor_printf(mon, "balloon: actual=%" PRId64, info->actual >> 20); |
| 468 | if (info->has_mem_swapped_in) { |
| 469 | monitor_printf(mon, " mem_swapped_in=%" PRId64, info->mem_swapped_in); |
| 470 | } |
| 471 | if (info->has_mem_swapped_out) { |
| 472 | monitor_printf(mon, " mem_swapped_out=%" PRId64, info->mem_swapped_out); |
| 473 | } |
| 474 | if (info->has_major_page_faults) { |
| 475 | monitor_printf(mon, " major_page_faults=%" PRId64, |
| 476 | info->major_page_faults); |
| 477 | } |
| 478 | if (info->has_minor_page_faults) { |
| 479 | monitor_printf(mon, " minor_page_faults=%" PRId64, |
| 480 | info->minor_page_faults); |
| 481 | } |
| 482 | if (info->has_free_mem) { |
| 483 | monitor_printf(mon, " free_mem=%" PRId64, info->free_mem); |
| 484 | } |
| 485 | if (info->has_total_mem) { |
| 486 | monitor_printf(mon, " total_mem=%" PRId64, info->total_mem); |
| 487 | } |
| 488 | |
| 489 | monitor_printf(mon, "\n"); |
| 490 | |
| 491 | qapi_free_BalloonInfo(info); |
| 492 | } |
| 493 | |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 494 | static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) |
| 495 | { |
| 496 | PciMemoryRegionList *region; |
| 497 | |
| 498 | monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus); |
| 499 | monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n", |
| 500 | dev->slot, dev->function); |
| 501 | monitor_printf(mon, " "); |
| 502 | |
| 503 | if (dev->class_info.has_desc) { |
| 504 | monitor_printf(mon, "%s", dev->class_info.desc); |
| 505 | } else { |
| 506 | monitor_printf(mon, "Class %04" PRId64, dev->class_info.class); |
| 507 | } |
| 508 | |
| 509 | monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n", |
| 510 | dev->id.vendor, dev->id.device); |
| 511 | |
| 512 | if (dev->has_irq) { |
| 513 | monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq); |
| 514 | } |
| 515 | |
| 516 | if (dev->has_pci_bridge) { |
| 517 | monitor_printf(mon, " BUS %" PRId64 ".\n", |
| 518 | dev->pci_bridge->bus.number); |
| 519 | monitor_printf(mon, " secondary bus %" PRId64 ".\n", |
| 520 | dev->pci_bridge->bus.secondary); |
| 521 | monitor_printf(mon, " subordinate bus %" PRId64 ".\n", |
| 522 | dev->pci_bridge->bus.subordinate); |
| 523 | |
| 524 | monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n", |
| 525 | dev->pci_bridge->bus.io_range->base, |
| 526 | dev->pci_bridge->bus.io_range->limit); |
| 527 | |
| 528 | monitor_printf(mon, |
| 529 | " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n", |
| 530 | dev->pci_bridge->bus.memory_range->base, |
| 531 | dev->pci_bridge->bus.memory_range->limit); |
| 532 | |
| 533 | monitor_printf(mon, " prefetchable memory range " |
| 534 | "[0x%08"PRIx64", 0x%08"PRIx64"]\n", |
| 535 | dev->pci_bridge->bus.prefetchable_range->base, |
| 536 | dev->pci_bridge->bus.prefetchable_range->limit); |
| 537 | } |
| 538 | |
| 539 | for (region = dev->regions; region; region = region->next) { |
| 540 | uint64_t addr, size; |
| 541 | |
| 542 | addr = region->value->address; |
| 543 | size = region->value->size; |
| 544 | |
| 545 | monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar); |
| 546 | |
| 547 | if (!strcmp(region->value->type, "io")) { |
| 548 | monitor_printf(mon, "I/O at 0x%04" PRIx64 |
| 549 | " [0x%04" PRIx64 "].\n", |
| 550 | addr, addr + size - 1); |
| 551 | } else { |
| 552 | monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64 |
| 553 | " [0x%08" PRIx64 "].\n", |
| 554 | region->value->mem_type_64 ? 64 : 32, |
| 555 | region->value->prefetch ? " prefetchable" : "", |
| 556 | addr, addr + size - 1); |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | monitor_printf(mon, " id \"%s\"\n", dev->qdev_id); |
| 561 | |
| 562 | if (dev->has_pci_bridge) { |
| 563 | if (dev->pci_bridge->has_devices) { |
| 564 | PciDeviceInfoList *cdev; |
| 565 | for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) { |
| 566 | hmp_info_pci_device(mon, cdev->value); |
| 567 | } |
| 568 | } |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | void hmp_info_pci(Monitor *mon) |
| 573 | { |
Stefan Berger | f46cee3 | 2012-01-11 10:51:52 -0500 | [diff] [blame] | 574 | PciInfoList *info_list, *info; |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 575 | Error *err = NULL; |
| 576 | |
Stefan Berger | f46cee3 | 2012-01-11 10:51:52 -0500 | [diff] [blame] | 577 | info_list = qmp_query_pci(&err); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 578 | if (err) { |
| 579 | monitor_printf(mon, "PCI devices not supported\n"); |
| 580 | error_free(err); |
| 581 | return; |
| 582 | } |
| 583 | |
Stefan Berger | f46cee3 | 2012-01-11 10:51:52 -0500 | [diff] [blame] | 584 | for (info = info_list; info; info = info->next) { |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 585 | PciDeviceInfoList *dev; |
| 586 | |
| 587 | for (dev = info->value->devices; dev; dev = dev->next) { |
| 588 | hmp_info_pci_device(mon, dev->value); |
| 589 | } |
| 590 | } |
| 591 | |
Stefan Berger | f46cee3 | 2012-01-11 10:51:52 -0500 | [diff] [blame] | 592 | qapi_free_PciInfoList(info_list); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 593 | } |
| 594 | |
Stefan Hajnoczi | fb5458c | 2012-01-18 14:40:49 +0000 | [diff] [blame] | 595 | void hmp_info_block_jobs(Monitor *mon) |
| 596 | { |
| 597 | BlockJobInfoList *list; |
| 598 | Error *err = NULL; |
| 599 | |
| 600 | list = qmp_query_block_jobs(&err); |
| 601 | assert(!err); |
| 602 | |
| 603 | if (!list) { |
| 604 | monitor_printf(mon, "No active jobs\n"); |
| 605 | return; |
| 606 | } |
| 607 | |
| 608 | while (list) { |
| 609 | if (strcmp(list->value->type, "stream") == 0) { |
| 610 | monitor_printf(mon, "Streaming device %s: Completed %" PRId64 |
| 611 | " of %" PRId64 " bytes, speed limit %" PRId64 |
| 612 | " bytes/s\n", |
| 613 | list->value->device, |
| 614 | list->value->offset, |
| 615 | list->value->len, |
| 616 | list->value->speed); |
| 617 | } else { |
| 618 | monitor_printf(mon, "Type %s, device %s: Completed %" PRId64 |
| 619 | " of %" PRId64 " bytes, speed limit %" PRId64 |
| 620 | " bytes/s\n", |
| 621 | list->value->type, |
| 622 | list->value->device, |
| 623 | list->value->offset, |
| 624 | list->value->len, |
| 625 | list->value->speed); |
| 626 | } |
| 627 | list = list->next; |
| 628 | } |
| 629 | } |
| 630 | |
Luiz Capitulino | 7a7f325 | 2011-09-15 14:20:28 -0300 | [diff] [blame] | 631 | void hmp_quit(Monitor *mon, const QDict *qdict) |
| 632 | { |
| 633 | monitor_suspend(mon); |
| 634 | qmp_quit(NULL); |
| 635 | } |
Luiz Capitulino | 5f158f2 | 2011-09-15 14:34:39 -0300 | [diff] [blame] | 636 | |
| 637 | void hmp_stop(Monitor *mon, const QDict *qdict) |
| 638 | { |
| 639 | qmp_stop(NULL); |
| 640 | } |
Luiz Capitulino | 38d2265 | 2011-09-15 14:41:46 -0300 | [diff] [blame] | 641 | |
| 642 | void hmp_system_reset(Monitor *mon, const QDict *qdict) |
| 643 | { |
| 644 | qmp_system_reset(NULL); |
| 645 | } |
Luiz Capitulino | 5bc465e | 2011-09-28 11:06:15 -0300 | [diff] [blame] | 646 | |
| 647 | void hmp_system_powerdown(Monitor *mon, const QDict *qdict) |
| 648 | { |
| 649 | qmp_system_powerdown(NULL); |
| 650 | } |
Luiz Capitulino | 755f196 | 2011-10-06 14:31:39 -0300 | [diff] [blame] | 651 | |
| 652 | void hmp_cpu(Monitor *mon, const QDict *qdict) |
| 653 | { |
| 654 | int64_t cpu_index; |
| 655 | |
| 656 | /* XXX: drop the monitor_set_cpu() usage when all HMP commands that |
| 657 | use it are converted to the QAPI */ |
| 658 | cpu_index = qdict_get_int(qdict, "index"); |
| 659 | if (monitor_set_cpu(cpu_index) < 0) { |
| 660 | monitor_printf(mon, "invalid CPU index\n"); |
| 661 | } |
| 662 | } |
Luiz Capitulino | 0cfd6a9 | 2011-11-22 16:32:37 -0200 | [diff] [blame] | 663 | |
| 664 | void hmp_memsave(Monitor *mon, const QDict *qdict) |
| 665 | { |
| 666 | uint32_t size = qdict_get_int(qdict, "size"); |
| 667 | const char *filename = qdict_get_str(qdict, "filename"); |
| 668 | uint64_t addr = qdict_get_int(qdict, "val"); |
| 669 | Error *errp = NULL; |
| 670 | |
| 671 | qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &errp); |
| 672 | hmp_handle_error(mon, &errp); |
| 673 | } |
Luiz Capitulino | 6d3962b | 2011-11-22 17:26:46 -0200 | [diff] [blame] | 674 | |
| 675 | void hmp_pmemsave(Monitor *mon, const QDict *qdict) |
| 676 | { |
| 677 | uint32_t size = qdict_get_int(qdict, "size"); |
| 678 | const char *filename = qdict_get_str(qdict, "filename"); |
| 679 | uint64_t addr = qdict_get_int(qdict, "val"); |
| 680 | Error *errp = NULL; |
| 681 | |
| 682 | qmp_pmemsave(addr, size, filename, &errp); |
| 683 | hmp_handle_error(mon, &errp); |
| 684 | } |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 685 | |
| 686 | static void hmp_cont_cb(void *opaque, int err) |
| 687 | { |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 688 | if (!err) { |
Luiz Capitulino | 8b7f6fb | 2012-07-26 20:41:53 -0300 | [diff] [blame] | 689 | qmp_cont(NULL); |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
Luiz Capitulino | 8b7f6fb | 2012-07-26 20:41:53 -0300 | [diff] [blame] | 693 | static bool key_is_missing(const BlockInfo *bdev) |
| 694 | { |
| 695 | return (bdev->inserted && bdev->inserted->encryption_key_missing); |
| 696 | } |
| 697 | |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 698 | void hmp_cont(Monitor *mon, const QDict *qdict) |
| 699 | { |
Luiz Capitulino | 8b7f6fb | 2012-07-26 20:41:53 -0300 | [diff] [blame] | 700 | BlockInfoList *bdev_list, *bdev; |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 701 | Error *errp = NULL; |
| 702 | |
Luiz Capitulino | 8b7f6fb | 2012-07-26 20:41:53 -0300 | [diff] [blame] | 703 | bdev_list = qmp_query_block(NULL); |
| 704 | for (bdev = bdev_list; bdev; bdev = bdev->next) { |
| 705 | if (key_is_missing(bdev->value)) { |
| 706 | monitor_read_block_device_key(mon, bdev->value->device, |
| 707 | hmp_cont_cb, NULL); |
| 708 | goto out; |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 709 | } |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 710 | } |
Luiz Capitulino | 8b7f6fb | 2012-07-26 20:41:53 -0300 | [diff] [blame] | 711 | |
| 712 | qmp_cont(&errp); |
| 713 | hmp_handle_error(mon, &errp); |
| 714 | |
| 715 | out: |
| 716 | qapi_free_BlockInfoList(bdev_list); |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 717 | } |
Luiz Capitulino | ab49ab5 | 2011-11-23 12:55:53 -0200 | [diff] [blame] | 718 | |
Gerd Hoffmann | 9b9df25 | 2012-02-23 13:45:21 +0100 | [diff] [blame] | 719 | void hmp_system_wakeup(Monitor *mon, const QDict *qdict) |
| 720 | { |
| 721 | qmp_system_wakeup(NULL); |
| 722 | } |
| 723 | |
Luiz Capitulino | ab49ab5 | 2011-11-23 12:55:53 -0200 | [diff] [blame] | 724 | void hmp_inject_nmi(Monitor *mon, const QDict *qdict) |
| 725 | { |
| 726 | Error *errp = NULL; |
| 727 | |
| 728 | qmp_inject_nmi(&errp); |
| 729 | hmp_handle_error(mon, &errp); |
| 730 | } |
Luiz Capitulino | 4b37156 | 2011-11-23 13:11:55 -0200 | [diff] [blame] | 731 | |
| 732 | void hmp_set_link(Monitor *mon, const QDict *qdict) |
| 733 | { |
| 734 | const char *name = qdict_get_str(qdict, "name"); |
| 735 | int up = qdict_get_bool(qdict, "up"); |
| 736 | Error *errp = NULL; |
| 737 | |
| 738 | qmp_set_link(name, up, &errp); |
| 739 | hmp_handle_error(mon, &errp); |
| 740 | } |
Luiz Capitulino | a4dea8a | 2011-11-23 13:28:21 -0200 | [diff] [blame] | 741 | |
| 742 | void hmp_block_passwd(Monitor *mon, const QDict *qdict) |
| 743 | { |
| 744 | const char *device = qdict_get_str(qdict, "device"); |
| 745 | const char *password = qdict_get_str(qdict, "password"); |
| 746 | Error *errp = NULL; |
| 747 | |
| 748 | qmp_block_passwd(device, password, &errp); |
| 749 | hmp_handle_error(mon, &errp); |
| 750 | } |
Luiz Capitulino | d72f326 | 2011-11-25 14:38:09 -0200 | [diff] [blame] | 751 | |
| 752 | void hmp_balloon(Monitor *mon, const QDict *qdict) |
| 753 | { |
| 754 | int64_t value = qdict_get_int(qdict, "value"); |
| 755 | Error *errp = NULL; |
| 756 | |
| 757 | qmp_balloon(value, &errp); |
| 758 | if (error_is_set(&errp)) { |
| 759 | monitor_printf(mon, "balloon: %s\n", error_get_pretty(errp)); |
| 760 | error_free(errp); |
| 761 | } |
| 762 | } |
Luiz Capitulino | 5e7caac | 2011-11-25 14:57:10 -0200 | [diff] [blame] | 763 | |
| 764 | void hmp_block_resize(Monitor *mon, const QDict *qdict) |
| 765 | { |
| 766 | const char *device = qdict_get_str(qdict, "device"); |
| 767 | int64_t size = qdict_get_int(qdict, "size"); |
| 768 | Error *errp = NULL; |
| 769 | |
| 770 | qmp_block_resize(device, size, &errp); |
| 771 | hmp_handle_error(mon, &errp); |
| 772 | } |
Luiz Capitulino | 6106e24 | 2011-11-25 16:15:19 -0200 | [diff] [blame] | 773 | |
| 774 | void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) |
| 775 | { |
| 776 | const char *device = qdict_get_str(qdict, "device"); |
| 777 | const char *filename = qdict_get_try_str(qdict, "snapshot-file"); |
| 778 | const char *format = qdict_get_try_str(qdict, "format"); |
Paolo Bonzini | 6cc2a41 | 2012-03-06 18:55:59 +0100 | [diff] [blame] | 779 | int reuse = qdict_get_try_bool(qdict, "reuse", 0); |
| 780 | enum NewImageMode mode; |
Luiz Capitulino | 6106e24 | 2011-11-25 16:15:19 -0200 | [diff] [blame] | 781 | Error *errp = NULL; |
| 782 | |
| 783 | if (!filename) { |
| 784 | /* In the future, if 'snapshot-file' is not specified, the snapshot |
| 785 | will be taken internally. Today it's actually required. */ |
| 786 | error_set(&errp, QERR_MISSING_PARAMETER, "snapshot-file"); |
| 787 | hmp_handle_error(mon, &errp); |
| 788 | return; |
| 789 | } |
| 790 | |
Paolo Bonzini | 6cc2a41 | 2012-03-06 18:55:59 +0100 | [diff] [blame] | 791 | mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS; |
| 792 | qmp_blockdev_snapshot_sync(device, filename, !!format, format, |
| 793 | true, mode, &errp); |
Luiz Capitulino | 6106e24 | 2011-11-25 16:15:19 -0200 | [diff] [blame] | 794 | hmp_handle_error(mon, &errp); |
| 795 | } |
Luiz Capitulino | 6cdedb0 | 2011-11-27 22:54:09 -0200 | [diff] [blame] | 796 | |
| 797 | void hmp_migrate_cancel(Monitor *mon, const QDict *qdict) |
| 798 | { |
| 799 | qmp_migrate_cancel(NULL); |
| 800 | } |
Luiz Capitulino | 4f0a993 | 2011-11-27 23:18:01 -0200 | [diff] [blame] | 801 | |
| 802 | void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict) |
| 803 | { |
| 804 | double value = qdict_get_double(qdict, "value"); |
| 805 | qmp_migrate_set_downtime(value, NULL); |
| 806 | } |
Luiz Capitulino | 3dc8538 | 2011-11-28 11:59:37 -0200 | [diff] [blame] | 807 | |
Orit Wasserman | 9e1ba4c | 2012-08-06 21:42:54 +0300 | [diff] [blame] | 808 | void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict) |
| 809 | { |
| 810 | int64_t value = qdict_get_int(qdict, "value"); |
| 811 | Error *err = NULL; |
| 812 | |
| 813 | qmp_migrate_set_cache_size(value, &err); |
| 814 | if (err) { |
| 815 | monitor_printf(mon, "%s\n", error_get_pretty(err)); |
| 816 | error_free(err); |
| 817 | return; |
| 818 | } |
| 819 | } |
| 820 | |
Luiz Capitulino | 3dc8538 | 2011-11-28 11:59:37 -0200 | [diff] [blame] | 821 | void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict) |
| 822 | { |
| 823 | int64_t value = qdict_get_int(qdict, "value"); |
| 824 | qmp_migrate_set_speed(value, NULL); |
| 825 | } |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 826 | |
Orit Wasserman | 0045843 | 2012-08-06 21:42:48 +0300 | [diff] [blame] | 827 | void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict) |
| 828 | { |
| 829 | const char *cap = qdict_get_str(qdict, "capability"); |
| 830 | bool state = qdict_get_bool(qdict, "state"); |
| 831 | Error *err = NULL; |
| 832 | MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps)); |
| 833 | int i; |
| 834 | |
| 835 | for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) { |
| 836 | if (strcmp(cap, MigrationCapability_lookup[i]) == 0) { |
| 837 | caps->value = g_malloc0(sizeof(*caps->value)); |
| 838 | caps->value->capability = i; |
| 839 | caps->value->state = state; |
| 840 | caps->next = NULL; |
| 841 | qmp_migrate_set_capabilities(caps, &err); |
| 842 | break; |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | if (i == MIGRATION_CAPABILITY_MAX) { |
| 847 | error_set(&err, QERR_INVALID_PARAMETER, cap); |
| 848 | } |
| 849 | |
| 850 | qapi_free_MigrationCapabilityStatusList(caps); |
| 851 | |
| 852 | if (err) { |
| 853 | monitor_printf(mon, "migrate_set_parameter: %s\n", |
| 854 | error_get_pretty(err)); |
| 855 | error_free(err); |
| 856 | } |
| 857 | } |
| 858 | |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 859 | void hmp_set_password(Monitor *mon, const QDict *qdict) |
| 860 | { |
| 861 | const char *protocol = qdict_get_str(qdict, "protocol"); |
| 862 | const char *password = qdict_get_str(qdict, "password"); |
| 863 | const char *connected = qdict_get_try_str(qdict, "connected"); |
| 864 | Error *err = NULL; |
| 865 | |
| 866 | qmp_set_password(protocol, password, !!connected, connected, &err); |
| 867 | hmp_handle_error(mon, &err); |
| 868 | } |
Luiz Capitulino | 9ad5372 | 2011-12-07 11:47:57 -0200 | [diff] [blame] | 869 | |
| 870 | void hmp_expire_password(Monitor *mon, const QDict *qdict) |
| 871 | { |
| 872 | const char *protocol = qdict_get_str(qdict, "protocol"); |
| 873 | const char *whenstr = qdict_get_str(qdict, "time"); |
| 874 | Error *err = NULL; |
| 875 | |
| 876 | qmp_expire_password(protocol, whenstr, &err); |
| 877 | hmp_handle_error(mon, &err); |
| 878 | } |
Luiz Capitulino | c245b6a | 2011-12-07 16:02:36 -0200 | [diff] [blame] | 879 | |
| 880 | void hmp_eject(Monitor *mon, const QDict *qdict) |
| 881 | { |
| 882 | int force = qdict_get_try_bool(qdict, "force", 0); |
| 883 | const char *device = qdict_get_str(qdict, "device"); |
| 884 | Error *err = NULL; |
| 885 | |
| 886 | qmp_eject(device, true, force, &err); |
| 887 | hmp_handle_error(mon, &err); |
| 888 | } |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 889 | |
| 890 | static void hmp_change_read_arg(Monitor *mon, const char *password, |
| 891 | void *opaque) |
| 892 | { |
| 893 | qmp_change_vnc_password(password, NULL); |
| 894 | monitor_read_command(mon, 1); |
| 895 | } |
| 896 | |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 897 | void hmp_change(Monitor *mon, const QDict *qdict) |
| 898 | { |
| 899 | const char *device = qdict_get_str(qdict, "device"); |
| 900 | const char *target = qdict_get_str(qdict, "target"); |
| 901 | const char *arg = qdict_get_try_str(qdict, "arg"); |
| 902 | Error *err = NULL; |
| 903 | |
| 904 | if (strcmp(device, "vnc") == 0 && |
| 905 | (strcmp(target, "passwd") == 0 || |
| 906 | strcmp(target, "password") == 0)) { |
| 907 | if (!arg) { |
| 908 | monitor_read_password(mon, hmp_change_read_arg, NULL); |
| 909 | return; |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | qmp_change(device, target, !!arg, arg, &err); |
Luiz Capitulino | ab878dd | 2012-08-06 15:55:22 -0300 | [diff] [blame] | 914 | if (error_is_set(&err) && |
| 915 | error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) { |
Luiz Capitulino | eef5ad1 | 2012-08-06 15:49:34 -0300 | [diff] [blame] | 916 | error_free(err); |
| 917 | monitor_read_block_device_key(mon, device, NULL, NULL); |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 918 | return; |
| 919 | } |
| 920 | hmp_handle_error(mon, &err); |
| 921 | } |
Luiz Capitulino | 80047da | 2011-12-14 16:49:14 -0200 | [diff] [blame] | 922 | |
| 923 | void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) |
| 924 | { |
| 925 | Error *err = NULL; |
| 926 | |
| 927 | qmp_block_set_io_throttle(qdict_get_str(qdict, "device"), |
| 928 | qdict_get_int(qdict, "bps"), |
| 929 | qdict_get_int(qdict, "bps_rd"), |
| 930 | qdict_get_int(qdict, "bps_wr"), |
| 931 | qdict_get_int(qdict, "iops"), |
| 932 | qdict_get_int(qdict, "iops_rd"), |
| 933 | qdict_get_int(qdict, "iops_wr"), &err); |
| 934 | hmp_handle_error(mon, &err); |
| 935 | } |
Stefan Hajnoczi | 12bd451 | 2012-01-18 14:40:46 +0000 | [diff] [blame] | 936 | |
| 937 | void hmp_block_stream(Monitor *mon, const QDict *qdict) |
| 938 | { |
| 939 | Error *error = NULL; |
| 940 | const char *device = qdict_get_str(qdict, "device"); |
| 941 | const char *base = qdict_get_try_str(qdict, "base"); |
Stefan Hajnoczi | c83c66c | 2012-04-25 16:51:03 +0100 | [diff] [blame] | 942 | int64_t speed = qdict_get_try_int(qdict, "speed", 0); |
Stefan Hajnoczi | 12bd451 | 2012-01-18 14:40:46 +0000 | [diff] [blame] | 943 | |
Stefan Hajnoczi | c83c66c | 2012-04-25 16:51:03 +0100 | [diff] [blame] | 944 | qmp_block_stream(device, base != NULL, base, |
Paolo Bonzini | 1d80909 | 2012-09-28 17:22:59 +0200 | [diff] [blame] | 945 | qdict_haskey(qdict, "speed"), speed, |
| 946 | BLOCKDEV_ON_ERROR_REPORT, true, &error); |
Stefan Hajnoczi | 12bd451 | 2012-01-18 14:40:46 +0000 | [diff] [blame] | 947 | |
| 948 | hmp_handle_error(mon, &error); |
| 949 | } |
Stefan Hajnoczi | 2d47c6e | 2012-01-18 14:40:47 +0000 | [diff] [blame] | 950 | |
| 951 | void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict) |
| 952 | { |
| 953 | Error *error = NULL; |
| 954 | const char *device = qdict_get_str(qdict, "device"); |
Paolo Bonzini | c6db239 | 2012-05-08 16:51:56 +0200 | [diff] [blame] | 955 | int64_t value = qdict_get_int(qdict, "speed"); |
Stefan Hajnoczi | 2d47c6e | 2012-01-18 14:40:47 +0000 | [diff] [blame] | 956 | |
| 957 | qmp_block_job_set_speed(device, value, &error); |
| 958 | |
| 959 | hmp_handle_error(mon, &error); |
| 960 | } |
Stefan Hajnoczi | 370521a | 2012-01-18 14:40:48 +0000 | [diff] [blame] | 961 | |
| 962 | void hmp_block_job_cancel(Monitor *mon, const QDict *qdict) |
| 963 | { |
| 964 | Error *error = NULL; |
| 965 | const char *device = qdict_get_str(qdict, "device"); |
Paolo Bonzini | 6e37fb8 | 2012-09-28 17:22:51 +0200 | [diff] [blame] | 966 | bool force = qdict_get_try_bool(qdict, "force", 0); |
Stefan Hajnoczi | 370521a | 2012-01-18 14:40:48 +0000 | [diff] [blame] | 967 | |
Paolo Bonzini | 6e37fb8 | 2012-09-28 17:22:51 +0200 | [diff] [blame] | 968 | qmp_block_job_cancel(device, true, force, &error); |
| 969 | |
| 970 | hmp_handle_error(mon, &error); |
| 971 | } |
| 972 | |
| 973 | void hmp_block_job_pause(Monitor *mon, const QDict *qdict) |
| 974 | { |
| 975 | Error *error = NULL; |
| 976 | const char *device = qdict_get_str(qdict, "device"); |
| 977 | |
| 978 | qmp_block_job_pause(device, &error); |
| 979 | |
| 980 | hmp_handle_error(mon, &error); |
| 981 | } |
| 982 | |
| 983 | void hmp_block_job_resume(Monitor *mon, const QDict *qdict) |
| 984 | { |
| 985 | Error *error = NULL; |
| 986 | const char *device = qdict_get_str(qdict, "device"); |
| 987 | |
| 988 | qmp_block_job_resume(device, &error); |
Stefan Hajnoczi | 370521a | 2012-01-18 14:40:48 +0000 | [diff] [blame] | 989 | |
| 990 | hmp_handle_error(mon, &error); |
| 991 | } |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 992 | |
| 993 | typedef struct MigrationStatus |
| 994 | { |
| 995 | QEMUTimer *timer; |
| 996 | Monitor *mon; |
| 997 | bool is_block_migration; |
| 998 | } MigrationStatus; |
| 999 | |
| 1000 | static void hmp_migrate_status_cb(void *opaque) |
| 1001 | { |
| 1002 | MigrationStatus *status = opaque; |
| 1003 | MigrationInfo *info; |
| 1004 | |
| 1005 | info = qmp_query_migrate(NULL); |
| 1006 | if (!info->has_status || strcmp(info->status, "active") == 0) { |
| 1007 | if (info->has_disk) { |
| 1008 | int progress; |
| 1009 | |
| 1010 | if (info->disk->remaining) { |
| 1011 | progress = info->disk->transferred * 100 / info->disk->total; |
| 1012 | } else { |
| 1013 | progress = 100; |
| 1014 | } |
| 1015 | |
| 1016 | monitor_printf(status->mon, "Completed %d %%\r", progress); |
| 1017 | monitor_flush(status->mon); |
| 1018 | } |
| 1019 | |
| 1020 | qemu_mod_timer(status->timer, qemu_get_clock_ms(rt_clock) + 1000); |
| 1021 | } else { |
| 1022 | if (status->is_block_migration) { |
| 1023 | monitor_printf(status->mon, "\n"); |
| 1024 | } |
| 1025 | monitor_resume(status->mon); |
| 1026 | qemu_del_timer(status->timer); |
| 1027 | g_free(status); |
| 1028 | } |
| 1029 | |
| 1030 | qapi_free_MigrationInfo(info); |
| 1031 | } |
| 1032 | |
| 1033 | void hmp_migrate(Monitor *mon, const QDict *qdict) |
| 1034 | { |
| 1035 | int detach = qdict_get_try_bool(qdict, "detach", 0); |
| 1036 | int blk = qdict_get_try_bool(qdict, "blk", 0); |
| 1037 | int inc = qdict_get_try_bool(qdict, "inc", 0); |
| 1038 | const char *uri = qdict_get_str(qdict, "uri"); |
| 1039 | Error *err = NULL; |
| 1040 | |
| 1041 | qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err); |
| 1042 | if (err) { |
| 1043 | monitor_printf(mon, "migrate: %s\n", error_get_pretty(err)); |
| 1044 | error_free(err); |
| 1045 | return; |
| 1046 | } |
| 1047 | |
| 1048 | if (!detach) { |
| 1049 | MigrationStatus *status; |
| 1050 | |
| 1051 | if (monitor_suspend(mon) < 0) { |
| 1052 | monitor_printf(mon, "terminal does not allow synchronous " |
| 1053 | "migration, continuing detached\n"); |
| 1054 | return; |
| 1055 | } |
| 1056 | |
| 1057 | status = g_malloc0(sizeof(*status)); |
| 1058 | status->mon = mon; |
| 1059 | status->is_block_migration = blk || inc; |
| 1060 | status->timer = qemu_new_timer_ms(rt_clock, hmp_migrate_status_cb, |
| 1061 | status); |
| 1062 | qemu_mod_timer(status->timer, qemu_get_clock_ms(rt_clock)); |
| 1063 | } |
| 1064 | } |
Luiz Capitulino | a15fef2 | 2012-03-29 12:38:50 -0300 | [diff] [blame] | 1065 | |
| 1066 | void hmp_device_del(Monitor *mon, const QDict *qdict) |
| 1067 | { |
| 1068 | const char *id = qdict_get_str(qdict, "id"); |
| 1069 | Error *err = NULL; |
| 1070 | |
| 1071 | qmp_device_del(id, &err); |
| 1072 | hmp_handle_error(mon, &err); |
| 1073 | } |
Wen Congyang | 783e9b4 | 2012-05-07 12:10:47 +0800 | [diff] [blame] | 1074 | |
| 1075 | void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) |
| 1076 | { |
| 1077 | Error *errp = NULL; |
| 1078 | int paging = qdict_get_try_bool(qdict, "paging", 0); |
Luiz Capitulino | 7536376 | 2012-09-21 13:53:00 -0300 | [diff] [blame] | 1079 | const char *file = qdict_get_str(qdict, "filename"); |
Wen Congyang | 783e9b4 | 2012-05-07 12:10:47 +0800 | [diff] [blame] | 1080 | bool has_begin = qdict_haskey(qdict, "begin"); |
| 1081 | bool has_length = qdict_haskey(qdict, "length"); |
| 1082 | int64_t begin = 0; |
| 1083 | int64_t length = 0; |
Luiz Capitulino | 7536376 | 2012-09-21 13:53:00 -0300 | [diff] [blame] | 1084 | char *prot; |
Wen Congyang | 783e9b4 | 2012-05-07 12:10:47 +0800 | [diff] [blame] | 1085 | |
| 1086 | if (has_begin) { |
| 1087 | begin = qdict_get_int(qdict, "begin"); |
| 1088 | } |
| 1089 | if (has_length) { |
| 1090 | length = qdict_get_int(qdict, "length"); |
| 1091 | } |
| 1092 | |
Luiz Capitulino | 7536376 | 2012-09-21 13:53:00 -0300 | [diff] [blame] | 1093 | prot = g_strconcat("file:", file, NULL); |
| 1094 | |
| 1095 | qmp_dump_guest_memory(paging, prot, has_begin, begin, has_length, length, |
Wen Congyang | 783e9b4 | 2012-05-07 12:10:47 +0800 | [diff] [blame] | 1096 | &errp); |
| 1097 | hmp_handle_error(mon, &errp); |
Luiz Capitulino | 7536376 | 2012-09-21 13:53:00 -0300 | [diff] [blame] | 1098 | g_free(prot); |
Wen Congyang | 783e9b4 | 2012-05-07 12:10:47 +0800 | [diff] [blame] | 1099 | } |
Luiz Capitulino | 928059a | 2012-04-18 17:34:15 -0300 | [diff] [blame] | 1100 | |
| 1101 | void hmp_netdev_add(Monitor *mon, const QDict *qdict) |
| 1102 | { |
| 1103 | Error *err = NULL; |
| 1104 | QemuOpts *opts; |
| 1105 | |
| 1106 | opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err); |
| 1107 | if (error_is_set(&err)) { |
| 1108 | goto out; |
| 1109 | } |
| 1110 | |
| 1111 | netdev_add(opts, &err); |
| 1112 | if (error_is_set(&err)) { |
| 1113 | qemu_opts_del(opts); |
| 1114 | } |
| 1115 | |
| 1116 | out: |
| 1117 | hmp_handle_error(mon, &err); |
| 1118 | } |
Luiz Capitulino | 5f96415 | 2012-04-16 14:36:32 -0300 | [diff] [blame] | 1119 | |
| 1120 | void hmp_netdev_del(Monitor *mon, const QDict *qdict) |
| 1121 | { |
| 1122 | const char *id = qdict_get_str(qdict, "id"); |
| 1123 | Error *err = NULL; |
| 1124 | |
| 1125 | qmp_netdev_del(id, &err); |
| 1126 | hmp_handle_error(mon, &err); |
| 1127 | } |
Corey Bryant | 208c9d1 | 2012-06-22 14:36:09 -0400 | [diff] [blame] | 1128 | |
| 1129 | void hmp_getfd(Monitor *mon, const QDict *qdict) |
| 1130 | { |
| 1131 | const char *fdname = qdict_get_str(qdict, "fdname"); |
| 1132 | Error *errp = NULL; |
| 1133 | |
| 1134 | qmp_getfd(fdname, &errp); |
| 1135 | hmp_handle_error(mon, &errp); |
| 1136 | } |
| 1137 | |
| 1138 | void hmp_closefd(Monitor *mon, const QDict *qdict) |
| 1139 | { |
| 1140 | const char *fdname = qdict_get_str(qdict, "fdname"); |
| 1141 | Error *errp = NULL; |
| 1142 | |
| 1143 | qmp_closefd(fdname, &errp); |
| 1144 | hmp_handle_error(mon, &errp); |
| 1145 | } |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1146 | |
| 1147 | void hmp_send_key(Monitor *mon, const QDict *qdict) |
| 1148 | { |
| 1149 | const char *keys = qdict_get_str(qdict, "keys"); |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 1150 | KeyValueList *keylist, *head = NULL, *tmp = NULL; |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1151 | int has_hold_time = qdict_haskey(qdict, "hold-time"); |
| 1152 | int hold_time = qdict_get_try_int(qdict, "hold-time", -1); |
| 1153 | Error *err = NULL; |
| 1154 | char keyname_buf[16]; |
| 1155 | char *separator; |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 1156 | int keyname_len; |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1157 | |
| 1158 | while (1) { |
| 1159 | separator = strchr(keys, '-'); |
| 1160 | keyname_len = separator ? separator - keys : strlen(keys); |
| 1161 | pstrcpy(keyname_buf, sizeof(keyname_buf), keys); |
| 1162 | |
| 1163 | /* Be compatible with old interface, convert user inputted "<" */ |
| 1164 | if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) { |
| 1165 | pstrcpy(keyname_buf, sizeof(keyname_buf), "less"); |
| 1166 | keyname_len = 4; |
| 1167 | } |
| 1168 | keyname_buf[keyname_len] = 0; |
| 1169 | |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1170 | keylist = g_malloc0(sizeof(*keylist)); |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 1171 | keylist->value = g_malloc0(sizeof(*keylist->value)); |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1172 | |
| 1173 | if (!head) { |
| 1174 | head = keylist; |
| 1175 | } |
| 1176 | if (tmp) { |
| 1177 | tmp->next = keylist; |
| 1178 | } |
| 1179 | tmp = keylist; |
| 1180 | |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 1181 | if (strstart(keyname_buf, "0x", NULL)) { |
| 1182 | char *endp; |
| 1183 | int value = strtoul(keyname_buf, &endp, 0); |
| 1184 | if (*endp != '\0') { |
| 1185 | goto err_out; |
| 1186 | } |
| 1187 | keylist->value->kind = KEY_VALUE_KIND_NUMBER; |
| 1188 | keylist->value->number = value; |
| 1189 | } else { |
| 1190 | int idx = index_from_key(keyname_buf); |
| 1191 | if (idx == Q_KEY_CODE_MAX) { |
| 1192 | goto err_out; |
| 1193 | } |
| 1194 | keylist->value->kind = KEY_VALUE_KIND_QCODE; |
| 1195 | keylist->value->qcode = idx; |
| 1196 | } |
| 1197 | |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1198 | if (!separator) { |
| 1199 | break; |
| 1200 | } |
| 1201 | keys = separator + 1; |
| 1202 | } |
| 1203 | |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 1204 | qmp_send_key(head, has_hold_time, hold_time, &err); |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1205 | hmp_handle_error(mon, &err); |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 1206 | |
| 1207 | out: |
| 1208 | qapi_free_KeyValueList(head); |
| 1209 | return; |
| 1210 | |
| 1211 | err_out: |
| 1212 | monitor_printf(mon, "invalid parameter: %s\n", keyname_buf); |
| 1213 | goto out; |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1214 | } |
Luiz Capitulino | ad39cf6 | 2012-05-24 13:48:23 -0300 | [diff] [blame] | 1215 | |
| 1216 | void hmp_screen_dump(Monitor *mon, const QDict *qdict) |
| 1217 | { |
| 1218 | const char *filename = qdict_get_str(qdict, "filename"); |
| 1219 | Error *err = NULL; |
| 1220 | |
| 1221 | qmp_screendump(filename, &err); |
| 1222 | hmp_handle_error(mon, &err); |
| 1223 | } |