qemu_conf.h 10.7 KB
Newer Older
D
Daniel P. Berrange 已提交
1
/*
2
 * qemu_conf.h: QEMU configuration management
D
Daniel P. Berrange 已提交
3
 *
4
 * Copyright (C) 2006-2007, 2009-2013 Red Hat, Inc.
D
Daniel P. Berrange 已提交
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/>.
D
Daniel P. Berrange 已提交
20 21 22 23
 *
 * Author: Daniel P. Berrange <berrange@redhat.com>
 */

24
#ifndef __QEMUD_CONF_H
25
# define __QEMUD_CONF_H
D
Daniel P. Berrange 已提交
26

M
Michal Privoznik 已提交
27 28
# include <unistd.h>

29
# include "virebtables.h"
30 31 32 33
# include "internal.h"
# include "capabilities.h"
# include "network_conf.h"
# include "domain_conf.h"
34
# include "snapshot_conf.h"
35
# include "domain_event.h"
36
# include "virthread.h"
37
# include "security/security_manager.h"
38
# include "virpci.h"
39
# include "virusb.h"
40
# include "virscsi.h"
41 42
# include "cpu_conf.h"
# include "driver.h"
43
# include "virportallocator.h"
44
# include "vircommand.h"
45
# include "virthreadpool.h"
46
# include "locking/lock_manager.h"
47
# include "qemu_capabilities.h"
48
# include "virclosecallbacks.h"
49
# include "virhostdev.h"
50
# include "virfile.h"
51
# include "virfilecache.h"
52
# include "virfirmware.h"
53

E
Eric Blake 已提交
54 55 56 57 58 59 60
# ifdef CPU_SETSIZE /* Linux */
#  define QEMUD_CPUMASK_LEN CPU_SETSIZE
# elif defined(_SC_NPROCESSORS_CONF) /* Cygwin */
#  define QEMUD_CPUMASK_LEN (sysconf(_SC_NPROCESSORS_CONF))
# else
#  error "Port me"
# endif
61

C
Chunyan Liu 已提交
62 63
# define QEMU_DRIVER_NAME "QEMU"

64 65 66
typedef struct _virQEMUDriver virQEMUDriver;
typedef virQEMUDriver *virQEMUDriverPtr;

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
typedef struct _virQEMUDriverConfig virQEMUDriverConfig;
typedef virQEMUDriverConfig *virQEMUDriverConfigPtr;

/* Main driver config. The data in these object
 * instances is immutable, so can be accessed
 * without locking. Threads must, however, hold
 * a valid reference on the object to prevent it
 * being released while they use it.
 *
 * eg
 *  qemuDriverLock(driver);
 *  virQEMUDriverConfigPtr cfg = virObjectRef(driver->config);
 *  qemuDriverUnlock(driver);
 *
 *  ...do stuff with 'cfg'..
 *
 *  virObjectUnref(cfg);
 */
struct _virQEMUDriverConfig {
    virObject parent;
H
Hu Tao 已提交
87

88
    const char *uri;
89

90 91
    uid_t user;
    gid_t group;
92
    bool dynamicOwnership;
93

94
    virBitmapPtr namespaces;
95
    bool rememberOwner;
96

97 98 99
    int cgroupControllers;
    char **cgroupDeviceACL;

100
    /* These five directories are ones libvirtd uses (so must be root:root
101
     * to avoid security risk from QEMU processes */
102
    char *configBaseDir;
103 104
    char *configDir;
    char *autostartDir;
105
    char *logDir;
106
    char *swtpmLogDir;
107
    char *stateDir;
108
    char *swtpmStateDir;
109 110 111 112
    /* These two directories are ones QEMU processes use (so must match
     * the QEMU user/group */
    char *libDir;
    char *cacheDir;
113
    char *saveDir;
C
Chris Lalancette 已提交
114
    char *snapshotDir;
115
    char *channelTargetDir;
116
    char *nvramDir;
117
    char *swtpmStorageDir;
118

119
    char *defaultTLSx509certdir;
120
    bool checkdefaultTLSx509certdir;
121
    bool defaultTLSx509verify;
122
    char *defaultTLSx509secretUUID;
123

124 125 126 127
    bool vncAutoUnixSocket;
    bool vncTLS;
    bool vncTLSx509verify;
    bool vncSASL;
D
Daniel P. Berrange 已提交
128
    char *vncTLSx509certdir;
129
    char *vncListen;
130
    char *vncPassword;
131
    char *vncSASLdir;
132 133

