qemu_domain.h 34.3 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 43 44 45
# define QEMU_DOMAIN_FORMAT_LIVE_FLAGS      \
    (VIR_DOMAIN_XML_SECURE |                \
     VIR_DOMAIN_XML_UPDATE_CPU)

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

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

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

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

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

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

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

    QEMU_ASYNC_JOB_LAST
99
} qemuDomainAsyncJob;
100
VIR_ENUM_DECL(qemuDomainAsyncJob)
101

J
Jiri Denemark 已提交
102 103 104 105
typedef struct _qemuDomainJobInfo qemuDomainJobInfo;
typedef qemuDomainJobInfo *qemuDomainJobInfoPtr;
struct _qemuDomainJobInfo {
    virDomainJobType type;
106
    virDomainJobOperation operation;
J
Jiri Denemark 已提交
107
    unsigned long long started; /* When the async job started */
108
    unsigned long long stopped; /* When the domain's CPUs were stopped */
109 110 111 112
    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 已提交
113 114 115
    /* Computed values */
    unsigned long long timeElapsed;
    unsigned long long timeRemaining;
J
Jiri Denemark 已提交
116
    long long timeDelta; /* delta = received - sent, i.e., the difference
117 118 119 120 121
                            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 已提交
122
    /* Raw values from QEMU */
123
    qemuMonitorMigrationStats stats;
J
Jiri Denemark 已提交
124 125
};

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

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

150
typedef void (*qemuDomainCleanupCallback)(virQEMUDriverPtr driver,
151 152
                                          virDomainObjPtr vm);

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


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

170 171 172 173 174 175 176 177 178 179

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

bool qemuDomainNamespaceEnabled(virDomainObjPtr vm,
                                qemuDomainNamespace ns);

180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
/* 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;
};

217 218 219
typedef struct _qemuDomainObjPrivate qemuDomainObjPrivate;
typedef qemuDomainObjPrivate *qemuDomainObjPrivatePtr;
struct _qemuDomainObjPrivate {
220
    struct qemuDomainJobObj job;
221

222 223
    virBitmapPtr namespaces;

224
    qemuMonitorPtr mon;
225
    virDomainChrSourceDefPtr monConfig;
E
Eric Blake 已提交
226
    bool monJSON;
227 228
    bool monError;
    unsigned long long monStart;
D
Daniel P. Berrange 已提交
229 230 231 232

    qemuAgentPtr agent;
    bool agentError;

233
    bool gotShutdown;
234
    bool beingDestroyed;
235
    char *pidfile;
236

237
    virDomainPCIAddressSetPtr pciaddrs;
J
Ján Tomko 已提交
238
    virDomainUSBAddressSetPtr usbaddrs;
239

240
    virQEMUCapsPtr qemuCaps;
241
    char *lockState;
242 243

    bool fakeReboot;
244 245

    int jobs_queued;
246 247

    unsigned long migMaxBandwidth;
J
Jiri Denemark 已提交
248
    char *origname;
249
    int nbdPort; /* Port used for migration with NBD */
250
    unsigned short migrationPort;
251
    int preMigrationState;
252

253
    virChrdevsPtr devs;
254 255 256 257

    qemuDomainCleanupCallback *cleanupCallbacks;
    size_t ncleanupCallbacks;
    size_t ncleanupCallbacks_max;
258 259

    virCgroupPtr cgroup;
260

261 262
    virPerfPtr perf;

263 264
    qemuDomainUnpluggingDevice unplug;

265
    char **qemuDevices; /* NULL-terminated list of devices aliases known to QEMU */
266 267

    bool hookRun;  /* true if there was a hook run over this domain */
268 269

    /* Bitmaps below hold data from the auto NUMA feature */
270
    virBitmapPtr autoNodeset;
271
    virBitmapPtr autoCpuset;
272 273 274

    bool signalIOError; /* true if the domain condition should be signalled on
                           I/O error */
