You need to sign in or sign up before continuing.
qemu_conf.h 9.3 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 95
    int cgroupControllers;
    char **cgroupDeviceACL;

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

112 113
    char *defaultTLSx509certdir;
    bool defaultTLSx509verify;
114
    char *defaultTLSx509secretUUID;
115

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

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

133 134 135
    bool chardevTLS;
    char *chardevTLSx509certdir;
    bool chardevTLSx509verify;
136
    char *chardevTLSx509secretUUID;
137

138 139
    unsigned int remotePortMin;
    unsigned int remotePortMax;
140

141 142
    unsigned int webSocketPortMin;
    unsigned int webSocketPortMax;
143

144 145 146
    virHugeTLBFSPtr hugetlbfs;
    size_t nhugetlbfs;

147
    char *bridgeHelperName;
148 149

    bool macFilter;
150

151 152
    bool relaxedACS;
    bool vncAllowHostAudio;
153
    bool nogfxAllowHostAudio;
154 155 156
    bool clearEmulatorCapabilities;
    bool allowDiskFormatProbing;
    bool setProcessName;
157

158 159
    unsigned int maxProcesses;
    unsigned int maxFiles;
160
    unsigned long long maxCore;
161
    bool dumpGuestCore;
162

163
    unsigned int maxQueuedJobs;
164

165
    char **securityDriverNames;
166 167
    bool securityDefaultConfined;
    bool securityRequireConfined;
168 169

    char *saveImageFormat;
170
    char *dumpImageFormat;
171
    char *snapshotImageFormat;
172

H
Hu Tao 已提交
173
    char *autoDumpPath;
174 175
    bool autoDumpBypassCache;
    bool autoStartBypassCache;
H
Hu Tao 已提交
176

177 178 179 180 181 182
    char *lockManagerName;

    int keepAliveInterval;
    unsigned int keepAliveCount;

    int seccompSandbox;
183

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

    bool logTimestamp;
191
    bool stdioLogD;
192

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

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

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

206
    /* Immutable pointer, self-locking APIs */
207 208
    virThreadPoolPtr workerPool;

209
    /* Atomic increment only */
E
Erik Skultety 已提交
210
    int lastvmid;
211

212
    /* Atomic inc/dec only */
213
    unsigned int nactive;
214

215 216 217
    /* Immutable value */
    bool privileged;

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

222
    /* Immutable pointer, self-locking APIs */
223
    virDomainObjListPtr domains;
224

225
    /* Immutable pointer */
226 227
    char *qemuImgBinary;

228
    /* Immutable pointer, lockless APIs. Pointless abstraction */
229 230
    ebtablesContext *ebtables;

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

236
    /* Immutable pointer, Immutable object */
237
    virDomainXMLOptionPtr xmlopt;
238

239
    /* Immutable pointer, self-locking APIs */
240
    virQEMUCapsCachePtr qemuCapsCache;
241

242
    /* Immutable pointer, self-locking APIs */
243
    virObjectEventStatePtr domainEventState;
244

245
    /* Immutable pointer. self-locking APIs */
246 247
    virSecurityManagerPtr securityManager;

248
    virHostdevManagerPtr hostdevMgr;
249

250
    /* Immutable pointer. Unsafe APIs. XXX */
251
    virHashTablePtr sharedDevices;
252

253
    /* Immutable pointer, self-locking APIs */
254
    virPortAllocatorPtr remotePorts;
255

256 257 258
    /* Immutable pointer, self-locking APIs */
    virPortAllocatorPtr webSocketPorts;

259 260 261
    /* Immutable pointer, self-locking APIs */
    virPortAllocatorPtr migrationPorts;

262
    /* Immutable pointer, lockless APIs*/
263
    virSysinfoDefPtr hostsysinfo;
264

265
    /* Immutable pointer. lockless access */
266
    virLockManagerPluginPtr lockManager;
267

268
    /* Immutable pointer, self-clocking APIs */
269
    virCloseCallbacksPtr closeCallbacks;
270 271 272

    /* Immutable pointer, self-locking APIs */
    virHashAtomicPtr migrationErrors;
273 274
};

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

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

286 287


288 289
void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def);

290 291 292 293 294 295
virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged);

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

virQEMUDriverConfigPtr virQEMUDriverGetConfig(virQEMUDriverPtr driver);
296
bool virQEMUDriverIsPrivileged(virQEMUDriverPtr driver);
297

298 299 300 301
virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver);
virCapsPtr virQEMUDriverGetCapabilities(virQEMUDriverPtr driver,
                                        bool refresh);

302 303
typedef struct _qemuSharedDeviceEntry qemuSharedDeviceEntry;
typedef qemuSharedDeviceEntry *qemuSharedDeviceEntryPtr;
304

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

310
char *qemuGetSharedDeviceKey(const char *disk_path)
311 312
    ATTRIBUTE_NONNULL(1);

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

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

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

330
int qemuSetUnprivSGIO(virDomainDeviceDefPtr dev);
331

332
int qemuDriverAllocateID(virQEMUDriverPtr driver);
333 334
virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver);

335 336 337
int qemuTranslateSnapshotDiskSourcePool(virConnectPtr conn,
                                        virDomainSnapshotDiskDefPtr def);

338 339 340
char * qemuGetHugepagePath(virHugeTLBFSPtr hugepage);
char * qemuGetDefaultHugepath(virHugeTLBFSPtr hugetlbfs,
                              size_t nhugetlbfs);
341 342 343 344

int qemuGetHupageMemPath(virQEMUDriverConfigPtr cfg,
                         unsigned long long pagesize,
                         char **memPath);
345
#endif /* __QEMUD_CONF_H */