hmp-cmds.c 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764
  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 "qemu/help_option.h"
  27. #include "monitor/monitor-internal.h"
  28. #include "qapi/error.h"
  29. #include "qapi/clone-visitor.h"
  30. #include "qapi/opts-visitor.h"
  31. #include "qapi/qapi-builtin-visit.h"
  32. #include "qapi/qapi-commands-block.h"
  33. #include "qapi/qapi-commands-char.h"
  34. #include "qapi/qapi-commands-control.h"
  35. #include "qapi/qapi-commands-machine.h"
  36. #include "qapi/qapi-commands-migration.h"
  37. #include "qapi/qapi-commands-misc.h"
  38. #include "qapi/qapi-commands-net.h"
  39. #include "qapi/qapi-commands-pci.h"
  40. #include "qapi/qapi-commands-rocker.h"
  41. #include "qapi/qapi-commands-run-state.h"
  42. #include "qapi/qapi-commands-stats.h"
  43. #include "qapi/qapi-commands-tpm.h"
  44. #include "qapi/qapi-commands-ui.h"
  45. #include "qapi/qapi-commands-virtio.h"
  46. #include "qapi/qapi-visit-virtio.h"
  47. #include "qapi/qapi-visit-net.h"
  48. #include "qapi/qapi-visit-migration.h"
  49. #include "qapi/qmp/qdict.h"
  50. #include "qapi/qmp/qerror.h"
  51. #include "qapi/string-input-visitor.h"
  52. #include "qapi/string-output-visitor.h"
  53. #include "qom/object_interfaces.h"
  54. #include "ui/console.h"
  55. #include "qemu/cutils.h"
  56. #include "qemu/error-report.h"
  57. #include "hw/core/cpu.h"
  58. #include "hw/intc/intc.h"
  59. #include "migration/snapshot.h"
  60. #include "migration/misc.h"
  61. #ifdef CONFIG_SPICE
  62. #include <spice/enums.h>
  63. #endif
  64. bool hmp_handle_error(Monitor *mon, Error *err)
  65. {
  66. if (err) {
  67. error_reportf_err(err, "Error: ");
  68. return true;
  69. }
  70. return false;
  71. }
  72. /*
  73. * Produce a strList from a comma separated list.
  74. * A NULL or empty input string return NULL.
  75. */
  76. static strList *strList_from_comma_list(const char *in)
  77. {
  78. strList *res = NULL;
  79. strList **tail = &res;
  80. while (in && in[0]) {
  81. char *comma = strchr(in, ',');
  82. char *value;
  83. if (comma) {
  84. value = g_strndup(in, comma - in);
  85. in = comma + 1; /* skip the , */
  86. } else {
  87. value = g_strdup(in);
  88. in = NULL;
  89. }
  90. QAPI_LIST_APPEND(tail, value);
  91. }
  92. return res;
  93. }
  94. void hmp_info_name(Monitor *mon, const QDict *qdict)
  95. {
  96. NameInfo *info;
  97. info = qmp_query_name(NULL);
  98. if (info->has_name) {
  99. monitor_printf(mon, "%s\n", info->name);
  100. }
  101. qapi_free_NameInfo(info);
  102. }
  103. void hmp_info_version(Monitor *mon, const QDict *qdict)
  104. {
  105. VersionInfo *info;
  106. info = qmp_query_version(NULL);
  107. monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
  108. info->qemu->major, info->qemu->minor, info->qemu->micro,
  109. info->package);
  110. qapi_free_VersionInfo(info);
  111. }
  112. void hmp_info_kvm(Monitor *mon, const QDict *qdict)
  113. {
  114. KvmInfo *info;
  115. info = qmp_query_kvm(NULL);
  116. monitor_printf(mon, "kvm support: ");
  117. if (info->present) {
  118. monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
  119. } else {
  120. monitor_printf(mon, "not compiled\n");
  121. }
  122. qapi_free_KvmInfo(info);
  123. }
  124. void hmp_info_status(Monitor *mon, const QDict *qdict)
  125. {
  126. StatusInfo *info;
  127. info = qmp_query_status(NULL);
  128. monitor_printf(mon, "VM status: %s%s",
  129. info->running ? "running" : "paused",
  130. info->singlestep ? " (single step mode)" : "");
  131. if (!info->running && info->status != RUN_STATE_PAUSED) {
  132. monitor_printf(mon, " (%s)", RunState_str(info->status));
  133. }
  134. monitor_printf(mon, "\n");
  135. qapi_free_StatusInfo(info);
  136. }
  137. void hmp_info_uuid(Monitor *mon, const QDict *qdict)
  138. {
  139. UuidInfo *info;
  140. info = qmp_query_uuid(NULL);
  141. monitor_printf(mon, "%s\n", info->UUID);
  142. qapi_free_UuidInfo(info);
  143. }
  144. void hmp_info_chardev(Monitor *mon, const QDict *qdict)
  145. {
  146. ChardevInfoList *char_info, *info;
  147. char_info = qmp_query_chardev(NULL);
  148. for (info = char_info; info; info = info->next) {
  149. monitor_printf(mon, "%s: filename=%s\n", info->value->label,
  150. info->value->filename);
  151. }
  152. qapi_free_ChardevInfoList(char_info);
  153. }
  154. void hmp_info_mice(Monitor *mon, const QDict *qdict)
  155. {
  156. MouseInfoList *mice_list, *mouse;
  157. mice_list = qmp_query_mice(NULL);
  158. if (!mice_list) {
  159. monitor_printf(mon, "No mouse devices connected\n");
  160. return;
  161. }
  162. for (mouse = mice_list; mouse; mouse = mouse->next) {
  163. monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
  164. mouse->value->current ? '*' : ' ',
  165. mouse->value->index, mouse->value->name,
  166. mouse->value->absolute ? " (absolute)" : "");
  167. }
  168. qapi_free_MouseInfoList(mice_list);
  169. }
  170. void hmp_info_migrate(Monitor *mon, const QDict *qdict)
  171. {
  172. MigrationInfo *info;
  173. info = qmp_query_migrate(NULL);
  174. migration_global_dump(mon);
  175. if (info->blocked_reasons) {
  176. strList *reasons = info->blocked_reasons;
  177. monitor_printf(mon, "Outgoing migration blocked:\n");
  178. while (reasons) {
  179. monitor_printf(mon, " %s\n", reasons->value);
  180. reasons = reasons->next;
  181. }
  182. }
  183. if (info->has_status) {
  184. monitor_printf(mon, "Migration status: %s",
  185. MigrationStatus_str(info->status));
  186. if (info->status == MIGRATION_STATUS_FAILED &&
  187. info->has_error_desc) {
  188. monitor_printf(mon, " (%s)\n", info->error_desc);
  189. } else {
  190. monitor_printf(mon, "\n");
  191. }
  192. monitor_printf(mon, "total time: %" PRIu64 " ms\n",
  193. info->total_time);
  194. if (info->has_expected_downtime) {
  195. monitor_printf(mon, "expected downtime: %" PRIu64 " ms\n",
  196. info->expected_downtime);
  197. }
  198. if (info->has_downtime) {
  199. monitor_printf(mon, "downtime: %" PRIu64 " ms\n",
  200. info->downtime);
  201. }
  202. if (info->has_setup_time) {
  203. monitor_printf(mon, "setup: %" PRIu64 " ms\n",
  204. info->setup_time);
  205. }
  206. }
  207. if (info->has_ram) {
  208. monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
  209. info->ram->transferred >> 10);
  210. monitor_printf(mon, "throughput: %0.2f mbps\n",
  211. info->ram->mbps);
  212. monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
  213. info->ram->remaining >> 10);
  214. monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
  215. info->ram->total >> 10);
  216. monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
  217. info->ram->duplicate);
  218. monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
  219. info->ram->skipped);
  220. monitor_printf(mon, "normal: %" PRIu64 " pages\n",
  221. info->ram->normal);
  222. monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
  223. info->ram->normal_bytes >> 10);
  224. monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
  225. info->ram->dirty_sync_count);
  226. monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
  227. info->ram->page_size >> 10);
  228. monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n",
  229. info->ram->multifd_bytes >> 10);
  230. monitor_printf(mon, "pages-per-second: %" PRIu64 "\n",
  231. info->ram->pages_per_second);
  232. if (info->ram->dirty_pages_rate) {
  233. monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
  234. info->ram->dirty_pages_rate);
  235. }
  236. if (info->ram->postcopy_requests) {
  237. monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
  238. info->ram->postcopy_requests);
  239. }
  240. if (info->ram->precopy_bytes) {
  241. monitor_printf(mon, "precopy ram: %" PRIu64 " kbytes\n",
  242. info->ram->precopy_bytes >> 10);
  243. }
  244. if (info->ram->downtime_bytes) {
  245. monitor_printf(mon, "downtime ram: %" PRIu64 " kbytes\n",
  246. info->ram->downtime_bytes >> 10);
  247. }
  248. if (info->ram->postcopy_bytes) {
  249. monitor_printf(mon, "postcopy ram: %" PRIu64 " kbytes\n",
  250. info->ram->postcopy_bytes >> 10);
  251. }
  252. if (info->ram->dirty_sync_missed_zero_copy) {
  253. monitor_printf(mon,
  254. "Zero-copy-send fallbacks happened: %" PRIu64 " times\n",
  255. info->ram->dirty_sync_missed_zero_copy);
  256. }
  257. }
  258. if (info->has_disk) {
  259. monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
  260. info->disk->transferred >> 10);
  261. monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
  262. info->disk->remaining >> 10);
  263. monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
  264. info->disk->total >> 10);
  265. }
  266. if (info->has_xbzrle_cache) {
  267. monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
  268. info->xbzrle_cache->cache_size);
  269. monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
  270. info->xbzrle_cache->bytes >> 10);
  271. monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
  272. info->xbzrle_cache->pages);
  273. monitor_printf(mon, "xbzrle cache miss: %" PRIu64 " pages\n",
  274. info->xbzrle_cache->cache_miss);
  275. monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
  276. info->xbzrle_cache->cache_miss_rate);
  277. monitor_printf(mon, "xbzrle encoding rate: %0.2f\n",
  278. info->xbzrle_cache->encoding_rate);
  279. monitor_printf(mon, "xbzrle overflow: %" PRIu64 "\n",
  280. info->xbzrle_cache->overflow);
  281. }
  282. if (info->has_compression) {
  283. monitor_printf(mon, "compression pages: %" PRIu64 " pages\n",
  284. info->compression->pages);
  285. monitor_printf(mon, "compression busy: %" PRIu64 "\n",
  286. info->compression->busy);
  287. monitor_printf(mon, "compression busy rate: %0.2f\n",
  288. info->compression->busy_rate);
  289. monitor_printf(mon, "compressed size: %" PRIu64 " kbytes\n",
  290. info->compression->compressed_size >> 10);
  291. monitor_printf(mon, "compression rate: %0.2f\n",
  292. info->compression->compression_rate);
  293. }
  294. if (info->has_cpu_throttle_percentage) {
  295. monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
  296. info->cpu_throttle_percentage);
  297. }
  298. if (info->has_postcopy_blocktime) {
  299. monitor_printf(mon, "postcopy blocktime: %u\n",
  300. info->postcopy_blocktime);
  301. }
  302. if (info->has_postcopy_vcpu_blocktime) {
  303. Visitor *v;
  304. char *str;
  305. v = string_output_visitor_new(false, &str);
  306. visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime,
  307. &error_abort);
  308. visit_complete(v, &str);
  309. monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
  310. g_free(str);
  311. visit_free(v);
  312. }
  313. if (info->has_socket_address) {
  314. SocketAddressList *addr;
  315. monitor_printf(mon, "socket address: [\n");
  316. for (addr = info->socket_address; addr; addr = addr->next) {
  317. char *s = socket_uri(addr->value);
  318. monitor_printf(mon, "\t%s\n", s);
  319. g_free(s);
  320. }
  321. monitor_printf(mon, "]\n");
  322. }
  323. if (info->has_vfio) {
  324. monitor_printf(mon, "vfio device transferred: %" PRIu64 " kbytes\n",
  325. info->vfio->transferred >> 10);
  326. }
  327. qapi_free_MigrationInfo(info);
  328. }
  329. void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
  330. {
  331. MigrationCapabilityStatusList *caps, *cap;
  332. caps = qmp_query_migrate_capabilities(NULL);
  333. if (caps) {
  334. for (cap = caps; cap; cap = cap->next) {
  335. monitor_printf(mon, "%s: %s\n",
  336. MigrationCapability_str(cap->value->capability),
  337. cap->value->state ? "on" : "off");
  338. }
  339. }
  340. qapi_free_MigrationCapabilityStatusList(caps);
  341. }
  342. void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
  343. {
  344. MigrationParameters *params;
  345. params = qmp_query_migrate_parameters(NULL);
  346. if (params) {
  347. monitor_printf(mon, "%s: %" PRIu64 " ms\n",
  348. MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL),
  349. params->announce_initial);
  350. monitor_printf(mon, "%s: %" PRIu64 " ms\n",
  351. MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX),
  352. params->announce_max);
  353. monitor_printf(mon, "%s: %" PRIu64 "\n",
  354. MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS),
  355. params->announce_rounds);
  356. monitor_printf(mon, "%s: %" PRIu64 " ms\n",
  357. MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP),
  358. params->announce_step);
  359. assert(params->has_compress_level);
  360. monitor_printf(mon, "%s: %u\n",
  361. MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
  362. params->compress_level);
  363. assert(params->has_compress_threads);
  364. monitor_printf(mon, "%s: %u\n",
  365. MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
  366. params->compress_threads);
  367. assert(params->has_compress_wait_thread);
  368. monitor_printf(mon, "%s: %s\n",
  369. MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD),
  370. params->compress_wait_thread ? "on" : "off");
  371. assert(params->has_decompress_threads);
  372. monitor_printf(mon, "%s: %u\n",
  373. MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
  374. params->decompress_threads);
  375. assert(params->has_throttle_trigger_threshold);
  376. monitor_printf(mon, "%s: %u\n",
  377. MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD),
  378. params->throttle_trigger_threshold);
  379. assert(params->has_cpu_throttle_initial);
  380. monitor_printf(mon, "%s: %u\n",
  381. MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
  382. params->cpu_throttle_initial);
  383. assert(params->has_cpu_throttle_increment);
  384. monitor_printf(mon, "%s: %u\n",
  385. MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
  386. params->cpu_throttle_increment);
  387. assert(params->has_cpu_throttle_tailslow);
  388. monitor_printf(mon, "%s: %s\n",
  389. MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW),
  390. params->cpu_throttle_tailslow ? "on" : "off");
  391. assert(params->has_max_cpu_throttle);
  392. monitor_printf(mon, "%s: %u\n",
  393. MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE),
  394. params->max_cpu_throttle);
  395. assert(params->has_tls_creds);
  396. monitor_printf(mon, "%s: '%s'\n",
  397. MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
  398. params->tls_creds);
  399. assert(params->has_tls_hostname);
  400. monitor_printf(mon, "%s: '%s'\n",
  401. MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
  402. params->tls_hostname);
  403. assert(params->has_max_bandwidth);
  404. monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
  405. MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
  406. params->max_bandwidth);
  407. assert(params->has_downtime_limit);
  408. monitor_printf(mon, "%s: %" PRIu64 " ms\n",
  409. MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
  410. params->downtime_limit);
  411. assert(params->has_x_checkpoint_delay);
  412. monitor_printf(mon, "%s: %u ms\n",
  413. MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
  414. params->x_checkpoint_delay);
  415. assert(params->has_block_incremental);
  416. monitor_printf(mon, "%s: %s\n",
  417. MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
  418. params->block_incremental ? "on" : "off");
  419. monitor_printf(mon, "%s: %u\n",
  420. MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS),
  421. params->multifd_channels);
  422. monitor_printf(mon, "%s: %s\n",
  423. MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION),
  424. MultiFDCompression_str(params->multifd_compression));
  425. monitor_printf(mon, "%s: %" PRIu64 " bytes\n",
  426. MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
  427. params->xbzrle_cache_size);
  428. monitor_printf(mon, "%s: %" PRIu64 "\n",
  429. MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
  430. params->max_postcopy_bandwidth);
  431. monitor_printf(mon, "%s: '%s'\n",
  432. MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
  433. params->tls_authz);
  434. if (params->has_block_bitmap_mapping) {
  435. const BitmapMigrationNodeAliasList *bmnal;
  436. monitor_printf(mon, "%s:\n",
  437. MigrationParameter_str(
  438. MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING));
  439. for (bmnal = params->block_bitmap_mapping;
  440. bmnal;
  441. bmnal = bmnal->next)
  442. {
  443. const BitmapMigrationNodeAlias *bmna = bmnal->value;
  444. const BitmapMigrationBitmapAliasList *bmbal;
  445. monitor_printf(mon, " '%s' -> '%s'\n",
  446. bmna->node_name, bmna->alias);
  447. for (bmbal = bmna->bitmaps; bmbal; bmbal = bmbal->next) {
  448. const BitmapMigrationBitmapAlias *bmba = bmbal->value;
  449. monitor_printf(mon, " '%s' -> '%s'\n",
  450. bmba->name, bmba->alias);
  451. }
  452. }
  453. }
  454. }
  455. qapi_free_MigrationParameters(params);
  456. }
  457. #ifdef CONFIG_VNC
  458. /* Helper for hmp_info_vnc_clients, _servers */
  459. static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
  460. const char *name)
  461. {
  462. monitor_printf(mon, " %s: %s:%s (%s%s)\n",
  463. name,
  464. info->host,
  465. info->service,
  466. NetworkAddressFamily_str(info->family),
  467. info->websocket ? " (Websocket)" : "");
  468. }
  469. /* Helper displaying and auth and crypt info */
  470. static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
  471. VncPrimaryAuth auth,
  472. VncVencryptSubAuth *vencrypt)
  473. {
  474. monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
  475. VncPrimaryAuth_str(auth),
  476. vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
  477. }
  478. static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
  479. {
  480. while (client) {
  481. VncClientInfo *cinfo = client->value;
  482. hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
  483. monitor_printf(mon, " x509_dname: %s\n",
  484. cinfo->has_x509_dname ?
  485. cinfo->x509_dname : "none");
  486. monitor_printf(mon, " sasl_username: %s\n",
  487. cinfo->has_sasl_username ?
  488. cinfo->sasl_username : "none");
  489. client = client->next;
  490. }
  491. }
  492. static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
  493. {
  494. while (server) {
  495. VncServerInfo2 *sinfo = server->value;
  496. hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
  497. hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
  498. sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
  499. server = server->next;
  500. }
  501. }
  502. void hmp_info_vnc(Monitor *mon, const QDict *qdict)
  503. {
  504. VncInfo2List *info2l, *info2l_head;
  505. Error *err = NULL;
  506. info2l = qmp_query_vnc_servers(&err);
  507. info2l_head = info2l;
  508. if (hmp_handle_error(mon, err)) {
  509. return;
  510. }
  511. if (!info2l) {
  512. monitor_printf(mon, "None\n");
  513. return;
  514. }
  515. while (info2l) {
  516. VncInfo2 *info = info2l->value;
  517. monitor_printf(mon, "%s:\n", info->id);
  518. hmp_info_vnc_servers(mon, info->server);
  519. hmp_info_vnc_clients(mon, info->clients);
  520. if (!info->server) {
  521. /* The server entry displays its auth, we only
  522. * need to display in the case of 'reverse' connections
  523. * where there's no server.
  524. */
  525. hmp_info_vnc_authcrypt(mon, " ", info->auth,
  526. info->has_vencrypt ? &info->vencrypt : NULL);
  527. }
  528. if (info->has_display) {
  529. monitor_printf(mon, " Display: %s\n", info->display);
  530. }
  531. info2l = info2l->next;
  532. }
  533. qapi_free_VncInfo2List(info2l_head);
  534. }
  535. #endif
  536. #ifdef CONFIG_SPICE
  537. void hmp_info_spice(Monitor *mon, const QDict *qdict)
  538. {
  539. SpiceChannelList *chan;
  540. SpiceInfo *info;
  541. const char *channel_name;
  542. const char * const channel_names[] = {
  543. [SPICE_CHANNEL_MAIN] = "main",
  544. [SPICE_CHANNEL_DISPLAY] = "display",
  545. [SPICE_CHANNEL_INPUTS] = "inputs",
  546. [SPICE_CHANNEL_CURSOR] = "cursor",
  547. [SPICE_CHANNEL_PLAYBACK] = "playback",
  548. [SPICE_CHANNEL_RECORD] = "record",
  549. [SPICE_CHANNEL_TUNNEL] = "tunnel",
  550. [SPICE_CHANNEL_SMARTCARD] = "smartcard",
  551. [SPICE_CHANNEL_USBREDIR] = "usbredir",
  552. [SPICE_CHANNEL_PORT] = "port",
  553. #if 0
  554. /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
  555. * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
  556. * as quick fix for build failures with older versions. */
  557. [SPICE_CHANNEL_WEBDAV] = "webdav",
  558. #endif
  559. };
  560. info = qmp_query_spice(NULL);
  561. if (!info->enabled) {
  562. monitor_printf(mon, "Server: disabled\n");
  563. goto out;
  564. }
  565. monitor_printf(mon, "Server:\n");
  566. if (info->has_port) {
  567. monitor_printf(mon, " address: %s:%" PRId64 "\n",
  568. info->host, info->port);
  569. }
  570. if (info->has_tls_port) {
  571. monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
  572. info->host, info->tls_port);
  573. }
  574. monitor_printf(mon, " migrated: %s\n",
  575. info->migrated ? "true" : "false");
  576. monitor_printf(mon, " auth: %s\n", info->auth);
  577. monitor_printf(mon, " compiled: %s\n", info->compiled_version);
  578. monitor_printf(mon, " mouse-mode: %s\n",
  579. SpiceQueryMouseMode_str(info->mouse_mode));
  580. if (!info->has_channels || info->channels == NULL) {
  581. monitor_printf(mon, "Channels: none\n");
  582. } else {
  583. for (chan = info->channels; chan; chan = chan->next) {
  584. monitor_printf(mon, "Channel:\n");
  585. monitor_printf(mon, " address: %s:%s%s\n",
  586. chan->value->host, chan->value->port,
  587. chan->value->tls ? " [tls]" : "");
  588. monitor_printf(mon, " session: %" PRId64 "\n",
  589. chan->value->connection_id);
  590. monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
  591. chan->value->channel_type, chan->value->channel_id);
  592. channel_name = "unknown";
  593. if (chan->value->channel_type > 0 &&
  594. chan->value->channel_type < ARRAY_SIZE(channel_names) &&
  595. channel_names[chan->value->channel_type]) {
  596. channel_name = channel_names[chan->value->channel_type];
  597. }
  598. monitor_printf(mon, " channel name: %s\n", channel_name);
  599. }
  600. }
  601. out:
  602. qapi_free_SpiceInfo(info);
  603. }
  604. #endif
  605. void hmp_info_balloon(Monitor *mon, const QDict *qdict)
  606. {
  607. BalloonInfo *info;
  608. Error *err = NULL;
  609. info = qmp_query_balloon(&err);
  610. if (hmp_handle_error(mon, err)) {
  611. return;
  612. }
  613. monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
  614. qapi_free_BalloonInfo(info);
  615. }
  616. static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
  617. {
  618. PciMemoryRegionList *region;
  619. monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
  620. monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
  621. dev->slot, dev->function);
  622. monitor_printf(mon, " ");
  623. if (dev->class_info->has_desc) {
  624. monitor_puts(mon, dev->class_info->desc);
  625. } else {
  626. monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
  627. }
  628. monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
  629. dev->id->vendor, dev->id->device);
  630. if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) {
  631. monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n",
  632. dev->id->subsystem_vendor, dev->id->subsystem);
  633. }
  634. if (dev->has_irq) {
  635. monitor_printf(mon, " IRQ %" PRId64 ", pin %c\n",
  636. dev->irq, (char)('A' + dev->irq_pin - 1));
  637. }
  638. if (dev->has_pci_bridge) {
  639. monitor_printf(mon, " BUS %" PRId64 ".\n",
  640. dev->pci_bridge->bus->number);
  641. monitor_printf(mon, " secondary bus %" PRId64 ".\n",
  642. dev->pci_bridge->bus->secondary);
  643. monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
  644. dev->pci_bridge->bus->subordinate);
  645. monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
  646. dev->pci_bridge->bus->io_range->base,
  647. dev->pci_bridge->bus->io_range->limit);
  648. monitor_printf(mon,
  649. " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
  650. dev->pci_bridge->bus->memory_range->base,
  651. dev->pci_bridge->bus->memory_range->limit);
  652. monitor_printf(mon, " prefetchable memory range "
  653. "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
  654. dev->pci_bridge->bus->prefetchable_range->base,
  655. dev->pci_bridge->bus->prefetchable_range->limit);
  656. }
  657. for (region = dev->regions; region; region = region->next) {
  658. uint64_t addr, size;
  659. addr = region->value->address;
  660. size = region->value->size;
  661. monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
  662. if (!strcmp(region->value->type, "io")) {
  663. monitor_printf(mon, "I/O at 0x%04" PRIx64
  664. " [0x%04" PRIx64 "].\n",
  665. addr, addr + size - 1);
  666. } else {
  667. monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
  668. " [0x%08" PRIx64 "].\n",
  669. region->value->mem_type_64 ? 64 : 32,
  670. region->value->prefetch ? " prefetchable" : "",
  671. addr, addr + size - 1);
  672. }
  673. }
  674. monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
  675. if (dev->has_pci_bridge) {
  676. if (dev->pci_bridge->has_devices) {
  677. PciDeviceInfoList *cdev;
  678. for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
  679. hmp_info_pci_device(mon, cdev->value);
  680. }
  681. }
  682. }
  683. }
  684. static int hmp_info_pic_foreach(Object *obj, void *opaque)
  685. {
  686. InterruptStatsProvider *intc;
  687. InterruptStatsProviderClass *k;
  688. Monitor *mon = opaque;
  689. if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
  690. intc = INTERRUPT_STATS_PROVIDER(obj);
  691. k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
  692. if (k->print_info) {
  693. k->print_info(intc, mon);
  694. } else {
  695. monitor_printf(mon, "Interrupt controller information not available for %s.\n",
  696. object_get_typename(obj));
  697. }
  698. }
  699. return 0;
  700. }
  701. void hmp_info_pic(Monitor *mon, const QDict *qdict)
  702. {
  703. object_child_foreach_recursive(object_get_root(),
  704. hmp_info_pic_foreach, mon);
  705. }
  706. void hmp_info_pci(Monitor *mon, const QDict *qdict)
  707. {
  708. PciInfoList *info_list, *info;
  709. Error *err = NULL;
  710. info_list = qmp_query_pci(&err);
  711. if (err) {
  712. monitor_printf(mon, "PCI devices not supported\n");
  713. error_free(err);
  714. return;
  715. }
  716. for (info = info_list; info; info = info->next) {
  717. PciDeviceInfoList *dev;
  718. for (dev = info->value->devices; dev; dev = dev->next) {
  719. hmp_info_pci_device(mon, dev->value);
  720. }
  721. }
  722. qapi_free_PciInfoList(info_list);
  723. }
  724. void hmp_info_tpm(Monitor *mon, const QDict *qdict)
  725. {
  726. #ifdef CONFIG_TPM
  727. TPMInfoList *info_list, *info;
  728. Error *err = NULL;
  729. unsigned int c = 0;
  730. TPMPassthroughOptions *tpo;
  731. TPMEmulatorOptions *teo;
  732. info_list = qmp_query_tpm(&err);
  733. if (err) {
  734. monitor_printf(mon, "TPM device not supported\n");
  735. error_free(err);
  736. return;
  737. }
  738. if (info_list) {
  739. monitor_printf(mon, "TPM device:\n");
  740. }
  741. for (info = info_list; info; info = info->next) {
  742. TPMInfo *ti = info->value;
  743. monitor_printf(mon, " tpm%d: model=%s\n",
  744. c, TpmModel_str(ti->model));
  745. monitor_printf(mon, " \\ %s: type=%s",
  746. ti->id, TpmType_str(ti->options->type));
  747. switch (ti->options->type) {
  748. case TPM_TYPE_PASSTHROUGH:
  749. tpo = ti->options->u.passthrough.data;
  750. monitor_printf(mon, "%s%s%s%s",
  751. tpo->has_path ? ",path=" : "",
  752. tpo->has_path ? tpo->path : "",
  753. tpo->has_cancel_path ? ",cancel-path=" : "",
  754. tpo->has_cancel_path ? tpo->cancel_path : "");
  755. break;
  756. case TPM_TYPE_EMULATOR:
  757. teo = ti->options->u.emulator.data;
  758. monitor_printf(mon, ",chardev=%s", teo->chardev);
  759. break;
  760. case TPM_TYPE__MAX:
  761. break;
  762. }
  763. monitor_printf(mon, "\n");
  764. c++;
  765. }
  766. qapi_free_TPMInfoList(info_list);
  767. #else
  768. monitor_printf(mon, "TPM device not supported\n");
  769. #endif /* CONFIG_TPM */
  770. }
  771. void hmp_quit(Monitor *mon, const QDict *qdict)
  772. {
  773. monitor_suspend(mon);
  774. qmp_quit(NULL);
  775. }
  776. void hmp_stop(Monitor *mon, const QDict *qdict)
  777. {
  778. qmp_stop(NULL);
  779. }
  780. void hmp_sync_profile(Monitor *mon, const QDict *qdict)
  781. {
  782. const char *op = qdict_get_try_str(qdict, "op");
  783. if (op == NULL) {
  784. bool on = qsp_is_enabled();
  785. monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off");
  786. return;
  787. }
  788. if (!strcmp(op, "on")) {
  789. qsp_enable();
  790. } else if (!strcmp(op, "off")) {
  791. qsp_disable();
  792. } else if (!strcmp(op, "reset")) {
  793. qsp_reset();
  794. } else {
  795. Error *err = NULL;
  796. error_setg(&err, QERR_INVALID_PARAMETER, op);
  797. hmp_handle_error(mon, err);
  798. }
  799. }
  800. void hmp_system_reset(Monitor *mon, const QDict *qdict)
  801. {
  802. qmp_system_reset(NULL);
  803. }
  804. void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
  805. {
  806. qmp_system_powerdown(NULL);
  807. }
  808. void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
  809. {
  810. Error *err = NULL;
  811. qmp_x_exit_preconfig(&err);
  812. hmp_handle_error(mon, err);
  813. }
  814. void hmp_cpu(Monitor *mon, const QDict *qdict)
  815. {
  816. int64_t cpu_index;
  817. /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
  818. use it are converted to the QAPI */
  819. cpu_index = qdict_get_int(qdict, "index");
  820. if (monitor_set_cpu(mon, cpu_index) < 0) {
  821. monitor_printf(mon, "invalid CPU index\n");
  822. }
  823. }
  824. void hmp_memsave(Monitor *mon, const QDict *qdict)
  825. {
  826. uint32_t size = qdict_get_int(qdict, "size");
  827. const char *filename = qdict_get_str(qdict, "filename");
  828. uint64_t addr = qdict_get_int(qdict, "val");
  829. Error *err = NULL;
  830. int cpu_index = monitor_get_cpu_index(mon);
  831. if (cpu_index < 0) {
  832. monitor_printf(mon, "No CPU available\n");
  833. return;
  834. }
  835. qmp_memsave(addr, size, filename, true, cpu_index, &err);
  836. hmp_handle_error(mon, err);
  837. }
  838. void hmp_pmemsave(Monitor *mon, const QDict *qdict)
  839. {
  840. uint32_t size = qdict_get_int(qdict, "size");
  841. const char *filename = qdict_get_str(qdict, "filename");
  842. uint64_t addr = qdict_get_int(qdict, "val");
  843. Error *err = NULL;
  844. qmp_pmemsave(addr, size, filename, &err);
  845. hmp_handle_error(mon, err);
  846. }
  847. void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
  848. {
  849. const char *chardev = qdict_get_str(qdict, "device");
  850. const char *data = qdict_get_str(qdict, "data");
  851. Error *err = NULL;
  852. qmp_ringbuf_write(chardev, data, false, 0, &err);
  853. hmp_handle_error(mon, err);
  854. }
  855. void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
  856. {
  857. uint32_t size = qdict_get_int(qdict, "size");
  858. const char *chardev = qdict_get_str(qdict, "device");
  859. char *data;
  860. Error *err = NULL;
  861. int i;
  862. data = qmp_ringbuf_read(chardev, size, false, 0, &err);
  863. if (hmp_handle_error(mon, err)) {
  864. return;
  865. }
  866. for (i = 0; data[i]; i++) {
  867. unsigned char ch = data[i];
  868. if (ch == '\\') {
  869. monitor_printf(mon, "\\\\");
  870. } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
  871. monitor_printf(mon, "\\u%04X", ch);
  872. } else {
  873. monitor_printf(mon, "%c", ch);
  874. }
  875. }
  876. monitor_printf(mon, "\n");
  877. g_free(data);
  878. }
  879. void hmp_cont(Monitor *mon, const QDict *qdict)
  880. {
  881. Error *err = NULL;
  882. qmp_cont(&err);
  883. hmp_handle_error(mon, err);
  884. }
  885. void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
  886. {
  887. Error *err = NULL;
  888. qmp_system_wakeup(&err);
  889. hmp_handle_error(mon, err);
  890. }
  891. void hmp_nmi(Monitor *mon, const QDict *qdict)
  892. {
  893. Error *err = NULL;
  894. qmp_inject_nmi(&err);
  895. hmp_handle_error(mon, err);
  896. }
  897. void hmp_set_link(Monitor *mon, const QDict *qdict)
  898. {
  899. const char *name = qdict_get_str(qdict, "name");
  900. bool up = qdict_get_bool(qdict, "up");
  901. Error *err = NULL;
  902. qmp_set_link(name, up, &err);
  903. hmp_handle_error(mon, err);
  904. }
  905. void hmp_balloon(Monitor *mon, const QDict *qdict)
  906. {
  907. int64_t value = qdict_get_int(qdict, "value");
  908. Error *err = NULL;
  909. qmp_balloon(value, &err);
  910. hmp_handle_error(mon, err);
  911. }
  912. void hmp_loadvm(Monitor *mon, const QDict *qdict)
  913. {
  914. int saved_vm_running = runstate_is_running();
  915. const char *name = qdict_get_str(qdict, "name");
  916. Error *err = NULL;
  917. vm_stop(RUN_STATE_RESTORE_VM);
  918. if (load_snapshot(name, NULL, false, NULL, &err) && saved_vm_running) {
  919. vm_start();
  920. }
  921. hmp_handle_error(mon, err);
  922. }
  923. void hmp_savevm(Monitor *mon, const QDict *qdict)
  924. {
  925. Error *err = NULL;
  926. save_snapshot(qdict_get_try_str(qdict, "name"),
  927. true, NULL, false, NULL, &err);
  928. hmp_handle_error(mon, err);
  929. }
  930. void hmp_delvm(Monitor *mon, const QDict *qdict)
  931. {
  932. Error *err = NULL;
  933. const char *name = qdict_get_str(qdict, "name");
  934. delete_snapshot(name, false, NULL, &err);
  935. hmp_handle_error(mon, err);
  936. }
  937. void hmp_announce_self(Monitor *mon, const QDict *qdict)
  938. {
  939. const char *interfaces_str = qdict_get_try_str(qdict, "interfaces");
  940. const char *id = qdict_get_try_str(qdict, "id");
  941. AnnounceParameters *params = QAPI_CLONE(AnnounceParameters,
  942. migrate_announce_params());
  943. qapi_free_strList(params->interfaces);
  944. params->interfaces = strList_from_comma_list(interfaces_str);
  945. params->has_interfaces = params->interfaces != NULL;
  946. params->id = g_strdup(id);
  947. params->has_id = !!params->id;
  948. qmp_announce_self(params, NULL);
  949. qapi_free_AnnounceParameters(params);
  950. }
  951. void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
  952. {
  953. qmp_migrate_cancel(NULL);
  954. }
  955. void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
  956. {
  957. Error *err = NULL;
  958. const char *state = qdict_get_str(qdict, "state");
  959. int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
  960. if (val >= 0) {
  961. qmp_migrate_continue(val, &err);
  962. }
  963. hmp_handle_error(mon, err);
  964. }
  965. void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
  966. {
  967. Error *err = NULL;
  968. const char *uri = qdict_get_str(qdict, "uri");
  969. qmp_migrate_incoming(uri, &err);
  970. hmp_handle_error(mon, err);
  971. }
  972. void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
  973. {
  974. Error *err = NULL;
  975. const char *uri = qdict_get_str(qdict, "uri");
  976. qmp_migrate_recover(uri, &err);
  977. hmp_handle_error(mon, err);
  978. }
  979. void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
  980. {
  981. Error *err = NULL;
  982. qmp_migrate_pause(&err);
  983. hmp_handle_error(mon, err);
  984. }
  985. void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
  986. {
  987. const char *cap = qdict_get_str(qdict, "capability");
  988. bool state = qdict_get_bool(qdict, "state");
  989. Error *err = NULL;
  990. MigrationCapabilityStatusList *caps = NULL;
  991. MigrationCapabilityStatus *value;
  992. int val;
  993. val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
  994. if (val < 0) {
  995. goto end;
  996. }
  997. value = g_malloc0(sizeof(*value));
  998. value->capability = val;
  999. value->state = state;
  1000. QAPI_LIST_PREPEND(caps, value);
  1001. qmp_migrate_set_capabilities(caps, &err);
  1002. qapi_free_MigrationCapabilityStatusList(caps);
  1003. end:
  1004. hmp_handle_error(mon, err);
  1005. }
  1006. void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
  1007. {
  1008. const char *param = qdict_get_str(qdict, "parameter");
  1009. const char *valuestr = qdict_get_str(qdict, "value");
  1010. Visitor *v = string_input_visitor_new(valuestr);
  1011. MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
  1012. uint64_t valuebw = 0;
  1013. uint64_t cache_size;
  1014. Error *err = NULL;
  1015. int val, ret;
  1016. val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
  1017. if (val < 0) {
  1018. goto cleanup;
  1019. }
  1020. switch (val) {
  1021. case MIGRATION_PARAMETER_COMPRESS_LEVEL:
  1022. p->has_compress_level = true;
  1023. visit_type_uint8(v, param, &p->compress_level, &err);
  1024. break;
  1025. case MIGRATION_PARAMETER_COMPRESS_THREADS:
  1026. p->has_compress_threads = true;
  1027. visit_type_uint8(v, param, &p->compress_threads, &err);
  1028. break;
  1029. case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD:
  1030. p->has_compress_wait_thread = true;
  1031. visit_type_bool(v, param, &p->compress_wait_thread, &err);
  1032. break;
  1033. case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
  1034. p->has_decompress_threads = true;
  1035. visit_type_uint8(v, param, &p->decompress_threads, &err);
  1036. break;
  1037. case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD:
  1038. p->has_throttle_trigger_threshold = true;
  1039. visit_type_uint8(v, param, &p->throttle_trigger_threshold, &err);
  1040. break;
  1041. case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
  1042. p->has_cpu_throttle_initial = true;
  1043. visit_type_uint8(v, param, &p->cpu_throttle_initial, &err);
  1044. break;
  1045. case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
  1046. p->has_cpu_throttle_increment = true;
  1047. visit_type_uint8(v, param, &p->cpu_throttle_increment, &err);
  1048. break;
  1049. case MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW:
  1050. p->has_cpu_throttle_tailslow = true;
  1051. visit_type_bool(v, param, &p->cpu_throttle_tailslow, &err);
  1052. break;
  1053. case MIGRATION_PARAMETER_MAX_CPU_THROTTLE:
  1054. p->has_max_cpu_throttle = true;
  1055. visit_type_uint8(v, param, &p->max_cpu_throttle, &err);
  1056. break;
  1057. case MIGRATION_PARAMETER_TLS_CREDS:
  1058. p->has_tls_creds = true;
  1059. p->tls_creds = g_new0(StrOrNull, 1);
  1060. p->tls_creds->type = QTYPE_QSTRING;
  1061. visit_type_str(v, param, &p->tls_creds->u.s, &err);
  1062. break;
  1063. case MIGRATION_PARAMETER_TLS_HOSTNAME:
  1064. p->has_tls_hostname = true;
  1065. p->tls_hostname = g_new0(StrOrNull, 1);
  1066. p->tls_hostname->type = QTYPE_QSTRING;
  1067. visit_type_str(v, param, &p->tls_hostname->u.s, &err);
  1068. break;
  1069. case MIGRATION_PARAMETER_TLS_AUTHZ:
  1070. p->has_tls_authz = true;
  1071. p->tls_authz = g_new0(StrOrNull, 1);
  1072. p->tls_authz->type = QTYPE_QSTRING;
  1073. visit_type_str(v, param, &p->tls_authz->u.s, &err);
  1074. break;
  1075. case MIGRATION_PARAMETER_MAX_BANDWIDTH:
  1076. p->has_max_bandwidth = true;
  1077. /*
  1078. * Can't use visit_type_size() here, because it
  1079. * defaults to Bytes rather than Mebibytes.
  1080. */
  1081. ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
  1082. if (ret < 0 || valuebw > INT64_MAX
  1083. || (size_t)valuebw != valuebw) {
  1084. error_setg(&err, "Invalid size %s", valuestr);
  1085. break;
  1086. }
  1087. p->max_bandwidth = valuebw;
  1088. break;
  1089. case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
  1090. p->has_downtime_limit = true;
  1091. visit_type_size(v, param, &p->downtime_limit, &err);
  1092. break;
  1093. case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
  1094. p->has_x_checkpoint_delay = true;
  1095. visit_type_uint32(v, param, &p->x_checkpoint_delay, &err);
  1096. break;
  1097. case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
  1098. p->has_block_incremental = true;
  1099. visit_type_bool(v, param, &p->block_incremental, &err);
  1100. break;
  1101. case MIGRATION_PARAMETER_MULTIFD_CHANNELS:
  1102. p->has_multifd_channels = true;
  1103. visit_type_uint8(v, param, &p->multifd_channels, &err);
  1104. break;
  1105. case MIGRATION_PARAMETER_MULTIFD_COMPRESSION:
  1106. p->has_multifd_compression = true;
  1107. visit_type_MultiFDCompression(v, param, &p->multifd_compression,
  1108. &err);
  1109. break;
  1110. case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL:
  1111. p->has_multifd_zlib_level = true;
  1112. visit_type_uint8(v, param, &p->multifd_zlib_level, &err);
  1113. break;
  1114. case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL:
  1115. p->has_multifd_zstd_level = true;
  1116. visit_type_uint8(v, param, &p->multifd_zstd_level, &err);
  1117. break;
  1118. case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
  1119. p->has_xbzrle_cache_size = true;
  1120. if (!visit_type_size(v, param, &cache_size, &err)) {
  1121. break;
  1122. }
  1123. if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) {
  1124. error_setg(&err, "Invalid size %s", valuestr);
  1125. break;
  1126. }
  1127. p->xbzrle_cache_size = cache_size;
  1128. break;
  1129. case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH:
  1130. p->has_max_postcopy_bandwidth = true;
  1131. visit_type_size(v, param, &p->max_postcopy_bandwidth, &err);
  1132. break;
  1133. case MIGRATION_PARAMETER_ANNOUNCE_INITIAL:
  1134. p->has_announce_initial = true;
  1135. visit_type_size(v, param, &p->announce_initial, &err);
  1136. break;
  1137. case MIGRATION_PARAMETER_ANNOUNCE_MAX:
  1138. p->has_announce_max = true;
  1139. visit_type_size(v, param, &p->announce_max, &err);
  1140. break;
  1141. case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS:
  1142. p->has_announce_rounds = true;
  1143. visit_type_size(v, param, &p->announce_rounds, &err);
  1144. break;
  1145. case MIGRATION_PARAMETER_ANNOUNCE_STEP:
  1146. p->has_announce_step = true;
  1147. visit_type_size(v, param, &p->announce_step, &err);
  1148. break;
  1149. case MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING:
  1150. error_setg(&err, "The block-bitmap-mapping parameter can only be set "
  1151. "through QMP");
  1152. break;
  1153. default:
  1154. assert(0);
  1155. }
  1156. if (err) {
  1157. goto cleanup;
  1158. }
  1159. qmp_migrate_set_parameters(p, &err);
  1160. cleanup:
  1161. qapi_free_MigrateSetParameters(p);
  1162. visit_free(v);
  1163. hmp_handle_error(mon, err);
  1164. }
  1165. void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
  1166. {
  1167. Error *err = NULL;
  1168. const char *protocol = qdict_get_str(qdict, "protocol");
  1169. const char *hostname = qdict_get_str(qdict, "hostname");
  1170. bool has_port = qdict_haskey(qdict, "port");
  1171. int port = qdict_get_try_int(qdict, "port", -1);
  1172. bool has_tls_port = qdict_haskey(qdict, "tls-port");
  1173. int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
  1174. const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
  1175. qmp_client_migrate_info(protocol, hostname,
  1176. has_port, port, has_tls_port, tls_port,
  1177. !!cert_subject, cert_subject, &err);
  1178. hmp_handle_error(mon, err);
  1179. }
  1180. void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
  1181. {
  1182. Error *err = NULL;
  1183. qmp_migrate_start_postcopy(&err);
  1184. hmp_handle_error(mon, err);
  1185. }
  1186. void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
  1187. {
  1188. Error *err = NULL;
  1189. qmp_x_colo_lost_heartbeat(&err);
  1190. hmp_handle_error(mon, err);
  1191. }
  1192. void hmp_set_password(Monitor *mon, const QDict *qdict)
  1193. {
  1194. const char *protocol = qdict_get_str(qdict, "protocol");
  1195. const char *password = qdict_get_str(qdict, "password");
  1196. const char *display = qdict_get_try_str(qdict, "display");
  1197. const char *connected = qdict_get_try_str(qdict, "connected");
  1198. Error *err = NULL;
  1199. SetPasswordOptions opts = {
  1200. .password = (char *)password,
  1201. .has_connected = !!connected,
  1202. };
  1203. opts.connected = qapi_enum_parse(&SetPasswordAction_lookup, connected,
  1204. SET_PASSWORD_ACTION_KEEP, &err);
  1205. if (err) {
  1206. goto out;
  1207. }
  1208. opts.protocol = qapi_enum_parse(&DisplayProtocol_lookup, protocol,
  1209. DISPLAY_PROTOCOL_VNC, &err);
  1210. if (err) {
  1211. goto out;
  1212. }
  1213. if (opts.protocol == DISPLAY_PROTOCOL_VNC) {
  1214. opts.u.vnc.has_display = !!display;
  1215. opts.u.vnc.display = (char *)display;
  1216. }
  1217. qmp_set_password(&opts, &err);
  1218. out:
  1219. hmp_handle_error(mon, err);
  1220. }
  1221. void hmp_expire_password(Monitor *mon, const QDict *qdict)
  1222. {
  1223. const char *protocol = qdict_get_str(qdict, "protocol");
  1224. const char *whenstr = qdict_get_str(qdict, "time");
  1225. const char *display = qdict_get_try_str(qdict, "display");
  1226. Error *err = NULL;
  1227. ExpirePasswordOptions opts = {
  1228. .time = (char *)whenstr,
  1229. };
  1230. opts.protocol = qapi_enum_parse(&DisplayProtocol_lookup, protocol,
  1231. DISPLAY_PROTOCOL_VNC, &err);
  1232. if (err) {
  1233. goto out;
  1234. }
  1235. if (opts.protocol == DISPLAY_PROTOCOL_VNC) {
  1236. opts.u.vnc.has_display = !!display;
  1237. opts.u.vnc.display = (char *)display;
  1238. }
  1239. qmp_expire_password(&opts, &err);
  1240. out:
  1241. hmp_handle_error(mon, err);
  1242. }
  1243. #ifdef CONFIG_VNC
  1244. static void hmp_change_read_arg(void *opaque, const char *password,
  1245. void *readline_opaque)
  1246. {
  1247. qmp_change_vnc_password(password, NULL);
  1248. monitor_read_command(opaque, 1);
  1249. }
  1250. #endif
  1251. void hmp_change(Monitor *mon, const QDict *qdict)
  1252. {
  1253. const char *device = qdict_get_str(qdict, "device");
  1254. const char *target = qdict_get_str(qdict, "target");
  1255. const char *arg = qdict_get_try_str(qdict, "arg");
  1256. const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
  1257. bool force = qdict_get_try_bool(qdict, "force", false);
  1258. BlockdevChangeReadOnlyMode read_only_mode = 0;
  1259. Error *err = NULL;
  1260. #ifdef CONFIG_VNC
  1261. if (strcmp(device, "vnc") == 0) {
  1262. if (read_only) {
  1263. monitor_printf(mon,
  1264. "Parameter 'read-only-mode' is invalid for VNC\n");
  1265. return;
  1266. }
  1267. if (strcmp(target, "passwd") == 0 ||
  1268. strcmp(target, "password") == 0) {
  1269. if (!arg) {
  1270. MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
  1271. monitor_read_password(hmp_mon, hmp_change_read_arg, NULL);
  1272. return;
  1273. } else {
  1274. qmp_change_vnc_password(arg, &err);
  1275. }
  1276. } else {
  1277. monitor_printf(mon, "Expected 'password' after 'vnc'\n");
  1278. }
  1279. } else
  1280. #endif
  1281. {
  1282. if (read_only) {
  1283. read_only_mode =
  1284. qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
  1285. read_only,
  1286. BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
  1287. if (err) {
  1288. goto end;
  1289. }
  1290. }
  1291. qmp_blockdev_change_medium(true, device, false, NULL, target,
  1292. !!arg, arg, true, force,
  1293. !!read_only, read_only_mode,
  1294. false, 0,
  1295. &err);
  1296. }
  1297. end:
  1298. hmp_handle_error(mon, err);
  1299. }
  1300. typedef struct HMPMigrationStatus {
  1301. QEMUTimer *timer;
  1302. Monitor *mon;
  1303. bool is_block_migration;
  1304. } HMPMigrationStatus;
  1305. static void hmp_migrate_status_cb(void *opaque)
  1306. {
  1307. HMPMigrationStatus *status = opaque;
  1308. MigrationInfo *info;
  1309. info = qmp_query_migrate(NULL);
  1310. if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
  1311. info->status == MIGRATION_STATUS_SETUP) {
  1312. if (info->has_disk) {
  1313. int progress;
  1314. if (info->disk->remaining) {
  1315. progress = info->disk->transferred * 100 / info->disk->total;
  1316. } else {
  1317. progress = 100;
  1318. }
  1319. monitor_printf(status->mon, "Completed %d %%\r", progress);
  1320. monitor_flush(status->mon);
  1321. }
  1322. timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
  1323. } else {
  1324. if (status->is_block_migration) {
  1325. monitor_printf(status->mon, "\n");
  1326. }
  1327. if (info->has_error_desc) {
  1328. error_report("%s", info->error_desc);
  1329. }
  1330. monitor_resume(status->mon);
  1331. timer_free(status->timer);
  1332. g_free(status);
  1333. }
  1334. qapi_free_MigrationInfo(info);
  1335. }
  1336. void hmp_migrate(Monitor *mon, const QDict *qdict)
  1337. {
  1338. bool detach = qdict_get_try_bool(qdict, "detach", false);
  1339. bool blk = qdict_get_try_bool(qdict, "blk", false);
  1340. bool inc = qdict_get_try_bool(qdict, "inc", false);
  1341. bool resume = qdict_get_try_bool(qdict, "resume", false);
  1342. const char *uri = qdict_get_str(qdict, "uri");
  1343. Error *err = NULL;
  1344. qmp_migrate(uri, !!blk, blk, !!inc, inc,
  1345. false, false, true, resume, &err);
  1346. if (hmp_handle_error(mon, err)) {
  1347. return;
  1348. }
  1349. if (!detach) {
  1350. HMPMigrationStatus *status;
  1351. if (monitor_suspend(mon) < 0) {
  1352. monitor_printf(mon, "terminal does not allow synchronous "
  1353. "migration, continuing detached\n");
  1354. return;
  1355. }
  1356. status = g_malloc0(sizeof(*status));
  1357. status->mon = mon;
  1358. status->is_block_migration = blk || inc;
  1359. status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
  1360. status);
  1361. timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
  1362. }
  1363. }
  1364. void hmp_netdev_add(Monitor *mon, const QDict *qdict)
  1365. {
  1366. Error *err = NULL;
  1367. QemuOpts *opts;
  1368. const char *type = qdict_get_try_str(qdict, "type");
  1369. if (type && is_help_option(type)) {
  1370. show_netdevs();
  1371. return;
  1372. }
  1373. opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
  1374. if (err) {
  1375. goto out;
  1376. }
  1377. netdev_add(opts, &err);
  1378. if (err) {
  1379. qemu_opts_del(opts);
  1380. }
  1381. out:
  1382. hmp_handle_error(mon, err);
  1383. }
  1384. void hmp_netdev_del(Monitor *mon, const QDict *qdict)
  1385. {
  1386. const char *id = qdict_get_str(qdict, "id");
  1387. Error *err = NULL;
  1388. qmp_netdev_del(id, &err);
  1389. hmp_handle_error(mon, err);
  1390. }
  1391. void hmp_object_add(Monitor *mon, const QDict *qdict)
  1392. {
  1393. const char *options = qdict_get_str(qdict, "object");
  1394. Error *err = NULL;
  1395. user_creatable_add_from_str(options, &err);
  1396. hmp_handle_error(mon, err);
  1397. }
  1398. void hmp_getfd(Monitor *mon, const QDict *qdict)
  1399. {
  1400. const char *fdname = qdict_get_str(qdict, "fdname");
  1401. Error *err = NULL;
  1402. qmp_getfd(fdname, &err);
  1403. hmp_handle_error(mon, err);
  1404. }
  1405. void hmp_closefd(Monitor *mon, const QDict *qdict)
  1406. {
  1407. const char *fdname = qdict_get_str(qdict, "fdname");
  1408. Error *err = NULL;
  1409. qmp_closefd(fdname, &err);
  1410. hmp_handle_error(mon, err);
  1411. }
  1412. void hmp_sendkey(Monitor *mon, const QDict *qdict)
  1413. {
  1414. const char *keys = qdict_get_str(qdict, "keys");
  1415. KeyValue *v = NULL;
  1416. KeyValueList *head = NULL, **tail = &head;
  1417. int has_hold_time = qdict_haskey(qdict, "hold-time");
  1418. int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
  1419. Error *err = NULL;
  1420. const char *separator;
  1421. int keyname_len;
  1422. while (1) {
  1423. separator = qemu_strchrnul(keys, '-');
  1424. keyname_len = separator - keys;
  1425. /* Be compatible with old interface, convert user inputted "<" */
  1426. if (keys[0] == '<' && keyname_len == 1) {
  1427. keys = "less";
  1428. keyname_len = 4;
  1429. }
  1430. v = g_malloc0(sizeof(*v));
  1431. if (strstart(keys, "0x", NULL)) {
  1432. char *endp;
  1433. int value = strtoul(keys, &endp, 0);
  1434. assert(endp <= keys + keyname_len);
  1435. if (endp != keys + keyname_len) {
  1436. goto err_out;
  1437. }
  1438. v->type = KEY_VALUE_KIND_NUMBER;
  1439. v->u.number.data = value;
  1440. } else {
  1441. int idx = index_from_key(keys, keyname_len);
  1442. if (idx == Q_KEY_CODE__MAX) {
  1443. goto err_out;
  1444. }
  1445. v->type = KEY_VALUE_KIND_QCODE;
  1446. v->u.qcode.data = idx;
  1447. }
  1448. QAPI_LIST_APPEND(tail, v);
  1449. v = NULL;
  1450. if (!*separator) {
  1451. break;
  1452. }
  1453. keys = separator + 1;
  1454. }
  1455. qmp_send_key(head, has_hold_time, hold_time, &err);
  1456. hmp_handle_error(mon, err);
  1457. out:
  1458. qapi_free_KeyValue(v);
  1459. qapi_free_KeyValueList(head);
  1460. return;
  1461. err_out:
  1462. monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
  1463. goto out;
  1464. }
  1465. void coroutine_fn
  1466. hmp_screendump(Monitor *mon, const QDict *qdict)
  1467. {
  1468. const char *filename = qdict_get_str(qdict, "filename");
  1469. const char *id = qdict_get_try_str(qdict, "device");
  1470. int64_t head = qdict_get_try_int(qdict, "head", 0);
  1471. const char *input_format = qdict_get_try_str(qdict, "format");
  1472. Error *err = NULL;
  1473. ImageFormat format;
  1474. format = qapi_enum_parse(&ImageFormat_lookup, input_format,
  1475. IMAGE_FORMAT_PPM, &err);
  1476. if (err) {
  1477. goto end;
  1478. }
  1479. qmp_screendump(filename, id != NULL, id, id != NULL, head,
  1480. input_format != NULL, format, &err);
  1481. end:
  1482. hmp_handle_error(mon, err);
  1483. }
  1484. void hmp_chardev_add(Monitor *mon, const QDict *qdict)
  1485. {
  1486. const char *args = qdict_get_str(qdict, "args");
  1487. Error *err = NULL;
  1488. QemuOpts *opts;
  1489. opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
  1490. if (opts == NULL) {
  1491. error_setg(&err, "Parsing chardev args failed");
  1492. } else {
  1493. qemu_chr_new_from_opts(opts, NULL, &err);
  1494. qemu_opts_del(opts);
  1495. }
  1496. hmp_handle_error(mon, err);
  1497. }
  1498. void hmp_chardev_change(Monitor *mon, const QDict *qdict)
  1499. {
  1500. const char *args = qdict_get_str(qdict, "args");
  1501. const char *id;
  1502. Error *err = NULL;
  1503. ChardevBackend *backend = NULL;
  1504. ChardevReturn *ret = NULL;
  1505. QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
  1506. true);
  1507. if (!opts) {
  1508. error_setg(&err, "Parsing chardev args failed");
  1509. goto end;
  1510. }
  1511. id = qdict_get_str(qdict, "id");
  1512. if (qemu_opts_id(opts)) {
  1513. error_setg(&err, "Unexpected 'id' parameter");
  1514. goto end;
  1515. }
  1516. backend = qemu_chr_parse_opts(opts, &err);
  1517. if (!backend) {
  1518. goto end;
  1519. }
  1520. ret = qmp_chardev_change(id, backend, &err);
  1521. end:
  1522. qapi_free_ChardevReturn(ret);
  1523. qapi_free_ChardevBackend(backend);
  1524. qemu_opts_del(opts);
  1525. hmp_handle_error(mon, err);
  1526. }
  1527. void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
  1528. {
  1529. Error *local_err = NULL;
  1530. qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
  1531. hmp_handle_error(mon, local_err);
  1532. }
  1533. void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
  1534. {
  1535. Error *local_err = NULL;
  1536. qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
  1537. hmp_handle_error(mon, local_err);
  1538. }
  1539. void hmp_object_del(Monitor *mon, const QDict *qdict)
  1540. {
  1541. const char *id = qdict_get_str(qdict, "id");
  1542. Error *err = NULL;
  1543. user_creatable_del(id, &err);
  1544. hmp_handle_error(mon, err);
  1545. }
  1546. void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
  1547. {
  1548. Error *err = NULL;
  1549. MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
  1550. MemoryDeviceInfoList *info;
  1551. VirtioPMEMDeviceInfo *vpi;
  1552. VirtioMEMDeviceInfo *vmi;
  1553. MemoryDeviceInfo *value;
  1554. PCDIMMDeviceInfo *di;
  1555. SgxEPCDeviceInfo *se;
  1556. for (info = info_list; info; info = info->next) {
  1557. value = info->value;
  1558. if (value) {
  1559. switch (value->type) {
  1560. case MEMORY_DEVICE_INFO_KIND_DIMM:
  1561. case MEMORY_DEVICE_INFO_KIND_NVDIMM:
  1562. di = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ?
  1563. value->u.dimm.data : value->u.nvdimm.data;
  1564. monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
  1565. MemoryDeviceInfoKind_str(value->type),
  1566. di->id ? di->id : "");
  1567. monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
  1568. monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
  1569. monitor_printf(mon, " node: %" PRId64 "\n", di->node);
  1570. monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
  1571. monitor_printf(mon, " memdev: %s\n", di->memdev);
  1572. monitor_printf(mon, " hotplugged: %s\n",
  1573. di->hotplugged ? "true" : "false");
  1574. monitor_printf(mon, " hotpluggable: %s\n",
  1575. di->hotpluggable ? "true" : "false");
  1576. break;
  1577. case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM:
  1578. vpi = value->u.virtio_pmem.data;
  1579. monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
  1580. MemoryDeviceInfoKind_str(value->type),
  1581. vpi->id ? vpi->id : "");
  1582. monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->memaddr);
  1583. monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size);
  1584. monitor_printf(mon, " memdev: %s\n", vpi->memdev);
  1585. break;
  1586. case MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM:
  1587. vmi = value->u.virtio_mem.data;
  1588. monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
  1589. MemoryDeviceInfoKind_str(value->type),
  1590. vmi->id ? vmi->id : "");
  1591. monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vmi->memaddr);
  1592. monitor_printf(mon, " node: %" PRId64 "\n", vmi->node);
  1593. monitor_printf(mon, " requested-size: %" PRIu64 "\n",
  1594. vmi->requested_size);
  1595. monitor_printf(mon, " size: %" PRIu64 "\n", vmi->size);
  1596. monitor_printf(mon, " max-size: %" PRIu64 "\n", vmi->max_size);
  1597. monitor_printf(mon, " block-size: %" PRIu64 "\n",
  1598. vmi->block_size);
  1599. monitor_printf(mon, " memdev: %s\n", vmi->memdev);
  1600. break;
  1601. case MEMORY_DEVICE_INFO_KIND_SGX_EPC:
  1602. se = value->u.sgx_epc.data;
  1603. monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
  1604. MemoryDeviceInfoKind_str(value->type),
  1605. se->id ? se->id : "");
  1606. monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", se->memaddr);
  1607. monitor_printf(mon, " size: %" PRIu64 "\n", se->size);
  1608. monitor_printf(mon, " node: %" PRId64 "\n", se->node);
  1609. monitor_printf(mon, " memdev: %s\n", se->memdev);
  1610. break;
  1611. default:
  1612. g_assert_not_reached();
  1613. }
  1614. }
  1615. }
  1616. qapi_free_MemoryDeviceInfoList(info_list);
  1617. hmp_handle_error(mon, err);
  1618. }
  1619. void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
  1620. {
  1621. IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
  1622. IOThreadInfoList *info;
  1623. IOThreadInfo *value;
  1624. for (info = info_list; info; info = info->next) {
  1625. value = info->value;
  1626. monitor_printf(mon, "%s:\n", value->id);
  1627. monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
  1628. monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
  1629. monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
  1630. monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
  1631. monitor_printf(mon, " aio-max-batch=%" PRId64 "\n",
  1632. value->aio_max_batch);
  1633. }
  1634. qapi_free_IOThreadInfoList(info_list);
  1635. }
  1636. void hmp_rocker(Monitor *mon, const QDict *qdict)
  1637. {
  1638. const char *name = qdict_get_str(qdict, "name");
  1639. RockerSwitch *rocker;
  1640. Error *err = NULL;
  1641. rocker = qmp_query_rocker(name, &err);
  1642. if (hmp_handle_error(mon, err)) {
  1643. return;
  1644. }
  1645. monitor_printf(mon, "name: %s\n", rocker->name);
  1646. monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
  1647. monitor_printf(mon, "ports: %d\n", rocker->ports);
  1648. qapi_free_RockerSwitch(rocker);
  1649. }
  1650. void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
  1651. {
  1652. RockerPortList *list, *port;
  1653. const char *name = qdict_get_str(qdict, "name");
  1654. Error *err = NULL;
  1655. list = qmp_query_rocker_ports(name, &err);
  1656. if (hmp_handle_error(mon, err)) {
  1657. return;
  1658. }
  1659. monitor_printf(mon, " ena/ speed/ auto\n");
  1660. monitor_printf(mon, " port link duplex neg?\n");
  1661. for (port = list; port; port = port->next) {
  1662. monitor_printf(mon, "%10s %-4s %-3s %2s %s\n",
  1663. port->value->name,
  1664. port->value->enabled ? port->value->link_up ?
  1665. "up" : "down" : "!ena",
  1666. port->value->speed == 10000 ? "10G" : "??",
  1667. port->value->duplex ? "FD" : "HD",
  1668. port->value->autoneg ? "Yes" : "No");
  1669. }
  1670. qapi_free_RockerPortList(list);
  1671. }
  1672. void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
  1673. {
  1674. RockerOfDpaFlowList *list, *info;
  1675. const char *name = qdict_get_str(qdict, "name");
  1676. uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
  1677. Error *err = NULL;
  1678. list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
  1679. if (hmp_handle_error(mon, err)) {
  1680. return;
  1681. }
  1682. monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
  1683. for (info = list; info; info = info->next) {
  1684. RockerOfDpaFlow *flow = info->value;
  1685. RockerOfDpaFlowKey *key = flow->key;
  1686. RockerOfDpaFlowMask *mask = flow->mask;
  1687. RockerOfDpaFlowAction *action = flow->action;
  1688. if (flow->hits) {
  1689. monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
  1690. key->priority, key->tbl_id, flow->hits);
  1691. } else {
  1692. monitor_printf(mon, "%-4d %-3d ",
  1693. key->priority, key->tbl_id);
  1694. }
  1695. if (key->has_in_pport) {
  1696. monitor_printf(mon, " pport %d", key->in_pport);
  1697. if (mask->has_in_pport) {
  1698. monitor_printf(mon, "(0x%x)", mask->in_pport);
  1699. }
  1700. }
  1701. if (key->has_vlan_id) {
  1702. monitor_printf(mon, " vlan %d",
  1703. key->vlan_id & VLAN_VID_MASK);
  1704. if (mask->has_vlan_id) {
  1705. monitor_printf(mon, "(0x%x)", mask->vlan_id);
  1706. }
  1707. }
  1708. if (key->has_tunnel_id) {
  1709. monitor_printf(mon, " tunnel %d", key->tunnel_id);
  1710. if (mask->has_tunnel_id) {
  1711. monitor_printf(mon, "(0x%x)", mask->tunnel_id);
  1712. }
  1713. }
  1714. if (key->has_eth_type) {
  1715. switch (key->eth_type) {
  1716. case 0x0806:
  1717. monitor_printf(mon, " ARP");
  1718. break;
  1719. case 0x0800:
  1720. monitor_printf(mon, " IP");
  1721. break;
  1722. case 0x86dd:
  1723. monitor_printf(mon, " IPv6");
  1724. break;
  1725. case 0x8809:
  1726. monitor_printf(mon, " LACP");
  1727. break;
  1728. case 0x88cc:
  1729. monitor_printf(mon, " LLDP");
  1730. break;
  1731. default:
  1732. monitor_printf(mon, " eth type 0x%04x", key->eth_type);
  1733. break;
  1734. }
  1735. }
  1736. if (key->has_eth_src) {
  1737. if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
  1738. (mask->has_eth_src) &&
  1739. (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
  1740. monitor_printf(mon, " src <any mcast/bcast>");
  1741. } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
  1742. (mask->has_eth_src) &&
  1743. (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
  1744. monitor_printf(mon, " src <any ucast>");
  1745. } else {
  1746. monitor_printf(mon, " src %s", key->eth_src);
  1747. if (mask->has_eth_src) {
  1748. monitor_printf(mon, "(%s)", mask->eth_src);
  1749. }
  1750. }
  1751. }
  1752. if (key->has_eth_dst) {
  1753. if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
  1754. (mask->has_eth_dst) &&
  1755. (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
  1756. monitor_printf(mon, " dst <any mcast/bcast>");
  1757. } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
  1758. (mask->has_eth_dst) &&
  1759. (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
  1760. monitor_printf(mon, " dst <any ucast>");
  1761. } else {
  1762. monitor_printf(mon, " dst %s", key->eth_dst);
  1763. if (mask->has_eth_dst) {
  1764. monitor_printf(mon, "(%s)", mask->eth_dst);
  1765. }
  1766. }
  1767. }
  1768. if (key->has_ip_proto) {
  1769. monitor_printf(mon, " proto %d", key->ip_proto);
  1770. if (mask->has_ip_proto) {
  1771. monitor_printf(mon, "(0x%x)", mask->ip_proto);
  1772. }
  1773. }
  1774. if (key->has_ip_tos) {
  1775. monitor_printf(mon, " TOS %d", key->ip_tos);
  1776. if (mask->has_ip_tos) {
  1777. monitor_printf(mon, "(0x%x)", mask->ip_tos);
  1778. }
  1779. }
  1780. if (key->has_ip_dst) {
  1781. monitor_printf(mon, " dst %s", key->ip_dst);
  1782. }
  1783. if (action->has_goto_tbl || action->has_group_id ||
  1784. action->has_new_vlan_id) {
  1785. monitor_printf(mon, " -->");
  1786. }
  1787. if (action->has_new_vlan_id) {
  1788. monitor_printf(mon, " apply new vlan %d",
  1789. ntohs(action->new_vlan_id));
  1790. }
  1791. if (action->has_group_id) {
  1792. monitor_printf(mon, " write group 0x%08x", action->group_id);
  1793. }
  1794. if (action->has_goto_tbl) {
  1795. monitor_printf(mon, " goto tbl %d", action->goto_tbl);
  1796. }
  1797. monitor_printf(mon, "\n");
  1798. }
  1799. qapi_free_RockerOfDpaFlowList(list);
  1800. }
  1801. void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
  1802. {
  1803. RockerOfDpaGroupList *list, *g;
  1804. const char *name = qdict_get_str(qdict, "name");
  1805. uint8_t type = qdict_get_try_int(qdict, "type", 9);
  1806. Error *err = NULL;
  1807. list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
  1808. if (hmp_handle_error(mon, err)) {
  1809. return;
  1810. }
  1811. monitor_printf(mon, "id (decode) --> buckets\n");
  1812. for (g = list; g; g = g->next) {
  1813. RockerOfDpaGroup *group = g->value;
  1814. bool set = false;
  1815. monitor_printf(mon, "0x%08x", group->id);
  1816. monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
  1817. group->type == 1 ? "L2 rewrite" :
  1818. group->type == 2 ? "L3 unicast" :
  1819. group->type == 3 ? "L2 multicast" :
  1820. group->type == 4 ? "L2 flood" :
  1821. group->type == 5 ? "L3 interface" :
  1822. group->type == 6 ? "L3 multicast" :
  1823. group->type == 7 ? "L3 ECMP" :
  1824. group->type == 8 ? "L2 overlay" :
  1825. "unknown");
  1826. if (group->has_vlan_id) {
  1827. monitor_printf(mon, " vlan %d", group->vlan_id);
  1828. }
  1829. if (group->has_pport) {
  1830. monitor_printf(mon, " pport %d", group->pport);
  1831. }
  1832. if (group->has_index) {
  1833. monitor_printf(mon, " index %d", group->index);
  1834. }
  1835. monitor_printf(mon, ") -->");
  1836. if (group->has_set_vlan_id && group->set_vlan_id) {
  1837. set = true;
  1838. monitor_printf(mon, " set vlan %d",
  1839. group->set_vlan_id & VLAN_VID_MASK);
  1840. }
  1841. if (group->has_set_eth_src) {
  1842. if (!set) {
  1843. set = true;
  1844. monitor_printf(mon, " set");
  1845. }
  1846. monitor_printf(mon, " src %s", group->set_eth_src);
  1847. }
  1848. if (group->has_set_eth_dst) {
  1849. if (!set) {
  1850. monitor_printf(mon, " set");
  1851. }
  1852. monitor_printf(mon, " dst %s", group->set_eth_dst);
  1853. }
  1854. if (group->has_ttl_check && group->ttl_check) {
  1855. monitor_printf(mon, " check TTL");
  1856. }
  1857. if (group->has_group_id && group->group_id) {
  1858. monitor_printf(mon, " group id 0x%08x", group->group_id);
  1859. }
  1860. if (group->has_pop_vlan && group->pop_vlan) {
  1861. monitor_printf(mon, " pop vlan");
  1862. }
  1863. if (group->has_out_pport) {
  1864. monitor_printf(mon, " out pport %d", group->out_pport);
  1865. }
  1866. if (group->has_group_ids) {
  1867. struct uint32List *id;
  1868. monitor_printf(mon, " groups [");
  1869. for (id = group->group_ids; id; id = id->next) {
  1870. monitor_printf(mon, "0x%08x", id->value);
  1871. if (id->next) {
  1872. monitor_printf(mon, ",");
  1873. }
  1874. }
  1875. monitor_printf(mon, "]");
  1876. }
  1877. monitor_printf(mon, "\n");
  1878. }
  1879. qapi_free_RockerOfDpaGroupList(list);
  1880. }
  1881. void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
  1882. {
  1883. Error *err = NULL;
  1884. GuidInfo *info = qmp_query_vm_generation_id(&err);
  1885. if (info) {
  1886. monitor_printf(mon, "%s\n", info->guid);
  1887. }
  1888. hmp_handle_error(mon, err);
  1889. qapi_free_GuidInfo(info);
  1890. }
  1891. void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
  1892. {
  1893. Error *err = NULL;
  1894. MemoryInfo *info = qmp_query_memory_size_summary(&err);
  1895. if (info) {
  1896. monitor_printf(mon, "base memory: %" PRIu64 "\n",
  1897. info->base_memory);
  1898. if (info->has_plugged_memory) {
  1899. monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
  1900. info->plugged_memory);
  1901. }
  1902. qapi_free_MemoryInfo(info);
  1903. }
  1904. hmp_handle_error(mon, err);
  1905. }
  1906. static void print_stats_schema_value(Monitor *mon, StatsSchemaValue *value)
  1907. {
  1908. const char *unit = NULL;
  1909. monitor_printf(mon, " %s (%s%s", value->name, StatsType_str(value->type),
  1910. value->has_unit || value->exponent ? ", " : "");
  1911. if (value->has_unit) {
  1912. if (value->unit == STATS_UNIT_SECONDS) {
  1913. unit = "s";
  1914. } else if (value->unit == STATS_UNIT_BYTES) {
  1915. unit = "B";
  1916. }
  1917. }
  1918. if (unit && value->base == 10 &&
  1919. value->exponent >= -18 && value->exponent <= 18 &&
  1920. value->exponent % 3 == 0) {
  1921. monitor_puts(mon, si_prefix(value->exponent));
  1922. } else if (unit && value->base == 2 &&
  1923. value->exponent >= 0 && value->exponent <= 60 &&
  1924. value->exponent % 10 == 0) {
  1925. monitor_puts(mon, iec_binary_prefix(value->exponent));
  1926. } else if (value->exponent) {
  1927. /* Use exponential notation and write the unit's English name */
  1928. monitor_printf(mon, "* %d^%d%s",
  1929. value->base, value->exponent,
  1930. value->has_unit ? " " : "");
  1931. unit = NULL;
  1932. }
  1933. if (value->has_unit) {
  1934. monitor_puts(mon, unit ? unit : StatsUnit_str(value->unit));
  1935. }
  1936. /* Print bucket size for linear histograms */
  1937. if (value->type == STATS_TYPE_LINEAR_HISTOGRAM && value->has_bucket_size) {
  1938. monitor_printf(mon, ", bucket size=%d", value->bucket_size);
  1939. }
  1940. monitor_printf(mon, ")");
  1941. }
  1942. static StatsSchemaValueList *find_schema_value_list(
  1943. StatsSchemaList *list, StatsProvider provider,
  1944. StatsTarget target)
  1945. {
  1946. StatsSchemaList *node;
  1947. for (node = list; node; node = node->next) {
  1948. if (node->value->provider == provider &&
  1949. node->value->target == target) {
  1950. return node->value->stats;
  1951. }
  1952. }
  1953. return NULL;
  1954. }
  1955. static void print_stats_results(Monitor *mon, StatsTarget target,
  1956. bool show_provider,
  1957. StatsResult *result,
  1958. StatsSchemaList *schema)
  1959. {
  1960. /* Find provider schema */
  1961. StatsSchemaValueList *schema_value_list =
  1962. find_schema_value_list(schema, result->provider, target);
  1963. StatsList *stats_list;
  1964. if (!schema_value_list) {
  1965. monitor_printf(mon, "failed to find schema list for %s\n",
  1966. StatsProvider_str(result->provider));
  1967. return;
  1968. }
  1969. if (show_provider) {
  1970. monitor_printf(mon, "provider: %s\n",
  1971. StatsProvider_str(result->provider));
  1972. }
  1973. for (stats_list = result->stats; stats_list;
  1974. stats_list = stats_list->next,
  1975. schema_value_list = schema_value_list->next) {
  1976. Stats *stats = stats_list->value;
  1977. StatsValue *stats_value = stats->value;
  1978. StatsSchemaValue *schema_value = schema_value_list->value;
  1979. /* Find schema entry */
  1980. while (!g_str_equal(stats->name, schema_value->name)) {
  1981. if (!schema_value_list->next) {
  1982. monitor_printf(mon, "failed to find schema entry for %s\n",
  1983. stats->name);
  1984. return;
  1985. }
  1986. schema_value_list = schema_value_list->next;
  1987. schema_value = schema_value_list->value;
  1988. }
  1989. print_stats_schema_value(mon, schema_value);
  1990. if (stats_value->type == QTYPE_QNUM) {
  1991. monitor_printf(mon, ": %" PRId64 "\n", stats_value->u.scalar);
  1992. } else if (stats_value->type == QTYPE_QBOOL) {
  1993. monitor_printf(mon, ": %s\n", stats_value->u.boolean ? "yes" : "no");
  1994. } else if (stats_value->type == QTYPE_QLIST) {
  1995. uint64List *list;
  1996. int i;
  1997. monitor_printf(mon, ": ");
  1998. for (list = stats_value->u.list, i = 1;
  1999. list;
  2000. list = list->next, i++) {
  2001. monitor_printf(mon, "[%d]=%" PRId64 " ", i, list->value);
  2002. }
  2003. monitor_printf(mon, "\n");
  2004. }
  2005. }
  2006. }
  2007. /* Create the StatsFilter that is needed for an "info stats" invocation. */
  2008. static StatsFilter *stats_filter(StatsTarget target, const char *names,
  2009. int cpu_index, StatsProvider provider)
  2010. {
  2011. StatsFilter *filter = g_malloc0(sizeof(*filter));
  2012. StatsProvider provider_idx;
  2013. StatsRequestList *request_list = NULL;
  2014. filter->target = target;
  2015. switch (target) {
  2016. case STATS_TARGET_VM:
  2017. break;
  2018. case STATS_TARGET_VCPU:
  2019. {
  2020. strList *vcpu_list = NULL;
  2021. CPUState *cpu = qemu_get_cpu(cpu_index);
  2022. char *canonical_path = object_get_canonical_path(OBJECT(cpu));
  2023. QAPI_LIST_PREPEND(vcpu_list, canonical_path);
  2024. filter->u.vcpu.has_vcpus = true;
  2025. filter->u.vcpu.vcpus = vcpu_list;
  2026. break;
  2027. }
  2028. default:
  2029. break;
  2030. }
  2031. if (!names && provider == STATS_PROVIDER__MAX) {
  2032. return filter;
  2033. }
  2034. /*
  2035. * "info stats" can only query either one or all the providers. Querying
  2036. * by name, but not by provider, requires the creation of one filter per
  2037. * provider.
  2038. */
  2039. for (provider_idx = 0; provider_idx < STATS_PROVIDER__MAX; provider_idx++) {
  2040. if (provider == STATS_PROVIDER__MAX || provider == provider_idx) {
  2041. StatsRequest *request = g_new0(StatsRequest, 1);
  2042. request->provider = provider_idx;
  2043. if (names && !g_str_equal(names, "*")) {
  2044. request->has_names = true;
  2045. request->names = strList_from_comma_list(names);
  2046. }
  2047. QAPI_LIST_PREPEND(request_list, request);
  2048. }
  2049. }
  2050. filter->has_providers = true;
  2051. filter->providers = request_list;
  2052. return filter;
  2053. }
  2054. void hmp_info_stats(Monitor *mon, const QDict *qdict)
  2055. {
  2056. const char *target_str = qdict_get_str(qdict, "target");
  2057. const char *provider_str = qdict_get_try_str(qdict, "provider");
  2058. const char *names = qdict_get_try_str(qdict, "names");
  2059. StatsProvider provider = STATS_PROVIDER__MAX;
  2060. StatsTarget target;
  2061. Error *err = NULL;
  2062. g_autoptr(StatsSchemaList) schema = NULL;
  2063. g_autoptr(StatsResultList) stats = NULL;
  2064. g_autoptr(StatsFilter) filter = NULL;
  2065. StatsResultList *entry;
  2066. target = qapi_enum_parse(&StatsTarget_lookup, target_str, -1, &err);
  2067. if (err) {
  2068. monitor_printf(mon, "invalid stats target %s\n", target_str);
  2069. goto exit_no_print;
  2070. }
  2071. if (provider_str) {
  2072. provider = qapi_enum_parse(&StatsProvider_lookup, provider_str, -1, &err);
  2073. if (err) {
  2074. monitor_printf(mon, "invalid stats provider %s\n", provider_str);
  2075. goto exit_no_print;
  2076. }
  2077. }
  2078. schema = qmp_query_stats_schemas(provider_str ? true : false,
  2079. provider, &err);
  2080. if (err) {
  2081. goto exit;
  2082. }
  2083. switch (target) {
  2084. case STATS_TARGET_VM:
  2085. filter = stats_filter(target, names, -1, provider);
  2086. break;
  2087. case STATS_TARGET_VCPU: {}
  2088. int cpu_index = monitor_get_cpu_index(mon);
  2089. filter = stats_filter(target, names, cpu_index, provider);
  2090. break;
  2091. default:
  2092. abort();
  2093. }
  2094. stats = qmp_query_stats(filter, &err);
  2095. if (err) {
  2096. goto exit;
  2097. }
  2098. for (entry = stats; entry; entry = entry->next) {
  2099. print_stats_results(mon, target, provider_str == NULL, entry->value, schema);
  2100. }
  2101. exit:
  2102. if (err) {
  2103. monitor_printf(mon, "%s\n", error_get_pretty(err));
  2104. }
  2105. exit_no_print:
  2106. error_free(err);
  2107. }
  2108. static void hmp_virtio_dump_protocols(Monitor *mon,
  2109. VhostDeviceProtocols *pcol)
  2110. {
  2111. strList *pcol_list = pcol->protocols;
  2112. while (pcol_list) {
  2113. monitor_printf(mon, "\t%s", pcol_list->value);
  2114. pcol_list = pcol_list->next;
  2115. if (pcol_list != NULL) {
  2116. monitor_printf(mon, ",\n");
  2117. }
  2118. }
  2119. monitor_printf(mon, "\n");
  2120. if (pcol->has_unknown_protocols) {
  2121. monitor_printf(mon, " unknown-protocols(0x%016"PRIx64")\n",
  2122. pcol->unknown_protocols);
  2123. }
  2124. }
  2125. static void hmp_virtio_dump_status(Monitor *mon,
  2126. VirtioDeviceStatus *status)
  2127. {
  2128. strList *status_list = status->statuses;
  2129. while (status_list) {
  2130. monitor_printf(mon, "\t%s", status_list->value);
  2131. status_list = status_list->next;
  2132. if (status_list != NULL) {
  2133. monitor_printf(mon, ",\n");
  2134. }
  2135. }
  2136. monitor_printf(mon, "\n");
  2137. if (status->has_unknown_statuses) {
  2138. monitor_printf(mon, " unknown-statuses(0x%016"PRIx32")\n",
  2139. status->unknown_statuses);
  2140. }
  2141. }
  2142. static void hmp_virtio_dump_features(Monitor *mon,
  2143. VirtioDeviceFeatures *features)
  2144. {
  2145. strList *transport_list = features->transports;
  2146. while (transport_list) {
  2147. monitor_printf(mon, "\t%s", transport_list->value);
  2148. transport_list = transport_list->next;
  2149. if (transport_list != NULL) {
  2150. monitor_printf(mon, ",\n");
  2151. }
  2152. }
  2153. monitor_printf(mon, "\n");
  2154. strList *list = features->dev_features;
  2155. if (list) {
  2156. while (list) {
  2157. monitor_printf(mon, "\t%s", list->value);
  2158. list = list->next;
  2159. if (list != NULL) {
  2160. monitor_printf(mon, ",\n");
  2161. }
  2162. }
  2163. monitor_printf(mon, "\n");
  2164. }
  2165. if (features->has_unknown_dev_features) {
  2166. monitor_printf(mon, " unknown-features(0x%016"PRIx64")\n",
  2167. features->unknown_dev_features);
  2168. }
  2169. }
  2170. void hmp_virtio_query(Monitor *mon, const QDict *qdict)
  2171. {
  2172. Error *err = NULL;
  2173. VirtioInfoList *list = qmp_x_query_virtio(&err);
  2174. VirtioInfoList *node;
  2175. if (err != NULL) {
  2176. hmp_handle_error(mon, err);
  2177. return;
  2178. }
  2179. if (list == NULL) {
  2180. monitor_printf(mon, "No VirtIO devices\n");
  2181. return;
  2182. }
  2183. node = list;
  2184. while (node) {
  2185. monitor_printf(mon, "%s [%s]\n", node->value->path,
  2186. node->value->name);
  2187. node = node->next;
  2188. }
  2189. qapi_free_VirtioInfoList(list);
  2190. }
  2191. void hmp_virtio_status(Monitor *mon, const QDict *qdict)
  2192. {
  2193. Error *err = NULL;
  2194. const char *path = qdict_get_try_str(qdict, "path");
  2195. VirtioStatus *s = qmp_x_query_virtio_status(path, &err);
  2196. if (err != NULL) {
  2197. hmp_handle_error(mon, err);
  2198. return;
  2199. }
  2200. monitor_printf(mon, "%s:\n", path);
  2201. monitor_printf(mon, " device_name: %s %s\n",
  2202. s->name, s->has_vhost_dev ? "(vhost)" : "");
  2203. monitor_printf(mon, " device_id: %d\n", s->device_id);
  2204. monitor_printf(mon, " vhost_started: %s\n",
  2205. s->vhost_started ? "true" : "false");
  2206. monitor_printf(mon, " bus_name: %s\n", s->bus_name);
  2207. monitor_printf(mon, " broken: %s\n",
  2208. s->broken ? "true" : "false");
  2209. monitor_printf(mon, " disabled: %s\n",
  2210. s->disabled ? "true" : "false");
  2211. monitor_printf(mon, " disable_legacy_check: %s\n",
  2212. s->disable_legacy_check ? "true" : "false");
  2213. monitor_printf(mon, " started: %s\n",
  2214. s->started ? "true" : "false");
  2215. monitor_printf(mon, " use_started: %s\n",
  2216. s->use_started ? "true" : "false");
  2217. monitor_printf(mon, " start_on_kick: %s\n",
  2218. s->start_on_kick ? "true" : "false");
  2219. monitor_printf(mon, " use_guest_notifier_mask: %s\n",
  2220. s->use_guest_notifier_mask ? "true" : "false");
  2221. monitor_printf(mon, " vm_running: %s\n",
  2222. s->vm_running ? "true" : "false");
  2223. monitor_printf(mon, " num_vqs: %"PRId64"\n", s->num_vqs);
  2224. monitor_printf(mon, " queue_sel: %d\n",
  2225. s->queue_sel);
  2226. monitor_printf(mon, " isr: %d\n", s->isr);
  2227. monitor_printf(mon, " endianness: %s\n",
  2228. s->device_endian);
  2229. monitor_printf(mon, " status:\n");
  2230. hmp_virtio_dump_status(mon, s->status);
  2231. monitor_printf(mon, " Guest features:\n");
  2232. hmp_virtio_dump_features(mon, s->guest_features);
  2233. monitor_printf(mon, " Host features:\n");
  2234. hmp_virtio_dump_features(mon, s->host_features);
  2235. monitor_printf(mon, " Backend features:\n");
  2236. hmp_virtio_dump_features(mon, s->backend_features);
  2237. if (s->has_vhost_dev) {
  2238. monitor_printf(mon, " VHost:\n");
  2239. monitor_printf(mon, " nvqs: %d\n",
  2240. s->vhost_dev->nvqs);
  2241. monitor_printf(mon, " vq_index: %"PRId64"\n",
  2242. s->vhost_dev->vq_index);
  2243. monitor_printf(mon, " max_queues: %"PRId64"\n",
  2244. s->vhost_dev->max_queues);
  2245. monitor_printf(mon, " n_mem_sections: %"PRId64"\n",
  2246. s->vhost_dev->n_mem_sections);
  2247. monitor_printf(mon, " n_tmp_sections: %"PRId64"\n",
  2248. s->vhost_dev->n_tmp_sections);
  2249. monitor_printf(mon, " backend_cap: %"PRId64"\n",
  2250. s->vhost_dev->backend_cap);
  2251. monitor_printf(mon, " log_enabled: %s\n",
  2252. s->vhost_dev->log_enabled ? "true" : "false");
  2253. monitor_printf(mon, " log_size: %"PRId64"\n",
  2254. s->vhost_dev->log_size);
  2255. monitor_printf(mon, " Features:\n");
  2256. hmp_virtio_dump_features(mon, s->vhost_dev->features);
  2257. monitor_printf(mon, " Acked features:\n");
  2258. hmp_virtio_dump_features(mon, s->vhost_dev->acked_features);
  2259. monitor_printf(mon, " Backend features:\n");
  2260. hmp_virtio_dump_features(mon, s->vhost_dev->backend_features);
  2261. monitor_printf(mon, " Protocol features:\n");
  2262. hmp_virtio_dump_protocols(mon, s->vhost_dev->protocol_features);
  2263. }
  2264. qapi_free_VirtioStatus(s);
  2265. }
  2266. void hmp_vhost_queue_status(Monitor *mon, const QDict *qdict)
  2267. {
  2268. Error *err = NULL;
  2269. const char *path = qdict_get_try_str(qdict, "path");
  2270. int queue = qdict_get_int(qdict, "queue");
  2271. VirtVhostQueueStatus *s =
  2272. qmp_x_query_virtio_vhost_queue_status(path, queue, &err);
  2273. if (err != NULL) {
  2274. hmp_handle_error(mon, err);
  2275. return;
  2276. }
  2277. monitor_printf(mon, "%s:\n", path);
  2278. monitor_printf(mon, " device_name: %s (vhost)\n",
  2279. s->name);
  2280. monitor_printf(mon, " kick: %"PRId64"\n", s->kick);
  2281. monitor_printf(mon, " call: %"PRId64"\n", s->call);
  2282. monitor_printf(mon, " VRing:\n");
  2283. monitor_printf(mon, " num: %"PRId64"\n", s->num);
  2284. monitor_printf(mon, " desc: 0x%016"PRIx64"\n", s->desc);
  2285. monitor_printf(mon, " desc_phys: 0x%016"PRIx64"\n",
  2286. s->desc_phys);
  2287. monitor_printf(mon, " desc_size: %"PRId32"\n", s->desc_size);
  2288. monitor_printf(mon, " avail: 0x%016"PRIx64"\n", s->avail);
  2289. monitor_printf(mon, " avail_phys: 0x%016"PRIx64"\n",
  2290. s->avail_phys);
  2291. monitor_printf(mon, " avail_size: %"PRId32"\n", s->avail_size);
  2292. monitor_printf(mon, " used: 0x%016"PRIx64"\n", s->used);
  2293. monitor_printf(mon, " used_phys: 0x%016"PRIx64"\n",
  2294. s->used_phys);
  2295. monitor_printf(mon, " used_size: %"PRId32"\n", s->used_size);
  2296. qapi_free_VirtVhostQueueStatus(s);
  2297. }
  2298. void hmp_virtio_queue_status(Monitor *mon, const QDict *qdict)
  2299. {
  2300. Error *err = NULL;
  2301. const char *path = qdict_get_try_str(qdict, "path");
  2302. int queue = qdict_get_int(qdict, "queue");
  2303. VirtQueueStatus *s = qmp_x_query_virtio_queue_status(path, queue, &err);
  2304. if (err != NULL) {
  2305. hmp_handle_error(mon, err);
  2306. return;
  2307. }
  2308. monitor_printf(mon, "%s:\n", path);
  2309. monitor_printf(mon, " device_name: %s\n", s->name);
  2310. monitor_printf(mon, " queue_index: %d\n", s->queue_index);
  2311. monitor_printf(mon, " inuse: %d\n", s->inuse);
  2312. monitor_printf(mon, " used_idx: %d\n", s->used_idx);
  2313. monitor_printf(mon, " signalled_used: %d\n",
  2314. s->signalled_used);
  2315. monitor_printf(mon, " signalled_used_valid: %s\n",
  2316. s->signalled_used_valid ? "true" : "false");
  2317. if (s->has_last_avail_idx) {
  2318. monitor_printf(mon, " last_avail_idx: %d\n",
  2319. s->last_avail_idx);
  2320. }
  2321. if (s->has_shadow_avail_idx) {
  2322. monitor_printf(mon, " shadow_avail_idx: %d\n",
  2323. s->shadow_avail_idx);
  2324. }
  2325. monitor_printf(mon, " VRing:\n");
  2326. monitor_printf(mon, " num: %"PRId32"\n", s->vring_num);
  2327. monitor_printf(mon, " num_default: %"PRId32"\n",
  2328. s->vring_num_default);
  2329. monitor_printf(mon, " align: %"PRId32"\n",
  2330. s->vring_align);
  2331. monitor_printf(mon, " desc: 0x%016"PRIx64"\n",
  2332. s->vring_desc);
  2333. monitor_printf(mon, " avail: 0x%016"PRIx64"\n",
  2334. s->vring_avail);
  2335. monitor_printf(mon, " used: 0x%016"PRIx64"\n",
  2336. s->vring_used);
  2337. qapi_free_VirtQueueStatus(s);
  2338. }
  2339. void hmp_virtio_queue_element(Monitor *mon, const QDict *qdict)
  2340. {
  2341. Error *err = NULL;
  2342. const char *path = qdict_get_try_str(qdict, "path");
  2343. int queue = qdict_get_int(qdict, "queue");
  2344. int index = qdict_get_try_int(qdict, "index", -1);
  2345. VirtioQueueElement *e;
  2346. VirtioRingDescList *list;
  2347. e = qmp_x_query_virtio_queue_element(path, queue, index != -1,
  2348. index, &err);
  2349. if (err != NULL) {
  2350. hmp_handle_error(mon, err);
  2351. return;
  2352. }
  2353. monitor_printf(mon, "%s:\n", path);
  2354. monitor_printf(mon, " device_name: %s\n", e->name);
  2355. monitor_printf(mon, " index: %d\n", e->index);
  2356. monitor_printf(mon, " desc:\n");
  2357. monitor_printf(mon, " descs:\n");
  2358. list = e->descs;
  2359. while (list) {
  2360. monitor_printf(mon, " addr 0x%"PRIx64" len %d",
  2361. list->value->addr, list->value->len);
  2362. if (list->value->flags) {
  2363. strList *flag = list->value->flags;
  2364. monitor_printf(mon, " (");
  2365. while (flag) {
  2366. monitor_printf(mon, "%s", flag->value);
  2367. flag = flag->next;
  2368. if (flag) {
  2369. monitor_printf(mon, ", ");
  2370. }
  2371. }
  2372. monitor_printf(mon, ")");
  2373. }
  2374. list = list->next;
  2375. if (list) {
  2376. monitor_printf(mon, ",\n");
  2377. }
  2378. }
  2379. monitor_printf(mon, "\n");
  2380. monitor_printf(mon, " avail:\n");
  2381. monitor_printf(mon, " flags: %d\n", e->avail->flags);
  2382. monitor_printf(mon, " idx: %d\n", e->avail->idx);
  2383. monitor_printf(mon, " ring: %d\n", e->avail->ring);
  2384. monitor_printf(mon, " used:\n");
  2385. monitor_printf(mon, " flags: %d\n", e->used->flags);
  2386. monitor_printf(mon, " idx: %d\n", e->used->idx);
  2387. qapi_free_VirtioQueueElement(e);
  2388. }