[PATCH 11/12] libxl: Remove unnecessary driver locking

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

 



Now that most fields of libxlDriverPrivate struct are immutable
or self-locking, there is no need to acquire the driver lock in
much of the libxl driver.

Signed-off-by: Jim Fehlig <jfehlig@xxxxxxxx>
---
 src/libxl/libxl_conf.c   |   7 +-
 src/libxl/libxl_driver.c | 217 +++++++++--------------------------------------
 2 files changed, 46 insertions(+), 178 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 19fd8a6..34f6bc1 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1110,7 +1110,12 @@ error:
 libxlDriverConfigPtr
 libxlDriverConfigGet(libxlDriverPrivatePtr driver)
 {
-    return virObjectRef(driver->config);
+    libxlDriverConfigPtr cfg;
+
+    libxlDriverLock(driver);
+    cfg = virObjectRef(driver->config);
+    libxlDriverUnlock(driver);
+    return cfg;
 }
 
 virCapsPtr
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 8ece4c9..22bd26f 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -77,7 +77,6 @@ static int
 libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
              bool start_paused, int restore_fd);
 
-/* driver must be locked before calling */
 static void
 libxlDomainEventQueue(libxlDriverPrivatePtr driver, virDomainEventPtr event)
 {
@@ -156,17 +155,21 @@ libxlDomainManagedSavePath(libxlDriverPrivatePtr driver, virDomainObjPtr vm) {
     return ret;
 }
 
-/* This internal function expects the driver lock to already be held on
- * entry. */
-static int ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4)
-libxlSaveImageOpen(libxlDriverPrivatePtr driver, const char *from,
-                     virDomainDefPtr *ret_def, libxlSavefileHeaderPtr ret_hdr)
+/*
+ * This internal function expects the driver lock to already be held on
+ * entry.
+ */
+static int ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5)
+libxlSaveImageOpen(libxlDriverPrivatePtr driver,
+                   libxlDriverConfigPtr cfg,
+                   const char *from,
+                   virDomainDefPtr *ret_def,
+                   libxlSavefileHeaderPtr ret_hdr)
 {
     int fd;
     virDomainDefPtr def = NULL;
     libxlSavefileHeader hdr;
     char *xml = NULL;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
     int ret = -1;
 
     if ((fd = virFileOpenAs(from, O_RDONLY, 0, -1, -1, 0)) < 0) {
@@ -350,10 +353,7 @@ libxlEventHandler(void *data, VIR_LIBXL_EVENT_CONST libxl_event *event)
         if (xl_reason == LIBXL_SHUTDOWN_REASON_SUSPEND)
             goto cleanup;
 
-        libxlDriverLock(driver);
         vm = virDomainObjListFindByID(driver->domains, event->domid);
-        libxlDriverUnlock(driver);
-
         if (!vm)
             goto cleanup;
 
@@ -387,11 +387,8 @@ libxlEventHandler(void *data, VIR_LIBXL_EVENT_CONST libxl_event *event)
 cleanup:
     if (vm)
         virObjectUnlock(vm);
-    if (dom_event) {
-        libxlDriverLock(driver);
+    if (dom_event)
         libxlDomainEventQueue(driver, dom_event);
-        libxlDriverUnlock(driver);
-    }
     /* Cast away any const */
     libxl_event_free(priv->ctx, (libxl_event *)event);
 }
@@ -550,7 +547,8 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
 
         if (virFileExists(managed_save_path)) {
 
-            managed_save_fd = libxlSaveImageOpen(driver, managed_save_path,
+            managed_save_fd = libxlSaveImageOpen(driver, cfg,
+                                                 managed_save_path,
                                                  &def, &hdr);
             if (managed_save_fd < 0)
                 goto error;
@@ -811,7 +809,6 @@ libxlStateInitialize(bool privileged,
         VIR_FREE(libxl_driver);
         return -1;
     }
-    libxlDriverLock(libxl_driver);
 
     /* Allocate bitmap for vnc port reservation */
     if (!(libxl_driver->reservedVNCPorts =
@@ -892,13 +889,9 @@ libxlStateInitialize(bool privileged,
     virDomainObjListForEach(libxl_driver->domains, libxlDomainManagedSaveLoad,
                             libxl_driver);
 
-    libxlDriverUnlock(libxl_driver);
-
     return 0;
 
 error:
-    if (libxl_driver)
-        libxlDriverUnlock(libxl_driver);
     libxlStateCleanup();
     return -1;
 }
@@ -909,10 +902,8 @@ libxlStateAutoStart(void)
     if (!libxl_driver)
         return;
 
-    libxlDriverLock(libxl_driver);
     virDomainObjListForEach(libxl_driver->domains, libxlAutostartDomain,
                             libxl_driver);
-    libxlDriverUnlock(libxl_driver);
 }
 
 static int
@@ -923,7 +914,6 @@ libxlStateReload(void)
     if (!libxl_driver)
         return 0;
 
-    libxlDriverLock(libxl_driver);
     cfg = libxlDriverConfigGet(libxl_driver);
 
     virDomainObjListLoadAllConfigs(libxl_driver->domains,
@@ -939,8 +929,6 @@ libxlStateReload(void)
                             libxl_driver);
 
     virObjectUnref(cfg);
-    libxlDriverUnlock(libxl_driver);
-
     return 0;
 }
 
@@ -1019,11 +1007,9 @@ libxlConnectGetVersion(virConnectPtr conn, unsigned long *version)
     if (virConnectGetVersionEnsureACL(conn) < 0)
         return 0;
 
-    libxlDriverLock(driver);
     cfg = libxlDriverConfigGet(driver);
     *version = cfg->version;
     virObjectUnref(cfg);
-    libxlDriverUnlock(driver);
     return 0;
 }
 
@@ -1102,11 +1088,9 @@ libxlConnectGetCapabilities(virConnectPtr conn)
     if (virConnectGetCapabilitiesEnsureACL(conn) < 0)
         return NULL;
 
-    libxlDriverLock(driver);
     cfg = libxlDriverConfigGet(driver);
     if ((xml = virCapabilitiesFormatXML(cfg->caps)) == NULL)
         virReportOOMError();
-    libxlDriverUnlock(driver);
 
     virObjectUnref(cfg);
     return xml;
@@ -1121,10 +1105,8 @@ libxlConnectListDomains(virConnectPtr conn, int *ids, int nids)
     if (virConnectListDomainsEnsureACL(conn) < 0)
         return -1;
 
-    libxlDriverLock(driver);
     n = virDomainObjListGetActiveIDs(driver->domains, ids, nids,
                                      virConnectListDomainsCheckACL, conn);
-    libxlDriverUnlock(driver);
 
     return n;
 }
@@ -1138,10 +1120,8 @@ libxlConnectNumOfDomains(virConnectPtr conn)
     if (virConnectNumOfDomainsEnsureACL(conn) < 0)
         return -1;
 
-    libxlDriverLock(driver);
     n = virDomainObjListNumOfDomains(driver->domains, true,
                                      virConnectNumOfDomainsCheckACL, conn);
-    libxlDriverUnlock(driver);
 
     return n;
 }
