if (bhyveDomainAssignAddresses(def, NULL) < 0)
goto cleanup;
- if (!(vm = virDomainObjListAdd(privconn->domains, def,
+ if (!(vm = virDomainObjListAdd(privconn->domains, &def,
privconn->xmlopt,
0, &oldDef)))
goto cleanup;
- def = NULL;
vm->persistent = 1;
if (virDomainDefSave(vm->newDef ? vm->newDef : vm->def,
if (bhyveDomainAssignAddresses(def, NULL) < 0)
goto cleanup;
- if (!(vm = virDomainObjListAdd(privconn->domains, def,
+ if (!(vm = virDomainObjListAdd(privconn->domains, &def,
privconn->xmlopt,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL)))
goto cleanup;
- def = NULL;
if (virBhyveProcessStart(conn, vm,
VIR_DOMAIN_RUNNING_BOOTED,
goto cleanup;
if (!(vm = virDomainObjListAdd(driver->domains,
- vmdef,
+ &vmdef,
driver->xmlopt,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
- vmdef = NULL;
-
if (virCHDomainObjBeginJob(vm, CH_JOB_MODIFY) < 0)
goto cleanup;
if (virDomainDefineXMLFlagsEnsureACL(conn, vmdef) < 0)
goto cleanup;
- if (!(vm = virDomainObjListAdd(driver->domains, vmdef,
+ if (!(vm = virDomainObjListAdd(driver->domains, &vmdef,
driver->xmlopt,
0, NULL)))
goto cleanup;
- vmdef = NULL;
vm->persistent = 1;
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
void virDomainObjAssignDef(virDomainObj *domain,
- virDomainDef *def,
+ virDomainDef **def,
bool live,
virDomainDef **oldDef)
{
*oldDef = domain->newDef;
else
virDomainDefFree(domain->newDef);
- domain->newDef = def;
+ domain->newDef = g_steal_pointer(def);
} else {
if (live) {
/* save current configuration to be restored on domain shutdown */
domain->newDef = domain->def;
else
virDomainDefFree(domain->def);
- domain->def = def;
+ domain->def = g_steal_pointer(def);
} else {
if (oldDef)
*oldDef = domain->def;
else
virDomainDefFree(domain->def);
- domain->def = def;
+ domain->def = g_steal_pointer(def);
}
}
}
virDomainDef *virDomainDefNew(virDomainXMLOption *xmlopt);
void virDomainObjAssignDef(virDomainObj *domain,
- virDomainDef *def,
+ virDomainDef **def,
bool live,
virDomainDef **oldDef);
int virDomainObjSetDefTransient(virDomainXMLOption *xmlopt,
* the @def being added is assumed to represent a
* live config, not a future inactive config
*
+ * Upon successful return the virDomain object is the owner of
+ * @def and callers should use @vm->def if they need to access
+ * the definition as @def is set to NULL.
+ *
* The returned @vm from this function will be locked and ref
* counted. The caller is expected to use virDomainObjEndAPI
* when it completes usage.
*/
static virDomainObj *
virDomainObjListAddLocked(virDomainObjList *doms,
- virDomainDef *def,
+ virDomainDef **def,
virDomainXMLOption *xmlopt,
unsigned int flags,
virDomainDef **oldDef)
*oldDef = NULL;
/* See if a VM with matching UUID already exists */
- if ((vm = virDomainObjListFindByUUIDLocked(doms, def->uuid))) {
+ if ((vm = virDomainObjListFindByUUIDLocked(doms, (*def)->uuid))) {
if (vm->removing) {
virReportError(VIR_ERR_OPERATION_FAILED,
_("domain '%s' is already being removed"),
vm->def->name);
goto error;
- } else if (STRNEQ(vm->def->name, def->name)) {
+ } else if (STRNEQ(vm->def->name, (*def)->name)) {
/* UUID matches, but if names don't match, refuse it */
virUUIDFormat(vm->def->uuid, uuidstr);
virReportError(VIR_ERR_OPERATION_FAILED,
oldDef);
} else {
/* UUID does not match, but if a name matches, refuse it */
- if ((vm = virDomainObjListFindByNameLocked(doms, def->name))) {
+ if ((vm = virDomainObjListFindByNameLocked(doms, (*def)->name))) {
virUUIDFormat(vm->def->uuid, uuidstr);
virReportError(VIR_ERR_OPERATION_FAILED,
_("domain '%s' already exists with uuid %s"),
- def->name, uuidstr);
+ (*def)->name, uuidstr);
goto error;
}
if (!(vm = virDomainObjNew(xmlopt)))
goto error;
- vm->def = def;
+ vm->def = g_steal_pointer(def);
if (virDomainObjListAddObjLocked(doms, vm) < 0) {
- vm->def = NULL;
+ *def = g_steal_pointer(&vm->def);
goto error;
}
}
virDomainObj *
virDomainObjListAdd(virDomainObjList *doms,
- virDomainDef *def,
+ virDomainDef **def,
virDomainXMLOption *xmlopt,
unsigned int flags,
virDomainDef **oldDef)
if ((autostart = virFileLinkPointsTo(autostartLink, configFile)) < 0)
goto error;
- if (!(dom = virDomainObjListAddLocked(doms, def, xmlopt, 0, &oldDef)))
+ if (!(dom = virDomainObjListAddLocked(doms, &def, xmlopt, 0, &oldDef)))
goto error;
dom->autostart = autostart;
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE = (1 << 1),
};
virDomainObj *virDomainObjListAdd(virDomainObjList *doms,
- virDomainDef *def,
+ virDomainDef **def,
virDomainXMLOption *xmlopt,
unsigned int flags,
virDomainDef **oldDef);
goto cleanup;
}
- virDomainObjAssignDef(vm, def, true, NULL);
- def = NULL;
+ virDomainObjAssignDef(vm, &def, true, NULL);
if (unlink(managed_save_path) < 0)
VIR_WARN("Failed to remove the managed state %s",
if (virUUIDParse("00000000-0000-0000-0000-000000000000", def->uuid) < 0)
goto cleanup;
- if (!(vm = virDomainObjListAdd(driver->domains, def,
+ if (!(vm = virDomainObjListAdd(driver->domains, &def,
driver->xmlopt,
0,
NULL)))
goto cleanup;
- def = NULL;
vm->persistent = 1;
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);
}
if (virDomainCreateXMLEnsureACL(conn, def) < 0)
goto cleanup;
- if (!(vm = virDomainObjListAdd(driver->domains, def,
+ if (!(vm = virDomainObjListAdd(driver->domains, &def,
driver->xmlopt,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
- def = NULL;
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) {
if (!vm->persistent)
if (virDomainRestoreFlagsEnsureACL(conn, def) < 0)
goto cleanup;
- if (!(vm = virDomainObjListAdd(driver->domains, def,
+ if (!(vm = virDomainObjListAdd(driver->domains, &def,
driver->xmlopt,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
- def = NULL;
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) {
if (!vm->persistent)
if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0)
goto cleanup;
- if (!(vm = virDomainObjListAdd(driver->domains, def,
+ if (!(vm = virDomainObjListAdd(driver->domains, &def,
driver->xmlopt,
0,
&oldDef)))
goto cleanup;
- def = NULL;
vm->persistent = 1;
/* Finally, if no error until here, we can save config. */
if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) {
ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir);
- if (!ret) {
- virDomainObjAssignDef(vm, vmdef, false, NULL);
- vmdef = NULL;
- }
+ if (!ret)
+ virDomainObjAssignDef(vm, &vmdef, false, NULL);
}
endjob:
/* Finally, if no error until here, we can save config. */
if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) {
ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir);
- if (!ret) {
- virDomainObjAssignDef(vm, vmdef, false, NULL);
- vmdef = NULL;
- }
+ if (!ret)
+ virDomainObjAssignDef(vm, &vmdef, false, NULL);
}
endjob:
/* Finally, if no error until here, we can save config. */
if (!ret && (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG)) {
ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir);
- if (!ret) {
- virDomainObjAssignDef(vm, vmdef, false, NULL);
- vmdef = NULL;
- }
+ if (!ret)
+ virDomainObjAssignDef(vm, &vmdef, false, NULL);
}
cleanup:
&mig, &xmlout, &taint_hook) < 0)
goto error;
- if (!(vm = virDomainObjListAdd(driver->domains, *def,
+ if (!(vm = virDomainObjListAdd(driver->domains, def,
driver->xmlopt,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto error;
- *def = NULL;
/*
* Unless an error is encountered in this function, the job will
&mig, &xmlout, &taint_hook) < 0)
goto error;
- if (!(vm = virDomainObjListAdd(driver->domains, *def,
+ if (!(vm = virDomainObjListAdd(driver->domains, def,
driver->xmlopt,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto error;
- *def = NULL;
/*
* Unless an error is encountered in this function, the job will
goto cleanup;
}
- if (!(vm = virDomainObjListAdd(driver->domains, def,
+ if (!(vm = virDomainObjListAdd(driver->domains, &def,
driver->xmlopt,
0, &oldDef)))
goto cleanup;
- def = NULL;
vm->persistent = 1;
if (virDomainDefSave(vm->newDef ? vm->newDef : vm->def,
}
- if (!(vm = virDomainObjListAdd(driver->domains, def,
+ if (!(vm = virDomainObjListAdd(driver->domains, &def,
driver->xmlopt,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
- def = NULL;
if (virLXCDomainObjBeginJob(driver, vm, LXC_JOB_MODIFY) < 0) {
if (!vm->persistent)
if (rc < 0)
goto endjob;
- virDomainObjAssignDef(vm, persistentDefCopy, false, NULL);
- persistentDefCopy = NULL;
+ virDomainObjAssignDef(vm, &persistentDefCopy, false, NULL);
}
ret = 0;
/* Finally, if no error until here, we can save config. */
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir);
- if (!ret) {
- virDomainObjAssignDef(vm, vmdef, false, NULL);
- vmdef = NULL;
- }
+ if (!ret)
+ virDomainObjAssignDef(vm, &vmdef, false, NULL);
}
endjob:
if (virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir) < 0)
goto endjob;
- virDomainObjAssignDef(vm, vmdef, false, NULL);
- vmdef = NULL;
+ virDomainObjAssignDef(vm, &vmdef, false, NULL);
ret = 0;
endjob:
/* Finally, if no error until here, we can save config. */
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir);
- if (!ret) {
- virDomainObjAssignDef(vm, vmdef, false, NULL);
- vmdef = NULL;
- }
+ if (!ret)
+ virDomainObjAssignDef(vm, &vmdef, false, NULL);
}
endjob:
flags |= VIR_DOMAIN_OBJ_LIST_ADD_LIVE;
if (!(dom = virDomainObjListAdd(driver->domains,
- def,
+ &def,
driver->xmlopt,
flags,
NULL)))
virDomainObjEndAPI(&dom);
dom = NULL;
- def = NULL;
}
virCommandFree(cmd);
if (virXMLCheckIllegalChars("name", vmdef->name, "\n") < 0)
goto cleanup;
- if (!(vm = virDomainObjListAdd(driver->domains, vmdef,
+ if (!(vm = virDomainObjListAdd(driver->domains, &vmdef,
driver->xmlopt,
0, NULL)))
goto cleanup;
- vmdef = NULL;
vm->persistent = 1;
if (openvzSetInitialConfig(vm->def) < 0) {
goto cleanup;
if (!(vm = virDomainObjListAdd(driver->domains,
- vmdef,
+ &vmdef,
driver->xmlopt,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
- vmdef = NULL;
+
/* All OpenVZ domains seem to be persistent - this is a bit of a violation
* of this libvirt API which is intended for transient domain creation */
vm->persistent = 1;
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE)))
goto error;
- if (!(vm = virDomainObjListAdd(driver->domains, def,
+ if (!(vm = virDomainObjListAdd(driver->domains, &def,
driver->xmlopt,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto error;
- def = NULL;
if (!uri_in) {
if ((my_hostname = virGetHostname()) == NULL)
if (virDomainCreateXMLEnsureACL(conn, def) < 0)
goto cleanup;
- if (!(vm = virDomainObjListAdd(driver->domains, def,
+ if (!(vm = virDomainObjListAdd(driver->domains, &def,
driver->xmlopt,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
- def = NULL;
if (qemuProcessBeginJob(driver, vm, VIR_DOMAIN_JOB_OPERATION_START,
flags) < 0) {
def = tmp;
}
- if (!(vm = virDomainObjListAdd(driver->domains, def,
+ if (!(vm = virDomainObjListAdd(driver->domains, &def,
driver->xmlopt,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
- def = NULL;
if (flags & VIR_DOMAIN_SAVE_RUNNING)
data->header.was_running = 1;
goto cleanup;
}
- virDomainObjAssignDef(vm, def, true, NULL);
- def = NULL;
+ virDomainObjAssignDef(vm, &def, true, NULL);
ret = qemuSaveImageStartVM(conn, driver, vm, &fd, data, path,
start_paused, asyncJob);
if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0)
goto cleanup;
- if (!(vm = virDomainObjListAdd(driver->domains, def,
+ if (!(vm = virDomainObjListAdd(driver->domains, &def,
driver->xmlopt,
0, &oldDef)))
goto cleanup;
- def = NULL;
if (!oldDef && qemuDomainNamePathsCleanup(cfg, vm->def->name, false) < 0)
goto cleanup;
if (virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir) < 0)
return -1;
- virDomainObjAssignDef(vm, vmdef, false, NULL);
- vmdef = NULL;
+ virDomainObjAssignDef(vm, &vmdef, false, NULL);
}
return 0;
/* Finally, if no error until here, we can save config. */
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir);
- if (!ret) {
- virDomainObjAssignDef(vm, vmdef, false, NULL);
- vmdef = NULL;
- }
+ if (!ret)
+ virDomainObjAssignDef(vm, &vmdef, false, NULL);
}
endjob:
if (virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir) < 0)
goto cleanup;
- virDomainObjAssignDef(vm, vmdef, false, NULL);
- vmdef = NULL;
+ virDomainObjAssignDef(vm, &vmdef, false, NULL);
}
ret = 0;
if (vmdef) {
if (virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir) < 0)
return -1;
- virDomainObjAssignDef(vm, vmdef, false, NULL);
- vmdef = NULL;
+ virDomainObjAssignDef(vm, &vmdef, false, NULL);
}
return 0;
if (rc < 0)
goto endjob;
- virDomainObjAssignDef(vm, persistentDefCopy, false, NULL);
- persistentDefCopy = NULL;
+ virDomainObjAssignDef(vm, &persistentDefCopy, false, NULL);
}
ret = 0;
QEMU_MIGRATION_COOKIE_BLOCK_DIRTY_BITMAPS)))
goto cleanup;
- if (!(vm = virDomainObjListAdd(driver->domains, *def,
+ if (!(vm = virDomainObjListAdd(driver->domains, def,
driver->xmlopt,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
- *def = NULL;
priv = vm->privateData;
jobPriv = priv->job.privateData;
}
if (inactiveConfig) {
- virDomainObjAssignDef(vm, inactiveConfig, false, NULL);
- inactiveConfig = NULL;
+ virDomainObjAssignDef(vm, &inactiveConfig, false, NULL);
defined = true;
}
- virDomainObjAssignDef(vm, config, true, NULL);
- config = NULL;
+ virDomainObjAssignDef(vm, &config, true, NULL);
/* No cookie means libvirt which saved the domain was too old to
* mess up the CPU definitions.
}
if (inactiveConfig) {
- virDomainObjAssignDef(vm, inactiveConfig, false, NULL);
- inactiveConfig = NULL;
+ virDomainObjAssignDef(vm, &inactiveConfig, false, NULL);
defined = true;
}
if (testDomainGenerateIfnames(def) < 0 ||
!(obj = virDomainObjListAdd(privconn->domains,
- def,
+ &def,
privconn->xmlopt,
0, NULL))) {
virDomainDefFree(def);
if (testParseDomainSnapshots(privconn, obj, file, ctxt) < 0)
goto error;
- nsdata = def->namespaceData;
+ nsdata = obj->def->namespaceData;
obj->persistent = !nsdata->transient;
obj->hasManagedSave = nsdata->hasManagedSave;
if (testDomainGenerateIfnames(def) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
- def,
+ &def,
privconn->xmlopt,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
- def = NULL;
if (testDomainStartState(privconn, dom, VIR_DOMAIN_RUNNING_BOOTED) < 0) {
if (!dom->persistent)
if (testDomainGenerateIfnames(def) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
- def,
+ &def,
privconn->xmlopt,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
- def = NULL;
if (testDomainStartState(privconn, dom, VIR_DOMAIN_RUNNING_RESTORED) < 0) {
if (!dom->persistent)
if (testDomainGenerateIfnames(def) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
- def,
+ &def,
privconn->xmlopt,
0,
&oldDef)))
goto cleanup;
- def = NULL;
dom->persistent = 1;
event = virDomainEventLifecycleNewFromObj(dom,
virObjectEventStateQueue(privconn->eventState, event);
}
- virDomainObjAssignDef(vm, config, false, NULL);
+ virDomainObjAssignDef(vm, &config, false, NULL);
if (testDomainStartState(privconn, vm,
VIR_DOMAIN_RUNNING_FROM_SNAPSHOT) < 0)
goto cleanup;
}
} else {
/* Transitions 1, 4, 7 */
- virDomainObjAssignDef(vm, config, false, NULL);
+ virDomainObjAssignDef(vm, &config, false, NULL);
if (virDomainObjIsActive(vm)) {
/* Transitions 4, 7 */
goto cleanup;
}
- if (!(vm = virDomainObjListAdd(driver->domains, vmdef,
+ if (!(vm = virDomainObjListAdd(driver->domains, &vmdef,
driver->xmlopt,
0, NULL)))
goto cleanup;
pDomain->vmxPath = g_strdup(vmxPath);
- vmwareDomainConfigDisplay(pDomain, vmdef);
+ vmwareDomainConfigDisplay(pDomain, vm->def);
if ((vm->def->id = vmwareExtractPid(vmxPath)) < 0)
goto cleanup;
vm->persistent = 1;
virDomainObjEndAPI(&vm);
-
- vmdef = NULL;
}
ret = 0;
/* assign def */
if (!(vm = virDomainObjListAdd(driver->domains,
- vmdef,
+ &vmdef,
driver->xmlopt,
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
pDomain = vm->privateData;
pDomain->vmxPath = g_strdup(vmxPath);
- vmwareDomainConfigDisplay(pDomain, vmdef);
+ vmwareDomainConfigDisplay(pDomain, vm->def);
- vmdef = NULL;
vm->persistent = 1;
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, -1);
/* assign def */
if (!(vm = virDomainObjListAdd(driver->domains,
- vmdef,
+ &vmdef,
driver->xmlopt,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
pDomain = vm->privateData;
pDomain->vmxPath = g_strdup(vmxPath);
- vmwareDomainConfigDisplay(pDomain, vmdef);
- vmdef = NULL;
+ vmwareDomainConfigDisplay(pDomain, vm->def);
if (vmwareStartVM(driver, vm) < 0) {
if (!vm->persistent)