qemu_domain.h 14.0 KB
Newer Older
1 2 3
/*
 * qemu_domain.h: QEMU domain private state
 *
4
 * Copyright (C) 2006-2014 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16 17
 * Copyright (C) 2006 Daniel P. Berrange
 *
 * 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
18
 * License along with this library.  If not, see
O
Osier Yang 已提交
19
 * <http://www.gnu.org/licenses/>.
20 21 22 23 24 25 26
 *
 * Author: Daniel P. Berrange <berrange@redhat.com>
 */

#ifndef __QEMU_DOMAIN_H__
# define __QEMU_DOMAIN_H__

27
# include "virthread.h"
28
# include "vircgroup.h"
29
# include "domain_conf.h"
30
# include "snapshot_conf.h"
31
# include "qemu_monitor.h"
D
Daniel P. Berrange 已提交
32
# include "qemu_agent.h"
33
# include "qemu_conf.h"
34
# include "qemu_capabilities.h"
35
# include "virchrdev.h"
36

M
Matthias Bolte 已提交
37 38 39 40 41 42
# define QEMU_EXPECTED_VIRT_TYPES      \
    ((1 << VIR_DOMAIN_VIRT_QEMU) |     \
     (1 << VIR_DOMAIN_VIRT_KQEMU) |    \
     (1 << VIR_DOMAIN_VIRT_KVM) |      \
     (1 << VIR_DOMAIN_VIRT_XEN))

43 44 45 46
# define QEMU_DOMAIN_FORMAT_LIVE_FLAGS      \
    (VIR_DOMAIN_XML_SECURE |                \
     VIR_DOMAIN_XML_UPDATE_CPU)

47 48 49
# if ULONG_MAX == 4294967295
/* Qemu has a 64-bit limit, but we are limited by our historical choice of
 * representing bandwidth in a long instead of a 64-bit int.  */
50
#  define QEMU_DOMAIN_MIG_BANDWIDTH_MAX ULONG_MAX
51
# else
52
#  define QEMU_DOMAIN_MIG_BANDWIDTH_MAX (INT64_MAX / (1024 * 1024))
53
# endif
54

55 56
# define JOB_MASK(job)                  (1 << (job - 1))
# define DEFAULT_JOB_MASK               \
57 58 59
    (JOB_MASK(QEMU_JOB_QUERY) |         \
     JOB_MASK(QEMU_JOB_DESTROY) |       \
     JOB_MASK(QEMU_JOB_ABORT))
60

61 62 63 64 65
/* Jobs which have to be tracked in domain state XML. */
# define QEMU_DOMAIN_TRACK_JOBS         \
    (JOB_MASK(QEMU_JOB_DESTROY) |       \
     JOB_MASK(QEMU_JOB_ASYNC))

66 67 68 69 70
/* Only 1 job is allowed at any time
 * A job includes *all* monitor commands, even those just querying
 * information, not merely actions */
enum qemuDomainJob {
    QEMU_JOB_NONE = 0,  /* Always set to 0 for easy if (jobActive) conditions */
71 72 73 74
    QEMU_JOB_QUERY,         /* Doesn't change any state */
    QEMU_JOB_DESTROY,       /* Destroys the domain (cannot be masked out) */
    QEMU_JOB_SUSPEND,       /* Suspends (stops vCPUs) the domain */
    QEMU_JOB_MODIFY,        /* May change state */
75
    QEMU_JOB_ABORT,         /* Abort current async job */
76
    QEMU_JOB_MIGRATION_OP,  /* Operation influencing outgoing migration */
77

78
    /* The following two items must always be the last items before JOB_LAST */
79 80
    QEMU_JOB_ASYNC,         /* Asynchronous job */
    QEMU_JOB_ASYNC_NESTED,  /* Normal job within an async job */
81 82

    QEMU_JOB_LAST
83
};
84
VIR_ENUM_DECL(qemuDomainJob)
85 86 87 88 89 90 91 92 93 94 95

/* Async job consists of a series of jobs that may change state. Independent
 * jobs that do not change state (and possibly others if explicitly allowed by
 * current async job) are allowed to be run even if async job is active.
 */