275 276
    bool signalStop; /* true if the domain condition should be signalled on
                        QMP STOP event */
277
    char *machineName;
278 279
    char *libDir;            /* base path for per-domain files */
    char *channelTargetDir;  /* base path for per-domain channel targets */
J
John Ferlan 已提交
280 281 282 283 284

    /* 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;
285 286 287

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

289 290 291
    /* for migrations using TLS with a secret (not to be saved in our */
    /* private XML). */
    qemuDomainSecretInfoPtr migSecinfo;
292

293 294 295
    /* Used when fetching/storing the current 'tls-creds' migration setting */
    /* (not to be saved in our private XML). */
    char *migTLSAlias;
296 297
};

298 299
# define QEMU_DOMAIN_PRIVATE(vm)	\
    ((qemuDomainObjPrivatePtr) (vm)->privateData)
300

301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
# define QEMU_DOMAIN_DISK_PRIVATE(disk)	\
    ((qemuDomainDiskPrivatePtr) (disk)->privateData)

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

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

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

    bool migrating; /* the disk is being migrated */
320 321 322 323

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

J
John Ferlan 已提交
325 326 327 328 329
    /* 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;

330 331 332
    /* information about the device */
    bool tray; /* device has tray */
    bool removable; /* device media can be removed/changed */
333 334
};

335 336 337
# define QEMU_DOMAIN_HOSTDEV_PRIVATE(hostdev)	\
    ((qemuDomainHostdevPrivatePtr) (hostdev)->privateData)

338 339 340 341 342 343

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

344
    pid_t tid; /* vcpu thread id */
345
    int enable_id; /* order in which the vcpus were enabled in qemu */
346
    int qemu_id; /* ID reported by qemu as 'CPU' in query-cpus */
347
    char *alias;
348
    bool halted;
349 350 351 352 353 354 355

    /* information for hotpluggable cpus */
    char *type;
    int socket_id;
    int core_id;
    int thread_id;
    int vcpus;
356 357 358 359 360 361
};

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


362 363 364
struct qemuDomainDiskInfo {
    bool removable;
    bool locked;
365
    bool tray;
366
    bool tray_open;
367
    bool empty;
368
    int io_status;
369
    char *nodename;
370 371
};

372 373 374 375 376 377 378 379 380 381
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;
};

382 383
# define QEMU_DOMAIN_CHR_SOURCE_PRIVATE(dev)	\
    ((qemuDomainChrSourcePrivatePtr) (dev)->privateData)
384

385 386 387
typedef struct _qemuDomainChrSourcePrivate qemuDomainChrSourcePrivate;
typedef qemuDomainChrSourcePrivate *qemuDomainChrSourcePrivatePtr;
struct _qemuDomainChrSourcePrivate {
388 389 390 391 392 393 394 395
    virObject parent;

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


C
Chen Fan 已提交
396 397
typedef enum {
    QEMU_PROCESS_EVENT_WATCHDOG = 0,
398
    QEMU_PROCESS_EVENT_GUESTPANIC,
399
    QEMU_PROCESS_EVENT_DEVICE_DELETED,
400
    QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED,
401
    QEMU_PROCESS_EVENT_SERIAL_CHANGED,
402
    QEMU_PROCESS_EVENT_BLOCK_JOB,
403
    QEMU_PROCESS_EVENT_MONITOR_EOF,
C
Chen Fan 已提交
404 405 406 407 408

    QEMU_PROCESS_EVENT_LAST
} qemuProcessEventType;

struct qemuProcessEvent {
409
    virDomainObjPtr vm;
C
Chen Fan 已提交
410
    qemuProcessEventType eventType;
411
    int action;
412
    int status;
413
    void *data;
414 415
};

416 417 418
typedef struct _qemuDomainLogContext qemuDomainLogContext;
typedef qemuDomainLogContext *qemuDomainLogContextPtr;

419
const char *qemuDomainAsyncJobPhaseToString(qemuDomainAsyncJob job,
J
Jiri Denemark 已提交
420
                                            int phase);
421
int qemuDomainAsyncJobPhaseFromString(qemuDomainAsyncJob job,
J
Jiri Denemark 已提交
422 423
                                      const char *phase);

424
void qemuDomainEventFlush(int timer, void *opaque);
425

426
void qemuDomainEventQueue(virQEMUDriverPtr driver,
427
                          virObjectEventPtr event);
428 429
void qemuDomainEventEmitJobCompleted(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm);
430

431
int qemuDomainObjBeginJob(virQEMUDriverPtr driver,
432
                          virDomainObjPtr obj,
433
                          qemuDomainJob job)
434
    ATTRIBUTE_RETURN_CHECK;
435
int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver,
436
                               virDomainObjPtr obj,
437 438
                               qemuDomainAsyncJob asyncJob,
                               virDomainJobOperation operation)
