qemu_conf.h 9.6 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 "virfirmware.h"
52

E
Eric Blake 已提交
53 54 55 56 57 58 59
# 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
60

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

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

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
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 已提交
86

87
    const char *uri;
88

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

93 94
    virBitmapPtr namespaces;

95 96 97
    int cgroupControllers;
    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 102
    char *configDir;
    char *autostartDir;
103
    char *logDir;
104
    char *stateDir;
105 106 107 108
    /* These two directories are ones QEMU processes use (so must match
     * the QEMU user/group */
    char *libDir;
    char *cacheDir;
109
    char *saveDir;
C
Chris Lalancette 已提交
110
    char *snapshotDir;
111
    char *channelTargetDir;
112
    char *nvramDir;
113

114 115
    char *defaultTLSx509certdir;
    bool defaultTLSx509verify;
116
    char *defaultTLSx509secretUUID;
117

118 119 120 121
    bool vncAutoUnixSocket;
    bool vncTLS;
    bool vncTLSx509verify;
    bool vncSASL;
D
Daniel P. Berrange 已提交
122
    char *vncTLSx509certdir;
123
    char *vncListen;
124
    char *vncPassword;
125
    char *vncSASLdir;
126 127

    bool spiceTLS;
128
    char *spiceTLSx509certdir;
129 130
    bool spiceSASL;
    char *spiceSASLdir;
131 132
    char *spiceListen;
    char *spicePassword;
133
    bool spiceAutoUnixSocket;
134

135 136 137
    bool chardevTLS;
    char *chardevTLSx509certdir;
    bool chardevTLSx509verify;
138
    char *chardevTLSx509secretUUID;
139

140 141
    unsigned int remotePortMin;
    unsigned int remotePortMax;
142

143 144
    unsigned int webSocketPortMin;
    unsigned int webSocketPortMax;
145

146 147 148
    virHugeTLBFSPtr hugetlbfs;
    size_t nhugetlbfs;

149
    char *bridgeHelperName;
150 151

    bool macFilter;
152

153 154
    bool relaxedACS;
    bool vncAllowHostAudio;
155
    bool nogfxAllowHostAudio;
156 157 158
    bool clearEmulatorCapabilities;
    bool allowDiskFormatProbing;
    bool setProcessName;
159

160 161
    unsigned int maxProcesses;
    unsigned int maxFiles;
162
    unsigned long long maxCore;
163
    bool dumpGuestCore;
164

165
    unsigned int maxQueuedJobs;
166

167
    char **securityDriverNames;
168 169
    bool securityDefaultConfined;
    bool securityRequireConfined;
170 171

    char *saveImageFormat;
172
    char *dumpImageFormat;
173
    char *snapshotImageFormat;
174

H
Hu Tao 已提交
175
    char *autoDumpPath;
176 177
    bool autoDumpBypassCache;
    bool autoStartBypassCache;
H
Hu Tao 已提交
178

179 180 181 182 183 184
    char *lockManagerName;

    int keepAliveInterval;
    unsigned int keepAliveCount;

    int seccompSandbox;
185

186
    char *migrateHost;
187 188
    /* The default for -incoming */
    char *migrationAddress;
189 190
    unsigned int migrationPortMin;
    unsigned int migrationPortMax;
191 192

    bool logTimestamp;
193
    bool stdioLogD;
194

195 196
    virFirmwarePtr *firmwares;
    size_t nfirmwares;
197
    unsigned int glusterDebugLevel;
198 199 200 201 202 203
};

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

204 205
    /* Require lock to get reference on 'config',
     * then lockless thereafter */
206 207
    virQEMUDriverConfigPtr config;

208
    /* Immutable pointer, self-locking APIs */
209 210
    virThreadPoolPtr workerPool;

211
    /* Atomic increment only */
E
Erik Skultety 已提交
212
    int lastvmid;
213

214
    /* Atomic inc/dec only */
215
    unsigned int nactive;
216

217 218 219
    /* Immutable value */
    bool privileged;

