Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/conf/virinterfaceobj.c | 7 ++--
src/datatypes.c | 44 +++++++++++++++----------
src/datatypes.h | 10 +++---
src/interface/interface_backend_netcf.c | 2 +-
src/interface/interface_backend_udev.c | 2 +-
src/libvirt-interface.c | 6 ++--
src/libvirt_private.syms | 1 -
7 files changed, 42 insertions(+), 30 deletions(-)
diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c
index 43ba395d2b..da6c56862b 100644
--- a/src/conf/virinterfaceobj.c
+++ b/src/conf/virinterfaceobj.c
@@ -338,9 +338,10 @@ virInterfaceObjListExport(virConnectPtr conn,
ret = data.nifaces;
cleanup:
virObjectRWUnlock(ifaceobjs);
- while (data.ifaces && data.nifaces)
- virObjectUnref(data.ifaces[--data.nifaces]);
-
+ while (data.ifaces && data.nifaces) {
+ if (data.ifaces[--data.nifaces])
+ g_object_unref(data.ifaces[data.nifaces]);
+ }
VIR_FREE(data.ifaces);
return ret;
}
diff --git a/src/datatypes.c b/src/datatypes.c
index e715c37306..f1bcca44f1 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -36,7 +36,6 @@ VIR_LOG_INIT("datatypes");
virClassPtr virConnectClass;
virClassPtr virConnectCloseCallbackDataClass;
virClassPtr virDomainClass;
-virClassPtr virInterfaceClass;
virClassPtr virNodeDeviceClass;
virClassPtr virSecretClass;
virClassPtr virStreamClass;
@@ -46,7 +45,6 @@ virClassPtr virStoragePoolClass;
static void virConnectDispose(void *obj);
static void virConnectCloseCallbackDataDispose(void *obj);
static void virDomainDispose(void *obj);
-static void virInterfaceDispose(void *obj);
static void virNodeDeviceDispose(void *obj);
static void virSecretDispose(void *obj);
static void virStreamDispose(void *obj);
@@ -85,6 +83,22 @@ vir_domain_snapshot_class_init(virDomainSnapshotClass *klass)
obj->finalize = virDomainSnapshotFinalize;
}
+G_DEFINE_TYPE(virInterface, vir_interface, G_TYPE_OBJECT);
+static void virInterfaceFinalize(GObject *obj);
+
+static void
+vir_interface_init(virInterface *iface G_GNUC_UNUSED)
+{
+}
+
+static void
+vir_interface_class_init(virInterfaceClass *klass)
+{
+ GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+ obj->finalize = virInterfaceFinalize;
+}
+
G_DEFINE_TYPE(virNetwork, vir_network, G_TYPE_OBJECT);
static void virNetworkFinalize(GObject *obj);
@@ -201,7 +215,6 @@ virDataTypesOnceInit(void)
DECLARE_CLASS_LOCKABLE(virConnect);
DECLARE_CLASS_LOCKABLE(virConnectCloseCallbackData);
DECLARE_CLASS(virDomain);
- DECLARE_CLASS(virInterface);
DECLARE_CLASS(virNodeDevice);
DECLARE_CLASS(virSecret);
DECLARE_CLASS(virStream);
@@ -553,42 +566,37 @@ virNetworkPortFinalize(GObject *obj)
* @mac: pointer to the mac
*
* Allocates a new interface object. When the object is no longer needed,
- * virObjectUnref() must be called in order to not leak data.
+ * g_object_unref() must be called in order to not leak data.
*
* Returns a pointer to the interface object, or NULL on error.
*/
virInterfacePtr
virGetInterface(virConnectPtr conn, const char *name, const char *mac)
{
- virInterfacePtr ret = NULL;
+ g_autoptr(virInterface) ret = NULL;
if (virDataTypesInitialize() < 0)
return NULL;
- virCheckConnectGoto(conn, error);
- virCheckNonNullArgGoto(name, error);
+ virCheckConnectReturn(conn, NULL);
+ virCheckNonNullArgReturn(name, NULL);
/* a NULL mac from caller is okay. Treat it as blank */
if (mac == NULL)
mac = "";
- if (!(ret = virObjectNew(virInterfaceClass)))
- goto error;
+ ret = VIR_INTERFACE(g_object_new(VIR_TYPE_INTERFACE, NULL));
ret->name = g_strdup(name);
ret->mac = g_strdup(mac);
ret->conn = virObjectRef(conn);
- return ret;
-
- error:
- virObjectUnref(ret);
- return NULL;
+ return g_steal_pointer(&ret);
}
/**
- * virInterfaceDispose:
+ * virInterfaceFinalize:
* @obj: the interface to release
*
* Unconditionally release all memory associated with an interface.
@@ -598,14 +606,16 @@ virGetInterface(virConnectPtr conn, const char *name, const char
*mac)
* which may also be released if its ref count hits zero.
*/
static void
-virInterfaceDispose(void *obj)
+virInterfaceFinalize(GObject *obj)
{
- virInterfacePtr iface = obj;
+ virInterfacePtr iface = VIR_INTERFACE(obj);
VIR_DEBUG("release interface %p %s", iface, iface->name);
VIR_FREE(iface->name);
VIR_FREE(iface->mac);
virObjectUnref(iface->conn);
+
+ G_OBJECT_CLASS(vir_interface_parent_class)->finalize(obj);
}
diff --git a/src/datatypes.h b/src/datatypes.h
index a544a7a347..c68a0e9265 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -32,7 +32,6 @@
extern virClassPtr virConnectClass;
extern virClassPtr virDomainClass;
-extern virClassPtr virInterfaceClass;
extern virClassPtr virNodeDeviceClass;
extern virClassPtr virSecretClass;
extern virClassPtr virStreamClass;
@@ -54,6 +53,9 @@ G_DECLARE_FINAL_TYPE(virDomainSnapshot,
DOMAIN_SNAPSHOT,
GObject);
+#define VIR_TYPE_INTERFACE vir_interface_get_type()
+G_DECLARE_FINAL_TYPE(virInterface, vir_interface, VIR, INTERFACE, GObject);
+
#define VIR_TYPE_NETWORK vir_network_get_type()
G_DECLARE_FINAL_TYPE(virNetwork, vir_network, VIR, NETWORK, GObject);
@@ -176,8 +178,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT,
GObject);
#define virCheckInterfaceReturn(obj, retval) \
do { \
- virInterfacePtr _iface = (obj); \
- if (!virObjectIsClass(_iface, virInterfaceClass) || \
+ virInterfacePtr _iface = VIR_INTERFACE(obj); \
+ if (!G_IS_OBJECT(_iface) || !(G_OBJECT_TYPE(_iface) == VIR_TYPE_INTERFACE) || \
!virObjectIsClass(_iface->conn, virConnectClass)) { \
virReportErrorHelper(VIR_FROM_INTERFACE, \
VIR_ERR_INVALID_INTERFACE, \
@@ -670,7 +672,7 @@ struct _virNetworkPort {
* Internal structure associated to a physical host interface
*/
struct _virInterface {
- virObject parent;
+ GObject parent;
virConnectPtr conn; /* pointer back to the connection */
char *name; /* the network external name */
char *mac; /* the interface MAC address */
diff --git a/src/interface/interface_backend_netcf.c
b/src/interface/interface_backend_netcf.c
index dd0c1481d9..dbf21088fd 100644
--- a/src/interface/interface_backend_netcf.c
+++ b/src/interface/interface_backend_netcf.c
@@ -740,7 +740,7 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
if (tmp_iface_objs) {
for (i = 0; i < niface_objs; i++)
- virObjectUnref(tmp_iface_objs[i]);
+ g_object_unref(tmp_iface_objs[i]);
VIR_FREE(tmp_iface_objs);
}
diff --git a/src/interface/interface_backend_udev.c
b/src/interface/interface_backend_udev.c
index e388f98536..6fc9ca840e 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -421,7 +421,7 @@ udevConnectListAllInterfaces(virConnectPtr conn,
if (ifaces) {
for (tmp_count = 0; tmp_count < count; tmp_count++)
- virObjectUnref(ifaces_list[tmp_count]);
+ g_object_unref(ifaces_list[tmp_count]);
}
VIR_FREE(ifaces_list);
diff --git a/src/libvirt-interface.c b/src/libvirt-interface.c
index 2d2df68131..0fd0ce7154 100644
--- a/src/libvirt-interface.c
+++ b/src/libvirt-interface.c
@@ -642,13 +642,13 @@ virInterfaceDestroy(virInterfacePtr iface, unsigned int flags)
int
virInterfaceRef(virInterfacePtr iface)
{
- VIR_DEBUG("iface=%p refs=%d", iface, iface ? iface->parent.u.s.refs :
0);
+ VIR_DEBUG("iface=%p", iface);
virResetLastError();
virCheckInterfaceReturn(iface, -1);
- virObjectRef(iface);
+ g_object_ref(iface);
return 0;
}
@@ -671,7 +671,7 @@ virInterfaceFree(virInterfacePtr iface)
virCheckInterfaceReturn(iface, -1);
- virObjectUnref(iface);
+ g_object_unref(iface);
return 0;
}
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 9530b7a254..a5e4b00a0e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1364,7 +1364,6 @@ virGetSecret;
virGetStoragePool;
virGetStorageVol;
virGetStream;
-virInterfaceClass;
virNewConnectCloseCallbackData;
virNodeDeviceClass;
virSecretClass;
--
2.25.1