You need to sign in or sign up before continuing.
qemu_domain.h 36.7 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 "virmdev.h"
38
# include "virchrdev.h"
39
# include "virobject.h"
40
# include "logging/log_manager.h"
41

42
# define QEMU_DOMAIN_FORMAT_LIVE_FLAGS      \
43
    (VIR_DOMAIN_XML_SECURE)
44

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

C
caoxinhua 已提交
53
# define JOB_MASK(job)                  (job == 0 ? 0 : 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

101 102 103
typedef enum {
    QEMU_DOMAIN_JOB_STATUS_NONE = 0,
    QEMU_DOMAIN_JOB_STATUS_ACTIVE,
104
    QEMU_DOMAIN_JOB_STATUS_MIGRATING,
105
    QEMU_DOMAIN_JOB_STATUS_QEMU_COMPLETED,
106
    QEMU_DOMAIN_JOB_STATUS_POSTCOPY,
107 108 109 110 111
    QEMU_DOMAIN_JOB_STATUS_COMPLETED,
    QEMU_DOMAIN_JOB_STATUS_FAILED,
    QEMU_DOMAIN_JOB_STATUS_CANCELED,
} qemuDomainJobStatus;

112 113 114 115 116 117 118 119

typedef struct _qemuDomainMirrorStats qemuDomainMirrorStats;
typedef qemuDomainMirrorStats *qemuDomainMirrorStatsPtr;
struct _qemuDomainMirrorStats {
    unsigned long long transferred;
    unsigned long long total;
};

J
Jiri Denemark 已提交
120 121 122
typedef struct _qemuDomainJobInfo qemuDomainJobInfo;
typedef qemuDomainJobInfo *qemuDomainJobInfoPtr;
struct _qemuDomainJobInfo {
123
    qemuDomainJobStatus status;
124
    virDomainJobOperation operation;
J
Jiri Denemark 已提交
125
    unsigned long long started; /* When the async job started */
126
    unsigned long long stopped; /* When the domain's CPUs were stopped */
127 128 129 130
    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 已提交
131 132
    /* Computed values */
    unsigned long long timeElapsed;
J
Jiri Denemark 已提交
133
    long long timeDelta; /* delta = received - sent, i.e., the difference
134 135 136 137 138
                            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 已提交
139
    /* Raw values from QEMU */
140
    qemuMonitorMigrationStats stats;
141
    qemuDomainMirrorStats mirrorStats;
J
Jiri Denemark 已提交
142 143
};

144
struct qemuDomainJobObj {
145
    virCond cond;                       /* Use to coordinate jobs */
146
    qemuDomainJob active;               /* Currently running job */
147
    unsigned long long owner;           /* Thread id which set current job */
148
    const char *ownerAPI;               /* The API which owns the job */
J
Jiri Denemark 已提交
149
    unsigned long long started;         /* When the current job started */
150

151
    virCond asyncCond;                  /* Use to coordinate with async jobs */
152
    qemuDomainAsyncJob asyncJob;        /* Currently active async job */
153
    unsigned long long asyncOwner;      /* Thread which set current async job */
154
    const char *asyncOwnerAPI;          /* The API which owns the async job */
J
Jiri Denemark 已提交
155
    unsigned long long asyncStarted;    /* When the current async job started */
J
Jiri Denemark 已提交
156
    int phase;                          /* Job phase (mainly for migrations) */
157
    unsigned long long mask;            /* Jobs allowed during async job */
158
    bool dump_memory_only;              /* use dump-guest-memory to do dump */
J
Jiri Denemark 已提交
159
    qemuDomainJobInfoPtr current;       /* async job progress data */
160
    qemuDomainJobInfoPtr completed;     /* statistics data of a recently completed job */
161
    bool abortJob;                      /* abort of the job requested */
162 163
    bool spiceMigration;                /* we asked for spice migration and we
                                         * should wait for it to finish */
164
    bool spiceMigrated;                 /* spice migration completed */
165
    bool postcopyEnabled;               /* post-copy migration was enabled */
166 167
};

168
typedef void (*qemuDomainCleanupCallback)(virQEMUDriverPtr driver,
169 170
                                          virDomainObjPtr vm);

J
John Ferlan 已提交
171
# define QEMU_DOMAIN_MASTER_KEY_LEN 32  /* 32 bytes for 256 bit random key */
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187


