[PATCH 20/36] datatypes: convert virNetworkPort to GObject

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx>
---
 src/conf/domain_conf.c              |  6 ++---
 src/conf/virnetworkobj.c            |  7 +++---
 src/datatypes.c                     | 37 +++++++++++++++++++----------
 src/datatypes.h                     | 15 ++++++------
 src/libvirt-network.c               |  7 +++---
 src/libvirt_private.syms            |  1 -
 src/remote/remote_daemon_dispatch.c |  2 +-
 7 files changed, 43 insertions(+), 32 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 772d9ae0a8..f3a8a36eb2 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -31541,7 +31541,7 @@ virDomainNetReleaseActualDevice(virConnectPtr conn,
                                 virDomainNetDefPtr iface)
 {
     g_autoptr(virNetwork) net = NULL;
-    virNetworkPortPtr port = NULL;
+    g_autoptr(virNetworkPort) port = NULL;
     int ret = -1;
 
     /* Port might not exist if a failure occurred during VM startup */
@@ -31560,7 +31560,6 @@ virDomainNetReleaseActualDevice(virConnectPtr conn,
         goto cleanup;
 
  cleanup:
-    virObjectUnref(port);
     return ret;
 }
 
@@ -31614,7 +31613,7 @@ virDomainNetBandwidthUpdate(virDomainNetDefPtr iface,
                             virNetDevBandwidthPtr newBandwidth)
 {
     g_autoptr(virNetwork) net = NULL;
-    virNetworkPortPtr port = NULL;
+    g_autoptr(virNetworkPort) port = NULL;
     virTypedParameterPtr params = NULL;
     int nparams = 0;
     virConnectPtr conn = NULL;
@@ -31639,7 +31638,6 @@ virDomainNetBandwidthUpdate(virDomainNetDefPtr iface,
  cleanup:
     virObjectUnref(conn);
     virTypedParamsFree(params, nparams);
-    virObjectUnref(port);
     return ret;
 }
 
diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index 762c9d9159..fba2587fd8 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -1825,9 +1825,10 @@ virNetworkObjPortListExport(virNetworkPtr net,
 
     ret = data.nports;
  cleanup:
-    while (data.ports && data.nports)
-        virObjectUnref(data.ports[--data.nports]);
-
+    while (data.ports && data.nports) {
+        if (data.ports[--data.nports])
+            g_object_unref(data.ports[data.nports]);
+    }
     VIR_FREE(data.ports);
     return ret;
 }
diff --git a/src/datatypes.c b/src/datatypes.c
index 15130ca0fa..e715c37306 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -37,7 +37,6 @@ virClassPtr virConnectClass;
 virClassPtr virConnectCloseCallbackDataClass;
 virClassPtr virDomainClass;
 virClassPtr virInterfaceClass;
-virClassPtr virNetworkPortClass;
 virClassPtr virNodeDeviceClass;
 virClassPtr virSecretClass;
 virClassPtr virStreamClass;
@@ -48,7 +47,6 @@ static void virConnectDispose(void *obj);
 static void virConnectCloseCallbackDataDispose(void *obj);
 static void virDomainDispose(void *obj);
 static void virInterfaceDispose(void *obj);
-static void virNetworkPortDispose(void *obj);
 static void virNodeDeviceDispose(void *obj);
 static void virSecretDispose(void *obj);
 static void virStreamDispose(void *obj);
@@ -103,6 +101,22 @@ vir_network_class_init(virNetworkClass *klass)
     obj->finalize = virNetworkFinalize;
 }
 
+G_DEFINE_TYPE(virNetworkPort, vir_network_port, G_TYPE_OBJECT);
+static void virNetworkPortFinalize(GObject *obj);
+
+static void
+vir_network_port_init(virNetworkPort *np G_GNUC_UNUSED)
+{
+}
+
+static void
+vir_network_port_class_init(virNetworkPortClass *klass)
+{
+    GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+    obj->finalize = virNetworkPortFinalize;
+}
+
 G_DEFINE_TYPE(virNWFilter, vir_nw_filter, G_TYPE_OBJECT);
 static void virNWFilterFinalize(GObject *obj);
 
@@ -188,7 +202,6 @@ virDataTypesOnceInit(void)
     DECLARE_CLASS_LOCKABLE(virConnectCloseCallbackData);
     DECLARE_CLASS(virDomain);
     DECLARE_CLASS(virInterface);
-    DECLARE_CLASS(virNetworkPort);
     DECLARE_CLASS(virNodeDevice);
     DECLARE_CLASS(virSecret);
     DECLARE_CLASS(virStream);
@@ -482,14 +495,14 @@ virNetworkFinalize(GObject *obj)
  * @uuid: pointer to the uuid
  *
  * Allocates a new network port 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 port object, or NULL on error.
  */
 virNetworkPortPtr
 virGetNetworkPort(virNetworkPtr net, const unsigned char *uuid)
 {
-    virNetworkPortPtr ret = NULL;
+    g_autoptr(virNetworkPort) ret = NULL;
 
     if (virDataTypesInitialize() < 0)
         return NULL;
@@ -497,21 +510,19 @@ virGetNetworkPort(virNetworkPtr net, const unsigned char *uuid)
     virCheckNetworkGoto(net, error);
     virCheckNonNullArgGoto(uuid, error);
 
-    if (!(ret = virObjectNew(virNetworkPortClass)))
-        goto error;
+    ret = VIR_NETWORK_PORT(g_object_new(VIR_TYPE_NETWORK_PORT, NULL));
 
     ret->net = g_object_ref(net);
     memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
 
-    return ret;
+    return g_steal_pointer(&ret);
 
  error:
-    virObjectUnref(ret);
     return NULL;
 }
 
 /**
- * virNetworkPortDispose:
+ * virNetworkPortFinalize:
  * @obj: the network port to release
  *
  * Unconditionally release all memory associated with a network port.
@@ -521,15 +532,17 @@ virGetNetworkPort(virNetworkPtr net, const unsigned char *uuid)
  * which may also be released if its ref count hits zero.
  */
 static void
-virNetworkPortDispose(void *obj)
+virNetworkPortFinalize(GObject *obj)
 {
-    virNetworkPortPtr port = obj;
+    virNetworkPortPtr port = VIR_NETWORK_PORT(obj);
     char uuidstr[VIR_UUID_STRING_BUFLEN];
 
     virUUIDFormat(port->uuid, uuidstr);
     VIR_DEBUG("release network port %p %s", port, uuidstr);
 
     g_object_unref(port->net);
+
+    G_OBJECT_CLASS(vir_network_port_parent_class)->finalize(obj);
 }
 
 
diff --git a/src/datatypes.h b/src/datatypes.h
index e91a6c71f4..a544a7a347 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -33,7 +33,6 @@
 extern virClassPtr virConnectClass;
 extern virClassPtr virDomainClass;
 extern virClassPtr virInterfaceClass;
-extern virClassPtr virNetworkPortClass;
 extern virClassPtr virNodeDeviceClass;
 extern virClassPtr virSecretClass;
 extern virClassPtr virStreamClass;
@@ -58,6 +57,9 @@ G_DECLARE_FINAL_TYPE(virDomainSnapshot,
 #define VIR_TYPE_NETWORK vir_network_get_type()
 G_DECLARE_FINAL_TYPE(virNetwork, vir_network, VIR, NETWORK, GObject);
 
+#define VIR_TYPE_NETWORK_PORT vir_network_port_get_type()
+G_DECLARE_FINAL_TYPE(virNetworkPort, vir_network_port, VIR, NETWORK_PORT, GObject);
+
 #define VIR_TYPE_NW_FILTER vir_nw_filter_get_type()
 G_DECLARE_FINAL_TYPE(virNWFilter, vir_nw_filter, VIR, NW_FILTER, GObject);
 
@@ -147,8 +149,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT, GObject);
 
 #define virCheckNetworkPortReturn(obj, retval) \
     do { \
-        virNetworkPortPtr _port = (obj); \
-        if (!virObjectIsClass(_port, virNetworkPortClass) || \
+        virNetworkPortPtr _port = VIR_NETWORK_PORT(obj); \
+        if (!G_IS_OBJECT(_port) || !(G_OBJECT_TYPE(_port) == VIR_TYPE_NETWORK_PORT) || \
             !G_IS_OBJECT(_port->net) || !(G_OBJECT_TYPE(_port->net) == VIR_TYPE_NETWORK)) { \
             virReportErrorHelper(VIR_FROM_NETWORK, \
                                  VIR_ERR_INVALID_NETWORK_PORT, \
@@ -161,8 +163,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT, GObject);
 
 #define virCheckNetworkPortGoto(obj, label) \
     do { \
-        virNetworkPortPtr _port = (obj); \
-        if (!virObjectIsClass(_port, virNetworkPortClass) || \
+        virNetworkPortPtr _port = VIR_NETWORK_PORT(obj); \
+        if (!G_IS_OBJECT(_port) || !(G_OBJECT_TYPE(_port) == VIR_TYPE_NETWORK_PORT) || \
             !G_IS_OBJECT(_port->net) || !(G_OBJECT_TYPE(_port->net) == VIR_TYPE_NETWORK)) { \
             virReportErrorHelper(VIR_FROM_NETWORK, \
                                  VIR_ERR_INVALID_NETWORK_PORT, \
@@ -655,12 +657,11 @@ struct _virNetwork {
 * Internal structure associated to a network port
 */
 struct _virNetworkPort {
-    virObject parent;
+    GObject parent;
     virNetworkPtr net;                   /* pointer back to the connection */
     unsigned char uuid[VIR_UUID_BUFLEN]; /* the network unique identifier */
 };
 
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetworkPort, virObjectUnref);
 
 
 /**
diff --git a/src/libvirt-network.c b/src/libvirt-network.c
index 3847617d4d..1ab499fb18 100644
--- a/src/libvirt-network.c
+++ b/src/libvirt-network.c
@@ -1688,7 +1688,7 @@ virNetworkPortFree(virNetworkPortPtr port)
 
     virCheckNetworkPortReturn(port, -1);
 
-    virObjectUnref(port);
+    g_object_unref(port);
     return 0;
 }
 
@@ -1713,13 +1713,12 @@ virNetworkPortFree(virNetworkPortPtr port)
 int
 virNetworkPortRef(virNetworkPortPtr port)
 {
-    VIR_DEBUG("port=%p refs=%d", port,
-              port ? port->parent.u.s.refs : 0);
+    VIR_DEBUG("port=%p", port);
 
     virResetLastError();
 
     virCheckNetworkPortReturn(port, -1);
 
-    virObjectRef(port);
+    g_object_ref(port);
     return 0;
 }
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8293a5e88d..9530b7a254 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1365,7 +1365,6 @@ virGetStoragePool;
 virGetStorageVol;
 virGetStream;
 virInterfaceClass;
-virNetworkPortClass;
 virNewConnectCloseCallbackData;
 virNodeDeviceClass;
 virSecretClass;
diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c
index ee6bbb24d0..9f5aee07cd 100644
--- a/src/remote/remote_daemon_dispatch.c
+++ b/src/remote/remote_daemon_dispatch.c
@@ -7199,7 +7199,7 @@ remoteDispatchNetworkPortGetParameters(virNetServerPtr server G_GNUC_UNUSED,
  cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(port);
+    g_object_unref(port);
     virTypedParamsFree(params, nparams);
     return rv;
 }
-- 
2.25.1






[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux