Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/conf/domain_conf.c | 6 ++--
src/conf/network_event.c | 2 +-
src/conf/virnetworkobj.c | 7 ++--
src/datatypes.c | 50 +++++++++++++++++------------
src/datatypes.h | 33 ++++++++++---------
src/libvirt-network.c | 7 ++--
src/libvirt_private.syms | 1 -
src/libxl/libxl_conf.c | 3 +-
src/libxl/xen_common.c | 2 +-
src/remote/remote_daemon_dispatch.c | 6 ++--
src/remote/remote_driver.c | 4 +--
11 files changed, 64 insertions(+), 57 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a29e6681a5..772d9ae0a8 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -31540,7 +31540,7 @@ virDomainNetReleaseActualDevice(virConnectPtr conn,
virDomainDefPtr dom G_GNUC_UNUSED,
virDomainNetDefPtr iface)
{
- virNetworkPtr net = NULL;
+ g_autoptr(virNetwork) net = NULL;
virNetworkPortPtr port = NULL;
int ret = -1;
@@ -31561,7 +31561,6 @@ virDomainNetReleaseActualDevice(virConnectPtr conn,
cleanup:
virObjectUnref(port);
- virObjectUnref(net);
return ret;
}
@@ -31614,7 +31613,7 @@ int
virDomainNetBandwidthUpdate(virDomainNetDefPtr iface,
virNetDevBandwidthPtr newBandwidth)
{
- virNetworkPtr net = NULL;
+ g_autoptr(virNetwork) net = NULL;
virNetworkPortPtr port = NULL;
virTypedParameterPtr params = NULL;
int nparams = 0;
@@ -31641,7 +31640,6 @@ virDomainNetBandwidthUpdate(virDomainNetDefPtr iface,
virObjectUnref(conn);
virTypedParamsFree(params, nparams);
virObjectUnref(port);
- virObjectUnref(net);
return ret;
}
diff --git a/src/conf/network_event.c b/src/conf/network_event.c
index 41cabe340a..5a8f138dfd 100644
--- a/src/conf/network_event.c
+++ b/src/conf/network_event.c
@@ -111,7 +111,7 @@ virNetworkEventDispatchDefaultFunc(virConnectPtr conn,
VIR_WARN("Unexpected event ID %d", event->eventID);
cleanup:
- virObjectUnref(net);
+ g_object_unref(net);
}
diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index b2affaacd3..762c9d9159 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -1429,9 +1429,10 @@ virNetworkObjListExport(virConnectPtr conn,
ret = data.nnets;
cleanup:
virObjectRWUnlock(netobjs);
- while (data.nets && data.nnets)
- virObjectUnref(data.nets[--data.nnets]);
-
+ while (data.nets && data.nnets) {
+ if (data.nets[--data.nnets])
+ g_object_unref(data.nets[data.nnets]);
+ }
VIR_FREE(data.nets);
return ret;
}
diff --git a/src/datatypes.c b/src/datatypes.c
index b9879cfb9e..15130ca0fa 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -37,7 +37,6 @@ virClassPtr virConnectClass;
virClassPtr virConnectCloseCallbackDataClass;
virClassPtr virDomainClass;
virClassPtr virInterfaceClass;
-virClassPtr virNetworkClass;
virClassPtr virNetworkPortClass;
virClassPtr virNodeDeviceClass;
virClassPtr virSecretClass;
@@ -49,7 +48,6 @@ static void virConnectDispose(void *obj);
static void virConnectCloseCallbackDataDispose(void *obj);
static void virDomainDispose(void *obj);
static void virInterfaceDispose(void *obj);
-static void virNetworkDispose(void *obj);
static void virNetworkPortDispose(void *obj);
static void virNodeDeviceDispose(void *obj);
static void virSecretDispose(void *obj);
@@ -89,6 +87,22 @@ vir_domain_snapshot_class_init(virDomainSnapshotClass *klass)
obj->finalize = virDomainSnapshotFinalize;
}
+G_DEFINE_TYPE(virNetwork, vir_network, G_TYPE_OBJECT);
+static void virNetworkFinalize(GObject *obj);
+
+static void
+vir_network_init(virNetwork *net G_GNUC_UNUSED)
+{
+}
+
+static void
+vir_network_class_init(virNetworkClass *klass)
+{
+ GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+ obj->finalize = virNetworkFinalize;
+}
+
G_DEFINE_TYPE(virNWFilter, vir_nw_filter, G_TYPE_OBJECT);
static void virNWFilterFinalize(GObject *obj);
@@ -174,7 +188,6 @@ virDataTypesOnceInit(void)
DECLARE_CLASS_LOCKABLE(virConnectCloseCallbackData);
DECLARE_CLASS(virDomain);
DECLARE_CLASS(virInterface);
- DECLARE_CLASS(virNetwork);
DECLARE_CLASS(virNetworkPort);
DECLARE_CLASS(virNodeDevice);
DECLARE_CLASS(virSecret);
@@ -411,39 +424,34 @@ virDomainDispose(void *obj)
* @uuid: pointer to the uuid
*
* Allocates a new network 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 network object, or NULL on error.
*/
virNetworkPtr
virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid)
{
- virNetworkPtr ret = NULL;
+ g_autoptr(virNetwork) ret = NULL;
if (virDataTypesInitialize() < 0)
return NULL;
- virCheckConnectGoto(conn, error);
- virCheckNonNullArgGoto(name, error);
- virCheckNonNullArgGoto(uuid, error);
+ virCheckConnectReturn(conn, NULL);
+ virCheckNonNullArgReturn(name, NULL);
+ virCheckNonNullArgReturn(uuid, NULL);
- if (!(ret = virObjectNew(virNetworkClass)))
- goto error;
+ ret = VIR_NETWORK(g_object_new(VIR_TYPE_NETWORK, NULL));
ret->name = g_strdup(name);
ret->conn = virObjectRef(conn);
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
- return ret;
-
- error:
- virObjectUnref(ret);
- return NULL;
+ return g_steal_pointer(&ret);
}
/**
- * virNetworkDispose:
+ * virNetworkFinalize:
* @obj: the network to release
*
* Unconditionally release all memory associated with a network.
@@ -453,9 +461,9 @@ virGetNetwork(virConnectPtr conn, const char *name, const unsigned
char *uuid)
* which may also be released if its ref count hits zero.
*/
static void
-virNetworkDispose(void *obj)
+virNetworkFinalize(GObject *obj)
{
- virNetworkPtr network = obj;
+ virNetworkPtr network = VIR_NETWORK(obj);
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(network->uuid, uuidstr);
@@ -463,6 +471,8 @@ virNetworkDispose(void *obj)
VIR_FREE(network->name);
virObjectUnref(network->conn);
+
+ G_OBJECT_CLASS(vir_network_parent_class)->finalize(obj);
}
@@ -490,7 +500,7 @@ virGetNetworkPort(virNetworkPtr net, const unsigned char *uuid)
if (!(ret = virObjectNew(virNetworkPortClass)))
goto error;
- ret->net = virObjectRef(net);
+ ret->net = g_object_ref(net);
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
return ret;
@@ -519,7 +529,7 @@ virNetworkPortDispose(void *obj)
virUUIDFormat(port->uuid, uuidstr);
VIR_DEBUG("release network port %p %s", port, uuidstr);
- virObjectUnref(port->net);
+ g_object_unref(port->net);
}
diff --git a/src/datatypes.h b/src/datatypes.h
index 87c6a1366e..e91a6c71f4 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -33,7 +33,6 @@
extern virClassPtr virConnectClass;
extern virClassPtr virDomainClass;
extern virClassPtr virInterfaceClass;
-extern virClassPtr virNetworkClass;
extern virClassPtr virNetworkPortClass;
extern virClassPtr virNodeDeviceClass;
extern virClassPtr virSecretClass;
@@ -49,13 +48,6 @@ G_DECLARE_FINAL_TYPE(virDomainCheckpoint,
DOMAIN_CHECKPOINT,
GObject);
-#define VIR_TYPE_NW_FILTER_BINDING vir_nw_filter_binding_get_type()
-G_DECLARE_FINAL_TYPE(virNWFilterBinding,
- vir_nw_filter_binding,
- VIR,
- NW_FILTER_BINDING,
- GObject);
-
#define VIR_TYPE_DOMAIN_SNAPSHOT vir_domain_snapshot_get_type()
G_DECLARE_FINAL_TYPE(virDomainSnapshot,
vir_domain_snapshot,
@@ -63,9 +55,19 @@ G_DECLARE_FINAL_TYPE(virDomainSnapshot,
DOMAIN_SNAPSHOT,
GObject);
+#define VIR_TYPE_NETWORK vir_network_get_type()
+G_DECLARE_FINAL_TYPE(virNetwork, vir_network, VIR, NETWORK, GObject);
+
#define VIR_TYPE_NW_FILTER vir_nw_filter_get_type()
G_DECLARE_FINAL_TYPE(virNWFilter, vir_nw_filter, VIR, NW_FILTER, GObject);
+#define VIR_TYPE_NW_FILTER_BINDING vir_nw_filter_binding_get_type()
+G_DECLARE_FINAL_TYPE(virNWFilterBinding,
+ vir_nw_filter_binding,
+ VIR,
+ NW_FILTER_BINDING,
+ GObject);
+
extern virClassPtr virAdmConnectClass;
#define VIR_TYPE_ADM_SERVER vir_adm_server_get_type()
@@ -119,8 +121,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT,
GObject);
#define virCheckNetworkReturn(obj, retval) \
do { \
- virNetworkPtr _net = (obj); \
- if (!virObjectIsClass(_net, virNetworkClass) || \
+ virNetworkPtr _net = VIR_NETWORK(obj); \
+ if (!G_IS_OBJECT(_net) || !(G_OBJECT_TYPE(_net) == VIR_TYPE_NETWORK) || \
!virObjectIsClass(_net->conn, virConnectClass)) { \
virReportErrorHelper(VIR_FROM_NETWORK, \
VIR_ERR_INVALID_NETWORK, \
@@ -132,8 +134,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT,
GObject);
} while (0)
#define virCheckNetworkGoto(obj, label) \
do { \
- virNetworkPtr _net = (obj); \
- if (!virObjectIsClass(_net, virNetworkClass) || \
+ virNetworkPtr _net = VIR_NETWORK(obj); \
+ if (!G_IS_OBJECT(_net) || !(G_OBJECT_TYPE(_net) == VIR_TYPE_NETWORK) || \
!virObjectIsClass(_net->conn, virConnectClass)) { \
virReportErrorHelper(VIR_FROM_NETWORK, \
VIR_ERR_INVALID_NETWORK, \
@@ -147,7 +149,7 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT,
GObject);
do { \
virNetworkPortPtr _port = (obj); \
if (!virObjectIsClass(_port, virNetworkPortClass) || \
- !virObjectIsClass(_port->net, virNetworkClass)) { \
+ !G_IS_OBJECT(_port->net) || !(G_OBJECT_TYPE(_port->net) ==
VIR_TYPE_NETWORK)) { \
virReportErrorHelper(VIR_FROM_NETWORK, \
VIR_ERR_INVALID_NETWORK_PORT, \
__FILE__, __FUNCTION__, __LINE__, \
@@ -161,7 +163,7 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT,
GObject);
do { \
virNetworkPortPtr _port = (obj); \
if (!virObjectIsClass(_port, virNetworkPortClass) || \
- !virObjectIsClass(_port->net, virNetworkClass)) { \
+ !G_IS_OBJECT(_port->net) || !(G_OBJECT_TYPE(_port->net) ==
VIR_TYPE_NETWORK)) { \
virReportErrorHelper(VIR_FROM_NETWORK, \
VIR_ERR_INVALID_NETWORK_PORT, \
__FILE__, __FUNCTION__, __LINE__, \
@@ -639,13 +641,12 @@ struct _virDomain {
* Internal structure associated to a network
*/
struct _virNetwork {
- virObject parent;
+ GObject parent;
virConnectPtr conn; /* pointer back to the connection */
char *name; /* the network external name */
unsigned char uuid[VIR_UUID_BUFLEN]; /* the network unique identifier */
};
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetwork, virObjectUnref);
/**
diff --git a/src/libvirt-network.c b/src/libvirt-network.c
index 09e24fb0a8..3847617d4d 100644
--- a/src/libvirt-network.c
+++ b/src/libvirt-network.c
@@ -654,7 +654,7 @@ virNetworkFree(virNetworkPtr network)
virCheckNetworkReturn(network, -1);
- virObjectUnref(network);
+ g_object_unref(network);
return 0;
}
@@ -679,14 +679,13 @@ virNetworkFree(virNetworkPtr network)
int
virNetworkRef(virNetworkPtr network)
{
- VIR_DEBUG("network=%p refs=%d", network,
- network ? network->parent.u.s.refs : 0);
+ VIR_DEBUG("network=%p", network);
virResetLastError();
virCheckNetworkReturn(network, -1);
- virObjectRef(network);
+ g_object_ref(network);
return 0;
}
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index aff0688548..8293a5e88d 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1365,7 +1365,6 @@ virGetStoragePool;
virGetStorageVol;
virGetStream;
virInterfaceClass;
-virNetworkClass;
virNetworkPortClass;
virNewConnectCloseCallbackData;
virNodeDeviceClass;
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 21089c33d7..d9377438d9 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1198,7 +1198,7 @@ libxlMakeNic(virDomainDefPtr def,
bool attach)
{
virDomainNetType actual_type = virDomainNetGetActualType(l_nic);
- virNetworkPtr network = NULL;
+ g_autoptr(virNetwork) network = NULL;
virConnectPtr conn = NULL;
const virNetDevBandwidth *actual_bw;
const virNetDevVPortProfile *port_profile;
@@ -1397,7 +1397,6 @@ libxlMakeNic(virDomainDefPtr def,
cleanup:
virBufferFreeAndReset(&buf);
- virObjectUnref(network);
virObjectUnref(conn);
return ret;
diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c
index 9a385eba0d..94863245fe 100644
--- a/src/libxl/xen_common.c
+++ b/src/libxl/xen_common.c
@@ -1717,7 +1717,7 @@ xenFormatNet(virConnectPtr conn,
return -1;
}
bridge = virNetworkGetBridgeName(network);
- virObjectUnref(network);
+ g_object_unref(network);
if (!bridge) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("network %s is not active"),
diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c
index c024211ea5..ee6bbb24d0 100644
--- a/src/remote/remote_daemon_dispatch.c
+++ b/src/remote/remote_daemon_dispatch.c
@@ -6075,7 +6075,7 @@ remoteDispatchConnectNetworkEventRegisterAny(virNetServerPtr server
G_GNUC_UNUSE
remoteEventCallbackFree(callback);
if (rv < 0)
virNetMessageSaveError(rerr);
- virObjectUnref(net);
+ g_object_unref(net);
return rv;
}
@@ -6807,7 +6807,7 @@ remoteDispatchNetworkGetDHCPLeases(virNetServerPtr server
G_GNUC_UNUSED,
for (i = 0; i < nleases; i++)
virNetworkDHCPLeaseFree(leases[i]);
VIR_FREE(leases);
- virObjectUnref(net);
+ g_object_unref(net);
return rv;
}
@@ -7234,7 +7234,7 @@ get_nonnull_network_port(virConnectPtr conn,
remote_nonnull_network_port port)
if (!net)
return NULL;
ret = virGetNetworkPort(net, BAD_CAST port.uuid);
- virObjectUnref(net);
+ g_object_unref(net);
return ret;
}
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 5051c583d7..f19061200c 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -5471,7 +5471,7 @@ remoteNetworkBuildEventLifecycle(virNetClientProgramPtr prog
G_GNUC_UNUSED,
event = virNetworkEventLifecycleNew(net->name, net->uuid, msg->event,
msg->detail);
- virObjectUnref(net);
+ g_object_unref(net);
virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackID);
}
@@ -8281,7 +8281,7 @@ get_nonnull_network_port(virConnectPtr conn,
remote_nonnull_network_port port)
if (!net)
return NULL;
ret = virGetNetworkPort(net, BAD_CAST port.uuid);
- virObjectUnref(net);
+ g_object_unref(net);
return ret;
}
--
2.25.1