/* 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;
};

188 189 190 191 192 193 194 195 196 197

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

bool qemuDomainNamespaceEnabled(virDomainObjPtr vm,
                                qemuDomainNamespace ns);

198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
/* Type of domain secret */
typedef enum {
    VIR_DOMAIN_SECRET_INFO_TYPE_PLAIN = 0,
    VIR_DOMAIN_SECRET_INFO_TYPE_AES,  /* utilize GNUTLS_CIPHER_AES_256_CBC */

    VIR_DOMAIN_SECRET_INFO_TYPE_LAST
} qemuDomainSecretInfoType;

typedef struct _qemuDomainSecretPlain qemuDomainSecretPlain;
typedef struct _qemuDomainSecretPlain *qemuDomainSecretPlainPtr;
struct _qemuDomainSecretPlain {
    char *username;
    uint8_t *secret;
    size_t secretlen;
};

# define QEMU_DOMAIN_AES_IV_LEN 16   /* 16 bytes for 128 bit random */
                                     /*    initialization vector */
typedef struct _qemuDomainSecretAES qemuDomainSecretAES;
typedef struct _qemuDomainSecretAES *qemuDomainSecretAESPtr;
struct _qemuDomainSecretAES {
    char *username;
    char *alias;      /* generated alias for secret */
    char *iv;         /* base64 encoded initialization vector */
    char *ciphertext; /* encoded/encrypted secret */
};

typedef struct _qemuDomainSecretInfo qemuDomainSecretInfo;
typedef qemuDomainSecretInfo *qemuDomainSecretInfoPtr;
struct _qemuDomainSecretInfo {
    qemuDomainSecretInfoType type;
    union {
        qemuDomainSecretPlain plain;
        qemuDomainSecretAES aes;
    } s;
};

235 236 237
typedef struct _qemuDomainObjPrivate qemuDomainObjPrivate;
typedef qemuDomainObjPrivate *qemuDomainObjPrivatePtr;
struct _qemuDomainObjPrivate {
238 239
    virQEMUDriverPtr driver;

240
    struct qemuDomainJobObj job;
241

242 243
    virBitmapPtr namespaces;

244
    qemuMonitorPtr mon;
245
    virDomainChrSourceDefPtr monConfig;
E
Eric Blake 已提交
246
    bool monJSON;
247 248
    bool monError;
    unsigned long long monStart;
D
Daniel P. Berrange 已提交
249 250 251 252

    qemuAgentPtr agent;
    bool agentError;

253
    bool gotShutdown;
254
    bool beingDestroyed;
255
    char *pidfile;
256

257
    virDomainPCIAddressSetPtr pciaddrs;
J
Ján Tomko 已提交
258
    virDomainUSBAddressSetPtr usbaddrs;
259

260
    virQEMUCapsPtr qemuCaps;
261
    char *lockState;
262 263

    bool fakeReboot;
264 265

    int jobs_queued;
266 267

    unsigned long migMaxBandwidth;
J
Jiri Denemark 已提交
268
    char *origname;
269
    int nbdPort; /* Port used for migration with NBD */
270
    unsigned short migrationPort;
271
    int preMigrationState;
272

273
    virChrdevsPtr devs;
274 275 276 277

    qemuDomainCleanupCallback *cleanupCallbacks;
    size_t ncleanupCallbacks;
    size_t ncleanupCallbacks_max;
278 279

    virCgroupPtr cgroup;
280

281 282
    virPerfPtr perf;

283 284
    qemuDomainUnpluggingDevice unplug;

285
    char **qemuDevices; /* NULL-terminated list of devices aliases known to QEMU */
286 287

    bool hookRun;  /* true if there was a hook run over this domain */
288 289

    /* Bitmaps below hold data from the auto NUMA feature */
290
    virBitmapPtr autoNodeset;
291
    virBitmapPtr autoCpuset;
292 293 294

    bool signalIOError; /* true if the domain condition should be signalled on
                           I/O error */
295 296
    bool signalStop; /* true if the domain condition should be signalled on
                        QMP STOP event */
297
    char *machineName;
298 299
    char *libDir;            /* base path for per-domain files */
    char *channelTargetDir;  /* base path for per-domain channel targets */
J
John Ferlan 已提交
300 301 302 303 304

    /* 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;
305 306 307

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

309 310 311
    /* for migrations using TLS with a secret (not to be saved in our */
    /* private XML). */
    qemuDomainSecretInfoPtr migSecinfo;
312

313 314 315
    /* Used when fetching/storing the current 'tls-creds' migration setting */
    /* (not to be saved in our private XML). */
    char *migTLSAlias;
316 317 318 319

