qemu_migration.h 11.6 KB
Newer Older
1 2 3
/*
 * qemu_migration.h: QEMU migration handling
 *
4
 * Copyright (C) 2006-2011, 2014 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library.  If not, see
O
Osier Yang 已提交
18
 * <http://www.gnu.org/licenses/>.
19 20 21 22 23 24 25
 *
 */

#ifndef __QEMU_MIGRATION_H__
# define __QEMU_MIGRATION_H__

# include "qemu_conf.h"
26
# include "qemu_domain.h"
27

28 29 30
typedef struct _qemuMigrationCompression qemuMigrationCompression;
typedef qemuMigrationCompression *qemuMigrationCompressionPtr;

31 32 33 34 35 36 37 38 39
/* All supported qemu migration flags.  */
# define QEMU_MIGRATION_FLAGS                   \
    (VIR_MIGRATE_LIVE |                         \
     VIR_MIGRATE_PEER2PEER |                    \
     VIR_MIGRATE_TUNNELLED |                    \
     VIR_MIGRATE_PERSIST_DEST |                 \
     VIR_MIGRATE_UNDEFINE_SOURCE |              \
     VIR_MIGRATE_PAUSED |                       \
     VIR_MIGRATE_NON_SHARED_DISK |              \
40
     VIR_MIGRATE_NON_SHARED_INC |               \
41
     VIR_MIGRATE_CHANGE_PROTECTION |            \
L
liguang 已提交
42
     VIR_MIGRATE_UNSAFE |                       \
43
     VIR_MIGRATE_OFFLINE |                      \
44
     VIR_MIGRATE_COMPRESSED |                   \
45
     VIR_MIGRATE_ABORT_ON_ERROR |               \
46
     VIR_MIGRATE_AUTO_CONVERGE |                \
47
     VIR_MIGRATE_RDMA_PIN_ALL |                 \
48 49
     VIR_MIGRATE_POSTCOPY |                     \
     VIR_MIGRATE_TLS)
50

51
/* All supported migration parameters and their types. */
52 53 54 55 56 57 58 59 60
# define QEMU_MIGRATION_PARAMETERS                                \
    VIR_MIGRATE_PARAM_URI,              VIR_TYPED_PARAM_STRING,   \
    VIR_MIGRATE_PARAM_DEST_NAME,        VIR_TYPED_PARAM_STRING,   \
    VIR_MIGRATE_PARAM_DEST_XML,         VIR_TYPED_PARAM_STRING,   \
    VIR_MIGRATE_PARAM_BANDWIDTH,        VIR_TYPED_PARAM_ULLONG,   \
    VIR_MIGRATE_PARAM_GRAPHICS_URI,     VIR_TYPED_PARAM_STRING,   \
    VIR_MIGRATE_PARAM_LISTEN_ADDRESS,   VIR_TYPED_PARAM_STRING,   \
    VIR_MIGRATE_PARAM_MIGRATE_DISKS,    VIR_TYPED_PARAM_STRING |  \
                                        VIR_TYPED_PARAM_MULTIPLE, \
61
    VIR_MIGRATE_PARAM_DISKS_PORT,       VIR_TYPED_PARAM_INT,      \
62 63
    VIR_MIGRATE_PARAM_COMPRESSION,      VIR_TYPED_PARAM_STRING |  \
                                        VIR_TYPED_PARAM_MULTIPLE, \
64 65 66 67
    VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL,         VIR_TYPED_PARAM_INT,    \
    VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS,       VIR_TYPED_PARAM_INT,    \
    VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS,      VIR_TYPED_PARAM_INT,    \
    VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE,     VIR_TYPED_PARAM_ULLONG, \
68
    VIR_MIGRATE_PARAM_PERSIST_XML,      VIR_TYPED_PARAM_STRING,   \
69 70
    VIR_MIGRATE_PARAM_AUTO_CONVERGE_INITIAL,        VIR_TYPED_PARAM_INT,    \
    VIR_MIGRATE_PARAM_AUTO_CONVERGE_INCREMENT,      VIR_TYPED_PARAM_INT,    \
71 72 73
    NULL