439
    ATTRIBUTE_RETURN_CHECK;
440 441 442 443
int qemuDomainObjBeginNestedJob(virQEMUDriverPtr driver,
                                virDomainObjPtr obj,
                                qemuDomainAsyncJob asyncJob)
    ATTRIBUTE_RETURN_CHECK;
444

445 446 447 448
void qemuDomainObjEndJob(virQEMUDriverPtr driver,
                         virDomainObjPtr obj);
void qemuDomainObjEndAsyncJob(virQEMUDriverPtr driver,
                              virDomainObjPtr obj);
449
void qemuDomainObjAbortAsyncJob(virDomainObjPtr obj);
450
void qemuDomainObjSetJobPhase(virQEMUDriverPtr driver,
J
Jiri Denemark 已提交
451 452
                              virDomainObjPtr obj,
                              int phase);
453 454
void qemuDomainObjSetAsyncJobMask(virDomainObjPtr obj,
                                  unsigned long long allowedJobs);
455 456
void qemuDomainObjRestoreJob(virDomainObjPtr obj,
                             struct qemuDomainJobObj *job);
457
void qemuDomainObjDiscardAsyncJob(virQEMUDriverPtr driver,
458
                                  virDomainObjPtr obj);
459
void qemuDomainObjReleaseAsyncJob(virDomainObjPtr obj);
460

461 462
qemuMonitorPtr qemuDomainGetMonitor(virDomainObjPtr vm)
    ATTRIBUTE_NONNULL(1);
