Signed-off-by: Dmitry Guryanov <dguryanov(a)parallels.com>
---
src/parallels/parallels_driver.c | 40 +++++++++++++++----------------------
1 files changed, 16 insertions(+), 24 deletions(-)
diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index 1f6dcef..72e32ff 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -1589,8 +1589,9 @@ parallelsDomainDefineXML(virConnectPtr conn, const char *xml)
virDomainDefPtr def;
virDomainObjPtr dom = NULL, olddom = NULL;
int dupVM;
+ virDomainObjListPtr domains = NULL;
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
- parallelsDriverLock(privconn);
if ((def = virDomainDefParseString(privconn->caps, xml,
1 << VIR_DOMAIN_VIRT_PARALLELS,
VIR_DOMAIN_XML_INACTIVE)) == NULL) {
@@ -1599,41 +1600,32 @@ parallelsDomainDefineXML(virConnectPtr conn, const char *xml)
goto cleanup;
}
- if ((dupVM = virDomainObjIsDuplicate(privconn->domains, def, 0)) < 0) {
+ if (!(domains = parallelsGetDomains(privconn)))
+ goto cleanup;
+
+ if ((dupVM = virDomainObjIsDuplicate(domains, def, 0)) < 0) {
virReportError(VIR_ERR_INVALID_ARG, "%s", _("Already
exists"));
goto cleanup;
}
if (dupVM == 1) {
- olddom = virDomainFindByUUID(privconn->domains, def->uuid);
+ olddom = virDomainFindByUUID(domains, def->uuid);
if (parallelsApplyChanges(olddom, def) < 0) {
virDomainObjUnlock(olddom);
goto cleanup;
}
virDomainObjUnlock(olddom);
-
- if (!(dom = virDomainAssignDef(privconn->caps,
- privconn->domains, def, false))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Can't allocate domobj"));
- goto cleanup;
- }
-
- def = NULL;
} else {
- char uuidstr[VIR_UUID_STRING_BUFLEN];
-
if (parallelsCreateVm(conn, def))
goto cleanup;
+ }
- if (!(dom = parallelsGetDomain(privconn, def->name)))
- goto cleanup;
+ virUUIDFormat(def->uuid, uuidstr);
- virUUIDFormat(dom->def->uuid, uuidstr);
- if (virHashAddEntry(privconn->domains->objs, uuidstr, dom) < 0) {
- VIR_FREE(dom);
- goto cleanup;
- }
+ if (!(dom = parallelsGetDomain(privconn, uuidstr))) {
+ virReportError(VIR_ERR_NO_DOMAIN,
+ _("no domain with matching uuid '%s'"),
uuidstr);
+ goto cleanup;
}
ret = virGetDomain(conn, dom->def->name, dom->def->uuid);
@@ -1642,9 +1634,9 @@ parallelsDomainDefineXML(virConnectPtr conn, const char *xml)
cleanup:
virDomainDefFree(def);
- if (dom)
- virDomainObjUnlock(dom);
- parallelsDriverUnlock(privconn);
+ virObjectUnref(dom);
+ virDomainObjListDeinit(domains);
+ VIR_FREE(domains);
return ret;
}
--
1.7.1