+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>
* src/storage_backend_iscsi.c: patch from Chris Lalancette to improve
lxc_vm_def_t *def)
{
int rc = -1;
- char uuidstr[VIR_UUID_STRING_BUFLEN];
if (vm->configFile[0] == '\0') {
if ((rc = virFileMakePath(driver->configDir))) {
goto save_complete;
}
- virUUIDFormat(def->uuid, uuidstr);
- if (virFileBuildPath(driver->configDir, uuidstr, ".xml",
+ if (virFileBuildPath(driver->configDir, vm->def->name, ".xml",
vm->configFile, PATH_MAX) < 0) {
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
_("cannot construct config file path"));
goto save_complete;
}
- strncpy(vm->configFileBase, uuidstr, PATH_MAX);
- strncat(vm->configFileBase, ".xml", PATH_MAX - strlen(uuidstr));
+ strncpy(vm->configFileBase, vm->def->name, PATH_MAX-1);
+ strncat(vm->configFileBase, ".xml", PATH_MAX - strlen(vm->def->name)-1);
}
{
lxc_vm_def_t *containerDef;
lxc_vm_t * vm;
- char uuidstr[VIR_UUID_STRING_BUFLEN];
containerDef = lxcParseVMDef(NULL, xmlData, file);
if (NULL == containerDef) {
return NULL;
}
- virUUIDFormat(containerDef->uuid, uuidstr);
- if (!virFileMatchesNameSuffix(file, uuidstr, ".xml")) {
- DEBUG0("Container uuid does not match config file name");
+ if (!virFileMatchesNameSuffix(file, containerDef->name, ".xml")) {
+ DEBUG0("Container name does not match config file name");
lxcFreeVMDef(containerDef);
return NULL;
}
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 */
- driverPtr->configDir = strdup(SYSCONF_DIR "/libvirt/lxc");
- if (NULL == driverPtr->configDir) {
- lxcError(conn, NULL, VIR_ERR_NO_MEMORY, "configDir");
+ driver->configDir = strdup(SYSCONF_DIR "/libvirt/lxc");
+ if (NULL == driver->configDir) {
+ lxcError(NULL, NULL, VIR_ERR_NO_MEMORY, "configDir");
return -1;
}
return rc;
}
-int lxcLoadContainerInfo(virConnectPtr conn)
+int lxcLoadContainerInfo(lxc_driver_t *driver)
{
int rc = -1;
- lxc_driver_t *driverPtr = (lxc_driver_t*)conn->privateData;
DIR *dir;
struct dirent *dirEntry;
- if (!(dir = opendir(driverPtr->configDir))) {
+ if (!(dir = opendir(driver->configDir))) {
if (ENOENT == errno) {
/* no config dir => no containers */
rc = 0;
} else {
- lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
+ lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
_("failed to open config directory: %s"), strerror(errno));
}
continue;
}
- lxcLoadContainerConfigFile(driverPtr, dirEntry->d_name);
+ lxcLoadContainerConfigFile(driver, dirEntry->d_name);
}
closedir(dir);
}
if (lxcIsActiveVM(vm)) {
- if (virBufferVSprintf(buf, "<domain type='linuxcontainer' id='%d'>\n",
- vm->def->id) < 0) {
+ if (virBufferVSprintf(buf, "<domain type='%s' id='%d'>\n",
+ LXC_DOMAIN_TYPE, vm->def->id) < 0) {
goto no_memory;
}
} else {
- if (virBufferAddLit(buf, "<domain type='linuxcontainer'>\n") < 0) {
+ if (virBufferVSprintf(buf, "<domain type='%s'>\n",
+ LXC_DOMAIN_TYPE) < 0) {
goto no_memory;
}
}
#endif /* WITH_LXC */
+
+/*
+ * Local variables:
+ * indent-tabs-mode: nil
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
lxc_driver_t *driver,
lxc_vm_t *vm,
lxc_vm_def_t *def);
-int lxcLoadDriverConfig(virConnectPtr conn);
+int lxcLoadDriverConfig(lxc_driver_t *driver);
int lxcSaveConfig(virConnectPtr conn,
lxc_driver_t *driver,
lxc_vm_t *vm,
lxc_vm_def_t *def);
-int lxcLoadContainerInfo(virConnectPtr conn);
+int lxcLoadContainerInfo(lxc_driver_t *driver);
int lxcLoadContainerConfigFile(lxc_driver_t *driver,
const char *file);
lxc_vm_t * lxcAssignVMDef(virConnectPtr conn,
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
#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 */
static int lxcDummyChild( void *argv ATTRIBUTE_UNUSED )
goto declineConnection;
}
+ if (lxc_driver == NULL)
+ goto declineConnection;
+
/* Verify uri was specified */
if ((NULL == uri) || (NULL == uri->scheme)) {
goto declineConnection;
goto declineConnection;
}
- /* Check that this is a container enabled kernel */
- if(0 != lxcCheckContainerSupport()) {
- goto declineConnection;
- }
-
- /* initialize driver data */
- if (0 > lxcStartup(conn)) {
- goto declineConnection;
- }
+ conn->privateData = lxc_driver;
return VIR_DRV_OPEN_SUCCESS;
static int lxcClose(virConnectPtr conn)
{
- return lxcShutdown(conn);
+ conn->privateData = NULL;
+ return 0;
}
static virDomainPtr lxcDomainLookupByID(virConnectPtr conn,
return lxcGenerateXML(dom->conn, driver, vm, vm->def);
}
-static int lxcStartup(virConnectPtr conn)
+
+static int lxcStartup(void)
{
- lxc_driver_t *driver;
+ lxc_driver = calloc(1, sizeof(lxc_driver_t));
+ if (NULL == lxc_driver) {
+ return -1;
+ }
- driver = calloc(1, sizeof(lxc_driver_t));
- if (NULL == driver) {
+ /* Check that this is a container enabled kernel */
+ if(0 != lxcCheckContainerSupport()) {
return -1;
}
- conn->privateData = driver;
/* Call function to load lxc driver configuration information */
- if (lxcLoadDriverConfig(conn) < 0) {
- lxcShutdown(conn);
+ if (lxcLoadDriverConfig(lxc_driver) < 0) {
+ lxcShutdown();
return -1;
}
/* Call function to load the container configuration files */
- if (lxcLoadContainerInfo(conn) < 0) {
- lxcShutdown(conn);
+ if (lxcLoadContainerInfo(lxc_driver) < 0) {
+ lxcShutdown();
return -1;
}
free(driver);
}
-static int lxcShutdown(virConnectPtr conn)
+static int lxcShutdown(void)
{
- lxc_driver_t *driver = (lxc_driver_t *)conn->privateData;
- lxc_vm_t *vms = driver->vms;
+ lxc_vm_t *vms = lxc_driver->vms;
lxcFreeVMs(vms);
- driver->vms = NULL;
- lxcFreeDriver(driver);
- conn->privateData = NULL;
+ lxc_driver->vms = NULL;
+ lxcFreeDriver(lxc_driver);
+
+ 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 */
static virDriver lxcDriver = {
VIR_DRV_LXC, /* the number virDrvNo */
NULL, /* getFreeMemory */
};
+
+static virStateDriver lxcStateDriver = {
+ lxcStartup,
+ lxcShutdown,
+ NULL, /* reload */
+ lxcActive,
+};
+
int lxcRegister(void)
{
virRegisterDriver(&lxcDriver);
+ virRegisterStateDriver(&lxcStateDriver);
return 0;
}
rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
}
#endif
+#if WITH_LXC
+ if (uri &&
+ uri->scheme && STREQ (uri->scheme, "lxc")) {
+ rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
+ }
+#endif
priv->magic = DEAD;
priv->sock = -1;