463
void qemuDomainObjEnterMonitor(virQEMUDriverPtr driver,
464 465
                               virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
466 467
int qemuDomainObjExitMonitor(virQEMUDriverPtr driver,
                             virDomainObjPtr obj)
468 469
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
    ATTRIBUTE_RETURN_CHECK;
470
int qemuDomainObjEnterMonitorAsync(virQEMUDriverPtr driver,
471
                                   virDomainObjPtr obj,
472
                                   qemuDomainAsyncJob asyncJob)
473
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
D
Daniel P. Berrange 已提交
474 475


476
qemuAgentPtr qemuDomainObjEnterAgent(virDomainObjPtr obj)
477
    ATTRIBUTE_NONNULL(1);
478 479
void qemuDomainObjExitAgent(virDomainObjPtr obj, qemuAgentPtr agent)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
D
Daniel P. Berrange 已提交
480 481


482 483 484 485
void qemuDomainObjEnterRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
void qemuDomainObjExitRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
486

487 488 489 490
virDomainDefPtr qemuDomainDefCopy(virQEMUDriverPtr driver,
                                  virDomainDefPtr src,
                                  unsigned int flags);

491
int qemuDomainDefFormatBuf(virQEMUDriverPtr driver,
492 493 494 495
                           virDomainDefPtr vm,
                           unsigned int flags,
                           virBuffer *buf);

496
char *qemuDomainDefFormatXML(virQEMUDriverPtr driver,
497
                             virDomainDefPtr vm,
498
                             unsigned int flags);
499

500
char *qemuDomainFormatXML(virQEMUDriverPtr driver,
501
                          virDomainObjPtr vm,
502
                          unsigned int flags);
503

504
char *qemuDomainDefFormatLive(virQEMUDriverPtr driver,
505
                              virDomainDefPtr def,
506 507
                              bool inactive,
                              bool compatible);
508

509
void qemuDomainObjTaint(virQEMUDriverPtr driver,
510
                        virDomainObjPtr obj,
511
                        virDomainTaintFlags taint,
512
                        qemuDomainLogContextPtr logCtxt);
513

514
void qemuDomainObjCheckTaint(virQEMUDriverPtr driver,
515
                             virDomainObjPtr obj,
516
                             qemuDomainLogContextPtr logCtxt);
517
void qemuDomainObjCheckDiskTaint(virQEMUDriverPtr driver,
518
                                 virDomainObjPtr obj,
519
                                 virDomainDiskDefPtr disk,
520
                                 qemuDomainLogContextPtr logCtxt);
521 522 523
void qemuDomainObjCheckHostdevTaint(virQEMUDriverPtr driver,
                                    virDomainObjPtr obj,
                                    virDomainHostdevDefPtr disk,
524
                                    qemuDomainLogContextPtr logCtxt);
525
void qemuDomainObjCheckNetTaint(virQEMUDriverPtr driver,
526
                                virDomainObjPtr obj,
527
                                virDomainNetDefPtr net,
528
                                qemuDomainLogContextPtr logCtxt);
529

530 531 532 533 534 535 536 537 538 539 540 541 542 543 544
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);
545

546 547
virLogManagerPtr qemuDomainLogContextGetManager(qemuDomainLogContextPtr ctxt);

548 549 550 551 552
int qemuDomainLogAppendMessage(virQEMUDriverPtr driver,
                               virDomainObjPtr vm,
                               const char *fmt,
                               ...) ATTRIBUTE_FMT_PRINTF(3, 4);

553
const char *qemuFindQemuImgBinary(virQEMUDriverPtr driver);
554 555 556

int qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
                                    virDomainSnapshotObjPtr snapshot,
557
                                    virCapsPtr caps,
558
                                    virDomainXMLOptionPtr xmlopt,
559 560
                                    char *snapshotDir);

561
int qemuDomainSnapshotForEachQcow2(virQEMUDriverPtr driver,
562 563 564 565 566
                                   virDomainObjPtr vm,
                                   virDomainSnapshotObjPtr snap,
                                   const char *op,
                                   bool try_all);

567
int qemuDomainSnapshotDiscard(virQEMUDriverPtr driver,
568 569 570 571 572
                              virDomainObjPtr vm,
                              virDomainSnapshotObjPtr snap,
                              bool update_current,
                              bool metadata_only);

573 574 575
typedef struct _virQEMUSnapRemove virQEMUSnapRemove;
typedef virQEMUSnapRemove *virQEMUSnapRemovePtr;
struct _virQEMUSnapRemove {
576
    virQEMUDriverPtr driver;
577 578 579 580 581 582
    virDomainObjPtr vm;
    int err;
    bool metadata_only;
    bool current;
};

583 584 585
int qemuDomainSnapshotDiscardAll(void *payload,
                                 const void *name,
                                 void *data);
586

587
int qemuDomainSnapshotDiscardAllMetadata(virQEMUDriverPtr driver,
588 589
                                         virDomainObjPtr vm);

590
void qemuDomainRemoveInactive(virQEMUDriverPtr driver,
591 592
                              virDomainObjPtr vm);

593
void qemuDomainSetFakeReboot(virQEMUDriverPtr driver,
594 595 596
                             virDomainObjPtr vm,
                             bool value);

597
bool qemuDomainJobAllowed(qemuDomainObjPrivatePtr priv,
598
                          qemuDomainJob job);
M
Michal Privoznik 已提交
599

