提交 7fca3755 编写于 作者: M Michal Privoznik

Introduce a virLXCDriverConfigPtr object

Currently the virLXCDriverPtr struct contains an wide variety
of data with varying access needs. Move all the static config
data into a dedicated virLXCDriverConfigPtr object. The only
locking requirement is to hold the driver lock, while obtaining
an instance of virLXCDriverConfigPtr. Once a reference is held
on the config object, it can be used completely lockless since
it is immutable.

NB, not all APIs correctly hold the driver lock while getting
a reference to the config object in this patch. This is safe
for now since the config is never updated on the fly. Later
patches will address this fully.
上级 7e94a1a4
...@@ -41,6 +41,22 @@ ...@@ -41,6 +41,22 @@
#define VIR_FROM_THIS VIR_FROM_LXC #define VIR_FROM_THIS VIR_FROM_LXC
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)
/* Functions */ /* Functions */
virCapsPtr lxcCapsInit(virLXCDriverPtr driver) virCapsPtr lxcCapsInit(virLXCDriverPtr driver)
...@@ -146,28 +162,42 @@ lxcDomainXMLConfInit(void) ...@@ -146,28 +162,42 @@ lxcDomainXMLConfInit(void)
} }
int lxcLoadDriverConfig(virLXCDriverPtr driver) virLXCDriverConfigPtr
virLXCDriverConfigNew(void)
{ {
char *filename; virLXCDriverConfigPtr cfg;
virConfPtr conf;
virConfValuePtr p; if (virLXCConfigInitialize() < 0)
return NULL;
driver->securityDefaultConfined = false; if (!(cfg = virObjectNew(virLXCDriverConfigClass)))
driver->securityRequireConfined = false; return NULL;
cfg->securityDefaultConfined = false;
cfg->securityRequireConfined = false;
/* Set the container configuration directory */ /* Set the container configuration directory */
if (VIR_STRDUP(driver->configDir, LXC_CONFIG_DIR) < 0) if (VIR_STRDUP(cfg->configDir, LXC_CONFIG_DIR) < 0)
goto error; goto error;
if (VIR_STRDUP(driver->stateDir, LXC_STATE_DIR) < 0) if (VIR_STRDUP(cfg->stateDir, LXC_STATE_DIR) < 0)
goto error; goto error;
if (VIR_STRDUP(driver->logDir, LXC_LOG_DIR) < 0) if (VIR_STRDUP(cfg->logDir, LXC_LOG_DIR) < 0)
goto error; goto error;
if (VIR_STRDUP(driver->autostartDir, LXC_AUTOSTART_DIR) < 0) if (VIR_STRDUP(cfg->autostartDir, LXC_AUTOSTART_DIR) < 0)
goto error; goto error;
return cfg;
error:
virObjectUnref(cfg);
return NULL;
}
if (VIR_STRDUP(filename, SYSCONFDIR "/libvirt/lxc.conf") < 0) int
goto error; virLXCLoadDriverConfig(virLXCDriverConfigPtr cfg,
const char *filename)
{
virConfPtr conf;
virConfValuePtr p;
/* Avoid error from non-existant or unreadable file. */ /* Avoid error from non-existant or unreadable file. */
if (access(filename, R_OK) == -1) if (access(filename, R_OK) == -1)
...@@ -186,12 +216,12 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver) ...@@ -186,12 +216,12 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver)
p = virConfGetValue(conf, "log_with_libvirtd"); p = virConfGetValue(conf, "log_with_libvirtd");
CHECK_TYPE("log_with_libvirtd", VIR_CONF_LONG); CHECK_TYPE("log_with_libvirtd", VIR_CONF_LONG);
if (p) driver->log_libvirtd = p->l; if (p) cfg->log_libvirtd = p->l;
p = virConfGetValue(conf, "security_driver"); p = virConfGetValue(conf, "security_driver");
CHECK_TYPE("security_driver", VIR_CONF_STRING); CHECK_TYPE("security_driver", VIR_CONF_STRING);
if (p && p->str) { if (p && p->str) {
if (VIR_STRDUP(driver->securityDriverName, p->str) < 0) { if (VIR_STRDUP(cfg->securityDriverName, p->str) < 0) {
virConfFree(conf); virConfFree(conf);
return -1; return -1;
} }
...@@ -199,11 +229,11 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver) ...@@ -199,11 +229,11 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver)
p = virConfGetValue(conf, "security_default_confined"); p = virConfGetValue(conf, "security_default_confined");
CHECK_TYPE("security_default_confined", VIR_CONF_LONG); CHECK_TYPE("security_default_confined", VIR_CONF_LONG);
if (p) driver->securityDefaultConfined = p->l; if (p) cfg->securityDefaultConfined = p->l;
p = virConfGetValue(conf, "security_require_confined"); p = virConfGetValue(conf, "security_require_confined");
CHECK_TYPE("security_require_confined", VIR_CONF_LONG); CHECK_TYPE("security_require_confined", VIR_CONF_LONG);
if (p) driver->securityRequireConfined = p->l; if (p) cfg->securityRequireConfined = p->l;
#undef CHECK_TYPE #undef CHECK_TYPE
...@@ -211,9 +241,22 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver) ...@@ -211,9 +241,22 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver)
virConfFree(conf); virConfFree(conf);
done: done:
VIR_FREE(filename);
return 0; return 0;
}
error: virLXCDriverConfigPtr virLXCDriverGetConfig(virLXCDriverPtr driver)
return -1; {
return virObjectRef(driver->config);
}
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);
} }
...@@ -46,33 +46,46 @@ ...@@ -46,33 +46,46 @@
typedef struct _virLXCDriver virLXCDriver; typedef struct _virLXCDriver virLXCDriver;
typedef virLXCDriver *virLXCDriverPtr; typedef virLXCDriver *virLXCDriverPtr;
typedef struct _virLXCDriverConfig virLXCDriverConfig;
typedef virLXCDriverConfig *virLXCDriverConfigPtr;
struct _virLXCDriverConfig {
virObject parent;
char *configDir;
char *autostartDir;
char *stateDir;
char *logDir;
int log_libvirtd;
int have_netns;
char *securityDriverName;
bool securityDefaultConfined;
bool securityRequireConfined;
};
struct _virLXCDriver { struct _virLXCDriver {
virMutex lock; virMutex lock;
virLXCDriverConfigPtr config;
virCapsPtr caps; virCapsPtr caps;
virDomainXMLOptionPtr xmlopt; virDomainXMLOptionPtr xmlopt;
virSysinfoDefPtr hostsysinfo; virSysinfoDefPtr hostsysinfo;
size_t nactive; size_t nactive;
virStateInhibitCallback inhibitCallback; virStateInhibitCallback inhibitCallback;
void *inhibitOpaque; void *inhibitOpaque;
virDomainObjListPtr domains; virDomainObjListPtr domains;
char *configDir;
char *autostartDir;
char *stateDir;
char *logDir;
int log_libvirtd;
int have_netns;
virUSBDeviceListPtr activeUsbHostdevs; virUSBDeviceListPtr activeUsbHostdevs;
virDomainEventStatePtr domainEventState; virDomainEventStatePtr domainEventState;
char *securityDriverName;
bool securityDefaultConfined;
bool securityRequireConfined;
virSecurityManagerPtr securityManager; virSecurityManagerPtr securityManager;
/* Mapping of 'char *uuidstr' -> virConnectPtr /* Mapping of 'char *uuidstr' -> virConnectPtr
...@@ -81,7 +94,10 @@ struct _virLXCDriver { ...@@ -81,7 +94,10 @@ struct _virLXCDriver {
virHashTablePtr autodestroy; virHashTablePtr autodestroy;
}; };
int lxcLoadDriverConfig(virLXCDriverPtr driver); virLXCDriverConfigPtr virLXCDriverConfigNew(void);
virLXCDriverConfigPtr virLXCDriverGetConfig(virLXCDriverPtr driver);
int virLXCLoadDriverConfig(virLXCDriverConfigPtr cfg,
const char *filename);
virCapsPtr lxcCapsInit(virLXCDriverPtr driver); virCapsPtr lxcCapsInit(virLXCDriverPtr driver);
virDomainXMLOptionPtr lxcDomainXMLConfInit(void); virDomainXMLOptionPtr lxcDomainXMLConfInit(void);
......
...@@ -456,8 +456,11 @@ static virDomainPtr lxcDomainDefineXML(virConnectPtr conn, const char *xml) ...@@ -456,8 +456,11 @@ static virDomainPtr lxcDomainDefineXML(virConnectPtr conn, const char *xml)
virDomainPtr dom = NULL; virDomainPtr dom = NULL;
virDomainEventPtr event = NULL; virDomainEventPtr event = NULL;
virDomainDefPtr oldDef = NULL; virDomainDefPtr oldDef = NULL;
virLXCDriverConfigPtr cfg = NULL;
lxcDriverLock(driver); lxcDriverLock(driver);
cfg = virLXCDriverGetConfig(driver);
if (!(def = virDomainDefParseString(xml, driver->caps, driver->xmlopt, if (!(def = virDomainDefParseString(xml, driver->caps, driver->xmlopt,
1 << VIR_DOMAIN_VIRT_LXC, 1 << VIR_DOMAIN_VIRT_LXC,
VIR_DOMAIN_XML_INACTIVE))) VIR_DOMAIN_XML_INACTIVE)))
...@@ -469,7 +472,7 @@ static virDomainPtr lxcDomainDefineXML(virConnectPtr conn, const char *xml) ...@@ -469,7 +472,7 @@ static virDomainPtr lxcDomainDefineXML(virConnectPtr conn, const char *xml)
if (virSecurityManagerVerify(driver->securityManager, def) < 0) if (virSecurityManagerVerify(driver->securityManager, def) < 0)
goto cleanup; goto cleanup;
if ((def->nets != NULL) && !(driver->have_netns)) { if ((def->nets != NULL) && !(cfg->have_netns)) {
virReportError(VIR_ERR_OPERATION_INVALID, virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("System lacks NETNS support")); "%s", _("System lacks NETNS support"));
goto cleanup; goto cleanup;
...@@ -482,7 +485,7 @@ static virDomainPtr lxcDomainDefineXML(virConnectPtr conn, const char *xml) ...@@ -482,7 +485,7 @@ static virDomainPtr lxcDomainDefineXML(virConnectPtr conn, const char *xml)
def = NULL; def = NULL;
vm->persistent = 1; vm->persistent = 1;
if (virDomainSaveConfig(driver->configDir, if (virDomainSaveConfig(cfg->configDir,
vm->newDef ? vm->newDef : vm->def) < 0) { vm->newDef ? vm->newDef : vm->def) < 0) {
virDomainObjListRemove(driver->domains, vm); virDomainObjListRemove(driver->domains, vm);
vm = NULL; vm = NULL;
...@@ -507,6 +510,7 @@ cleanup: ...@@ -507,6 +510,7 @@ cleanup:
if (event) if (event)
virDomainEventStateQueue(driver->domainEventState, event); virDomainEventStateQueue(driver->domainEventState, event);
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
virObjectUnref(cfg);
return dom; return dom;
} }
...@@ -517,10 +521,13 @@ static int lxcDomainUndefineFlags(virDomainPtr dom, ...@@ -517,10 +521,13 @@ static int lxcDomainUndefineFlags(virDomainPtr dom,
virDomainObjPtr vm; virDomainObjPtr vm;
virDomainEventPtr event = NULL; virDomainEventPtr event = NULL;
int ret = -1; int ret = -1;
virLXCDriverConfigPtr cfg = NULL;
virCheckFlags(0, -1); virCheckFlags(0, -1);
lxcDriverLock(driver); lxcDriverLock(driver);
cfg = virLXCDriverGetConfig(driver);
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
if (!vm) { if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
...@@ -539,8 +546,8 @@ static int lxcDomainUndefineFlags(virDomainPtr dom, ...@@ -539,8 +546,8 @@ static int lxcDomainUndefineFlags(virDomainPtr dom,
goto cleanup; goto cleanup;
} }
if (virDomainDeleteConfig(driver->configDir, if (virDomainDeleteConfig(cfg->configDir,
driver->autostartDir, cfg->autostartDir,
vm) < 0) vm) < 0)
goto cleanup; goto cleanup;
...@@ -563,6 +570,7 @@ cleanup: ...@@ -563,6 +570,7 @@ cleanup:
if (event) if (event)
virDomainEventStateQueue(driver->domainEventState, event); virDomainEventStateQueue(driver->domainEventState, event);
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
virObjectUnref(cfg);
return ret; return ret;
} }
...@@ -1030,10 +1038,13 @@ static int lxcDomainCreateWithFiles(virDomainPtr dom, ...@@ -1030,10 +1038,13 @@ static int lxcDomainCreateWithFiles(virDomainPtr dom,
virDomainObjPtr vm; virDomainObjPtr vm;
virDomainEventPtr event = NULL; virDomainEventPtr event = NULL;
int ret = -1; int ret = -1;
virLXCDriverConfigPtr cfg = NULL;
virCheckFlags(VIR_DOMAIN_START_AUTODESTROY, -1); virCheckFlags(VIR_DOMAIN_START_AUTODESTROY, -1);
lxcDriverLock(driver); lxcDriverLock(driver);
cfg = virLXCDriverGetConfig(driver);
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
if (!vm) { if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
...@@ -1046,7 +1057,7 @@ static int lxcDomainCreateWithFiles(virDomainPtr dom, ...@@ -1046,7 +1057,7 @@ static int lxcDomainCreateWithFiles(virDomainPtr dom,
if (virDomainCreateWithFilesEnsureACL(dom->conn, vm->def) < 0) if (virDomainCreateWithFilesEnsureACL(dom->conn, vm->def) < 0)
goto cleanup; goto cleanup;
if ((vm->def->nets != NULL) && !(driver->have_netns)) { if ((vm->def->nets != NULL) && !(cfg->have_netns)) {
virReportError(VIR_ERR_OPERATION_INVALID, virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("System lacks NETNS support")); "%s", _("System lacks NETNS support"));
goto cleanup; goto cleanup;
...@@ -1078,6 +1089,7 @@ cleanup: ...@@ -1078,6 +1089,7 @@ cleanup:
if (event) if (event)
virDomainEventStateQueue(driver->domainEventState, event); virDomainEventStateQueue(driver->domainEventState, event);
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
virObjectUnref(cfg);
return ret; return ret;
} }
...@@ -1129,10 +1141,13 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn, ...@@ -1129,10 +1141,13 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn,
virDomainDefPtr def; virDomainDefPtr def;
virDomainPtr dom = NULL; virDomainPtr dom = NULL;
virDomainEventPtr event = NULL; virDomainEventPtr event = NULL;
virLXCDriverConfigPtr cfg = NULL;
virCheckFlags(VIR_DOMAIN_START_AUTODESTROY, NULL); virCheckFlags(VIR_DOMAIN_START_AUTODESTROY, NULL);
lxcDriverLock(driver); lxcDriverLock(driver);
cfg = virLXCDriverGetConfig(driver);
if (!(def = virDomainDefParseString(xml, driver->caps, driver->xmlopt, if (!(def = virDomainDefParseString(xml, driver->caps, driver->xmlopt,
1 << VIR_DOMAIN_VIRT_LXC, 1 << VIR_DOMAIN_VIRT_LXC,
VIR_DOMAIN_XML_INACTIVE))) VIR_DOMAIN_XML_INACTIVE)))
...@@ -1144,7 +1159,7 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn, ...@@ -1144,7 +1159,7 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn,
if (virSecurityManagerVerify(driver->securityManager, def) < 0) if (virSecurityManagerVerify(driver->securityManager, def) < 0)
goto cleanup; goto cleanup;
if ((def->nets != NULL) && !(driver->have_netns)) { if ((def->nets != NULL) && !(cfg->have_netns)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
"%s", _("System lacks NETNS support")); "%s", _("System lacks NETNS support"));
goto cleanup; goto cleanup;
...@@ -1184,6 +1199,7 @@ cleanup: ...@@ -1184,6 +1199,7 @@ cleanup:
if (event) if (event)
virDomainEventStateQueue(driver->domainEventState, event); virDomainEventStateQueue(driver->domainEventState, event);
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
virObjectUnref(cfg);
return dom; return dom;
} }
...@@ -1485,26 +1501,24 @@ static int lxcCheckNetNsSupport(void) ...@@ -1485,26 +1501,24 @@ static int lxcCheckNetNsSupport(void)
} }
static int static virSecurityManagerPtr
lxcSecurityInit(virLXCDriverPtr driver) lxcSecurityInit(virLXCDriverConfigPtr cfg)
{ {
VIR_INFO("lxcSecurityInit %s", driver->securityDriverName); VIR_INFO("lxcSecurityInit %s", cfg->securityDriverName);
virSecurityManagerPtr mgr = virSecurityManagerNew(driver->securityDriverName, virSecurityManagerPtr mgr = virSecurityManagerNew(cfg->securityDriverName,
LXC_DRIVER_NAME, LXC_DRIVER_NAME,
false, false,
driver->securityDefaultConfined, cfg->securityDefaultConfined,
driver->securityRequireConfined); cfg->securityRequireConfined);
if (!mgr) if (!mgr)
goto error; goto error;
driver->securityManager = mgr; return mgr;
return 0;
error: error:
VIR_ERROR(_("Failed to initialize security drivers")); VIR_ERROR(_("Failed to initialize security drivers"));
virObjectUnref(mgr); virObjectUnref(mgr);
return -1; return NULL;
} }
...@@ -1513,6 +1527,7 @@ static int lxcStateInitialize(bool privileged, ...@@ -1513,6 +1527,7 @@ static int lxcStateInitialize(bool privileged,
void *opaque ATTRIBUTE_UNUSED) void *opaque ATTRIBUTE_UNUSED)
{ {
char *ld; char *ld;
virLXCDriverConfigPtr cfg = NULL;
/* Valgrind gets very annoyed when we clone containers, so /* Valgrind gets very annoyed when we clone containers, so
* disable LXC when under valgrind * disable LXC when under valgrind
...@@ -1554,14 +1569,17 @@ static int lxcStateInitialize(bool privileged, ...@@ -1554,14 +1569,17 @@ static int lxcStateInitialize(bool privileged,
lxc_driver->hostsysinfo = virSysinfoRead(); lxc_driver->hostsysinfo = virSysinfoRead();
lxc_driver->log_libvirtd = 0; /* by default log to container logfile */ if (!(lxc_driver->config = cfg = virLXCDriverConfigNew()))
lxc_driver->have_netns = lxcCheckNetNsSupport(); goto cleanup;
cfg->log_libvirtd = 0; /* by default log to container logfile */
cfg->have_netns = lxcCheckNetNsSupport();
/* Call function to load lxc driver configuration information */ /* Call function to load lxc driver configuration information */
if (lxcLoadDriverConfig(lxc_driver) < 0) if (virLXCLoadDriverConfig(cfg, SYSCONFDIR "/libvirt/lxc.conf") < 0)
goto cleanup; goto cleanup;
if (lxcSecurityInit(lxc_driver) < 0) if (!(lxc_driver->securityManager = lxcSecurityInit(cfg)))
goto cleanup; goto cleanup;
if ((lxc_driver->activeUsbHostdevs = virUSBDeviceListNew()) == NULL) if ((lxc_driver->activeUsbHostdevs = virUSBDeviceListNew()) == NULL)
...@@ -1578,7 +1596,7 @@ static int lxcStateInitialize(bool privileged, ...@@ -1578,7 +1596,7 @@ static int lxcStateInitialize(bool privileged,
/* Get all the running persistent or transient configs first */ /* Get all the running persistent or transient configs first */
if (virDomainObjListLoadAllConfigs(lxc_driver->domains, if (virDomainObjListLoadAllConfigs(lxc_driver->domains,
lxc_driver->stateDir, cfg->stateDir,
NULL, 1, NULL, 1,
lxc_driver->caps, lxc_driver->caps,
lxc_driver->xmlopt, lxc_driver->xmlopt,
...@@ -1590,8 +1608,8 @@ static int lxcStateInitialize(bool privileged, ...@@ -1590,8 +1608,8 @@ static int lxcStateInitialize(bool privileged,
/* Then inactive persistent configs */ /* Then inactive persistent configs */
if (virDomainObjListLoadAllConfigs(lxc_driver->domains, if (virDomainObjListLoadAllConfigs(lxc_driver->domains,
lxc_driver->configDir, cfg->configDir,
lxc_driver->autostartDir, 0, cfg->autostartDir, 0,
lxc_driver->caps, lxc_driver->caps,
lxc_driver->xmlopt, lxc_driver->xmlopt,
1 << VIR_DOMAIN_VIRT_LXC, 1 << VIR_DOMAIN_VIRT_LXC,
...@@ -1633,19 +1651,23 @@ static void lxcNotifyLoadDomain(virDomainObjPtr vm, int newVM, void *opaque) ...@@ -1633,19 +1651,23 @@ static void lxcNotifyLoadDomain(virDomainObjPtr vm, int newVM, void *opaque)
*/ */
static int static int
lxcStateReload(void) { lxcStateReload(void) {
virLXCDriverConfigPtr cfg = NULL;
if (!lxc_driver) if (!lxc_driver)
return 0; return 0;
lxcDriverLock(lxc_driver); lxcDriverLock(lxc_driver);
cfg = virLXCDriverGetConfig(lxc_driver);
virDomainObjListLoadAllConfigs(lxc_driver->domains, virDomainObjListLoadAllConfigs(lxc_driver->domains,
lxc_driver->configDir, cfg->configDir,
lxc_driver->autostartDir, 0, cfg->autostartDir, 0,
lxc_driver->caps, lxc_driver->caps,
lxc_driver->xmlopt, lxc_driver->xmlopt,
1 << VIR_DOMAIN_VIRT_LXC, 1 << VIR_DOMAIN_VIRT_LXC,
lxcNotifyLoadDomain, lxc_driver); lxcNotifyLoadDomain, lxc_driver);
lxcDriverUnlock(lxc_driver); lxcDriverUnlock(lxc_driver);
virObjectUnref(cfg);
return 0; return 0;
} }
...@@ -1667,10 +1689,7 @@ static int lxcStateCleanup(void) ...@@ -1667,10 +1689,7 @@ static int lxcStateCleanup(void)
virObjectUnref(lxc_driver->caps); virObjectUnref(lxc_driver->caps);
virObjectUnref(lxc_driver->securityManager); virObjectUnref(lxc_driver->securityManager);
virObjectUnref(lxc_driver->xmlopt); virObjectUnref(lxc_driver->xmlopt);
VIR_FREE(lxc_driver->configDir); virObjectUnref(lxc_driver->config);
VIR_FREE(lxc_driver->autostartDir);
VIR_FREE(lxc_driver->stateDir);
VIR_FREE(lxc_driver->logDir);
lxcDriverUnlock(lxc_driver); lxcDriverUnlock(lxc_driver);
virMutexDestroy(&lxc_driver->lock); virMutexDestroy(&lxc_driver->lock);
VIR_FREE(lxc_driver); VIR_FREE(lxc_driver);
...@@ -1881,6 +1900,7 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom, ...@@ -1881,6 +1900,7 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom,
int ret = -1; int ret = -1;
int rc; int rc;
virLXCDomainObjPrivatePtr priv; virLXCDomainObjPrivatePtr priv;
virLXCDriverConfigPtr cfg = NULL;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1); VIR_DOMAIN_AFFECT_CONFIG, -1);
...@@ -1896,6 +1916,8 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom, ...@@ -1896,6 +1916,8 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom,
lxcDriverLock(driver); lxcDriverLock(driver);
cfg = virLXCDriverGetConfig(driver);
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
if (vm == NULL) { if (vm == NULL) {
...@@ -1974,12 +1996,12 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom, ...@@ -1974,12 +1996,12 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom,
} }
} }
if (virDomainSaveStatus(driver->xmlopt, driver->stateDir, vm) < 0) if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
goto cleanup; goto cleanup;
if (flags & VIR_DOMAIN_AFFECT_CONFIG) { if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
rc = virDomainSaveConfig(driver->configDir, vmdef); rc = virDomainSaveConfig(cfg->configDir, vmdef);
if (rc < 0) if (rc < 0)
goto cleanup; goto cleanup;
...@@ -1994,6 +2016,7 @@ cleanup: ...@@ -1994,6 +2016,7 @@ cleanup:
if (vm) if (vm)
virObjectUnlock(vm); virObjectUnlock(vm);
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
virObjectUnref(cfg);
return ret; return ret;
} }
...@@ -2135,6 +2158,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, ...@@ -2135,6 +2158,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
virDomainDefPtr persistentDef = NULL; virDomainDefPtr persistentDef = NULL;
int ret = -1; int ret = -1;
virLXCDomainObjPrivatePtr priv; virLXCDomainObjPrivatePtr priv;
virLXCDriverConfigPtr cfg = NULL;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1); VIR_DOMAIN_AFFECT_CONFIG, -1);
...@@ -2146,6 +2170,8 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, ...@@ -2146,6 +2170,8 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
lxcDriverLock(driver); lxcDriverLock(driver);
cfg = virLXCDriverGetConfig(driver);
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
if (vm == NULL) { if (vm == NULL) {
...@@ -2208,7 +2234,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, ...@@ -2208,7 +2234,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
} }
} }
if (virDomainSaveConfig(driver->configDir, persistentDef) < 0) if (virDomainSaveConfig(cfg->configDir, persistentDef) < 0)
goto cleanup; goto cleanup;
} }
...@@ -2217,6 +2243,7 @@ cleanup: ...@@ -2217,6 +2243,7 @@ cleanup:
if (vm) if (vm)
virObjectUnlock(vm); virObjectUnlock(vm);
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
virObjectUnref(cfg);
return ret; return ret;
} }
...@@ -2420,13 +2447,17 @@ cleanup: ...@@ -2420,13 +2447,17 @@ cleanup:
} }
static int lxcDomainSetAutostart(virDomainPtr dom, static int lxcDomainSetAutostart(virDomainPtr dom,
int autostart) { int autostart)
{
virLXCDriverPtr driver = dom->conn->privateData; virLXCDriverPtr driver = dom->conn->privateData;
virDomainObjPtr vm; virDomainObjPtr vm;
char *configFile = NULL, *autostartLink = NULL; char *configFile = NULL, *autostartLink = NULL;
int ret = -1; int ret = -1;
virLXCDriverConfigPtr cfg = NULL;
lxcDriverLock(driver); lxcDriverLock(driver);
cfg = virLXCDriverGetConfig(driver);
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
if (!vm) { if (!vm) {
...@@ -2453,20 +2484,20 @@ static int lxcDomainSetAutostart(virDomainPtr dom, ...@@ -2453,20 +2484,20 @@ static int lxcDomainSetAutostart(virDomainPtr dom,
goto cleanup; goto cleanup;
} }
configFile = virDomainConfigFile(driver->configDir, configFile = virDomainConfigFile(cfg->configDir,
vm->def->name); vm->def->name);
if (configFile == NULL) if (configFile == NULL)
goto cleanup; goto cleanup;
autostartLink = virDomainConfigFile(driver->autostartDir, autostartLink = virDomainConfigFile(cfg->autostartDir,
vm->def->name); vm->def->name);
if (autostartLink == NULL) if (autostartLink == NULL)
goto cleanup; goto cleanup;
if (autostart) { if (autostart) {
if (virFileMakePath(driver->autostartDir) < 0) { if (virFileMakePath(cfg->autostartDir) < 0) {
virReportSystemError(errno, virReportSystemError(errno,
_("Cannot create autostart directory %s"), _("Cannot create autostart directory %s"),
driver->autostartDir); cfg->autostartDir);
goto cleanup; goto cleanup;
} }
...@@ -2494,6 +2525,7 @@ cleanup: ...@@ -2494,6 +2525,7 @@ cleanup:
if (vm) if (vm)
virObjectUnlock(vm); virObjectUnlock(vm);
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
virObjectUnref(cfg);
return ret; return ret;
} }
...@@ -2589,8 +2621,11 @@ static int lxcDomainSuspend(virDomainPtr dom) ...@@ -2589,8 +2621,11 @@ static int lxcDomainSuspend(virDomainPtr dom)
virDomainObjPtr vm; virDomainObjPtr vm;
virDomainEventPtr event = NULL; virDomainEventPtr event = NULL;
int ret = -1; int ret = -1;
virLXCDriverConfigPtr cfg = NULL;
lxcDriverLock(driver); lxcDriverLock(driver);
cfg = virLXCDriverGetConfig(driver);
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
if (!vm) { if (!vm) {
...@@ -2623,7 +2658,7 @@ static int lxcDomainSuspend(virDomainPtr dom) ...@@ -2623,7 +2658,7 @@ static int lxcDomainSuspend(virDomainPtr dom)
VIR_DOMAIN_EVENT_SUSPENDED_PAUSED); VIR_DOMAIN_EVENT_SUSPENDED_PAUSED);
} }
if (virDomainSaveStatus(driver->xmlopt, driver->stateDir, vm) < 0) if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;
...@@ -2633,6 +2668,7 @@ cleanup: ...@@ -2633,6 +2668,7 @@ cleanup:
if (vm) if (vm)
virObjectUnlock(vm); virObjectUnlock(vm);
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
virObjectUnref(cfg);
return ret; return ret;
} }
...@@ -2643,8 +2679,11 @@ static int lxcDomainResume(virDomainPtr dom) ...@@ -2643,8 +2679,11 @@ static int lxcDomainResume(virDomainPtr dom)
virDomainEventPtr event = NULL; virDomainEventPtr event = NULL;
int ret = -1; int ret = -1;
virLXCDomainObjPrivatePtr priv; virLXCDomainObjPrivatePtr priv;
virLXCDriverConfigPtr cfg = NULL;
lxcDriverLock(driver); lxcDriverLock(driver);
cfg = virLXCDriverGetConfig(driver);
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
if (!vm) { if (!vm) {
...@@ -2680,7 +2719,7 @@ static int lxcDomainResume(virDomainPtr dom) ...@@ -2680,7 +2719,7 @@ static int lxcDomainResume(virDomainPtr dom)
VIR_DOMAIN_EVENT_RESUMED_UNPAUSED); VIR_DOMAIN_EVENT_RESUMED_UNPAUSED);
} }
if (virDomainSaveStatus(driver->xmlopt, driver->stateDir, vm) < 0) if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;
...@@ -2690,6 +2729,7 @@ cleanup: ...@@ -2690,6 +2729,7 @@ cleanup:
if (vm) if (vm)
virObjectUnlock(vm); virObjectUnlock(vm);
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
virObjectUnref(cfg);
return ret; return ret;
} }
...@@ -4313,6 +4353,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom, ...@@ -4313,6 +4353,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom,
virDomainDeviceDefPtr dev = NULL, dev_copy = NULL; virDomainDeviceDefPtr dev = NULL, dev_copy = NULL;
int ret = -1; int ret = -1;
unsigned int affect; unsigned int affect;
virLXCDriverConfigPtr cfg = NULL;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1); VIR_DOMAIN_AFFECT_CONFIG, -1);
...@@ -4320,6 +4361,8 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom, ...@@ -4320,6 +4361,8 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom,
affect = flags & (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG); affect = flags & (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG);
lxcDriverLock(driver); lxcDriverLock(driver);
cfg = virLXCDriverGetConfig(driver);
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
if (!vm) { if (!vm) {
...@@ -4395,7 +4438,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom, ...@@ -4395,7 +4438,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom,
* changed even if we failed to attach the device. For example, * changed even if we failed to attach the device. For example,
* a new controller may be created. * a new controller may be created.
*/ */
if (virDomainSaveStatus(driver->xmlopt, driver->stateDir, vm) < 0) { if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) {
ret = -1; ret = -1;
goto cleanup; goto cleanup;
} }
...@@ -4403,7 +4446,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom, ...@@ -4403,7 +4446,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom,
/* Finally, if no error until here, we can save config. */ /* Finally, if no error until here, we can save config. */
if (flags & VIR_DOMAIN_AFFECT_CONFIG) { if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
ret = virDomainSaveConfig(driver->configDir, vmdef); ret = virDomainSaveConfig(cfg->configDir, vmdef);
if (!ret) { if (!ret) {
virDomainObjAssignDef(vm, vmdef, false, NULL); virDomainObjAssignDef(vm, vmdef, false, NULL);
vmdef = NULL; vmdef = NULL;
...@@ -4418,6 +4461,7 @@ cleanup: ...@@ -4418,6 +4461,7 @@ cleanup:
if (vm) if (vm)
virObjectUnlock(vm); virObjectUnlock(vm);
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
virObjectUnref(cfg);
return ret; return ret;
} }
...@@ -4440,6 +4484,7 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom, ...@@ -4440,6 +4484,7 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom,
virDomainDeviceDefPtr dev = NULL, dev_copy = NULL; virDomainDeviceDefPtr dev = NULL, dev_copy = NULL;
int ret = -1; int ret = -1;
unsigned int affect; unsigned int affect;
virLXCDriverConfigPtr cfg = NULL;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG | VIR_DOMAIN_AFFECT_CONFIG |
...@@ -4448,6 +4493,8 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom, ...@@ -4448,6 +4493,8 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom,
affect = flags & (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG); affect = flags & (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG);
lxcDriverLock(driver); lxcDriverLock(driver);
cfg = virLXCDriverGetConfig(driver);
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
if (!vm) { if (!vm) {
...@@ -4524,7 +4571,7 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom, ...@@ -4524,7 +4571,7 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom,
/* Finally, if no error until here, we can save config. */ /* Finally, if no error until here, we can save config. */
if (flags & VIR_DOMAIN_AFFECT_CONFIG) { if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
ret = virDomainSaveConfig(driver->configDir, vmdef); ret = virDomainSaveConfig(cfg->configDir, vmdef);
if (!ret) { if (!ret) {
virDomainObjAssignDef(vm, vmdef, false, NULL); virDomainObjAssignDef(vm, vmdef, false, NULL);
vmdef = NULL; vmdef = NULL;
...@@ -4539,6 +4586,7 @@ cleanup: ...@@ -4539,6 +4586,7 @@ cleanup:
if (vm) if (vm)
virObjectUnlock(vm); virObjectUnlock(vm);
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
virObjectUnref(cfg);
return ret; return ret;
} }
...@@ -4553,6 +4601,7 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom, ...@@ -4553,6 +4601,7 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
virDomainDeviceDefPtr dev = NULL, dev_copy = NULL; virDomainDeviceDefPtr dev = NULL, dev_copy = NULL;
int ret = -1; int ret = -1;
unsigned int affect; unsigned int affect;
virLXCDriverConfigPtr cfg = NULL;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1); VIR_DOMAIN_AFFECT_CONFIG, -1);
...@@ -4560,6 +4609,8 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom, ...@@ -4560,6 +4609,8 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
affect = flags & (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG); affect = flags & (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG);
lxcDriverLock(driver); lxcDriverLock(driver);
cfg = virLXCDriverGetConfig(driver);
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
if (!vm) { if (!vm) {
...@@ -4636,7 +4687,7 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom, ...@@ -4636,7 +4687,7 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
* changed even if we failed to attach the device. For example, * changed even if we failed to attach the device. For example,
* a new controller may be created. * a new controller may be created.
*/ */
if (virDomainSaveStatus(driver->xmlopt, driver->stateDir, vm) < 0) { if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) {
ret = -1; ret = -1;
goto cleanup; goto cleanup;
} }
...@@ -4644,7 +4695,7 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom, ...@@ -4644,7 +4695,7 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
/* Finally, if no error until here, we can save config. */ /* Finally, if no error until here, we can save config. */
if (flags & VIR_DOMAIN_AFFECT_CONFIG) { if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
ret = virDomainSaveConfig(driver->configDir, vmdef); ret = virDomainSaveConfig(cfg->configDir, vmdef);
if (!ret) { if (!ret) {
virDomainObjAssignDef(vm, vmdef, false, NULL); virDomainObjAssignDef(vm, vmdef, false, NULL);
vmdef = NULL; vmdef = NULL;
...@@ -4659,6 +4710,7 @@ cleanup: ...@@ -4659,6 +4710,7 @@ cleanup:
if (vm) if (vm)
virObjectUnlock(vm); virObjectUnlock(vm);
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
virObjectUnref(cfg);
return ret; return ret;
} }
......
...@@ -225,6 +225,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver, ...@@ -225,6 +225,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
size_t i; size_t i;
virLXCDomainObjPrivatePtr priv = vm->privateData; virLXCDomainObjPrivatePtr priv = vm->privateData;
virNetDevVPortProfilePtr vport = NULL; virNetDevVPortProfilePtr vport = NULL;
virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
VIR_DEBUG("Stopping VM name=%s pid=%d reason=%d", VIR_DEBUG("Stopping VM name=%s pid=%d reason=%d",
vm->def->name, (int)vm->pid, (int)reason); vm->def->name, (int)vm->pid, (int)reason);
...@@ -249,8 +250,8 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver, ...@@ -249,8 +250,8 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
priv->monitor = NULL; priv->monitor = NULL;
} }
virPidFileDelete(driver->stateDir, vm->def->name); virPidFileDelete(cfg->stateDir, vm->def->name);
virDomainDeleteConfig(driver->stateDir, NULL, vm); virDomainDeleteConfig(cfg->stateDir, NULL, vm);
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, reason); virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, reason);
vm->pid = -1; vm->pid = -1;
...@@ -301,6 +302,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver, ...@@ -301,6 +302,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
vm->def->id = -1; vm->def->id = -1;
vm->newDef = NULL; vm->newDef = NULL;
} }
virObjectUnref(cfg);
} }
...@@ -367,6 +369,7 @@ char *virLXCProcessSetupInterfaceDirect(virConnectPtr conn, ...@@ -367,6 +369,7 @@ char *virLXCProcessSetupInterfaceDirect(virConnectPtr conn,
virLXCDriverPtr driver = conn->privateData; virLXCDriverPtr driver = conn->privateData;
virNetDevBandwidthPtr bw; virNetDevBandwidthPtr bw;
virNetDevVPortProfilePtr prof; virNetDevVPortProfilePtr prof;
virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
/* XXX how todo bandwidth controls ? /* XXX how todo bandwidth controls ?
* Since the 'net-ifname' is about to be moved to a different * Since the 'net-ifname' is about to be moved to a different
...@@ -402,13 +405,14 @@ char *virLXCProcessSetupInterfaceDirect(virConnectPtr conn, ...@@ -402,13 +405,14 @@ char *virLXCProcessSetupInterfaceDirect(virConnectPtr conn,
virDomainNetGetActualVirtPortProfile(net), virDomainNetGetActualVirtPortProfile(net),
&res_ifname, &res_ifname,
VIR_NETDEV_VPORT_PROFILE_OP_CREATE, VIR_NETDEV_VPORT_PROFILE_OP_CREATE,
driver->stateDir, cfg->stateDir,
virDomainNetGetActualBandwidth(net)) < 0) virDomainNetGetActualBandwidth(net)) < 0)
goto cleanup; goto cleanup;
ret = res_ifname; ret = res_ifname;
cleanup: cleanup:
virObjectUnref(cfg);
return ret; return ret;
} }
...@@ -673,10 +677,12 @@ static void virLXCProcessMonitorInitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED ...@@ -673,10 +677,12 @@ static void virLXCProcessMonitorInitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED
{ {
virLXCDriverPtr driver = lxc_driver; virLXCDriverPtr driver = lxc_driver;
virLXCDomainObjPrivatePtr priv; virLXCDomainObjPrivatePtr priv;
virLXCDriverConfigPtr cfg;
ino_t inode; ino_t inode;
lxcDriverLock(driver); lxcDriverLock(driver);
virObjectLock(vm); virObjectLock(vm);
cfg = virLXCDriverGetConfig(driver);
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
priv = vm->privateData; priv = vm->privateData;
...@@ -692,10 +698,11 @@ static void virLXCProcessMonitorInitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED ...@@ -692,10 +698,11 @@ static void virLXCProcessMonitorInitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED
} }
virDomainAuditInit(vm, initpid, inode); virDomainAuditInit(vm, initpid, inode);
if (virDomainSaveStatus(lxc_driver->xmlopt, lxc_driver->stateDir, vm) < 0) if (virDomainSaveStatus(lxc_driver->xmlopt, cfg->stateDir, vm) < 0)
VIR_WARN("Cannot update XML with PID for LXC %s", vm->def->name); VIR_WARN("Cannot update XML with PID for LXC %s", vm->def->name);
virObjectUnlock(vm); virObjectUnlock(vm);
virObjectUnref(cfg);
} }
static virLXCMonitorCallbacks monitorCallbacks = { static virLXCMonitorCallbacks monitorCallbacks = {
...@@ -709,6 +716,7 @@ static virLXCMonitorPtr virLXCProcessConnectMonitor(virLXCDriverPtr driver, ...@@ -709,6 +716,7 @@ static virLXCMonitorPtr virLXCProcessConnectMonitor(virLXCDriverPtr driver,
virDomainObjPtr vm) virDomainObjPtr vm)
{ {
virLXCMonitorPtr monitor = NULL; virLXCMonitorPtr monitor = NULL;
virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
if (virSecurityManagerSetSocketLabel(driver->securityManager, vm->def) < 0) if (virSecurityManagerSetSocketLabel(driver->securityManager, vm->def) < 0)
goto cleanup; goto cleanup;
...@@ -717,7 +725,7 @@ static virLXCMonitorPtr virLXCProcessConnectMonitor(virLXCDriverPtr driver, ...@@ -717,7 +725,7 @@ static virLXCMonitorPtr virLXCProcessConnectMonitor(virLXCDriverPtr driver,
* deleted while the monitor is active */ * deleted while the monitor is active */
virObjectRef(vm); virObjectRef(vm);
monitor = virLXCMonitorNew(vm, driver->stateDir, &monitorCallbacks); monitor = virLXCMonitorNew(vm, cfg->stateDir, &monitorCallbacks);
if (monitor == NULL) if (monitor == NULL)
virObjectUnref(vm); virObjectUnref(vm);
...@@ -731,6 +739,7 @@ static virLXCMonitorPtr virLXCProcessConnectMonitor(virLXCDriverPtr driver, ...@@ -731,6 +739,7 @@ static virLXCMonitorPtr virLXCProcessConnectMonitor(virLXCDriverPtr driver,
} }
cleanup: cleanup:
virObjectUnref(cfg);
return monitor; return monitor;
} }
...@@ -812,6 +821,7 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver, ...@@ -812,6 +821,7 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver,
char *filterstr; char *filterstr;
char *outputstr; char *outputstr;
virCommandPtr cmd; virCommandPtr cmd;
virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
cmd = virCommandNew(vm->def->emulator); cmd = virCommandNew(vm->def->emulator);
...@@ -832,7 +842,7 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver, ...@@ -832,7 +842,7 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver,
VIR_FREE(filterstr); VIR_FREE(filterstr);
} }
if (driver->log_libvirtd) { if (cfg->log_libvirtd) {
if (virLogGetNbOutputs() > 0) { if (virLogGetNbOutputs() > 0) {
outputstr = virLogGetOutputs(); outputstr = virLogGetOutputs();
if (!outputstr) { if (!outputstr) {
...@@ -878,6 +888,7 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver, ...@@ -878,6 +888,7 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver,
return cmd; return cmd;
cleanup: cleanup:
virCommandFree(cmd); virCommandFree(cmd);
virObjectUnref(cfg);
return NULL; return NULL;
} }
...@@ -1052,6 +1063,7 @@ int virLXCProcessStart(virConnectPtr conn, ...@@ -1052,6 +1063,7 @@ int virLXCProcessStart(virConnectPtr conn,
virCommandPtr cmd = NULL; virCommandPtr cmd = NULL;
virLXCDomainObjPrivatePtr priv = vm->privateData; virLXCDomainObjPrivatePtr priv = vm->privateData;
virErrorPtr err = NULL; virErrorPtr err = NULL;
virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
virCgroupFree(&priv->cgroup); virCgroupFree(&priv->cgroup);
...@@ -1080,15 +1092,15 @@ int virLXCProcessStart(virConnectPtr conn, ...@@ -1080,15 +1092,15 @@ int virLXCProcessStart(virConnectPtr conn,
return -1; return -1;
} }
if (virFileMakePath(driver->logDir) < 0) { if (virFileMakePath(cfg->logDir) < 0) {
virReportSystemError(errno, virReportSystemError(errno,
_("Cannot create log directory '%s'"), _("Cannot create log directory '%s'"),
driver->logDir); cfg->logDir);
return -1; return -1;
} }
if (virAsprintf(&logfile, "%s/%s.log", if (virAsprintf(&logfile, "%s/%s.log",
driver->logDir, vm->def->name) < 0) cfg->logDir, vm->def->name) < 0)
return -1; return -1;
/* Do this up front, so any part of the startup process can add /* Do this up front, so any part of the startup process can add
...@@ -1178,7 +1190,7 @@ int virLXCProcessStart(virConnectPtr conn, ...@@ -1178,7 +1190,7 @@ int virLXCProcessStart(virConnectPtr conn,
goto cleanup; goto cleanup;
/* Save the configuration for the controller */ /* Save the configuration for the controller */
if (virDomainSaveConfig(driver->stateDir, vm->def) < 0) if (virDomainSaveConfig(cfg->stateDir, vm->def) < 0)
goto cleanup; goto cleanup;
if ((logfd = open(logfile, O_WRONLY | O_APPEND | O_CREAT, if ((logfd = open(logfile, O_WRONLY | O_APPEND | O_CREAT,
...@@ -1253,7 +1265,7 @@ int virLXCProcessStart(virConnectPtr conn, ...@@ -1253,7 +1265,7 @@ int virLXCProcessStart(virConnectPtr conn,
goto cleanup; goto cleanup;
/* And get its pid */ /* And get its pid */
if ((r = virPidFileRead(driver->stateDir, vm->def->name, &vm->pid)) < 0) { if ((r = virPidFileRead(cfg->stateDir, vm->def->name, &vm->pid)) < 0) {
char out[1024]; char out[1024];
if (virLXCProcessReadLogOutput(vm, logfile, pos, out, 1024) > 0) if (virLXCProcessReadLogOutput(vm, logfile, pos, out, 1024) > 0)
...@@ -1262,7 +1274,7 @@ int virLXCProcessStart(virConnectPtr conn, ...@@ -1262,7 +1274,7 @@ int virLXCProcessStart(virConnectPtr conn,
else else
virReportSystemError(-r, virReportSystemError(-r,
_("Failed to read pid file %s/%s.pid"), _("Failed to read pid file %s/%s.pid"),
driver->stateDir, vm->def->name); cfg->stateDir, vm->def->name);
goto cleanup; goto cleanup;
} }
...@@ -1301,7 +1313,7 @@ int virLXCProcessStart(virConnectPtr conn, ...@@ -1301,7 +1313,7 @@ int virLXCProcessStart(virConnectPtr conn,
* location for the benefit of libvirt_lxc. We're now overwriting * location for the benefit of libvirt_lxc. We're now overwriting
* it with the live status XML instead. This is a (currently * it with the live status XML instead. This is a (currently
* harmless) inconsistency we should fix one day */ * harmless) inconsistency we should fix one day */
if (virDomainSaveStatus(driver->xmlopt, driver->stateDir, vm) < 0) if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
goto error; goto error;
/* finally we can call the 'started' hook script if any */ /* finally we can call the 'started' hook script if any */
...@@ -1364,6 +1376,7 @@ cleanup: ...@@ -1364,6 +1376,7 @@ cleanup:
VIR_FORCE_CLOSE(handshakefds[0]); VIR_FORCE_CLOSE(handshakefds[0]);
VIR_FORCE_CLOSE(handshakefds[1]); VIR_FORCE_CLOSE(handshakefds[1]);
VIR_FREE(logfile); VIR_FREE(logfile);
virObjectUnref(cfg);
if (err) { if (err) {
virSetError(err); virSetError(err);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册