hmp-cmds.c 70 KB

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