qemu_domain.h 32.2 KB
Newer Older
1 2 3
/*
 * qemu_domain.h: QEMU domain private state
 *
4
 * Copyright (C) 2006-2016 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 "virperf.h"
30
# include "domain_addr.h"
31
# include "domain_conf.h"
32
# include "snapshot_conf.h"
33
# include "qemu_monitor.h"
D
Daniel P. Berrange 已提交
34
# include "qemu_agent.h"
35
# include "qemu_conf.h"
36
# include "qemu_capabilities.h"
37
# include "virchrdev.h"
38
# include "virobject.h"
39
# include "logging/log_manager.h"
40

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

45
# if ULONG_MAX == 4294967295
P
Philipp Hahn 已提交
46
/* QEMU has a 64-bit limit, but we are limited by our historical choice of
47
 * representing bandwidth in a long instead of a 64-bit int.  */
48
#  define QEMU_DOMAIN_MIG_BANDWIDTH_MAX ULONG_MAX
49
# else
50
#  define QEMU_DOMAIN_MIG_BANDWIDTH_MAX (INT64_MAX / (1024 * 1024))
51
# endif
52

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

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

64 65 66
/* Only 1 job is allowed at any time
 * A job includes *all* monitor commands, even those just querying
 * information, not merely actions */
67
typedef enum {
68
    QEMU_JOB_NONE = 0,  /* Always set to 0 for easy if (jobActive) conditions */
69 70 71 72
    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 */
73
    QEMU_JOB_ABORT,         /* Abort current async job */
74
    QEMU_JOB_MIGRATION_OP,  /* Operation influencing outgoing migration */
75

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

    QEMU_JOB_LAST
81
} qemuDomainJob;
82
VIR_ENUM_DECL(qemuDomainJob)
83 84 85 86 87

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

    QEMU_ASYNC_JOB_LAST
98
} qemuDomainAsyncJob;
99
VIR_ENUM_DECL(qemuDomainAsyncJob)
100

J
Jiri Denemark 已提交
101 102 103 104 105
typedef struct _qemuDomainJobInfo qemuDomainJobInfo;
typedef qemuDomainJobInfo *qemuDomainJobInfoPtr;
struct _qemuDomainJobInfo {
    virDomainJobType type;
    unsigned long long started; /* When the async job started */
106
    unsigned long long stopped; /* When the domain's CPUs were stopped */
107 108 109 110
    unsigned long long sent; /* When the source sent status info to the
                                destination (only for migrations). */
    unsigned long long received; /* When the destination host received status
                                    info from the source (migrations only). */
J
Jiri Denemark 已提交
111 112 113
    /* Computed values */
    unsigned long long timeElapsed;
    unsigned long long timeRemaining;
J
Jiri Denemark 已提交
114
    long long timeDelta; /* delta = received - sent, i.e., the difference
115 116 117 118 119
                            between the source and the destination time plus
                            the time between the end of Perform phase on the
                            source and the beginning of Finish phase on the
                            destination. */
    bool timeDeltaSet;
J
Jiri Denemark 已提交
120
    /* Raw values from QEMU */
121
    qemuMonitorMigrationStats stats;
J
Jiri Denemark 已提交
122 123
};

124
struct qemuDomainJobObj {
125
    virCond cond;                       /* Use to coordinate jobs */
126
    qemuDomainJob active;               /* Currently running job */
127
    unsigned long long owner;           /* Thread id which set current job */
128
    const char *ownerAPI;               /* The API which owns the job */
J
Jiri Denemark 已提交
129
    unsigned long long started;         /* When the current job started */
130

131
    virCond asyncCond;                  /* Use to coordinate with async jobs */
132
    qemuDomainAsyncJob asyncJob;        /* Currently active async job */
133
    unsigned long long asyncOwner;      /* Thread which set current async job */
134
    const char *asyncOwnerAPI;          /* The API which owns the async job */
J
Jiri Denemark 已提交
135
    unsigned long long asyncStarted;    /* When the current async job started */
J
Jiri Denemark 已提交
136
    int phase;                          /* Job phase (mainly for migrations) */
137
    unsigned long long mask;            /* Jobs allowed during async job */
138
    bool dump_memory_only;              /* use dump-guest-memory to do dump */
J
Jiri Denemark 已提交
139
    qemuDomainJobInfoPtr current;       /* async job progress data */
140
    qemuDomainJobInfoPtr completed;     /* statistics data of a recently completed job */
141
    bool abortJob;                      /* abort of the job requested */
142 143
    bool spiceMigration;                /* we asked for spice migration and we
                                         * should wait for it to finish */
144
    bool spiceMigrated;                 /* spice migration completed */
145
    bool postcopyEnabled;               /* post-copy migration was enabled */
146 147
};

