[PATCH v1 19/31] network_conf: Turn virNetworkObjList into virObject

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

 



Well, one day this will be self-locking object, but not today.
But lets prepare the code for that! Moreover,
virNetworkObjListFree() is no longer needed, so turn it into
virNetworkObjListDispose().

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 cfg.mk                            |  1 -
 src/conf/network_conf.c           | 53 +++++++++++++++++++++++++++++----------
 src/conf/network_conf.h           | 11 ++++----
 src/libvirt_private.syms          |  2 +-
 src/network/bridge_driver.c       |  5 ++--
 src/parallels/parallels_driver.c  |  2 +-
 src/parallels/parallels_network.c |  2 +-
 src/test/test_driver.c            | 13 ++++------
 8 files changed, 56 insertions(+), 33 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index d72b039..07a794a 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -250,7 +250,6 @@ useless_free_options =				\
 # n virNetworkFree (returns int)
 # n virNetworkFreeName (returns int)
 # y virNetworkObjFree
-# n virNetworkObjListFree FIXME
 # n virNodeDevCapsDefFree FIXME
 # y virNodeDeviceDefFree
 # n virNodeDeviceFree (returns int)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 24a5f7c..4efad43 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -73,17 +73,33 @@ VIR_ENUM_IMPL(virNetworkForwardDriverName,
 VIR_ENUM_IMPL(virNetworkTaint, VIR_NETWORK_TAINT_LAST,
               "hook-script");
 
-bool
-virNetworkObjTaint(virNetworkObjPtr obj,
-                   virNetworkTaintFlags taint)
+static virClassPtr virNetworkObjListClass;
+static void virNetworkObjListDispose(void *obj);
+
+static int virNetworkObjOnceInit(void)
+{
+    if (!(virNetworkObjListClass = virClassNew(virClassForObject(),
+                                               "virNetworkObjList",
+                                               sizeof(virNetworkObjList),
+                                               virNetworkObjListDispose)))
+        return -1;
+    return 0;
+}
+
+
+VIR_ONCE_GLOBAL_INIT(virNetworkObj)
+
+virNetworkObjListPtr virNetworkObjListNew(void)
 {
-    unsigned int flag = (1 << taint);
+    virNetworkObjListPtr nets;
+
+    if (virNetworkObjInitialize() < 0)
+        return NULL;
 
-    if (obj->taint & flag)
-        return false;
+    if (!(nets = virObjectNew(virNetworkObjListClass)))
+        return NULL;
 
-    obj->taint |= flag;
-    return true;
+    return nets;
 }
 
 virNetworkObjPtr virNetworkObjFindByUUID(virNetworkObjListPtr nets,
@@ -116,6 +132,19 @@ virNetworkObjPtr virNetworkObjFindByName(virNetworkObjListPtr nets,
     return NULL;
 }
 
+bool
+virNetworkObjTaint(virNetworkObjPtr obj,
+                   virNetworkTaintFlags taint)
+{
+    unsigned int flag = (1 << taint);
+
+    if (obj->taint & flag)
+        return false;
+
+    obj->taint |= flag;
+    return true;
+}
+
 
 static void
 virPortGroupDefClear(virPortGroupDefPtr def)
@@ -275,18 +304,16 @@ void virNetworkObjFree(virNetworkObjPtr net)
     VIR_FREE(net);
 }
 
-void virNetworkObjListFree(virNetworkObjListPtr nets)
+static void
+virNetworkObjListDispose(void *obj)
 {
+    virNetworkObjListPtr nets = obj;
     size_t i;
 
-    if (!nets)
-        return;
-
     for (i = 0; i < nets->count; i++)
         virNetworkObjFree(nets->objs[i]);
 
     VIR_FREE(nets->objs);
-    nets->count = 0;
 }
 
 /*
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 164fb1a..5725258 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -40,6 +40,7 @@
 # include "device_conf.h"
 # include "virbitmap.h"
 # include "networkcommon_conf.h"
+# include "virobject.h"
 
 typedef enum {
     VIR_NETWORK_FORWARD_NONE   = 0,
@@ -277,6 +278,8 @@ struct _virNetworkObj {
 typedef struct _virNetworkObjList virNetworkObjList;
 typedef virNetworkObjList *virNetworkObjListPtr;
 struct _virNetworkObjList {
+    virObject parent;
+
     size_t count;
     virNetworkObjPtr *objs;
 };
@@ -298,19 +301,17 @@ virNetworkObjIsActive(const virNetworkObj *net)
     return net->active;
 }
 
-bool virNetworkObjTaint(virNetworkObjPtr obj,
-                        virNetworkTaintFlags taint);
+virNetworkObjListPtr virNetworkObjListNew(void);
 
 virNetworkObjPtr virNetworkObjFindByUUID(virNetworkObjListPtr nets,
                                          const unsigned char *uuid);
 virNetworkObjPtr virNetworkObjFindByName(virNetworkObjListPtr nets,
                                          const char *name);
-
+bool virNetworkObjTaint(virNetworkObjPtr obj,
+                        virNetworkTaintFlags taint);
 
 void virNetworkDefFree(virNetworkDefPtr def);
 void virNetworkObjFree(virNetworkObjPtr net);
-void virNetworkObjListFree(virNetworkObjListPtr nets);
-
 
 typedef bool (*virNetworkObjListFilter)(virConnectPtr conn,
                                         virNetworkDefPtr def);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8aacc30..a9ce2cd 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -571,8 +571,8 @@ virNetworkObjGetPersistentDef;
 virNetworkObjIsDuplicate;
 virNetworkObjListExport;
 virNetworkObjListForEach;
-virNetworkObjListFree;
 virNetworkObjListGetNames;
+virNetworkObjListNew;
 virNetworkObjListNumOfNetworks;
 virNetworkObjLock;
 virNetworkObjReplacePersistentDef;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 1c73342..0bde89d 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -624,7 +624,7 @@ networkStateInitialize(bool privileged,
     /* if this fails now, it will be retried later with dnsmasqCapsRefresh() */
     driver->dnsmasqCaps = dnsmasqCapsNewFromBinary(DNSMASQ);
 
