]> git.proxmox.com Git - mirror_qemu.git/blame - migration/multifd.h
migration/multifd: Move load_cleanup inside incoming_state_destroy
[mirror_qemu.git] / migration / multifd.h
CommitLineData
d32ca5ad
JQ
1/*
2 * Multifd common functions
3 *
4 * Copyright (c) 2019-2020 Red Hat Inc
5 *
6 * Authors:
7 * Juan Quintela <quintela@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_MIGRATION_MULTIFD_H
14#define QEMU_MIGRATION_MULTIFD_H
15
16int multifd_save_setup(Error **errp);
17void multifd_save_cleanup(void);
18int multifd_load_setup(Error **errp);
e5bac1f5 19void multifd_load_cleanup(void);
cfc3bcf3 20void multifd_load_shutdown(void);
d32ca5ad 21bool multifd_recv_all_channels_created(void);
6720c2b3 22void multifd_recv_new_channel(QIOChannel *ioc, Error **errp);
d32ca5ad 23void multifd_recv_sync_main(void);
33d70973 24int multifd_send_sync_main(QEMUFile *f);
d32ca5ad
JQ
25int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset);
26
7ec2c2b3 27/* Multifd Compression flags */
d32ca5ad
JQ
28#define MULTIFD_FLAG_SYNC (1 << 0)
29
ab7cbb0b
JQ
30/* We reserve 3 bits for compression methods */
31#define MULTIFD_FLAG_COMPRESSION_MASK (7 << 1)
32/* we need to be compatible. Before compression value was 0 */
33#define MULTIFD_FLAG_NOCOMP (0 << 1)
7ec2c2b3 34#define MULTIFD_FLAG_ZLIB (1 << 1)
87dc6f5f 35#define MULTIFD_FLAG_ZSTD (2 << 1)
ab7cbb0b 36
d32ca5ad
JQ
37/* This value needs to be a multiple of qemu_target_page_size() */
38#define MULTIFD_PACKET_SIZE (512 * 1024)
39
40typedef struct {
41 uint32_t magic;
42 uint32_t version;
43 uint32_t flags;
44 /* maximum number of allocated pages */
45 uint32_t pages_alloc;
8c0ec0b2
JQ
46 /* non zero pages */
47 uint32_t normal_pages;
d32ca5ad
JQ
48 /* size of the next packet that contains pages */
49 uint32_t next_packet_size;
50 uint64_t packet_num;
51 uint64_t unused[4]; /* Reserved for future use */
52 char ramblock[256];
53 uint64_t offset[];
54} __attribute__((packed)) MultiFDPacket_t;
55
56typedef struct {
57 /* number of used pages */
90a3d2f9 58 uint32_t num;
d32ca5ad
JQ
59 /* number of allocated pages */
60 uint32_t allocated;
61 /* global number of generated multifd packets */
62 uint64_t packet_num;
63 /* offset of each page */
64 ram_addr_t *offset;
d32ca5ad
JQ
65 RAMBlock *block;
66} MultiFDPages_t;
67
68typedef struct {
4a8f19c9
JQ
69 /* Fields are only written at creating/deletion time */
70 /* No lock required for them, they are read only */
71
d32ca5ad
JQ
72 /* channel number */
73 uint8_t id;
74 /* channel thread name */
75 char *name;
76 /* channel thread id */
77 QemuThread thread;
78 /* communication channel */
79 QIOChannel *c;
4a8f19c9
JQ
80 /* is the yank function registered */
81 bool registered_yank;
82 /* packet allocated len */
83 uint32_t packet_len;
ddec20f8
JQ
84 /* guest page size */
85 uint32_t page_size;
d6f45eba
JQ
86 /* number of pages in a full packet */
87 uint32_t page_count;
4a8f19c9
JQ
88 /* multifd flags for sending ram */
89 int write_flags;
90
d32ca5ad
JQ
91 /* sem where to wait for more work */
92 QemuSemaphore sem;
4a8f19c9
JQ
93 /* syncs main thread and channels */
94 QemuSemaphore sem_sync;
95
d32ca5ad
JQ
96 /* this mutex protects the following parameters */
97 QemuMutex mutex;
98 /* is this channel thread running */
99 bool running;
100 /* should this thread finish */
101 bool quit;
4a8f19c9
JQ
102 /* multifd flags for each packet */
103 uint32_t flags;
104 /* global number of generated multifd packets */
105 uint64_t packet_num;
d32ca5ad
JQ
106 /* thread has work to do */
107 int pending_job;
4a8f19c9
JQ
108 /* array of pages to sent.
109 * The owner of 'pages' depends of 'pending_job' value:
110 * pending_job == 0 -> migration_thread can use it.
111 * pending_job != 0 -> multifd_channel can use it.
112 */
d32ca5ad 113 MultiFDPages_t *pages;
4a8f19c9
JQ
114
115 /* thread local variables. No locking required */
116
d32ca5ad
JQ
117 /* pointer to the packet */
118 MultiFDPacket_t *packet;
d32ca5ad
JQ
119 /* size of the next packet that contains pages */
120 uint32_t next_packet_size;
d32ca5ad
JQ
121 /* packets sent through this channel */
122 uint64_t num_packets;
815956f0
JQ
123 /* non zero pages sent through this channel */
124 uint64_t total_normal_pages;
226468ba
JQ
125 /* buffers to send */
126 struct iovec *iov;
127 /* number of iovs used */
128 uint32_t iovs_num;
815956f0
JQ
129 /* Pages that are not zero */
130 ram_addr_t *normal;
131 /* num of non zero pages */
132 uint32_t normal_num;
ab7cbb0b
JQ
133 /* used for compression methods */
134 void *data;
d32ca5ad
JQ
135} MultiFDSendParams;
136
137typedef struct {
4a8f19c9
JQ
138 /* Fields are only written at creating/deletion time */
139 /* No lock required for them, they are read only */
140
d32ca5ad
JQ
141 /* channel number */
142 uint8_t id;
143 /* channel thread name */
144 char *name;
145 /* channel thread id */
146 QemuThread thread;
147 /* communication channel */
148 QIOChannel *c;
4a8f19c9
JQ
149 /* packet allocated len */
150 uint32_t packet_len;
ddec20f8
JQ
151 /* guest page size */
152 uint32_t page_size;
d6f45eba
JQ
153 /* number of pages in a full packet */
154 uint32_t page_count;
4a8f19c9
JQ
155
156 /* syncs main thread and channels */
157 QemuSemaphore sem_sync;
158
d32ca5ad
JQ
159 /* this mutex protects the following parameters */
160 QemuMutex mutex;
161 /* is this channel thread running */
162 bool running;
163 /* should this thread finish */
164 bool quit;
d32ca5ad
JQ
165 /* multifd flags for each packet */
166 uint32_t flags;
167 /* global number of generated multifd packets */
168 uint64_t packet_num;
4a8f19c9
JQ
169
170 /* thread local variables. No locking required */
171
172 /* pointer to the packet */
173 MultiFDPacket_t *packet;
d32ca5ad
JQ
174 /* size of the next packet that contains pages */
175 uint32_t next_packet_size;
176 /* packets sent through this channel */
177 uint64_t num_packets;
4a8f19c9
JQ
178 /* ramblock host address */
179 uint8_t *host;
cf2d4aa8
JQ
180 /* non zero pages recv through this channel */
181 uint64_t total_normal_pages;
226468ba
JQ
182 /* buffers to recv */
183 struct iovec *iov;
cf2d4aa8
JQ
184 /* Pages that are not zero */
185 ram_addr_t *normal;
186 /* num of non zero pages */
187 uint32_t normal_num;
ab7cbb0b
JQ
188 /* used for de-compression methods */
189 void *data;
d32ca5ad
JQ
190} MultiFDRecvParams;
191
ab7cbb0b
JQ
192typedef struct {
193 /* Setup for sending side */
194 int (*send_setup)(MultiFDSendParams *p, Error **errp);
195 /* Cleanup for sending side */
196 void (*send_cleanup)(MultiFDSendParams *p, Error **errp);
197 /* Prepare the send packet */
02fb8104 198 int (*send_prepare)(MultiFDSendParams *p, Error **errp);
ab7cbb0b
JQ
199 /* Setup for receiving side */
200 int (*recv_setup)(MultiFDRecvParams *p, Error **errp);
201 /* Cleanup for receiving side */
202 void (*recv_cleanup)(MultiFDRecvParams *p);
203 /* Read all pages */
40a4bfe9 204 int (*recv_pages)(MultiFDRecvParams *p, Error **errp);
ab7cbb0b
JQ
205} MultiFDMethods;
206
7ec2c2b3
JQ
207void multifd_register_ops(int method, MultiFDMethods *ops);
208
d32ca5ad
JQ
209#endif
210