You need to sign in or sign up before continuing.
qemu_domain.h 16.3 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_addr.h"
30
# include "domain_conf.h"
31
# include "snapshot_conf.h"
32
# include "qemu_monitor.h"
D
Daniel P. Berrange 已提交
33
# include "qemu_agent.h"
34
# include "qemu_conf.h"
35
# include "qemu_capabilities.h"
36
# include "virchrdev.h"
37

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

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

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

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

62 63 64 65 66
/* 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))

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 */
70
typedef enum {
71
    QEMU_JOB_NONE = 0,  /* Always set to 0 for easy if (jobActive) conditions */
72 73 74 75
    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 */
76
    QEMU_JOB_ABORT,         /* Abort current async job */
77
    QEMU_JOB_MIGRATION_OP,  /* Operation influencing outgoing migration */
78

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

    QEMU_JOB_LAST
84
} qemuDomainJob;
85
VIR_ENUM_DECL(qemuDomainJob)
86 87 88 89 90

/* 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.
 */
91
typedef enum {
92 93 94 95 96
    QEMU_ASYNC_JOB_NONE = 0,
    QEMU_ASYNC_JOB_MIGRATION_OUT,
    QEMU_ASYNC_JOB_MIGRATION_IN,
    QEMU_ASYNC_JOB_SAVE,
    QEMU_ASYNC_JOB_DUMP,
97
    QEMU_ASYNC_JOB_SNAPSHOT,
98 99

    QEMU_ASYNC_JOB_LAST
100
} qemuDomainAsyncJob;
101
VIR_ENUM_DECL(qemuDomainAsyncJob)
102

J
Jiri Denemark 已提交
103 104 105 106 107
typedef struct _qemuDomainJobInfo qemuDomainJobInfo;
typedef qemuDomainJobInfo *qemuDomainJobInfoPtr;
struct _qemuDomainJobInfo {
    virDomainJobType type;
    unsigned long long started; /* When the async job started */
108
    unsigned long long stopped; /* When the domain's CPUs were stopped */
J
Jiri Denemark 已提交
109 110 111 112 113 114 115
    /* Computed values */
    unsigned long long timeElapsed;
    unsigned long long timeRemaining;
    /* Raw values from QEMU */
    qemuMonitorMigrationStatus status;
};

116
struct qemuDomainJobObj {
117
    virCond cond;                       /* Use to coordinate jobs */
118
    qemuDomainJob active;               /* Currently running job */
119
    unsigned long long owner;           /* Thread id which set current job */
120
    const char *ownerAPI;               /* The API which owns the job */
J
Jiri Denemark 已提交
121
    unsigned long long started;         /* When the current job started */
122

123
    virCond asyncCond;                  /* Use to coordinate with async jobs */
124
    qemuDomainAsyncJob asyncJob;        /* Currently active async job */
125
    unsigned long long asyncOwner;      /* Thread which set current async job */
126
    const char *asyncOwnerAPI;          /* The API which owns the async job */
J
Jiri Denemark 已提交
127
    unsigned long long asyncStarted;    /* When the current async job started */
J
Jiri Denemark 已提交
128
    int phase;                          /* Job phase (mainly for migrations) */
129
    unsigned long long mask;            /* Jobs allowed during async job */
130
    bool dump_memory_only;              /* use dump-guest-memory to do dump */
J
Jiri Denemark 已提交
131
    qemuDomainJobInfoPtr current;       /* async job progress data */
132
    qemuDomainJobInfoPtr completed;     /* statistics data of a recently completed job */
133
    bool asyncAbort;                    /* abort of async job requested */
134 135
};

136
typedef void (*qemuDomainCleanupCallback)(virQEMUDriverPtr driver,
137 138
                                          virDomainObjPtr vm);

139 140 141
typedef struct _qemuDomainObjPrivate qemuDomainObjPrivate;
typedef qemuDomainObjPrivate *qemuDomainObjPrivatePtr;
struct _qemuDomainObjPrivate {
142
    struct qemuDomainJobObj job;
143 144

    qemuMonitorPtr mon;
145
    virDomainChrSourceDefPtr monConfig;
E
Eric Blake 已提交
146
    bool monJSON;
147 148
    bool monError;
    unsigned long long monStart;
D
Daniel P. Berrange 已提交
149 150 151 152 153

