qemu_domain.h 36.9 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 55 56
# define QEMU_JOB_DEFAULT_MASK \
    (JOB_MASK(QEMU_JOB_QUERY) | \
     JOB_MASK(QEMU_JOB_DESTROY) | \
57
     JOB_MASK(QEMU_JOB_ABORT))
58

59
/* Jobs which have to be tracked in domain state XML. */
60 61
# define QEMU_DOMAIN_TRACK_JOBS \
    (JOB_MASK(QEMU_JOB_DESTROY) | \
62 63
     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_PAUSED,
107
    QEMU_DOMAIN_JOB_STATUS_POSTCOPY,
108 109 110 111 112
    QEMU_DOMAIN_JOB_STATUS_COMPLETED,
    QEMU_DOMAIN_JOB_STATUS_FAILED,
    QEMU_DOMAIN_JOB_STATUS_CANCELED,
} qemuDomainJobStatus;

113 114 115 116 117 118 119 120

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

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

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

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

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

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


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

189 190 191 192 193 194 195 196 197 198

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

bool qemuDomainNamespaceEnabled(virDomainObjPtr vm,
                                qemuDomainNamespace ns);

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

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

241
    struct qemuDomainJobObj job;
242

243 244
    virBitmapPtr namespaces;

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

    qemuAgentPtr agent;
    bool agentError;

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

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

261
    virQEMUCapsPtr qemuCaps;
262
    char *lockState;
263 264

    bool fakeReboot;
265
    virTristateBool allowReboot;
266 267

    int jobs_queued;
268 269

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

275
    virChrdevsPtr devs;
276 277 278 279

    qemuDomainCleanupCallback *cleanupCallbacks;
    size_t ncleanupCallbacks;
    size_t ncleanupCallbacks_max;
280 281

    virCgroupPtr cgroup;
282

283 284
    virPerfPtr perf;

285 286
    qemuDomainUnpluggingDevice unplug;

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

    bool hookRun;  /* true if there was a hook run over this domain */
290 291

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

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

    /* 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;
307 308 309

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

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

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

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

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

    /* Tracks blockjob state for vm. Valid only while reconnecting to qemu. */
    virTristateBool reconnectBlockjobs;
328 329 330 331

    /* Migration capabilities. Rechecked on reconnect, not to be saved in
     * private XML. */
    virBitmapPtr migrationCaps;
332 333
};

334
# define QEMU_DOMAIN_PRIVATE(vm) \
335
    ((qemuDomainObjPrivatePtr) (vm)->privateData)
336

