2007-02-14 01:40:09 +00:00
|
|
|
/*
|
2009-05-21 14:16:55 +00:00
|
|
|
* qemu_conf.c: QEMU configuration management
|
2007-02-14 01:40:09 +00:00
|
|
|
*
|
conf: use disk source accessors in qemu/
Part of a series of cleanups to use new accessor methods.
* src/qemu/qemu_conf.c (qemuCheckSharedDevice)
(qemuAddSharedDevice, qemuRemoveSharedDevice, qemuSetUnprivSGIO):
Use accessors.
* src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse)
(qemuDomainObjCheckDiskTaint, qemuDomainSnapshotForEachQcow2Raw)
(qemuDomainCheckRemoveOptionalDisk, qemuDomainCheckDiskPresence)
(qemuDiskChainCheckBroken, qemuDomainDetermineDiskChain):
Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia)
(qemuDomainCheckEjectableMedia)
(qemuDomainAttachVirtioDiskDevice, qemuDomainAttachSCSIDisk)
(qemuDomainAttachUSBMassstorageDevice)
(qemuDomainAttachDeviceDiskLive, qemuDomainRemoveDiskDevice)
(qemuDomainDetachVirtioDiskDevice, qemuDomainDetachDiskDevice):
Likewise.
* src/qemu/qemu_migration.c (qemuMigrationStartNBDServer)
(qemuMigrationDriveMirror, qemuMigrationCancelDriveMirror)
(qemuMigrationIsSafe): Likewise.
* src/qemu/qemu_process.c (qemuProcessGetVolumeQcowPassphrase)
(qemuProcessHandleIOError, qemuProcessHandleBlockJob)
(qemuProcessInitPasswords): Likewise.
* src/qemu/qemu_driver.c (qemuDomainChangeDiskMediaLive)
(qemuDomainGetBlockInfo, qemuDiskPathToAlias): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-18 19:16:47 +00:00
|
|
|
* Copyright (C) 2006-2014 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
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2007-02-14 01:40:09 +00:00
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2008-01-29 18:15:54 +00:00
|
|
|
#include <config.h>
|
2007-11-26 11:50:16 +00:00
|
|
|
|
2007-02-14 01:40:09 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2008-10-10 16:52:20 +00:00
|
|
|
#include <stdlib.h>
|
2007-02-14 01:40:09 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2007-02-23 17:15:18 +00:00
|
|
|
#include <sys/wait.h>
|
2007-04-10 23:17:46 +00:00
|
|
|
#include <arpa/inet.h>
|
2007-02-14 01:40:09 +00:00
|
|
|
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2007-06-27 00:12:29 +00:00
|
|
|
#include "qemu_conf.h"
|
2010-12-16 15:07:07 +00:00
|
|
|
#include "qemu_capabilities.h"
|
2016-02-10 14:43:57 +00:00
|
|
|
#include "qemu_domain.h"
|
2012-12-13 18:01:25 +00:00
|
|
|
#include "viruuid.h"
|
2012-12-04 12:04:07 +00:00
|
|
|
#include "virbuffer.h"
|
2012-12-12 16:35:35 +00:00
|
|
|
#include "virconf.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2008-12-20 13:09:45 +00:00
|
|
|
#include "datatypes.h"
|
2012-12-13 18:13:21 +00:00
|
|
|
#include "virxml.h"
|
make NUMA-initialization code more portable and more robust
qemudCapsInitNUMA and umlCapsInitNUMA were identical, so this change
factors them into a new function, virCapsInitNUMA, and puts it in
nodeinfo.c.
In addition to factoring out the duplicates, this change also
adjusts that function definition (along with its macros) so
that it works with Fedora 9's numactl version 1, and makes it
so the code will work even if someone builds the kernel with
CONFIG_NR_CPUS > 4096.
Finally, also perform this NUMA initialization for the lxc
and openvz drivers.
* src/nodeinfo.c: Include <stdint.h>, <numa.h> and "memory.h".
(virCapsInitNUMA): Rename from qemudCapsInitNUMA and umlCapsInitNUMA.
(NUMA_MAX_N_CPUS): Define depending on NUMA API version.
(n_bits, MASK_CPU_ISSET): Define, adjust, use uint64 rather than long.
* src/nodeinfo.h: Include "capabilities.h".
(virCapsInitNUMA): Declare it.
* examples/domain-events/events-c/Makefile.am:
* src/Makefile.am: Add $(NUMACTL_CFLAGS) and $(NUMACTL_LIBS) to various
compile/link-related variables.
* src/qemu_conf.c: Include "nodeinfo.h".
(qemudCapsInitNUMA): Remove duplicate code. Adjust caller.
* src/uml_conf.c (umlCapsInitNUMA): Likewise.
Include "nodeinfo.h".
* src/lxc_conf.c: Include "nodeinfo.h".
(lxcCapsInit): Perform NUMA initialization here, too.
* src/openvz_conf.c (openvzCapsInit): And here.
Include "nodeinfo.h".
* src/libvirt_sym.version.in: Add virCapsInitNUMA so that libvirtd
can link to this function.
2008-12-21 18:55:09 +00:00
|
|
|
#include "nodeinfo.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2009-12-18 15:24:14 +00:00
|
|
|
#include "cpu/cpu.h"
|
2010-06-21 18:18:31 +00:00
|
|
|
#include "domain_nwfilter.h"
|
2011-07-19 18:32:58 +00:00
|
|
|
#include "virfile.h"
|
2013-01-10 21:03:14 +00:00
|
|
|
#include "virstring.h"
|
2013-01-14 16:50:08 +00:00
|
|
|
#include "viratomic.h"
|
2013-07-18 10:39:55 +00:00
|
|
|
#include "storage_conf.h"
|
2010-11-16 14:54:17 +00:00
|
|
|
#include "configmake.h"
|
2008-07-11 19:34:11 +00:00
|
|
|
|
2009-01-23 16:22:20 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_QEMU
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("qemu.qemu_conf");
|
|
|
|
|
2016-02-10 14:43:57 +00:00
|
|
|
/* These are only defaults, they can be changed now in qemu.conf and
|
|
|
|
* explicitly specified port is checked against these two (makes
|
|
|
|
* sense to limit the values).
|
|
|
|
*
|
|
|
|
* This limitation is mentioned in qemu.conf, so bear in mind that the
|
|
|
|
* configuration file should reflect any changes made to these values.
|
|
|
|
*/
|
|
|
|
#define QEMU_REMOTE_PORT_MIN 5900
|
|
|
|
#define QEMU_REMOTE_PORT_MAX 65535
|
|
|
|
|
|
|
|
#define QEMU_WEBSOCKET_PORT_MIN 5700
|
|
|
|
#define QEMU_WEBSOCKET_PORT_MAX 65535
|
|
|
|
|
|
|
|
#define QEMU_MIGRATION_PORT_MIN 49152
|
|
|
|
#define QEMU_MIGRATION_PORT_MAX 49215
|
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
static virClassPtr virQEMUDriverConfigClass;
|
|
|
|
static void virQEMUDriverConfigDispose(void *obj);
|
|
|
|
|
|
|
|
static int virQEMUConfigOnceInit(void)
|
|
|
|
{
|
2013-02-15 12:05:12 +00:00
|
|
|
virQEMUDriverConfigClass = virClassNew(virClassForObject(),
|
|
|
|
"virQEMUDriverConfig",
|
|
|
|
sizeof(virQEMUDriverConfig),
|
|
|
|
virQEMUDriverConfigDispose);
|
2013-01-10 21:03:14 +00:00
|
|
|
|
2013-07-15 14:53:13 +00:00
|
|
|
if (!virQEMUDriverConfigClass)
|
2013-02-15 12:05:12 +00:00
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 0;
|
2013-01-10 21:03:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VIR_ONCE_GLOBAL_INIT(virQEMUConfig)
|
|
|
|
|
|
|
|
|
2013-02-06 18:17:20 +00:00
|
|
|
static void
|
|
|
|
qemuDriverLock(virQEMUDriverPtr driver)
|
2010-12-16 16:11:48 +00:00
|
|
|
{
|
|
|
|
virMutexLock(&driver->lock);
|
|
|
|
}
|
2013-02-06 18:17:20 +00:00
|
|
|
static void
|
|
|
|
qemuDriverUnlock(virQEMUDriverPtr driver)
|
2010-12-16 16:11:48 +00:00
|
|
|
{
|
|
|
|
virMutexUnlock(&driver->lock);
|
|
|
|
}
|
|
|
|
|
2013-09-24 15:38:26 +00:00
|
|
|
void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (!def)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < def->num_args; i++)
|
|
|
|
VIR_FREE(def->args[i]);
|
|
|
|
for (i = 0; i < def->num_env; i++) {
|
|
|
|
VIR_FREE(def->env_name[i]);
|
|
|
|
VIR_FREE(def->env_value[i]);
|
|
|
|
}
|
|
|
|
VIR_FREE(def->args);
|
|
|
|
VIR_FREE(def->env_name);
|
|
|
|
VIR_FREE(def->env_value);
|
|
|
|
VIR_FREE(def);
|
|
|
|
}
|
2010-12-16 16:11:48 +00:00
|
|
|
|
2015-01-21 18:38:57 +00:00
|
|
|
|
|
|
|
static int ATTRIBUTE_UNUSED
|
|
|
|
virQEMUDriverConfigLoaderNVRAMParse(virQEMUDriverConfigPtr cfg,
|
|
|
|
const char *list)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
char **token;
|
|
|
|
size_t i, j;
|
|
|
|
|
|
|
|
if (!(token = virStringSplit(list, ":", 0)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; token[i]; i += 2) {
|
|
|
|
if (!token[i] || !token[i + 1] ||
|
|
|
|
STREQ(token[i], "") || STREQ(token[i + 1], "")) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Invalid --with-loader-nvram list: %s"),
|
|
|
|
list);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i) {
|
|
|
|
if (VIR_ALLOC_N(cfg->loader, i / 2) < 0 ||
|
|
|
|
VIR_ALLOC_N(cfg->nvram, i / 2) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
cfg->nloader = i / 2;
|
|
|
|
|
|
|
|
for (j = 0; j < i / 2; j++) {
|
|
|
|
if (VIR_STRDUP(cfg->loader[j], token[2 * j]) < 0 ||
|
|
|
|
VIR_STRDUP(cfg->nvram[j], token[2 * j + 1]) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
virStringFreeList(token);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-18 19:26:02 +00:00
|
|
|
#define VIR_QEMU_OVMF_LOADER_PATH "/usr/share/OVMF/OVMF_CODE.fd"
|
|
|
|
#define VIR_QEMU_OVMF_NVRAM_PATH "/usr/share/OVMF/OVMF_VARS.fd"
|
|
|
|
#define VIR_QEMU_AAVMF_LOADER_PATH "/usr/share/AAVMF/AAVMF_CODE.fd"
|
|
|
|
#define VIR_QEMU_AAVMF_NVRAM_PATH "/usr/share/AAVMF/AAVMF_VARS.fd"
|
2014-08-07 14:59:21 +00:00
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
|
|
|
|
{
|
|
|
|
virQEMUDriverConfigPtr cfg;
|
|
|
|
|
|
|
|
if (virQEMUConfigInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(cfg = virObjectNew(virQEMUDriverConfigClass)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
cfg->uri = privileged ? "qemu:///system" : "qemu:///session";
|
|
|
|
|
|
|
|
if (privileged) {
|
|
|
|
if (virGetUserID(QEMU_USER, &cfg->user) < 0)
|
|
|
|
goto error;
|
|
|
|
if (virGetGroupID(QEMU_GROUP, &cfg->group) < 0)
|
|
|
|
goto error;
|
|
|
|
} else {
|
2013-03-02 14:19:47 +00:00
|
|
|
cfg->user = (uid_t)-1;
|
|
|
|
cfg->group = (gid_t)-1;
|
2013-01-10 21:03:14 +00:00
|
|
|
}
|
|
|
|
cfg->dynamicOwnership = privileged;
|
|
|
|
|
2013-03-21 13:27:13 +00:00
|
|
|
cfg->cgroupControllers = -1; /* -1 == auto-detect */
|
2013-01-10 21:03:14 +00:00
|
|
|
|
|
|
|
if (privileged) {
|
|
|
|
if (virAsprintf(&cfg->logDir,
|
|
|
|
"%s/log/libvirt/qemu", LOCALSTATEDIR) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2013-01-10 21:03:14 +00:00
|
|
|
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(cfg->configBaseDir, SYSCONFDIR "/libvirt") < 0)
|
|
|
|
goto error;
|
2007-10-12 16:05:44 +00:00
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
if (virAsprintf(&cfg->stateDir,
|
|
|
|
"%s/run/libvirt/qemu", LOCALSTATEDIR) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2013-01-10 21:03:14 +00:00
|
|
|
|
|
|
|
if (virAsprintf(&cfg->cacheDir,
|
|
|
|
"%s/cache/libvirt/qemu", LOCALSTATEDIR) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2015-04-24 00:16:30 +00:00
|
|
|
|
|
|
|
if (virAsprintf(&cfg->libDir,
|
|
|
|
"%s/lib/libvirt/qemu", LOCALSTATEDIR) < 0)
|
|
|
|
goto error;
|
|
|
|
if (virAsprintf(&cfg->saveDir, "%s/save", cfg->libDir) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2015-04-24 00:16:30 +00:00
|
|
|
if (virAsprintf(&cfg->snapshotDir, "%s/snapshot", cfg->libDir) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2015-04-24 00:16:30 +00:00
|
|
|
if (virAsprintf(&cfg->autoDumpPath, "%s/dump", cfg->libDir) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2015-04-23 23:24:50 +00:00
|
|
|
if (virAsprintf(&cfg->channelTargetDir,
|
|
|
|
"%s/channel/target", cfg->libDir) < 0)
|
|
|
|
goto error;
|
2015-04-24 00:01:05 +00:00
|
|
|
if (virAsprintf(&cfg->nvramDir, "%s/nvram", cfg->libDir) < 0)
|
|
|
|
goto error;
|
2013-01-10 21:03:14 +00:00
|
|
|
} else {
|
|
|
|
char *rundir;
|
|
|
|
char *cachedir;
|
|
|
|
|
|
|
|
cachedir = virGetUserCacheDirectory();
|
|
|
|
if (!cachedir)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (virAsprintf(&cfg->logDir,
|
|
|
|
"%s/qemu/log", cachedir) < 0) {
|
|
|
|
VIR_FREE(cachedir);
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2013-01-10 21:03:14 +00:00
|
|
|
}
|
|
|
|
if (virAsprintf(&cfg->cacheDir, "%s/qemu/cache", cachedir) < 0) {
|
|
|
|
VIR_FREE(cachedir);
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2013-01-10 21:03:14 +00:00
|
|
|
}
|
|
|
|
VIR_FREE(cachedir);
|
2010-01-13 17:41:36 +00:00
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
rundir = virGetUserRuntimeDirectory();
|
|
|
|
if (!rundir)
|
|
|
|
goto error;
|
|
|
|
if (virAsprintf(&cfg->stateDir, "%s/qemu/run", rundir) < 0) {
|
|
|
|
VIR_FREE(rundir);
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2013-01-10 21:03:14 +00:00
|
|
|
}
|
|
|
|
VIR_FREE(rundir);
|
|
|
|
|
|
|
|
if (!(cfg->configBaseDir = virGetUserConfigDirectory()))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (virAsprintf(&cfg->libDir, "%s/qemu/lib", cfg->configBaseDir) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2013-01-10 21:03:14 +00:00
|
|
|
if (virAsprintf(&cfg->saveDir, "%s/qemu/save", cfg->configBaseDir) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2013-01-10 21:03:14 +00:00
|
|
|
if (virAsprintf(&cfg->snapshotDir, "%s/qemu/snapshot", cfg->configBaseDir) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2013-01-10 21:03:14 +00:00
|
|
|
if (virAsprintf(&cfg->autoDumpPath, "%s/qemu/dump", cfg->configBaseDir) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2015-04-23 23:24:50 +00:00
|
|
|
if (virAsprintf(&cfg->channelTargetDir,
|
|
|
|
"%s/qemu/channel/target", cfg->configBaseDir) < 0)
|
|
|
|
goto error;
|
2015-04-24 00:01:05 +00:00
|
|
|
if (virAsprintf(&cfg->nvramDir,
|
|
|
|
"%s/qemu/nvram", cfg->configBaseDir) < 0)
|
|
|
|
goto error;
|
2013-01-10 21:03:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (virAsprintf(&cfg->configDir, "%s/qemu", cfg->configBaseDir) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2013-01-10 21:03:14 +00:00
|
|
|
if (virAsprintf(&cfg->autostartDir, "%s/qemu/autostart", cfg->configBaseDir) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2012-06-18 08:22:07 +00:00
|
|
|
|
|
|
|
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(cfg->vncListen, "127.0.0.1") < 0)
|
|
|
|
goto error;
|
2012-11-29 11:25:07 +00:00
|
|
|
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(cfg->vncTLSx509certdir, SYSCONFDIR "/pki/libvirt-vnc") < 0)
|
|
|
|
goto error;
|
2007-10-12 16:05:44 +00:00
|
|
|
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(cfg->spiceListen, "127.0.0.1") < 0)
|
|
|
|
goto error;
|
2013-01-10 21:03:14 +00:00
|
|
|
|
2013-11-19 22:45:43 +00:00
|
|
|
if (VIR_STRDUP(cfg->spiceTLSx509certdir,
|
|
|
|
SYSCONFDIR "/pki/libvirt-spice") < 0)
|
2013-05-20 09:23:13 +00:00
|
|
|
goto error;
|
2010-03-05 20:31:50 +00:00
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
cfg->remotePortMin = QEMU_REMOTE_PORT_MIN;
|
|
|
|
cfg->remotePortMax = QEMU_REMOTE_PORT_MAX;
|
|
|
|
|
2013-04-30 14:26:43 +00:00
|
|
|
cfg->webSocketPortMin = QEMU_WEBSOCKET_PORT_MIN;
|
|
|
|
cfg->webSocketPortMax = QEMU_WEBSOCKET_PORT_MAX;
|
|
|
|
|
2013-10-15 13:26:52 +00:00
|
|
|
cfg->migrationPortMin = QEMU_MIGRATION_PORT_MIN;
|
|
|
|
cfg->migrationPortMax = QEMU_MIGRATION_PORT_MAX;
|
|
|
|
|
2014-07-23 15:37:18 +00:00
|
|
|
/* For privileged driver, try and find hugetlbfs mounts automatically.
|
Support configuration of huge pages in guests
Add option to domain XML for
<memoryBacking>
<hugepages/>
</memoryBacking>
* configure.in: Add check for mntent.h
* qemud/libvirtd_qemu.aug, qemud/test_libvirtd_qemu.aug, src/qemu.conf
Add 'hugetlbfs_mount' config parameter
* src/qemu_conf.c, src/qemu_conf.h: Check for -mem-path flag in QEMU,
and pass it when hugepages are requested.
Load hugetlbfs_mount config parameter, search for mount if not given.
* src/qemu_driver.c: Free hugetlbfs_mount/path parameter in driver shutdown.
Create directory for QEMU hugepage usage, chowning if required.
* docs/formatdomain.html.in: Document memoryBacking/hugepages elements
* docs/schemas/domain.rng: Add memoryBacking/hugepages elements to schema
* src/util.c, src/util.h, src/libvirt_private.syms: Add virFileFindMountPoint
helper API
* tests/qemuhelptest.c: Add -mem-path constants
* tests/qemuxml2argvtest.c, tests/qemuxml2xmltest.c: Add tests for hugepage
handling
* tests/qemuxml2argvdata/qemuxml2argv-hugepages.xml,
tests/qemuxml2argvdata/qemuxml2argv-hugepages.args: Data files for
hugepage tests
2009-08-25 14:05:18 +00:00
|
|
|
* Non-privileged driver requires admin to create a dir for the
|
2014-07-23 15:37:18 +00:00
|
|
|
* user, chown it, and then let user configure it manually. */
|
2013-01-10 21:03:14 +00:00
|
|
|
if (privileged &&
|
2014-07-23 15:37:18 +00:00
|
|
|
virFileFindHugeTLBFS(&cfg->hugetlbfs, &cfg->nhugetlbfs) < 0) {
|
|
|
|
/* This however is not implemented on all platforms. */
|
|
|
|
virErrorPtr err = virGetLastError();
|
|
|
|
if (err && err->code != VIR_ERR_NO_SUPPORT)
|
2013-01-10 21:03:14 +00:00
|
|
|
goto error;
|
Support configuration of huge pages in guests
Add option to domain XML for
<memoryBacking>
<hugepages/>
</memoryBacking>
* configure.in: Add check for mntent.h
* qemud/libvirtd_qemu.aug, qemud/test_libvirtd_qemu.aug, src/qemu.conf
Add 'hugetlbfs_mount' config parameter
* src/qemu_conf.c, src/qemu_conf.h: Check for -mem-path flag in QEMU,
and pass it when hugepages are requested.
Load hugetlbfs_mount config parameter, search for mount if not given.
* src/qemu_driver.c: Free hugetlbfs_mount/path parameter in driver shutdown.
Create directory for QEMU hugepage usage, chowning if required.
* docs/formatdomain.html.in: Document memoryBacking/hugepages elements
* docs/schemas/domain.rng: Add memoryBacking/hugepages elements to schema
* src/util.c, src/util.h, src/libvirt_private.syms: Add virFileFindMountPoint
helper API
* tests/qemuhelptest.c: Add -mem-path constants
* tests/qemuxml2argvtest.c, tests/qemuxml2xmltest.c: Add tests for hugepage
handling
* tests/qemuxml2argvdata/qemuxml2argv-hugepages.xml,
tests/qemuxml2argvdata/qemuxml2argv-hugepages.args: Data files for
hugepage tests
2009-08-25 14:05:18 +00:00
|
|
|
}
|
2014-07-23 15:37:18 +00:00
|
|
|
|
2015-08-13 10:20:29 +00:00
|
|
|
if (VIR_STRDUP(cfg->bridgeHelperName, QEMU_BRIDGE_HELPER) < 0)
|
2013-05-20 09:23:13 +00:00
|
|
|
goto error;
|
Support configuration of huge pages in guests
Add option to domain XML for
<memoryBacking>
<hugepages/>
</memoryBacking>
* configure.in: Add check for mntent.h
* qemud/libvirtd_qemu.aug, qemud/test_libvirtd_qemu.aug, src/qemu.conf
Add 'hugetlbfs_mount' config parameter
* src/qemu_conf.c, src/qemu_conf.h: Check for -mem-path flag in QEMU,
and pass it when hugepages are requested.
Load hugetlbfs_mount config parameter, search for mount if not given.
* src/qemu_driver.c: Free hugetlbfs_mount/path parameter in driver shutdown.
Create directory for QEMU hugepage usage, chowning if required.
* docs/formatdomain.html.in: Document memoryBacking/hugepages elements
* docs/schemas/domain.rng: Add memoryBacking/hugepages elements to schema
* src/util.c, src/util.h, src/libvirt_private.syms: Add virFileFindMountPoint
helper API
* tests/qemuhelptest.c: Add -mem-path constants
* tests/qemuxml2argvtest.c, tests/qemuxml2xmltest.c: Add tests for hugepage
handling
* tests/qemuxml2argvdata/qemuxml2argv-hugepages.xml,
tests/qemuxml2argvdata/qemuxml2argv-hugepages.args: Data files for
hugepage tests
2009-08-25 14:05:18 +00:00
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
cfg->clearEmulatorCapabilities = true;
|
|
|
|
|
|
|
|
cfg->securityDefaultConfined = true;
|
|
|
|
cfg->securityRequireConfined = false;
|
|
|
|
|
|
|
|
cfg->keepAliveInterval = 5;
|
|
|
|
cfg->keepAliveCount = 5;
|
|
|
|
cfg->seccompSandbox = -1;
|
|
|
|
|
2014-04-09 13:23:45 +00:00
|
|
|
cfg->logTimestamp = true;
|
|
|
|
|
2015-01-21 18:38:57 +00:00
|
|
|
#ifdef DEFAULT_LOADER_NVRAM
|
|
|
|
if (virQEMUDriverConfigLoaderNVRAMParse(cfg, DEFAULT_LOADER_NVRAM) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2015-01-21 18:44:43 +00:00
|
|
|
if (VIR_ALLOC_N(cfg->loader, 2) < 0 ||
|
|
|
|
VIR_ALLOC_N(cfg->nvram, 2) < 0)
|
2014-08-07 14:59:21 +00:00
|
|
|
goto error;
|
2015-01-21 18:44:43 +00:00
|
|
|
cfg->nloader = 2;
|
2014-08-07 14:59:21 +00:00
|
|
|
|
2015-02-18 19:26:02 +00:00
|
|
|
if (VIR_STRDUP(cfg->loader[0], VIR_QEMU_AAVMF_LOADER_PATH) < 0 ||
|
|
|
|
VIR_STRDUP(cfg->nvram[0], VIR_QEMU_AAVMF_NVRAM_PATH) < 0 ||
|
|
|
|
VIR_STRDUP(cfg->loader[1], VIR_QEMU_OVMF_LOADER_PATH) < 0 ||
|
|
|
|
VIR_STRDUP(cfg->nvram[1], VIR_QEMU_OVMF_NVRAM_PATH) < 0)
|
2014-08-07 14:59:21 +00:00
|
|
|
goto error;
|
2015-01-21 18:38:57 +00:00
|
|
|
#endif
|
2014-08-07 14:59:21 +00:00
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
return cfg;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
error:
|
2013-01-10 21:03:14 +00:00
|
|
|
virObjectUnref(cfg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void virQEMUDriverConfigDispose(void *obj)
|
|
|
|
{
|
|
|
|
virQEMUDriverConfigPtr cfg = obj;
|
|
|
|
|
|
|
|
|
|
|
|
virStringFreeList(cfg->cgroupDeviceACL);
|
|
|
|
|
|
|
|
VIR_FREE(cfg->configBaseDir);
|
|
|
|
VIR_FREE(cfg->configDir);
|
|
|
|
VIR_FREE(cfg->autostartDir);
|
|
|
|
VIR_FREE(cfg->logDir);
|
|
|
|
VIR_FREE(cfg->stateDir);
|
|
|
|
|
|
|
|
VIR_FREE(cfg->libDir);
|
|
|
|
VIR_FREE(cfg->cacheDir);
|
|
|
|
VIR_FREE(cfg->saveDir);
|
|
|
|
VIR_FREE(cfg->snapshotDir);
|
2015-04-23 23:24:50 +00:00
|
|
|
VIR_FREE(cfg->channelTargetDir);
|
2015-04-24 00:01:05 +00:00
|
|
|
VIR_FREE(cfg->nvramDir);
|
2013-01-10 21:03:14 +00:00
|
|
|
|
|
|
|
VIR_FREE(cfg->vncTLSx509certdir);
|
|
|
|
VIR_FREE(cfg->vncListen);
|
|
|
|
VIR_FREE(cfg->vncPassword);
|
|
|
|
VIR_FREE(cfg->vncSASLdir);
|
|
|
|
|
|
|
|
VIR_FREE(cfg->spiceTLSx509certdir);
|
|
|
|
VIR_FREE(cfg->spiceListen);
|
|
|
|
VIR_FREE(cfg->spicePassword);
|
2012-02-24 14:13:06 +00:00
|
|
|
VIR_FREE(cfg->spiceSASLdir);
|
2013-01-10 21:03:14 +00:00
|
|
|
|
2014-07-23 15:37:18 +00:00
|
|
|
while (cfg->nhugetlbfs) {
|
|
|
|
cfg->nhugetlbfs--;
|
|
|
|
VIR_FREE(cfg->hugetlbfs[cfg->nhugetlbfs].mnt_dir);
|
|
|
|
}
|
|
|
|
VIR_FREE(cfg->hugetlbfs);
|
2013-03-25 14:25:30 +00:00
|
|
|
VIR_FREE(cfg->bridgeHelperName);
|
2013-01-10 21:03:14 +00:00
|
|
|
|
|
|
|
VIR_FREE(cfg->saveImageFormat);
|
|
|
|
VIR_FREE(cfg->dumpImageFormat);
|
|
|
|
VIR_FREE(cfg->autoDumpPath);
|
|
|
|
|
|
|
|
virStringFreeList(cfg->securityDriverNames);
|
|
|
|
|
|
|
|
VIR_FREE(cfg->lockManagerName);
|
2014-08-07 14:59:21 +00:00
|
|
|
|
|
|
|
while (cfg->nloader) {
|
|
|
|
VIR_FREE(cfg->loader[cfg->nloader - 1]);
|
|
|
|
VIR_FREE(cfg->nvram[cfg->nloader - 1]);
|
|
|
|
cfg->nloader--;
|
|
|
|
}
|
|
|
|
VIR_FREE(cfg->loader);
|
|
|
|
VIR_FREE(cfg->nvram);
|
2013-01-10 21:03:14 +00:00
|
|
|
}
|
|
|
|
|
Support configuration of huge pages in guests
Add option to domain XML for
<memoryBacking>
<hugepages/>
</memoryBacking>
* configure.in: Add check for mntent.h
* qemud/libvirtd_qemu.aug, qemud/test_libvirtd_qemu.aug, src/qemu.conf
Add 'hugetlbfs_mount' config parameter
* src/qemu_conf.c, src/qemu_conf.h: Check for -mem-path flag in QEMU,
and pass it when hugepages are requested.
Load hugetlbfs_mount config parameter, search for mount if not given.
* src/qemu_driver.c: Free hugetlbfs_mount/path parameter in driver shutdown.
Create directory for QEMU hugepage usage, chowning if required.
* docs/formatdomain.html.in: Document memoryBacking/hugepages elements
* docs/schemas/domain.rng: Add memoryBacking/hugepages elements to schema
* src/util.c, src/util.h, src/libvirt_private.syms: Add virFileFindMountPoint
helper API
* tests/qemuhelptest.c: Add -mem-path constants
* tests/qemuxml2argvtest.c, tests/qemuxml2xmltest.c: Add tests for hugepage
handling
* tests/qemuxml2argvdata/qemuxml2argv-hugepages.xml,
tests/qemuxml2argvdata/qemuxml2argv-hugepages.args: Data files for
hugepage tests
2009-08-25 14:05:18 +00:00
|
|
|
|
2014-07-23 15:37:18 +00:00
|
|
|
static int
|
|
|
|
virQEMUDriverConfigHugeTLBFSInit(virHugeTLBFSPtr hugetlbfs,
|
|
|
|
const char *path,
|
|
|
|
bool deflt)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (VIR_STRDUP(hugetlbfs->mnt_dir, path) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virFileGetHugepageSize(path, &hugetlbfs->size) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
hugetlbfs->deflt = deflt;
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-07 14:59:21 +00:00
|
|
|
static int
|
|
|
|
virQEMUDriverConfigNVRAMParse(const char *str,
|
|
|
|
char **loader,
|
|
|
|
char **nvram)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
char **token;
|
|
|
|
|
|
|
|
if (!(token = virStringSplit(str, ":", 0)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (token[0]) {
|
|
|
|
virSkipSpaces((const char **) &token[0]);
|
|
|
|
if (token[1])
|
|
|
|
virSkipSpaces((const char **) &token[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Exactly two tokens are expected */
|
|
|
|
if (!token[0] || !token[1] || token[2] ||
|
|
|
|
STREQ(token[0], "") || STREQ(token[1], "")) {
|
|
|
|
virReportError(VIR_ERR_CONF_SYNTAX,
|
|
|
|
_("Invalid nvram format: '%s'"),
|
|
|
|
str);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_STRDUP(*loader, token[0]) < 0 ||
|
|
|
|
VIR_STRDUP(*nvram, token[1]) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
virStringFreeList(token);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
|
|
|
|
const char *filename)
|
|
|
|
{
|
|
|
|
virConfPtr conf = NULL;
|
|
|
|
virConfValuePtr p;
|
|
|
|
int ret = -1;
|
Convert 'int i' to 'size_t i' in src/qemu files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2015-11-03 11:13:25 +00:00
|
|
|
char *stdioHandler = NULL;
|
2011-09-16 11:50:56 +00:00
|
|
|
|
2007-10-12 16:05:44 +00:00
|
|
|
/* Just check the file is readable before opening it, otherwise
|
|
|
|
* libvirt emits an error.
|
|
|
|
*/
|
2012-10-17 09:23:12 +00:00
|
|
|
if (access(filename, R_OK) == -1) {
|
2010-06-30 18:14:37 +00:00
|
|
|
VIR_INFO("Could not read qemu config file %s", filename);
|
2013-01-10 21:03:14 +00:00
|
|
|
return 0;
|
2010-06-30 18:14:37 +00:00
|
|
|
}
|
2007-10-12 16:05:44 +00:00
|
|
|
|
2012-11-29 11:25:07 +00:00
|
|
|
if (!(conf = virConfReadFile(filename, 0)))
|
|
|
|
goto cleanup;
|
2007-10-12 16:05:44 +00:00
|
|
|
|
2014-08-22 12:59:28 +00:00
|
|
|
#define CHECK_TYPE(name, typ) \
|
2012-11-27 16:59:34 +00:00
|
|
|
if (p && p->type != (typ)) { \
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, \
|
|
|
|
"%s: %s: expected type " #typ, \
|
|
|
|
filename, (name)); \
|
2012-11-29 11:25:07 +00:00
|
|
|
goto cleanup; \
|
2012-11-27 16:59:34 +00:00
|
|
|
}
|
|
|
|
|
2014-12-09 15:22:09 +00:00
|
|
|
#define CHECK_TYPE_ALT(name, type1, type2) \
|
|
|
|
if (p && (p->type != (type1) && p->type != (type2))) { \
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, \
|
|
|
|
"%s: %s: expected type " #type1, \
|
|
|
|
filename, (name)); \
|
|
|
|
goto cleanup; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GET_VALUE_LONG(NAME, VAR) \
|
|
|
|
p = virConfGetValue(conf, NAME); \
|
|
|
|
CHECK_TYPE_ALT(NAME, VIR_CONF_LONG, VIR_CONF_ULONG); \
|
|
|
|
if (p) \
|
|
|
|
VAR = p->l;
|
|
|
|
|
|
|
|
#define GET_VALUE_ULONG(NAME, VAR) \
|
2012-11-27 16:59:34 +00:00
|
|
|
p = virConfGetValue(conf, NAME); \
|
2014-12-09 15:22:09 +00:00
|
|
|
CHECK_TYPE(NAME, VIR_CONF_ULONG); \
|
2012-11-27 16:59:34 +00:00
|
|
|
if (p) \
|
|
|
|
VAR = p->l;
|
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
#define GET_VALUE_BOOL(NAME, VAR) \
|
|
|
|
p = virConfGetValue(conf, NAME); \
|
2014-12-09 15:22:09 +00:00
|
|
|
CHECK_TYPE(NAME, VIR_CONF_ULONG); \
|
2013-01-10 21:03:14 +00:00
|
|
|
if (p) \
|
|
|
|
VAR = p->l != 0;
|
|
|
|
|
2012-11-27 16:59:34 +00:00
|
|
|
#define GET_VALUE_STR(NAME, VAR) \
|
|
|
|
p = virConfGetValue(conf, NAME); \
|
|
|
|
CHECK_TYPE(NAME, VIR_CONF_STRING); \
|
|
|
|
if (p && p->str) { \
|
|
|
|
VIR_FREE(VAR); \
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(VAR, p->str) < 0) \
|
|
|
|
goto cleanup; \
|
2012-11-27 16:59:34 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
GET_VALUE_BOOL("vnc_auto_unix_socket", cfg->vncAutoUnixSocket);
|
|
|
|
GET_VALUE_BOOL("vnc_tls", cfg->vncTLS);
|
|
|
|
GET_VALUE_BOOL("vnc_tls_x509_verify", cfg->vncTLSx509verify);
|
|
|
|
GET_VALUE_STR("vnc_tls_x509_cert_dir", cfg->vncTLSx509certdir);
|
|
|
|
GET_VALUE_STR("vnc_listen", cfg->vncListen);
|
|
|
|
GET_VALUE_STR("vnc_password", cfg->vncPassword);
|
|
|
|
GET_VALUE_BOOL("vnc_sasl", cfg->vncSASL);
|
|
|
|
GET_VALUE_STR("vnc_sasl_dir", cfg->vncSASLdir);
|
|
|
|
GET_VALUE_BOOL("vnc_allow_host_audio", cfg->vncAllowHostAudio);
|
2013-08-17 19:30:47 +00:00
|
|
|
GET_VALUE_BOOL("nographics_allow_host_audio", cfg->nogfxAllowHostAudio);
|
2009-01-29 17:50:00 +00:00
|
|
|
|
2012-10-17 09:23:12 +00:00
|
|
|
p = virConfGetValue(conf, "security_driver");
|
2012-08-15 22:10:38 +00:00
|
|
|
if (p && p->type == VIR_CONF_LIST) {
|
2015-01-19 11:46:37 +00:00
|
|
|
size_t len, j;
|
2012-08-15 22:10:38 +00:00
|
|
|
virConfValuePtr pp;
|
|
|
|
|
2012-10-11 16:31:20 +00:00
|
|
|
/* Calc length and check items */
|
2012-08-15 22:10:38 +00:00
|
|
|
for (len = 0, pp = p->list; pp; len++, pp = pp->next) {
|
|
|
|
if (pp->type != VIR_CONF_STRING) {
|
2012-11-29 11:25:07 +00:00
|
|
|
virReportError(VIR_ERR_CONF_SYNTAX, "%s",
|
|
|
|
_("security_driver must be a list of strings"));
|
|
|
|
goto cleanup;
|
2012-08-15 22:10:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
if (VIR_ALLOC_N(cfg->securityDriverNames, len + 1) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto cleanup;
|
2012-08-15 22:10:38 +00:00
|
|
|
|
|
|
|
for (i = 0, pp = p->list; pp; i++, pp = pp->next) {
|
2015-01-19 11:46:37 +00:00
|
|
|
for (j = 0; j < i; j++) {
|
|
|
|
if (STREQ(pp->str, cfg->securityDriverNames[j])) {
|
|
|
|
virReportError(VIR_ERR_CONF_SYNTAX,
|
|
|
|
_("Duplicate security driver %s"), pp->str);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(cfg->securityDriverNames[i], pp->str) < 0)
|
|
|
|
goto cleanup;
|
2012-08-15 22:10:38 +00:00
|
|
|
}
|
2013-01-10 21:03:14 +00:00
|
|
|
cfg->securityDriverNames[len] = NULL;
|
2012-08-15 22:10:38 +00:00
|
|
|
} else {
|
2012-10-17 09:23:12 +00:00
|
|
|
CHECK_TYPE("security_driver", VIR_CONF_STRING);
|
2012-08-15 22:10:38 +00:00
|
|
|
if (p && p->str) {
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_ALLOC_N(cfg->securityDriverNames, 2) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto cleanup;
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(cfg->securityDriverNames[0], p->str) < 0)
|
|
|
|
goto cleanup;
|
2012-11-29 11:25:07 +00:00
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
cfg->securityDriverNames[1] = NULL;
|
2012-08-15 22:10:38 +00:00
|
|
|
}
|
2009-03-03 12:03:44 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
GET_VALUE_BOOL("security_default_confined", cfg->securityDefaultConfined);
|
|
|
|
GET_VALUE_BOOL("security_require_confined", cfg->securityRequireConfined);
|
2010-03-05 20:31:50 +00:00
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
GET_VALUE_BOOL("spice_tls", cfg->spiceTLS);
|
|
|
|
GET_VALUE_STR("spice_tls_x509_cert_dir", cfg->spiceTLSx509certdir);
|
2012-02-24 14:13:06 +00:00
|
|
|
GET_VALUE_BOOL("spice_sasl", cfg->spiceSASL);
|
|
|
|
GET_VALUE_STR("spice_sasl_dir", cfg->spiceSASLdir);
|
2013-01-10 21:03:14 +00:00
|
|
|
GET_VALUE_STR("spice_listen", cfg->spiceListen);
|
|
|
|
GET_VALUE_STR("spice_password", cfg->spicePassword);
|
2010-03-05 20:31:50 +00:00
|
|
|
|
|
|
|
|
2014-12-09 15:22:09 +00:00
|
|
|
GET_VALUE_ULONG("remote_websocket_port_min", cfg->webSocketPortMin);
|
2013-04-30 14:26:43 +00:00
|
|
|
if (cfg->webSocketPortMin < QEMU_WEBSOCKET_PORT_MIN) {
|
|
|
|
/* if the port is too low, we can't get the display name
|
|
|
|
* to tell to vnc (usually subtract 5700, e.g. localhost:1
|
|
|
|
* for port 5701) */
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("%s: remote_websocket_port_min: port must be greater "
|
|
|
|
"than or equal to %d"),
|
|
|
|
filename, QEMU_WEBSOCKET_PORT_MIN);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-12-09 15:22:09 +00:00
|
|
|
GET_VALUE_ULONG("remote_websocket_port_max", cfg->webSocketPortMax);
|
2013-04-30 14:26:43 +00:00
|
|
|
if (cfg->webSocketPortMax > QEMU_WEBSOCKET_PORT_MAX ||
|
|
|
|
cfg->webSocketPortMax < cfg->webSocketPortMin) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("%s: remote_websocket_port_max: port must be between "
|
|
|
|
"the minimal port and %d"),
|
|
|
|
filename, QEMU_WEBSOCKET_PORT_MAX);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cfg->webSocketPortMin > cfg->webSocketPortMax) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("%s: remote_websocket_port_min: min port must not be "
|
|
|
|
"greater than max port"), filename);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-12-09 15:22:09 +00:00
|
|
|
GET_VALUE_ULONG("remote_display_port_min", cfg->remotePortMin);
|
2013-01-10 21:03:14 +00:00
|
|
|
if (cfg->remotePortMin < QEMU_REMOTE_PORT_MIN) {
|
2012-11-27 16:59:34 +00:00
|
|
|
/* if the port is too low, we can't get the display name
|
|
|
|
* to tell to vnc (usually subtract 5900, e.g. localhost:1
|
|
|
|
* for port 5901) */
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("%s: remote_display_port_min: port must be greater "
|
|
|
|
"than or equal to %d"),
|
|
|
|
filename, QEMU_REMOTE_PORT_MIN);
|
2012-11-29 11:25:07 +00:00
|
|
|
goto cleanup;
|
2012-06-18 08:22:07 +00:00
|
|
|
}
|
|
|
|
|
2014-12-09 15:22:09 +00:00
|
|
|
GET_VALUE_ULONG("remote_display_port_max", cfg->remotePortMax);
|
2013-01-10 21:03:14 +00:00
|
|
|
if (cfg->remotePortMax > QEMU_REMOTE_PORT_MAX ||
|
|
|
|
cfg->remotePortMax < cfg->remotePortMin) {
|
2012-11-27 16:59:34 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("%s: remote_display_port_max: port must be between "
|
|
|
|
"the minimal port and %d"),
|
|
|
|
filename, QEMU_REMOTE_PORT_MAX);
|
2012-11-29 11:25:07 +00:00
|
|
|
goto cleanup;
|
2012-06-18 08:22:07 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
if (cfg->remotePortMin > cfg->remotePortMax) {
|
2012-06-18 08:22:07 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2012-11-27 16:59:34 +00:00
|
|
|
_("%s: remote_display_port_min: min port must not be "
|
|
|
|
"greater than max port"), filename);
|
2012-11-29 11:25:07 +00:00
|
|
|
goto cleanup;
|
2012-06-18 08:22:07 +00:00
|
|
|
}
|
|
|
|
|
2014-12-09 15:22:09 +00:00
|
|
|
GET_VALUE_ULONG("migration_port_min", cfg->migrationPortMin);
|
2013-10-15 13:26:52 +00:00
|
|
|
if (cfg->migrationPortMin <= 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("%s: migration_port_min: port must be greater than 0"),
|
|
|
|
filename);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-12-09 15:22:09 +00:00
|
|
|
GET_VALUE_ULONG("migration_port_max", cfg->migrationPortMax);
|
2013-10-15 13:26:52 +00:00
|
|
|
if (cfg->migrationPortMax > 65535 ||
|
|
|
|
cfg->migrationPortMax < cfg->migrationPortMin) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("%s: migration_port_max: port must be between "
|
|
|
|
"the minimal port %d and 65535"),
|
|
|
|
filename, cfg->migrationPortMin);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-10-17 09:23:12 +00:00
|
|
|
p = virConfGetValue(conf, "user");
|
|
|
|
CHECK_TYPE("user", VIR_CONF_STRING);
|
2013-01-10 21:03:14 +00:00
|
|
|
if (p && p->str &&
|
|
|
|
virGetUserID(p->str, &cfg->user) < 0)
|
2012-11-29 11:25:07 +00:00
|
|
|
goto cleanup;
|
2010-01-13 17:41:36 +00:00
|
|
|
|
2012-10-17 09:23:12 +00:00
|
|
|
p = virConfGetValue(conf, "group");
|
|
|
|
CHECK_TYPE("group", VIR_CONF_STRING);
|
2013-01-10 21:03:14 +00:00
|
|
|
if (p && p->str &&
|
|
|
|
virGetGroupID(p->str, &cfg->group) < 0)
|
2012-11-29 11:25:07 +00:00
|
|
|
goto cleanup;
|
2009-07-15 21:25:01 +00:00
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
GET_VALUE_BOOL("dynamic_ownership", cfg->dynamicOwnership);
|
2010-01-13 17:41:36 +00:00
|
|
|
|
2012-10-17 09:23:12 +00:00
|
|
|
p = virConfGetValue(conf, "cgroup_controllers");
|
|
|
|
CHECK_TYPE("cgroup_controllers", VIR_CONF_LIST);
|
2009-07-22 15:08:04 +00:00
|
|
|
if (p) {
|
2013-03-21 13:27:13 +00:00
|
|
|
cfg->cgroupControllers = 0;
|
2009-07-22 15:08:04 +00:00
|
|
|
virConfValuePtr pp;
|
|
|
|
for (i = 0, pp = p->list; pp; ++i, pp = pp->next) {
|
|
|
|
int ctl;
|
|
|
|
if (pp->type != VIR_CONF_STRING) {
|
2012-11-29 11:25:07 +00:00
|
|
|
virReportError(VIR_ERR_CONF_SYNTAX, "%s",
|
|
|
|
_("cgroup_controllers must be a "
|
|
|
|
"list of strings"));
|
|
|
|
goto cleanup;
|
2009-07-22 15:08:04 +00:00
|
|
|
}
|
2012-11-29 11:25:07 +00:00
|
|
|
|
|
|
|
if ((ctl = virCgroupControllerTypeFromString(pp->str)) < 0) {
|
|
|
|
virReportError(VIR_ERR_CONF_SYNTAX,
|
|
|
|
_("Unknown cgroup controller '%s'"), pp->str);
|
|
|
|
goto cleanup;
|
2009-07-22 15:08:04 +00:00
|
|
|
}
|
2013-01-10 21:03:14 +00:00
|
|
|
cfg->cgroupControllers |= (1 << ctl);
|
2009-07-22 15:08:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-17 09:23:12 +00:00
|
|
|
p = virConfGetValue(conf, "cgroup_device_acl");
|
|
|
|
CHECK_TYPE("cgroup_device_acl", VIR_CONF_LIST);
|
2009-07-22 15:08:04 +00:00
|
|
|
if (p) {
|
|
|
|
int len = 0;
|
|
|
|
virConfValuePtr pp;
|
|
|
|
for (pp = p->list; pp; pp = pp->next)
|
|
|
|
len++;
|
2013-01-10 21:03:14 +00:00
|
|
|
if (VIR_ALLOC_N(cfg->cgroupDeviceACL, 1+len) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto cleanup;
|
2012-11-29 11:25:07 +00:00
|
|
|
|
2009-07-22 15:08:04 +00:00
|
|
|
for (i = 0, pp = p->list; pp; ++i, pp = pp->next) {
|
|
|
|
if (pp->type != VIR_CONF_STRING) {
|
2012-11-29 11:25:07 +00:00
|
|
|
virReportError(VIR_ERR_CONF_SYNTAX, "%s",
|
|
|
|
_("cgroup_device_acl must be a "
|
|
|
|
"list of strings"));
|
|
|
|
goto cleanup;
|
2009-07-22 15:08:04 +00:00
|
|
|
}
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(cfg->cgroupDeviceACL[i], pp->str) < 0)
|
|
|
|
goto cleanup;
|
2009-07-22 15:08:04 +00:00
|
|
|
}
|
2013-01-10 21:03:14 +00:00
|
|
|
cfg->cgroupDeviceACL[i] = NULL;
|
2009-07-22 15:08:04 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
GET_VALUE_STR("save_image_format", cfg->saveImageFormat);
|
|
|
|
GET_VALUE_STR("dump_image_format", cfg->dumpImageFormat);
|
2013-10-09 16:05:43 +00:00
|
|
|
GET_VALUE_STR("snapshot_image_format", cfg->snapshotImageFormat);
|
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
GET_VALUE_STR("auto_dump_path", cfg->autoDumpPath);
|
|
|
|
GET_VALUE_BOOL("auto_dump_bypass_cache", cfg->autoDumpBypassCache);
|
|
|
|
GET_VALUE_BOOL("auto_start_bypass_cache", cfg->autoStartBypassCache);
|
2009-11-03 22:41:23 +00:00
|
|
|
|
2014-07-23 15:37:18 +00:00
|
|
|
/* Some crazy backcompat. Back in the old days, this was just a pure
|
|
|
|
* string. We must continue supporting it. These days however, this may be
|
|
|
|
* an array of strings. */
|
|
|
|
p = virConfGetValue(conf, "hugetlbfs_mount");
|
|
|
|
if (p) {
|
|
|
|
/* There already might be something autodetected. Avoid leaking it. */
|
|
|
|
while (cfg->nhugetlbfs) {
|
|
|
|
cfg->nhugetlbfs--;
|
|
|
|
VIR_FREE(cfg->hugetlbfs[cfg->nhugetlbfs].mnt_dir);
|
|
|
|
}
|
|
|
|
VIR_FREE(cfg->hugetlbfs);
|
|
|
|
|
|
|
|
if (p->type == VIR_CONF_LIST) {
|
|
|
|
size_t len = 0;
|
|
|
|
virConfValuePtr pp = p->list;
|
|
|
|
|
|
|
|
/* Calc length and check items */
|
|
|
|
while (pp) {
|
|
|
|
if (pp->type != VIR_CONF_STRING) {
|
|
|
|
virReportError(VIR_ERR_CONF_SYNTAX, "%s",
|
|
|
|
_("hugetlbfs_mount must be a list of strings"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
len++;
|
|
|
|
pp = pp->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len && VIR_ALLOC_N(cfg->hugetlbfs, len) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
cfg->nhugetlbfs = len;
|
|
|
|
|
|
|
|
pp = p->list;
|
|
|
|
len = 0;
|
|
|
|
while (pp) {
|
|
|
|
if (virQEMUDriverConfigHugeTLBFSInit(&cfg->hugetlbfs[len],
|
|
|
|
pp->str, !len) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
len++;
|
|
|
|
pp = pp->next;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CHECK_TYPE("hugetlbfs_mount", VIR_CONF_STRING);
|
|
|
|
if (STRNEQ(p->str, "")) {
|
|
|
|
if (VIR_ALLOC_N(cfg->hugetlbfs, 1) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
cfg->nhugetlbfs = 1;
|
|
|
|
if (virQEMUDriverConfigHugeTLBFSInit(&cfg->hugetlbfs[0],
|
|
|
|
p->str, true) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-25 14:25:30 +00:00
|
|
|
GET_VALUE_STR("bridge_helper", cfg->bridgeHelperName);
|
2009-11-03 22:41:23 +00:00
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
GET_VALUE_BOOL("mac_filter", cfg->macFilter);
|
|
|
|
|
|
|
|
GET_VALUE_BOOL("relaxed_acs_check", cfg->relaxedACS);
|
|
|
|
GET_VALUE_BOOL("clear_emulator_capabilities", cfg->clearEmulatorCapabilities);
|
|
|
|
GET_VALUE_BOOL("allow_disk_format_probing", cfg->allowDiskFormatProbing);
|
|
|
|
GET_VALUE_BOOL("set_process_name", cfg->setProcessName);
|
2014-12-09 15:22:09 +00:00
|
|
|
GET_VALUE_ULONG("max_processes", cfg->maxProcesses);
|
|
|
|
GET_VALUE_ULONG("max_files", cfg->maxFiles);
|
2010-10-26 14:04:46 +00:00
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
GET_VALUE_STR("lock_manager", cfg->lockManagerName);
|
2015-11-03 11:13:25 +00:00
|
|
|
GET_VALUE_STR("stdio_handler", stdioHandler);
|
|
|
|
if (stdioHandler) {
|
|
|
|
if (STREQ(stdioHandler, "logd")) {
|
|
|
|
cfg->stdioLogD = true;
|
|
|
|
} else if (STREQ(stdioHandler, "file")) {
|
|
|
|
cfg->stdioLogD = false;
|
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Unknown stdio handler %s"),
|
|
|
|
stdioHandler);
|
|
|
|
VIR_FREE(stdioHandler);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
VIR_FREE(stdioHandler);
|
|
|
|
} else {
|
|
|
|
cfg->stdioLogD = true;
|
|
|
|
}
|
2013-01-10 21:03:14 +00:00
|
|
|
|
2014-12-09 15:22:09 +00:00
|
|
|
GET_VALUE_ULONG("max_queued", cfg->maxQueuedJobs);
|
2013-01-10 21:03:14 +00:00
|
|
|
|
|
|
|
GET_VALUE_LONG("keepalive_interval", cfg->keepAliveInterval);
|
2014-12-09 15:22:09 +00:00
|
|
|
GET_VALUE_ULONG("keepalive_count", cfg->keepAliveCount);
|
2013-01-10 21:03:14 +00:00
|
|
|
|
|
|
|
GET_VALUE_LONG("seccomp_sandbox", cfg->seccompSandbox);
|
2012-09-17 07:59:53 +00:00
|
|
|
|
2014-05-20 06:08:05 +00:00
|
|
|
GET_VALUE_STR("migration_host", cfg->migrateHost);
|
2014-10-07 04:07:31 +00:00
|
|
|
virStringStripIPv6Brackets(cfg->migrateHost);
|
|
|
|
if (cfg->migrateHost &&
|
|
|
|
(STRPREFIX(cfg->migrateHost, "localhost") ||
|
|
|
|
virSocketAddrIsNumericLocalhost(cfg->migrateHost))) {
|
|
|
|
virReportError(VIR_ERR_CONF_SYNTAX,
|
|
|
|
_("migration_host must not be the address of"
|
|
|
|
" the local machine: %s"),
|
|
|
|
cfg->migrateHost);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-09 09:32:55 +00:00
|
|
|
GET_VALUE_STR("migration_address", cfg->migrationAddress);
|
2014-10-07 04:07:32 +00:00
|
|
|
virStringStripIPv6Brackets(cfg->migrationAddress);
|
|
|
|
if (cfg->migrationAddress &&
|
|
|
|
(STRPREFIX(cfg->migrationAddress, "localhost") ||
|
|
|
|
virSocketAddrIsNumericLocalhost(cfg->migrationAddress))) {
|
|
|
|
virReportError(VIR_ERR_CONF_SYNTAX,
|
|
|
|
_("migration_address must not be the address of"
|
|
|
|
" the local machine: %s"),
|
|
|
|
cfg->migrationAddress);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-10-09 09:32:55 +00:00
|
|
|
|
2014-04-09 13:23:45 +00:00
|
|
|
GET_VALUE_BOOL("log_timestamp", cfg->logTimestamp);
|
|
|
|
|
2014-08-07 14:59:21 +00:00
|
|
|
if ((p = virConfGetValue(conf, "nvram"))) {
|
|
|
|
size_t len;
|
|
|
|
virConfValuePtr pp;
|
|
|
|
|
|
|
|
CHECK_TYPE("nvram", VIR_CONF_LIST);
|
|
|
|
|
|
|
|
while (cfg->nloader) {
|
|
|
|
VIR_FREE(cfg->loader[cfg->nloader - 1]);
|
|
|
|
VIR_FREE(cfg->nvram[cfg->nloader - 1]);
|
|
|
|
cfg->nloader--;
|
|
|
|
}
|
|
|
|
VIR_FREE(cfg->loader);
|
|
|
|
VIR_FREE(cfg->nvram);
|
|
|
|
|
|
|
|
/* Calc length and check items */
|
|
|
|
for (len = 0, pp = p->list; pp; len++, pp = pp->next) {
|
|
|
|
if (pp->type != VIR_CONF_STRING) {
|
|
|
|
virReportError(VIR_ERR_CONF_SYNTAX, "%s",
|
|
|
|
_("nvram must be a list of strings"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len &&
|
|
|
|
(VIR_ALLOC_N(cfg->loader, len) < 0 ||
|
|
|
|
VIR_ALLOC_N(cfg->nvram, len) < 0))
|
|
|
|
goto cleanup;
|
|
|
|
cfg->nloader = len;
|
|
|
|
|
|
|
|
for (i = 0, pp = p->list; pp; i++, pp = pp->next) {
|
|
|
|
if (virQEMUDriverConfigNVRAMParse(pp->str,
|
|
|
|
&cfg->loader[i],
|
|
|
|
&cfg->nvram[i]) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-29 11:25:07 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2012-10-17 09:23:12 +00:00
|
|
|
virConfFree(conf);
|
2012-11-29 11:25:07 +00:00
|
|
|
return ret;
|
2007-10-12 16:05:44 +00:00
|
|
|
}
|
2012-11-27 16:59:34 +00:00
|
|
|
#undef GET_VALUE_LONG
|
2014-12-09 15:22:09 +00:00
|
|
|
#undef GET_VALUE_ULONG
|
|
|
|
#undef GET_VALUE_BOOL
|
2014-08-12 15:39:52 +00:00
|
|
|
#undef GET_VALUE_STR
|
2012-03-19 13:28:10 +00:00
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
virQEMUDriverConfigPtr virQEMUDriverGetConfig(virQEMUDriverPtr driver)
|
|
|
|
{
|
2013-02-06 18:17:20 +00:00
|
|
|
virQEMUDriverConfigPtr conf;
|
|
|
|
qemuDriverLock(driver);
|
|
|
|
conf = virObjectRef(driver->config);
|
|
|
|
qemuDriverUnlock(driver);
|
|
|
|
return conf;
|
2013-01-10 21:03:14 +00:00
|
|
|
}
|
|
|
|
|
2015-06-15 18:59:58 +00:00
|
|
|
bool
|
|
|
|
virQEMUDriverIsPrivileged(virQEMUDriverPtr driver)
|
|
|
|
{
|
|
|
|
return driver->privileged;
|
|
|
|
}
|
|
|
|
|
2013-03-31 18:03:42 +00:00
|
|
|
virDomainXMLOptionPtr
|
2013-03-11 09:24:29 +00:00
|
|
|
virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver)
|
2013-03-05 15:17:24 +00:00
|
|
|
{
|
2013-03-11 09:24:29 +00:00
|
|
|
virQEMUDriverDomainDefParserConfig.priv = driver;
|
2013-02-19 16:33:52 +00:00
|
|
|
return virDomainXMLOptionNew(&virQEMUDriverDomainDefParserConfig,
|
2013-02-19 16:29:39 +00:00
|
|
|
&virQEMUDriverPrivateDataCallbacks,
|
|
|
|
&virQEMUDriverDomainXMLNamespace);
|
2013-03-05 15:17:24 +00:00
|
|
|
}
|
|
|
|
|
2013-02-01 17:04:15 +00:00
|
|
|
|
|
|
|
virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver)
|
|
|
|
{
|
2013-10-18 12:13:21 +00:00
|
|
|
size_t i, j;
|
2013-02-01 17:04:15 +00:00
|
|
|
virCapsPtr caps;
|
|
|
|
virSecurityManagerPtr *sec_managers = NULL;
|
|
|
|
/* Security driver data */
|
2013-10-18 12:13:21 +00:00
|
|
|
const char *doi, *model, *lbl, *type;
|
2013-02-01 17:04:15 +00:00
|
|
|
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
2013-10-18 12:13:21 +00:00
|
|
|
const int virtTypes[] = {VIR_DOMAIN_VIRT_KVM,
|
|
|
|
VIR_DOMAIN_VIRT_QEMU,};
|
2013-02-01 17:04:15 +00:00
|
|
|
|
|
|
|
/* Basic host arch / guest machine capabilities */
|
2013-02-19 09:56:06 +00:00
|
|
|
if (!(caps = virQEMUCapsInit(driver->qemuCapsCache)))
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2013-02-01 17:04:15 +00:00
|
|
|
|
|
|
|
if (virGetHostUUID(caps->host.host_uuid)) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("cannot get the host uuid"));
|
2013-02-19 09:56:06 +00:00
|
|
|
goto error;
|
2013-02-01 17:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* access sec drivers and create a sec model for each one */
|
2013-02-19 09:56:06 +00:00
|
|
|
if (!(sec_managers = virSecurityManagerGetNested(driver->securityManager)))
|
|
|
|
goto error;
|
2013-02-01 17:04:15 +00:00
|
|
|
|
|
|
|
/* calculate length */
|
|
|
|
for (i = 0; sec_managers[i]; i++)
|
|
|
|
;
|
|
|
|
caps->host.nsecModels = i;
|
|
|
|
|
|
|
|
if (VIR_ALLOC_N(caps->host.secModels, caps->host.nsecModels) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2013-02-01 17:04:15 +00:00
|
|
|
|
|
|
|
for (i = 0; sec_managers[i]; i++) {
|
2013-10-18 12:13:21 +00:00
|
|
|
virCapsHostSecModelPtr sm = &caps->host.secModels[i];
|
2013-02-01 17:04:15 +00:00
|
|
|
doi = virSecurityManagerGetDOI(sec_managers[i]);
|
|
|
|
model = virSecurityManagerGetModel(sec_managers[i]);
|
2013-10-18 12:13:21 +00:00
|
|
|
if (VIR_STRDUP(sm->model, model) < 0 ||
|
|
|
|
VIR_STRDUP(sm->doi, doi) < 0)
|
2013-05-20 09:23:13 +00:00
|
|
|
goto error;
|
2013-10-18 12:13:21 +00:00
|
|
|
|
|
|
|
for (j = 0; j < ARRAY_CARDINALITY(virtTypes); j++) {
|
|
|
|
lbl = virSecurityManagerGetBaseLabel(sec_managers[i], virtTypes[j]);
|
|
|
|
type = virDomainVirtTypeToString(virtTypes[j]);
|
|
|
|
if (lbl &&
|
|
|
|
virCapabilitiesHostSecModelAddBaseLabel(sm, type, lbl) < 0)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-02-01 17:04:15 +00:00
|
|
|
VIR_DEBUG("Initialized caps for security driver \"%s\" with "
|
|
|
|
"DOI \"%s\"", model, doi);
|
|
|
|
}
|
|
|
|
VIR_FREE(sec_managers);
|
|
|
|
|
|
|
|
virObjectUnref(cfg);
|
|
|
|
return caps;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
error:
|
2013-02-01 17:04:15 +00:00
|
|
|
VIR_FREE(sec_managers);
|
|
|
|
virObjectUnref(caps);
|
|
|
|
virObjectUnref(cfg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virQEMUDriverGetCapabilities:
|
|
|
|
*
|
|
|
|
* Get a reference to the virCapsPtr instance for the
|
|
|
|
* driver. If @refresh is true, the capabilities will be
|
|
|
|
* rebuilt first
|
|
|
|
*
|
|
|
|
* The caller must release the reference with virObjetUnref
|
|
|
|
*
|
|
|
|
* Returns: a reference to a virCapsPtr instance or NULL
|
|
|
|
*/
|
|
|
|
virCapsPtr virQEMUDriverGetCapabilities(virQEMUDriverPtr driver,
|
|
|
|
bool refresh)
|
|
|
|
{
|
2013-02-06 18:17:20 +00:00
|
|
|
virCapsPtr ret = NULL;
|
2013-02-01 17:04:15 +00:00
|
|
|
if (refresh) {
|
|
|
|
virCapsPtr caps = NULL;
|
|
|
|
if ((caps = virQEMUDriverCreateCapabilities(driver)) == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2013-02-06 18:17:20 +00:00
|
|
|
qemuDriverLock(driver);
|
2013-02-01 17:04:15 +00:00
|
|
|
virObjectUnref(driver->caps);
|
|
|
|
driver->caps = caps;
|
2013-02-06 18:17:20 +00:00
|
|
|
} else {
|
|
|
|
qemuDriverLock(driver);
|
2013-02-01 17:04:15 +00:00
|
|
|
}
|
|
|
|
|
2015-04-16 18:51:26 +00:00
|
|
|
if (driver->caps->nguests == 0 && !refresh) {
|
|
|
|
VIR_DEBUG("Capabilities didn't detect any guests. Forcing a "
|
|
|
|
"refresh.");
|
|
|
|
qemuDriverUnlock(driver);
|
|
|
|
return virQEMUDriverGetCapabilities(driver, true);
|
|
|
|
}
|
|
|
|
|
2013-02-06 18:17:20 +00:00
|
|
|
ret = virObjectRef(driver->caps);
|
|
|
|
qemuDriverUnlock(driver);
|
|
|
|
return ret;
|
2013-02-01 17:04:15 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 18:07:35 +00:00
|
|
|
struct _qemuSharedDeviceEntry {
|
2013-02-20 07:43:55 +00:00
|
|
|
size_t ref;
|
|
|
|
char **domains; /* array of domain names */
|
|
|
|
};
|
|
|
|
|
2013-05-03 18:07:35 +00:00
|
|
|
/* Construct the hash key for sharedDevices as "major:minor" */
|
2013-01-02 14:37:07 +00:00
|
|
|
char *
|
2013-05-03 18:07:35 +00:00
|
|
|
qemuGetSharedDeviceKey(const char *device_path)
|
2013-01-02 14:37:07 +00:00
|
|
|
{
|
|
|
|
int maj, min;
|
|
|
|
char *key = NULL;
|
|
|
|
int rc;
|
|
|
|
|
2013-05-03 18:07:35 +00:00
|
|
|
if ((rc = virGetDeviceID(device_path, &maj, &min)) < 0) {
|
2013-01-02 14:37:07 +00:00
|
|
|
virReportSystemError(-rc,
|
|
|
|
_("Unable to get minor number of device '%s'"),
|
2013-05-03 18:07:35 +00:00
|
|
|
device_path);
|
2013-01-02 14:37:07 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-04 10:14:12 +00:00
|
|
|
if (virAsprintf(&key, "%d:%d", maj, min) < 0)
|
2013-01-02 14:37:07 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2015-07-06 17:08:32 +00:00
|
|
|
/*
|
|
|
|
* Make necessary checks for the need to check and for the current setting
|
|
|
|
* of the 'unpriv_sgio' value for the device_path passed.
|
2013-02-19 12:27:41 +00:00
|
|
|
*
|
2015-07-06 17:08:32 +00:00
|
|
|
* Returns:
|
|
|
|
* 0 - Success
|
|
|
|
* -1 - Some failure which would already have been messaged
|
|
|
|
* -2 - Mismatch with the "shared" sgio setting - needs to be messaged
|
|
|
|
* by caller since it has context of which type of disk resource is
|
|
|
|
* being used and in the future the hostdev information.
|
2013-02-19 12:27:41 +00:00
|
|
|
*/
|
|
|
|
static int
|
2015-07-06 17:08:32 +00:00
|
|
|
qemuCheckUnprivSGIO(virHashTablePtr sharedDevices,
|
|
|
|
const char *device_path,
|
|
|
|
int sgio)
|
2013-02-19 12:27:41 +00:00
|
|
|
{
|
|
|
|
char *sysfs_path = NULL;
|
|
|
|
char *key = NULL;
|
2013-02-20 07:43:55 +00:00
|
|
|
int val;
|
2014-08-07 12:56:30 +00:00
|
|
|
int ret = -1;
|
2013-05-03 18:07:44 +00:00
|
|
|
|
2015-07-06 17:08:32 +00:00
|
|
|
if (!(sysfs_path = virGetUnprivSGIOSysfsPath(device_path, NULL)))
|
2013-02-19 12:27:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-08-07 12:56:30 +00:00
|
|
|
/* It can't be conflict if unpriv_sgio is not supported by kernel. */
|
|
|
|
if (!virFileExists(sysfs_path)) {
|
|
|
|
ret = 0;
|
2013-02-19 12:27:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-07-06 17:08:32 +00:00
|
|
|
if (!(key = qemuGetSharedDeviceKey(device_path)))
|
2013-02-19 12:27:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-08-07 12:56:30 +00:00
|
|
|
/* It can't be conflict if no other domain is sharing it. */
|
|
|
|
if (!(virHashLookup(sharedDevices, key))) {
|
|
|
|
ret = 0;
|
2013-02-19 12:27:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-07-06 17:08:32 +00:00
|
|
|
if (virGetDeviceUnprivSGIO(device_path, NULL, &val) < 0)
|
2013-02-19 12:27:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-07-06 17:08:32 +00:00
|
|
|
/* Error message on failure needs to be handled in caller
|
|
|
|
* since there is more specific knowledge of device
|
|
|
|
*/
|
2014-08-07 12:56:30 +00:00
|
|
|
if (!((val == 0 &&
|
2015-07-06 17:08:32 +00:00
|
|
|
(sgio == VIR_DOMAIN_DEVICE_SGIO_FILTERED ||
|
|
|
|
sgio == VIR_DOMAIN_DEVICE_SGIO_DEFAULT)) ||
|
2014-08-07 12:56:30 +00:00
|
|
|
(val == 1 &&
|
2015-07-06 17:08:32 +00:00
|
|
|
sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED))) {
|
|
|
|
ret = -2;
|
2014-08-07 12:56:30 +00:00
|
|
|
goto cleanup;
|
2013-04-04 19:38:02 +00:00
|
|
|
}
|
|
|
|
|
2014-08-07 12:56:30 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2013-02-19 12:27:41 +00:00
|
|
|
VIR_FREE(sysfs_path);
|
|
|
|
VIR_FREE(key);
|
|
|
|
return ret;
|
|
|
|
}
|
qemu: Forbid "sgio" support for SCSI generic host device
The kernel didn't support the unprivileged SGIO for SCSI generic
device finally, and since it's unknow whether the way to support
unprivileged SGIO for SCSI generic device will be similar as for
SCSI block device or not, even it's simliar (I.e. via sysfs, for
SCSI block device, it's /sys/dev/block/8\:0/queue/unpriv_sgio,
for example), the file name might be different, So it's better not
guess what it should be like currently.
This patch removes the related code (mainly about the "shareable"
checking on the "sgio" setting, it's not supported at all, why
we leave checking code there? :-), and error out if "sgio" is
specified in the domain config.
2014-03-07 14:23:26 +00:00
|
|
|
|
2014-08-07 12:56:30 +00:00
|
|
|
|
2015-07-06 17:08:32 +00:00
|
|
|
/* Check if a shared device's setting conflicts with the conf
|
|
|
|
* used by other domain(s). Currently only checks the sgio
|
|
|
|
* setting. Note that this should only be called for disk with
|
|
|
|
* block source if the device type is disk.
|
|
|
|
*
|
|
|
|
* Returns 0 if no conflicts, otherwise returns -1.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
qemuCheckSharedDisk(virHashTablePtr sharedDevices,
|
|
|
|
virDomainDiskDefPtr disk)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((ret = qemuCheckUnprivSGIO(sharedDevices, disk->src->path,
|
|
|
|
disk->sgio)) < 0) {
|
|
|
|
if (ret == -2) {
|
|
|
|
if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_VOLUME) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("sgio of shared disk 'pool=%s' 'volume=%s' "
|
|
|
|
"conflicts with other active domains"),
|
|
|
|
disk->src->srcpool->pool,
|
|
|
|
disk->src->srcpool->volume);
|
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("sgio of shared disk '%s' conflicts with "
|
|
|
|
"other active domains"),
|
|
|
|
disk->src->path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-20 07:43:55 +00:00
|
|
|
bool
|
2013-05-03 18:07:35 +00:00
|
|
|
qemuSharedDeviceEntryDomainExists(qemuSharedDeviceEntryPtr entry,
|
|
|
|
const char *name,
|
|
|
|
int *idx)
|
2013-02-20 07:43:55 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < entry->ref; i++) {
|
|
|
|
if (STREQ(entry->domains[i], name)) {
|
|
|
|
if (idx)
|
|
|
|
*idx = i;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-03 18:07:35 +00:00
|
|
|
qemuSharedDeviceEntryFree(void *payload, const void *name ATTRIBUTE_UNUSED)
|
2013-02-20 07:43:55 +00:00
|
|
|
{
|
2013-05-03 18:07:35 +00:00
|
|
|
qemuSharedDeviceEntryPtr entry = payload;
|
2013-02-20 07:43:55 +00:00
|
|
|
size_t i;
|
|
|
|
|
2013-03-12 08:10:41 +00:00
|
|
|
if (!entry)
|
|
|
|
return;
|
|
|
|
|
2014-11-13 14:25:30 +00:00
|
|
|
for (i = 0; i < entry->ref; i++)
|
2013-02-20 07:43:55 +00:00
|
|
|
VIR_FREE(entry->domains[i]);
|
|
|
|
VIR_FREE(entry->domains);
|
|
|
|
VIR_FREE(entry);
|
|
|
|
}
|
|
|
|
|
2014-08-06 11:57:42 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
qemuSharedDeviceEntryInsert(virQEMUDriverPtr driver,
|
|
|
|
const char *key,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
qemuSharedDeviceEntry *entry = NULL;
|
|
|
|
|
|
|
|
if ((entry = virHashLookup(driver->sharedDevices, key))) {
|
|
|
|
/* Nothing to do if the shared scsi host device is already
|
|
|
|
* recorded in the table.
|
|
|
|
*/
|
2014-09-17 10:36:21 +00:00
|
|
|
if (!qemuSharedDeviceEntryDomainExists(entry, name, NULL)) {
|
|
|
|
if (VIR_EXPAND_N(entry->domains, entry->ref, 1) < 0 ||
|
|
|
|
VIR_STRDUP(entry->domains[entry->ref - 1], name) < 0) {
|
|
|
|
/* entry is owned by the hash table here */
|
|
|
|
entry = NULL;
|
|
|
|
goto error;
|
|
|
|
}
|
2014-08-06 11:57:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (VIR_ALLOC(entry) < 0 ||
|
|
|
|
VIR_ALLOC_N(entry->domains, 1) < 0 ||
|
|
|
|
VIR_STRDUP(entry->domains[0], name) < 0)
|
2014-09-17 10:36:21 +00:00
|
|
|
goto error;
|
2014-08-06 11:57:42 +00:00
|
|
|
|
|
|
|
entry->ref = 1;
|
|
|
|
|
|
|
|
if (virHashAddEntry(driver->sharedDevices, key, entry))
|
2014-09-17 10:36:21 +00:00
|
|
|
goto error;
|
2014-08-06 11:57:42 +00:00
|
|
|
}
|
|
|
|
|
2014-09-17 10:36:21 +00:00
|
|
|
return 0;
|
2014-08-06 11:57:42 +00:00
|
|
|
|
2014-09-17 10:36:21 +00:00
|
|
|
error:
|
2014-08-06 11:57:42 +00:00
|
|
|
qemuSharedDeviceEntryFree(entry, NULL);
|
2014-09-17 10:36:21 +00:00
|
|
|
return -1;
|
2014-08-06 11:57:42 +00:00
|
|
|
}
|
|
|
|
|
2014-08-07 13:20:40 +00:00
|
|
|
|
|
|
|
/* qemuAddSharedDisk:
|
2013-02-20 07:43:55 +00:00
|
|
|
* @driver: Pointer to qemu driver struct
|
2014-08-07 13:20:40 +00:00
|
|
|
* @src: disk source
|
2013-02-20 07:43:55 +00:00
|
|
|
* @name: The domain name
|
|
|
|
*
|
|
|
|
* Increase ref count and add the domain name into the list which
|
2013-05-03 18:07:37 +00:00
|
|
|
* records all the domains that use the shared device if the entry
|
2013-02-20 07:43:55 +00:00
|
|
|
* already exists, otherwise add a new entry.
|
2013-01-02 14:37:07 +00:00
|
|
|
*/
|
2014-08-07 13:20:40 +00:00
|
|
|
static int
|
|
|
|
qemuAddSharedDisk(virQEMUDriverPtr driver,
|
|
|
|
virDomainDiskDefPtr disk,
|
|
|
|
const char *name)
|
2013-01-02 14:37:07 +00:00
|
|
|
{
|
|
|
|
char *key = NULL;
|
2013-02-06 14:18:34 +00:00
|
|
|
int ret = -1;
|
2013-01-02 14:37:07 +00:00
|
|
|
|
2015-07-18 11:34:34 +00:00
|
|
|
if (!disk->src->shared || !virDomainDiskSourceIsBlockType(disk->src, false))
|
2014-08-07 13:20:40 +00:00
|
|
|
return 0;
|
2013-05-03 18:07:37 +00:00
|
|
|
|
2014-08-07 13:20:40 +00:00
|
|
|
qemuDriverLock(driver);
|
2013-05-03 18:07:37 +00:00
|
|
|
|
2014-08-07 13:20:40 +00:00
|
|
|
if (qemuCheckSharedDisk(driver->sharedDevices, disk) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(key = qemuGetSharedDeviceKey(virDomainDiskGetSource(disk))))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuSharedDeviceEntryInsert(driver, key, name) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
qemuDriverUnlock(driver);
|
|
|
|
VIR_FREE(key);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-16 17:33:37 +00:00
|
|
|
static bool
|
|
|
|
qemuIsSharedHostdev(virDomainHostdevDefPtr hostdev)
|
|
|
|
{
|
|
|
|
return (hostdev->shareable &&
|
|
|
|
(hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
|
|
|
|
hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI &&
|
|
|
|
hostdev->source.subsys.u.scsi.protocol !=
|
|
|
|
VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-07 16:16:38 +00:00
|
|
|
static char *
|
2015-06-16 17:58:44 +00:00
|
|
|
qemuGetHostdevPath(virDomainHostdevDefPtr hostdev)
|
2014-08-07 13:20:40 +00:00
|
|
|
{
|
|
|
|
virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi;
|
|
|
|
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
|
|
|
|
char *dev_name = NULL;
|
|
|
|
char *dev_path = NULL;
|
2013-02-19 12:27:41 +00:00
|
|
|
|
2014-08-07 13:20:40 +00:00
|
|
|
if (!(dev_name = virSCSIDeviceGetDevName(NULL,
|
|
|
|
scsihostsrc->adapter,
|
|
|
|
scsihostsrc->bus,
|
|
|
|
scsihostsrc->target,
|
|
|
|
scsihostsrc->unit)))
|
|
|
|
goto cleanup;
|
2013-05-03 18:07:37 +00:00
|
|
|
|
2015-06-16 17:58:44 +00:00
|
|
|
ignore_value(virAsprintf(&dev_path, "/dev/%s", dev_name));
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(dev_name);
|
|
|
|
return dev_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-07 16:16:38 +00:00
|
|
|
static int
|
|
|
|
qemuAddSharedHostdev(virQEMUDriverPtr driver,
|
|
|
|
virDomainHostdevDefPtr hostdev,
|
|
|
|
const char *name)
|
|
|
|
{
|
2015-06-16 15:34:06 +00:00
|
|
|
char *dev_path = NULL;
|
2014-08-07 16:16:38 +00:00
|
|
|
char *key = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
2015-06-16 17:33:37 +00:00
|
|
|
if (!qemuIsSharedHostdev(hostdev))
|
2014-08-07 16:16:38 +00:00
|
|
|
return 0;
|
|
|
|
|
2015-06-16 15:34:06 +00:00
|
|
|
if (!(dev_path = qemuGetHostdevPath(hostdev)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(key = qemuGetSharedDeviceKey(dev_path)))
|
|
|
|
goto cleanup;
|
2014-08-07 16:16:38 +00:00
|
|
|
|
|
|
|
qemuDriverLock(driver);
|
|
|
|
ret = qemuSharedDeviceEntryInsert(driver, key, name);
|
|
|
|
qemuDriverUnlock(driver);
|
|
|
|
|
2015-06-16 15:34:06 +00:00
|
|
|
cleanup:
|
|
|
|
VIR_FREE(dev_path);
|
2013-01-02 14:37:07 +00:00
|
|
|
VIR_FREE(key);
|
2013-02-06 14:18:34 +00:00
|
|
|
return ret;
|
2013-01-02 14:37:07 +00:00
|
|
|
}
|
|
|
|
|
2014-08-07 15:55:12 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
qemuSharedDeviceEntryRemove(virQEMUDriverPtr driver,
|
|
|
|
const char *key,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
qemuSharedDeviceEntryPtr entry = NULL;
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
if (!(entry = virHashLookup(driver->sharedDevices, key)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Nothing to do if the shared disk is not recored in the table. */
|
|
|
|
if (!qemuSharedDeviceEntryDomainExists(entry, name, &idx))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (entry->ref != 1)
|
|
|
|
VIR_DELETE_ELEMENT(entry->domains, idx, entry->ref);
|
|
|
|
else
|
|
|
|
ignore_value(virHashRemoveEntry(driver->sharedDevices, key));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-07 13:20:40 +00:00
|
|
|
/* qemuAddSharedDevice:
|
|
|
|
* @driver: Pointer to qemu driver struct
|
|
|
|
* @dev: The device def
|
|
|
|
* @name: The domain name
|
|
|
|
*
|
|
|
|
* Increase ref count and add the domain name into the list which
|
|
|
|
* records all the domains that use the shared device if the entry
|
|
|
|
* already exists, otherwise add a new entry.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
qemuAddSharedDevice(virQEMUDriverPtr driver,
|
|
|
|
virDomainDeviceDefPtr dev,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
/* Currently the only conflicts we have to care about for
|
|
|
|
* the shared disk and shared host device is "sgio" setting,
|
|
|
|
* which is only valid for block disk and scsi host device.
|
|
|
|
*/
|
|
|
|
if (dev->type == VIR_DOMAIN_DEVICE_DISK)
|
|
|
|
return qemuAddSharedDisk(driver, dev->data.disk, name);
|
|
|
|
else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV)
|
|
|
|
return qemuAddSharedHostdev(driver, dev->data.hostdev, name);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-07 13:20:40 +00:00
|
|
|
|
2014-08-08 08:55:30 +00:00
|
|
|
int
|
2014-08-07 13:20:40 +00:00
|
|
|
qemuRemoveSharedDisk(virQEMUDriverPtr driver,
|
|
|
|
virDomainDiskDefPtr disk,
|
|
|
|
const char *name)
|
2013-01-02 14:37:07 +00:00
|
|
|
{
|
|
|
|
char *key = NULL;
|
2013-02-06 14:18:34 +00:00
|
|
|
int ret = -1;
|
2013-01-02 14:37:07 +00:00
|
|
|
|
2015-07-18 11:34:34 +00:00
|
|
|
if (!disk->src->shared || !virDomainDiskSourceIsBlockType(disk->src, false))
|
2014-08-07 13:20:40 +00:00
|
|
|
return 0;
|
2013-05-03 18:07:37 +00:00
|
|
|
|
2014-08-07 13:20:40 +00:00
|
|
|
qemuDriverLock(driver);
|
2013-05-03 18:07:37 +00:00
|
|
|
|
2014-08-07 13:20:40 +00:00
|
|
|
if (!(key = qemuGetSharedDeviceKey(virDomainDiskGetSource(disk))))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuSharedDeviceEntryRemove(driver, key, name) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
qemuDriverUnlock(driver);
|
|
|
|
VIR_FREE(key);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
qemuRemoveSharedHostdev(virQEMUDriverPtr driver,
|
|
|
|
virDomainHostdevDefPtr hostdev,
|
|
|
|
const char *name)
|
|
|
|
{
|
2015-06-16 15:34:06 +00:00
|
|
|
char *dev_path = NULL;
|
2014-08-07 13:20:40 +00:00
|
|
|
char *key = NULL;
|
2015-07-09 17:08:49 +00:00
|
|
|
int ret = -1;
|
2014-08-07 13:20:40 +00:00
|
|
|
|
2015-06-16 17:33:37 +00:00
|
|
|
if (!qemuIsSharedHostdev(hostdev))
|
2013-02-19 12:27:40 +00:00
|
|
|
return 0;
|
|
|
|
|
2015-06-16 15:34:06 +00:00
|
|
|
if (!(dev_path = qemuGetHostdevPath(hostdev)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(key = qemuGetSharedDeviceKey(dev_path)))
|
|
|
|
goto cleanup;
|
2013-01-02 14:37:07 +00:00
|
|
|
|
2014-08-07 16:16:38 +00:00
|
|
|
qemuDriverLock(driver);
|
|
|
|
ret = qemuSharedDeviceEntryRemove(driver, key, name);
|
2013-02-06 18:17:20 +00:00
|
|
|
qemuDriverUnlock(driver);
|
2014-08-07 16:16:38 +00:00
|
|
|
|
2015-06-16 15:34:06 +00:00
|
|
|
cleanup:
|
|
|
|
VIR_FREE(dev_path);
|
2013-01-02 14:37:07 +00:00
|
|
|
VIR_FREE(key);
|
2013-02-06 14:18:34 +00:00
|
|
|
return ret;
|
2013-01-02 14:37:07 +00:00
|
|
|
}
|
2013-01-14 16:50:08 +00:00
|
|
|
|
2014-08-07 13:20:40 +00:00
|
|
|
|
|
|
|
/* qemuRemoveSharedDevice:
|
|
|
|
* @driver: Pointer to qemu driver struct
|
|
|
|
* @device: The device def
|
|
|
|
* @name: The domain name
|
|
|
|
*
|
|
|
|
* Decrease ref count and remove the domain name from the list which
|
|
|
|
* records all the domains that use the shared device if ref is not
|
|
|
|
* 1, otherwise remove the entry.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
qemuRemoveSharedDevice(virQEMUDriverPtr driver,
|
|
|
|
virDomainDeviceDefPtr dev,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
if (dev->type == VIR_DOMAIN_DEVICE_DISK)
|
|
|
|
return qemuRemoveSharedDisk(driver, dev->data.disk, name);
|
|
|
|
else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV)
|
|
|
|
return qemuRemoveSharedHostdev(driver, dev->data.hostdev, name);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-03 18:07:41 +00:00
|
|
|
int
|
2013-05-03 18:07:42 +00:00
|
|
|
qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
|
2013-05-03 18:07:41 +00:00
|
|
|
{
|
2013-05-03 18:07:42 +00:00
|
|
|
virDomainDiskDefPtr disk = NULL;
|
|
|
|
virDomainHostdevDefPtr hostdev = NULL;
|
2013-05-03 18:07:41 +00:00
|
|
|
char *sysfs_path = NULL;
|
conf: use disk source accessors in qemu/
Part of a series of cleanups to use new accessor methods.
* src/qemu/qemu_conf.c (qemuCheckSharedDevice)
(qemuAddSharedDevice, qemuRemoveSharedDevice, qemuSetUnprivSGIO):
Use accessors.
* src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse)
(qemuDomainObjCheckDiskTaint, qemuDomainSnapshotForEachQcow2Raw)
(qemuDomainCheckRemoveOptionalDisk, qemuDomainCheckDiskPresence)
(qemuDiskChainCheckBroken, qemuDomainDetermineDiskChain):
Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia)
(qemuDomainCheckEjectableMedia)
(qemuDomainAttachVirtioDiskDevice, qemuDomainAttachSCSIDisk)
(qemuDomainAttachUSBMassstorageDevice)
(qemuDomainAttachDeviceDiskLive, qemuDomainRemoveDiskDevice)
(qemuDomainDetachVirtioDiskDevice, qemuDomainDetachDiskDevice):
Likewise.
* src/qemu/qemu_migration.c (qemuMigrationStartNBDServer)
(qemuMigrationDriveMirror, qemuMigrationCancelDriveMirror)
(qemuMigrationIsSafe): Likewise.
* src/qemu/qemu_process.c (qemuProcessGetVolumeQcowPassphrase)
(qemuProcessHandleIOError, qemuProcessHandleBlockJob)
(qemuProcessInitPasswords): Likewise.
* src/qemu/qemu_driver.c (qemuDomainChangeDiskMediaLive)
(qemuDomainGetBlockInfo, qemuDiskPathToAlias): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-18 19:16:47 +00:00
|
|
|
const char *path = NULL;
|
2015-09-18 12:18:38 +00:00
|
|
|
int val = -1;
|
2015-07-06 14:33:04 +00:00
|
|
|
int ret = -1;
|
2013-05-03 18:07:41 +00:00
|
|
|
|
|
|
|
/* "sgio" is only valid for block disk; cdrom
|
|
|
|
* and floopy disk can have empty source.
|
|
|
|
*/
|
2013-05-03 18:07:42 +00:00
|
|
|
if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
|
|
|
|
disk = dev->data.disk;
|
|
|
|
|
2013-07-18 10:39:55 +00:00
|
|
|
if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN ||
|
2015-07-18 11:34:34 +00:00
|
|
|
!virDomainDiskSourceIsBlockType(disk->src, false))
|
2013-05-03 18:07:42 +00:00
|
|
|
return 0;
|
|
|
|
|
conf: use disk source accessors in qemu/
Part of a series of cleanups to use new accessor methods.
* src/qemu/qemu_conf.c (qemuCheckSharedDevice)
(qemuAddSharedDevice, qemuRemoveSharedDevice, qemuSetUnprivSGIO):
Use accessors.
* src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse)
(qemuDomainObjCheckDiskTaint, qemuDomainSnapshotForEachQcow2Raw)
(qemuDomainCheckRemoveOptionalDisk, qemuDomainCheckDiskPresence)
(qemuDiskChainCheckBroken, qemuDomainDetermineDiskChain):
Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia)
(qemuDomainCheckEjectableMedia)
(qemuDomainAttachVirtioDiskDevice, qemuDomainAttachSCSIDisk)
(qemuDomainAttachUSBMassstorageDevice)
(qemuDomainAttachDeviceDiskLive, qemuDomainRemoveDiskDevice)
(qemuDomainDetachVirtioDiskDevice, qemuDomainDetachDiskDevice):
Likewise.
* src/qemu/qemu_migration.c (qemuMigrationStartNBDServer)
(qemuMigrationDriveMirror, qemuMigrationCancelDriveMirror)
(qemuMigrationIsSafe): Likewise.
* src/qemu/qemu_process.c (qemuProcessGetVolumeQcowPassphrase)
(qemuProcessHandleIOError, qemuProcessHandleBlockJob)
(qemuProcessInitPasswords): Likewise.
* src/qemu/qemu_driver.c (qemuDomainChangeDiskMediaLive)
(qemuDomainGetBlockInfo, qemuDiskPathToAlias): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-18 19:16:47 +00:00
|
|
|
path = virDomainDiskGetSource(disk);
|
2013-05-03 18:07:42 +00:00
|
|
|
} else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
|
|
|
|
hostdev = dev->data.hostdev;
|
|
|
|
|
2015-06-16 17:33:37 +00:00
|
|
|
if (!qemuIsSharedHostdev(hostdev))
|
|
|
|
return 0;
|
2013-05-03 18:07:42 +00:00
|
|
|
|
2015-06-16 17:33:37 +00:00
|
|
|
if (hostdev->source.subsys.u.scsi.sgio) {
|
qemu: Forbid "sgio" support for SCSI generic host device
The kernel didn't support the unprivileged SGIO for SCSI generic
device finally, and since it's unknow whether the way to support
unprivileged SGIO for SCSI generic device will be similar as for
SCSI block device or not, even it's simliar (I.e. via sysfs, for
SCSI block device, it's /sys/dev/block/8\:0/queue/unpriv_sgio,
for example), the file name might be different, So it's better not
guess what it should be like currently.
This patch removes the related code (mainly about the "shareable"
checking on the "sgio" setting, it's not supported at all, why
we leave checking code there? :-), and error out if "sgio" is
specified in the domain config.
2014-03-07 14:23:26 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("'sgio' is not supported for SCSI "
|
|
|
|
"generic device yet "));
|
2013-05-03 18:07:42 +00:00
|
|
|
goto cleanup;
|
qemu: Forbid "sgio" support for SCSI generic host device
The kernel didn't support the unprivileged SGIO for SCSI generic
device finally, and since it's unknow whether the way to support
unprivileged SGIO for SCSI generic device will be similar as for
SCSI block device or not, even it's simliar (I.e. via sysfs, for
SCSI block device, it's /sys/dev/block/8\:0/queue/unpriv_sgio,
for example), the file name might be different, So it's better not
guess what it should be like currently.
This patch removes the related code (mainly about the "shareable"
checking on the "sgio" setting, it's not supported at all, why
we leave checking code there? :-), and error out if "sgio" is
specified in the domain config.
2014-03-07 14:23:26 +00:00
|
|
|
}
|
2013-05-03 18:07:42 +00:00
|
|
|
|
qemu: Forbid "sgio" support for SCSI generic host device
The kernel didn't support the unprivileged SGIO for SCSI generic
device finally, and since it's unknow whether the way to support
unprivileged SGIO for SCSI generic device will be similar as for
SCSI block device or not, even it's simliar (I.e. via sysfs, for
SCSI block device, it's /sys/dev/block/8\:0/queue/unpriv_sgio,
for example), the file name might be different, So it's better not
guess what it should be like currently.
This patch removes the related code (mainly about the "shareable"
checking on the "sgio" setting, it's not supported at all, why
we leave checking code there? :-), and error out if "sgio" is
specified in the domain config.
2014-03-07 14:23:26 +00:00
|
|
|
return 0;
|
2013-05-03 18:07:42 +00:00
|
|
|
} else {
|
2013-05-03 18:07:41 +00:00
|
|
|
return 0;
|
2013-05-03 18:07:42 +00:00
|
|
|
}
|
2013-05-03 18:07:41 +00:00
|
|
|
|
2015-07-06 14:33:04 +00:00
|
|
|
if (!(sysfs_path = virGetUnprivSGIOSysfsPath(path, NULL)))
|
2013-05-03 18:07:42 +00:00
|
|
|
goto cleanup;
|
2013-05-03 18:07:41 +00:00
|
|
|
|
|
|
|
/* By default, filter the SG_IO commands, i.e. set unpriv_sgio to 0. */
|
qemu: Forbid "sgio" support for SCSI generic host device
The kernel didn't support the unprivileged SGIO for SCSI generic
device finally, and since it's unknow whether the way to support
unprivileged SGIO for SCSI generic device will be similar as for
SCSI block device or not, even it's simliar (I.e. via sysfs, for
SCSI block device, it's /sys/dev/block/8\:0/queue/unpriv_sgio,
for example), the file name might be different, So it's better not
guess what it should be like currently.
This patch removes the related code (mainly about the "shareable"
checking on the "sgio" setting, it's not supported at all, why
we leave checking code there? :-), and error out if "sgio" is
specified in the domain config.
2014-03-07 14:23:26 +00:00
|
|
|
val = (disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED);
|
2013-05-03 18:07:41 +00:00
|
|
|
|
|
|
|
/* Do not do anything if unpriv_sgio is not supported by the kernel and the
|
|
|
|
* whitelist is enabled. But if requesting unfiltered access, always call
|
|
|
|
* virSetDeviceUnprivSGIO, to report an error for unsupported unpriv_sgio.
|
|
|
|
*/
|
2015-09-18 12:18:38 +00:00
|
|
|
if ((virFileExists(sysfs_path) || val == 1) &&
|
|
|
|
virSetDeviceUnprivSGIO(path, NULL, val) < 0)
|
2015-07-06 14:33:04 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
2013-05-03 18:07:41 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2013-05-03 18:07:41 +00:00
|
|
|
VIR_FREE(sysfs_path);
|
|
|
|
return ret;
|
|
|
|
}
|
2013-02-06 14:18:34 +00:00
|
|
|
|
2013-01-14 16:50:08 +00:00
|
|
|
int qemuDriverAllocateID(virQEMUDriverPtr driver)
|
|
|
|
{
|
2015-07-28 15:33:53 +00:00
|
|
|
return virAtomicIntInc(&driver->lastvmid);
|
2013-01-14 16:50:08 +00:00
|
|
|
}
|
2013-04-04 19:38:00 +00:00
|
|
|
|
2013-11-25 16:26:02 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
qemuTranslateSnapshotDiskSourcePool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainSnapshotDiskDefPtr def)
|
|
|
|
{
|
2014-05-21 21:21:02 +00:00
|
|
|
if (def->src->type != VIR_STORAGE_TYPE_VOLUME)
|
2013-11-25 16:26:02 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Snapshots are not yet supported with 'pool' volumes"));
|
|
|
|
return -1;
|
|
|
|
}
|
2014-07-23 15:37:18 +00:00
|
|
|
|
|
|
|
char *
|
|
|
|
qemuGetHugepagePath(virHugeTLBFSPtr hugepage)
|
|
|
|
{
|
|
|
|
char *ret;
|
|
|
|
|
|
|
|
if (virAsprintf(&ret, "%s/libvirt/qemu", hugepage->mnt_dir) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
qemuGetDefaultHugepath(virHugeTLBFSPtr hugetlbfs,
|
|
|
|
size_t nhugetlbfs)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < nhugetlbfs; i++)
|
|
|
|
if (hugetlbfs[i].deflt)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i == nhugetlbfs)
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
return qemuGetHugepagePath(&hugetlbfs[i]);
|
|
|
|
}
|