First, we don't need to call prlsdkApplyConfig after creating new VM or containers, because it's done in functions prlsdkCreateVm and prlsdkCreateCt. No need to check, if domain exists in the list after prlsdkAddDomain. Also organize code, so that we can call virObjectUnlock in one place. Signed-off-by: Dmitry Guryanov <dguryanov@xxxxxxxxxxxxx> --- src/parallels/parallels_driver.c | 35 ++++++++++++++--------------------- src/parallels/parallels_sdk.c | 2 +- src/parallels/parallels_sdk.h | 1 + 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index 582ffdb..955516a 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -661,10 +661,9 @@ static virDomainPtr parallelsDomainDefineXML(virConnectPtr conn, const char *xml) { parallelsConnPtr privconn = conn->privateData; - virDomainPtr ret = NULL; + virDomainPtr retdom = NULL; virDomainDefPtr def; virDomainObjPtr olddom = NULL; - virDomainObjPtr dom = NULL; parallelsDriverLock(privconn); if ((def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt, @@ -689,34 +688,28 @@ parallelsDomainDefineXML(virConnectPtr conn, const char *xml) _("Unsupported OS type: %s"), def->os.type); goto cleanup; } - dom = prlsdkAddDomain(privconn, def->uuid); - if (dom) - virObjectUnlock(dom); - else + + olddom = prlsdkAddDomain(privconn, def->uuid); + if (!olddom) goto cleanup; - olddom = virDomainObjListFindByName(privconn->domains, def->name); - if (!olddom) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Domain for '%s' is not defined after creation"), - def->name ? def->name : _("(unnamed)")); + } else { + if (prlsdkApplyConfig(conn, olddom, def)) goto cleanup; - } - } - if (prlsdkApplyConfig(conn, olddom, def) < 0) { - virObjectUnlock(olddom); - goto cleanup; + if (prlsdkUpdateDomain(privconn, olddom)) + goto cleanup; } - virObjectUnlock(olddom); - ret = virGetDomain(conn, def->name, def->uuid); - if (ret) - ret->id = def->id; + retdom = virGetDomain(conn, def->name, def->uuid); + if (retdom) + retdom->id = def->id; cleanup: + if (olddom) + virObjectUnlock(olddom); virDomainDefFree(def); parallelsDriverUnlock(privconn); - return ret; + return retdom; } static int diff --git a/src/parallels/parallels_sdk.c b/src/parallels/parallels_sdk.c index abb2db1..6fe84d5 100644 --- a/src/parallels/parallels_sdk.c +++ b/src/parallels/parallels_sdk.c @@ -1248,7 +1248,7 @@ prlsdkAddDomain(parallelsConnPtr privconn, const unsigned char *uuid) return dom; } -static int +int prlsdkUpdateDomain(parallelsConnPtr privconn, virDomainObjPtr dom) { PRL_HANDLE job; diff --git a/src/parallels/parallels_sdk.h b/src/parallels/parallels_sdk.h index b654c2a..1fdef1a 100644 --- a/src/parallels/parallels_sdk.h +++ b/src/parallels/parallels_sdk.h @@ -32,6 +32,7 @@ int prlsdkLoadDomains(parallelsConnPtr privconn); virDomainObjPtr prlsdkAddDomain(parallelsConnPtr privconn, const unsigned char *uuid); +int prlsdkUpdateDomain(parallelsConnPtr privconn, virDomainObjPtr dom); int prlsdkSubscribeToPCSEvents(parallelsConnPtr privconn); void prlsdkUnsubscribeFromPCSEvents(parallelsConnPtr privconn); int prlsdkStart(parallelsConnPtr privconn, PRL_HANDLE sdkdom); -- 1.9.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list