337
# define QEMU_DOMAIN_DISK_PRIVATE(disk) \
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
    ((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 */
353
    char *blockJobError; /* block job completed event error */
354
    bool blockJobSync; /* the block job needs synchronized termination */
355 356

    bool migrating; /* the disk is being migrated */
357

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

363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
# define QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src) \
    ((qemuDomainStorageSourcePrivatePtr) (src)->privateData)

typedef struct _qemuDomainStorageSourcePrivate qemuDomainStorageSourcePrivate;
typedef qemuDomainStorageSourcePrivate *qemuDomainStorageSourcePrivatePtr;
struct _qemuDomainStorageSourcePrivate {
    virObject parent;

    /* data required for authentication to the storage source */
    qemuDomainSecretInfoPtr secinfo;

    /* data required for decryption of encrypted storage source */
    qemuDomainSecretInfoPtr encinfo;
};

virObjectPtr qemuDomainStorageSourcePrivateNew(void);

380 381 382 383 384
typedef struct _qemuDomainVcpuPrivate qemuDomainVcpuPrivate;
typedef qemuDomainVcpuPrivate *qemuDomainVcpuPrivatePtr;
struct _qemuDomainVcpuPrivate {
    virObject parent;

385
    pid_t tid; /* vcpu thread id */
386
    int enable_id; /* order in which the vcpus were enabled in qemu */
387
    int qemu_id; /* ID reported by qemu as 'CPU' in query-cpus */
388
    char *alias;
389
    bool halted;
390 391 392 393 394 395

    /* information for hotpluggable cpus */
    char *type;
    int socket_id;
    int core_id;
    int thread_id;
396
    int node_id;
397
    int vcpus;
398 399
};

400
# define QEMU_DOMAIN_VCPU_PRIVATE(vcpu) \
401 402 403
    ((qemuDomainVcpuPrivatePtr) (vcpu)->privateData)


404 405 406
struct qemuDomainDiskInfo {
    bool removable;
    bool locked;
407
    bool tray;
408
    bool tray_open;
409
    bool empty;
410
    int io_status;
411
    char *nodename;
412 413
};

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

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

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


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

    QEMU_PROCESS_EVENT_LAST
} qemuProcessEventType;

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

448 449
void qemuProcessEventFree(struct qemuProcessEvent *event);

450 451 452
typedef struct _qemuDomainLogContext qemuDomainLogContext;
typedef qemuDomainLogContext *qemuDomainLogContextPtr;

453 454 455 456
typedef struct _qemuDomainSaveCookie qemuDomainSaveCookie;
typedef qemuDomainSaveCookie *qemuDomainSaveCookiePtr;
struct _qemuDomainSaveCookie {
    virObject parent;
457 458

    virCPUDefPtr cpu;
459 460 461 462
};

qemuDomainSaveCookiePtr qemuDomainSaveCookieNew(virDomainObjPtr vm);

463
const char *qemuDomainAsyncJobPhaseToString(qemuDomainAsyncJob job,
J
Jiri Denemark 已提交
464
                                            int phase);
465
int qemuDomainAsyncJobPhaseFromString(qemuDomainAsyncJob job,
J
Jiri Denemark 已提交
466 467
                                      const char *phase);

468
void qemuDomainEventFlush(int timer, void *opaque);
469

470
void qemuDomainEventQueue(virQEMUDriverPtr driver,
471
                          virObjectEventPtr event);
472 473
void qemuDomainEventEmitJobCompleted(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm);
474

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

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

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


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


526 527 528 529
void qemuDomainObjEnterRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
void qemuDomainObjExitRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
530

531 532 533 534
virDomainDefPtr qemuDomainDefCopy(virQEMUDriverPtr driver,
                                  virDomainDefPtr src,
                                  unsigned int flags);

535
int qemuDomainDefFormatBuf(virQEMUDriverPtr driver,
536 537 538 539
                           virDomainDefPtr vm,
                           unsigned int flags,
                           virBuffer *buf);

540
char *qemuDomainDefFormatXML(virQEMUDriverPtr driver,
541
                             virDomainDefPtr vm,
542
                             unsigned int flags);
543

544
char *qemuDomainFormatXML(virQEMUDriverPtr driver,
545
                          virDomainObjPtr vm,
546
                          unsigned int flags);
547

548
char *qemuDomainDefFormatLive(virQEMUDriverPtr driver,
549
                              virDomainDefPtr def,
550
                              virCPUDefPtr origCPU,
551 552
                              bool inactive,
                              bool compatible);
553

554
void qemuDomainObjTaint(virQEMUDriverPtr driver,
555
                        virDomainObjPtr obj,
556
                        virDomainTaintFlags taint,
557
                        qemuDomainLogContextPtr logCtxt);
558

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

575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
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);
590

591 592
virLogManagerPtr qemuDomainLogContextGetManager(qemuDomainLogContextPtr ctxt);

593 594 595 596 597
int qemuDomainLogAppendMessage(virQEMUDriverPtr driver,
                               virDomainObjPtr vm,
                               const char *fmt,
                               ...) ATTRIBUTE_FMT_PRINTF(3, 4);

598
const char *qemuFindQemuImgBinary(virQEMUDriverPtr driver);
599 600 601

int qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
                                    virDomainSnapshotObjPtr snapshot,
602
                                    virCapsPtr caps,
603
                                    virDomainXMLOptionPtr xmlopt,
604 605
                                    char *snapshotDir);

606
int qemuDomainSnapshotForEachQcow2(virQEMUDriverPtr driver,
607 608 609 610 611
                                   virDomainObjPtr vm,
                                   virDomainSnapshotObjPtr snap,
                                   const char *op,
                                   bool try_all);

612
int qemuDomainSnapshotDiscard(virQEMUDriverPtr driver,
613 614 615 616 617
                              virDomainObjPtr vm,
                              virDomainSnapshotObjPtr snap,
                              bool update_current,
                              bool metadata_only);

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

628 629 630
int qemuDomainSnapshotDiscardAll(void *payload,
                                 const void *name,
                                 void *data);
631

632
int qemuDomainSnapshotDiscardAllMetadata(virQEMUDriverPtr driver,
633 634
                                         virDomainObjPtr vm);

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

