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(a)redhat.com>
---
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_network.c | 7 +++---
src/test/test_driver.c | 13 ++++------
7 files changed, 57 insertions(+), 35 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 ea9a9d4..f843e3c 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 3fbd609..0c2609a 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 4ce5e3a..e2b558f 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -570,8 +570,8 @@ virNetworkObjGetPersistentDef;
virNetworkObjIsDuplicate;
virNetworkObjListExport;
virNetworkObjListForEach;
-virNetworkObjListFree;
virNetworkObjListGetNames;
+virNetworkObjListNew;
virNetworkObjListNumOfNetworks;
virNetworkObjListPrune;
virNetworkObjLock;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 1878833..9637371 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -620,7 +620,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,
@@ -751,8 +751,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_network.c b/src/parallels/parallels_network.c
index 6b53518..62ed268 100644
--- a/src/parallels/parallels_network.c
+++ b/src/parallels/parallels_network.c
@@ -329,7 +329,7 @@ parallelsNetworkOpen(virConnectPtr conn,
if (STRNEQ(conn->driver->name, "Parallels"))
return VIR_DRV_OPEN_DECLINED;
- if (VIR_ALLOC(privconn->networks) < 0)
+ if (!(privconn->networks = virNetworkObjListNew()))
goto error;
if (parallelsLoadNetworks(conn->privateData) < 0)
@@ -337,7 +337,7 @@ parallelsNetworkOpen(virConnectPtr conn,
return VIR_DRV_OPEN_SUCCESS;
error:
- VIR_FREE(privconn->networks);
+ virObjectUnref(privconn->networks);
return VIR_DRV_OPEN_DECLINED;
}
@@ -349,8 +349,7 @@ int parallelsNetworkClose(virConnectPtr conn)
return 0;
parallelsDriverLock(privconn);
- virNetworkObjListFree(privconn->networks);
- VIR_FREE(privconn->networks);
+ virObjectUnref(privconn->networks);
parallelsDriverUnlock(privconn);
return 0;
}
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 2bfe0ad..693b930 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