600 601
int qemuDomainCheckDiskPresence(virConnectPtr conn,
                                virQEMUDriverPtr driver,
M
Michal Privoznik 已提交
602
                                virDomainObjPtr vm,
603
                                unsigned int flags);
604

605
int qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
606
                                 virDomainObjPtr vm,
607
                                 virDomainDiskDefPtr disk,
608 609
                                 bool force_probe,
                                 bool report_broken);
610

611
bool qemuDomainDiskSourceDiffers(virDomainDiskDefPtr disk,
612 613
                                 virDomainDiskDefPtr origDisk);

614 615 616
bool qemuDomainDiskChangeSupported(virDomainDiskDefPtr disk,
                                   virDomainDiskDefPtr orig_disk);

617 618 619
int qemuDomainStorageFileInit(virQEMUDriverPtr driver,
                              virDomainObjPtr vm,
                              virStorageSourcePtr src);
620
char *qemuDomainStorageAlias(const char *device, int depth);
621

622 623 624 625 626 627 628 629
void qemuDomainDiskChainElementRevoke(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm,
                                      virStorageSourcePtr elem);
int qemuDomainDiskChainElementPrepare(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm,
                                      virStorageSourcePtr elem,
                                      bool readonly);

630 631 632 633
int qemuDomainCleanupAdd(virDomainObjPtr vm,
                         qemuDomainCleanupCallback cb);
void qemuDomainCleanupRemove(virDomainObjPtr vm,
                             qemuDomainCleanupCallback cb);
634
void qemuDomainCleanupRun(virQEMUDriverPtr driver,
635 636
                          virDomainObjPtr vm);

637 638
extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks;
extern virDomainXMLNamespace virQEMUDriverDomainXMLNamespace;
639
extern virDomainDefParserConfig virQEMUDriverDomainDefParserConfig;
640
extern virDomainABIStability virQEMUDriverDomainABIStability;
641

642
int qemuDomainUpdateDeviceList(virQEMUDriverPtr driver,
643
                               virDomainObjPtr vm, int asyncJob);
644

645 646 647 648
int qemuDomainUpdateMemoryDeviceInfo(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm,
                                     int asyncJob);

649 650 651
bool qemuDomainDefCheckABIStability(virQEMUDriverPtr driver,
                                    virDomainDefPtr src,
                                    virDomainDefPtr dst);
652

653
bool qemuDomainAgentAvailable(virDomainObjPtr vm,
654 655
                              bool reportError);

J
Jiri Denemark 已提交
656 657
int qemuDomainJobInfoUpdateTime(qemuDomainJobInfoPtr jobInfo)
    ATTRIBUTE_NONNULL(1);
658 659
int qemuDomainJobInfoUpdateDowntime(qemuDomainJobInfoPtr jobInfo)
    ATTRIBUTE_NONNULL(1);
J
Jiri Denemark 已提交
660 661 662 663 664 665 666 667 668 669
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);

670 671
int qemuDomainSupportsBlockJobs(virDomainObjPtr vm, bool *modern)
    ATTRIBUTE_NONNULL(1);
672
bool qemuDomainDiskBlockJobIsActive(virDomainDiskDefPtr disk);
673 674
bool qemuDomainHasBlockjob(virDomainObjPtr vm, bool copy_only)
    ATTRIBUTE_NONNULL(1);
675

676
int qemuDomainAlignMemorySizes(virDomainDefPtr def);
677 678
void qemuDomainMemoryDeviceAlignSize(virDomainDefPtr def,
                                     virDomainMemoryDefPtr mem);
679

680
virDomainChrDefPtr qemuFindAgentConfig(virDomainDefPtr def);
681

682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
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);
701

702 703 704
int qemuDomainUpdateCurrentMemorySize(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm);

705
unsigned long long qemuDomainGetMemLockLimitBytes(virDomainDefPtr def);
706
int qemuDomainAdjustMaxMemLock(virDomainObjPtr vm);
707

