qemu_domain.h 37.6 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
# define QEMU_DOMAIN_HOSTDEV_PRIVATE(hostdev) \
380 381
    ((qemuDomainHostdevPrivatePtr) (hostdev)->privateData)

382 383 384 385 386 387

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

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

    /* information for hotpluggable cpus */
    char *type;
    int socket_id;
    int core_id;
    int thread_id;
399
    int node_id;
400
    int vcpus;
401 402
};

403
# define QEMU_DOMAIN_VCPU_PRIVATE(vcpu) \
404 405 406
    ((qemuDomainVcpuPrivatePtr) (vcpu)->privateData)


407 408 409
struct qemuDomainDiskInfo {
    bool removable;
    bool locked;
410
    bool tray;
411
    bool tray_open;
412
    bool empty;
413
    int io_status;
414
    char *nodename;
415 416
};

417 418 419 420 421 422 423 424 425 426
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;
};

427
# define QEMU_DOMAIN_CHR_SOURCE_PRIVATE(dev) \
428
    ((qemuDomainChrSourcePrivatePtr) (dev)->privateData)
429

430 431 432
typedef struct _qemuDomainChrSourcePrivate qemuDomainChrSourcePrivate;
typedef qemuDomainChrSourcePrivate *qemuDomainChrSourcePrivatePtr;
struct _qemuDomainChrSourcePrivate {
433 434 435 436 437 438 439 440
    virObject parent;

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


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

    QEMU_PROCESS_EVENT_LAST
} qemuProcessEventType;

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

461 462 463
typedef struct _qemuDomainLogContext qemuDomainLogContext;
typedef qemuDomainLogContext *qemuDomainLogContextPtr;

464 465 466 467
typedef struct _qemuDomainSaveCookie qemuDomainSaveCookie;
typedef qemuDomainSaveCookie *qemuDomainSaveCookiePtr;
struct _qemuDomainSaveCookie {
    virObject parent;
468 469

    virCPUDefPtr cpu;
470 471 472 473
};

qemuDomainSaveCookiePtr qemuDomainSaveCookieNew(virDomainObjPtr vm);

474
const char *qemuDomainAsyncJobPhaseToString(qemuDomainAsyncJob job,
J
Jiri Denemark 已提交
475
                                            int phase);
476
int qemuDomainAsyncJobPhaseFromString(qemuDomainAsyncJob job,
J
Jiri Denemark 已提交
477 478
                                      const char *phase);

479
void qemuDomainEventFlush(int timer, void *opaque);
480

481
void qemuDomainEventQueue(virQEMUDriverPtr driver,
482
                          virObjectEventPtr event);
483 484
void qemuDomainEventEmitJobCompleted(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm);
485

486
int qemuDomainObjBeginJob(virQEMUDriverPtr driver,
487
                          virDomainObjPtr obj,
488
                          qemuDomainJob job)
489
    ATTRIBUTE_RETURN_CHECK;
490
int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver,
491
                               virDomainObjPtr obj,
492 493
                               qemuDomainAsyncJob asyncJob,
                               virDomainJobOperation operation)
494
    ATTRIBUTE_RETURN_CHECK;
495 496 497 498
int qemuDomainObjBeginNestedJob(virQEMUDriverPtr driver,
                                virDomainObjPtr obj,
                                qemuDomainAsyncJob asyncJob)
    ATTRIBUTE_RETURN_CHECK;
499

500 501 502 503
void qemuDomainObjEndJob(virQEMUDriverPtr driver,
                         virDomainObjPtr obj);
void qemuDomainObjEndAsyncJob(virQEMUDriverPtr driver,
                              virDomainObjPtr obj);
504
void qemuDomainObjAbortAsyncJob(virDomainObjPtr obj);
505
void qemuDomainObjSetJobPhase(virQEMUDriverPtr driver,
J
Jiri Denemark 已提交
506 507
                              virDomainObjPtr obj,
                              int phase);
508 509
void qemuDomainObjSetAsyncJobMask(virDomainObjPtr obj,
                                  unsigned long long allowedJobs);
510 511
void qemuDomainObjRestoreJob(virDomainObjPtr obj,
                             struct qemuDomainJobObj *job);
512
void qemuDomainObjDiscardAsyncJob(virQEMUDriverPtr driver,
513
                                  virDomainObjPtr obj);
