qemu_domain.h 37.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 "qemu_migration_params.h"
38
# include "virmdev.h"
39
# include "virchrdev.h"
40
# include "virobject.h"
41
# include "logging/log_manager.h"
42

43
# define QEMU_DOMAIN_FORMAT_LIVE_FLAGS \
44
    (VIR_DOMAIN_XML_SECURE)
45

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

C
caoxinhua 已提交
54
# define JOB_MASK(job)                  (job == 0 ? 0 : 1 << (job - 1))
55 56 57
# define QEMU_JOB_DEFAULT_MASK \
    (JOB_MASK(QEMU_JOB_QUERY) | \
     JOB_MASK(QEMU_JOB_DESTROY) | \
58
     JOB_MASK(QEMU_JOB_ABORT))
59

60
/* Jobs which have to be tracked in domain state XML. */
61 62
# define QEMU_DOMAIN_TRACK_JOBS \
    (JOB_MASK(QEMU_JOB_DESTROY) | \
63 64
     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

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

114 115 116
typedef enum {
    QEMU_DOMAIN_JOB_STATS_TYPE_NONE = 0,
    QEMU_DOMAIN_JOB_STATS_TYPE_MIGRATION,
117
    QEMU_DOMAIN_JOB_STATS_TYPE_SAVEDUMP,
118
    QEMU_DOMAIN_JOB_STATS_TYPE_MEMDUMP,
119 120
} qemuDomainJobStatsType;

121 122 123 124 125 126 127 128

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

J
Jiri Denemark 已提交
129 130 131
typedef struct _qemuDomainJobInfo qemuDomainJobInfo;
typedef qemuDomainJobInfo *qemuDomainJobInfoPtr;
struct _qemuDomainJobInfo {
132
    qemuDomainJobStatus status;
133
    virDomainJobOperation operation;
J
Jiri Denemark 已提交
134
    unsigned long long started; /* When the async job started */
135
    unsigned long long stopped; /* When the domain's CPUs were stopped */
136 137 138 139
    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 已提交
140 141
    /* Computed values */
    unsigned long long timeElapsed;
J
Jiri Denemark 已提交
142
    long long timeDelta; /* delta = received - sent, i.e., the difference
143 144 145 146 147
                            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 已提交
148
    /* Raw values from QEMU */
149 150 151
    qemuDomainJobStatsType statsType;
    union {
        qemuMonitorMigrationStats mig;
152
        qemuMonitorDumpStats dump;
153
    } stats;
154
    qemuDomainMirrorStats mirrorStats;
J
Jiri Denemark 已提交
155 156
};

157 158 159
typedef struct _qemuDomainJobObj qemuDomainJobObj;
typedef qemuDomainJobObj *qemuDomainJobObjPtr;
struct _qemuDomainJobObj {
160
    virCond cond;                       /* Use to coordinate jobs */
161
    qemuDomainJob active;               /* Currently running job */
162
    unsigned long long owner;           /* Thread id which set current job */
163
    const char *ownerAPI;               /* The API which owns the job */
J
Jiri Denemark 已提交
164
    unsigned long long started;         /* When the current job started */
165

166
    virCond asyncCond;                  /* Use to coordinate with async jobs */
167
    qemuDomainAsyncJob asyncJob;        /* Currently active async job */
168
    unsigned long long asyncOwner;      /* Thread which set current async job */
169
    const char *asyncOwnerAPI;          /* The API which owns the async job */
J
Jiri Denemark 已提交
170
    unsigned long long asyncStarted;    /* When the current async job started */
J
Jiri Denemark 已提交
171
    int phase;                          /* Job phase (mainly for migrations) */
172
    unsigned long long mask;            /* Jobs allowed during async job */
J
Jiri Denemark 已提交
173
    qemuDomainJobInfoPtr current;       /* async job progress data */
174
    qemuDomainJobInfoPtr completed;     /* statistics data of a recently completed job */
175
    bool abortJob;                      /* abort of the job requested */
176 177
    bool spiceMigration;                /* we asked for spice migration and we
                                         * should wait for it to finish */
178
    bool spiceMigrated;                 /* spice migration completed */
179 180
    char *error;                        /* job event completion error */
    bool dumpCompleted;                 /* dump completed */
181 182

    qemuMigrationParamsPtr migParams;
183
    unsigned long apiFlags; /* flags passed to the API which started the async job */
184 185
};

186
typedef void (*qemuDomainCleanupCallback)(virQEMUDriverPtr driver,
187 188
                                          virDomainObjPtr vm);

J
John Ferlan 已提交
189
# define QEMU_DOMAIN_MASTER_KEY_LEN 32  /* 32 bytes for 256 bit random key */
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205


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

206 207 208 209 210 211 212 213 214 215

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

bool qemuDomainNamespaceEnabled(virDomainObjPtr vm,
                                qemuDomainNamespace ns);

216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
/* 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;
};

253 254 255
typedef struct _qemuDomainObjPrivate qemuDomainObjPrivate;
typedef qemuDomainObjPrivate *qemuDomainObjPrivatePtr;
struct _qemuDomainObjPrivate {
256 257
    virQEMUDriverPtr driver;

258
    qemuDomainJobObj job;
259

260 261
    virBitmapPtr namespaces;

262
    qemuMonitorPtr mon;
263
    virDomainChrSourceDefPtr monConfig;
E
Eric Blake 已提交
264
    bool monJSON;
265 266
    bool monError;
    unsigned long long monStart;
D
Daniel P. Berrange 已提交
267 268 269 270

    qemuAgentPtr agent;
    bool agentError;

271
    bool gotShutdown;
272
    bool beingDestroyed;
273
    char *pidfile;
274

275
    virDomainPCIAddressSetPtr pciaddrs;
J
Ján Tomko 已提交
276
    virDomainUSBAddressSetPtr usbaddrs;
277

278
    virQEMUCapsPtr qemuCaps;
279
    char *lockState;
280 281

    bool fakeReboot;
282
    virTristateBool allowReboot;
283 284

    int jobs_queued;
285 286

    unsigned long migMaxBandwidth;
J
Jiri Denemark 已提交
287
    char *origname;
288
    int nbdPort; /* Port used for migration with NBD */
289
    unsigned short migrationPort;
290
    int preMigrationState;
291

292
    virChrdevsPtr devs;
293 294 295 296

    qemuDomainCleanupCallback *cleanupCallbacks;
    size_t ncleanupCallbacks;
    size_t ncleanupCallbacks_max;
297 298

    virCgroupPtr cgroup;
299

300 301
    virPerfPtr perf;

302 303
    qemuDomainUnpluggingDevice unplug;

304
    char **qemuDevices; /* NULL-terminated list of devices aliases known to QEMU */
305 306

    bool hookRun;  /* true if there was a hook run over this domain */
307 308

    /* Bitmaps below hold data from the auto NUMA feature */
309
    virBitmapPtr autoNodeset;
310
    virBitmapPtr autoCpuset;
311 312 313

    bool signalIOError; /* true if the domain condition should be signalled on
                           I/O error */
314 315
    bool signalStop; /* true if the domain condition should be signalled on
                        QMP STOP event */
316
    char *machineName;
317 318
    char *libDir;            /* base path for per-domain files */
    char *channelTargetDir;  /* base path for per-domain channel targets */
J
John Ferlan 已提交
319 320 321 322 323

    /* 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;
324 325 326

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

328 329 330
    /* for migrations using TLS with a secret (not to be saved in our */
    /* private XML). */
    qemuDomainSecretInfoPtr migSecinfo;
331

332 333 334
    /* CPU def used to start the domain when it differs from the one actually
     * provided by QEMU. */
    virCPUDefPtr origCPU;
335 336 337

    /* If true virtlogd is used as stdio handler for character devices. */
    bool chardevStdioLogd;
338 339 340

    /* Tracks blockjob state for vm. Valid only while reconnecting to qemu. */
    virTristateBool reconnectBlockjobs;
341 342 343 344

    /* Migration capabilities. Rechecked on reconnect, not to be saved in
     * private XML. */
    virBitmapPtr migrationCaps;
345 346 347

    /* true if qemu-pr-helper process is running for the domain */
    bool prDaemonRunning;
348 349
};