    /* CPU def used to start the domain when it differs from the one actually
     * provided by QEMU. */
    virCPUDefPtr origCPU;
320 321 322

    /* If true virtlogd is used as stdio handler for character devices. */
    bool chardevStdioLogd;
323 324 325

    /* Tracks blockjob state for vm. Valid only while reconnecting to qemu. */
    virTristateBool reconnectBlockjobs;
326 327
};

328
# define QEMU_DOMAIN_PRIVATE(vm)        \
329
    ((qemuDomainObjPrivatePtr) (vm)->privateData)
330

331
# define QEMU_DOMAIN_DISK_PRIVATE(disk) \
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
    ((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 */
348 349

    bool migrating; /* the disk is being migrated */
350 351 352 353

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

J
John Ferlan 已提交
355 356 357 358 359
    /* 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;

360 361 362
    /* information about the device */
    bool tray; /* device has tray */
    bool removable; /* device media can be removed/changed */
363 364
};

365
# define QEMU_DOMAIN_HOSTDEV_PRIVATE(hostdev)   \
366 367
    ((qemuDomainHostdevPrivatePtr) (hostdev)->privateData)

368 369 370 371 372 373

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

374
    pid_t tid; /* vcpu thread id */
375
    int enable_id; /* order in which the vcpus were enabled in qemu */
376
    int qemu_id; /* ID reported by qemu as 'CPU' in query-cpus */
377
    char *alias;
378
    bool halted;
379 380 381 382 383 384

    /* information for hotpluggable cpus */
    char *type;
    int socket_id;
    int core_id;
    int thread_id;
385
    int node_id;
386
    int vcpus;
387 388 389 390 391 392
};

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


393 394 395
struct qemuDomainDiskInfo {
    bool removable;
    bool locked;
396
    bool tray;
397
    bool tray_open;
398
    bool empty;
399
    int io_status;
400
    char *nodename;
401 402
};

403 404 405 406 407 408 409 410 411 412
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;
};

413
# define QEMU_DOMAIN_CHR_SOURCE_PRIVATE(dev)    \
414
    ((qemuDomainChrSourcePrivatePtr) (dev)->privateData)
415

416 417 418
typedef struct _qemuDomainChrSourcePrivate qemuDomainChrSourcePrivate;
typedef qemuDomainChrSourcePrivate *qemuDomainChrSourcePrivatePtr;
struct _qemuDomainChrSourcePrivate {
419 420 421 422 423 424 425 426
    virObject parent;

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


C
Chen Fan 已提交
427 428
typedef enum {
    QEMU_PROCESS_EVENT_WATCHDOG = 0,
429
    QEMU_PROCESS_EVENT_GUESTPANIC,
430
    QEMU_PROCESS_EVENT_DEVICE_DELETED,
431
    QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED,
432
    QEMU_PROCESS_EVENT_SERIAL_CHANGED,
433
    QEMU_PROCESS_EVENT_BLOCK_JOB,
434
    QEMU_PROCESS_EVENT_MONITOR_EOF,
C
Chen Fan 已提交
435 436 437 438 439

    QEMU_PROCESS_EVENT_LAST
} qemuProcessEventType;

struct qemuProcessEvent {
440
    virDomainObjPtr vm;
C
Chen Fan 已提交
441
    qemuProcessEventType eventType;
442
    int action;
443
    int status;
444
    void *data;
445 446
};

447 448 449
typedef struct _qemuDomainLogContext qemuDomainLogContext;
typedef qemuDomainLogContext *qemuDomainLogContextPtr;

450 451 452 453
typedef struct _qemuDomainSaveCookie qemuDomainSaveCookie;
typedef qemuDomainSaveCookie *qemuDomainSaveCookiePtr;
struct _qemuDomainSaveCookie {
    virObject parent;
454 455

    virCPUDefPtr cpu;
456 457 458 459
};

qemuDomainSaveCookiePtr qemuDomainSaveCookieNew(virDomainObjPtr vm);

460
const char *qemuDomainAsyncJobPhaseToString(qemuDomainAsyncJob job,
J
Jiri Denemark 已提交
461
                                            int phase);
462
int qemuDomainAsyncJobPhaseFromString(qemuDomainAsyncJob job,
J
Jiri Denemark 已提交
463 464
                                      const char *phase);

465
void qemuDomainEventFlush(int timer, void *opaque);
466

467
void qemuDomainEventQueue(virQEMUDriverPtr driver,
468
                          virObjectEventPtr event);
469 470
void qemuDomainEventEmitJobCompleted(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm);
471

472
int qemuDomainObjBeginJob(virQEMUDriverPtr driver,
473
                          virDomainObjPtr obj,
474
                          qemuDomainJob job)
475
    ATTRIBUTE_RETURN_CHECK;
476
int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver,
477
                               virDomainObjPtr obj,
478 479
                               qemuDomainAsyncJob asyncJob,
                               virDomainJobOperation operation)
