hmp.c 89 KB

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