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