350
# define QEMU_DOMAIN_PRIVATE(vm) \
351
    ((qemuDomainObjPrivatePtr) (vm)->privateData)
352

353
# define QEMU_DOMAIN_DISK_PRIVATE(disk) \
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
    ((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 */
369
    char *blockJobError; /* block job completed event error */
370
    bool blockJobSync; /* the block job needs synchronized termination */
371 372

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

374 375 376
    /* information about the device */
    bool tray; /* device has tray */
    bool removable; /* device media can be removed/changed */
377 378
};

379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
# 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);

396 397 398 399 400
typedef struct _qemuDomainVcpuPrivate qemuDomainVcpuPrivate;
typedef qemuDomainVcpuPrivate *qemuDomainVcpuPrivatePtr;
struct _qemuDomainVcpuPrivate {
    virObject parent;

401
    pid_t tid; /* vcpu thread id */
402
    int enable_id; /* order in which the vcpus were enabled in qemu */
403
    int qemu_id; /* ID reported by qemu as 'CPU' in query-cpus */
404
    char *alias;
405
    virTristateBool halted;
406 407 408 409 410 411

    /* information for hotpluggable cpus */
    char *type;
    int socket_id;
    int core_id;
    int thread_id;
412
    int node_id;
413
    int vcpus;
414 415
};

416
# define QEMU_DOMAIN_VCPU_PRIVATE(vcpu) \
417 418 419
    ((qemuDomainVcpuPrivatePtr) (vcpu)->privateData)


420 421 422
struct qemuDomainDiskInfo {
    bool removable;
    bool locked;
423
    bool tray;
424
    bool tray_open;
425
    bool empty;
426
    int io_status;
427
    char *nodename;
428 429
};

430
# define QEMU_DOMAIN_CHR_SOURCE_PRIVATE(dev) \
431
    ((qemuDomainChrSourcePrivatePtr) (dev)->privateData)
432

433 434 435
typedef struct _qemuDomainChrSourcePrivate qemuDomainChrSourcePrivate;
typedef qemuDomainChrSourcePrivate *qemuDomainChrSourcePrivatePtr;
struct _qemuDomainChrSourcePrivate {
436 437 438 439 440 441 442 443
    virObject parent;

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


C
Chen Fan 已提交
444 445
typedef enum {
    QEMU_PROCESS_EVENT_WATCHDOG = 0,
446
    QEMU_PROCESS_EVENT_GUESTPANIC,
447
    QEMU_PROCESS_EVENT_DEVICE_DELETED,
448
    QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED,
449
    QEMU_PROCESS_EVENT_SERIAL_CHANGED,
450
    QEMU_PROCESS_EVENT_BLOCK_JOB,
451
    QEMU_PROCESS_EVENT_MONITOR_EOF,
C
Chen Fan 已提交
452 453 454 455 456

    QEMU_PROCESS_EVENT_LAST
} qemuProcessEventType;

struct qemuProcessEvent {
457
    virDomainObjPtr vm;
C
Chen Fan 已提交
458
    qemuProcessEventType eventType;
459
    int action;
460
    int status;
461
    void *data;
462 463
};

464 465
void qemuProcessEventFree(struct qemuProcessEvent *event);

466 467 468
typedef struct _qemuDomainLogContext qemuDomainLogContext;
typedef qemuDomainLogContext *qemuDomainLogContextPtr;

469 470 471 472
typedef struct _qemuDomainSaveCookie qemuDomainSaveCookie;
typedef qemuDomainSaveCookie *qemuDomainSaveCookiePtr;
struct _qemuDomainSaveCookie {
    virObject parent;
473 474

    virCPUDefPtr cpu;
475 476 477 478
};

qemuDomainSaveCookiePtr qemuDomainSaveCookieNew(virDomainObjPtr vm);

479
const char *qemuDomainAsyncJobPhaseToString(qemuDomainAsyncJob job,
J
Jiri Denemark 已提交
480
                                            int phase);
481
int qemuDomainAsyncJobPhaseFromString(qemuDomainAsyncJob job,
J
Jiri Denemark 已提交
482 483
                                      const char *phase);

484
void qemuDomainEventFlush(int timer, void *opaque);
485

486
void qemuDomainEventQueue(virQEMUDriverPtr driver,
487
                          virObjectEventPtr event);
488 489
void qemuDomainEventEmitJobCompleted(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm);
490

491
int qemuDomainObjBeginJob(virQEMUDriverPtr driver,
492
                          virDomainObjPtr obj,
493
                          qemuDomainJob job)
494
    ATTRIBUTE_RETURN_CHECK;
495
int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver,
496
                               virDomainObjPtr obj,
497
                               qemuDomainAsyncJob asyncJob,
498 499
                               virDomainJobOperation operation,
                               unsigned long apiFlags)
500
    ATTRIBUTE_RETURN_CHECK;
501 502 503 504
int qemuDomainObjBeginNestedJob(virQEMUDriverPtr driver,
                                virDomainObjPtr obj,
                                qemuDomainAsyncJob asyncJob)
    ATTRIBUTE_RETURN_CHECK;
505

506 507 508 509
void qemuDomainObjEndJob(virQEMUDriverPtr driver,
                         virDomainObjPtr obj);
void qemuDomainObjEndAsyncJob(virQEMUDriverPtr driver,
                              virDomainObjPtr obj);
510
void qemuDomainObjAbortAsyncJob(virDomainObjPtr obj);
511
void qemuDomainObjSetJobPhase(virQEMUDriverPtr driver,
J
Jiri Denemark 已提交
512 513
                              virDomainObjPtr obj,
                              int phase);
514 515
void qemuDomainObjSetAsyncJobMask(virDomainObjPtr obj,
                                  unsigned long long allowedJobs);
516
void qemuDomainObjRestoreJob(virDomainObjPtr obj,
517
                             qemuDomainJobObjPtr job);
518
void qemuDomainObjDiscardAsyncJob(virQEMUDriverPtr driver,
519
                                  virDomainObjPtr obj);
520
void qemuDomainObjReleaseAsyncJob(virDomainObjPtr obj);
521

522 523
qemuMonitorPtr qemuDomainGetMonitor(virDomainObjPtr vm)
    ATTRIBUTE_NONNULL(1);
524
void qemuDomainObjEnterMonitor(virQEMUDriverPtr driver,
525 526
                               virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
527 528
int qemuDomainObjExitMonitor(virQEMUDriverPtr driver,
                             virDomainObjPtr obj)
529 530
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
    ATTRIBUTE_RETURN_CHECK;
531
int qemuDomainObjEnterMonitorAsync(virQEMUDriverPtr driver,
532
                                   virDomainObjPtr obj,
533
                                   qemuDomainAsyncJob asyncJob)
534
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
D
Daniel P. Berrange 已提交
535 536


537
qemuAgentPtr qemuDomainObjEnterAgent(virDomainObjPtr obj)
538
    ATTRIBUTE_NONNULL(1);
539 540
void qemuDomainObjExitAgent(virDomainObjPtr obj, qemuAgentPtr agent)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
D
Daniel P. Berrange 已提交
541 542


543 544 545 546
void qemuDomainObjEnterRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
void qemuDomainObjExitRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
547

548 549 550 551
virDomainDefPtr qemuDomainDefCopy(virQEMUDriverPtr driver,
                                  virDomainDefPtr src,
                                  unsigned int flags);

552
int qemuDomainDefFormatBuf(virQEMUDriverPtr driver,
553 554 555 556
                           virDomainDefPtr vm,
                           unsigned int flags,
                           virBuffer *buf);

557
char *qemuDomainDefFormatXML(virQEMUDriverPtr driver,
558
                             virDomainDefPtr vm,
559
                             unsigned int flags);
560

561
char *qemuDomainFormatXML(virQEMUDriverPtr driver,
562
                          virDomainObjPtr vm,
563
                          unsigned int flags);
564

565
char *qemuDomainDefFormatLive(virQEMUDriverPtr driver,
566
                              virDomainDefPtr def,
567
                              virCPUDefPtr origCPU,
568 569
                              bool inactive,
                              bool compatible);
570

571
void qemuDomainObjTaint(virQEMUDriverPtr driver,
572
                        virDomainObjPtr obj,
573
                        virDomainTaintFlags taint,
574
                        qemuDomainLogContextPtr logCtxt);
575

576
void qemuDomainObjCheckTaint(virQEMUDriverPtr driver,
577
                             virDomainObjPtr obj,
578
                             qemuDomainLogContextPtr logCtxt);
579
void qemuDomainObjCheckDiskTaint(virQEMUDriverPtr driver,
580
                                 virDomainObjPtr obj,
581
                                 virDomainDiskDefPtr disk,
582
                                 qemuDomainLogContextPtr logCtxt);
583 584 585
void qemuDomainObjCheckHostdevTaint(virQEMUDriverPtr driver,
                                    virDomainObjPtr obj,
                                    virDomainHostdevDefPtr disk,
586
                                    qemuDomainLogContextPtr logCtxt);
587
void qemuDomainObjCheckNetTaint(virQEMUDriverPtr driver,
588
                                virDomainObjPtr obj,
589
                                virDomainNetDefPtr net,
590
                                qemuDomainLogContextPtr logCtxt);
591

592 593 594 595 596 597 598 599 600 601 602 603 604 605 606
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);
607

608 609
virLogManagerPtr qemuDomainLogContextGetManager(qemuDomainLogContextPtr ctxt);

610 611 612 613 614
int qemuDomainLogAppendMessage(virQEMUDriverPtr driver,
                               virDomainObjPtr vm,
                               const char *fmt,
                               ...) ATTRIBUTE_FMT_PRINTF(3, 4);

615
const char *qemuFindQemuImgBinary(virQEMUDriverPtr driver);
616 617 618

int qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
                                    virDomainSnapshotObjPtr snapshot,
619
                                    virCapsPtr caps,
620
                                    virDomainXMLOptionPtr xmlopt,
621 622
                                    char *snapshotDir);

