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 "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
    virStorageSourcePtr migrSource; /* disk source object used for NBD migration */
374

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

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

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

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

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

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


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

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

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

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


J
Ján Tomko 已提交
445 446 447 448 449
typedef struct _qemuDomainVsockPrivate qemuDomainVsockPrivate;
typedef qemuDomainVsockPrivate *qemuDomainVsockPrivatePtr;
struct _qemuDomainVsockPrivate {
    virObject parent;

450
    int vhostfd;
J
Ján Tomko 已提交
451 452 453
};


C
Chen Fan 已提交
454 455
typedef enum {
    QEMU_PROCESS_EVENT_WATCHDOG = 0,
456
    QEMU_PROCESS_EVENT_GUESTPANIC,
457
    QEMU_PROCESS_EVENT_DEVICE_DELETED,
458
    QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED,
459
    QEMU_PROCESS_EVENT_SERIAL_CHANGED,
460
    QEMU_PROCESS_EVENT_BLOCK_JOB,
461
    QEMU_PROCESS_EVENT_MONITOR_EOF,
C
Chen Fan 已提交
462 463 464 465 466

    QEMU_PROCESS_EVENT_LAST
} qemuProcessEventType;

struct qemuProcessEvent {
467
    virDomainObjPtr vm;
C
Chen Fan 已提交
468
    qemuProcessEventType eventType;
469
    int action;
470
    int status;
471
    void *data;
472 473
};

474 475
void qemuProcessEventFree(struct qemuProcessEvent *event);

476 477 478
typedef struct _qemuDomainLogContext qemuDomainLogContext;
typedef qemuDomainLogContext *qemuDomainLogContextPtr;

479 480 481 482
typedef struct _qemuDomainSaveCookie qemuDomainSaveCookie;
typedef qemuDomainSaveCookie *qemuDomainSaveCookiePtr;
struct _qemuDomainSaveCookie {
    virObject parent;
483 484

    virCPUDefPtr cpu;
485 486 487 488
};

qemuDomainSaveCookiePtr qemuDomainSaveCookieNew(virDomainObjPtr vm);

489
const char *qemuDomainAsyncJobPhaseToString(qemuDomainAsyncJob job,
J
Jiri Denemark 已提交
490
                                            int phase);
491
int qemuDomainAsyncJobPhaseFromString(qemuDomainAsyncJob job,
J
Jiri Denemark 已提交
492 493
                                      const char *phase);

494
void qemuDomainEventFlush(int timer, void *opaque);
495

496
void qemuDomainEventQueue(virQEMUDriverPtr driver,
497
                          virObjectEventPtr event);
498 499
void qemuDomainEventEmitJobCompleted(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm);
500

501
int qemuDomainObjBeginJob(virQEMUDriverPtr driver,
502
                          virDomainObjPtr obj,
503
                          qemuDomainJob job)
504
    ATTRIBUTE_RETURN_CHECK;
505
int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver,
506
                               virDomainObjPtr obj,
507
                               qemuDomainAsyncJob asyncJob,
508 509
                               virDomainJobOperation operation,
                               unsigned long apiFlags)
510
    ATTRIBUTE_RETURN_CHECK;
511 512 513 514
int qemuDomainObjBeginNestedJob(virQEMUDriverPtr driver,
                                virDomainObjPtr obj,
                                qemuDomainAsyncJob asyncJob)
    ATTRIBUTE_RETURN_CHECK;
515

516 517 518 519
void qemuDomainObjEndJob(virQEMUDriverPtr driver,
                         virDomainObjPtr obj);
void qemuDomainObjEndAsyncJob(virQEMUDriverPtr driver,
                              virDomainObjPtr obj);
520
void qemuDomainObjAbortAsyncJob(virDomainObjPtr obj);
521
void qemuDomainObjSetJobPhase(virQEMUDriverPtr driver,
J
Jiri Denemark 已提交
522 523
                              virDomainObjPtr obj,
                              int phase);
524 525
void qemuDomainObjSetAsyncJobMask(virDomainObjPtr obj,
                                  unsigned long long allowedJobs);
