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