2
0

options.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439
  1. /*
  2. * QEMU migration capabilities
  3. *
  4. * Copyright (c) 2012-2023 Red Hat Inc
  5. *
  6. * Authors:
  7. * Orit Wasserman <owasserm@redhat.com>
  8. * Juan Quintela <quintela@redhat.com>
  9. *
  10. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  11. * See the COPYING file in the top-level directory.
  12. */
  13. #include "qemu/osdep.h"
  14. #include "qemu/error-report.h"
  15. #include "exec/target_page.h"
  16. #include "qapi/clone-visitor.h"
  17. #include "qapi/error.h"
  18. #include "qapi/qapi-commands-migration.h"
  19. #include "qapi/qapi-visit-migration.h"
  20. #include "qapi/qmp/qerror.h"
  21. #include "qobject/qnull.h"
  22. #include "system/runstate.h"
  23. #include "migration/colo.h"
  24. #include "migration/cpr.h"
  25. #include "migration/misc.h"
  26. #include "migration.h"
  27. #include "migration-stats.h"
  28. #include "qemu-file.h"
  29. #include "ram.h"
  30. #include "options.h"
  31. #include "system/kvm.h"
  32. /* Maximum migrate downtime set to 2000 seconds */
  33. #define MAX_MIGRATE_DOWNTIME_SECONDS 2000
  34. #define MAX_MIGRATE_DOWNTIME (MAX_MIGRATE_DOWNTIME_SECONDS * 1000)
  35. #define MAX_THROTTLE (128 << 20) /* Migration transfer speed throttling */
  36. /* Time in milliseconds we are allowed to stop the source,
  37. * for sending the last part */
  38. #define DEFAULT_MIGRATE_SET_DOWNTIME 300
  39. /* Define default autoconverge cpu throttle migration parameters */
  40. #define DEFAULT_MIGRATE_THROTTLE_TRIGGER_THRESHOLD 50
  41. #define DEFAULT_MIGRATE_CPU_THROTTLE_INITIAL 20
  42. #define DEFAULT_MIGRATE_CPU_THROTTLE_INCREMENT 10
  43. #define DEFAULT_MIGRATE_MAX_CPU_THROTTLE 99
  44. /* Migration XBZRLE default cache size */
  45. #define DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE (64 * 1024 * 1024)
  46. /* The delay time (in ms) between two COLO checkpoints */
  47. #define DEFAULT_MIGRATE_X_CHECKPOINT_DELAY (200 * 100)
  48. #define DEFAULT_MIGRATE_MULTIFD_CHANNELS 2
  49. #define DEFAULT_MIGRATE_MULTIFD_COMPRESSION MULTIFD_COMPRESSION_NONE
  50. /* 0: means nocompress, 1: best speed, ... 9: best compress ratio */
  51. #define DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL 1
  52. /*
  53. * 1: best speed, ... 9: best compress ratio
  54. * There is some nuance here. Refer to QATzip documentation to understand
  55. * the mapping of QATzip levels to standard deflate levels.
  56. */
  57. #define DEFAULT_MIGRATE_MULTIFD_QATZIP_LEVEL 1
  58. /* 0: means nocompress, 1: best speed, ... 20: best compress ratio */
  59. #define DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL 1
  60. /* Background transfer rate for postcopy, 0 means unlimited, note
  61. * that page requests can still exceed this limit.
  62. */
  63. #define DEFAULT_MIGRATE_MAX_POSTCOPY_BANDWIDTH 0
  64. /*
  65. * Parameters for self_announce_delay giving a stream of RARP/ARP
  66. * packets after migration.
  67. */
  68. #define DEFAULT_MIGRATE_ANNOUNCE_INITIAL 50
  69. #define DEFAULT_MIGRATE_ANNOUNCE_MAX 550
  70. #define DEFAULT_MIGRATE_ANNOUNCE_ROUNDS 5
  71. #define DEFAULT_MIGRATE_ANNOUNCE_STEP 100
  72. #define DEFINE_PROP_MIG_CAP(name, x) \
  73. DEFINE_PROP_BOOL(name, MigrationState, capabilities[x], false)
  74. #define DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD 1000 /* milliseconds */
  75. #define DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT 1 /* MB/s */
  76. const Property migration_properties[] = {
  77. DEFINE_PROP_BOOL("store-global-state", MigrationState,
  78. store_global_state, true),
  79. DEFINE_PROP_BOOL("send-configuration", MigrationState,
  80. send_configuration, true),
  81. DEFINE_PROP_BOOL("send-section-footer", MigrationState,
  82. send_section_footer, true),
  83. DEFINE_PROP_BOOL("send-switchover-start", MigrationState,
  84. send_switchover_start, true),
  85. DEFINE_PROP_BOOL("multifd-flush-after-each-section", MigrationState,
  86. multifd_flush_after_each_section, false),
  87. DEFINE_PROP_UINT8("x-clear-bitmap-shift", MigrationState,
  88. clear_bitmap_shift, CLEAR_BITMAP_SHIFT_DEFAULT),
  89. DEFINE_PROP_BOOL("x-preempt-pre-7-2", MigrationState,
  90. preempt_pre_7_2, false),
  91. DEFINE_PROP_BOOL("multifd-clean-tls-termination", MigrationState,
  92. multifd_clean_tls_termination, true),
  93. /* Migration parameters */
  94. DEFINE_PROP_UINT8("x-throttle-trigger-threshold", MigrationState,
  95. parameters.throttle_trigger_threshold,
  96. DEFAULT_MIGRATE_THROTTLE_TRIGGER_THRESHOLD),
  97. DEFINE_PROP_UINT8("x-cpu-throttle-initial", MigrationState,
  98. parameters.cpu_throttle_initial,
  99. DEFAULT_MIGRATE_CPU_THROTTLE_INITIAL),
  100. DEFINE_PROP_UINT8("x-cpu-throttle-increment", MigrationState,
  101. parameters.cpu_throttle_increment,
  102. DEFAULT_MIGRATE_CPU_THROTTLE_INCREMENT),
  103. DEFINE_PROP_BOOL("x-cpu-throttle-tailslow", MigrationState,
  104. parameters.cpu_throttle_tailslow, false),
  105. DEFINE_PROP_SIZE("x-max-bandwidth", MigrationState,
  106. parameters.max_bandwidth, MAX_THROTTLE),
  107. DEFINE_PROP_SIZE("avail-switchover-bandwidth", MigrationState,
  108. parameters.avail_switchover_bandwidth, 0),
  109. DEFINE_PROP_UINT64("x-downtime-limit", MigrationState,
  110. parameters.downtime_limit,
  111. DEFAULT_MIGRATE_SET_DOWNTIME),
  112. DEFINE_PROP_UINT32("x-checkpoint-delay", MigrationState,
  113. parameters.x_checkpoint_delay,
  114. DEFAULT_MIGRATE_X_CHECKPOINT_DELAY),
  115. DEFINE_PROP_UINT8("multifd-channels", MigrationState,
  116. parameters.multifd_channels,
  117. DEFAULT_MIGRATE_MULTIFD_CHANNELS),
  118. DEFINE_PROP_MULTIFD_COMPRESSION("multifd-compression", MigrationState,
  119. parameters.multifd_compression,
  120. DEFAULT_MIGRATE_MULTIFD_COMPRESSION),
  121. DEFINE_PROP_UINT8("multifd-zlib-level", MigrationState,
  122. parameters.multifd_zlib_level,
  123. DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL),
  124. DEFINE_PROP_UINT8("multifd-qatzip-level", MigrationState,
  125. parameters.multifd_qatzip_level,
  126. DEFAULT_MIGRATE_MULTIFD_QATZIP_LEVEL),
  127. DEFINE_PROP_UINT8("multifd-zstd-level", MigrationState,
  128. parameters.multifd_zstd_level,
  129. DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL),
  130. DEFINE_PROP_SIZE("xbzrle-cache-size", MigrationState,
  131. parameters.xbzrle_cache_size,
  132. DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE),
  133. DEFINE_PROP_SIZE("max-postcopy-bandwidth", MigrationState,
  134. parameters.max_postcopy_bandwidth,
  135. DEFAULT_MIGRATE_MAX_POSTCOPY_BANDWIDTH),
  136. DEFINE_PROP_UINT8("max-cpu-throttle", MigrationState,
  137. parameters.max_cpu_throttle,
  138. DEFAULT_MIGRATE_MAX_CPU_THROTTLE),
  139. DEFINE_PROP_SIZE("announce-initial", MigrationState,
  140. parameters.announce_initial,
  141. DEFAULT_MIGRATE_ANNOUNCE_INITIAL),
  142. DEFINE_PROP_SIZE("announce-max", MigrationState,
  143. parameters.announce_max,
  144. DEFAULT_MIGRATE_ANNOUNCE_MAX),
  145. DEFINE_PROP_SIZE("announce-rounds", MigrationState,
  146. parameters.announce_rounds,
  147. DEFAULT_MIGRATE_ANNOUNCE_ROUNDS),
  148. DEFINE_PROP_SIZE("announce-step", MigrationState,
  149. parameters.announce_step,
  150. DEFAULT_MIGRATE_ANNOUNCE_STEP),
  151. DEFINE_PROP_STRING("tls-creds", MigrationState, parameters.tls_creds),
  152. DEFINE_PROP_STRING("tls-hostname", MigrationState, parameters.tls_hostname),
  153. DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz),
  154. DEFINE_PROP_UINT64("x-vcpu-dirty-limit-period", MigrationState,
  155. parameters.x_vcpu_dirty_limit_period,
  156. DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD),
  157. DEFINE_PROP_UINT64("vcpu-dirty-limit", MigrationState,
  158. parameters.vcpu_dirty_limit,
  159. DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT),
  160. DEFINE_PROP_MIG_MODE("mode", MigrationState,
  161. parameters.mode,
  162. MIG_MODE_NORMAL),
  163. DEFINE_PROP_ZERO_PAGE_DETECTION("zero-page-detection", MigrationState,
  164. parameters.zero_page_detection,
  165. ZERO_PAGE_DETECTION_MULTIFD),
  166. /* Migration capabilities */
  167. DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE),
  168. DEFINE_PROP_MIG_CAP("x-rdma-pin-all", MIGRATION_CAPABILITY_RDMA_PIN_ALL),
  169. DEFINE_PROP_MIG_CAP("x-auto-converge", MIGRATION_CAPABILITY_AUTO_CONVERGE),
  170. DEFINE_PROP_MIG_CAP("x-zero-blocks", MIGRATION_CAPABILITY_ZERO_BLOCKS),
  171. DEFINE_PROP_MIG_CAP("x-events", MIGRATION_CAPABILITY_EVENTS),
  172. DEFINE_PROP_MIG_CAP("x-postcopy-ram", MIGRATION_CAPABILITY_POSTCOPY_RAM),
  173. DEFINE_PROP_MIG_CAP("x-postcopy-preempt",
  174. MIGRATION_CAPABILITY_POSTCOPY_PREEMPT),
  175. DEFINE_PROP_MIG_CAP("x-colo", MIGRATION_CAPABILITY_X_COLO),
  176. DEFINE_PROP_MIG_CAP("x-release-ram", MIGRATION_CAPABILITY_RELEASE_RAM),
  177. DEFINE_PROP_MIG_CAP("x-return-path", MIGRATION_CAPABILITY_RETURN_PATH),
  178. DEFINE_PROP_MIG_CAP("x-multifd", MIGRATION_CAPABILITY_MULTIFD),
  179. DEFINE_PROP_MIG_CAP("x-background-snapshot",
  180. MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT),
  181. #ifdef CONFIG_LINUX
  182. DEFINE_PROP_MIG_CAP("x-zero-copy-send",
  183. MIGRATION_CAPABILITY_ZERO_COPY_SEND),
  184. #endif
  185. DEFINE_PROP_MIG_CAP("x-switchover-ack",
  186. MIGRATION_CAPABILITY_SWITCHOVER_ACK),
  187. DEFINE_PROP_MIG_CAP("x-dirty-limit", MIGRATION_CAPABILITY_DIRTY_LIMIT),
  188. DEFINE_PROP_MIG_CAP("mapped-ram", MIGRATION_CAPABILITY_MAPPED_RAM),
  189. };
  190. const size_t migration_properties_count = ARRAY_SIZE(migration_properties);
  191. bool migrate_auto_converge(void)
  192. {
  193. MigrationState *s = migrate_get_current();
  194. return s->capabilities[MIGRATION_CAPABILITY_AUTO_CONVERGE];
  195. }
  196. bool migrate_send_switchover_start(void)
  197. {
  198. MigrationState *s = migrate_get_current();
  199. return s->send_switchover_start;
  200. }
  201. bool migrate_background_snapshot(void)
  202. {
  203. MigrationState *s = migrate_get_current();
  204. return s->capabilities[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT];
  205. }
  206. bool migrate_colo(void)
  207. {
  208. MigrationState *s = migrate_get_current();
  209. return s->capabilities[MIGRATION_CAPABILITY_X_COLO];
  210. }
  211. bool migrate_dirty_bitmaps(void)
  212. {
  213. MigrationState *s = migrate_get_current();
  214. return s->capabilities[MIGRATION_CAPABILITY_DIRTY_BITMAPS];
  215. }
  216. bool migrate_dirty_limit(void)
  217. {
  218. MigrationState *s = migrate_get_current();
  219. return s->capabilities[MIGRATION_CAPABILITY_DIRTY_LIMIT];
  220. }
  221. bool migrate_events(void)
  222. {
  223. MigrationState *s = migrate_get_current();
  224. return s->capabilities[MIGRATION_CAPABILITY_EVENTS];
  225. }
  226. bool migrate_mapped_ram(void)
  227. {
  228. MigrationState *s = migrate_get_current();
  229. return s->capabilities[MIGRATION_CAPABILITY_MAPPED_RAM];
  230. }
  231. bool migrate_ignore_shared(void)
  232. {
  233. MigrationState *s = migrate_get_current();
  234. return s->capabilities[MIGRATION_CAPABILITY_X_IGNORE_SHARED];
  235. }
  236. bool migrate_late_block_activate(void)
  237. {
  238. MigrationState *s = migrate_get_current();
  239. return s->capabilities[MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE];
  240. }
  241. bool migrate_multifd(void)
  242. {
  243. MigrationState *s = migrate_get_current();
  244. return s->capabilities[MIGRATION_CAPABILITY_MULTIFD];
  245. }
  246. bool migrate_pause_before_switchover(void)
  247. {
  248. MigrationState *s = migrate_get_current();
  249. return s->capabilities[MIGRATION_CAPABILITY_PAUSE_BEFORE_SWITCHOVER];
  250. }
  251. bool migrate_postcopy_blocktime(void)
  252. {
  253. MigrationState *s = migrate_get_current();
  254. return s->capabilities[MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME];
  255. }
  256. bool migrate_postcopy_preempt(void)
  257. {
  258. MigrationState *s = migrate_get_current();
  259. return s->capabilities[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT];
  260. }
  261. bool migrate_postcopy_ram(void)
  262. {
  263. MigrationState *s = migrate_get_current();
  264. return s->capabilities[MIGRATION_CAPABILITY_POSTCOPY_RAM];
  265. }
  266. bool migrate_rdma_pin_all(void)
  267. {
  268. MigrationState *s = migrate_get_current();
  269. return s->capabilities[MIGRATION_CAPABILITY_RDMA_PIN_ALL];
  270. }
  271. bool migrate_release_ram(void)
  272. {
  273. MigrationState *s = migrate_get_current();
  274. return s->capabilities[MIGRATION_CAPABILITY_RELEASE_RAM];
  275. }
  276. bool migrate_return_path(void)
  277. {
  278. MigrationState *s = migrate_get_current();
  279. return s->capabilities[MIGRATION_CAPABILITY_RETURN_PATH];
  280. }
  281. bool migrate_switchover_ack(void)
  282. {
  283. MigrationState *s = migrate_get_current();
  284. return s->capabilities[MIGRATION_CAPABILITY_SWITCHOVER_ACK];
  285. }
  286. bool migrate_validate_uuid(void)
  287. {
  288. MigrationState *s = migrate_get_current();
  289. return s->capabilities[MIGRATION_CAPABILITY_VALIDATE_UUID];
  290. }
  291. bool migrate_xbzrle(void)
  292. {
  293. MigrationState *s = migrate_get_current();
  294. return s->capabilities[MIGRATION_CAPABILITY_XBZRLE];
  295. }
  296. bool migrate_zero_copy_send(void)
  297. {
  298. MigrationState *s = migrate_get_current();
  299. return s->capabilities[MIGRATION_CAPABILITY_ZERO_COPY_SEND];
  300. }
  301. /* pseudo capabilities */
  302. bool migrate_multifd_flush_after_each_section(void)
  303. {
  304. MigrationState *s = migrate_get_current();
  305. return s->multifd_flush_after_each_section;
  306. }
  307. bool migrate_postcopy(void)
  308. {
  309. return migrate_postcopy_ram() || migrate_dirty_bitmaps();
  310. }
  311. bool migrate_rdma(void)
  312. {
  313. MigrationState *s = migrate_get_current();
  314. return s->rdma_migration;
  315. }
  316. bool migrate_tls(void)
  317. {
  318. MigrationState *s = migrate_get_current();
  319. return s->parameters.tls_creds && *s->parameters.tls_creds;
  320. }
  321. typedef enum WriteTrackingSupport {
  322. WT_SUPPORT_UNKNOWN = 0,
  323. WT_SUPPORT_ABSENT,
  324. WT_SUPPORT_AVAILABLE,
  325. WT_SUPPORT_COMPATIBLE
  326. } WriteTrackingSupport;
  327. static
  328. WriteTrackingSupport migrate_query_write_tracking(void)
  329. {
  330. /* Check if kernel supports required UFFD features */
  331. if (!ram_write_tracking_available()) {
  332. return WT_SUPPORT_ABSENT;
  333. }
  334. /*
  335. * Check if current memory configuration is
  336. * compatible with required UFFD features.
  337. */
  338. if (!ram_write_tracking_compatible()) {
  339. return WT_SUPPORT_AVAILABLE;
  340. }
  341. return WT_SUPPORT_COMPATIBLE;
  342. }
  343. /* Migration capabilities set */
  344. struct MigrateCapsSet {
  345. int size; /* Capability set size */
  346. MigrationCapability caps[]; /* Variadic array of capabilities */
  347. };
  348. typedef struct MigrateCapsSet MigrateCapsSet;
  349. /* Define and initialize MigrateCapsSet */
  350. #define INITIALIZE_MIGRATE_CAPS_SET(_name, ...) \
  351. MigrateCapsSet _name = { \
  352. .size = sizeof((int []) { __VA_ARGS__ }) / sizeof(int), \
  353. .caps = { __VA_ARGS__ } \
  354. }
  355. /* Background-snapshot compatibility check list */
  356. static const
  357. INITIALIZE_MIGRATE_CAPS_SET(check_caps_background_snapshot,
  358. MIGRATION_CAPABILITY_POSTCOPY_RAM,
  359. MIGRATION_CAPABILITY_DIRTY_BITMAPS,
  360. MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME,
  361. MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE,
  362. MIGRATION_CAPABILITY_RETURN_PATH,
  363. MIGRATION_CAPABILITY_MULTIFD,
  364. MIGRATION_CAPABILITY_PAUSE_BEFORE_SWITCHOVER,
  365. MIGRATION_CAPABILITY_AUTO_CONVERGE,
  366. MIGRATION_CAPABILITY_RELEASE_RAM,
  367. MIGRATION_CAPABILITY_RDMA_PIN_ALL,
  368. MIGRATION_CAPABILITY_XBZRLE,
  369. MIGRATION_CAPABILITY_X_COLO,
  370. MIGRATION_CAPABILITY_VALIDATE_UUID,
  371. MIGRATION_CAPABILITY_ZERO_COPY_SEND);
  372. static bool migrate_incoming_started(void)
  373. {
  374. return !!migration_incoming_get_current()->transport_data;
  375. }
  376. /**
  377. * @migration_caps_check - check capability compatibility
  378. *
  379. * @old_caps: old capability list
  380. * @new_caps: new capability list
  381. * @errp: set *errp if the check failed, with reason
  382. *
  383. * Returns true if check passed, otherwise false.
  384. */
  385. bool migrate_caps_check(bool *old_caps, bool *new_caps, Error **errp)
  386. {
  387. ERRP_GUARD();
  388. MigrationIncomingState *mis = migration_incoming_get_current();
  389. if (new_caps[MIGRATION_CAPABILITY_ZERO_BLOCKS]) {
  390. warn_report("zero-blocks capability is deprecated");
  391. }
  392. #ifndef CONFIG_REPLICATION
  393. if (new_caps[MIGRATION_CAPABILITY_X_COLO]) {
  394. error_setg(errp, "QEMU compiled without replication module"
  395. " can't enable COLO");
  396. error_append_hint(errp, "Please enable replication before COLO.\n");
  397. return false;
  398. }
  399. #endif
  400. if (new_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM]) {
  401. /* This check is reasonably expensive, so only when it's being
  402. * set the first time, also it's only the destination that needs
  403. * special support.
  404. */
  405. if (!old_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM] &&
  406. runstate_check(RUN_STATE_INMIGRATE) &&
  407. !postcopy_ram_supported_by_host(mis, errp)) {
  408. error_prepend(errp, "Postcopy is not supported: ");
  409. return false;
  410. }
  411. if (new_caps[MIGRATION_CAPABILITY_X_IGNORE_SHARED]) {
  412. error_setg(errp, "Postcopy is not compatible with ignore-shared");
  413. return false;
  414. }
  415. if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) {
  416. error_setg(errp, "Postcopy is not yet compatible with multifd");
  417. return false;
  418. }
  419. }
  420. if (new_caps[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT]) {
  421. WriteTrackingSupport wt_support;
  422. int idx;
  423. /*
  424. * Check if 'background-snapshot' capability is supported by
  425. * host kernel and compatible with guest memory configuration.
  426. */
  427. wt_support = migrate_query_write_tracking();
  428. if (wt_support < WT_SUPPORT_AVAILABLE) {
  429. error_setg(errp, "Background-snapshot is not supported by host kernel");
  430. return false;
  431. }
  432. if (wt_support < WT_SUPPORT_COMPATIBLE) {
  433. error_setg(errp, "Background-snapshot is not compatible "
  434. "with guest memory configuration");
  435. return false;
  436. }
  437. /*
  438. * Check if there are any migration capabilities
  439. * incompatible with 'background-snapshot'.
  440. */
  441. for (idx = 0; idx < check_caps_background_snapshot.size; idx++) {
  442. int incomp_cap = check_caps_background_snapshot.caps[idx];
  443. if (new_caps[incomp_cap]) {
  444. error_setg(errp,
  445. "Background-snapshot is not compatible with %s",
  446. MigrationCapability_str(incomp_cap));
  447. return false;
  448. }
  449. }
  450. }
  451. #ifdef CONFIG_LINUX
  452. if (new_caps[MIGRATION_CAPABILITY_ZERO_COPY_SEND] &&
  453. (!new_caps[MIGRATION_CAPABILITY_MULTIFD] ||
  454. new_caps[MIGRATION_CAPABILITY_XBZRLE] ||
  455. migrate_multifd_compression() ||
  456. migrate_tls())) {
  457. error_setg(errp,
  458. "Zero copy only available for non-compressed non-TLS multifd migration");
  459. return false;
  460. }
  461. #else
  462. if (new_caps[MIGRATION_CAPABILITY_ZERO_COPY_SEND]) {
  463. error_setg(errp,
  464. "Zero copy currently only available on Linux");
  465. return false;
  466. }
  467. #endif
  468. if (new_caps[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT]) {
  469. if (!new_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM]) {
  470. error_setg(errp, "Postcopy preempt requires postcopy-ram");
  471. return false;
  472. }
  473. if (!migrate_postcopy_preempt() && migrate_incoming_started()) {
  474. error_setg(errp,
  475. "Postcopy preempt must be set before incoming starts");
  476. return false;
  477. }
  478. }
  479. if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) {
  480. if (!migrate_multifd() && migrate_incoming_started()) {
  481. error_setg(errp, "Multifd must be set before incoming starts");
  482. return false;
  483. }
  484. }
  485. if (new_caps[MIGRATION_CAPABILITY_SWITCHOVER_ACK]) {
  486. if (!new_caps[MIGRATION_CAPABILITY_RETURN_PATH]) {
  487. error_setg(errp, "Capability 'switchover-ack' requires capability "
  488. "'return-path'");
  489. return false;
  490. }
  491. }
  492. if (new_caps[MIGRATION_CAPABILITY_DIRTY_LIMIT]) {
  493. if (new_caps[MIGRATION_CAPABILITY_AUTO_CONVERGE]) {
  494. error_setg(errp, "dirty-limit conflicts with auto-converge"
  495. " either of then available currently");
  496. return false;
  497. }
  498. if (!kvm_enabled() || !kvm_dirty_ring_enabled()) {
  499. error_setg(errp, "dirty-limit requires KVM with accelerator"
  500. " property 'dirty-ring-size' set");
  501. return false;
  502. }
  503. }
  504. if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) {
  505. if (new_caps[MIGRATION_CAPABILITY_XBZRLE]) {
  506. error_setg(errp, "Multifd is not compatible with xbzrle");
  507. return false;
  508. }
  509. }
  510. if (new_caps[MIGRATION_CAPABILITY_MAPPED_RAM]) {
  511. if (new_caps[MIGRATION_CAPABILITY_XBZRLE]) {
  512. error_setg(errp,
  513. "Mapped-ram migration is incompatible with xbzrle");
  514. return false;
  515. }
  516. if (new_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM]) {
  517. error_setg(errp,
  518. "Mapped-ram migration is incompatible with postcopy");
  519. return false;
  520. }
  521. }
  522. return true;
  523. }
  524. MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp)
  525. {
  526. MigrationCapabilityStatusList *head = NULL, **tail = &head;
  527. MigrationCapabilityStatus *caps;
  528. MigrationState *s = migrate_get_current();
  529. int i;
  530. for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
  531. caps = g_malloc0(sizeof(*caps));
  532. caps->capability = i;
  533. caps->state = s->capabilities[i];
  534. QAPI_LIST_APPEND(tail, caps);
  535. }
  536. return head;
  537. }
  538. void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
  539. Error **errp)
  540. {
  541. MigrationState *s = migrate_get_current();
  542. MigrationCapabilityStatusList *cap;
  543. bool new_caps[MIGRATION_CAPABILITY__MAX];
  544. if (migration_is_running() || migration_in_colo_state()) {
  545. error_setg(errp, "There's a migration process in progress");
  546. return;
  547. }
  548. memcpy(new_caps, s->capabilities, sizeof(new_caps));
  549. for (cap = params; cap; cap = cap->next) {
  550. new_caps[cap->value->capability] = cap->value->state;
  551. }
  552. if (!migrate_caps_check(s->capabilities, new_caps, errp)) {
  553. return;
  554. }
  555. for (cap = params; cap; cap = cap->next) {
  556. s->capabilities[cap->value->capability] = cap->value->state;
  557. }
  558. }
  559. /* parameters */
  560. const BitmapMigrationNodeAliasList *migrate_block_bitmap_mapping(void)
  561. {
  562. MigrationState *s = migrate_get_current();
  563. return s->parameters.block_bitmap_mapping;
  564. }
  565. bool migrate_has_block_bitmap_mapping(void)
  566. {
  567. MigrationState *s = migrate_get_current();
  568. return s->parameters.has_block_bitmap_mapping;
  569. }
  570. uint32_t migrate_checkpoint_delay(void)
  571. {
  572. MigrationState *s = migrate_get_current();
  573. return s->parameters.x_checkpoint_delay;
  574. }
  575. uint8_t migrate_cpu_throttle_increment(void)
  576. {
  577. MigrationState *s = migrate_get_current();
  578. return s->parameters.cpu_throttle_increment;
  579. }
  580. uint8_t migrate_cpu_throttle_initial(void)
  581. {
  582. MigrationState *s = migrate_get_current();
  583. return s->parameters.cpu_throttle_initial;
  584. }
  585. bool migrate_cpu_throttle_tailslow(void)
  586. {
  587. MigrationState *s = migrate_get_current();
  588. return s->parameters.cpu_throttle_tailslow;
  589. }
  590. bool migrate_direct_io(void)
  591. {
  592. MigrationState *s = migrate_get_current();
  593. /*
  594. * O_DIRECT is only supported with mapped-ram and multifd.
  595. *
  596. * mapped-ram is needed because filesystems impose restrictions on
  597. * O_DIRECT IO alignment (see MAPPED_RAM_FILE_OFFSET_ALIGNMENT).
  598. *
  599. * multifd is needed to keep the unaligned portion of the stream
  600. * isolated to the main migration thread while multifd channels
  601. * process the aligned data with O_DIRECT enabled.
  602. */
  603. return s->parameters.direct_io &&
  604. s->capabilities[MIGRATION_CAPABILITY_MAPPED_RAM] &&
  605. s->capabilities[MIGRATION_CAPABILITY_MULTIFD];
  606. }
  607. uint64_t migrate_downtime_limit(void)
  608. {
  609. MigrationState *s = migrate_get_current();
  610. return s->parameters.downtime_limit;
  611. }
  612. uint8_t migrate_max_cpu_throttle(void)
  613. {
  614. MigrationState *s = migrate_get_current();
  615. return s->parameters.max_cpu_throttle;
  616. }
  617. uint64_t migrate_max_bandwidth(void)
  618. {
  619. MigrationState *s = migrate_get_current();
  620. return s->parameters.max_bandwidth;
  621. }
  622. uint64_t migrate_avail_switchover_bandwidth(void)
  623. {
  624. MigrationState *s = migrate_get_current();
  625. return s->parameters.avail_switchover_bandwidth;
  626. }
  627. uint64_t migrate_max_postcopy_bandwidth(void)
  628. {
  629. MigrationState *s = migrate_get_current();
  630. return s->parameters.max_postcopy_bandwidth;
  631. }
  632. MigMode migrate_mode(void)
  633. {
  634. MigMode mode = cpr_get_incoming_mode();
  635. if (mode == MIG_MODE_NONE) {
  636. mode = migrate_get_current()->parameters.mode;
  637. }
  638. assert(mode >= 0 && mode < MIG_MODE__MAX);
  639. return mode;
  640. }
  641. int migrate_multifd_channels(void)
  642. {
  643. MigrationState *s = migrate_get_current();
  644. return s->parameters.multifd_channels;
  645. }
  646. MultiFDCompression migrate_multifd_compression(void)
  647. {
  648. MigrationState *s = migrate_get_current();
  649. assert(s->parameters.multifd_compression < MULTIFD_COMPRESSION__MAX);
  650. return s->parameters.multifd_compression;
  651. }
  652. int migrate_multifd_zlib_level(void)
  653. {
  654. MigrationState *s = migrate_get_current();
  655. return s->parameters.multifd_zlib_level;
  656. }
  657. int migrate_multifd_qatzip_level(void)
  658. {
  659. MigrationState *s = migrate_get_current();
  660. return s->parameters.multifd_qatzip_level;
  661. }
  662. int migrate_multifd_zstd_level(void)
  663. {
  664. MigrationState *s = migrate_get_current();
  665. return s->parameters.multifd_zstd_level;
  666. }
  667. uint8_t migrate_throttle_trigger_threshold(void)
  668. {
  669. MigrationState *s = migrate_get_current();
  670. return s->parameters.throttle_trigger_threshold;
  671. }
  672. const char *migrate_tls_authz(void)
  673. {
  674. MigrationState *s = migrate_get_current();
  675. return s->parameters.tls_authz;
  676. }
  677. const char *migrate_tls_creds(void)
  678. {
  679. MigrationState *s = migrate_get_current();
  680. return s->parameters.tls_creds;
  681. }
  682. const char *migrate_tls_hostname(void)
  683. {
  684. MigrationState *s = migrate_get_current();
  685. return s->parameters.tls_hostname;
  686. }
  687. uint64_t migrate_vcpu_dirty_limit_period(void)
  688. {
  689. MigrationState *s = migrate_get_current();
  690. return s->parameters.x_vcpu_dirty_limit_period;
  691. }
  692. uint64_t migrate_xbzrle_cache_size(void)
  693. {
  694. MigrationState *s = migrate_get_current();
  695. return s->parameters.xbzrle_cache_size;
  696. }
  697. ZeroPageDetection migrate_zero_page_detection(void)
  698. {
  699. MigrationState *s = migrate_get_current();
  700. return s->parameters.zero_page_detection;
  701. }
  702. /* parameters helpers */
  703. AnnounceParameters *migrate_announce_params(void)
  704. {
  705. static AnnounceParameters ap;
  706. MigrationState *s = migrate_get_current();
  707. ap.initial = s->parameters.announce_initial;
  708. ap.max = s->parameters.announce_max;
  709. ap.rounds = s->parameters.announce_rounds;
  710. ap.step = s->parameters.announce_step;
  711. return &ap;
  712. }
  713. MigrationParameters *qmp_query_migrate_parameters(Error **errp)
  714. {
  715. MigrationParameters *params;
  716. MigrationState *s = migrate_get_current();
  717. /* TODO use QAPI_CLONE() instead of duplicating it inline */
  718. params = g_malloc0(sizeof(*params));
  719. params->has_throttle_trigger_threshold = true;
  720. params->throttle_trigger_threshold = s->parameters.throttle_trigger_threshold;
  721. params->has_cpu_throttle_initial = true;
  722. params->cpu_throttle_initial = s->parameters.cpu_throttle_initial;
  723. params->has_cpu_throttle_increment = true;
  724. params->cpu_throttle_increment = s->parameters.cpu_throttle_increment;
  725. params->has_cpu_throttle_tailslow = true;
  726. params->cpu_throttle_tailslow = s->parameters.cpu_throttle_tailslow;
  727. params->tls_creds = g_strdup(s->parameters.tls_creds);
  728. params->tls_hostname = g_strdup(s->parameters.tls_hostname);
  729. params->tls_authz = g_strdup(s->parameters.tls_authz ?
  730. s->parameters.tls_authz : "");
  731. params->has_max_bandwidth = true;
  732. params->max_bandwidth = s->parameters.max_bandwidth;
  733. params->has_avail_switchover_bandwidth = true;
  734. params->avail_switchover_bandwidth = s->parameters.avail_switchover_bandwidth;
  735. params->has_downtime_limit = true;
  736. params->downtime_limit = s->parameters.downtime_limit;
  737. params->has_x_checkpoint_delay = true;
  738. params->x_checkpoint_delay = s->parameters.x_checkpoint_delay;
  739. params->has_multifd_channels = true;
  740. params->multifd_channels = s->parameters.multifd_channels;
  741. params->has_multifd_compression = true;
  742. params->multifd_compression = s->parameters.multifd_compression;
  743. params->has_multifd_zlib_level = true;
  744. params->multifd_zlib_level = s->parameters.multifd_zlib_level;
  745. params->has_multifd_qatzip_level = true;
  746. params->multifd_qatzip_level = s->parameters.multifd_qatzip_level;
  747. params->has_multifd_zstd_level = true;
  748. params->multifd_zstd_level = s->parameters.multifd_zstd_level;
  749. params->has_xbzrle_cache_size = true;
  750. params->xbzrle_cache_size = s->parameters.xbzrle_cache_size;
  751. params->has_max_postcopy_bandwidth = true;
  752. params->max_postcopy_bandwidth = s->parameters.max_postcopy_bandwidth;
  753. params->has_max_cpu_throttle = true;
  754. params->max_cpu_throttle = s->parameters.max_cpu_throttle;
  755. params->has_announce_initial = true;
  756. params->announce_initial = s->parameters.announce_initial;
  757. params->has_announce_max = true;
  758. params->announce_max = s->parameters.announce_max;
  759. params->has_announce_rounds = true;
  760. params->announce_rounds = s->parameters.announce_rounds;
  761. params->has_announce_step = true;
  762. params->announce_step = s->parameters.announce_step;
  763. if (s->parameters.has_block_bitmap_mapping) {
  764. params->has_block_bitmap_mapping = true;
  765. params->block_bitmap_mapping =
  766. QAPI_CLONE(BitmapMigrationNodeAliasList,
  767. s->parameters.block_bitmap_mapping);
  768. }
  769. params->has_x_vcpu_dirty_limit_period = true;
  770. params->x_vcpu_dirty_limit_period = s->parameters.x_vcpu_dirty_limit_period;
  771. params->has_vcpu_dirty_limit = true;
  772. params->vcpu_dirty_limit = s->parameters.vcpu_dirty_limit;
  773. params->has_mode = true;
  774. params->mode = s->parameters.mode;
  775. params->has_zero_page_detection = true;
  776. params->zero_page_detection = s->parameters.zero_page_detection;
  777. params->has_direct_io = true;
  778. params->direct_io = s->parameters.direct_io;
  779. return params;
  780. }
  781. void migrate_params_init(MigrationParameters *params)
  782. {
  783. params->tls_hostname = g_strdup("");
  784. params->tls_creds = g_strdup("");
  785. /* Set has_* up only for parameter checks */
  786. params->has_throttle_trigger_threshold = true;
  787. params->has_cpu_throttle_initial = true;
  788. params->has_cpu_throttle_increment = true;
  789. params->has_cpu_throttle_tailslow = true;
  790. params->has_max_bandwidth = true;
  791. params->has_downtime_limit = true;
  792. params->has_x_checkpoint_delay = true;
  793. params->has_multifd_channels = true;
  794. params->has_multifd_compression = true;
  795. params->has_multifd_zlib_level = true;
  796. params->has_multifd_qatzip_level = true;
  797. params->has_multifd_zstd_level = true;
  798. params->has_xbzrle_cache_size = true;
  799. params->has_max_postcopy_bandwidth = true;
  800. params->has_max_cpu_throttle = true;
  801. params->has_announce_initial = true;
  802. params->has_announce_max = true;
  803. params->has_announce_rounds = true;
  804. params->has_announce_step = true;
  805. params->has_x_vcpu_dirty_limit_period = true;
  806. params->has_vcpu_dirty_limit = true;
  807. params->has_mode = true;
  808. params->has_zero_page_detection = true;
  809. params->has_direct_io = true;
  810. }
  811. /*
  812. * Check whether the parameters are valid. Error will be put into errp
  813. * (if provided). Return true if valid, otherwise false.
  814. */
  815. bool migrate_params_check(MigrationParameters *params, Error **errp)
  816. {
  817. ERRP_GUARD();
  818. if (params->has_throttle_trigger_threshold &&
  819. (params->throttle_trigger_threshold < 1 ||
  820. params->throttle_trigger_threshold > 100)) {
  821. error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
  822. "throttle_trigger_threshold",
  823. "an integer in the range of 1 to 100");
  824. return false;
  825. }
  826. if (params->has_cpu_throttle_initial &&
  827. (params->cpu_throttle_initial < 1 ||
  828. params->cpu_throttle_initial > 99)) {
  829. error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
  830. "cpu_throttle_initial",
  831. "an integer in the range of 1 to 99");
  832. return false;
  833. }
  834. if (params->has_cpu_throttle_increment &&
  835. (params->cpu_throttle_increment < 1 ||
  836. params->cpu_throttle_increment > 99)) {
  837. error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
  838. "cpu_throttle_increment",
  839. "an integer in the range of 1 to 99");
  840. return false;
  841. }
  842. if (params->has_max_bandwidth && (params->max_bandwidth > SIZE_MAX)) {
  843. error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
  844. "max_bandwidth",
  845. "an integer in the range of 0 to "stringify(SIZE_MAX)
  846. " bytes/second");
  847. return false;
  848. }
  849. if (params->has_avail_switchover_bandwidth &&
  850. (params->avail_switchover_bandwidth > SIZE_MAX)) {
  851. error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
  852. "avail_switchover_bandwidth",
  853. "an integer in the range of 0 to "stringify(SIZE_MAX)
  854. " bytes/second");
  855. return false;
  856. }
  857. if (params->has_downtime_limit &&
  858. (params->downtime_limit > MAX_MIGRATE_DOWNTIME)) {
  859. error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
  860. "downtime_limit",
  861. "an integer in the range of 0 to "
  862. stringify(MAX_MIGRATE_DOWNTIME)" ms");
  863. return false;
  864. }
  865. /* x_checkpoint_delay is now always positive */
  866. if (params->has_multifd_channels && (params->multifd_channels < 1)) {
  867. error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
  868. "multifd_channels",
  869. "a value between 1 and 255");
  870. return false;
  871. }
  872. if (params->has_multifd_zlib_level &&
  873. (params->multifd_zlib_level > 9)) {
  874. error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "multifd_zlib_level",
  875. "a value between 0 and 9");
  876. return false;
  877. }
  878. if (params->has_multifd_qatzip_level &&
  879. ((params->multifd_qatzip_level > 9) ||
  880. (params->multifd_qatzip_level < 1))) {
  881. error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "multifd_qatzip_level",
  882. "a value between 1 and 9");
  883. return false;
  884. }
  885. if (params->has_multifd_zstd_level &&
  886. (params->multifd_zstd_level > 20)) {
  887. error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "multifd_zstd_level",
  888. "a value between 0 and 20");
  889. return false;
  890. }
  891. if (params->has_xbzrle_cache_size &&
  892. (params->xbzrle_cache_size < qemu_target_page_size() ||
  893. !is_power_of_2(params->xbzrle_cache_size))) {
  894. error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
  895. "xbzrle_cache_size",
  896. "a power of two no less than the target page size");
  897. return false;
  898. }
  899. if (params->has_max_cpu_throttle &&
  900. (params->max_cpu_throttle < params->cpu_throttle_initial ||
  901. params->max_cpu_throttle > 99)) {
  902. error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
  903. "max_cpu_throttle",
  904. "an integer in the range of cpu_throttle_initial to 99");
  905. return false;
  906. }
  907. if (params->has_announce_initial &&
  908. params->announce_initial > 100000) {
  909. error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
  910. "announce_initial",
  911. "a value between 0 and 100000");
  912. return false;
  913. }
  914. if (params->has_announce_max &&
  915. params->announce_max > 100000) {
  916. error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
  917. "announce_max",
  918. "a value between 0 and 100000");
  919. return false;
  920. }
  921. if (params->has_announce_rounds &&
  922. params->announce_rounds > 1000) {
  923. error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
  924. "announce_rounds",
  925. "a value between 0 and 1000");
  926. return false;
  927. }
  928. if (params->has_announce_step &&
  929. (params->announce_step < 1 ||
  930. params->announce_step > 10000)) {
  931. error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
  932. "announce_step",
  933. "a value between 0 and 10000");
  934. return false;
  935. }
  936. if (params->has_block_bitmap_mapping &&
  937. !check_dirty_bitmap_mig_alias_map(params->block_bitmap_mapping, errp)) {
  938. error_prepend(errp, "Invalid mapping given for block-bitmap-mapping: ");
  939. return false;
  940. }
  941. #ifdef CONFIG_LINUX
  942. if (migrate_zero_copy_send() &&
  943. ((params->has_multifd_compression && params->multifd_compression) ||
  944. (params->tls_creds && *params->tls_creds))) {
  945. error_setg(errp,
  946. "Zero copy only available for non-compressed non-TLS multifd migration");
  947. return false;
  948. }
  949. #endif
  950. if (migrate_mapped_ram() &&
  951. (migrate_multifd_compression() || migrate_tls())) {
  952. error_setg(errp,
  953. "Mapped-ram only available for non-compressed non-TLS multifd migration");
  954. return false;
  955. }
  956. if (params->has_x_vcpu_dirty_limit_period &&
  957. (params->x_vcpu_dirty_limit_period < 1 ||
  958. params->x_vcpu_dirty_limit_period > 1000)) {
  959. error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
  960. "x-vcpu-dirty-limit-period",
  961. "a value between 1 and 1000");
  962. return false;
  963. }
  964. if (params->has_vcpu_dirty_limit &&
  965. (params->vcpu_dirty_limit < 1)) {
  966. error_setg(errp,
  967. "Parameter 'vcpu_dirty_limit' must be greater than 1 MB/s");
  968. return false;
  969. }
  970. if (params->has_direct_io && params->direct_io && !qemu_has_direct_io()) {
  971. error_setg(errp, "No build-time support for direct-io");
  972. return false;
  973. }
  974. return true;
  975. }
  976. static void migrate_params_test_apply(MigrateSetParameters *params,
  977. MigrationParameters *dest)
  978. {
  979. *dest = migrate_get_current()->parameters;
  980. /* TODO use QAPI_CLONE() instead of duplicating it inline */
  981. if (params->has_throttle_trigger_threshold) {
  982. dest->throttle_trigger_threshold = params->throttle_trigger_threshold;
  983. }
  984. if (params->has_cpu_throttle_initial) {
  985. dest->cpu_throttle_initial = params->cpu_throttle_initial;
  986. }
  987. if (params->has_cpu_throttle_increment) {
  988. dest->cpu_throttle_increment = params->cpu_throttle_increment;
  989. }
  990. if (params->has_cpu_throttle_tailslow) {
  991. dest->cpu_throttle_tailslow = params->cpu_throttle_tailslow;
  992. }
  993. if (params->tls_creds) {
  994. assert(params->tls_creds->type == QTYPE_QSTRING);
  995. dest->tls_creds = params->tls_creds->u.s;
  996. }
  997. if (params->tls_hostname) {
  998. assert(params->tls_hostname->type == QTYPE_QSTRING);
  999. dest->tls_hostname = params->tls_hostname->u.s;
  1000. }
  1001. if (params->has_max_bandwidth) {
  1002. dest->max_bandwidth = params->max_bandwidth;
  1003. }
  1004. if (params->has_avail_switchover_bandwidth) {
  1005. dest->avail_switchover_bandwidth = params->avail_switchover_bandwidth;
  1006. }
  1007. if (params->has_downtime_limit) {
  1008. dest->downtime_limit = params->downtime_limit;
  1009. }
  1010. if (params->has_x_checkpoint_delay) {
  1011. dest->x_checkpoint_delay = params->x_checkpoint_delay;
  1012. }
  1013. if (params->has_multifd_channels) {
  1014. dest->multifd_channels = params->multifd_channels;
  1015. }
  1016. if (params->has_multifd_compression) {
  1017. dest->multifd_compression = params->multifd_compression;
  1018. }
  1019. if (params->has_multifd_qatzip_level) {
  1020. dest->multifd_qatzip_level = params->multifd_qatzip_level;
  1021. }
  1022. if (params->has_multifd_zlib_level) {
  1023. dest->multifd_zlib_level = params->multifd_zlib_level;
  1024. }
  1025. if (params->has_multifd_zstd_level) {
  1026. dest->multifd_zstd_level = params->multifd_zstd_level;
  1027. }
  1028. if (params->has_xbzrle_cache_size) {
  1029. dest->xbzrle_cache_size = params->xbzrle_cache_size;
  1030. }
  1031. if (params->has_max_postcopy_bandwidth) {
  1032. dest->max_postcopy_bandwidth = params->max_postcopy_bandwidth;
  1033. }
  1034. if (params->has_max_cpu_throttle) {
  1035. dest->max_cpu_throttle = params->max_cpu_throttle;
  1036. }
  1037. if (params->has_announce_initial) {
  1038. dest->announce_initial = params->announce_initial;
  1039. }
  1040. if (params->has_announce_max) {
  1041. dest->announce_max = params->announce_max;
  1042. }
  1043. if (params->has_announce_rounds) {
  1044. dest->announce_rounds = params->announce_rounds;
  1045. }
  1046. if (params->has_announce_step) {
  1047. dest->announce_step = params->announce_step;
  1048. }
  1049. if (params->has_block_bitmap_mapping) {
  1050. dest->has_block_bitmap_mapping = true;
  1051. dest->block_bitmap_mapping = params->block_bitmap_mapping;
  1052. }
  1053. if (params->has_x_vcpu_dirty_limit_period) {
  1054. dest->x_vcpu_dirty_limit_period =
  1055. params->x_vcpu_dirty_limit_period;
  1056. }
  1057. if (params->has_vcpu_dirty_limit) {
  1058. dest->vcpu_dirty_limit = params->vcpu_dirty_limit;
  1059. }
  1060. if (params->has_mode) {
  1061. dest->mode = params->mode;
  1062. }
  1063. if (params->has_zero_page_detection) {
  1064. dest->zero_page_detection = params->zero_page_detection;
  1065. }
  1066. if (params->has_direct_io) {
  1067. dest->direct_io = params->direct_io;
  1068. }
  1069. }
  1070. static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
  1071. {
  1072. MigrationState *s = migrate_get_current();
  1073. /* TODO use QAPI_CLONE() instead of duplicating it inline */
  1074. if (params->has_throttle_trigger_threshold) {
  1075. s->parameters.throttle_trigger_threshold = params->throttle_trigger_threshold;
  1076. }
  1077. if (params->has_cpu_throttle_initial) {
  1078. s->parameters.cpu_throttle_initial = params->cpu_throttle_initial;
  1079. }
  1080. if (params->has_cpu_throttle_increment) {
  1081. s->parameters.cpu_throttle_increment = params->cpu_throttle_increment;
  1082. }
  1083. if (params->has_cpu_throttle_tailslow) {
  1084. s->parameters.cpu_throttle_tailslow = params->cpu_throttle_tailslow;
  1085. }
  1086. if (params->tls_creds) {
  1087. g_free(s->parameters.tls_creds);
  1088. assert(params->tls_creds->type == QTYPE_QSTRING);
  1089. s->parameters.tls_creds = g_strdup(params->tls_creds->u.s);
  1090. }
  1091. if (params->tls_hostname) {
  1092. g_free(s->parameters.tls_hostname);
  1093. assert(params->tls_hostname->type == QTYPE_QSTRING);
  1094. s->parameters.tls_hostname = g_strdup(params->tls_hostname->u.s);
  1095. }
  1096. if (params->tls_authz) {
  1097. g_free(s->parameters.tls_authz);
  1098. assert(params->tls_authz->type == QTYPE_QSTRING);
  1099. s->parameters.tls_authz = g_strdup(params->tls_authz->u.s);
  1100. }
  1101. if (params->has_max_bandwidth) {
  1102. s->parameters.max_bandwidth = params->max_bandwidth;
  1103. if (s->to_dst_file && !migration_in_postcopy()) {
  1104. migration_rate_set(s->parameters.max_bandwidth);
  1105. }
  1106. }
  1107. if (params->has_avail_switchover_bandwidth) {
  1108. s->parameters.avail_switchover_bandwidth = params->avail_switchover_bandwidth;
  1109. }
  1110. if (params->has_downtime_limit) {
  1111. s->parameters.downtime_limit = params->downtime_limit;
  1112. }
  1113. if (params->has_x_checkpoint_delay) {
  1114. s->parameters.x_checkpoint_delay = params->x_checkpoint_delay;
  1115. colo_checkpoint_delay_set();
  1116. }
  1117. if (params->has_multifd_channels) {
  1118. s->parameters.multifd_channels = params->multifd_channels;
  1119. }
  1120. if (params->has_multifd_compression) {
  1121. s->parameters.multifd_compression = params->multifd_compression;
  1122. }
  1123. if (params->has_multifd_qatzip_level) {
  1124. s->parameters.multifd_qatzip_level = params->multifd_qatzip_level;
  1125. }
  1126. if (params->has_multifd_zlib_level) {
  1127. s->parameters.multifd_zlib_level = params->multifd_zlib_level;
  1128. }
  1129. if (params->has_multifd_zstd_level) {
  1130. s->parameters.multifd_zstd_level = params->multifd_zstd_level;
  1131. }
  1132. if (params->has_xbzrle_cache_size) {
  1133. s->parameters.xbzrle_cache_size = params->xbzrle_cache_size;
  1134. xbzrle_cache_resize(params->xbzrle_cache_size, errp);
  1135. }
  1136. if (params->has_max_postcopy_bandwidth) {
  1137. s->parameters.max_postcopy_bandwidth = params->max_postcopy_bandwidth;
  1138. if (s->to_dst_file && migration_in_postcopy()) {
  1139. migration_rate_set(s->parameters.max_postcopy_bandwidth);
  1140. }
  1141. }
  1142. if (params->has_max_cpu_throttle) {
  1143. s->parameters.max_cpu_throttle = params->max_cpu_throttle;
  1144. }
  1145. if (params->has_announce_initial) {
  1146. s->parameters.announce_initial = params->announce_initial;
  1147. }
  1148. if (params->has_announce_max) {
  1149. s->parameters.announce_max = params->announce_max;
  1150. }
  1151. if (params->has_announce_rounds) {
  1152. s->parameters.announce_rounds = params->announce_rounds;
  1153. }
  1154. if (params->has_announce_step) {
  1155. s->parameters.announce_step = params->announce_step;
  1156. }
  1157. if (params->has_block_bitmap_mapping) {
  1158. qapi_free_BitmapMigrationNodeAliasList(
  1159. s->parameters.block_bitmap_mapping);
  1160. s->parameters.has_block_bitmap_mapping = true;
  1161. s->parameters.block_bitmap_mapping =
  1162. QAPI_CLONE(BitmapMigrationNodeAliasList,
  1163. params->block_bitmap_mapping);
  1164. }
  1165. if (params->has_x_vcpu_dirty_limit_period) {
  1166. s->parameters.x_vcpu_dirty_limit_period =
  1167. params->x_vcpu_dirty_limit_period;
  1168. }
  1169. if (params->has_vcpu_dirty_limit) {
  1170. s->parameters.vcpu_dirty_limit = params->vcpu_dirty_limit;
  1171. }
  1172. if (params->has_mode) {
  1173. s->parameters.mode = params->mode;
  1174. }
  1175. if (params->has_zero_page_detection) {
  1176. s->parameters.zero_page_detection = params->zero_page_detection;
  1177. }
  1178. if (params->has_direct_io) {
  1179. s->parameters.direct_io = params->direct_io;
  1180. }
  1181. }
  1182. void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp)
  1183. {
  1184. MigrationParameters tmp;
  1185. /* TODO Rewrite "" to null instead for all three tls_* parameters */
  1186. if (params->tls_creds
  1187. && params->tls_creds->type == QTYPE_QNULL) {
  1188. qobject_unref(params->tls_creds->u.n);
  1189. params->tls_creds->type = QTYPE_QSTRING;
  1190. params->tls_creds->u.s = strdup("");
  1191. }
  1192. if (params->tls_hostname
  1193. && params->tls_hostname->type == QTYPE_QNULL) {
  1194. qobject_unref(params->tls_hostname->u.n);
  1195. params->tls_hostname->type = QTYPE_QSTRING;
  1196. params->tls_hostname->u.s = strdup("");
  1197. }
  1198. if (params->tls_authz
  1199. && params->tls_authz->type == QTYPE_QNULL) {
  1200. qobject_unref(params->tls_authz->u.n);
  1201. params->tls_authz->type = QTYPE_QSTRING;
  1202. params->tls_authz->u.s = strdup("");
  1203. }
  1204. migrate_params_test_apply(params, &tmp);
  1205. if (!migrate_params_check(&tmp, errp)) {
  1206. /* Invalid parameter */
  1207. return;
  1208. }
  1209. migrate_params_apply(params, errp);
  1210. }