libvirt/src/qemu/qemu_conf.h

315 lines
8.2 KiB
C
Raw Normal View History

2007-02-14 01:40:09 +00:00
/*
* qemu_conf.h: QEMU configuration management
2007-02-14 01:40:09 +00:00
*
* Copyright (C) 2006-2007, 2009-2013 Red Hat, Inc.
2007-02-14 01:40:09 +00:00
* 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
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
2007-02-14 01:40:09 +00:00
*
* Author: Daniel P. Berrange <berrange@redhat.com>
*/
#ifndef __QEMUD_CONF_H
# define __QEMUD_CONF_H
2007-02-14 01:40:09 +00:00
# include "virebtables.h"
# include "internal.h"
# include "capabilities.h"
# include "network_conf.h"
# include "domain_conf.h"
# include "snapshot_conf.h"
# include "domain_event.h"
# include "virthread.h"
Refactor the security drivers to simplify usage The current security driver usage requires horrible code like if (driver->securityDriver && driver->securityDriver->domainSetSecurityHostdevLabel && driver->securityDriver->domainSetSecurityHostdevLabel(driver->securityDriver, vm, hostdev) < 0) This pair of checks for NULL clutters up the code, making the driver calls 2 lines longer than they really need to be. The goal of the patchset is to change the calling convention to simply if (virSecurityManagerSetHostdevLabel(driver->securityDriver, vm, hostdev) < 0) The first check for 'driver->securityDriver' being NULL is removed by introducing a 'no op' security driver that will always be present if no real driver is enabled. This guarentees driver->securityDriver != NULL. The second check for 'driver->securityDriver->domainSetSecurityHostdevLabel' being non-NULL is hidden in a new abstraction called virSecurityManager. This separates the driver callbacks, from main internal API. The addition of a virSecurityManager object, that is separate from the virSecurityDriver struct also allows for security drivers to carry state / configuration information directly. Thus the DAC/Stack drivers from src/qemu which used to pull config from 'struct qemud_driver' can now be moved into the 'src/security' directory and store their config directly. * src/qemu/qemu_conf.h, src/qemu/qemu_driver.c: Update to use new virSecurityManager APIs * src/qemu/qemu_security_dac.c, src/qemu/qemu_security_dac.h src/qemu/qemu_security_stacked.c, src/qemu/qemu_security_stacked.h: Move into src/security directory * src/security/security_stack.c, src/security/security_stack.h, src/security/security_dac.c, src/security/security_dac.h: Generic versions of previous QEMU specific drivers * src/security/security_apparmor.c, src/security/security_apparmor.h, src/security/security_driver.c, src/security/security_driver.h, src/security/security_selinux.c, src/security/security_selinux.h: Update to take virSecurityManagerPtr object as the first param in all callbacks * src/security/security_nop.c, src/security/security_nop.h: Stub implementation of all security driver APIs. * src/security/security_manager.h, src/security/security_manager.c: New internal API for invoking security drivers * src/libvirt.c: Add missing debug for security APIs
2010-11-17 20:26:30 +00:00
# include "security/security_manager.h"
2012-12-13 14:52:25 +00:00
# include "virpci.h"
2012-12-12 17:04:51 +00:00
# include "virusb.h"
# include "virscsi.h"
# include "cpu_conf.h"
# include "driver.h"
# include "virportallocator.h"
# include "vircommand.h"
# include "virthreadpool.h"
# include "locking/lock_manager.h"
# include "qemu_capabilities.h"
# include "virclosecallbacks.h"
# include "virhostdev.h"
# 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
# define QEMU_DRIVER_NAME "QEMU"
typedef struct _virQEMUDriver virQEMUDriver;
typedef virQEMUDriver *virQEMUDriverPtr;
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;
bool privileged;
const char *uri;
uid_t user;
gid_t group;
int dynamicOwnership;
int cgroupControllers;
char **cgroupDeviceACL;
/* These five directories are ones libvirtd uses (so must be root:root
* to avoid security risk from QEMU processes */
char *configBaseDir;
char *configDir;
char *autostartDir;
char *logDir;
char *stateDir;
/* These two directories are ones QEMU processes use (so must match
* the QEMU user/group */
char *libDir;
char *cacheDir;
char *saveDir;
char *snapshotDir;
bool vncAutoUnixSocket;
bool vncTLS;
bool vncTLSx509verify;
bool vncSASL;
2007-10-12 16:05:44 +00:00
char *vncTLSx509certdir;
char *vncListen;
char *vncPassword;
2009-03-16 13:54:26 +00:00
char *vncSASLdir;
bool spiceTLS;
char *spiceTLSx509certdir;
bool spiceSASL;
char *spiceSASLdir;
char *spiceListen;
char *spicePassword;
int remotePortMin;
int remotePortMax;
int webSocketPortMin;
int webSocketPortMax;
char *hugetlbfsMount;
char *hugepagePath;
char *bridgeHelperName;
bool macFilter;
bool relaxedACS;
bool vncAllowHostAudio;
bool nogfxAllowHostAudio;
bool clearEmulatorCapabilities;
bool allowDiskFormatProbing;
bool setProcessName;
int maxProcesses;
int maxFiles;
int maxQueuedJobs;
char **securityDriverNames;
bool securityDefaultConfined;
bool securityRequireConfined;
char *saveImageFormat;
char *dumpImageFormat;
char *snapshotImageFormat;
char *autoDumpPath;
bool autoDumpBypassCache;
bool autoStartBypassCache;
char *lockManagerName;
int keepAliveInterval;
unsigned int keepAliveCount;
int seccompSandbox;
char *migrateHost;
/* The default for -incoming */
char *migrationAddress;
int migrationPortMin;
int migrationPortMax;
bool logTimestamp;
};
/* Main driver state */
struct _virQEMUDriver {
virMutex lock;
/* Require lock to get reference on 'config',
* then lockless thereafter */
virQEMUDriverConfigPtr config;
/* Immutable pointer, self-locking APIs */
virThreadPoolPtr workerPool;
/* Atomic increment only */
int nextvmid;
/* Atomic inc/dec only */
unsigned int nactive;
/* Immutable pointers. Caller must provide locking */
virStateInhibitCallback inhibitCallback;
void *inhibitOpaque;
/* Immutable pointer, self-locking APIs */
virDomainObjListPtr domains;
/* Immutable pointer */
char *qemuImgBinary;
/* Immutable pointer, lockless APIs. Pointless abstraction */
ebtablesContext *ebtables;
/* Require lock to get a reference on the object,
* lockless access thereafter
*/
virCapsPtr caps;
/* Immutable pointer, Immutable object */
virDomainXMLOptionPtr xmlopt;
/* Immutable pointer, self-locking APIs */
virQEMUCapsCachePtr qemuCapsCache;
/* Immutable pointer, self-locking APIs */
virObjectEventStatePtr domainEventState;
/* Immutable pointer. self-locking APIs */
virSecurityManagerPtr securityManager;
virHostdevManagerPtr hostdevMgr;
/* Immutable pointer. Unsafe APIs. XXX */
virHashTablePtr sharedDevices;
/* Immutable pointer, self-locking APIs */
virPortAllocatorPtr remotePorts;
/* Immutable pointer, self-locking APIs */
virPortAllocatorPtr webSocketPorts;
/* Immutable pointer, self-locking APIs */
virPortAllocatorPtr migrationPorts;
/* Immutable pointer, lockless APIs*/
virSysinfoDefPtr hostsysinfo;
/* Immutable pointer. lockless access */
virLockManagerPluginPtr lockManager;
/* Immutable pointer, self-clocking APIs */
virCloseCallbacksPtr closeCallbacks;
};
typedef struct _qemuDomainCmdlineDef qemuDomainCmdlineDef;
typedef qemuDomainCmdlineDef *qemuDomainCmdlineDefPtr;
struct _qemuDomainCmdlineDef {
size_t num_args;
char **args;
unsigned int num_env;
char **env_name;
char **env_value;
};
void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def);
virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged);
int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
const char *filename);
virQEMUDriverConfigPtr virQEMUDriverGetConfig(virQEMUDriverPtr driver);
virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver);
virCapsPtr virQEMUDriverGetCapabilities(virQEMUDriverPtr driver,
bool refresh);
struct qemuDomainDiskInfo {
bool removable;
bool locked;
bool tray_open;
2012-01-19 16:58:58 +00:00
int io_status;
};
typedef struct _qemuSharedDeviceEntry qemuSharedDeviceEntry;
typedef qemuSharedDeviceEntry *qemuSharedDeviceEntryPtr;
bool qemuSharedDeviceEntryDomainExists(qemuSharedDeviceEntryPtr entry,
const char *name,
int *index)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
char * qemuGetSharedDeviceKey(const char *disk_path)
ATTRIBUTE_NONNULL(1);
void qemuSharedDeviceEntryFree(void *payload, const void *name)
ATTRIBUTE_NONNULL(1);
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);
int qemuSetUnprivSGIO(virDomainDeviceDefPtr dev);
int qemuDriverAllocateID(virQEMUDriverPtr driver);
virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver);
int qemuTranslateDiskSourcePool(virConnectPtr conn,
virDomainDiskDefPtr def);
int qemuTranslateSnapshotDiskSourcePool(virConnectPtr conn,
virDomainSnapshotDiskDefPtr def);
#endif /* __QEMUD_CONF_H */