526
void qemuDomainObjRestoreJob(virDomainObjPtr obj,
527
                             qemuDomainJobObjPtr job);
528
void qemuDomainObjDiscardAsyncJob(virQEMUDriverPtr driver,
529
                                  virDomainObjPtr obj);
530
void qemuDomainObjReleaseAsyncJob(virDomainObjPtr obj);
531

532 533
qemuMonitorPtr qemuDomainGetMonitor(virDomainObjPtr vm)
    ATTRIBUTE_NONNULL(1);
534
void qemuDomainObjEnterMonitor(virQEMUDriverPtr driver,
535 536
                               virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
537 538
int qemuDomainObjExitMonitor(virQEMUDriverPtr driver,
                             virDomainObjPtr obj)
539 540
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
    ATTRIBUTE_RETURN_CHECK;
541
int qemuDomainObjEnterMonitorAsync(virQEMUDriverPtr driver,
542
                                   virDomainObjPtr obj,
543
                                   qemuDomainAsyncJob asyncJob)
544
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
D
Daniel P. Berrange 已提交
545 546


547
qemuAgentPtr qemuDomainObjEnterAgent(virDomainObjPtr obj)
548
    ATTRIBUTE_NONNULL(1);
549 550
void qemuDomainObjExitAgent(virDomainObjPtr obj, qemuAgentPtr agent)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
D
Daniel P. Berrange 已提交
551 552


553 554 555 556
void qemuDomainObjEnterRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
void qemuDomainObjExitRemote(virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1);
557

558 559 560 561
virDomainDefPtr qemuDomainDefCopy(virQEMUDriverPtr driver,
                                  virDomainDefPtr src,
                                  unsigned int flags);

562
int qemuDomainDefFormatBuf(virQEMUDriverPtr driver,
563 564 565 566
                           virDomainDefPtr vm,
                           unsigned int flags,
                           virBuffer *buf);

567
char *qemuDomainDefFormatXML(virQEMUDriverPtr driver,
568
                             virDomainDefPtr vm,
569
                             unsigned int flags);
570

571
char *qemuDomainFormatXML(virQEMUDriverPtr driver,
572
                          virDomainObjPtr vm,
573
                          unsigned int flags);
574

575
char *qemuDomainDefFormatLive(virQEMUDriverPtr driver,
576
                              virDomainDefPtr def,
577
                              virCPUDefPtr origCPU,
578 579
                              bool inactive,
                              bool compatible);
580

581
void qemuDomainObjTaint(virQEMUDriverPtr driver,
582
                        virDomainObjPtr obj,
583
                        virDomainTaintFlags taint,
584
                        qemuDomainLogContextPtr logCtxt);
585

586
void qemuDomainObjCheckTaint(virQEMUDriverPtr driver,
587
                             virDomainObjPtr obj,
588
                             qemuDomainLogContextPtr logCtxt);
589
void qemuDomainObjCheckDiskTaint(virQEMUDriverPtr driver,
590
                                 virDomainObjPtr obj,
591
                                 virDomainDiskDefPtr disk,
592
                                 qemuDomainLogContextPtr logCtxt);
593 594 595
void qemuDomainObjCheckHostdevTaint(virQEMUDriverPtr driver,
                                    virDomainObjPtr obj,
                                    virDomainHostdevDefPtr disk,
596
                                    qemuDomainLogContextPtr logCtxt);
597
void qemuDomainObjCheckNetTaint(virQEMUDriverPtr driver,
598
                                virDomainObjPtr obj,
599
                                virDomainNetDefPtr net,
600
                                qemuDomainLogContextPtr logCtxt);
601

602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
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);
617

618 619
virLogManagerPtr qemuDomainLogContextGetManager(qemuDomainLogContextPtr ctxt);

620 621 622 623 624
int qemuDomainLogAppendMessage(virQEMUDriverPtr driver,
                               virDomainObjPtr vm,
                               const char *fmt,
                               ...) ATTRIBUTE_FMT_PRINTF(3, 4);

625
const char *qemuFindQemuImgBinary(virQEMUDriverPtr driver);
626 627 628

int qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
                                    virDomainSnapshotObjPtr snapshot,