638 639 640
void qemuDomainRemoveInactiveJob(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm);

641
void qemuDomainSetFakeReboot(virQEMUDriverPtr driver,
642 643 644
                             virDomainObjPtr vm,
                             bool value);

645
bool qemuDomainJobAllowed(qemuDomainObjPrivatePtr priv,
646
                          qemuDomainJob job);
M
Michal Privoznik 已提交
647

648 649 650 651 652
int qemuDomainCheckDiskStartupPolicy(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm,
                                     size_t diskIndex,
                                     bool cold_boot);

653
int qemuDomainCheckDiskPresence(virQEMUDriverPtr driver,
M
Michal Privoznik 已提交
654
                                virDomainObjPtr vm,
655
                                unsigned int flags);
656

657
int qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
658
                                 virDomainObjPtr vm,
659
                                 virDomainDiskDefPtr disk,
660 661
                                 bool force_probe,
                                 bool report_broken);
662

663
bool qemuDomainDiskSourceDiffers(virDomainDiskDefPtr disk,
664 665
                                 virDomainDiskDefPtr origDisk);

666 667 668
bool qemuDomainDiskChangeSupported(virDomainDiskDefPtr disk,
                                   virDomainDiskDefPtr orig_disk);

669 670
int qemuDomainStorageFileInit(virQEMUDriverPtr driver,
                              virDomainObjPtr vm,
671 672
                              virStorageSourcePtr src,
                              virStorageSourcePtr parent);
673
char *qemuDomainStorageAlias(const char *device, int depth);
674

675 676 677 678 679 680
void qemuDomainDiskChainElementRevoke(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm,
                                      virStorageSourcePtr elem);
int qemuDomainDiskChainElementPrepare(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm,
                                      virStorageSourcePtr elem,
681 682
                                      bool readonly,
                                      bool newSource);
683

684 685 686 687
int qemuDomainCleanupAdd(virDomainObjPtr vm,
                         qemuDomainCleanupCallback cb);
void qemuDomainCleanupRemove(virDomainObjPtr vm,
                             qemuDomainCleanupCallback cb);
688
void qemuDomainCleanupRun(virQEMUDriverPtr driver,
689 690
                          virDomainObjPtr vm);

691 692
void qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr priv);

693 694
extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks;
extern virDomainXMLNamespace virQEMUDriverDomainXMLNamespace;
695
extern virDomainDefParserConfig virQEMUDriverDomainDefParserConfig;
696
extern virDomainABIStability virQEMUDriverDomainABIStability;
697
extern virSaveCookieCallbacks virQEMUDriverDomainSaveCookie;
698

699
int qemuDomainUpdateDeviceList(virQEMUDriverPtr driver,
700
                               virDomainObjPtr vm, int asyncJob);
701

702 703 704 705
int qemuDomainUpdateMemoryDeviceInfo(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm,
                                     int asyncJob);

706 707 708
bool qemuDomainDefCheckABIStability(virQEMUDriverPtr driver,
                                    virDomainDefPtr src,
                                    virDomainDefPtr dst);
709

710 711 712 713
bool qemuDomainCheckABIStability(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm,
                                 virDomainDefPtr dst);

714
bool qemuDomainAgentAvailable(virDomainObjPtr vm,
715 716
                              bool reportError);

J
Jiri Denemark 已提交
717 718
int qemuDomainJobInfoUpdateTime(qemuDomainJobInfoPtr jobInfo)
    ATTRIBUTE_NONNULL(1);
719 720
int qemuDomainJobInfoUpdateDowntime(qemuDomainJobInfoPtr jobInfo)
    ATTRIBUTE_NONNULL(1);
J
Jiri Denemark 已提交
721 722 723 724 725 726 727 728 729 730
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);

731
int qemuDomainSupportsBlockJobs(virDomainObjPtr vm)
732
    ATTRIBUTE_NONNULL(1);
733
bool qemuDomainDiskBlockJobIsActive(virDomainDiskDefPtr disk);
734 735
bool qemuDomainHasBlockjob(virDomainObjPtr vm, bool copy_only)
    ATTRIBUTE_NONNULL(1);
736

737
int qemuDomainAlignMemorySizes(virDomainDefPtr def);
738 739
void qemuDomainMemoryDeviceAlignSize(virDomainDefPtr def,
                                     virDomainMemoryDefPtr mem);