480
    ATTRIBUTE_RETURN_CHECK;
481 482 483 484
int qemuDomainObjBeginNestedJob(virQEMUDriverPtr driver,
                                virDomainObjPtr obj,
                                qemuDomainAsyncJob asyncJob)
    ATTRIBUTE_RETURN_CHECK;
485

486 487 488 489
void qemuDomainObjEndJob(virQEMUDriverPtr driver,
                         virDomainObjPtr obj);
void qemuDomainObjEndAsyncJob(virQEMUDriverPtr driver,
                              virDomainObjPtr obj);
490
void qemuDomainObjAbortAsyncJob(virDomainObjPtr obj);
491
void qemuDomainObjSetJobPhase(virQEMUDriverPtr driver,
J
Jiri Denemark 已提交
492 493
                              virDomainObjPtr obj,
                              int phase);
494 495
void qemuDomainObjSetAsyncJobMask(virDomainObjPtr obj,
                                  unsigned long long allowedJobs);
496 497
void qemuDomainObjRestoreJob(virDomainObjPtr obj,
                             struct qemuDomainJobObj *job);
498
void qemuDomainObjDiscardAsyncJob(virQEMUDriverPtr driver,
499
                                  virDomainObjPtr obj);
500
void qemuDomainObjReleaseAsyncJob(virDomainObjPtr obj);
501

502 503
qemuMonitorPtr qemuDomainGetMonitor(virDomainObjPtr vm)
    ATTRIBUTE_NONNULL(1);
504
void qemuDomainObjEnterMonitor(virQEMUDriverPtr driver,
505 506
                               virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
507 508
int qemuDomainObjExitMonitor(virQEMUDriverPtr driver,
                             virDomainObjPtr obj)
509 510
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
    ATTRIBUTE_RETURN_CHECK;
511
int qemuDomainObjEnterMonitorAsync(virQEMUDriverPtr driver,
512
                                   virDomainObjPtr obj,
513
                                   qemuDomainAsyncJob asyncJob)
514
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
D
Daniel P. Berrange 已提交
515 516


517
qemuAgentPtr qemuDomainObjEnterAgent(virDomainObjPtr obj)
518
    ATTRIBUTE_NONNULL(1);
519 520
void qemuDomainObjExitAgent(virDomainObjPtr obj, qemuAgentPtr agent)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
D
Daniel P. Berrange 已提交
521 522


523 524 525 526
void qemuDomainObjEnterRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
void qemuDomainObjExitRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
527

528 529 530 531
virDomainDefPtr qemuDomainDefCopy(virQEMUDriverPtr driver,
                                  virDomainDefPtr src,
                                  unsigned int flags);

532
int qemuDomainDefFormatBuf(virQEMUDriverPtr driver,
533 534 535 536
                           virDomainDefPtr vm,
                           unsigned int flags,
                           virBuffer *buf);

537
char *qemuDomainDefFormatXML(virQEMUDriverPtr driver,
538
                             virDomainDefPtr vm,
539
                             unsigned int flags);
540

541
char *qemuDomainFormatXML(virQEMUDriverPtr driver,
542
                          virDomainObjPtr vm,
543
                          unsigned int flags);
544

545
char *qemuDomainDefFormatLive(virQEMUDriverPtr driver,
546
                              virDomainDefPtr def,
547
                              virCPUDefPtr origCPU,
548 549
                              bool inactive,
                              bool compatible);
550

551
void qemuDomainObjTaint(virQEMUDriverPtr driver,
552
                        virDomainObjPtr obj,
553
                        virDomainTaintFlags taint,
554
                        qemuDomainLogContextPtr logCtxt);
555

556
void qemuDomainObjCheckTaint(virQEMUDriverPtr driver,
557
                             virDomainObjPtr obj,
558
                             qemuDomainLogContextPtr logCtxt);
559
void qemuDomainObjCheckDiskTaint(virQEMUDriverPtr driver,
560
                                 virDomainObjPtr obj,
561
                                 virDomainDiskDefPtr disk,
562
                                 qemuDomainLogContextPtr logCtxt);
563 564 565
void qemuDomainObjCheckHostdevTaint(virQEMUDriverPtr driver,
                                    virDomainObjPtr obj,
                                    virDomainHostdevDefPtr disk,
566
                                    qemuDomainLogContextPtr logCtxt);
567
void qemuDomainObjCheckNetTaint(virQEMUDriverPtr driver,
568
                                virDomainObjPtr obj,
569
                                virDomainNetDefPtr net,
570
                                qemuDomainLogContextPtr logCtxt);
571

572 573 574 575 576 577 578 579 580 581 582 583 584 585 586
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);
587