74
typedef enum {
75 76 77 78 79 80 81 82 83 84 85 86
    QEMU_MIGRATION_PHASE_NONE = 0,
    QEMU_MIGRATION_PHASE_PERFORM2,
    QEMU_MIGRATION_PHASE_BEGIN3,
    QEMU_MIGRATION_PHASE_PERFORM3,
    QEMU_MIGRATION_PHASE_PERFORM3_DONE,
    QEMU_MIGRATION_PHASE_CONFIRM3_CANCELLED,
    QEMU_MIGRATION_PHASE_CONFIRM3,
    QEMU_MIGRATION_PHASE_PREPARE,
    QEMU_MIGRATION_PHASE_FINISH2,
    QEMU_MIGRATION_PHASE_FINISH3,

    QEMU_MIGRATION_PHASE_LAST
87
} qemuMigrationJobPhase;
88 89
VIR_ENUM_DECL(qemuMigrationJobPhase)

90 91 92 93 94 95 96 97 98 99
typedef enum {
    QEMU_MIGRATION_COMPRESS_XBZRLE = 0,
    QEMU_MIGRATION_COMPRESS_MT,

    QEMU_MIGRATION_COMPRESS_LAST
} qemuMigrationCompressMethod;
VIR_ENUM_DECL(qemuMigrationCompressMethod)

struct _qemuMigrationCompression {
    unsigned long long methods;
100

101 102 103 104 105 106 107 108
    bool level_set;
    int level;

    bool threads_set;
    int threads;

    bool dthreads_set;
    int dthreads;
109 110 111

    bool xbzrle_cache_set;
    unsigned long long xbzrle_cache;
112 113 114 115 116 117 118 119 120 121 122 123
};

qemuMigrationCompressionPtr
qemuMigrationCompressionParse(virTypedParameterPtr params,
                              int nparams,
                              unsigned long flags);
int qemuMigrationCompressionDump(qemuMigrationCompressionPtr compression,
                                 virTypedParameterPtr *params,
                                 int *nparams,
                                 int *maxparams,
                                 unsigned long *flags);

124 125 126 127 128 129
void
qemuMigrationParamsClear(qemuMonitorMigrationParamsPtr migParams);

void
qemuMigrationParamsFree(qemuMonitorMigrationParamsPtr *migParams);

130 131 132 133 134
qemuMonitorMigrationParamsPtr
qemuMigrationParams(virTypedParameterPtr params,
                    int nparams,
                    unsigned long flags);

135
int qemuMigrationJobStart(virQEMUDriverPtr driver,
136
                          virDomainObjPtr vm,
137
                          qemuDomainAsyncJob job)
138
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
139
void qemuMigrationJobSetPhase(virQEMUDriverPtr driver,
140
                              virDomainObjPtr vm,
141
                              qemuMigrationJobPhase phase)
142
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
143
void qemuMigrationJobStartPhase(virQEMUDriverPtr driver,
144
                                virDomainObjPtr vm,
145
                                qemuMigrationJobPhase phase)