740

741
virDomainChrDefPtr qemuFindAgentConfig(virDomainDefPtr def);
742

743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
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);
762

763 764 765
int qemuDomainUpdateCurrentMemorySize(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm);

766
unsigned long long qemuDomainGetMemLockLimitBytes(virDomainDefPtr def);
767
int qemuDomainAdjustMaxMemLock(virDomainObjPtr vm);
768

769 770 771 772
int qemuDomainDefValidateMemoryHotplug(const virDomainDef *def,
                                       virQEMUCapsPtr qemuCaps,
                                       const virDomainMemoryDef *mem);

773
bool qemuDomainSupportsNewVcpuHotplug(virDomainObjPtr vm);
774
bool qemuDomainHasVcpuPids(virDomainObjPtr vm);
775
pid_t qemuDomainGetVcpuPid(virDomainObjPtr vm, unsigned int vcpuid);
776
int qemuDomainValidateVcpuInfo(virDomainObjPtr vm);
777 778
int qemuDomainRefreshVcpuInfo(virQEMUDriverPtr driver,
                              virDomainObjPtr vm,
779 780
                              int asyncJob,
                              bool state);
781 782 783 784
bool qemuDomainGetVcpuHalted(virDomainObjPtr vm, unsigned int vcpu);
int qemuDomainRefreshVcpuHalted(virQEMUDriverPtr driver,
                                virDomainObjPtr vm,
                                int asyncJob);
785

786 787 788 789 790 791 792
bool qemuDomainSupportsNicdev(virDomainDefPtr def,
                              virDomainNetDefPtr net);

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

793 794
bool qemuDomainNetSupportsMTU(virDomainNetType type);

J
John Ferlan 已提交
795
int qemuDomainNetVLAN(virDomainNetDefPtr def);
796

797 798 799
int qemuDomainSetPrivatePaths(virQEMUDriverPtr driver,
                              virDomainObjPtr vm);

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

J
John Ferlan 已提交
802 803 804 805
char *qemuDomainGetMasterKeyFilePath(const char *libDir);

int qemuDomainMasterKeyReadFile(qemuDomainObjPrivatePtr priv);

806 807 808 809
int qemuDomainWriteMasterKeyFile(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm);

int qemuDomainMasterKeyCreate(virDomainObjPtr vm);
J
John Ferlan 已提交
810 811 812

void qemuDomainMasterKeyRemove(qemuDomainObjPrivatePtr priv);

813 814 815
void qemuDomainSecretInfoFree(qemuDomainSecretInfoPtr *secinfo)
    ATTRIBUTE_NONNULL(1);

816 817 818
void qemuDomainSecretDiskDestroy(virDomainDiskDefPtr disk)
    ATTRIBUTE_NONNULL(1);

819 820 821
bool qemuDomainSecretDiskCapable(virStorageSourcePtr src)
    ATTRIBUTE_NONNULL(1);

822 823 824
bool qemuDomainDiskHasEncryptionSecret(virStorageSourcePtr src)
    ATTRIBUTE_NONNULL(1);

825 826 827 828 829 830
qemuDomainSecretInfoPtr
qemuDomainSecretInfoTLSNew(virConnectPtr conn,
                           qemuDomainObjPrivatePtr priv,
                           const char *srcAlias,
                           const char *secretUUID);

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
int qemuDomainPrepareShmemChardev(virDomainShmemDefPtr shmem)
    ATTRIBUTE_NONNULL(1);

876 877 878
bool qemuDomainVcpuHotplugIsInOrder(virDomainDefPtr def)
    ATTRIBUTE_NONNULL(1);

879 880 881
void qemuDomainVcpuPersistOrder(virDomainDefPtr def)
    ATTRIBUTE_NONNULL(1);

L
Lin Ma 已提交
882 883 884
int qemuDomainDefValidateDisk(const virDomainDiskDef *disk,
                              virQEMUCapsPtr qemuCaps);

885 886 887 888
int qemuDomainCheckMonitor(virQEMUDriverPtr driver,
                           virDomainObjPtr vm,
                           qemuDomainAsyncJob asyncJob);

889 890 891
bool qemuDomainSupportsVideoVga(virDomainVideoDefPtr video,
                                virQEMUCapsPtr qemuCaps);

