2008-03-21 15:03:37 +00:00
|
|
|
/*
|
2010-11-16 14:54:17 +00:00
|
|
|
* Copyright (C) 2010 Red Hat, Inc.
|
2008-03-21 15:03:37 +00:00
|
|
|
* Copyright IBM Corp. 2008
|
|
|
|
*
|
|
|
|
* lxc_conf.c: config functions for managing linux containers
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* David L. Leskovec <dlesko at linux.vnet.ibm.com>
|
|
|
|
*
|
|
|
|
* 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/>.
|
2008-03-21 15:03:37 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* includes */
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "lxc_conf.h"
|
2013-03-05 15:17:24 +00:00
|
|
|
#include "lxc_domain.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-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-12-12 16:35:35 +00:00
|
|
|
#include "virconf.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2012-12-13 18:01:25 +00:00
|
|
|
#include "viruuid.h"
|
2010-11-16 14:54:17 +00:00
|
|
|
#include "configmake.h"
|
2011-02-23 17:17:53 +00:00
|
|
|
#include "lxc_container.h"
|
2011-11-29 15:28:26 +00:00
|
|
|
#include "virnodesuspend.h"
|
2013-05-03 12:43:39 +00:00
|
|
|
#include "virstring.h"
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2009-01-29 12:10:32 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_LXC
|
|
|
|
|
2013-07-16 15:45:05 +00:00
|
|
|
static virClassPtr virLXCDriverConfigClass;
|
|
|
|
static void virLXCDriverConfigDispose(void *obj);
|
|
|
|
|
|
|
|
static int virLXCConfigOnceInit(void)
|
|
|
|
{
|
|
|
|
if (!(virLXCDriverConfigClass = virClassNew(virClassForObject(),
|
|
|
|
"virLXCDriverConfig",
|
|
|
|
sizeof(virLXCDriverConfig),
|
|
|
|
virLXCDriverConfigDispose)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_ONCE_GLOBAL_INIT(virLXCConfig)
|
|
|
|
|
Fix default console type setting
The default console type may vary based on the OS type. ie a Xen
paravirt guests wants a 'xen' console, while a fullvirt guests
wants a 'serial' console.
A plain integer default console type in the capabilities does
not suffice. Instead introduce a callback that is passed the
OS type.
* src/conf/capabilities.h: Use a callback for default console
type
* src/conf/domain_conf.c, src/conf/domain_conf.h: Use callback
for default console type. Add missing LXC/OpenVZ console types.
* src/esx/esx_driver.c, src/libxl/libxl_conf.c,
src/lxc/lxc_conf.c, src/openvz/openvz_conf.c,
src/phyp/phyp_driver.c, src/qemu/qemu_capabilities.c,
src/uml/uml_conf.c, src/vbox/vbox_tmpl.c,
src/vmware/vmware_conf.c, src/xen/xen_hypervisor.c,
src/xenapi/xenapi_driver.c: Set default console type callback
2011-10-20 13:56:20 +00:00
|
|
|
|
2008-03-21 15:03:37 +00:00
|
|
|
/* Functions */
|
2013-07-15 09:43:10 +00:00
|
|
|
virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver)
|
2008-03-21 15:03:37 +00:00
|
|
|
{
|
2008-08-13 12:50:55 +00:00
|
|
|
virCapsPtr caps;
|
|
|
|
virCapsGuestPtr guest;
|
2012-12-10 22:28:09 +00:00
|
|
|
virArch altArch;
|
2008-06-05 06:03:00 +00:00
|
|
|
|
2012-12-10 22:28:09 +00:00
|
|
|
if ((caps = virCapabilitiesNew(virArchFromHost(),
|
2008-08-13 12:50:55 +00:00
|
|
|
0, 0)) == NULL)
|
2010-05-25 14:33:51 +00:00
|
|
|
goto error;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2009-08-13 10:56:31 +00:00
|
|
|
/* Some machines have problematic NUMA toplogy causing
|
|
|
|
* unexpected failures. We don't want to break the QEMU
|
|
|
|
* driver in this scenario, so log errors & carry on
|
|
|
|
*/
|
|
|
|
if (nodeCapsInitNUMA(caps) < 0) {
|
|
|
|
virCapabilitiesFreeNUMAInfo(caps);
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
|
2009-08-13 10:56:31 +00:00
|
|
|
}
|
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
|
|
|
|
2011-11-29 15:28:26 +00:00
|
|
|
if (virNodeSuspendGetTargetMask(&caps->host.powerMgmt) < 0)
|
|
|
|
VIR_WARN("Failed to get host power management capabilities");
|
|
|
|
|
2010-05-25 14:33:51 +00:00
|
|
|
if (virGetHostUUID(caps->host.host_uuid)) {
|
2012-07-13 12:59:51 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("cannot get the host uuid"));
|
2010-05-25 14:33:51 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
if ((guest = virCapabilitiesAddGuest(caps,
|
|
|
|
"exe",
|
2012-12-10 22:28:09 +00:00
|
|
|
caps->host.arch,
|
2010-11-16 14:54:17 +00:00
|
|
|
LIBEXECDIR "/libvirt_lxc",
|
2008-08-13 12:50:55 +00:00
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL)) == NULL)
|
2010-05-25 14:33:51 +00:00
|
|
|
goto error;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
if (virCapabilitiesAddGuestDomain(guest,
|
|
|
|
"lxc",
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL) == NULL)
|
2010-05-25 14:33:51 +00:00
|
|
|
goto error;
|
2009-06-16 15:27:33 +00:00
|
|
|
|
2011-02-23 17:17:53 +00:00
|
|
|
/* On 64-bit hosts, we can use personality() to request a 32bit process */
|
2012-12-10 22:28:09 +00:00
|
|
|
if ((altArch = lxcContainerGetAlt32bitArch(caps->host.arch)) != VIR_ARCH_NONE) {
|
2011-02-23 17:17:53 +00:00
|
|
|
if ((guest = virCapabilitiesAddGuest(caps,
|
|
|
|
"exe",
|
|
|
|
altArch,
|
|
|
|
LIBEXECDIR "/libvirt_lxc",
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL)) == NULL)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (virCapabilitiesAddGuestDomain(guest,
|
|
|
|
"lxc",
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL) == NULL)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2012-01-25 14:12:53 +00:00
|
|
|
if (driver) {
|
|
|
|
/* Security driver data */
|
|
|
|
const char *doi, *model;
|
|
|
|
|
|
|
|
doi = virSecurityManagerGetDOI(driver->securityManager);
|
|
|
|
model = virSecurityManagerGetModel(driver->securityManager);
|
2013-07-15 13:36:04 +00:00
|
|
|
/* Allocate the primary security driver for LXC. */
|
|
|
|
if (VIR_ALLOC(caps->host.secModels) < 0)
|
|
|
|
goto error;
|
|
|
|
caps->host.nsecModels = 1;
|
|
|
|
if (VIR_STRDUP(caps->host.secModels[0].model, model) < 0)
|
|
|
|
goto error;
|
|
|
|
if (VIR_STRDUP(caps->host.secModels[0].doi, doi) < 0)
|
|
|
|
goto error;
|
2012-01-25 14:12:53 +00:00
|
|
|
|
|
|
|
VIR_DEBUG("Initialized caps for security driver \"%s\" with "
|
|
|
|
"DOI \"%s\"", model, doi);
|
|
|
|
} else {
|
|
|
|
VIR_INFO("No driver, not initializing security driver");
|
|
|
|
}
|
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
return caps;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2010-05-25 14:33:51 +00:00
|
|
|
error:
|
2013-02-01 12:26:18 +00:00
|
|
|
virObjectUnref(caps);
|
2008-03-21 15:03:37 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-05 15:17:24 +00:00
|
|
|
|
2013-07-15 09:43:10 +00:00
|
|
|
/**
|
|
|
|
* virLXCDriverGetCapabilities:
|
|
|
|
*
|
|
|
|
* 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 virLXCDriverGetCapabilities(virLXCDriverPtr driver,
|
|
|
|
bool refresh)
|
|
|
|
{
|
2013-07-17 07:20:26 +00:00
|
|
|
virCapsPtr ret;
|
2013-07-15 09:43:10 +00:00
|
|
|
if (refresh) {
|
|
|
|
virCapsPtr caps = NULL;
|
|
|
|
if ((caps = virLXCDriverCapsInit(driver)) == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2013-07-17 07:20:26 +00:00
|
|
|
lxcDriverLock(driver);
|
2013-07-15 09:43:10 +00:00
|
|
|
virObjectUnref(driver->caps);
|
|
|
|
driver->caps = caps;
|
2013-07-17 07:20:26 +00:00
|
|
|
} else {
|
|
|
|
lxcDriverLock(driver);
|
2013-07-15 09:43:10 +00:00
|
|
|
}
|
|
|
|
|
2013-07-17 07:20:26 +00:00
|
|
|
ret = virObjectRef(driver->caps);
|
|
|
|
lxcDriverUnlock(driver);
|
|
|
|
return ret;
|
2013-07-15 09:43:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-31 18:03:42 +00:00
|
|
|
virDomainXMLOptionPtr
|
2013-03-05 15:17:24 +00:00
|
|
|
lxcDomainXMLConfInit(void)
|
|
|
|
{
|
2013-03-11 11:12:08 +00:00
|
|
|
return virDomainXMLOptionNew(&virLXCDriverDomainDefParserConfig,
|
2013-02-19 16:29:39 +00:00
|
|
|
&virLXCDriverPrivateDataCallbacks,
|
|
|
|
NULL);
|
2013-03-05 15:17:24 +00:00
|
|
|
}
|
|
|
|
|
2013-03-11 11:12:08 +00:00
|
|
|
|
2013-07-16 15:45:05 +00:00
|
|
|
virLXCDriverConfigPtr
|
|
|
|
virLXCDriverConfigNew(void)
|
2008-03-21 15:03:37 +00:00
|
|
|
{
|
2013-07-16 15:45:05 +00:00
|
|
|
virLXCDriverConfigPtr cfg;
|
|
|
|
|
|
|
|
if (virLXCConfigInitialize() < 0)
|
|
|
|
return NULL;
|
2009-10-08 15:40:14 +00:00
|
|
|
|
2013-07-16 15:45:05 +00:00
|
|
|
if (!(cfg = virObjectNew(virLXCDriverConfigClass)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
cfg->securityDefaultConfined = false;
|
|
|
|
cfg->securityRequireConfined = false;
|
2012-01-25 14:12:53 +00:00
|
|
|
|
2008-03-21 15:03:37 +00:00
|
|
|
/* Set the container configuration directory */
|
2013-07-16 15:45:05 +00:00
|
|
|
if (VIR_STRDUP(cfg->configDir, LXC_CONFIG_DIR) < 0)
|
2013-05-03 12:43:39 +00:00
|
|
|
goto error;
|
2013-07-16 15:45:05 +00:00
|
|
|
if (VIR_STRDUP(cfg->stateDir, LXC_STATE_DIR) < 0)
|
2013-05-03 12:43:39 +00:00
|
|
|
goto error;
|
2013-07-16 15:45:05 +00:00
|
|
|
if (VIR_STRDUP(cfg->logDir, LXC_LOG_DIR) < 0)
|
2013-05-03 12:43:39 +00:00
|
|
|
goto error;
|
2013-07-16 15:45:05 +00:00
|
|
|
if (VIR_STRDUP(cfg->autostartDir, LXC_AUTOSTART_DIR) < 0)
|
2013-05-03 12:43:39 +00:00
|
|
|
goto error;
|
2009-10-21 11:32:20 +00:00
|
|
|
|
2013-07-16 15:45:05 +00:00
|
|
|
return cfg;
|
|
|
|
error:
|
|
|
|
virObjectUnref(cfg);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-06-05 06:03:00 +00:00
|
|
|
|
2013-07-16 15:45:05 +00:00
|
|
|
int
|
|
|
|
virLXCLoadDriverConfig(virLXCDriverConfigPtr cfg,
|
|
|
|
const char *filename)
|
|
|
|
{
|
|
|
|
virConfPtr conf;
|
|
|
|
virConfValuePtr p;
|
2009-10-08 15:40:14 +00:00
|
|
|
|
|
|
|
/* Avoid error from non-existant or unreadable file. */
|
2012-10-17 09:23:12 +00:00
|
|
|
if (access(filename, R_OK) == -1)
|
2009-11-10 11:56:11 +00:00
|
|
|
goto done;
|
2009-10-08 15:40:14 +00:00
|
|
|
conf = virConfReadFile(filename, 0);
|
|
|
|
if (!conf)
|
2009-11-10 11:56:11 +00:00
|
|
|
goto done;
|
2009-10-08 15:40:14 +00:00
|
|
|
|
2012-01-25 14:12:53 +00:00
|
|
|
#define CHECK_TYPE(name,typ) if (p && p->type != (typ)) { \
|
2012-07-13 12:59:51 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, \
|
|
|
|
"%s: %s: expected type " #typ, \
|
|
|
|
filename, (name)); \
|
2012-01-25 14:12:53 +00:00
|
|
|
virConfFree(conf); \
|
|
|
|
return -1; \
|
|
|
|
}
|
|
|
|
|
2009-10-08 15:40:14 +00:00
|
|
|
p = virConfGetValue(conf, "log_with_libvirtd");
|
2012-10-17 09:23:12 +00:00
|
|
|
CHECK_TYPE("log_with_libvirtd", VIR_CONF_LONG);
|
2013-07-16 15:45:05 +00:00
|
|
|
if (p) cfg->log_libvirtd = p->l;
|
2012-01-25 14:12:53 +00:00
|
|
|
|
2012-10-17 09:23:12 +00:00
|
|
|
p = virConfGetValue(conf, "security_driver");
|
|
|
|
CHECK_TYPE("security_driver", VIR_CONF_STRING);
|
2012-01-25 14:12:53 +00:00
|
|
|
if (p && p->str) {
|
2013-07-16 15:45:05 +00:00
|
|
|
if (VIR_STRDUP(cfg->securityDriverName, p->str) < 0) {
|
2012-01-25 14:12:53 +00:00
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
2009-10-08 15:40:14 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 09:23:12 +00:00
|
|
|
p = virConfGetValue(conf, "security_default_confined");
|
|
|
|
CHECK_TYPE("security_default_confined", VIR_CONF_LONG);
|
2013-07-16 15:45:05 +00:00
|
|
|
if (p) cfg->securityDefaultConfined = p->l;
|
2012-01-25 14:12:53 +00:00
|
|
|
|
2012-10-17 09:23:12 +00:00
|
|
|
p = virConfGetValue(conf, "security_require_confined");
|
|
|
|
CHECK_TYPE("security_require_confined", VIR_CONF_LONG);
|
2013-07-16 15:45:05 +00:00
|
|
|
if (p) cfg->securityRequireConfined = p->l;
|
2012-01-25 14:12:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
#undef CHECK_TYPE
|
|
|
|
|
2009-10-08 15:40:14 +00:00
|
|
|
virConfFree(conf);
|
2009-11-10 11:56:11 +00:00
|
|
|
|
|
|
|
done:
|
2008-03-21 15:03:37 +00:00
|
|
|
return 0;
|
2013-07-16 15:45:05 +00:00
|
|
|
}
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2013-07-16 15:45:05 +00:00
|
|
|
virLXCDriverConfigPtr virLXCDriverGetConfig(virLXCDriverPtr driver)
|
|
|
|
{
|
2013-07-17 07:20:26 +00:00
|
|
|
virLXCDriverConfigPtr cfg;
|
|
|
|
lxcDriverLock(driver);
|
|
|
|
cfg = virObjectRef(driver->config);
|
|
|
|
lxcDriverUnlock(driver);
|
|
|
|
return cfg;
|
2013-07-16 15:45:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
virLXCDriverConfigDispose(void *obj)
|
|
|
|
{
|
|
|
|
virLXCDriverConfigPtr cfg = obj;
|
|
|
|
|
|
|
|
VIR_FREE(cfg->configDir);
|
|
|
|
VIR_FREE(cfg->autostartDir);
|
|
|
|
VIR_FREE(cfg->stateDir);
|
|
|
|
VIR_FREE(cfg->logDir);
|
|
|
|
VIR_FREE(cfg->securityDriverName);
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|