623
int qemuDomainSnapshotForEachQcow2(virQEMUDriverPtr driver,
624 625 626 627 628
                                   virDomainObjPtr vm,
                                   virDomainSnapshotObjPtr snap,
                                   const char *op,
                                   bool try_all);

629
int qemuDomainSnapshotDiscard(virQEMUDriverPtr driver,
630 631 632 633 634
                              virDomainObjPtr vm,
                              virDomainSnapshotObjPtr snap,
                              bool update_current,
                              bool metadata_only);

635 636 637
typedef struct _virQEMUSnapRemove virQEMUSnapRemove;
typedef virQEMUSnapRemove *virQEMUSnapRemovePtr;
struct _virQEMUSnapRemove {
638
    virQEMUDriverPtr driver;
639 640 641 642 643 644
    virDomainObjPtr vm;
    int err;
    bool metadata_only;
    bool current;
};

645 646 647
int qemuDomainSnapshotDiscardAll(void *payload,
                                 const void *name,
                                 void *data);
648

649
int qemuDomainSnapshotDiscardAllMetadata(virQEMUDriverPtr driver,
650 651
                                         virDomainObjPtr vm);

652
void qemuDomainRemoveInactive(virQEMUDriverPtr driver,
653 654
                              virDomainObjPtr vm);

