hmp-cmds.c 70 KB

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