    bool spiceTLS;
134
    char *spiceTLSx509certdir;
135 136
    bool spiceSASL;
    char *spiceSASLdir;
137 138
    char *spiceListen;
    char *spicePassword;
139
    bool spiceAutoUnixSocket;
140

141 142 143
    bool chardevTLS;
    char *chardevTLSx509certdir;
    bool chardevTLSx509verify;
144
    char *chardevTLSx509secretUUID;
145

146 147 148 149
    char *migrateTLSx509certdir;
    bool migrateTLSx509verify;
    char *migrateTLSx509secretUUID;

150 151
    unsigned int remotePortMin;
    unsigned int remotePortMax;
152

153 154
    unsigned int webSocketPortMin;
    unsigned int webSocketPortMax;
155

156 157 158
    virHugeTLBFSPtr hugetlbfs;
    size_t nhugetlbfs;

159
    char *bridgeHelperName;
160
    char *prHelperName;
161 162

    bool macFilter;
163

164 165
    bool relaxedACS;
    bool vncAllowHostAudio;
166
    bool nogfxAllowHostAudio;
167 168
    bool clearEmulatorCapabilities;
    bool setProcessName;
169

170 171
    unsigned int maxProcesses;
    unsigned int maxFiles;
172
    unsigned long long maxCore;
173
    bool dumpGuestCore;
174

175
    unsigned int maxQueuedJobs;
176

177
    char **securityDriverNames;
178 179
    bool securityDefaultConfined;
    bool securityRequireConfined;
180 181

    char *saveImageFormat;
182
    char *dumpImageFormat;
183
    char *snapshotImageFormat;
184

H
Hu Tao 已提交
185
    char *autoDumpPath;
186 187
    bool autoDumpBypassCache;
    bool autoStartBypassCache;
H
Hu Tao 已提交
188

189 190 191 192 193 194
    char *lockManagerName;

    int keepAliveInterval;
    unsigned int keepAliveCount;

    int seccompSandbox;
195

196
    char *migrateHost;
197 198
    /* The default for -incoming */
    char *migrationAddress;
199 200
    unsigned int migrationPortMin;
    unsigned int migrationPortMax;
201 202

    bool logTimestamp;
203
    bool stdioLogD;
204

205 206
    virFirmwarePtr *firmwares;
    size_t nfirmwares;
207
    unsigned int glusterDebugLevel;
208 209

    char *memoryBackingDir;
210 211 212

    bool vxhsTLS;
    char *vxhsTLSx509certdir;
213 214 215

    bool nbdTLS;
    char *nbdTLSx509certdir;
216 217 218

    uid_t swtpm_user;
    gid_t swtpm_group;
219 220 221 222 223 224
};

/* Main driver state */
struct _virQEMUDriver {
    virMutex lock;

225 226
    /* Require lock to get reference on 'config',
     * then lockless thereafter */
227 228
    virQEMUDriverConfigPtr config;

229
    /* Immutable pointer, self-locking APIs */
230 231
    virThreadPoolPtr workerPool;

232
    /* Atomic increment only */
E
Erik Skultety 已提交
233
    int lastvmid;
234

235
    /* Atomic inc/dec only */
236
    unsigned int nactive;
237

238 239 240
    /* Immutable value */
    bool privileged;

241
    /* Immutable pointers. Caller must provide locking */
242 243 244
    virStateInhibitCallback inhibitCallback;
    void *inhibitOpaque;

245
    /* Immutable pointer, self-locking APIs */
246
    virDomainObjListPtr domains;
247

248
    /* Immutable pointer */
249 250
    char *qemuImgBinary;

251
    /* Immutable pointer, lockless APIs. Pointless abstraction */
252 253
    ebtablesContext *ebtables;

254 255 256
    /* Require lock to get a reference on the object,
     * lockless access thereafter
     */
257 258
    virCapsPtr caps;

259
    /* Immutable pointer, Immutable object */
260
    virDomainXMLOptionPtr xmlopt;
261

262
    /* Immutable pointer, self-locking APIs */
263
    virFileCachePtr qemuCapsCache;
264

265
    /* Immutable pointer, self-locking APIs */
266
    virObjectEventStatePtr domainEventState;
267

268
    /* Immutable pointer. self-locking APIs */
269 270
    virSecurityManagerPtr securityManager;

271
    virHostdevManagerPtr hostdevMgr;
272

273
    /* Immutable pointer. Unsafe APIs. XXX */
274
    virHashTablePtr sharedDevices;
275

276
    /* Immutable pointer, immutable object */
277
    virPortAllocatorRangePtr remotePorts;
278

279
    /* Immutable pointer, immutable object */
280
    virPortAllocatorRangePtr webSocketPorts;
281

282
    /* Immutable pointer, immutable object */
283
    virPortAllocatorRangePtr migrationPorts;
284

285
    /* Immutable pointer, lockless APIs*/
286
    virSysinfoDefPtr hostsysinfo;
287

288
    /* Immutable pointer. lockless access */
289
    virLockManagerPluginPtr lockManager;
290

291
    /* Immutable pointer, self-clocking APIs */
292
    virCloseCallbacksPtr closeCallbacks;
293 294 295

