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