@@ -1158,7 +1138,6 @@ libxlDomainCreateXML(virConnectPtr conn, const char *xml,
 
     virCheckFlags(VIR_DOMAIN_START_PAUSED, NULL);
 
-    libxlDriverLock(driver);
     if (!(def = virDomainDefParseString(xml, cfg->caps, driver->xmlopt,
                                         1 << VIR_DOMAIN_VIRT_XEN,
                                         VIR_DOMAIN_XML_INACTIVE)))
@@ -1189,7 +1168,6 @@ cleanup:
     virDomainDefFree(def);
     if (vm)
         virObjectUnlock(vm);
-    libxlDriverUnlock(driver);
     virObjectUnref(cfg);
     return dom;
 }
@@ -1201,10 +1179,7 @@ libxlDomainLookupByID(virConnectPtr conn, int id)
     virDomainObjPtr vm;
     virDomainPtr dom = NULL;
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByID(driver->domains, id);
-    libxlDriverUnlock(driver);
-
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, NULL);
         goto cleanup;
@@ -1230,10 +1205,7 @@ libxlDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
     virDomainObjPtr vm;
     virDomainPtr dom = NULL;
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, uuid);
-    libxlDriverUnlock(driver);
-
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, NULL);
         goto cleanup;
@@ -1259,10 +1231,7 @@ libxlDomainLookupByName(virConnectPtr conn, const char *name)
     virDomainObjPtr vm;
     virDomainPtr dom = NULL;
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByName(driver->domains, name);
-    libxlDriverUnlock(driver);
-
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, NULL);
         goto cleanup;