655 656 657
void qemuDomainRemoveInactiveJob(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm);

658
void qemuDomainSetFakeReboot(virQEMUDriverPtr driver,
659 660 661
                             virDomainObjPtr vm,
                             bool value);

662
bool qemuDomainJobAllowed(qemuDomainObjPrivatePtr priv,
663
                          qemuDomainJob job);
M
Michal Privoznik 已提交
664

665 666 667 668 669
int qemuDomainCheckDiskStartupPolicy(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm,
                                     size_t diskIndex,
                                     bool cold_boot);

670
int qemuDomainCheckDiskPresence(virQEMUDriverPtr driver,
M
Michal Privoznik 已提交
671
                                virDomainObjPtr vm,
672
                                unsigned int flags);
673

674
int qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
675
                                 virDomainObjPtr vm,
676
                                 virDomainDiskDefPtr disk,
677 678
                                 bool force_probe,
                                 bool report_broken);
679

680
bool qemuDomainDiskSourceDiffers(virDomainDiskDefPtr disk,
681 682
                                 virDomainDiskDefPtr origDisk);

683 684 685
bool qemuDomainDiskChangeSupported(virDomainDiskDefPtr disk,
                                   virDomainDiskDefPtr orig_disk);

686 687
int qemuDomainStorageFileInit(virQEMUDriverPtr driver,
                              virDomainObjPtr vm,
688 689
                              virStorageSourcePtr src,
                              virStorageSourcePtr parent);