629
                                    virCapsPtr caps,
630
                                    virDomainXMLOptionPtr xmlopt,
631 632
                                    char *snapshotDir);

633
int qemuDomainSnapshotForEachQcow2(virQEMUDriverPtr driver,
634 635 636 637 638
                                   virDomainObjPtr vm,
                                   virDomainSnapshotObjPtr snap,
                                   const char *op,
                                   bool try_all);

639
int qemuDomainSnapshotDiscard(virQEMUDriverPtr driver,
640 641 642 643 644
                              virDomainObjPtr vm,
                              virDomainSnapshotObjPtr snap,
                              bool update_current,
                              bool metadata_only);

645 646 647
typedef struct _virQEMUSnapRemove virQEMUSnapRemove;
typedef virQEMUSnapRemove *virQEMUSnapRemovePtr;
struct _virQEMUSnapRemove {
648
    virQEMUDriverPtr driver;
649 650 651 652 653 654
    virDomainObjPtr vm;
    int err;
    bool metadata_only;
    bool current;
};

655 656 657
int qemuDomainSnapshotDiscardAll(void *payload,
                                 const void *name,
                                 void *data);
658

659
int qemuDomainSnapshotDiscardAllMetadata(virQEMUDriverPtr driver,
660 661
                                         virDomainObjPtr vm);

662
void qemuDomainRemoveInactive(virQEMUDriverPtr driver,
663 664
                              virDomainObjPtr vm);

665 666 667
void qemuDomainRemoveInactiveJob(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm);

668
void qemuDomainSetFakeReboot(virQEMUDriverPtr driver,
669 670 671
                             virDomainObjPtr vm,
                             bool value);

672
bool qemuDomainJobAllowed(qemuDomainObjPrivatePtr priv,
673
                          qemuDomainJob job);
M
Michal Privoznik 已提交
674

675 676 677 678 679
int qemuDomainCheckDiskStartupPolicy(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm,
                                     size_t diskIndex,
                                     bool cold_boot);

680
int qemuDomainCheckDiskPresence(virQEMUDriverPtr driver,
M
Michal Privoznik 已提交
681
                                virDomainObjPtr vm,
682
                                unsigned int flags);
683

684
int qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
685
                                 virDomainObjPtr vm,
686
                                 virDomainDiskDefPtr disk,
687 688
                                 bool force_probe,
                                 bool report_broken);
689

690
bool qemuDomainDiskSourceDiffers(virDomainDiskDefPtr disk,
691 692
                                 virDomainDiskDefPtr origDisk);

693 694 695
bool qemuDomainDiskChangeSupported(virDomainDiskDefPtr disk,
                                   virDomainDiskDefPtr orig_disk);

696 697
int qemuDomainStorageFileInit(virQEMUDriverPtr driver,
                              virDomainObjPtr vm,
698 699
                              virStorageSourcePtr src,
                              virStorageSourcePtr parent);
700
char *qemuDomainStorageAlias(const char *device, int depth);
701

702 703 704 705 706 707
void qemuDomainDiskChainElementRevoke(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm,
                                      virStorageSourcePtr elem);
int qemuDomainDiskChainElementPrepare(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm,
                                      virStorageSourcePtr elem,
708 709
                                      bool readonly,
                                      bool newSource);
710

711 712 713 714
int qemuDomainCleanupAdd(virDomainObjPtr vm,
                         qemuDomainCleanupCallback cb);
void qemuDomainCleanupRemove(virDomainObjPtr vm,
                             qemuDomainCleanupCallback cb);
715
void qemuDomainCleanupRun(virQEMUDriverPtr driver,
716 717
                          virDomainObjPtr vm);

718 719
void qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr priv);

720 721
extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks;
extern virDomainXMLNamespace virQEMUDriverDomainXMLNamespace;
722
extern virDomainDefParserConfig virQEMUDriverDomainDefParserConfig;
723
extern virDomainABIStability virQEMUDriverDomainABIStability;
724
extern virSaveCookieCallbacks virQEMUDriverDomainSaveCookie;
725

