qemu_domain.h 37.4 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 353
    ((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 */
354 355

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

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

362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
# 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);

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

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

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

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


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

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
int qemuDomainStorageFileInit(virQEMUDriverPtr driver,
                              virDomainObjPtr vm,
668 669
                              virStorageSourcePtr src,
                              virStorageSourcePtr parent);
670
char *qemuDomainStorageAlias(const char *device, int depth);
671

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

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

688 689
void qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr priv);

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

696
int qemuDomainUpdateDeviceList(virQEMUDriverPtr driver,
697
                               virDomainObjPtr vm, int asyncJob);
698

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

703 704 705
bool qemuDomainDefCheckABIStability(virQEMUDriverPtr driver,
                                    virDomainDefPtr src,
                                    virDomainDefPtr dst);
706

707 708 709 710
bool qemuDomainCheckABIStability(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm,
                                 virDomainDefPtr dst);

711
bool qemuDomainAgentAvailable(virDomainObjPtr vm,
712 713
                              bool reportError);

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

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

734
int qemuDomainAlignMemorySizes(virDomainDefPtr def);
735 736
void qemuDomainMemoryDeviceAlignSize(virDomainDefPtr def,
                                     virDomainMemoryDefPtr mem);
737

738
virDomainChrDefPtr qemuFindAgentConfig(virDomainDefPtr def);
739

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

760 761 762
int qemuDomainUpdateCurrentMemorySize(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm);

763
unsigned long long qemuDomainGetMemLockLimitBytes(virDomainDefPtr def);
764
int qemuDomainAdjustMaxMemLock(virDomainObjPtr vm);
765

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

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

783 784 785 786 787 788 789
bool qemuDomainSupportsNicdev(virDomainDefPtr def,
                              virDomainNetDefPtr net);

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

790 791
bool qemuDomainNetSupportsMTU(virDomainNetType type);

J
John Ferlan 已提交
792
int qemuDomainNetVLAN(virDomainNetDefPtr def);
793

794 795 796
int qemuDomainSetPrivatePaths(virQEMUDriverPtr driver,
                              virDomainObjPtr vm);

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

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

int qemuDomainMasterKeyReadFile(qemuDomainObjPrivatePtr priv);

803 804 805 806
int qemuDomainWriteMasterKeyFile(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm);

int qemuDomainMasterKeyCreate(virDomainObjPtr vm);
J
John Ferlan 已提交
807 808 809

void qemuDomainMasterKeyRemove(qemuDomainObjPrivatePtr priv);

810 811 812
void qemuDomainSecretInfoFree(qemuDomainSecretInfoPtr *secinfo)
    ATTRIBUTE_NONNULL(1);

813 814 815
void qemuDomainSecretDiskDestroy(virDomainDiskDefPtr disk)
    ATTRIBUTE_NONNULL(1);

816 817 818
bool qemuDomainSecretDiskCapable(virStorageSourcePtr src)
    ATTRIBUTE_NONNULL(1);

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

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

828 829 830 831
void qemuDomainSecretHostdevDestroy(virDomainHostdevDefPtr disk)
    ATTRIBUTE_NONNULL(1);

int qemuDomainSecretHostdevPrepare(virConnectPtr conn,
J
John Ferlan 已提交
832
                                   qemuDomainObjPrivatePtr priv,
833
                                   virDomainHostdevDefPtr hostdev)
J
John Ferlan 已提交
834
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
835

836 837 838 839 840 841 842 843 844 845 846
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);

847 848 849
void qemuDomainSecretDestroy(virDomainObjPtr vm)
    ATTRIBUTE_NONNULL(1);

850 851 852 853
int qemuDomainSecretPrepare(virConnectPtr conn,
                            virQEMUDriverPtr driver,
                            virDomainObjPtr vm)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
854

855 856 857
int qemuDomainDefValidateDiskLunSource(const virStorageSource *src)
    ATTRIBUTE_NONNULL(1);

858 859 860 861
int qemuDomainPrepareChannel(virDomainChrDefPtr chr,
                             const char *domainChannelTargetDir)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

862 863 864 865 866
void qemuDomainPrepareChardevSourceTLS(virDomainChrSourceDefPtr source,
                                       virQEMUDriverConfigPtr cfg)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

void qemuDomainPrepareChardevSource(virDomainDefPtr def,
867
                                    virQEMUDriverConfigPtr cfg)
868 869
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

870 871 872
int qemuDomainPrepareShmemChardev(virDomainShmemDefPtr shmem)
    ATTRIBUTE_NONNULL(1);

873 874 875
bool qemuDomainVcpuHotplugIsInOrder(virDomainDefPtr def)
    ATTRIBUTE_NONNULL(1);

876 877 878
void qemuDomainVcpuPersistOrder(virDomainDefPtr def)
    ATTRIBUTE_NONNULL(1);

