[PATCH v1 29/31] bridge_driver: Drop networkDriverLock() from almost everywhere

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

 



Now that we have fine grained locks, there's no need to lock the
whole driver. We can rely on self-locking APIs.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/network/bridge_driver.c | 45 +++------------------------------------------
 1 file changed, 3 insertions(+), 42 deletions(-)

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index c2a992a..56debb3 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -129,9 +129,7 @@ networkObjFromNetwork(virNetworkPtr net)
     virNetworkObjPtr network;
     char uuidstr[VIR_UUID_STRING_BUFLEN];
 
-    networkDriverLock();
     network = virNetworkObjFindByUUID(driver->networks, net->uuid);
-    networkDriverUnlock();
 
     if (!network) {
         virUUIDFormat(net->uuid, uuidstr);
@@ -264,6 +262,8 @@ networkRemoveInactive(virNetworkObjPtr net)
 
     int ret = -1;
 
+    networkDriverLock();
+
     /* remove the (possibly) existing dnsmasq and radvd files */
     if (!(dctx = dnsmasqContextNew(def->name,
                                    driver->dnsmasqStateDir))) {
@@ -315,6 +315,7 @@ networkRemoveInactive(virNetworkObjPtr net)
     VIR_FREE(radvdpidbase);
     VIR_FREE(statusfile);
     dnsmasqContextFree(dctx);
+    networkDriverUnlock();
     return ret;
 }
 
@@ -701,11 +702,9 @@ networkStateAutoStart(void)
     if (!driver)
         return;
 
-    networkDriverLock();
     virNetworkObjListForEach(driver->networks,
                              networkAutostartConfigs,
                              NULL);
-    networkDriverUnlock();
 }
 
 /**
@@ -2479,9 +2478,7 @@ static virNetworkPtr networkLookupByUUID(virConnectPtr conn,
     virNetworkObjPtr network;
     virNetworkPtr ret = NULL;
 
-    networkDriverLock();
     network = virNetworkObjFindByUUID(driver->networks, uuid);
-    networkDriverUnlock();
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
                        _("no network with matching uuid '%s'"),
@@ -2505,9 +2502,7 @@ static virNetworkPtr networkLookupByName(virConnectPtr conn,
     virNetworkObjPtr network;
     virNetworkPtr ret = NULL;
 
-    networkDriverLock();
     network = virNetworkObjFindByName(driver->networks, name);
-    networkDriverUnlock();
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
                        _("no network with matching name '%s'"), name);
@@ -2531,12 +2526,10 @@ static int networkConnectNumOfNetworks(virConnectPtr conn)
     if (virConnectNumOfNetworksEnsureACL(conn) < 0)
         return -1;
 
-    networkDriverLock();
     nactive = virNetworkObjListNumOfNetworks(driver->networks,
                                              true,
                                              virConnectNumOfNetworksCheckACL,
                                              conn);
-    networkDriverUnlock();
 
     return nactive;
 }
@@ -2547,12 +2540,10 @@ static int networkConnectListNetworks(virConnectPtr conn, char **const names, in
     if (virConnectListNetworksEnsureACL(conn) < 0)
         return -1;
 
-    networkDriverLock();
     got = virNetworkObjListGetNames(driver->networks,
                                     true, names, nnames,
                                     virConnectListNetworksCheckACL,
                                     conn);
-    networkDriverUnlock();
 
     return got;
 }
@@ -2564,12 +2555,10 @@ static int networkConnectNumOfDefinedNetworks(virConnectPtr conn)
     if (virConnectNumOfDefinedNetworksEnsureACL(conn) < 0)
         return -1;
 
-    networkDriverLock();
     ninactive = virNetworkObjListNumOfNetworks(driver->networks,
                                                false,
                                                virConnectNumOfDefinedNetworksCheckACL,
                                                conn);
-    networkDriverUnlock();
 
     return ninactive;
 }
@@ -2580,12 +2569,10 @@ static int networkConnectListDefinedNetworks(virConnectPtr conn, char **const na
     if (virConnectListDefinedNetworksEnsureACL(conn) < 0)
         return -1;
 
-    networkDriverLock();
     got = virNetworkObjListGetNames(driver->networks,
                                     false, names, nnames,
                                     virConnectListDefinedNetworksCheckACL,
                                     conn);
-    networkDriverUnlock();
     return got;
 }
 
@@ -2601,11 +2588,9 @@ networkConnectListAllNetworks(virConnectPtr conn,
     if (virConnectListAllNetworksEnsureACL(conn) < 0)
         goto cleanup;
 
-    networkDriverLock();
     ret = virNetworkObjListExport(conn, driver->networks, nets,
                                   virConnectListAllNetworksCheckACL,
                                   flags);
-    networkDriverUnlock();
 
  cleanup:
     return ret;
@@ -2916,8 +2901,6 @@ static virNetworkPtr networkCreateXML(virConnectPtr conn, const char *xml)
     virNetworkPtr ret = NULL;
     virObjectEventPtr event = NULL;
 
-    networkDriverLock();
-
     if (!(def = virNetworkDefParseString(xml)))
         goto cleanup;
 
@@ -2955,7 +2938,6 @@ static virNetworkPtr networkCreateXML(virConnectPtr conn, const char *xml)
     if (event)
         virObjectEventStateQueue(driver->networkEventState, event);
     virNetworkObjEndAPI(&network);
-    networkDriverUnlock();
     return ret;
 }
 
@@ -2967,8 +2949,6 @@ static virNetworkPtr networkDefineXML(virConnectPtr conn, const char *xml)
     virNetworkPtr ret = NULL;
     virObjectEventPtr event = NULL;
 
-    networkDriverLock();
-
     if (!(def = virNetworkDefParseString(xml)))
         goto cleanup;
 
@@ -3011,7 +2991,6 @@ static virNetworkPtr networkDefineXML(virConnectPtr conn, const char *xml)
     if (freeDef)
         virNetworkDefFree(def);
     virNetworkObjEndAPI(&network);
-    networkDriverUnlock();
     return ret;
 }
 
@@ -3023,8 +3002,6 @@ networkUndefine(virNetworkPtr net)
     bool active = false;
     virObjectEventPtr event = NULL;
 
-    networkDriverLock();
-
     network = virNetworkObjFindByUUID(driver->networks, net->uuid);
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
@@ -3071,7 +3048,6 @@ networkUndefine(virNetworkPtr net)
     if (event)
         virObjectEventStateQueue(driver->networkEventState, event);
     virNetworkObjEndAPI(&network);
-    networkDriverUnlock();
     return ret;
 }
 
@@ -3095,8 +3071,6 @@ networkUpdate(virNetworkPtr net,
                   VIR_NETWORK_UPDATE_AFFECT_CONFIG,
                   -1);
 
-    networkDriverLock();
-
     network = virNetworkObjFindByUUID(driver->networks, net->uuid);
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
@@ -3242,7 +3216,6 @@ networkUpdate(virNetworkPtr net,
     ret = 0;
  cleanup:
     virNetworkObjEndAPI(&network);
-    networkDriverUnlock();
     return ret;
 }
 
@@ -3252,7 +3225,6 @@ static int networkCreate(virNetworkPtr net)
     int ret = -1;
     virObjectEventPtr event = NULL;
 
-    networkDriverLock();
     network = virNetworkObjFindByUUID(driver->networks, net->uuid);
 
     if (!network) {
@@ -3276,7 +3248,6 @@ static int networkCreate(virNetworkPtr net)
     if (event)
         virObjectEventStateQueue(driver->networkEventState, event);
     virNetworkObjEndAPI(&network);
-    networkDriverUnlock();
     return ret;
 }
 
@@ -3286,7 +3257,6 @@ static int networkDestroy(virNetworkPtr net)
     int ret = -1;
     virObjectEventPtr event = NULL;
 
-    networkDriverLock();
     network = virNetworkObjFindByUUID(driver->networks, net->uuid);
 
     if (!network) {
@@ -3326,7 +3296,6 @@ static int networkDestroy(virNetworkPtr net)
     if (event)
         virObjectEventStateQueue(driver->networkEventState, event);
     virNetworkObjEndAPI(&network);
-    networkDriverUnlock();
     return ret;
 }
 
@@ -3736,9 +3705,7 @@ networkAllocateActualDevice(virDomainDefPtr dom,
     virDomainActualNetDefFree(iface->data.network.actual);
     iface->data.network.actual = NULL;
 
-    networkDriverLock();
     network = virNetworkObjFindByName(driver->networks, iface->data.network.name);
-    networkDriverUnlock();
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
                        _("no network with matching name '%s'"),
@@ -4144,9 +4111,7 @@ networkNotifyActualDevice(virDomainDefPtr dom,
     if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK)
         return 0;
 
-    networkDriverLock();
     network = virNetworkObjFindByName(driver->networks, iface->data.network.name);
-    networkDriverUnlock();
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
                        _("no network with matching name '%s'"),
@@ -4343,9 +4308,7 @@ networkReleaseActualDevice(virDomainDefPtr dom,
     if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK)
         return 0;
 
-    networkDriverLock();
     network = virNetworkObjFindByName(driver->networks, iface->data.network.name);
-    networkDriverUnlock();
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
                        _("no network with matching name '%s'"),
@@ -4501,9 +4464,7 @@ networkGetNetworkAddress(const char *netname, char **netaddr)
     char *dev_name = NULL;
 
     *netaddr = NULL;
-    networkDriverLock();
     network = virNetworkObjFindByName(driver->networks, netname);
-    networkDriverUnlock();
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
                        _("no network with matching name '%s'"),
-- 
2.0.5

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