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