You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hmp.c 97KB

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