708 709 710 711
int qemuDomainDefValidateMemoryHotplug(const virDomainDef *def,
                                       virQEMUCapsPtr qemuCaps,
                                       const virDomainMemoryDef *mem);

712
bool qemuDomainSupportsNewVcpuHotplug(virDomainObjPtr vm);
713
bool qemuDomainHasVcpuPids(virDomainObjPtr vm);
714
pid_t qemuDomainGetVcpuPid(virDomainObjPtr vm, unsigned int vcpuid);
715
int qemuDomainValidateVcpuInfo(virDomainObjPtr vm);
716 717
int qemuDomainRefreshVcpuInfo(virQEMUDriverPtr driver,
                              virDomainObjPtr vm,
718 719
                              int asyncJob,
                              bool state);
720 721 722 723
bool qemuDomainGetVcpuHalted(virDomainObjPtr vm, unsigned int vcpu);
int qemuDomainRefreshVcpuHalted(virQEMUDriverPtr driver,
                                virDomainObjPtr vm,
                                int asyncJob);
724

725 726 727 728 729 730 731
bool qemuDomainSupportsNicdev(virDomainDefPtr def,
                              virDomainNetDefPtr net);

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

732 733
bool qemuDomainNetSupportsMTU(virDomainNetType type);

J
John Ferlan 已提交
734
int qemuDomainNetVLAN(virDomainNetDefPtr def);
735

736 737 738
int qemuDomainSetPrivatePaths(virQEMUDriverPtr driver,
                              virDomainObjPtr vm);

739
void qemuDomainClearPrivatePaths(virDomainObjPtr vm);
P
Peter Krempa 已提交
740 741 742

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

J
John Ferlan 已提交
743 744 745 746
char *qemuDomainGetMasterKeyFilePath(const char *libDir);

int qemuDomainMasterKeyReadFile(qemuDomainObjPrivatePtr priv);

747 748 749 750
int qemuDomainWriteMasterKeyFile(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm);

int qemuDomainMasterKeyCreate(virDomainObjPtr vm);
J
John Ferlan 已提交
751 752 753

void qemuDomainMasterKeyRemove(qemuDomainObjPrivatePtr priv);

754 755 756
void qemuDomainSecretInfoFree(qemuDomainSecretInfoPtr *secinfo)
    ATTRIBUTE_NONNULL(1);

757 758 759
void qemuDomainSecretDiskDestroy(virDomainDiskDefPtr disk)
    ATTRIBUTE_NONNULL(1);

760 761 762
bool qemuDomainSecretDiskCapable(virStorageSourcePtr src)
    ATTRIBUTE_NONNULL(1);

763 764 765
bool qemuDomainDiskHasEncryptionSecret(virStorageSourcePtr src)
    ATTRIBUTE_NONNULL(1);

766 767 768 769 770 771
qemuDomainSecretInfoPtr
qemuDomainSecretInfoTLSNew(virConnectPtr conn,
                           qemuDomainObjPrivatePtr priv,
                           const char *srcAlias,
                           const char *secretUUID);

J
John Ferlan 已提交
772 773 774 775
int qemuDomainSecretDiskPrepare(virConnectPtr conn,
                                qemuDomainObjPrivatePtr priv,
                                virDomainDiskDefPtr disk)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
776

777 778 779 780
void qemuDomainSecretHostdevDestroy(virDomainHostdevDefPtr disk)
    ATTRIBUTE_NONNULL(1);

int qemuDomainSecretHostdevPrepare(virConnectPtr conn,
J
John Ferlan 已提交
781
                                   qemuDomainObjPrivatePtr priv,
782
                                   virDomainHostdevDefPtr hostdev)
J
John Ferlan 已提交
783
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
784

785 786 787 788 789 790 791 792 793 794 795
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);

796 797 798
void qemuDomainSecretDestroy(virDomainObjPtr vm)
    ATTRIBUTE_NONNULL(1);