588 589
virLogManagerPtr qemuDomainLogContextGetManager(qemuDomainLogContextPtr ctxt);

590 591 592 593 594
int qemuDomainLogAppendMessage(virQEMUDriverPtr driver,
                               virDomainObjPtr vm,
                               const char *fmt,
                               ...) ATTRIBUTE_FMT_PRINTF(3, 4);

595
const char *qemuFindQemuImgBinary(virQEMUDriverPtr driver);
596 597 598

int qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
                                    virDomainSnapshotObjPtr snapshot,
599
                                    virCapsPtr caps,
600
                                    virDomainXMLOptionPtr xmlopt,
601 602
                                    char *snapshotDir);

603
int qemuDomainSnapshotForEachQcow2(virQEMUDriverPtr driver,
604 605 606 607 608
                                   virDomainObjPtr vm,
                                   virDomainSnapshotObjPtr snap,
                                   const char *op,
                                   bool try_all);

609
int qemuDomainSnapshotDiscard(virQEMUDriverPtr driver,
610 611 612 613 614
                              virDomainObjPtr vm,
                              virDomainSnapshotObjPtr snap,
                              bool update_current,
                              bool metadata_only);

615 616 617
typedef struct _virQEMUSnapRemove virQEMUSnapRemove;
typedef virQEMUSnapRemove *virQEMUSnapRemovePtr;
struct _virQEMUSnapRemove {
618
    virQEMUDriverPtr driver;
619 620 621 622 623 624
    virDomainObjPtr vm;
    int err;
    bool metadata_only;
    bool current;
};

625 626 627
int qemuDomainSnapshotDiscardAll(void *payload,
                                 const void *name,
                                 void *data);
628

629
int qemuDomainSnapshotDiscardAllMetadata(virQEMUDriverPtr driver,
630 631
                                         virDomainObjPtr vm);

632
void qemuDomainRemoveInactive(virQEMUDriverPtr driver,
633 634
                              virDomainObjPtr vm);

635 636 637
void qemuDomainRemoveInactiveJob(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm);

638
void qemuDomainSetFakeReboot(virQEMUDriverPtr driver,
639 640 641
                             virDomainObjPtr vm,
                             bool value);

642
bool qemuDomainJobAllowed(qemuDomainObjPrivatePtr priv,
643
                          qemuDomainJob job);
M
Michal Privoznik 已提交
644

645 646 647 648 649
int qemuDomainCheckDiskStartupPolicy(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm,
                                     size_t diskIndex,
                                     bool cold_boot);

650
int qemuDomainCheckDiskPresence(virQEMUDriverPtr driver,
M
Michal Privoznik 已提交
651
                                virDomainObjPtr vm,
652
                                unsigned int flags);
653

654
int qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
655
                                 virDomainObjPtr vm,
656
                                 virDomainDiskDefPtr disk,
657 658
                                 bool force_probe,
                                 bool report_broken);
659

660
bool qemuDomainDiskSourceDiffers(virDomainDiskDefPtr disk,
661 662
                                 virDomainDiskDefPtr origDisk);

663 664 665
bool qemuDomainDiskChangeSupported(virDomainDiskDefPtr disk,
                                   virDomainDiskDefPtr orig_disk);

666 667 668
int qemuDomainStorageFileInit(virQEMUDriverPtr driver,
                              virDomainObjPtr vm,
                              virStorageSourcePtr src);
669
char *qemuDomainStorageAlias(const char *device, int depth);
670

671 672 673 674 675 676 677 678
void qemuDomainDiskChainElementRevoke(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm,
                                      virStorageSourcePtr elem);
int qemuDomainDiskChainElementPrepare(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm,
                                      virStorageSourcePtr elem,
                                      bool readonly);

