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