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