148
typedef void (*qemuDomainCleanupCallback)(virQEMUDriverPtr driver,
149 150
                                          virDomainObjPtr vm);

J
John Ferlan 已提交
151
# define QEMU_DOMAIN_MASTER_KEY_LEN 32  /* 32 bytes for 256 bit random key */
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167


/* helper data types for async device unplug */
typedef enum {
    QEMU_DOMAIN_UNPLUGGING_DEVICE_STATUS_NONE = 0,
    QEMU_DOMAIN_UNPLUGGING_DEVICE_STATUS_OK,
    QEMU_DOMAIN_UNPLUGGING_DEVICE_STATUS_GUEST_REJECTED,
} qemuDomainUnpluggingDeviceStatus;

typedef struct _qemuDomainUnpluggingDevice qemuDomainUnpluggingDevice;
typedef qemuDomainUnpluggingDevice *qemuDomainUnpluggingDevicePtr;
struct _qemuDomainUnpluggingDevice {
    const char *alias;
    qemuDomainUnpluggingDeviceStatus status;
};

168 169 170 171 172 173 174 175 176 177

typedef enum {
    QEMU_DOMAIN_NS_MOUNT = 0,
    QEMU_DOMAIN_NS_LAST
} qemuDomainNamespace;
VIR_ENUM_DECL(qemuDomainNamespace)

bool qemuDomainNamespaceEnabled(virDomainObjPtr vm,
                                qemuDomainNamespace ns);

178 179 180
typedef struct _qemuDomainObjPrivate qemuDomainObjPrivate;
typedef qemuDomainObjPrivate *qemuDomainObjPrivatePtr;
struct _qemuDomainObjPrivate {
181
    struct qemuDomainJobObj job;
182

183 184
    virBitmapPtr namespaces;

185
    qemuMonitorPtr mon;
186
    virDomainChrSourceDefPtr monConfig;
E
Eric Blake 已提交
187
    bool monJSON;
188 189
    bool monError;
    unsigned long long monStart;
D
Daniel P. Berrange 已提交
190 191 192 193

    qemuAgentPtr agent;
    bool agentError;

194
    bool gotShutdown;
195
    bool beingDestroyed;
196
    char *pidfile;
197

198
    virDomainPCIAddressSetPtr pciaddrs;
J
Ján Tomko 已提交
199
    virDomainUSBAddressSetPtr usbaddrs;
200

201
    virQEMUCapsPtr qemuCaps;
202
    char *lockState;
203 204

    bool fakeReboot;
205 206

    int jobs_queued;
207 208

    unsigned long migMaxBandwidth;
J
Jiri Denemark 已提交
209
    char *origname;
210
    int nbdPort; /* Port used for migration with NBD */
211
    unsigned short migrationPort;
212
    int preMigrationState;
213

214
    virChrdevsPtr devs;
215 216 217 218

    qemuDomainCleanupCallback *cleanupCallbacks;
    size_t ncleanupCallbacks;
    size_t ncleanupCallbacks_max;
219 220

    virCgroupPtr cgroup;
221

222 223
    virPerfPtr perf;

224 225
    qemuDomainUnpluggingDevice unplug;

226
    char **qemuDevices; /* NULL-terminated list of devices aliases known to QEMU */
227 228

    bool hookRun;  /* true if there was a hook run over this domain */
229 230

    /* Bitmaps below hold data from the auto NUMA feature */
231
    virBitmapPtr autoNodeset;
232
    virBitmapPtr autoCpuset;
233 234 235

    bool signalIOError; /* true if the domain condition should be signalled on
                           I/O error */
236 237
    bool signalStop; /* true if the domain condition should be signalled on
                        QMP STOP event */
238
    char *machineName;
239 240
    char *libDir;            /* base path for per-domain files */
    char *channelTargetDir;  /* base path for per-domain channel targets */
J
John Ferlan 已提交
241 242 243 244 245

    /* random masterKey and length for encryption (not to be saved in our */
    /* private XML) - need to restore at process reconnect */
    uint8_t *masterKey;
    size_t masterKeyLen;
246 247 248

    /* note whether memory device alias does not correspond to slot number */
    bool memAliasOrderMismatch;
249 250
};

251 252 253
# define QEMU_DOMAIN_PRIVATE(vm)	\
    ((qemuDomainObjPrivatePtr) (vm)->privateData)