@@ -1291,10 +1260,7 @@ libxlDomainSuspend(virDomainPtr dom)
     virDomainEventPtr event = NULL;
     int ret = -1;
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
-
     if (!vm) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
         virUUIDFormat(dom->uuid, uuidstr);
@@ -1335,11 +1301,8 @@ libxlDomainSuspend(virDomainPtr dom)
 cleanup:
     if (vm)
         virObjectUnlock(vm);
-    if (event) {
-        libxlDriverLock(driver);
+    if (event)
         libxlDomainEventQueue(driver, event);
-        libxlDriverUnlock(driver);
-    }
     virObjectUnref(cfg);
     return ret;
 }
@@ -1355,10 +1318,7 @@ libxlDomainResume(virDomainPtr dom)
     virDomainEventPtr event = NULL;
     int ret = -1;
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
-
     if (!vm) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
         virUUIDFormat(dom->uuid, uuidstr);
@@ -1400,11 +1360,8 @@ libxlDomainResume(virDomainPtr dom)
 cleanup:
     if (vm)
         virObjectUnlock(vm);
-    if (event) {
-        libxlDriverLock(driver);
+    if (event)
         libxlDomainEventQueue(driver, event);
-        libxlDriverUnlock(driver);
-    }
     virObjectUnref(cfg);
     return ret;
 }
@@ -1419,7 +1376,6 @@ libxlDomainShutdownFlags(virDomainPtr dom, unsigned int flags)
 
     virCheckFlags(0, -1);
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
     if (!vm) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
@@ -1454,7 +1410,6 @@ libxlDomainShutdownFlags(virDomainPtr dom, unsigned int flags)
 cleanup:
     if (vm)
         virObjectUnlock(vm);
-    libxlDriverUnlock(driver);
     return ret;
 }
 
@@ -1475,7 +1430,6 @@ libxlDomainReboot(virDomainPtr dom, unsigned int flags)
 
     virCheckFlags(0, -1);
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
     if (!vm) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
@@ -1506,7 +1460,6 @@ libxlDomainReboot(virDomainPtr dom, unsigned int flags)
 cleanup:
     if (vm)
         virObjectUnlock(vm);
-    libxlDriverUnlock(driver);
     return ret;
 }
 
@@ -1521,7 +1474,6 @@ libxlDomainDestroyFlags(virDomainPtr dom,
 
     virCheckFlags(0, -1);
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
     if (!vm) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
@@ -1561,7 +1513,6 @@ cleanup:
         virObjectUnlock(vm);
     if (event)
         libxlDomainEventQueue(driver, event);
-    libxlDriverUnlock(driver);
     return ret;
 }
 
@@ -1578,9 +1529,7 @@ libxlDomainGetOSType(virDomainPtr dom)
     virDomainObjPtr vm;
     char *type = NULL;
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
     if (!vm) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
         virUUIDFormat(dom->uuid, uuidstr);
@@ -1608,10 +1557,7 @@ libxlDomainGetMaxMemory(virDomainPtr dom)
     virDomainObjPtr vm;
     unsigned long long ret = 0;
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
-
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, "%s", _("no domain with matching uuid"));
         goto cleanup;
@@ -1644,10 +1590,7 @@ libxlDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
                   VIR_DOMAIN_MEM_CONFIG |
                   VIR_DOMAIN_MEM_MAXIMUM, -1);
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
-
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, "%s", _("no domain with matching uuid"));
         goto cleanup;
@@ -1770,10 +1713,7 @@ libxlDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info)
     libxlDomainObjPrivatePtr priv;
     int ret = -1;
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
-
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, "%s",
                        _("no domain with matching uuid"));
@@ -1821,10 +1761,7 @@ libxlDomainGetState(virDomainPtr dom,
 
     virCheckFlags(0, -1);
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
-
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, "%s",
                        _("no domain with matching uuid"));