892 893 894
int qemuDomainGetHostdevPath(virDomainDefPtr def,
                             virDomainHostdevDefPtr dev,
                             bool teardown,
895 896 897
                             size_t *npaths,
                             char ***path,
                             int **perms);
898

899 900
int qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg,
                             virSecurityManagerPtr mgr,
901 902 903 904 905
                             virDomainObjPtr vm);

int qemuDomainCreateNamespace(virQEMUDriverPtr driver,
                              virDomainObjPtr vm);

906 907 908
void qemuDomainDestroyNamespace(virQEMUDriverPtr driver,
                                virDomainObjPtr vm);

909 910
bool qemuDomainNamespaceAvailable(qemuDomainNamespace ns);

911
int qemuDomainNamespaceSetupDisk(virDomainObjPtr vm,
912
                                 virStorageSourcePtr src);
913

914
int qemuDomainNamespaceTeardownDisk(virDomainObjPtr vm,
915
                                    virStorageSourcePtr src);
916

917
int qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm,
918 919
                                    virDomainHostdevDefPtr hostdev);

920
int qemuDomainNamespaceTeardownHostdev(virDomainObjPtr vm,
921
                                       virDomainHostdevDefPtr hostdev);
922

923
int qemuDomainNamespaceSetupMemory(virDomainObjPtr vm,
M
Michal Privoznik 已提交
924 925
                                   virDomainMemoryDefPtr memory);

926
int qemuDomainNamespaceTeardownMemory(virDomainObjPtr vm,
M
Michal Privoznik 已提交
927 928
                                      virDomainMemoryDefPtr memory);

929
int qemuDomainNamespaceSetupChardev(virDomainObjPtr vm,
930 931
                                    virDomainChrDefPtr chr);

932
int qemuDomainNamespaceTeardownChardev(virDomainObjPtr vm,
933
                                       virDomainChrDefPtr chr);
934

935
int qemuDomainNamespaceSetupRNG(virDomainObjPtr vm,
936
                                virDomainRNGDefPtr rng);
937

938
int qemuDomainNamespaceTeardownRNG(virDomainObjPtr vm,
939
                                   virDomainRNGDefPtr rng);
940

941 942 943 944 945 946
int qemuDomainNamespaceSetupInput(virDomainObjPtr vm,
                                  virDomainInputDefPtr input);

int qemuDomainNamespaceTeardownInput(virDomainObjPtr vm,
                                     virDomainInputDefPtr input);

947 948 949 950 951
virDomainDiskDefPtr qemuDomainDiskLookupByNodename(virDomainDefPtr def,
                                                   const char *nodename,
                                                   virStorageSourcePtr *src,
                                                   unsigned int *idx);

952 953 954 955
char *qemuDomainDiskBackingStoreGetName(virDomainDiskDefPtr disk,
                                        virStorageSourcePtr src,
                                        unsigned int idx);

956 957 958
virStorageSourcePtr qemuDomainGetStorageSourceByDevstr(const char *devstr,
                                                       virDomainDefPtr def);

959 960 961 962 963
int
qemuDomainUpdateCPU(virDomainObjPtr vm,
                    virCPUDefPtr cpu,
                    virCPUDefPtr *origCPU);

964 965 966 967
int
qemuDomainFixupCPUs(virDomainObjPtr vm,
                    virCPUDefPtr *origCPU);

968 969 970
char *
qemuDomainGetMachineName(virDomainObjPtr vm);

971 972 973 974 975 976 977 978
void
qemuDomainObjPrivateXMLFormatAllowReboot(virBufferPtr buf,
                                         virTristateBool allowReboot);

int
qemuDomainObjPrivateXMLParseAllowReboot(xmlXPathContextPtr ctxt,
                                        virTristateBool *allowReboot);

979 980 981 982 983
bool qemuDomainCheckCCWS390AddressSupport(const virDomainDef *def,
                                    virDomainDeviceInfo info,
                                    virQEMUCapsPtr qemuCaps,
                                    const char *devicename);

984 985 986 987 988
int
qemuDomainCheckMigrationCapabilities(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm,
                                     qemuDomainAsyncJob asyncJob);

989 990 991 992 993 994
int
qemuDomainPrepareDiskSource(virConnectPtr conn,
                            virDomainDiskDefPtr disk,
                            qemuDomainObjPrivatePtr priv,
                            virQEMUDriverConfigPtr cfg);

995
#endif /* __QEMU_DOMAIN_H__ */