254 255
/* Type of domain secret */
typedef enum {
256
    VIR_DOMAIN_SECRET_INFO_TYPE_PLAIN = 0,
257
    VIR_DOMAIN_SECRET_INFO_TYPE_AES,  /* utilize GNUTLS_CIPHER_AES_256_CBC */
258

259
    VIR_DOMAIN_SECRET_INFO_TYPE_LAST
260 261 262 263 264 265
} qemuDomainSecretInfoType;

typedef struct _qemuDomainSecretPlain qemuDomainSecretPlain;
typedef struct _qemuDomainSecretPlain *qemuDomainSecretPlainPtr;
struct _qemuDomainSecretPlain {
    char *username;
266 267
    uint8_t *secret;
    size_t secretlen;
268 269
};

270 271
# define QEMU_DOMAIN_AES_IV_LEN 16   /* 16 bytes for 128 bit random */
                                     /*    initialization vector */
272 273 274
typedef struct _qemuDomainSecretAES qemuDomainSecretAES;
typedef struct _qemuDomainSecretAES *qemuDomainSecretAESPtr;
struct _qemuDomainSecretAES {
J
John Ferlan 已提交
275 276 277 278 279 280
    char *username;
    char *alias;      /* generated alias for secret */
    char *iv;         /* base64 encoded initialization vector */
    char *ciphertext; /* encoded/encrypted secret */
};

281 282 283
typedef struct _qemuDomainSecretInfo qemuDomainSecretInfo;
typedef qemuDomainSecretInfo *qemuDomainSecretInfoPtr;
struct _qemuDomainSecretInfo {
284
    qemuDomainSecretInfoType type;
285 286
    union {
        qemuDomainSecretPlain plain;
287
        qemuDomainSecretAES aes;
288 289 290
    } s;
};

291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
# define QEMU_DOMAIN_DISK_PRIVATE(disk)	\
    ((qemuDomainDiskPrivatePtr) (disk)->privateData)

typedef struct _qemuDomainDiskPrivate qemuDomainDiskPrivate;
typedef qemuDomainDiskPrivate *qemuDomainDiskPrivatePtr;
struct _qemuDomainDiskPrivate {
    virObject parent;

    /* ideally we want a smarter way to interlock block jobs on single qemu disk
     * in the future, but for now we just disallow any concurrent job on a
     * single disk */
    bool blockjob;

    /* for some synchronous block jobs, we need to notify the owner */
    int blockJobType;   /* type of the block job from the event */
    int blockJobStatus; /* status of the finished block job */
    bool blockJobSync; /* the block job needs synchronized termination */
308 309

    bool migrating; /* the disk is being migrated */
310 311 312 313

    /* for storage devices using auth/secret
     * NB: *not* to be written to qemu domain object XML */
    qemuDomainSecretInfoPtr secinfo;
314

J
John Ferlan 已提交
315 316 317 318 319
    /* for storage devices using encryption/secret
     * Can have both <auth> and <encryption> for some disks
     * NB:*not* to be written to qemu domain object XML */
    qemuDomainSecretInfoPtr encinfo;

320 321 322
    /* information about the device */
    bool tray; /* device has tray */
    bool removable; /* device media can be removed/changed */
323 324
};

325 326 327
# define QEMU_DOMAIN_HOSTDEV_PRIVATE(hostdev)	\
    ((qemuDomainHostdevPrivatePtr) (hostdev)->privateData)

328 329 330 331 332 333

typedef struct _qemuDomainVcpuPrivate qemuDomainVcpuPrivate;
typedef qemuDomainVcpuPrivate *qemuDomainVcpuPrivatePtr;
struct _qemuDomainVcpuPrivate {
    virObject parent;

334
    pid_t tid; /* vcpu thread id */
335
    int enable_id; /* order in which the vcpus were enabled in qemu */
336
    int qemu_id; /* ID reported by qemu as 'CPU' in query-cpus */
337
    char *alias;
338
    bool halted;
339 340 341 342 343 344 345

    /* information for hotpluggable cpus */
    char *type;
    int socket_id;
    int core_id;
    int thread_id;
    int vcpus;
346 347 348 349 350 351
};

# define QEMU_DOMAIN_VCPU_PRIVATE(vcpu)    \
    ((qemuDomainVcpuPrivatePtr) (vcpu)->privateData)


352 353 354
struct qemuDomainDiskInfo {
    bool removable;
    bool locked;
355
    bool tray;
356
    bool tray_open;
357
    bool empty;
358 359 360
    int io_status;
};

361 362 363 364 365 366 367 368 369 370
typedef struct _qemuDomainHostdevPrivate qemuDomainHostdevPrivate;
typedef qemuDomainHostdevPrivate *qemuDomainHostdevPrivatePtr;
struct _qemuDomainHostdevPrivate {
    virObject parent;