    qemuAgentPtr agent;
    bool agentError;
    unsigned long long agentStart;

154
    bool gotShutdown;
155
    bool beingDestroyed;
156
    char *pidfile;
157 158 159 160

    int nvcpupids;
    int *vcpupids;

161 162 163
    int niothreadpids;
    int *iothreadpids;

164
    virDomainPCIAddressSetPtr pciaddrs;
J
Ján Tomko 已提交
165
    virDomainCCWAddressSetPtr ccwaddrs;
166
    virDomainVirtioSerialAddrSetPtr vioserialaddrs;
167
    int persistentAddrs;
168

169
    virQEMUCapsPtr qemuCaps;
170
    char *lockState;
171 172

    bool fakeReboot;
173 174

    int jobs_queued;
175 176

    unsigned long migMaxBandwidth;
J
Jiri Denemark 已提交
177
    char *origname;
178
    int nbdPort; /* Port used for migration with NBD */
179
    unsigned short migrationPort;
180
    int preMigrationState;
181

182
    virChrdevsPtr devs;
183 184 185 186

    qemuDomainCleanupCallback *cleanupCallbacks;
    size_t ncleanupCallbacks;
    size_t ncleanupCallbacks_max;
187 188

    virCgroupPtr cgroup;
189 190 191

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

    bool hookRun;  /* true if there was a hook run over this domain */
195 196

    /* Bitmaps below hold data from the auto NUMA feature */
197
    virBitmapPtr autoNodeset;
198
    virBitmapPtr autoCpuset;
199 200
};

C
Chen Fan 已提交
201 202
typedef enum {
    QEMU_PROCESS_EVENT_WATCHDOG = 0,
203
    QEMU_PROCESS_EVENT_GUESTPANIC,
204
    QEMU_PROCESS_EVENT_DEVICE_DELETED,
205
    QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED,
206
    QEMU_PROCESS_EVENT_SERIAL_CHANGED,
207
    QEMU_PROCESS_EVENT_BLOCK_JOB,
C
Chen Fan 已提交
208 209 210 211 212

    QEMU_PROCESS_EVENT_LAST
} qemuProcessEventType;

struct qemuProcessEvent {
213
    virDomainObjPtr vm;
C
Chen Fan 已提交
214
    qemuProcessEventType eventType;
215
    int action;
216
    int status;
217
    void *data;
218 219
};

220
const char *qemuDomainAsyncJobPhaseToString(qemuDomainAsyncJob job,
J
Jiri Denemark 已提交
221
                                            int phase);
222
int qemuDomainAsyncJobPhaseFromString(qemuDomainAsyncJob job,
J
Jiri Denemark 已提交
223 224
                                      const char *phase);

225
void qemuDomainEventFlush(int timer, void *opaque);
226

227
void qemuDomainEventQueue(virQEMUDriverPtr driver,
228
                          virObjectEventPtr event);
229

230
int qemuDomainObjBeginJob(virQEMUDriverPtr driver,
231
                          virDomainObjPtr obj,
232
                          qemuDomainJob job)
233
    ATTRIBUTE_RETURN_CHECK;
234
int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver,
235
                               virDomainObjPtr obj,
236
                               qemuDomainAsyncJob asyncJob)
237 238
    ATTRIBUTE_RETURN_CHECK;

239 240 241 242
void qemuDomainObjEndJob(virQEMUDriverPtr driver,
                         virDomainObjPtr obj);
void qemuDomainObjEndAsyncJob(virQEMUDriverPtr driver,
                              virDomainObjPtr obj);
243
void qemuDomainObjAbortAsyncJob(virDomainObjPtr obj);
244
void qemuDomainObjSetJobPhase(virQEMUDriverPtr driver,
J
Jiri Denemark 已提交
245 246
                              virDomainObjPtr obj,
                              int phase);
247 248
void qemuDomainObjSetAsyncJobMask(virDomainObjPtr obj,
                                  unsigned long long allowedJobs);
249 250
void qemuDomainObjRestoreJob(virDomainObjPtr obj,
                             struct qemuDomainJobObj *job);