146
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
147 148
void qemuMigrationJobContinue(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
149
bool qemuMigrationJobIsActive(virDomainObjPtr vm,
150
                              qemuDomainAsyncJob job)
151
    ATTRIBUTE_NONNULL(1);
152 153
void qemuMigrationJobFinish(virQEMUDriverPtr driver, virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
154

155
int qemuMigrationSetOffline(virQEMUDriverPtr driver,
156 157
                            virDomainObjPtr vm);

158
char *qemuMigrationBegin(virConnectPtr conn,
159
                         virDomainObjPtr vm,
160
                         const char *xmlin,
161
                         const char *dname,
162
                         char **cookieout,
163
                         int *cookieoutlen,
164 165
                         size_t nmigrate_disks,
                         const char **migrate_disks,
166
                         unsigned long flags);
167

168 169
virDomainDefPtr qemuMigrationPrepareDef(virQEMUDriverPtr driver,
                                        const char *dom_xml,
170 171
                                        const char *dname,
                                        char **origname);
172

173
int qemuMigrationPrepareTunnel(virQEMUDriverPtr driver,
174
                               virConnectPtr dconn,
175 176 177 178
                               const char *cookiein,
                               int cookieinlen,
                               char **cookieout,
                               int *cookieoutlen,
179
                               virStreamPtr st,
180
                               virDomainDefPtr *def,
181
                               const char *origname,
L
liguang 已提交
182
                               unsigned long flags);
183

184
int qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
185
                               virConnectPtr dconn,
186 187 188 189
                               const char *cookiein,
                               int cookieinlen,
                               char **cookieout,
                               int *cookieoutlen,
190 191
                               const char *uri_in,
                               char **uri_out,
192
                               virDomainDefPtr *def,
193
                               const char *origname,
194
                               const char *listenAddress,
195 196
                               size_t nmigrate_disks,
                               const char **migrate_disks,
197
                               int nbdPort,
198
                               qemuMigrationCompressionPtr compression,
L
liguang 已提交
199
                               unsigned long flags);
200

201
int qemuMigrationPerform(virQEMUDriverPtr driver,
202 203
                         virConnectPtr conn,
                         virDomainObjPtr vm,
204
                         const char *xmlin,
205
                         const char *persist_xml,
206
                         const char *dconnuri,
207
                         const char *uri,
208
                         const char *graphicsuri,
209
                         const char *listenAddress,
210 211
                         size_t nmigrate_disks,
                         const char **migrate_disks,
212
                         int nbdPort,
213
                         qemuMigrationCompressionPtr compression,
214
                         qemuMonitorMigrationParamsPtr migParams,
215 216 217 218
                         const char *cookiein,
                         int cookieinlen,
                         char **cookieout,
                         int *cookieoutlen,
219 220
                         unsigned long flags,
                         const char *dname,
221
                         unsigned long resource,
222
                         bool v3proto);
223

224
virDomainPtr qemuMigrationFinish(virQEMUDriverPtr driver,
225 226
                                 virConnectPtr dconn,
                                 virDomainObjPtr vm,
227 228 229 230
                                 const char *cookiein,
                                 int cookieinlen,
                                 char **cookieout,
                                 int *cookieoutlen,
231
                                 unsigned long flags,
232 233
                                 int retcode,
                                 bool v3proto);
234

235
int qemuMigrationConfirm(virConnectPtr conn,
236 237 238 239
                         virDomainObjPtr vm,
                         const char *cookiein,
                         int cookieinlen,
                         unsigned int flags,
240
                         int cancelled);
241

242
bool qemuMigrationIsAllowed(virQEMUDriverPtr driver, virDomainObjPtr vm,
243
                            bool remote, unsigned int flags);
244

245 246 247
int qemuMigrationToFile(virQEMUDriverPtr driver,
                        virDomainObjPtr vm,
                        int fd,
248
                        const char *compressor,
249
                        qemuDomainAsyncJob asyncJob)
250
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
251

252 253 254
int qemuMigrationCancel(virQEMUDriverPtr driver,
                        virDomainObjPtr vm);

255 256 257 258 259
int qemuMigrationFetchJobStatus(virQEMUDriverPtr driver,
                                virDomainObjPtr vm,
                                qemuDomainAsyncJob asyncJob,
                                qemuDomainJobInfoPtr jobInfo);

260 261 262 263 264 265 266
int qemuMigrationErrorInit(virQEMUDriverPtr driver);
void qemuMigrationErrorSave(virQEMUDriverPtr driver,
                            const char *name,
                            virErrorPtr err);
void qemuMigrationErrorReport(virQEMUDriverPtr driver,
                              const char *name);

267 268 269 270 271 272
int qemuMigrationCheckIncoming(virQEMUCapsPtr qemuCaps,
                               const char *migrateFrom);

char *qemuMigrationIncomingURI(const char *migrateFrom,
                               int migrateFd);

273 274 275 276 277
int qemuMigrationRunIncoming(virQEMUDriverPtr driver,
                             virDomainObjPtr vm,
                             const char *uri,
                             qemuDomainAsyncJob asyncJob);

278 279 280
void qemuMigrationPostcopyFailed(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm);

281 282 283 284 285 286 287
int
qemuMigrationResetTLS(virQEMUDriverPtr driver,
                      virDomainObjPtr vm,
                      qemuDomainAsyncJob asyncJob,
                      char *in_tlsAlias,
                      char *in_secAlias);

288
#endif /* __QEMU_MIGRATION_H__ */