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-07-21 10:06:23 +00:00
|
|
|
* License along with this library; If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
2008-03-21 15:03:37 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* includes */
|
|
|
|
#include <config.h>
|
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
#include <sys/utsname.h>
|
2008-03-21 15:03:37 +00:00
|
|
|
|
|
|
|
#include "lxc_conf.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"
|
|
|
|
#include "virterror_internal.h"
|
2009-10-08 15:40:14 +00:00
|
|
|
#include "conf.h"
|
2009-11-10 11:56:11 +00:00
|
|
|
#include "memory.h"
|
2009-08-13 10:56:31 +00:00
|
|
|
#include "logging.h"
|
2010-05-25 14:33:51 +00:00
|
|
|
#include "uuid.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"
|
|
|
|
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2009-01-29 12:10:32 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_LXC
|
|
|
|
|
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
|
|
|
static int lxcDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_LXC;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-21 15:03:37 +00:00
|
|
|
/* Functions */
|
2012-01-25 14:12:53 +00:00
|
|
|
virCapsPtr lxcCapsInit(lxc_driver_t *driver)
|
2008-03-21 15:03:37 +00:00
|
|
|
{
|
2008-08-13 12:50:55 +00:00
|
|
|
struct utsname utsname;
|
|
|
|
virCapsPtr caps;
|
|
|
|
virCapsGuestPtr guest;
|
2011-02-23 17:17:53 +00:00
|
|
|
const char *altArch;
|
2008-06-05 06:03:00 +00:00
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
uname(&utsname);
|
2008-06-05 06:03:00 +00:00
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
if ((caps = virCapabilitiesNew(utsname.machine,
|
|
|
|
0, 0)) == NULL)
|
2010-05-25 14:33:51 +00:00
|
|
|
goto error;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
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
|
|
|
caps->defaultConsoleTargetType = lxcDefaultConsoleType;
|
|
|
|
|
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)) {
|
|
|
|
lxcError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("cannot get the host uuid"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2008-10-24 11:20:08 +00:00
|
|
|
/* XXX shouldn't 'borrow' KVM's prefix */
|
|
|
|
virCapabilitiesSetMacPrefix(caps, (unsigned char []){ 0x52, 0x54, 0x00 });
|
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
if ((guest = virCapabilitiesAddGuest(caps,
|
|
|
|
"exe",
|
|
|
|
utsname.machine,
|
2011-02-23 17:17:53 +00:00
|
|
|
sizeof(void*) == 4 ? 32 : 64,
|
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 */
|
|
|
|
if ((altArch = lxcContainerGetAlt32bitArch(utsname.machine)) != NULL) {
|
|
|
|
if ((guest = virCapabilitiesAddGuest(caps,
|
|
|
|
"exe",
|
|
|
|
altArch,
|
|
|
|
32,
|
|
|
|
LIBEXECDIR "/libvirt_lxc",
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL)) == NULL)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (virCapabilitiesAddGuestDomain(guest,
|
|
|
|
"lxc",
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL) == NULL)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2009-06-16 15:27:33 +00:00
|
|
|
/* LXC Requires an emulator in the XML */
|
|
|
|
virCapabilitiesSetEmulatorRequired(caps);
|
|
|
|
|
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);
|
|
|
|
if (STRNEQ(model, "none")) {
|
|
|
|
if (!(caps->host.secModel.model = strdup(model)))
|
|
|
|
goto no_memory;
|
|
|
|
if (!(caps->host.secModel.doi = strdup(doi)))
|
|
|
|
goto no_memory;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2012-01-25 14:12:53 +00:00
|
|
|
no_memory:
|
|
|
|
virReportOOMError();
|
|
|
|
|
2010-05-25 14:33:51 +00:00
|
|
|
error:
|
2008-08-13 12:50:55 +00:00
|
|
|
virCapabilitiesFree(caps);
|
2008-03-21 15:03:37 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-03-27 09:34:06 +00:00
|
|
|
int lxcLoadDriverConfig(lxc_driver_t *driver)
|
2008-03-21 15:03:37 +00:00
|
|
|
{
|
2009-10-08 15:40:14 +00:00
|
|
|
char *filename;
|
|
|
|
virConfPtr conf;
|
|
|
|
virConfValuePtr p;
|
|
|
|
|
2012-01-25 14:12:53 +00:00
|
|
|
driver->securityDefaultConfined = false;
|
|
|
|
driver->securityRequireConfined = false;
|
|
|
|
|
2008-03-21 15:03:37 +00:00
|
|
|
/* Set the container configuration directory */
|
2008-08-20 20:55:32 +00:00
|
|
|
if ((driver->configDir = strdup(LXC_CONFIG_DIR)) == NULL)
|
2008-08-13 10:52:15 +00:00
|
|
|
goto no_memory;
|
2008-08-20 20:55:32 +00:00
|
|
|
if ((driver->stateDir = strdup(LXC_STATE_DIR)) == NULL)
|
2008-08-13 10:52:15 +00:00
|
|
|
goto no_memory;
|
2008-08-20 20:55:32 +00:00
|
|
|
if ((driver->logDir = strdup(LXC_LOG_DIR)) == NULL)
|
2008-08-13 10:52:15 +00:00
|
|
|
goto no_memory;
|
2009-10-21 11:32:20 +00:00
|
|
|
if ((driver->autostartDir = strdup(LXC_AUTOSTART_DIR)) == NULL)
|
|
|
|
goto no_memory;
|
|
|
|
|
2008-06-05 06:03:00 +00:00
|
|
|
|
2010-11-16 14:54:17 +00:00
|
|
|
if ((filename = strdup(SYSCONFDIR "/libvirt/lxc.conf")) == NULL)
|
2009-10-08 15:40:14 +00:00
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
/* Avoid error from non-existant or unreadable file. */
|
|
|
|
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)) { \
|
|
|
|
lxcError(VIR_ERR_INTERNAL_ERROR, \
|
|
|
|
"%s: %s: expected type " #typ, \
|
|
|
|
filename, (name)); \
|
|
|
|
virConfFree(conf); \
|
|
|
|
return -1; \
|
|
|
|
}
|
|
|
|
|
2009-10-08 15:40:14 +00:00
|
|
|
p = virConfGetValue(conf, "log_with_libvirtd");
|
2012-01-25 14:12:53 +00:00
|
|
|
CHECK_TYPE ("log_with_libvirtd", VIR_CONF_LONG);
|
|
|
|
if (p) driver->log_libvirtd = p->l;
|
|
|
|
|
|
|
|
p = virConfGetValue (conf, "security_driver");
|
|
|
|
CHECK_TYPE ("security_driver", VIR_CONF_STRING);
|
|
|
|
if (p && p->str) {
|
|
|
|
if (!(driver->securityDriverName = strdup(p->str))) {
|
|
|
|
virReportOOMError();
|
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
2009-10-08 15:40:14 +00:00
|
|
|
}
|
|
|
|
|
2012-01-25 14:12:53 +00:00
|
|
|
p = virConfGetValue (conf, "security_default_confined");
|
|
|
|
CHECK_TYPE ("security_default_confined", VIR_CONF_LONG);
|
|
|
|
if (p) driver->securityDefaultConfined = p->l;
|
|
|
|
|
|
|
|
p = virConfGetValue (conf, "security_require_confined");
|
|
|
|
CHECK_TYPE ("security_require_confined", VIR_CONF_LONG);
|
|
|
|
if (p) driver->securityRequireConfined = p->l;
|
|
|
|
|
|
|
|
|
|
|
|
#undef CHECK_TYPE
|
|
|
|
|
2009-10-08 15:40:14 +00:00
|
|
|
virConfFree(conf);
|
2009-11-10 11:56:11 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
VIR_FREE(filename);
|
2008-03-21 15:03:37 +00:00
|
|
|
return 0;
|
2008-08-13 10:52:15 +00:00
|
|
|
|
|
|
|
no_memory:
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-08-13 10:52:15 +00:00
|
|
|
return -1;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|