690
char *qemuDomainStorageAlias(const char *device, int depth);
691

692 693 694 695 696 697
void qemuDomainDiskChainElementRevoke(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm,
                                      virStorageSourcePtr elem);
int qemuDomainDiskChainElementPrepare(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm,
                                      virStorageSourcePtr elem,
698 699
                                      bool readonly,
                                      bool newSource);
700

701 702 703 704
int qemuDomainCleanupAdd(virDomainObjPtr vm,
                         qemuDomainCleanupCallback cb);
void qemuDomainCleanupRemove(virDomainObjPtr vm,
                             qemuDomainCleanupCallback cb);
705
void qemuDomainCleanupRun(virQEMUDriverPtr driver,
706 707
                          virDomainObjPtr vm);

708 709
void qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr priv);

710 711
extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks;
extern virDomainXMLNamespace virQEMUDriverDomainXMLNamespace;
712
extern virDomainDefParserConfig virQEMUDriverDomainDefParserConfig;
713
extern virDomainABIStability virQEMUDriverDomainABIStability;
714
extern virSaveCookieCallbacks virQEMUDriverDomainSaveCookie;
715

716
int qemuDomainUpdateDeviceList(virQEMUDriverPtr driver,
717
                               virDomainObjPtr vm, int asyncJob);
