qemu_domain.h 15.9 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
    int persistentAddrs;
167

168
    virQEMUCapsPtr qemuCaps;
169
    char *lockState;
170 171

    bool fakeReboot;
172 173

    int jobs_queued;
174 175

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

181
    virChrdevsPtr devs;
182 183 184 185

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

    virCgroupPtr cgroup;
188 189 190

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

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

C
Chen Fan 已提交
197 198
typedef enum {
    QEMU_PROCESS_EVENT_WATCHDOG = 0,
199
    QEMU_PROCESS_EVENT_GUESTPANIC,
200
    QEMU_PROCESS_EVENT_DEVICE_DELETED,
201
    QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED,
202
    QEMU_PROCESS_EVENT_SERIAL_CHANGED,
203
    QEMU_PROCESS_EVENT_BLOCK_JOB,
C
Chen Fan 已提交
204 205 206 207 208

    QEMU_PROCESS_EVENT_LAST
} qemuProcessEventType;

struct qemuProcessEvent {
209
    virDomainObjPtr vm;
C
Chen Fan 已提交
210
    qemuProcessEventType eventType;
211
    int action;
212
    int status;
213
    void *data;
214 215
};

216
const char *qemuDomainAsyncJobPhaseToString(qemuDomainAsyncJob job,
J
Jiri Denemark 已提交
217
                                            int phase);
218
int qemuDomainAsyncJobPhaseFromString(qemuDomainAsyncJob job,
J
Jiri Denemark 已提交
219 220
                                      const char *phase);

221
void qemuDomainEventFlush(int timer, void *opaque);
222

223
void qemuDomainEventQueue(virQEMUDriverPtr driver,
224
                          virObjectEventPtr event);
225

226
int qemuDomainObjBeginJob(virQEMUDriverPtr driver,
227
                          virDomainObjPtr obj,
228
                          qemuDomainJob job)
229
    ATTRIBUTE_RETURN_CHECK;
230
int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver,
231
                               virDomainObjPtr obj,
232
                               qemuDomainAsyncJob asyncJob)
233 234
    ATTRIBUTE_RETURN_CHECK;

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

