[PATCH v3 12/15] bridge_driver: Drop networkDriverLock() from 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          | 71 ------------------------------------
 src/network/bridge_driver_platform.h |  2 -
 tests/objectlocking.ml               |  2 -
 3 files changed, 75 deletions(-)

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 5ef9910..c6957c3 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -88,16 +88,6 @@ VIR_LOG_INIT("network.bridge_driver");
 
 static virNetworkDriverStatePtr driver;
 
-
-static void networkDriverLock(void)
-{
-    virMutexLock(&driver->lock);
-}
-static void networkDriverUnlock(void)
-{
-    virMutexUnlock(&driver->lock);
-}
-
 static int networkStateCleanup(void);
 
 static int networkStartNetwork(virNetworkObjPtr network);
@@ -129,9 +119,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);
@@ -557,12 +545,6 @@ networkStateInitialize(bool privileged,
     if (VIR_ALLOC(driver) < 0)
         goto error;
 
-    if (virMutexInit(&driver->lock) < 0) {
-        VIR_FREE(driver);
-        goto error;
-    }
-    networkDriverLock();
-
     /* configuration/state paths are one of
      * ~/.config/libvirt/... (session/unprivileged)
      * /etc/libvirt/... && /var/(run|lib)/libvirt/... (system/privileged).
@@ -648,8 +630,6 @@ networkStateInitialize(bool privileged,
 
     driver->networkEventState = virObjectEventStateNew();
 
-    networkDriverUnlock();
-
 #ifdef HAVE_FIREWALLD
     if (!(sysbus = virDBusGetSystemBus())) {
         virErrorPtr err = virGetLastError();
@@ -683,8 +663,6 @@ networkStateInitialize(bool privileged,
     return ret;
 
  error:
-    if (driver)
-        networkDriverUnlock();
     networkStateCleanup();
     goto cleanup;
 }
@@ -700,11 +678,9 @@ networkStateAutoStart(void)
     if (!driver)
         return;
 
-    networkDriverLock();
     virNetworkObjListForEach(driver->networks,
                              networkAutostartConfig,
                              NULL);
-    networkDriverUnlock();
 }
 
 /**
@@ -719,7 +695,6 @@ networkStateReload(void)
     if (!driver)
         return 0;
 
-    networkDriverLock();
     virNetworkLoadAllState(driver->networks,
                            driver->stateDir);
     virNetworkLoadAllConfigs(driver->networks,
@@ -730,7 +705,6 @@ networkStateReload(void)
     virNetworkObjListForEach(driver->networks,
                              networkAutostartConfig,
                              NULL);
-    networkDriverUnlock();
     return 0;
 }
 
@@ -746,8 +720,6 @@ networkStateCleanup(void)
     if (!driver)
         return -1;
 
-    networkDriverLock();
-
     virObjectEventStateFree(driver->networkEventState);
 
     /* free inactive networks */
@@ -762,9 +734,6 @@ networkStateCleanup(void)
 
     virObjectUnref(driver->dnsmasqCaps);
 
-    networkDriverUnlock();
-    virMutexDestroy(&driver->lock);
-
     VIR_FREE(driver);
 
     return 0;
@@ -2478,9 +2447,7 @@ static virNetworkPtr networkLookupByUUID(virConnectPtr conn,
     virNetworkObjPtr network;
     virNetworkPtr ret = NULL;
 
-    networkDriverLock();
     network = virNetworkObjFindByUUID(driver->networks, uuid);
-    networkDriverUnlock();
     if (!network) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
         virUUIDFormat(uuid, uuidstr);
@@ -2506,9 +2473,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);
@@ -2532,12 +2497,10 @@ static int networkConnectNumOfNetworks(virConnectPtr conn)
     if (virConnectNumOfNetworksEnsureACL(conn) < 0)
         return -1;
 
-    networkDriverLock();
     nactive = virNetworkObjListNumOfNetworks(driver->networks,
                                              true,
                                              virConnectNumOfNetworksCheckACL,
                                              conn);
-    networkDriverUnlock();
 
     return nactive;
 }
@@ -2548,12 +2511,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;
 }
@@ -2565,12 +2526,10 @@ static int networkConnectNumOfDefinedNetworks(virConnectPtr conn)
     if (virConnectNumOfDefinedNetworksEnsureACL(conn) < 0)
         return -1;
 
-    networkDriverLock();
     ninactive = virNetworkObjListNumOfNetworks(driver->networks,
                                                false,
                                                virConnectNumOfDefinedNetworksCheckACL,
                                                conn);
-    networkDriverUnlock();
 
     return ninactive;
 }
@@ -2581,12 +2540,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;
 }
 
@@ -2602,11 +2559,9 @@ networkConnectListAllNetworks(virConnectPtr conn,
     if (virConnectListAllNetworksEnsureACL(conn) < 0)
         goto cleanup;
 
-    networkDriverLock();
     ret = virNetworkObjListExport(conn, driver->networks, nets,
                                   virConnectListAllNetworksCheckACL,
                                   flags);
-    networkDriverUnlock();
 
  cleanup:
     return ret;
@@ -2917,8 +2872,6 @@ static virNetworkPtr networkCreateXML(virConnectPtr conn, const char *xml)
     virNetworkPtr ret = NULL;
     virObjectEventPtr event = NULL;
 
-    networkDriverLock();
-
     if (!(def = virNetworkDefParseString(xml)))
         goto cleanup;
 
@@ -2955,7 +2908,6 @@ static virNetworkPtr networkCreateXML(virConnectPtr conn, const char *xml)
     if (event)
         virObjectEventStateQueue(driver->networkEventState, event);
     virNetworkObjEndAPI(&network);
-    networkDriverUnlock();
     return ret;
 }
 
