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