2
0

hmp-cmds.c 69 KB

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