xref: /qemu/include/migration/misc.h (revision d884e272)
1 /*
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 
17 #include "qemu/notify.h"
18 #include "qapi/qapi-types-migration.h"
19 #include "qapi/qapi-types-net.h"
20 
21 /* migration/ram.c */
22 
23 typedef enum PrecopyNotifyReason {
24     PRECOPY_NOTIFY_SETUP = 0,
25     PRECOPY_NOTIFY_BEFORE_BITMAP_SYNC = 1,
26     PRECOPY_NOTIFY_AFTER_BITMAP_SYNC = 2,
27     PRECOPY_NOTIFY_COMPLETE = 3,
28     PRECOPY_NOTIFY_CLEANUP = 4,
29     PRECOPY_NOTIFY_MAX = 5,
30 } PrecopyNotifyReason;
31 
32 typedef struct PrecopyNotifyData {
33     enum PrecopyNotifyReason reason;
34 } PrecopyNotifyData;
35 
36 void precopy_infrastructure_init(void);
37 void precopy_add_notifier(NotifierWithReturn *n);
38 void precopy_remove_notifier(NotifierWithReturn *n);
39 int precopy_notify(PrecopyNotifyReason reason, Error **errp);
40 
41 void ram_mig_init(void);
42 void qemu_guest_free_page_hint(void *addr, size_t len);
43 bool migrate_ram_is_ignored(RAMBlock *block);
44 
45 /* migration/block.c */
46 
47 #ifdef CONFIG_LIVE_BLOCK_MIGRATION
48 void blk_mig_init(void);
49 #else
50 static inline void blk_mig_init(void) {}
51 #endif
52 
53 AnnounceParameters *migrate_announce_params(void);
54 /* migration/savevm.c */
55 
56 void dump_vmstate_json_to_file(FILE *out_fp);
57 
58 /* migration/migration.c */
59 void migration_object_init(void);
60 void migration_shutdown(void);
61 bool migration_is_idle(void);
62 bool migration_is_active(MigrationState *);
63 bool migrate_mode_is_cpr(MigrationState *);
64 
65 typedef enum MigrationEventType {
66     MIG_EVENT_PRECOPY_SETUP,
67     MIG_EVENT_PRECOPY_DONE,
68     MIG_EVENT_PRECOPY_FAILED,
69     MIG_EVENT_MAX
70 } MigrationEventType;
71 
72 typedef struct MigrationEvent {
73     MigrationEventType type;
74 } MigrationEvent;
75 
76 /*
77  * A MigrationNotifyFunc may return an error code and an Error object,
78  * but only when @e->type is MIG_EVENT_PRECOPY_SETUP.  The code is an int
79  * to allow for different failure modes and recovery actions.
80  */
81 typedef int (*MigrationNotifyFunc)(NotifierWithReturn *notify,
82                                    MigrationEvent *e, Error **errp);
83 
84 /*
85  * Register the notifier @notify to be called when a migration event occurs
86  * for MIG_MODE_NORMAL, as specified by the MigrationEvent passed to @func.
87  * Notifiers may receive events in any of the following orders:
88  *    - MIG_EVENT_PRECOPY_SETUP -> MIG_EVENT_PRECOPY_DONE
89  *    - MIG_EVENT_PRECOPY_SETUP -> MIG_EVENT_PRECOPY_FAILED
90  *    - MIG_EVENT_PRECOPY_FAILED
91  */
92 void migration_add_notifier(NotifierWithReturn *notify,
93                             MigrationNotifyFunc func);
94 
95 /*
96  * Same as migration_add_notifier, but applies to be specified @mode.
97  */
98 void migration_add_notifier_mode(NotifierWithReturn *notify,
99                                  MigrationNotifyFunc func, MigMode mode);
100 
101 void migration_remove_notifier(NotifierWithReturn *notify);
102 int migration_call_notifiers(MigrationState *s, MigrationEventType type,
103                              Error **errp);
104 bool migration_in_setup(MigrationState *);
105 bool migration_has_finished(MigrationState *);
106 bool migration_has_failed(MigrationState *);
107 /* ...and after the device transmission */
108 /* True if incoming migration entered POSTCOPY_INCOMING_DISCARD */
109 bool migration_in_incoming_postcopy(void);
110 /* True if incoming migration entered POSTCOPY_INCOMING_ADVISE */
111 bool migration_incoming_postcopy_advised(void);
112 /* True if background snapshot is active */
113 bool migration_in_bg_snapshot(void);
114 
115 /* migration/block-dirty-bitmap.c */
116 void dirty_bitmap_mig_init(void);
117 
118 #endif
119