726
int qemuDomainUpdateDeviceList(virQEMUDriverPtr driver,
727
                               virDomainObjPtr vm, int asyncJob);
728

729 730 731 732
int qemuDomainUpdateMemoryDeviceInfo(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm,
                                     int asyncJob);

733 734 735
bool qemuDomainDefCheckABIStability(virQEMUDriverPtr driver,
                                    virDomainDefPtr src,
                                    virDomainDefPtr dst);
736

737 738 739 740
bool qemuDomainCheckABIStability(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm,
                                 virDomainDefPtr dst);

741
bool qemuDomainAgentAvailable(virDomainObjPtr vm,
742 743
                              bool reportError);

J
Jiri Denemark 已提交
744 745
int qemuDomainJobInfoUpdateTime(qemuDomainJobInfoPtr jobInfo)
    ATTRIBUTE_NONNULL(1);
746 747
int qemuDomainJobInfoUpdateDowntime(qemuDomainJobInfoPtr jobInfo)
    ATTRIBUTE_NONNULL(1);
J
Jiri Denemark 已提交
748 749 750 751 752 753 754 755 756 757
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);

758
int qemuDomainSupportsBlockJobs(virDomainObjPtr vm)
759
    ATTRIBUTE_NONNULL(1);
760
bool qemuDomainDiskBlockJobIsActive(virDomainDiskDefPtr disk);
761 762
bool qemuDomainHasBlockjob(virDomainObjPtr vm, bool copy_only)
    ATTRIBUTE_NONNULL(1);
763

764
int qemuDomainAlignMemorySizes(virDomainDefPtr def);
765 766
void qemuDomainMemoryDeviceAlignSize(virDomainDefPtr def,
                                     virDomainMemoryDefPtr mem);
767

768
virDomainChrDefPtr qemuFindAgentConfig(virDomainDefPtr def);
769

770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788
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);
789

790 791 792
int qemuDomainUpdateCurrentMemorySize(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm);

793
unsigned long long qemuDomainGetMemLockLimitBytes(virDomainDefPtr def);
794
int qemuDomainAdjustMaxMemLock(virDomainObjPtr vm);
795

796 797 798 799
int qemuDomainDefValidateMemoryHotplug(const virDomainDef *def,
                                       virQEMUCapsPtr qemuCaps,
                                       const virDomainMemoryDef *mem);

800
bool qemuDomainSupportsNewVcpuHotplug(virDomainObjPtr vm);
801
bool qemuDomainHasVcpuPids(virDomainObjPtr vm);
802
pid_t qemuDomainGetVcpuPid(virDomainObjPtr vm, unsigned int vcpuid);
803
int qemuDomainValidateVcpuInfo(virDomainObjPtr vm);
804 805
int qemuDomainRefreshVcpuInfo(virQEMUDriverPtr driver,
                              virDomainObjPtr vm,
806 807
                              int asyncJob,
                              bool state);
808 809 810 811
bool qemuDomainGetVcpuHalted(virDomainObjPtr vm, unsigned int vcpu);
int qemuDomainRefreshVcpuHalted(virQEMUDriverPtr driver,
                                virDomainObjPtr vm,
                                int asyncJob);
812

813 814 815
bool qemuDomainSupportsNicdev(virDomainDefPtr def,
                              virDomainNetDefPtr net);

816 817
bool qemuDomainNetSupportsMTU(virDomainNetType type);

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

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

J
John Ferlan 已提交
823 824 825 826
char *qemuDomainGetMasterKeyFilePath(const char *libDir);

int qemuDomainMasterKeyReadFile(qemuDomainObjPrivatePtr priv);

827 828 829 830
int qemuDomainWriteMasterKeyFile(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm);

int qemuDomainMasterKeyCreate(virDomainObjPtr vm);
J
John Ferlan 已提交
831 832 833

void qemuDomainMasterKeyRemove(qemuDomainObjPrivatePtr priv);

834 835
bool qemuDomainSupportsEncryptedSecret(qemuDomainObjPrivatePtr priv);

836 837 838
void qemuDomainSecretInfoFree(qemuDomainSecretInfoPtr *secinfo)
    ATTRIBUTE_NONNULL(1);

