[PATCH v1 10/31] bridge_driver: s/virNetworkObjList/virNetworkObjListPtr/

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

 



In order to hide the object internals (and use just accessors
everywhere), lets store a pointer to the object, instead of object
itself.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/network/bridge_driver.c          | 98 +++++++++++++++++++-----------------
 src/network/bridge_driver_platform.h |  2 +-
 2 files changed, 52 insertions(+), 48 deletions(-)

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index edc4ed4..1011984 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -130,7 +130,7 @@ networkObjFromNetwork(virNetworkPtr net)
     char uuidstr[VIR_UUID_STRING_BUFLEN];
 
     networkDriverLock();
-    network = virNetworkFindByUUID(&driver->networks, net->uuid);
+    network = virNetworkFindByUUID(driver->networks, net->uuid);
     networkDriverUnlock();
 
     if (!network) {
@@ -303,7 +303,7 @@ networkRemoveInactive(virNetworkObjPtr net)
     unlink(statusfile);
 
     /* remove the network definition */
-    virNetworkRemoveInactive(&driver->networks, net);
+    virNetworkRemoveInactive(driver->networks, net);
 
     ret = 0;
 
@@ -350,8 +350,8 @@ networkUpdateAllState(void)
 {
     size_t i;
 
-    for (i = 0; i < driver->networks.count; i++) {
-        virNetworkObjPtr obj = driver->networks.objs[i];
+    for (i = 0; i < driver->networks->count; i++) {
+        virNetworkObjPtr obj = driver->networks->objs[i];
 
         virNetworkObjLock(obj);
         if (!virNetworkObjIsActive(obj)) {
@@ -411,8 +411,8 @@ networkUpdateAllState(void)
 
     /* remove inactive transient networks */
     i = 0;
-    while (i < driver->networks.count) {
-        virNetworkObjPtr obj = driver->networks.objs[i];
+    while (i < driver->networks->count) {
+        virNetworkObjPtr obj = driver->networks->objs[i];
         virNetworkObjLock(obj);
 
         if (!obj->persistent && !obj->active) {
@@ -431,15 +431,15 @@ networkAutostartConfigs(void)
 {
     size_t i;
 
-    for (i = 0; i < driver->networks.count; i++) {
-        virNetworkObjLock(driver->networks.objs[i]);
-        if (driver->networks.objs[i]->autostart &&
-            !virNetworkObjIsActive(driver->networks.objs[i])) {
-            if (networkStartNetwork(driver->networks.objs[i]) < 0) {
+    for (i = 0; i < driver->networks->count; i++) {
+        virNetworkObjLock(driver->networks->objs[i]);
+        if (driver->networks->objs[i]->autostart &&
+            !virNetworkObjIsActive(driver->networks->objs[i])) {
+            if (networkStartNetwork(driver->networks->objs[i]) < 0) {
                 /* failed to start but already logged */
             }
         }
-        virNetworkObjUnlock(driver->networks.objs[i]);
+        virNetworkObjUnlock(driver->networks->objs[i]);
     }
 }
 
@@ -638,11 +638,14 @@ networkStateInitialize(bool privileged,
     /* if this fails now, it will be retried later with dnsmasqCapsRefresh() */
     driver->dnsmasqCaps = dnsmasqCapsNewFromBinary(DNSMASQ);
 
-    if (virNetworkLoadAllState(&driver->networks,
+    if (VIR_ALLOC(driver->networks) < 0)
+        goto error;
+
+    if (virNetworkLoadAllState(driver->networks,
                                driver->stateDir) < 0)
         goto error;
 
-    if (virNetworkLoadAllConfigs(&driver->networks,
+    if (virNetworkLoadAllConfigs(driver->networks,
                                  driver->networkConfigDir,
                                  driver->networkAutostartDir) < 0)
         goto error;
@@ -723,9 +726,9 @@ networkStateReload(void)
         return 0;
 
     networkDriverLock();
-    virNetworkLoadAllState(&driver->networks,
+    virNetworkLoadAllState(driver->networks,
                            driver->stateDir);
-    virNetworkLoadAllConfigs(&driver->networks,
+    virNetworkLoadAllConfigs(driver->networks,
                              driver->networkConfigDir,
                              driver->networkAutostartDir);
     networkReloadFirewallRules();
@@ -752,7 +755,8 @@ networkStateCleanup(void)
     virObjectEventStateFree(driver->networkEventState);
 
     /* free inactive networks */
-    virNetworkObjListFree(&driver->networks);
+    virNetworkObjListFree(driver->networks);
+    VIR_FREE(driver->networks);
 
     VIR_FREE(driver->networkConfigDir);
     VIR_FREE(driver->networkAutostartDir);
@@ -1751,8 +1755,8 @@ networkRefreshDaemons(void)
 
     VIR_INFO("Refreshing network daemons");
 
-    for (i = 0; i < driver->networks.count; i++) {
-        virNetworkObjPtr network = driver->networks.objs[i];
+    for (i = 0; i < driver->networks->count; i++) {
+        virNetworkObjPtr network = driver->networks->objs[i];
 
         virNetworkObjLock(network);
         if (virNetworkObjIsActive(network) &&
@@ -1779,8 +1783,8 @@ networkReloadFirewallRules(void)
 
     VIR_INFO("Reloading iptables rules");
 
-    for (i = 0; i < driver->networks.count; i++) {
-        virNetworkObjPtr network = driver->networks.objs[i];
+    for (i = 0; i < driver->networks->count; i++) {
+        virNetworkObjPtr network = driver->networks->objs[i];
 
         virNetworkObjLock(network);
         if (virNetworkObjIsActive(network) &&
@@ -2472,7 +2476,7 @@ static virNetworkPtr networkLookupByUUID(virConnectPtr conn,
     virNetworkPtr ret = NULL;
 
     networkDriverLock();
-    network = virNetworkFindByUUID(&driver->networks, uuid);
+    network = virNetworkFindByUUID(driver->networks, uuid);
     networkDriverUnlock();
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
@@ -2499,7 +2503,7 @@ static virNetworkPtr networkLookupByName(virConnectPtr conn,
     virNetworkPtr ret = NULL;
 
     networkDriverLock();
-    network = virNetworkFindByName(&driver->networks, name);
+    network = virNetworkFindByName(driver->networks, name);
     networkDriverUnlock();
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
@@ -2527,8 +2531,8 @@ static int networkConnectNumOfNetworks(virConnectPtr conn)
         return -1;
 
     networkDriverLock();
-    for (i = 0; i < driver->networks.count; i++) {
-        virNetworkObjPtr obj = driver->networks.objs[i];
+    for (i = 0; i < driver->networks->count; i++) {
+        virNetworkObjPtr obj = driver->networks->objs[i];
         virNetworkObjLock(obj);
         if (virConnectNumOfNetworksCheckACL(conn, obj->def) &&
             virNetworkObjIsActive(obj))
@@ -2548,8 +2552,8 @@ static int networkConnectListNetworks(virConnectPtr conn, char **const names, in
         return -1;
 
     networkDriverLock();
-    for (i = 0; i < driver->networks.count && got < nnames; i++) {
-        virNetworkObjPtr obj = driver->networks.objs[i];
+    for (i = 0; i < driver->networks->count && got < nnames; i++) {
+        virNetworkObjPtr obj = driver->networks->objs[i];
         virNetworkObjLock(obj);
         if (virConnectListNetworksCheckACL(conn, obj->def) &&
             virNetworkObjIsActive(obj)) {
@@ -2581,8 +2585,8 @@ static int networkConnectNumOfDefinedNetworks(virConnectPtr conn)
         return -1;
 
     networkDriverLock();
-    for (i = 0; i < driver->networks.count; i++) {
-        virNetworkObjPtr obj = driver->networks.objs[i];
+    for (i = 0; i < driver->networks->count; i++) {
+        virNetworkObjPtr obj = driver->networks->objs[i];
         virNetworkObjLock(obj);
         if (virConnectNumOfDefinedNetworksCheckACL(conn, obj->def) &&
             !virNetworkObjIsActive(obj))
@@ -2602,8 +2606,8 @@ static int networkConnectListDefinedNetworks(virConnectPtr conn, char **const na
         return -1;
 
     networkDriverLock();
-    for (i = 0; i < driver->networks.count && got < nnames; i++) {
-        virNetworkObjPtr obj = driver->networks.objs[i];
+    for (i = 0; i < driver->networks->count && got < nnames; i++) {
+        virNetworkObjPtr obj = driver->networks->objs[i];
         virNetworkObjLock(obj);
         if (virConnectListDefinedNetworksCheckACL(conn, obj->def) &&
             !virNetworkObjIsActive(obj)) {
@@ -2638,7 +2642,7 @@ networkConnectListAllNetworks(virConnectPtr conn,
         goto cleanup;
 
     networkDriverLock();
-    ret = virNetworkObjListExport(conn, &driver->networks, nets,
+    ret = virNetworkObjListExport(conn, driver->networks, nets,
                                   virConnectListAllNetworksCheckACL,
                                   flags);
     networkDriverUnlock();
@@ -2741,7 +2745,7 @@ networkValidate(virNetworkDefPtr def,
     bool usesInterface = false, usesAddress = false;
 
     /* check for duplicate networks */
-    if (virNetworkObjIsDuplicate(&driver->networks, def, check_active) < 0)
+    if (virNetworkObjIsDuplicate(driver->networks, def, check_active) < 0)
         return -1;
 
     /* Only the three L3 network types that are configured by libvirt
@@ -2751,7 +2755,7 @@ networkValidate(virNetworkDefPtr def,
         def->forward.type == VIR_NETWORK_FORWARD_NAT ||
         def->forward.type == VIR_NETWORK_FORWARD_ROUTE) {
 
-        if (virNetworkSetBridgeName(&driver->networks, def, 1))
+        if (virNetworkSetBridgeName(driver->networks, def, 1))
             return -1;
 
         virNetworkSetBridgeMacAddr(def);
@@ -2969,12 +2973,12 @@ static virNetworkPtr networkCreateXML(virConnectPtr conn, const char *xml)
      * we assign the def with live = true in anticipation that it will
      * be started momentarily.
      */
-    if (!(network = virNetworkAssignDef(&driver->networks, def, true)))
+    if (!(network = virNetworkAssignDef(driver->networks, def, true)))
         goto cleanup;
     def = NULL;
 
     if (networkStartNetwork(network) < 0) {
-        virNetworkRemoveInactive(&driver->networks,
+        virNetworkRemoveInactive(driver->networks,
                                  network);
         network = NULL;
         goto cleanup;
@@ -3017,7 +3021,7 @@ static virNetworkPtr networkDefineXML(virConnectPtr conn, const char *xml)
     if (networkValidate(def, false) < 0)
         goto cleanup;
 
-    if (!(network = virNetworkAssignDef(&driver->networks, def, false)))
+    if (!(network = virNetworkAssignDef(driver->networks, def, false)))
         goto cleanup;
 
     /* def was assigned to network object */
@@ -3025,7 +3029,7 @@ static virNetworkPtr networkDefineXML(virConnectPtr conn, const char *xml)
 
     if (virNetworkSaveConfig(driver->networkConfigDir, def) < 0) {
         if (!virNetworkObjIsActive(network)) {
-            virNetworkRemoveInactive(&driver->networks, network);
+            virNetworkRemoveInactive(driver->networks, network);
             network = NULL;
             goto cleanup;
         }
@@ -3065,7 +3069,7 @@ networkUndefine(virNetworkPtr net)
 
     networkDriverLock();
 
-    network = virNetworkFindByUUID(&driver->networks, net->uuid);
+    network = virNetworkFindByUUID(driver->networks, net->uuid);
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
                        "%s", _("no network with matching uuid"));
@@ -3138,7 +3142,7 @@ networkUpdate(virNetworkPtr net,
 
     networkDriverLock();
 
-    network = virNetworkFindByUUID(&driver->networks, net->uuid);
+    network = virNetworkFindByUUID(driver->networks, net->uuid);
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
                        "%s", _("no network with matching uuid"));
@@ -3295,7 +3299,7 @@ static int networkCreate(virNetworkPtr net)
     virObjectEventPtr event = NULL;
 
     networkDriverLock();
-    network = virNetworkFindByUUID(&driver->networks, net->uuid);
+    network = virNetworkFindByUUID(driver->networks, net->uuid);
 
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
@@ -3330,7 +3334,7 @@ static int networkDestroy(virNetworkPtr net)
     virObjectEventPtr event = NULL;
 
     networkDriverLock();
-    network = virNetworkFindByUUID(&driver->networks, net->uuid);
+    network = virNetworkFindByUUID(driver->networks, net->uuid);
 
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
@@ -3456,7 +3460,7 @@ static int networkSetAutostart(virNetworkPtr net,
     int ret = -1;
 
     networkDriverLock();
-    network = virNetworkFindByUUID(&driver->networks, net->uuid);
+    network = virNetworkFindByUUID(driver->networks, net->uuid);
 
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
@@ -3786,7 +3790,7 @@ networkAllocateActualDevice(virDomainDefPtr dom,
     iface->data.network.actual = NULL;
 
     networkDriverLock();
-    network = virNetworkFindByName(&driver->networks, iface->data.network.name);
+    network = virNetworkFindByName(driver->networks, iface->data.network.name);
     networkDriverUnlock();
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
@@ -4195,7 +4199,7 @@ networkNotifyActualDevice(virDomainDefPtr dom,
         return 0;
 
     networkDriverLock();
-    network = virNetworkFindByName(&driver->networks, iface->data.network.name);
+    network = virNetworkFindByName(driver->networks, iface->data.network.name);
     networkDriverUnlock();
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
@@ -4395,7 +4399,7 @@ networkReleaseActualDevice(virDomainDefPtr dom,
         return 0;
 
     networkDriverLock();
-    network = virNetworkFindByName(&driver->networks, iface->data.network.name);
+    network = virNetworkFindByName(driver->networks, iface->data.network.name);
     networkDriverUnlock();
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
@@ -4554,7 +4558,7 @@ networkGetNetworkAddress(const char *netname, char **netaddr)
 
     *netaddr = NULL;
     networkDriverLock();
-    network = virNetworkFindByName(&driver->networks, netname);
+    network = virNetworkFindByName(driver->networks, netname);
     networkDriverUnlock();
     if (!network) {
         virReportError(VIR_ERR_NO_NETWORK,
diff --git a/src/network/bridge_driver_platform.h b/src/network/bridge_driver_platform.h
index 1e8264a..b7492e6 100644
--- a/src/network/bridge_driver_platform.h
+++ b/src/network/bridge_driver_platform.h
@@ -34,7 +34,7 @@
 struct _virNetworkDriverState {
     virMutex lock;
 
-    virNetworkObjList networks;
+    virNetworkObjListPtr networks;
 
     char *networkConfigDir;
     char *networkAutostartDir;
-- 
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]