The libxlDriverPrivate struct contains an variety of data with varying access needs. Similar to the QEMU and LXC drivers, move all the static config data into a dedicated libxlDriverConfig object. The only locking requirement is to hold the driver lock while obtaining an instance of libxlDriverConfig. Once a reference is held on the config object, it can be used completely lockless since it is immutable. Signed-off-by: Jim Fehlig <jfehlig@xxxxxxxx> --- src/libxl/libxl_conf.c | 124 ++++++++++++++++++- src/libxl/libxl_conf.h | 52 +++++--- src/libxl/libxl_driver.c | 313 +++++++++++++++++++++++------------------------ 3 files changed, 309 insertions(+), 180 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 231a53d..19fd8a6 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -64,6 +64,41 @@ static const char *xen_cap_re = "(xen|hvm)-[[:digit:]]+\\.[[:digit:]]+-(x86_32|x static regex_t xen_cap_rec; +static virClassPtr libxlDriverConfigClass; +static void libxlDriverConfigDispose(void *obj); + +static int libxlConfigOnceInit(void) +{ + if (!(libxlDriverConfigClass = virClassNew(virClassForObject(), + "libxlDriverConfig", + sizeof(libxlDriverConfig), + libxlDriverConfigDispose))) + return -1; + + return 0; +} + +VIR_ONCE_GLOBAL_INIT(libxlConfig) + +static void +libxlDriverConfigDispose(void *obj) +{ + libxlDriverConfigPtr cfg = obj; + + virObjectUnref(cfg->caps); + libxl_ctx_free(cfg->ctx); + xtl_logger_destroy(cfg->logger); + if (cfg->logger_file) + VIR_FORCE_FCLOSE(cfg->logger_file); + + VIR_FREE(cfg->configDir); + VIR_FREE(cfg->autostartDir); + VIR_FREE(cfg->logDir); + VIR_FREE(cfg->stateDir); + VIR_FREE(cfg->libDir); + VIR_FREE(cfg->saveDir); +} + static int libxlCapsInitHost(libxl_ctx *ctx, virCapsPtr caps) { @@ -978,8 +1013,8 @@ error: return -1; } -bool -libxlGetAutoballoonConf(libxlDriverPrivatePtr driver) +static bool +libxlGetAutoballoonConf(libxlDriverConfigPtr cfg) { regex_t regex; int ret; @@ -990,11 +1025,94 @@ libxlGetAutoballoonConf(libxlDriverPrivatePtr driver) if (ret) return true; - ret = regexec(®ex, driver->verInfo->commandline, 0, NULL, 0); + ret = regexec(®ex, cfg->verInfo->commandline, 0, NULL, 0); regfree(®ex); return ret == REG_NOMATCH; } +libxlDriverConfigPtr +libxlDriverConfigNew(void) +{ + libxlDriverConfigPtr cfg; + char *log_file = NULL; + char ebuf[1024]; + unsigned int free_mem; + + if (libxlConfigInitialize() < 0) + return NULL; + + if (!(cfg = virObjectNew(libxlDriverConfigClass))) + return NULL; + + if (VIR_STRDUP(cfg->configDir, LIBXL_CONFIG_DIR) < 0) + goto error; + if (VIR_STRDUP(cfg->autostartDir, LIBXL_AUTOSTART_DIR) < 0) + goto error; + if (VIR_STRDUP(cfg->logDir, LIBXL_LOG_DIR) < 0) + goto error; + if (VIR_STRDUP(cfg->stateDir, LIBXL_STATE_DIR) < 0) + goto error; + if (VIR_STRDUP(cfg->libDir, LIBXL_LIB_DIR) < 0) + goto error; + if (VIR_STRDUP(cfg->saveDir, LIBXL_SAVE_DIR) < 0) + goto error; + + if (virAsprintf(&log_file, "%s/libxl-driver.log", cfg->logDir) < 0) + goto error; + + if ((cfg->logger_file = fopen(log_file, "a")) == NULL) { + VIR_ERROR(_("Failed to create log file '%s': %s"), + log_file, virStrerror(errno, ebuf, sizeof(ebuf))); + goto error; + } + VIR_FREE(log_file); + + cfg->logger = + (xentoollog_logger *)xtl_createlogger_stdiostream(cfg->logger_file, + XTL_DEBUG, 0); + if (!cfg->logger) { + VIR_ERROR(_("cannot create logger for libxenlight, disabling driver")); + goto error; + } + + if (libxl_ctx_alloc(&cfg->ctx, LIBXL_VERSION, 0, cfg->logger)) { + VIR_ERROR(_("cannot initialize libxenlight context, probably not " + "running in a Xen Dom0, disabling driver")); + goto error; + } + + if ((cfg->verInfo = libxl_get_version_info(cfg->ctx)) == NULL) { + VIR_ERROR(_("cannot version information from libxenlight, " + "disabling driver")); + goto error; + } + cfg->version = (cfg->verInfo->xen_version_major * 1000000) + + (cfg->verInfo->xen_version_minor * 1000); + + /* This will fill xenstore info about free and dom0 memory if missing, + * should be called before starting first domain */ + if (libxl_get_free_memory(cfg->ctx, &free_mem)) { + VIR_ERROR(_("Unable to configure libxl's memory management parameters")); + goto error; + } + + /* setup autoballoon */ + cfg->autoballoon = libxlGetAutoballoonConf(cfg); + + return cfg; + +error: + VIR_FREE(log_file); + virObjectUnref(cfg); + return NULL; +} + +libxlDriverConfigPtr +libxlDriverConfigGet(libxlDriverPrivatePtr driver) +{ + return virObjectRef(driver->config); +} + virCapsPtr libxlMakeCapabilities(libxl_ctx *ctx) { diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h index be3a473..e3875ba 100644 --- a/src/libxl/libxl_conf.h +++ b/src/libxl/libxl_conf.h @@ -51,10 +51,13 @@ typedef struct _libxlDriverPrivate libxlDriverPrivate; typedef libxlDriverPrivate *libxlDriverPrivatePtr; -struct _libxlDriverPrivate { - virMutex lock; - virCapsPtr caps; - virDomainXMLOptionPtr xmlopt; + +typedef struct _libxlDriverConfig libxlDriverConfig; +typedef libxlDriverConfig *libxlDriverConfigPtr; + +struct _libxlDriverConfig { + virObject parent; + const libxl_version_info *verInfo; unsigned int version; @@ -64,27 +67,43 @@ struct _libxlDriverPrivate { /* libxl ctx for driver wide ops; getVersion, getNodeInfo, ... */ libxl_ctx *ctx; - virPortAllocatorPtr reservedVNCPorts; - /* Controls automatic ballooning of domain0. If true, attempt to get * memory for new domains from domain0. */ bool autoballoon; + /* Once created, caps are immutable */ + virCapsPtr caps; + + char *configDir; + char *autostartDir; + char *logDir; + char *stateDir; + char *libDir; + char *saveDir; +}; + + +struct _libxlDriverPrivate { + virMutex lock; + + /* Require lock to get reference on 'config', + * then lockless thereafter */ + libxlDriverConfigPtr config; + size_t nactive; + virStateInhibitCallback inhibitCallback; void *inhibitOpaque; virDomainObjListPtr domains; + virDomainXMLOptionPtr xmlopt; + virDomainEventStatePtr domainEventState; - virSysinfoDefPtr hostsysinfo; - char *configDir; - char *autostartDir; - char *logDir; - char *stateDir; - char *libDir; - char *saveDir; + virPortAllocatorPtr reservedVNCPorts; + + virSysinfoDefPtr hostsysinfo; }; typedef struct _libxlEventHookInfo libxlEventHookInfo; @@ -103,8 +122,11 @@ struct _libxlSavefileHeader { uint32_t unused[10]; }; -bool -libxlGetAutoballoonConf(libxlDriverPrivatePtr driver); +libxlDriverConfigPtr +libxlDriverConfigNew(void); + +libxlDriverConfigPtr +libxlDriverConfigGet(libxlDriverPrivatePtr driver); virCapsPtr libxlMakeCapabilities(libxl_ctx *ctx); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index a26fbf6..e604899 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -126,35 +126,44 @@ libxlDoNodeGetInfo(libxlDriverPrivatePtr driver, virNodeInfoPtr info) { libxl_physinfo phy_info; virArch hostarch = virArchFromHost(); + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); + int ret = -1; - if (libxl_get_physinfo(driver->ctx, &phy_info)) { + if (libxl_get_physinfo(cfg->ctx, &phy_info)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("libxl_get_physinfo_info failed")); - return -1; + goto cleanup; } if (virStrcpyStatic(info->model, virArchToString(hostarch)) == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, _("machine type %s too big for destination"), virArchToString(hostarch)); - return -1; + goto cleanup; } - info->memory = phy_info.total_pages * (driver->verInfo->pagesize / 1024); + info->memory = phy_info.total_pages * (cfg->verInfo->pagesize / 1024); info->cpus = phy_info.nr_cpus; info->nodes = phy_info.nr_nodes; info->cores = phy_info.cores_per_socket; info->threads = phy_info.threads_per_core; info->sockets = 1; info->mhz = phy_info.cpu_khz / 1000; - return 0; + + ret = 0; + +cleanup: + virObjectUnref(cfg); + return ret; } static char * libxlDomainManagedSavePath(libxlDriverPrivatePtr driver, virDomainObjPtr vm) { char *ret; + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); - ignore_value(virAsprintf(&ret, "%s/%s.save", driver->saveDir, vm->def->name)); + ignore_value(virAsprintf(&ret, "%s/%s.save", cfg->saveDir, vm->def->name)); + virObjectUnref(cfg); return ret; } @@ -168,6 +177,8 @@ libxlSaveImageOpen(libxlDriverPrivatePtr driver, const char *from, virDomainDefPtr def = NULL; libxlSavefileHeader hdr; char *xml = NULL; + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); + int ret = -1; if ((fd = virFileOpenAs(from, O_RDONLY, 0, -1, -1, 0)) < 0) { virReportSystemError(-fd, @@ -207,23 +218,25 @@ libxlSaveImageOpen(libxlDriverPrivatePtr driver, const char *from, goto error; } - if (!(def = virDomainDefParseString(xml, driver->caps, driver->xmlopt, + if (!(def = virDomainDefParseString(xml, cfg->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, VIR_DOMAIN_XML_INACTIVE))) goto error; - VIR_FREE(xml); - *ret_def = def; *ret_hdr = hdr; - return fd; + ret = fd; + goto cleanup; error: - VIR_FREE(xml); virDomainDefFree(def); VIR_FORCE_CLOSE(fd); - return -1; + +cleanup: + VIR_FREE(xml); + virObjectUnref(cfg); + return ret; } /* @@ -237,6 +250,7 @@ libxlVmCleanup(libxlDriverPrivatePtr driver, virDomainShutoffReason reason) { libxlDomainObjPrivatePtr priv = vm->privateData; + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); int vnc_port; char *file; size_t i; @@ -276,7 +290,7 @@ libxlVmCleanup(libxlDriverPrivatePtr driver, vm->def->cputune.nvcpupin = 0; } - if (virAsprintf(&file, "%s/%s.xml", driver->stateDir, vm->def->name) > 0) { + if (virAsprintf(&file, "%s/%s.xml", cfg->stateDir, vm->def->name) > 0) { if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR) VIR_DEBUG("Failed to remove domain XML for %s", vm->def->name); VIR_FREE(file); @@ -290,6 +304,7 @@ libxlVmCleanup(libxlDriverPrivatePtr driver, } libxlDomainObjRegisteredTimeoutsCleanup(priv); + virObjectUnref(cfg); } /* @@ -533,6 +548,7 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, char *managed_save_path = NULL; int managed_save_fd = -1; libxlDomainObjPrivatePtr priv = vm->privateData; + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); if (libxlDomainObjPrivateInitCtx(vm) < 0) goto error; @@ -583,7 +599,7 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, if (libxlBuildDomainConfig(driver, vm, &d_config) < 0) goto error; - if (driver->autoballoon && libxlFreeMem(priv, &d_config) < 0) { + if (cfg->autoballoon && libxlFreeMem(priv, &d_config) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("libxenlight failed to get free memory for domain '%s'"), d_config.c_info.name); @@ -636,7 +652,7 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, } - if (virDomainSaveStatus(driver->xmlopt, driver->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) goto error; if (!driver->nactive && driver->inhibitCallback) @@ -653,6 +669,7 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, libxl_domain_config_dispose(&d_config); VIR_FREE(dom_xml); VIR_FORCE_CLOSE(managed_save_fd); + virObjectUnref(cfg); return 0; error: @@ -666,6 +683,7 @@ error: VIR_FREE(managed_save_path); virDomainDefFree(def); VIR_FORCE_CLOSE(managed_save_fd); + virObjectUnref(cfg); return -1; } @@ -740,28 +758,14 @@ libxlStateCleanup(void) if (!libxl_driver) return -1; - libxlDriverLock(libxl_driver); - virObjectUnref(libxl_driver->caps); + virObjectUnref(libxl_driver->config); virObjectUnref(libxl_driver->xmlopt); virObjectUnref(libxl_driver->domains); - libxl_ctx_free(libxl_driver->ctx); - xtl_logger_destroy(libxl_driver->logger); - if (libxl_driver->logger_file) - VIR_FORCE_FCLOSE(libxl_driver->logger_file); - virObjectUnref(libxl_driver->reservedVNCPorts); - VIR_FREE(libxl_driver->configDir); - VIR_FREE(libxl_driver->autostartDir); - VIR_FREE(libxl_driver->logDir); - VIR_FREE(libxl_driver->stateDir); - VIR_FREE(libxl_driver->libDir); - VIR_FREE(libxl_driver->saveDir); - virDomainEventStateFree(libxl_driver->domainEventState); virSysinfoDefFree(libxl_driver->hostsysinfo); - libxlDriverUnlock(libxl_driver); virMutexDestroy(&libxl_driver->lock); VIR_FREE(libxl_driver); @@ -807,10 +811,7 @@ libxlStateInitialize(bool privileged, virStateInhibitCallback callback ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) { - const libxl_version_info *ver_info; - char *log_file = NULL; - int ret = 0; - unsigned int free_mem; + libxlDriverConfigPtr cfg; char ebuf[1024]; if (!libxlDriverShouldLoad(privileged)) @@ -835,56 +836,31 @@ libxlStateInitialize(bool privileged, if (!(libxl_driver->domains = virDomainObjListNew())) goto error; - if (VIR_STRDUP(libxl_driver->configDir, LIBXL_CONFIG_DIR) < 0) - goto error; - - if (VIR_STRDUP(libxl_driver->autostartDir, LIBXL_AUTOSTART_DIR) < 0) - goto error; - - if (VIR_STRDUP(libxl_driver->logDir, LIBXL_LOG_DIR) < 0) - goto error; - - if (VIR_STRDUP(libxl_driver->stateDir, LIBXL_STATE_DIR) < 0) - goto error; - - if (VIR_STRDUP(libxl_driver->libDir, LIBXL_LIB_DIR) < 0) - goto error; - - if (VIR_STRDUP(libxl_driver->saveDir, LIBXL_SAVE_DIR) < 0) + if (!(cfg = libxlDriverConfigNew())) goto error; - if (virFileMakePath(libxl_driver->logDir) < 0) { + libxl_driver->config = cfg; + if (virFileMakePath(cfg->logDir) < 0) { VIR_ERROR(_("Failed to create log dir '%s': %s"), - libxl_driver->logDir, virStrerror(errno, ebuf, sizeof(ebuf))); + cfg->logDir, virStrerror(errno, ebuf, sizeof(ebuf))); goto error; } - if (virFileMakePath(libxl_driver->stateDir) < 0) { + if (virFileMakePath(cfg->stateDir) < 0) { VIR_ERROR(_("Failed to create state dir '%s': %s"), - libxl_driver->stateDir, virStrerror(errno, ebuf, sizeof(ebuf))); + cfg->stateDir, virStrerror(errno, ebuf, sizeof(ebuf))); goto error; } - if (virFileMakePath(libxl_driver->libDir) < 0) { + if (virFileMakePath(cfg->libDir) < 0) { VIR_ERROR(_("Failed to create lib dir '%s': %s"), - libxl_driver->libDir, virStrerror(errno, ebuf, sizeof(ebuf))); + cfg->libDir, virStrerror(errno, ebuf, sizeof(ebuf))); goto error; } - if (virFileMakePath(libxl_driver->saveDir) < 0) { + if (virFileMakePath(cfg->saveDir) < 0) { VIR_ERROR(_("Failed to create save dir '%s': %s"), - libxl_driver->saveDir, virStrerror(errno, ebuf, sizeof(ebuf))); + cfg->saveDir, virStrerror(errno, ebuf, sizeof(ebuf))); goto error; } - if (virAsprintf(&log_file, "%s/libxl-driver.log", libxl_driver->logDir) < 0) - goto error; - - if ((libxl_driver->logger_file = fopen(log_file, "a")) == NULL) { - virReportSystemError(errno, - _("failed to create logfile %s"), - log_file); - goto error; - } - VIR_FREE(log_file); - /* read the host sysinfo */ if (privileged) libxl_driver->hostsysinfo = virSysinfoRead(); @@ -893,30 +869,7 @@ libxlStateInitialize(bool privileged, if (!libxl_driver->domainEventState) goto error; - libxl_driver->logger = - (xentoollog_logger *)xtl_createlogger_stdiostream(libxl_driver->logger_file, XTL_DEBUG, 0); - if (!libxl_driver->logger) { - VIR_ERROR(_("Failed to create logger for libxenlight")); - goto error; - } - - if (libxl_ctx_alloc(&libxl_driver->ctx, - LIBXL_VERSION, 0, - libxl_driver->logger)) { - VIR_ERROR(_("Failed to initialize libxenlight context")); - goto error; - } - - if ((ver_info = libxl_get_version_info(libxl_driver->ctx)) == NULL) { - VIR_ERROR(_("Failed to get version information from libxenlight")); - goto error; - } - libxl_driver->verInfo = ver_info; - libxl_driver->version = (ver_info->xen_version_major * 1000000) + - (ver_info->xen_version_minor * 1000); - - if ((libxl_driver->caps = - libxlMakeCapabilities(libxl_driver->ctx)) == NULL) { + if ((cfg->caps = libxlMakeCapabilities(cfg->ctx)) == NULL) { VIR_ERROR(_("cannot create capabilities for libxenlight")); goto error; } @@ -926,22 +879,12 @@ libxlStateInitialize(bool privileged, NULL))) goto error; - /* This will fill xenstore info about free and dom0 memory if missing, - * should be called before starting first domain */ - if (libxl_get_free_memory(libxl_driver->ctx, &free_mem)) { - VIR_ERROR(_("Unable to configure libxl's memory management parameters")); - goto error; - } - - /* setup autoballoon */ - libxl_driver->autoballoon = libxlGetAutoballoonConf(libxl_driver); - /* Load running domains first. */ if (virDomainObjListLoadAllConfigs(libxl_driver->domains, - libxl_driver->stateDir, - libxl_driver->autostartDir, + cfg->stateDir, + cfg->autostartDir, 1, - libxl_driver->caps, + cfg->caps, libxl_driver->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, NULL, NULL) < 0) @@ -951,10 +894,10 @@ libxlStateInitialize(bool privileged, /* Then inactive persistent configs */ if (virDomainObjListLoadAllConfigs(libxl_driver->domains, - libxl_driver->configDir, - libxl_driver->autostartDir, + cfg->configDir, + cfg->autostartDir, 0, - libxl_driver->caps, + cfg->caps, libxl_driver->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, NULL, NULL) < 0) @@ -968,12 +911,10 @@ libxlStateInitialize(bool privileged, return 0; error: - ret = -1; - VIR_FREE(log_file); if (libxl_driver) libxlDriverUnlock(libxl_driver); libxlStateCleanup(); - return ret; + return -1; } static void @@ -991,15 +932,19 @@ libxlStateAutoStart(void) static int libxlStateReload(void) { + libxlDriverConfigPtr cfg; + if (!libxl_driver) return 0; libxlDriverLock(libxl_driver); + cfg = libxlDriverConfigGet(libxl_driver); + virDomainObjListLoadAllConfigs(libxl_driver->domains, - libxl_driver->configDir, - libxl_driver->autostartDir, + cfg->configDir, + cfg->autostartDir, 1, - libxl_driver->caps, + cfg->caps, libxl_driver->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, NULL, libxl_driver); @@ -1007,6 +952,7 @@ libxlStateReload(void) virDomainObjListForEach(libxl_driver->domains, libxlAutostartDomain, libxl_driver); + virObjectUnref(cfg); libxlDriverUnlock(libxl_driver); return 0; @@ -1082,12 +1028,15 @@ static int libxlConnectGetVersion(virConnectPtr conn, unsigned long *version) { libxlDriverPrivatePtr driver = conn->privateData; + libxlDriverConfigPtr cfg; if (virConnectGetVersionEnsureACL(conn) < 0) return 0; libxlDriverLock(driver); - *version = driver->version; + cfg = libxlDriverConfigGet(driver); + *version = cfg->version; + virObjectUnref(cfg); libxlDriverUnlock(driver); return 0; } @@ -1132,16 +1081,19 @@ libxlConnectGetMaxVcpus(virConnectPtr conn, const char *type ATTRIBUTE_UNUSED) { int ret; libxlDriverPrivatePtr driver = conn->privateData; + libxlDriverConfigPtr cfg; if (virConnectGetMaxVcpusEnsureACL(conn) < 0) return -1; - ret = libxl_get_max_cpus(driver->ctx); + cfg = libxlDriverConfigGet(driver); + ret = libxl_get_max_cpus(cfg->ctx); /* libxl_get_max_cpus() will return 0 if there were any failures, e.g. xc_physinfo() failing */ if (ret == 0) - return -1; + ret = -1; + virObjectUnref(cfg); return ret; } @@ -1159,15 +1111,18 @@ libxlConnectGetCapabilities(virConnectPtr conn) { libxlDriverPrivatePtr driver = conn->privateData; char *xml; + libxlDriverConfigPtr cfg; if (virConnectGetCapabilitiesEnsureACL(conn) < 0) return NULL; libxlDriverLock(driver); - if ((xml = virCapabilitiesFormatXML(driver->caps)) == NULL) + cfg = libxlDriverConfigGet(driver); + if ((xml = virCapabilitiesFormatXML(cfg->caps)) == NULL) virReportOOMError(); libxlDriverUnlock(driver); + virObjectUnref(cfg); return xml; } @@ -1213,11 +1168,12 @@ libxlDomainCreateXML(virConnectPtr conn, const char *xml, virDomainDefPtr def; virDomainObjPtr vm = NULL; virDomainPtr dom = NULL; + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); virCheckFlags(VIR_DOMAIN_START_PAUSED, NULL); libxlDriverLock(driver); - if (!(def = virDomainDefParseString(xml, driver->caps, driver->xmlopt, + if (!(def = virDomainDefParseString(xml, cfg->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; @@ -1248,6 +1204,7 @@ cleanup: if (vm) virObjectUnlock(vm); libxlDriverUnlock(driver); + virObjectUnref(cfg); return dom; } @@ -1342,6 +1299,7 @@ static int libxlDomainSuspend(virDomainPtr dom) { libxlDriverPrivatePtr driver = dom->conn->privateData; + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); virDomainObjPtr vm; libxlDomainObjPrivatePtr priv; virDomainEventPtr event = NULL; @@ -1383,7 +1341,7 @@ libxlDomainSuspend(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; @@ -1396,6 +1354,7 @@ cleanup: libxlDomainEventQueue(driver, event); libxlDriverUnlock(driver); } + virObjectUnref(cfg); return ret; } @@ -1404,6 +1363,7 @@ static int libxlDomainResume(virDomainPtr dom) { libxlDriverPrivatePtr driver = dom->conn->privateData; + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); virDomainObjPtr vm; libxlDomainObjPrivatePtr priv; virDomainEventPtr event = NULL; @@ -1446,7 +1406,7 @@ libxlDomainResume(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; @@ -1459,6 +1419,7 @@ cleanup: libxlDomainEventQueue(driver, event); libxlDriverUnlock(driver); } + virObjectUnref(cfg); return ret; } @@ -1686,6 +1647,7 @@ libxlDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, unsigned int flags) { libxlDriverPrivatePtr driver = dom->conn->privateData; + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); libxlDomainObjPrivatePtr priv; virDomainObjPtr vm; virDomainDefPtr persistentDef = NULL; @@ -1735,7 +1697,7 @@ libxlDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, _("cannot change persistent config of a transient domain")); goto cleanup; } - if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, + if (!(persistentDef = virDomainObjGetPersistentDef(cfg->caps, driver->xmlopt, vm))) goto cleanup; @@ -1760,7 +1722,7 @@ libxlDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, persistentDef->mem.max_balloon = newmem; if (persistentDef->mem.cur_balloon > newmem) persistentDef->mem.cur_balloon = newmem; - ret = virDomainSaveConfig(driver->configDir, persistentDef); + ret = virDomainSaveConfig(cfg->configDir, persistentDef); goto cleanup; } @@ -1787,7 +1749,7 @@ libxlDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, if (flags & VIR_DOMAIN_MEM_CONFIG) { sa_assert(persistentDef); persistentDef->mem.cur_balloon = newmem; - ret = virDomainSaveConfig(driver->configDir, persistentDef); + ret = virDomainSaveConfig(cfg->configDir, persistentDef); goto cleanup; } } @@ -1797,6 +1759,7 @@ libxlDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, cleanup: if (vm) virObjectUnlock(vm); + virObjectUnref(cfg); return ret; } @@ -2336,6 +2299,7 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, unsigned int flags) { libxlDriverPrivatePtr driver = dom->conn->privateData; + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); libxlDomainObjPrivatePtr priv; virDomainDefPtr def; virDomainObjPtr vm; @@ -2409,7 +2373,7 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, priv = vm->privateData; - if (!(def = virDomainObjGetPersistentDef(driver->caps, driver->xmlopt, vm))) + if (!(def = virDomainObjGetPersistentDef(cfg->caps, driver->xmlopt, vm))) goto cleanup; maplen = VIR_CPU_MAPLEN(nvcpus); @@ -2458,12 +2422,13 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, ret = 0; if (flags & VIR_DOMAIN_VCPU_CONFIG) - ret = virDomainSaveConfig(driver->configDir, def); + ret = virDomainSaveConfig(cfg->configDir, def); cleanup: VIR_FREE(bitmask); if (vm) virObjectUnlock(vm); + virObjectUnref(cfg); return ret; } @@ -2541,6 +2506,7 @@ libxlDomainPinVcpu(virDomainPtr dom, unsigned int vcpu, unsigned char *cpumap, int maplen) { libxlDriverPrivatePtr driver = dom->conn->privateData; + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); libxlDomainObjPrivatePtr priv; virDomainObjPtr vm; int ret = -1; @@ -2589,7 +2555,7 @@ libxlDomainPinVcpu(virDomainPtr dom, unsigned int vcpu, unsigned char *cpumap, goto cleanup; } - if (virDomainSaveStatus(driver->xmlopt, driver->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) goto cleanup; ret = 0; @@ -2597,6 +2563,7 @@ libxlDomainPinVcpu(virDomainPtr dom, unsigned int vcpu, unsigned char *cpumap, cleanup: if (vm) virObjectUnlock(vm); + virObjectUnref(cfg); return ret; } @@ -2707,6 +2674,7 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn, const char * nativeFormat, unsigned int flags) { libxlDriverPrivatePtr driver = conn->privateData; + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); virDomainDefPtr def = NULL; virConfPtr conf = NULL; char *xml = NULL; @@ -2726,8 +2694,8 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn, const char * nativeFormat, goto cleanup; if (!(def = xenParseXM(conf, - driver->verInfo->xen_version_major, - driver->caps))) { + cfg->verInfo->xen_version_major, + cfg->caps))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("parsing xm config failed")); goto cleanup; } @@ -2738,6 +2706,7 @@ cleanup: virDomainDefFree(def); if (conf) virConfFree(conf); + virObjectUnref(cfg); return xml; } @@ -2748,6 +2717,7 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char * nativeFormat, unsigned int flags) { libxlDriverPrivatePtr driver = conn->privateData; + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); virDomainDefPtr def = NULL; virConfPtr conf = NULL; int len = MAX_CONFIG_SIZE; @@ -2765,11 +2735,11 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char * nativeFormat, } if (!(def = virDomainDefParseString(domainXml, - driver->caps, driver->xmlopt, + cfg->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, 0))) goto cleanup; - if (!(conf = xenFormatXM(conn, def, driver->verInfo->xen_version_major))) + if (!(conf = xenFormatXM(conn, def, cfg->verInfo->xen_version_major))) goto cleanup; if (VIR_ALLOC_N(ret, len) < 0) @@ -2784,6 +2754,7 @@ cleanup: virDomainDefFree(def); if (conf) virConfFree(conf); + virObjectUnref(cfg); return ret; } @@ -2870,6 +2841,7 @@ static virDomainPtr libxlDomainDefineXML(virConnectPtr conn, const char *xml) { libxlDriverPrivatePtr driver = conn->privateData; + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); virDomainDefPtr def = NULL; virDomainObjPtr vm = NULL; virDomainPtr dom = NULL; @@ -2877,7 +2849,7 @@ libxlDomainDefineXML(virConnectPtr conn, const char *xml) virDomainDefPtr oldDef = NULL; libxlDriverLock(driver); - if (!(def = virDomainDefParseString(xml, driver->caps, driver->xmlopt, + if (!(def = virDomainDefParseString(xml, cfg->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; @@ -2893,7 +2865,7 @@ libxlDomainDefineXML(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; @@ -2917,6 +2889,7 @@ cleanup: if (event) libxlDomainEventQueue(driver, event); libxlDriverUnlock(driver); + virObjectUnref(cfg); return dom; } @@ -2925,6 +2898,7 @@ libxlDomainUndefineFlags(virDomainPtr dom, unsigned int flags) { libxlDriverPrivatePtr driver = dom->conn->privateData; + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); virDomainObjPtr vm; virDomainEventPtr event = NULL; char *name = NULL; @@ -2972,9 +2946,7 @@ libxlDomainUndefineFlags(virDomainPtr dom, } } - if (virDomainDeleteConfig(driver->configDir, - driver->autostartDir, - vm) < 0) + if (virDomainDeleteConfig(cfg->configDir, cfg->autostartDir, vm) < 0) goto cleanup; event = virDomainEventNewFromObj(vm, VIR_DOMAIN_EVENT_UNDEFINED, @@ -2996,6 +2968,7 @@ libxlDomainUndefineFlags(virDomainPtr dom, if (event) libxlDomainEventQueue(driver, event); libxlDriverUnlock(driver); + virObjectUnref(cfg); return ret; } @@ -3355,6 +3328,7 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, unsigned int flags) { libxlDriverPrivatePtr driver = dom->conn->privateData; + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); virDomainObjPtr vm = NULL; virDomainDefPtr vmdef = NULL; virDomainDeviceDefPtr dev = NULL; @@ -3399,12 +3373,12 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) { if (!(dev = virDomainDeviceDefParse(xml, vm->def, - driver->caps, driver->xmlopt, + cfg->caps, driver->xmlopt, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; /* Make a copy for updated domain. */ - if (!(vmdef = virDomainObjCopyPersistentDef(vm, driver->caps, + if (!(vmdef = virDomainObjCopyPersistentDef(vm, cfg->caps, driver->xmlopt))) goto cleanup; @@ -3418,7 +3392,7 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, /* If dev exists it was created to modify the domain config. Free it. */ virDomainDeviceDefFree(dev); if (!(dev = virDomainDeviceDefParse(xml, vm->def, - driver->caps, driver->xmlopt, + cfg->caps, driver->xmlopt, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; @@ -3429,13 +3403,13 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, * update domain status forcibly because the domain status may be * changed even if we attach the device failed. */ - if (virDomainSaveStatus(driver->xmlopt, driver->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) ret = -1; } /* Finally, if no error until here, we can save config. */ if (!ret && (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG)) { - ret = virDomainSaveConfig(driver->configDir, vmdef); + ret = virDomainSaveConfig(cfg->configDir, vmdef); if (!ret) { virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef = NULL; @@ -3448,6 +3422,7 @@ cleanup: if (vm) virObjectUnlock(vm); libxlDriverUnlock(driver); + virObjectUnref(cfg); return ret; } @@ -3463,6 +3438,7 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, unsigned int flags) { libxlDriverPrivatePtr driver = dom->conn->privateData; + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); virDomainObjPtr vm = NULL; virDomainDefPtr vmdef = NULL; virDomainDeviceDefPtr dev = NULL; @@ -3507,12 +3483,12 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) { if (!(dev = virDomainDeviceDefParse(xml, vm->def, - driver->caps, driver->xmlopt, + cfg->caps, driver->xmlopt, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; /* Make a copy for updated domain. */ - if (!(vmdef = virDomainObjCopyPersistentDef(vm, driver->caps, + if (!(vmdef = virDomainObjCopyPersistentDef(vm, cfg->caps, driver->xmlopt))) goto cleanup; @@ -3526,7 +3502,7 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, /* If dev exists it was created to modify the domain config. Free it. */ virDomainDeviceDefFree(dev); if (!(dev = virDomainDeviceDefParse(xml, vm->def, - driver->caps, driver->xmlopt, + cfg->caps, driver->xmlopt, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; @@ -3537,13 +3513,13 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, * update domain status forcibly because the domain status may be * changed even if we attach the device failed. */ - if (virDomainSaveStatus(driver->xmlopt, driver->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) ret = -1; } /* Finally, if no error until here, we can save config. */ if (!ret && (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG)) { - ret = virDomainSaveConfig(driver->configDir, vmdef); + ret = virDomainSaveConfig(cfg->configDir, vmdef); if (!ret) { virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef = NULL; @@ -3556,6 +3532,7 @@ cleanup: if (vm) virObjectUnlock(vm); libxlDriverUnlock(driver); + virObjectUnref(cfg); return ret; } @@ -3571,6 +3548,7 @@ libxlDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml, unsigned int flags) { libxlDriverPrivatePtr driver = dom->conn->privateData; + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); virDomainObjPtr vm = NULL; virDomainDefPtr vmdef = NULL; virDomainDeviceDefPtr dev = NULL; @@ -3615,12 +3593,12 @@ libxlDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml, if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) { if (!(dev = virDomainDeviceDefParse(xml, vm->def, - driver->caps, driver->xmlopt, + cfg->caps, driver->xmlopt, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; /* Make a copy for updated domain. */ - if (!(vmdef = virDomainObjCopyPersistentDef(vm, driver->caps, + if (!(vmdef = virDomainObjCopyPersistentDef(vm, cfg->caps, driver->xmlopt))) goto cleanup; @@ -3634,7 +3612,7 @@ libxlDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml, /* If dev exists it was created to modify the domain config. Free it. */ virDomainDeviceDefFree(dev); if (!(dev = virDomainDeviceDefParse(xml, vm->def, - driver->caps, driver->xmlopt, + cfg->caps, driver->xmlopt, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; @@ -3645,13 +3623,13 @@ libxlDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml, * update domain status forcibly because the domain status may be * changed even if we attach the device failed. */ - if (virDomainSaveStatus(driver->xmlopt, driver->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) ret = -1; } /* Finally, if no error until here, we can save config. */ if (!ret && (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG)) { - ret = virDomainSaveConfig(driver->configDir, vmdef); + ret = virDomainSaveConfig(cfg->configDir, vmdef); if (!ret) { virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef = NULL; @@ -3664,6 +3642,7 @@ cleanup: if (vm) virObjectUnlock(vm); libxlDriverUnlock(driver); + virObjectUnref(cfg); return ret; } @@ -3672,17 +3651,23 @@ libxlNodeGetFreeMemory(virConnectPtr conn) { libxl_physinfo phy_info; libxlDriverPrivatePtr driver = conn->privateData; + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); + unsigned long long ret = 0; if (virNodeGetFreeMemoryEnsureACL(conn) < 0) - return 0; + goto cleanup; - if (libxl_get_physinfo(driver->ctx, &phy_info)) { + if (libxl_get_physinfo(cfg->ctx, &phy_info)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("libxl_get_physinfo_info failed")); - return 0; + goto cleanup; } - return phy_info.free_pages * driver->verInfo->pagesize; + ret = phy_info.free_pages * cfg->verInfo->pagesize; + +cleanup: + virObjectUnref(cfg); + return ret; } static int @@ -3695,11 +3680,12 @@ libxlNodeGetCellsFreeMemory(virConnectPtr conn, int ret = -1, nr_nodes = 0; libxl_numainfo *numa_info = NULL; libxlDriverPrivatePtr driver = conn->privateData; + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); if (virNodeGetCellsFreeMemoryEnsureACL(conn) < 0) - return -1; + goto cleanup; - numa_info = libxl_get_numainfo(driver->ctx, &nr_nodes); + numa_info = libxl_get_numainfo(cfg->ctx, &nr_nodes); if (numa_info == NULL || nr_nodes == 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("libxl_get_numainfo failed")); @@ -3728,6 +3714,7 @@ libxlNodeGetCellsFreeMemory(virConnectPtr conn, cleanup: libxl_numainfo_list_free(numa_info, nr_nodes); + virObjectUnref(cfg); return ret; } @@ -3806,6 +3793,7 @@ static int libxlDomainSetAutostart(virDomainPtr dom, int autostart) { libxlDriverPrivatePtr driver = dom->conn->privateData; + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); virDomainObjPtr vm; char *configFile = NULL, *autostartLink = NULL; int ret = -1; @@ -3833,16 +3821,16 @@ libxlDomainSetAutostart(virDomainPtr dom, int autostart) autostart = (autostart != 0); if (vm->autostart != autostart) { - if (!(configFile = virDomainConfigFile(driver->configDir, vm->def->name))) + if (!(configFile = virDomainConfigFile(cfg->configDir, vm->def->name))) goto cleanup; - if (!(autostartLink = virDomainConfigFile(driver->autostartDir, vm->def->name))) + if (!(autostartLink = virDomainConfigFile(cfg->autostartDir, vm->def->name))) 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; } @@ -3871,6 +3859,7 @@ cleanup: if (vm) virObjectUnlock(vm); libxlDriverUnlock(driver); + virObjectUnref(cfg); return ret; } -- 1.8.1.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list