network_conf: Turn virNetworkObjList into virObject

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@redhat.com>
This commit is contained in:
Michal Privoznik 2015-02-24 13:45:45 +01:00
parent 58092dfe87
commit 88aed14f12
7 changed files with 57 additions and 35 deletions

1
cfg.mk
View File

@ -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)

View File

@ -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)
{
unsigned int flag = (1 << taint);
if (!(virNetworkObjListClass = virClassNew(virClassForObject(),
"virNetworkObjList",
sizeof(virNetworkObjList),
virNetworkObjListDispose)))
return -1;
return 0;
}
if (obj->taint & flag)
return false;
obj->taint |= flag;
return true;
VIR_ONCE_GLOBAL_INIT(virNetworkObj)
virNetworkObjListPtr virNetworkObjListNew(void)
{
virNetworkObjListPtr nets;
if (virNetworkObjInitialize() < 0)
return NULL;
if (!(nets = virObjectNew(virNetworkObjListClass)))
return NULL;
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;
}
/*

View File

@ -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);

View File

@ -570,8 +570,8 @@ virNetworkObjGetPersistentDef;
virNetworkObjIsDuplicate;
virNetworkObjListExport;
virNetworkObjListForEach;
virNetworkObjListFree;
virNetworkObjListGetNames;
virNetworkObjListNew;
virNetworkObjListNumOfNetworks;
virNetworkObjListPrune;
virNetworkObjLock;

View File

@ -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);

View File

@ -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;
}

View File

@ -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);