enum qemuDomainAsyncJob {
    QEMU_ASYNC_JOB_NONE = 0,
    QEMU_ASYNC_JOB_MIGRATION_OUT,
    QEMU_ASYNC_JOB_MIGRATION_IN,
    QEMU_ASYNC_JOB_SAVE,
    QEMU_ASYNC_JOB_DUMP,
96
    QEMU_ASYNC_JOB_SNAPSHOT,
97 98

    QEMU_ASYNC_JOB_LAST
99
};
100
VIR_ENUM_DECL(qemuDomainAsyncJob)
101

102
struct qemuDomainJobObj {
103 104
    virCond cond;                       /* Use to coordinate jobs */
    enum qemuDomainJob active;          /* Currently running job */
105
    unsigned long long owner;           /* Thread id which set current job */
106

107 108
    virCond asyncCond;                  /* Use to coordinate with async jobs */
    enum qemuDomainAsyncJob asyncJob;   /* Currently active async job */
109
    unsigned long long asyncOwner;      /* Thread which set current async job */
J
Jiri Denemark 已提交
110
    int phase;                          /* Job phase (mainly for migrations) */
111 112
    unsigned long long mask;            /* Jobs allowed during async job */
    unsigned long long start;           /* When the async job started */
113
    bool dump_memory_only;              /* use dump-guest-memory to do dump */
114 115
    qemuMonitorMigrationStatus status;  /* Raw async job progress data */
    virDomainJobInfo info;              /* Processed async job progress data */
116
    bool asyncAbort;                    /* abort of async job requested */
117 118
};

119 120 121
typedef struct _qemuDomainPCIAddressSet qemuDomainPCIAddressSet;
typedef qemuDomainPCIAddressSet *qemuDomainPCIAddressSetPtr;

122
typedef void (*qemuDomainCleanupCallback)(virQEMUDriverPtr driver,
123
                                          virDomainObjPtr vm);
124 125
typedef struct _qemuDomainCCWAddressSet qemuDomainCCWAddressSet;
typedef qemuDomainCCWAddressSet *qemuDomainCCWAddressSetPtr;
126

127 128 129
typedef struct _qemuDomainObjPrivate qemuDomainObjPrivate;
typedef qemuDomainObjPrivate *qemuDomainObjPrivatePtr;
struct _qemuDomainObjPrivate {
130
    struct qemuDomainJobObj job;
131 132

    qemuMonitorPtr mon;
133
    virDomainChrSourceDefPtr monConfig;
E
Eric Blake 已提交
134
    bool monJSON;
135 136
    bool monError;
    unsigned long long monStart;
D
Daniel P. Berrange 已提交
137 138 139 140 141

    qemuAgentPtr agent;
    bool agentError;
    unsigned long long agentStart;

142
    bool gotShutdown;
143
    bool beingDestroyed;
144
    char *pidfile;
145 146 147 148 149

    int nvcpupids;
    int *vcpupids;

    qemuDomainPCIAddressSetPtr pciaddrs;
150
    qemuDomainCCWAddressSetPtr ccwaddrs;
151
    int persistentAddrs;
152

153
    virQEMUCapsPtr qemuCaps;
154
    char *lockState;
155 156

    bool fakeReboot;
157 158

    int jobs_queued;
159 160

    unsigned long migMaxBandwidth;
J
Jiri Denemark 已提交
161
    char *origname;
162
    int nbdPort; /* Port used for migration with NBD */
163
    unsigned short migrationPort;
164
    int preMigrationState;
165

166
    virChrdevsPtr devs;
167 168 169 170

    qemuDomainCleanupCallback *cleanupCallbacks;
    size_t ncleanupCallbacks;
    size_t ncleanupCallbacks_max;
171 172

    virCgroupPtr cgroup;
173 174 175

    virCond unplugFinished; /* signals that unpluggingDevice was unplugged */
    const char *unpluggingDevice; /* alias of the device that is being unplugged */
176
    char **qemuDevices; /* NULL-terminated list of devices aliases known to QEMU */
177 178

    bool hookRun;  /* true if there was a hook run over this domain */
179 180
};

C
Chen Fan 已提交
181 182
typedef enum {
    QEMU_PROCESS_EVENT_WATCHDOG = 0,
183
    QEMU_PROCESS_EVENT_GUESTPANIC,
C
Chen Fan 已提交
184 185 186 187 188

    QEMU_PROCESS_EVENT_LAST
} qemuProcessEventType;