514
void qemuDomainObjReleaseAsyncJob(virDomainObjPtr obj);
515

516 517
qemuMonitorPtr qemuDomainGetMonitor(virDomainObjPtr vm)
    ATTRIBUTE_NONNULL(1);
518
void qemuDomainObjEnterMonitor(virQEMUDriverPtr driver,
519 520
                               virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
521 522
int qemuDomainObjExitMonitor(virQEMUDriverPtr driver,
                             virDomainObjPtr obj)
523 524
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
    ATTRIBUTE_RETURN_CHECK;
525
int qemuDomainObjEnterMonitorAsync(virQEMUDriverPtr driver,
526
                                   virDomainObjPtr obj,
527
                                   qemuDomainAsyncJob asyncJob)
528
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
D
Daniel P. Berrange 已提交
529 530


531
qemuAgentPtr qemuDomainObjEnterAgent(virDomainObjPtr obj)
532
    ATTRIBUTE_NONNULL(1);
533 534
void qemuDomainObjExitAgent(virDomainObjPtr obj, qemuAgentPtr agent)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
D
Daniel P. Berrange 已提交
535 536


537 538 539 540
void qemuDomainObjEnterRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
void qemuDomainObjExitRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
541

542 543 544 545
virDomainDefPtr qemuDomainDefCopy(virQEMUDriverPtr driver,
                                  virDomainDefPtr src,
                                  unsigned int flags);

546
int qemuDomainDefFormatBuf(virQEMUDriverPtr driver,
547 548 549 550
                           virDomainDefPtr vm,
                           unsigned int flags,
                           virBuffer *buf);

551
char *qemuDomainDefFormatXML(virQEMUDriverPtr driver,
552
                             virDomainDefPtr vm,
553
                             unsigned int flags);
554

555
char *qemuDomainFormatXML(virQEMUDriverPtr driver,
556
                          virDomainObjPtr vm,
557
                          unsigned int flags);
558

559
char *qemuDomainDefFormatLive(virQEMUDriverPtr driver,
560
                              virDomainDefPtr def,
561
                              virCPUDefPtr origCPU,
562 563
                              bool inactive,
                              bool compatible);
564

565
void qemuDomainObjTaint(virQEMUDriverPtr driver,
566
                        virDomainObjPtr obj,
567
                        virDomainTaintFlags taint,
568
                        qemuDomainLogContextPtr logCtxt);
569

570
void qemuDomainObjCheckTaint(virQEMUDriverPtr driver,
571
                             virDomainObjPtr obj,
572
                             qemuDomainLogContextPtr logCtxt);
573
void qemuDomainObjCheckDiskTaint(virQEMUDriverPtr driver,
574
                                 virDomainObjPtr obj,
575
                                 virDomainDiskDefPtr disk,
576
                                 qemuDomainLogContextPtr logCtxt);
577 578 579
void qemuDomainObjCheckHostdevTaint(virQEMUDriverPtr driver,
                                    virDomainObjPtr obj,
                                    virDomainHostdevDefPtr disk,
580
                                    qemuDomainLogContextPtr logCtxt);
581
void qemuDomainObjCheckNetTaint(virQEMUDriverPtr driver,
582
                                virDomainObjPtr obj,
583
                                virDomainNetDefPtr net,
584
                                qemuDomainLogContextPtr logCtxt);
585

586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
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);
601

602 603
virLogManagerPtr qemuDomainLogContextGetManager(qemuDomainLogContextPtr ctxt);

604 605 606 607 608
int qemuDomainLogAppendMessage(virQEMUDriverPtr driver,
                               virDomainObjPtr vm,
                               const char *fmt,
                               ...) ATTRIBUTE_FMT_PRINTF(3, 4);

609
const char *qemuFindQemuImgBinary(virQEMUDriverPtr driver);
610 611 612

int qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
                                    virDomainSnapshotObjPtr snapshot,
613
                                    virCapsPtr caps,
614
                                    virDomainXMLOptionPtr xmlopt,
615 616
                                    char *snapshotDir);

617
int qemuDomainSnapshotForEachQcow2(virQEMUDriverPtr driver,
618 619 620 621 622
                                   virDomainObjPtr vm,
                                   virDomainSnapshotObjPtr snap,
                                   const char *op,
                                   bool try_all);

