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