@@ -1935,9 +1872,7 @@ libxlDomainSaveFlags(virDomainPtr dom, const char *to, const char *dxml,
         return -1;
     }
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-
     if (!vm) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
         virUUIDFormat(dom->uuid, uuidstr);
@@ -1967,7 +1902,6 @@ libxlDomainSaveFlags(virDomainPtr dom, const char *to, const char *dxml,
 cleanup:
     if (vm)
         virObjectUnlock(vm);
-    libxlDriverUnlock(driver);
     return ret;
 }
 
@@ -1982,6 +1916,7 @@ libxlDomainRestoreFlags(virConnectPtr conn, const char *from,
                         const char *dxml, unsigned int flags)
 {
     libxlDriverPrivatePtr driver = conn->privateData;
+    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm = NULL;
     virDomainDefPtr def = NULL;
     libxlSavefileHeader hdr;
@@ -1995,22 +1930,26 @@ libxlDomainRestoreFlags(virConnectPtr conn, const char *from,
         return -1;
     }
 
+    /* Lock the driver until domain def is read from the saved
+       image and a virDomainObj is created and locked.
+    */
     libxlDriverLock(driver);
 
-    fd = libxlSaveImageOpen(driver, from, &def, &hdr);
+    fd = libxlSaveImageOpen(driver, cfg, from, &def, &hdr);
     if (fd < 0)
-        goto cleanup;
+        goto cleanup_unlock;
 
     if (virDomainRestoreFlagsEnsureACL(conn, def) < 0)
-        goto cleanup;
+        goto cleanup_unlock;
 
     if (!(vm = virDomainObjListAdd(driver->domains, def,
                                    driver->xmlopt,
                                    VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
                                    VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
                                    NULL)))
-        goto cleanup;
+        goto cleanup_unlock;
 
+    libxlDriverUnlock(driver);
     def = NULL;
 
     ret = libxlVmStart(driver, vm, (flags & VIR_DOMAIN_SAVE_PAUSED) != 0, fd);
@@ -2025,8 +1964,11 @@ cleanup:
     virDomainDefFree(def);
     if (vm)
         virObjectUnlock(vm);
-    libxlDriverUnlock(driver);
     return ret;
+
+cleanup_unlock:
+    libxlDriverUnlock(driver);
+    goto cleanup;
 }
 
 static int
@@ -2047,10 +1989,7 @@ libxlDomainCoreDump(virDomainPtr dom, const char *to, unsigned int flags)
 
     virCheckFlags(VIR_DUMP_LIVE | VIR_DUMP_CRASH, -1);
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
-
     if (!vm) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
         virUUIDFormat(dom->uuid, uuidstr);
@@ -2089,12 +2028,11 @@ libxlDomainCoreDump(virDomainPtr dom, const char *to, unsigned int flags)
         goto cleanup_unpause;
     }
 
-    libxlDriverLock(driver);
     if (flags & VIR_DUMP_CRASH) {
         if (libxlVmReap(driver, vm, VIR_DOMAIN_SHUTOFF_CRASHED) != 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Failed to destroy domain '%d'"), dom->id);
-            goto cleanup_unlock;
+            goto cleanup_unpause;
         }
 
         event = virDomainEventNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED,
@@ -2108,8 +2046,6 @@ libxlDomainCoreDump(virDomainPtr dom, const char *to, unsigned int flags)
 
     ret = 0;
 
-cleanup_unlock:
-    libxlDriverUnlock(driver);
 cleanup_unpause:
     if (virDomainObjIsActive(vm) && paused) {
         if (libxl_domain_unpause(priv->ctx, dom->id) != 0) {
@@ -2124,11 +2060,8 @@ cleanup_unpause:
 cleanup:
     if (vm)
         virObjectUnlock(vm);
-    if (event) {
-        libxlDriverLock(driver);
+    if (event)
         libxlDomainEventQueue(driver, event);
-        libxlDriverUnlock(driver);
-    }
     return ret;
 }
 
@@ -2142,7 +2075,6 @@ libxlDomainManagedSave(virDomainPtr dom, unsigned int flags)
 
     virCheckFlags(0, -1);
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
     if (!vm) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
@@ -2184,7 +2116,6 @@ libxlDomainManagedSave(virDomainPtr dom, unsigned int flags)
 cleanup:
     if (vm)
         virObjectUnlock(vm);
-    libxlDriverUnlock(driver);
     VIR_FREE(name);
     return ret;
 }
@@ -2220,7 +2151,6 @@ libxlDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
 
     virCheckFlags(0, -1);
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
     if (!vm) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
@@ -2238,7 +2168,6 @@ libxlDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
 cleanup:
     if (vm)
         virObjectUnlock(vm);
-    libxlDriverUnlock(driver);
     return ret;
 }
 