679 680 681 682
int qemuDomainCleanupAdd(virDomainObjPtr vm,
                         qemuDomainCleanupCallback cb);
void qemuDomainCleanupRemove(virDomainObjPtr vm,
                             qemuDomainCleanupCallback cb);
683
void qemuDomainCleanupRun(virQEMUDriverPtr driver,
684 685
                          virDomainObjPtr vm);

686 687
void qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr priv);

688 689
extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks;
extern virDomainXMLNamespace virQEMUDriverDomainXMLNamespace;
690
extern virDomainDefParserConfig virQEMUDriverDomainDefParserConfig;
691
extern virDomainABIStability virQEMUDriverDomainABIStability;
692
extern virSaveCookieCallbacks virQEMUDriverDomainSaveCookie;
693

694
int qemuDomainUpdateDeviceList(virQEMUDriverPtr driver,
695
                               virDomainObjPtr vm, int asyncJob);
696

697 698 699 700
int qemuDomainUpdateMemoryDeviceInfo(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm,
                                     int asyncJob);

701 702 703
bool qemuDomainDefCheckABIStability(virQEMUDriverPtr driver,
                                    virDomainDefPtr src,
                                    virDomainDefPtr dst);
704

705 706 707 708
bool qemuDomainCheckABIStability(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm,
                                 virDomainDefPtr dst);

709
bool qemuDomainAgentAvailable(virDomainObjPtr vm,
710 711
                              bool reportError);

J
Jiri Denemark 已提交
712 713
int qemuDomainJobInfoUpdateTime(qemuDomainJobInfoPtr jobInfo)
    ATTRIBUTE_NONNULL(1);
714 715
int qemuDomainJobInfoUpdateDowntime(qemuDomainJobInfoPtr jobInfo)
    ATTRIBUTE_NONNULL(1);
J
Jiri Denemark 已提交
716 717 718 719 720 721 722 723 724 725
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);

726
int qemuDomainSupportsBlockJobs(virDomainObjPtr vm)
727
    ATTRIBUTE_NONNULL(1);
728
bool qemuDomainDiskBlockJobIsActive(virDomainDiskDefPtr disk);
729 730
bool qemuDomainHasBlockjob(virDomainObjPtr vm, bool copy_only)
    ATTRIBUTE_NONNULL(1);
731

732
int qemuDomainAlignMemorySizes(virDomainDefPtr def);
733 734
void qemuDomainMemoryDeviceAlignSize(virDomainDefPtr def,
                                     virDomainMemoryDefPtr mem);
735

736
virDomainChrDefPtr qemuFindAgentConfig(virDomainDefPtr def);
737

738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
bool qemuDomainIsQ35(const virDomainDef *def);
bool qemuDomainIsI440FX(const virDomainDef *def);
bool qemuDomainHasPCIRoot(const virDomainDef *def);
bool qemuDomainHasPCIeRoot(const virDomainDef *def);
bool qemuDomainNeedsFDC(const virDomainDef *def);
bool qemuDomainIsS390CCW(const virDomainDef *def);
bool qemuDomainIsVirt(const virDomainDef *def);
bool qemuDomainIsPSeries(const virDomainDef *def);
bool qemuDomainHasBuiltinIDE(const virDomainDef *def);

bool qemuDomainMachineIsQ35(const char *machine);
bool qemuDomainMachineIsI440FX(const char *machine);
bool qemuDomainMachineNeedsFDC(const char *machine);
bool qemuDomainMachineIsS390CCW(const char *machine);
bool qemuDomainMachineIsVirt(const char *machine,
                             const virArch arch);
bool qemuDomainMachineIsPSeries(const char *machine,
                                const virArch arch);
bool qemuDomainMachineHasBuiltinIDE(const char *machine);
757

758 759 760
int qemuDomainUpdateCurrentMemorySize(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm);

761
unsigned long long qemuDomainGetMemLockLimitBytes(virDomainDefPtr def);
762
int qemuDomainAdjustMaxMemLock(virDomainObjPtr vm);
763

764 765 766 767
int qemuDomainDefValidateMemoryHotplug(const virDomainDef *def,
                                       virQEMUCapsPtr qemuCaps,
                                       const virDomainMemoryDef *mem);