L
Lin Ma 已提交
879 880 881
int qemuDomainDefValidateDisk(const virDomainDiskDef *disk,
                              virQEMUCapsPtr qemuCaps);

882 883 884 885
int qemuDomainCheckMonitor(virQEMUDriverPtr driver,
                           virDomainObjPtr vm,
                           qemuDomainAsyncJob asyncJob);

886 887 888
bool qemuDomainSupportsVideoVga(virDomainVideoDefPtr video,
                                virQEMUCapsPtr qemuCaps);

889 890 891
int qemuDomainGetHostdevPath(virDomainDefPtr def,
                             virDomainHostdevDefPtr dev,
                             bool teardown,
892 893 894
                             size_t *npaths,
                             char ***path,
                             int **perms);
895

896 897
int qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg,
                             virSecurityManagerPtr mgr,
898 899 900 901 902
                             virDomainObjPtr vm);

int qemuDomainCreateNamespace(virQEMUDriverPtr driver,
                              virDomainObjPtr vm);

903 904 905
void qemuDomainDestroyNamespace(virQEMUDriverPtr driver,
                                virDomainObjPtr vm);

906 907
bool qemuDomainNamespaceAvailable(qemuDomainNamespace ns);

908 909
int qemuDomainNamespaceSetupDisk(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm,
910
                                 virStorageSourcePtr src);
911 912 913

int qemuDomainNamespaceTeardownDisk(virQEMUDriverPtr driver,
                                    virDomainObjPtr vm,
914
                                    virStorageSourcePtr src);
915 916 917 918 919 920 921 922

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

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

M
Michal Privoznik 已提交
924 925 926 927 928 929 930 931
int qemuDomainNamespaceSetupMemory(virQEMUDriverPtr driver,
                                   virDomainObjPtr vm,
                                   virDomainMemoryDefPtr memory);

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

932 933 934 935 936 937 938
int qemuDomainNamespaceSetupChardev(virQEMUDriverPtr driver,
                                    virDomainObjPtr vm,
                                    virDomainChrDefPtr chr);

int qemuDomainNamespaceTeardownChardev(virQEMUDriverPtr driver,
                                       virDomainObjPtr vm,
                                       virDomainChrDefPtr chr);
939 940

int qemuDomainNamespaceSetupRNG(virQEMUDriverPtr driver,
941 942
                                virDomainObjPtr vm,
                                virDomainRNGDefPtr rng);
943 944

int qemuDomainNamespaceTeardownRNG(virQEMUDriverPtr driver,
945 946
                                   virDomainObjPtr vm,
                                   virDomainRNGDefPtr rng);
947

948 949 950 951 952 953
int qemuDomainNamespaceSetupInput(virDomainObjPtr vm,
                                  virDomainInputDefPtr input);

int qemuDomainNamespaceTeardownInput(virDomainObjPtr vm,
                                     virDomainInputDefPtr input);

954 955 956 957 958
virDomainDiskDefPtr qemuDomainDiskLookupByNodename(virDomainDefPtr def,
                                                   const char *nodename,
                                                   virStorageSourcePtr *src,
                                                   unsigned int *idx);

959 960 961 962
char *qemuDomainDiskBackingStoreGetName(virDomainDiskDefPtr disk,
                                        virStorageSourcePtr src,
                                        unsigned int idx);

963 964 965
virStorageSourcePtr qemuDomainGetStorageSourceByDevstr(const char *devstr,
                                                       virDomainDefPtr def);

966 967 968 969 970
int
qemuDomainUpdateCPU(virDomainObjPtr vm,
                    virCPUDefPtr cpu,
                    virCPUDefPtr *origCPU);

971 972 973 974
int
qemuDomainFixupCPUs(virDomainObjPtr vm,
                    virCPUDefPtr *origCPU);

975 976 977
char *
qemuDomainGetMachineName(virDomainObjPtr vm);

978 979 980 981 982 983 984 985
void
qemuDomainObjPrivateXMLFormatAllowReboot(virBufferPtr buf,
                                         virTristateBool allowReboot);

int
qemuDomainObjPrivateXMLParseAllowReboot(xmlXPathContextPtr ctxt,
                                        virTristateBool *allowReboot);

986 987 988 989 990
bool qemuDomainCheckCCWS390AddressSupport(const virDomainDef *def,
                                    virDomainDeviceInfo info,
                                    virQEMUCapsPtr qemuCaps,
                                    const char *devicename);

991 992 993 994 995
int
qemuDomainCheckMigrationCapabilities(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm,
                                     qemuDomainAsyncJob asyncJob);

996 997 998 999 1000 1001
int
qemuDomainPrepareDiskSource(virConnectPtr conn,
                            virDomainDiskDefPtr disk,
                            qemuDomainObjPrivatePtr priv,
                            virQEMUDriverConfigPtr cfg);

1002
#endif /* __QEMU_DOMAIN_H__ */