@@ -2252,7 +2181,6 @@ libxlDomainManagedSaveRemove(virDomainPtr dom, unsigned int flags)
 
     virCheckFlags(0, -1);
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
     if (!vm) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
@@ -2276,7 +2204,6 @@ cleanup:
     VIR_FREE(name);
     if (vm)
         virObjectUnlock(vm);
-    libxlDriverUnlock(driver);
     return ret;
 }
 
@@ -2316,10 +2243,7 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
         return -1;
     }
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
-
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, "%s", _("no domain with matching uuid"));
         goto cleanup;
@@ -2437,10 +2361,7 @@ libxlDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
                   VIR_DOMAIN_VCPU_CONFIG |
                   VIR_DOMAIN_VCPU_MAXIMUM, -1);
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
-
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, "%s", _("no domain with matching uuid"));
         goto cleanup;
@@ -2498,10 +2419,7 @@ libxlDomainPinVcpu(virDomainPtr dom, unsigned int vcpu, unsigned char *cpumap,
     int ret = -1;
     libxl_bitmap map;
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
-
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, "%s", _("no domain with matching uuid"));
         goto cleanup;
@@ -2567,10 +2485,7 @@ libxlDomainGetVcpus(virDomainPtr dom, virVcpuInfoPtr info, int maxinfo,
     size_t i;
     unsigned char *cpumap;
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
-
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, "%s", _("no domain with matching uuid"));
         goto cleanup;
@@ -2633,10 +2548,7 @@ libxlDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
 
     /* Flags checked by virDomainDefFormat */
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
-
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, "%s",
                        _("no domain with matching uuid"));
@@ -2754,10 +2666,8 @@ libxlConnectListDefinedDomains(virConnectPtr conn,
     if (virConnectListDefinedDomainsEnsureACL(conn) < 0)
         return -1;
 
-    libxlDriverLock(driver);
     n = virDomainObjListGetInactiveNames(driver->domains, names, nnames,
                                          virConnectListDefinedDomainsCheckACL, conn);
-    libxlDriverUnlock(driver);
     return n;
 }
 
@@ -2770,12 +2680,9 @@ libxlConnectNumOfDefinedDomains(virConnectPtr conn)
     if (virConnectNumOfDefinedDomainsEnsureACL(conn) < 0)
         return -1;
 
-    libxlDriverLock(driver);
     n = virDomainObjListNumOfDomains(driver->domains, false,
                                      virConnectNumOfDefinedDomainsCheckACL,
                                      conn);
-    libxlDriverUnlock(driver);
-
     return n;
 }
 
