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