2
0

hmp.c 80 KB

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