251
void qemuDomainObjDiscardAsyncJob(virQEMUDriverPtr driver,
252
                                  virDomainObjPtr obj);
253
void qemuDomainObjReleaseAsyncJob(virDomainObjPtr obj);
254

255 256
qemuMonitorPtr qemuDomainGetMonitor(virDomainObjPtr vm)
    ATTRIBUTE_NONNULL(1);
257
void qemuDomainObjEnterMonitor(virQEMUDriverPtr driver,
258 259
                               virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
260 261
int qemuDomainObjExitMonitor(virQEMUDriverPtr driver,
                             virDomainObjPtr obj)
262 263
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
    ATTRIBUTE_RETURN_CHECK;
264
int qemuDomainObjEnterMonitorAsync(virQEMUDriverPtr driver,
265
                                   virDomainObjPtr obj,
266
                                   qemuDomainAsyncJob asyncJob)
267
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
D
Daniel P. Berrange 已提交
268 269


270 271 272 273
void qemuDomainObjEnterAgent(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
void qemuDomainObjExitAgent(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
D
Daniel P. Berrange 已提交
274 275


276 277 278 279
void qemuDomainObjEnterRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
void qemuDomainObjExitRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
280

281 282 283 284
virDomainDefPtr qemuDomainDefCopy(virQEMUDriverPtr driver,
                                  virDomainDefPtr src,
                                  unsigned int flags);

285
int qemuDomainDefFormatBuf(virQEMUDriverPtr driver,
286 287 288 289
                           virDomainDefPtr vm,
                           unsigned int flags,
                           virBuffer *buf);

290
char *qemuDomainDefFormatXML(virQEMUDriverPtr driver,
291
                             virDomainDefPtr vm,
292
                             unsigned int flags);
293

294
char *qemuDomainFormatXML(virQEMUDriverPtr driver,
295
                          virDomainObjPtr vm,
296
                          unsigned int flags);
297

298
char *qemuDomainDefFormatLive(virQEMUDriverPtr driver,
299
                              virDomainDefPtr def,
300 301
                              bool inactive,
                              bool compatible);
302

303
void qemuDomainObjTaint(virQEMUDriverPtr driver,
304
                        virDomainObjPtr obj,
305
                        virDomainTaintFlags taint,
306
                        int logFD);
307

308
void qemuDomainObjCheckTaint(virQEMUDriverPtr driver,
309 310
                             virDomainObjPtr obj,
                             int logFD);
311
void qemuDomainObjCheckDiskTaint(virQEMUDriverPtr driver,
312
                                 virDomainObjPtr obj,
313 314
                                 virDomainDiskDefPtr disk,
                                 int logFD);
315 316 317 318
void qemuDomainObjCheckHostdevTaint(virQEMUDriverPtr driver,
                                    virDomainObjPtr obj,
                                    virDomainHostdevDefPtr disk,
                                    int logFD);
319
void qemuDomainObjCheckNetTaint(virQEMUDriverPtr driver,
320
                                virDomainObjPtr obj,
321 322
                                virDomainNetDefPtr net,
                                int logFD);
323

324

325 326 327
int qemuDomainCreateLog(virQEMUDriverPtr driver, virDomainObjPtr vm, bool append);
int qemuDomainOpenLog(virQEMUDriverPtr driver, virDomainObjPtr vm, off_t pos);
int qemuDomainAppendLog(virQEMUDriverPtr driver,
328 329 330
                        virDomainObjPtr vm,
                        int logFD,
                        const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(4, 5);
331

332
const char *qemuFindQemuImgBinary(virQEMUDriverPtr driver);
333 334 335 336 337

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

338
int qemuDomainSnapshotForEachQcow2(virQEMUDriverPtr driver,
339 340 341 342 343
                                   virDomainObjPtr vm,
                                   virDomainSnapshotObjPtr snap,
                                   const char *op,
                                   bool try_all);

344
int qemuDomainSnapshotDiscard(virQEMUDriverPtr driver,
345 346 347 348 349
                              virDomainObjPtr vm,
                              virDomainSnapshotObjPtr snap,
                              bool update_current,
                              bool metadata_only);

350 351 352
typedef struct _virQEMUSnapRemove virQEMUSnapRemove;
typedef virQEMUSnapRemove *virQEMUSnapRemovePtr;
struct _virQEMUSnapRemove {
353
    virQEMUDriverPtr driver;
354 355 356 357 358 359 360 361 362 363
    virDomainObjPtr vm;
    int err;
    bool metadata_only;
    bool current;
};

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

364
int qemuDomainSnapshotDiscardAllMetadata(virQEMUDriverPtr driver,
365 366
                                         virDomainObjPtr vm);

367
void qemuDomainRemoveInactive(virQEMUDriverPtr driver,
368 369
                              virDomainObjPtr vm);

370
void qemuDomainSetFakeReboot(virQEMUDriverPtr driver,
371 372 373
                             virDomainObjPtr vm,
                             bool value);

374
bool qemuDomainJobAllowed(qemuDomainObjPrivatePtr priv,
375
                          qemuDomainJob job);
M
Michal Privoznik 已提交
376

377
int qemuDomainCheckDiskPresence(virQEMUDriverPtr driver,
M
Michal Privoznik 已提交
378 379
                                virDomainObjPtr vm,
                                bool start_with_state);
380

381
int qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
382
                                 virDomainObjPtr vm,
383
                                 virDomainDiskDefPtr disk,
384 385
                                 bool force_probe,
                                 bool report_broken);
386

387 388 389
int qemuDomainStorageFileInit(virQEMUDriverPtr driver,
                              virDomainObjPtr vm,
                              virStorageSourcePtr src);
390
char *qemuDomainStorageAlias(const char *device, int depth);
391

392 393 394 395
int qemuDomainCleanupAdd(virDomainObjPtr vm,
                         qemuDomainCleanupCallback cb);
void qemuDomainCleanupRemove(virDomainObjPtr vm,
                             qemuDomainCleanupCallback cb);
396
void qemuDomainCleanupRun(virQEMUDriverPtr driver,
397 398
                          virDomainObjPtr vm);

399 400
extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks;
extern virDomainXMLNamespace virQEMUDriverDomainXMLNamespace;
401
extern virDomainDefParserConfig virQEMUDriverDomainDefParserConfig;
402

403
int qemuDomainUpdateDeviceList(virQEMUDriverPtr driver,
404
                               virDomainObjPtr vm, int asyncJob);
405

406 407 408 409
int qemuDomainUpdateMemoryDeviceInfo(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm,
                                     int asyncJob);

410 411 412
bool qemuDomainDefCheckABIStability(virQEMUDriverPtr driver,
                                    virDomainDefPtr src,
                                    virDomainDefPtr dst);
413

414
bool qemuDomainAgentAvailable(virDomainObjPtr vm,
415 416
                              bool reportError);

J
Jiri Denemark 已提交
417 418
int qemuDomainJobInfoUpdateTime(qemuDomainJobInfoPtr jobInfo)
    ATTRIBUTE_NONNULL(1);
419 420
int qemuDomainJobInfoUpdateDowntime(qemuDomainJobInfoPtr jobInfo)
    ATTRIBUTE_NONNULL(1);
J
Jiri Denemark 已提交
421 422 423 424 425 426 427 428 429 430
int qemuDomainJobInfoToInfo(qemuDomainJobInfoPtr jobInfo,
                            virDomainJobInfoPtr info)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int qemuDomainJobInfoToParams(qemuDomainJobInfoPtr jobInfo,
                              int *type,
                              virTypedParameterPtr *params,
                              int *nparams)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
    ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);

431 432
int qemuDomainSupportsBlockJobs(virDomainObjPtr vm, bool *modern)
    ATTRIBUTE_NONNULL(1);
433 434
bool qemuDomainDiskBlockJobIsActive(virDomainDiskDefPtr disk);

435 436
void qemuDomObjEndAPI(virDomainObjPtr *vm);

437
int qemuDomainAlignMemorySizes(virDomainDefPtr def);
438
void qemuDomainMemoryDeviceAlignSize(virDomainMemoryDefPtr mem);
439

440
#endif /* __QEMU_DOMAIN_H__ */