220
    /* Immutable pointers. Caller must provide locking */
221 222 223
    virStateInhibitCallback inhibitCallback;
    void *inhibitOpaque;

224
    /* Immutable pointer, self-locking APIs */
225
    virDomainObjListPtr domains;
226

227
    /* Immutable pointer */
228 229
    char *qemuImgBinary;

230
    /* Immutable pointer, lockless APIs. Pointless abstraction */
231 232
    ebtablesContext *ebtables;

233 234 235
    /* Require lock to get a reference on the object,
     * lockless access thereafter
     */
236 237
    virCapsPtr caps;

238
    /* Immutable pointer, Immutable object */
239
    virDomainXMLOptionPtr xmlopt;
240

241
    /* Immutable pointer, self-locking APIs */
242
    virQEMUCapsCachePtr qemuCapsCache;
243

244
    /* Immutable pointer, self-locking APIs */
245
    virObjectEventStatePtr domainEventState;
246

247
    /* Immutable pointer. self-locking APIs */
248 249
    virSecurityManagerPtr securityManager;

250
    virHostdevManagerPtr hostdevMgr;
251

252
    /* Immutable pointer. Unsafe APIs. XXX */
253
    virHashTablePtr sharedDevices;
254

255
    /* Immutable pointer, self-locking APIs */
256
    virPortAllocatorPtr remotePorts;
257

258 259 260
    /* Immutable pointer, self-locking APIs */
    virPortAllocatorPtr webSocketPorts;

261 262 263
    /* Immutable pointer, self-locking APIs */
    virPortAllocatorPtr migrationPorts;

264
    /* Immutable pointer, lockless APIs*/
265
    virSysinfoDefPtr hostsysinfo;
266

267
    /* Immutable pointer. lockless access */
268
    virLockManagerPluginPtr lockManager;
269

270
    /* Immutable pointer, self-clocking APIs */
271
    virCloseCallbacksPtr closeCallbacks;
272 273 274

    /* Immutable pointer, self-locking APIs */
    virHashAtomicPtr migrationErrors;
275 276
};

277 278 279
typedef struct _qemuDomainCmdlineDef qemuDomainCmdlineDef;
typedef qemuDomainCmdlineDef *qemuDomainCmdlineDefPtr;
struct _qemuDomainCmdlineDef {
280
    size_t num_args;
281 282 283 284 285 286 287
    char **args;

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

288 289


290 291
void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def);

292 293 294 295 296 297
virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged);

int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
                                const char *filename);

virQEMUDriverConfigPtr virQEMUDriverGetConfig(virQEMUDriverPtr driver);
298
bool virQEMUDriverIsPrivileged(virQEMUDriverPtr driver);
299

300 301 302 303
virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver);
virCapsPtr virQEMUDriverGetCapabilities(virQEMUDriverPtr driver,
                                        bool refresh);

304 305
typedef struct _qemuSharedDeviceEntry qemuSharedDeviceEntry;
typedef qemuSharedDeviceEntry *qemuSharedDeviceEntryPtr;
306

307 308
bool qemuSharedDeviceEntryDomainExists(qemuSharedDeviceEntryPtr entry,
                                       const char *name,
309
                                       int *idx)
310 311
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

312
char *qemuGetSharedDeviceKey(const char *disk_path)
313 314
    ATTRIBUTE_NONNULL(1);

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

317 318 319 320 321 322 323 324 325 326
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);

327 328 329 330 331
int qemuRemoveSharedDisk(virQEMUDriverPtr driver,
                         virDomainDiskDefPtr disk,
                         const char *name)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);

332
int qemuSetUnprivSGIO(virDomainDeviceDefPtr dev);
333

334
int qemuDriverAllocateID(virQEMUDriverPtr driver);
335 336
virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver);

337 338 339
int qemuTranslateSnapshotDiskSourcePool(virConnectPtr conn,
                                        virDomainSnapshotDiskDefPtr def);

340 341 342 343 344 345 346 347 348 349 350
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);
351
#endif /* __QEMUD_CONF_H */