hmp-cmds.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260
  1. /*
  2. * Human Monitor Interface commands
  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. *
  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.
  14. */
  15. #include "qemu/osdep.h"
  16. #include "monitor/hmp.h"
  17. #include "net/net.h"
  18. #include "net/eth.h"
  19. #include "chardev/char.h"
  20. #include "sysemu/block-backend.h"
  21. #include "sysemu/runstate.h"
  22. #include "qemu/config-file.h"
  23. #include "qemu/option.h"
  24. #include "qemu/timer.h"
  25. #include "qemu/sockets.h"
  26. #include "monitor/monitor-internal.h"
  27. #include "qapi/error.h"
  28. #include "qapi/clone-visitor.h"
  29. #include "qapi/opts-visitor.h"
  30. #include "qapi/qapi-builtin-visit.h"
  31. #include "qapi/qapi-commands-block.h"
  32. #include "qapi/qapi-commands-char.h"
  33. #include "qapi/qapi-commands-control.h"
  34. #include "qapi/qapi-commands-machine.h"
  35. #include "qapi/qapi-commands-migration.h"
  36. #include "qapi/qapi-commands-misc.h"
  37. #include "qapi/qapi-commands-net.h"
  38. #include "qapi/qapi-commands-pci.h"
  39. #include "qapi/qapi-commands-rocker.h"
  40. #include "qapi/qapi-commands-run-state.h"
  41. #include "qapi/qapi-commands-tpm.h"
  42. #include "qapi/qapi-commands-ui.h"
  43. #include "qapi/qapi-visit-net.h"
  44. #include "qapi/qapi-visit-migration.h"
  45. #include "qapi/qmp/qdict.h"
  46. #include "qapi/qmp/qerror.h"
  47. #include "qapi/string-input-visitor.h"
  48. #include "qapi/string-output-visitor.h"
  49. #include "qom/object_interfaces.h"
  50. #include "ui/console.h"
  51. #include "qemu/cutils.h"
  52. #include "qemu/error-report.h"
  53. #include "exec/ramlist.h"
  54. #include "hw/intc/intc.h"
  55. #include "hw/rdma/rdma.h"
  56. #include "migration/snapshot.h"
  57. #include "migration/misc.h"
  58. #ifdef CONFIG_SPICE
  59. #include <spice/enums.h>
  60. #endif
  61. void hmp_handle_error(Monitor *mon, Error *err)
  62. {
  63. if (err) {
  64. error_reportf_err(err, "Error: ");
  65. }
  66. }
  67. /*
  68. * Produce a strList from a comma separated list.
  69. * A NULL or empty input string return NULL.
  70. */
  71. static strList *strList_from_comma_list(const char *in)
  72. {
  73. strList *res = NULL;
  74. strList **hook = &res;
  75. while (in && in[0]) {
  76. char *comma = strchr(in, ',');
  77. *hook = g_new0(strList, 1);
  78. if (comma) {
  79. (*hook)->value = g_strndup(in, comma - in);
  80. in = comma + 1; /* skip the , */
  81. } else {
  82. (*hook)->value = g_strdup(in);
  83. in = NULL;
  84. }
  85. hook = &(*hook)->next;
  86. }
  87. return res;
  88. }
  89. void hmp_info_name(Monitor *mon, const QDict *qdict)
  90. {
  91. NameInfo *info;
  92. info = qmp_query_name(NULL);
  93. if (info->has_name) {
  94. monitor_printf(mon, "%s\n", info->name);
  95. }
  96. qapi_free_NameInfo(info);
  97. }
  98. void hmp_info_version(Monitor *mon, const QDict *qdict)
  99. {
  100. VersionInfo *info;
  101. info = qmp_query_version(NULL);
  102. monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
  103. info->qemu->major, info->qemu->minor, info->qemu->micro,
  104. info->package);
  105. qapi_free_VersionInfo(info);
  106. }
  107. void hmp_info_kvm(Monitor *mon, const QDict *qdict)
  108. {
  109. KvmInfo *info;
  110. info = qmp_query_kvm(NULL);
  111. monitor_printf(mon, "kvm support: ");
  112. if (info->present) {
  113. monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
  114. } else {
  115. monitor_printf(mon, "not compiled\n");
  116. }
  117. qapi_free_KvmInfo(info);
  118. }
  119. void hmp_info_status(Monitor *mon, const QDict *qdict)
  120. {
  121. StatusInfo *info;
  122. info = qmp_query_status(NULL);
  123. monitor_printf(mon, "VM status: %s%s",
  124. info->running ? "running" : "paused",
  125. info->singlestep ? " (single step mode)" : "");
  126. if (!info->running && info->status != RUN_STATE_PAUSED) {
  127. monitor_printf(mon, " (%s)", RunState_str(info->status));
  128. }
  129. monitor_printf(mon, "\n");
  130. qapi_free_StatusInfo(info);
  131. }
  132. void hmp_info_uuid(Monitor *mon, const QDict *qdict)
  133. {
  134. UuidInfo *info;
  135. info = qmp_query_uuid(NULL);
  136. monitor_printf(mon, "%s\n", info->UUID);
  137. qapi_free_UuidInfo(info);
  138. }
  139. void hmp_info_chardev(Monitor *mon, const QDict *qdict)
  140. {
  141. ChardevInfoList *char_info, *info;
  142. char_info = qmp_query_chardev(NULL);
  143. for (info = char_info; info; info = info->next) {
  144. monitor_printf(mon, "%s: filename=%s\n", info->value->label,
  145. info->value->filename);
  146. }
  147. qapi_free_ChardevInfoList(char_info);
  148. }
  149. void hmp_info_mice(Monitor *mon, const QDict *qdict)
  150. {
  151. MouseInfoList *mice_list, *mouse;
  152. mice_list = qmp_query_mice(NULL);
  153. if (!mice_list) {
  154. monitor_printf(mon, "No mouse devices connected\n");
  155. return;
  156. }
  157. for (mouse = mice_list; mouse; mouse = mouse->next) {
  158. monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
  159. mouse->value->current ? '*' : ' ',
  160. mouse->value->index, mouse->value->name,
  161. mouse->value->absolute ? " (absolute)" : "");
  162. }
  163. qapi_free_MouseInfoList(mice_list);
  164. }
  165. static char *SocketAddress_to_str(SocketAddress *addr)
  166. {
  167. switch (addr->type) {
  168. case SOCKET_ADDRESS_TYPE_INET:
  169. return g_strdup_printf("tcp:%s:%s",
  170. addr->u.inet.host,
  171. addr->u.inet.port);
  172. case SOCKET_ADDRESS_TYPE_UNIX:
  173. return g_strdup_printf("unix:%s",
  174. addr->u.q_unix.path);
  175. case SOCKET_ADDRESS_TYPE_FD:
  176. return g_strdup_printf("fd:%s", addr->u.fd.str);
  177. case SOCKET_ADDRESS_TYPE_VSOCK:
  178. return g_strdup_printf("tcp:%s:%s",
  179. addr->u.vsock.cid,
  180. addr->u.vsock.port);
  181. default:
  182. return g_strdup("unknown address type");
  183. }
  184. }
  185. void hmp_info_migrate(Monitor *mon, const QDict *qdict)
  186. {
  187. MigrationInfo *info;
  188. info = qmp_query_migrate(NULL);
  189. migration_global_dump(mon);
  190. if (info->has_status) {
  191. monitor_printf(mon, "Migration status: %s",
  192. MigrationStatus_str(info->status));
  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. monitor_printf(mon, "total time: %" PRIu64 " ms\n",
  200. info->total_time);
  201. if (info->has_expected_downtime) {
  202. monitor_printf(mon, "expected downtime: %" PRIu64 " ms\n",
  203. info->expected_downtime);
  204. }
  205. if (info->has_downtime) {
  206. monitor_printf(mon, "downtime: %" PRIu64 " ms\n",
  207. info->downtime);
  208. }
  209. if (info->has_setup_time) {
  210. monitor_printf(mon, "setup: %" PRIu64 " ms\n",
  211. info->setup_time);
  212. }
  213. }
  214. if (info->has_ram) {
  215. monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
  216. info->ram->transferred >> 10);
  217. monitor_printf(mon, "throughput: %0.2f mbps\n",
  218. info->ram->mbps);
  219. monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
  220. info->ram->remaining >> 10);
  221. monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
  222. info->ram->total >> 10);
  223. monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
  224. info->ram->duplicate);
  225. monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
  226. info->ram->skipped);
  227. monitor_printf(mon, "normal: %" PRIu64 " pages\n",
  228. info->ram->normal);
  229. monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
  230. info->ram->normal_bytes >> 10);
  231. monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
  232. info->ram->dirty_sync_count);
  233. monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
  234. info->ram->page_size >> 10);
  235. monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n",
  236. info->ram->multifd_bytes >> 10);
  237. monitor_printf(mon, "pages-per-second: %" PRIu64 "\n",
  238. info->ram->pages_per_second);
  239. if (info->ram->dirty_pages_rate) {
  240. monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
  241. info->ram->dirty_pages_rate);
  242. }
  243. if (info->ram->postcopy_requests) {
  244. monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
  245. info->ram->postcopy_requests);
  246. }
  247. }
  248. if (info->has_disk) {
  249. monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
  250. info->disk->transferred >> 10);
  251. monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
  252. info->disk->remaining >> 10);
  253. monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
  254. info->disk->total >> 10);
  255. }
  256. if (info->has_xbzrle_cache) {
  257. monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
  258. info->xbzrle_cache->cache_size);
  259. monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
  260. info->xbzrle_cache->bytes >> 10);
  261. monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
  262. info->xbzrle_cache->pages);
  263. monitor_printf(mon, "xbzrle cache miss: %" PRIu64 " pages\n",
  264. info->xbzrle_cache->cache_miss);
  265. monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
  266. info->xbzrle_cache->cache_miss_rate);
  267. monitor_printf(mon, "xbzrle encoding rate: %0.2f\n",
  268. info->xbzrle_cache->encoding_rate);
  269. monitor_printf(mon, "xbzrle overflow: %" PRIu64 "\n",
  270. info->xbzrle_cache->overflow);
  271. }
  272. if (info->has_compression) {
  273. monitor_printf(mon, "compression pages: %" PRIu64 " pages\n",
  274. info->compression->pages);
  275. monitor_printf(mon, "compression busy: %" PRIu64 "\n",
  276. info->compression->busy);
  277. monitor_printf(mon, "compression busy rate: %0.2f\n",
  278. info->compression->busy_rate);
  279. monitor_printf(mon, "compressed size: %" PRIu64 " kbytes\n",
  280. info->compression->compressed_size >> 10);
  281. monitor_printf(mon, "compression rate: %0.2f\n",
  282. info->compression->compression_rate);
  283. }
  284. if (info->has_cpu_throttle_percentage) {
  285. monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
  286. info->cpu_throttle_percentage);
  287. }
  288. if (info->has_postcopy_blocktime) {
  289. monitor_printf(mon, "postcopy blocktime: %u\n",
  290. info->postcopy_blocktime);
  291. }
  292. if (info->has_postcopy_vcpu_blocktime) {
  293. Visitor *v;
  294. char *str;
  295. v = string_output_visitor_new(false, &str);
  296. visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime,
  297. &error_abort);
  298. visit_complete(v, &str);
  299. monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
  300. g_free(str);
  301. visit_free(v);
  302. }
  303. if (info->has_socket_address) {
  304. SocketAddressList *addr;
  305. monitor_printf(mon, "socket address: [\n");
  306. for (addr = info->socket_address; addr; addr = addr->next) {
  307. char *s = SocketAddress_to_str(addr->value);
  308. monitor_printf(mon, "\t%s\n", s);
  309. g_free(s);
  310. }
  311. monitor_printf(mon, "]\n");
  312. }
  313. qapi_free_MigrationInfo(info);
  314. }
  315. void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
  316. {
  317. MigrationCapabilityStatusList *caps, *cap;
  318. caps = qmp_query_migrate_capabilities(NULL);
  319. if (caps) {
  320. for (cap = caps; cap; cap = cap->next) {
  321. monitor_printf(mon, "%s: %s\n",
  322. MigrationCapability_str(cap->value->capability),
  323. cap->value->state ? "on" : "off");
  324. }
  325. }
  326. qapi_free_MigrationCapabilityStatusList(caps);
  327. }
  328. void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
  329. {
  330. MigrationParameters *params;
  331. params = qmp_query_migrate_parameters(NULL);
  332. if (params) {
  333. monitor_printf(mon, "%s: %" PRIu64 " ms\n",
  334. MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL),
  335. params->announce_initial);
  336. monitor_printf(mon, "%s: %" PRIu64 " ms\n",
  337. MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX),
  338. params->announce_max);
  339. monitor_printf(mon, "%s: %" PRIu64 "\n",
  340. MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS),
  341. params->announce_rounds);
  342. monitor_printf(mon, "%s: %" PRIu64 " ms\n",
  343. MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP),
  344. params->announce_step);
  345. assert(params->has_compress_level);
  346. monitor_printf(mon, "%s: %u\n",
  347. MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
  348. params->compress_level);
  349. assert(params->has_compress_threads);
  350. monitor_printf(mon, "%s: %u\n",
  351. MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
  352. params->compress_threads);
  353. assert(params->has_compress_wait_thread);
  354. monitor_printf(mon, "%s: %s\n",
  355. MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD),
  356. params->compress_wait_thread ? "on" : "off");
  357. assert(params->has_decompress_threads);
  358. monitor_printf(mon, "%s: %u\n",
  359. MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
  360. params->decompress_threads);
  361. assert(params->has_throttle_trigger_threshold);
  362. monitor_printf(mon, "%s: %u\n",
  363. MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD),
  364. params->throttle_trigger_threshold);
  365. assert(params->has_cpu_throttle_initial);
  366. monitor_printf(mon, "%s: %u\n",
  367. MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
  368. params->cpu_throttle_initial);
  369. assert(params->has_cpu_throttle_increment);
  370. monitor_printf(mon, "%s: %u\n",
  371. MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
  372. params->cpu_throttle_increment);
  373. assert(params->has_cpu_throttle_tailslow);
  374. monitor_printf(mon, "%s: %s\n",
  375. MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW),
  376. params->cpu_throttle_tailslow ? "on" : "off");
  377. assert(params->has_max_cpu_throttle);
  378. monitor_printf(mon, "%s: %u\n",
  379. MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE),
  380. params->max_cpu_throttle);
  381. assert(params->has_tls_creds);
  382. monitor_printf(mon, "%s: '%s'\n",
  383. MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
  384. params->tls_creds);
  385. assert(params->has_tls_hostname);
  386. monitor_printf(mon, "%s: '%s'\n",
  387. MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
  388. params->tls_hostname);
  389. assert(params->has_max_bandwidth);
  390. monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
  391. MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
  392. params->max_bandwidth);
  393. assert(params->has_downtime_limit);
  394. monitor_printf(mon, "%s: %" PRIu64 " ms\n",
  395. MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
  396. params->downtime_limit);
  397. assert(params->has_x_checkpoint_delay);
  398. monitor_printf(mon, "%s: %u ms\n",
  399. MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
  400. params->x_checkpoint_delay);
  401. assert(params->has_block_incremental);
  402. monitor_printf(mon, "%s: %s\n",
  403. MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
  404. params->block_incremental ? "on" : "off");
  405. monitor_printf(mon, "%s: %u\n",
  406. MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS),
  407. params->multifd_channels);
  408. monitor_printf(mon, "%s: %s\n",
  409. MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION),
  410. MultiFDCompression_str(params->multifd_compression));
  411. monitor_printf(mon, "%s: %" PRIu64 " bytes\n",
  412. MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
  413. params->xbzrle_cache_size);
  414. monitor_printf(mon, "%s: %" PRIu64 "\n",
  415. MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
  416. params->max_postcopy_bandwidth);
  417. monitor_printf(mon, "%s: '%s'\n",
  418. MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
  419. params->tls_authz);
  420. if (params->has_block_bitmap_mapping) {
  421. const BitmapMigrationNodeAliasList *bmnal;
  422. monitor_printf(mon, "%s:\n",
  423. MigrationParameter_str(
  424. MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING));
  425. for (bmnal = params->block_bitmap_mapping;
  426. bmnal;
  427. bmnal = bmnal->next)
  428. {
  429. const BitmapMigrationNodeAlias *bmna = bmnal->value;
  430. const BitmapMigrationBitmapAliasList *bmbal;
  431. monitor_printf(mon, " '%s' -> '%s'\n",
  432. bmna->node_name, bmna->alias);
  433. for (bmbal = bmna->bitmaps; bmbal; bmbal = bmbal->next) {
  434. const BitmapMigrationBitmapAlias *bmba = bmbal->value;
  435. monitor_printf(mon, " '%s' -> '%s'\n",
  436. bmba->name, bmba->alias);
  437. }
  438. }
  439. }
  440. }
  441. qapi_free_MigrationParameters(params);
  442. }
  443. void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
  444. {
  445. monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
  446. qmp_query_migrate_cache_size(NULL) >> 10);
  447. }
  448. #ifdef CONFIG_VNC
  449. /* Helper for hmp_info_vnc_clients, _servers */
  450. static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
  451. const char *name)
  452. {
  453. monitor_printf(mon, " %s: %s:%s (%s%s)\n",
  454. name,
  455. info->host,
  456. info->service,
  457. NetworkAddressFamily_str(info->family),
  458. info->websocket ? " (Websocket)" : "");
  459. }
  460. /* Helper displaying and auth and crypt info */
  461. static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
  462. VncPrimaryAuth auth,
  463. VncVencryptSubAuth *vencrypt)
  464. {
  465. monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
  466. VncPrimaryAuth_str(auth),
  467. vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
  468. }
  469. static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
  470. {
  471. while (client) {
  472. VncClientInfo *cinfo = client->value;
  473. hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
  474. monitor_printf(mon, " x509_dname: %s\n",
  475. cinfo->has_x509_dname ?
  476. cinfo->x509_dname : "none");
  477. monitor_printf(mon, " sasl_username: %s\n",
  478. cinfo->has_sasl_username ?
  479. cinfo->sasl_username : "none");
  480. client = client->next;
  481. }
  482. }
  483. static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
  484. {
  485. while (server) {
  486. VncServerInfo2 *sinfo = server->value;
  487. hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
  488. hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
  489. sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
  490. server = server->next;
  491. }
  492. }
  493. void hmp_info_vnc(Monitor *mon, const QDict *qdict)
  494. {
  495. VncInfo2List *info2l, *info2l_head;
  496. Error *err = NULL;
  497. info2l = qmp_query_vnc_servers(&err);
  498. info2l_head = info2l;
  499. if (err) {
  500. hmp_handle_error(mon, err);
  501. return;
  502. }
  503. if (!info2l) {
  504. monitor_printf(mon, "None\n");
  505. return;
  506. }
  507. while (info2l) {
  508. VncInfo2 *info = info2l->value;
  509. monitor_printf(mon, "%s:\n", info->id);
  510. hmp_info_vnc_servers(mon, info->server);
  511. hmp_info_vnc_clients(mon, info->clients);
  512. if (!info->server) {
  513. /* The server entry displays its auth, we only
  514. * need to display in the case of 'reverse' connections
  515. * where there's no server.
  516. */
  517. hmp_info_vnc_authcrypt(mon, " ", info->auth,
  518. info->has_vencrypt ? &info->vencrypt : NULL);
  519. }
  520. if (info->has_display) {
  521. monitor_printf(mon, " Display: %s\n", info->display);
  522. }
  523. info2l = info2l->next;
  524. }
  525. qapi_free_VncInfo2List(info2l_head);
  526. }
  527. #endif
  528. #ifdef CONFIG_SPICE
  529. void hmp_info_spice(Monitor *mon, const QDict *qdict)
  530. {
  531. SpiceChannelList *chan;
  532. SpiceInfo *info;
  533. const char *channel_name;
  534. const char * const channel_names[] = {
  535. [SPICE_CHANNEL_MAIN] = "main",
  536. [SPICE_CHANNEL_DISPLAY] = "display",
  537. [SPICE_CHANNEL_INPUTS] = "inputs",
  538. [SPICE_CHANNEL_CURSOR] = "cursor",
  539. [SPICE_CHANNEL_PLAYBACK] = "playback",
  540. [SPICE_CHANNEL_RECORD] = "record",
  541. [SPICE_CHANNEL_TUNNEL] = "tunnel",
  542. [SPICE_CHANNEL_SMARTCARD] = "smartcard",
  543. [SPICE_CHANNEL_USBREDIR] = "usbredir",
  544. [SPICE_CHANNEL_PORT] = "port",
  545. #if 0
  546. /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
  547. * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
  548. * as quick fix for build failures with older versions. */
  549. [SPICE_CHANNEL_WEBDAV] = "webdav",
  550. #endif
  551. };
  552. info = qmp_query_spice(NULL);
  553. if (!info->enabled) {
  554. monitor_printf(mon, "Server: disabled\n");
  555. goto out;
  556. }
  557. monitor_printf(mon, "Server:\n");
  558. if (info->has_port) {
  559. monitor_printf(mon, " address: %s:%" PRId64 "\n",
  560. info->host, info->port);
  561. }
  562. if (info->has_tls_port) {
  563. monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
  564. info->host, info->tls_port);
  565. }
  566. monitor_printf(mon, " migrated: %s\n",
  567. info->migrated ? "true" : "false");
  568. monitor_printf(mon, " auth: %s\n", info->auth);
  569. monitor_printf(mon, " compiled: %s\n", info->compiled_version);
  570. monitor_printf(mon, " mouse-mode: %s\n",
  571. SpiceQueryMouseMode_str(info->mouse_mode));
  572. if (!info->has_channels || info->channels == NULL) {
  573. monitor_printf(mon, "Channels: none\n");
  574. } else {
  575. for (chan = info->channels; chan; chan = chan->next) {
  576. monitor_printf(mon, "Channel:\n");
  577. monitor_printf(mon, " address: %s:%s%s\n",
  578. chan->value->host, chan->value->port,
  579. chan->value->tls ? " [tls]" : "");
  580. monitor_printf(mon, " session: %" PRId64 "\n",
  581. chan->value->connection_id);
  582. monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
  583. chan->value->channel_type, chan->value->channel_id);
  584. channel_name = "unknown";
  585. if (chan->value->channel_type > 0 &&
  586. chan->value->channel_type < ARRAY_SIZE(channel_names) &&
  587. channel_names[chan->value->channel_type]) {
  588. channel_name = channel_names[chan->value->channel_type];
  589. }
  590. monitor_printf(mon, " channel name: %s\n", channel_name);
  591. }
  592. }
  593. out:
  594. qapi_free_SpiceInfo(info);
  595. }
  596. #endif
  597. void hmp_info_balloon(Monitor *mon, const QDict *qdict)
  598. {
  599. BalloonInfo *info;
  600. Error *err = NULL;
  601. info = qmp_query_balloon(&err);
  602. if (err) {
  603. hmp_handle_error(mon, err);
  604. return;
  605. }
  606. monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
  607. qapi_free_BalloonInfo(info);
  608. }
  609. static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
  610. {
  611. PciMemoryRegionList *region;
  612. monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
  613. monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
  614. dev->slot, dev->function);
  615. monitor_printf(mon, " ");
  616. if (dev->class_info->has_desc) {
  617. monitor_printf(mon, "%s", dev->class_info->desc);
  618. } else {
  619. monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
  620. }
  621. monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
  622. dev->id->vendor, dev->id->device);
  623. if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) {
  624. monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n",
  625. dev->id->subsystem_vendor, dev->id->subsystem);
  626. }
  627. if (dev->has_irq) {
  628. monitor_printf(mon, " IRQ %" PRId64 ", pin %c\n",
  629. dev->irq, (char)('A' + dev->irq_pin - 1));
  630. }
  631. if (dev->has_pci_bridge) {
  632. monitor_printf(mon, " BUS %" PRId64 ".\n",
  633. dev->pci_bridge->bus->number);
  634. monitor_printf(mon, " secondary bus %" PRId64 ".\n",
  635. dev->pci_bridge->bus->secondary);
  636. monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
  637. dev->pci_bridge->bus->subordinate);
  638. monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
  639. dev->pci_bridge->bus->io_range->base,
  640. dev->pci_bridge->bus->io_range->limit);
  641. monitor_printf(mon,
  642. " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
  643. dev->pci_bridge->bus->memory_range->base,
  644. dev->pci_bridge->bus->memory_range->limit);
  645. monitor_printf(mon, " prefetchable memory range "
  646. "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
  647. dev->pci_bridge->bus->prefetchable_range->base,
  648. dev->pci_bridge->bus->prefetchable_range->limit);
  649. }
  650. for (region = dev->regions; region; region = region->next) {
  651. uint64_t addr, size;
  652. addr = region->value->address;
  653. size = region->value->size;
  654. monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
  655. if (!strcmp(region->value->type, "io")) {
  656. monitor_printf(mon, "I/O at 0x%04" PRIx64
  657. " [0x%04" PRIx64 "].\n",
  658. addr, addr + size - 1);
  659. } else {
  660. monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
  661. " [0x%08" PRIx64 "].\n",
  662. region->value->mem_type_64 ? 64 : 32,
  663. region->value->prefetch ? " prefetchable" : "",
  664. addr, addr + size - 1);
  665. }
  666. }
  667. monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
  668. if (dev->has_pci_bridge) {
  669. if (dev->pci_bridge->has_devices) {
  670. PciDeviceInfoList *cdev;
  671. for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
  672. hmp_info_pci_device(mon, cdev->value);
  673. }
  674. }
  675. }
  676. }
  677. static int hmp_info_irq_foreach(Object *obj, void *opaque)
  678. {
  679. InterruptStatsProvider *intc;
  680. InterruptStatsProviderClass *k;
  681. Monitor *mon = opaque;
  682. if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
  683. intc = INTERRUPT_STATS_PROVIDER(obj);
  684. k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
  685. uint64_t *irq_counts;
  686. unsigned int nb_irqs, i;
  687. if (k->get_statistics &&
  688. k->get_statistics(intc, &irq_counts, &nb_irqs)) {
  689. if (nb_irqs > 0) {
  690. monitor_printf(mon, "IRQ statistics for %s:\n",
  691. object_get_typename(obj));
  692. for (i = 0; i < nb_irqs; i++) {
  693. if (irq_counts[i] > 0) {
  694. monitor_printf(mon, "%2d: %" PRId64 "\n", i,
  695. irq_counts[i]);
  696. }
  697. }
  698. }
  699. } else {
  700. monitor_printf(mon, "IRQ statistics not available for %s.\n",
  701. object_get_typename(obj));
  702. }
  703. }
  704. return 0;
  705. }
  706. void hmp_info_irq(Monitor *mon, const QDict *qdict)
  707. {
  708. object_child_foreach_recursive(object_get_root(),
  709. hmp_info_irq_foreach, mon);
  710. }
  711. static int hmp_info_pic_foreach(Object *obj, void *opaque)
  712. {
  713. InterruptStatsProvider *intc;
  714. InterruptStatsProviderClass *k;
  715. Monitor *mon = opaque;
  716. if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
  717. intc = INTERRUPT_STATS_PROVIDER(obj);
  718. k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
  719. if (k->print_info) {
  720. k->print_info(intc, mon);
  721. } else {
  722. monitor_printf(mon, "Interrupt controller information not available for %s.\n",
  723. object_get_typename(obj));
  724. }
  725. }
  726. return 0;
  727. }
  728. void hmp_info_pic(Monitor *mon, const QDict *qdict)
  729. {
  730. object_child_foreach_recursive(object_get_root(),
  731. hmp_info_pic_foreach, mon);
  732. }
  733. static int hmp_info_rdma_foreach(Object *obj, void *opaque)
  734. {
  735. RdmaProvider *rdma;
  736. RdmaProviderClass *k;
  737. Monitor *mon = opaque;
  738. if (object_dynamic_cast(obj, INTERFACE_RDMA_PROVIDER)) {
  739. rdma = RDMA_PROVIDER(obj);
  740. k = RDMA_PROVIDER_GET_CLASS(obj);
  741. if (k->print_statistics) {
  742. k->print_statistics(mon, rdma);
  743. } else {
  744. monitor_printf(mon, "RDMA statistics not available for %s.\n",
  745. object_get_typename(obj));
  746. }
  747. }
  748. return 0;
  749. }
  750. void hmp_info_rdma(Monitor *mon, const QDict *qdict)
  751. {
  752. object_child_foreach_recursive(object_get_root(),
  753. hmp_info_rdma_foreach, mon);
  754. }
  755. void hmp_info_pci(Monitor *mon, const QDict *qdict)
  756. {
  757. PciInfoList *info_list, *info;
  758. Error *err = NULL;
  759. info_list = qmp_query_pci(&err);
  760. if (err) {
  761. monitor_printf(mon, "PCI devices not supported\n");
  762. error_free(err);
  763. return;
  764. }
  765. for (info = info_list; info; info = info->next) {
  766. PciDeviceInfoList *dev;
  767. for (dev = info->value->devices; dev; dev = dev->next) {
  768. hmp_info_pci_device(mon, dev->value);
  769. }
  770. }
  771. qapi_free_PciInfoList(info_list);
  772. }
  773. void hmp_info_tpm(Monitor *mon, const QDict *qdict)
  774. {
  775. TPMInfoList *info_list, *info;
  776. Error *err = NULL;
  777. unsigned int c = 0;
  778. TPMPassthroughOptions *tpo;
  779. TPMEmulatorOptions *teo;
  780. info_list = qmp_query_tpm(&err);
  781. if (err) {
  782. monitor_printf(mon, "TPM device not supported\n");
  783. error_free(err);
  784. return;
  785. }
  786. if (info_list) {
  787. monitor_printf(mon, "TPM device:\n");
  788. }
  789. for (info = info_list; info; info = info->next) {
  790. TPMInfo *ti = info->value;
  791. monitor_printf(mon, " tpm%d: model=%s\n",
  792. c, TpmModel_str(ti->model));
  793. monitor_printf(mon, " \\ %s: type=%s",
  794. ti->id, TpmTypeOptionsKind_str(ti->options->type));
  795. switch (ti->options->type) {
  796. case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
  797. tpo = ti->options->u.passthrough.data;
  798. monitor_printf(mon, "%s%s%s%s",
  799. tpo->has_path ? ",path=" : "",
  800. tpo->has_path ? tpo->path : "",
  801. tpo->has_cancel_path ? ",cancel-path=" : "",
  802. tpo->has_cancel_path ? tpo->cancel_path : "");
  803. break;
  804. case TPM_TYPE_OPTIONS_KIND_EMULATOR:
  805. teo = ti->options->u.emulator.data;
  806. monitor_printf(mon, ",chardev=%s", teo->chardev);
  807. break;
  808. case TPM_TYPE_OPTIONS_KIND__MAX:
  809. break;
  810. }
  811. monitor_printf(mon, "\n");
  812. c++;
  813. }
  814. qapi_free_TPMInfoList(info_list);
  815. }
  816. void hmp_quit(Monitor *mon, const QDict *qdict)
  817. {
  818. monitor_suspend(mon);
  819. qmp_quit(NULL);
  820. }
  821. void hmp_stop(Monitor *mon, const QDict *qdict)
  822. {
  823. qmp_stop(NULL);
  824. }
  825. void hmp_sync_profile(Monitor *mon, const QDict *qdict)
  826. {
  827. const char *op = qdict_get_try_str(qdict, "op");
  828. if (op == NULL) {
  829. bool on = qsp_is_enabled();
  830. monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off");
  831. return;
  832. }
  833. if (!strcmp(op, "on")) {
  834. qsp_enable();
  835. } else if (!strcmp(op, "off")) {
  836. qsp_disable();
  837. } else if (!strcmp(op, "reset")) {
  838. qsp_reset();
  839. } else {
  840. Error *err = NULL;
  841. error_setg(&err, QERR_INVALID_PARAMETER, op);
  842. hmp_handle_error(mon, err);
  843. }
  844. }
  845. void hmp_system_reset(Monitor *mon, const QDict *qdict)
  846. {
  847. qmp_system_reset(NULL);
  848. }
  849. void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
  850. {
  851. qmp_system_powerdown(NULL);
  852. }
  853. void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
  854. {
  855. Error *err = NULL;
  856. qmp_x_exit_preconfig(&err);
  857. hmp_handle_error(mon, err);
  858. }
  859. void hmp_cpu(Monitor *mon, const QDict *qdict)
  860. {
  861. int64_t cpu_index;
  862. /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
  863. use it are converted to the QAPI */
  864. cpu_index = qdict_get_int(qdict, "index");
  865. if (monitor_set_cpu(mon, cpu_index) < 0) {
  866. monitor_printf(mon, "invalid CPU index\n");
  867. }
  868. }
  869. void hmp_memsave(Monitor *mon, const QDict *qdict)
  870. {
  871. uint32_t size = qdict_get_int(qdict, "size");
  872. const char *filename = qdict_get_str(qdict, "filename");
  873. uint64_t addr = qdict_get_int(qdict, "val");
  874. Error *err = NULL;
  875. int cpu_index = monitor_get_cpu_index(mon);
  876. if (cpu_index < 0) {
  877. monitor_printf(mon, "No CPU available\n");
  878. return;
  879. }
  880. qmp_memsave(addr, size, filename, true, cpu_index, &err);
  881. hmp_handle_error(mon, err);
  882. }
  883. void hmp_pmemsave(Monitor *mon, const QDict *qdict)
  884. {
  885. uint32_t size = qdict_get_int(qdict, "size");
  886. const char *filename = qdict_get_str(qdict, "filename");
  887. uint64_t addr = qdict_get_int(qdict, "val");
  888. Error *err = NULL;
  889. qmp_pmemsave(addr, size, filename, &err);
  890. hmp_handle_error(mon, err);
  891. }
  892. void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
  893. {
  894. const char *chardev = qdict_get_str(qdict, "device");
  895. const char *data = qdict_get_str(qdict, "data");
  896. Error *err = NULL;
  897. qmp_ringbuf_write(chardev, data, false, 0, &err);
  898. hmp_handle_error(mon, err);
  899. }
  900. void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
  901. {
  902. uint32_t size = qdict_get_int(qdict, "size");
  903. const char *chardev = qdict_get_str(qdict, "device");
  904. char *data;
  905. Error *err = NULL;
  906. int i;
  907. data = qmp_ringbuf_read(chardev, size, false, 0, &err);
  908. if (err) {
  909. hmp_handle_error(mon, err);
  910. return;
  911. }
  912. for (i = 0; data[i]; i++) {
  913. unsigned char ch = data[i];
  914. if (ch == '\\') {
  915. monitor_printf(mon, "\\\\");
  916. } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
  917. monitor_printf(mon, "\\u%04X", ch);
  918. } else {
  919. monitor_printf(mon, "%c", ch);
  920. }
  921. }
  922. monitor_printf(mon, "\n");
  923. g_free(data);
  924. }
  925. void hmp_cont(Monitor *mon, const QDict *qdict)
  926. {
  927. Error *err = NULL;
  928. qmp_cont(&err);
  929. hmp_handle_error(mon, err);
  930. }
  931. void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
  932. {
  933. Error *err = NULL;
  934. qmp_system_wakeup(&err);
  935. hmp_handle_error(mon, err);
  936. }
  937. void hmp_nmi(Monitor *mon, const QDict *qdict)
  938. {
  939. Error *err = NULL;
  940. qmp_inject_nmi(&err);
  941. hmp_handle_error(mon, err);
  942. }
  943. void hmp_set_link(Monitor *mon, const QDict *qdict)
  944. {
  945. const char *name = qdict_get_str(qdict, "name");
  946. bool up = qdict_get_bool(qdict, "up");
  947. Error *err = NULL;
  948. qmp_set_link(name, up, &err);
  949. hmp_handle_error(mon, err);
  950. }
  951. void hmp_balloon(Monitor *mon, const QDict *qdict)
  952. {
  953. int64_t value = qdict_get_int(qdict, "value");
  954. Error *err = NULL;
  955. qmp_balloon(value, &err);
  956. hmp_handle_error(mon, err);
  957. }
  958. void hmp_loadvm(Monitor *mon, const QDict *qdict)
  959. {
  960. int saved_vm_running = runstate_is_running();
  961. const char *name = qdict_get_str(qdict, "name");
  962. Error *err = NULL;
  963. vm_stop(RUN_STATE_RESTORE_VM);
  964. if (load_snapshot(name, &err) == 0 && saved_vm_running) {
  965. vm_start();
  966. }
  967. hmp_handle_error(mon, err);
  968. }
  969. void hmp_savevm(Monitor *mon, const QDict *qdict)
  970. {
  971. Error *err = NULL;
  972. save_snapshot(qdict_get_try_str(qdict, "name"), &err);
  973. hmp_handle_error(mon, err);
  974. }
  975. void hmp_delvm(Monitor *mon, const QDict *qdict)
  976. {
  977. BlockDriverState *bs;
  978. Error *err = NULL;
  979. const char *name = qdict_get_str(qdict, "name");
  980. if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
  981. error_prepend(&err,
  982. "deleting snapshot on device '%s': ",
  983. bdrv_get_device_name(bs));
  984. }
  985. hmp_handle_error(mon, err);
  986. }
  987. void hmp_announce_self(Monitor *mon, const QDict *qdict)
  988. {
  989. const char *interfaces_str = qdict_get_try_str(qdict, "interfaces");
  990. const char *id = qdict_get_try_str(qdict, "id");
  991. AnnounceParameters *params = QAPI_CLONE(AnnounceParameters,
  992. migrate_announce_params());
  993. qapi_free_strList(params->interfaces);
  994. params->interfaces = strList_from_comma_list(interfaces_str);
  995. params->has_interfaces = params->interfaces != NULL;
  996. params->id = g_strdup(id);
  997. params->has_id = !!params->id;
  998. qmp_announce_self(params, NULL);
  999. qapi_free_AnnounceParameters(params);
  1000. }
  1001. void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
  1002. {
  1003. qmp_migrate_cancel(NULL);
  1004. }
  1005. void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
  1006. {
  1007. Error *err = NULL;
  1008. const char *state = qdict_get_str(qdict, "state");
  1009. int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
  1010. if (val >= 0) {
  1011. qmp_migrate_continue(val, &err);
  1012. }
  1013. hmp_handle_error(mon, err);
  1014. }
  1015. void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
  1016. {
  1017. Error *err = NULL;
  1018. const char *uri = qdict_get_str(qdict, "uri");
  1019. qmp_migrate_incoming(uri, &err);
  1020. hmp_handle_error(mon, err);
  1021. }
  1022. void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
  1023. {
  1024. Error *err = NULL;
  1025. const char *uri = qdict_get_str(qdict, "uri");
  1026. qmp_migrate_recover(uri, &err);
  1027. hmp_handle_error(mon, err);
  1028. }
  1029. void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
  1030. {
  1031. Error *err = NULL;
  1032. qmp_migrate_pause(&err);
  1033. hmp_handle_error(mon, err);
  1034. }
  1035. /* Kept for backwards compatibility */
  1036. void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
  1037. {
  1038. Error *err = NULL;
  1039. double value = qdict_get_double(qdict, "value");
  1040. qmp_migrate_set_downtime(value, &err);
  1041. hmp_handle_error(mon, err);
  1042. }
  1043. void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
  1044. {
  1045. int64_t value = qdict_get_int(qdict, "value");
  1046. Error *err = NULL;
  1047. qmp_migrate_set_cache_size(value, &err);
  1048. hmp_handle_error(mon, err);
  1049. }
  1050. /* Kept for backwards compatibility */
  1051. void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
  1052. {
  1053. Error *err = NULL;
  1054. int64_t value = qdict_get_int(qdict, "value");
  1055. qmp_migrate_set_speed(value, &err);
  1056. hmp_handle_error(mon, err);
  1057. }
  1058. void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
  1059. {
  1060. const char *cap = qdict_get_str(qdict, "capability");
  1061. bool state = qdict_get_bool(qdict, "state");
  1062. Error *err = NULL;
  1063. MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
  1064. int val;
  1065. val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
  1066. if (val < 0) {
  1067. goto end;
  1068. }
  1069. caps->value = g_malloc0(sizeof(*caps->value));
  1070. caps->value->capability = val;
  1071. caps->value->state = state;
  1072. caps->next = NULL;
  1073. qmp_migrate_set_capabilities(caps, &err);
  1074. end:
  1075. qapi_free_MigrationCapabilityStatusList(caps);
  1076. hmp_handle_error(mon, err);
  1077. }
  1078. void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
  1079. {
  1080. const char *param = qdict_get_str(qdict, "parameter");
  1081. const char *valuestr = qdict_get_str(qdict, "value");
  1082. Visitor *v = string_input_visitor_new(valuestr);
  1083. MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
  1084. uint64_t valuebw = 0;
  1085. uint64_t cache_size;
  1086. Error *err = NULL;
  1087. int val, ret;
  1088. val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
  1089. if (val < 0) {
  1090. goto cleanup;
  1091. }
  1092. switch (val) {
  1093. case MIGRATION_PARAMETER_COMPRESS_LEVEL:
  1094. p->has_compress_level = true;
  1095. visit_type_int(v, param, &p->compress_level, &err);
  1096. break;
  1097. case MIGRATION_PARAMETER_COMPRESS_THREADS:
  1098. p->has_compress_threads = true;
  1099. visit_type_int(v, param, &p->compress_threads, &err);
  1100. break;
  1101. case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD:
  1102. p->has_compress_wait_thread = true;
  1103. visit_type_bool(v, param, &p->compress_wait_thread, &err);
  1104. break;
  1105. case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
  1106. p->has_decompress_threads = true;
  1107. visit_type_int(v, param, &p->decompress_threads, &err);
  1108. break;
  1109. case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD:
  1110. p->has_throttle_trigger_threshold = true;
  1111. visit_type_int(v, param, &p->throttle_trigger_threshold, &err);
  1112. break;
  1113. case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
  1114. p->has_cpu_throttle_initial = true;
  1115. visit_type_int(v, param, &p->cpu_throttle_initial, &err);
  1116. break;
  1117. case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
  1118. p->has_cpu_throttle_increment = true;
  1119. visit_type_int(v, param, &p->cpu_throttle_increment, &err);
  1120. break;
  1121. case MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW:
  1122. p->has_cpu_throttle_tailslow = true;
  1123. visit_type_bool(v, param, &p->cpu_throttle_tailslow, &err);
  1124. break;
  1125. case MIGRATION_PARAMETER_MAX_CPU_THROTTLE:
  1126. p->has_max_cpu_throttle = true;
  1127. visit_type_int(v, param, &p->max_cpu_throttle, &err);
  1128. break;
  1129. case MIGRATION_PARAMETER_TLS_CREDS:
  1130. p->has_tls_creds = true;
  1131. p->tls_creds = g_new0(StrOrNull, 1);
  1132. p->tls_creds->type = QTYPE_QSTRING;
  1133. visit_type_str(v, param, &p->tls_creds->u.s, &err);
  1134. break;
  1135. case MIGRATION_PARAMETER_TLS_HOSTNAME:
  1136. p->has_tls_hostname = true;
  1137. p->tls_hostname = g_new0(StrOrNull, 1);
  1138. p->tls_hostname->type = QTYPE_QSTRING;
  1139. visit_type_str(v, param, &p->tls_hostname->u.s, &err);
  1140. break;
  1141. case MIGRATION_PARAMETER_TLS_AUTHZ:
  1142. p->has_tls_authz = true;
  1143. p->tls_authz = g_new0(StrOrNull, 1);
  1144. p->tls_authz->type = QTYPE_QSTRING;
  1145. visit_type_str(v, param, &p->tls_authz->u.s, &err);
  1146. break;
  1147. case MIGRATION_PARAMETER_MAX_BANDWIDTH:
  1148. p->has_max_bandwidth = true;
  1149. /*
  1150. * Can't use visit_type_size() here, because it
  1151. * defaults to Bytes rather than Mebibytes.
  1152. */
  1153. ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
  1154. if (ret < 0 || valuebw > INT64_MAX
  1155. || (size_t)valuebw != valuebw) {
  1156. error_setg(&err, "Invalid size %s", valuestr);
  1157. break;
  1158. }
  1159. p->max_bandwidth = valuebw;
  1160. break;
  1161. case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
  1162. p->has_downtime_limit = true;
  1163. visit_type_int(v, param, &p->downtime_limit, &err);
  1164. break;
  1165. case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
  1166. p->has_x_checkpoint_delay = true;
  1167. visit_type_int(v, param, &p->x_checkpoint_delay, &err);
  1168. break;
  1169. case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
  1170. p->has_block_incremental = true;
  1171. visit_type_bool(v, param, &p->block_incremental, &err);
  1172. break;
  1173. case MIGRATION_PARAMETER_MULTIFD_CHANNELS:
  1174. p->has_multifd_channels = true;
  1175. visit_type_int(v, param, &p->multifd_channels, &err);
  1176. break;
  1177. case MIGRATION_PARAMETER_MULTIFD_COMPRESSION:
  1178. p->has_multifd_compression = true;
  1179. visit_type_MultiFDCompression(v, param, &p->multifd_compression,
  1180. &err);
  1181. break;
  1182. case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL:
  1183. p->has_multifd_zlib_level = true;
  1184. visit_type_int(v, param, &p->multifd_zlib_level, &err);
  1185. break;
  1186. case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL:
  1187. p->has_multifd_zstd_level = true;
  1188. visit_type_int(v, param, &p->multifd_zstd_level, &err);
  1189. break;
  1190. case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
  1191. p->has_xbzrle_cache_size = true;
  1192. if (!visit_type_size(v, param, &cache_size, &err)) {
  1193. break;
  1194. }
  1195. if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) {
  1196. error_setg(&err, "Invalid size %s", valuestr);
  1197. break;
  1198. }
  1199. p->xbzrle_cache_size = cache_size;
  1200. break;
  1201. case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH:
  1202. p->has_max_postcopy_bandwidth = true;
  1203. visit_type_size(v, param, &p->max_postcopy_bandwidth, &err);
  1204. break;
  1205. case MIGRATION_PARAMETER_ANNOUNCE_INITIAL:
  1206. p->has_announce_initial = true;
  1207. visit_type_size(v, param, &p->announce_initial, &err);
  1208. break;
  1209. case MIGRATION_PARAMETER_ANNOUNCE_MAX:
  1210. p->has_announce_max = true;
  1211. visit_type_size(v, param, &p->announce_max, &err);
  1212. break;
  1213. case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS:
  1214. p->has_announce_rounds = true;
  1215. visit_type_size(v, param, &p->announce_rounds, &err);
  1216. break;
  1217. case MIGRATION_PARAMETER_ANNOUNCE_STEP:
  1218. p->has_announce_step = true;
  1219. visit_type_size(v, param, &p->announce_step, &err);
  1220. break;
  1221. case MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING:
  1222. error_setg(&err, "The block-bitmap-mapping parameter can only be set "
  1223. "through QMP");
  1224. break;
  1225. default:
  1226. assert(0);
  1227. }
  1228. if (err) {
  1229. goto cleanup;
  1230. }
  1231. qmp_migrate_set_parameters(p, &err);
  1232. cleanup:
  1233. qapi_free_MigrateSetParameters(p);
  1234. visit_free(v);
  1235. hmp_handle_error(mon, err);
  1236. }
  1237. void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
  1238. {
  1239. Error *err = NULL;
  1240. const char *protocol = qdict_get_str(qdict, "protocol");
  1241. const char *hostname = qdict_get_str(qdict, "hostname");
  1242. bool has_port = qdict_haskey(qdict, "port");
  1243. int port = qdict_get_try_int(qdict, "port", -1);
  1244. bool has_tls_port = qdict_haskey(qdict, "tls-port");
  1245. int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
  1246. const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
  1247. qmp_client_migrate_info(protocol, hostname,
  1248. has_port, port, has_tls_port, tls_port,
  1249. !!cert_subject, cert_subject, &err);
  1250. hmp_handle_error(mon, err);
  1251. }
  1252. void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
  1253. {
  1254. Error *err = NULL;
  1255. qmp_migrate_start_postcopy(&err);
  1256. hmp_handle_error(mon, err);
  1257. }
  1258. void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
  1259. {
  1260. Error *err = NULL;
  1261. qmp_x_colo_lost_heartbeat(&err);
  1262. hmp_handle_error(mon, err);
  1263. }
  1264. void hmp_set_password(Monitor *mon, const QDict *qdict)
  1265. {
  1266. const char *protocol = qdict_get_str(qdict, "protocol");
  1267. const char *password = qdict_get_str(qdict, "password");
  1268. const char *connected = qdict_get_try_str(qdict, "connected");
  1269. Error *err = NULL;
  1270. qmp_set_password(protocol, password, !!connected, connected, &err);
  1271. hmp_handle_error(mon, err);
  1272. }
  1273. void hmp_expire_password(Monitor *mon, const QDict *qdict)
  1274. {
  1275. const char *protocol = qdict_get_str(qdict, "protocol");
  1276. const char *whenstr = qdict_get_str(qdict, "time");
  1277. Error *err = NULL;
  1278. qmp_expire_password(protocol, whenstr, &err);
  1279. hmp_handle_error(mon, err);
  1280. }
  1281. #ifdef CONFIG_VNC
  1282. static void hmp_change_read_arg(void *opaque, const char *password,
  1283. void *readline_opaque)
  1284. {
  1285. qmp_change_vnc_password(password, NULL);
  1286. monitor_read_command(opaque, 1);
  1287. }
  1288. #endif
  1289. void hmp_change(Monitor *mon, const QDict *qdict)
  1290. {
  1291. const char *device = qdict_get_str(qdict, "device");
  1292. const char *target = qdict_get_str(qdict, "target");
  1293. const char *arg = qdict_get_try_str(qdict, "arg");
  1294. const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
  1295. BlockdevChangeReadOnlyMode read_only_mode = 0;
  1296. Error *err = NULL;
  1297. #ifdef CONFIG_VNC
  1298. if (strcmp(device, "vnc") == 0) {
  1299. if (read_only) {
  1300. monitor_printf(mon,
  1301. "Parameter 'read-only-mode' is invalid for VNC\n");
  1302. return;
  1303. }
  1304. if (strcmp(target, "passwd") == 0 ||
  1305. strcmp(target, "password") == 0) {
  1306. if (!arg) {
  1307. MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
  1308. monitor_read_password(hmp_mon, hmp_change_read_arg, NULL);
  1309. return;
  1310. }
  1311. }
  1312. qmp_change("vnc", target, !!arg, arg, &err);
  1313. } else
  1314. #endif
  1315. {
  1316. if (read_only) {
  1317. read_only_mode =
  1318. qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
  1319. read_only,
  1320. BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
  1321. if (err) {
  1322. goto end;
  1323. }
  1324. }
  1325. qmp_blockdev_change_medium(true, device, false, NULL, target,
  1326. !!arg, arg, !!read_only, read_only_mode,
  1327. &err);
  1328. }
  1329. end:
  1330. hmp_handle_error(mon, err);
  1331. }
  1332. typedef struct HMPMigrationStatus
  1333. {
  1334. QEMUTimer *timer;
  1335. Monitor *mon;
  1336. bool is_block_migration;
  1337. } HMPMigrationStatus;
  1338. static void hmp_migrate_status_cb(void *opaque)
  1339. {
  1340. HMPMigrationStatus *status = opaque;
  1341. MigrationInfo *info;
  1342. info = qmp_query_migrate(NULL);
  1343. if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
  1344. info->status == MIGRATION_STATUS_SETUP) {
  1345. if (info->has_disk) {
  1346. int progress;
  1347. if (info->disk->remaining) {
  1348. progress = info->disk->transferred * 100 / info->disk->total;
  1349. } else {
  1350. progress = 100;
  1351. }
  1352. monitor_printf(status->mon, "Completed %d %%\r", progress);
  1353. monitor_flush(status->mon);
  1354. }
  1355. timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
  1356. } else {
  1357. if (status->is_block_migration) {
  1358. monitor_printf(status->mon, "\n");
  1359. }
  1360. if (info->has_error_desc) {
  1361. error_report("%s", info->error_desc);
  1362. }
  1363. monitor_resume(status->mon);
  1364. timer_del(status->timer);
  1365. timer_free(status->timer);
  1366. g_free(status);
  1367. }
  1368. qapi_free_MigrationInfo(info);
  1369. }
  1370. void hmp_migrate(Monitor *mon, const QDict *qdict)
  1371. {
  1372. bool detach = qdict_get_try_bool(qdict, "detach", false);
  1373. bool blk = qdict_get_try_bool(qdict, "blk", false);
  1374. bool inc = qdict_get_try_bool(qdict, "inc", false);
  1375. bool resume = qdict_get_try_bool(qdict, "resume", false);
  1376. const char *uri = qdict_get_str(qdict, "uri");
  1377. Error *err = NULL;
  1378. qmp_migrate(uri, !!blk, blk, !!inc, inc,
  1379. false, false, true, resume, &err);
  1380. if (err) {
  1381. hmp_handle_error(mon, err);
  1382. return;
  1383. }
  1384. if (!detach) {
  1385. HMPMigrationStatus *status;
  1386. if (monitor_suspend(mon) < 0) {
  1387. monitor_printf(mon, "terminal does not allow synchronous "
  1388. "migration, continuing detached\n");
  1389. return;
  1390. }
  1391. status = g_malloc0(sizeof(*status));
  1392. status->mon = mon;
  1393. status->is_block_migration = blk || inc;
  1394. status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
  1395. status);
  1396. timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
  1397. }
  1398. }
  1399. void hmp_netdev_add(Monitor *mon, const QDict *qdict)
  1400. {
  1401. Error *err = NULL;
  1402. QemuOpts *opts;
  1403. opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
  1404. if (err) {
  1405. goto out;
  1406. }
  1407. netdev_add(opts, &err);
  1408. if (err) {
  1409. qemu_opts_del(opts);
  1410. }
  1411. out:
  1412. hmp_handle_error(mon, err);
  1413. }
  1414. void hmp_netdev_del(Monitor *mon, const QDict *qdict)
  1415. {
  1416. const char *id = qdict_get_str(qdict, "id");
  1417. Error *err = NULL;
  1418. qmp_netdev_del(id, &err);
  1419. hmp_handle_error(mon, err);
  1420. }
  1421. void hmp_object_add(Monitor *mon, const QDict *qdict)
  1422. {
  1423. Error *err = NULL;
  1424. QemuOpts *opts;
  1425. Object *obj = NULL;
  1426. opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
  1427. if (err) {
  1428. goto end;
  1429. }
  1430. obj = user_creatable_add_opts(opts, &err);
  1431. qemu_opts_del(opts);
  1432. end:
  1433. hmp_handle_error(mon, err);
  1434. if (obj) {
  1435. object_unref(obj);
  1436. }
  1437. }
  1438. void hmp_getfd(Monitor *mon, const QDict *qdict)
  1439. {
  1440. const char *fdname = qdict_get_str(qdict, "fdname");
  1441. Error *err = NULL;
  1442. qmp_getfd(fdname, &err);
  1443. hmp_handle_error(mon, err);
  1444. }
  1445. void hmp_closefd(Monitor *mon, const QDict *qdict)
  1446. {
  1447. const char *fdname = qdict_get_str(qdict, "fdname");
  1448. Error *err = NULL;
  1449. qmp_closefd(fdname, &err);
  1450. hmp_handle_error(mon, err);
  1451. }
  1452. void hmp_sendkey(Monitor *mon, const QDict *qdict)
  1453. {
  1454. const char *keys = qdict_get_str(qdict, "keys");
  1455. KeyValueList *keylist, *head = NULL, *tmp = NULL;
  1456. int has_hold_time = qdict_haskey(qdict, "hold-time");
  1457. int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
  1458. Error *err = NULL;
  1459. const char *separator;
  1460. int keyname_len;
  1461. while (1) {
  1462. separator = qemu_strchrnul(keys, '-');
  1463. keyname_len = separator - keys;
  1464. /* Be compatible with old interface, convert user inputted "<" */
  1465. if (keys[0] == '<' && keyname_len == 1) {
  1466. keys = "less";
  1467. keyname_len = 4;
  1468. }
  1469. keylist = g_malloc0(sizeof(*keylist));
  1470. keylist->value = g_malloc0(sizeof(*keylist->value));
  1471. if (!head) {
  1472. head = keylist;
  1473. }
  1474. if (tmp) {
  1475. tmp->next = keylist;
  1476. }
  1477. tmp = keylist;
  1478. if (strstart(keys, "0x", NULL)) {
  1479. char *endp;
  1480. int value = strtoul(keys, &endp, 0);
  1481. assert(endp <= keys + keyname_len);
  1482. if (endp != keys + keyname_len) {
  1483. goto err_out;
  1484. }
  1485. keylist->value->type = KEY_VALUE_KIND_NUMBER;
  1486. keylist->value->u.number.data = value;
  1487. } else {
  1488. int idx = index_from_key(keys, keyname_len);
  1489. if (idx == Q_KEY_CODE__MAX) {
  1490. goto err_out;
  1491. }
  1492. keylist->value->type = KEY_VALUE_KIND_QCODE;
  1493. keylist->value->u.qcode.data = idx;
  1494. }
  1495. if (!*separator) {
  1496. break;
  1497. }
  1498. keys = separator + 1;
  1499. }
  1500. qmp_send_key(head, has_hold_time, hold_time, &err);
  1501. hmp_handle_error(mon, err);
  1502. out:
  1503. qapi_free_KeyValueList(head);
  1504. return;
  1505. err_out:
  1506. monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
  1507. goto out;
  1508. }
  1509. void hmp_screendump(Monitor *mon, const QDict *qdict)
  1510. {
  1511. const char *filename = qdict_get_str(qdict, "filename");
  1512. const char *id = qdict_get_try_str(qdict, "device");
  1513. int64_t head = qdict_get_try_int(qdict, "head", 0);
  1514. Error *err = NULL;
  1515. qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
  1516. hmp_handle_error(mon, err);
  1517. }
  1518. void hmp_chardev_add(Monitor *mon, const QDict *qdict)
  1519. {
  1520. const char *args = qdict_get_str(qdict, "args");
  1521. Error *err = NULL;
  1522. QemuOpts *opts;
  1523. opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
  1524. if (opts == NULL) {
  1525. error_setg(&err, "Parsing chardev args failed");
  1526. } else {
  1527. qemu_chr_new_from_opts(opts, NULL, &err);
  1528. qemu_opts_del(opts);
  1529. }
  1530. hmp_handle_error(mon, err);
  1531. }
  1532. void hmp_chardev_change(Monitor *mon, const QDict *qdict)
  1533. {
  1534. const char *args = qdict_get_str(qdict, "args");
  1535. const char *id;
  1536. Error *err = NULL;
  1537. ChardevBackend *backend = NULL;
  1538. ChardevReturn *ret = NULL;
  1539. QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
  1540. true);
  1541. if (!opts) {
  1542. error_setg(&err, "Parsing chardev args failed");
  1543. goto end;
  1544. }
  1545. id = qdict_get_str(qdict, "id");
  1546. if (qemu_opts_id(opts)) {
  1547. error_setg(&err, "Unexpected 'id' parameter");
  1548. goto end;
  1549. }
  1550. backend = qemu_chr_parse_opts(opts, &err);
  1551. if (!backend) {
  1552. goto end;
  1553. }
  1554. ret = qmp_chardev_change(id, backend, &err);
  1555. end:
  1556. qapi_free_ChardevReturn(ret);
  1557. qapi_free_ChardevBackend(backend);
  1558. qemu_opts_del(opts);
  1559. hmp_handle_error(mon, err);
  1560. }
  1561. void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
  1562. {
  1563. Error *local_err = NULL;
  1564. qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
  1565. hmp_handle_error(mon, local_err);
  1566. }
  1567. void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
  1568. {
  1569. Error *local_err = NULL;
  1570. qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
  1571. hmp_handle_error(mon, local_err);
  1572. }
  1573. void hmp_object_del(Monitor *mon, const QDict *qdict)
  1574. {
  1575. const char *id = qdict_get_str(qdict, "id");
  1576. Error *err = NULL;
  1577. user_creatable_del(id, &err);
  1578. hmp_handle_error(mon, err);
  1579. }
  1580. void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
  1581. {
  1582. Error *err = NULL;
  1583. MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
  1584. MemoryDeviceInfoList *info;
  1585. VirtioPMEMDeviceInfo *vpi;
  1586. VirtioMEMDeviceInfo *vmi;
  1587. MemoryDeviceInfo *value;
  1588. PCDIMMDeviceInfo *di;
  1589. for (info = info_list; info; info = info->next) {
  1590. value = info->value;
  1591. if (value) {
  1592. switch (value->type) {
  1593. case MEMORY_DEVICE_INFO_KIND_DIMM:
  1594. case MEMORY_DEVICE_INFO_KIND_NVDIMM:
  1595. di = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ?
  1596. value->u.dimm.data : value->u.nvdimm.data;
  1597. monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
  1598. MemoryDeviceInfoKind_str(value->type),
  1599. di->id ? di->id : "");
  1600. monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
  1601. monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
  1602. monitor_printf(mon, " node: %" PRId64 "\n", di->node);
  1603. monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
  1604. monitor_printf(mon, " memdev: %s\n", di->memdev);
  1605. monitor_printf(mon, " hotplugged: %s\n",
  1606. di->hotplugged ? "true" : "false");
  1607. monitor_printf(mon, " hotpluggable: %s\n",
  1608. di->hotpluggable ? "true" : "false");
  1609. break;
  1610. case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM:
  1611. vpi = value->u.virtio_pmem.data;
  1612. monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
  1613. MemoryDeviceInfoKind_str(value->type),
  1614. vpi->id ? vpi->id : "");
  1615. monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->memaddr);
  1616. monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size);
  1617. monitor_printf(mon, " memdev: %s\n", vpi->memdev);
  1618. break;
  1619. case MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM:
  1620. vmi = value->u.virtio_mem.data;
  1621. monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
  1622. MemoryDeviceInfoKind_str(value->type),
  1623. vmi->id ? vmi->id : "");
  1624. monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vmi->memaddr);
  1625. monitor_printf(mon, " node: %" PRId64 "\n", vmi->node);
  1626. monitor_printf(mon, " requested-size: %" PRIu64 "\n",
  1627. vmi->requested_size);
  1628. monitor_printf(mon, " size: %" PRIu64 "\n", vmi->size);
  1629. monitor_printf(mon, " max-size: %" PRIu64 "\n", vmi->max_size);
  1630. monitor_printf(mon, " block-size: %" PRIu64 "\n",
  1631. vmi->block_size);
  1632. monitor_printf(mon, " memdev: %s\n", vmi->memdev);
  1633. break;
  1634. default:
  1635. g_assert_not_reached();
  1636. }
  1637. }
  1638. }
  1639. qapi_free_MemoryDeviceInfoList(info_list);
  1640. hmp_handle_error(mon, err);
  1641. }
  1642. void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
  1643. {
  1644. IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
  1645. IOThreadInfoList *info;
  1646. IOThreadInfo *value;
  1647. for (info = info_list; info; info = info->next) {
  1648. value = info->value;
  1649. monitor_printf(mon, "%s:\n", value->id);
  1650. monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
  1651. monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
  1652. monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
  1653. monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
  1654. }
  1655. qapi_free_IOThreadInfoList(info_list);
  1656. }
  1657. void hmp_rocker(Monitor *mon, const QDict *qdict)
  1658. {
  1659. const char *name = qdict_get_str(qdict, "name");
  1660. RockerSwitch *rocker;
  1661. Error *err = NULL;
  1662. rocker = qmp_query_rocker(name, &err);
  1663. if (err != NULL) {
  1664. hmp_handle_error(mon, err);
  1665. return;
  1666. }
  1667. monitor_printf(mon, "name: %s\n", rocker->name);
  1668. monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
  1669. monitor_printf(mon, "ports: %d\n", rocker->ports);
  1670. qapi_free_RockerSwitch(rocker);
  1671. }
  1672. void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
  1673. {
  1674. RockerPortList *list, *port;
  1675. const char *name = qdict_get_str(qdict, "name");
  1676. Error *err = NULL;
  1677. list = qmp_query_rocker_ports(name, &err);
  1678. if (err != NULL) {
  1679. hmp_handle_error(mon, err);
  1680. return;
  1681. }
  1682. monitor_printf(mon, " ena/ speed/ auto\n");
  1683. monitor_printf(mon, " port link duplex neg?\n");
  1684. for (port = list; port; port = port->next) {
  1685. monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
  1686. port->value->name,
  1687. port->value->enabled ? port->value->link_up ?
  1688. "up" : "down" : "!ena",
  1689. port->value->speed == 10000 ? "10G" : "??",
  1690. port->value->duplex ? "FD" : "HD",
  1691. port->value->autoneg ? "Yes" : "No");
  1692. }
  1693. qapi_free_RockerPortList(list);
  1694. }
  1695. void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
  1696. {
  1697. RockerOfDpaFlowList *list, *info;
  1698. const char *name = qdict_get_str(qdict, "name");
  1699. uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
  1700. Error *err = NULL;
  1701. list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
  1702. if (err != NULL) {
  1703. hmp_handle_error(mon, err);
  1704. return;
  1705. }
  1706. monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
  1707. for (info = list; info; info = info->next) {
  1708. RockerOfDpaFlow *flow = info->value;
  1709. RockerOfDpaFlowKey *key = flow->key;
  1710. RockerOfDpaFlowMask *mask = flow->mask;
  1711. RockerOfDpaFlowAction *action = flow->action;
  1712. if (flow->hits) {
  1713. monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
  1714. key->priority, key->tbl_id, flow->hits);
  1715. } else {
  1716. monitor_printf(mon, "%-4d %-3d ",
  1717. key->priority, key->tbl_id);
  1718. }
  1719. if (key->has_in_pport) {
  1720. monitor_printf(mon, " pport %d", key->in_pport);
  1721. if (mask->has_in_pport) {
  1722. monitor_printf(mon, "(0x%x)", mask->in_pport);
  1723. }
  1724. }
  1725. if (key->has_vlan_id) {
  1726. monitor_printf(mon, " vlan %d",
  1727. key->vlan_id & VLAN_VID_MASK);
  1728. if (mask->has_vlan_id) {
  1729. monitor_printf(mon, "(0x%x)", mask->vlan_id);
  1730. }
  1731. }
  1732. if (key->has_tunnel_id) {
  1733. monitor_printf(mon, " tunnel %d", key->tunnel_id);
  1734. if (mask->has_tunnel_id) {
  1735. monitor_printf(mon, "(0x%x)", mask->tunnel_id);
  1736. }
  1737. }
  1738. if (key->has_eth_type) {
  1739. switch (key->eth_type) {
  1740. case 0x0806:
  1741. monitor_printf(mon, " ARP");
  1742. break;
  1743. case 0x0800:
  1744. monitor_printf(mon, " IP");
  1745. break;
  1746. case 0x86dd:
  1747. monitor_printf(mon, " IPv6");
  1748. break;
  1749. case 0x8809:
  1750. monitor_printf(mon, " LACP");
  1751. break;
  1752. case 0x88cc:
  1753. monitor_printf(mon, " LLDP");
  1754. break;
  1755. default:
  1756. monitor_printf(mon, " eth type 0x%04x", key->eth_type);
  1757. break;
  1758. }
  1759. }
  1760. if (key->has_eth_src) {
  1761. if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
  1762. (mask->has_eth_src) &&
  1763. (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
  1764. monitor_printf(mon, " src <any mcast/bcast>");
  1765. } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
  1766. (mask->has_eth_src) &&
  1767. (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
  1768. monitor_printf(mon, " src <any ucast>");
  1769. } else {
  1770. monitor_printf(mon, " src %s", key->eth_src);
  1771. if (mask->has_eth_src) {
  1772. monitor_printf(mon, "(%s)", mask->eth_src);
  1773. }
  1774. }
  1775. }
  1776. if (key->has_eth_dst) {
  1777. if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
  1778. (mask->has_eth_dst) &&
  1779. (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
  1780. monitor_printf(mon, " dst <any mcast/bcast>");
  1781. } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
  1782. (mask->has_eth_dst) &&
  1783. (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
  1784. monitor_printf(mon, " dst <any ucast>");
  1785. } else {
  1786. monitor_printf(mon, " dst %s", key->eth_dst);
  1787. if (mask->has_eth_dst) {
  1788. monitor_printf(mon, "(%s)", mask->eth_dst);
  1789. }
  1790. }
  1791. }
  1792. if (key->has_ip_proto) {
  1793. monitor_printf(mon, " proto %d", key->ip_proto);
  1794. if (mask->has_ip_proto) {
  1795. monitor_printf(mon, "(0x%x)", mask->ip_proto);
  1796. }
  1797. }
  1798. if (key->has_ip_tos) {
  1799. monitor_printf(mon, " TOS %d", key->ip_tos);
  1800. if (mask->has_ip_tos) {
  1801. monitor_printf(mon, "(0x%x)", mask->ip_tos);
  1802. }
  1803. }
  1804. if (key->has_ip_dst) {
  1805. monitor_printf(mon, " dst %s", key->ip_dst);
  1806. }
  1807. if (action->has_goto_tbl || action->has_group_id ||
  1808. action->has_new_vlan_id) {
  1809. monitor_printf(mon, " -->");
  1810. }
  1811. if (action->has_new_vlan_id) {
  1812. monitor_printf(mon, " apply new vlan %d",
  1813. ntohs(action->new_vlan_id));
  1814. }
  1815. if (action->has_group_id) {
  1816. monitor_printf(mon, " write group 0x%08x", action->group_id);
  1817. }
  1818. if (action->has_goto_tbl) {
  1819. monitor_printf(mon, " goto tbl %d", action->goto_tbl);
  1820. }
  1821. monitor_printf(mon, "\n");
  1822. }
  1823. qapi_free_RockerOfDpaFlowList(list);
  1824. }
  1825. void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
  1826. {
  1827. RockerOfDpaGroupList *list, *g;
  1828. const char *name = qdict_get_str(qdict, "name");
  1829. uint8_t type = qdict_get_try_int(qdict, "type", 9);
  1830. Error *err = NULL;
  1831. list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
  1832. if (err != NULL) {
  1833. hmp_handle_error(mon, err);
  1834. return;
  1835. }
  1836. monitor_printf(mon, "id (decode) --> buckets\n");
  1837. for (g = list; g; g = g->next) {
  1838. RockerOfDpaGroup *group = g->value;
  1839. bool set = false;
  1840. monitor_printf(mon, "0x%08x", group->id);
  1841. monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
  1842. group->type == 1 ? "L2 rewrite" :
  1843. group->type == 2 ? "L3 unicast" :
  1844. group->type == 3 ? "L2 multicast" :
  1845. group->type == 4 ? "L2 flood" :
  1846. group->type == 5 ? "L3 interface" :
  1847. group->type == 6 ? "L3 multicast" :
  1848. group->type == 7 ? "L3 ECMP" :
  1849. group->type == 8 ? "L2 overlay" :
  1850. "unknown");
  1851. if (group->has_vlan_id) {
  1852. monitor_printf(mon, " vlan %d", group->vlan_id);
  1853. }
  1854. if (group->has_pport) {
  1855. monitor_printf(mon, " pport %d", group->pport);
  1856. }
  1857. if (group->has_index) {
  1858. monitor_printf(mon, " index %d", group->index);
  1859. }
  1860. monitor_printf(mon, ") -->");
  1861. if (group->has_set_vlan_id && group->set_vlan_id) {
  1862. set = true;
  1863. monitor_printf(mon, " set vlan %d",
  1864. group->set_vlan_id & VLAN_VID_MASK);
  1865. }
  1866. if (group->has_set_eth_src) {
  1867. if (!set) {
  1868. set = true;
  1869. monitor_printf(mon, " set");
  1870. }
  1871. monitor_printf(mon, " src %s", group->set_eth_src);
  1872. }
  1873. if (group->has_set_eth_dst) {
  1874. if (!set) {
  1875. monitor_printf(mon, " set");
  1876. }
  1877. monitor_printf(mon, " dst %s", group->set_eth_dst);
  1878. }
  1879. if (group->has_ttl_check && group->ttl_check) {
  1880. monitor_printf(mon, " check TTL");
  1881. }
  1882. if (group->has_group_id && group->group_id) {
  1883. monitor_printf(mon, " group id 0x%08x", group->group_id);
  1884. }
  1885. if (group->has_pop_vlan && group->pop_vlan) {
  1886. monitor_printf(mon, " pop vlan");
  1887. }
  1888. if (group->has_out_pport) {
  1889. monitor_printf(mon, " out pport %d", group->out_pport);
  1890. }
  1891. if (group->has_group_ids) {
  1892. struct uint32List *id;
  1893. monitor_printf(mon, " groups [");
  1894. for (id = group->group_ids; id; id = id->next) {
  1895. monitor_printf(mon, "0x%08x", id->value);
  1896. if (id->next) {
  1897. monitor_printf(mon, ",");
  1898. }
  1899. }
  1900. monitor_printf(mon, "]");
  1901. }
  1902. monitor_printf(mon, "\n");
  1903. }
  1904. qapi_free_RockerOfDpaGroupList(list);
  1905. }
  1906. void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
  1907. {
  1908. ram_block_dump(mon);
  1909. }
  1910. void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
  1911. {
  1912. Error *err = NULL;
  1913. GuidInfo *info = qmp_query_vm_generation_id(&err);
  1914. if (info) {
  1915. monitor_printf(mon, "%s\n", info->guid);
  1916. }
  1917. hmp_handle_error(mon, err);
  1918. qapi_free_GuidInfo(info);
  1919. }
  1920. void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
  1921. {
  1922. Error *err = NULL;
  1923. MemoryInfo *info = qmp_query_memory_size_summary(&err);
  1924. if (info) {
  1925. monitor_printf(mon, "base memory: %" PRIu64 "\n",
  1926. info->base_memory);
  1927. if (info->has_plugged_memory) {
  1928. monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
  1929. info->plugged_memory);
  1930. }
  1931. qapi_free_MemoryInfo(info);
  1932. }
  1933. hmp_handle_error(mon, err);
  1934. }