    /* for hostdev storage devices using auth/secret
     * NB: *not* to be written to qemu domain object XML */
    qemuDomainSecretInfoPtr secinfo;
};

371 372
# define QEMU_DOMAIN_CHR_SOURCE_PRIVATE(dev)	\
    ((qemuDomainChrSourcePrivatePtr) (dev)->privateData)
373

374 375 376
typedef struct _qemuDomainChrSourcePrivate qemuDomainChrSourcePrivate;
typedef qemuDomainChrSourcePrivate *qemuDomainChrSourcePrivatePtr;
struct _qemuDomainChrSourcePrivate {
377 378 379 380 381 382 383 384
    virObject parent;

    /* for char devices using secret
     * NB: *not* to be written to qemu domain object XML */
    qemuDomainSecretInfoPtr secinfo;
};


C
Chen Fan 已提交
385 386
typedef enum {
    QEMU_PROCESS_EVENT_WATCHDOG = 0,
387
    QEMU_PROCESS_EVENT_GUESTPANIC,
388
    QEMU_PROCESS_EVENT_DEVICE_DELETED,
389
    QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED,
390
    QEMU_PROCESS_EVENT_SERIAL_CHANGED,
391
    QEMU_PROCESS_EVENT_BLOCK_JOB,
392
    QEMU_PROCESS_EVENT_MONITOR_EOF,
C
Chen Fan 已提交
393 394 395 396 397

    QEMU_PROCESS_EVENT_LAST
} qemuProcessEventType;

struct qemuProcessEvent {
398
    virDomainObjPtr vm;
C
Chen Fan 已提交
399
    qemuProcessEventType eventType;
400
    int action;
401
    int status;
402
    void *data;
403 404
};

405 406 407
typedef struct _qemuDomainLogContext qemuDomainLogContext;
typedef qemuDomainLogContext *qemuDomainLogContextPtr;

408
const char *qemuDomainAsyncJobPhaseToString(qemuDomainAsyncJob job,
J
Jiri Denemark 已提交
409
                                            int phase);
410
int qemuDomainAsyncJobPhaseFromString(qemuDomainAsyncJob job,
J
Jiri Denemark 已提交
411 412
                                      const char *phase);

413
void qemuDomainEventFlush(int timer, void *opaque);
414

415
void qemuDomainEventQueue(virQEMUDriverPtr driver,
416
                          virObjectEventPtr event);
417 418
void qemuDomainEventEmitJobCompleted(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm);
419

420
int qemuDomainObjBeginJob(virQEMUDriverPtr driver,
421
                          virDomainObjPtr obj,
422
                          qemuDomainJob job)
423
    ATTRIBUTE_RETURN_CHECK;
424
int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver,
425
                               virDomainObjPtr obj,
426
                               qemuDomainAsyncJob asyncJob)
427
    ATTRIBUTE_RETURN_CHECK;
428 429 430 431
int qemuDomainObjBeginNestedJob(virQEMUDriverPtr driver,
                                virDomainObjPtr obj,
                                qemuDomainAsyncJob asyncJob)
    ATTRIBUTE_RETURN_CHECK;
432

433 434 435 436
void qemuDomainObjEndJob(virQEMUDriverPtr driver,
                         virDomainObjPtr obj);
void qemuDomainObjEndAsyncJob(virQEMUDriverPtr driver,
                              virDomainObjPtr obj);
437
void qemuDomainObjAbortAsyncJob(virDomainObjPtr obj);
438
void qemuDomainObjSetJobPhase(virQEMUDriverPtr driver,
J
Jiri Denemark 已提交
439 440
                              virDomainObjPtr obj,
                              int phase);
441 442
void qemuDomainObjSetAsyncJobMask(virDomainObjPtr obj,
                                  unsigned long long allowedJobs);
443 444
void qemuDomainObjRestoreJob(virDomainObjPtr obj,
                             struct qemuDomainJobObj *job);
445
void qemuDomainObjDiscardAsyncJob(virQEMUDriverPtr driver,
446
                                  virDomainObjPtr obj);
447
void qemuDomainObjReleaseAsyncJob(virDomainObjPtr obj);
448

449 450
qemuMonitorPtr qemuDomainGetMonitor(virDomainObjPtr vm)
    ATTRIBUTE_NONNULL(1);