718

719 720 721 722
int qemuDomainUpdateMemoryDeviceInfo(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm,
                                     int asyncJob);

723 724 725
bool qemuDomainDefCheckABIStability(virQEMUDriverPtr driver,
                                    virDomainDefPtr src,
                                    virDomainDefPtr dst);
726

727 728 729 730
bool qemuDomainCheckABIStability(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm,
                                 virDomainDefPtr dst);

731
bool qemuDomainAgentAvailable(virDomainObjPtr vm,
732 733
                              bool reportError);

J
Jiri Denemark 已提交
734 735
int qemuDomainJobInfoUpdateTime(qemuDomainJobInfoPtr jobInfo)
    ATTRIBUTE_NONNULL(1);
736 737
int qemuDomainJobInfoUpdateDowntime(qemuDomainJobInfoPtr jobInfo)
    ATTRIBUTE_NONNULL(1);
J
Jiri Denemark 已提交
738 739 740 741 742 743 744 745 746 747
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);

748
int qemuDomainSupportsBlockJobs(virDomainObjPtr vm)
749
    ATTRIBUTE_NONNULL(1);
750
bool qemuDomainDiskBlockJobIsActive(virDomainDiskDefPtr disk);
751 752
bool qemuDomainHasBlockjob(virDomainObjPtr vm, bool copy_only)
    ATTRIBUTE_NONNULL(1);
