]> xenbits.xensource.com Git - libvirt.git/commitdiff
vz: fix possible vzDomainDefineXMLFlags and prlsdkNewDomainByHandle race
authorMaxim Nestratov <mnestratov@virtuozzo.com>
Tue, 12 Apr 2016 17:30:57 +0000 (20:30 +0300)
committerMaxim Nestratov <mnestratov@virtuozzo.com>
Wed, 13 Apr 2016 15:48:44 +0000 (18:48 +0300)
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>
src/vz/vz_sdk.c

index 658fdf938899ec007cf3b0ade13e11da3ab42a32..6131b9db86c68865b3fb3fcb42fdf1542b04b436 100644 (file)
@@ -1254,9 +1254,18 @@ prlsdkNewDomainByHandle(vzDriverPtr driver, PRL_HANDLE sdkdom)
     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;
 
@@ -1267,6 +1276,7 @@ prlsdkNewDomainByHandle(vzDriverPtr driver, PRL_HANDLE sdkdom)
     }
 
  cleanup:
+    virObjectUnlock(driver);
     VIR_FREE(name);
     return dom;
 }