---
src/Makefile.am | 2 ++
src/lxc/lxc_conf.c | 8 ++++++++
src/lxc/lxc_conf.h | 2 ++
src/lxc/lxc_controller.c | 7 ++++++-
src/lxc/lxc_domain.c | 13 ++++++-------
src/lxc/lxc_domain.h | 2 +-
src/lxc/lxc_driver.c | 43 ++++++++++++++++++++++++-------------------
src/lxc/lxc_process.c | 9 +++++----
8 files changed, 54 insertions(+), 32 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index c1659a4..b615902 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -493,6 +493,8 @@ LXC_CONTROLLER_SOURCES = \
lxc/lxc_conf.c lxc/lxc_conf.h \
lxc/lxc_container.c lxc/lxc_container.h \
lxc/lxc_cgroup.c lxc/lxc_cgroup.h \
+ lxc/lxc_domain.c lxc/lxc_domain.h \
+ lxc/lxc_hostdev.c lxc/lxc_hostdev.h \
lxc/lxc_fuse.c lxc/lxc_fuse.h \
lxc/lxc_controller.c
diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c
index 7b808e7..c723e77 100644
--- a/src/lxc/lxc_conf.c
+++ b/src/lxc/lxc_conf.c
@@ -27,6 +27,7 @@
#include <config.h>
#include "lxc_conf.h"
+#include "lxc_domain.h"
#include "nodeinfo.h"
#include "virerror.h"
#include "virconf.h"
@@ -154,6 +155,13 @@ error:
return NULL;
}
+
+virDomainXMLConfPtr
+lxcDomainXMLConfInit(void)
+{
+ return virDomainXMLConfNew(&virLXCDriverPrivateDataCallbacks, NULL);
+}
+
int lxcLoadDriverConfig(virLXCDriverPtr driver)
{
char *filename;
diff --git a/src/lxc/lxc_conf.h b/src/lxc/lxc_conf.h
index 2649cd6..b46dc32 100644
--- a/src/lxc/lxc_conf.h
+++ b/src/lxc/lxc_conf.h
@@ -51,6 +51,7 @@ struct _virLXCDriver {
virMutex lock;
virCapsPtr caps;
+ virDomainXMLConfPtr xmlconf;
virCgroupPtr cgroup;
@@ -83,6 +84,7 @@ struct _virLXCDriver {
int lxcLoadDriverConfig(virLXCDriverPtr driver);
virCapsPtr lxcCapsInit(virLXCDriverPtr driver);
+virDomainXMLConfPtr lxcDomainXMLConfInit(void);
static inline void lxcDriverLock(virLXCDriverPtr driver)
{
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 15aa334..8059a6d 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -151,6 +151,7 @@ static virLXCControllerPtr virLXCControllerNew(const char *name)
{
virLXCControllerPtr ctrl = NULL;
virCapsPtr caps = NULL;
+ virDomainXMLConfPtr xmlconf = NULL;
char *configFile = NULL;
if (VIR_ALLOC(ctrl) < 0)
@@ -165,11 +166,14 @@ static virLXCControllerPtr virLXCControllerNew(const char *name)
if ((caps = lxcCapsInit(NULL)) == NULL)
goto error;
+ if (!(xmlconf = lxcDomainXMLConfInit()))
+ goto error;
+
if ((configFile = virDomainConfigFile(LXC_STATE_DIR,
ctrl->name)) == NULL)
goto error;
- if ((ctrl->def = virDomainDefParseFile(caps,
+ if ((ctrl->def = virDomainDefParseFile(caps, xmlconf,
configFile,
1 << VIR_DOMAIN_VIRT_LXC,
0)) == NULL)
@@ -183,6 +187,7 @@ static virLXCControllerPtr virLXCControllerNew(const char *name)
cleanup:
VIR_FREE(configFile);
virObjectUnref(caps);
+ virObjectUnref(xmlconf);
return ctrl;
no_memory:
diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c
index 1b02aa5..08cf8f6 100644
--- a/src/lxc/lxc_domain.c
+++ b/src/lxc/lxc_domain.c
@@ -73,10 +73,9 @@ static int virLXCDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, void
*data)
return 0;
}
-void virLXCDomainSetPrivateDataHooks(virCapsPtr caps)
-{
- caps->privateDataAllocFunc = virLXCDomainObjPrivateAlloc;
- caps->privateDataFreeFunc = virLXCDomainObjPrivateFree;
- caps->privateDataXMLFormat = virLXCDomainObjPrivateXMLFormat;
- caps->privateDataXMLParse = virLXCDomainObjPrivateXMLParse;
-}
+virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks = {
+ .alloc = virLXCDomainObjPrivateAlloc,
+ .free = virLXCDomainObjPrivateFree,
+ .format = virLXCDomainObjPrivateXMLFormat,
+ .parse = virLXCDomainObjPrivateXMLParse,
+};
diff --git a/src/lxc/lxc_domain.h b/src/lxc/lxc_domain.h
index 882f34a..007ea84 100644
--- a/src/lxc/lxc_domain.h
+++ b/src/lxc/lxc_domain.h
@@ -38,6 +38,6 @@ struct _virLXCDomainObjPrivate {
pid_t initpid;
};
-void virLXCDomainSetPrivateDataHooks(virCapsPtr caps);
+extern virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks;
#endif /* __LXC_DOMAIN_H__ */
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index f136df2..59bb786 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -413,7 +413,7 @@ static virDomainPtr lxcDomainDefine(virConnectPtr conn, const char
*xml)
virDomainDefPtr oldDef = NULL;
lxcDriverLock(driver);
- if (!(def = virDomainDefParseString(driver->caps, xml,
+ if (!(def = virDomainDefParseString(driver->caps, driver->xmlconf, xml,
1 << VIR_DOMAIN_VIRT_LXC,
VIR_DOMAIN_XML_INACTIVE)))
goto cleanup;
@@ -428,7 +428,7 @@ static virDomainPtr lxcDomainDefine(virConnectPtr conn, const char
*xml)
}
if (!(vm = virDomainObjListAdd(driver->domains,
- driver->caps,
+ driver->xmlconf,
def,
0,
&oldDef)))
@@ -1069,7 +1069,7 @@ lxcDomainCreateAndStart(virConnectPtr conn,
virCheckFlags(VIR_DOMAIN_START_AUTODESTROY, NULL);
lxcDriverLock(driver);
- if (!(def = virDomainDefParseString(driver->caps, xml,
+ if (!(def = virDomainDefParseString(driver->caps, driver->xmlconf, xml,
1 << VIR_DOMAIN_VIRT_LXC,
VIR_DOMAIN_XML_INACTIVE)))
goto cleanup;
@@ -1085,7 +1085,7 @@ lxcDomainCreateAndStart(virConnectPtr conn,
if (!(vm = virDomainObjListAdd(driver->domains,
- driver->caps,
+ driver->xmlconf,
def,
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
@@ -1472,7 +1472,8 @@ static int lxcStartup(bool privileged,
if ((lxc_driver->caps = lxcCapsInit(lxc_driver)) == NULL)
goto cleanup;
- virLXCDomainSetPrivateDataHooks(lxc_driver->caps);
+ if (!(lxc_driver->xmlconf = lxcDomainXMLConfInit()))
+ goto cleanup;
if (virLXCProcessAutoDestroyInit(lxc_driver) < 0)
goto cleanup;
@@ -1480,6 +1481,7 @@ static int lxcStartup(bool privileged,
/* Get all the running persistent or transient configs first */
if (virDomainObjListLoadAllConfigs(lxc_driver->domains,
lxc_driver->caps,
+ lxc_driver->xmlconf,
lxc_driver->stateDir,
NULL,
1, 1 << VIR_DOMAIN_VIRT_LXC,
@@ -1491,6 +1493,7 @@ static int lxcStartup(bool privileged,
/* Then inactive persistent configs */
if (virDomainObjListLoadAllConfigs(lxc_driver->domains,
lxc_driver->caps,
+ lxc_driver->xmlconf,
lxc_driver->configDir,
lxc_driver->autostartDir,
0, 1 << VIR_DOMAIN_VIRT_LXC,
@@ -1538,6 +1541,7 @@ lxcReload(void) {
lxcDriverLock(lxc_driver);
virDomainObjListLoadAllConfigs(lxc_driver->domains,
lxc_driver->caps,
+ lxc_driver->xmlconf,
lxc_driver->configDir,
lxc_driver->autostartDir,
0, 1 << VIR_DOMAIN_VIRT_LXC,
@@ -1561,6 +1565,7 @@ static int lxcShutdown(void)
virObjectUnref(lxc_driver->caps);
virObjectUnref(lxc_driver->securityManager);
+ virObjectUnref(lxc_driver->xmlconf);
VIR_FREE(lxc_driver->configDir);
VIR_FREE(lxc_driver->autostartDir);
VIR_FREE(lxc_driver->stateDir);
@@ -1782,13 +1787,13 @@ lxcSetSchedulerParametersFlags(virDomainPtr dom,
goto cleanup;
}
- if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags,
- &vmdef) < 0)
+ if (virDomainLiveConfigHelperMethod(driver->caps, driver->xmlconf,
+ vm, &flags, &vmdef) < 0)
goto cleanup;
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
/* Make a copy for updated domain. */
- vmdef = virDomainObjCopyPersistentDef(driver->caps, vm);
+ vmdef = virDomainObjCopyPersistentDef(driver->caps, driver->xmlconf, vm);
if (!vmdef)
goto cleanup;
}
@@ -1854,7 +1859,7 @@ lxcSetSchedulerParametersFlags(virDomainPtr dom,
}
}
- if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0)
+ if (virDomainSaveStatus(driver->xmlconf, driver->stateDir, vm) < 0)
goto cleanup;
@@ -1924,8 +1929,8 @@ lxcGetSchedulerParametersFlags(virDomainPtr dom,
goto cleanup;
}
- if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags,
- &persistentDef) < 0)
+ if (virDomainLiveConfigHelperMethod(driver->caps, driver->xmlconf,
+ vm, &flags, &persistentDef) < 0)
goto cleanup;
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
@@ -2037,8 +2042,8 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
goto cleanup;
}
- if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags,
- &persistentDef) < 0)
+ if (virDomainLiveConfigHelperMethod(driver->caps, driver->xmlconf,
+ vm, &flags, &persistentDef) < 0)
goto cleanup;
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
@@ -2142,8 +2147,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom,
goto cleanup;
}
- if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags,
- &persistentDef) < 0)
+ if (virDomainLiveConfigHelperMethod(driver->caps, driver->xmlconf,
+ vm, &flags, &persistentDef) < 0)
goto cleanup;
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
@@ -2508,7 +2513,7 @@ static int lxcDomainSuspend(virDomainPtr dom)
VIR_DOMAIN_EVENT_SUSPENDED_PAUSED);
}
- if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0)
+ if (virDomainSaveStatus(driver->xmlconf, driver->stateDir, vm) < 0)
goto cleanup;
ret = 0;
@@ -2574,7 +2579,7 @@ static int lxcDomainResume(virDomainPtr dom)
VIR_DOMAIN_EVENT_RESUMED_UNPAUSED);
}
- if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0)
+ if (virDomainSaveStatus(driver->xmlconf, driver->stateDir, vm) < 0)
goto cleanup;
ret = 0;
@@ -4353,7 +4358,7 @@ lxcDomainModifyDeviceFlags(virDomainPtr dom, const char *xml,
goto cleanup;
/* Make a copy for updated domain. */
- vmdef = virDomainObjCopyPersistentDef(driver->caps, vm);
+ vmdef = virDomainObjCopyPersistentDef(driver->caps, driver->xmlconf, vm);
if (!vmdef)
goto cleanup;
switch (action) {
@@ -4401,7 +4406,7 @@ lxcDomainModifyDeviceFlags(virDomainPtr dom, const char *xml,
* changed even if we failed to attach the device. For example,
* a new controller may be created.
*/
- if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0) {
+ if (virDomainSaveStatus(driver->xmlconf, driver->stateDir, vm) < 0) {
ret = -1;
goto cleanup;
}
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index aaa81a7..d36baf9 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -640,7 +640,7 @@ static void virLXCProcessMonitorInitNotify(virLXCMonitorPtr mon
ATTRIBUTE_UNUSED
priv->initpid = initpid;
virDomainAuditInit(vm, initpid);
- if (virDomainSaveStatus(lxc_driver->caps, lxc_driver->stateDir, vm) < 0)
+ if (virDomainSaveStatus(lxc_driver->xmlconf, lxc_driver->stateDir, vm) < 0)
VIR_WARN("Cannot update XML with PID for LXC %s",
vm->def->name);
}
@@ -963,7 +963,7 @@ int virLXCProcessStart(virConnectPtr conn,
* report implicit runtime defaults in the XML, like vnc listen/socket
*/
VIR_DEBUG("Setting current domain def as transient");
- if (virDomainObjSetDefTransient(driver->caps, vm, true) < 0)
+ if (virDomainObjSetDefTransient(driver->caps, driver->xmlconf, vm, true) <
0)
goto cleanup;
/* Run an early hook to set-up missing devices */
@@ -1155,7 +1155,8 @@ int virLXCProcessStart(virConnectPtr conn,
virLXCProcessAutoDestroyAdd(driver, vm, conn) < 0)
goto error;
- if (virDomainObjSetDefTransient(driver->caps, vm, false) < 0)
+ if (virDomainObjSetDefTransient(driver->caps, driver->xmlconf,
+ vm, false) < 0)
goto error;
/* Write domain status to disk.
@@ -1164,7 +1165,7 @@ int virLXCProcessStart(virConnectPtr conn,
* location for the benefit of libvirt_lxc. We're now overwriting
* it with the live status XML instead. This is a (currently
* harmless) inconsistency we should fix one day */
- if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0)
+ if (virDomainSaveStatus(driver->xmlconf, driver->stateDir, vm) < 0)
goto error;
/* finally we can call the 'started' hook script if any */
--
1.8.1.1