qemu_domain.h 12.2 KB
Newer Older
1 2 3
/*
 * qemu_domain.h: QEMU domain private state
 *
4
 * Copyright (C) 2006-2013 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 "domain_conf.h"
29
# include "snapshot_conf.h"
30
# include "qemu_monitor.h"
D
Daniel P. Berrange 已提交
31
# include "qemu_agent.h"
32
# include "qemu_conf.h"
33
# include "qemu_capabilities.h"
34
# include "virchrdev.h"
35

M
Matthias Bolte 已提交
36 37 38 39 40 41
# 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))

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

46 47 48
# 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.  */
49
#  define QEMU_DOMAIN_MIG_BANDWIDTH_MAX ULONG_MAX
50
# else
51
#  define QEMU_DOMAIN_MIG_BANDWIDTH_MAX (INT64_MAX / (1024 * 1024))
52
# endif
53

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

60 61 62 63 64
/* 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))

65 66 67 68 69
/* 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 */
70 71 72 73
    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 */
74
    QEMU_JOB_ABORT,         /* Abort current async job */
75
    QEMU_JOB_MIGRATION_OP,  /* Operation influencing outgoing migration */
76

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

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

/* 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,
95
    QEMU_ASYNC_JOB_SNAPSHOT,
96 97

    QEMU_ASYNC_JOB_LAST
98
};
99
VIR_ENUM_DECL(qemuDomainAsyncJob)
100

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

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

117 118 119
typedef struct _qemuDomainPCIAddressSet qemuDomainPCIAddressSet;
typedef qemuDomainPCIAddressSet *qemuDomainPCIAddressSetPtr;

120
typedef void (*qemuDomainCleanupCallback)(virQEMUDriverPtr driver,
121 122
                                          virDomainObjPtr vm);

123 124 125
typedef struct _qemuDomainObjPrivate qemuDomainObjPrivate;
typedef qemuDomainObjPrivate *qemuDomainObjPrivatePtr;
struct _qemuDomainObjPrivate {
126
    struct qemuDomainJobObj job;
127 128

    qemuMonitorPtr mon;
129
    virDomainChrSourceDefPtr monConfig;
130
    int monJSON;
131 132
    bool monError;
    unsigned long long monStart;
D
Daniel P. Berrange 已提交
133 134 135 136 137

    qemuAgentPtr agent;
    bool agentError;
    unsigned long long agentStart;

138
    bool gotShutdown;
139
    bool beingDestroyed;
140
    char *pidfile;
141 142 143 144 145 146

    int nvcpupids;
    int *vcpupids;

    qemuDomainPCIAddressSetPtr pciaddrs;
    int persistentAddrs;
147

148
    virQEMUCapsPtr qemuCaps;
149
    char *lockState;
150 151

    bool fakeReboot;
152 153

    int jobs_queued;
154 155

    unsigned long migMaxBandwidth;
J
Jiri Denemark 已提交
156
    char *origname;
157

158
    virChrdevsPtr devs;
159 160 161 162

    qemuDomainCleanupCallback *cleanupCallbacks;
    size_t ncleanupCallbacks;
    size_t ncleanupCallbacks_max;
163 164
};

165 166 167 168 169 170
struct qemuDomainWatchdogEvent
{
    virDomainObjPtr vm;
    int action;
};

J
Jiri Denemark 已提交
171 172 173 174 175
const char *qemuDomainAsyncJobPhaseToString(enum qemuDomainAsyncJob job,
                                            int phase);
int qemuDomainAsyncJobPhaseFromString(enum qemuDomainAsyncJob job,
                                      const char *phase);

176
void qemuDomainEventFlush(int timer, void *opaque);
177

178
void qemuDomainEventQueue(virQEMUDriverPtr driver,
179
                          virDomainEventPtr event);
180 181 182 183

void qemuDomainSetPrivateDataHooks(virCapsPtr caps);
void qemuDomainSetNamespaceHooks(virCapsPtr caps);

184
int qemuDomainObjBeginJob(virQEMUDriverPtr driver,
185
                          virDomainObjPtr obj,
186 187
                          enum qemuDomainJob job)
    ATTRIBUTE_RETURN_CHECK;
188
int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver,
189
                               virDomainObjPtr obj,
190 191 192
                               enum qemuDomainAsyncJob asyncJob)
    ATTRIBUTE_RETURN_CHECK;

193
bool qemuDomainObjEndJob(virQEMUDriverPtr driver,
194
                         virDomainObjPtr obj)
195
    ATTRIBUTE_RETURN_CHECK;
196
bool qemuDomainObjEndAsyncJob(virQEMUDriverPtr driver,
197
                              virDomainObjPtr obj)
198
    ATTRIBUTE_RETURN_CHECK;
199
void qemuDomainObjAbortAsyncJob(virDomainObjPtr obj);
200
void qemuDomainObjSetJobPhase(virQEMUDriverPtr driver,
J
Jiri Denemark 已提交
201 202
                              virDomainObjPtr obj,
                              int phase);
203 204
void qemuDomainObjSetAsyncJobMask(virDomainObjPtr obj,
                                  unsigned long long allowedJobs);
205 206
void qemuDomainObjRestoreJob(virDomainObjPtr obj,
                             struct qemuDomainJobObj *job);
207
void qemuDomainObjTransferJob(virDomainObjPtr obj);
208
void qemuDomainObjDiscardAsyncJob(virQEMUDriverPtr driver,
209
                                  virDomainObjPtr obj);
210
void qemuDomainObjReleaseAsyncJob(virDomainObjPtr obj);
211

212
void qemuDomainObjEnterMonitor(virQEMUDriverPtr driver,
213 214
                               virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
215
void qemuDomainObjExitMonitor(virQEMUDriverPtr driver,
216 217
                              virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
218
int qemuDomainObjEnterMonitorAsync(virQEMUDriverPtr driver,
219 220 221
                                   virDomainObjPtr obj,
                                   enum qemuDomainAsyncJob asyncJob)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
D
Daniel P. Berrange 已提交
222 223


224 225 226 227
void qemuDomainObjEnterAgent(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
void qemuDomainObjExitAgent(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
D
Daniel P. Berrange 已提交
228 229


230 231 232 233
void qemuDomainObjEnterRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
void qemuDomainObjExitRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
234

235
int qemuDomainDefFormatBuf(virQEMUDriverPtr driver,
236 237 238 239
                           virDomainDefPtr vm,
                           unsigned int flags,
                           virBuffer *buf);

240
char *qemuDomainDefFormatXML(virQEMUDriverPtr driver,
241
                             virDomainDefPtr vm,
242
                             unsigned int flags);
243

244
char *qemuDomainFormatXML(virQEMUDriverPtr driver,
245
                          virDomainObjPtr vm,
246
                          unsigned int flags);
247

248
char *qemuDomainDefFormatLive(virQEMUDriverPtr driver,
249
                              virDomainDefPtr def,
250 251
                              bool inactive,
                              bool compatible);
252

253
void qemuDomainObjTaint(virQEMUDriverPtr driver,
254
                        virDomainObjPtr obj,
255 256
                        enum virDomainTaintFlags taint,
                        int logFD);
257

258
void qemuDomainObjCheckTaint(virQEMUDriverPtr driver,
259 260
                             virDomainObjPtr obj,
                             int logFD);
261
void qemuDomainObjCheckDiskTaint(virQEMUDriverPtr driver,
262
                                 virDomainObjPtr obj,
263 264
                                 virDomainDiskDefPtr disk,
                                 int logFD);
265
void qemuDomainObjCheckNetTaint(virQEMUDriverPtr driver,
266
                                virDomainObjPtr obj,
267 268
                                virDomainNetDefPtr net,
                                int logFD);
269

270

271 272 273
int qemuDomainCreateLog(virQEMUDriverPtr driver, virDomainObjPtr vm, bool append);
int qemuDomainOpenLog(virQEMUDriverPtr driver, virDomainObjPtr vm, off_t pos);
int qemuDomainAppendLog(virQEMUDriverPtr driver,
274 275 276
                        virDomainObjPtr vm,
                        int logFD,
                        const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(4, 5);
277

278
const char *qemuFindQemuImgBinary(virQEMUDriverPtr driver);
279 280 281 282 283

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

284
int qemuDomainSnapshotForEachQcow2(virQEMUDriverPtr driver,
285 286 287 288 289
                                   virDomainObjPtr vm,
                                   virDomainSnapshotObjPtr snap,
                                   const char *op,
                                   bool try_all);

290
int qemuDomainSnapshotDiscard(virQEMUDriverPtr driver,
291 292 293 294 295
                              virDomainObjPtr vm,
                              virDomainSnapshotObjPtr snap,
                              bool update_current,
                              bool metadata_only);

296 297 298
typedef struct _virQEMUSnapRemove virQEMUSnapRemove;
typedef virQEMUSnapRemove *virQEMUSnapRemovePtr;
struct _virQEMUSnapRemove {
299
    virQEMUDriverPtr driver;
300 301 302 303 304 305 306 307 308 309
    virDomainObjPtr vm;
    int err;
    bool metadata_only;
    bool current;
};

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

310
int qemuDomainSnapshotDiscardAllMetadata(virQEMUDriverPtr driver,
311 312
                                         virDomainObjPtr vm);

313
void qemuDomainRemoveInactive(virQEMUDriverPtr driver,
314 315
                              virDomainObjPtr vm);

316
void qemuDomainSetFakeReboot(virQEMUDriverPtr driver,
317 318 319
                             virDomainObjPtr vm,
                             bool value);

320 321
bool qemuDomainJobAllowed(qemuDomainObjPrivatePtr priv,
                          enum qemuDomainJob job);
M
Michal Privoznik 已提交
322

323
int qemuDomainCheckDiskPresence(virQEMUDriverPtr driver,
M
Michal Privoznik 已提交
324 325
                                virDomainObjPtr vm,
                                bool start_with_state);
326
int qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
327 328
                                 virDomainDiskDefPtr disk,
                                 bool force);
329 330 331 332 333

int qemuDomainCleanupAdd(virDomainObjPtr vm,
                         qemuDomainCleanupCallback cb);
void qemuDomainCleanupRemove(virDomainObjPtr vm,
                             qemuDomainCleanupCallback cb);
334
void qemuDomainCleanupRun(virQEMUDriverPtr driver,
335 336
                          virDomainObjPtr vm);

337
#endif /* __QEMU_DOMAIN_H__ */