@@ -2789,7 +2696,6 @@ libxlDomainCreateWithFlags(virDomainPtr dom,
 
     virCheckFlags(VIR_DOMAIN_START_PAUSED, -1);
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
     if (!vm) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
@@ -2813,7 +2719,6 @@ libxlDomainCreateWithFlags(virDomainPtr dom,
 cleanup:
     if (vm)
         virObjectUnlock(vm);
-    libxlDriverUnlock(driver);
     return ret;
 }
 
@@ -2834,22 +2739,25 @@ libxlDomainDefineXML(virConnectPtr conn, const char *xml)
     virDomainEventPtr event = NULL;
     virDomainDefPtr oldDef = NULL;
 
+    /* Lock the driver until the virDomainObj is created and locked */
     libxlDriverLock(driver);
     if (!(def = virDomainDefParseString(xml, cfg->caps, driver->xmlopt,
                                         1 << VIR_DOMAIN_VIRT_XEN,
                                         VIR_DOMAIN_XML_INACTIVE)))
-        goto cleanup;
+        goto cleanup_unlock;
 
     if (virDomainDefineXMLEnsureACL(conn, def) < 0)
-        goto cleanup;
+        goto cleanup_unlock;
 
     if (!(vm = virDomainObjListAdd(driver->domains, def,
                                    driver->xmlopt,
                                    0,
                                    &oldDef)))
-        goto cleanup;
+        goto cleanup_unlock;
+
     def = NULL;
     vm->persistent = 1;
+    libxlDriverUnlock(driver);
 
     if (virDomainSaveConfig(cfg->configDir,
                             vm->newDef ? vm->newDef : vm->def) < 0) {
@@ -2874,9 +2782,12 @@ cleanup:
         virObjectUnlock(vm);
     if (event)
         libxlDomainEventQueue(driver, event);
-    libxlDriverUnlock(driver);
     virObjectUnref(cfg);
     return dom;
+
+cleanup_unlock:
+    libxlDriverUnlock(driver);
+    goto cleanup;
 }
 
 static int
@@ -2892,9 +2803,7 @@ libxlDomainUndefineFlags(virDomainPtr dom,
 
     virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE, -1);
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-
     if (!vm) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
 
@@ -2953,7 +2862,6 @@ libxlDomainUndefineFlags(virDomainPtr dom,
         virObjectUnlock(vm);
     if (event)
         libxlDomainEventQueue(driver, event);
-    libxlDriverUnlock(driver);
     virObjectUnref(cfg);
     return ret;
 }
@@ -3324,9 +3232,7 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
     virCheckFlags(VIR_DOMAIN_DEVICE_MODIFY_LIVE |
                   VIR_DOMAIN_DEVICE_MODIFY_CONFIG, -1);
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, "%s", _("no domain with matching uuid"));
         goto cleanup;
@@ -3407,7 +3313,6 @@ cleanup:
     virDomainDeviceDefFree(dev);
     if (vm)
         virObjectUnlock(vm);
-    libxlDriverUnlock(driver);
     virObjectUnref(cfg);
     return ret;
 }
@@ -3434,9 +3339,7 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
     virCheckFlags(VIR_DOMAIN_DEVICE_MODIFY_LIVE |
                   VIR_DOMAIN_DEVICE_MODIFY_CONFIG, -1);
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, "%s", _("no domain with matching uuid"));
         goto cleanup;
@@ -3517,7 +3420,6 @@ cleanup:
     virDomainDeviceDefFree(dev);
     if (vm)
         virObjectUnlock(vm);
-    libxlDriverUnlock(driver);
     virObjectUnref(cfg);
     return ret;
 }
@@ -3544,9 +3446,7 @@ libxlDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml,
     virCheckFlags(VIR_DOMAIN_DEVICE_MODIFY_LIVE |
                   VIR_DOMAIN_DEVICE_MODIFY_CONFIG, -1);
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, "%s", _("no domain with matching uuid"));
         goto cleanup;
@@ -3627,7 +3527,6 @@ cleanup:
     virDomainDeviceDefFree(dev);
     if (vm)
         virObjectUnlock(vm);
-    libxlDriverUnlock(driver);
     virObjectUnref(cfg);
     return ret;
 }
@@ -3715,11 +3614,9 @@ libxlConnectDomainEventRegister(virConnectPtr conn,
     if (virConnectDomainEventRegisterEnsureACL(conn) < 0)
         return -1;
 
-    libxlDriverLock(driver);
     ret = virDomainEventStateRegister(conn,
                                       driver->domainEventState,
                                       callback, opaque, freecb);
-    libxlDriverUnlock(driver);
 
     return ret;
 }
@@ -3735,11 +3632,9 @@ libxlConnectDomainEventDeregister(virConnectPtr conn,
     if (virConnectDomainEventDeregisterEnsureACL(conn) < 0)
         return -1;
 
-    libxlDriverLock(driver);
     ret = virDomainEventStateDeregister(conn,
                                         driver->domainEventState,
                                         callback);
-    libxlDriverUnlock(driver);
 
     return ret;
 }
@@ -3751,10 +3646,7 @@ libxlDomainGetAutostart(virDomainPtr dom, int *autostart)
     virDomainObjPtr vm;
     int ret = -1;
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
-
     if (!vm) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
         virUUIDFormat(dom->uuid, uuidstr);
@@ -3784,9 +3676,7 @@ libxlDomainSetAutostart(virDomainPtr dom, int autostart)
     char *configFile = NULL, *autostartLink = NULL;
     int ret = -1;
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-
     if (!vm) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
         virUUIDFormat(dom->uuid, uuidstr);