251
void qemuDomainObjEnterMonitor(virQEMUDriverPtr driver,
252 253
                               virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
254 255
int qemuDomainObjExitMonitor(virQEMUDriverPtr driver,
                             virDomainObjPtr obj)
256 257
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
    ATTRIBUTE_RETURN_CHECK;
258
int qemuDomainObjEnterMonitorAsync(virQEMUDriverPtr driver,
259
                                   virDomainObjPtr obj,
260
                                   qemuDomainAsyncJob asyncJob)
261
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
D
Daniel P. Berrange 已提交
262 263


264 265 266 267
void qemuDomainObjEnterAgent(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
void qemuDomainObjExitAgent(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
D
Daniel P. Berrange 已提交
268 269


270 271 272 273
void qemuDomainObjEnterRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
void qemuDomainObjExitRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
274

275 276 277 278
virDomainDefPtr qemuDomainDefCopy(virQEMUDriverPtr driver,
                                  virDomainDefPtr src,
                                  unsigned int flags);

279
int qemuDomainDefFormatBuf(virQEMUDriverPtr driver,
280 281 282 283
                           virDomainDefPtr vm,
                           unsigned int flags,
                           virBuffer *buf);

284
char *qemuDomainDefFormatXML(virQEMUDriverPtr driver,
285
                             virDomainDefPtr vm,
286
                             unsigned int flags);
287

288
char *qemuDomainFormatXML(virQEMUDriverPtr driver,
289
                          virDomainObjPtr vm,
290
                          unsigned int flags);
291

292
char *qemuDomainDefFormatLive(virQEMUDriverPtr driver,
293
                              virDomainDefPtr def,
294 295
                              bool inactive,
                              bool compatible);
296

297
void qemuDomainObjTaint(virQEMUDriverPtr driver,
298
                        virDomainObjPtr obj,
299
                        virDomainTaintFlags taint,
300
                        int logFD);
301

302
void qemuDomainObjCheckTaint(virQEMUDriverPtr driver,
303 304
                             virDomainObjPtr obj,
                             int logFD);
305
void qemuDomainObjCheckDiskTaint(virQEMUDriverPtr driver,
306
                                 virDomainObjPtr obj,
307 308
                                 virDomainDiskDefPtr disk,
                                 int logFD);
309 310 311 312
void qemuDomainObjCheckHostdevTaint(virQEMUDriverPtr driver,
                                    virDomainObjPtr obj,
                                    virDomainHostdevDefPtr disk,
                                    int logFD);
313
void qemuDomainObjCheckNetTaint(virQEMUDriverPtr driver,
314
                                virDomainObjPtr obj,
315 316
                                virDomainNetDefPtr net,
                                int logFD);
317

318

319 320 321
int qemuDomainCreateLog(virQEMUDriverPtr driver, virDomainObjPtr vm, bool append);
int qemuDomainOpenLog(virQEMUDriverPtr driver, virDomainObjPtr vm, off_t pos);
int qemuDomainAppendLog(virQEMUDriverPtr driver,
322 323 324
                        virDomainObjPtr vm,
                        int logFD,
                        const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(4, 5);
325

326
const char *qemuFindQemuImgBinary(virQEMUDriverPtr driver);
327 328 329 330 331

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

332
int qemuDomainSnapshotForEachQcow2(virQEMUDriverPtr driver,
333 334 335 336 337
                                   virDomainObjPtr vm,
                                   virDomainSnapshotObjPtr snap,
                                   const char *op,
                                   bool try_all);

338
int qemuDomainSnapshotDiscard(virQEMUDriverPtr driver,
339 340 341 342 343
                              virDomainObjPtr vm,
                              virDomainSnapshotObjPtr snap,
                              bool update_current,
                              bool metadata_only);

344 345 346
typedef struct _virQEMUSnapRemove virQEMUSnapRemove;
typedef virQEMUSnapRemove *virQEMUSnapRemovePtr;
struct _virQEMUSnapRemove {
347
    virQEMUDriverPtr driver;
348 349 350 351 352 353 354 355 356 357
    virDomainObjPtr vm;
    int err;
    bool metadata_only;
    bool current;
};

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

358
int qemuDomainSnapshotDiscardAllMetadata(virQEMUDriverPtr driver,
359 360
                                         virDomainObjPtr vm);

361
void qemuDomainRemoveInactive(virQEMUDriverPtr driver,
362 363
                              virDomainObjPtr vm);

364
void qemuDomainSetFakeReboot(virQEMUDriverPtr driver,
365 366 367
                             virDomainObjPtr vm,
                             bool value);

368
bool qemuDomainJobAllowed(qemuDomainObjPrivatePtr priv,
369
                          qemuDomainJob job);
M
Michal Privoznik 已提交
370

371
int qemuDomainCheckDiskPresence(virQEMUDriverPtr driver,
M
Michal Privoznik 已提交
372 373
                                virDomainObjPtr vm,
                                bool start_with_state);
374

375
int qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
376
                                 virDomainObjPtr vm,
377
                                 virDomainDiskDefPtr disk,
378 379
                                 bool force_probe,
                                 bool report_broken);
380

381 382 383
int qemuDomainStorageFileInit(virQEMUDriverPtr driver,
                              virDomainObjPtr vm,
                              virStorageSourcePtr src);
384
char *qemuDomainStorageAlias(const char *device, int depth);
385

386 387 388 389
int qemuDomainCleanupAdd(virDomainObjPtr vm,
                         qemuDomainCleanupCallback cb);
void qemuDomainCleanupRemove(virDomainObjPtr vm,
                             qemuDomainCleanupCallback cb);
390
void qemuDomainCleanupRun(virQEMUDriverPtr driver,
391 392
                          virDomainObjPtr vm);

393 394
extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks;
extern virDomainXMLNamespace virQEMUDriverDomainXMLNamespace;
395
extern virDomainDefParserConfig virQEMUDriverDomainDefParserConfig;
396

397
int qemuDomainUpdateDeviceList(virQEMUDriverPtr driver,
398
                               virDomainObjPtr vm, int asyncJob);
399

400 401 402 403
int qemuDomainUpdateMemoryDeviceInfo(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm,
                                     int asyncJob);

404 405 406
bool qemuDomainDefCheckABIStability(virQEMUDriverPtr driver,
                                    virDomainDefPtr src,
                                    virDomainDefPtr dst);
407

408
bool qemuDomainAgentAvailable(virDomainObjPtr vm,
409 410
                              bool reportError);

J
Jiri Denemark 已提交
411 412
int qemuDomainJobInfoUpdateTime(qemuDomainJobInfoPtr jobInfo)
    ATTRIBUTE_NONNULL(1);
413 414
int qemuDomainJobInfoUpdateDowntime(qemuDomainJobInfoPtr jobInfo)
    ATTRIBUTE_NONNULL(1);
J
Jiri Denemark 已提交
415 416 417 418 419 420 421 422 423 424
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);

425 426
bool qemuDomainDiskBlockJobIsActive(virDomainDiskDefPtr disk);

427 428
void qemuDomObjEndAPI(virDomainObjPtr *vm);

429
int qemuDomainAlignMemorySizes(virDomainDefPtr def);
430
void qemuDomainMemoryDeviceAlignSize(virDomainMemoryDefPtr mem);
431

432
#endif /* __QEMU_DOMAIN_H__ */