623
int qemuDomainSnapshotDiscard(virQEMUDriverPtr driver,
624 625 626 627 628
                              virDomainObjPtr vm,
                              virDomainSnapshotObjPtr snap,
                              bool update_current,
                              bool metadata_only);

629 630 631
typedef struct _virQEMUSnapRemove virQEMUSnapRemove;
typedef virQEMUSnapRemove *virQEMUSnapRemovePtr;
struct _virQEMUSnapRemove {
632
    virQEMUDriverPtr driver;
633 634 635 636 637 638
    virDomainObjPtr vm;
    int err;
    bool metadata_only;
    bool current;
};

639 640 641
int qemuDomainSnapshotDiscardAll(void *payload,
                                 const void *name,
                                 void *data);
642

643
int qemuDomainSnapshotDiscardAllMetadata(virQEMUDriverPtr driver,
644 645
                                         virDomainObjPtr vm);

646
void qemuDomainRemoveInactive(virQEMUDriverPtr driver,
647 648
                              virDomainObjPtr vm);

649 650 651
void qemuDomainRemoveInactiveJob(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm);

652
void qemuDomainSetFakeReboot(virQEMUDriverPtr driver,
653 654 655
                             virDomainObjPtr vm,
                             bool value);

656
bool qemuDomainJobAllowed(qemuDomainObjPrivatePtr priv,
657
                          qemuDomainJob job);
M
Michal Privoznik 已提交
658

659 660 661 662 663
int qemuDomainCheckDiskStartupPolicy(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm,
                                     size_t diskIndex,
                                     bool cold_boot);

664
int qemuDomainCheckDiskPresence(virQEMUDriverPtr driver,
M
Michal Privoznik 已提交
665
                                virDomainObjPtr vm,
666
                                unsigned int flags);
667

668
int qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
669
                                 virDomainObjPtr vm,
670
                                 virDomainDiskDefPtr disk,
671 672
                                 bool force_probe,
                                 bool report_broken);
673

674
bool qemuDomainDiskSourceDiffers(virDomainDiskDefPtr disk,
675 676
                                 virDomainDiskDefPtr origDisk);

677 678 679
bool qemuDomainDiskChangeSupported(virDomainDiskDefPtr disk,
                                   virDomainDiskDefPtr orig_disk);

680 681
int qemuDomainStorageFileInit(virQEMUDriverPtr driver,
                              virDomainObjPtr vm,
682 683
                              virStorageSourcePtr src,
                              virStorageSourcePtr parent);
684
char *qemuDomainStorageAlias(const char *device, int depth);
685

686 687 688 689 690 691
void qemuDomainDiskChainElementRevoke(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm,
                                      virStorageSourcePtr elem);
int qemuDomainDiskChainElementPrepare(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm,
                                      virStorageSourcePtr elem,
692 693
                                      bool readonly,
                                      bool newSource);
694

695 696 697 698
int qemuDomainCleanupAdd(virDomainObjPtr vm,
                         qemuDomainCleanupCallback cb);
void qemuDomainCleanupRemove(virDomainObjPtr vm,
                             qemuDomainCleanupCallback cb);
699
void qemuDomainCleanupRun(virQEMUDriverPtr driver,
700 701
                          virDomainObjPtr vm);

702 703
void qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr priv);

704 705
extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks;
extern virDomainXMLNamespace virQEMUDriverDomainXMLNamespace;
706
extern virDomainDefParserConfig virQEMUDriverDomainDefParserConfig;
707
extern virDomainABIStability virQEMUDriverDomainABIStability;
708
extern virSaveCookieCallbacks virQEMUDriverDomainSaveCookie;
709

710
int qemuDomainUpdateDeviceList(virQEMUDriverPtr driver,
711
                               virDomainObjPtr vm, int asyncJob);
712

713 714 715 716
int qemuDomainUpdateMemoryDeviceInfo(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm,
                                     int asyncJob);

717 718 719
bool qemuDomainDefCheckABIStability(virQEMUDriverPtr driver,
                                    virDomainDefPtr src,
                                    virDomainDefPtr dst);
720

721 722 723 724
bool qemuDomainCheckABIStability(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm,
                                 virDomainDefPtr dst);

725
bool qemuDomainAgentAvailable(virDomainObjPtr vm,
726 727
                              bool reportError);

