]> git.proxmox.com Git - mirror_qemu.git/blame - migration/postcopy-ram.h
log: Make glib logging go through QEMU
[mirror_qemu.git] / migration / postcopy-ram.h
CommitLineData
eb59db53
DDAG
1/*
2 * Postcopy migration for RAM
3 *
4 * Copyright 2013 Red Hat, Inc. and/or its affiliates
5 *
6 * Authors:
7 * Dave Gilbert <dgilbert@redhat.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
11 *
12 */
13#ifndef QEMU_POSTCOPY_RAM_H
14#define QEMU_POSTCOPY_RAM_H
15
16/* Return true if the host supports everything we need to do postcopy-ram */
d7651f15 17bool postcopy_ram_supported_by_host(MigrationIncomingState *mis);
eb59db53 18
f0a227ad
DDAG
19/*
20 * Make all of RAM sensitive to accesses to areas that haven't yet been written
21 * and wire up anything necessary to deal with it.
22 */
23int postcopy_ram_enable_notify(MigrationIncomingState *mis);
24
1caddf8a
DDAG
25/*
26 * Initialise postcopy-ram, setting the RAM to a state where we can go into
27 * postcopy later; must be called prior to any precopy.
28 * called from ram.c's similarly named ram_postcopy_incoming_init
29 */
c136180c 30int postcopy_ram_incoming_init(MigrationIncomingState *mis);
1caddf8a
DDAG
31
32/*
33 * At the end of a migration where postcopy_ram_incoming_init was called.
34 */
35int postcopy_ram_incoming_cleanup(MigrationIncomingState *mis);
36
f9527107
DDAG
37/*
38 * Userfault requires us to mark RAM as NOHUGEPAGE prior to discard
39 * however leaving it until after precopy means that most of the precopy
40 * data is still THPd
41 */
42int postcopy_ram_prepare_discard(MigrationIncomingState *mis);
e0b266f0
DDAG
43
44/*
45 * Called at the start of each RAMBlock by the bitmap code.
e0b266f0
DDAG
46 * Returns a new PDS
47 */
48PostcopyDiscardState *postcopy_discard_send_init(MigrationState *ms,
e0b266f0
DDAG
49 const char *name);
50
51/*
52 * Called by the bitmap code for each chunk to discard.
53 * May send a discard message, may just leave it queued to
54 * be sent later.
55 * @start,@length: a range of pages in the migration bitmap in the
56 * RAM block passed to postcopy_discard_send_init() (length=1 is one page)
57 */
58void postcopy_discard_send_range(MigrationState *ms, PostcopyDiscardState *pds,
59 unsigned long start, unsigned long length);
60
61/*
62 * Called at the end of each RAMBlock by the bitmap code.
63 * Sends any outstanding discard messages, frees the PDS.
64 */
65void postcopy_discard_send_finish(MigrationState *ms,
66 PostcopyDiscardState *pds);
67
696ed9a9
DDAG
68/*
69 * Place a page (from) at (host) efficiently
70 * There are restrictions on how 'from' must be mapped, in general best
71 * to use other postcopy_ routines to allocate.
72 * returns 0 on success
73 */
df9ff5e1 74int postcopy_place_page(MigrationIncomingState *mis, void *host, void *from,
8be4620b 75 RAMBlock *rb);
696ed9a9
DDAG
76
77/*
78 * Place a zero page at (host) atomically
79 * returns 0 on success
80 */
df9ff5e1 81int postcopy_place_page_zero(MigrationIncomingState *mis, void *host,
8be4620b 82 RAMBlock *rb);
696ed9a9 83
bac3b212
JQ
84/* The current postcopy state is read/set by postcopy_state_get/set
85 * which update it atomically.
86 * The state is updated as postcopy messages are received, and
87 * in general only one thread should be writing to the state at any one
88 * time, initially the main thread and then the listen thread;
89 * Corner cases are where either thread finishes early and/or errors.
90 * The state is checked as messages are received to ensure that
91 * the source is sending us messages in the correct order.
92 * The state is also used by the RAM reception code to know if it
93 * has to place pages atomically, and the cleanup code at the end of
94 * the main thread to know if it has to delay cleanup until the end
95 * of postcopy.
96 */
97typedef enum {
98 POSTCOPY_INCOMING_NONE = 0, /* Initial state - no postcopy */
99 POSTCOPY_INCOMING_ADVISE,
100 POSTCOPY_INCOMING_DISCARD,
101 POSTCOPY_INCOMING_LISTENING,
102 POSTCOPY_INCOMING_RUNNING,
103 POSTCOPY_INCOMING_END
104} PostcopyState;
105
696ed9a9
DDAG
106/*
107 * Allocate a page of memory that can be mapped at a later point in time
108 * using postcopy_place_page
109 * Returns: Pointer to allocated page
110 */
111void *postcopy_get_tmp_page(MigrationIncomingState *mis);
112
bac3b212
JQ
113PostcopyState postcopy_state_get(void);
114/* Set the state and return the old state */
115PostcopyState postcopy_state_set(PostcopyState new_state);
116
9ab7ef9b
PX
117void postcopy_fault_thread_notify(MigrationIncomingState *mis);
118
1693c64c
DDAG
119/*
120 * To be called once at the start before any device initialisation
121 */
122void postcopy_infrastructure_init(void);
123
124/* Add a notifier to a list to be called when checking whether the devices
125 * can support postcopy.
126 * It's data is a *PostcopyNotifyData
127 * It should return 0 if OK, or a negative value on failure.
128 * On failure it must set the data->errp to an error.
129 *
130 */
131enum PostcopyNotifyReason {
132 POSTCOPY_NOTIFY_PROBE = 0,
d3dff7a5 133 POSTCOPY_NOTIFY_INBOUND_ADVISE,
6864a7b5 134 POSTCOPY_NOTIFY_INBOUND_LISTEN,
46343570 135 POSTCOPY_NOTIFY_INBOUND_END,
1693c64c
DDAG
136};
137
138struct PostcopyNotifyData {
139 enum PostcopyNotifyReason reason;
140 Error **errp;
141};
142
143void postcopy_add_notifier(NotifierWithReturn *nn);
144void postcopy_remove_notifier(NotifierWithReturn *n);
145/* Call the notifier list set by postcopy_add_start_notifier */
146int postcopy_notify(enum PostcopyNotifyReason reason, Error **errp);
147
00fa4fc8
DDAG
148struct PostCopyFD;
149
150/* ufd is a pointer to the struct uffd_msg *TODO: more Portable! */
151typedef int (*pcfdhandler)(struct PostCopyFD *pcfd, void *ufd);
d488b349
DDAG
152/* Notification to wake, either on place or on reception of
153 * a fault on something that's already arrived (race)
154 */
155typedef int (*pcfdwake)(struct PostCopyFD *pcfd, RAMBlock *rb, uint64_t offset);
00fa4fc8
DDAG
156
157struct PostCopyFD {
158 int fd;
159 /* Data to pass to handler */
160 void *data;
161 /* Handler to be called whenever we get a poll event */
162 pcfdhandler handler;
d488b349
DDAG
163 /* Notification to wake shared client */
164 pcfdwake waker;
00fa4fc8
DDAG
165 /* A string to use in error messages */
166 const char *idstr;
167};
168
169/* Register a userfaultfd owned by an external process for
170 * shared memory.
171 */
172void postcopy_register_shared_ufd(struct PostCopyFD *pcfd);
173void postcopy_unregister_shared_ufd(struct PostCopyFD *pcfd);
d488b349
DDAG
174/* Call each of the shared 'waker's registerd telling them of
175 * availability of a block.
176 */
177int postcopy_notify_shared_wake(RAMBlock *rb, uint64_t offset);
5efc3564
DDAG
178/* postcopy_wake_shared: Notify a client ufd that a page is available
179 *
180 * Returns 0 on success
181 *
182 * @pcfd: Structure with fd, handler and name as above
183 * @client_addr: Address in the client program, not QEMU
184 * @rb: The RAMBlock the page is in
185 */
186int postcopy_wake_shared(struct PostCopyFD *pcfd, uint64_t client_addr,
187 RAMBlock *rb);
096bf4c8
DDAG
188/* Callback from shared fault handlers to ask for a page */
189int postcopy_request_shared_page(struct PostCopyFD *pcfd, RAMBlock *rb,
190 uint64_t client_addr, uint64_t offset);
00fa4fc8 191
eb59db53 192#endif