Use the virPoolObj[Table] object management model in order to manage the
Interface objects.
While making the adjustments to use the new model, there are some code
formatting adjustments that were also made with the goal to follow more
recent code flow and layout.
All interface object management API's have their own virinterfaceobj
entry points now instead of being mashed in with interface_conf
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/Makefile.am | 3 +-
src/conf/interface_conf.c | 170 +---------------
src/conf/interface_conf.h | 46 +----
src/conf/virinterfaceobj.c | 205 +++++++++++++++++++
src/conf/virinterfaceobj.h | 46 +++++
src/interface/interface_backend_netcf.c | 6 +-
src/interface/interface_backend_udev.c | 5 +-
src/libvirt_private.syms | 15 +-
src/test/test_driver.c | 349 +++++++++++++-------------------
9 files changed, 415 insertions(+), 430 deletions(-)
create mode 100644 src/conf/virinterfaceobj.c
create mode 100644 src/conf/virinterfaceobj.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 20ee73a..d864e6c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -383,7 +383,8 @@ STORAGE_CONF_SOURCES = \
# Interface driver generic impl APIs
INTERFACE_CONF_SOURCES = \
- conf/interface_conf.c conf/interface_conf.h
+ conf/interface_conf.c conf/interface_conf.h \
+ conf/virinterfaceobj.c conf/virinterfaceobj.h
# Secret driver generic impl APIs
SECRET_CONF_SOURCES = \
diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c
index e1e6a25..cbab22b 100644
--- a/src/conf/interface_conf.c
+++ b/src/conf/interface_conf.c
@@ -68,8 +68,10 @@ void virInterfaceProtocolDefFree(virInterfaceProtocolDefPtr def)
VIR_FREE(def);
}
-void virInterfaceDefFree(virInterfaceDefPtr def)
+void
+virInterfaceDefFree(void *opaque)
{
+ virInterfaceDefPtr def = opaque;
size_t i;
int pp;
@@ -1114,169 +1116,3 @@ char *virInterfaceDefFormat(const virInterfaceDef *def)
}
return virBufferContentAndReset(&buf);
}
-
-/* virInterfaceObj manipulation */
-
-void virInterfaceObjLock(virInterfaceObjPtr obj)
-{
- virMutexLock(&obj->lock);
-}
-
-void virInterfaceObjUnlock(virInterfaceObjPtr obj)
-{
- virMutexUnlock(&obj->lock);
-}
-
-void virInterfaceObjFree(virInterfaceObjPtr iface)
-{
- if (!iface)
- return;
-
- virInterfaceDefFree(iface->def);
- virMutexDestroy(&iface->lock);
- VIR_FREE(iface);
-}
-
-/* virInterfaceObjList manipulation */
-
-int virInterfaceFindByMACString(virInterfaceObjListPtr interfaces,
- const char *mac,
- virInterfaceObjPtr *matches, int maxmatches)
-{
- size_t i;
- unsigned int matchct = 0;
-
- for (i = 0; i < interfaces->count; i++) {
-
- virInterfaceObjLock(interfaces->objs[i]);
- if (STRCASEEQ(interfaces->objs[i]->def->mac, mac)) {
- matchct++;
- if (matchct <= maxmatches) {
- matches[matchct - 1] = interfaces->objs[i];
- /* keep the lock if we're returning object to caller */
- /* it is the caller's responsibility to unlock *all* matches */
- continue;
- }
- }
- virInterfaceObjUnlock(interfaces->objs[i]);
-
- }
- return matchct;
-}
-
-virInterfaceObjPtr virInterfaceFindByName(virInterfaceObjListPtr interfaces,
- const char *name)
-{
- size_t i;
-
- for (i = 0; i < interfaces->count; i++) {
- virInterfaceObjLock(interfaces->objs[i]);
- if (STREQ(interfaces->objs[i]->def->name, name))
- return interfaces->objs[i];
- virInterfaceObjUnlock(interfaces->objs[i]);
- }
-
- return NULL;
-}
-
-void virInterfaceObjListFree(virInterfaceObjListPtr interfaces)
-{
- size_t i;
-
- for (i = 0; i < interfaces->count; i++)
- virInterfaceObjFree(interfaces->objs[i]);
-
- VIR_FREE(interfaces->objs);
- interfaces->count = 0;
-}
-
-int virInterfaceObjListClone(virInterfaceObjListPtr src,
- virInterfaceObjListPtr dest)
-{
- int ret = -1;
- size_t i;
- unsigned int cnt;
-
- if (!src || !dest)
- goto cleanup;
-
- virInterfaceObjListFree(dest); /* start with an empty list */
- cnt = src->count;
- for (i = 0; i < cnt; i++) {
- virInterfaceDefPtr def = src->objs[i]->def;
- virInterfaceDefPtr backup;
- virInterfaceObjPtr iface;
- char *xml = virInterfaceDefFormat(def);
-
- if (!xml)
- goto cleanup;
-
- if ((backup = virInterfaceDefParseString(xml)) == NULL) {
- VIR_FREE(xml);
- goto cleanup;
- }
-
- VIR_FREE(xml);
- if ((iface = virInterfaceAssignDef(dest, backup)) == NULL)
- goto cleanup;
- virInterfaceObjUnlock(iface); /* was locked by virInterfaceAssignDef */
- }
-
- ret = cnt;
- cleanup:
- if ((ret < 0) && dest)
- virInterfaceObjListFree(dest);
- return ret;
-}
-
-virInterfaceObjPtr virInterfaceAssignDef(virInterfaceObjListPtr interfaces,
- virInterfaceDefPtr def)
-{
- virInterfaceObjPtr iface;
-
- if ((iface = virInterfaceFindByName(interfaces, def->name))) {
- virInterfaceDefFree(iface->def);
- iface->def = def;
-
- return iface;
- }
-
- if (VIR_ALLOC(iface) < 0)
- return NULL;
- if (virMutexInit(&iface->lock) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("cannot initialize mutex"));
- VIR_FREE(iface);
- return NULL;
- }
- virInterfaceObjLock(iface);
-
- if (VIR_APPEND_ELEMENT_COPY(interfaces->objs,
- interfaces->count, iface) < 0) {
- virInterfaceObjFree(iface);
- return NULL;
- }
-
- iface->def = def;
- return iface;
-
-}
-
-void virInterfaceRemove(virInterfaceObjListPtr interfaces,
- virInterfaceObjPtr iface)
-{
- size_t i;
-
- virInterfaceObjUnlock(iface);
- for (i = 0; i < interfaces->count; i++) {
- virInterfaceObjLock(interfaces->objs[i]);
- if (interfaces->objs[i] == iface) {
- virInterfaceObjUnlock(interfaces->objs[i]);
- virInterfaceObjFree(interfaces->objs[i]);
-
- VIR_DELETE_ELEMENT(interfaces->objs, i, interfaces->count);
- break;
- }
- virInterfaceObjUnlock(interfaces->objs[i]);
- }
-}
diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h
index 1e38412..31523dc 100644
--- a/src/conf/interface_conf.h
+++ b/src/conf/interface_conf.h
@@ -161,46 +161,7 @@ struct _virInterfaceDef {
virInterfaceProtocolDefPtr *protos; /* ptr to array of protos[nprotos] */
};
-typedef struct _virInterfaceObj virInterfaceObj;
-typedef virInterfaceObj *virInterfaceObjPtr;
-struct _virInterfaceObj {
- virMutex lock;
-
- bool active; /* true if interface is active (up) */
- virInterfaceDefPtr def; /* The interface definition */
-};
-
-typedef struct _virInterfaceObjList virInterfaceObjList;
-typedef virInterfaceObjList *virInterfaceObjListPtr;
-struct _virInterfaceObjList {
- size_t count;
- virInterfaceObjPtr *objs;
-};
-
-static inline bool
-virInterfaceObjIsActive(const virInterfaceObj *iface)
-{
- return iface->active;
-}
-
-int virInterfaceFindByMACString(virInterfaceObjListPtr interfaces,
- const char *mac,
- virInterfaceObjPtr *matches, int maxmatches);
-virInterfaceObjPtr virInterfaceFindByName(virInterfaceObjListPtr interfaces,
- const char *name);
-
-
-void virInterfaceDefFree(virInterfaceDefPtr def);
-void virInterfaceObjFree(virInterfaceObjPtr iface);
-void virInterfaceObjListFree(virInterfaceObjListPtr vms);
-int virInterfaceObjListClone(virInterfaceObjListPtr src,
- virInterfaceObjListPtr dest);
-
-
-virInterfaceObjPtr virInterfaceAssignDef(virInterfaceObjListPtr interfaces,
- virInterfaceDefPtr def);
-void virInterfaceRemove(virInterfaceObjListPtr interfaces,
- virInterfaceObjPtr iface);
+void virInterfaceDefFree(void *opaque);
virInterfaceDefPtr virInterfaceDefParseString(const char *xmlStr);
virInterfaceDefPtr virInterfaceDefParseFile(const char *filename);
@@ -209,11 +170,6 @@ virInterfaceDefPtr virInterfaceDefParseNode(xmlDocPtr xml,
char *virInterfaceDefFormat(const virInterfaceDef *def);
-void virInterfaceObjLock(virInterfaceObjPtr obj);
-void virInterfaceObjUnlock(virInterfaceObjPtr obj);
-
-typedef bool (*virInterfaceObjListFilter)(virConnectPtr conn, void *opaque);
-
# define VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE \
(VIR_CONNECT_LIST_INTERFACES_ACTIVE | \
VIR_CONNECT_LIST_INTERFACES_INACTIVE)
diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c
new file mode 100644
index 0000000..9ef0a45
--- /dev/null
+++ b/src/conf/virinterfaceobj.c
@@ -0,0 +1,205 @@
+/*
+ * virinterfaceobj.c: interface object handling
+ * (derived from interface_conf.c)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <
http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "datatypes.h"
+#include "interface_conf.h"
+
+#include "viralloc.h"
+#include "virerror.h"
+#include "virinterfaceobj.h"
+#include "virlog.h"
+#include "virstring.h"
+
+#define VIR_FROM_THIS VIR_FROM_INTERFACE
+
+VIR_LOG_INIT("conf.virinterfaceobj");
+
+
+struct interfaceCountData {
+ bool wantActive;
+ int count;
+};
+
+static int
+interfaceCount(virPoolObjPtr obj,
+ void *opaque)
+{
+ struct interfaceCountData *data = opaque;
+
+ if ((data->wantActive && virPoolObjIsActive(obj)) ||
+ (!data->wantActive && !virPoolObjIsActive(obj)))
+ data->count++;
+
+ return 0;
+}
+
+
+int
+virInterfaceObjNumOfInterfaces(virPoolObjTablePtr ifaces,
+ virConnectPtr conn,
+ bool wantActive,
+ virPoolObjACLFilter aclfilter)
+{
+ struct interfaceCountData data = { .wantActive = wantActive,
+ .count = 0 };
+
+ if (virPoolObjTableList(ifaces, conn, aclfilter, interfaceCount, &data) < 0)
+ return 0;
+
+ return data.count;
+}
+
+
+struct interfaceNameData {
+ bool wantActive;
+ int nnames;
+ char **const names;
+ int maxnames;
+};
+
+static int
+interfaceGetNames(virPoolObjPtr obj,
+ void *opaque)
+{
+ struct interfaceNameData *data = opaque;
+
+ if (data->nnames < data->maxnames) {
+ if (data->wantActive && virPoolObjIsActive(obj)) {
+ virInterfaceDefPtr def = virPoolObjGetDef(obj);
+
+ if (VIR_STRDUP(data->names[data->nnames++], def->name) < 0)
+ return -1;
+ } else if (!data->wantActive && !virPoolObjIsActive(obj)) {
+ virInterfaceDefPtr def = virPoolObjGetDef(obj);
+
+ if (VIR_STRDUP(data->names[data->nnames++], def->name) < 0)
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+
+int
+virInterfaceObjGetNames(virPoolObjTablePtr ifaces,
+ virConnectPtr conn,
+ bool wantActive,
+ virPoolObjACLFilter aclfilter,
+ char **const names,
+ int maxnames)
+{
+ struct interfaceNameData data = { .wantActive = wantActive,
+ .nnames = 0,
+ .names = names,
+ .maxnames = maxnames };
+
+ memset(names, 0, sizeof(*names) * maxnames);
+ if (virPoolObjTableList(ifaces, conn, aclfilter,
+ interfaceGetNames, &data) < 0)
+ goto error;
+
+ return data.nnames;
+
+ error:
+ while (--data.nnames >= 0)
+ VIR_FREE(names[data.nnames]);
+ return -1;
+}
+
+
+struct interfaceListMACData {
+ const char *mac;
+ int nmatches;
+ char **const matches;
+ int maxmatches;
+};
+
+static int
+interfaceListMACString(virPoolObjPtr obj,
+ void *opaque)
+{
+ virInterfaceDefPtr def = virPoolObjGetDef(obj);
+ struct interfaceListMACData *data = opaque;
+
+ if (STRCASEEQ(def->mac, data->mac)) {
+ if (data->nmatches < data->maxmatches) {
+ if (VIR_STRDUP(data->matches[data->nmatches++], def->name) < 0)
+ return -1;
+ }
+ }
+ return 0;
+}
+
+
+/* virInterfaceFindByMACString:
+ * @interfaces: Pointer to object table
+ * @mac: String to search on
+ * @matches: Array of entries to store names matching MAC
+ * @maxmatches: Size of the array
+ *
+ * Search the object table for matching MAC's
+ *
+ * Returns: count of matches found, -1 on error
+ */
+int
+virInterfaceObjFindByMACString(virConnectPtr conn,
+ virPoolObjTablePtr interfaces,
+ const char *mac,
+ char **const matches,
+ int maxmatches)
+{
+ struct interfaceListMACData data = { .mac = mac,
+ .nmatches = 0,
+ .matches = matches,
+ .maxmatches = maxmatches };
+
+ if (virPoolObjTableList(interfaces, conn, NULL,
+ interfaceListMACString, &data) < 0)
+ return -1;
+
+ return data.nmatches;
+}
+
+
+static void *
+cloneObjCallback(virPoolObjPtr src)
+{
+ virInterfaceDefPtr srcdef = virPoolObjGetDef(src);
+ virInterfaceDefPtr dstdef;
+ char *xml;
+
+ if (!(xml = virInterfaceDefFormat(srcdef)))
+ return NULL;
+
+ dstdef = virInterfaceDefParseString(xml);
+
+ VIR_FREE(xml);
+
+ return dstdef;
+}
+
+
+virPoolObjTablePtr
+virInterfaceObjClone(virPoolObjTablePtr src)
+{
+ return virPoolObjTableClone(src, cloneObjCallback);
+}
diff --git a/src/conf/virinterfaceobj.h b/src/conf/virinterfaceobj.h
new file mode 100644
index 0000000..3a59616
--- /dev/null
+++ b/src/conf/virinterfaceobj.h
@@ -0,0 +1,46 @@
+/*
+ * virinterfaceobj.h: interface object handling entry points
+ * (derived from interface_conf.h)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <
http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __VIRINTERFACEOBJ_H__
+# define __VIRINTERFACEOBJ_H__
+
+# include "internal.h"
+# include "virpoolobj.h"
+
+int virInterfaceObjNumOfInterfaces(virPoolObjTablePtr ifaces,
+ virConnectPtr conn,
+ bool wantActive,
+ virPoolObjACLFilter aclfilter);
+
+int virInterfaceObjGetNames(virPoolObjTablePtr ifaces,
+ virConnectPtr conn,
+ bool wantActive,
+ virPoolObjACLFilter aclfilter,
+ char **const names,
+ int maxnames);
+
+int virInterfaceObjFindByMACString(virConnectPtr conn,
+ virPoolObjTablePtr interfaces,
+ const char *mac,
+ char **const matches,
+ int maxmatches);
+
+virPoolObjTablePtr virInterfaceObjClone(virPoolObjTablePtr src);
+
+#endif /* __VIRINTERFACEOBJ_H__ */
diff --git a/src/interface/interface_backend_netcf.c
b/src/interface/interface_backend_netcf.c
index 0181635..fa57905 100644
--- a/src/interface/interface_backend_netcf.c
+++ b/src/interface/interface_backend_netcf.c
@@ -31,6 +31,7 @@
#include "interface_conf.h"
#include "viralloc.h"
#include "virlog.h"
+#include "virpoolobj.h"
#include "virstring.h"
#include "viraccessapicheck.h"
@@ -95,6 +96,7 @@ netcfStateInitialize(bool privileged ATTRIBUTE_UNUSED,
driver = NULL;
return -1;
}
+
return 0;
}
@@ -266,7 +268,7 @@ netcfInterfaceObjIsActive(struct netcf_if *iface,
static int netcfConnectNumOfInterfacesImpl(virConnectPtr conn,
int status,
- virInterfaceObjListFilter filter)
+ virPoolObjACLFilter filter)
{
int count;
int want = 0;
@@ -359,7 +361,7 @@ static int netcfConnectNumOfInterfacesImpl(virConnectPtr conn,
static int netcfConnectListInterfacesImpl(virConnectPtr conn,
int status,
char **const names, int nnames,
- virInterfaceObjListFilter filter)
+ virPoolObjACLFilter filter)
{
int count = 0;
int want = 0;
diff --git a/src/interface/interface_backend_udev.c
b/src/interface/interface_backend_udev.c
index 5d0fc64..c9a3143 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -32,6 +32,7 @@
#include "interface_driver.h"
#include "interface_conf.h"
#include "viralloc.h"
+#include "virpoolobj.h"
#include "virstring.h"
#include "viraccessapicheck.h"
#include "virnetdev.h"
@@ -137,7 +138,7 @@ udevGetDevices(struct udev *udev, virUdevStatus status)
static int
udevNumOfInterfacesByStatus(virConnectPtr conn, virUdevStatus status,
- virInterfaceObjListFilter filter)
+ virPoolObjACLFilter filter)
{
struct udev *udev = udev_ref(driver->udev);
struct udev_enumerate *enumerate = NULL;
@@ -190,7 +191,7 @@ udevListInterfacesByStatus(virConnectPtr conn,
char **const names,
int names_len,
virUdevStatus status,
- virInterfaceObjListFilter filter)
+ virPoolObjACLFilter filter)
{
struct udev *udev = udev_ref(driver->udev);
struct udev_enumerate *enumerate = NULL;
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 98b3840..5f95814 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -594,19 +594,11 @@ virDomainConfVMNWFilterTeardown;
# conf/interface_conf.h
-virInterfaceAssignDef;
virInterfaceDefFormat;
virInterfaceDefFree;
virInterfaceDefParseFile;
virInterfaceDefParseNode;
virInterfaceDefParseString;
-virInterfaceFindByMACString;
-virInterfaceFindByName;
-virInterfaceObjListClone;
-virInterfaceObjListFree;
-virInterfaceObjLock;
-virInterfaceObjUnlock;
-virInterfaceRemove;
# conf/netdev_bandwidth_conf.h
@@ -948,6 +940,13 @@ virDomainObjListRemoveLocked;
virDomainObjListRename;
+# conf/virinterfaceobj.h
+virInterfaceObjClone;
+virInterfaceObjFindByMACString;
+virInterfaceObjGetNames;
+virInterfaceObjNumOfInterfaces;
+
+
# conf/virnodedeviceobj.h
virNodeDeviceObjExportList;
virNodeDeviceObjFindByName;
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index ce44728..51605f3 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -65,6 +65,7 @@
#include "virauth.h"
#include "viratomic.h"
#include "virdomainobjlist.h"
+#include "virinterfaceobj.h"
#include "virhostcpu.h"
#define VIR_FROM_THIS VIR_FROM_TEST
@@ -96,9 +97,9 @@ struct _testDriver {
virMutex lock;
virNodeInfo nodeInfo;
- virInterfaceObjList ifaces;
+ virPoolObjTablePtr ifaces;
bool transaction_running;
- virInterfaceObjList backupIfaces;
+ virPoolObjTablePtr backupIfaces;
virStoragePoolObjList pools;
virPoolObjTablePtr devs;
int numCells;
@@ -153,7 +154,8 @@ testDriverFree(testDriverPtr driver)
virObjectUnref(driver->domains);
virObjectUnref(driver->devs);
virObjectUnref(driver->networks);
- virInterfaceObjListFree(&driver->ifaces);
+ virObjectUnref(driver->ifaces);
+ virObjectUnref(driver->backupIfaces);
virStoragePoolObjListFree(&driver->pools);
virObjectUnref(driver->eventState);
virMutexUnlock(&driver->lock);
@@ -418,6 +420,9 @@ testDriverNew(void)
!(ret->devs = virPoolObjTableNew(VIR_POOLOBJTABLE_NODEDEVICE,
VIR_POOLOBJTABLE_NODEDEVICE_HASHSTART,
true)) ||
+ !(ret->ifaces = virPoolObjTableNew(VIR_POOLOBJTABLE_INTERFACE,
+ VIR_POOLOBJTABLE_INTERFACE_HASHSTART,
+ true)) ||
!(ret->domains = virDomainObjListNew()) ||
!(ret->networks = virNetworkObjListNew()))
goto error;
@@ -970,34 +975,33 @@ testParseInterfaces(testDriverPtr privconn,
int num, ret = -1;
size_t i;
xmlNodePtr *nodes = NULL;
- virInterfaceObjPtr obj;
+ virInterfaceDefPtr def = NULL;
+ xmlNodePtr node;
+ virPoolObjPtr obj;
- num = virXPathNodeSet("/node/interface", ctxt, &nodes);
- if (num < 0)
+ if ((num = virXPathNodeSet("/node/interface", ctxt, &nodes)) < 0)
goto error;
for (i = 0; i < num; i++) {
- virInterfaceDefPtr def;
- xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file,
- "interface");
- if (!node)
+ if (!(node = testParseXMLDocFromFile(nodes[i], file, "interface")))
goto error;
- def = virInterfaceDefParseNode(ctxt->doc, node);
- if (!def)
+ if (!(def = virInterfaceDefParseNode(ctxt->doc, node)))
goto error;
- if (!(obj = virInterfaceAssignDef(&privconn->ifaces, def))) {
- virInterfaceDefFree(def);
+ if (!(obj = virPoolObjTableAdd(privconn->ifaces, NULL, def->name,
+ def, NULL, NULL, virInterfaceDefFree,
+ NULL, 0)))
goto error;
- }
+ def = NULL;
- obj->active = 1;
- virInterfaceObjUnlock(obj);
+ virPoolObjSetActive(obj, true);
+ virPoolObjEndAPI(&obj);
}
ret = 0;
error:
+ virInterfaceDefFree(def);
VIR_FREE(nodes);
return ret;
}
@@ -3605,133 +3609,94 @@ static int testNetworkSetAutostart(virNetworkPtr network,
*/
-static int testConnectNumOfInterfaces(virConnectPtr conn)
+static int
+testConnectNumOfInterfaces(virConnectPtr conn)
{
testDriverPtr privconn = conn->privateData;
- size_t i;
- int count = 0;
- testDriverLock(privconn);
- for (i = 0; (i < privconn->ifaces.count); i++) {
- virInterfaceObjLock(privconn->ifaces.objs[i]);
- if (virInterfaceObjIsActive(privconn->ifaces.objs[i]))
- count++;
- virInterfaceObjUnlock(privconn->ifaces.objs[i]);
- }
- testDriverUnlock(privconn);
- return count;
+ return virInterfaceObjNumOfInterfaces(privconn->ifaces, conn, true, NULL);
}
-static int testConnectListInterfaces(virConnectPtr conn, char **const names, int nnames)
+
+static int
+testConnectListInterfaces(virConnectPtr conn,
+ char **const names,
+ int maxnames)
{
testDriverPtr privconn = conn->privateData;
- int n = 0;
- size_t i;
- testDriverLock(privconn);
- memset(names, 0, sizeof(*names)*nnames);
- for (i = 0; (i < privconn->ifaces.count) && (n < nnames); i++) {
- virInterfaceObjLock(privconn->ifaces.objs[i]);
- if (virInterfaceObjIsActive(privconn->ifaces.objs[i])) {
- if (VIR_STRDUP(names[n++], privconn->ifaces.objs[i]->def->name) <
0) {
- virInterfaceObjUnlock(privconn->ifaces.objs[i]);
- goto error;
- }
- }
- virInterfaceObjUnlock(privconn->ifaces.objs[i]);
- }
- testDriverUnlock(privconn);
+ return virInterfaceObjGetNames(privconn->ifaces, conn, true, NULL,
+ names, maxnames);
+}
- return n;
- error:
- for (n = 0; n < nnames; n++)
- VIR_FREE(names[n]);
- testDriverUnlock(privconn);
- return -1;
+static int
+testConnectNumOfDefinedInterfaces(virConnectPtr conn)
+{
+ testDriverPtr privconn = conn->privateData;
+
+ return virInterfaceObjNumOfInterfaces(privconn->ifaces, conn, false, NULL);
}
-static int testConnectNumOfDefinedInterfaces(virConnectPtr conn)
+
+static int
+testConnectListDefinedInterfaces(virConnectPtr conn,
+ char **const names,
+ int maxnames)
{
testDriverPtr privconn = conn->privateData;
- size_t i;
- int count = 0;
- testDriverLock(privconn);
- for (i = 0; i < privconn->ifaces.count; i++) {
- virInterfaceObjLock(privconn->ifaces.objs[i]);
- if (!virInterfaceObjIsActive(privconn->ifaces.objs[i]))
- count++;
- virInterfaceObjUnlock(privconn->ifaces.objs[i]);
- }
- testDriverUnlock(privconn);
- return count;
+ return virInterfaceObjGetNames(privconn->ifaces, conn, false, NULL,
+ names, maxnames);
}
-static int testConnectListDefinedInterfaces(virConnectPtr conn, char **const names, int
nnames)
+
+static virPoolObjPtr
+testInterfaceObjFromName(virPoolObjTablePtr ifaces,
+ const char *name)
{
- testDriverPtr privconn = conn->privateData;
- int n = 0;
- size_t i;
+ virPoolObjPtr obj;
- testDriverLock(privconn);
- memset(names, 0, sizeof(*names)*nnames);
- for (i = 0; (i < privconn->ifaces.count) && (n < nnames); i++) {
- virInterfaceObjLock(privconn->ifaces.objs[i]);
- if (!virInterfaceObjIsActive(privconn->ifaces.objs[i])) {
- if (VIR_STRDUP(names[n++], privconn->ifaces.objs[i]->def->name) <
0) {
- virInterfaceObjUnlock(privconn->ifaces.objs[i]);
- goto error;
- }
- }
- virInterfaceObjUnlock(privconn->ifaces.objs[i]);
+ if (!(obj = virPoolObjTableFindByName(ifaces, name))) {
+ virReportError(VIR_ERR_NO_INTERFACE,
+ _("no interface with matching name '%s'"),
name);
+ return NULL;
}
- testDriverUnlock(privconn);
- return n;
-
- error:
- for (n = 0; n < nnames; n++)
- VIR_FREE(names[n]);
- testDriverUnlock(privconn);
- return -1;
+ return obj;
}
-static virInterfacePtr testInterfaceLookupByName(virConnectPtr conn,
- const char *name)
+
+static virInterfacePtr
+testInterfaceLookupByName(virConnectPtr conn,
+ const char *name)
{
testDriverPtr privconn = conn->privateData;
- virInterfaceObjPtr iface;
+ virPoolObjPtr obj;
+ virInterfaceDefPtr def;
virInterfacePtr ret = NULL;
- testDriverLock(privconn);
- iface = virInterfaceFindByName(&privconn->ifaces, name);
- testDriverUnlock(privconn);
-
- if (iface == NULL) {
- virReportError(VIR_ERR_NO_INTERFACE, NULL);
- goto cleanup;
- }
+ if (!(obj = testInterfaceObjFromName(privconn->ifaces, name)))
+ return NULL;
- ret = virGetInterface(conn, iface->def->name, iface->def->mac);
+ def = virPoolObjGetDef(obj);
+ ret = virGetInterface(conn, def->name, def->mac);
- cleanup:
- if (iface)
- virInterfaceObjUnlock(iface);
+ virPoolObjEndAPI(&obj);
return ret;
}
-static virInterfacePtr testInterfaceLookupByMACString(virConnectPtr conn,
- const char *mac)
+static virInterfacePtr
+testInterfaceLookupByMACString(virConnectPtr conn,
+ const char *mac)
{
testDriverPtr privconn = conn->privateData;
- virInterfaceObjPtr iface;
int ifacect;
+ char *ifacenames[] = { NULL, NULL };
virInterfacePtr ret = NULL;
- testDriverLock(privconn);
- ifacect = virInterfaceFindByMACString(&privconn->ifaces, mac, &iface, 1);
- testDriverUnlock(privconn);
+ ifacect = virInterfaceObjFindByMACString(conn, privconn->ifaces,
+ mac, ifacenames, 2);
if (ifacect == 0) {
virReportError(VIR_ERR_NO_INTERFACE, NULL);
@@ -3743,35 +3708,35 @@ static virInterfacePtr
testInterfaceLookupByMACString(virConnectPtr conn,
goto cleanup;
}
- ret = virGetInterface(conn, iface->def->name, iface->def->mac);
+ ret = virGetInterface(conn, ifacenames[0], mac);
cleanup:
- if (iface)
- virInterfaceObjUnlock(iface);
+ VIR_FREE(ifacenames[0]);
+ VIR_FREE(ifacenames[1]);
return ret;
}
-static int testInterfaceIsActive(virInterfacePtr iface)
+
+static int
+testInterfaceIsActive(virInterfacePtr iface)
{
testDriverPtr privconn = iface->conn->privateData;
- virInterfaceObjPtr obj;
+ virPoolObjPtr obj;
int ret = -1;
- testDriverLock(privconn);
- obj = virInterfaceFindByName(&privconn->ifaces, iface->name);
- testDriverUnlock(privconn);
- if (!obj) {
- virReportError(VIR_ERR_NO_INTERFACE, NULL);
- goto cleanup;
- }
- ret = virInterfaceObjIsActive(obj);
+ if (!(obj = testInterfaceObjFromName(privconn->ifaces, iface->name)))
+ return -1;
- cleanup:
- if (obj)
- virInterfaceObjUnlock(obj);
+ if (virPoolObjIsActive(obj))
+ ret = 1;
+ else
+ ret = 0;
+
+ virPoolObjEndAPI(&obj);
return ret;
}
+
static int testInterfaceChangeBegin(virConnectPtr conn,
unsigned int flags)
{
@@ -3789,8 +3754,7 @@ static int testInterfaceChangeBegin(virConnectPtr conn,
privconn->transaction_running = true;
- if (virInterfaceObjListClone(&privconn->ifaces,
- &privconn->backupIfaces) < 0)
+ if (!(privconn->backupIfaces = virInterfaceObjClone(privconn->ifaces)))
goto cleanup;
ret = 0;
@@ -3816,7 +3780,8 @@ static int testInterfaceChangeCommit(virConnectPtr conn,
goto cleanup;
}
- virInterfaceObjListFree(&privconn->backupIfaces);
+ virObjectUnref(privconn->backupIfaces);
+ privconn->backupIfaces = NULL;
privconn->transaction_running = false;
ret = 0;
@@ -3844,11 +3809,8 @@ static int testInterfaceChangeRollback(virConnectPtr conn,
goto cleanup;
}
- virInterfaceObjListFree(&privconn->ifaces);
- privconn->ifaces.count = privconn->backupIfaces.count;
- privconn->ifaces.objs = privconn->backupIfaces.objs;
- privconn->backupIfaces.count = 0;
- privconn->backupIfaces.objs = NULL;
+ virObjectUnref(privconn->ifaces);
+ VIR_STEAL_PTR(privconn->ifaces, privconn->backupIfaces);
privconn->transaction_running = false;
@@ -3859,40 +3821,36 @@ static int testInterfaceChangeRollback(virConnectPtr conn,
return ret;
}
-static char *testInterfaceGetXMLDesc(virInterfacePtr iface,
- unsigned int flags)
+
+static char *
+testInterfaceGetXMLDesc(virInterfacePtr iface,
+ unsigned int flags)
{
testDriverPtr privconn = iface->conn->privateData;
- virInterfaceObjPtr privinterface;
+ virPoolObjPtr obj;
char *ret = NULL;
virCheckFlags(0, NULL);
- testDriverLock(privconn);
- privinterface = virInterfaceFindByName(&privconn->ifaces,
- iface->name);
- testDriverUnlock(privconn);
-
- if (privinterface == NULL) {
- virReportError(VIR_ERR_NO_INTERFACE, __FUNCTION__);
- goto cleanup;
- }
+ if (!(obj = testInterfaceObjFromName(privconn->ifaces, iface->name)))
+ return NULL;
- ret = virInterfaceDefFormat(privinterface->def);
+ ret = virInterfaceDefFormat(virPoolObjGetDef(obj));
- cleanup:
- if (privinterface)
- virInterfaceObjUnlock(privinterface);
+ virPoolObjEndAPI(&obj);
return ret;
}
-static virInterfacePtr testInterfaceDefineXML(virConnectPtr conn, const char *xmlStr,
- unsigned int flags)
+static virInterfacePtr
+testInterfaceDefineXML(virConnectPtr conn,
+ const char *xmlStr,
+ unsigned int flags)
{
testDriverPtr privconn = conn->privateData;
- virInterfaceDefPtr def;
- virInterfaceObjPtr iface = NULL;
+ virInterfaceDefPtr def = NULL;
+ virPoolObjPtr obj;
+ virInterfaceDefPtr objdef;
virInterfacePtr ret = NULL;
virCheckFlags(0, NULL);
@@ -3901,107 +3859,88 @@ static virInterfacePtr testInterfaceDefineXML(virConnectPtr conn,
const char *xm
if ((def = virInterfaceDefParseString(xmlStr)) == NULL)
goto cleanup;
- if ((iface = virInterfaceAssignDef(&privconn->ifaces, def)) == NULL)
+ if (!(obj = virPoolObjTableAdd(privconn->ifaces, NULL, def->name,
+ def, NULL, NULL, virInterfaceDefFree,
+ NULL, 0)))
goto cleanup;
- def = NULL;
+ VIR_STEAL_PTR(objdef, def);
- ret = virGetInterface(conn, iface->def->name, iface->def->mac);
+ ret = virGetInterface(conn, objdef->name, objdef->mac);
cleanup:
virInterfaceDefFree(def);
- if (iface)
- virInterfaceObjUnlock(iface);
+ virPoolObjEndAPI(&obj);
testDriverUnlock(privconn);
return ret;
}
-static int testInterfaceUndefine(virInterfacePtr iface)
+
+static int
+testInterfaceUndefine(virInterfacePtr iface)
{
testDriverPtr privconn = iface->conn->privateData;
- virInterfaceObjPtr privinterface;
- int ret = -1;
-
- testDriverLock(privconn);
- privinterface = virInterfaceFindByName(&privconn->ifaces,
- iface->name);
+ virPoolObjPtr obj;
- if (privinterface == NULL) {
- virReportError(VIR_ERR_NO_INTERFACE, NULL);
- goto cleanup;
- }
+ if (!(obj = testInterfaceObjFromName(privconn->ifaces, iface->name)))
+ return -1;
- virInterfaceRemove(&privconn->ifaces,
- privinterface);
- ret = 0;
+ virPoolObjTableRemove(privconn->ifaces, &obj);
- cleanup:
- testDriverUnlock(privconn);
- return ret;
+ virPoolObjEndAPI(&obj);
+ return 0;
}
-static int testInterfaceCreate(virInterfacePtr iface,
- unsigned int flags)
+
+static int
+testInterfaceCreate(virInterfacePtr iface,
+ unsigned int flags)
{
testDriverPtr privconn = iface->conn->privateData;
- virInterfaceObjPtr privinterface;
+ virPoolObjPtr obj;
int ret = -1;
virCheckFlags(0, -1);
- testDriverLock(privconn);
- privinterface = virInterfaceFindByName(&privconn->ifaces,
- iface->name);
-
- if (privinterface == NULL) {
- virReportError(VIR_ERR_NO_INTERFACE, NULL);
- goto cleanup;
- }
+ if (!(obj = testInterfaceObjFromName(privconn->ifaces, iface->name)))
+ return -1;
- if (privinterface->active != 0) {
+ if (virPoolObjIsActive(obj)) {
virReportError(VIR_ERR_OPERATION_INVALID, NULL);
goto cleanup;
}
- privinterface->active = 1;
+ virPoolObjSetActive(obj, true);
ret = 0;
cleanup:
- if (privinterface)
- virInterfaceObjUnlock(privinterface);
- testDriverUnlock(privconn);
+ virPoolObjEndAPI(&obj);
return ret;
}
-static int testInterfaceDestroy(virInterfacePtr iface,
- unsigned int flags)
+
+static int
+testInterfaceDestroy(virInterfacePtr iface,
+ unsigned int flags)
{
testDriverPtr privconn = iface->conn->privateData;
- virInterfaceObjPtr privinterface;
+ virPoolObjPtr obj;
int ret = -1;
virCheckFlags(0, -1);
- testDriverLock(privconn);
- privinterface = virInterfaceFindByName(&privconn->ifaces,
- iface->name);
-
- if (privinterface == NULL) {
- virReportError(VIR_ERR_NO_INTERFACE, NULL);
- goto cleanup;
- }
+ if (!(obj = testInterfaceObjFromName(privconn->ifaces, iface->name)))
+ return -1;
- if (privinterface->active == 0) {
+ if (!virPoolObjIsActive(obj)) {
virReportError(VIR_ERR_OPERATION_INVALID, NULL);
goto cleanup;
}
- privinterface->active = 0;
+ virPoolObjSetActive(obj, false);
ret = 0;
cleanup:
- if (privinterface)
- virInterfaceObjUnlock(privinterface);
- testDriverUnlock(privconn);
+ virPoolObjEndAPI(&obj);
return ret;
}
--
2.7.4