839 840 841
void qemuDomainSecretDiskDestroy(virDomainDiskDefPtr disk)
    ATTRIBUTE_NONNULL(1);

842
bool qemuDomainStorageSourceHasAuth(virStorageSourcePtr src)
843 844
    ATTRIBUTE_NONNULL(1);

845 846 847
bool qemuDomainDiskHasEncryptionSecret(virStorageSourcePtr src)
    ATTRIBUTE_NONNULL(1);

848
qemuDomainSecretInfoPtr
849
qemuDomainSecretInfoTLSNew(qemuDomainObjPrivatePtr priv,
850 851 852
                           const char *srcAlias,
                           const char *secretUUID);

853 854 855
void qemuDomainSecretHostdevDestroy(virDomainHostdevDefPtr disk)
    ATTRIBUTE_NONNULL(1);

856
int qemuDomainSecretHostdevPrepare(qemuDomainObjPrivatePtr priv,
857
                                   virDomainHostdevDefPtr hostdev)
858
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
859

860 861 862
void qemuDomainSecretChardevDestroy(virDomainChrSourceDefPtr dev)
    ATTRIBUTE_NONNULL(1);

863
int qemuDomainSecretChardevPrepare(virQEMUDriverConfigPtr cfg,
864 865 866 867
                                   qemuDomainObjPrivatePtr priv,
                                   const char *chrAlias,
                                   virDomainChrSourceDefPtr dev)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
868
    ATTRIBUTE_NONNULL(4);
869

870 871 872
void qemuDomainSecretDestroy(virDomainObjPtr vm)
    ATTRIBUTE_NONNULL(1);

873
int qemuDomainSecretPrepare(virQEMUDriverPtr driver,
874
                            virDomainObjPtr vm)
875
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
876

877 878 879
int qemuDomainDefValidateDiskLunSource(const virStorageSource *src)
    ATTRIBUTE_NONNULL(1);

880 881 882
int qemuDomainDeviceDefValidateDisk(const virDomainDiskDef *disk,
                                    virQEMUCapsPtr qemuCaps);

883 884 885 886
int qemuDomainPrepareChannel(virDomainChrDefPtr chr,
                             const char *domainChannelTargetDir)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

887 888 889 890 891
void qemuDomainPrepareChardevSourceTLS(virDomainChrSourceDefPtr source,
                                       virQEMUDriverConfigPtr cfg)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

void qemuDomainPrepareChardevSource(virDomainDefPtr def,
892
                                    virQEMUDriverConfigPtr cfg)
893 894
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

895 896 897
int qemuDomainPrepareShmemChardev(virDomainShmemDefPtr shmem)
    ATTRIBUTE_NONNULL(1);

898 899 900
bool qemuDomainVcpuHotplugIsInOrder(virDomainDefPtr def)
    ATTRIBUTE_NONNULL(1);

901 902 903
void qemuDomainVcpuPersistOrder(virDomainDefPtr def)
    ATTRIBUTE_NONNULL(1);

904 905 906 907
int qemuDomainCheckMonitor(virQEMUDriverPtr driver,
                           virDomainObjPtr vm,
                           qemuDomainAsyncJob asyncJob);

908 909 910
bool qemuDomainSupportsVideoVga(virDomainVideoDefPtr video,
                                virQEMUCapsPtr qemuCaps);

911 912 913
int qemuDomainGetHostdevPath(virDomainDefPtr def,
                             virDomainHostdevDefPtr dev,
                             bool teardown,
914 915 916
                             size_t *npaths,
                             char ***path,
                             int **perms);
917

918 919
int qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg,
                             virSecurityManagerPtr mgr,
920 921 922 923 924
                             virDomainObjPtr vm);

int qemuDomainCreateNamespace(virQEMUDriverPtr driver,
                              virDomainObjPtr vm);

925 926 927
void qemuDomainDestroyNamespace(virQEMUDriverPtr driver,
                                virDomainObjPtr vm);

928 929
bool qemuDomainNamespaceAvailable(qemuDomainNamespace ns);

930
int qemuDomainNamespaceSetupDisk(virDomainObjPtr vm,
931
                                 virStorageSourcePtr src);
