blob: c9e200f4eb8f8a8ab2c8b8d0e0dbf871817b94fc [file] [log] [blame]
Juan Quintela7b1e1a22017-04-17 20:26:27 +02001/*
2 * QEMU migration miscellaneus exported functions
3 *
4 * Copyright IBM, Corp. 2008
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
12 */
13
14#ifndef MIGRATION_MISC_H
15#define MIGRATION_MISC_H
16
Juan Quintela1adc1ce2017-04-24 16:51:10 +020017#include "qemu/notify.h"
Steve Sistareeea1e5c2023-10-25 12:44:24 -070018#include "qapi/qapi-types-migration.h"
Dr. David Alan Gilbertee3d96b2019-02-27 13:24:06 +000019#include "qapi/qapi-types-net.h"
Steve Sistaref3bff6c2024-03-11 10:48:39 -070020#include "migration/client-options.h"
Juan Quintela1adc1ce2017-04-24 16:51:10 +020021
Juan Quintela7b1e1a22017-04-17 20:26:27 +020022/* migration/ram.c */
23
Wei Wangbd227062018-12-11 16:24:51 +080024typedef enum PrecopyNotifyReason {
25 PRECOPY_NOTIFY_SETUP = 0,
26 PRECOPY_NOTIFY_BEFORE_BITMAP_SYNC = 1,
27 PRECOPY_NOTIFY_AFTER_BITMAP_SYNC = 2,
28 PRECOPY_NOTIFY_COMPLETE = 3,
29 PRECOPY_NOTIFY_CLEANUP = 4,
30 PRECOPY_NOTIFY_MAX = 5,
31} PrecopyNotifyReason;
32
33typedef struct PrecopyNotifyData {
34 enum PrecopyNotifyReason reason;
Wei Wangbd227062018-12-11 16:24:51 +080035} PrecopyNotifyData;
36
37void precopy_infrastructure_init(void);
38void precopy_add_notifier(NotifierWithReturn *n);
39void precopy_remove_notifier(NotifierWithReturn *n);
40int precopy_notify(PrecopyNotifyReason reason, Error **errp);
41
Juan Quintela7b1e1a22017-04-17 20:26:27 +020042void ram_mig_init(void);
Wei Wang6bcb05f2018-12-11 16:24:50 +080043void qemu_guest_free_page_hint(void *addr, size_t len);
David Hildenbrandf161c882023-07-06 09:56:08 +020044bool migrate_ram_is_ignored(RAMBlock *block);
Juan Quintela7b1e1a22017-04-17 20:26:27 +020045
Juan Quintela2c9e6fe2017-04-21 14:31:22 +020046/* migration/block.c */
47
48#ifdef CONFIG_LIVE_BLOCK_MIGRATION
49void blk_mig_init(void);
50#else
51static inline void blk_mig_init(void) {}
52#endif
53
Dr. David Alan Gilbertee3d96b2019-02-27 13:24:06 +000054AnnounceParameters *migrate_announce_params(void);
Juan Quintelab7722742017-04-24 13:51:10 +020055/* migration/savevm.c */
56
57void dump_vmstate_json_to_file(FILE *out_fp);
58
Juan Quintelac4b63b72017-04-24 19:02:44 +020059/* migration/migration.c */
Peter Xue5cb7e72017-06-27 12:10:13 +080060void migration_object_init(void);
Dr. David Alan Gilbert892ae712019-02-27 16:49:00 +000061void migration_shutdown(void);
Juan Quintelac4b63b72017-04-24 19:02:44 +020062bool migration_is_idle(void);
Steve Sistare3a6813b2024-03-11 10:48:50 -070063bool migration_is_active(void);
Steve Sistare9bb630c2024-03-11 10:48:54 -070064bool migration_is_device(void);
Steve Sistare6e785632024-03-11 10:48:53 -070065bool migration_thread_is_self(void);
Steve Sistare7dcb3c82024-03-11 10:48:49 -070066bool migration_is_setup_or_active(void);
Steve Sistare9d9babf2024-02-22 09:28:30 -080067
68typedef enum MigrationEventType {
69 MIG_EVENT_PRECOPY_SETUP,
70 MIG_EVENT_PRECOPY_DONE,
71 MIG_EVENT_PRECOPY_FAILED,
72 MIG_EVENT_MAX
73} MigrationEventType;
74
75typedef struct MigrationEvent {
76 MigrationEventType type;
77} MigrationEvent;
78
Steve Sistare4af667f2024-02-22 09:28:35 -080079/*
80 * A MigrationNotifyFunc may return an error code and an Error object,
81 * but only when @e->type is MIG_EVENT_PRECOPY_SETUP. The code is an int
82 * to allow for different failure modes and recovery actions.
83 */
Steve Sistare5663dd32024-02-22 09:28:32 -080084typedef int (*MigrationNotifyFunc)(NotifierWithReturn *notify,
85 MigrationEvent *e, Error **errp);
86
Steve Sistare9d9babf2024-02-22 09:28:30 -080087/*
88 * Register the notifier @notify to be called when a migration event occurs
89 * for MIG_MODE_NORMAL, as specified by the MigrationEvent passed to @func.
90 * Notifiers may receive events in any of the following orders:
91 * - MIG_EVENT_PRECOPY_SETUP -> MIG_EVENT_PRECOPY_DONE
92 * - MIG_EVENT_PRECOPY_SETUP -> MIG_EVENT_PRECOPY_FAILED
93 * - MIG_EVENT_PRECOPY_FAILED
94 */
Steve Sistare3e775732024-02-22 09:28:29 -080095void migration_add_notifier(NotifierWithReturn *notify,
Steve Sistare5663dd32024-02-22 09:28:32 -080096 MigrationNotifyFunc func);
Steve Sistare9d9babf2024-02-22 09:28:30 -080097
Steve Sistare6835f5a2024-02-22 09:28:33 -080098/*
99 * Same as migration_add_notifier, but applies to be specified @mode.
100 */
101void migration_add_notifier_mode(NotifierWithReturn *notify,
102 MigrationNotifyFunc func, MigMode mode);
103
Steve Sistare3e775732024-02-22 09:28:29 -0800104void migration_remove_notifier(NotifierWithReturn *notify);
Steve Sistareaeaafb12024-03-11 10:48:51 -0700105bool migration_is_running(void);
Steve Sistare20c64c82024-03-11 10:48:55 -0700106void migration_file_set_error(int err);
107
David Hildenbrand80fe3152023-01-17 12:22:46 +0100108/* True if incoming migration entered POSTCOPY_INCOMING_DISCARD */
David Hildenbrand06df2e62020-06-26 09:22:33 +0200109bool migration_in_incoming_postcopy(void);
Steve Sistarec9539d92024-03-11 10:48:58 -0700110
David Hildenbrand80fe3152023-01-17 12:22:46 +0100111/* True if incoming migration entered POSTCOPY_INCOMING_ADVISE */
112bool migration_incoming_postcopy_advised(void);
Steve Sistarec9539d92024-03-11 10:48:58 -0700113
Andrey Gruzdev1a8e44a2021-04-01 12:22:24 +0300114/* True if background snapshot is active */
115bool migration_in_bg_snapshot(void);
Peter Xu3df663e2017-06-27 12:10:15 +0800116
Vladimir Sementsov-Ogievskiyb35ebdf2018-03-13 15:34:01 -0400117/* migration/block-dirty-bitmap.c */
118void dirty_bitmap_mig_init(void);
119
Juan Quintela7b1e1a22017-04-17 20:26:27 +0200120#endif