@@ -2967,8 +2919,6 @@ static virNetworkPtr networkDefineXML(virConnectPtr conn, const char *xml)
     virNetworkPtr ret = NULL;
     virObjectEventPtr event = NULL;
 
-    networkDriverLock();
-
     if (!(def = virNetworkDefParseString(xml)))
         goto cleanup;
 
@@ -3010,7 +2960,6 @@ static virNetworkPtr networkDefineXML(virConnectPtr conn, const char *xml)
     if (freeDef)
         virNetworkDefFree(def);
     virNetworkObjEndAPI(&network);
-    networkDriverUnlock();
     return ret;
 }
 
@@ -3022,8 +2971,6 @@ networkUndefine(virNetworkPtr net)
     bool active = false;
     virObjectEventPtr event = NULL;
 
-    networkDriverLock();
-
     network = virNetworkObjFindByUUID(driver->networks, net->uuid);
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
@@ -3067,7 +3014,6 @@ networkUndefine(virNetworkPtr net)
     if (event)
         virObjectEventStateQueue(driver->networkEventState, event);
     virNetworkObjEndAPI(&network);
-    networkDriverUnlock();
     return ret;
 }
 
@@ -3091,8 +3037,6 @@ networkUpdate(virNetworkPtr net,
                   VIR_NETWORK_UPDATE_AFFECT_CONFIG,
                   -1);
 
-    networkDriverLock();
-
     network = virNetworkObjFindByUUID(driver->networks, net->uuid);
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
@@ -3238,7 +3182,6 @@ networkUpdate(virNetworkPtr net,
     ret = 0;
  cleanup:
     virNetworkObjEndAPI(&network);
-    networkDriverUnlock();
     return ret;
 }
 
@@ -3248,7 +3191,6 @@ static int networkCreate(virNetworkPtr net)
     int ret = -1;
     virObjectEventPtr event = NULL;
 
-    networkDriverLock();
     network = virNetworkObjFindByUUID(driver->networks, net->uuid);
 
     if (!network) {
@@ -3272,7 +3214,6 @@ static int networkCreate(virNetworkPtr net)
     if (event)
         virObjectEventStateQueue(driver->networkEventState, event);
     virNetworkObjEndAPI(&network);
-    networkDriverUnlock();
     return ret;
 }
 
@@ -3282,7 +3223,6 @@ static int networkDestroy(virNetworkPtr net)
     int ret = -1;
     virObjectEventPtr event = NULL;
 
-    networkDriverLock();
     network = virNetworkObjFindByUUID(driver->networks, net->uuid);
 
     if (!network) {
@@ -3319,7 +3259,6 @@ static int networkDestroy(virNetworkPtr net)
     if (event)
         virObjectEventStateQueue(driver->networkEventState, event);
     virNetworkObjEndAPI(&network);
-    networkDriverUnlock();
     return ret;
 }
 
@@ -3401,7 +3340,6 @@ static int networkSetAutostart(virNetworkPtr net,
     char *configFile = NULL, *autostartLink = NULL;
     int ret = -1;
 
-    networkDriverLock();
     network = virNetworkObjFindByUUID(driver->networks, net->uuid);
 
     if (!network) {
@@ -3458,7 +3396,6 @@ static int networkSetAutostart(virNetworkPtr net,
     VIR_FREE(configFile);
     VIR_FREE(autostartLink);
     virNetworkObjEndAPI(&network);
-    networkDriverUnlock();
     return ret;
 }
 
@@ -3729,9 +3666,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'"),
@@ -4137,9 +4072,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'"),
@@ -4336,9 +4269,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'"),
@@ -4494,9 +4425,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'"),
diff --git a/src/network/bridge_driver_platform.h b/src/network/bridge_driver_platform.h
index d9cf6a8..df1b7a8 100644
--- a/src/network/bridge_driver_platform.h
+++ b/src/network/bridge_driver_platform.h
@@ -32,8 +32,6 @@
 
 /* Main driver state */
 struct _virNetworkDriverState {
-    virMutex lock;
-
     /* Immutable pointer, self-locking APIs */
     virNetworkObjListPtr networks;
 
diff --git a/tests/objectlocking.ml b/tests/objectlocking.ml
index fd83d6d..4fdf95b 100644
--- a/tests/objectlocking.ml
+++ b/tests/objectlocking.ml
@@ -125,7 +125,6 @@ let driverLockMethods = [
     "lxcDriverLock";
     "umlDriverLock";
     "nodedevDriverLock";
-    "networkDriverLock";
     "storageDriverLock";
     "oneDriverLock"
 ]
@@ -140,7 +139,6 @@ let driverUnlockMethods = [
     "lxcDriverUnlock";
     "umlDriverUnlock";
     "nodedevDriverUnlock";
-    "networkDriverUnlock";
     "storageDriverUnlock";
     "oneDriverUnlock"
 ]
-- 
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]