@@ -3844,7 +3734,6 @@ cleanup:
     VIR_FREE(autostartLink);
     if (vm)
         virObjectUnlock(vm);
-    libxlDriverUnlock(driver);
     virObjectUnref(cfg);
     return ret;
 }
@@ -3859,10 +3748,7 @@ libxlDomainGetSchedulerType(virDomainPtr dom, int *nparams)
     const char *name = NULL;
     libxl_scheduler sched_id;
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
-
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, "%s", _("no domain with matching uuid"));
         goto cleanup;
@@ -3929,10 +3815,7 @@ libxlDomainGetSchedulerParametersFlags(virDomainPtr dom,
     /* We don't return strings, and thus trivially support this flag.  */
     flags &= ~VIR_TYPED_PARAM_STRING_OKAY;
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
-
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, "%s",
                        _("no domain with matching uuid"));
@@ -4015,10 +3898,7 @@ libxlDomainSetSchedulerParametersFlags(virDomainPtr dom,
                                NULL) < 0)
         return -1;
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
-
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, "%s", _("no domain with matching uuid"));
         goto cleanup;
@@ -4096,9 +3976,7 @@ libxlDomainOpenConsole(virDomainPtr dom,
         goto cleanup;
     }
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
     if (!vm) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
         virUUIDFormat(dom->uuid, uuidstr);
@@ -4199,10 +4077,7 @@ libxlDomainGetNumaParameters(virDomainPtr dom,
      * the filtering on behalf of older clients that can't parse it. */
     flags &= ~VIR_TYPED_PARAM_STRING_OKAY;
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
-
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, "%s",
                        _("no domain with matching uuid"));
@@ -4312,9 +4187,7 @@ libxlDomainIsActive(virDomainPtr dom)
     virDomainObjPtr obj;
     int ret = -1;
 
-    libxlDriverLock(driver);
     obj = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
     if (!obj) {
         virReportError(VIR_ERR_NO_DOMAIN, NULL);
         goto cleanup;
@@ -4338,9 +4211,7 @@ libxlDomainIsPersistent(virDomainPtr dom)
     virDomainObjPtr obj;
     int ret = -1;
 
-    libxlDriverLock(driver);
     obj = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
     if (!obj) {
         virReportError(VIR_ERR_NO_DOMAIN, NULL);
         goto cleanup;
@@ -4364,9 +4235,7 @@ libxlDomainIsUpdated(virDomainPtr dom)
     virDomainObjPtr vm;
     int ret = -1;
 
-    libxlDriverLock(driver);
     vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-    libxlDriverUnlock(driver);
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, NULL);
         goto cleanup;
@@ -4394,13 +4263,11 @@ libxlConnectDomainEventRegisterAny(virConnectPtr conn, virDomainPtr dom, int eve
     if (virConnectDomainEventRegisterAnyEnsureACL(conn) < 0)
         return -1;
 
-    libxlDriverLock(driver);
     if (virDomainEventStateRegisterID(conn,
                                       driver->domainEventState,
                                       dom, eventID, callback, opaque,
                                       freecb, &ret) < 0)
         ret = -1;
-    libxlDriverUnlock(driver);
 
     return ret;
 }
@@ -4415,11 +4282,9 @@ libxlConnectDomainEventDeregisterAny(virConnectPtr conn, int callbackID)
     if (virConnectDomainEventDeregisterAnyEnsureACL(conn) < 0)
         return -1;
 
-    libxlDriverLock(driver);
     ret = virDomainEventStateDeregisterID(conn,
                                           driver->domainEventState,
                                           callbackID);
-    libxlDriverUnlock(driver);
 
     return ret;
 }
@@ -4444,10 +4309,8 @@ libxlConnectListAllDomains(virConnectPtr conn,
     if (virConnectListAllDomainsEnsureACL(conn) < 0)
         return -1;
 
-    libxlDriverLock(driver);
     ret = virDomainObjListExport(driver->domains, conn, domains,
                                  virConnectListAllDomainsCheckACL, flags);
-    libxlDriverUnlock(driver);
 
     return ret;
 }
-- 
1.8.1.4

--
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]