struct qemuProcessEvent {
189
    virDomainObjPtr vm;
C
Chen Fan 已提交
190
    qemuProcessEventType eventType;
191 192 193
    int action;
};

J
Jiri Denemark 已提交
194 195 196 197 198
const char *qemuDomainAsyncJobPhaseToString(enum qemuDomainAsyncJob job,
                                            int phase);
int qemuDomainAsyncJobPhaseFromString(enum qemuDomainAsyncJob job,
                                      const char *phase);

199
void qemuDomainEventFlush(int timer, void *opaque);
200

201
void qemuDomainEventQueue(virQEMUDriverPtr driver,
202
                          virObjectEventPtr event);
203

204
int qemuDomainObjBeginJob(virQEMUDriverPtr driver,
205
                          virDomainObjPtr obj,
206 207
                          enum qemuDomainJob job)
    ATTRIBUTE_RETURN_CHECK;
208
int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver,
209
                               virDomainObjPtr obj,
210 211
                               enum qemuDomainAsyncJob asyncJob)
    ATTRIBUTE_RETURN_CHECK;
212 213 214 215
int qemuDomainObjBeginNestedJob(virQEMUDriverPtr driver,
                                virDomainObjPtr obj,
                                enum qemuDomainAsyncJob asyncJob)
    ATTRIBUTE_RETURN_CHECK;
216

217
bool qemuDomainObjEndJob(virQEMUDriverPtr driver,
218
                         virDomainObjPtr obj)
219
    ATTRIBUTE_RETURN_CHECK;
220
bool qemuDomainObjEndAsyncJob(virQEMUDriverPtr driver,
221
                              virDomainObjPtr obj)
222
    ATTRIBUTE_RETURN_CHECK;
223
void qemuDomainObjAbortAsyncJob(virDomainObjPtr obj);
224
void qemuDomainObjSetJobPhase(virQEMUDriverPtr driver,
J
Jiri Denemark 已提交
225 226
                              virDomainObjPtr obj,
                              int phase);
227 228
void qemuDomainObjSetAsyncJobMask(virDomainObjPtr obj,
                                  unsigned long long allowedJobs);
229 230
void qemuDomainObjRestoreJob(virDomainObjPtr obj,
                             struct qemuDomainJobObj *job);
231
void qemuDomainObjTransferJob(virDomainObjPtr obj);
232
void qemuDomainObjDiscardAsyncJob(virQEMUDriverPtr driver,
233
                                  virDomainObjPtr obj);
234
void qemuDomainObjReleaseAsyncJob(virDomainObjPtr obj);
235

