Lock driver when a new domain is created in prlsdkNewDomainByHandle
and try to find it in the list under lock again because it can race
with vzDomainDefineXMLFlags when a domain with the same uuid is added
via vz dispatcher directly and libvirt define.
Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
unsigned char uuid[VIR_UUID_BUFLEN];
char *name = NULL;
+ virObjectLock(driver);
if (prlsdkGetDomainIds(sdkdom, &name, uuid) < 0)
goto cleanup;
+ /* we should make sure that there is no such a VM exists */
+ dom = virDomainObjListFindByUUID(driver->domains, uuid);
+ if (dom) {
+ virObjectUnlock(dom);
+ dom = NULL;
+ goto cleanup;
+ }
+
if (!(dom = vzNewDomain(driver, name, uuid)))
goto cleanup;
}
cleanup:
+ virObjectUnlock(driver);
VIR_FREE(name);
return dom;
}