451
void qemuDomainObjEnterMonitor(virQEMUDriverPtr driver,
452 453
                               virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
454 455
int qemuDomainObjExitMonitor(virQEMUDriverPtr driver,
                             virDomainObjPtr obj)
456 457
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
    ATTRIBUTE_RETURN_CHECK;
458
int qemuDomainObjEnterMonitorAsync(virQEMUDriverPtr driver,
459
                                   virDomainObjPtr obj,
460
                                   qemuDomainAsyncJob asyncJob)
461
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
D
Daniel P. Berrange 已提交
462 463


464
qemuAgentPtr qemuDomainObjEnterAgent(virDomainObjPtr obj)
465
    ATTRIBUTE_NONNULL(1);
466 467
void qemuDomainObjExitAgent(virDomainObjPtr obj, qemuAgentPtr agent)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
D
Daniel P. Berrange 已提交
468 469


470 471 472 473
void qemuDomainObjEnterRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
void qemuDomainObjExitRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
474

475 476 477 478
virDomainDefPtr qemuDomainDefCopy(virQEMUDriverPtr driver,
                                  virDomainDefPtr src,
                                  unsigned int flags);

479
int qemuDomainDefFormatBuf(virQEMUDriverPtr driver,
480 481 482 483
                           virDomainDefPtr vm,
                           unsigned int flags,
                           virBuffer *buf);

484
char *qemuDomainDefFormatXML(virQEMUDriverPtr driver,
485
                             virDomainDefPtr vm,
486
                             unsigned int flags);
487

488
char *qemuDomainFormatXML(virQEMUDriverPtr driver,
489
                          virDomainObjPtr vm,
490
                          unsigned int flags);
491

492
char *qemuDomainDefFormatLive(virQEMUDriverPtr driver,
493
                              virDomainDefPtr def,
494 495
                              bool inactive,
                              bool compatible);
496

497
void qemuDomainObjTaint(virQEMUDriverPtr driver,
498
                        virDomainObjPtr obj,
499
                        virDomainTaintFlags taint,
500
                        qemuDomainLogContextPtr logCtxt);
501

502
void qemuDomainObjCheckTaint(virQEMUDriverPtr driver,
503
                             virDomainObjPtr obj,
504
                             qemuDomainLogContextPtr logCtxt);
505
void qemuDomainObjCheckDiskTaint(virQEMUDriverPtr driver,
506
                                 virDomainObjPtr obj,
507
                                 virDomainDiskDefPtr disk,
508
                                 qemuDomainLogContextPtr logCtxt);
509 510 511
void qemuDomainObjCheckHostdevTaint(virQEMUDriverPtr driver,
                                    virDomainObjPtr obj,
                                    virDomainHostdevDefPtr disk,
512
                                    qemuDomainLogContextPtr logCtxt);
513
void qemuDomainObjCheckNetTaint(virQEMUDriverPtr driver,
514
                                virDomainObjPtr obj,
515
                                virDomainNetDefPtr net,
516
                                qemuDomainLogContextPtr logCtxt);
517

518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
typedef enum {
    QEMU_DOMAIN_LOG_CONTEXT_MODE_START,
    QEMU_DOMAIN_LOG_CONTEXT_MODE_ATTACH,
    QEMU_DOMAIN_LOG_CONTEXT_MODE_STOP,
} qemuDomainLogContextMode;

qemuDomainLogContextPtr qemuDomainLogContextNew(virQEMUDriverPtr driver,
                                                virDomainObjPtr vm,
                                                qemuDomainLogContextMode mode);
int qemuDomainLogContextWrite(qemuDomainLogContextPtr ctxt,
                              const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(2, 3);
ssize_t qemuDomainLogContextRead(qemuDomainLogContextPtr ctxt,
                                 char **msg);
int qemuDomainLogContextGetWriteFD(qemuDomainLogContextPtr ctxt);
void qemuDomainLogContextMarkPosition(qemuDomainLogContextPtr ctxt);
void qemuDomainLogContextRef(qemuDomainLogContextPtr ctxt);
void qemuDomainLogContextFree(qemuDomainLogContextPtr ctxt);
535

536 537
virLogManagerPtr qemuDomainLogContextGetManager(qemuDomainLogContextPtr ctxt);

538 539 540 541 542
int qemuDomainLogAppendMessage(virQEMUDriverPtr driver,
                               virDomainObjPtr vm,
                               const char *fmt,
                               ...) ATTRIBUTE_FMT_PRINTF(3, 4);

543
const char *qemuFindQemuImgBinary(virQEMUDriverPtr driver);
544 545 546

int qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
                                    virDomainSnapshotObjPtr snapshot,
547
                                    virCapsPtr caps,
548 549
                                    char *snapshotDir);

550
int qemuDomainSnapshotForEachQcow2(virQEMUDriverPtr driver,
551 552 553 554 555
                                   virDomainObjPtr vm,
                                   virDomainSnapshotObjPtr snap,
                                   const char *op,
                                   bool try_all);

556
int qemuDomainSnapshotDiscard(virQEMUDriverPtr driver,
557 558 559 560 561
                              virDomainObjPtr vm,
                              virDomainSnapshotObjPtr snap,
                              bool update_current,
                              bool metadata_only);

562 563 564
typedef struct _virQEMUSnapRemove virQEMUSnapRemove;
typedef virQEMUSnapRemove *virQEMUSnapRemovePtr;
struct _virQEMUSnapRemove {
565
    virQEMUDriverPtr driver;
566 567 568 569 570 571
    virDomainObjPtr vm;
    int err;
    bool metadata_only;
    bool current;
};

572 573 574
int qemuDomainSnapshotDiscardAll(void *payload,
                                 const void *name,
                                 void *data);
575

576
int qemuDomainSnapshotDiscardAllMetadata(virQEMUDriverPtr driver,
577 578
                                         virDomainObjPtr vm);

579
void qemuDomainRemoveInactive(virQEMUDriverPtr driver,
580 581
                              virDomainObjPtr vm);

582
void qemuDomainSetFakeReboot(virQEMUDriverPtr driver,
583 584 585
                             virDomainObjPtr vm,
                             bool value);

586
bool qemuDomainJobAllowed(qemuDomainObjPrivatePtr priv,
587
                          qemuDomainJob job);
M
Michal Privoznik 已提交
588

589 590
int qemuDomainCheckDiskPresence(virConnectPtr conn,
                                virQEMUDriverPtr driver,
M
Michal Privoznik 已提交
591
                                virDomainObjPtr vm,
592
                                unsigned int flags);
593

594
int qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
595
                                 virDomainObjPtr vm,
596
                                 virDomainDiskDefPtr disk,
597 598
                                 bool force_probe,
                                 bool report_broken);