J
Jiri Denemark 已提交
728 729
int qemuDomainJobInfoUpdateTime(qemuDomainJobInfoPtr jobInfo)
    ATTRIBUTE_NONNULL(1);
730 731
int qemuDomainJobInfoUpdateDowntime(qemuDomainJobInfoPtr jobInfo)
    ATTRIBUTE_NONNULL(1);
J
Jiri Denemark 已提交
732 733 734 735 736 737 738 739 740 741
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);

742
int qemuDomainSupportsBlockJobs(virDomainObjPtr vm)
743
    ATTRIBUTE_NONNULL(1);
744
bool qemuDomainDiskBlockJobIsActive(virDomainDiskDefPtr disk);
745 746
bool qemuDomainHasBlockjob(virDomainObjPtr vm, bool copy_only)
    ATTRIBUTE_NONNULL(1);
747

748
int qemuDomainAlignMemorySizes(virDomainDefPtr def);
749 750
void qemuDomainMemoryDeviceAlignSize(virDomainDefPtr def,
                                     virDomainMemoryDefPtr mem);
751

752
virDomainChrDefPtr qemuFindAgentConfig(virDomainDefPtr def);
753

754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772
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);
773

774 775 776
int qemuDomainUpdateCurrentMemorySize(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm);

777
unsigned long long qemuDomainGetMemLockLimitBytes(virDomainDefPtr def);
778
int qemuDomainAdjustMaxMemLock(virDomainObjPtr vm);
779

780 781 782 783
int qemuDomainDefValidateMemoryHotplug(const virDomainDef *def,
                                       virQEMUCapsPtr qemuCaps,
                                       const virDomainMemoryDef *mem);

784
bool qemuDomainSupportsNewVcpuHotplug(virDomainObjPtr vm);
785
bool qemuDomainHasVcpuPids(virDomainObjPtr vm);
786
pid_t qemuDomainGetVcpuPid(virDomainObjPtr vm, unsigned int vcpuid);
787
int qemuDomainValidateVcpuInfo(virDomainObjPtr vm);
788 789
int qemuDomainRefreshVcpuInfo(virQEMUDriverPtr driver,
                              virDomainObjPtr vm,
790 791
                              int asyncJob,
                              bool state);
792 793 794 795
bool qemuDomainGetVcpuHalted(virDomainObjPtr vm, unsigned int vcpu);
int qemuDomainRefreshVcpuHalted(virQEMUDriverPtr driver,
                                virDomainObjPtr vm,
                                int asyncJob);
796

797 798 799 800 801 802 803
bool qemuDomainSupportsNicdev(virDomainDefPtr def,
                              virDomainNetDefPtr net);

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

804 805
bool qemuDomainNetSupportsMTU(virDomainNetType type);

J
John Ferlan 已提交
806
int qemuDomainNetVLAN(virDomainNetDefPtr def);
807

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 837 838 839 840 841
qemuDomainSecretInfoPtr
qemuDomainSecretInfoTLSNew(virConnectPtr conn,
                           qemuDomainObjPrivatePtr priv,
                           const char *srcAlias,
                           const char *secretUUID);

842 843 844 845
void qemuDomainSecretHostdevDestroy(virDomainHostdevDefPtr disk)
    ATTRIBUTE_NONNULL(1);

int qemuDomainSecretHostdevPrepare(virConnectPtr conn,
J
John Ferlan 已提交
846
                                   qemuDomainObjPrivatePtr priv,
847
                                   virDomainHostdevDefPtr hostdev)
J
John Ferlan 已提交
848
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
849

850 851 852 853 854 855 856 857 858 859 860
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);

861 862 863
void qemuDomainSecretDestroy(virDomainObjPtr vm)
    ATTRIBUTE_NONNULL(1);

864 865 866 867
int qemuDomainSecretPrepare(virConnectPtr conn,
                            virQEMUDriverPtr driver,
                            virDomainObjPtr vm)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
868

869 870 871
int qemuDomainDefValidateDiskLunSource(const virStorageSource *src)
    ATTRIBUTE_NONNULL(1);

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

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

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

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

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

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

L
Lin Ma 已提交
893 894 895
int qemuDomainDefValidateDisk(const virDomainDiskDef *disk,
                              virQEMUCapsPtr qemuCaps);

