options.c 46 KB

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