mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 02:51:16 +00:00
Linux container fixes, move driver in the daemon.
* src/lxc_conf.c src/lxc_conf.h src/lxc_driver.c src/remote_internal.c: applied patch from Dan Berrange to change the way the lxc driver works, migrating the support in the daemon, it also removes some compilation issues and teh way the configuration files are named. Daniel
This commit is contained in:
parent
ae15bc7245
commit
425cf2e792
@ -1,3 +1,10 @@
|
|||||||
|
Thu Mar 27 10:30:12 CET 2008 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
|
* src/lxc_conf.c src/lxc_conf.h src/lxc_driver.c src/remote_internal.c:
|
||||||
|
applied patch from Dan Berrange to change the way the lxc driver
|
||||||
|
works, migrating the support in the daemon, it also removes some
|
||||||
|
compilation issues and teh way the configuration files are named.
|
||||||
|
|
||||||
Thu Mar 27 09:09:34 CET 2008 Daniel Veillard <veillard@redhat.com>
|
Thu Mar 27 09:09:34 CET 2008 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
* src/storage_backend_iscsi.c: patch from Chris Lalancette to improve
|
* src/storage_backend_iscsi.c: patch from Chris Lalancette to improve
|
||||||
|
@ -593,7 +593,6 @@ int lxcSaveVMDef(virConnectPtr conn,
|
|||||||
lxc_vm_def_t *def)
|
lxc_vm_def_t *def)
|
||||||
{
|
{
|
||||||
int rc = -1;
|
int rc = -1;
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
||||||
|
|
||||||
if (vm->configFile[0] == '\0') {
|
if (vm->configFile[0] == '\0') {
|
||||||
if ((rc = virFileMakePath(driver->configDir))) {
|
if ((rc = virFileMakePath(driver->configDir))) {
|
||||||
@ -603,16 +602,15 @@ int lxcSaveVMDef(virConnectPtr conn,
|
|||||||
goto save_complete;
|
goto save_complete;
|
||||||
}
|
}
|
||||||
|
|
||||||
virUUIDFormat(def->uuid, uuidstr);
|
if (virFileBuildPath(driver->configDir, vm->def->name, ".xml",
|
||||||
if (virFileBuildPath(driver->configDir, uuidstr, ".xml",
|
|
||||||
vm->configFile, PATH_MAX) < 0) {
|
vm->configFile, PATH_MAX) < 0) {
|
||||||
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("cannot construct config file path"));
|
_("cannot construct config file path"));
|
||||||
goto save_complete;
|
goto save_complete;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(vm->configFileBase, uuidstr, PATH_MAX);
|
strncpy(vm->configFileBase, vm->def->name, PATH_MAX-1);
|
||||||
strncat(vm->configFileBase, ".xml", PATH_MAX - strlen(uuidstr));
|
strncat(vm->configFileBase, ".xml", PATH_MAX - strlen(vm->def->name)-1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -631,7 +629,6 @@ static lxc_vm_t * lxcLoadConfig(lxc_driver_t *driver,
|
|||||||
{
|
{
|
||||||
lxc_vm_def_t *containerDef;
|
lxc_vm_def_t *containerDef;
|
||||||
lxc_vm_t * vm;
|
lxc_vm_t * vm;
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
||||||
|
|
||||||
containerDef = lxcParseVMDef(NULL, xmlData, file);
|
containerDef = lxcParseVMDef(NULL, xmlData, file);
|
||||||
if (NULL == containerDef) {
|
if (NULL == containerDef) {
|
||||||
@ -639,9 +636,8 @@ static lxc_vm_t * lxcLoadConfig(lxc_driver_t *driver,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
virUUIDFormat(containerDef->uuid, uuidstr);
|
if (!virFileMatchesNameSuffix(file, containerDef->name, ".xml")) {
|
||||||
if (!virFileMatchesNameSuffix(file, uuidstr, ".xml")) {
|
DEBUG0("Container name does not match config file name");
|
||||||
DEBUG0("Container uuid does not match config file name");
|
|
||||||
lxcFreeVMDef(containerDef);
|
lxcFreeVMDef(containerDef);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -662,14 +658,12 @@ static lxc_vm_t * lxcLoadConfig(lxc_driver_t *driver,
|
|||||||
return vm;
|
return vm;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lxcLoadDriverConfig(virConnectPtr conn)
|
int lxcLoadDriverConfig(lxc_driver_t *driver)
|
||||||
{
|
{
|
||||||
lxc_driver_t *driverPtr = (lxc_driver_t*)conn->privateData;
|
|
||||||
|
|
||||||
/* Set the container configuration directory */
|
/* Set the container configuration directory */
|
||||||
driverPtr->configDir = strdup(SYSCONF_DIR "/libvirt/lxc");
|
driver->configDir = strdup(SYSCONF_DIR "/libvirt/lxc");
|
||||||
if (NULL == driverPtr->configDir) {
|
if (NULL == driver->configDir) {
|
||||||
lxcError(conn, NULL, VIR_ERR_NO_MEMORY, "configDir");
|
lxcError(NULL, NULL, VIR_ERR_NO_MEMORY, "configDir");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -702,19 +696,18 @@ load_complete:
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lxcLoadContainerInfo(virConnectPtr conn)
|
int lxcLoadContainerInfo(lxc_driver_t *driver)
|
||||||
{
|
{
|
||||||
int rc = -1;
|
int rc = -1;
|
||||||
lxc_driver_t *driverPtr = (lxc_driver_t*)conn->privateData;
|
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *dirEntry;
|
struct dirent *dirEntry;
|
||||||
|
|
||||||
if (!(dir = opendir(driverPtr->configDir))) {
|
if (!(dir = opendir(driver->configDir))) {
|
||||||
if (ENOENT == errno) {
|
if (ENOENT == errno) {
|
||||||
/* no config dir => no containers */
|
/* no config dir => no containers */
|
||||||
rc = 0;
|
rc = 0;
|
||||||
} else {
|
} else {
|
||||||
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("failed to open config directory: %s"), strerror(errno));
|
_("failed to open config directory: %s"), strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -730,7 +723,7 @@ int lxcLoadContainerInfo(virConnectPtr conn)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
lxcLoadContainerConfigFile(driverPtr, dirEntry->d_name);
|
lxcLoadContainerConfigFile(driver, dirEntry->d_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
@ -758,12 +751,13 @@ char *lxcGenerateXML(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (lxcIsActiveVM(vm)) {
|
if (lxcIsActiveVM(vm)) {
|
||||||
if (virBufferVSprintf(buf, "<domain type='linuxcontainer' id='%d'>\n",
|
if (virBufferVSprintf(buf, "<domain type='%s' id='%d'>\n",
|
||||||
vm->def->id) < 0) {
|
LXC_DOMAIN_TYPE, vm->def->id) < 0) {
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (virBufferAddLit(buf, "<domain type='linuxcontainer'>\n") < 0) {
|
if (virBufferVSprintf(buf, "<domain type='%s'>\n",
|
||||||
|
LXC_DOMAIN_TYPE) < 0) {
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -940,3 +934,12 @@ int lxcDeleteConfig(virConnectPtr conn,
|
|||||||
|
|
||||||
#endif /* WITH_LXC */
|
#endif /* WITH_LXC */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Local variables:
|
||||||
|
* indent-tabs-mode: nil
|
||||||
|
* c-indent-level: 4
|
||||||
|
* c-basic-offset: 4
|
||||||
|
* tab-width: 4
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
|
@ -102,12 +102,12 @@ int lxcSaveVMDef(virConnectPtr conn,
|
|||||||
lxc_driver_t *driver,
|
lxc_driver_t *driver,
|
||||||
lxc_vm_t *vm,
|
lxc_vm_t *vm,
|
||||||
lxc_vm_def_t *def);
|
lxc_vm_def_t *def);
|
||||||
int lxcLoadDriverConfig(virConnectPtr conn);
|
int lxcLoadDriverConfig(lxc_driver_t *driver);
|
||||||
int lxcSaveConfig(virConnectPtr conn,
|
int lxcSaveConfig(virConnectPtr conn,
|
||||||
lxc_driver_t *driver,
|
lxc_driver_t *driver,
|
||||||
lxc_vm_t *vm,
|
lxc_vm_t *vm,
|
||||||
lxc_vm_def_t *def);
|
lxc_vm_def_t *def);
|
||||||
int lxcLoadContainerInfo(virConnectPtr conn);
|
int lxcLoadContainerInfo(lxc_driver_t *driver);
|
||||||
int lxcLoadContainerConfigFile(lxc_driver_t *driver,
|
int lxcLoadContainerConfigFile(lxc_driver_t *driver,
|
||||||
const char *file);
|
const char *file);
|
||||||
lxc_vm_t * lxcAssignVMDef(virConnectPtr conn,
|
lxc_vm_t * lxcAssignVMDef(virConnectPtr conn,
|
||||||
|
101
src/lxc_driver.c
101
src/lxc_driver.c
@ -41,8 +41,27 @@
|
|||||||
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
|
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
|
||||||
#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
|
#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
|
||||||
|
|
||||||
static int lxcStartup(virConnectPtr conn);
|
/*
|
||||||
static int lxcShutdown(virConnectPtr conn);
|
* GLibc headers are behind the kernel, so we define these
|
||||||
|
* constants if they're not present already.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CLONE_NEWPID
|
||||||
|
#define CLONE_NEWPID 0x20000000
|
||||||
|
#endif
|
||||||
|
#ifndef CLONE_NEWUTS
|
||||||
|
#define CLONE_NEWUTS 0x04000000
|
||||||
|
#endif
|
||||||
|
#ifndef CLONE_NEWUSER
|
||||||
|
#define CLONE_NEWUSER 0x10000000
|
||||||
|
#endif
|
||||||
|
#ifndef CLONE_NEWIPC
|
||||||
|
#define CLONE_NEWIPC 0x08000000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int lxcStartup(void);
|
||||||
|
static int lxcShutdown(void);
|
||||||
|
static lxc_driver_t *lxc_driver;
|
||||||
|
|
||||||
/* Functions */
|
/* Functions */
|
||||||
static int lxcDummyChild( void *argv ATTRIBUTE_UNUSED )
|
static int lxcDummyChild( void *argv ATTRIBUTE_UNUSED )
|
||||||
@ -105,6 +124,9 @@ static virDrvOpenStatus lxcOpen(virConnectPtr conn,
|
|||||||
goto declineConnection;
|
goto declineConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lxc_driver == NULL)
|
||||||
|
goto declineConnection;
|
||||||
|
|
||||||
/* Verify uri was specified */
|
/* Verify uri was specified */
|
||||||
if ((NULL == uri) || (NULL == uri->scheme)) {
|
if ((NULL == uri) || (NULL == uri->scheme)) {
|
||||||
goto declineConnection;
|
goto declineConnection;
|
||||||
@ -115,15 +137,7 @@ static virDrvOpenStatus lxcOpen(virConnectPtr conn,
|
|||||||
goto declineConnection;
|
goto declineConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check that this is a container enabled kernel */
|
conn->privateData = lxc_driver;
|
||||||
if(0 != lxcCheckContainerSupport()) {
|
|
||||||
goto declineConnection;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* initialize driver data */
|
|
||||||
if (0 > lxcStartup(conn)) {
|
|
||||||
goto declineConnection;
|
|
||||||
}
|
|
||||||
|
|
||||||
return VIR_DRV_OPEN_SUCCESS;
|
return VIR_DRV_OPEN_SUCCESS;
|
||||||
|
|
||||||
@ -133,7 +147,8 @@ declineConnection:
|
|||||||
|
|
||||||
static int lxcClose(virConnectPtr conn)
|
static int lxcClose(virConnectPtr conn)
|
||||||
{
|
{
|
||||||
return lxcShutdown(conn);
|
conn->privateData = NULL;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static virDomainPtr lxcDomainLookupByID(virConnectPtr conn,
|
static virDomainPtr lxcDomainLookupByID(virConnectPtr conn,
|
||||||
@ -360,26 +375,29 @@ static char *lxcDomainDumpXML(virDomainPtr dom,
|
|||||||
return lxcGenerateXML(dom->conn, driver, vm, vm->def);
|
return lxcGenerateXML(dom->conn, driver, vm, vm->def);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lxcStartup(virConnectPtr conn)
|
|
||||||
{
|
|
||||||
lxc_driver_t *driver;
|
|
||||||
|
|
||||||
driver = calloc(1, sizeof(lxc_driver_t));
|
static int lxcStartup(void)
|
||||||
if (NULL == driver) {
|
{
|
||||||
|
lxc_driver = calloc(1, sizeof(lxc_driver_t));
|
||||||
|
if (NULL == lxc_driver) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check that this is a container enabled kernel */
|
||||||
|
if(0 != lxcCheckContainerSupport()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
conn->privateData = driver;
|
|
||||||
|
|
||||||
/* Call function to load lxc driver configuration information */
|
/* Call function to load lxc driver configuration information */
|
||||||
if (lxcLoadDriverConfig(conn) < 0) {
|
if (lxcLoadDriverConfig(lxc_driver) < 0) {
|
||||||
lxcShutdown(conn);
|
lxcShutdown();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Call function to load the container configuration files */
|
/* Call function to load the container configuration files */
|
||||||
if (lxcLoadContainerInfo(conn) < 0) {
|
if (lxcLoadContainerInfo(lxc_driver) < 0) {
|
||||||
lxcShutdown(conn);
|
lxcShutdown();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,19 +410,37 @@ static void lxcFreeDriver(lxc_driver_t *driver)
|
|||||||
free(driver);
|
free(driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lxcShutdown(virConnectPtr conn)
|
static int lxcShutdown(void)
|
||||||
{
|
{
|
||||||
lxc_driver_t *driver = (lxc_driver_t *)conn->privateData;
|
lxc_vm_t *vms = lxc_driver->vms;
|
||||||
lxc_vm_t *vms = driver->vms;
|
|
||||||
|
|
||||||
lxcFreeVMs(vms);
|
lxcFreeVMs(vms);
|
||||||
driver->vms = NULL;
|
lxc_driver->vms = NULL;
|
||||||
lxcFreeDriver(driver);
|
lxcFreeDriver(lxc_driver);
|
||||||
conn->privateData = NULL;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* lxcActive:
|
||||||
|
*
|
||||||
|
* Checks if the LXC daemon is active, i.e. has an active domain
|
||||||
|
*
|
||||||
|
* Returns 1 if active, 0 otherwise
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
lxcActive(void) {
|
||||||
|
/* If we've any active networks or guests, then we
|
||||||
|
* mark this driver as active
|
||||||
|
*/
|
||||||
|
if (lxc_driver->nactivevms)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
/* Otherwise we're happy to deal with a shutdown */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Function Tables */
|
/* Function Tables */
|
||||||
static virDriver lxcDriver = {
|
static virDriver lxcDriver = {
|
||||||
VIR_DRV_LXC, /* the number virDrvNo */
|
VIR_DRV_LXC, /* the number virDrvNo */
|
||||||
@ -466,9 +502,18 @@ static virDriver lxcDriver = {
|
|||||||
NULL, /* getFreeMemory */
|
NULL, /* getFreeMemory */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static virStateDriver lxcStateDriver = {
|
||||||
|
lxcStartup,
|
||||||
|
lxcShutdown,
|
||||||
|
NULL, /* reload */
|
||||||
|
lxcActive,
|
||||||
|
};
|
||||||
|
|
||||||
int lxcRegister(void)
|
int lxcRegister(void)
|
||||||
{
|
{
|
||||||
virRegisterDriver(&lxcDriver);
|
virRegisterDriver(&lxcDriver);
|
||||||
|
virRegisterStateDriver(&lxcStateDriver);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -843,6 +843,12 @@ remoteOpen (virConnectPtr conn,
|
|||||||
rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
|
rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#if WITH_LXC
|
||||||
|
if (uri &&
|
||||||
|
uri->scheme && STREQ (uri->scheme, "lxc")) {
|
||||||
|
rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
priv->magic = DEAD;
|
priv->magic = DEAD;
|
||||||
priv->sock = -1;
|
priv->sock = -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user