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 | |
Peter Maydell | d38ea87 | 2016-01-29 17:50:05 +0000 | [diff] [blame^] | 16 | #include "qemu/osdep.h" |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 17 | #include "hmp.h" |
Paolo Bonzini | 1422e32 | 2012-10-24 08:43:34 +0200 | [diff] [blame] | 18 | #include "net/net.h" |
Scott Feldman | fafa4d5 | 2015-06-10 18:21:21 -0700 | [diff] [blame] | 19 | #include "net/eth.h" |
Paolo Bonzini | dccfcd0 | 2013-04-08 16:55:25 +0200 | [diff] [blame] | 20 | #include "sysemu/char.h" |
Max Reitz | 4c7b7e9 | 2015-02-05 13:58:22 -0500 | [diff] [blame] | 21 | #include "sysemu/block-backend.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 22 | #include "qemu/option.h" |
| 23 | #include "qemu/timer.h" |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 24 | #include "qmp-commands.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 25 | #include "qemu/sockets.h" |
Paolo Bonzini | 83c9089 | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 26 | #include "monitor/monitor.h" |
Markus Armbruster | 318660f | 2015-03-05 17:24:48 +0100 | [diff] [blame] | 27 | #include "monitor/qdev.h" |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 28 | #include "qapi/opts-visitor.h" |
Markus Armbruster | cc7a8ea | 2015-03-17 17:22:46 +0100 | [diff] [blame] | 29 | #include "qapi/qmp/qerror.h" |
Hu Tao | eb1539b | 2014-05-14 17:43:35 +0800 | [diff] [blame] | 30 | #include "qapi/string-output-visitor.h" |
Max Reitz | baead0a | 2015-10-26 21:39:18 +0100 | [diff] [blame] | 31 | #include "qapi/util.h" |
Hu Tao | eb1539b | 2014-05-14 17:43:35 +0800 | [diff] [blame] | 32 | #include "qapi-visit.h" |
Paolo Bonzini | 28ecbae | 2012-11-28 12:06:30 +0100 | [diff] [blame] | 33 | #include "ui/console.h" |
Wenchao Xia | bd093a3 | 2013-06-06 12:28:00 +0800 | [diff] [blame] | 34 | #include "block/qapi.h" |
Kevin Wolf | 587da2c | 2013-06-05 14:19:41 +0200 | [diff] [blame] | 35 | #include "qemu-io.h" |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 36 | |
Cole Robinson | 22fa7da | 2015-03-01 09:29:18 -0500 | [diff] [blame] | 37 | #ifdef CONFIG_SPICE |
| 38 | #include <spice/enums.h> |
| 39 | #endif |
| 40 | |
Luiz Capitulino | 0cfd6a9 | 2011-11-22 16:32:37 -0200 | [diff] [blame] | 41 | static void hmp_handle_error(Monitor *mon, Error **errp) |
| 42 | { |
Markus Armbruster | 415168e | 2014-05-02 13:26:34 +0200 | [diff] [blame] | 43 | assert(errp); |
| 44 | if (*errp) { |
Markus Armbruster | 193227f | 2015-12-18 16:35:06 +0100 | [diff] [blame] | 45 | error_report_err(*errp); |
Luiz Capitulino | 0cfd6a9 | 2011-11-22 16:32:37 -0200 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 49 | void hmp_info_name(Monitor *mon, const QDict *qdict) |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 50 | { |
| 51 | NameInfo *info; |
| 52 | |
| 53 | info = qmp_query_name(NULL); |
| 54 | if (info->has_name) { |
| 55 | monitor_printf(mon, "%s\n", info->name); |
| 56 | } |
| 57 | qapi_free_NameInfo(info); |
| 58 | } |
Luiz Capitulino | b9c15f1 | 2011-08-26 17:38:13 -0300 | [diff] [blame] | 59 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 60 | void hmp_info_version(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | b9c15f1 | 2011-08-26 17:38:13 -0300 | [diff] [blame] | 61 | { |
| 62 | VersionInfo *info; |
| 63 | |
| 64 | info = qmp_query_version(NULL); |
| 65 | |
| 66 | monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n", |
Eric Blake | 4752cdb | 2015-05-04 09:05:31 -0600 | [diff] [blame] | 67 | info->qemu->major, info->qemu->minor, info->qemu->micro, |
Luiz Capitulino | b9c15f1 | 2011-08-26 17:38:13 -0300 | [diff] [blame] | 68 | info->package); |
| 69 | |
| 70 | qapi_free_VersionInfo(info); |
| 71 | } |
Luiz Capitulino | 292a260 | 2011-09-12 15:10:53 -0300 | [diff] [blame] | 72 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 73 | void hmp_info_kvm(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | 292a260 | 2011-09-12 15:10:53 -0300 | [diff] [blame] | 74 | { |
| 75 | KvmInfo *info; |
| 76 | |
| 77 | info = qmp_query_kvm(NULL); |
| 78 | monitor_printf(mon, "kvm support: "); |
| 79 | if (info->present) { |
| 80 | monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled"); |
| 81 | } else { |
| 82 | monitor_printf(mon, "not compiled\n"); |
| 83 | } |
| 84 | |
| 85 | qapi_free_KvmInfo(info); |
| 86 | } |
| 87 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 88 | void hmp_info_status(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | 1fa9a5e | 2011-09-12 17:54:20 -0300 | [diff] [blame] | 89 | { |
| 90 | StatusInfo *info; |
| 91 | |
| 92 | info = qmp_query_status(NULL); |
| 93 | |
| 94 | monitor_printf(mon, "VM status: %s%s", |
| 95 | info->running ? "running" : "paused", |
| 96 | info->singlestep ? " (single step mode)" : ""); |
| 97 | |
| 98 | if (!info->running && info->status != RUN_STATE_PAUSED) { |
| 99 | monitor_printf(mon, " (%s)", RunState_lookup[info->status]); |
| 100 | } |
| 101 | |
| 102 | monitor_printf(mon, "\n"); |
| 103 | |
| 104 | qapi_free_StatusInfo(info); |
| 105 | } |
| 106 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 107 | void hmp_info_uuid(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | efab767 | 2011-09-13 17:16:25 -0300 | [diff] [blame] | 108 | { |
| 109 | UuidInfo *info; |
| 110 | |
| 111 | info = qmp_query_uuid(NULL); |
| 112 | monitor_printf(mon, "%s\n", info->UUID); |
| 113 | qapi_free_UuidInfo(info); |
| 114 | } |
Luiz Capitulino | c5a415a | 2011-09-14 16:05:49 -0300 | [diff] [blame] | 115 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 116 | void hmp_info_chardev(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | c5a415a | 2011-09-14 16:05:49 -0300 | [diff] [blame] | 117 | { |
| 118 | ChardevInfoList *char_info, *info; |
| 119 | |
| 120 | char_info = qmp_query_chardev(NULL); |
| 121 | for (info = char_info; info; info = info->next) { |
| 122 | monitor_printf(mon, "%s: filename=%s\n", info->value->label, |
| 123 | info->value->filename); |
| 124 | } |
| 125 | |
| 126 | qapi_free_ChardevInfoList(char_info); |
| 127 | } |
Luiz Capitulino | 7a7f325 | 2011-09-15 14:20:28 -0300 | [diff] [blame] | 128 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 129 | void hmp_info_mice(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | e235cec | 2011-09-21 15:29:55 -0300 | [diff] [blame] | 130 | { |
| 131 | MouseInfoList *mice_list, *mouse; |
| 132 | |
| 133 | mice_list = qmp_query_mice(NULL); |
| 134 | if (!mice_list) { |
| 135 | monitor_printf(mon, "No mouse devices connected\n"); |
| 136 | return; |
| 137 | } |
| 138 | |
| 139 | for (mouse = mice_list; mouse; mouse = mouse->next) { |
| 140 | monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n", |
| 141 | mouse->value->current ? '*' : ' ', |
| 142 | mouse->value->index, mouse->value->name, |
| 143 | mouse->value->absolute ? " (absolute)" : ""); |
| 144 | } |
| 145 | |
| 146 | qapi_free_MouseInfoList(mice_list); |
| 147 | } |
| 148 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 149 | void hmp_info_migrate(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 150 | { |
| 151 | MigrationInfo *info; |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 152 | MigrationCapabilityStatusList *caps, *cap; |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 153 | |
| 154 | info = qmp_query_migrate(NULL); |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 155 | caps = qmp_query_migrate_capabilities(NULL); |
| 156 | |
| 157 | /* do not display parameters during setup */ |
| 158 | if (info->has_status && caps) { |
| 159 | monitor_printf(mon, "capabilities: "); |
| 160 | for (cap = caps; cap; cap = cap->next) { |
| 161 | monitor_printf(mon, "%s: %s ", |
| 162 | MigrationCapability_lookup[cap->value->capability], |
| 163 | cap->value->state ? "on" : "off"); |
| 164 | } |
| 165 | monitor_printf(mon, "\n"); |
| 166 | } |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 167 | |
| 168 | if (info->has_status) { |
zhanghailiang | 24b8c39 | 2015-03-13 16:08:40 +0800 | [diff] [blame] | 169 | monitor_printf(mon, "Migration status: %s\n", |
| 170 | MigrationStatus_lookup[info->status]); |
Juan Quintela | 7aa939a | 2012-08-18 13:17:10 +0200 | [diff] [blame] | 171 | monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n", |
| 172 | info->total_time); |
Juan Quintela | 2c52ddf | 2012-08-13 09:53:12 +0200 | [diff] [blame] | 173 | if (info->has_expected_downtime) { |
| 174 | monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n", |
| 175 | info->expected_downtime); |
| 176 | } |
Juan Quintela | 9c5a9fc | 2012-08-13 09:35:16 +0200 | [diff] [blame] | 177 | if (info->has_downtime) { |
| 178 | monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n", |
| 179 | info->downtime); |
| 180 | } |
Michael R. Hines | ed4fbd1 | 2013-07-22 10:01:58 -0400 | [diff] [blame] | 181 | if (info->has_setup_time) { |
| 182 | monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n", |
| 183 | info->setup_time); |
| 184 | } |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | if (info->has_ram) { |
| 188 | monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n", |
| 189 | info->ram->transferred >> 10); |
Michael R. Hines | 7e114f8 | 2013-06-25 21:35:30 -0400 | [diff] [blame] | 190 | monitor_printf(mon, "throughput: %0.2f mbps\n", |
| 191 | info->ram->mbps); |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 192 | monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n", |
| 193 | info->ram->remaining >> 10); |
| 194 | monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n", |
| 195 | info->ram->total >> 10); |
Orit Wasserman | 004d4c1 | 2012-08-06 21:42:56 +0300 | [diff] [blame] | 196 | monitor_printf(mon, "duplicate: %" PRIu64 " pages\n", |
| 197 | info->ram->duplicate); |
Peter Lieven | f1c7279 | 2013-03-26 10:58:37 +0100 | [diff] [blame] | 198 | monitor_printf(mon, "skipped: %" PRIu64 " pages\n", |
| 199 | info->ram->skipped); |
Orit Wasserman | 004d4c1 | 2012-08-06 21:42:56 +0300 | [diff] [blame] | 200 | monitor_printf(mon, "normal: %" PRIu64 " pages\n", |
| 201 | info->ram->normal); |
| 202 | monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n", |
| 203 | info->ram->normal_bytes >> 10); |
ChenLiang | 58570ed | 2014-04-04 17:57:55 +0800 | [diff] [blame] | 204 | monitor_printf(mon, "dirty sync count: %" PRIu64 "\n", |
| 205 | info->ram->dirty_sync_count); |
Juan Quintela | 8d01719 | 2012-08-13 12:31:25 +0200 | [diff] [blame] | 206 | if (info->ram->dirty_pages_rate) { |
| 207 | monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n", |
| 208 | info->ram->dirty_pages_rate); |
| 209 | } |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | if (info->has_disk) { |
| 213 | monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n", |
| 214 | info->disk->transferred >> 10); |
| 215 | monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n", |
| 216 | info->disk->remaining >> 10); |
| 217 | monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n", |
| 218 | info->disk->total >> 10); |
| 219 | } |
| 220 | |
Orit Wasserman | f36d55a | 2012-08-06 21:42:57 +0300 | [diff] [blame] | 221 | if (info->has_xbzrle_cache) { |
| 222 | monitor_printf(mon, "cache size: %" PRIu64 " bytes\n", |
| 223 | info->xbzrle_cache->cache_size); |
| 224 | monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n", |
| 225 | info->xbzrle_cache->bytes >> 10); |
| 226 | monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n", |
| 227 | info->xbzrle_cache->pages); |
| 228 | monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n", |
| 229 | info->xbzrle_cache->cache_miss); |
ChenLiang | 8bc3923 | 2014-04-04 17:57:56 +0800 | [diff] [blame] | 230 | monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n", |
| 231 | info->xbzrle_cache->cache_miss_rate); |
Orit Wasserman | f36d55a | 2012-08-06 21:42:57 +0300 | [diff] [blame] | 232 | monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n", |
| 233 | info->xbzrle_cache->overflow); |
| 234 | } |
| 235 | |
Jason J. Herne | 4782893 | 2015-09-08 13:12:36 -0400 | [diff] [blame] | 236 | if (info->has_x_cpu_throttle_percentage) { |
| 237 | monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n", |
| 238 | info->x_cpu_throttle_percentage); |
| 239 | } |
| 240 | |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 241 | qapi_free_MigrationInfo(info); |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 242 | qapi_free_MigrationCapabilityStatusList(caps); |
| 243 | } |
| 244 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 245 | void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict) |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 246 | { |
| 247 | MigrationCapabilityStatusList *caps, *cap; |
| 248 | |
| 249 | caps = qmp_query_migrate_capabilities(NULL); |
| 250 | |
| 251 | if (caps) { |
| 252 | monitor_printf(mon, "capabilities: "); |
| 253 | for (cap = caps; cap; cap = cap->next) { |
| 254 | monitor_printf(mon, "%s: %s ", |
| 255 | MigrationCapability_lookup[cap->value->capability], |
| 256 | cap->value->state ? "on" : "off"); |
| 257 | } |
| 258 | monitor_printf(mon, "\n"); |
| 259 | } |
| 260 | |
| 261 | qapi_free_MigrationCapabilityStatusList(caps); |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 262 | } |
| 263 | |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 264 | void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) |
| 265 | { |
| 266 | MigrationParameters *params; |
| 267 | |
| 268 | params = qmp_query_migrate_parameters(NULL); |
| 269 | |
| 270 | if (params) { |
| 271 | monitor_printf(mon, "parameters:"); |
| 272 | monitor_printf(mon, " %s: %" PRId64, |
| 273 | MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_LEVEL], |
| 274 | params->compress_level); |
| 275 | monitor_printf(mon, " %s: %" PRId64, |
| 276 | MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_THREADS], |
| 277 | params->compress_threads); |
| 278 | monitor_printf(mon, " %s: %" PRId64, |
| 279 | MigrationParameter_lookup[MIGRATION_PARAMETER_DECOMPRESS_THREADS], |
| 280 | params->decompress_threads); |
Jason J. Herne | 1626fee | 2015-09-08 13:12:34 -0400 | [diff] [blame] | 281 | monitor_printf(mon, " %s: %" PRId64, |
| 282 | MigrationParameter_lookup[MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL], |
| 283 | params->x_cpu_throttle_initial); |
| 284 | monitor_printf(mon, " %s: %" PRId64, |
| 285 | MigrationParameter_lookup[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT], |
| 286 | params->x_cpu_throttle_increment); |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 287 | monitor_printf(mon, "\n"); |
| 288 | } |
| 289 | |
| 290 | qapi_free_MigrationParameters(params); |
| 291 | } |
| 292 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 293 | void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict) |
Orit Wasserman | 9e1ba4c | 2012-08-06 21:42:54 +0300 | [diff] [blame] | 294 | { |
| 295 | monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n", |
| 296 | qmp_query_migrate_cache_size(NULL) >> 10); |
| 297 | } |
| 298 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 299 | void hmp_info_cpus(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | de0b36b | 2011-09-21 16:38:35 -0300 | [diff] [blame] | 300 | { |
| 301 | CpuInfoList *cpu_list, *cpu; |
| 302 | |
| 303 | cpu_list = qmp_query_cpus(NULL); |
| 304 | |
| 305 | for (cpu = cpu_list; cpu; cpu = cpu->next) { |
| 306 | int active = ' '; |
| 307 | |
| 308 | if (cpu->value->CPU == monitor_get_cpu_index()) { |
| 309 | active = '*'; |
| 310 | } |
| 311 | |
Aurelien Jarno | 852bef0 | 2012-10-19 23:19:19 +0200 | [diff] [blame] | 312 | monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU); |
Luiz Capitulino | de0b36b | 2011-09-21 16:38:35 -0300 | [diff] [blame] | 313 | |
Eric Blake | 86f4b68 | 2015-11-18 01:52:59 -0700 | [diff] [blame] | 314 | switch (cpu->value->arch) { |
| 315 | case CPU_INFO_ARCH_X86: |
| 316 | monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->u.x86->pc); |
| 317 | break; |
| 318 | case CPU_INFO_ARCH_PPC: |
| 319 | monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->u.ppc->nip); |
| 320 | break; |
| 321 | case CPU_INFO_ARCH_SPARC: |
| 322 | monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->u.sparc->pc); |
| 323 | monitor_printf(mon, " npc=0x%016" PRIx64, cpu->value->u.sparc->npc); |
| 324 | break; |
| 325 | case CPU_INFO_ARCH_MIPS: |
| 326 | monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.mips->PC); |
| 327 | break; |
| 328 | case CPU_INFO_ARCH_TRICORE: |
| 329 | monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.tricore->PC); |
| 330 | break; |
| 331 | default: |
| 332 | break; |
Luiz Capitulino | de0b36b | 2011-09-21 16:38:35 -0300 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | if (cpu->value->halted) { |
| 336 | monitor_printf(mon, " (halted)"); |
| 337 | } |
| 338 | |
| 339 | monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id); |
| 340 | } |
| 341 | |
| 342 | qapi_free_CpuInfoList(cpu_list); |
| 343 | } |
| 344 | |
Kevin Wolf | 289b276 | 2014-09-15 12:06:39 +0200 | [diff] [blame] | 345 | static void print_block_info(Monitor *mon, BlockInfo *info, |
| 346 | BlockDeviceInfo *inserted, bool verbose) |
| 347 | { |
| 348 | ImageInfo *image_info; |
| 349 | |
Kevin Wolf | 8d6adcc | 2014-09-15 12:12:52 +0200 | [diff] [blame] | 350 | assert(!info || !info->has_inserted || info->inserted == inserted); |
| 351 | |
| 352 | if (info) { |
| 353 | monitor_printf(mon, "%s", info->device); |
| 354 | if (inserted && inserted->has_node_name) { |
| 355 | monitor_printf(mon, " (%s)", inserted->node_name); |
| 356 | } |
| 357 | } else { |
| 358 | assert(inserted); |
| 359 | monitor_printf(mon, "%s", |
| 360 | inserted->has_node_name |
| 361 | ? inserted->node_name |
| 362 | : "<anonymous>"); |
| 363 | } |
| 364 | |
Kevin Wolf | 289b276 | 2014-09-15 12:06:39 +0200 | [diff] [blame] | 365 | if (inserted) { |
| 366 | monitor_printf(mon, ": %s (%s%s%s)\n", |
| 367 | inserted->file, |
| 368 | inserted->drv, |
| 369 | inserted->ro ? ", read-only" : "", |
| 370 | inserted->encrypted ? ", encrypted" : ""); |
| 371 | } else { |
| 372 | monitor_printf(mon, ": [not inserted]\n"); |
| 373 | } |
| 374 | |
Kevin Wolf | 8d6adcc | 2014-09-15 12:12:52 +0200 | [diff] [blame] | 375 | if (info) { |
| 376 | if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) { |
| 377 | monitor_printf(mon, " I/O status: %s\n", |
| 378 | BlockDeviceIoStatus_lookup[info->io_status]); |
| 379 | } |
Kevin Wolf | 289b276 | 2014-09-15 12:06:39 +0200 | [diff] [blame] | 380 | |
Kevin Wolf | 8d6adcc | 2014-09-15 12:12:52 +0200 | [diff] [blame] | 381 | if (info->removable) { |
| 382 | monitor_printf(mon, " Removable device: %slocked, tray %s\n", |
| 383 | info->locked ? "" : "not ", |
| 384 | info->tray_open ? "open" : "closed"); |
| 385 | } |
Kevin Wolf | 289b276 | 2014-09-15 12:06:39 +0200 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | |
| 389 | if (!inserted) { |
| 390 | return; |
| 391 | } |
| 392 | |
| 393 | monitor_printf(mon, " Cache mode: %s%s%s\n", |
| 394 | inserted->cache->writeback ? "writeback" : "writethrough", |
| 395 | inserted->cache->direct ? ", direct" : "", |
| 396 | inserted->cache->no_flush ? ", ignore flushes" : ""); |
| 397 | |
| 398 | if (inserted->has_backing_file) { |
| 399 | monitor_printf(mon, |
| 400 | " Backing file: %s " |
| 401 | "(chain depth: %" PRId64 ")\n", |
| 402 | inserted->backing_file, |
| 403 | inserted->backing_file_depth); |
| 404 | } |
| 405 | |
| 406 | if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) { |
| 407 | monitor_printf(mon, " Detect zeroes: %s\n", |
| 408 | BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]); |
| 409 | } |
| 410 | |
| 411 | if (inserted->bps || inserted->bps_rd || inserted->bps_wr || |
| 412 | inserted->iops || inserted->iops_rd || inserted->iops_wr) |
| 413 | { |
| 414 | monitor_printf(mon, " I/O throttling: bps=%" PRId64 |
| 415 | " bps_rd=%" PRId64 " bps_wr=%" PRId64 |
| 416 | " bps_max=%" PRId64 |
| 417 | " bps_rd_max=%" PRId64 |
| 418 | " bps_wr_max=%" PRId64 |
| 419 | " iops=%" PRId64 " iops_rd=%" PRId64 |
| 420 | " iops_wr=%" PRId64 |
| 421 | " iops_max=%" PRId64 |
| 422 | " iops_rd_max=%" PRId64 |
| 423 | " iops_wr_max=%" PRId64 |
Alberto Garcia | b8fe169 | 2015-06-08 18:17:46 +0200 | [diff] [blame] | 424 | " iops_size=%" PRId64 |
| 425 | " group=%s\n", |
Kevin Wolf | 289b276 | 2014-09-15 12:06:39 +0200 | [diff] [blame] | 426 | inserted->bps, |
| 427 | inserted->bps_rd, |
| 428 | inserted->bps_wr, |
| 429 | inserted->bps_max, |
| 430 | inserted->bps_rd_max, |
| 431 | inserted->bps_wr_max, |
| 432 | inserted->iops, |
| 433 | inserted->iops_rd, |
| 434 | inserted->iops_wr, |
| 435 | inserted->iops_max, |
| 436 | inserted->iops_rd_max, |
| 437 | inserted->iops_wr_max, |
Alberto Garcia | b8fe169 | 2015-06-08 18:17:46 +0200 | [diff] [blame] | 438 | inserted->iops_size, |
| 439 | inserted->group); |
Kevin Wolf | 289b276 | 2014-09-15 12:06:39 +0200 | [diff] [blame] | 440 | } |
| 441 | |
Stefan Hajnoczi | 9419874 | 2015-04-22 11:15:10 +0100 | [diff] [blame] | 442 | if (verbose) { |
Kevin Wolf | 289b276 | 2014-09-15 12:06:39 +0200 | [diff] [blame] | 443 | monitor_printf(mon, "\nImages:\n"); |
| 444 | image_info = inserted->image; |
| 445 | while (1) { |
| 446 | bdrv_image_info_dump((fprintf_function)monitor_printf, |
| 447 | mon, image_info); |
| 448 | if (image_info->has_backing_image) { |
| 449 | image_info = image_info->backing_image; |
| 450 | } else { |
| 451 | break; |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 457 | void hmp_info_block(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | b202381 | 2011-09-21 17:16:47 -0300 | [diff] [blame] | 458 | { |
| 459 | BlockInfoList *block_list, *info; |
Kevin Wolf | e6bb31e | 2014-09-15 12:19:14 +0200 | [diff] [blame] | 460 | BlockDeviceInfoList *blockdev_list, *blockdev; |
Wenchao Xia | e73fe2b | 2013-06-06 12:28:01 +0800 | [diff] [blame] | 461 | const char *device = qdict_get_try_str(qdict, "device"); |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 462 | bool verbose = qdict_get_try_bool(qdict, "verbose", false); |
| 463 | bool nodes = qdict_get_try_bool(qdict, "nodes", false); |
Kevin Wolf | e6bb31e | 2014-09-15 12:19:14 +0200 | [diff] [blame] | 464 | bool printed = false; |
Luiz Capitulino | b202381 | 2011-09-21 17:16:47 -0300 | [diff] [blame] | 465 | |
Kevin Wolf | e6bb31e | 2014-09-15 12:19:14 +0200 | [diff] [blame] | 466 | /* Print BlockBackend information */ |
| 467 | if (!nodes) { |
Stefan Weil | f19e44b | 2015-02-08 15:40:48 +0100 | [diff] [blame] | 468 | block_list = qmp_query_block(NULL); |
Kevin Wolf | e6bb31e | 2014-09-15 12:19:14 +0200 | [diff] [blame] | 469 | } else { |
| 470 | block_list = NULL; |
| 471 | } |
Luiz Capitulino | b202381 | 2011-09-21 17:16:47 -0300 | [diff] [blame] | 472 | |
| 473 | for (info = block_list; info; info = info->next) { |
Wenchao Xia | e73fe2b | 2013-06-06 12:28:01 +0800 | [diff] [blame] | 474 | if (device && strcmp(device, info->value->device)) { |
| 475 | continue; |
| 476 | } |
Luiz Capitulino | b202381 | 2011-09-21 17:16:47 -0300 | [diff] [blame] | 477 | |
Kevin Wolf | fbe2e26 | 2013-06-19 16:10:55 +0200 | [diff] [blame] | 478 | if (info != block_list) { |
| 479 | monitor_printf(mon, "\n"); |
Luiz Capitulino | b202381 | 2011-09-21 17:16:47 -0300 | [diff] [blame] | 480 | } |
| 481 | |
Kevin Wolf | 289b276 | 2014-09-15 12:06:39 +0200 | [diff] [blame] | 482 | print_block_info(mon, info->value, info->value->has_inserted |
| 483 | ? info->value->inserted : NULL, |
| 484 | verbose); |
Kevin Wolf | e6bb31e | 2014-09-15 12:19:14 +0200 | [diff] [blame] | 485 | printed = true; |
Luiz Capitulino | b202381 | 2011-09-21 17:16:47 -0300 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | qapi_free_BlockInfoList(block_list); |
Kevin Wolf | e6bb31e | 2014-09-15 12:19:14 +0200 | [diff] [blame] | 489 | |
| 490 | if ((!device && !nodes) || printed) { |
| 491 | return; |
| 492 | } |
| 493 | |
| 494 | /* Print node information */ |
| 495 | blockdev_list = qmp_query_named_block_nodes(NULL); |
| 496 | for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) { |
| 497 | assert(blockdev->value->has_node_name); |
| 498 | if (device && strcmp(device, blockdev->value->node_name)) { |
| 499 | continue; |
| 500 | } |
| 501 | |
| 502 | if (blockdev != blockdev_list) { |
| 503 | monitor_printf(mon, "\n"); |
| 504 | } |
| 505 | |
| 506 | print_block_info(mon, NULL, blockdev->value, verbose); |
| 507 | } |
| 508 | qapi_free_BlockDeviceInfoList(blockdev_list); |
Luiz Capitulino | b202381 | 2011-09-21 17:16:47 -0300 | [diff] [blame] | 509 | } |
| 510 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 511 | void hmp_info_blockstats(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | f11f57e | 2011-09-22 15:56:36 -0300 | [diff] [blame] | 512 | { |
| 513 | BlockStatsList *stats_list, *stats; |
| 514 | |
Fam Zheng | f71eaa7 | 2014-10-31 11:32:57 +0800 | [diff] [blame] | 515 | stats_list = qmp_query_blockstats(false, false, NULL); |
Luiz Capitulino | f11f57e | 2011-09-22 15:56:36 -0300 | [diff] [blame] | 516 | |
| 517 | for (stats = stats_list; stats; stats = stats->next) { |
| 518 | if (!stats->value->has_device) { |
| 519 | continue; |
| 520 | } |
| 521 | |
| 522 | monitor_printf(mon, "%s:", stats->value->device); |
| 523 | monitor_printf(mon, " rd_bytes=%" PRId64 |
| 524 | " wr_bytes=%" PRId64 |
| 525 | " rd_operations=%" PRId64 |
| 526 | " wr_operations=%" PRId64 |
| 527 | " flush_operations=%" PRId64 |
| 528 | " wr_total_time_ns=%" PRId64 |
| 529 | " rd_total_time_ns=%" PRId64 |
| 530 | " flush_total_time_ns=%" PRId64 |
Peter Lieven | f4564d5 | 2015-02-02 14:52:18 +0100 | [diff] [blame] | 531 | " rd_merged=%" PRId64 |
| 532 | " wr_merged=%" PRId64 |
Alberto Garcia | cb38fff | 2015-10-28 17:33:02 +0200 | [diff] [blame] | 533 | " idle_time_ns=%" PRId64 |
Luiz Capitulino | f11f57e | 2011-09-22 15:56:36 -0300 | [diff] [blame] | 534 | "\n", |
| 535 | stats->value->stats->rd_bytes, |
| 536 | stats->value->stats->wr_bytes, |
| 537 | stats->value->stats->rd_operations, |
| 538 | stats->value->stats->wr_operations, |
| 539 | stats->value->stats->flush_operations, |
| 540 | stats->value->stats->wr_total_time_ns, |
| 541 | stats->value->stats->rd_total_time_ns, |
Peter Lieven | f4564d5 | 2015-02-02 14:52:18 +0100 | [diff] [blame] | 542 | stats->value->stats->flush_total_time_ns, |
| 543 | stats->value->stats->rd_merged, |
Alberto Garcia | cb38fff | 2015-10-28 17:33:02 +0200 | [diff] [blame] | 544 | stats->value->stats->wr_merged, |
| 545 | stats->value->stats->idle_time_ns); |
Luiz Capitulino | f11f57e | 2011-09-22 15:56:36 -0300 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | qapi_free_BlockStatsList(stats_list); |
| 549 | } |
| 550 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 551 | void hmp_info_vnc(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 552 | { |
| 553 | VncInfo *info; |
| 554 | Error *err = NULL; |
| 555 | VncClientInfoList *client; |
| 556 | |
| 557 | info = qmp_query_vnc(&err); |
| 558 | if (err) { |
Markus Armbruster | 193227f | 2015-12-18 16:35:06 +0100 | [diff] [blame] | 559 | error_report_err(err); |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 560 | return; |
| 561 | } |
| 562 | |
| 563 | if (!info->enabled) { |
| 564 | monitor_printf(mon, "Server: disabled\n"); |
| 565 | goto out; |
| 566 | } |
| 567 | |
| 568 | monitor_printf(mon, "Server:\n"); |
| 569 | if (info->has_host && info->has_service) { |
| 570 | monitor_printf(mon, " address: %s:%s\n", info->host, info->service); |
| 571 | } |
| 572 | if (info->has_auth) { |
| 573 | monitor_printf(mon, " auth: %s\n", info->auth); |
| 574 | } |
| 575 | |
| 576 | if (!info->has_clients || info->clients == NULL) { |
| 577 | monitor_printf(mon, "Client: none\n"); |
| 578 | } else { |
| 579 | for (client = info->clients; client; client = client->next) { |
| 580 | monitor_printf(mon, "Client:\n"); |
| 581 | monitor_printf(mon, " address: %s:%s\n", |
Eric Blake | ddf2190 | 2015-10-26 16:34:49 -0600 | [diff] [blame] | 582 | client->value->host, |
| 583 | client->value->service); |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 584 | monitor_printf(mon, " x509_dname: %s\n", |
| 585 | client->value->x509_dname ? |
| 586 | client->value->x509_dname : "none"); |
| 587 | monitor_printf(mon, " username: %s\n", |
| 588 | client->value->has_sasl_username ? |
| 589 | client->value->sasl_username : "none"); |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | out: |
| 594 | qapi_free_VncInfo(info); |
| 595 | } |
| 596 | |
Markus Armbruster | 206addd | 2015-01-13 15:46:39 +0100 | [diff] [blame] | 597 | #ifdef CONFIG_SPICE |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 598 | void hmp_info_spice(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 599 | { |
| 600 | SpiceChannelList *chan; |
| 601 | SpiceInfo *info; |
Cole Robinson | 22fa7da | 2015-03-01 09:29:18 -0500 | [diff] [blame] | 602 | const char *channel_name; |
| 603 | const char * const channel_names[] = { |
| 604 | [SPICE_CHANNEL_MAIN] = "main", |
| 605 | [SPICE_CHANNEL_DISPLAY] = "display", |
| 606 | [SPICE_CHANNEL_INPUTS] = "inputs", |
| 607 | [SPICE_CHANNEL_CURSOR] = "cursor", |
| 608 | [SPICE_CHANNEL_PLAYBACK] = "playback", |
| 609 | [SPICE_CHANNEL_RECORD] = "record", |
| 610 | [SPICE_CHANNEL_TUNNEL] = "tunnel", |
| 611 | [SPICE_CHANNEL_SMARTCARD] = "smartcard", |
| 612 | [SPICE_CHANNEL_USBREDIR] = "usbredir", |
| 613 | [SPICE_CHANNEL_PORT] = "port", |
Gerd Hoffmann | 7c6044a | 2015-03-03 09:27:28 +0100 | [diff] [blame] | 614 | #if 0 |
| 615 | /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7, |
| 616 | * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable |
| 617 | * as quick fix for build failures with older versions. */ |
Cole Robinson | 22fa7da | 2015-03-01 09:29:18 -0500 | [diff] [blame] | 618 | [SPICE_CHANNEL_WEBDAV] = "webdav", |
Gerd Hoffmann | 7c6044a | 2015-03-03 09:27:28 +0100 | [diff] [blame] | 619 | #endif |
Cole Robinson | 22fa7da | 2015-03-01 09:29:18 -0500 | [diff] [blame] | 620 | }; |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 621 | |
| 622 | info = qmp_query_spice(NULL); |
| 623 | |
| 624 | if (!info->enabled) { |
| 625 | monitor_printf(mon, "Server: disabled\n"); |
| 626 | goto out; |
| 627 | } |
| 628 | |
| 629 | monitor_printf(mon, "Server:\n"); |
| 630 | if (info->has_port) { |
| 631 | monitor_printf(mon, " address: %s:%" PRId64 "\n", |
| 632 | info->host, info->port); |
| 633 | } |
| 634 | if (info->has_tls_port) { |
| 635 | monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n", |
| 636 | info->host, info->tls_port); |
| 637 | } |
Yonit Halperin | 61c4efe | 2012-08-21 11:51:58 +0300 | [diff] [blame] | 638 | monitor_printf(mon, " migrated: %s\n", |
| 639 | info->migrated ? "true" : "false"); |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 640 | monitor_printf(mon, " auth: %s\n", info->auth); |
| 641 | monitor_printf(mon, " compiled: %s\n", info->compiled_version); |
Alon Levy | 4efee02 | 2012-03-29 23:23:14 +0200 | [diff] [blame] | 642 | monitor_printf(mon, " mouse-mode: %s\n", |
| 643 | SpiceQueryMouseMode_lookup[info->mouse_mode]); |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 644 | |
| 645 | if (!info->has_channels || info->channels == NULL) { |
| 646 | monitor_printf(mon, "Channels: none\n"); |
| 647 | } else { |
| 648 | for (chan = info->channels; chan; chan = chan->next) { |
| 649 | monitor_printf(mon, "Channel:\n"); |
| 650 | monitor_printf(mon, " address: %s:%s%s\n", |
Eric Blake | ddf2190 | 2015-10-26 16:34:49 -0600 | [diff] [blame] | 651 | chan->value->host, chan->value->port, |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 652 | chan->value->tls ? " [tls]" : ""); |
| 653 | monitor_printf(mon, " session: %" PRId64 "\n", |
| 654 | chan->value->connection_id); |
| 655 | monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n", |
| 656 | chan->value->channel_type, chan->value->channel_id); |
Cole Robinson | 22fa7da | 2015-03-01 09:29:18 -0500 | [diff] [blame] | 657 | |
| 658 | channel_name = "unknown"; |
| 659 | if (chan->value->channel_type > 0 && |
| 660 | chan->value->channel_type < ARRAY_SIZE(channel_names) && |
| 661 | channel_names[chan->value->channel_type]) { |
| 662 | channel_name = channel_names[chan->value->channel_type]; |
| 663 | } |
| 664 | |
| 665 | monitor_printf(mon, " channel name: %s\n", channel_name); |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 666 | } |
| 667 | } |
| 668 | |
| 669 | out: |
| 670 | qapi_free_SpiceInfo(info); |
| 671 | } |
Markus Armbruster | 206addd | 2015-01-13 15:46:39 +0100 | [diff] [blame] | 672 | #endif |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 673 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 674 | void hmp_info_balloon(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | 96637bc | 2011-10-21 11:41:37 -0200 | [diff] [blame] | 675 | { |
| 676 | BalloonInfo *info; |
| 677 | Error *err = NULL; |
| 678 | |
| 679 | info = qmp_query_balloon(&err); |
| 680 | if (err) { |
Markus Armbruster | 193227f | 2015-12-18 16:35:06 +0100 | [diff] [blame] | 681 | error_report_err(err); |
Luiz Capitulino | 96637bc | 2011-10-21 11:41:37 -0200 | [diff] [blame] | 682 | return; |
| 683 | } |
| 684 | |
Luiz Capitulino | 01ceb97 | 2012-12-03 15:56:41 -0200 | [diff] [blame] | 685 | monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20); |
Luiz Capitulino | 96637bc | 2011-10-21 11:41:37 -0200 | [diff] [blame] | 686 | |
| 687 | qapi_free_BalloonInfo(info); |
| 688 | } |
| 689 | |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 690 | static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) |
| 691 | { |
| 692 | PciMemoryRegionList *region; |
| 693 | |
| 694 | monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus); |
| 695 | monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n", |
| 696 | dev->slot, dev->function); |
| 697 | monitor_printf(mon, " "); |
| 698 | |
Eric Blake | 9fa02cd | 2015-05-04 09:05:32 -0600 | [diff] [blame] | 699 | if (dev->class_info->has_desc) { |
| 700 | monitor_printf(mon, "%s", dev->class_info->desc); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 701 | } else { |
Eric Blake | 9fa02cd | 2015-05-04 09:05:32 -0600 | [diff] [blame] | 702 | monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n", |
Eric Blake | 9fa02cd | 2015-05-04 09:05:32 -0600 | [diff] [blame] | 706 | dev->id->vendor, dev->id->device); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 707 | |
| 708 | if (dev->has_irq) { |
| 709 | monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq); |
| 710 | } |
| 711 | |
| 712 | if (dev->has_pci_bridge) { |
| 713 | monitor_printf(mon, " BUS %" PRId64 ".\n", |
Eric Blake | 9fa02cd | 2015-05-04 09:05:32 -0600 | [diff] [blame] | 714 | dev->pci_bridge->bus->number); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 715 | monitor_printf(mon, " secondary bus %" PRId64 ".\n", |
Eric Blake | 9fa02cd | 2015-05-04 09:05:32 -0600 | [diff] [blame] | 716 | dev->pci_bridge->bus->secondary); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 717 | monitor_printf(mon, " subordinate bus %" PRId64 ".\n", |
Eric Blake | 9fa02cd | 2015-05-04 09:05:32 -0600 | [diff] [blame] | 718 | dev->pci_bridge->bus->subordinate); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 719 | |
| 720 | monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n", |
Eric Blake | 9fa02cd | 2015-05-04 09:05:32 -0600 | [diff] [blame] | 721 | dev->pci_bridge->bus->io_range->base, |
| 722 | dev->pci_bridge->bus->io_range->limit); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 723 | |
| 724 | monitor_printf(mon, |
| 725 | " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n", |
Eric Blake | 9fa02cd | 2015-05-04 09:05:32 -0600 | [diff] [blame] | 726 | dev->pci_bridge->bus->memory_range->base, |
| 727 | dev->pci_bridge->bus->memory_range->limit); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 728 | |
| 729 | monitor_printf(mon, " prefetchable memory range " |
| 730 | "[0x%08"PRIx64", 0x%08"PRIx64"]\n", |
Eric Blake | 9fa02cd | 2015-05-04 09:05:32 -0600 | [diff] [blame] | 731 | dev->pci_bridge->bus->prefetchable_range->base, |
| 732 | dev->pci_bridge->bus->prefetchable_range->limit); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | for (region = dev->regions; region; region = region->next) { |
| 736 | uint64_t addr, size; |
| 737 | |
| 738 | addr = region->value->address; |
| 739 | size = region->value->size; |
| 740 | |
| 741 | monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar); |
| 742 | |
| 743 | if (!strcmp(region->value->type, "io")) { |
| 744 | monitor_printf(mon, "I/O at 0x%04" PRIx64 |
| 745 | " [0x%04" PRIx64 "].\n", |
| 746 | addr, addr + size - 1); |
| 747 | } else { |
| 748 | monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64 |
| 749 | " [0x%08" PRIx64 "].\n", |
| 750 | region->value->mem_type_64 ? 64 : 32, |
| 751 | region->value->prefetch ? " prefetchable" : "", |
| 752 | addr, addr + size - 1); |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | monitor_printf(mon, " id \"%s\"\n", dev->qdev_id); |
| 757 | |
| 758 | if (dev->has_pci_bridge) { |
| 759 | if (dev->pci_bridge->has_devices) { |
| 760 | PciDeviceInfoList *cdev; |
| 761 | for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) { |
| 762 | hmp_info_pci_device(mon, cdev->value); |
| 763 | } |
| 764 | } |
| 765 | } |
| 766 | } |
| 767 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 768 | void hmp_info_pci(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 769 | { |
Stefan Berger | f46cee3 | 2012-01-11 10:51:52 -0500 | [diff] [blame] | 770 | PciInfoList *info_list, *info; |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 771 | Error *err = NULL; |
| 772 | |
Stefan Berger | f46cee3 | 2012-01-11 10:51:52 -0500 | [diff] [blame] | 773 | info_list = qmp_query_pci(&err); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 774 | if (err) { |
| 775 | monitor_printf(mon, "PCI devices not supported\n"); |
| 776 | error_free(err); |
| 777 | return; |
| 778 | } |
| 779 | |
Stefan Berger | f46cee3 | 2012-01-11 10:51:52 -0500 | [diff] [blame] | 780 | for (info = info_list; info; info = info->next) { |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 781 | PciDeviceInfoList *dev; |
| 782 | |
| 783 | for (dev = info->value->devices; dev; dev = dev->next) { |
| 784 | hmp_info_pci_device(mon, dev->value); |
| 785 | } |
| 786 | } |
| 787 | |
Stefan Berger | f46cee3 | 2012-01-11 10:51:52 -0500 | [diff] [blame] | 788 | qapi_free_PciInfoList(info_list); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 789 | } |
| 790 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 791 | void hmp_info_block_jobs(Monitor *mon, const QDict *qdict) |
Stefan Hajnoczi | fb5458c | 2012-01-18 14:40:49 +0000 | [diff] [blame] | 792 | { |
| 793 | BlockJobInfoList *list; |
| 794 | Error *err = NULL; |
| 795 | |
| 796 | list = qmp_query_block_jobs(&err); |
| 797 | assert(!err); |
| 798 | |
| 799 | if (!list) { |
| 800 | monitor_printf(mon, "No active jobs\n"); |
| 801 | return; |
| 802 | } |
| 803 | |
| 804 | while (list) { |
| 805 | if (strcmp(list->value->type, "stream") == 0) { |
| 806 | monitor_printf(mon, "Streaming device %s: Completed %" PRId64 |
| 807 | " of %" PRId64 " bytes, speed limit %" PRId64 |
| 808 | " bytes/s\n", |
| 809 | list->value->device, |
| 810 | list->value->offset, |
| 811 | list->value->len, |
| 812 | list->value->speed); |
| 813 | } else { |
| 814 | monitor_printf(mon, "Type %s, device %s: Completed %" PRId64 |
| 815 | " of %" PRId64 " bytes, speed limit %" PRId64 |
| 816 | " bytes/s\n", |
| 817 | list->value->type, |
| 818 | list->value->device, |
| 819 | list->value->offset, |
| 820 | list->value->len, |
| 821 | list->value->speed); |
| 822 | } |
| 823 | list = list->next; |
| 824 | } |
Gonglei | 93bb131 | 2014-09-16 21:36:55 +0800 | [diff] [blame] | 825 | |
| 826 | qapi_free_BlockJobInfoList(list); |
Stefan Hajnoczi | fb5458c | 2012-01-18 14:40:49 +0000 | [diff] [blame] | 827 | } |
| 828 | |
Stefan Berger | d1a0cf7 | 2013-02-27 12:47:49 -0500 | [diff] [blame] | 829 | void hmp_info_tpm(Monitor *mon, const QDict *qdict) |
| 830 | { |
| 831 | TPMInfoList *info_list, *info; |
| 832 | Error *err = NULL; |
| 833 | unsigned int c = 0; |
| 834 | TPMPassthroughOptions *tpo; |
| 835 | |
| 836 | info_list = qmp_query_tpm(&err); |
| 837 | if (err) { |
| 838 | monitor_printf(mon, "TPM device not supported\n"); |
| 839 | error_free(err); |
| 840 | return; |
| 841 | } |
| 842 | |
| 843 | if (info_list) { |
| 844 | monitor_printf(mon, "TPM device:\n"); |
| 845 | } |
| 846 | |
| 847 | for (info = info_list; info; info = info->next) { |
| 848 | TPMInfo *ti = info->value; |
| 849 | monitor_printf(mon, " tpm%d: model=%s\n", |
| 850 | c, TpmModel_lookup[ti->model]); |
| 851 | |
| 852 | monitor_printf(mon, " \\ %s: type=%s", |
Eric Blake | ce21131 | 2015-10-26 16:35:00 -0600 | [diff] [blame] | 853 | ti->id, TpmTypeOptionsKind_lookup[ti->options->type]); |
Stefan Berger | d1a0cf7 | 2013-02-27 12:47:49 -0500 | [diff] [blame] | 854 | |
Eric Blake | ce21131 | 2015-10-26 16:35:00 -0600 | [diff] [blame] | 855 | switch (ti->options->type) { |
Corey Bryant | 88ca7bc | 2013-03-20 12:34:48 -0400 | [diff] [blame] | 856 | case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH: |
Eric Blake | ce21131 | 2015-10-26 16:35:00 -0600 | [diff] [blame] | 857 | tpo = ti->options->u.passthrough; |
Stefan Berger | d1a0cf7 | 2013-02-27 12:47:49 -0500 | [diff] [blame] | 858 | monitor_printf(mon, "%s%s%s%s", |
| 859 | tpo->has_path ? ",path=" : "", |
| 860 | tpo->has_path ? tpo->path : "", |
| 861 | tpo->has_cancel_path ? ",cancel-path=" : "", |
| 862 | tpo->has_cancel_path ? tpo->cancel_path : ""); |
| 863 | break; |
Eric Blake | 7fb1cf1 | 2015-11-18 01:52:57 -0700 | [diff] [blame] | 864 | case TPM_TYPE_OPTIONS_KIND__MAX: |
Stefan Berger | d1a0cf7 | 2013-02-27 12:47:49 -0500 | [diff] [blame] | 865 | break; |
| 866 | } |
| 867 | monitor_printf(mon, "\n"); |
| 868 | c++; |
| 869 | } |
| 870 | qapi_free_TPMInfoList(info_list); |
| 871 | } |
| 872 | |
Luiz Capitulino | 7a7f325 | 2011-09-15 14:20:28 -0300 | [diff] [blame] | 873 | void hmp_quit(Monitor *mon, const QDict *qdict) |
| 874 | { |
| 875 | monitor_suspend(mon); |
| 876 | qmp_quit(NULL); |
| 877 | } |
Luiz Capitulino | 5f158f2 | 2011-09-15 14:34:39 -0300 | [diff] [blame] | 878 | |
| 879 | void hmp_stop(Monitor *mon, const QDict *qdict) |
| 880 | { |
| 881 | qmp_stop(NULL); |
| 882 | } |
Luiz Capitulino | 38d2265 | 2011-09-15 14:41:46 -0300 | [diff] [blame] | 883 | |
| 884 | void hmp_system_reset(Monitor *mon, const QDict *qdict) |
| 885 | { |
| 886 | qmp_system_reset(NULL); |
| 887 | } |
Luiz Capitulino | 5bc465e | 2011-09-28 11:06:15 -0300 | [diff] [blame] | 888 | |
| 889 | void hmp_system_powerdown(Monitor *mon, const QDict *qdict) |
| 890 | { |
| 891 | qmp_system_powerdown(NULL); |
| 892 | } |
Luiz Capitulino | 755f196 | 2011-10-06 14:31:39 -0300 | [diff] [blame] | 893 | |
| 894 | void hmp_cpu(Monitor *mon, const QDict *qdict) |
| 895 | { |
| 896 | int64_t cpu_index; |
| 897 | |
| 898 | /* XXX: drop the monitor_set_cpu() usage when all HMP commands that |
| 899 | use it are converted to the QAPI */ |
| 900 | cpu_index = qdict_get_int(qdict, "index"); |
| 901 | if (monitor_set_cpu(cpu_index) < 0) { |
| 902 | monitor_printf(mon, "invalid CPU index\n"); |
| 903 | } |
| 904 | } |
Luiz Capitulino | 0cfd6a9 | 2011-11-22 16:32:37 -0200 | [diff] [blame] | 905 | |
| 906 | void hmp_memsave(Monitor *mon, const QDict *qdict) |
| 907 | { |
| 908 | uint32_t size = qdict_get_int(qdict, "size"); |
| 909 | const char *filename = qdict_get_str(qdict, "filename"); |
| 910 | uint64_t addr = qdict_get_int(qdict, "val"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 911 | Error *err = NULL; |
Luiz Capitulino | 0cfd6a9 | 2011-11-22 16:32:37 -0200 | [diff] [blame] | 912 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 913 | qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &err); |
| 914 | hmp_handle_error(mon, &err); |
Luiz Capitulino | 0cfd6a9 | 2011-11-22 16:32:37 -0200 | [diff] [blame] | 915 | } |
Luiz Capitulino | 6d3962b | 2011-11-22 17:26:46 -0200 | [diff] [blame] | 916 | |
| 917 | void hmp_pmemsave(Monitor *mon, const QDict *qdict) |
| 918 | { |
| 919 | uint32_t size = qdict_get_int(qdict, "size"); |
| 920 | const char *filename = qdict_get_str(qdict, "filename"); |
| 921 | uint64_t addr = qdict_get_int(qdict, "val"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 922 | Error *err = NULL; |
Luiz Capitulino | 6d3962b | 2011-11-22 17:26:46 -0200 | [diff] [blame] | 923 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 924 | qmp_pmemsave(addr, size, filename, &err); |
| 925 | hmp_handle_error(mon, &err); |
Luiz Capitulino | 6d3962b | 2011-11-22 17:26:46 -0200 | [diff] [blame] | 926 | } |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 927 | |
Markus Armbruster | 3949e59 | 2013-02-06 21:27:24 +0100 | [diff] [blame] | 928 | void hmp_ringbuf_write(Monitor *mon, const QDict *qdict) |
Lei Li | 1f590cf | 2013-01-25 00:03:20 +0800 | [diff] [blame] | 929 | { |
Lei Li | 1f590cf | 2013-01-25 00:03:20 +0800 | [diff] [blame] | 930 | const char *chardev = qdict_get_str(qdict, "device"); |
| 931 | const char *data = qdict_get_str(qdict, "data"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 932 | Error *err = NULL; |
Lei Li | 1f590cf | 2013-01-25 00:03:20 +0800 | [diff] [blame] | 933 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 934 | qmp_ringbuf_write(chardev, data, false, 0, &err); |
Lei Li | 1f590cf | 2013-01-25 00:03:20 +0800 | [diff] [blame] | 935 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 936 | hmp_handle_error(mon, &err); |
Lei Li | 1f590cf | 2013-01-25 00:03:20 +0800 | [diff] [blame] | 937 | } |
| 938 | |
Markus Armbruster | 3949e59 | 2013-02-06 21:27:24 +0100 | [diff] [blame] | 939 | void hmp_ringbuf_read(Monitor *mon, const QDict *qdict) |
Lei Li | 49b6d72 | 2013-01-25 00:03:21 +0800 | [diff] [blame] | 940 | { |
| 941 | uint32_t size = qdict_get_int(qdict, "size"); |
| 942 | const char *chardev = qdict_get_str(qdict, "device"); |
Markus Armbruster | 3ab651f | 2013-02-06 21:27:15 +0100 | [diff] [blame] | 943 | char *data; |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 944 | Error *err = NULL; |
Markus Armbruster | 543f341 | 2013-02-06 21:27:26 +0100 | [diff] [blame] | 945 | int i; |
Lei Li | 49b6d72 | 2013-01-25 00:03:21 +0800 | [diff] [blame] | 946 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 947 | data = qmp_ringbuf_read(chardev, size, false, 0, &err); |
| 948 | if (err) { |
Markus Armbruster | 193227f | 2015-12-18 16:35:06 +0100 | [diff] [blame] | 949 | error_report_err(err); |
Lei Li | 49b6d72 | 2013-01-25 00:03:21 +0800 | [diff] [blame] | 950 | return; |
| 951 | } |
| 952 | |
Markus Armbruster | 543f341 | 2013-02-06 21:27:26 +0100 | [diff] [blame] | 953 | for (i = 0; data[i]; i++) { |
| 954 | unsigned char ch = data[i]; |
| 955 | |
| 956 | if (ch == '\\') { |
| 957 | monitor_printf(mon, "\\\\"); |
| 958 | } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) { |
| 959 | monitor_printf(mon, "\\u%04X", ch); |
| 960 | } else { |
| 961 | monitor_printf(mon, "%c", ch); |
| 962 | } |
| 963 | |
| 964 | } |
| 965 | monitor_printf(mon, "\n"); |
Markus Armbruster | 3ab651f | 2013-02-06 21:27:15 +0100 | [diff] [blame] | 966 | g_free(data); |
Lei Li | 49b6d72 | 2013-01-25 00:03:21 +0800 | [diff] [blame] | 967 | } |
| 968 | |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 969 | static void hmp_cont_cb(void *opaque, int err) |
| 970 | { |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 971 | if (!err) { |
Luiz Capitulino | 8b7f6fb | 2012-07-26 20:41:53 -0300 | [diff] [blame] | 972 | qmp_cont(NULL); |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 973 | } |
| 974 | } |
| 975 | |
Luiz Capitulino | 8b7f6fb | 2012-07-26 20:41:53 -0300 | [diff] [blame] | 976 | static bool key_is_missing(const BlockInfo *bdev) |
| 977 | { |
| 978 | return (bdev->inserted && bdev->inserted->encryption_key_missing); |
| 979 | } |
| 980 | |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 981 | void hmp_cont(Monitor *mon, const QDict *qdict) |
| 982 | { |
Luiz Capitulino | 8b7f6fb | 2012-07-26 20:41:53 -0300 | [diff] [blame] | 983 | BlockInfoList *bdev_list, *bdev; |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 984 | Error *err = NULL; |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 985 | |
Luiz Capitulino | 8b7f6fb | 2012-07-26 20:41:53 -0300 | [diff] [blame] | 986 | bdev_list = qmp_query_block(NULL); |
| 987 | for (bdev = bdev_list; bdev; bdev = bdev->next) { |
| 988 | if (key_is_missing(bdev->value)) { |
| 989 | monitor_read_block_device_key(mon, bdev->value->device, |
| 990 | hmp_cont_cb, NULL); |
| 991 | goto out; |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 992 | } |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 993 | } |
Luiz Capitulino | 8b7f6fb | 2012-07-26 20:41:53 -0300 | [diff] [blame] | 994 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 995 | qmp_cont(&err); |
| 996 | hmp_handle_error(mon, &err); |
Luiz Capitulino | 8b7f6fb | 2012-07-26 20:41:53 -0300 | [diff] [blame] | 997 | |
| 998 | out: |
| 999 | qapi_free_BlockInfoList(bdev_list); |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 1000 | } |
Luiz Capitulino | ab49ab5 | 2011-11-23 12:55:53 -0200 | [diff] [blame] | 1001 | |
Gerd Hoffmann | 9b9df25 | 2012-02-23 13:45:21 +0100 | [diff] [blame] | 1002 | void hmp_system_wakeup(Monitor *mon, const QDict *qdict) |
| 1003 | { |
| 1004 | qmp_system_wakeup(NULL); |
| 1005 | } |
| 1006 | |
Markus Armbruster | 3e5a50d | 2015-02-06 13:55:43 +0100 | [diff] [blame] | 1007 | void hmp_nmi(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | ab49ab5 | 2011-11-23 12:55:53 -0200 | [diff] [blame] | 1008 | { |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1009 | Error *err = NULL; |
Luiz Capitulino | ab49ab5 | 2011-11-23 12:55:53 -0200 | [diff] [blame] | 1010 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1011 | qmp_inject_nmi(&err); |
| 1012 | hmp_handle_error(mon, &err); |
Luiz Capitulino | ab49ab5 | 2011-11-23 12:55:53 -0200 | [diff] [blame] | 1013 | } |
Luiz Capitulino | 4b37156 | 2011-11-23 13:11:55 -0200 | [diff] [blame] | 1014 | |
| 1015 | void hmp_set_link(Monitor *mon, const QDict *qdict) |
| 1016 | { |
| 1017 | const char *name = qdict_get_str(qdict, "name"); |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 1018 | bool up = qdict_get_bool(qdict, "up"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1019 | Error *err = NULL; |
Luiz Capitulino | 4b37156 | 2011-11-23 13:11:55 -0200 | [diff] [blame] | 1020 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1021 | qmp_set_link(name, up, &err); |
| 1022 | hmp_handle_error(mon, &err); |
Luiz Capitulino | 4b37156 | 2011-11-23 13:11:55 -0200 | [diff] [blame] | 1023 | } |
Luiz Capitulino | a4dea8a | 2011-11-23 13:28:21 -0200 | [diff] [blame] | 1024 | |
| 1025 | void hmp_block_passwd(Monitor *mon, const QDict *qdict) |
| 1026 | { |
| 1027 | const char *device = qdict_get_str(qdict, "device"); |
| 1028 | const char *password = qdict_get_str(qdict, "password"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1029 | Error *err = NULL; |
Luiz Capitulino | a4dea8a | 2011-11-23 13:28:21 -0200 | [diff] [blame] | 1030 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1031 | qmp_block_passwd(true, device, false, NULL, password, &err); |
| 1032 | hmp_handle_error(mon, &err); |
Luiz Capitulino | a4dea8a | 2011-11-23 13:28:21 -0200 | [diff] [blame] | 1033 | } |
Luiz Capitulino | d72f326 | 2011-11-25 14:38:09 -0200 | [diff] [blame] | 1034 | |
| 1035 | void hmp_balloon(Monitor *mon, const QDict *qdict) |
| 1036 | { |
| 1037 | int64_t value = qdict_get_int(qdict, "value"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1038 | Error *err = NULL; |
Luiz Capitulino | d72f326 | 2011-11-25 14:38:09 -0200 | [diff] [blame] | 1039 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1040 | qmp_balloon(value, &err); |
| 1041 | if (err) { |
Markus Armbruster | 193227f | 2015-12-18 16:35:06 +0100 | [diff] [blame] | 1042 | error_report_err(err); |
Luiz Capitulino | d72f326 | 2011-11-25 14:38:09 -0200 | [diff] [blame] | 1043 | } |
| 1044 | } |
Luiz Capitulino | 5e7caac | 2011-11-25 14:57:10 -0200 | [diff] [blame] | 1045 | |
| 1046 | void hmp_block_resize(Monitor *mon, const QDict *qdict) |
| 1047 | { |
| 1048 | const char *device = qdict_get_str(qdict, "device"); |
| 1049 | int64_t size = qdict_get_int(qdict, "size"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1050 | Error *err = NULL; |
Luiz Capitulino | 5e7caac | 2011-11-25 14:57:10 -0200 | [diff] [blame] | 1051 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1052 | qmp_block_resize(true, device, false, NULL, size, &err); |
| 1053 | hmp_handle_error(mon, &err); |
Luiz Capitulino | 5e7caac | 2011-11-25 14:57:10 -0200 | [diff] [blame] | 1054 | } |
Luiz Capitulino | 6106e24 | 2011-11-25 16:15:19 -0200 | [diff] [blame] | 1055 | |
Paolo Bonzini | d9b902d | 2012-10-18 16:49:24 +0200 | [diff] [blame] | 1056 | void hmp_drive_mirror(Monitor *mon, const QDict *qdict) |
| 1057 | { |
| 1058 | const char *device = qdict_get_str(qdict, "device"); |
| 1059 | const char *filename = qdict_get_str(qdict, "target"); |
| 1060 | const char *format = qdict_get_try_str(qdict, "format"); |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 1061 | bool reuse = qdict_get_try_bool(qdict, "reuse", false); |
| 1062 | bool full = qdict_get_try_bool(qdict, "full", false); |
Paolo Bonzini | d9b902d | 2012-10-18 16:49:24 +0200 | [diff] [blame] | 1063 | enum NewImageMode mode; |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1064 | Error *err = NULL; |
Paolo Bonzini | d9b902d | 2012-10-18 16:49:24 +0200 | [diff] [blame] | 1065 | |
| 1066 | if (!filename) { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 1067 | error_setg(&err, QERR_MISSING_PARAMETER, "target"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1068 | hmp_handle_error(mon, &err); |
Paolo Bonzini | d9b902d | 2012-10-18 16:49:24 +0200 | [diff] [blame] | 1069 | return; |
| 1070 | } |
| 1071 | |
| 1072 | if (reuse) { |
| 1073 | mode = NEW_IMAGE_MODE_EXISTING; |
| 1074 | } else { |
| 1075 | mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS; |
| 1076 | } |
| 1077 | |
| 1078 | qmp_drive_mirror(device, filename, !!format, format, |
Benoît Canet | 09158f0 | 2014-06-27 18:25:25 +0200 | [diff] [blame] | 1079 | false, NULL, false, NULL, |
Paolo Bonzini | d9b902d | 2012-10-18 16:49:24 +0200 | [diff] [blame] | 1080 | full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP, |
Paolo Bonzini | 08e4ed6 | 2013-01-22 09:03:13 +0100 | [diff] [blame] | 1081 | true, mode, false, 0, false, 0, false, 0, |
Fam Zheng | 0fc9f8e | 2015-06-08 13:56:08 +0800 | [diff] [blame] | 1082 | false, 0, false, 0, false, true, &err); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1083 | hmp_handle_error(mon, &err); |
Paolo Bonzini | d9b902d | 2012-10-18 16:49:24 +0200 | [diff] [blame] | 1084 | } |
| 1085 | |
Stefan Hajnoczi | de90930 | 2013-06-26 14:11:58 +0200 | [diff] [blame] | 1086 | void hmp_drive_backup(Monitor *mon, const QDict *qdict) |
| 1087 | { |
| 1088 | const char *device = qdict_get_str(qdict, "device"); |
| 1089 | const char *filename = qdict_get_str(qdict, "target"); |
| 1090 | const char *format = qdict_get_try_str(qdict, "format"); |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 1091 | bool reuse = qdict_get_try_bool(qdict, "reuse", false); |
| 1092 | bool full = qdict_get_try_bool(qdict, "full", false); |
Stefan Hajnoczi | de90930 | 2013-06-26 14:11:58 +0200 | [diff] [blame] | 1093 | enum NewImageMode mode; |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1094 | Error *err = NULL; |
Stefan Hajnoczi | de90930 | 2013-06-26 14:11:58 +0200 | [diff] [blame] | 1095 | |
| 1096 | if (!filename) { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 1097 | error_setg(&err, QERR_MISSING_PARAMETER, "target"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1098 | hmp_handle_error(mon, &err); |
Stefan Hajnoczi | de90930 | 2013-06-26 14:11:58 +0200 | [diff] [blame] | 1099 | return; |
| 1100 | } |
| 1101 | |
| 1102 | if (reuse) { |
| 1103 | mode = NEW_IMAGE_MODE_EXISTING; |
| 1104 | } else { |
| 1105 | mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS; |
| 1106 | } |
| 1107 | |
| 1108 | qmp_drive_backup(device, filename, !!format, format, |
| 1109 | full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP, |
John Snow | d58d845 | 2015-04-17 19:49:58 -0400 | [diff] [blame] | 1110 | true, mode, false, 0, false, NULL, |
| 1111 | false, 0, false, 0, &err); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1112 | hmp_handle_error(mon, &err); |
Stefan Hajnoczi | de90930 | 2013-06-26 14:11:58 +0200 | [diff] [blame] | 1113 | } |
| 1114 | |
Luiz Capitulino | 6106e24 | 2011-11-25 16:15:19 -0200 | [diff] [blame] | 1115 | void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) |
| 1116 | { |
| 1117 | const char *device = qdict_get_str(qdict, "device"); |
| 1118 | const char *filename = qdict_get_try_str(qdict, "snapshot-file"); |
| 1119 | const char *format = qdict_get_try_str(qdict, "format"); |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 1120 | bool reuse = qdict_get_try_bool(qdict, "reuse", false); |
Paolo Bonzini | 6cc2a41 | 2012-03-06 18:55:59 +0100 | [diff] [blame] | 1121 | enum NewImageMode mode; |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1122 | Error *err = NULL; |
Luiz Capitulino | 6106e24 | 2011-11-25 16:15:19 -0200 | [diff] [blame] | 1123 | |
| 1124 | if (!filename) { |
| 1125 | /* In the future, if 'snapshot-file' is not specified, the snapshot |
| 1126 | will be taken internally. Today it's actually required. */ |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 1127 | error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1128 | hmp_handle_error(mon, &err); |
Luiz Capitulino | 6106e24 | 2011-11-25 16:15:19 -0200 | [diff] [blame] | 1129 | return; |
| 1130 | } |
| 1131 | |
Paolo Bonzini | 6cc2a41 | 2012-03-06 18:55:59 +0100 | [diff] [blame] | 1132 | mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS; |
Benoît Canet | 0901f67 | 2014-01-23 21:31:38 +0100 | [diff] [blame] | 1133 | qmp_blockdev_snapshot_sync(true, device, false, NULL, |
| 1134 | filename, false, NULL, |
| 1135 | !!format, format, |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1136 | true, mode, &err); |
| 1137 | hmp_handle_error(mon, &err); |
Luiz Capitulino | 6106e24 | 2011-11-25 16:15:19 -0200 | [diff] [blame] | 1138 | } |
Luiz Capitulino | 6cdedb0 | 2011-11-27 22:54:09 -0200 | [diff] [blame] | 1139 | |
Wenchao Xia | 775ca88 | 2013-09-11 14:04:37 +0800 | [diff] [blame] | 1140 | void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict) |
| 1141 | { |
| 1142 | const char *device = qdict_get_str(qdict, "device"); |
| 1143 | const char *name = qdict_get_str(qdict, "name"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1144 | Error *err = NULL; |
Wenchao Xia | 775ca88 | 2013-09-11 14:04:37 +0800 | [diff] [blame] | 1145 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1146 | qmp_blockdev_snapshot_internal_sync(device, name, &err); |
| 1147 | hmp_handle_error(mon, &err); |
Wenchao Xia | 775ca88 | 2013-09-11 14:04:37 +0800 | [diff] [blame] | 1148 | } |
| 1149 | |
Wenchao Xia | 7a4ed2e | 2013-09-11 14:04:38 +0800 | [diff] [blame] | 1150 | void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict) |
| 1151 | { |
| 1152 | const char *device = qdict_get_str(qdict, "device"); |
| 1153 | const char *name = qdict_get_str(qdict, "name"); |
| 1154 | const char *id = qdict_get_try_str(qdict, "id"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1155 | Error *err = NULL; |
Wenchao Xia | 7a4ed2e | 2013-09-11 14:04:38 +0800 | [diff] [blame] | 1156 | |
| 1157 | qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id, |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1158 | true, name, &err); |
| 1159 | hmp_handle_error(mon, &err); |
Wenchao Xia | 7a4ed2e | 2013-09-11 14:04:38 +0800 | [diff] [blame] | 1160 | } |
| 1161 | |
Luiz Capitulino | 6cdedb0 | 2011-11-27 22:54:09 -0200 | [diff] [blame] | 1162 | void hmp_migrate_cancel(Monitor *mon, const QDict *qdict) |
| 1163 | { |
| 1164 | qmp_migrate_cancel(NULL); |
| 1165 | } |
Luiz Capitulino | 4f0a993 | 2011-11-27 23:18:01 -0200 | [diff] [blame] | 1166 | |
Dr. David Alan Gilbert | bf1ae1f | 2015-02-19 11:40:28 +0000 | [diff] [blame] | 1167 | void hmp_migrate_incoming(Monitor *mon, const QDict *qdict) |
| 1168 | { |
| 1169 | Error *err = NULL; |
| 1170 | const char *uri = qdict_get_str(qdict, "uri"); |
| 1171 | |
| 1172 | qmp_migrate_incoming(uri, &err); |
| 1173 | |
Dr. David Alan Gilbert | 1fa57f5 | 2015-02-26 14:54:39 +0000 | [diff] [blame] | 1174 | hmp_handle_error(mon, &err); |
Dr. David Alan Gilbert | bf1ae1f | 2015-02-19 11:40:28 +0000 | [diff] [blame] | 1175 | } |
| 1176 | |
Luiz Capitulino | 4f0a993 | 2011-11-27 23:18:01 -0200 | [diff] [blame] | 1177 | void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict) |
| 1178 | { |
| 1179 | double value = qdict_get_double(qdict, "value"); |
| 1180 | qmp_migrate_set_downtime(value, NULL); |
| 1181 | } |
Luiz Capitulino | 3dc8538 | 2011-11-28 11:59:37 -0200 | [diff] [blame] | 1182 | |
Orit Wasserman | 9e1ba4c | 2012-08-06 21:42:54 +0300 | [diff] [blame] | 1183 | void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict) |
| 1184 | { |
| 1185 | int64_t value = qdict_get_int(qdict, "value"); |
| 1186 | Error *err = NULL; |
| 1187 | |
| 1188 | qmp_migrate_set_cache_size(value, &err); |
| 1189 | if (err) { |
Markus Armbruster | 193227f | 2015-12-18 16:35:06 +0100 | [diff] [blame] | 1190 | error_report_err(err); |
Orit Wasserman | 9e1ba4c | 2012-08-06 21:42:54 +0300 | [diff] [blame] | 1191 | return; |
| 1192 | } |
| 1193 | } |
| 1194 | |
Luiz Capitulino | 3dc8538 | 2011-11-28 11:59:37 -0200 | [diff] [blame] | 1195 | void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict) |
| 1196 | { |
| 1197 | int64_t value = qdict_get_int(qdict, "value"); |
| 1198 | qmp_migrate_set_speed(value, NULL); |
| 1199 | } |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 1200 | |
Orit Wasserman | 0045843 | 2012-08-06 21:42:48 +0300 | [diff] [blame] | 1201 | void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict) |
| 1202 | { |
| 1203 | const char *cap = qdict_get_str(qdict, "capability"); |
| 1204 | bool state = qdict_get_bool(qdict, "state"); |
| 1205 | Error *err = NULL; |
| 1206 | MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps)); |
| 1207 | int i; |
| 1208 | |
Eric Blake | 7fb1cf1 | 2015-11-18 01:52:57 -0700 | [diff] [blame] | 1209 | for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) { |
Orit Wasserman | 0045843 | 2012-08-06 21:42:48 +0300 | [diff] [blame] | 1210 | if (strcmp(cap, MigrationCapability_lookup[i]) == 0) { |
| 1211 | caps->value = g_malloc0(sizeof(*caps->value)); |
| 1212 | caps->value->capability = i; |
| 1213 | caps->value->state = state; |
| 1214 | caps->next = NULL; |
| 1215 | qmp_migrate_set_capabilities(caps, &err); |
| 1216 | break; |
| 1217 | } |
| 1218 | } |
| 1219 | |
Eric Blake | 7fb1cf1 | 2015-11-18 01:52:57 -0700 | [diff] [blame] | 1220 | if (i == MIGRATION_CAPABILITY__MAX) { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 1221 | error_setg(&err, QERR_INVALID_PARAMETER, cap); |
Orit Wasserman | 0045843 | 2012-08-06 21:42:48 +0300 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | qapi_free_MigrationCapabilityStatusList(caps); |
| 1225 | |
| 1226 | if (err) { |
Markus Armbruster | 193227f | 2015-12-18 16:35:06 +0100 | [diff] [blame] | 1227 | error_report_err(err); |
Orit Wasserman | 0045843 | 2012-08-06 21:42:48 +0300 | [diff] [blame] | 1228 | } |
| 1229 | } |
| 1230 | |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 1231 | void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) |
| 1232 | { |
| 1233 | const char *param = qdict_get_str(qdict, "parameter"); |
| 1234 | int value = qdict_get_int(qdict, "value"); |
| 1235 | Error *err = NULL; |
| 1236 | bool has_compress_level = false; |
| 1237 | bool has_compress_threads = false; |
| 1238 | bool has_decompress_threads = false; |
Jason J. Herne | 1626fee | 2015-09-08 13:12:34 -0400 | [diff] [blame] | 1239 | bool has_x_cpu_throttle_initial = false; |
| 1240 | bool has_x_cpu_throttle_increment = false; |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 1241 | int i; |
| 1242 | |
Eric Blake | 7fb1cf1 | 2015-11-18 01:52:57 -0700 | [diff] [blame] | 1243 | for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) { |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 1244 | if (strcmp(param, MigrationParameter_lookup[i]) == 0) { |
| 1245 | switch (i) { |
| 1246 | case MIGRATION_PARAMETER_COMPRESS_LEVEL: |
| 1247 | has_compress_level = true; |
| 1248 | break; |
| 1249 | case MIGRATION_PARAMETER_COMPRESS_THREADS: |
| 1250 | has_compress_threads = true; |
| 1251 | break; |
| 1252 | case MIGRATION_PARAMETER_DECOMPRESS_THREADS: |
| 1253 | has_decompress_threads = true; |
| 1254 | break; |
Jason J. Herne | 1626fee | 2015-09-08 13:12:34 -0400 | [diff] [blame] | 1255 | case MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL: |
| 1256 | has_x_cpu_throttle_initial = true; |
| 1257 | break; |
| 1258 | case MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT: |
| 1259 | has_x_cpu_throttle_increment = true; |
| 1260 | break; |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 1261 | } |
| 1262 | qmp_migrate_set_parameters(has_compress_level, value, |
| 1263 | has_compress_threads, value, |
| 1264 | has_decompress_threads, value, |
Jason J. Herne | 1626fee | 2015-09-08 13:12:34 -0400 | [diff] [blame] | 1265 | has_x_cpu_throttle_initial, value, |
| 1266 | has_x_cpu_throttle_increment, value, |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 1267 | &err); |
| 1268 | break; |
| 1269 | } |
| 1270 | } |
| 1271 | |
Eric Blake | 7fb1cf1 | 2015-11-18 01:52:57 -0700 | [diff] [blame] | 1272 | if (i == MIGRATION_PARAMETER__MAX) { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 1273 | error_setg(&err, QERR_INVALID_PARAMETER, param); |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | if (err) { |
Markus Armbruster | 193227f | 2015-12-18 16:35:06 +0100 | [diff] [blame] | 1277 | error_report_err(err); |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 1278 | } |
| 1279 | } |
| 1280 | |
Markus Armbruster | b8a185b | 2015-03-05 17:29:02 +0100 | [diff] [blame] | 1281 | void hmp_client_migrate_info(Monitor *mon, const QDict *qdict) |
| 1282 | { |
| 1283 | Error *err = NULL; |
| 1284 | const char *protocol = qdict_get_str(qdict, "protocol"); |
| 1285 | const char *hostname = qdict_get_str(qdict, "hostname"); |
| 1286 | bool has_port = qdict_haskey(qdict, "port"); |
| 1287 | int port = qdict_get_try_int(qdict, "port", -1); |
| 1288 | bool has_tls_port = qdict_haskey(qdict, "tls-port"); |
| 1289 | int tls_port = qdict_get_try_int(qdict, "tls-port", -1); |
| 1290 | const char *cert_subject = qdict_get_try_str(qdict, "cert-subject"); |
| 1291 | |
| 1292 | qmp_client_migrate_info(protocol, hostname, |
| 1293 | has_port, port, has_tls_port, tls_port, |
| 1294 | !!cert_subject, cert_subject, &err); |
| 1295 | hmp_handle_error(mon, &err); |
| 1296 | } |
| 1297 | |
Dr. David Alan Gilbert | 4886a1b | 2015-11-05 18:10:56 +0000 | [diff] [blame] | 1298 | void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict) |
| 1299 | { |
| 1300 | Error *err = NULL; |
| 1301 | qmp_migrate_start_postcopy(&err); |
| 1302 | hmp_handle_error(mon, &err); |
| 1303 | } |
| 1304 | |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 1305 | void hmp_set_password(Monitor *mon, const QDict *qdict) |
| 1306 | { |
| 1307 | const char *protocol = qdict_get_str(qdict, "protocol"); |
| 1308 | const char *password = qdict_get_str(qdict, "password"); |
| 1309 | const char *connected = qdict_get_try_str(qdict, "connected"); |
| 1310 | Error *err = NULL; |
| 1311 | |
| 1312 | qmp_set_password(protocol, password, !!connected, connected, &err); |
| 1313 | hmp_handle_error(mon, &err); |
| 1314 | } |
Luiz Capitulino | 9ad5372 | 2011-12-07 11:47:57 -0200 | [diff] [blame] | 1315 | |
| 1316 | void hmp_expire_password(Monitor *mon, const QDict *qdict) |
| 1317 | { |
| 1318 | const char *protocol = qdict_get_str(qdict, "protocol"); |
| 1319 | const char *whenstr = qdict_get_str(qdict, "time"); |
| 1320 | Error *err = NULL; |
| 1321 | |
| 1322 | qmp_expire_password(protocol, whenstr, &err); |
| 1323 | hmp_handle_error(mon, &err); |
| 1324 | } |
Luiz Capitulino | c245b6a | 2011-12-07 16:02:36 -0200 | [diff] [blame] | 1325 | |
| 1326 | void hmp_eject(Monitor *mon, const QDict *qdict) |
| 1327 | { |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 1328 | bool force = qdict_get_try_bool(qdict, "force", false); |
Luiz Capitulino | c245b6a | 2011-12-07 16:02:36 -0200 | [diff] [blame] | 1329 | const char *device = qdict_get_str(qdict, "device"); |
| 1330 | Error *err = NULL; |
| 1331 | |
| 1332 | qmp_eject(device, true, force, &err); |
| 1333 | hmp_handle_error(mon, &err); |
| 1334 | } |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 1335 | |
Stefan Hajnoczi | c60bf33 | 2013-11-14 11:54:14 +0100 | [diff] [blame] | 1336 | static void hmp_change_read_arg(void *opaque, const char *password, |
| 1337 | void *readline_opaque) |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 1338 | { |
| 1339 | qmp_change_vnc_password(password, NULL); |
Stefan Hajnoczi | c60bf33 | 2013-11-14 11:54:14 +0100 | [diff] [blame] | 1340 | monitor_read_command(opaque, 1); |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 1341 | } |
| 1342 | |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 1343 | void hmp_change(Monitor *mon, const QDict *qdict) |
| 1344 | { |
| 1345 | const char *device = qdict_get_str(qdict, "device"); |
| 1346 | const char *target = qdict_get_str(qdict, "target"); |
| 1347 | const char *arg = qdict_get_try_str(qdict, "arg"); |
Max Reitz | baead0a | 2015-10-26 21:39:18 +0100 | [diff] [blame] | 1348 | const char *read_only = qdict_get_try_str(qdict, "read-only-mode"); |
| 1349 | BlockdevChangeReadOnlyMode read_only_mode = 0; |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 1350 | Error *err = NULL; |
| 1351 | |
Max Reitz | 1068674 | 2015-10-26 21:39:16 +0100 | [diff] [blame] | 1352 | if (strcmp(device, "vnc") == 0) { |
Max Reitz | baead0a | 2015-10-26 21:39:18 +0100 | [diff] [blame] | 1353 | if (read_only) { |
| 1354 | monitor_printf(mon, |
| 1355 | "Parameter 'read-only-mode' is invalid for VNC\n"); |
| 1356 | return; |
| 1357 | } |
Max Reitz | 1068674 | 2015-10-26 21:39:16 +0100 | [diff] [blame] | 1358 | if (strcmp(target, "passwd") == 0 || |
| 1359 | strcmp(target, "password") == 0) { |
| 1360 | if (!arg) { |
| 1361 | monitor_read_password(mon, hmp_change_read_arg, NULL); |
| 1362 | return; |
| 1363 | } |
| 1364 | } |
| 1365 | qmp_change("vnc", target, !!arg, arg, &err); |
| 1366 | } else { |
Max Reitz | baead0a | 2015-10-26 21:39:18 +0100 | [diff] [blame] | 1367 | if (read_only) { |
| 1368 | read_only_mode = |
| 1369 | qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup, |
Eric Blake | 7fb1cf1 | 2015-11-18 01:52:57 -0700 | [diff] [blame] | 1370 | read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX, |
Max Reitz | baead0a | 2015-10-26 21:39:18 +0100 | [diff] [blame] | 1371 | BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err); |
| 1372 | if (err) { |
| 1373 | hmp_handle_error(mon, &err); |
| 1374 | return; |
| 1375 | } |
| 1376 | } |
| 1377 | |
| 1378 | qmp_blockdev_change_medium(device, target, !!arg, arg, |
| 1379 | !!read_only, read_only_mode, &err); |
Max Reitz | 1068674 | 2015-10-26 21:39:16 +0100 | [diff] [blame] | 1380 | if (err && |
| 1381 | error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) { |
| 1382 | error_free(err); |
| 1383 | monitor_read_block_device_key(mon, device, NULL, NULL); |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 1384 | return; |
| 1385 | } |
| 1386 | } |
| 1387 | |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 1388 | hmp_handle_error(mon, &err); |
| 1389 | } |
Luiz Capitulino | 80047da | 2011-12-14 16:49:14 -0200 | [diff] [blame] | 1390 | |
| 1391 | void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) |
| 1392 | { |
| 1393 | Error *err = NULL; |
| 1394 | |
| 1395 | qmp_block_set_io_throttle(qdict_get_str(qdict, "device"), |
| 1396 | qdict_get_int(qdict, "bps"), |
| 1397 | qdict_get_int(qdict, "bps_rd"), |
| 1398 | qdict_get_int(qdict, "bps_wr"), |
| 1399 | qdict_get_int(qdict, "iops"), |
| 1400 | qdict_get_int(qdict, "iops_rd"), |
Benoît Canet | 3e9fab6 | 2013-09-02 14:14:40 +0200 | [diff] [blame] | 1401 | qdict_get_int(qdict, "iops_wr"), |
| 1402 | false, /* no burst max via HMP */ |
| 1403 | 0, |
| 1404 | false, |
| 1405 | 0, |
| 1406 | false, |
| 1407 | 0, |
| 1408 | false, |
| 1409 | 0, |
| 1410 | false, |
| 1411 | 0, |
| 1412 | false, |
Benoît Canet | 2024c1d | 2013-09-02 14:14:41 +0200 | [diff] [blame] | 1413 | 0, |
| 1414 | false, /* No default I/O size */ |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 1415 | 0, |
| 1416 | false, |
| 1417 | NULL, &err); |
Luiz Capitulino | 80047da | 2011-12-14 16:49:14 -0200 | [diff] [blame] | 1418 | hmp_handle_error(mon, &err); |
| 1419 | } |
Stefan Hajnoczi | 12bd451 | 2012-01-18 14:40:46 +0000 | [diff] [blame] | 1420 | |
| 1421 | void hmp_block_stream(Monitor *mon, const QDict *qdict) |
| 1422 | { |
| 1423 | Error *error = NULL; |
| 1424 | const char *device = qdict_get_str(qdict, "device"); |
| 1425 | const char *base = qdict_get_try_str(qdict, "base"); |
Stefan Hajnoczi | c83c66c | 2012-04-25 16:51:03 +0100 | [diff] [blame] | 1426 | int64_t speed = qdict_get_try_int(qdict, "speed", 0); |
Stefan Hajnoczi | 12bd451 | 2012-01-18 14:40:46 +0000 | [diff] [blame] | 1427 | |
Jeff Cody | 13d8cc5 | 2014-06-25 15:40:11 -0400 | [diff] [blame] | 1428 | qmp_block_stream(device, base != NULL, base, false, NULL, |
Paolo Bonzini | 1d80909 | 2012-09-28 17:22:59 +0200 | [diff] [blame] | 1429 | qdict_haskey(qdict, "speed"), speed, |
Anthony Liguori | 46663e5 | 2013-09-17 11:10:47 -0500 | [diff] [blame] | 1430 | true, BLOCKDEV_ON_ERROR_REPORT, &error); |
Stefan Hajnoczi | 12bd451 | 2012-01-18 14:40:46 +0000 | [diff] [blame] | 1431 | |
| 1432 | hmp_handle_error(mon, &error); |
| 1433 | } |
Stefan Hajnoczi | 2d47c6e | 2012-01-18 14:40:47 +0000 | [diff] [blame] | 1434 | |
| 1435 | void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict) |
| 1436 | { |
| 1437 | Error *error = NULL; |
| 1438 | const char *device = qdict_get_str(qdict, "device"); |
Paolo Bonzini | c6db239 | 2012-05-08 16:51:56 +0200 | [diff] [blame] | 1439 | int64_t value = qdict_get_int(qdict, "speed"); |
Stefan Hajnoczi | 2d47c6e | 2012-01-18 14:40:47 +0000 | [diff] [blame] | 1440 | |
| 1441 | qmp_block_job_set_speed(device, value, &error); |
| 1442 | |
| 1443 | hmp_handle_error(mon, &error); |
| 1444 | } |
Stefan Hajnoczi | 370521a | 2012-01-18 14:40:48 +0000 | [diff] [blame] | 1445 | |
| 1446 | void hmp_block_job_cancel(Monitor *mon, const QDict *qdict) |
| 1447 | { |
| 1448 | Error *error = NULL; |
| 1449 | const char *device = qdict_get_str(qdict, "device"); |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 1450 | bool force = qdict_get_try_bool(qdict, "force", false); |
Stefan Hajnoczi | 370521a | 2012-01-18 14:40:48 +0000 | [diff] [blame] | 1451 | |
Paolo Bonzini | 6e37fb8 | 2012-09-28 17:22:51 +0200 | [diff] [blame] | 1452 | qmp_block_job_cancel(device, true, force, &error); |
| 1453 | |
| 1454 | hmp_handle_error(mon, &error); |
| 1455 | } |
| 1456 | |
| 1457 | void hmp_block_job_pause(Monitor *mon, const QDict *qdict) |
| 1458 | { |
| 1459 | Error *error = NULL; |
| 1460 | const char *device = qdict_get_str(qdict, "device"); |
| 1461 | |
| 1462 | qmp_block_job_pause(device, &error); |
| 1463 | |
| 1464 | hmp_handle_error(mon, &error); |
| 1465 | } |
| 1466 | |
| 1467 | void hmp_block_job_resume(Monitor *mon, const QDict *qdict) |
| 1468 | { |
| 1469 | Error *error = NULL; |
| 1470 | const char *device = qdict_get_str(qdict, "device"); |
| 1471 | |
| 1472 | qmp_block_job_resume(device, &error); |
Stefan Hajnoczi | 370521a | 2012-01-18 14:40:48 +0000 | [diff] [blame] | 1473 | |
| 1474 | hmp_handle_error(mon, &error); |
| 1475 | } |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 1476 | |
Paolo Bonzini | aeae883 | 2012-10-18 16:49:21 +0200 | [diff] [blame] | 1477 | void hmp_block_job_complete(Monitor *mon, const QDict *qdict) |
| 1478 | { |
| 1479 | Error *error = NULL; |
| 1480 | const char *device = qdict_get_str(qdict, "device"); |
| 1481 | |
| 1482 | qmp_block_job_complete(device, &error); |
| 1483 | |
| 1484 | hmp_handle_error(mon, &error); |
| 1485 | } |
| 1486 | |
zhanghailiang | e49f35b | 2015-03-13 16:08:39 +0800 | [diff] [blame] | 1487 | typedef struct HMPMigrationStatus |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 1488 | { |
| 1489 | QEMUTimer *timer; |
| 1490 | Monitor *mon; |
| 1491 | bool is_block_migration; |
zhanghailiang | e49f35b | 2015-03-13 16:08:39 +0800 | [diff] [blame] | 1492 | } HMPMigrationStatus; |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 1493 | |
| 1494 | static void hmp_migrate_status_cb(void *opaque) |
| 1495 | { |
zhanghailiang | e49f35b | 2015-03-13 16:08:39 +0800 | [diff] [blame] | 1496 | HMPMigrationStatus *status = opaque; |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 1497 | MigrationInfo *info; |
| 1498 | |
| 1499 | info = qmp_query_migrate(NULL); |
zhanghailiang | 24b8c39 | 2015-03-13 16:08:40 +0800 | [diff] [blame] | 1500 | if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE || |
| 1501 | info->status == MIGRATION_STATUS_SETUP) { |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 1502 | if (info->has_disk) { |
| 1503 | int progress; |
| 1504 | |
| 1505 | if (info->disk->remaining) { |
| 1506 | progress = info->disk->transferred * 100 / info->disk->total; |
| 1507 | } else { |
| 1508 | progress = 100; |
| 1509 | } |
| 1510 | |
| 1511 | monitor_printf(status->mon, "Completed %d %%\r", progress); |
| 1512 | monitor_flush(status->mon); |
| 1513 | } |
| 1514 | |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 1515 | timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000); |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 1516 | } else { |
| 1517 | if (status->is_block_migration) { |
| 1518 | monitor_printf(status->mon, "\n"); |
| 1519 | } |
| 1520 | monitor_resume(status->mon); |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 1521 | timer_del(status->timer); |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 1522 | g_free(status); |
| 1523 | } |
| 1524 | |
| 1525 | qapi_free_MigrationInfo(info); |
| 1526 | } |
| 1527 | |
| 1528 | void hmp_migrate(Monitor *mon, const QDict *qdict) |
| 1529 | { |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 1530 | bool detach = qdict_get_try_bool(qdict, "detach", false); |
| 1531 | bool blk = qdict_get_try_bool(qdict, "blk", false); |
| 1532 | bool inc = qdict_get_try_bool(qdict, "inc", false); |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 1533 | const char *uri = qdict_get_str(qdict, "uri"); |
| 1534 | Error *err = NULL; |
| 1535 | |
| 1536 | qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err); |
| 1537 | if (err) { |
Markus Armbruster | 193227f | 2015-12-18 16:35:06 +0100 | [diff] [blame] | 1538 | error_report_err(err); |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 1539 | return; |
| 1540 | } |
| 1541 | |
| 1542 | if (!detach) { |
zhanghailiang | e49f35b | 2015-03-13 16:08:39 +0800 | [diff] [blame] | 1543 | HMPMigrationStatus *status; |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 1544 | |
| 1545 | if (monitor_suspend(mon) < 0) { |
| 1546 | monitor_printf(mon, "terminal does not allow synchronous " |
| 1547 | "migration, continuing detached\n"); |
| 1548 | return; |
| 1549 | } |
| 1550 | |
| 1551 | status = g_malloc0(sizeof(*status)); |
| 1552 | status->mon = mon; |
| 1553 | status->is_block_migration = blk || inc; |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 1554 | status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb, |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 1555 | status); |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 1556 | timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME)); |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 1557 | } |
| 1558 | } |
Luiz Capitulino | a15fef2 | 2012-03-29 12:38:50 -0300 | [diff] [blame] | 1559 | |
Markus Armbruster | 318660f | 2015-03-05 17:24:48 +0100 | [diff] [blame] | 1560 | void hmp_device_add(Monitor *mon, const QDict *qdict) |
| 1561 | { |
Markus Armbruster | 485febc | 2015-03-13 17:25:50 +0100 | [diff] [blame] | 1562 | Error *err = NULL; |
| 1563 | |
| 1564 | qmp_device_add((QDict *)qdict, NULL, &err); |
| 1565 | hmp_handle_error(mon, &err); |
Markus Armbruster | 318660f | 2015-03-05 17:24:48 +0100 | [diff] [blame] | 1566 | } |
| 1567 | |
Luiz Capitulino | a15fef2 | 2012-03-29 12:38:50 -0300 | [diff] [blame] | 1568 | void hmp_device_del(Monitor *mon, const QDict *qdict) |
| 1569 | { |
| 1570 | const char *id = qdict_get_str(qdict, "id"); |
| 1571 | Error *err = NULL; |
| 1572 | |
| 1573 | qmp_device_del(id, &err); |
| 1574 | hmp_handle_error(mon, &err); |
| 1575 | } |
Wen Congyang | 783e9b4 | 2012-05-07 12:10:47 +0800 | [diff] [blame] | 1576 | |
| 1577 | void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) |
| 1578 | { |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1579 | Error *err = NULL; |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 1580 | bool paging = qdict_get_try_bool(qdict, "paging", false); |
| 1581 | bool zlib = qdict_get_try_bool(qdict, "zlib", false); |
| 1582 | bool lzo = qdict_get_try_bool(qdict, "lzo", false); |
| 1583 | bool snappy = qdict_get_try_bool(qdict, "snappy", false); |
Luiz Capitulino | 7536376 | 2012-09-21 13:53:00 -0300 | [diff] [blame] | 1584 | const char *file = qdict_get_str(qdict, "filename"); |
Wen Congyang | 783e9b4 | 2012-05-07 12:10:47 +0800 | [diff] [blame] | 1585 | bool has_begin = qdict_haskey(qdict, "begin"); |
| 1586 | bool has_length = qdict_haskey(qdict, "length"); |
| 1587 | int64_t begin = 0; |
| 1588 | int64_t length = 0; |
qiaonuohan | b53ccc3 | 2014-02-18 14:11:36 +0800 | [diff] [blame] | 1589 | enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF; |
Luiz Capitulino | 7536376 | 2012-09-21 13:53:00 -0300 | [diff] [blame] | 1590 | char *prot; |
Wen Congyang | 783e9b4 | 2012-05-07 12:10:47 +0800 | [diff] [blame] | 1591 | |
Qiao Nuohan | 1b7a0f7 | 2014-04-17 16:15:07 +0800 | [diff] [blame] | 1592 | if (zlib + lzo + snappy > 1) { |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1593 | error_setg(&err, "only one of '-z|-l|-s' can be set"); |
| 1594 | hmp_handle_error(mon, &err); |
Qiao Nuohan | 1b7a0f7 | 2014-04-17 16:15:07 +0800 | [diff] [blame] | 1595 | return; |
| 1596 | } |
| 1597 | |
| 1598 | if (zlib) { |
| 1599 | dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB; |
| 1600 | } |
| 1601 | |
| 1602 | if (lzo) { |
| 1603 | dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO; |
| 1604 | } |
| 1605 | |
| 1606 | if (snappy) { |
| 1607 | dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY; |
| 1608 | } |
| 1609 | |
Wen Congyang | 783e9b4 | 2012-05-07 12:10:47 +0800 | [diff] [blame] | 1610 | if (has_begin) { |
| 1611 | begin = qdict_get_int(qdict, "begin"); |
| 1612 | } |
| 1613 | if (has_length) { |
| 1614 | length = qdict_get_int(qdict, "length"); |
| 1615 | } |
| 1616 | |
Luiz Capitulino | 7536376 | 2012-09-21 13:53:00 -0300 | [diff] [blame] | 1617 | prot = g_strconcat("file:", file, NULL); |
| 1618 | |
| 1619 | qmp_dump_guest_memory(paging, prot, has_begin, begin, has_length, length, |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1620 | true, dump_format, &err); |
| 1621 | hmp_handle_error(mon, &err); |
Luiz Capitulino | 7536376 | 2012-09-21 13:53:00 -0300 | [diff] [blame] | 1622 | g_free(prot); |
Wen Congyang | 783e9b4 | 2012-05-07 12:10:47 +0800 | [diff] [blame] | 1623 | } |
Luiz Capitulino | 928059a | 2012-04-18 17:34:15 -0300 | [diff] [blame] | 1624 | |
| 1625 | void hmp_netdev_add(Monitor *mon, const QDict *qdict) |
| 1626 | { |
| 1627 | Error *err = NULL; |
| 1628 | QemuOpts *opts; |
| 1629 | |
| 1630 | opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err); |
Markus Armbruster | 84d18f0 | 2014-01-30 15:07:28 +0100 | [diff] [blame] | 1631 | if (err) { |
Luiz Capitulino | 928059a | 2012-04-18 17:34:15 -0300 | [diff] [blame] | 1632 | goto out; |
| 1633 | } |
| 1634 | |
| 1635 | netdev_add(opts, &err); |
Markus Armbruster | 84d18f0 | 2014-01-30 15:07:28 +0100 | [diff] [blame] | 1636 | if (err) { |
Luiz Capitulino | 928059a | 2012-04-18 17:34:15 -0300 | [diff] [blame] | 1637 | qemu_opts_del(opts); |
| 1638 | } |
| 1639 | |
| 1640 | out: |
| 1641 | hmp_handle_error(mon, &err); |
| 1642 | } |
Luiz Capitulino | 5f96415 | 2012-04-16 14:36:32 -0300 | [diff] [blame] | 1643 | |
| 1644 | void hmp_netdev_del(Monitor *mon, const QDict *qdict) |
| 1645 | { |
| 1646 | const char *id = qdict_get_str(qdict, "id"); |
| 1647 | Error *err = NULL; |
| 1648 | |
| 1649 | qmp_netdev_del(id, &err); |
| 1650 | hmp_handle_error(mon, &err); |
| 1651 | } |
Corey Bryant | 208c9d1 | 2012-06-22 14:36:09 -0400 | [diff] [blame] | 1652 | |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 1653 | void hmp_object_add(Monitor *mon, const QDict *qdict) |
| 1654 | { |
| 1655 | Error *err = NULL; |
Markus Armbruster | f9f3a5e | 2014-05-07 09:53:51 +0200 | [diff] [blame] | 1656 | Error *err_end = NULL; |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 1657 | QemuOpts *opts; |
| 1658 | char *type = NULL; |
| 1659 | char *id = NULL; |
| 1660 | void *dummy = NULL; |
| 1661 | OptsVisitor *ov; |
| 1662 | QDict *pdict; |
| 1663 | |
| 1664 | opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err); |
| 1665 | if (err) { |
| 1666 | goto out; |
| 1667 | } |
| 1668 | |
| 1669 | ov = opts_visitor_new(opts); |
| 1670 | pdict = qdict_clone_shallow(qdict); |
| 1671 | |
| 1672 | visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err); |
| 1673 | if (err) { |
| 1674 | goto out_clean; |
| 1675 | } |
| 1676 | |
| 1677 | qdict_del(pdict, "qom-type"); |
| 1678 | visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err); |
| 1679 | if (err) { |
Markus Armbruster | f9f3a5e | 2014-05-07 09:53:51 +0200 | [diff] [blame] | 1680 | goto out_end; |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | qdict_del(pdict, "id"); |
| 1684 | visit_type_str(opts_get_visitor(ov), &id, "id", &err); |
| 1685 | if (err) { |
Markus Armbruster | f9f3a5e | 2014-05-07 09:53:51 +0200 | [diff] [blame] | 1686 | goto out_end; |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | object_add(type, id, pdict, opts_get_visitor(ov), &err); |
Markus Armbruster | f9f3a5e | 2014-05-07 09:53:51 +0200 | [diff] [blame] | 1690 | |
| 1691 | out_end: |
| 1692 | visit_end_struct(opts_get_visitor(ov), &err_end); |
| 1693 | if (!err && err_end) { |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 1694 | qmp_object_del(id, NULL); |
| 1695 | } |
Markus Armbruster | f9f3a5e | 2014-05-07 09:53:51 +0200 | [diff] [blame] | 1696 | error_propagate(&err, err_end); |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 1697 | out_clean: |
| 1698 | opts_visitor_cleanup(ov); |
| 1699 | |
| 1700 | QDECREF(pdict); |
| 1701 | qemu_opts_del(opts); |
| 1702 | g_free(id); |
| 1703 | g_free(type); |
| 1704 | g_free(dummy); |
| 1705 | |
| 1706 | out: |
| 1707 | hmp_handle_error(mon, &err); |
| 1708 | } |
| 1709 | |
Corey Bryant | 208c9d1 | 2012-06-22 14:36:09 -0400 | [diff] [blame] | 1710 | void hmp_getfd(Monitor *mon, const QDict *qdict) |
| 1711 | { |
| 1712 | const char *fdname = qdict_get_str(qdict, "fdname"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1713 | Error *err = NULL; |
Corey Bryant | 208c9d1 | 2012-06-22 14:36:09 -0400 | [diff] [blame] | 1714 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1715 | qmp_getfd(fdname, &err); |
| 1716 | hmp_handle_error(mon, &err); |
Corey Bryant | 208c9d1 | 2012-06-22 14:36:09 -0400 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | void hmp_closefd(Monitor *mon, const QDict *qdict) |
| 1720 | { |
| 1721 | const char *fdname = qdict_get_str(qdict, "fdname"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1722 | Error *err = NULL; |
Corey Bryant | 208c9d1 | 2012-06-22 14:36:09 -0400 | [diff] [blame] | 1723 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1724 | qmp_closefd(fdname, &err); |
| 1725 | hmp_handle_error(mon, &err); |
Corey Bryant | 208c9d1 | 2012-06-22 14:36:09 -0400 | [diff] [blame] | 1726 | } |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1727 | |
Markus Armbruster | 3e5a50d | 2015-02-06 13:55:43 +0100 | [diff] [blame] | 1728 | void hmp_sendkey(Monitor *mon, const QDict *qdict) |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1729 | { |
| 1730 | const char *keys = qdict_get_str(qdict, "keys"); |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 1731 | KeyValueList *keylist, *head = NULL, *tmp = NULL; |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1732 | int has_hold_time = qdict_haskey(qdict, "hold-time"); |
| 1733 | int hold_time = qdict_get_try_int(qdict, "hold-time", -1); |
| 1734 | Error *err = NULL; |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1735 | char *separator; |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 1736 | int keyname_len; |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1737 | |
| 1738 | while (1) { |
| 1739 | separator = strchr(keys, '-'); |
| 1740 | keyname_len = separator ? separator - keys : strlen(keys); |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1741 | |
| 1742 | /* Be compatible with old interface, convert user inputted "<" */ |
Wolfgang Bumiller | 64ffbe0 | 2016-01-13 09:09:58 +0100 | [diff] [blame] | 1743 | if (keys[0] == '<' && keyname_len == 1) { |
| 1744 | keys = "less"; |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1745 | keyname_len = 4; |
| 1746 | } |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1747 | |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1748 | keylist = g_malloc0(sizeof(*keylist)); |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 1749 | keylist->value = g_malloc0(sizeof(*keylist->value)); |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1750 | |
| 1751 | if (!head) { |
| 1752 | head = keylist; |
| 1753 | } |
| 1754 | if (tmp) { |
| 1755 | tmp->next = keylist; |
| 1756 | } |
| 1757 | tmp = keylist; |
| 1758 | |
Wolfgang Bumiller | 64ffbe0 | 2016-01-13 09:09:58 +0100 | [diff] [blame] | 1759 | if (strstart(keys, "0x", NULL)) { |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 1760 | char *endp; |
Wolfgang Bumiller | 64ffbe0 | 2016-01-13 09:09:58 +0100 | [diff] [blame] | 1761 | int value = strtoul(keys, &endp, 0); |
| 1762 | assert(endp <= keys + keyname_len); |
| 1763 | if (endp != keys + keyname_len) { |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 1764 | goto err_out; |
| 1765 | } |
Eric Blake | 568c73a | 2015-10-26 16:34:58 -0600 | [diff] [blame] | 1766 | keylist->value->type = KEY_VALUE_KIND_NUMBER; |
| 1767 | keylist->value->u.number = value; |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 1768 | } else { |
Wolfgang Bumiller | 64ffbe0 | 2016-01-13 09:09:58 +0100 | [diff] [blame] | 1769 | int idx = index_from_key(keys, keyname_len); |
Eric Blake | 7fb1cf1 | 2015-11-18 01:52:57 -0700 | [diff] [blame] | 1770 | if (idx == Q_KEY_CODE__MAX) { |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 1771 | goto err_out; |
| 1772 | } |
Eric Blake | 568c73a | 2015-10-26 16:34:58 -0600 | [diff] [blame] | 1773 | keylist->value->type = KEY_VALUE_KIND_QCODE; |
| 1774 | keylist->value->u.qcode = idx; |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 1775 | } |
| 1776 | |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1777 | if (!separator) { |
| 1778 | break; |
| 1779 | } |
| 1780 | keys = separator + 1; |
| 1781 | } |
| 1782 | |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 1783 | qmp_send_key(head, has_hold_time, hold_time, &err); |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1784 | hmp_handle_error(mon, &err); |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 1785 | |
| 1786 | out: |
| 1787 | qapi_free_KeyValueList(head); |
| 1788 | return; |
| 1789 | |
| 1790 | err_out: |
Wolfgang Bumiller | 64ffbe0 | 2016-01-13 09:09:58 +0100 | [diff] [blame] | 1791 | monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys); |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 1792 | goto out; |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 1793 | } |
Luiz Capitulino | ad39cf6 | 2012-05-24 13:48:23 -0300 | [diff] [blame] | 1794 | |
Markus Armbruster | 3e5a50d | 2015-02-06 13:55:43 +0100 | [diff] [blame] | 1795 | void hmp_screendump(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | ad39cf6 | 2012-05-24 13:48:23 -0300 | [diff] [blame] | 1796 | { |
| 1797 | const char *filename = qdict_get_str(qdict, "filename"); |
| 1798 | Error *err = NULL; |
| 1799 | |
| 1800 | qmp_screendump(filename, &err); |
| 1801 | hmp_handle_error(mon, &err); |
| 1802 | } |
Paolo Bonzini | 4057725 | 2012-08-23 11:53:04 +0200 | [diff] [blame] | 1803 | |
| 1804 | void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) |
| 1805 | { |
| 1806 | const char *uri = qdict_get_str(qdict, "uri"); |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 1807 | bool writable = qdict_get_try_bool(qdict, "writable", false); |
| 1808 | bool all = qdict_get_try_bool(qdict, "all", false); |
Paolo Bonzini | 4057725 | 2012-08-23 11:53:04 +0200 | [diff] [blame] | 1809 | Error *local_err = NULL; |
| 1810 | BlockInfoList *block_list, *info; |
| 1811 | SocketAddress *addr; |
| 1812 | |
| 1813 | if (writable && !all) { |
| 1814 | error_setg(&local_err, "-w only valid together with -a"); |
| 1815 | goto exit; |
| 1816 | } |
| 1817 | |
| 1818 | /* First check if the address is valid and start the server. */ |
| 1819 | addr = socket_parse(uri, &local_err); |
| 1820 | if (local_err != NULL) { |
| 1821 | goto exit; |
| 1822 | } |
| 1823 | |
| 1824 | qmp_nbd_server_start(addr, &local_err); |
| 1825 | qapi_free_SocketAddress(addr); |
| 1826 | if (local_err != NULL) { |
| 1827 | goto exit; |
| 1828 | } |
| 1829 | |
| 1830 | if (!all) { |
| 1831 | return; |
| 1832 | } |
| 1833 | |
| 1834 | /* Then try adding all block devices. If one fails, close all and |
| 1835 | * exit. |
| 1836 | */ |
| 1837 | block_list = qmp_query_block(NULL); |
| 1838 | |
| 1839 | for (info = block_list; info; info = info->next) { |
| 1840 | if (!info->value->has_inserted) { |
| 1841 | continue; |
| 1842 | } |
| 1843 | |
| 1844 | qmp_nbd_server_add(info->value->device, true, writable, &local_err); |
| 1845 | |
| 1846 | if (local_err != NULL) { |
| 1847 | qmp_nbd_server_stop(NULL); |
| 1848 | break; |
| 1849 | } |
| 1850 | } |
| 1851 | |
| 1852 | qapi_free_BlockInfoList(block_list); |
| 1853 | |
| 1854 | exit: |
| 1855 | hmp_handle_error(mon, &local_err); |
| 1856 | } |
| 1857 | |
| 1858 | void hmp_nbd_server_add(Monitor *mon, const QDict *qdict) |
| 1859 | { |
| 1860 | const char *device = qdict_get_str(qdict, "device"); |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 1861 | bool writable = qdict_get_try_bool(qdict, "writable", false); |
Paolo Bonzini | 4057725 | 2012-08-23 11:53:04 +0200 | [diff] [blame] | 1862 | Error *local_err = NULL; |
| 1863 | |
| 1864 | qmp_nbd_server_add(device, true, writable, &local_err); |
| 1865 | |
| 1866 | if (local_err != NULL) { |
| 1867 | hmp_handle_error(mon, &local_err); |
| 1868 | } |
| 1869 | } |
| 1870 | |
| 1871 | void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict) |
| 1872 | { |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1873 | Error *err = NULL; |
Paolo Bonzini | 4057725 | 2012-08-23 11:53:04 +0200 | [diff] [blame] | 1874 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1875 | qmp_nbd_server_stop(&err); |
| 1876 | hmp_handle_error(mon, &err); |
Paolo Bonzini | 4057725 | 2012-08-23 11:53:04 +0200 | [diff] [blame] | 1877 | } |
Gerd Hoffmann | f108890 | 2012-12-19 10:33:40 +0100 | [diff] [blame] | 1878 | |
Jason J. Herne | abf2332 | 2013-12-11 13:24:14 -0500 | [diff] [blame] | 1879 | void hmp_cpu_add(Monitor *mon, const QDict *qdict) |
| 1880 | { |
| 1881 | int cpuid; |
| 1882 | Error *err = NULL; |
| 1883 | |
| 1884 | cpuid = qdict_get_int(qdict, "id"); |
| 1885 | qmp_cpu_add(cpuid, &err); |
| 1886 | hmp_handle_error(mon, &err); |
| 1887 | } |
| 1888 | |
Gerd Hoffmann | f108890 | 2012-12-19 10:33:40 +0100 | [diff] [blame] | 1889 | void hmp_chardev_add(Monitor *mon, const QDict *qdict) |
| 1890 | { |
| 1891 | const char *args = qdict_get_str(qdict, "args"); |
| 1892 | Error *err = NULL; |
| 1893 | QemuOpts *opts; |
| 1894 | |
Markus Armbruster | 70b9433 | 2015-02-13 12:50:26 +0100 | [diff] [blame] | 1895 | opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true); |
Gerd Hoffmann | f108890 | 2012-12-19 10:33:40 +0100 | [diff] [blame] | 1896 | if (opts == NULL) { |
Markus Armbruster | 312fd5f | 2013-02-08 21:22:16 +0100 | [diff] [blame] | 1897 | error_setg(&err, "Parsing chardev args failed"); |
Gerd Hoffmann | f108890 | 2012-12-19 10:33:40 +0100 | [diff] [blame] | 1898 | } else { |
| 1899 | qemu_chr_new_from_opts(opts, NULL, &err); |
| 1900 | } |
| 1901 | hmp_handle_error(mon, &err); |
| 1902 | } |
| 1903 | |
| 1904 | void hmp_chardev_remove(Monitor *mon, const QDict *qdict) |
| 1905 | { |
| 1906 | Error *local_err = NULL; |
| 1907 | |
| 1908 | qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err); |
| 1909 | hmp_handle_error(mon, &local_err); |
| 1910 | } |
Kevin Wolf | 587da2c | 2013-06-05 14:19:41 +0200 | [diff] [blame] | 1911 | |
| 1912 | void hmp_qemu_io(Monitor *mon, const QDict *qdict) |
| 1913 | { |
Max Reitz | 4c7b7e9 | 2015-02-05 13:58:22 -0500 | [diff] [blame] | 1914 | BlockBackend *blk; |
Kevin Wolf | 587da2c | 2013-06-05 14:19:41 +0200 | [diff] [blame] | 1915 | const char* device = qdict_get_str(qdict, "device"); |
| 1916 | const char* command = qdict_get_str(qdict, "command"); |
| 1917 | Error *err = NULL; |
| 1918 | |
Max Reitz | 4c7b7e9 | 2015-02-05 13:58:22 -0500 | [diff] [blame] | 1919 | blk = blk_by_name(device); |
| 1920 | if (blk) { |
| 1921 | qemuio_command(blk, command); |
Kevin Wolf | 587da2c | 2013-06-05 14:19:41 +0200 | [diff] [blame] | 1922 | } else { |
Markus Armbruster | 75158eb | 2015-03-16 08:57:47 +0100 | [diff] [blame] | 1923 | error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND, |
| 1924 | "Device '%s' not found", device); |
Kevin Wolf | 587da2c | 2013-06-05 14:19:41 +0200 | [diff] [blame] | 1925 | } |
| 1926 | |
| 1927 | hmp_handle_error(mon, &err); |
| 1928 | } |
Paolo Bonzini | ab2d053 | 2013-12-20 23:21:09 +0100 | [diff] [blame] | 1929 | |
| 1930 | void hmp_object_del(Monitor *mon, const QDict *qdict) |
| 1931 | { |
| 1932 | const char *id = qdict_get_str(qdict, "id"); |
| 1933 | Error *err = NULL; |
| 1934 | |
| 1935 | qmp_object_del(id, &err); |
| 1936 | hmp_handle_error(mon, &err); |
| 1937 | } |
Hu Tao | eb1539b | 2014-05-14 17:43:35 +0800 | [diff] [blame] | 1938 | |
| 1939 | void hmp_info_memdev(Monitor *mon, const QDict *qdict) |
| 1940 | { |
| 1941 | Error *err = NULL; |
| 1942 | MemdevList *memdev_list = qmp_query_memdev(&err); |
| 1943 | MemdevList *m = memdev_list; |
| 1944 | StringOutputVisitor *ov; |
Chen Fan | 976620a | 2014-08-18 14:46:34 +0800 | [diff] [blame] | 1945 | char *str; |
Hu Tao | eb1539b | 2014-05-14 17:43:35 +0800 | [diff] [blame] | 1946 | int i = 0; |
| 1947 | |
| 1948 | |
| 1949 | while (m) { |
| 1950 | ov = string_output_visitor_new(false); |
| 1951 | visit_type_uint16List(string_output_get_visitor(ov), |
| 1952 | &m->value->host_nodes, NULL, NULL); |
Igor Mammedov | 8f4e5ac | 2014-06-19 16:14:43 +0200 | [diff] [blame] | 1953 | monitor_printf(mon, "memory backend: %d\n", i); |
Hu Tao | eb1539b | 2014-05-14 17:43:35 +0800 | [diff] [blame] | 1954 | monitor_printf(mon, " size: %" PRId64 "\n", m->value->size); |
| 1955 | monitor_printf(mon, " merge: %s\n", |
| 1956 | m->value->merge ? "true" : "false"); |
| 1957 | monitor_printf(mon, " dump: %s\n", |
| 1958 | m->value->dump ? "true" : "false"); |
| 1959 | monitor_printf(mon, " prealloc: %s\n", |
| 1960 | m->value->prealloc ? "true" : "false"); |
| 1961 | monitor_printf(mon, " policy: %s\n", |
| 1962 | HostMemPolicy_lookup[m->value->policy]); |
Chen Fan | 976620a | 2014-08-18 14:46:34 +0800 | [diff] [blame] | 1963 | str = string_output_get_string(ov); |
| 1964 | monitor_printf(mon, " host nodes: %s\n", str); |
Hu Tao | eb1539b | 2014-05-14 17:43:35 +0800 | [diff] [blame] | 1965 | |
Chen Fan | 976620a | 2014-08-18 14:46:34 +0800 | [diff] [blame] | 1966 | g_free(str); |
Hu Tao | eb1539b | 2014-05-14 17:43:35 +0800 | [diff] [blame] | 1967 | string_output_visitor_cleanup(ov); |
| 1968 | m = m->next; |
| 1969 | i++; |
| 1970 | } |
| 1971 | |
| 1972 | monitor_printf(mon, "\n"); |
Chen Fan | ecaf54a | 2014-08-18 14:46:35 +0800 | [diff] [blame] | 1973 | |
| 1974 | qapi_free_MemdevList(memdev_list); |
Hu Tao | eb1539b | 2014-05-14 17:43:35 +0800 | [diff] [blame] | 1975 | } |
Zhu Guihua | a631892 | 2014-09-23 13:35:19 +0800 | [diff] [blame] | 1976 | |
| 1977 | void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) |
| 1978 | { |
| 1979 | Error *err = NULL; |
| 1980 | MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err); |
| 1981 | MemoryDeviceInfoList *info; |
| 1982 | MemoryDeviceInfo *value; |
| 1983 | PCDIMMDeviceInfo *di; |
| 1984 | |
| 1985 | for (info = info_list; info; info = info->next) { |
| 1986 | value = info->value; |
| 1987 | |
| 1988 | if (value) { |
Eric Blake | 1fd5d4f | 2015-10-26 16:34:59 -0600 | [diff] [blame] | 1989 | switch (value->type) { |
Zhu Guihua | a631892 | 2014-09-23 13:35:19 +0800 | [diff] [blame] | 1990 | case MEMORY_DEVICE_INFO_KIND_DIMM: |
Eric Blake | 1fd5d4f | 2015-10-26 16:34:59 -0600 | [diff] [blame] | 1991 | di = value->u.dimm; |
Zhu Guihua | a631892 | 2014-09-23 13:35:19 +0800 | [diff] [blame] | 1992 | |
| 1993 | monitor_printf(mon, "Memory device [%s]: \"%s\"\n", |
Eric Blake | 1fd5d4f | 2015-10-26 16:34:59 -0600 | [diff] [blame] | 1994 | MemoryDeviceInfoKind_lookup[value->type], |
Zhu Guihua | a631892 | 2014-09-23 13:35:19 +0800 | [diff] [blame] | 1995 | di->id ? di->id : ""); |
| 1996 | monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr); |
| 1997 | monitor_printf(mon, " slot: %" PRId64 "\n", di->slot); |
| 1998 | monitor_printf(mon, " node: %" PRId64 "\n", di->node); |
| 1999 | monitor_printf(mon, " size: %" PRIu64 "\n", di->size); |
| 2000 | monitor_printf(mon, " memdev: %s\n", di->memdev); |
| 2001 | monitor_printf(mon, " hotplugged: %s\n", |
| 2002 | di->hotplugged ? "true" : "false"); |
| 2003 | monitor_printf(mon, " hotpluggable: %s\n", |
| 2004 | di->hotpluggable ? "true" : "false"); |
| 2005 | break; |
| 2006 | default: |
| 2007 | break; |
| 2008 | } |
| 2009 | } |
| 2010 | } |
| 2011 | |
| 2012 | qapi_free_MemoryDeviceInfoList(info_list); |
| 2013 | } |
Andreas Färber | 89d7fa9 | 2014-05-07 18:08:29 +0200 | [diff] [blame] | 2014 | |
Ting Wang | 6231316 | 2015-06-26 16:07:13 +0800 | [diff] [blame] | 2015 | void hmp_info_iothreads(Monitor *mon, const QDict *qdict) |
| 2016 | { |
| 2017 | IOThreadInfoList *info_list = qmp_query_iothreads(NULL); |
| 2018 | IOThreadInfoList *info; |
| 2019 | |
| 2020 | for (info = info_list; info; info = info->next) { |
| 2021 | monitor_printf(mon, "%s: thread_id=%" PRId64 "\n", |
| 2022 | info->value->id, info->value->thread_id); |
| 2023 | } |
| 2024 | |
| 2025 | qapi_free_IOThreadInfoList(info_list); |
| 2026 | } |
| 2027 | |
Andreas Färber | 89d7fa9 | 2014-05-07 18:08:29 +0200 | [diff] [blame] | 2028 | void hmp_qom_list(Monitor *mon, const QDict *qdict) |
| 2029 | { |
| 2030 | const char *path = qdict_get_try_str(qdict, "path"); |
| 2031 | ObjectPropertyInfoList *list; |
| 2032 | Error *err = NULL; |
| 2033 | |
| 2034 | if (path == NULL) { |
| 2035 | monitor_printf(mon, "/\n"); |
| 2036 | return; |
| 2037 | } |
| 2038 | |
| 2039 | list = qmp_qom_list(path, &err); |
| 2040 | if (err == NULL) { |
| 2041 | ObjectPropertyInfoList *start = list; |
| 2042 | while (list != NULL) { |
| 2043 | ObjectPropertyInfo *value = list->value; |
| 2044 | |
| 2045 | monitor_printf(mon, "%s (%s)\n", |
| 2046 | value->name, value->type); |
| 2047 | list = list->next; |
| 2048 | } |
| 2049 | qapi_free_ObjectPropertyInfoList(start); |
| 2050 | } |
| 2051 | hmp_handle_error(mon, &err); |
| 2052 | } |
Andreas Färber | c0e6ee9 | 2014-05-07 19:48:15 +0200 | [diff] [blame] | 2053 | |
| 2054 | void hmp_qom_set(Monitor *mon, const QDict *qdict) |
| 2055 | { |
| 2056 | const char *path = qdict_get_str(qdict, "path"); |
| 2057 | const char *property = qdict_get_str(qdict, "property"); |
| 2058 | const char *value = qdict_get_str(qdict, "value"); |
| 2059 | Error *err = NULL; |
| 2060 | bool ambiguous = false; |
| 2061 | Object *obj; |
| 2062 | |
| 2063 | obj = object_resolve_path(path, &ambiguous); |
| 2064 | if (obj == NULL) { |
Markus Armbruster | 75158eb | 2015-03-16 08:57:47 +0100 | [diff] [blame] | 2065 | error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND, |
| 2066 | "Device '%s' not found", path); |
Andreas Färber | c0e6ee9 | 2014-05-07 19:48:15 +0200 | [diff] [blame] | 2067 | } else { |
| 2068 | if (ambiguous) { |
| 2069 | monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path); |
| 2070 | } |
| 2071 | object_property_parse(obj, value, property, &err); |
| 2072 | } |
| 2073 | hmp_handle_error(mon, &err); |
| 2074 | } |
Scott Feldman | fafa4d5 | 2015-06-10 18:21:21 -0700 | [diff] [blame] | 2075 | |
| 2076 | void hmp_rocker(Monitor *mon, const QDict *qdict) |
| 2077 | { |
| 2078 | const char *name = qdict_get_str(qdict, "name"); |
| 2079 | RockerSwitch *rocker; |
Markus Armbruster | 533fdae | 2015-12-18 16:35:27 +0100 | [diff] [blame] | 2080 | Error *err = NULL; |
Scott Feldman | fafa4d5 | 2015-06-10 18:21:21 -0700 | [diff] [blame] | 2081 | |
Markus Armbruster | 533fdae | 2015-12-18 16:35:27 +0100 | [diff] [blame] | 2082 | rocker = qmp_query_rocker(name, &err); |
| 2083 | if (err != NULL) { |
| 2084 | hmp_handle_error(mon, &err); |
Scott Feldman | fafa4d5 | 2015-06-10 18:21:21 -0700 | [diff] [blame] | 2085 | return; |
| 2086 | } |
| 2087 | |
| 2088 | monitor_printf(mon, "name: %s\n", rocker->name); |
| 2089 | monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id); |
| 2090 | monitor_printf(mon, "ports: %d\n", rocker->ports); |
| 2091 | |
| 2092 | qapi_free_RockerSwitch(rocker); |
| 2093 | } |
| 2094 | |
| 2095 | void hmp_rocker_ports(Monitor *mon, const QDict *qdict) |
| 2096 | { |
| 2097 | RockerPortList *list, *port; |
| 2098 | const char *name = qdict_get_str(qdict, "name"); |
Markus Armbruster | 533fdae | 2015-12-18 16:35:27 +0100 | [diff] [blame] | 2099 | Error *err = NULL; |
Scott Feldman | fafa4d5 | 2015-06-10 18:21:21 -0700 | [diff] [blame] | 2100 | |
Markus Armbruster | 533fdae | 2015-12-18 16:35:27 +0100 | [diff] [blame] | 2101 | list = qmp_query_rocker_ports(name, &err); |
| 2102 | if (err != NULL) { |
| 2103 | hmp_handle_error(mon, &err); |
Scott Feldman | fafa4d5 | 2015-06-10 18:21:21 -0700 | [diff] [blame] | 2104 | return; |
| 2105 | } |
| 2106 | |
| 2107 | monitor_printf(mon, " ena/ speed/ auto\n"); |
| 2108 | monitor_printf(mon, " port link duplex neg?\n"); |
| 2109 | |
| 2110 | for (port = list; port; port = port->next) { |
| 2111 | monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n", |
| 2112 | port->value->name, |
| 2113 | port->value->enabled ? port->value->link_up ? |
| 2114 | "up" : "down" : "!ena", |
| 2115 | port->value->speed == 10000 ? "10G" : "??", |
| 2116 | port->value->duplex ? "FD" : "HD", |
| 2117 | port->value->autoneg ? "Yes" : "No"); |
| 2118 | } |
| 2119 | |
| 2120 | qapi_free_RockerPortList(list); |
| 2121 | } |
| 2122 | |
| 2123 | void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict) |
| 2124 | { |
| 2125 | RockerOfDpaFlowList *list, *info; |
| 2126 | const char *name = qdict_get_str(qdict, "name"); |
| 2127 | uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1); |
Markus Armbruster | 533fdae | 2015-12-18 16:35:27 +0100 | [diff] [blame] | 2128 | Error *err = NULL; |
Scott Feldman | fafa4d5 | 2015-06-10 18:21:21 -0700 | [diff] [blame] | 2129 | |
Markus Armbruster | 533fdae | 2015-12-18 16:35:27 +0100 | [diff] [blame] | 2130 | list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err); |
| 2131 | if (err != NULL) { |
| 2132 | hmp_handle_error(mon, &err); |
Scott Feldman | fafa4d5 | 2015-06-10 18:21:21 -0700 | [diff] [blame] | 2133 | return; |
| 2134 | } |
| 2135 | |
| 2136 | monitor_printf(mon, "prio tbl hits key(mask) --> actions\n"); |
| 2137 | |
| 2138 | for (info = list; info; info = info->next) { |
| 2139 | RockerOfDpaFlow *flow = info->value; |
| 2140 | RockerOfDpaFlowKey *key = flow->key; |
| 2141 | RockerOfDpaFlowMask *mask = flow->mask; |
| 2142 | RockerOfDpaFlowAction *action = flow->action; |
| 2143 | |
| 2144 | if (flow->hits) { |
| 2145 | monitor_printf(mon, "%-4d %-3d %-4" PRIu64, |
| 2146 | key->priority, key->tbl_id, flow->hits); |
| 2147 | } else { |
| 2148 | monitor_printf(mon, "%-4d %-3d ", |
| 2149 | key->priority, key->tbl_id); |
| 2150 | } |
| 2151 | |
| 2152 | if (key->has_in_pport) { |
| 2153 | monitor_printf(mon, " pport %d", key->in_pport); |
| 2154 | if (mask->has_in_pport) { |
| 2155 | monitor_printf(mon, "(0x%x)", mask->in_pport); |
| 2156 | } |
| 2157 | } |
| 2158 | |
| 2159 | if (key->has_vlan_id) { |
| 2160 | monitor_printf(mon, " vlan %d", |
| 2161 | key->vlan_id & VLAN_VID_MASK); |
| 2162 | if (mask->has_vlan_id) { |
| 2163 | monitor_printf(mon, "(0x%x)", mask->vlan_id); |
| 2164 | } |
| 2165 | } |
| 2166 | |
| 2167 | if (key->has_tunnel_id) { |
| 2168 | monitor_printf(mon, " tunnel %d", key->tunnel_id); |
| 2169 | if (mask->has_tunnel_id) { |
| 2170 | monitor_printf(mon, "(0x%x)", mask->tunnel_id); |
| 2171 | } |
| 2172 | } |
| 2173 | |
| 2174 | if (key->has_eth_type) { |
| 2175 | switch (key->eth_type) { |
| 2176 | case 0x0806: |
| 2177 | monitor_printf(mon, " ARP"); |
| 2178 | break; |
| 2179 | case 0x0800: |
| 2180 | monitor_printf(mon, " IP"); |
| 2181 | break; |
| 2182 | case 0x86dd: |
| 2183 | monitor_printf(mon, " IPv6"); |
| 2184 | break; |
| 2185 | case 0x8809: |
| 2186 | monitor_printf(mon, " LACP"); |
| 2187 | break; |
| 2188 | case 0x88cc: |
| 2189 | monitor_printf(mon, " LLDP"); |
| 2190 | break; |
| 2191 | default: |
| 2192 | monitor_printf(mon, " eth type 0x%04x", key->eth_type); |
| 2193 | break; |
| 2194 | } |
| 2195 | } |
| 2196 | |
| 2197 | if (key->has_eth_src) { |
| 2198 | if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) && |
| 2199 | (mask->has_eth_src) && |
| 2200 | (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { |
| 2201 | monitor_printf(mon, " src <any mcast/bcast>"); |
| 2202 | } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) && |
| 2203 | (mask->has_eth_src) && |
| 2204 | (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { |
| 2205 | monitor_printf(mon, " src <any ucast>"); |
| 2206 | } else { |
| 2207 | monitor_printf(mon, " src %s", key->eth_src); |
| 2208 | if (mask->has_eth_src) { |
| 2209 | monitor_printf(mon, "(%s)", mask->eth_src); |
| 2210 | } |
| 2211 | } |
| 2212 | } |
| 2213 | |
| 2214 | if (key->has_eth_dst) { |
| 2215 | if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) && |
| 2216 | (mask->has_eth_dst) && |
| 2217 | (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { |
| 2218 | monitor_printf(mon, " dst <any mcast/bcast>"); |
| 2219 | } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) && |
| 2220 | (mask->has_eth_dst) && |
| 2221 | (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { |
| 2222 | monitor_printf(mon, " dst <any ucast>"); |
| 2223 | } else { |
| 2224 | monitor_printf(mon, " dst %s", key->eth_dst); |
| 2225 | if (mask->has_eth_dst) { |
| 2226 | monitor_printf(mon, "(%s)", mask->eth_dst); |
| 2227 | } |
| 2228 | } |
| 2229 | } |
| 2230 | |
| 2231 | if (key->has_ip_proto) { |
| 2232 | monitor_printf(mon, " proto %d", key->ip_proto); |
| 2233 | if (mask->has_ip_proto) { |
| 2234 | monitor_printf(mon, "(0x%x)", mask->ip_proto); |
| 2235 | } |
| 2236 | } |
| 2237 | |
| 2238 | if (key->has_ip_tos) { |
| 2239 | monitor_printf(mon, " TOS %d", key->ip_tos); |
| 2240 | if (mask->has_ip_tos) { |
| 2241 | monitor_printf(mon, "(0x%x)", mask->ip_tos); |
| 2242 | } |
| 2243 | } |
| 2244 | |
| 2245 | if (key->has_ip_dst) { |
| 2246 | monitor_printf(mon, " dst %s", key->ip_dst); |
| 2247 | } |
| 2248 | |
| 2249 | if (action->has_goto_tbl || action->has_group_id || |
| 2250 | action->has_new_vlan_id) { |
| 2251 | monitor_printf(mon, " -->"); |
| 2252 | } |
| 2253 | |
| 2254 | if (action->has_new_vlan_id) { |
| 2255 | monitor_printf(mon, " apply new vlan %d", |
| 2256 | ntohs(action->new_vlan_id)); |
| 2257 | } |
| 2258 | |
| 2259 | if (action->has_group_id) { |
| 2260 | monitor_printf(mon, " write group 0x%08x", action->group_id); |
| 2261 | } |
| 2262 | |
| 2263 | if (action->has_goto_tbl) { |
| 2264 | monitor_printf(mon, " goto tbl %d", action->goto_tbl); |
| 2265 | } |
| 2266 | |
| 2267 | monitor_printf(mon, "\n"); |
| 2268 | } |
| 2269 | |
| 2270 | qapi_free_RockerOfDpaFlowList(list); |
| 2271 | } |
| 2272 | |
| 2273 | void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict) |
| 2274 | { |
| 2275 | RockerOfDpaGroupList *list, *g; |
| 2276 | const char *name = qdict_get_str(qdict, "name"); |
| 2277 | uint8_t type = qdict_get_try_int(qdict, "type", 9); |
Markus Armbruster | 533fdae | 2015-12-18 16:35:27 +0100 | [diff] [blame] | 2278 | Error *err = NULL; |
Scott Feldman | fafa4d5 | 2015-06-10 18:21:21 -0700 | [diff] [blame] | 2279 | bool set = false; |
| 2280 | |
Markus Armbruster | 533fdae | 2015-12-18 16:35:27 +0100 | [diff] [blame] | 2281 | list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err); |
| 2282 | if (err != NULL) { |
| 2283 | hmp_handle_error(mon, &err); |
Scott Feldman | fafa4d5 | 2015-06-10 18:21:21 -0700 | [diff] [blame] | 2284 | return; |
| 2285 | } |
| 2286 | |
| 2287 | monitor_printf(mon, "id (decode) --> buckets\n"); |
| 2288 | |
| 2289 | for (g = list; g; g = g->next) { |
| 2290 | RockerOfDpaGroup *group = g->value; |
| 2291 | |
| 2292 | monitor_printf(mon, "0x%08x", group->id); |
| 2293 | |
| 2294 | monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" : |
| 2295 | group->type == 1 ? "L2 rewrite" : |
| 2296 | group->type == 2 ? "L3 unicast" : |
| 2297 | group->type == 3 ? "L2 multicast" : |
| 2298 | group->type == 4 ? "L2 flood" : |
| 2299 | group->type == 5 ? "L3 interface" : |
| 2300 | group->type == 6 ? "L3 multicast" : |
| 2301 | group->type == 7 ? "L3 ECMP" : |
| 2302 | group->type == 8 ? "L2 overlay" : |
| 2303 | "unknown"); |
| 2304 | |
| 2305 | if (group->has_vlan_id) { |
| 2306 | monitor_printf(mon, " vlan %d", group->vlan_id); |
| 2307 | } |
| 2308 | |
| 2309 | if (group->has_pport) { |
| 2310 | monitor_printf(mon, " pport %d", group->pport); |
| 2311 | } |
| 2312 | |
| 2313 | if (group->has_index) { |
| 2314 | monitor_printf(mon, " index %d", group->index); |
| 2315 | } |
| 2316 | |
| 2317 | monitor_printf(mon, ") -->"); |
| 2318 | |
| 2319 | if (group->has_set_vlan_id && group->set_vlan_id) { |
| 2320 | set = true; |
| 2321 | monitor_printf(mon, " set vlan %d", |
| 2322 | group->set_vlan_id & VLAN_VID_MASK); |
| 2323 | } |
| 2324 | |
| 2325 | if (group->has_set_eth_src) { |
| 2326 | if (!set) { |
| 2327 | set = true; |
| 2328 | monitor_printf(mon, " set"); |
| 2329 | } |
| 2330 | monitor_printf(mon, " src %s", group->set_eth_src); |
| 2331 | } |
| 2332 | |
| 2333 | if (group->has_set_eth_dst) { |
| 2334 | if (!set) { |
| 2335 | set = true; |
| 2336 | monitor_printf(mon, " set"); |
| 2337 | } |
| 2338 | monitor_printf(mon, " dst %s", group->set_eth_dst); |
| 2339 | } |
| 2340 | |
| 2341 | set = false; |
| 2342 | |
| 2343 | if (group->has_ttl_check && group->ttl_check) { |
| 2344 | monitor_printf(mon, " check TTL"); |
| 2345 | } |
| 2346 | |
| 2347 | if (group->has_group_id && group->group_id) { |
| 2348 | monitor_printf(mon, " group id 0x%08x", group->group_id); |
| 2349 | } |
| 2350 | |
| 2351 | if (group->has_pop_vlan && group->pop_vlan) { |
| 2352 | monitor_printf(mon, " pop vlan"); |
| 2353 | } |
| 2354 | |
| 2355 | if (group->has_out_pport) { |
| 2356 | monitor_printf(mon, " out pport %d", group->out_pport); |
| 2357 | } |
| 2358 | |
| 2359 | if (group->has_group_ids) { |
| 2360 | struct uint32List *id; |
| 2361 | |
| 2362 | monitor_printf(mon, " groups ["); |
| 2363 | for (id = group->group_ids; id; id = id->next) { |
| 2364 | monitor_printf(mon, "0x%08x", id->value); |
| 2365 | if (id->next) { |
| 2366 | monitor_printf(mon, ","); |
| 2367 | } |
| 2368 | } |
| 2369 | monitor_printf(mon, "]"); |
| 2370 | } |
| 2371 | |
| 2372 | monitor_printf(mon, "\n"); |
| 2373 | } |
| 2374 | |
| 2375 | qapi_free_RockerOfDpaGroupList(list); |
| 2376 | } |