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. --- src/lxc/lxc_conf.c | 81 +++++++++++++++++++++------- src/lxc/lxc_conf.h | 41 +++++++++----- src/lxc/lxc_driver.c | 145 ++++++++++++++++++++++++++++++++++---------------- src/lxc/lxc_process.c | 39 +++++++++----- 4 files changed, 214 insertions(+), 92 deletions(-) diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index 78b1559..4e97f10 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -41,6 +41,22 @@ #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 */ virCapsPtr lxcCapsInit(virLXCDriverPtr driver) @@ -146,28 +162,42 @@ lxcDomainXMLConfInit(void) } -int lxcLoadDriverConfig(virLXCDriverPtr driver) +virLXCDriverConfigPtr +virLXCDriverConfigNew(void) { - char *filename; - virConfPtr conf; - virConfValuePtr p; + virLXCDriverConfigPtr cfg; + + if (virLXCConfigInitialize() < 0) + return NULL; - driver->securityDefaultConfined = false; - driver->securityRequireConfined = false; + if (!(cfg = virObjectNew(virLXCDriverConfigClass))) + return NULL; + + cfg->securityDefaultConfined = false; + cfg->securityRequireConfined = false; /* 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; - if (VIR_STRDUP(driver->stateDir, LXC_STATE_DIR) < 0) + if (VIR_STRDUP(cfg->stateDir, LXC_STATE_DIR) < 0) goto error; - if (VIR_STRDUP(driver->logDir, LXC_LOG_DIR) < 0) + if (VIR_STRDUP(cfg->logDir, LXC_LOG_DIR) < 0) goto error; - if (VIR_STRDUP(driver->autostartDir, LXC_AUTOSTART_DIR) < 0) + if (VIR_STRDUP(cfg->autostartDir, LXC_AUTOSTART_DIR) < 0) goto error; + return cfg; +error: + virObjectUnref(cfg); + return NULL; +} - if (VIR_STRDUP(filename, SYSCONFDIR "/libvirt/lxc.conf") < 0) - goto error; +int +virLXCLoadDriverConfig(virLXCDriverConfigPtr cfg, + const char *filename) +{ + virConfPtr conf; + virConfValuePtr p; /* Avoid error from non-existant or unreadable file. */ if (access(filename, R_OK) == -1) @@ -186,12 +216,12 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver) p = virConfGetValue(conf, "log_with_libvirtd"); 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"); CHECK_TYPE("security_driver", VIR_CONF_STRING); if (p && p->str) { - if (VIR_STRDUP(driver->securityDriverName, p->str) < 0) { + if (VIR_STRDUP(cfg->securityDriverName, p->str) < 0) { virConfFree(conf); return -1; } @@ -199,11 +229,11 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver) p = virConfGetValue(conf, "security_default_confined"); 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"); CHECK_TYPE("security_require_confined", VIR_CONF_LONG); - if (p) driver->securityRequireConfined = p->l; + if (p) cfg->securityRequireConfined = p->l; #undef CHECK_TYPE @@ -211,9 +241,22 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver) virConfFree(conf); done: - VIR_FREE(filename); return 0; +} -error: - return -1; +virLXCDriverConfigPtr virLXCDriverGetConfig(virLXCDriverPtr driver) +{ + 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); } diff --git a/src/lxc/lxc_conf.h b/src/lxc/lxc_conf.h index 5a5b9aa..6ca6198 100644 --- a/src/lxc/lxc_conf.h +++ b/src/lxc/lxc_conf.h @@ -46,44 +46,57 @@ typedef struct _virLXCDriver virLXCDriver; 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 { virMutex lock; + virLXCDriverConfigPtr config; + virCapsPtr caps; - virDomainXMLOptionPtr xmlopt; virCgroupPtr cgroup; + virDomainXMLOptionPtr xmlopt; + virSysinfoDefPtr hostsysinfo; size_t nactive; + virStateInhibitCallback inhibitCallback; void *inhibitOpaque; virDomainObjListPtr domains; - char *configDir; - char *autostartDir; - char *stateDir; - char *logDir; - int log_libvirtd; - int have_netns; virUSBDeviceListPtr activeUsbHostdevs; virDomainEventStatePtr domainEventState; - char *securityDriverName; - bool securityDefaultConfined; - bool securityRequireConfined; virSecurityManagerPtr securityManager; - /* Mapping of 'char *uuidstr' -> virConnectPtr - * of guests which will be automatically killed - * when the virConnectPtr is closed*/ virHashTablePtr autodestroy; }; -int lxcLoadDriverConfig(virLXCDriverPtr driver); +virLXCDriverConfigPtr virLXCDriverConfigNew(void); +virLXCDriverConfigPtr virLXCDriverGetConfig(virLXCDriverPtr driver); +int virLXCLoadDriverConfig(virLXCDriverConfigPtr cfg, + const char *filename); virCapsPtr lxcCapsInit(virLXCDriverPtr driver); virDomainXMLOptionPtr lxcDomainXMLConfInit(void); diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 098051b..855dad3 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -456,8 +456,11 @@ static virDomainPtr lxcDomainDefineXML(virConnectPtr conn, const char *xml) virDomainPtr dom = NULL; virDomainEventPtr event = NULL; virDomainDefPtr oldDef = NULL; + virLXCDriverConfigPtr cfg = NULL; lxcDriverLock(driver); + cfg = virLXCDriverGetConfig(driver); + if (!(def = virDomainDefParseString(xml, driver->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_LXC, VIR_DOMAIN_XML_INACTIVE))) @@ -469,7 +472,7 @@ static virDomainPtr lxcDomainDefineXML(virConnectPtr conn, const char *xml) if (virSecurityManagerVerify(driver->securityManager, def) < 0) goto cleanup; - if ((def->nets != NULL) && !(driver->have_netns)) { + if ((def->nets != NULL) && !(cfg->have_netns)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("System lacks NETNS support")); goto cleanup; @@ -482,7 +485,7 @@ static virDomainPtr lxcDomainDefineXML(virConnectPtr conn, const char *xml) def = NULL; vm->persistent = 1; - if (virDomainSaveConfig(driver->configDir, + if (virDomainSaveConfig(cfg->configDir, vm->newDef ? vm->newDef : vm->def) < 0) { virDomainObjListRemove(driver->domains, vm); vm = NULL; @@ -507,6 +510,7 @@ cleanup: if (event) virDomainEventStateQueue(driver->domainEventState, event); lxcDriverUnlock(driver); + virObjectUnref(cfg); return dom; } @@ -517,10 +521,13 @@ static int lxcDomainUndefineFlags(virDomainPtr dom, virDomainObjPtr vm; virDomainEventPtr event = NULL; int ret = -1; + virLXCDriverConfigPtr cfg = NULL; virCheckFlags(0, -1); lxcDriverLock(driver); + cfg = virLXCDriverGetConfig(driver); + vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); if (!vm) { char uuidstr[VIR_UUID_STRING_BUFLEN]; @@ -539,8 +546,8 @@ static int lxcDomainUndefineFlags(virDomainPtr dom, goto cleanup; } - if (virDomainDeleteConfig(driver->configDir, - driver->autostartDir, + if (virDomainDeleteConfig(cfg->configDir, + cfg->autostartDir, vm) < 0) goto cleanup; @@ -563,6 +570,7 @@ cleanup: if (event) virDomainEventStateQueue(driver->domainEventState, event); lxcDriverUnlock(driver); + virObjectUnref(cfg); return ret; } @@ -1027,10 +1035,13 @@ static int lxcDomainCreateWithFlags(virDomainPtr dom, unsigned int flags) virDomainObjPtr vm; virDomainEventPtr event = NULL; int ret = -1; + virLXCDriverConfigPtr cfg = NULL; virCheckFlags(VIR_DOMAIN_START_AUTODESTROY, -1); lxcDriverLock(driver); + cfg = virLXCDriverGetConfig(driver); + vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); if (!vm) { char uuidstr[VIR_UUID_STRING_BUFLEN]; @@ -1043,7 +1054,7 @@ static int lxcDomainCreateWithFlags(virDomainPtr dom, unsigned int flags) if (virDomainCreateWithFlagsEnsureACL(dom->conn, vm->def) < 0) goto cleanup; - if ((vm->def->nets != NULL) && !(driver->have_netns)) { + if ((vm->def->nets != NULL) && !(cfg->have_netns)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("System lacks NETNS support")); goto cleanup; @@ -1074,6 +1085,7 @@ cleanup: if (event) virDomainEventStateQueue(driver->domainEventState, event); lxcDriverUnlock(driver); + virObjectUnref(cfg); return ret; } @@ -1103,16 +1115,20 @@ static int lxcDomainCreate(virDomainPtr dom) static virDomainPtr lxcDomainCreateXML(virConnectPtr conn, const char *xml, - unsigned int flags) { + unsigned int flags) +{ virLXCDriverPtr driver = conn->privateData; virDomainObjPtr vm = NULL; virDomainDefPtr def; virDomainPtr dom = NULL; virDomainEventPtr event = NULL; + virLXCDriverConfigPtr cfg = NULL; virCheckFlags(VIR_DOMAIN_START_AUTODESTROY, NULL); lxcDriverLock(driver); + cfg = virLXCDriverGetConfig(driver); + if (!(def = virDomainDefParseString(xml, driver->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_LXC, VIR_DOMAIN_XML_INACTIVE))) @@ -1124,7 +1140,7 @@ lxcDomainCreateXML(virConnectPtr conn, if (virSecurityManagerVerify(driver->securityManager, def) < 0) goto cleanup; - if ((def->nets != NULL) && !(driver->have_netns)) { + if ((def->nets != NULL) && !(cfg->have_netns)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("System lacks NETNS support")); goto cleanup; @@ -1163,6 +1179,7 @@ cleanup: if (event) virDomainEventStateQueue(driver->domainEventState, event); lxcDriverUnlock(driver); + virObjectUnref(cfg); return dom; } @@ -1456,26 +1473,24 @@ static int lxcCheckNetNsSupport(void) } -static int -lxcSecurityInit(virLXCDriverPtr driver) +static virSecurityManagerPtr +lxcSecurityInit(virLXCDriverConfigPtr cfg) { - VIR_INFO("lxcSecurityInit %s", driver->securityDriverName); - virSecurityManagerPtr mgr = virSecurityManagerNew(driver->securityDriverName, + VIR_INFO("lxcSecurityInit %s", cfg->securityDriverName); + virSecurityManagerPtr mgr = virSecurityManagerNew(cfg->securityDriverName, LXC_DRIVER_NAME, false, - driver->securityDefaultConfined, - driver->securityRequireConfined); + cfg->securityDefaultConfined, + cfg->securityRequireConfined); if (!mgr) goto error; - driver->securityManager = mgr; - - return 0; + return mgr; error: VIR_ERROR(_("Failed to initialize security drivers")); virObjectUnref(mgr); - return -1; + return NULL; } @@ -1484,6 +1499,7 @@ static int lxcStateInitialize(bool privileged, void *opaque ATTRIBUTE_UNUSED) { char *ld; + virLXCDriverConfigPtr cfg = NULL; /* Valgrind gets very annoyed when we clone containers, so * disable LXC when under valgrind @@ -1525,14 +1541,17 @@ static int lxcStateInitialize(bool privileged, lxc_driver->hostsysinfo = virSysinfoRead(); - lxc_driver->log_libvirtd = 0; /* by default log to container logfile */ - lxc_driver->have_netns = lxcCheckNetNsSupport(); + if (!(lxc_driver->config = cfg = virLXCDriverConfigNew())) + goto cleanup; + + cfg->log_libvirtd = 0; /* by default log to container logfile */ + cfg->have_netns = lxcCheckNetNsSupport(); /* Call function to load lxc driver configuration information */ - if (lxcLoadDriverConfig(lxc_driver) < 0) + if (virLXCLoadDriverConfig(cfg, SYSCONFDIR "/libvirt/lxc.conf") < 0) goto cleanup; - if (lxcSecurityInit(lxc_driver) < 0) + if (!(lxc_driver->securityManager = lxcSecurityInit(cfg))) goto cleanup; if ((lxc_driver->activeUsbHostdevs = virUSBDeviceListNew()) == NULL) @@ -1549,7 +1568,7 @@ static int lxcStateInitialize(bool privileged, /* Get all the running persistent or transient configs first */ if (virDomainObjListLoadAllConfigs(lxc_driver->domains, - lxc_driver->stateDir, + cfg->stateDir, NULL, 1, lxc_driver->caps, lxc_driver->xmlopt, @@ -1561,8 +1580,8 @@ static int lxcStateInitialize(bool privileged, /* Then inactive persistent configs */ if (virDomainObjListLoadAllConfigs(lxc_driver->domains, - lxc_driver->configDir, - lxc_driver->autostartDir, 0, + cfg->configDir, + cfg->autostartDir, 0, lxc_driver->caps, lxc_driver->xmlopt, 1 << VIR_DOMAIN_VIRT_LXC, @@ -1604,19 +1623,23 @@ static void lxcNotifyLoadDomain(virDomainObjPtr vm, int newVM, void *opaque) */ static int lxcStateReload(void) { + virLXCDriverConfigPtr cfg = NULL; + if (!lxc_driver) return 0; lxcDriverLock(lxc_driver); + cfg = virLXCDriverGetConfig(lxc_driver); + virDomainObjListLoadAllConfigs(lxc_driver->domains, - lxc_driver->configDir, - lxc_driver->autostartDir, 0, + cfg->configDir, + cfg->autostartDir, 0, lxc_driver->caps, lxc_driver->xmlopt, 1 << VIR_DOMAIN_VIRT_LXC, lxcNotifyLoadDomain, lxc_driver); lxcDriverUnlock(lxc_driver); - + virObjectUnref(cfg); return 0; } @@ -1638,10 +1661,7 @@ static int lxcStateCleanup(void) virObjectUnref(lxc_driver->caps); virObjectUnref(lxc_driver->securityManager); virObjectUnref(lxc_driver->xmlopt); - VIR_FREE(lxc_driver->configDir); - VIR_FREE(lxc_driver->autostartDir); - VIR_FREE(lxc_driver->stateDir); - VIR_FREE(lxc_driver->logDir); + virObjectUnref(lxc_driver->config); lxcDriverUnlock(lxc_driver); virMutexDestroy(&lxc_driver->lock); VIR_FREE(lxc_driver); @@ -1852,6 +1872,7 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom, int ret = -1; int rc; virLXCDomainObjPrivatePtr priv; + virLXCDriverConfigPtr cfg = NULL; virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); @@ -1867,6 +1888,8 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom, lxcDriverLock(driver); + cfg = virLXCDriverGetConfig(driver); + vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); if (vm == NULL) { @@ -1945,12 +1968,12 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom, } } - if (virDomainSaveStatus(driver->xmlopt, driver->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) goto cleanup; if (flags & VIR_DOMAIN_AFFECT_CONFIG) { - rc = virDomainSaveConfig(driver->configDir, vmdef); + rc = virDomainSaveConfig(cfg->configDir, vmdef); if (rc < 0) goto cleanup; @@ -1965,6 +1988,7 @@ cleanup: if (vm) virObjectUnlock(vm); lxcDriverUnlock(driver); + virObjectUnref(cfg); return ret; } @@ -2106,6 +2130,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, virDomainDefPtr persistentDef = NULL; int ret = -1; virLXCDomainObjPrivatePtr priv; + virLXCDriverConfigPtr cfg = NULL; virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); @@ -2117,6 +2142,8 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, lxcDriverLock(driver); + cfg = virLXCDriverGetConfig(driver); + vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); if (vm == NULL) { @@ -2179,7 +2206,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, } } - if (virDomainSaveConfig(driver->configDir, persistentDef) < 0) + if (virDomainSaveConfig(cfg->configDir, persistentDef) < 0) goto cleanup; } @@ -2188,6 +2215,7 @@ cleanup: if (vm) virObjectUnlock(vm); lxcDriverUnlock(driver); + virObjectUnref(cfg); return ret; } @@ -2391,13 +2419,17 @@ cleanup: } static int lxcDomainSetAutostart(virDomainPtr dom, - int autostart) { + int autostart) +{ virLXCDriverPtr driver = dom->conn->privateData; virDomainObjPtr vm; char *configFile = NULL, *autostartLink = NULL; int ret = -1; + virLXCDriverConfigPtr cfg = NULL; lxcDriverLock(driver); + cfg = virLXCDriverGetConfig(driver); + vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); if (!vm) { @@ -2424,20 +2456,20 @@ static int lxcDomainSetAutostart(virDomainPtr dom, goto cleanup; } - configFile = virDomainConfigFile(driver->configDir, + configFile = virDomainConfigFile(cfg->configDir, vm->def->name); if (configFile == NULL) goto cleanup; - autostartLink = virDomainConfigFile(driver->autostartDir, + autostartLink = virDomainConfigFile(cfg->autostartDir, vm->def->name); if (autostartLink == NULL) goto cleanup; if (autostart) { - if (virFileMakePath(driver->autostartDir) < 0) { + if (virFileMakePath(cfg->autostartDir) < 0) { virReportSystemError(errno, _("Cannot create autostart directory %s"), - driver->autostartDir); + cfg->autostartDir); goto cleanup; } @@ -2465,6 +2497,7 @@ cleanup: if (vm) virObjectUnlock(vm); lxcDriverUnlock(driver); + virObjectUnref(cfg); return ret; } @@ -2560,8 +2593,11 @@ static int lxcDomainSuspend(virDomainPtr dom) virDomainObjPtr vm; virDomainEventPtr event = NULL; int ret = -1; + virLXCDriverConfigPtr cfg = NULL; lxcDriverLock(driver); + cfg = virLXCDriverGetConfig(driver); + vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); if (!vm) { @@ -2594,7 +2630,7 @@ static int lxcDomainSuspend(virDomainPtr dom) VIR_DOMAIN_EVENT_SUSPENDED_PAUSED); } - if (virDomainSaveStatus(driver->xmlopt, driver->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) goto cleanup; ret = 0; @@ -2604,6 +2640,7 @@ cleanup: if (vm) virObjectUnlock(vm); lxcDriverUnlock(driver); + virObjectUnref(cfg); return ret; } @@ -2614,8 +2651,11 @@ static int lxcDomainResume(virDomainPtr dom) virDomainEventPtr event = NULL; int ret = -1; virLXCDomainObjPrivatePtr priv; + virLXCDriverConfigPtr cfg = NULL; lxcDriverLock(driver); + cfg = virLXCDriverGetConfig(driver); + vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); if (!vm) { @@ -2651,7 +2691,7 @@ static int lxcDomainResume(virDomainPtr dom) VIR_DOMAIN_EVENT_RESUMED_UNPAUSED); } - if (virDomainSaveStatus(driver->xmlopt, driver->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) goto cleanup; ret = 0; @@ -2661,6 +2701,7 @@ cleanup: if (vm) virObjectUnlock(vm); lxcDriverUnlock(driver); + virObjectUnref(cfg); return ret; } @@ -4284,6 +4325,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom, virDomainDeviceDefPtr dev = NULL, dev_copy = NULL; int ret = -1; unsigned int affect; + virLXCDriverConfigPtr cfg = NULL; virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); @@ -4291,6 +4333,8 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom, affect = flags & (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG); lxcDriverLock(driver); + cfg = virLXCDriverGetConfig(driver); + vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); if (!vm) { @@ -4366,7 +4410,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom, * changed even if we failed to attach the device. For example, * a new controller may be created. */ - if (virDomainSaveStatus(driver->xmlopt, driver->stateDir, vm) < 0) { + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) { ret = -1; goto cleanup; } @@ -4374,7 +4418,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom, /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_AFFECT_CONFIG) { - ret = virDomainSaveConfig(driver->configDir, vmdef); + ret = virDomainSaveConfig(cfg->configDir, vmdef); if (!ret) { virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef = NULL; @@ -4389,6 +4433,7 @@ cleanup: if (vm) virObjectUnlock(vm); lxcDriverUnlock(driver); + virObjectUnref(cfg); return ret; } @@ -4411,6 +4456,7 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom, virDomainDeviceDefPtr dev = NULL, dev_copy = NULL; int ret = -1; unsigned int affect; + virLXCDriverConfigPtr cfg = NULL; virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG | @@ -4419,6 +4465,8 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom, affect = flags & (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG); lxcDriverLock(driver); + cfg = virLXCDriverGetConfig(driver); + vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); if (!vm) { @@ -4495,7 +4543,7 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom, /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_AFFECT_CONFIG) { - ret = virDomainSaveConfig(driver->configDir, vmdef); + ret = virDomainSaveConfig(cfg->configDir, vmdef); if (!ret) { virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef = NULL; @@ -4510,6 +4558,7 @@ cleanup: if (vm) virObjectUnlock(vm); lxcDriverUnlock(driver); + virObjectUnref(cfg); return ret; } @@ -4524,6 +4573,7 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom, virDomainDeviceDefPtr dev = NULL, dev_copy = NULL; int ret = -1; unsigned int affect; + virLXCDriverConfigPtr cfg = NULL; virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); @@ -4531,6 +4581,8 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom, affect = flags & (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG); lxcDriverLock(driver); + cfg = virLXCDriverGetConfig(driver); + vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); if (!vm) { @@ -4607,7 +4659,7 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom, * changed even if we failed to attach the device. For example, * a new controller may be created. */ - if (virDomainSaveStatus(driver->xmlopt, driver->stateDir, vm) < 0) { + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) { ret = -1; goto cleanup; } @@ -4615,7 +4667,7 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom, /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_AFFECT_CONFIG) { - ret = virDomainSaveConfig(driver->configDir, vmdef); + ret = virDomainSaveConfig(cfg->configDir, vmdef); if (!ret) { virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef = NULL; @@ -4630,6 +4682,7 @@ cleanup: if (vm) virObjectUnlock(vm); lxcDriverUnlock(driver); + virObjectUnref(cfg); return ret; } diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 396e0eb..1024576 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -224,6 +224,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver, size_t i; virLXCDomainObjPrivatePtr priv = vm->privateData; virNetDevVPortProfilePtr vport = NULL; + virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver); VIR_DEBUG("Stopping VM name=%s pid=%d reason=%d", vm->def->name, (int)vm->pid, (int)reason); @@ -248,8 +249,8 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver, priv->monitor = NULL; } - virPidFileDelete(driver->stateDir, vm->def->name); - virDomainDeleteConfig(driver->stateDir, NULL, vm); + virPidFileDelete(cfg->stateDir, vm->def->name); + virDomainDeleteConfig(cfg->stateDir, NULL, vm); virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, reason); vm->pid = -1; @@ -300,6 +301,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver, vm->def->id = -1; vm->newDef = NULL; } + virObjectUnref(cfg); } @@ -366,6 +368,7 @@ char *virLXCProcessSetupInterfaceDirect(virConnectPtr conn, virLXCDriverPtr driver = conn->privateData; virNetDevBandwidthPtr bw; virNetDevVPortProfilePtr prof; + virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver); /* XXX how todo bandwidth controls ? * Since the 'net-ifname' is about to be moved to a different @@ -401,13 +404,14 @@ char *virLXCProcessSetupInterfaceDirect(virConnectPtr conn, virDomainNetGetActualVirtPortProfile(net), &res_ifname, VIR_NETDEV_VPORT_PROFILE_OP_CREATE, - driver->stateDir, + cfg->stateDir, virDomainNetGetActualBandwidth(net)) < 0) goto cleanup; ret = res_ifname; cleanup: + virObjectUnref(cfg); return ret; } @@ -672,10 +676,12 @@ static void virLXCProcessMonitorInitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED { virLXCDriverPtr driver = lxc_driver; virLXCDomainObjPrivatePtr priv; + virLXCDriverConfigPtr cfg; ino_t inode; lxcDriverLock(driver); virObjectLock(vm); + cfg = virLXCDriverGetConfig(driver); lxcDriverUnlock(driver); priv = vm->privateData; @@ -691,10 +697,11 @@ static void virLXCProcessMonitorInitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED } 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); virObjectUnlock(vm); + virObjectUnref(cfg); } static virLXCMonitorCallbacks monitorCallbacks = { @@ -708,6 +715,7 @@ static virLXCMonitorPtr virLXCProcessConnectMonitor(virLXCDriverPtr driver, virDomainObjPtr vm) { virLXCMonitorPtr monitor = NULL; + virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver); if (virSecurityManagerSetSocketLabel(driver->securityManager, vm->def) < 0) goto cleanup; @@ -716,7 +724,7 @@ static virLXCMonitorPtr virLXCProcessConnectMonitor(virLXCDriverPtr driver, * deleted while the monitor is active */ virObjectRef(vm); - monitor = virLXCMonitorNew(vm, driver->stateDir, &monitorCallbacks); + monitor = virLXCMonitorNew(vm, cfg->stateDir, &monitorCallbacks); if (monitor == NULL) virObjectUnref(vm); @@ -730,6 +738,7 @@ static virLXCMonitorPtr virLXCProcessConnectMonitor(virLXCDriverPtr driver, } cleanup: + virObjectUnref(cfg); return monitor; } @@ -809,6 +818,7 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver, char *filterstr; char *outputstr; virCommandPtr cmd; + virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver); cmd = virCommandNew(vm->def->emulator); @@ -829,7 +839,7 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver, VIR_FREE(filterstr); } - if (driver->log_libvirtd) { + if (cfg->log_libvirtd) { if (virLogGetNbOutputs() > 0) { outputstr = virLogGetOutputs(); if (!outputstr) { @@ -869,6 +879,7 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver, return cmd; cleanup: virCommandFree(cmd); + virObjectUnref(cfg); return NULL; } @@ -1042,6 +1053,7 @@ int virLXCProcessStart(virConnectPtr conn, virCommandPtr cmd = NULL; virLXCDomainObjPrivatePtr priv = vm->privateData; virErrorPtr err = NULL; + virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver); virCgroupFree(&priv->cgroup); @@ -1070,15 +1082,15 @@ int virLXCProcessStart(virConnectPtr conn, return -1; } - if (virFileMakePath(driver->logDir) < 0) { + if (virFileMakePath(cfg->logDir) < 0) { virReportSystemError(errno, _("Cannot create log directory '%s'"), - driver->logDir); + cfg->logDir); return -1; } if (virAsprintf(&logfile, "%s/%s.log", - driver->logDir, vm->def->name) < 0) + cfg->logDir, vm->def->name) < 0) return -1; /* Do this up front, so any part of the startup process can add @@ -1168,7 +1180,7 @@ int virLXCProcessStart(virConnectPtr conn, goto cleanup; /* Save the configuration for the controller */ - if (virDomainSaveConfig(driver->stateDir, vm->def) < 0) + if (virDomainSaveConfig(cfg->stateDir, vm->def) < 0) goto cleanup; if ((logfd = open(logfile, O_WRONLY | O_APPEND | O_CREAT, @@ -1242,7 +1254,7 @@ int virLXCProcessStart(virConnectPtr conn, goto cleanup; /* 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]; if (virLXCProcessReadLogOutput(vm, logfile, pos, out, 1024) > 0) @@ -1251,7 +1263,7 @@ int virLXCProcessStart(virConnectPtr conn, else virReportSystemError(-r, _("Failed to read pid file %s/%s.pid"), - driver->stateDir, vm->def->name); + cfg->stateDir, vm->def->name); goto cleanup; } @@ -1290,7 +1302,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->xmlopt, driver->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) goto error; /* finally we can call the 'started' hook script if any */ @@ -1353,6 +1365,7 @@ cleanup: VIR_FORCE_CLOSE(handshakefds[0]); VIR_FORCE_CLOSE(handshakefds[1]); VIR_FREE(logfile); + virObjectUnref(cfg); if (err) { virSetError(err); -- 1.8.1.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list