599

600
bool qemuDomainDiskSourceDiffers(virDomainDiskDefPtr disk,
601 602
                                 virDomainDiskDefPtr origDisk);

603 604 605
bool qemuDomainDiskChangeSupported(virDomainDiskDefPtr disk,
                                   virDomainDiskDefPtr orig_disk);

606 607 608
int qemuDomainStorageFileInit(virQEMUDriverPtr driver,
                              virDomainObjPtr vm,
                              virStorageSourcePtr src);
609
char *qemuDomainStorageAlias(const char *device, int depth);
610

611 612 613 614 615 616 617 618
void qemuDomainDiskChainElementRevoke(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm,
                                      virStorageSourcePtr elem);
int qemuDomainDiskChainElementPrepare(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm,
                                      virStorageSourcePtr elem,
                                      bool readonly);

619 620 621 622
int qemuDomainCleanupAdd(virDomainObjPtr vm,
                         qemuDomainCleanupCallback cb);
void qemuDomainCleanupRemove(virDomainObjPtr vm,
                             qemuDomainCleanupCallback cb);
623
void qemuDomainCleanupRun(virQEMUDriverPtr driver,
624 625
                          virDomainObjPtr vm);

626 627
extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks;
extern virDomainXMLNamespace virQEMUDriverDomainXMLNamespace;
628
extern virDomainDefParserConfig virQEMUDriverDomainDefParserConfig;
629

630
int qemuDomainUpdateDeviceList(virQEMUDriverPtr driver,
631
                               virDomainObjPtr vm, int asyncJob);
632

633 634 635 636
int qemuDomainUpdateMemoryDeviceInfo(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm,
                                     int asyncJob);

637 638 639
bool qemuDomainDefCheckABIStability(virQEMUDriverPtr driver,
                                    virDomainDefPtr src,
                                    virDomainDefPtr dst);
640

641
bool qemuDomainAgentAvailable(virDomainObjPtr vm,
642 643
                              bool reportError);

J
Jiri Denemark 已提交
644 645
int qemuDomainJobInfoUpdateTime(qemuDomainJobInfoPtr jobInfo)
    ATTRIBUTE_NONNULL(1);
646 647
int qemuDomainJobInfoUpdateDowntime(qemuDomainJobInfoPtr jobInfo)
    ATTRIBUTE_NONNULL(1);
J
Jiri Denemark 已提交
648 649 650 651 652 653 654 655 656 657
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);

658 659
int qemuDomainSupportsBlockJobs(virDomainObjPtr vm, bool *modern)
    ATTRIBUTE_NONNULL(1);
660
bool qemuDomainDiskBlockJobIsActive(virDomainDiskDefPtr disk);
661 662
bool qemuDomainHasBlockjob(virDomainObjPtr vm, bool copy_only)
    ATTRIBUTE_NONNULL(1);
663

