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" |
Marc-André Lureau | 8228e35 | 2017-01-26 17:19:46 +0400 | [diff] [blame] | 20 | #include "chardev/char.h" |
Max Reitz | 4c7b7e9 | 2015-02-05 13:58:22 -0500 | [diff] [blame] | 21 | #include "sysemu/block-backend.h" |
Juan Quintela | 52b2620 | 2017-04-18 11:40:56 +0200 | [diff] [blame] | 22 | #include "sysemu/sysemu.h" |
Marc-André Lureau | 213dcb0 | 2016-12-12 20:22:24 +0300 | [diff] [blame] | 23 | #include "qemu/config-file.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 24 | #include "qemu/option.h" |
| 25 | #include "qemu/timer.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 26 | #include "qemu/sockets.h" |
Paolo Bonzini | 83c9089 | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 27 | #include "monitor/monitor.h" |
Markus Armbruster | 318660f | 2015-03-05 17:24:48 +0100 | [diff] [blame] | 28 | #include "monitor/qdev.h" |
Markus Armbruster | e688df6 | 2018-02-01 12:18:31 +0100 | [diff] [blame] | 29 | #include "qapi/error.h" |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 30 | #include "qapi/opts-visitor.h" |
Markus Armbruster | eb815e2 | 2018-02-11 10:36:05 +0100 | [diff] [blame] | 31 | #include "qapi/qapi-builtin-visit.h" |
Markus Armbruster | 112ed24 | 2018-02-26 17:13:27 -0600 | [diff] [blame] | 32 | #include "qapi/qapi-commands-block.h" |
| 33 | #include "qapi/qapi-commands-char.h" |
| 34 | #include "qapi/qapi-commands-migration.h" |
| 35 | #include "qapi/qapi-commands-misc.h" |
| 36 | #include "qapi/qapi-commands-net.h" |
| 37 | #include "qapi/qapi-commands-rocker.h" |
| 38 | #include "qapi/qapi-commands-run-state.h" |
| 39 | #include "qapi/qapi-commands-tpm.h" |
| 40 | #include "qapi/qapi-commands-ui.h" |
Markus Armbruster | 452fcdb | 2018-02-01 12:18:39 +0100 | [diff] [blame] | 41 | #include "qapi/qmp/qdict.h" |
Markus Armbruster | cc7a8ea | 2015-03-17 17:22:46 +0100 | [diff] [blame] | 42 | #include "qapi/qmp/qerror.h" |
Juan Quintela | f4a06d1 | 2017-05-16 11:37:45 +0200 | [diff] [blame] | 43 | #include "qapi/string-input-visitor.h" |
Hu Tao | eb1539b | 2014-05-14 17:43:35 +0800 | [diff] [blame] | 44 | #include "qapi/string-output-visitor.h" |
Daniel P. Berrange | 90998d5 | 2016-02-10 18:40:59 +0000 | [diff] [blame] | 45 | #include "qom/object_interfaces.h" |
Paolo Bonzini | 28ecbae | 2012-11-28 12:06:30 +0100 | [diff] [blame] | 46 | #include "ui/console.h" |
Markus Armbruster | bd269eb | 2017-04-26 09:36:41 +0200 | [diff] [blame] | 47 | #include "block/nbd.h" |
Wenchao Xia | bd093a3 | 2013-06-06 12:28:00 +0800 | [diff] [blame] | 48 | #include "block/qapi.h" |
Kevin Wolf | 587da2c | 2013-06-05 14:19:41 +0200 | [diff] [blame] | 49 | #include "qemu-io.h" |
Veronia Bahaa | f348b6d | 2016-03-20 19:16:19 +0200 | [diff] [blame] | 50 | #include "qemu/cutils.h" |
Daniel P. Berrange | d59ce6f | 2016-04-27 11:05:00 +0100 | [diff] [blame] | 51 | #include "qemu/error-report.h" |
Peter Xu | be9b23c | 2017-05-12 12:17:41 +0800 | [diff] [blame] | 52 | #include "exec/ramlist.h" |
Hervé Poussineau | 61b9783 | 2016-09-26 22:23:27 +0200 | [diff] [blame] | 53 | #include "hw/intc/intc.h" |
Juan Quintela | 5e22479 | 2017-04-20 14:25:55 +0200 | [diff] [blame] | 54 | #include "migration/snapshot.h" |
Peter Xu | 9d18af9 | 2017-06-27 12:10:19 +0800 | [diff] [blame] | 55 | #include "migration/misc.h" |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 56 | |
Cole Robinson | 22fa7da | 2015-03-01 09:29:18 -0500 | [diff] [blame] | 57 | #ifdef CONFIG_SPICE |
| 58 | #include <spice/enums.h> |
| 59 | #endif |
| 60 | |
Luiz Capitulino | 0cfd6a9 | 2011-11-22 16:32:37 -0200 | [diff] [blame] | 61 | static void hmp_handle_error(Monitor *mon, Error **errp) |
| 62 | { |
Markus Armbruster | 415168e | 2014-05-02 13:26:34 +0200 | [diff] [blame] | 63 | assert(errp); |
| 64 | if (*errp) { |
Dr. David Alan Gilbert | 66363e9 | 2019-02-12 13:47:56 +0000 | [diff] [blame^] | 65 | error_reportf_err(*errp, "Error: "); |
Luiz Capitulino | 0cfd6a9 | 2011-11-22 16:32:37 -0200 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 69 | void hmp_info_name(Monitor *mon, const QDict *qdict) |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 70 | { |
| 71 | NameInfo *info; |
| 72 | |
| 73 | info = qmp_query_name(NULL); |
| 74 | if (info->has_name) { |
| 75 | monitor_printf(mon, "%s\n", info->name); |
| 76 | } |
| 77 | qapi_free_NameInfo(info); |
| 78 | } |
Luiz Capitulino | b9c15f1 | 2011-08-26 17:38:13 -0300 | [diff] [blame] | 79 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 80 | void hmp_info_version(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | b9c15f1 | 2011-08-26 17:38:13 -0300 | [diff] [blame] | 81 | { |
| 82 | VersionInfo *info; |
| 83 | |
| 84 | info = qmp_query_version(NULL); |
| 85 | |
| 86 | monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n", |
Eric Blake | 4752cdb | 2015-05-04 09:05:31 -0600 | [diff] [blame] | 87 | info->qemu->major, info->qemu->minor, info->qemu->micro, |
Luiz Capitulino | b9c15f1 | 2011-08-26 17:38:13 -0300 | [diff] [blame] | 88 | info->package); |
| 89 | |
| 90 | qapi_free_VersionInfo(info); |
| 91 | } |
Luiz Capitulino | 292a260 | 2011-09-12 15:10:53 -0300 | [diff] [blame] | 92 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 93 | void hmp_info_kvm(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | 292a260 | 2011-09-12 15:10:53 -0300 | [diff] [blame] | 94 | { |
| 95 | KvmInfo *info; |
| 96 | |
| 97 | info = qmp_query_kvm(NULL); |
| 98 | monitor_printf(mon, "kvm support: "); |
| 99 | if (info->present) { |
| 100 | monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled"); |
| 101 | } else { |
| 102 | monitor_printf(mon, "not compiled\n"); |
| 103 | } |
| 104 | |
| 105 | qapi_free_KvmInfo(info); |
| 106 | } |
| 107 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 108 | void hmp_info_status(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | 1fa9a5e | 2011-09-12 17:54:20 -0300 | [diff] [blame] | 109 | { |
| 110 | StatusInfo *info; |
| 111 | |
| 112 | info = qmp_query_status(NULL); |
| 113 | |
| 114 | monitor_printf(mon, "VM status: %s%s", |
| 115 | info->running ? "running" : "paused", |
| 116 | info->singlestep ? " (single step mode)" : ""); |
| 117 | |
| 118 | if (!info->running && info->status != RUN_STATE_PAUSED) { |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 119 | monitor_printf(mon, " (%s)", RunState_str(info->status)); |
Luiz Capitulino | 1fa9a5e | 2011-09-12 17:54:20 -0300 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | monitor_printf(mon, "\n"); |
| 123 | |
| 124 | qapi_free_StatusInfo(info); |
| 125 | } |
| 126 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 127 | void hmp_info_uuid(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | efab767 | 2011-09-13 17:16:25 -0300 | [diff] [blame] | 128 | { |
| 129 | UuidInfo *info; |
| 130 | |
| 131 | info = qmp_query_uuid(NULL); |
| 132 | monitor_printf(mon, "%s\n", info->UUID); |
| 133 | qapi_free_UuidInfo(info); |
| 134 | } |
Luiz Capitulino | c5a415a | 2011-09-14 16:05:49 -0300 | [diff] [blame] | 135 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 136 | void hmp_info_chardev(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | c5a415a | 2011-09-14 16:05:49 -0300 | [diff] [blame] | 137 | { |
| 138 | ChardevInfoList *char_info, *info; |
| 139 | |
| 140 | char_info = qmp_query_chardev(NULL); |
| 141 | for (info = char_info; info; info = info->next) { |
| 142 | monitor_printf(mon, "%s: filename=%s\n", info->value->label, |
| 143 | info->value->filename); |
| 144 | } |
| 145 | |
| 146 | qapi_free_ChardevInfoList(char_info); |
| 147 | } |
Luiz Capitulino | 7a7f325 | 2011-09-15 14:20:28 -0300 | [diff] [blame] | 148 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 149 | void hmp_info_mice(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | e235cec | 2011-09-21 15:29:55 -0300 | [diff] [blame] | 150 | { |
| 151 | MouseInfoList *mice_list, *mouse; |
| 152 | |
| 153 | mice_list = qmp_query_mice(NULL); |
| 154 | if (!mice_list) { |
| 155 | monitor_printf(mon, "No mouse devices connected\n"); |
| 156 | return; |
| 157 | } |
| 158 | |
| 159 | for (mouse = mice_list; mouse; mouse = mouse->next) { |
| 160 | monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n", |
| 161 | mouse->value->current ? '*' : ' ', |
| 162 | mouse->value->index, mouse->value->name, |
| 163 | mouse->value->absolute ? " (absolute)" : ""); |
| 164 | } |
| 165 | |
| 166 | qapi_free_MouseInfoList(mice_list); |
| 167 | } |
| 168 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 169 | void hmp_info_migrate(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 170 | { |
| 171 | MigrationInfo *info; |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 172 | MigrationCapabilityStatusList *caps, *cap; |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 173 | |
| 174 | info = qmp_query_migrate(NULL); |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 175 | caps = qmp_query_migrate_capabilities(NULL); |
| 176 | |
Peter Xu | 9d18af9 | 2017-06-27 12:10:19 +0800 | [diff] [blame] | 177 | migration_global_dump(mon); |
| 178 | |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 179 | /* do not display parameters during setup */ |
| 180 | if (info->has_status && caps) { |
| 181 | monitor_printf(mon, "capabilities: "); |
| 182 | for (cap = caps; cap; cap = cap->next) { |
| 183 | monitor_printf(mon, "%s: %s ", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 184 | MigrationCapability_str(cap->value->capability), |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 185 | cap->value->state ? "on" : "off"); |
| 186 | } |
| 187 | monitor_printf(mon, "\n"); |
| 188 | } |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 189 | |
| 190 | if (info->has_status) { |
Daniel P. Berrange | d59ce6f | 2016-04-27 11:05:00 +0100 | [diff] [blame] | 191 | monitor_printf(mon, "Migration status: %s", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 192 | MigrationStatus_str(info->status)); |
Daniel P. Berrange | d59ce6f | 2016-04-27 11:05:00 +0100 | [diff] [blame] | 193 | if (info->status == MIGRATION_STATUS_FAILED && |
| 194 | info->has_error_desc) { |
| 195 | monitor_printf(mon, " (%s)\n", info->error_desc); |
| 196 | } else { |
| 197 | monitor_printf(mon, "\n"); |
| 198 | } |
| 199 | |
Juan Quintela | 7aa939a | 2012-08-18 13:17:10 +0200 | [diff] [blame] | 200 | monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n", |
| 201 | info->total_time); |
Juan Quintela | 2c52ddf | 2012-08-13 09:53:12 +0200 | [diff] [blame] | 202 | if (info->has_expected_downtime) { |
| 203 | monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n", |
| 204 | info->expected_downtime); |
| 205 | } |
Juan Quintela | 9c5a9fc | 2012-08-13 09:35:16 +0200 | [diff] [blame] | 206 | if (info->has_downtime) { |
| 207 | monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n", |
| 208 | info->downtime); |
| 209 | } |
Michael R. Hines | ed4fbd1 | 2013-07-22 10:01:58 -0400 | [diff] [blame] | 210 | if (info->has_setup_time) { |
| 211 | monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n", |
| 212 | info->setup_time); |
| 213 | } |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | if (info->has_ram) { |
| 217 | monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n", |
| 218 | info->ram->transferred >> 10); |
Michael R. Hines | 7e114f8 | 2013-06-25 21:35:30 -0400 | [diff] [blame] | 219 | monitor_printf(mon, "throughput: %0.2f mbps\n", |
| 220 | info->ram->mbps); |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 221 | monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n", |
| 222 | info->ram->remaining >> 10); |
| 223 | monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n", |
| 224 | info->ram->total >> 10); |
Orit Wasserman | 004d4c1 | 2012-08-06 21:42:56 +0300 | [diff] [blame] | 225 | monitor_printf(mon, "duplicate: %" PRIu64 " pages\n", |
| 226 | info->ram->duplicate); |
Peter Lieven | f1c7279 | 2013-03-26 10:58:37 +0100 | [diff] [blame] | 227 | monitor_printf(mon, "skipped: %" PRIu64 " pages\n", |
| 228 | info->ram->skipped); |
Orit Wasserman | 004d4c1 | 2012-08-06 21:42:56 +0300 | [diff] [blame] | 229 | monitor_printf(mon, "normal: %" PRIu64 " pages\n", |
| 230 | info->ram->normal); |
| 231 | monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n", |
| 232 | info->ram->normal_bytes >> 10); |
ChenLiang | 58570ed | 2014-04-04 17:57:55 +0800 | [diff] [blame] | 233 | monitor_printf(mon, "dirty sync count: %" PRIu64 "\n", |
| 234 | info->ram->dirty_sync_count); |
Chao Fan | 030ce1f | 2017-03-21 10:22:43 +0800 | [diff] [blame] | 235 | monitor_printf(mon, "page size: %" PRIu64 " kbytes\n", |
| 236 | info->ram->page_size >> 10); |
Juan Quintela | a61c45b | 2018-06-26 15:20:11 +0200 | [diff] [blame] | 237 | monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n", |
| 238 | info->ram->multifd_bytes >> 10); |
Xiao Guangrong | aecbfe9 | 2019-01-11 14:37:30 +0800 | [diff] [blame] | 239 | monitor_printf(mon, "pages-per-second: %" PRIu64 "\n", |
| 240 | info->ram->pages_per_second); |
Chao Fan | 030ce1f | 2017-03-21 10:22:43 +0800 | [diff] [blame] | 241 | |
Juan Quintela | 8d01719 | 2012-08-13 12:31:25 +0200 | [diff] [blame] | 242 | if (info->ram->dirty_pages_rate) { |
| 243 | monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n", |
| 244 | info->ram->dirty_pages_rate); |
| 245 | } |
Dr. David Alan Gilbert | d3bf541 | 2016-06-13 12:16:42 +0100 | [diff] [blame] | 246 | if (info->ram->postcopy_requests) { |
| 247 | monitor_printf(mon, "postcopy request count: %" PRIu64 "\n", |
| 248 | info->ram->postcopy_requests); |
| 249 | } |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | if (info->has_disk) { |
| 253 | monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n", |
| 254 | info->disk->transferred >> 10); |
| 255 | monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n", |
| 256 | info->disk->remaining >> 10); |
| 257 | monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n", |
| 258 | info->disk->total >> 10); |
| 259 | } |
| 260 | |
Orit Wasserman | f36d55a | 2012-08-06 21:42:57 +0300 | [diff] [blame] | 261 | if (info->has_xbzrle_cache) { |
| 262 | monitor_printf(mon, "cache size: %" PRIu64 " bytes\n", |
| 263 | info->xbzrle_cache->cache_size); |
| 264 | monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n", |
| 265 | info->xbzrle_cache->bytes >> 10); |
| 266 | monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n", |
| 267 | info->xbzrle_cache->pages); |
| 268 | monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n", |
| 269 | info->xbzrle_cache->cache_miss); |
ChenLiang | 8bc3923 | 2014-04-04 17:57:56 +0800 | [diff] [blame] | 270 | monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n", |
| 271 | info->xbzrle_cache->cache_miss_rate); |
Orit Wasserman | f36d55a | 2012-08-06 21:42:57 +0300 | [diff] [blame] | 272 | monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n", |
| 273 | info->xbzrle_cache->overflow); |
| 274 | } |
| 275 | |
Xiao Guangrong | 76e0300 | 2018-09-06 15:01:00 +0800 | [diff] [blame] | 276 | if (info->has_compression) { |
| 277 | monitor_printf(mon, "compression pages: %" PRIu64 " pages\n", |
| 278 | info->compression->pages); |
| 279 | monitor_printf(mon, "compression busy: %" PRIu64 "\n", |
| 280 | info->compression->busy); |
| 281 | monitor_printf(mon, "compression busy rate: %0.2f\n", |
| 282 | info->compression->busy_rate); |
| 283 | monitor_printf(mon, "compressed size: %" PRIu64 "\n", |
| 284 | info->compression->compressed_size); |
| 285 | monitor_printf(mon, "compression rate: %0.2f\n", |
| 286 | info->compression->compression_rate); |
| 287 | } |
| 288 | |
Jason J. Herne | d85a31d | 2016-04-21 14:07:18 -0400 | [diff] [blame] | 289 | if (info->has_cpu_throttle_percentage) { |
Jason J. Herne | 4782893 | 2015-09-08 13:12:36 -0400 | [diff] [blame] | 290 | monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n", |
Jason J. Herne | d85a31d | 2016-04-21 14:07:18 -0400 | [diff] [blame] | 291 | info->cpu_throttle_percentage); |
Jason J. Herne | 4782893 | 2015-09-08 13:12:36 -0400 | [diff] [blame] | 292 | } |
| 293 | |
Alexey Perevalov | 65ace06 | 2018-03-22 21:17:27 +0300 | [diff] [blame] | 294 | if (info->has_postcopy_blocktime) { |
| 295 | monitor_printf(mon, "postcopy blocktime: %u\n", |
| 296 | info->postcopy_blocktime); |
| 297 | } |
| 298 | |
| 299 | if (info->has_postcopy_vcpu_blocktime) { |
| 300 | Visitor *v; |
| 301 | char *str; |
| 302 | v = string_output_visitor_new(false, &str); |
| 303 | visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, NULL); |
| 304 | visit_complete(v, &str); |
| 305 | monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str); |
| 306 | g_free(str); |
| 307 | visit_free(v); |
| 308 | } |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 309 | qapi_free_MigrationInfo(info); |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 310 | qapi_free_MigrationCapabilityStatusList(caps); |
| 311 | } |
| 312 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 313 | void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict) |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 314 | { |
| 315 | MigrationCapabilityStatusList *caps, *cap; |
| 316 | |
| 317 | caps = qmp_query_migrate_capabilities(NULL); |
| 318 | |
| 319 | if (caps) { |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 320 | for (cap = caps; cap; cap = cap->next) { |
Peter Xu | d80a016 | 2017-04-01 16:18:44 +0800 | [diff] [blame] | 321 | monitor_printf(mon, "%s: %s\n", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 322 | MigrationCapability_str(cap->value->capability), |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 323 | cap->value->state ? "on" : "off"); |
| 324 | } |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | qapi_free_MigrationCapabilityStatusList(caps); |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 328 | } |
| 329 | |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 330 | void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) |
| 331 | { |
| 332 | MigrationParameters *params; |
| 333 | |
| 334 | params = qmp_query_migrate_parameters(NULL); |
| 335 | |
| 336 | if (params) { |
Eric Blake | de63ab6 | 2016-09-08 22:14:15 -0500 | [diff] [blame] | 337 | assert(params->has_compress_level); |
Juan Quintela | 741d408 | 2017-12-01 13:08:38 +0100 | [diff] [blame] | 338 | monitor_printf(mon, "%s: %u\n", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 339 | MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL), |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 340 | params->compress_level); |
Eric Blake | de63ab6 | 2016-09-08 22:14:15 -0500 | [diff] [blame] | 341 | assert(params->has_compress_threads); |
Juan Quintela | 741d408 | 2017-12-01 13:08:38 +0100 | [diff] [blame] | 342 | monitor_printf(mon, "%s: %u\n", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 343 | MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS), |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 344 | params->compress_threads); |
Xiao Guangrong | 1d58872 | 2018-08-21 16:10:20 +0800 | [diff] [blame] | 345 | assert(params->has_compress_wait_thread); |
| 346 | monitor_printf(mon, "%s: %s\n", |
| 347 | MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD), |
| 348 | params->compress_wait_thread ? "on" : "off"); |
Eric Blake | de63ab6 | 2016-09-08 22:14:15 -0500 | [diff] [blame] | 349 | assert(params->has_decompress_threads); |
Juan Quintela | 741d408 | 2017-12-01 13:08:38 +0100 | [diff] [blame] | 350 | monitor_printf(mon, "%s: %u\n", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 351 | MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS), |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 352 | params->decompress_threads); |
Eric Blake | de63ab6 | 2016-09-08 22:14:15 -0500 | [diff] [blame] | 353 | assert(params->has_cpu_throttle_initial); |
Juan Quintela | 741d408 | 2017-12-01 13:08:38 +0100 | [diff] [blame] | 354 | monitor_printf(mon, "%s: %u\n", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 355 | MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL), |
Jason J. Herne | d85a31d | 2016-04-21 14:07:18 -0400 | [diff] [blame] | 356 | params->cpu_throttle_initial); |
Eric Blake | de63ab6 | 2016-09-08 22:14:15 -0500 | [diff] [blame] | 357 | assert(params->has_cpu_throttle_increment); |
Juan Quintela | 741d408 | 2017-12-01 13:08:38 +0100 | [diff] [blame] | 358 | monitor_printf(mon, "%s: %u\n", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 359 | MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT), |
Jason J. Herne | d85a31d | 2016-04-21 14:07:18 -0400 | [diff] [blame] | 360 | params->cpu_throttle_increment); |
Li Qiang | 4cbc9c7 | 2018-08-01 06:00:20 -0700 | [diff] [blame] | 361 | assert(params->has_max_cpu_throttle); |
| 362 | monitor_printf(mon, "%s: %u\n", |
| 363 | MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE), |
| 364 | params->max_cpu_throttle); |
Markus Armbruster | 8cc99dc | 2017-07-18 12:04:54 +0200 | [diff] [blame] | 365 | assert(params->has_tls_creds); |
Peter Xu | 2c02468 | 2017-04-01 16:18:45 +0800 | [diff] [blame] | 366 | monitor_printf(mon, "%s: '%s'\n", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 367 | MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS), |
Markus Armbruster | 8cc99dc | 2017-07-18 12:04:54 +0200 | [diff] [blame] | 368 | params->tls_creds); |
| 369 | assert(params->has_tls_hostname); |
Peter Xu | 2c02468 | 2017-04-01 16:18:45 +0800 | [diff] [blame] | 370 | monitor_printf(mon, "%s: '%s'\n", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 371 | MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME), |
Markus Armbruster | 8cc99dc | 2017-07-18 12:04:54 +0200 | [diff] [blame] | 372 | params->tls_hostname); |
Ashijeet Acharya | 2ff3025 | 2016-09-15 21:50:28 +0530 | [diff] [blame] | 373 | assert(params->has_max_bandwidth); |
Juan Quintela | 741d408 | 2017-12-01 13:08:38 +0100 | [diff] [blame] | 374 | monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 375 | MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH), |
Ashijeet Acharya | 2ff3025 | 2016-09-15 21:50:28 +0530 | [diff] [blame] | 376 | params->max_bandwidth); |
| 377 | assert(params->has_downtime_limit); |
Juan Quintela | 741d408 | 2017-12-01 13:08:38 +0100 | [diff] [blame] | 378 | monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 379 | MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT), |
Ashijeet Acharya | 2ff3025 | 2016-09-15 21:50:28 +0530 | [diff] [blame] | 380 | params->downtime_limit); |
zhanghailiang | fe39a4d | 2016-11-02 15:42:09 +0800 | [diff] [blame] | 381 | assert(params->has_x_checkpoint_delay); |
Juan Quintela | 741d408 | 2017-12-01 13:08:38 +0100 | [diff] [blame] | 382 | monitor_printf(mon, "%s: %u\n", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 383 | MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY), |
zhanghailiang | 68b5359 | 2016-10-27 14:43:01 +0800 | [diff] [blame] | 384 | params->x_checkpoint_delay); |
Juan Quintela | 2833c59 | 2017-04-05 18:32:37 +0200 | [diff] [blame] | 385 | assert(params->has_block_incremental); |
| 386 | monitor_printf(mon, "%s: %s\n", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 387 | MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL), |
| 388 | params->block_incremental ? "on" : "off"); |
Juan Quintela | 741d408 | 2017-12-01 13:08:38 +0100 | [diff] [blame] | 389 | monitor_printf(mon, "%s: %u\n", |
Juan Quintela | 4075fb1 | 2016-01-15 08:56:17 +0100 | [diff] [blame] | 390 | MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_CHANNELS), |
| 391 | params->x_multifd_channels); |
Juan Quintela | 741d408 | 2017-12-01 13:08:38 +0100 | [diff] [blame] | 392 | monitor_printf(mon, "%s: %u\n", |
Juan Quintela | 0fb8660 | 2017-04-27 10:48:25 +0200 | [diff] [blame] | 393 | MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT), |
| 394 | params->x_multifd_page_count); |
Juan Quintela | 741d408 | 2017-12-01 13:08:38 +0100 | [diff] [blame] | 395 | monitor_printf(mon, "%s: %" PRIu64 "\n", |
Juan Quintela | 73af8dd | 2017-10-05 21:30:10 +0200 | [diff] [blame] | 396 | MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE), |
| 397 | params->xbzrle_cache_size); |
Dr. David Alan Gilbert | 7e555c6 | 2018-06-13 11:26:40 +0100 | [diff] [blame] | 398 | monitor_printf(mon, "%s: %" PRIu64 "\n", |
| 399 | MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH), |
| 400 | params->max_postcopy_bandwidth); |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | qapi_free_MigrationParameters(params); |
| 404 | } |
| 405 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 406 | void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict) |
Orit Wasserman | 9e1ba4c | 2012-08-06 21:42:54 +0300 | [diff] [blame] | 407 | { |
| 408 | monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n", |
| 409 | qmp_query_migrate_cache_size(NULL) >> 10); |
| 410 | } |
| 411 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 412 | void hmp_info_cpus(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | de0b36b | 2011-09-21 16:38:35 -0300 | [diff] [blame] | 413 | { |
Viktor Mihajlovski | 137b5cb | 2018-02-16 17:08:41 +0100 | [diff] [blame] | 414 | CpuInfoFastList *cpu_list, *cpu; |
Luiz Capitulino | de0b36b | 2011-09-21 16:38:35 -0300 | [diff] [blame] | 415 | |
Viktor Mihajlovski | 137b5cb | 2018-02-16 17:08:41 +0100 | [diff] [blame] | 416 | cpu_list = qmp_query_cpus_fast(NULL); |
Luiz Capitulino | de0b36b | 2011-09-21 16:38:35 -0300 | [diff] [blame] | 417 | |
| 418 | for (cpu = cpu_list; cpu; cpu = cpu->next) { |
| 419 | int active = ' '; |
| 420 | |
Viktor Mihajlovski | 137b5cb | 2018-02-16 17:08:41 +0100 | [diff] [blame] | 421 | if (cpu->value->cpu_index == monitor_get_cpu_index()) { |
Luiz Capitulino | de0b36b | 2011-09-21 16:38:35 -0300 | [diff] [blame] | 422 | active = '*'; |
| 423 | } |
| 424 | |
Viktor Mihajlovski | 137b5cb | 2018-02-16 17:08:41 +0100 | [diff] [blame] | 425 | monitor_printf(mon, "%c CPU #%" PRId64 ":", active, |
| 426 | cpu->value->cpu_index); |
Satheesh Rajendran | 0dfddbb | 2018-03-27 18:08:00 +0530 | [diff] [blame] | 427 | monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id); |
Luiz Capitulino | de0b36b | 2011-09-21 16:38:35 -0300 | [diff] [blame] | 428 | } |
| 429 | |
Viktor Mihajlovski | 137b5cb | 2018-02-16 17:08:41 +0100 | [diff] [blame] | 430 | qapi_free_CpuInfoFastList(cpu_list); |
Luiz Capitulino | de0b36b | 2011-09-21 16:38:35 -0300 | [diff] [blame] | 431 | } |
| 432 | |
Kevin Wolf | 289b276 | 2014-09-15 12:06:39 +0200 | [diff] [blame] | 433 | static void print_block_info(Monitor *mon, BlockInfo *info, |
| 434 | BlockDeviceInfo *inserted, bool verbose) |
| 435 | { |
| 436 | ImageInfo *image_info; |
| 437 | |
Kevin Wolf | 8d6adcc | 2014-09-15 12:12:52 +0200 | [diff] [blame] | 438 | assert(!info || !info->has_inserted || info->inserted == inserted); |
| 439 | |
Kevin Wolf | ec18b0a | 2017-07-11 14:00:57 +0200 | [diff] [blame] | 440 | if (info && *info->device) { |
Kevin Wolf | 8d6adcc | 2014-09-15 12:12:52 +0200 | [diff] [blame] | 441 | monitor_printf(mon, "%s", info->device); |
| 442 | if (inserted && inserted->has_node_name) { |
| 443 | monitor_printf(mon, " (%s)", inserted->node_name); |
| 444 | } |
| 445 | } else { |
Kevin Wolf | ec18b0a | 2017-07-11 14:00:57 +0200 | [diff] [blame] | 446 | assert(info || inserted); |
Kevin Wolf | 8d6adcc | 2014-09-15 12:12:52 +0200 | [diff] [blame] | 447 | monitor_printf(mon, "%s", |
Kevin Wolf | ec18b0a | 2017-07-11 14:00:57 +0200 | [diff] [blame] | 448 | inserted && inserted->has_node_name ? inserted->node_name |
| 449 | : info && info->has_qdev ? info->qdev |
Kevin Wolf | 8d6adcc | 2014-09-15 12:12:52 +0200 | [diff] [blame] | 450 | : "<anonymous>"); |
| 451 | } |
| 452 | |
Kevin Wolf | 289b276 | 2014-09-15 12:06:39 +0200 | [diff] [blame] | 453 | if (inserted) { |
| 454 | monitor_printf(mon, ": %s (%s%s%s)\n", |
| 455 | inserted->file, |
| 456 | inserted->drv, |
| 457 | inserted->ro ? ", read-only" : "", |
| 458 | inserted->encrypted ? ", encrypted" : ""); |
| 459 | } else { |
| 460 | monitor_printf(mon, ": [not inserted]\n"); |
| 461 | } |
| 462 | |
Kevin Wolf | 8d6adcc | 2014-09-15 12:12:52 +0200 | [diff] [blame] | 463 | if (info) { |
Kevin Wolf | 46eade7 | 2017-07-11 13:27:38 +0200 | [diff] [blame] | 464 | if (info->has_qdev) { |
| 465 | monitor_printf(mon, " Attached to: %s\n", info->qdev); |
| 466 | } |
Kevin Wolf | 8d6adcc | 2014-09-15 12:12:52 +0200 | [diff] [blame] | 467 | if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) { |
| 468 | monitor_printf(mon, " I/O status: %s\n", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 469 | BlockDeviceIoStatus_str(info->io_status)); |
Kevin Wolf | 8d6adcc | 2014-09-15 12:12:52 +0200 | [diff] [blame] | 470 | } |
Kevin Wolf | 289b276 | 2014-09-15 12:06:39 +0200 | [diff] [blame] | 471 | |
Kevin Wolf | 8d6adcc | 2014-09-15 12:12:52 +0200 | [diff] [blame] | 472 | if (info->removable) { |
| 473 | monitor_printf(mon, " Removable device: %slocked, tray %s\n", |
| 474 | info->locked ? "" : "not ", |
| 475 | info->tray_open ? "open" : "closed"); |
| 476 | } |
Kevin Wolf | 289b276 | 2014-09-15 12:06:39 +0200 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | |
| 480 | if (!inserted) { |
| 481 | return; |
| 482 | } |
| 483 | |
| 484 | monitor_printf(mon, " Cache mode: %s%s%s\n", |
| 485 | inserted->cache->writeback ? "writeback" : "writethrough", |
| 486 | inserted->cache->direct ? ", direct" : "", |
| 487 | inserted->cache->no_flush ? ", ignore flushes" : ""); |
| 488 | |
| 489 | if (inserted->has_backing_file) { |
| 490 | monitor_printf(mon, |
| 491 | " Backing file: %s " |
| 492 | "(chain depth: %" PRId64 ")\n", |
| 493 | inserted->backing_file, |
| 494 | inserted->backing_file_depth); |
| 495 | } |
| 496 | |
| 497 | if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) { |
| 498 | monitor_printf(mon, " Detect zeroes: %s\n", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 499 | BlockdevDetectZeroesOptions_str(inserted->detect_zeroes)); |
Kevin Wolf | 289b276 | 2014-09-15 12:06:39 +0200 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | if (inserted->bps || inserted->bps_rd || inserted->bps_wr || |
| 503 | inserted->iops || inserted->iops_rd || inserted->iops_wr) |
| 504 | { |
| 505 | monitor_printf(mon, " I/O throttling: bps=%" PRId64 |
| 506 | " bps_rd=%" PRId64 " bps_wr=%" PRId64 |
| 507 | " bps_max=%" PRId64 |
| 508 | " bps_rd_max=%" PRId64 |
| 509 | " bps_wr_max=%" PRId64 |
| 510 | " iops=%" PRId64 " iops_rd=%" PRId64 |
| 511 | " iops_wr=%" PRId64 |
| 512 | " iops_max=%" PRId64 |
| 513 | " iops_rd_max=%" PRId64 |
| 514 | " iops_wr_max=%" PRId64 |
Alberto Garcia | b8fe169 | 2015-06-08 18:17:46 +0200 | [diff] [blame] | 515 | " iops_size=%" PRId64 |
| 516 | " group=%s\n", |
Kevin Wolf | 289b276 | 2014-09-15 12:06:39 +0200 | [diff] [blame] | 517 | inserted->bps, |
| 518 | inserted->bps_rd, |
| 519 | inserted->bps_wr, |
| 520 | inserted->bps_max, |
| 521 | inserted->bps_rd_max, |
| 522 | inserted->bps_wr_max, |
| 523 | inserted->iops, |
| 524 | inserted->iops_rd, |
| 525 | inserted->iops_wr, |
| 526 | inserted->iops_max, |
| 527 | inserted->iops_rd_max, |
| 528 | inserted->iops_wr_max, |
Alberto Garcia | b8fe169 | 2015-06-08 18:17:46 +0200 | [diff] [blame] | 529 | inserted->iops_size, |
| 530 | inserted->group); |
Kevin Wolf | 289b276 | 2014-09-15 12:06:39 +0200 | [diff] [blame] | 531 | } |
| 532 | |
Stefan Hajnoczi | 9419874 | 2015-04-22 11:15:10 +0100 | [diff] [blame] | 533 | if (verbose) { |
Kevin Wolf | 289b276 | 2014-09-15 12:06:39 +0200 | [diff] [blame] | 534 | monitor_printf(mon, "\nImages:\n"); |
| 535 | image_info = inserted->image; |
| 536 | while (1) { |
| 537 | bdrv_image_info_dump((fprintf_function)monitor_printf, |
| 538 | mon, image_info); |
| 539 | if (image_info->has_backing_image) { |
| 540 | image_info = image_info->backing_image; |
| 541 | } else { |
| 542 | break; |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | } |
| 547 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 548 | void hmp_info_block(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | b202381 | 2011-09-21 17:16:47 -0300 | [diff] [blame] | 549 | { |
| 550 | BlockInfoList *block_list, *info; |
Kevin Wolf | e6bb31e | 2014-09-15 12:19:14 +0200 | [diff] [blame] | 551 | BlockDeviceInfoList *blockdev_list, *blockdev; |
Wenchao Xia | e73fe2b | 2013-06-06 12:28:01 +0800 | [diff] [blame] | 552 | const char *device = qdict_get_try_str(qdict, "device"); |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 553 | bool verbose = qdict_get_try_bool(qdict, "verbose", false); |
| 554 | bool nodes = qdict_get_try_bool(qdict, "nodes", false); |
Kevin Wolf | e6bb31e | 2014-09-15 12:19:14 +0200 | [diff] [blame] | 555 | bool printed = false; |
Luiz Capitulino | b202381 | 2011-09-21 17:16:47 -0300 | [diff] [blame] | 556 | |
Kevin Wolf | e6bb31e | 2014-09-15 12:19:14 +0200 | [diff] [blame] | 557 | /* Print BlockBackend information */ |
| 558 | if (!nodes) { |
Stefan Weil | f19e44b | 2015-02-08 15:40:48 +0100 | [diff] [blame] | 559 | block_list = qmp_query_block(NULL); |
Kevin Wolf | e6bb31e | 2014-09-15 12:19:14 +0200 | [diff] [blame] | 560 | } else { |
| 561 | block_list = NULL; |
| 562 | } |
Luiz Capitulino | b202381 | 2011-09-21 17:16:47 -0300 | [diff] [blame] | 563 | |
| 564 | for (info = block_list; info; info = info->next) { |
Wenchao Xia | e73fe2b | 2013-06-06 12:28:01 +0800 | [diff] [blame] | 565 | if (device && strcmp(device, info->value->device)) { |
| 566 | continue; |
| 567 | } |
Luiz Capitulino | b202381 | 2011-09-21 17:16:47 -0300 | [diff] [blame] | 568 | |
Kevin Wolf | fbe2e26 | 2013-06-19 16:10:55 +0200 | [diff] [blame] | 569 | if (info != block_list) { |
| 570 | monitor_printf(mon, "\n"); |
Luiz Capitulino | b202381 | 2011-09-21 17:16:47 -0300 | [diff] [blame] | 571 | } |
| 572 | |
Kevin Wolf | 289b276 | 2014-09-15 12:06:39 +0200 | [diff] [blame] | 573 | print_block_info(mon, info->value, info->value->has_inserted |
| 574 | ? info->value->inserted : NULL, |
| 575 | verbose); |
Kevin Wolf | e6bb31e | 2014-09-15 12:19:14 +0200 | [diff] [blame] | 576 | printed = true; |
Luiz Capitulino | b202381 | 2011-09-21 17:16:47 -0300 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | qapi_free_BlockInfoList(block_list); |
Kevin Wolf | e6bb31e | 2014-09-15 12:19:14 +0200 | [diff] [blame] | 580 | |
| 581 | if ((!device && !nodes) || printed) { |
| 582 | return; |
| 583 | } |
| 584 | |
| 585 | /* Print node information */ |
| 586 | blockdev_list = qmp_query_named_block_nodes(NULL); |
| 587 | for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) { |
| 588 | assert(blockdev->value->has_node_name); |
| 589 | if (device && strcmp(device, blockdev->value->node_name)) { |
| 590 | continue; |
| 591 | } |
| 592 | |
| 593 | if (blockdev != blockdev_list) { |
| 594 | monitor_printf(mon, "\n"); |
| 595 | } |
| 596 | |
| 597 | print_block_info(mon, NULL, blockdev->value, verbose); |
| 598 | } |
| 599 | qapi_free_BlockDeviceInfoList(blockdev_list); |
Luiz Capitulino | b202381 | 2011-09-21 17:16:47 -0300 | [diff] [blame] | 600 | } |
| 601 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 602 | void hmp_info_blockstats(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | f11f57e | 2011-09-22 15:56:36 -0300 | [diff] [blame] | 603 | { |
| 604 | BlockStatsList *stats_list, *stats; |
| 605 | |
Fam Zheng | f71eaa7 | 2014-10-31 11:32:57 +0800 | [diff] [blame] | 606 | stats_list = qmp_query_blockstats(false, false, NULL); |
Luiz Capitulino | f11f57e | 2011-09-22 15:56:36 -0300 | [diff] [blame] | 607 | |
| 608 | for (stats = stats_list; stats; stats = stats->next) { |
| 609 | if (!stats->value->has_device) { |
| 610 | continue; |
| 611 | } |
| 612 | |
| 613 | monitor_printf(mon, "%s:", stats->value->device); |
| 614 | monitor_printf(mon, " rd_bytes=%" PRId64 |
| 615 | " wr_bytes=%" PRId64 |
| 616 | " rd_operations=%" PRId64 |
| 617 | " wr_operations=%" PRId64 |
| 618 | " flush_operations=%" PRId64 |
| 619 | " wr_total_time_ns=%" PRId64 |
| 620 | " rd_total_time_ns=%" PRId64 |
| 621 | " flush_total_time_ns=%" PRId64 |
Peter Lieven | f4564d5 | 2015-02-02 14:52:18 +0100 | [diff] [blame] | 622 | " rd_merged=%" PRId64 |
| 623 | " wr_merged=%" PRId64 |
Alberto Garcia | cb38fff | 2015-10-28 17:33:02 +0200 | [diff] [blame] | 624 | " idle_time_ns=%" PRId64 |
Luiz Capitulino | f11f57e | 2011-09-22 15:56:36 -0300 | [diff] [blame] | 625 | "\n", |
| 626 | stats->value->stats->rd_bytes, |
| 627 | stats->value->stats->wr_bytes, |
| 628 | stats->value->stats->rd_operations, |
| 629 | stats->value->stats->wr_operations, |
| 630 | stats->value->stats->flush_operations, |
| 631 | stats->value->stats->wr_total_time_ns, |
| 632 | stats->value->stats->rd_total_time_ns, |
Peter Lieven | f4564d5 | 2015-02-02 14:52:18 +0100 | [diff] [blame] | 633 | stats->value->stats->flush_total_time_ns, |
| 634 | stats->value->stats->rd_merged, |
Alberto Garcia | cb38fff | 2015-10-28 17:33:02 +0200 | [diff] [blame] | 635 | stats->value->stats->wr_merged, |
| 636 | stats->value->stats->idle_time_ns); |
Luiz Capitulino | f11f57e | 2011-09-22 15:56:36 -0300 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | qapi_free_BlockStatsList(stats_list); |
| 640 | } |
| 641 | |
Marc-André Lureau | 05eb4a2 | 2018-07-03 17:56:47 +0200 | [diff] [blame] | 642 | #ifdef CONFIG_VNC |
Dr. David Alan Gilbert | 0a9667e | 2017-07-11 16:44:14 +0100 | [diff] [blame] | 643 | /* Helper for hmp_info_vnc_clients, _servers */ |
| 644 | static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info, |
| 645 | const char *name) |
| 646 | { |
| 647 | monitor_printf(mon, " %s: %s:%s (%s%s)\n", |
| 648 | name, |
| 649 | info->host, |
| 650 | info->service, |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 651 | NetworkAddressFamily_str(info->family), |
Dr. David Alan Gilbert | 0a9667e | 2017-07-11 16:44:14 +0100 | [diff] [blame] | 652 | info->websocket ? " (Websocket)" : ""); |
| 653 | } |
| 654 | |
| 655 | /* Helper displaying and auth and crypt info */ |
| 656 | static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent, |
| 657 | VncPrimaryAuth auth, |
| 658 | VncVencryptSubAuth *vencrypt) |
| 659 | { |
| 660 | monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent, |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 661 | VncPrimaryAuth_str(auth), |
| 662 | vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none"); |
Dr. David Alan Gilbert | 0a9667e | 2017-07-11 16:44:14 +0100 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client) |
| 666 | { |
| 667 | while (client) { |
| 668 | VncClientInfo *cinfo = client->value; |
| 669 | |
| 670 | hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client"); |
| 671 | monitor_printf(mon, " x509_dname: %s\n", |
| 672 | cinfo->has_x509_dname ? |
| 673 | cinfo->x509_dname : "none"); |
| 674 | monitor_printf(mon, " sasl_username: %s\n", |
| 675 | cinfo->has_sasl_username ? |
| 676 | cinfo->sasl_username : "none"); |
| 677 | |
| 678 | client = client->next; |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server) |
| 683 | { |
| 684 | while (server) { |
| 685 | VncServerInfo2 *sinfo = server->value; |
| 686 | hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server"); |
| 687 | hmp_info_vnc_authcrypt(mon, " ", sinfo->auth, |
| 688 | sinfo->has_vencrypt ? &sinfo->vencrypt : NULL); |
| 689 | server = server->next; |
| 690 | } |
| 691 | } |
| 692 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 693 | void hmp_info_vnc(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 694 | { |
Dr. David Alan Gilbert | 0a9667e | 2017-07-11 16:44:14 +0100 | [diff] [blame] | 695 | VncInfo2List *info2l; |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 696 | Error *err = NULL; |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 697 | |
Dr. David Alan Gilbert | 0a9667e | 2017-07-11 16:44:14 +0100 | [diff] [blame] | 698 | info2l = qmp_query_vnc_servers(&err); |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 699 | if (err) { |
ZhiPeng Lu | 554a39e | 2017-10-19 19:16:33 +0800 | [diff] [blame] | 700 | hmp_handle_error(mon, &err); |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 701 | return; |
| 702 | } |
Dr. David Alan Gilbert | 0a9667e | 2017-07-11 16:44:14 +0100 | [diff] [blame] | 703 | if (!info2l) { |
| 704 | monitor_printf(mon, "None\n"); |
| 705 | return; |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 706 | } |
| 707 | |
Dr. David Alan Gilbert | 0a9667e | 2017-07-11 16:44:14 +0100 | [diff] [blame] | 708 | while (info2l) { |
| 709 | VncInfo2 *info = info2l->value; |
| 710 | monitor_printf(mon, "%s:\n", info->id); |
| 711 | hmp_info_vnc_servers(mon, info->server); |
| 712 | hmp_info_vnc_clients(mon, info->clients); |
| 713 | if (!info->server) { |
| 714 | /* The server entry displays its auth, we only |
| 715 | * need to display in the case of 'reverse' connections |
| 716 | * where there's no server. |
| 717 | */ |
| 718 | hmp_info_vnc_authcrypt(mon, " ", info->auth, |
| 719 | info->has_vencrypt ? &info->vencrypt : NULL); |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 720 | } |
Dr. David Alan Gilbert | 0a9667e | 2017-07-11 16:44:14 +0100 | [diff] [blame] | 721 | if (info->has_display) { |
| 722 | monitor_printf(mon, " Display: %s\n", info->display); |
| 723 | } |
| 724 | info2l = info2l->next; |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 725 | } |
| 726 | |
Dr. David Alan Gilbert | 0a9667e | 2017-07-11 16:44:14 +0100 | [diff] [blame] | 727 | qapi_free_VncInfo2List(info2l); |
| 728 | |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 729 | } |
Marc-André Lureau | 05eb4a2 | 2018-07-03 17:56:47 +0200 | [diff] [blame] | 730 | #endif |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 731 | |
Markus Armbruster | 206addd | 2015-01-13 15:46:39 +0100 | [diff] [blame] | 732 | #ifdef CONFIG_SPICE |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 733 | void hmp_info_spice(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 734 | { |
| 735 | SpiceChannelList *chan; |
| 736 | SpiceInfo *info; |
Cole Robinson | 22fa7da | 2015-03-01 09:29:18 -0500 | [diff] [blame] | 737 | const char *channel_name; |
| 738 | const char * const channel_names[] = { |
| 739 | [SPICE_CHANNEL_MAIN] = "main", |
| 740 | [SPICE_CHANNEL_DISPLAY] = "display", |
| 741 | [SPICE_CHANNEL_INPUTS] = "inputs", |
| 742 | [SPICE_CHANNEL_CURSOR] = "cursor", |
| 743 | [SPICE_CHANNEL_PLAYBACK] = "playback", |
| 744 | [SPICE_CHANNEL_RECORD] = "record", |
| 745 | [SPICE_CHANNEL_TUNNEL] = "tunnel", |
| 746 | [SPICE_CHANNEL_SMARTCARD] = "smartcard", |
| 747 | [SPICE_CHANNEL_USBREDIR] = "usbredir", |
| 748 | [SPICE_CHANNEL_PORT] = "port", |
Gerd Hoffmann | 7c6044a | 2015-03-03 09:27:28 +0100 | [diff] [blame] | 749 | #if 0 |
| 750 | /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7, |
| 751 | * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable |
| 752 | * as quick fix for build failures with older versions. */ |
Cole Robinson | 22fa7da | 2015-03-01 09:29:18 -0500 | [diff] [blame] | 753 | [SPICE_CHANNEL_WEBDAV] = "webdav", |
Gerd Hoffmann | 7c6044a | 2015-03-03 09:27:28 +0100 | [diff] [blame] | 754 | #endif |
Cole Robinson | 22fa7da | 2015-03-01 09:29:18 -0500 | [diff] [blame] | 755 | }; |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 756 | |
| 757 | info = qmp_query_spice(NULL); |
| 758 | |
| 759 | if (!info->enabled) { |
| 760 | monitor_printf(mon, "Server: disabled\n"); |
| 761 | goto out; |
| 762 | } |
| 763 | |
| 764 | monitor_printf(mon, "Server:\n"); |
| 765 | if (info->has_port) { |
| 766 | monitor_printf(mon, " address: %s:%" PRId64 "\n", |
| 767 | info->host, info->port); |
| 768 | } |
| 769 | if (info->has_tls_port) { |
| 770 | monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n", |
| 771 | info->host, info->tls_port); |
| 772 | } |
Yonit Halperin | 61c4efe | 2012-08-21 11:51:58 +0300 | [diff] [blame] | 773 | monitor_printf(mon, " migrated: %s\n", |
| 774 | info->migrated ? "true" : "false"); |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 775 | monitor_printf(mon, " auth: %s\n", info->auth); |
| 776 | monitor_printf(mon, " compiled: %s\n", info->compiled_version); |
Alon Levy | 4efee02 | 2012-03-29 23:23:14 +0200 | [diff] [blame] | 777 | monitor_printf(mon, " mouse-mode: %s\n", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 778 | SpiceQueryMouseMode_str(info->mouse_mode)); |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 779 | |
| 780 | if (!info->has_channels || info->channels == NULL) { |
| 781 | monitor_printf(mon, "Channels: none\n"); |
| 782 | } else { |
| 783 | for (chan = info->channels; chan; chan = chan->next) { |
| 784 | monitor_printf(mon, "Channel:\n"); |
| 785 | monitor_printf(mon, " address: %s:%s%s\n", |
Eric Blake | ddf2190 | 2015-10-26 16:34:49 -0600 | [diff] [blame] | 786 | chan->value->host, chan->value->port, |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 787 | chan->value->tls ? " [tls]" : ""); |
| 788 | monitor_printf(mon, " session: %" PRId64 "\n", |
| 789 | chan->value->connection_id); |
| 790 | monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n", |
| 791 | chan->value->channel_type, chan->value->channel_id); |
Cole Robinson | 22fa7da | 2015-03-01 09:29:18 -0500 | [diff] [blame] | 792 | |
| 793 | channel_name = "unknown"; |
| 794 | if (chan->value->channel_type > 0 && |
| 795 | chan->value->channel_type < ARRAY_SIZE(channel_names) && |
| 796 | channel_names[chan->value->channel_type]) { |
| 797 | channel_name = channel_names[chan->value->channel_type]; |
| 798 | } |
| 799 | |
| 800 | monitor_printf(mon, " channel name: %s\n", channel_name); |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | |
| 804 | out: |
| 805 | qapi_free_SpiceInfo(info); |
| 806 | } |
Markus Armbruster | 206addd | 2015-01-13 15:46:39 +0100 | [diff] [blame] | 807 | #endif |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 808 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 809 | void hmp_info_balloon(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | 96637bc | 2011-10-21 11:41:37 -0200 | [diff] [blame] | 810 | { |
| 811 | BalloonInfo *info; |
| 812 | Error *err = NULL; |
| 813 | |
| 814 | info = qmp_query_balloon(&err); |
| 815 | if (err) { |
ZhiPeng Lu | 554a39e | 2017-10-19 19:16:33 +0800 | [diff] [blame] | 816 | hmp_handle_error(mon, &err); |
Luiz Capitulino | 96637bc | 2011-10-21 11:41:37 -0200 | [diff] [blame] | 817 | return; |
| 818 | } |
| 819 | |
Luiz Capitulino | 01ceb97 | 2012-12-03 15:56:41 -0200 | [diff] [blame] | 820 | monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20); |
Luiz Capitulino | 96637bc | 2011-10-21 11:41:37 -0200 | [diff] [blame] | 821 | |
| 822 | qapi_free_BalloonInfo(info); |
| 823 | } |
| 824 | |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 825 | static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) |
| 826 | { |
| 827 | PciMemoryRegionList *region; |
| 828 | |
| 829 | monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus); |
| 830 | monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n", |
| 831 | dev->slot, dev->function); |
| 832 | monitor_printf(mon, " "); |
| 833 | |
Eric Blake | 9fa02cd | 2015-05-04 09:05:32 -0600 | [diff] [blame] | 834 | if (dev->class_info->has_desc) { |
| 835 | monitor_printf(mon, "%s", dev->class_info->desc); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 836 | } else { |
Eric Blake | 9fa02cd | 2015-05-04 09:05:32 -0600 | [diff] [blame] | 837 | monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n", |
Eric Blake | 9fa02cd | 2015-05-04 09:05:32 -0600 | [diff] [blame] | 841 | dev->id->vendor, dev->id->device); |
Denis V. Lunev | 18613dc | 2018-10-02 16:55:38 +0300 | [diff] [blame] | 842 | if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) { |
| 843 | monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n", |
| 844 | dev->id->subsystem_vendor, dev->id->subsystem); |
| 845 | } |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 846 | |
| 847 | if (dev->has_irq) { |
| 848 | monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq); |
| 849 | } |
| 850 | |
| 851 | if (dev->has_pci_bridge) { |
| 852 | monitor_printf(mon, " BUS %" PRId64 ".\n", |
Eric Blake | 9fa02cd | 2015-05-04 09:05:32 -0600 | [diff] [blame] | 853 | dev->pci_bridge->bus->number); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 854 | monitor_printf(mon, " secondary bus %" PRId64 ".\n", |
Eric Blake | 9fa02cd | 2015-05-04 09:05:32 -0600 | [diff] [blame] | 855 | dev->pci_bridge->bus->secondary); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 856 | monitor_printf(mon, " subordinate bus %" PRId64 ".\n", |
Eric Blake | 9fa02cd | 2015-05-04 09:05:32 -0600 | [diff] [blame] | 857 | dev->pci_bridge->bus->subordinate); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 858 | |
| 859 | monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n", |
Eric Blake | 9fa02cd | 2015-05-04 09:05:32 -0600 | [diff] [blame] | 860 | dev->pci_bridge->bus->io_range->base, |
| 861 | dev->pci_bridge->bus->io_range->limit); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 862 | |
| 863 | monitor_printf(mon, |
| 864 | " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n", |
Eric Blake | 9fa02cd | 2015-05-04 09:05:32 -0600 | [diff] [blame] | 865 | dev->pci_bridge->bus->memory_range->base, |
| 866 | dev->pci_bridge->bus->memory_range->limit); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 867 | |
| 868 | monitor_printf(mon, " prefetchable memory range " |
| 869 | "[0x%08"PRIx64", 0x%08"PRIx64"]\n", |
Eric Blake | 9fa02cd | 2015-05-04 09:05:32 -0600 | [diff] [blame] | 870 | dev->pci_bridge->bus->prefetchable_range->base, |
| 871 | dev->pci_bridge->bus->prefetchable_range->limit); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | for (region = dev->regions; region; region = region->next) { |
| 875 | uint64_t addr, size; |
| 876 | |
| 877 | addr = region->value->address; |
| 878 | size = region->value->size; |
| 879 | |
| 880 | monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar); |
| 881 | |
| 882 | if (!strcmp(region->value->type, "io")) { |
| 883 | monitor_printf(mon, "I/O at 0x%04" PRIx64 |
| 884 | " [0x%04" PRIx64 "].\n", |
| 885 | addr, addr + size - 1); |
| 886 | } else { |
| 887 | monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64 |
| 888 | " [0x%08" PRIx64 "].\n", |
| 889 | region->value->mem_type_64 ? 64 : 32, |
| 890 | region->value->prefetch ? " prefetchable" : "", |
| 891 | addr, addr + size - 1); |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | monitor_printf(mon, " id \"%s\"\n", dev->qdev_id); |
| 896 | |
| 897 | if (dev->has_pci_bridge) { |
| 898 | if (dev->pci_bridge->has_devices) { |
| 899 | PciDeviceInfoList *cdev; |
| 900 | for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) { |
| 901 | hmp_info_pci_device(mon, cdev->value); |
| 902 | } |
| 903 | } |
| 904 | } |
| 905 | } |
| 906 | |
Hervé Poussineau | 61b9783 | 2016-09-26 22:23:27 +0200 | [diff] [blame] | 907 | static int hmp_info_irq_foreach(Object *obj, void *opaque) |
| 908 | { |
| 909 | InterruptStatsProvider *intc; |
| 910 | InterruptStatsProviderClass *k; |
| 911 | Monitor *mon = opaque; |
| 912 | |
| 913 | if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) { |
| 914 | intc = INTERRUPT_STATS_PROVIDER(obj); |
| 915 | k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj); |
| 916 | uint64_t *irq_counts; |
| 917 | unsigned int nb_irqs, i; |
| 918 | if (k->get_statistics && |
| 919 | k->get_statistics(intc, &irq_counts, &nb_irqs)) { |
| 920 | if (nb_irqs > 0) { |
| 921 | monitor_printf(mon, "IRQ statistics for %s:\n", |
| 922 | object_get_typename(obj)); |
| 923 | for (i = 0; i < nb_irqs; i++) { |
| 924 | if (irq_counts[i] > 0) { |
| 925 | monitor_printf(mon, "%2d: %" PRId64 "\n", i, |
| 926 | irq_counts[i]); |
| 927 | } |
| 928 | } |
| 929 | } |
| 930 | } else { |
| 931 | monitor_printf(mon, "IRQ statistics not available for %s.\n", |
| 932 | object_get_typename(obj)); |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | return 0; |
| 937 | } |
| 938 | |
| 939 | void hmp_info_irq(Monitor *mon, const QDict *qdict) |
| 940 | { |
| 941 | object_child_foreach_recursive(object_get_root(), |
| 942 | hmp_info_irq_foreach, mon); |
| 943 | } |
| 944 | |
| 945 | static int hmp_info_pic_foreach(Object *obj, void *opaque) |
| 946 | { |
| 947 | InterruptStatsProvider *intc; |
| 948 | InterruptStatsProviderClass *k; |
| 949 | Monitor *mon = opaque; |
| 950 | |
| 951 | if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) { |
| 952 | intc = INTERRUPT_STATS_PROVIDER(obj); |
| 953 | k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj); |
| 954 | if (k->print_info) { |
| 955 | k->print_info(intc, mon); |
| 956 | } else { |
| 957 | monitor_printf(mon, "Interrupt controller information not available for %s.\n", |
| 958 | object_get_typename(obj)); |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | return 0; |
| 963 | } |
| 964 | |
| 965 | void hmp_info_pic(Monitor *mon, const QDict *qdict) |
| 966 | { |
| 967 | object_child_foreach_recursive(object_get_root(), |
| 968 | hmp_info_pic_foreach, mon); |
| 969 | } |
| 970 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 971 | void hmp_info_pci(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 972 | { |
Stefan Berger | f46cee3 | 2012-01-11 10:51:52 -0500 | [diff] [blame] | 973 | PciInfoList *info_list, *info; |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 974 | Error *err = NULL; |
| 975 | |
Stefan Berger | f46cee3 | 2012-01-11 10:51:52 -0500 | [diff] [blame] | 976 | info_list = qmp_query_pci(&err); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 977 | if (err) { |
| 978 | monitor_printf(mon, "PCI devices not supported\n"); |
| 979 | error_free(err); |
| 980 | return; |
| 981 | } |
| 982 | |
Stefan Berger | f46cee3 | 2012-01-11 10:51:52 -0500 | [diff] [blame] | 983 | for (info = info_list; info; info = info->next) { |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 984 | PciDeviceInfoList *dev; |
| 985 | |
| 986 | for (dev = info->value->devices; dev; dev = dev->next) { |
| 987 | hmp_info_pci_device(mon, dev->value); |
| 988 | } |
| 989 | } |
| 990 | |
Stefan Berger | f46cee3 | 2012-01-11 10:51:52 -0500 | [diff] [blame] | 991 | qapi_free_PciInfoList(info_list); |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 992 | } |
| 993 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 994 | void hmp_info_block_jobs(Monitor *mon, const QDict *qdict) |
Stefan Hajnoczi | fb5458c | 2012-01-18 14:40:49 +0000 | [diff] [blame] | 995 | { |
| 996 | BlockJobInfoList *list; |
| 997 | Error *err = NULL; |
| 998 | |
| 999 | list = qmp_query_block_jobs(&err); |
| 1000 | assert(!err); |
| 1001 | |
| 1002 | if (!list) { |
| 1003 | monitor_printf(mon, "No active jobs\n"); |
| 1004 | return; |
| 1005 | } |
| 1006 | |
| 1007 | while (list) { |
| 1008 | if (strcmp(list->value->type, "stream") == 0) { |
| 1009 | monitor_printf(mon, "Streaming device %s: Completed %" PRId64 |
| 1010 | " of %" PRId64 " bytes, speed limit %" PRId64 |
| 1011 | " bytes/s\n", |
| 1012 | list->value->device, |
| 1013 | list->value->offset, |
| 1014 | list->value->len, |
| 1015 | list->value->speed); |
| 1016 | } else { |
| 1017 | monitor_printf(mon, "Type %s, device %s: Completed %" PRId64 |
| 1018 | " of %" PRId64 " bytes, speed limit %" PRId64 |
| 1019 | " bytes/s\n", |
| 1020 | list->value->type, |
| 1021 | list->value->device, |
| 1022 | list->value->offset, |
| 1023 | list->value->len, |
| 1024 | list->value->speed); |
| 1025 | } |
| 1026 | list = list->next; |
| 1027 | } |
Gonglei | 93bb131 | 2014-09-16 21:36:55 +0800 | [diff] [blame] | 1028 | |
| 1029 | qapi_free_BlockJobInfoList(list); |
Stefan Hajnoczi | fb5458c | 2012-01-18 14:40:49 +0000 | [diff] [blame] | 1030 | } |
| 1031 | |
Stefan Berger | d1a0cf7 | 2013-02-27 12:47:49 -0500 | [diff] [blame] | 1032 | void hmp_info_tpm(Monitor *mon, const QDict *qdict) |
| 1033 | { |
| 1034 | TPMInfoList *info_list, *info; |
| 1035 | Error *err = NULL; |
| 1036 | unsigned int c = 0; |
| 1037 | TPMPassthroughOptions *tpo; |
Amarnath Valluri | f4ede81 | 2017-09-29 14:10:20 +0300 | [diff] [blame] | 1038 | TPMEmulatorOptions *teo; |
Stefan Berger | d1a0cf7 | 2013-02-27 12:47:49 -0500 | [diff] [blame] | 1039 | |
| 1040 | info_list = qmp_query_tpm(&err); |
| 1041 | if (err) { |
| 1042 | monitor_printf(mon, "TPM device not supported\n"); |
| 1043 | error_free(err); |
| 1044 | return; |
| 1045 | } |
| 1046 | |
| 1047 | if (info_list) { |
| 1048 | monitor_printf(mon, "TPM device:\n"); |
| 1049 | } |
| 1050 | |
| 1051 | for (info = info_list; info; info = info->next) { |
| 1052 | TPMInfo *ti = info->value; |
| 1053 | monitor_printf(mon, " tpm%d: model=%s\n", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 1054 | c, TpmModel_str(ti->model)); |
Stefan Berger | d1a0cf7 | 2013-02-27 12:47:49 -0500 | [diff] [blame] | 1055 | |
| 1056 | monitor_printf(mon, " \\ %s: type=%s", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 1057 | ti->id, TpmTypeOptionsKind_str(ti->options->type)); |
Stefan Berger | d1a0cf7 | 2013-02-27 12:47:49 -0500 | [diff] [blame] | 1058 | |
Eric Blake | ce21131 | 2015-10-26 16:35:00 -0600 | [diff] [blame] | 1059 | switch (ti->options->type) { |
Corey Bryant | 88ca7bc | 2013-03-20 12:34:48 -0400 | [diff] [blame] | 1060 | case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH: |
Eric Blake | 32bafa8 | 2016-03-17 16:48:37 -0600 | [diff] [blame] | 1061 | tpo = ti->options->u.passthrough.data; |
Stefan Berger | d1a0cf7 | 2013-02-27 12:47:49 -0500 | [diff] [blame] | 1062 | monitor_printf(mon, "%s%s%s%s", |
| 1063 | tpo->has_path ? ",path=" : "", |
| 1064 | tpo->has_path ? tpo->path : "", |
| 1065 | tpo->has_cancel_path ? ",cancel-path=" : "", |
| 1066 | tpo->has_cancel_path ? tpo->cancel_path : ""); |
| 1067 | break; |
Amarnath Valluri | f4ede81 | 2017-09-29 14:10:20 +0300 | [diff] [blame] | 1068 | case TPM_TYPE_OPTIONS_KIND_EMULATOR: |
| 1069 | teo = ti->options->u.emulator.data; |
| 1070 | monitor_printf(mon, ",chardev=%s", teo->chardev); |
| 1071 | break; |
Eric Blake | 7fb1cf1 | 2015-11-18 01:52:57 -0700 | [diff] [blame] | 1072 | case TPM_TYPE_OPTIONS_KIND__MAX: |
Stefan Berger | d1a0cf7 | 2013-02-27 12:47:49 -0500 | [diff] [blame] | 1073 | break; |
| 1074 | } |
| 1075 | monitor_printf(mon, "\n"); |
| 1076 | c++; |
| 1077 | } |
| 1078 | qapi_free_TPMInfoList(info_list); |
| 1079 | } |
| 1080 | |
Luiz Capitulino | 7a7f325 | 2011-09-15 14:20:28 -0300 | [diff] [blame] | 1081 | void hmp_quit(Monitor *mon, const QDict *qdict) |
| 1082 | { |
| 1083 | monitor_suspend(mon); |
| 1084 | qmp_quit(NULL); |
| 1085 | } |
Luiz Capitulino | 5f158f2 | 2011-09-15 14:34:39 -0300 | [diff] [blame] | 1086 | |
| 1087 | void hmp_stop(Monitor *mon, const QDict *qdict) |
| 1088 | { |
| 1089 | qmp_stop(NULL); |
| 1090 | } |
Luiz Capitulino | 38d2265 | 2011-09-15 14:41:46 -0300 | [diff] [blame] | 1091 | |
Emilio G. Cota | dd12e1b | 2018-08-15 16:00:03 -0400 | [diff] [blame] | 1092 | void hmp_sync_profile(Monitor *mon, const QDict *qdict) |
| 1093 | { |
| 1094 | const char *op = qdict_get_try_str(qdict, "op"); |
| 1095 | |
| 1096 | if (op == NULL) { |
| 1097 | bool on = qsp_is_enabled(); |
| 1098 | |
| 1099 | monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off"); |
| 1100 | return; |
| 1101 | } |
| 1102 | if (!strcmp(op, "on")) { |
| 1103 | qsp_enable(); |
| 1104 | } else if (!strcmp(op, "off")) { |
| 1105 | qsp_disable(); |
| 1106 | } else if (!strcmp(op, "reset")) { |
| 1107 | qsp_reset(); |
| 1108 | } else { |
| 1109 | Error *err = NULL; |
| 1110 | |
| 1111 | error_setg(&err, QERR_INVALID_PARAMETER, op); |
| 1112 | hmp_handle_error(mon, &err); |
| 1113 | } |
| 1114 | } |
| 1115 | |
Luiz Capitulino | 38d2265 | 2011-09-15 14:41:46 -0300 | [diff] [blame] | 1116 | void hmp_system_reset(Monitor *mon, const QDict *qdict) |
| 1117 | { |
| 1118 | qmp_system_reset(NULL); |
| 1119 | } |
Luiz Capitulino | 5bc465e | 2011-09-28 11:06:15 -0300 | [diff] [blame] | 1120 | |
| 1121 | void hmp_system_powerdown(Monitor *mon, const QDict *qdict) |
| 1122 | { |
| 1123 | qmp_system_powerdown(NULL); |
| 1124 | } |
Luiz Capitulino | 755f196 | 2011-10-06 14:31:39 -0300 | [diff] [blame] | 1125 | |
Dr. David Alan Gilbert | 8e8581e | 2018-06-20 16:39:46 +0100 | [diff] [blame] | 1126 | void hmp_exit_preconfig(Monitor *mon, const QDict *qdict) |
| 1127 | { |
| 1128 | Error *err = NULL; |
| 1129 | |
Markus Armbruster | 361ac94 | 2018-07-05 11:14:02 +0200 | [diff] [blame] | 1130 | qmp_x_exit_preconfig(&err); |
Dr. David Alan Gilbert | 8e8581e | 2018-06-20 16:39:46 +0100 | [diff] [blame] | 1131 | hmp_handle_error(mon, &err); |
| 1132 | } |
| 1133 | |
Luiz Capitulino | 755f196 | 2011-10-06 14:31:39 -0300 | [diff] [blame] | 1134 | void hmp_cpu(Monitor *mon, const QDict *qdict) |
| 1135 | { |
| 1136 | int64_t cpu_index; |
| 1137 | |
| 1138 | /* XXX: drop the monitor_set_cpu() usage when all HMP commands that |
| 1139 | use it are converted to the QAPI */ |
| 1140 | cpu_index = qdict_get_int(qdict, "index"); |
| 1141 | if (monitor_set_cpu(cpu_index) < 0) { |
| 1142 | monitor_printf(mon, "invalid CPU index\n"); |
| 1143 | } |
| 1144 | } |
Luiz Capitulino | 0cfd6a9 | 2011-11-22 16:32:37 -0200 | [diff] [blame] | 1145 | |
| 1146 | void hmp_memsave(Monitor *mon, const QDict *qdict) |
| 1147 | { |
| 1148 | uint32_t size = qdict_get_int(qdict, "size"); |
| 1149 | const char *filename = qdict_get_str(qdict, "filename"); |
| 1150 | uint64_t addr = qdict_get_int(qdict, "val"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1151 | Error *err = NULL; |
Thomas Huth | 854e67f | 2017-01-13 13:12:35 +0100 | [diff] [blame] | 1152 | int cpu_index = monitor_get_cpu_index(); |
Luiz Capitulino | 0cfd6a9 | 2011-11-22 16:32:37 -0200 | [diff] [blame] | 1153 | |
Thomas Huth | 854e67f | 2017-01-13 13:12:35 +0100 | [diff] [blame] | 1154 | if (cpu_index < 0) { |
| 1155 | monitor_printf(mon, "No CPU available\n"); |
| 1156 | return; |
| 1157 | } |
| 1158 | |
| 1159 | qmp_memsave(addr, size, filename, true, cpu_index, &err); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1160 | hmp_handle_error(mon, &err); |
Luiz Capitulino | 0cfd6a9 | 2011-11-22 16:32:37 -0200 | [diff] [blame] | 1161 | } |
Luiz Capitulino | 6d3962b | 2011-11-22 17:26:46 -0200 | [diff] [blame] | 1162 | |
| 1163 | void hmp_pmemsave(Monitor *mon, const QDict *qdict) |
| 1164 | { |
| 1165 | uint32_t size = qdict_get_int(qdict, "size"); |
| 1166 | const char *filename = qdict_get_str(qdict, "filename"); |
| 1167 | uint64_t addr = qdict_get_int(qdict, "val"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1168 | Error *err = NULL; |
Luiz Capitulino | 6d3962b | 2011-11-22 17:26:46 -0200 | [diff] [blame] | 1169 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1170 | qmp_pmemsave(addr, size, filename, &err); |
| 1171 | hmp_handle_error(mon, &err); |
Luiz Capitulino | 6d3962b | 2011-11-22 17:26:46 -0200 | [diff] [blame] | 1172 | } |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 1173 | |
Markus Armbruster | 3949e59 | 2013-02-06 21:27:24 +0100 | [diff] [blame] | 1174 | void hmp_ringbuf_write(Monitor *mon, const QDict *qdict) |
Lei Li | 1f590cf | 2013-01-25 00:03:20 +0800 | [diff] [blame] | 1175 | { |
Lei Li | 1f590cf | 2013-01-25 00:03:20 +0800 | [diff] [blame] | 1176 | const char *chardev = qdict_get_str(qdict, "device"); |
| 1177 | const char *data = qdict_get_str(qdict, "data"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1178 | Error *err = NULL; |
Lei Li | 1f590cf | 2013-01-25 00:03:20 +0800 | [diff] [blame] | 1179 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1180 | qmp_ringbuf_write(chardev, data, false, 0, &err); |
Lei Li | 1f590cf | 2013-01-25 00:03:20 +0800 | [diff] [blame] | 1181 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1182 | hmp_handle_error(mon, &err); |
Lei Li | 1f590cf | 2013-01-25 00:03:20 +0800 | [diff] [blame] | 1183 | } |
| 1184 | |
Markus Armbruster | 3949e59 | 2013-02-06 21:27:24 +0100 | [diff] [blame] | 1185 | void hmp_ringbuf_read(Monitor *mon, const QDict *qdict) |
Lei Li | 49b6d72 | 2013-01-25 00:03:21 +0800 | [diff] [blame] | 1186 | { |
| 1187 | uint32_t size = qdict_get_int(qdict, "size"); |
| 1188 | const char *chardev = qdict_get_str(qdict, "device"); |
Markus Armbruster | 3ab651f | 2013-02-06 21:27:15 +0100 | [diff] [blame] | 1189 | char *data; |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1190 | Error *err = NULL; |
Markus Armbruster | 543f341 | 2013-02-06 21:27:26 +0100 | [diff] [blame] | 1191 | int i; |
Lei Li | 49b6d72 | 2013-01-25 00:03:21 +0800 | [diff] [blame] | 1192 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1193 | data = qmp_ringbuf_read(chardev, size, false, 0, &err); |
| 1194 | if (err) { |
ZhiPeng Lu | 554a39e | 2017-10-19 19:16:33 +0800 | [diff] [blame] | 1195 | hmp_handle_error(mon, &err); |
Lei Li | 49b6d72 | 2013-01-25 00:03:21 +0800 | [diff] [blame] | 1196 | return; |
| 1197 | } |
| 1198 | |
Markus Armbruster | 543f341 | 2013-02-06 21:27:26 +0100 | [diff] [blame] | 1199 | for (i = 0; data[i]; i++) { |
| 1200 | unsigned char ch = data[i]; |
| 1201 | |
| 1202 | if (ch == '\\') { |
| 1203 | monitor_printf(mon, "\\\\"); |
| 1204 | } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) { |
| 1205 | monitor_printf(mon, "\\u%04X", ch); |
| 1206 | } else { |
| 1207 | monitor_printf(mon, "%c", ch); |
| 1208 | } |
| 1209 | |
| 1210 | } |
| 1211 | monitor_printf(mon, "\n"); |
Markus Armbruster | 3ab651f | 2013-02-06 21:27:15 +0100 | [diff] [blame] | 1212 | g_free(data); |
Lei Li | 49b6d72 | 2013-01-25 00:03:21 +0800 | [diff] [blame] | 1213 | } |
| 1214 | |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 1215 | void hmp_cont(Monitor *mon, const QDict *qdict) |
| 1216 | { |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1217 | Error *err = NULL; |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 1218 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1219 | qmp_cont(&err); |
| 1220 | hmp_handle_error(mon, &err); |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 1221 | } |
Luiz Capitulino | ab49ab5 | 2011-11-23 12:55:53 -0200 | [diff] [blame] | 1222 | |
Gerd Hoffmann | 9b9df25 | 2012-02-23 13:45:21 +0100 | [diff] [blame] | 1223 | void hmp_system_wakeup(Monitor *mon, const QDict *qdict) |
| 1224 | { |
Daniel Henrique Barboza | fb06411 | 2018-12-05 17:47:01 -0200 | [diff] [blame] | 1225 | Error *err = NULL; |
| 1226 | |
| 1227 | qmp_system_wakeup(&err); |
| 1228 | hmp_handle_error(mon, &err); |
Gerd Hoffmann | 9b9df25 | 2012-02-23 13:45:21 +0100 | [diff] [blame] | 1229 | } |
| 1230 | |
Markus Armbruster | 3e5a50d | 2015-02-06 13:55:43 +0100 | [diff] [blame] | 1231 | void hmp_nmi(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | ab49ab5 | 2011-11-23 12:55:53 -0200 | [diff] [blame] | 1232 | { |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1233 | Error *err = NULL; |
Luiz Capitulino | ab49ab5 | 2011-11-23 12:55:53 -0200 | [diff] [blame] | 1234 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1235 | qmp_inject_nmi(&err); |
| 1236 | hmp_handle_error(mon, &err); |
Luiz Capitulino | ab49ab5 | 2011-11-23 12:55:53 -0200 | [diff] [blame] | 1237 | } |
Luiz Capitulino | 4b37156 | 2011-11-23 13:11:55 -0200 | [diff] [blame] | 1238 | |
| 1239 | void hmp_set_link(Monitor *mon, const QDict *qdict) |
| 1240 | { |
| 1241 | const char *name = qdict_get_str(qdict, "name"); |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 1242 | bool up = qdict_get_bool(qdict, "up"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1243 | Error *err = NULL; |
Luiz Capitulino | 4b37156 | 2011-11-23 13:11:55 -0200 | [diff] [blame] | 1244 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1245 | qmp_set_link(name, up, &err); |
| 1246 | hmp_handle_error(mon, &err); |
Luiz Capitulino | 4b37156 | 2011-11-23 13:11:55 -0200 | [diff] [blame] | 1247 | } |
Luiz Capitulino | a4dea8a | 2011-11-23 13:28:21 -0200 | [diff] [blame] | 1248 | |
| 1249 | void hmp_block_passwd(Monitor *mon, const QDict *qdict) |
| 1250 | { |
| 1251 | const char *device = qdict_get_str(qdict, "device"); |
| 1252 | const char *password = qdict_get_str(qdict, "password"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1253 | Error *err = NULL; |
Luiz Capitulino | a4dea8a | 2011-11-23 13:28:21 -0200 | [diff] [blame] | 1254 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1255 | qmp_block_passwd(true, device, false, NULL, password, &err); |
| 1256 | hmp_handle_error(mon, &err); |
Luiz Capitulino | a4dea8a | 2011-11-23 13:28:21 -0200 | [diff] [blame] | 1257 | } |
Luiz Capitulino | d72f326 | 2011-11-25 14:38:09 -0200 | [diff] [blame] | 1258 | |
| 1259 | void hmp_balloon(Monitor *mon, const QDict *qdict) |
| 1260 | { |
| 1261 | int64_t value = qdict_get_int(qdict, "value"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1262 | Error *err = NULL; |
Luiz Capitulino | d72f326 | 2011-11-25 14:38:09 -0200 | [diff] [blame] | 1263 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1264 | qmp_balloon(value, &err); |
ZhiPeng Lu | 554a39e | 2017-10-19 19:16:33 +0800 | [diff] [blame] | 1265 | hmp_handle_error(mon, &err); |
Luiz Capitulino | d72f326 | 2011-11-25 14:38:09 -0200 | [diff] [blame] | 1266 | } |
Luiz Capitulino | 5e7caac | 2011-11-25 14:57:10 -0200 | [diff] [blame] | 1267 | |
| 1268 | void hmp_block_resize(Monitor *mon, const QDict *qdict) |
| 1269 | { |
| 1270 | const char *device = qdict_get_str(qdict, "device"); |
| 1271 | int64_t size = qdict_get_int(qdict, "size"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1272 | Error *err = NULL; |
Luiz Capitulino | 5e7caac | 2011-11-25 14:57:10 -0200 | [diff] [blame] | 1273 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1274 | qmp_block_resize(true, device, false, NULL, size, &err); |
| 1275 | hmp_handle_error(mon, &err); |
Luiz Capitulino | 5e7caac | 2011-11-25 14:57:10 -0200 | [diff] [blame] | 1276 | } |
Luiz Capitulino | 6106e24 | 2011-11-25 16:15:19 -0200 | [diff] [blame] | 1277 | |
Paolo Bonzini | d9b902d | 2012-10-18 16:49:24 +0200 | [diff] [blame] | 1278 | void hmp_drive_mirror(Monitor *mon, const QDict *qdict) |
| 1279 | { |
Paolo Bonzini | d9b902d | 2012-10-18 16:49:24 +0200 | [diff] [blame] | 1280 | const char *filename = qdict_get_str(qdict, "target"); |
| 1281 | const char *format = qdict_get_try_str(qdict, "format"); |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 1282 | bool reuse = qdict_get_try_bool(qdict, "reuse", false); |
| 1283 | bool full = qdict_get_try_bool(qdict, "full", false); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1284 | Error *err = NULL; |
Eric Blake | faecd40 | 2016-07-14 16:37:58 -0600 | [diff] [blame] | 1285 | DriveMirror mirror = { |
| 1286 | .device = (char *)qdict_get_str(qdict, "device"), |
| 1287 | .target = (char *)filename, |
| 1288 | .has_format = !!format, |
| 1289 | .format = (char *)format, |
| 1290 | .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP, |
| 1291 | .has_mode = true, |
| 1292 | .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS, |
| 1293 | .unmap = true, |
| 1294 | }; |
Paolo Bonzini | d9b902d | 2012-10-18 16:49:24 +0200 | [diff] [blame] | 1295 | |
| 1296 | if (!filename) { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 1297 | error_setg(&err, QERR_MISSING_PARAMETER, "target"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1298 | hmp_handle_error(mon, &err); |
Paolo Bonzini | d9b902d | 2012-10-18 16:49:24 +0200 | [diff] [blame] | 1299 | return; |
| 1300 | } |
Eric Blake | faecd40 | 2016-07-14 16:37:58 -0600 | [diff] [blame] | 1301 | qmp_drive_mirror(&mirror, &err); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1302 | hmp_handle_error(mon, &err); |
Paolo Bonzini | d9b902d | 2012-10-18 16:49:24 +0200 | [diff] [blame] | 1303 | } |
| 1304 | |
Stefan Hajnoczi | de90930 | 2013-06-26 14:11:58 +0200 | [diff] [blame] | 1305 | void hmp_drive_backup(Monitor *mon, const QDict *qdict) |
| 1306 | { |
| 1307 | const char *device = qdict_get_str(qdict, "device"); |
| 1308 | const char *filename = qdict_get_str(qdict, "target"); |
| 1309 | const char *format = qdict_get_try_str(qdict, "format"); |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 1310 | bool reuse = qdict_get_try_bool(qdict, "reuse", false); |
| 1311 | bool full = qdict_get_try_bool(qdict, "full", false); |
Pavel Butsykin | 13b9414 | 2016-07-22 11:17:52 +0300 | [diff] [blame] | 1312 | bool compress = qdict_get_try_bool(qdict, "compress", false); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1313 | Error *err = NULL; |
Pavel Butsykin | 81206a8 | 2016-07-22 11:17:50 +0300 | [diff] [blame] | 1314 | DriveBackup backup = { |
| 1315 | .device = (char *)device, |
| 1316 | .target = (char *)filename, |
| 1317 | .has_format = !!format, |
| 1318 | .format = (char *)format, |
| 1319 | .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP, |
| 1320 | .has_mode = true, |
| 1321 | .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS, |
Pavel Butsykin | 13b9414 | 2016-07-22 11:17:52 +0300 | [diff] [blame] | 1322 | .has_compress = !!compress, |
| 1323 | .compress = compress, |
Pavel Butsykin | 81206a8 | 2016-07-22 11:17:50 +0300 | [diff] [blame] | 1324 | }; |
Stefan Hajnoczi | de90930 | 2013-06-26 14:11:58 +0200 | [diff] [blame] | 1325 | |
| 1326 | if (!filename) { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 1327 | error_setg(&err, QERR_MISSING_PARAMETER, "target"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1328 | hmp_handle_error(mon, &err); |
Stefan Hajnoczi | de90930 | 2013-06-26 14:11:58 +0200 | [diff] [blame] | 1329 | return; |
| 1330 | } |
| 1331 | |
Pavel Butsykin | 81206a8 | 2016-07-22 11:17:50 +0300 | [diff] [blame] | 1332 | qmp_drive_backup(&backup, &err); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1333 | hmp_handle_error(mon, &err); |
Stefan Hajnoczi | de90930 | 2013-06-26 14:11:58 +0200 | [diff] [blame] | 1334 | } |
| 1335 | |
Luiz Capitulino | 6106e24 | 2011-11-25 16:15:19 -0200 | [diff] [blame] | 1336 | void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) |
| 1337 | { |
| 1338 | const char *device = qdict_get_str(qdict, "device"); |
| 1339 | const char *filename = qdict_get_try_str(qdict, "snapshot-file"); |
| 1340 | const char *format = qdict_get_try_str(qdict, "format"); |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 1341 | bool reuse = qdict_get_try_bool(qdict, "reuse", false); |
Paolo Bonzini | 6cc2a41 | 2012-03-06 18:55:59 +0100 | [diff] [blame] | 1342 | enum NewImageMode mode; |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1343 | Error *err = NULL; |
Luiz Capitulino | 6106e24 | 2011-11-25 16:15:19 -0200 | [diff] [blame] | 1344 | |
| 1345 | if (!filename) { |
| 1346 | /* In the future, if 'snapshot-file' is not specified, the snapshot |
| 1347 | will be taken internally. Today it's actually required. */ |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 1348 | error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1349 | hmp_handle_error(mon, &err); |
Luiz Capitulino | 6106e24 | 2011-11-25 16:15:19 -0200 | [diff] [blame] | 1350 | return; |
| 1351 | } |
| 1352 | |
Paolo Bonzini | 6cc2a41 | 2012-03-06 18:55:59 +0100 | [diff] [blame] | 1353 | mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS; |
Benoît Canet | 0901f67 | 2014-01-23 21:31:38 +0100 | [diff] [blame] | 1354 | qmp_blockdev_snapshot_sync(true, device, false, NULL, |
| 1355 | filename, false, NULL, |
| 1356 | !!format, format, |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1357 | true, mode, &err); |
| 1358 | hmp_handle_error(mon, &err); |
Luiz Capitulino | 6106e24 | 2011-11-25 16:15:19 -0200 | [diff] [blame] | 1359 | } |
Luiz Capitulino | 6cdedb0 | 2011-11-27 22:54:09 -0200 | [diff] [blame] | 1360 | |
Wenchao Xia | 775ca88 | 2013-09-11 14:04:37 +0800 | [diff] [blame] | 1361 | void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict) |
| 1362 | { |
| 1363 | const char *device = qdict_get_str(qdict, "device"); |
| 1364 | const char *name = qdict_get_str(qdict, "name"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1365 | Error *err = NULL; |
Wenchao Xia | 775ca88 | 2013-09-11 14:04:37 +0800 | [diff] [blame] | 1366 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1367 | qmp_blockdev_snapshot_internal_sync(device, name, &err); |
| 1368 | hmp_handle_error(mon, &err); |
Wenchao Xia | 775ca88 | 2013-09-11 14:04:37 +0800 | [diff] [blame] | 1369 | } |
| 1370 | |
Wenchao Xia | 7a4ed2e | 2013-09-11 14:04:38 +0800 | [diff] [blame] | 1371 | void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict) |
| 1372 | { |
| 1373 | const char *device = qdict_get_str(qdict, "device"); |
| 1374 | const char *name = qdict_get_str(qdict, "name"); |
| 1375 | const char *id = qdict_get_try_str(qdict, "id"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1376 | Error *err = NULL; |
Wenchao Xia | 7a4ed2e | 2013-09-11 14:04:38 +0800 | [diff] [blame] | 1377 | |
| 1378 | qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id, |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 1379 | true, name, &err); |
| 1380 | hmp_handle_error(mon, &err); |
Wenchao Xia | 7a4ed2e | 2013-09-11 14:04:38 +0800 | [diff] [blame] | 1381 | } |
| 1382 | |
Juan Quintela | 52b2620 | 2017-04-18 11:40:56 +0200 | [diff] [blame] | 1383 | void hmp_loadvm(Monitor *mon, const QDict *qdict) |
| 1384 | { |
| 1385 | int saved_vm_running = runstate_is_running(); |
| 1386 | const char *name = qdict_get_str(qdict, "name"); |
Juan Quintela | 927d663 | 2017-04-18 18:12:35 +0200 | [diff] [blame] | 1387 | Error *err = NULL; |
Juan Quintela | 52b2620 | 2017-04-18 11:40:56 +0200 | [diff] [blame] | 1388 | |
| 1389 | vm_stop(RUN_STATE_RESTORE_VM); |
| 1390 | |
Juan Quintela | 5e22479 | 2017-04-20 14:25:55 +0200 | [diff] [blame] | 1391 | if (load_snapshot(name, &err) == 0 && saved_vm_running) { |
Juan Quintela | 52b2620 | 2017-04-18 11:40:56 +0200 | [diff] [blame] | 1392 | vm_start(); |
| 1393 | } |
Juan Quintela | 927d663 | 2017-04-18 18:12:35 +0200 | [diff] [blame] | 1394 | hmp_handle_error(mon, &err); |
Juan Quintela | 52b2620 | 2017-04-18 11:40:56 +0200 | [diff] [blame] | 1395 | } |
| 1396 | |
Juan Quintela | d9c7d13 | 2017-04-18 11:44:16 +0200 | [diff] [blame] | 1397 | void hmp_savevm(Monitor *mon, const QDict *qdict) |
| 1398 | { |
Juan Quintela | 927d663 | 2017-04-18 18:12:35 +0200 | [diff] [blame] | 1399 | Error *err = NULL; |
| 1400 | |
Juan Quintela | 5e22479 | 2017-04-20 14:25:55 +0200 | [diff] [blame] | 1401 | save_snapshot(qdict_get_try_str(qdict, "name"), &err); |
Juan Quintela | 927d663 | 2017-04-18 18:12:35 +0200 | [diff] [blame] | 1402 | hmp_handle_error(mon, &err); |
Juan Quintela | d9c7d13 | 2017-04-18 11:44:16 +0200 | [diff] [blame] | 1403 | } |
| 1404 | |
Juan Quintela | d905bb7 | 2017-04-18 11:46:23 +0200 | [diff] [blame] | 1405 | void hmp_delvm(Monitor *mon, const QDict *qdict) |
| 1406 | { |
| 1407 | BlockDriverState *bs; |
zhangjixiang | 32cd655 | 2018-02-25 09:47:51 +0800 | [diff] [blame] | 1408 | Error *err = NULL; |
Juan Quintela | d905bb7 | 2017-04-18 11:46:23 +0200 | [diff] [blame] | 1409 | const char *name = qdict_get_str(qdict, "name"); |
| 1410 | |
| 1411 | if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) { |
| 1412 | error_reportf_err(err, |
| 1413 | "Error while deleting snapshot on device '%s': ", |
| 1414 | bdrv_get_device_name(bs)); |
| 1415 | } |
| 1416 | } |
| 1417 | |
Juan Quintela | 6683061 | 2017-04-18 11:51:06 +0200 | [diff] [blame] | 1418 | void hmp_info_snapshots(Monitor *mon, const QDict *qdict) |
| 1419 | { |
| 1420 | BlockDriverState *bs, *bs1; |
| 1421 | BdrvNextIterator it1; |
| 1422 | QEMUSnapshotInfo *sn_tab, *sn; |
| 1423 | bool no_snapshot = true; |
| 1424 | int nb_sns, i; |
| 1425 | int total; |
| 1426 | int *global_snapshots; |
| 1427 | AioContext *aio_context; |
| 1428 | |
| 1429 | typedef struct SnapshotEntry { |
| 1430 | QEMUSnapshotInfo sn; |
| 1431 | QTAILQ_ENTRY(SnapshotEntry) next; |
| 1432 | } SnapshotEntry; |
| 1433 | |
| 1434 | typedef struct ImageEntry { |
| 1435 | const char *imagename; |
| 1436 | QTAILQ_ENTRY(ImageEntry) next; |
| 1437 | QTAILQ_HEAD(, SnapshotEntry) snapshots; |
| 1438 | } ImageEntry; |
| 1439 | |
| 1440 | QTAILQ_HEAD(, ImageEntry) image_list = |
| 1441 | QTAILQ_HEAD_INITIALIZER(image_list); |
| 1442 | |
| 1443 | ImageEntry *image_entry, *next_ie; |
| 1444 | SnapshotEntry *snapshot_entry; |
| 1445 | |
| 1446 | bs = bdrv_all_find_vmstate_bs(); |
| 1447 | if (!bs) { |
| 1448 | monitor_printf(mon, "No available block device supports snapshots\n"); |
| 1449 | return; |
| 1450 | } |
| 1451 | aio_context = bdrv_get_aio_context(bs); |
| 1452 | |
| 1453 | aio_context_acquire(aio_context); |
| 1454 | nb_sns = bdrv_snapshot_list(bs, &sn_tab); |
| 1455 | aio_context_release(aio_context); |
| 1456 | |
| 1457 | if (nb_sns < 0) { |
| 1458 | monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns); |
| 1459 | return; |
| 1460 | } |
| 1461 | |
| 1462 | for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) { |
| 1463 | int bs1_nb_sns = 0; |
| 1464 | ImageEntry *ie; |
| 1465 | SnapshotEntry *se; |
| 1466 | AioContext *ctx = bdrv_get_aio_context(bs1); |
| 1467 | |
| 1468 | aio_context_acquire(ctx); |
| 1469 | if (bdrv_can_snapshot(bs1)) { |
| 1470 | sn = NULL; |
| 1471 | bs1_nb_sns = bdrv_snapshot_list(bs1, &sn); |
| 1472 | if (bs1_nb_sns > 0) { |
| 1473 | no_snapshot = false; |
| 1474 | ie = g_new0(ImageEntry, 1); |
| 1475 | ie->imagename = bdrv_get_device_name(bs1); |
| 1476 | QTAILQ_INIT(&ie->snapshots); |
| 1477 | QTAILQ_INSERT_TAIL(&image_list, ie, next); |
| 1478 | for (i = 0; i < bs1_nb_sns; i++) { |
| 1479 | se = g_new0(SnapshotEntry, 1); |
| 1480 | se->sn = sn[i]; |
| 1481 | QTAILQ_INSERT_TAIL(&ie->snapshots, se, next); |
| 1482 | } |
| 1483 | } |
| 1484 | g_free(sn); |
| 1485 | } |
| 1486 | aio_context_release(ctx); |
| 1487 | } |
| 1488 | |
| 1489 | if (no_snapshot) { |
| 1490 | monitor_printf(mon, "There is no snapshot available.\n"); |
| 1491 | return; |
| 1492 | } |
| 1493 | |
| 1494 | global_snapshots = g_new0(int, nb_sns); |
| 1495 | total = 0; |
| 1496 | for (i = 0; i < nb_sns; i++) { |
| 1497 | SnapshotEntry *next_sn; |
| 1498 | if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) { |
| 1499 | global_snapshots[total] = i; |
| 1500 | total++; |
| 1501 | QTAILQ_FOREACH(image_entry, &image_list, next) { |
| 1502 | QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, |
| 1503 | next, next_sn) { |
| 1504 | if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) { |
| 1505 | QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry, |
| 1506 | next); |
| 1507 | g_free(snapshot_entry); |
| 1508 | } |
| 1509 | } |
| 1510 | } |
| 1511 | } |
| 1512 | } |
| 1513 | |
| 1514 | monitor_printf(mon, "List of snapshots present on all disks:\n"); |
| 1515 | |
| 1516 | if (total > 0) { |
| 1517 | bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL); |
| 1518 | monitor_printf(mon, "\n"); |
| 1519 | for (i = 0; i < total; i++) { |
| 1520 | sn = &sn_tab[global_snapshots[i]]; |
| 1521 | /* The ID is not guaranteed to be the same on all images, so |
| 1522 | * overwrite it. |
| 1523 | */ |
| 1524 | pstrcpy(sn->id_str, sizeof(sn->id_str), "--"); |
| 1525 | bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, sn); |
| 1526 | monitor_printf(mon, "\n"); |
| 1527 | } |
| 1528 | } else { |
| 1529 | monitor_printf(mon, "None\n"); |
| 1530 | } |
| 1531 | |
| 1532 | QTAILQ_FOREACH(image_entry, &image_list, next) { |
| 1533 | if (QTAILQ_EMPTY(&image_entry->snapshots)) { |
| 1534 | continue; |
| 1535 | } |
| 1536 | monitor_printf(mon, |
| 1537 | "\nList of partial (non-loadable) snapshots on '%s':\n", |
| 1538 | image_entry->imagename); |
| 1539 | bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL); |
| 1540 | monitor_printf(mon, "\n"); |
| 1541 | QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) { |
| 1542 | bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, |
| 1543 | &snapshot_entry->sn); |
| 1544 | monitor_printf(mon, "\n"); |
| 1545 | } |
| 1546 | } |
| 1547 | |
| 1548 | QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) { |
| 1549 | SnapshotEntry *next_sn; |
| 1550 | QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next, |
| 1551 | next_sn) { |
| 1552 | g_free(snapshot_entry); |
| 1553 | } |
| 1554 | g_free(image_entry); |
| 1555 | } |
| 1556 | g_free(sn_tab); |
| 1557 | g_free(global_snapshots); |
| 1558 | |
| 1559 | } |
| 1560 | |
Luiz Capitulino | 6cdedb0 | 2011-11-27 22:54:09 -0200 | [diff] [blame] | 1561 | void hmp_migrate_cancel(Monitor *mon, const QDict *qdict) |
| 1562 | { |
| 1563 | qmp_migrate_cancel(NULL); |
| 1564 | } |
Luiz Capitulino | 4f0a993 | 2011-11-27 23:18:01 -0200 | [diff] [blame] | 1565 | |
Dr. David Alan Gilbert | 94ae12c | 2017-10-20 10:05:54 +0100 | [diff] [blame] | 1566 | void hmp_migrate_continue(Monitor *mon, const QDict *qdict) |
| 1567 | { |
| 1568 | Error *err = NULL; |
| 1569 | const char *state = qdict_get_str(qdict, "state"); |
| 1570 | int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err); |
| 1571 | |
| 1572 | if (val >= 0) { |
| 1573 | qmp_migrate_continue(val, &err); |
| 1574 | } |
| 1575 | |
| 1576 | hmp_handle_error(mon, &err); |
| 1577 | } |
| 1578 | |
Dr. David Alan Gilbert | bf1ae1f | 2015-02-19 11:40:28 +0000 | [diff] [blame] | 1579 | void hmp_migrate_incoming(Monitor *mon, const QDict *qdict) |
| 1580 | { |
| 1581 | Error *err = NULL; |
| 1582 | const char *uri = qdict_get_str(qdict, "uri"); |
| 1583 | |
| 1584 | qmp_migrate_incoming(uri, &err); |
| 1585 | |
Dr. David Alan Gilbert | 1fa57f5 | 2015-02-26 14:54:39 +0000 | [diff] [blame] | 1586 | hmp_handle_error(mon, &err); |
Dr. David Alan Gilbert | bf1ae1f | 2015-02-19 11:40:28 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
Peter Xu | 3b563c4 | 2018-05-02 18:47:37 +0800 | [diff] [blame] | 1589 | void hmp_migrate_recover(Monitor *mon, const QDict *qdict) |
| 1590 | { |
| 1591 | Error *err = NULL; |
| 1592 | const char *uri = qdict_get_str(qdict, "uri"); |
| 1593 | |
| 1594 | qmp_migrate_recover(uri, &err); |
| 1595 | |
| 1596 | hmp_handle_error(mon, &err); |
| 1597 | } |
| 1598 | |
Peter Xu | d37297d | 2018-05-02 18:47:40 +0800 | [diff] [blame] | 1599 | void hmp_migrate_pause(Monitor *mon, const QDict *qdict) |
| 1600 | { |
| 1601 | Error *err = NULL; |
| 1602 | |
| 1603 | qmp_migrate_pause(&err); |
| 1604 | |
| 1605 | hmp_handle_error(mon, &err); |
| 1606 | } |
| 1607 | |
Ashijeet Acharya | 2ff3025 | 2016-09-15 21:50:28 +0530 | [diff] [blame] | 1608 | /* Kept for backwards compatibility */ |
Luiz Capitulino | 4f0a993 | 2011-11-27 23:18:01 -0200 | [diff] [blame] | 1609 | void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict) |
| 1610 | { |
| 1611 | double value = qdict_get_double(qdict, "value"); |
| 1612 | qmp_migrate_set_downtime(value, NULL); |
| 1613 | } |
Luiz Capitulino | 3dc8538 | 2011-11-28 11:59:37 -0200 | [diff] [blame] | 1614 | |
Orit Wasserman | 9e1ba4c | 2012-08-06 21:42:54 +0300 | [diff] [blame] | 1615 | void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict) |
| 1616 | { |
| 1617 | int64_t value = qdict_get_int(qdict, "value"); |
| 1618 | Error *err = NULL; |
| 1619 | |
| 1620 | qmp_migrate_set_cache_size(value, &err); |
ZhiPeng Lu | 554a39e | 2017-10-19 19:16:33 +0800 | [diff] [blame] | 1621 | hmp_handle_error(mon, &err); |
Orit Wasserman | 9e1ba4c | 2012-08-06 21:42:54 +0300 | [diff] [blame] | 1622 | } |
| 1623 | |
Ashijeet Acharya | 2ff3025 | 2016-09-15 21:50:28 +0530 | [diff] [blame] | 1624 | /* Kept for backwards compatibility */ |
Luiz Capitulino | 3dc8538 | 2011-11-28 11:59:37 -0200 | [diff] [blame] | 1625 | void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict) |
| 1626 | { |
| 1627 | int64_t value = qdict_get_int(qdict, "value"); |
| 1628 | qmp_migrate_set_speed(value, NULL); |
| 1629 | } |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 1630 | |
Orit Wasserman | 0045843 | 2012-08-06 21:42:48 +0300 | [diff] [blame] | 1631 | void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict) |
| 1632 | { |
| 1633 | const char *cap = qdict_get_str(qdict, "capability"); |
| 1634 | bool state = qdict_get_bool(qdict, "state"); |
| 1635 | Error *err = NULL; |
| 1636 | MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps)); |
Marc-André Lureau | 8e615e3 | 2017-08-24 10:46:00 +0200 | [diff] [blame] | 1637 | int val; |
Orit Wasserman | 0045843 | 2012-08-06 21:42:48 +0300 | [diff] [blame] | 1638 | |
Marc-André Lureau | f7abe0e | 2017-08-24 10:46:10 +0200 | [diff] [blame] | 1639 | val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err); |
Marc-André Lureau | 8e615e3 | 2017-08-24 10:46:00 +0200 | [diff] [blame] | 1640 | if (val < 0) { |
| 1641 | goto end; |
Orit Wasserman | 0045843 | 2012-08-06 21:42:48 +0300 | [diff] [blame] | 1642 | } |
| 1643 | |
Marc-André Lureau | 8e615e3 | 2017-08-24 10:46:00 +0200 | [diff] [blame] | 1644 | caps->value = g_malloc0(sizeof(*caps->value)); |
| 1645 | caps->value->capability = val; |
| 1646 | caps->value->state = state; |
| 1647 | caps->next = NULL; |
| 1648 | qmp_migrate_set_capabilities(caps, &err); |
Orit Wasserman | 0045843 | 2012-08-06 21:42:48 +0300 | [diff] [blame] | 1649 | |
Marc-André Lureau | 8e615e3 | 2017-08-24 10:46:00 +0200 | [diff] [blame] | 1650 | end: |
Orit Wasserman | 0045843 | 2012-08-06 21:42:48 +0300 | [diff] [blame] | 1651 | qapi_free_MigrationCapabilityStatusList(caps); |
ZhiPeng Lu | 554a39e | 2017-10-19 19:16:33 +0800 | [diff] [blame] | 1652 | hmp_handle_error(mon, &err); |
Orit Wasserman | 0045843 | 2012-08-06 21:42:48 +0300 | [diff] [blame] | 1653 | } |
| 1654 | |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 1655 | void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) |
| 1656 | { |
| 1657 | const char *param = qdict_get_str(qdict, "parameter"); |
Daniel P. Berrange | 69ef1f3 | 2016-04-27 11:05:15 +0100 | [diff] [blame] | 1658 | const char *valuestr = qdict_get_str(qdict, "value"); |
Juan Quintela | f4a06d1 | 2017-05-16 11:37:45 +0200 | [diff] [blame] | 1659 | Visitor *v = string_input_visitor_new(valuestr); |
Markus Armbruster | 1bda8b3 | 2017-07-18 13:42:11 +0200 | [diff] [blame] | 1660 | MigrateSetParameters *p = g_new0(MigrateSetParameters, 1); |
Markus Armbruster | f46bfdb | 2017-02-21 21:14:07 +0100 | [diff] [blame] | 1661 | uint64_t valuebw = 0; |
Juan Quintela | 73af8dd | 2017-10-05 21:30:10 +0200 | [diff] [blame] | 1662 | uint64_t cache_size; |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 1663 | Error *err = NULL; |
Marc-André Lureau | 262517b | 2017-08-24 10:46:01 +0200 | [diff] [blame] | 1664 | int val, ret; |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 1665 | |
Marc-André Lureau | f7abe0e | 2017-08-24 10:46:10 +0200 | [diff] [blame] | 1666 | val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err); |
Marc-André Lureau | 262517b | 2017-08-24 10:46:01 +0200 | [diff] [blame] | 1667 | if (val < 0) { |
| 1668 | goto cleanup; |
| 1669 | } |
Daniel P. Berrange | 69ef1f3 | 2016-04-27 11:05:15 +0100 | [diff] [blame] | 1670 | |
Marc-André Lureau | 262517b | 2017-08-24 10:46:01 +0200 | [diff] [blame] | 1671 | switch (val) { |
| 1672 | case MIGRATION_PARAMETER_COMPRESS_LEVEL: |
| 1673 | p->has_compress_level = true; |
| 1674 | visit_type_int(v, param, &p->compress_level, &err); |
| 1675 | break; |
| 1676 | case MIGRATION_PARAMETER_COMPRESS_THREADS: |
| 1677 | p->has_compress_threads = true; |
| 1678 | visit_type_int(v, param, &p->compress_threads, &err); |
| 1679 | break; |
Xiao Guangrong | 1d58872 | 2018-08-21 16:10:20 +0800 | [diff] [blame] | 1680 | case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD: |
| 1681 | p->has_compress_wait_thread = true; |
| 1682 | visit_type_bool(v, param, &p->compress_wait_thread, &err); |
| 1683 | break; |
Marc-André Lureau | 262517b | 2017-08-24 10:46:01 +0200 | [diff] [blame] | 1684 | case MIGRATION_PARAMETER_DECOMPRESS_THREADS: |
| 1685 | p->has_decompress_threads = true; |
| 1686 | visit_type_int(v, param, &p->decompress_threads, &err); |
| 1687 | break; |
| 1688 | case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL: |
| 1689 | p->has_cpu_throttle_initial = true; |
| 1690 | visit_type_int(v, param, &p->cpu_throttle_initial, &err); |
| 1691 | break; |
| 1692 | case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT: |
| 1693 | p->has_cpu_throttle_increment = true; |
| 1694 | visit_type_int(v, param, &p->cpu_throttle_increment, &err); |
| 1695 | break; |
Li Qiang | 4cbc9c7 | 2018-08-01 06:00:20 -0700 | [diff] [blame] | 1696 | case MIGRATION_PARAMETER_MAX_CPU_THROTTLE: |
| 1697 | p->has_max_cpu_throttle = true; |
| 1698 | visit_type_int(v, param, &p->max_cpu_throttle, &err); |
| 1699 | break; |
Marc-André Lureau | 262517b | 2017-08-24 10:46:01 +0200 | [diff] [blame] | 1700 | case MIGRATION_PARAMETER_TLS_CREDS: |
| 1701 | p->has_tls_creds = true; |
| 1702 | p->tls_creds = g_new0(StrOrNull, 1); |
| 1703 | p->tls_creds->type = QTYPE_QSTRING; |
| 1704 | visit_type_str(v, param, &p->tls_creds->u.s, &err); |
| 1705 | break; |
| 1706 | case MIGRATION_PARAMETER_TLS_HOSTNAME: |
| 1707 | p->has_tls_hostname = true; |
| 1708 | p->tls_hostname = g_new0(StrOrNull, 1); |
| 1709 | p->tls_hostname->type = QTYPE_QSTRING; |
| 1710 | visit_type_str(v, param, &p->tls_hostname->u.s, &err); |
| 1711 | break; |
| 1712 | case MIGRATION_PARAMETER_MAX_BANDWIDTH: |
| 1713 | p->has_max_bandwidth = true; |
| 1714 | /* |
| 1715 | * Can't use visit_type_size() here, because it |
| 1716 | * defaults to Bytes rather than Mebibytes. |
| 1717 | */ |
| 1718 | ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw); |
| 1719 | if (ret < 0 || valuebw > INT64_MAX |
| 1720 | || (size_t)valuebw != valuebw) { |
| 1721 | error_setg(&err, "Invalid size %s", valuestr); |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 1722 | break; |
| 1723 | } |
Marc-André Lureau | 262517b | 2017-08-24 10:46:01 +0200 | [diff] [blame] | 1724 | p->max_bandwidth = valuebw; |
| 1725 | break; |
| 1726 | case MIGRATION_PARAMETER_DOWNTIME_LIMIT: |
| 1727 | p->has_downtime_limit = true; |
| 1728 | visit_type_int(v, param, &p->downtime_limit, &err); |
| 1729 | break; |
| 1730 | case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY: |
| 1731 | p->has_x_checkpoint_delay = true; |
| 1732 | visit_type_int(v, param, &p->x_checkpoint_delay, &err); |
| 1733 | break; |
| 1734 | case MIGRATION_PARAMETER_BLOCK_INCREMENTAL: |
| 1735 | p->has_block_incremental = true; |
| 1736 | visit_type_bool(v, param, &p->block_incremental, &err); |
| 1737 | break; |
Juan Quintela | 4075fb1 | 2016-01-15 08:56:17 +0100 | [diff] [blame] | 1738 | case MIGRATION_PARAMETER_X_MULTIFD_CHANNELS: |
| 1739 | p->has_x_multifd_channels = true; |
| 1740 | visit_type_int(v, param, &p->x_multifd_channels, &err); |
| 1741 | break; |
Juan Quintela | 0fb8660 | 2017-04-27 10:48:25 +0200 | [diff] [blame] | 1742 | case MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT: |
| 1743 | p->has_x_multifd_page_count = true; |
| 1744 | visit_type_int(v, param, &p->x_multifd_page_count, &err); |
| 1745 | break; |
Juan Quintela | 73af8dd | 2017-10-05 21:30:10 +0200 | [diff] [blame] | 1746 | case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE: |
| 1747 | p->has_xbzrle_cache_size = true; |
| 1748 | visit_type_size(v, param, &cache_size, &err); |
| 1749 | if (err || cache_size > INT64_MAX |
| 1750 | || (size_t)cache_size != cache_size) { |
| 1751 | error_setg(&err, "Invalid size %s", valuestr); |
| 1752 | break; |
| 1753 | } |
| 1754 | p->xbzrle_cache_size = cache_size; |
| 1755 | break; |
Dr. David Alan Gilbert | 7e555c6 | 2018-06-13 11:26:40 +0100 | [diff] [blame] | 1756 | case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH: |
| 1757 | p->has_max_postcopy_bandwidth = true; |
| 1758 | visit_type_size(v, param, &p->max_postcopy_bandwidth, &err); |
| 1759 | break; |
Marc-André Lureau | 262517b | 2017-08-24 10:46:01 +0200 | [diff] [blame] | 1760 | default: |
| 1761 | assert(0); |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 1762 | } |
| 1763 | |
Marc-André Lureau | 262517b | 2017-08-24 10:46:01 +0200 | [diff] [blame] | 1764 | if (err) { |
| 1765 | goto cleanup; |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 1766 | } |
| 1767 | |
Marc-André Lureau | 262517b | 2017-08-24 10:46:01 +0200 | [diff] [blame] | 1768 | qmp_migrate_set_parameters(p, &err); |
| 1769 | |
Daniel P. Berrange | 69ef1f3 | 2016-04-27 11:05:15 +0100 | [diff] [blame] | 1770 | cleanup: |
Markus Armbruster | 1bda8b3 | 2017-07-18 13:42:11 +0200 | [diff] [blame] | 1771 | qapi_free_MigrateSetParameters(p); |
Juan Quintela | f4a06d1 | 2017-05-16 11:37:45 +0200 | [diff] [blame] | 1772 | visit_free(v); |
ZhiPeng Lu | 554a39e | 2017-10-19 19:16:33 +0800 | [diff] [blame] | 1773 | hmp_handle_error(mon, &err); |
Liang Li | 50e9a62 | 2015-03-23 16:32:29 +0800 | [diff] [blame] | 1774 | } |
| 1775 | |
Markus Armbruster | b8a185b | 2015-03-05 17:29:02 +0100 | [diff] [blame] | 1776 | void hmp_client_migrate_info(Monitor *mon, const QDict *qdict) |
| 1777 | { |
| 1778 | Error *err = NULL; |
| 1779 | const char *protocol = qdict_get_str(qdict, "protocol"); |
| 1780 | const char *hostname = qdict_get_str(qdict, "hostname"); |
| 1781 | bool has_port = qdict_haskey(qdict, "port"); |
| 1782 | int port = qdict_get_try_int(qdict, "port", -1); |
| 1783 | bool has_tls_port = qdict_haskey(qdict, "tls-port"); |
| 1784 | int tls_port = qdict_get_try_int(qdict, "tls-port", -1); |
| 1785 | const char *cert_subject = qdict_get_try_str(qdict, "cert-subject"); |
| 1786 | |
| 1787 | qmp_client_migrate_info(protocol, hostname, |
| 1788 | has_port, port, has_tls_port, tls_port, |
| 1789 | !!cert_subject, cert_subject, &err); |
| 1790 | hmp_handle_error(mon, &err); |
| 1791 | } |
| 1792 | |
Dr. David Alan Gilbert | 4886a1b | 2015-11-05 18:10:56 +0000 | [diff] [blame] | 1793 | void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict) |
| 1794 | { |
| 1795 | Error *err = NULL; |
| 1796 | qmp_migrate_start_postcopy(&err); |
| 1797 | hmp_handle_error(mon, &err); |
| 1798 | } |
| 1799 | |
zhanghailiang | d89e666 | 2016-10-27 14:43:03 +0800 | [diff] [blame] | 1800 | void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict) |
| 1801 | { |
| 1802 | Error *err = NULL; |
| 1803 | |
| 1804 | qmp_x_colo_lost_heartbeat(&err); |
| 1805 | hmp_handle_error(mon, &err); |
| 1806 | } |
| 1807 | |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 1808 | void hmp_set_password(Monitor *mon, const QDict *qdict) |
| 1809 | { |
| 1810 | const char *protocol = qdict_get_str(qdict, "protocol"); |
| 1811 | const char *password = qdict_get_str(qdict, "password"); |
| 1812 | const char *connected = qdict_get_try_str(qdict, "connected"); |
| 1813 | Error *err = NULL; |
| 1814 | |
| 1815 | qmp_set_password(protocol, password, !!connected, connected, &err); |
| 1816 | hmp_handle_error(mon, &err); |
| 1817 | } |
Luiz Capitulino | 9ad5372 | 2011-12-07 11:47:57 -0200 | [diff] [blame] | 1818 | |
| 1819 | void hmp_expire_password(Monitor *mon, const QDict *qdict) |
| 1820 | { |
| 1821 | const char *protocol = qdict_get_str(qdict, "protocol"); |
| 1822 | const char *whenstr = qdict_get_str(qdict, "time"); |
| 1823 | Error *err = NULL; |
| 1824 | |
| 1825 | qmp_expire_password(protocol, whenstr, &err); |
| 1826 | hmp_handle_error(mon, &err); |
| 1827 | } |
Luiz Capitulino | c245b6a | 2011-12-07 16:02:36 -0200 | [diff] [blame] | 1828 | |
| 1829 | void hmp_eject(Monitor *mon, const QDict *qdict) |
| 1830 | { |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 1831 | bool force = qdict_get_try_bool(qdict, "force", false); |
Luiz Capitulino | c245b6a | 2011-12-07 16:02:36 -0200 | [diff] [blame] | 1832 | const char *device = qdict_get_str(qdict, "device"); |
| 1833 | Error *err = NULL; |
| 1834 | |
Kevin Wolf | fbe2d81 | 2016-09-20 13:38:46 +0200 | [diff] [blame] | 1835 | qmp_eject(true, device, false, NULL, true, force, &err); |
Luiz Capitulino | c245b6a | 2011-12-07 16:02:36 -0200 | [diff] [blame] | 1836 | hmp_handle_error(mon, &err); |
| 1837 | } |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 1838 | |
Marc-André Lureau | 05eb4a2 | 2018-07-03 17:56:47 +0200 | [diff] [blame] | 1839 | #ifdef CONFIG_VNC |
Stefan Hajnoczi | c60bf33 | 2013-11-14 11:54:14 +0100 | [diff] [blame] | 1840 | static void hmp_change_read_arg(void *opaque, const char *password, |
| 1841 | void *readline_opaque) |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 1842 | { |
| 1843 | qmp_change_vnc_password(password, NULL); |
Stefan Hajnoczi | c60bf33 | 2013-11-14 11:54:14 +0100 | [diff] [blame] | 1844 | monitor_read_command(opaque, 1); |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 1845 | } |
Marc-André Lureau | 05eb4a2 | 2018-07-03 17:56:47 +0200 | [diff] [blame] | 1846 | #endif |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 1847 | |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 1848 | void hmp_change(Monitor *mon, const QDict *qdict) |
| 1849 | { |
| 1850 | const char *device = qdict_get_str(qdict, "device"); |
| 1851 | const char *target = qdict_get_str(qdict, "target"); |
| 1852 | const char *arg = qdict_get_try_str(qdict, "arg"); |
Max Reitz | baead0a | 2015-10-26 21:39:18 +0100 | [diff] [blame] | 1853 | const char *read_only = qdict_get_try_str(qdict, "read-only-mode"); |
| 1854 | BlockdevChangeReadOnlyMode read_only_mode = 0; |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 1855 | Error *err = NULL; |
| 1856 | |
Marc-André Lureau | 05eb4a2 | 2018-07-03 17:56:47 +0200 | [diff] [blame] | 1857 | #ifdef CONFIG_VNC |
Max Reitz | 1068674 | 2015-10-26 21:39:16 +0100 | [diff] [blame] | 1858 | if (strcmp(device, "vnc") == 0) { |
Max Reitz | baead0a | 2015-10-26 21:39:18 +0100 | [diff] [blame] | 1859 | if (read_only) { |
| 1860 | monitor_printf(mon, |
| 1861 | "Parameter 'read-only-mode' is invalid for VNC\n"); |
| 1862 | return; |
| 1863 | } |
Max Reitz | 1068674 | 2015-10-26 21:39:16 +0100 | [diff] [blame] | 1864 | if (strcmp(target, "passwd") == 0 || |
| 1865 | strcmp(target, "password") == 0) { |
| 1866 | if (!arg) { |
| 1867 | monitor_read_password(mon, hmp_change_read_arg, NULL); |
| 1868 | return; |
| 1869 | } |
| 1870 | } |
| 1871 | qmp_change("vnc", target, !!arg, arg, &err); |
Marc-André Lureau | 05eb4a2 | 2018-07-03 17:56:47 +0200 | [diff] [blame] | 1872 | } else |
| 1873 | #endif |
| 1874 | { |
Max Reitz | baead0a | 2015-10-26 21:39:18 +0100 | [diff] [blame] | 1875 | if (read_only) { |
| 1876 | read_only_mode = |
Marc-André Lureau | f7abe0e | 2017-08-24 10:46:10 +0200 | [diff] [blame] | 1877 | qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup, |
Markus Armbruster | 06c60b6 | 2017-08-24 10:45:57 +0200 | [diff] [blame] | 1878 | read_only, |
Max Reitz | baead0a | 2015-10-26 21:39:18 +0100 | [diff] [blame] | 1879 | BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err); |
| 1880 | if (err) { |
| 1881 | hmp_handle_error(mon, &err); |
| 1882 | return; |
| 1883 | } |
| 1884 | } |
| 1885 | |
Kevin Wolf | 70e2cb3 | 2016-09-20 13:38:47 +0200 | [diff] [blame] | 1886 | qmp_blockdev_change_medium(true, device, false, NULL, target, |
| 1887 | !!arg, arg, !!read_only, read_only_mode, |
| 1888 | &err); |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 1889 | } |
| 1890 | |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 1891 | hmp_handle_error(mon, &err); |
| 1892 | } |
Luiz Capitulino | 80047da | 2011-12-14 16:49:14 -0200 | [diff] [blame] | 1893 | |
| 1894 | void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) |
| 1895 | { |
| 1896 | Error *err = NULL; |
Alberto Garcia | 8359218 | 2018-03-09 16:11:07 +0200 | [diff] [blame] | 1897 | char *device = (char *) qdict_get_str(qdict, "device"); |
Eric Blake | 4dc9397 | 2016-07-13 21:50:21 -0600 | [diff] [blame] | 1898 | BlockIOThrottle throttle = { |
Eric Blake | 4dc9397 | 2016-07-13 21:50:21 -0600 | [diff] [blame] | 1899 | .bps = qdict_get_int(qdict, "bps"), |
| 1900 | .bps_rd = qdict_get_int(qdict, "bps_rd"), |
| 1901 | .bps_wr = qdict_get_int(qdict, "bps_wr"), |
| 1902 | .iops = qdict_get_int(qdict, "iops"), |
| 1903 | .iops_rd = qdict_get_int(qdict, "iops_rd"), |
| 1904 | .iops_wr = qdict_get_int(qdict, "iops_wr"), |
| 1905 | }; |
Luiz Capitulino | 80047da | 2011-12-14 16:49:14 -0200 | [diff] [blame] | 1906 | |
Alberto Garcia | 8359218 | 2018-03-09 16:11:07 +0200 | [diff] [blame] | 1907 | /* qmp_block_set_io_throttle has separate parameters for the |
| 1908 | * (deprecated) block device name and the qdev ID but the HMP |
| 1909 | * version has only one, so we must decide which one to pass. */ |
| 1910 | if (blk_by_name(device)) { |
| 1911 | throttle.has_device = true; |
| 1912 | throttle.device = device; |
| 1913 | } else { |
| 1914 | throttle.has_id = true; |
| 1915 | throttle.id = device; |
| 1916 | } |
| 1917 | |
Eric Blake | 4dc9397 | 2016-07-13 21:50:21 -0600 | [diff] [blame] | 1918 | qmp_block_set_io_throttle(&throttle, &err); |
Luiz Capitulino | 80047da | 2011-12-14 16:49:14 -0200 | [diff] [blame] | 1919 | hmp_handle_error(mon, &err); |
| 1920 | } |
Stefan Hajnoczi | 12bd451 | 2012-01-18 14:40:46 +0000 | [diff] [blame] | 1921 | |
| 1922 | void hmp_block_stream(Monitor *mon, const QDict *qdict) |
| 1923 | { |
| 1924 | Error *error = NULL; |
| 1925 | const char *device = qdict_get_str(qdict, "device"); |
| 1926 | const char *base = qdict_get_try_str(qdict, "base"); |
Stefan Hajnoczi | c83c66c | 2012-04-25 16:51:03 +0100 | [diff] [blame] | 1927 | int64_t speed = qdict_get_try_int(qdict, "speed", 0); |
Stefan Hajnoczi | 12bd451 | 2012-01-18 14:40:46 +0000 | [diff] [blame] | 1928 | |
Alberto Garcia | 11d6fbe | 2016-11-04 15:44:43 +0200 | [diff] [blame] | 1929 | qmp_block_stream(true, device, device, base != NULL, base, false, NULL, |
John Snow | 241ca1a | 2018-09-06 09:02:23 -0400 | [diff] [blame] | 1930 | false, NULL, qdict_haskey(qdict, "speed"), speed, true, |
| 1931 | BLOCKDEV_ON_ERROR_REPORT, false, false, false, false, |
| 1932 | &error); |
Stefan Hajnoczi | 12bd451 | 2012-01-18 14:40:46 +0000 | [diff] [blame] | 1933 | |
| 1934 | hmp_handle_error(mon, &error); |
| 1935 | } |
Stefan Hajnoczi | 2d47c6e | 2012-01-18 14:40:47 +0000 | [diff] [blame] | 1936 | |
| 1937 | void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict) |
| 1938 | { |
| 1939 | Error *error = NULL; |
| 1940 | const char *device = qdict_get_str(qdict, "device"); |
Paolo Bonzini | c6db239 | 2012-05-08 16:51:56 +0200 | [diff] [blame] | 1941 | int64_t value = qdict_get_int(qdict, "speed"); |
Stefan Hajnoczi | 2d47c6e | 2012-01-18 14:40:47 +0000 | [diff] [blame] | 1942 | |
| 1943 | qmp_block_job_set_speed(device, value, &error); |
| 1944 | |
| 1945 | hmp_handle_error(mon, &error); |
| 1946 | } |
Stefan Hajnoczi | 370521a | 2012-01-18 14:40:48 +0000 | [diff] [blame] | 1947 | |
| 1948 | void hmp_block_job_cancel(Monitor *mon, const QDict *qdict) |
| 1949 | { |
| 1950 | Error *error = NULL; |
| 1951 | const char *device = qdict_get_str(qdict, "device"); |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 1952 | bool force = qdict_get_try_bool(qdict, "force", false); |
Stefan Hajnoczi | 370521a | 2012-01-18 14:40:48 +0000 | [diff] [blame] | 1953 | |
Paolo Bonzini | 6e37fb8 | 2012-09-28 17:22:51 +0200 | [diff] [blame] | 1954 | qmp_block_job_cancel(device, true, force, &error); |
| 1955 | |
| 1956 | hmp_handle_error(mon, &error); |
| 1957 | } |
| 1958 | |
| 1959 | void hmp_block_job_pause(Monitor *mon, const QDict *qdict) |
| 1960 | { |
| 1961 | Error *error = NULL; |
| 1962 | const char *device = qdict_get_str(qdict, "device"); |
| 1963 | |
| 1964 | qmp_block_job_pause(device, &error); |
| 1965 | |
| 1966 | hmp_handle_error(mon, &error); |
| 1967 | } |
| 1968 | |
| 1969 | void hmp_block_job_resume(Monitor *mon, const QDict *qdict) |
| 1970 | { |
| 1971 | Error *error = NULL; |
| 1972 | const char *device = qdict_get_str(qdict, "device"); |
| 1973 | |
| 1974 | qmp_block_job_resume(device, &error); |
Stefan Hajnoczi | 370521a | 2012-01-18 14:40:48 +0000 | [diff] [blame] | 1975 | |
| 1976 | hmp_handle_error(mon, &error); |
| 1977 | } |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 1978 | |
Paolo Bonzini | aeae883 | 2012-10-18 16:49:21 +0200 | [diff] [blame] | 1979 | void hmp_block_job_complete(Monitor *mon, const QDict *qdict) |
| 1980 | { |
| 1981 | Error *error = NULL; |
| 1982 | const char *device = qdict_get_str(qdict, "device"); |
| 1983 | |
| 1984 | qmp_block_job_complete(device, &error); |
| 1985 | |
| 1986 | hmp_handle_error(mon, &error); |
| 1987 | } |
| 1988 | |
zhanghailiang | e49f35b | 2015-03-13 16:08:39 +0800 | [diff] [blame] | 1989 | typedef struct HMPMigrationStatus |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 1990 | { |
| 1991 | QEMUTimer *timer; |
| 1992 | Monitor *mon; |
| 1993 | bool is_block_migration; |
zhanghailiang | e49f35b | 2015-03-13 16:08:39 +0800 | [diff] [blame] | 1994 | } HMPMigrationStatus; |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 1995 | |
| 1996 | static void hmp_migrate_status_cb(void *opaque) |
| 1997 | { |
zhanghailiang | e49f35b | 2015-03-13 16:08:39 +0800 | [diff] [blame] | 1998 | HMPMigrationStatus *status = opaque; |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 1999 | MigrationInfo *info; |
| 2000 | |
| 2001 | info = qmp_query_migrate(NULL); |
zhanghailiang | 24b8c39 | 2015-03-13 16:08:40 +0800 | [diff] [blame] | 2002 | if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE || |
| 2003 | info->status == MIGRATION_STATUS_SETUP) { |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 2004 | if (info->has_disk) { |
| 2005 | int progress; |
| 2006 | |
| 2007 | if (info->disk->remaining) { |
| 2008 | progress = info->disk->transferred * 100 / info->disk->total; |
| 2009 | } else { |
| 2010 | progress = 100; |
| 2011 | } |
| 2012 | |
| 2013 | monitor_printf(status->mon, "Completed %d %%\r", progress); |
| 2014 | monitor_flush(status->mon); |
| 2015 | } |
| 2016 | |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 2017 | timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000); |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 2018 | } else { |
| 2019 | if (status->is_block_migration) { |
| 2020 | monitor_printf(status->mon, "\n"); |
| 2021 | } |
Daniel P. Berrange | d59ce6f | 2016-04-27 11:05:00 +0100 | [diff] [blame] | 2022 | if (info->has_error_desc) { |
| 2023 | error_report("%s", info->error_desc); |
| 2024 | } |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 2025 | monitor_resume(status->mon); |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 2026 | timer_del(status->timer); |
Marc-André Lureau | d34a10a | 2018-09-01 15:46:52 +0200 | [diff] [blame] | 2027 | timer_free(status->timer); |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 2028 | g_free(status); |
| 2029 | } |
| 2030 | |
| 2031 | qapi_free_MigrationInfo(info); |
| 2032 | } |
| 2033 | |
| 2034 | void hmp_migrate(Monitor *mon, const QDict *qdict) |
| 2035 | { |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 2036 | bool detach = qdict_get_try_bool(qdict, "detach", false); |
| 2037 | bool blk = qdict_get_try_bool(qdict, "blk", false); |
| 2038 | bool inc = qdict_get_try_bool(qdict, "inc", false); |
Peter Xu | 7a4da28 | 2018-05-02 18:47:23 +0800 | [diff] [blame] | 2039 | bool resume = qdict_get_try_bool(qdict, "resume", false); |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 2040 | const char *uri = qdict_get_str(qdict, "uri"); |
| 2041 | Error *err = NULL; |
| 2042 | |
Peter Xu | 7a4da28 | 2018-05-02 18:47:23 +0800 | [diff] [blame] | 2043 | qmp_migrate(uri, !!blk, blk, !!inc, inc, |
| 2044 | false, false, true, resume, &err); |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 2045 | if (err) { |
ZhiPeng Lu | 554a39e | 2017-10-19 19:16:33 +0800 | [diff] [blame] | 2046 | hmp_handle_error(mon, &err); |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 2047 | return; |
| 2048 | } |
| 2049 | |
| 2050 | if (!detach) { |
zhanghailiang | e49f35b | 2015-03-13 16:08:39 +0800 | [diff] [blame] | 2051 | HMPMigrationStatus *status; |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 2052 | |
| 2053 | if (monitor_suspend(mon) < 0) { |
| 2054 | monitor_printf(mon, "terminal does not allow synchronous " |
| 2055 | "migration, continuing detached\n"); |
| 2056 | return; |
| 2057 | } |
| 2058 | |
| 2059 | status = g_malloc0(sizeof(*status)); |
| 2060 | status->mon = mon; |
| 2061 | status->is_block_migration = blk || inc; |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 2062 | status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb, |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 2063 | status); |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 2064 | timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME)); |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 2065 | } |
| 2066 | } |
Luiz Capitulino | a15fef2 | 2012-03-29 12:38:50 -0300 | [diff] [blame] | 2067 | |
Markus Armbruster | 318660f | 2015-03-05 17:24:48 +0100 | [diff] [blame] | 2068 | void hmp_device_add(Monitor *mon, const QDict *qdict) |
| 2069 | { |
Markus Armbruster | 485febc | 2015-03-13 17:25:50 +0100 | [diff] [blame] | 2070 | Error *err = NULL; |
| 2071 | |
| 2072 | qmp_device_add((QDict *)qdict, NULL, &err); |
| 2073 | hmp_handle_error(mon, &err); |
Markus Armbruster | 318660f | 2015-03-05 17:24:48 +0100 | [diff] [blame] | 2074 | } |
| 2075 | |
Luiz Capitulino | a15fef2 | 2012-03-29 12:38:50 -0300 | [diff] [blame] | 2076 | void hmp_device_del(Monitor *mon, const QDict *qdict) |
| 2077 | { |
| 2078 | const char *id = qdict_get_str(qdict, "id"); |
| 2079 | Error *err = NULL; |
| 2080 | |
| 2081 | qmp_device_del(id, &err); |
| 2082 | hmp_handle_error(mon, &err); |
| 2083 | } |
Wen Congyang | 783e9b4 | 2012-05-07 12:10:47 +0800 | [diff] [blame] | 2084 | |
| 2085 | void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) |
| 2086 | { |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 2087 | Error *err = NULL; |
Viktor Prutyanov | 2da91b5 | 2018-05-17 19:23:39 +0300 | [diff] [blame] | 2088 | bool win_dmp = qdict_get_try_bool(qdict, "windmp", false); |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 2089 | bool paging = qdict_get_try_bool(qdict, "paging", false); |
| 2090 | bool zlib = qdict_get_try_bool(qdict, "zlib", false); |
| 2091 | bool lzo = qdict_get_try_bool(qdict, "lzo", false); |
| 2092 | bool snappy = qdict_get_try_bool(qdict, "snappy", false); |
Luiz Capitulino | 7536376 | 2012-09-21 13:53:00 -0300 | [diff] [blame] | 2093 | const char *file = qdict_get_str(qdict, "filename"); |
Wen Congyang | 783e9b4 | 2012-05-07 12:10:47 +0800 | [diff] [blame] | 2094 | bool has_begin = qdict_haskey(qdict, "begin"); |
| 2095 | bool has_length = qdict_haskey(qdict, "length"); |
Peter Xu | 228de9c | 2016-02-18 13:16:47 +0800 | [diff] [blame] | 2096 | bool has_detach = qdict_haskey(qdict, "detach"); |
Wen Congyang | 783e9b4 | 2012-05-07 12:10:47 +0800 | [diff] [blame] | 2097 | int64_t begin = 0; |
| 2098 | int64_t length = 0; |
Peter Xu | 228de9c | 2016-02-18 13:16:47 +0800 | [diff] [blame] | 2099 | bool detach = false; |
qiaonuohan | b53ccc3 | 2014-02-18 14:11:36 +0800 | [diff] [blame] | 2100 | enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF; |
Luiz Capitulino | 7536376 | 2012-09-21 13:53:00 -0300 | [diff] [blame] | 2101 | char *prot; |
Wen Congyang | 783e9b4 | 2012-05-07 12:10:47 +0800 | [diff] [blame] | 2102 | |
Viktor Prutyanov | 2da91b5 | 2018-05-17 19:23:39 +0300 | [diff] [blame] | 2103 | if (zlib + lzo + snappy + win_dmp > 1) { |
| 2104 | error_setg(&err, "only one of '-z|-l|-s|-w' can be set"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 2105 | hmp_handle_error(mon, &err); |
Qiao Nuohan | 1b7a0f7 | 2014-04-17 16:15:07 +0800 | [diff] [blame] | 2106 | return; |
| 2107 | } |
| 2108 | |
Viktor Prutyanov | 2da91b5 | 2018-05-17 19:23:39 +0300 | [diff] [blame] | 2109 | if (win_dmp) { |
| 2110 | dump_format = DUMP_GUEST_MEMORY_FORMAT_WIN_DMP; |
| 2111 | } |
| 2112 | |
Qiao Nuohan | 1b7a0f7 | 2014-04-17 16:15:07 +0800 | [diff] [blame] | 2113 | if (zlib) { |
| 2114 | dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB; |
| 2115 | } |
| 2116 | |
| 2117 | if (lzo) { |
| 2118 | dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO; |
| 2119 | } |
| 2120 | |
| 2121 | if (snappy) { |
| 2122 | dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY; |
| 2123 | } |
| 2124 | |
Wen Congyang | 783e9b4 | 2012-05-07 12:10:47 +0800 | [diff] [blame] | 2125 | if (has_begin) { |
| 2126 | begin = qdict_get_int(qdict, "begin"); |
| 2127 | } |
| 2128 | if (has_length) { |
| 2129 | length = qdict_get_int(qdict, "length"); |
| 2130 | } |
Peter Xu | 228de9c | 2016-02-18 13:16:47 +0800 | [diff] [blame] | 2131 | if (has_detach) { |
| 2132 | detach = qdict_get_bool(qdict, "detach"); |
| 2133 | } |
Wen Congyang | 783e9b4 | 2012-05-07 12:10:47 +0800 | [diff] [blame] | 2134 | |
Luiz Capitulino | 7536376 | 2012-09-21 13:53:00 -0300 | [diff] [blame] | 2135 | prot = g_strconcat("file:", file, NULL); |
| 2136 | |
Peter Xu | 228de9c | 2016-02-18 13:16:47 +0800 | [diff] [blame] | 2137 | qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin, |
| 2138 | has_length, length, true, dump_format, &err); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 2139 | hmp_handle_error(mon, &err); |
Luiz Capitulino | 7536376 | 2012-09-21 13:53:00 -0300 | [diff] [blame] | 2140 | g_free(prot); |
Wen Congyang | 783e9b4 | 2012-05-07 12:10:47 +0800 | [diff] [blame] | 2141 | } |
Luiz Capitulino | 928059a | 2012-04-18 17:34:15 -0300 | [diff] [blame] | 2142 | |
| 2143 | void hmp_netdev_add(Monitor *mon, const QDict *qdict) |
| 2144 | { |
| 2145 | Error *err = NULL; |
| 2146 | QemuOpts *opts; |
| 2147 | |
| 2148 | opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err); |
Markus Armbruster | 84d18f0 | 2014-01-30 15:07:28 +0100 | [diff] [blame] | 2149 | if (err) { |
Luiz Capitulino | 928059a | 2012-04-18 17:34:15 -0300 | [diff] [blame] | 2150 | goto out; |
| 2151 | } |
| 2152 | |
| 2153 | netdev_add(opts, &err); |
Markus Armbruster | 84d18f0 | 2014-01-30 15:07:28 +0100 | [diff] [blame] | 2154 | if (err) { |
Luiz Capitulino | 928059a | 2012-04-18 17:34:15 -0300 | [diff] [blame] | 2155 | qemu_opts_del(opts); |
| 2156 | } |
| 2157 | |
| 2158 | out: |
| 2159 | hmp_handle_error(mon, &err); |
| 2160 | } |
Luiz Capitulino | 5f96415 | 2012-04-16 14:36:32 -0300 | [diff] [blame] | 2161 | |
| 2162 | void hmp_netdev_del(Monitor *mon, const QDict *qdict) |
| 2163 | { |
| 2164 | const char *id = qdict_get_str(qdict, "id"); |
| 2165 | Error *err = NULL; |
| 2166 | |
| 2167 | qmp_netdev_del(id, &err); |
| 2168 | hmp_handle_error(mon, &err); |
| 2169 | } |
Corey Bryant | 208c9d1 | 2012-06-22 14:36:09 -0400 | [diff] [blame] | 2170 | |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 2171 | void hmp_object_add(Monitor *mon, const QDict *qdict) |
| 2172 | { |
| 2173 | Error *err = NULL; |
| 2174 | QemuOpts *opts; |
Daniel P. Berrange | 90998d5 | 2016-02-10 18:40:59 +0000 | [diff] [blame] | 2175 | Object *obj = NULL; |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 2176 | |
| 2177 | opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err); |
| 2178 | if (err) { |
Daniel P. Berrange | 90998d5 | 2016-02-10 18:40:59 +0000 | [diff] [blame] | 2179 | hmp_handle_error(mon, &err); |
| 2180 | return; |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 2181 | } |
| 2182 | |
Igor Mammedov | 3a46410 | 2017-01-10 13:53:14 +0100 | [diff] [blame] | 2183 | obj = user_creatable_add_opts(opts, &err); |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 2184 | qemu_opts_del(opts); |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 2185 | |
Daniel P. Berrange | 90998d5 | 2016-02-10 18:40:59 +0000 | [diff] [blame] | 2186 | if (err) { |
| 2187 | hmp_handle_error(mon, &err); |
| 2188 | } |
| 2189 | if (obj) { |
| 2190 | object_unref(obj); |
| 2191 | } |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 2192 | } |
| 2193 | |
Corey Bryant | 208c9d1 | 2012-06-22 14:36:09 -0400 | [diff] [blame] | 2194 | void hmp_getfd(Monitor *mon, const QDict *qdict) |
| 2195 | { |
| 2196 | const char *fdname = qdict_get_str(qdict, "fdname"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 2197 | Error *err = NULL; |
Corey Bryant | 208c9d1 | 2012-06-22 14:36:09 -0400 | [diff] [blame] | 2198 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 2199 | qmp_getfd(fdname, &err); |
| 2200 | hmp_handle_error(mon, &err); |
Corey Bryant | 208c9d1 | 2012-06-22 14:36:09 -0400 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | void hmp_closefd(Monitor *mon, const QDict *qdict) |
| 2204 | { |
| 2205 | const char *fdname = qdict_get_str(qdict, "fdname"); |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 2206 | Error *err = NULL; |
Corey Bryant | 208c9d1 | 2012-06-22 14:36:09 -0400 | [diff] [blame] | 2207 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 2208 | qmp_closefd(fdname, &err); |
| 2209 | hmp_handle_error(mon, &err); |
Corey Bryant | 208c9d1 | 2012-06-22 14:36:09 -0400 | [diff] [blame] | 2210 | } |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 2211 | |
Markus Armbruster | 3e5a50d | 2015-02-06 13:55:43 +0100 | [diff] [blame] | 2212 | void hmp_sendkey(Monitor *mon, const QDict *qdict) |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 2213 | { |
| 2214 | const char *keys = qdict_get_str(qdict, "keys"); |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 2215 | KeyValueList *keylist, *head = NULL, *tmp = NULL; |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 2216 | int has_hold_time = qdict_haskey(qdict, "hold-time"); |
| 2217 | int hold_time = qdict_get_try_int(qdict, "hold-time", -1); |
| 2218 | Error *err = NULL; |
Keno Fischer | 5c99fa3 | 2018-06-29 12:32:10 +0200 | [diff] [blame] | 2219 | const char *separator; |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 2220 | int keyname_len; |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 2221 | |
| 2222 | while (1) { |
Keno Fischer | 5c99fa3 | 2018-06-29 12:32:10 +0200 | [diff] [blame] | 2223 | separator = qemu_strchrnul(keys, '-'); |
| 2224 | keyname_len = separator - keys; |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 2225 | |
| 2226 | /* Be compatible with old interface, convert user inputted "<" */ |
Wolfgang Bumiller | 64ffbe0 | 2016-01-13 09:09:58 +0100 | [diff] [blame] | 2227 | if (keys[0] == '<' && keyname_len == 1) { |
| 2228 | keys = "less"; |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 2229 | keyname_len = 4; |
| 2230 | } |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 2231 | |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 2232 | keylist = g_malloc0(sizeof(*keylist)); |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 2233 | keylist->value = g_malloc0(sizeof(*keylist->value)); |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 2234 | |
| 2235 | if (!head) { |
| 2236 | head = keylist; |
| 2237 | } |
| 2238 | if (tmp) { |
| 2239 | tmp->next = keylist; |
| 2240 | } |
| 2241 | tmp = keylist; |
| 2242 | |
Wolfgang Bumiller | 64ffbe0 | 2016-01-13 09:09:58 +0100 | [diff] [blame] | 2243 | if (strstart(keys, "0x", NULL)) { |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 2244 | char *endp; |
Wolfgang Bumiller | 64ffbe0 | 2016-01-13 09:09:58 +0100 | [diff] [blame] | 2245 | int value = strtoul(keys, &endp, 0); |
| 2246 | assert(endp <= keys + keyname_len); |
| 2247 | if (endp != keys + keyname_len) { |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 2248 | goto err_out; |
| 2249 | } |
Eric Blake | 568c73a | 2015-10-26 16:34:58 -0600 | [diff] [blame] | 2250 | keylist->value->type = KEY_VALUE_KIND_NUMBER; |
Eric Blake | 32bafa8 | 2016-03-17 16:48:37 -0600 | [diff] [blame] | 2251 | keylist->value->u.number.data = value; |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 2252 | } else { |
Wolfgang Bumiller | 64ffbe0 | 2016-01-13 09:09:58 +0100 | [diff] [blame] | 2253 | int idx = index_from_key(keys, keyname_len); |
Eric Blake | 7fb1cf1 | 2015-11-18 01:52:57 -0700 | [diff] [blame] | 2254 | if (idx == Q_KEY_CODE__MAX) { |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 2255 | goto err_out; |
| 2256 | } |
Eric Blake | 568c73a | 2015-10-26 16:34:58 -0600 | [diff] [blame] | 2257 | keylist->value->type = KEY_VALUE_KIND_QCODE; |
Eric Blake | 32bafa8 | 2016-03-17 16:48:37 -0600 | [diff] [blame] | 2258 | keylist->value->u.qcode.data = idx; |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 2259 | } |
| 2260 | |
Keno Fischer | 5c99fa3 | 2018-06-29 12:32:10 +0200 | [diff] [blame] | 2261 | if (!*separator) { |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 2262 | break; |
| 2263 | } |
| 2264 | keys = separator + 1; |
| 2265 | } |
| 2266 | |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 2267 | qmp_send_key(head, has_hold_time, hold_time, &err); |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 2268 | hmp_handle_error(mon, &err); |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 2269 | |
| 2270 | out: |
| 2271 | qapi_free_KeyValueList(head); |
| 2272 | return; |
| 2273 | |
| 2274 | err_out: |
Wolfgang Bumiller | 64ffbe0 | 2016-01-13 09:09:58 +0100 | [diff] [blame] | 2275 | monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys); |
Luiz Capitulino | 9f32897 | 2012-09-20 14:19:47 -0300 | [diff] [blame] | 2276 | goto out; |
Amos Kong | e4c8f00 | 2012-08-31 10:56:26 +0800 | [diff] [blame] | 2277 | } |
Luiz Capitulino | ad39cf6 | 2012-05-24 13:48:23 -0300 | [diff] [blame] | 2278 | |
Markus Armbruster | 3e5a50d | 2015-02-06 13:55:43 +0100 | [diff] [blame] | 2279 | void hmp_screendump(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | ad39cf6 | 2012-05-24 13:48:23 -0300 | [diff] [blame] | 2280 | { |
| 2281 | const char *filename = qdict_get_str(qdict, "filename"); |
Thomas Huth | f771c54 | 2018-03-05 17:37:48 +0100 | [diff] [blame] | 2282 | const char *id = qdict_get_try_str(qdict, "device"); |
| 2283 | int64_t head = qdict_get_try_int(qdict, "head", 0); |
Luiz Capitulino | ad39cf6 | 2012-05-24 13:48:23 -0300 | [diff] [blame] | 2284 | Error *err = NULL; |
| 2285 | |
Thomas Huth | f771c54 | 2018-03-05 17:37:48 +0100 | [diff] [blame] | 2286 | qmp_screendump(filename, id != NULL, id, id != NULL, head, &err); |
Luiz Capitulino | ad39cf6 | 2012-05-24 13:48:23 -0300 | [diff] [blame] | 2287 | hmp_handle_error(mon, &err); |
| 2288 | } |
Paolo Bonzini | 4057725 | 2012-08-23 11:53:04 +0200 | [diff] [blame] | 2289 | |
| 2290 | void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) |
| 2291 | { |
| 2292 | const char *uri = qdict_get_str(qdict, "uri"); |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 2293 | bool writable = qdict_get_try_bool(qdict, "writable", false); |
| 2294 | bool all = qdict_get_try_bool(qdict, "all", false); |
Paolo Bonzini | 4057725 | 2012-08-23 11:53:04 +0200 | [diff] [blame] | 2295 | Error *local_err = NULL; |
| 2296 | BlockInfoList *block_list, *info; |
Markus Armbruster | bd269eb | 2017-04-26 09:36:41 +0200 | [diff] [blame] | 2297 | SocketAddress *addr; |
Paolo Bonzini | 4057725 | 2012-08-23 11:53:04 +0200 | [diff] [blame] | 2298 | |
| 2299 | if (writable && !all) { |
| 2300 | error_setg(&local_err, "-w only valid together with -a"); |
| 2301 | goto exit; |
| 2302 | } |
| 2303 | |
| 2304 | /* First check if the address is valid and start the server. */ |
| 2305 | addr = socket_parse(uri, &local_err); |
| 2306 | if (local_err != NULL) { |
| 2307 | goto exit; |
| 2308 | } |
| 2309 | |
Markus Armbruster | bd269eb | 2017-04-26 09:36:41 +0200 | [diff] [blame] | 2310 | nbd_server_start(addr, NULL, &local_err); |
| 2311 | qapi_free_SocketAddress(addr); |
Paolo Bonzini | 4057725 | 2012-08-23 11:53:04 +0200 | [diff] [blame] | 2312 | if (local_err != NULL) { |
| 2313 | goto exit; |
| 2314 | } |
| 2315 | |
| 2316 | if (!all) { |
| 2317 | return; |
| 2318 | } |
| 2319 | |
| 2320 | /* Then try adding all block devices. If one fails, close all and |
| 2321 | * exit. |
| 2322 | */ |
| 2323 | block_list = qmp_query_block(NULL); |
| 2324 | |
| 2325 | for (info = block_list; info; info = info->next) { |
| 2326 | if (!info->value->has_inserted) { |
| 2327 | continue; |
| 2328 | } |
| 2329 | |
Vladimir Sementsov-Ogievskiy | 902a1f9 | 2018-01-19 16:57:15 +0300 | [diff] [blame] | 2330 | qmp_nbd_server_add(info->value->device, false, NULL, |
Eric Blake | 5fcbeb0 | 2019-01-11 13:47:17 -0600 | [diff] [blame] | 2331 | true, writable, false, NULL, &local_err); |
Paolo Bonzini | 4057725 | 2012-08-23 11:53:04 +0200 | [diff] [blame] | 2332 | |
| 2333 | if (local_err != NULL) { |
| 2334 | qmp_nbd_server_stop(NULL); |
| 2335 | break; |
| 2336 | } |
| 2337 | } |
| 2338 | |
| 2339 | qapi_free_BlockInfoList(block_list); |
| 2340 | |
| 2341 | exit: |
| 2342 | hmp_handle_error(mon, &local_err); |
| 2343 | } |
| 2344 | |
| 2345 | void hmp_nbd_server_add(Monitor *mon, const QDict *qdict) |
| 2346 | { |
| 2347 | const char *device = qdict_get_str(qdict, "device"); |
Eric Blake | dba4932 | 2018-01-09 13:28:02 -0600 | [diff] [blame] | 2348 | const char *name = qdict_get_try_str(qdict, "name"); |
Eric Blake | 34acbc9 | 2015-05-15 16:25:00 -0600 | [diff] [blame] | 2349 | bool writable = qdict_get_try_bool(qdict, "writable", false); |
Paolo Bonzini | 4057725 | 2012-08-23 11:53:04 +0200 | [diff] [blame] | 2350 | Error *local_err = NULL; |
| 2351 | |
Eric Blake | 5fcbeb0 | 2019-01-11 13:47:17 -0600 | [diff] [blame] | 2352 | qmp_nbd_server_add(device, !!name, name, true, writable, |
| 2353 | false, NULL, &local_err); |
Eric Blake | 08fb10a | 2018-01-25 08:45:57 -0600 | [diff] [blame] | 2354 | hmp_handle_error(mon, &local_err); |
| 2355 | } |
Paolo Bonzini | 4057725 | 2012-08-23 11:53:04 +0200 | [diff] [blame] | 2356 | |
Eric Blake | 08fb10a | 2018-01-25 08:45:57 -0600 | [diff] [blame] | 2357 | void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict) |
| 2358 | { |
| 2359 | const char *name = qdict_get_str(qdict, "name"); |
| 2360 | bool force = qdict_get_try_bool(qdict, "force", false); |
| 2361 | Error *err = NULL; |
| 2362 | |
| 2363 | /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */ |
| 2364 | qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err); |
| 2365 | hmp_handle_error(mon, &err); |
Paolo Bonzini | 4057725 | 2012-08-23 11:53:04 +0200 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict) |
| 2369 | { |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 2370 | Error *err = NULL; |
Paolo Bonzini | 4057725 | 2012-08-23 11:53:04 +0200 | [diff] [blame] | 2371 | |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 2372 | qmp_nbd_server_stop(&err); |
| 2373 | hmp_handle_error(mon, &err); |
Paolo Bonzini | 4057725 | 2012-08-23 11:53:04 +0200 | [diff] [blame] | 2374 | } |
Gerd Hoffmann | f108890 | 2012-12-19 10:33:40 +0100 | [diff] [blame] | 2375 | |
Jason J. Herne | abf2332 | 2013-12-11 13:24:14 -0500 | [diff] [blame] | 2376 | void hmp_cpu_add(Monitor *mon, const QDict *qdict) |
| 2377 | { |
| 2378 | int cpuid; |
| 2379 | Error *err = NULL; |
| 2380 | |
Kashyap Chamarthy | e25701b | 2018-10-30 13:35:25 +0100 | [diff] [blame] | 2381 | error_report("cpu_add is deprecated, please use device_add instead"); |
| 2382 | |
Jason J. Herne | abf2332 | 2013-12-11 13:24:14 -0500 | [diff] [blame] | 2383 | cpuid = qdict_get_int(qdict, "id"); |
| 2384 | qmp_cpu_add(cpuid, &err); |
| 2385 | hmp_handle_error(mon, &err); |
| 2386 | } |
| 2387 | |
Gerd Hoffmann | f108890 | 2012-12-19 10:33:40 +0100 | [diff] [blame] | 2388 | void hmp_chardev_add(Monitor *mon, const QDict *qdict) |
| 2389 | { |
| 2390 | const char *args = qdict_get_str(qdict, "args"); |
| 2391 | Error *err = NULL; |
| 2392 | QemuOpts *opts; |
| 2393 | |
Markus Armbruster | 70b9433 | 2015-02-13 12:50:26 +0100 | [diff] [blame] | 2394 | opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true); |
Gerd Hoffmann | f108890 | 2012-12-19 10:33:40 +0100 | [diff] [blame] | 2395 | if (opts == NULL) { |
Markus Armbruster | 312fd5f | 2013-02-08 21:22:16 +0100 | [diff] [blame] | 2396 | error_setg(&err, "Parsing chardev args failed"); |
Gerd Hoffmann | f108890 | 2012-12-19 10:33:40 +0100 | [diff] [blame] | 2397 | } else { |
Marc-André Lureau | b4948be | 2016-10-22 12:52:46 +0300 | [diff] [blame] | 2398 | qemu_chr_new_from_opts(opts, &err); |
Daniel P. Berrange | 0a73336 | 2016-10-07 13:18:34 +0100 | [diff] [blame] | 2399 | qemu_opts_del(opts); |
Gerd Hoffmann | f108890 | 2012-12-19 10:33:40 +0100 | [diff] [blame] | 2400 | } |
| 2401 | hmp_handle_error(mon, &err); |
| 2402 | } |
| 2403 | |
Anton Nefedov | 75b6016 | 2017-07-06 15:08:57 +0300 | [diff] [blame] | 2404 | void hmp_chardev_change(Monitor *mon, const QDict *qdict) |
| 2405 | { |
| 2406 | const char *args = qdict_get_str(qdict, "args"); |
| 2407 | const char *id; |
| 2408 | Error *err = NULL; |
| 2409 | ChardevBackend *backend = NULL; |
| 2410 | ChardevReturn *ret = NULL; |
| 2411 | QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, |
| 2412 | true); |
| 2413 | if (!opts) { |
| 2414 | error_setg(&err, "Parsing chardev args failed"); |
| 2415 | goto end; |
| 2416 | } |
| 2417 | |
| 2418 | id = qdict_get_str(qdict, "id"); |
| 2419 | if (qemu_opts_id(opts)) { |
| 2420 | error_setg(&err, "Unexpected 'id' parameter"); |
| 2421 | goto end; |
| 2422 | } |
| 2423 | |
| 2424 | backend = qemu_chr_parse_opts(opts, &err); |
| 2425 | if (!backend) { |
| 2426 | goto end; |
| 2427 | } |
| 2428 | |
| 2429 | ret = qmp_chardev_change(id, backend, &err); |
| 2430 | |
| 2431 | end: |
| 2432 | qapi_free_ChardevReturn(ret); |
| 2433 | qapi_free_ChardevBackend(backend); |
| 2434 | qemu_opts_del(opts); |
| 2435 | hmp_handle_error(mon, &err); |
| 2436 | } |
| 2437 | |
Gerd Hoffmann | f108890 | 2012-12-19 10:33:40 +0100 | [diff] [blame] | 2438 | void hmp_chardev_remove(Monitor *mon, const QDict *qdict) |
| 2439 | { |
| 2440 | Error *local_err = NULL; |
| 2441 | |
| 2442 | qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err); |
| 2443 | hmp_handle_error(mon, &local_err); |
| 2444 | } |
Kevin Wolf | 587da2c | 2013-06-05 14:19:41 +0200 | [diff] [blame] | 2445 | |
Stefan Fritsch | bd1d5ad | 2017-06-11 09:48:17 +0200 | [diff] [blame] | 2446 | void hmp_chardev_send_break(Monitor *mon, const QDict *qdict) |
| 2447 | { |
| 2448 | Error *local_err = NULL; |
| 2449 | |
| 2450 | qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err); |
| 2451 | hmp_handle_error(mon, &local_err); |
| 2452 | } |
| 2453 | |
Kevin Wolf | 587da2c | 2013-06-05 14:19:41 +0200 | [diff] [blame] | 2454 | void hmp_qemu_io(Monitor *mon, const QDict *qdict) |
| 2455 | { |
Max Reitz | 4c7b7e9 | 2015-02-05 13:58:22 -0500 | [diff] [blame] | 2456 | BlockBackend *blk; |
Kevin Wolf | e7f98f2 | 2016-07-13 17:27:51 +0200 | [diff] [blame] | 2457 | BlockBackend *local_blk = NULL; |
Kevin Wolf | 587da2c | 2013-06-05 14:19:41 +0200 | [diff] [blame] | 2458 | const char* device = qdict_get_str(qdict, "device"); |
| 2459 | const char* command = qdict_get_str(qdict, "command"); |
| 2460 | Error *err = NULL; |
Kevin Wolf | d708642 | 2017-01-13 19:02:32 +0100 | [diff] [blame] | 2461 | int ret; |
Kevin Wolf | 587da2c | 2013-06-05 14:19:41 +0200 | [diff] [blame] | 2462 | |
Max Reitz | 4c7b7e9 | 2015-02-05 13:58:22 -0500 | [diff] [blame] | 2463 | blk = blk_by_name(device); |
Kevin Wolf | e7f98f2 | 2016-07-13 17:27:51 +0200 | [diff] [blame] | 2464 | if (!blk) { |
| 2465 | BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err); |
| 2466 | if (bs) { |
Kevin Wolf | 6d0eb64 | 2017-01-20 17:07:26 +0100 | [diff] [blame] | 2467 | blk = local_blk = blk_new(0, BLK_PERM_ALL); |
Kevin Wolf | d708642 | 2017-01-13 19:02:32 +0100 | [diff] [blame] | 2468 | ret = blk_insert_bs(blk, bs, &err); |
| 2469 | if (ret < 0) { |
| 2470 | goto fail; |
| 2471 | } |
Kevin Wolf | e7f98f2 | 2016-07-13 17:27:51 +0200 | [diff] [blame] | 2472 | } else { |
| 2473 | goto fail; |
| 2474 | } |
| 2475 | } |
| 2476 | |
Kevin Wolf | 887354b | 2017-02-10 16:24:56 +0100 | [diff] [blame] | 2477 | /* |
| 2478 | * Notably absent: Proper permission management. This is sad, but it seems |
| 2479 | * almost impossible to achieve without changing the semantics and thereby |
| 2480 | * limiting the use cases of the qemu-io HMP command. |
| 2481 | * |
| 2482 | * In an ideal world we would unconditionally create a new BlockBackend for |
| 2483 | * qemuio_command(), but we have commands like 'reopen' and want them to |
| 2484 | * take effect on the exact BlockBackend whose name the user passed instead |
| 2485 | * of just on a temporary copy of it. |
| 2486 | * |
| 2487 | * Another problem is that deleting the temporary BlockBackend involves |
| 2488 | * draining all requests on it first, but some qemu-iotests cases want to |
| 2489 | * issue multiple aio_read/write requests and expect them to complete in |
| 2490 | * the background while the monitor has already returned. |
| 2491 | * |
| 2492 | * This is also what prevents us from saving the original permissions and |
| 2493 | * restoring them later: We can't revoke permissions until all requests |
| 2494 | * have completed, and we don't know when that is nor can we really let |
| 2495 | * anything else run before we have revoken them to avoid race conditions. |
| 2496 | * |
| 2497 | * What happens now is that command() in qemu-io-cmds.c can extend the |
| 2498 | * permissions if necessary for the qemu-io command. And they simply stay |
| 2499 | * extended, possibly resulting in a read-only guest device keeping write |
| 2500 | * permissions. Ugly, but it appears to be the lesser evil. |
| 2501 | */ |
Kevin Wolf | 1813d33 | 2016-09-15 17:44:16 +0200 | [diff] [blame] | 2502 | qemuio_command(blk, command); |
Vladimir Sementsov-Ogievskiy | 479b599 | 2016-06-08 12:39:17 +0300 | [diff] [blame] | 2503 | |
Kevin Wolf | e7f98f2 | 2016-07-13 17:27:51 +0200 | [diff] [blame] | 2504 | fail: |
| 2505 | blk_unref(local_blk); |
Kevin Wolf | 587da2c | 2013-06-05 14:19:41 +0200 | [diff] [blame] | 2506 | hmp_handle_error(mon, &err); |
| 2507 | } |
Paolo Bonzini | ab2d053 | 2013-12-20 23:21:09 +0100 | [diff] [blame] | 2508 | |
| 2509 | void hmp_object_del(Monitor *mon, const QDict *qdict) |
| 2510 | { |
| 2511 | const char *id = qdict_get_str(qdict, "id"); |
| 2512 | Error *err = NULL; |
| 2513 | |
Daniel P. Berrange | 90998d5 | 2016-02-10 18:40:59 +0000 | [diff] [blame] | 2514 | user_creatable_del(id, &err); |
Paolo Bonzini | ab2d053 | 2013-12-20 23:21:09 +0100 | [diff] [blame] | 2515 | hmp_handle_error(mon, &err); |
| 2516 | } |
Hu Tao | eb1539b | 2014-05-14 17:43:35 +0800 | [diff] [blame] | 2517 | |
| 2518 | void hmp_info_memdev(Monitor *mon, const QDict *qdict) |
| 2519 | { |
| 2520 | Error *err = NULL; |
| 2521 | MemdevList *memdev_list = qmp_query_memdev(&err); |
| 2522 | MemdevList *m = memdev_list; |
Eric Blake | 3b098d5 | 2016-06-09 10:48:43 -0600 | [diff] [blame] | 2523 | Visitor *v; |
Chen Fan | 976620a | 2014-08-18 14:46:34 +0800 | [diff] [blame] | 2524 | char *str; |
Hu Tao | eb1539b | 2014-05-14 17:43:35 +0800 | [diff] [blame] | 2525 | |
| 2526 | while (m) { |
Eric Blake | 3b098d5 | 2016-06-09 10:48:43 -0600 | [diff] [blame] | 2527 | v = string_output_visitor_new(false, &str); |
| 2528 | visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL); |
Igor Mammedov | e1ff3c6 | 2017-01-10 13:53:15 +0100 | [diff] [blame] | 2529 | monitor_printf(mon, "memory backend: %s\n", m->value->id); |
Hu Tao | eb1539b | 2014-05-14 17:43:35 +0800 | [diff] [blame] | 2530 | monitor_printf(mon, " size: %" PRId64 "\n", m->value->size); |
| 2531 | monitor_printf(mon, " merge: %s\n", |
| 2532 | m->value->merge ? "true" : "false"); |
| 2533 | monitor_printf(mon, " dump: %s\n", |
| 2534 | m->value->dump ? "true" : "false"); |
| 2535 | monitor_printf(mon, " prealloc: %s\n", |
| 2536 | m->value->prealloc ? "true" : "false"); |
| 2537 | monitor_printf(mon, " policy: %s\n", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 2538 | HostMemPolicy_str(m->value->policy)); |
Eric Blake | 3b098d5 | 2016-06-09 10:48:43 -0600 | [diff] [blame] | 2539 | visit_complete(v, &str); |
Chen Fan | 976620a | 2014-08-18 14:46:34 +0800 | [diff] [blame] | 2540 | monitor_printf(mon, " host nodes: %s\n", str); |
Hu Tao | eb1539b | 2014-05-14 17:43:35 +0800 | [diff] [blame] | 2541 | |
Chen Fan | 976620a | 2014-08-18 14:46:34 +0800 | [diff] [blame] | 2542 | g_free(str); |
Eric Blake | 3b098d5 | 2016-06-09 10:48:43 -0600 | [diff] [blame] | 2543 | visit_free(v); |
Hu Tao | eb1539b | 2014-05-14 17:43:35 +0800 | [diff] [blame] | 2544 | m = m->next; |
Hu Tao | eb1539b | 2014-05-14 17:43:35 +0800 | [diff] [blame] | 2545 | } |
| 2546 | |
| 2547 | monitor_printf(mon, "\n"); |
Chen Fan | ecaf54a | 2014-08-18 14:46:35 +0800 | [diff] [blame] | 2548 | |
| 2549 | qapi_free_MemdevList(memdev_list); |
Dr. David Alan Gilbert | 40c71f6 | 2017-08-17 11:42:15 +0100 | [diff] [blame] | 2550 | hmp_handle_error(mon, &err); |
Hu Tao | eb1539b | 2014-05-14 17:43:35 +0800 | [diff] [blame] | 2551 | } |
Zhu Guihua | a631892 | 2014-09-23 13:35:19 +0800 | [diff] [blame] | 2552 | |
| 2553 | void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) |
| 2554 | { |
| 2555 | Error *err = NULL; |
| 2556 | MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err); |
| 2557 | MemoryDeviceInfoList *info; |
| 2558 | MemoryDeviceInfo *value; |
| 2559 | PCDIMMDeviceInfo *di; |
| 2560 | |
| 2561 | for (info = info_list; info; info = info->next) { |
| 2562 | value = info->value; |
| 2563 | |
| 2564 | if (value) { |
Eric Blake | 1fd5d4f | 2015-10-26 16:34:59 -0600 | [diff] [blame] | 2565 | switch (value->type) { |
Zhu Guihua | a631892 | 2014-09-23 13:35:19 +0800 | [diff] [blame] | 2566 | case MEMORY_DEVICE_INFO_KIND_DIMM: |
Eric Blake | 32bafa8 | 2016-03-17 16:48:37 -0600 | [diff] [blame] | 2567 | di = value->u.dimm.data; |
Haozhong Zhang | 6388e18 | 2018-03-11 11:02:12 +0800 | [diff] [blame] | 2568 | break; |
Zhu Guihua | a631892 | 2014-09-23 13:35:19 +0800 | [diff] [blame] | 2569 | |
Haozhong Zhang | 6388e18 | 2018-03-11 11:02:12 +0800 | [diff] [blame] | 2570 | case MEMORY_DEVICE_INFO_KIND_NVDIMM: |
| 2571 | di = value->u.nvdimm.data; |
| 2572 | break; |
| 2573 | |
| 2574 | default: |
| 2575 | di = NULL; |
| 2576 | break; |
| 2577 | } |
| 2578 | |
| 2579 | if (di) { |
Zhu Guihua | a631892 | 2014-09-23 13:35:19 +0800 | [diff] [blame] | 2580 | monitor_printf(mon, "Memory device [%s]: \"%s\"\n", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 2581 | MemoryDeviceInfoKind_str(value->type), |
Zhu Guihua | a631892 | 2014-09-23 13:35:19 +0800 | [diff] [blame] | 2582 | di->id ? di->id : ""); |
| 2583 | monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr); |
| 2584 | monitor_printf(mon, " slot: %" PRId64 "\n", di->slot); |
| 2585 | monitor_printf(mon, " node: %" PRId64 "\n", di->node); |
| 2586 | monitor_printf(mon, " size: %" PRIu64 "\n", di->size); |
| 2587 | monitor_printf(mon, " memdev: %s\n", di->memdev); |
| 2588 | monitor_printf(mon, " hotplugged: %s\n", |
| 2589 | di->hotplugged ? "true" : "false"); |
| 2590 | monitor_printf(mon, " hotpluggable: %s\n", |
| 2591 | di->hotpluggable ? "true" : "false"); |
Zhu Guihua | a631892 | 2014-09-23 13:35:19 +0800 | [diff] [blame] | 2592 | } |
| 2593 | } |
| 2594 | } |
| 2595 | |
| 2596 | qapi_free_MemoryDeviceInfoList(info_list); |
Dr. David Alan Gilbert | 40c71f6 | 2017-08-17 11:42:15 +0100 | [diff] [blame] | 2597 | hmp_handle_error(mon, &err); |
Zhu Guihua | a631892 | 2014-09-23 13:35:19 +0800 | [diff] [blame] | 2598 | } |
Andreas Färber | 89d7fa9 | 2014-05-07 18:08:29 +0200 | [diff] [blame] | 2599 | |
Ting Wang | 6231316 | 2015-06-26 16:07:13 +0800 | [diff] [blame] | 2600 | void hmp_info_iothreads(Monitor *mon, const QDict *qdict) |
| 2601 | { |
| 2602 | IOThreadInfoList *info_list = qmp_query_iothreads(NULL); |
| 2603 | IOThreadInfoList *info; |
Pavel Hrdina | 5fc0048 | 2017-02-10 10:41:17 +0100 | [diff] [blame] | 2604 | IOThreadInfo *value; |
Ting Wang | 6231316 | 2015-06-26 16:07:13 +0800 | [diff] [blame] | 2605 | |
| 2606 | for (info = info_list; info; info = info->next) { |
Pavel Hrdina | 5fc0048 | 2017-02-10 10:41:17 +0100 | [diff] [blame] | 2607 | value = info->value; |
| 2608 | monitor_printf(mon, "%s:\n", value->id); |
| 2609 | monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id); |
| 2610 | monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns); |
| 2611 | monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow); |
| 2612 | monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink); |
Ting Wang | 6231316 | 2015-06-26 16:07:13 +0800 | [diff] [blame] | 2613 | } |
| 2614 | |
| 2615 | qapi_free_IOThreadInfoList(info_list); |
| 2616 | } |
| 2617 | |
Andreas Färber | 89d7fa9 | 2014-05-07 18:08:29 +0200 | [diff] [blame] | 2618 | void hmp_qom_list(Monitor *mon, const QDict *qdict) |
| 2619 | { |
| 2620 | const char *path = qdict_get_try_str(qdict, "path"); |
| 2621 | ObjectPropertyInfoList *list; |
| 2622 | Error *err = NULL; |
| 2623 | |
| 2624 | if (path == NULL) { |
| 2625 | monitor_printf(mon, "/\n"); |
| 2626 | return; |
| 2627 | } |
| 2628 | |
| 2629 | list = qmp_qom_list(path, &err); |
| 2630 | if (err == NULL) { |
| 2631 | ObjectPropertyInfoList *start = list; |
| 2632 | while (list != NULL) { |
| 2633 | ObjectPropertyInfo *value = list->value; |
| 2634 | |
| 2635 | monitor_printf(mon, "%s (%s)\n", |
| 2636 | value->name, value->type); |
| 2637 | list = list->next; |
| 2638 | } |
| 2639 | qapi_free_ObjectPropertyInfoList(start); |
| 2640 | } |
| 2641 | hmp_handle_error(mon, &err); |
| 2642 | } |
Andreas Färber | c0e6ee9 | 2014-05-07 19:48:15 +0200 | [diff] [blame] | 2643 | |
| 2644 | void hmp_qom_set(Monitor *mon, const QDict *qdict) |
| 2645 | { |
| 2646 | const char *path = qdict_get_str(qdict, "path"); |
| 2647 | const char *property = qdict_get_str(qdict, "property"); |
| 2648 | const char *value = qdict_get_str(qdict, "value"); |
| 2649 | Error *err = NULL; |
| 2650 | bool ambiguous = false; |
| 2651 | Object *obj; |
| 2652 | |
| 2653 | obj = object_resolve_path(path, &ambiguous); |
| 2654 | if (obj == NULL) { |
Markus Armbruster | 75158eb | 2015-03-16 08:57:47 +0100 | [diff] [blame] | 2655 | error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND, |
| 2656 | "Device '%s' not found", path); |
Andreas Färber | c0e6ee9 | 2014-05-07 19:48:15 +0200 | [diff] [blame] | 2657 | } else { |
| 2658 | if (ambiguous) { |
| 2659 | monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path); |
| 2660 | } |
| 2661 | object_property_parse(obj, value, property, &err); |
| 2662 | } |
| 2663 | hmp_handle_error(mon, &err); |
| 2664 | } |
Scott Feldman | fafa4d5 | 2015-06-10 18:21:21 -0700 | [diff] [blame] | 2665 | |
| 2666 | void hmp_rocker(Monitor *mon, const QDict *qdict) |
| 2667 | { |
| 2668 | const char *name = qdict_get_str(qdict, "name"); |
| 2669 | RockerSwitch *rocker; |
Markus Armbruster | 533fdae | 2015-12-18 16:35:27 +0100 | [diff] [blame] | 2670 | Error *err = NULL; |
Scott Feldman | fafa4d5 | 2015-06-10 18:21:21 -0700 | [diff] [blame] | 2671 | |
Markus Armbruster | 533fdae | 2015-12-18 16:35:27 +0100 | [diff] [blame] | 2672 | rocker = qmp_query_rocker(name, &err); |
| 2673 | if (err != NULL) { |
| 2674 | hmp_handle_error(mon, &err); |
Scott Feldman | fafa4d5 | 2015-06-10 18:21:21 -0700 | [diff] [blame] | 2675 | return; |
| 2676 | } |
| 2677 | |
| 2678 | monitor_printf(mon, "name: %s\n", rocker->name); |
| 2679 | monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id); |
| 2680 | monitor_printf(mon, "ports: %d\n", rocker->ports); |
| 2681 | |
| 2682 | qapi_free_RockerSwitch(rocker); |
| 2683 | } |
| 2684 | |
| 2685 | void hmp_rocker_ports(Monitor *mon, const QDict *qdict) |
| 2686 | { |
| 2687 | RockerPortList *list, *port; |
| 2688 | const char *name = qdict_get_str(qdict, "name"); |
Markus Armbruster | 533fdae | 2015-12-18 16:35:27 +0100 | [diff] [blame] | 2689 | Error *err = NULL; |
Scott Feldman | fafa4d5 | 2015-06-10 18:21:21 -0700 | [diff] [blame] | 2690 | |
Markus Armbruster | 533fdae | 2015-12-18 16:35:27 +0100 | [diff] [blame] | 2691 | list = qmp_query_rocker_ports(name, &err); |
| 2692 | if (err != NULL) { |
| 2693 | hmp_handle_error(mon, &err); |
Scott Feldman | fafa4d5 | 2015-06-10 18:21:21 -0700 | [diff] [blame] | 2694 | return; |
| 2695 | } |
| 2696 | |
| 2697 | monitor_printf(mon, " ena/ speed/ auto\n"); |
| 2698 | monitor_printf(mon, " port link duplex neg?\n"); |
| 2699 | |
| 2700 | for (port = list; port; port = port->next) { |
| 2701 | monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n", |
| 2702 | port->value->name, |
| 2703 | port->value->enabled ? port->value->link_up ? |
| 2704 | "up" : "down" : "!ena", |
| 2705 | port->value->speed == 10000 ? "10G" : "??", |
| 2706 | port->value->duplex ? "FD" : "HD", |
| 2707 | port->value->autoneg ? "Yes" : "No"); |
| 2708 | } |
| 2709 | |
| 2710 | qapi_free_RockerPortList(list); |
| 2711 | } |
| 2712 | |
| 2713 | void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict) |
| 2714 | { |
| 2715 | RockerOfDpaFlowList *list, *info; |
| 2716 | const char *name = qdict_get_str(qdict, "name"); |
| 2717 | uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1); |
Markus Armbruster | 533fdae | 2015-12-18 16:35:27 +0100 | [diff] [blame] | 2718 | Error *err = NULL; |
Scott Feldman | fafa4d5 | 2015-06-10 18:21:21 -0700 | [diff] [blame] | 2719 | |
Markus Armbruster | 533fdae | 2015-12-18 16:35:27 +0100 | [diff] [blame] | 2720 | list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err); |
| 2721 | if (err != NULL) { |
| 2722 | hmp_handle_error(mon, &err); |
Scott Feldman | fafa4d5 | 2015-06-10 18:21:21 -0700 | [diff] [blame] | 2723 | return; |
| 2724 | } |
| 2725 | |
| 2726 | monitor_printf(mon, "prio tbl hits key(mask) --> actions\n"); |
| 2727 | |
| 2728 | for (info = list; info; info = info->next) { |
| 2729 | RockerOfDpaFlow *flow = info->value; |
| 2730 | RockerOfDpaFlowKey *key = flow->key; |
| 2731 | RockerOfDpaFlowMask *mask = flow->mask; |
| 2732 | RockerOfDpaFlowAction *action = flow->action; |
| 2733 | |
| 2734 | if (flow->hits) { |
| 2735 | monitor_printf(mon, "%-4d %-3d %-4" PRIu64, |
| 2736 | key->priority, key->tbl_id, flow->hits); |
| 2737 | } else { |
| 2738 | monitor_printf(mon, "%-4d %-3d ", |
| 2739 | key->priority, key->tbl_id); |
| 2740 | } |
| 2741 | |
| 2742 | if (key->has_in_pport) { |
| 2743 | monitor_printf(mon, " pport %d", key->in_pport); |
| 2744 | if (mask->has_in_pport) { |
| 2745 | monitor_printf(mon, "(0x%x)", mask->in_pport); |
| 2746 | } |
| 2747 | } |
| 2748 | |
| 2749 | if (key->has_vlan_id) { |
| 2750 | monitor_printf(mon, " vlan %d", |
| 2751 | key->vlan_id & VLAN_VID_MASK); |
| 2752 | if (mask->has_vlan_id) { |
| 2753 | monitor_printf(mon, "(0x%x)", mask->vlan_id); |
| 2754 | } |
| 2755 | } |
| 2756 | |
| 2757 | if (key->has_tunnel_id) { |
| 2758 | monitor_printf(mon, " tunnel %d", key->tunnel_id); |
| 2759 | if (mask->has_tunnel_id) { |
| 2760 | monitor_printf(mon, "(0x%x)", mask->tunnel_id); |
| 2761 | } |
| 2762 | } |
| 2763 | |
| 2764 | if (key->has_eth_type) { |
| 2765 | switch (key->eth_type) { |
| 2766 | case 0x0806: |
| 2767 | monitor_printf(mon, " ARP"); |
| 2768 | break; |
| 2769 | case 0x0800: |
| 2770 | monitor_printf(mon, " IP"); |
| 2771 | break; |
| 2772 | case 0x86dd: |
| 2773 | monitor_printf(mon, " IPv6"); |
| 2774 | break; |
| 2775 | case 0x8809: |
| 2776 | monitor_printf(mon, " LACP"); |
| 2777 | break; |
| 2778 | case 0x88cc: |
| 2779 | monitor_printf(mon, " LLDP"); |
| 2780 | break; |
| 2781 | default: |
| 2782 | monitor_printf(mon, " eth type 0x%04x", key->eth_type); |
| 2783 | break; |
| 2784 | } |
| 2785 | } |
| 2786 | |
| 2787 | if (key->has_eth_src) { |
| 2788 | if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) && |
| 2789 | (mask->has_eth_src) && |
| 2790 | (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { |
| 2791 | monitor_printf(mon, " src <any mcast/bcast>"); |
| 2792 | } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) && |
| 2793 | (mask->has_eth_src) && |
| 2794 | (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { |
| 2795 | monitor_printf(mon, " src <any ucast>"); |
| 2796 | } else { |
| 2797 | monitor_printf(mon, " src %s", key->eth_src); |
| 2798 | if (mask->has_eth_src) { |
| 2799 | monitor_printf(mon, "(%s)", mask->eth_src); |
| 2800 | } |
| 2801 | } |
| 2802 | } |
| 2803 | |
| 2804 | if (key->has_eth_dst) { |
| 2805 | if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) && |
| 2806 | (mask->has_eth_dst) && |
| 2807 | (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { |
| 2808 | monitor_printf(mon, " dst <any mcast/bcast>"); |
| 2809 | } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) && |
| 2810 | (mask->has_eth_dst) && |
| 2811 | (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { |
| 2812 | monitor_printf(mon, " dst <any ucast>"); |
| 2813 | } else { |
| 2814 | monitor_printf(mon, " dst %s", key->eth_dst); |
| 2815 | if (mask->has_eth_dst) { |
| 2816 | monitor_printf(mon, "(%s)", mask->eth_dst); |
| 2817 | } |
| 2818 | } |
| 2819 | } |
| 2820 | |
| 2821 | if (key->has_ip_proto) { |
| 2822 | monitor_printf(mon, " proto %d", key->ip_proto); |
| 2823 | if (mask->has_ip_proto) { |
| 2824 | monitor_printf(mon, "(0x%x)", mask->ip_proto); |
| 2825 | } |
| 2826 | } |
| 2827 | |
| 2828 | if (key->has_ip_tos) { |
| 2829 | monitor_printf(mon, " TOS %d", key->ip_tos); |
| 2830 | if (mask->has_ip_tos) { |
| 2831 | monitor_printf(mon, "(0x%x)", mask->ip_tos); |
| 2832 | } |
| 2833 | } |
| 2834 | |
| 2835 | if (key->has_ip_dst) { |
| 2836 | monitor_printf(mon, " dst %s", key->ip_dst); |
| 2837 | } |
| 2838 | |
| 2839 | if (action->has_goto_tbl || action->has_group_id || |
| 2840 | action->has_new_vlan_id) { |
| 2841 | monitor_printf(mon, " -->"); |
| 2842 | } |
| 2843 | |
| 2844 | if (action->has_new_vlan_id) { |
| 2845 | monitor_printf(mon, " apply new vlan %d", |
| 2846 | ntohs(action->new_vlan_id)); |
| 2847 | } |
| 2848 | |
| 2849 | if (action->has_group_id) { |
| 2850 | monitor_printf(mon, " write group 0x%08x", action->group_id); |
| 2851 | } |
| 2852 | |
| 2853 | if (action->has_goto_tbl) { |
| 2854 | monitor_printf(mon, " goto tbl %d", action->goto_tbl); |
| 2855 | } |
| 2856 | |
| 2857 | monitor_printf(mon, "\n"); |
| 2858 | } |
| 2859 | |
| 2860 | qapi_free_RockerOfDpaFlowList(list); |
| 2861 | } |
| 2862 | |
| 2863 | void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict) |
| 2864 | { |
| 2865 | RockerOfDpaGroupList *list, *g; |
| 2866 | const char *name = qdict_get_str(qdict, "name"); |
| 2867 | uint8_t type = qdict_get_try_int(qdict, "type", 9); |
Markus Armbruster | 533fdae | 2015-12-18 16:35:27 +0100 | [diff] [blame] | 2868 | Error *err = NULL; |
Scott Feldman | fafa4d5 | 2015-06-10 18:21:21 -0700 | [diff] [blame] | 2869 | bool set = false; |
| 2870 | |
Markus Armbruster | 533fdae | 2015-12-18 16:35:27 +0100 | [diff] [blame] | 2871 | list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err); |
| 2872 | if (err != NULL) { |
| 2873 | hmp_handle_error(mon, &err); |
Scott Feldman | fafa4d5 | 2015-06-10 18:21:21 -0700 | [diff] [blame] | 2874 | return; |
| 2875 | } |
| 2876 | |
| 2877 | monitor_printf(mon, "id (decode) --> buckets\n"); |
| 2878 | |
| 2879 | for (g = list; g; g = g->next) { |
| 2880 | RockerOfDpaGroup *group = g->value; |
| 2881 | |
| 2882 | monitor_printf(mon, "0x%08x", group->id); |
| 2883 | |
| 2884 | monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" : |
| 2885 | group->type == 1 ? "L2 rewrite" : |
| 2886 | group->type == 2 ? "L3 unicast" : |
| 2887 | group->type == 3 ? "L2 multicast" : |
| 2888 | group->type == 4 ? "L2 flood" : |
| 2889 | group->type == 5 ? "L3 interface" : |
| 2890 | group->type == 6 ? "L3 multicast" : |
| 2891 | group->type == 7 ? "L3 ECMP" : |
| 2892 | group->type == 8 ? "L2 overlay" : |
| 2893 | "unknown"); |
| 2894 | |
| 2895 | if (group->has_vlan_id) { |
| 2896 | monitor_printf(mon, " vlan %d", group->vlan_id); |
| 2897 | } |
| 2898 | |
| 2899 | if (group->has_pport) { |
| 2900 | monitor_printf(mon, " pport %d", group->pport); |
| 2901 | } |
| 2902 | |
| 2903 | if (group->has_index) { |
| 2904 | monitor_printf(mon, " index %d", group->index); |
| 2905 | } |
| 2906 | |
| 2907 | monitor_printf(mon, ") -->"); |
| 2908 | |
| 2909 | if (group->has_set_vlan_id && group->set_vlan_id) { |
| 2910 | set = true; |
| 2911 | monitor_printf(mon, " set vlan %d", |
| 2912 | group->set_vlan_id & VLAN_VID_MASK); |
| 2913 | } |
| 2914 | |
| 2915 | if (group->has_set_eth_src) { |
| 2916 | if (!set) { |
| 2917 | set = true; |
| 2918 | monitor_printf(mon, " set"); |
| 2919 | } |
| 2920 | monitor_printf(mon, " src %s", group->set_eth_src); |
| 2921 | } |
| 2922 | |
| 2923 | if (group->has_set_eth_dst) { |
| 2924 | if (!set) { |
| 2925 | set = true; |
| 2926 | monitor_printf(mon, " set"); |
| 2927 | } |
| 2928 | monitor_printf(mon, " dst %s", group->set_eth_dst); |
| 2929 | } |
| 2930 | |
| 2931 | set = false; |
| 2932 | |
| 2933 | if (group->has_ttl_check && group->ttl_check) { |
| 2934 | monitor_printf(mon, " check TTL"); |
| 2935 | } |
| 2936 | |
| 2937 | if (group->has_group_id && group->group_id) { |
| 2938 | monitor_printf(mon, " group id 0x%08x", group->group_id); |
| 2939 | } |
| 2940 | |
| 2941 | if (group->has_pop_vlan && group->pop_vlan) { |
| 2942 | monitor_printf(mon, " pop vlan"); |
| 2943 | } |
| 2944 | |
| 2945 | if (group->has_out_pport) { |
| 2946 | monitor_printf(mon, " out pport %d", group->out_pport); |
| 2947 | } |
| 2948 | |
| 2949 | if (group->has_group_ids) { |
| 2950 | struct uint32List *id; |
| 2951 | |
| 2952 | monitor_printf(mon, " groups ["); |
| 2953 | for (id = group->group_ids; id; id = id->next) { |
| 2954 | monitor_printf(mon, "0x%08x", id->value); |
| 2955 | if (id->next) { |
| 2956 | monitor_printf(mon, ","); |
| 2957 | } |
| 2958 | } |
| 2959 | monitor_printf(mon, "]"); |
| 2960 | } |
| 2961 | |
| 2962 | monitor_printf(mon, "\n"); |
| 2963 | } |
| 2964 | |
| 2965 | qapi_free_RockerOfDpaGroupList(list); |
| 2966 | } |
Peter Xu | 4a6b52d | 2016-02-18 13:16:55 +0800 | [diff] [blame] | 2967 | |
| 2968 | void hmp_info_dump(Monitor *mon, const QDict *qdict) |
| 2969 | { |
| 2970 | DumpQueryResult *result = qmp_query_dump(NULL); |
| 2971 | |
| 2972 | assert(result && result->status < DUMP_STATUS__MAX); |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 2973 | monitor_printf(mon, "Status: %s\n", DumpStatus_str(result->status)); |
Peter Xu | 4a6b52d | 2016-02-18 13:16:55 +0800 | [diff] [blame] | 2974 | |
| 2975 | if (result->status == DUMP_STATUS_ACTIVE) { |
| 2976 | float percent = 0; |
| 2977 | assert(result->total != 0); |
| 2978 | percent = 100.0 * result->completed / result->total; |
| 2979 | monitor_printf(mon, "Finished: %.2f %%\n", percent); |
| 2980 | } |
| 2981 | |
| 2982 | qapi_free_DumpQueryResult(result); |
| 2983 | } |
Bharata B Rao | d2d8d46 | 2016-06-10 06:29:07 +0530 | [diff] [blame] | 2984 | |
Peter Xu | be9b23c | 2017-05-12 12:17:41 +0800 | [diff] [blame] | 2985 | void hmp_info_ramblock(Monitor *mon, const QDict *qdict) |
| 2986 | { |
| 2987 | ram_block_dump(mon); |
| 2988 | } |
| 2989 | |
Bharata B Rao | d2d8d46 | 2016-06-10 06:29:07 +0530 | [diff] [blame] | 2990 | void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict) |
| 2991 | { |
| 2992 | Error *err = NULL; |
| 2993 | HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err); |
| 2994 | HotpluggableCPUList *saved = l; |
| 2995 | CpuInstanceProperties *c; |
| 2996 | |
| 2997 | if (err != NULL) { |
| 2998 | hmp_handle_error(mon, &err); |
| 2999 | return; |
| 3000 | } |
| 3001 | |
| 3002 | monitor_printf(mon, "Hotpluggable CPUs:\n"); |
| 3003 | while (l) { |
| 3004 | monitor_printf(mon, " type: \"%s\"\n", l->value->type); |
| 3005 | monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n", |
| 3006 | l->value->vcpus_count); |
| 3007 | if (l->value->has_qom_path) { |
| 3008 | monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path); |
| 3009 | } |
| 3010 | |
| 3011 | c = l->value->props; |
| 3012 | monitor_printf(mon, " CPUInstance Properties:\n"); |
Peter Krempa | 27393c3 | 2016-06-23 23:23:34 +0200 | [diff] [blame] | 3013 | if (c->has_node_id) { |
| 3014 | monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id); |
Bharata B Rao | d2d8d46 | 2016-06-10 06:29:07 +0530 | [diff] [blame] | 3015 | } |
Peter Krempa | 27393c3 | 2016-06-23 23:23:34 +0200 | [diff] [blame] | 3016 | if (c->has_socket_id) { |
| 3017 | monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id); |
Bharata B Rao | d2d8d46 | 2016-06-10 06:29:07 +0530 | [diff] [blame] | 3018 | } |
Peter Krempa | 27393c3 | 2016-06-23 23:23:34 +0200 | [diff] [blame] | 3019 | if (c->has_core_id) { |
| 3020 | monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id); |
Bharata B Rao | d2d8d46 | 2016-06-10 06:29:07 +0530 | [diff] [blame] | 3021 | } |
Peter Krempa | 27393c3 | 2016-06-23 23:23:34 +0200 | [diff] [blame] | 3022 | if (c->has_thread_id) { |
| 3023 | monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id); |
Bharata B Rao | d2d8d46 | 2016-06-10 06:29:07 +0530 | [diff] [blame] | 3024 | } |
| 3025 | |
| 3026 | l = l->next; |
| 3027 | } |
| 3028 | |
| 3029 | qapi_free_HotpluggableCPUList(saved); |
| 3030 | } |
Igor Mammedov | 39164c1 | 2017-02-16 15:15:37 -0800 | [diff] [blame] | 3031 | |
| 3032 | void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict) |
| 3033 | { |
Ben Warren | 72d9196 | 2017-03-02 13:36:50 -0800 | [diff] [blame] | 3034 | Error *err = NULL; |
| 3035 | GuidInfo *info = qmp_query_vm_generation_id(&err); |
Igor Mammedov | 39164c1 | 2017-02-16 15:15:37 -0800 | [diff] [blame] | 3036 | if (info) { |
| 3037 | monitor_printf(mon, "%s\n", info->guid); |
| 3038 | } |
Ben Warren | 72d9196 | 2017-03-02 13:36:50 -0800 | [diff] [blame] | 3039 | hmp_handle_error(mon, &err); |
Igor Mammedov | 39164c1 | 2017-02-16 15:15:37 -0800 | [diff] [blame] | 3040 | qapi_free_GuidInfo(info); |
| 3041 | } |
Vadim Galitsyn | d0f63c1 | 2017-08-29 17:30:22 +0200 | [diff] [blame] | 3042 | |
| 3043 | void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict) |
| 3044 | { |
| 3045 | Error *err = NULL; |
| 3046 | MemoryInfo *info = qmp_query_memory_size_summary(&err); |
| 3047 | if (info) { |
| 3048 | monitor_printf(mon, "base memory: %" PRIu64 "\n", |
| 3049 | info->base_memory); |
| 3050 | |
| 3051 | if (info->has_plugged_memory) { |
| 3052 | monitor_printf(mon, "plugged memory: %" PRIu64 "\n", |
| 3053 | info->plugged_memory); |
| 3054 | } |
| 3055 | |
| 3056 | qapi_free_MemoryInfo(info); |
| 3057 | } |
| 3058 | hmp_handle_error(mon, &err); |
| 3059 | } |