799 800 801 802
int qemuDomainSecretPrepare(virConnectPtr conn,
                            virQEMUDriverPtr driver,
                            virDomainObjPtr vm)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
803

804 805 806
int qemuDomainDefValidateDiskLunSource(const virStorageSource *src)
    ATTRIBUTE_NONNULL(1);

807 808 809 810
int qemuDomainPrepareChannel(virDomainChrDefPtr chr,
                             const char *domainChannelTargetDir)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

811 812 813 814 815 816 817 818
void qemuDomainPrepareChardevSourceTLS(virDomainChrSourceDefPtr source,
                                       virQEMUDriverConfigPtr cfg)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

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

819 820 821
int qemuDomainPrepareShmemChardev(virDomainShmemDefPtr shmem)
    ATTRIBUTE_NONNULL(1);

822 823 824
bool qemuDomainVcpuHotplugIsInOrder(virDomainDefPtr def)
    ATTRIBUTE_NONNULL(1);

825 826 827
void qemuDomainVcpuPersistOrder(virDomainDefPtr def)
    ATTRIBUTE_NONNULL(1);

828 829 830 831
int qemuDomainCheckMonitor(virQEMUDriverPtr driver,
                           virDomainObjPtr vm,
                           qemuDomainAsyncJob asyncJob);

832 833 834
bool qemuDomainSupportsVideoVga(virDomainVideoDefPtr video,
                                virQEMUCapsPtr qemuCaps);

835 836 837
int qemuDomainGetHostdevPath(virDomainDefPtr def,
                             virDomainHostdevDefPtr dev,
                             bool teardown,
838 839 840
                             size_t *npaths,
                             char ***path,
                             int **perms);
841

842 843
int qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg,
                             virSecurityManagerPtr mgr,
844 845 846 847 848
                             virDomainObjPtr vm);

int qemuDomainCreateNamespace(virQEMUDriverPtr driver,
                              virDomainObjPtr vm);

849 850 851
void qemuDomainDestroyNamespace(virQEMUDriverPtr driver,
                                virDomainObjPtr vm);

852 853
bool qemuDomainNamespaceAvailable(qemuDomainNamespace ns);

854 855
int qemuDomainNamespaceSetupDisk(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm,
856
                                 virStorageSourcePtr src);
857 858 859

int qemuDomainNamespaceTeardownDisk(virQEMUDriverPtr driver,
                                    virDomainObjPtr vm,
860
                                    virStorageSourcePtr src);
861 862 863 864 865 866 867 868

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

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

M
Michal Privoznik 已提交
870 871 872 873 874 875 876 877
int qemuDomainNamespaceSetupMemory(virQEMUDriverPtr driver,
                                   virDomainObjPtr vm,
                                   virDomainMemoryDefPtr memory);

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

878 879 880 881 882 883 884
int qemuDomainNamespaceSetupChardev(virQEMUDriverPtr driver,
                                    virDomainObjPtr vm,
                                    virDomainChrDefPtr chr);

int qemuDomainNamespaceTeardownChardev(virQEMUDriverPtr driver,
                                       virDomainObjPtr vm,
                                       virDomainChrDefPtr chr);
885 886

int qemuDomainNamespaceSetupRNG(virQEMUDriverPtr driver,
887 888
                                virDomainObjPtr vm,
                                virDomainRNGDefPtr rng);
889 890

int qemuDomainNamespaceTeardownRNG(virQEMUDriverPtr driver,
891 892
                                   virDomainObjPtr vm,
                                   virDomainRNGDefPtr rng);
893 894 895 896 897 898

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

899 900 901 902
char *qemuDomainDiskBackingStoreGetName(virDomainDiskDefPtr disk,
                                        virStorageSourcePtr src,
                                        unsigned int idx);

903 904 905
virStorageSourcePtr qemuDomainGetStorageSourceByDevstr(const char *devstr,
                                                       virDomainDefPtr def);

906
#endif /* __QEMU_DOMAIN_H__ */