768
bool qemuDomainSupportsNewVcpuHotplug(virDomainObjPtr vm);
769
bool qemuDomainHasVcpuPids(virDomainObjPtr vm);
770
pid_t qemuDomainGetVcpuPid(virDomainObjPtr vm, unsigned int vcpuid);
771
int qemuDomainValidateVcpuInfo(virDomainObjPtr vm);
772 773
int qemuDomainRefreshVcpuInfo(virQEMUDriverPtr driver,
                              virDomainObjPtr vm,
774 775
                              int asyncJob,
                              bool state);
776 777 778 779
bool qemuDomainGetVcpuHalted(virDomainObjPtr vm, unsigned int vcpu);
int qemuDomainRefreshVcpuHalted(virQEMUDriverPtr driver,
                                virDomainObjPtr vm,
                                int asyncJob);
780

781 782 783 784 785 786 787
bool qemuDomainSupportsNicdev(virDomainDefPtr def,
                              virDomainNetDefPtr net);

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

788 789
bool qemuDomainNetSupportsMTU(virDomainNetType type);

J
John Ferlan 已提交
790
int qemuDomainNetVLAN(virDomainNetDefPtr def);
791

792 793 794
int qemuDomainSetPrivatePaths(virQEMUDriverPtr driver,
                              virDomainObjPtr vm);

P
Peter Krempa 已提交
795 796
virDomainDiskDefPtr qemuDomainDiskByName(virDomainDefPtr def, const char *name);

J
John Ferlan 已提交
797 798 799 800
char *qemuDomainGetMasterKeyFilePath(const char *libDir);

int qemuDomainMasterKeyReadFile(qemuDomainObjPrivatePtr priv);

801 802 803 804
int qemuDomainWriteMasterKeyFile(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm);

int qemuDomainMasterKeyCreate(virDomainObjPtr vm);
J
John Ferlan 已提交
805 806 807

void qemuDomainMasterKeyRemove(qemuDomainObjPrivatePtr priv);

808 809 810
void qemuDomainSecretInfoFree(qemuDomainSecretInfoPtr *secinfo)
    ATTRIBUTE_NONNULL(1);

811 812 813
void qemuDomainSecretDiskDestroy(virDomainDiskDefPtr disk)
    ATTRIBUTE_NONNULL(1);

814 815 816
bool qemuDomainSecretDiskCapable(virStorageSourcePtr src)
    ATTRIBUTE_NONNULL(1);

817 818 819
bool qemuDomainDiskHasEncryptionSecret(virStorageSourcePtr src)
    ATTRIBUTE_NONNULL(1);

820 821 822 823 824 825
qemuDomainSecretInfoPtr
qemuDomainSecretInfoTLSNew(virConnectPtr conn,
                           qemuDomainObjPrivatePtr priv,
                           const char *srcAlias,
                           const char *secretUUID);

J
John Ferlan 已提交
826 827 828 829
int qemuDomainSecretDiskPrepare(virConnectPtr conn,
                                qemuDomainObjPrivatePtr priv,
                                virDomainDiskDefPtr disk)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
830

831 832 833 834
void qemuDomainSecretHostdevDestroy(virDomainHostdevDefPtr disk)
    ATTRIBUTE_NONNULL(1);

int qemuDomainSecretHostdevPrepare(virConnectPtr conn,
J
John Ferlan 已提交
835
                                   qemuDomainObjPrivatePtr priv,
836
                                   virDomainHostdevDefPtr hostdev)
J
John Ferlan 已提交
837
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
838

839 840 841 842 843 844 845 846 847 848 849
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);

850 851 852
void qemuDomainSecretDestroy(virDomainObjPtr vm)
    ATTRIBUTE_NONNULL(1);

853 854 855 856
int qemuDomainSecretPrepare(virConnectPtr conn,
                            virQEMUDriverPtr driver,
                            virDomainObjPtr vm)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
857

858 859 860
int qemuDomainDefValidateDiskLunSource(const virStorageSource *src)
    ATTRIBUTE_NONNULL(1);

861 862 863 864
int qemuDomainPrepareChannel(virDomainChrDefPtr chr,
                             const char *domainChannelTargetDir)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

865 866 867 868 869
void qemuDomainPrepareChardevSourceTLS(virDomainChrSourceDefPtr source,
                                       virQEMUDriverConfigPtr cfg)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

void qemuDomainPrepareChardevSource(virDomainDefPtr def,
870
                                    virQEMUDriverConfigPtr cfg)
871 872
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

873 874 875 876 877 878
int
qemuDomainPrepareDiskSourceTLS(virStorageSourcePtr src,
                               const char *diskAlias,
                               virQEMUDriverConfigPtr cfg)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);

