[PATCH v4 3/6] vz: fix possible vzDomainDefineXMLFlags and prlsdkNewDomainByHandle race

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx>
---
 src/vz/vz_sdk.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index c6408e9..563e47a 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -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;
 }
-- 
2.4.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]