236
void qemuDomainObjEnterMonitor(virQEMUDriverPtr driver,
237 238
                               virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
239
void qemuDomainObjExitMonitor(virQEMUDriverPtr driver,
240 241
                              virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
242
int qemuDomainObjEnterMonitorAsync(virQEMUDriverPtr driver,
243 244 245
                                   virDomainObjPtr obj,
                                   enum qemuDomainAsyncJob asyncJob)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
D
Daniel P. Berrange 已提交
246 247


248 249 250 251
void qemuDomainObjEnterAgent(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
void qemuDomainObjExitAgent(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
D
Daniel P. Berrange 已提交
252 253


254 255 256 257
void qemuDomainObjEnterRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
void qemuDomainObjExitRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
258

259 260 261 262
virDomainDefPtr qemuDomainDefCopy(virQEMUDriverPtr driver,
                                  virDomainDefPtr src,
                                  unsigned int flags);

263
int qemuDomainDefFormatBuf(virQEMUDriverPtr driver,
264 265 266 267
                           virDomainDefPtr vm,
                           unsigned int flags,
                           virBuffer *buf);

268
char *qemuDomainDefFormatXML(virQEMUDriverPtr driver,
269
                             virDomainDefPtr vm,
270
                             unsigned int flags);
271

272
char *qemuDomainFormatXML(virQEMUDriverPtr driver,
273
                          virDomainObjPtr vm,
274
                          unsigned int flags);
275

276
char *qemuDomainDefFormatLive(virQEMUDriverPtr driver,
277
                              virDomainDefPtr def,
278 279
                              bool inactive,
                              bool compatible);
280

281
void qemuDomainObjTaint(virQEMUDriverPtr driver,
282
                        virDomainObjPtr obj,
283 284
                        enum virDomainTaintFlags taint,
                        int logFD);
285

286
void qemuDomainObjCheckTaint(virQEMUDriverPtr driver,
287 288
                             virDomainObjPtr obj,
                             int logFD);
289
void qemuDomainObjCheckDiskTaint(virQEMUDriverPtr driver,
290
                                 virDomainObjPtr obj,
291 292
                                 virDomainDiskDefPtr disk,
                                 int logFD);
293
void qemuDomainObjCheckNetTaint(virQEMUDriverPtr driver,
294
                                virDomainObjPtr obj,
295 296
                                virDomainNetDefPtr net,
                                int logFD);
297

298

299 300 301
int qemuDomainCreateLog(virQEMUDriverPtr driver, virDomainObjPtr vm, bool append);
int qemuDomainOpenLog(virQEMUDriverPtr driver, virDomainObjPtr vm, off_t pos);
int qemuDomainAppendLog(virQEMUDriverPtr driver,
302 303 304
                        virDomainObjPtr vm,
                        int logFD,
                        const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(4, 5);
305

306
const char *qemuFindQemuImgBinary(virQEMUDriverPtr driver);
307 308 309 310 311

int qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
                                    virDomainSnapshotObjPtr snapshot,
                                    char *snapshotDir);

312
int qemuDomainSnapshotForEachQcow2(virQEMUDriverPtr driver,
313 314 315 316 317
                                   virDomainObjPtr vm,
                                   virDomainSnapshotObjPtr snap,
                                   const char *op,
                                   bool try_all);

318
int qemuDomainSnapshotDiscard(virQEMUDriverPtr driver,
319 320 321 322 323
                              virDomainObjPtr vm,
                              virDomainSnapshotObjPtr snap,
                              bool update_current,
                              bool metadata_only);

324 325 326
typedef struct _virQEMUSnapRemove virQEMUSnapRemove;
typedef virQEMUSnapRemove *virQEMUSnapRemovePtr;
struct _virQEMUSnapRemove {
327
    virQEMUDriverPtr driver;
328 329 330 331 332 333 334 335 336 337
    virDomainObjPtr vm;
    int err;
    bool metadata_only;
    bool current;
};

void qemuDomainSnapshotDiscardAll(void *payload,
                                  const void *name,
                                  void *data);

338
int qemuDomainSnapshotDiscardAllMetadata(virQEMUDriverPtr driver,
339 340
                                         virDomainObjPtr vm);

341
void qemuDomainRemoveInactive(virQEMUDriverPtr driver,
342 343
                              virDomainObjPtr vm);

344
void qemuDomainSetFakeReboot(virQEMUDriverPtr driver,
345 346 347
                             virDomainObjPtr vm,
                             bool value);

348 349
bool qemuDomainJobAllowed(qemuDomainObjPrivatePtr priv,
                          enum qemuDomainJob job);
M
Michal Privoznik 已提交
350

351
int qemuDomainCheckDiskPresence(virQEMUDriverPtr driver,
M
Michal Privoznik 已提交
352 353
                                virDomainObjPtr vm,
                                bool start_with_state);
354 355 356

int qemuDiskChainCheckBroken(virDomainDiskDefPtr disk);

357
int qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
358
                                 virDomainObjPtr vm,
359 360
                                 virDomainDiskDefPtr disk,
                                 bool force);
361 362 363 364 365

int qemuDomainCleanupAdd(virDomainObjPtr vm,
                         qemuDomainCleanupCallback cb);
void qemuDomainCleanupRemove(virDomainObjPtr vm,
                             qemuDomainCleanupCallback cb);
366
void qemuDomainCleanupRun(virQEMUDriverPtr driver,
367 368
                          virDomainObjPtr vm);

369 370
extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks;
extern virDomainXMLNamespace virQEMUDriverDomainXMLNamespace;
371
extern virDomainDefParserConfig virQEMUDriverDomainDefParserConfig;
372

373 374 375
int qemuDomainUpdateDeviceList(virQEMUDriverPtr driver,
                               virDomainObjPtr vm);

376 377 378
bool qemuDomainDefCheckABIStability(virQEMUDriverPtr driver,
                                    virDomainDefPtr src,
                                    virDomainDefPtr dst);
379 380 381 382

bool qemuDomainAgentAvailable(qemuDomainObjPrivatePtr priv,
                              bool reportError);

383
#endif /* __QEMU_DOMAIN_H__ */