753

754
int qemuDomainAlignMemorySizes(virDomainDefPtr def);
755 756
void qemuDomainMemoryDeviceAlignSize(virDomainDefPtr def,
                                     virDomainMemoryDefPtr mem);
757

758
virDomainChrDefPtr qemuFindAgentConfig(virDomainDefPtr def);
759

760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778
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);
779

780 781 782
int qemuDomainUpdateCurrentMemorySize(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm);

783
unsigned long long qemuDomainGetMemLockLimitBytes(virDomainDefPtr def);
784
int qemuDomainAdjustMaxMemLock(virDomainObjPtr vm);
785

786 787 788 789
int qemuDomainDefValidateMemoryHotplug(const virDomainDef *def,
                                       virQEMUCapsPtr qemuCaps,
                                       const virDomainMemoryDef *mem);

790
bool qemuDomainSupportsNewVcpuHotplug(virDomainObjPtr vm);
791
bool qemuDomainHasVcpuPids(virDomainObjPtr vm);
792
pid_t qemuDomainGetVcpuPid(virDomainObjPtr vm, unsigned int vcpuid);
793
int qemuDomainValidateVcpuInfo(virDomainObjPtr vm);
794 795
int qemuDomainRefreshVcpuInfo(virQEMUDriverPtr driver,
                              virDomainObjPtr vm,
796 797
                              int asyncJob,
                              bool state);
798 799 800 801
bool qemuDomainGetVcpuHalted(virDomainObjPtr vm, unsigned int vcpu);
int qemuDomainRefreshVcpuHalted(virQEMUDriverPtr driver,
                                virDomainObjPtr vm,
                                int asyncJob);
802

803 804 805
bool qemuDomainSupportsNicdev(virDomainDefPtr def,
                              virDomainNetDefPtr net);

806 807
bool qemuDomainNetSupportsMTU(virDomainNetType type);

808 809 810
int qemuDomainSetPrivatePaths(virQEMUDriverPtr driver,
                              virDomainObjPtr vm);

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

J
John Ferlan 已提交
813 814 815 816
char *qemuDomainGetMasterKeyFilePath(const char *libDir);

int qemuDomainMasterKeyReadFile(qemuDomainObjPrivatePtr priv);

817 818 819 820
int qemuDomainWriteMasterKeyFile(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm);

int qemuDomainMasterKeyCreate(virDomainObjPtr vm);
J
John Ferlan 已提交
821 822 823

void qemuDomainMasterKeyRemove(qemuDomainObjPrivatePtr priv);

824 825 826
void qemuDomainSecretInfoFree(qemuDomainSecretInfoPtr *secinfo)
    ATTRIBUTE_NONNULL(1);

827 828 829
void qemuDomainSecretDiskDestroy(virDomainDiskDefPtr disk)
    ATTRIBUTE_NONNULL(1);

830 831 832
bool qemuDomainSecretDiskCapable(virStorageSourcePtr src)
    ATTRIBUTE_NONNULL(1);

833 834 835
bool qemuDomainDiskHasEncryptionSecret(virStorageSourcePtr src)
    ATTRIBUTE_NONNULL(1);

836
qemuDomainSecretInfoPtr
837
qemuDomainSecretInfoTLSNew(qemuDomainObjPrivatePtr priv,
838 839 840
                           const char *srcAlias,
                           const char *secretUUID);

841 842 843
void qemuDomainSecretHostdevDestroy(virDomainHostdevDefPtr disk)
    ATTRIBUTE_NONNULL(1);

844
int qemuDomainSecretHostdevPrepare(qemuDomainObjPrivatePtr priv,
845
                                   virDomainHostdevDefPtr hostdev)
846
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
847

848 849 850
void qemuDomainSecretChardevDestroy(virDomainChrSourceDefPtr dev)
    ATTRIBUTE_NONNULL(1);

