qemu: Fix leak in qemuProcessInitCpuAffinity()
[libvirt/ericb.git] / src / qemu / qemu_conf.h
blob983e74a3cf5d831c22fffd310559b054e7b5e58e
1 /*
2 * qemu_conf.h: QEMU configuration management
4 * Copyright (C) 2006-2007, 2009-2013 Red Hat, Inc.
5 * Copyright (C) 2006 Daniel P. Berrange
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library. If not, see
19 * <http://www.gnu.org/licenses/>.
22 #ifndef LIBVIRT_QEMU_CONF_H
23 # define LIBVIRT_QEMU_CONF_H
25 # include <unistd.h>
27 # include "virebtables.h"
28 # include "internal.h"
29 # include "capabilities.h"
30 # include "network_conf.h"
31 # include "domain_conf.h"
32 # include "snapshot_conf.h"
33 # include "domain_event.h"
34 # include "virthread.h"
35 # include "security/security_manager.h"
36 # include "virpci.h"
37 # include "virusb.h"
38 # include "virscsi.h"
39 # include "cpu_conf.h"
40 # include "driver.h"
41 # include "virportallocator.h"
42 # include "vircommand.h"
43 # include "virthreadpool.h"
44 # include "locking/lock_manager.h"
45 # include "qemu_capabilities.h"
46 # include "virclosecallbacks.h"
47 # include "virhostdev.h"
48 # include "virfile.h"
49 # include "virfilecache.h"
50 # include "virfirmware.h"
52 # ifdef CPU_SETSIZE /* Linux */
53 # define QEMUD_CPUMASK_LEN CPU_SETSIZE
54 # elif defined(_SC_NPROCESSORS_CONF) /* Cygwin */
55 # define QEMUD_CPUMASK_LEN (sysconf(_SC_NPROCESSORS_CONF))
56 # else
57 # error "Port me"
58 # endif
60 # define QEMU_DRIVER_NAME "QEMU"
62 typedef struct _virQEMUDriver virQEMUDriver;
63 typedef virQEMUDriver *virQEMUDriverPtr;
65 typedef struct _virQEMUDriverConfig virQEMUDriverConfig;
66 typedef virQEMUDriverConfig *virQEMUDriverConfigPtr;
68 /* Main driver config. The data in these object
69 * instances is immutable, so can be accessed
70 * without locking. Threads must, however, hold
71 * a valid reference on the object to prevent it
72 * being released while they use it.
74 * eg
75 * qemuDriverLock(driver);
76 * virQEMUDriverConfigPtr cfg = virObjectRef(driver->config);
77 * qemuDriverUnlock(driver);
79 * ...do stuff with 'cfg'..
81 * virObjectUnref(cfg);
83 struct _virQEMUDriverConfig {
84 virObject parent;
86 const char *uri;
88 uid_t user;
89 gid_t group;
90 bool dynamicOwnership;
92 virBitmapPtr namespaces;
93 bool rememberOwner;
95 int cgroupControllers;
96 char **cgroupDeviceACL;
98 /* These five directories are ones libvirtd uses (so must be root:root
99 * to avoid security risk from QEMU processes */
100 char *configBaseDir;
101 char *configDir;
102 char *autostartDir;
103 char *logDir;
104 char *swtpmLogDir;
105 char *stateDir;
106 char *swtpmStateDir;
107 /* These two directories are ones QEMU processes use (so must match
108 * the QEMU user/group */
109 char *libDir;
110 char *cacheDir;
111 char *saveDir;
112 char *snapshotDir;
113 char *channelTargetDir;
114 char *nvramDir;
115 char *swtpmStorageDir;
117 char *defaultTLSx509certdir;
118 bool defaultTLSx509certdirPresent;
119 bool defaultTLSx509verify;
120 char *defaultTLSx509secretUUID;
122 bool vncAutoUnixSocket;
123 bool vncTLS;
124 bool vncTLSx509verify;
125 bool vncTLSx509verifyPresent;
126 bool vncSASL;
127 char *vncTLSx509certdir;
128 char *vncTLSx509secretUUID;
129 char *vncListen;
130 char *vncPassword;
131 char *vncSASLdir;
133 bool spiceTLS;
134 char *spiceTLSx509certdir;
135 bool spiceSASL;
136 char *spiceSASLdir;
137 char *spiceListen;
138 char *spicePassword;
139 bool spiceAutoUnixSocket;
141 bool chardevTLS;
142 char *chardevTLSx509certdir;
143 bool chardevTLSx509verify;
144 bool chardevTLSx509verifyPresent;
145 char *chardevTLSx509secretUUID;
147 char *migrateTLSx509certdir;
148 bool migrateTLSx509verify;
149 bool migrateTLSx509verifyPresent;
150 char *migrateTLSx509secretUUID;
152 unsigned int remotePortMin;
153 unsigned int remotePortMax;
155 unsigned int webSocketPortMin;
156 unsigned int webSocketPortMax;
158 virHugeTLBFSPtr hugetlbfs;
159 size_t nhugetlbfs;
161 char *bridgeHelperName;
162 char *prHelperName;
164 bool macFilter;
166 bool relaxedACS;
167 bool vncAllowHostAudio;
168 bool nogfxAllowHostAudio;
169 bool clearEmulatorCapabilities;
170 bool setProcessName;
172 unsigned int maxProcesses;
173 unsigned int maxFiles;
174 unsigned long long maxCore;
175 bool dumpGuestCore;
177 unsigned int maxQueuedJobs;
179 char **securityDriverNames;
180 bool securityDefaultConfined;
181 bool securityRequireConfined;
183 char *saveImageFormat;
184 char *dumpImageFormat;
185 char *snapshotImageFormat;
187 char *autoDumpPath;
188 bool autoDumpBypassCache;
189 bool autoStartBypassCache;
191 char *lockManagerName;
193 int keepAliveInterval;
194 unsigned int keepAliveCount;
196 int seccompSandbox;
198 char *migrateHost;
199 /* The default for -incoming */
200 char *migrationAddress;
201 unsigned int migrationPortMin;
202 unsigned int migrationPortMax;
204 bool logTimestamp;
205 bool stdioLogD;
207 virFirmwarePtr *firmwares;
208 size_t nfirmwares;
209 unsigned int glusterDebugLevel;
211 char *memoryBackingDir;
213 bool vxhsTLS;
214 char *vxhsTLSx509certdir;
216 bool nbdTLS;
217 char *nbdTLSx509certdir;
219 uid_t swtpm_user;
220 gid_t swtpm_group;
223 /* Main driver state */
224 struct _virQEMUDriver {
225 virMutex lock;
227 /* Require lock to get reference on 'config',
228 * then lockless thereafter */
229 virQEMUDriverConfigPtr config;
231 /* Immutable pointer, self-locking APIs */
232 virThreadPoolPtr workerPool;
234 /* Atomic increment only */
235 int lastvmid;
237 /* Atomic inc/dec only */
238 unsigned int nactive;
240 /* Immutable value */
241 bool privileged;
243 /* Immutable pointers. Caller must provide locking */
244 virStateInhibitCallback inhibitCallback;
245 void *inhibitOpaque;
247 /* Immutable pointer, self-locking APIs */
248 virDomainObjListPtr domains;
250 /* Immutable pointer */
251 char *qemuImgBinary;
253 /* Immutable pointer, lockless APIs. Pointless abstraction */
254 ebtablesContext *ebtables;
256 /* Require lock to get a reference on the object,
257 * lockless access thereafter
259 virCapsPtr caps;
261 /* Immutable pointer, Immutable object */
262 virDomainXMLOptionPtr xmlopt;
264 /* Immutable pointer, self-locking APIs */
265 virFileCachePtr qemuCapsCache;
267 /* Immutable pointer, self-locking APIs */
268 virObjectEventStatePtr domainEventState;
270 /* Immutable pointer. self-locking APIs */
271 virSecurityManagerPtr securityManager;
273 virHostdevManagerPtr hostdevMgr;
275 /* Immutable pointer. Unsafe APIs. XXX */
276 virHashTablePtr sharedDevices;
278 /* Immutable pointer, immutable object */
279 virPortAllocatorRangePtr remotePorts;
281 /* Immutable pointer, immutable object */
282 virPortAllocatorRangePtr webSocketPorts;
284 /* Immutable pointer, immutable object */
285 virPortAllocatorRangePtr migrationPorts;
287 /* Immutable pointer, lockless APIs*/
288 virSysinfoDefPtr hostsysinfo;
290 /* Immutable pointer. lockless access */
291 virLockManagerPluginPtr lockManager;
293 /* Immutable pointer, self-clocking APIs */
294 virCloseCallbacksPtr closeCallbacks;
296 /* Immutable pointer, self-locking APIs */
297 virHashAtomicPtr migrationErrors;
300 typedef struct _qemuDomainCmdlineDef qemuDomainCmdlineDef;
301 typedef qemuDomainCmdlineDef *qemuDomainCmdlineDefPtr;
302 struct _qemuDomainCmdlineDef {
303 size_t num_args;
304 char **args;
306 unsigned int num_env;
307 char **env_name;
308 char **env_value;
313 void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def);
315 virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged);
317 int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
318 const char *filename,
319 bool privileged);
322 virQEMUDriverConfigValidate(virQEMUDriverConfigPtr cfg);
325 virQEMUDriverConfigSetDefaults(virQEMUDriverConfigPtr cfg);
327 virQEMUDriverConfigPtr virQEMUDriverGetConfig(virQEMUDriverPtr driver);
328 bool virQEMUDriverIsPrivileged(virQEMUDriverPtr driver);
330 virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver);
331 virCapsPtr virQEMUDriverGetCapabilities(virQEMUDriverPtr driver,
332 bool refresh);
334 typedef struct _qemuSharedDeviceEntry qemuSharedDeviceEntry;
335 typedef qemuSharedDeviceEntry *qemuSharedDeviceEntryPtr;
337 bool qemuSharedDeviceEntryDomainExists(qemuSharedDeviceEntryPtr entry,
338 const char *name,
339 int *idx)
340 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
342 char *qemuGetSharedDeviceKey(const char *disk_path)
343 ATTRIBUTE_NONNULL(1);
345 void qemuSharedDeviceEntryFree(void *payload, const void *name);
347 int qemuAddSharedDisk(virQEMUDriverPtr driver,
348 virDomainDiskDefPtr disk,
349 const char *name)
350 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
352 int qemuAddSharedDevice(virQEMUDriverPtr driver,
353 virDomainDeviceDefPtr dev,
354 const char *name)
355 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
357 int qemuRemoveSharedDevice(virQEMUDriverPtr driver,
358 virDomainDeviceDefPtr dev,
359 const char *name)
360 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
362 int qemuRemoveSharedDisk(virQEMUDriverPtr driver,
363 virDomainDiskDefPtr disk,
364 const char *name)
365 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
367 int qemuSetUnprivSGIO(virDomainDeviceDefPtr dev);
369 int qemuDriverAllocateID(virQEMUDriverPtr driver);
370 virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver);
372 int qemuTranslateSnapshotDiskSourcePool(virDomainSnapshotDiskDefPtr def);
374 char * qemuGetBaseHugepagePath(virHugeTLBFSPtr hugepage);
375 char * qemuGetDomainHugepagePath(const virDomainDef *def,
376 virHugeTLBFSPtr hugepage);
378 int qemuGetDomainHupageMemPath(const virDomainDef *def,
379 virQEMUDriverConfigPtr cfg,
380 unsigned long long pagesize,
381 char **memPath);
383 int qemuGetMemoryBackingBasePath(virQEMUDriverConfigPtr cfg,
384 char **path);
385 int qemuGetMemoryBackingDomainPath(const virDomainDef *def,
386 virQEMUDriverConfigPtr cfg,
387 char **path);
388 int qemuGetMemoryBackingPath(const virDomainDef *def,
389 virQEMUDriverConfigPtr cfg,
390 const char *alias,
391 char **memPath);
392 #endif /* LIBVIRT_QEMU_CONF_H */