664
int qemuDomainAlignMemorySizes(virDomainDefPtr def);
665 666
void qemuDomainMemoryDeviceAlignSize(virDomainDefPtr def,
                                     virDomainMemoryDefPtr mem);
667

668
virDomainChrDefPtr qemuFindAgentConfig(virDomainDefPtr def);
669

670 671
bool qemuDomainMachineIsQ35(const virDomainDef *def);
bool qemuDomainMachineIsI440FX(const virDomainDef *def);
672 673
bool qemuDomainMachineHasPCIRoot(const virDomainDef *def);
bool qemuDomainMachineHasPCIeRoot(const virDomainDef *def);
674
bool qemuDomainMachineNeedsFDC(const virDomainDef *def);
675
bool qemuDomainMachineIsS390CCW(const virDomainDef *def);
J
Ján Tomko 已提交
676
bool qemuDomainMachineIsVirt(const virDomainDef *def);
677
bool qemuDomainMachineIsPSeries(const virDomainDef *def);
678
bool qemuDomainMachineHasBuiltinIDE(const virDomainDef *def);
679

680 681 682
int qemuDomainUpdateCurrentMemorySize(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm);

683 684
unsigned long long qemuDomainGetMemLockLimitBytes(virDomainDefPtr def);
bool qemuDomainRequiresMemLock(virDomainDefPtr def);
685
int qemuDomainAdjustMaxMemLock(virDomainObjPtr vm);
686

687 688 689 690
int qemuDomainDefValidateMemoryHotplug(const virDomainDef *def,
                                       virQEMUCapsPtr qemuCaps,
                                       const virDomainMemoryDef *mem);

691
bool qemuDomainSupportsNewVcpuHotplug(virDomainObjPtr vm);
692
bool qemuDomainHasVcpuPids(virDomainObjPtr vm);
693
pid_t qemuDomainGetVcpuPid(virDomainObjPtr vm, unsigned int vcpuid);
694
int qemuDomainValidateVcpuInfo(virDomainObjPtr vm);
695 696
int qemuDomainRefreshVcpuInfo(virQEMUDriverPtr driver,
                              virDomainObjPtr vm,
697 698
                              int asyncJob,
                              bool state);
699 700 701 702
bool qemuDomainGetVcpuHalted(virDomainObjPtr vm, unsigned int vcpu);
int qemuDomainRefreshVcpuHalted(virQEMUDriverPtr driver,
                                virDomainObjPtr vm,
                                int asyncJob);
703

704 705 706 707 708 709 710
bool qemuDomainSupportsNicdev(virDomainDefPtr def,
                              virDomainNetDefPtr net);

bool qemuDomainSupportsNetdev(virDomainDefPtr def,
                              virQEMUCapsPtr qemuCaps,
                              virDomainNetDefPtr net);

711 712
bool qemuDomainNetSupportsMTU(virDomainNetType type);

J
John Ferlan 已提交
713
int qemuDomainNetVLAN(virDomainNetDefPtr def);
714

715 716 717
int qemuDomainSetPrivatePaths(virQEMUDriverPtr driver,
                              virDomainObjPtr vm);

718
void qemuDomainClearPrivatePaths(virDomainObjPtr vm);
P
Peter Krempa 已提交
719 720 721

virDomainDiskDefPtr qemuDomainDiskByName(virDomainDefPtr def, const char *name);

J
John Ferlan 已提交
722 723 724 725
char *qemuDomainGetMasterKeyFilePath(const char *libDir);

int qemuDomainMasterKeyReadFile(qemuDomainObjPrivatePtr priv);

726 727 728 729
int qemuDomainWriteMasterKeyFile(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm);

int qemuDomainMasterKeyCreate(virDomainObjPtr vm);
J
John Ferlan 已提交
730 731 732

void qemuDomainMasterKeyRemove(qemuDomainObjPrivatePtr priv);

733 734 735
void qemuDomainSecretDiskDestroy(virDomainDiskDefPtr disk)
    ATTRIBUTE_NONNULL(1);

736 737 738
bool qemuDomainSecretDiskCapable(virStorageSourcePtr src)
    ATTRIBUTE_NONNULL(1);

739 740 741
bool qemuDomainDiskHasEncryptionSecret(virStorageSourcePtr src)
    ATTRIBUTE_NONNULL(1);

J
John Ferlan 已提交
742 743 744 745
int qemuDomainSecretDiskPrepare(virConnectPtr conn,
                                qemuDomainObjPrivatePtr priv,
                                virDomainDiskDefPtr disk)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
746

747 748 749 750
void qemuDomainSecretHostdevDestroy(virDomainHostdevDefPtr disk)
    ATTRIBUTE_NONNULL(1);