932

933
int qemuDomainNamespaceTeardownDisk(virDomainObjPtr vm,
934
                                    virStorageSourcePtr src);
935

936
int qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm,
937 938
                                    virDomainHostdevDefPtr hostdev);

939
int qemuDomainNamespaceTeardownHostdev(virDomainObjPtr vm,
940
                                       virDomainHostdevDefPtr hostdev);
941

942
int qemuDomainNamespaceSetupMemory(virDomainObjPtr vm,
M
Michal Privoznik 已提交
943 944
                                   virDomainMemoryDefPtr memory);

945
int qemuDomainNamespaceTeardownMemory(virDomainObjPtr vm,
M
Michal Privoznik 已提交
946 947
                                      virDomainMemoryDefPtr memory);

948
int qemuDomainNamespaceSetupChardev(virDomainObjPtr vm,
949 950
                                    virDomainChrDefPtr chr);

951
int qemuDomainNamespaceTeardownChardev(virDomainObjPtr vm,
952
                                       virDomainChrDefPtr chr);
953

954
int qemuDomainNamespaceSetupRNG(virDomainObjPtr vm,
955
                                virDomainRNGDefPtr rng);
956

957
int qemuDomainNamespaceTeardownRNG(virDomainObjPtr vm,
958
                                   virDomainRNGDefPtr rng);
959

960 961 962 963 964 965
int qemuDomainNamespaceSetupInput(virDomainObjPtr vm,
                                  virDomainInputDefPtr input);

int qemuDomainNamespaceTeardownInput(virDomainObjPtr vm,
                                     virDomainInputDefPtr input);

966 967 968 969 970
virDomainDiskDefPtr qemuDomainDiskLookupByNodename(virDomainDefPtr def,
                                                   const char *nodename,
                                                   virStorageSourcePtr *src,
                                                   unsigned int *idx);

971 972 973 974
char *qemuDomainDiskBackingStoreGetName(virDomainDiskDefPtr disk,
                                        virStorageSourcePtr src,
                                        unsigned int idx);

975 976 977
virStorageSourcePtr qemuDomainGetStorageSourceByDevstr(const char *devstr,
                                                       virDomainDefPtr def);

978 979 980 981 982
int
qemuDomainUpdateCPU(virDomainObjPtr vm,
                    virCPUDefPtr cpu,
                    virCPUDefPtr *origCPU);

983 984 985 986
int
qemuDomainFixupCPUs(virDomainObjPtr vm,
                    virCPUDefPtr *origCPU);

987 988 989
char *
qemuDomainGetMachineName(virDomainObjPtr vm);

990 991 992 993 994 995 996 997
void
qemuDomainObjPrivateXMLFormatAllowReboot(virBufferPtr buf,
                                         virTristateBool allowReboot);

int
qemuDomainObjPrivateXMLParseAllowReboot(xmlXPathContextPtr ctxt,
                                        virTristateBool *allowReboot);

998 999 1000 1001 1002
bool qemuDomainCheckCCWS390AddressSupport(const virDomainDef *def,
                                    virDomainDeviceInfo info,
                                    virQEMUCapsPtr qemuCaps,
                                    const char *devicename);

1003
int
1004 1005 1006 1007 1008
qemuDomainPrepareDiskSourceChain(virDomainDiskDefPtr disk,
                                 virStorageSourcePtr src,
                                 virQEMUDriverConfigPtr cfg,
                                 virQEMUCapsPtr qemuCaps)
    ATTRIBUTE_RETURN_CHECK;
1009

1010
int
1011
qemuDomainPrepareDiskSource(virDomainDiskDefPtr disk,
1012 1013 1014
                            qemuDomainObjPrivatePtr priv,
                            virQEMUDriverConfigPtr cfg);

1015 1016 1017 1018 1019 1020
int
qemuDomainDiskCachemodeFlags(int cachemode,
                             bool *writeback,
                             bool *direct,
                             bool *noflush);

1021
char * qemuDomainGetManagedPRSocketPath(qemuDomainObjPrivatePtr priv);
1022

1023
#endif /* __QEMU_DOMAIN_H__ */