851
int qemuDomainSecretChardevPrepare(virQEMUDriverConfigPtr cfg,
852 853 854 855
                                   qemuDomainObjPrivatePtr priv,
                                   const char *chrAlias,
                                   virDomainChrSourceDefPtr dev)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
856
    ATTRIBUTE_NONNULL(4);
857

858 859 860
void qemuDomainSecretDestroy(virDomainObjPtr vm)
    ATTRIBUTE_NONNULL(1);

861
int qemuDomainSecretPrepare(virQEMUDriverPtr driver,
862
                            virDomainObjPtr vm)
863
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
864

865 866 867
int qemuDomainDefValidateDiskLunSource(const virStorageSource *src)
    ATTRIBUTE_NONNULL(1);

868 869 870
int qemuDomainDeviceDefValidateDisk(const virDomainDiskDef *disk,
                                    virQEMUCapsPtr qemuCaps);

871 872 873 874
int qemuDomainPrepareChannel(virDomainChrDefPtr chr,
                             const char *domainChannelTargetDir)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

875 876 877 878 879
void qemuDomainPrepareChardevSourceTLS(virDomainChrSourceDefPtr source,
                                       virQEMUDriverConfigPtr cfg)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

void qemuDomainPrepareChardevSource(virDomainDefPtr def,
880
                                    virQEMUDriverConfigPtr cfg)
881 882
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

883 884 885
int qemuDomainPrepareShmemChardev(virDomainShmemDefPtr shmem)
    ATTRIBUTE_NONNULL(1);

886 887 888
bool qemuDomainVcpuHotplugIsInOrder(virDomainDefPtr def)
    ATTRIBUTE_NONNULL(1);

889 890 891
void qemuDomainVcpuPersistOrder(virDomainDefPtr def)
    ATTRIBUTE_NONNULL(1);

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

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

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

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

int qemuDomainCreateNamespace(virQEMUDriverPtr driver,
                              virDomainObjPtr vm);

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

916 917
bool qemuDomainNamespaceAvailable(qemuDomainNamespace ns);

918
int qemuDomainNamespaceSetupDisk(virDomainObjPtr vm,
919
                                 virStorageSourcePtr src);
920

921
int qemuDomainNamespaceTeardownDisk(virDomainObjPtr vm,
922
                                    virStorageSourcePtr src);
923

924
int qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm,
925 926
                                    virDomainHostdevDefPtr hostdev);

927
int qemuDomainNamespaceTeardownHostdev(virDomainObjPtr vm,
928
                                       virDomainHostdevDefPtr hostdev);
929

930
int qemuDomainNamespaceSetupMemory(virDomainObjPtr vm,
M
Michal Privoznik 已提交
931 932
                                   virDomainMemoryDefPtr memory);

933
int qemuDomainNamespaceTeardownMemory(virDomainObjPtr vm,
M
Michal Privoznik 已提交
934 935
                                      virDomainMemoryDefPtr memory);

936
int qemuDomainNamespaceSetupChardev(virDomainObjPtr vm,
937 938
                                    virDomainChrDefPtr chr);

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

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

945
int qemuDomainNamespaceTeardownRNG(virDomainObjPtr vm,
946
                                   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
int
992 993 994 995 996
qemuDomainPrepareDiskSourceChain(virDomainDiskDefPtr disk,
                                 virStorageSourcePtr src,
                                 virQEMUDriverConfigPtr cfg,
                                 virQEMUCapsPtr qemuCaps)
    ATTRIBUTE_RETURN_CHECK;
997

998
int
999
qemuDomainPrepareDiskSource(virDomainDiskDefPtr disk,
1000 1001 1002
                            qemuDomainObjPrivatePtr priv,
                            virQEMUDriverConfigPtr cfg);

1003 1004 1005 1006 1007 1008
int
qemuDomainDiskCachemodeFlags(int cachemode,
                             bool *writeback,
                             bool *direct,
                             bool *noflush);

1009
char * qemuDomainGetManagedPRSocketPath(qemuDomainObjPrivatePtr priv);
1010

1011
#endif /* __QEMU_DOMAIN_H__ */