int qemuDomainSecretHostdevPrepare(virConnectPtr conn,
J
John Ferlan 已提交
751
                                   qemuDomainObjPrivatePtr priv,
752
                                   virDomainHostdevDefPtr hostdev)
J
John Ferlan 已提交
753
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
754

755 756 757 758 759 760 761 762 763 764 765
void qemuDomainSecretChardevDestroy(virDomainChrSourceDefPtr dev)
    ATTRIBUTE_NONNULL(1);

int qemuDomainSecretChardevPrepare(virConnectPtr conn,
                                   virQEMUDriverConfigPtr cfg,
                                   qemuDomainObjPrivatePtr priv,
                                   const char *chrAlias,
                                   virDomainChrSourceDefPtr dev)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
    ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5);

766 767 768
void qemuDomainSecretDestroy(virDomainObjPtr vm)
    ATTRIBUTE_NONNULL(1);

769 770 771 772
int qemuDomainSecretPrepare(virConnectPtr conn,
                            virQEMUDriverPtr driver,
                            virDomainObjPtr vm)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
773

774 775 776
int qemuDomainDefValidateDiskLunSource(const virStorageSource *src)
    ATTRIBUTE_NONNULL(1);

777 778 779 780
int qemuDomainPrepareChannel(virDomainChrDefPtr chr,
                             const char *domainChannelTargetDir)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

781 782 783 784 785 786 787 788
void qemuDomainPrepareChardevSourceTLS(virDomainChrSourceDefPtr source,
                                       virQEMUDriverConfigPtr cfg)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

void qemuDomainPrepareChardevSource(virDomainDefPtr def,
                                    virQEMUDriverPtr driver)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

789 790 791
int qemuDomainPrepareShmemChardev(virDomainShmemDefPtr shmem)
    ATTRIBUTE_NONNULL(1);

792 793 794
bool qemuDomainVcpuHotplugIsInOrder(virDomainDefPtr def)
    ATTRIBUTE_NONNULL(1);

795 796 797
void qemuDomainVcpuPersistOrder(virDomainDefPtr def)
    ATTRIBUTE_NONNULL(1);

798 799 800 801
int qemuDomainCheckMonitor(virQEMUDriverPtr driver,
                           virDomainObjPtr vm,
                           qemuDomainAsyncJob asyncJob);

802 803 804
bool qemuDomainSupportsVideoVga(virDomainVideoDefPtr video,
                                virQEMUCapsPtr qemuCaps);

805 806 807
int qemuDomainGetHostdevPath(virDomainDefPtr def,
                             virDomainHostdevDefPtr dev,
                             bool teardown,
808 809 810
                             size_t *npaths,
                             char ***path,
                             int **perms);
811

812 813
int qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg,
                             virSecurityManagerPtr mgr,
814 815 816 817 818
                             virDomainObjPtr vm);

int qemuDomainCreateNamespace(virQEMUDriverPtr driver,
                              virDomainObjPtr vm);

819 820 821
void qemuDomainDestroyNamespace(virQEMUDriverPtr driver,
                                virDomainObjPtr vm);

822 823
bool qemuDomainNamespaceAvailable(qemuDomainNamespace ns);

824 825
int qemuDomainNamespaceSetupDisk(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm,
826
                                 virStorageSourcePtr src);
827 828 829

int qemuDomainNamespaceTeardownDisk(virQEMUDriverPtr driver,
                                    virDomainObjPtr vm,
830
                                    virStorageSourcePtr src);
831 832 833 834 835 836 837 838

int qemuDomainNamespaceSetupHostdev(virQEMUDriverPtr driver,
                                    virDomainObjPtr vm,
                                    virDomainHostdevDefPtr hostdev);

int qemuDomainNamespaceTeardownHostdev(virQEMUDriverPtr driver,
                                       virDomainObjPtr vm,
                                       virDomainHostdevDefPtr hostdev);
839 840 841 842 843 844 845 846

int qemuDomainNamespaceSetupChardev(virQEMUDriverPtr driver,
                                    virDomainObjPtr vm,
                                    virDomainChrDefPtr chr);

int qemuDomainNamespaceTeardownChardev(virQEMUDriverPtr driver,
                                       virDomainObjPtr vm,
                                       virDomainChrDefPtr chr);
847 848

int qemuDomainNamespaceSetupRNG(virQEMUDriverPtr driver,
849 850
                                virDomainObjPtr vm,
                                virDomainRNGDefPtr rng);
851 852

int qemuDomainNamespaceTeardownRNG(virQEMUDriverPtr driver,
853 854
                                   virDomainObjPtr vm,
                                   virDomainRNGDefPtr rng);
855
#endif /* __QEMU_DOMAIN_H__ */