879 880 881
int qemuDomainPrepareShmemChardev(virDomainShmemDefPtr shmem)
    ATTRIBUTE_NONNULL(1);

882 883 884
bool qemuDomainVcpuHotplugIsInOrder(virDomainDefPtr def)
    ATTRIBUTE_NONNULL(1);

885 886 887
void qemuDomainVcpuPersistOrder(virDomainDefPtr def)
    ATTRIBUTE_NONNULL(1);

L
Lin Ma 已提交
888 889 890
int qemuDomainDefValidateDisk(const virDomainDiskDef *disk,
                              virQEMUCapsPtr qemuCaps);

891 892 893 894
int qemuDomainCheckMonitor(virQEMUDriverPtr driver,
                           virDomainObjPtr vm,
                           qemuDomainAsyncJob asyncJob);

895 896 897
bool qemuDomainSupportsVideoVga(virDomainVideoDefPtr video,
                                virQEMUCapsPtr qemuCaps);

898 899 900
int qemuDomainGetHostdevPath(virDomainDefPtr def,
                             virDomainHostdevDefPtr dev,
                             bool teardown,
901 902 903
                             size_t *npaths,
                             char ***path,
                             int **perms);
904

905 906
int qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg,
                             virSecurityManagerPtr mgr,
907 908 909 910 911
                             virDomainObjPtr vm);

int qemuDomainCreateNamespace(virQEMUDriverPtr driver,
                              virDomainObjPtr vm);

912 913 914
void qemuDomainDestroyNamespace(virQEMUDriverPtr driver,
                                virDomainObjPtr vm);

915 916
bool qemuDomainNamespaceAvailable(qemuDomainNamespace ns);

917 918
int qemuDomainNamespaceSetupDisk(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm,
919
                                 virStorageSourcePtr src);
920 921 922

int qemuDomainNamespaceTeardownDisk(virQEMUDriverPtr driver,
                                    virDomainObjPtr vm,
923
                                    virStorageSourcePtr src);
924 925 926 927 928 929 930 931

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

int qemuDomainNamespaceTeardownHostdev(virQEMUDriverPtr driver,
                                       virDomainObjPtr vm,
                                       virDomainHostdevDefPtr hostdev);
932

M
Michal Privoznik 已提交
933 934 935 936 937 938 939 940
int qemuDomainNamespaceSetupMemory(virQEMUDriverPtr driver,
                                   virDomainObjPtr vm,
                                   virDomainMemoryDefPtr memory);

int qemuDomainNamespaceTeardownMemory(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm,
                                      virDomainMemoryDefPtr memory);

941 942 943 944 945 946 947
int qemuDomainNamespaceSetupChardev(virQEMUDriverPtr driver,
                                    virDomainObjPtr vm,
                                    virDomainChrDefPtr chr);

int qemuDomainNamespaceTeardownChardev(virQEMUDriverPtr driver,
                                       virDomainObjPtr vm,
                                       virDomainChrDefPtr chr);
948 949

int qemuDomainNamespaceSetupRNG(virQEMUDriverPtr driver,
950 951
                                virDomainObjPtr vm,
                                virDomainRNGDefPtr rng);
952 953

int qemuDomainNamespaceTeardownRNG(virQEMUDriverPtr driver,
954 955
                                   virDomainObjPtr vm,
                                   virDomainRNGDefPtr rng);
956 957 958 959 960 961

virDomainDiskDefPtr qemuDomainDiskLookupByNodename(virDomainDefPtr def,
                                                   const char *nodename,
                                                   virStorageSourcePtr *src,
                                                   unsigned int *idx);

962 963 964 965
char *qemuDomainDiskBackingStoreGetName(virDomainDiskDefPtr disk,
                                        virStorageSourcePtr src,
                                        unsigned int idx);

966 967 968
virStorageSourcePtr qemuDomainGetStorageSourceByDevstr(const char *devstr,
                                                       virDomainDefPtr def);

969 970 971 972 973
int
qemuDomainUpdateCPU(virDomainObjPtr vm,
                    virCPUDefPtr cpu,
                    virCPUDefPtr *origCPU);

974 975 976 977
int
qemuDomainFixupCPUs(virDomainObjPtr vm,
                    virCPUDefPtr *origCPU);

978 979 980
char *
qemuDomainGetMachineName(virDomainObjPtr vm);

981
#endif /* __QEMU_DOMAIN_H__ */