-    if (VIR_ALLOC(driver->networks) < 0)
+    if (!(driver->networks = virNetworkObjListNew()))
         goto error;
 
     if (virNetworkLoadAllState(driver->networks,
@@ -752,8 +752,7 @@ networkStateCleanup(void)
     virObjectEventStateFree(driver->networkEventState);
 
     /* free inactive networks */
-    virNetworkObjListFree(driver->networks);
-    VIR_FREE(driver->networks);
+    virObjectUnref(driver->networks);
 
     VIR_FREE(driver->networkConfigDir);
     VIR_FREE(driver->networkAutostartDir);
diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index 32f2ede..d8bcb4b 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -208,7 +208,7 @@ parallelsOpenDefault(virConnectPtr conn)
         goto error;
 
     if (!(privconn->domains = virDomainObjListNew()) ||
-        VIR_ALLOC(privconn->networks) < 0)
+        !(privconn->networks = virNetworkObjListNew()))
         goto error;
 
     if (!(privconn->domainEventState = virObjectEventStateNew()))
diff --git a/src/parallels/parallels_network.c b/src/parallels/parallels_network.c
index 868e3f5..e626ff6 100644
--- a/src/parallels/parallels_network.c
+++ b/src/parallels/parallels_network.c
@@ -337,7 +337,7 @@ int parallelsNetworkClose(virConnectPtr conn)
 {
     parallelsConnPtr privconn = conn->privateData;
     parallelsDriverLock(privconn);
-    virNetworkObjListFree(privconn->networks);
+    virObjectUnref(privconn->networks);
     parallelsDriverUnlock(privconn);
     return 0;
 }
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 0a68283..4b3aa24 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -725,7 +725,7 @@ testOpenDefault(virConnectPtr conn)
         goto error;
 
     if (!(privconn->domains = virDomainObjListNew()) ||
-        VIR_ALLOC(privconn->networks) < 0)
+        !(privconn->networks = virNetworkObjListNew()))
         goto error;
 
     memmove(&privconn->nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo));
@@ -830,8 +830,7 @@ testOpenDefault(virConnectPtr conn)
 
  error:
     virObjectUnref(privconn->domains);
-    virNetworkObjListFree(privconn->networks);
-    VIR_FREE(privconn->networks);
+    virObjectUnref(privconn->networks);
     virInterfaceObjListFree(&privconn->ifaces);
     virStoragePoolObjListFree(&privconn->pools);
     virNodeDeviceObjListFree(&privconn->devs);
@@ -1414,7 +1413,7 @@ testOpenFromFile(virConnectPtr conn, const char *file)
     conn->privateData = privconn;
 
     if (!(privconn->domains = virDomainObjListNew()) ||
-        VIR_ALLOC(privconn->networks) < 0)
+        !(privconn->networks = virNetworkObjListNew()))
         goto error;
 
     if (!(privconn->caps = testBuildCapabilities(conn)))
@@ -1466,8 +1465,7 @@ testOpenFromFile(virConnectPtr conn, const char *file)
     xmlXPathFreeContext(ctxt);
     xmlFreeDoc(doc);
     virObjectUnref(privconn->domains);
-    virNetworkObjListFree(privconn->networks);
-    VIR_FREE(privconn->networks);
+    virObjectUnref(privconn->networks);
     virInterfaceObjListFree(&privconn->ifaces);
     virStoragePoolObjListFree(&privconn->pools);
     VIR_FREE(privconn->path);
@@ -1593,8 +1591,7 @@ static int testConnectClose(virConnectPtr conn)
     virObjectUnref(privconn->xmlopt);
     virObjectUnref(privconn->domains);
     virNodeDeviceObjListFree(&privconn->devs);
-    virNetworkObjListFree(privconn->networks);
-    VIR_FREE(privconn->networks);
+    virObjectUnref(privconn->networks);
     virInterfaceObjListFree(&privconn->ifaces);
     virStoragePoolObjListFree(&privconn->pools);
     virObjectEventStateFree(privconn->eventState);
-- 
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]