896 897 898 899
int qemuDomainCheckMonitor(virQEMUDriverPtr driver,
                           virDomainObjPtr vm,
                           qemuDomainAsyncJob asyncJob);

900 901 902
bool qemuDomainSupportsVideoVga(virDomainVideoDefPtr video,
                                virQEMUCapsPtr qemuCaps);

903 904 905
int qemuDomainGetHostdevPath(virDomainDefPtr def,
                             virDomainHostdevDefPtr dev,
                             bool teardown,
906 907 908
                             size_t *npaths,
                             char ***path,
                             int **perms);
909

910 911
int qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg,
                             virSecurityManagerPtr mgr,
912 913 914 915 916
                             virDomainObjPtr vm);

int qemuDomainCreateNamespace(virQEMUDriverPtr driver,
                              virDomainObjPtr vm);

917 918 919
void qemuDomainDestroyNamespace(virQEMUDriverPtr driver,
                                virDomainObjPtr vm);

920 921
bool qemuDomainNamespaceAvailable(qemuDomainNamespace ns);

922 923
int qemuDomainNamespaceSetupDisk(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm,
924
                                 virStorageSourcePtr src);
925 926 927

int qemuDomainNamespaceTeardownDisk(virQEMUDriverPtr driver,
                                    virDomainObjPtr vm,
928
                                    virStorageSourcePtr src);
929 930 931 932 933 934 935 936

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

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

M
Michal Privoznik 已提交
938 939 940 941 942 943 944 945
int qemuDomainNamespaceSetupMemory(virQEMUDriverPtr driver,
                                   virDomainObjPtr vm,
                                   virDomainMemoryDefPtr memory);

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

946 947 948 949 950 951 952
int qemuDomainNamespaceSetupChardev(virQEMUDriverPtr driver,
                                    virDomainObjPtr vm,
                                    virDomainChrDefPtr chr);

int qemuDomainNamespaceTeardownChardev(virQEMUDriverPtr driver,
                                       virDomainObjPtr vm,
                                       virDomainChrDefPtr chr);
953 954

int qemuDomainNamespaceSetupRNG(virQEMUDriverPtr driver,
955 956
                                virDomainObjPtr vm,
                                virDomainRNGDefPtr rng);
957 958

int qemuDomainNamespaceTeardownRNG(virQEMUDriverPtr driver,
959 960
                                   virDomainObjPtr vm,
                                   virDomainRNGDefPtr rng);
961 962 963 964 965 966

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

967 968 969 970
char *qemuDomainDiskBackingStoreGetName(virDomainDiskDefPtr disk,
                                        virStorageSourcePtr src,
                                        unsigned int idx);

971 972 973
virStorageSourcePtr qemuDomainGetStorageSourceByDevstr(const char *devstr,
                                                       virDomainDefPtr def);

974 975 976 977 978
int
qemuDomainUpdateCPU(virDomainObjPtr vm,
                    virCPUDefPtr cpu,
                    virCPUDefPtr *origCPU);

979 980 981 982
int
qemuDomainFixupCPUs(virDomainObjPtr vm,
                    virCPUDefPtr *origCPU);

983 984 985
char *
qemuDomainGetMachineName(virDomainObjPtr vm);

986 987 988 989 990 991 992 993
void
qemuDomainObjPrivateXMLFormatAllowReboot(virBufferPtr buf,
                                         virTristateBool allowReboot);

int
qemuDomainObjPrivateXMLParseAllowReboot(xmlXPathContextPtr ctxt,
                                        virTristateBool *allowReboot);

994 995 996 997 998
bool qemuDomainCheckCCWS390AddressSupport(const virDomainDef *def,
                                    virDomainDeviceInfo info,
                                    virQEMUCapsPtr qemuCaps,
                                    const char *devicename);

999 1000 1001 1002 1003
int
qemuDomainCheckMigrationCapabilities(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm,
                                     qemuDomainAsyncJob asyncJob);

1004 1005 1006 1007 1008 1009
int
qemuDomainPrepareDiskSource(virConnectPtr conn,
                            virDomainDiskDefPtr disk,
                            qemuDomainObjPrivatePtr priv,
                            virQEMUDriverConfigPtr cfg);

1010
#endif /* __QEMU_DOMAIN_H__ */