    /* Immutable pointer, self-locking APIs */
    virHashAtomicPtr migrationErrors;
296 297
};

298 299 300
typedef struct _qemuDomainCmdlineDef qemuDomainCmdlineDef;
typedef qemuDomainCmdlineDef *qemuDomainCmdlineDefPtr;
struct _qemuDomainCmdlineDef {
301
    size_t num_args;
302 303 304 305 306 307 308
    char **args;

    unsigned int num_env;
    char **env_name;
    char **env_value;
};

309 310


311 312
void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def);

313 314 315
virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged);

int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
316 317
                                const char *filename,
                                bool privileged);
318

319 320 321
int
virQEMUDriverConfigValidate(virQEMUDriverConfigPtr cfg);

322
virQEMUDriverConfigPtr virQEMUDriverGetConfig(virQEMUDriverPtr driver);
323
bool virQEMUDriverIsPrivileged(virQEMUDriverPtr driver);
324

325 326 327 328
virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver);
virCapsPtr virQEMUDriverGetCapabilities(virQEMUDriverPtr driver,
                                        bool refresh);

329 330
typedef struct _qemuSharedDeviceEntry qemuSharedDeviceEntry;
typedef qemuSharedDeviceEntry *qemuSharedDeviceEntryPtr;
331

332 333
bool qemuSharedDeviceEntryDomainExists(qemuSharedDeviceEntryPtr entry,
                                       const char *name,
334
                                       int *idx)
335 336
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

337
char *qemuGetSharedDeviceKey(const char *disk_path)
338 339
    ATTRIBUTE_NONNULL(1);

J
Ján Tomko 已提交
340
void qemuSharedDeviceEntryFree(void *payload, const void *name);
341

342 343 344 345 346
int qemuAddSharedDisk(virQEMUDriverPtr driver,
                      virDomainDiskDefPtr disk,
                      const char *name)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);

347 348 349 350 351 352 353 354 355 356
int qemuAddSharedDevice(virQEMUDriverPtr driver,
                        virDomainDeviceDefPtr dev,
                        const char *name)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);

int qemuRemoveSharedDevice(virQEMUDriverPtr driver,
                           virDomainDeviceDefPtr dev,
                           const char *name)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);

357 358 359 360 361
int qemuRemoveSharedDisk(virQEMUDriverPtr driver,
                         virDomainDiskDefPtr disk,
                         const char *name)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);

362
int qemuSetUnprivSGIO(virDomainDeviceDefPtr dev);
363

364
int qemuDriverAllocateID(virQEMUDriverPtr driver);
365 366
virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver);

367
int qemuTranslateSnapshotDiskSourcePool(virDomainSnapshotDiskDefPtr def);
368

369 370 371 372 373 374 375 376 377 378 379
char * qemuGetBaseHugepagePath(virHugeTLBFSPtr hugepage);
char * qemuGetDomainHugepagePath(const virDomainDef *def,
                                 virHugeTLBFSPtr hugepage);
char * qemuGetDomainDefaultHugepath(const virDomainDef *def,
                                    virHugeTLBFSPtr hugetlbfs,
                                    size_t nhugetlbfs);

int qemuGetDomainHupageMemPath(const virDomainDef *def,
                               virQEMUDriverConfigPtr cfg,
                               unsigned long long pagesize,
                               char **memPath);
380

381 382 383 384 385 386 387 388
int qemuGetMemoryBackingBasePath(virQEMUDriverConfigPtr cfg,
                                 char **path);
int qemuGetMemoryBackingDomainPath(const virDomainDef *def,
                                   virQEMUDriverConfigPtr cfg,
                                   char **path);
int qemuGetMemoryBackingPath(const virDomainDef *def,
                             virQEMUDriverConfigPtr cfg,
                             const char *alias,
389
                             char **memPath);
390
#endif /* __QEMUD_CONF_H */