{
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;
}
virDomainDefPtr def = NULL;
libxlSavefileHeader hdr;
char *xml = NULL;
+ libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
if ((fd = virFileOpenAs(from, O_RDONLY, 0, -1, -1, 0)) < 0) {
virReportSystemError(-fd,
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);
+ virObjectUnref(cfg);
*ret_def = def;
*ret_hdr = hdr;
error:
VIR_FREE(xml);
+ virObjectUnref(cfg);
virDomainDefFree(def);
VIR_FORCE_CLOSE(fd);
return -1;
virDomainShutoffReason reason)
{
libxlDomainObjPrivatePtr priv = vm->privateData;
+ libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
int vnc_port;
char *file;
size_t i;
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);
}
libxlDomainObjRegisteredTimeoutsCleanup(priv);
+ virObjectUnref(cfg);
}
/*
char *managed_save_path = NULL;
int managed_save_fd = -1;
libxlDomainObjPrivatePtr priv = vm->privateData;
+ libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
if (libxlDomainObjPrivateInitCtx(vm) < 0)
goto error;
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);
}
- if (virDomainSaveStatus(driver->xmlopt, driver->stateDir, vm) < 0)
+ if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
goto error;
if (!driver->nactive && driver->inhibitCallback)
libxl_domain_config_dispose(&d_config);
VIR_FREE(dom_xml);
VIR_FORCE_CLOSE(managed_save_fd);
+ virObjectUnref(cfg);
return 0;
error:
VIR_FREE(managed_save_path);
virDomainDefFree(def);
VIR_FORCE_CLOSE(managed_save_fd);
+ virObjectUnref(cfg);
return -1;
}
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);
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))
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) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to create log dir '%s': %s"),
- libxl_driver->logDir,
+ cfg->logDir,
virStrerror(errno, ebuf, sizeof(ebuf)));
goto error;
}
- if (virFileMakePath(libxl_driver->stateDir) < 0) {
+ if (virFileMakePath(cfg->stateDir) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to create state dir '%s': %s"),
- libxl_driver->stateDir,
+ cfg->stateDir,
virStrerror(errno, ebuf, sizeof(ebuf)));
goto error;
}
- if (virFileMakePath(libxl_driver->libDir) < 0) {
+ if (virFileMakePath(cfg->libDir) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to create lib dir '%s': %s"),
- libxl_driver->libDir,
+ cfg->libDir,
virStrerror(errno, ebuf, sizeof(ebuf)));
goto error;
}
- if (virFileMakePath(libxl_driver->saveDir) < 0) {
+ if (virFileMakePath(cfg->saveDir) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to create save dir '%s': %s"),
- libxl_driver->saveDir,
+ 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();
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) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("failed to create logger for libxenlight"));
- goto error;
- }
-
- if (libxl_ctx_alloc(&libxl_driver->ctx,
- LIBXL_VERSION, 0,
- libxl_driver->logger)) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("failed to initialize libxenlight context"));
- goto error;
- }
-
- if ((ver_info = libxl_get_version_info(libxl_driver->ctx)) == NULL) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "%s",
- _("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) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot create capabilities for libxenlight"));
goto error;
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)) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "%s",
- _("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)
/* 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)
return 0;
error:
- ret = -1;
- VIR_FREE(log_file);
if (libxl_driver)
libxlDriverUnlock(libxl_driver);
libxlStateCleanup();
- return ret;
+ return -1;
}
static 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);
virDomainObjListForEach(libxl_driver->domains, libxlAutostartDomain,
libxl_driver);
+ virObjectUnref(cfg);
libxlDriverUnlock(libxl_driver);
return 0;
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;
}
{
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;
}
{
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;
}
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;
if (vm)
virObjectUnlock(vm);
libxlDriverUnlock(driver);
+ virObjectUnref(cfg);
return dom;
}
libxlDomainSuspend(virDomainPtr dom)
{
libxlDriverPrivatePtr driver = dom->conn->privateData;
+ libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
virDomainObjPtr vm;
libxlDomainObjPrivatePtr priv;
virDomainEventPtr event = NULL;
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;
libxlDomainEventQueue(driver, event);
libxlDriverUnlock(driver);
}
+ virObjectUnref(cfg);
return ret;
}
libxlDomainResume(virDomainPtr dom)
{
libxlDriverPrivatePtr driver = dom->conn->privateData;
+ libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
virDomainObjPtr vm;
libxlDomainObjPrivatePtr priv;
virDomainEventPtr event = NULL;
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;
libxlDomainEventQueue(driver, event);
libxlDriverUnlock(driver);
}
+ virObjectUnref(cfg);
return ret;
}
unsigned int flags)
{
libxlDriverPrivatePtr driver = dom->conn->privateData;
+ libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
libxlDomainObjPrivatePtr priv;
virDomainObjPtr vm;
virDomainDefPtr persistentDef = NULL;
_("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;
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;
}
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;
}
}
cleanup:
if (vm)
virObjectUnlock(vm);
+ virObjectUnref(cfg);
return ret;
}
unsigned int flags)
{
libxlDriverPrivatePtr driver = dom->conn->privateData;
+ libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
libxlDomainObjPrivatePtr priv;
virDomainDefPtr def;
virDomainObjPtr vm;
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);
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;
}
int maplen)
{
libxlDriverPrivatePtr driver = dom->conn->privateData;
+ libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
libxlDomainObjPrivatePtr priv;
virDomainObjPtr vm;
int ret = -1;
goto cleanup;
}
- if (virDomainSaveStatus(driver->xmlopt, driver->stateDir, vm) < 0)
+ if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
goto cleanup;
ret = 0;
cleanup:
if (vm)
virObjectUnlock(vm);
+ virObjectUnref(cfg);
return ret;
}
unsigned int flags)
{
libxlDriverPrivatePtr driver = conn->privateData;
+ libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
virDomainDefPtr def = NULL;
virConfPtr conf = NULL;
char *xml = NULL;
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;
}
virDomainDefFree(def);
if (conf)
virConfFree(conf);
+ virObjectUnref(cfg);
return xml;
}
unsigned int flags)
{
libxlDriverPrivatePtr driver = conn->privateData;
+ libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
virDomainDefPtr def = NULL;
virConfPtr conf = NULL;
int len = MAX_CONFIG_SIZE;
}
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)
virDomainDefFree(def);
if (conf)
virConfFree(conf);
+ virObjectUnref(cfg);
return ret;
}
libxlDomainDefineXML(virConnectPtr conn, const char *xml)
{
libxlDriverPrivatePtr driver = conn->privateData;
+ libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
virDomainDefPtr def = NULL;
virDomainObjPtr vm = NULL;
virDomainPtr dom = NULL;
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;
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;
if (event)
libxlDomainEventQueue(driver, event);
libxlDriverUnlock(driver);
+ virObjectUnref(cfg);
return dom;
}
unsigned int flags)
{
libxlDriverPrivatePtr driver = dom->conn->privateData;
+ libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
virDomainObjPtr vm;
virDomainEventPtr event = NULL;
char *name = NULL;
}
}
- 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,
if (event)
libxlDomainEventQueue(driver, event);
libxlDriverUnlock(driver);
+ virObjectUnref(cfg);
return ret;
}
unsigned int flags)
{
libxlDriverPrivatePtr driver = dom->conn->privateData;
+ libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
virDomainObjPtr vm = NULL;
virDomainDefPtr vmdef = NULL;
virDomainDeviceDefPtr dev = NULL;
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;
/* 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;
* 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;
if (vm)
virObjectUnlock(vm);
libxlDriverUnlock(driver);
+ virObjectUnref(cfg);
return ret;
}
unsigned int flags)
{
libxlDriverPrivatePtr driver = dom->conn->privateData;
+ libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
virDomainObjPtr vm = NULL;
virDomainDefPtr vmdef = NULL;
virDomainDeviceDefPtr dev = NULL;
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;
/* 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;
* 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;
if (vm)
virObjectUnlock(vm);
libxlDriverUnlock(driver);
+ virObjectUnref(cfg);
return ret;
}
unsigned int flags)
{
libxlDriverPrivatePtr driver = dom->conn->privateData;
+ libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
virDomainObjPtr vm = NULL;
virDomainDefPtr vmdef = NULL;
virDomainDeviceDefPtr dev = NULL;
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;
/* 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;
* 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;
if (vm)
virObjectUnlock(vm);
libxlDriverUnlock(driver);
+ virObjectUnref(cfg);
return ret;
}
{
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
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"));
cleanup:
libxl_numainfo_list_free(numa_info, nr_nodes);
+ virObjectUnref(cfg);
return ret;
}
libxlDomainSetAutostart(virDomainPtr dom, int autostart)
{
libxlDriverPrivatePtr driver = dom->conn->privateData;
+ libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
virDomainObjPtr vm;
char *configFile = NULL, *autostartLink = NULL;
int ret = -1;
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;
}
if (vm)
virObjectUnlock(vm);
libxlDriverUnlock(driver);
+ virObjectUnref(cfg);
return ret;
}