Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/conf/virnwfilterobj.c | 7 +-----
src/datatypes.c | 46 ++++++++++++++++++++++++---------------
src/datatypes.h | 10 +++++----
src/libvirt-nwfilter.c | 7 +++---
src/libvirt_private.syms | 2 +-
src/rpc/gendispatch.pl | 1 +
6 files changed, 40 insertions(+), 33 deletions(-)
diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c
index c9e224061d..c08dc7a5d6 100644
--- a/src/conf/virnwfilterobj.c
+++ b/src/conf/virnwfilterobj.c
@@ -472,12 +472,7 @@ virNWFilterObjListExport(virConnectPtr conn,
ret = nfilters;
cleanup:
- if (tmp_filters) {
- for (i = 0; i < nfilters; i ++)
- virObjectUnref(tmp_filters[i]);
- }
- VIR_FREE(tmp_filters);
-
+ virGObjectListFreeCount(tmp_filters, nfilters);
return ret;
}
diff --git a/src/datatypes.c b/src/datatypes.c
index 504e045bd6..06a13a724a 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -40,7 +40,6 @@ virClassPtr virInterfaceClass;
virClassPtr virNetworkClass;
virClassPtr virNetworkPortClass;
virClassPtr virNodeDeviceClass;
-virClassPtr virNWFilterClass;
virClassPtr virNWFilterBindingClass;
virClassPtr virSecretClass;
virClassPtr virStreamClass;
@@ -54,7 +53,6 @@ static void virInterfaceDispose(void *obj);
static void virNetworkDispose(void *obj);
static void virNetworkPortDispose(void *obj);
static void virNodeDeviceDispose(void *obj);
-static void virNWFilterDispose(void *obj);
static void virNWFilterBindingDispose(void *obj);
static void virSecretDispose(void *obj);
static void virStreamDispose(void *obj);
@@ -93,6 +91,22 @@ vir_domain_snapshot_class_init(virDomainSnapshotClass *klass)
obj->finalize = virDomainSnapshotFinalize;
}
+G_DEFINE_TYPE(virNWFilter, vir_nw_filter, G_TYPE_OBJECT);
+static void virNWFilterFinalize(GObject *obj);
+
+static void
+vir_nw_filter_init(virNWFilter *filter G_GNUC_UNUSED)
+{
+}
+
+static void
+vir_nw_filter_class_init(virNWFilterClass *klass)
+{
+ GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+ obj->finalize = virNWFilterFinalize;
+}
+
virClassPtr virAdmConnectClass;
virClassPtr virAdmConnectCloseCallbackDataClass;
@@ -149,7 +163,6 @@ virDataTypesOnceInit(void)
DECLARE_CLASS(virNetwork);
DECLARE_CLASS(virNetworkPort);
DECLARE_CLASS(virNodeDevice);
- DECLARE_CLASS(virNWFilter);
DECLARE_CLASS(virNWFilterBinding);
DECLARE_CLASS(virSecret);
DECLARE_CLASS(virStream);
@@ -883,7 +896,7 @@ virStreamDispose(void *obj)
* @uuid: pointer to the uuid
*
* Allocates a new network filter 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 filter object, or NULL on error.
*/
@@ -891,17 +904,16 @@ virNWFilterPtr
virGetNWFilter(virConnectPtr conn, const char *name,
const unsigned char *uuid)
{
- virNWFilterPtr ret = NULL;
+ g_autoptr(virNWFilter) 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(virNWFilterClass)))
- goto error;
+ ret = VIR_NW_FILTER(g_object_new(VIR_TYPE_NW_FILTER, NULL));
ret->name = g_strdup(name);
@@ -909,16 +921,12 @@ virGetNWFilter(virConnectPtr conn, const char *name,
ret->conn = virObjectRef(conn);
- return ret;
-
- error:
- virObjectUnref(ret);
- return NULL;
+ return g_steal_pointer(&ret);
}
/**
- * virNWFilterDispose:
+ * virNWFilterFinalize:
* @obj: the network filter to release
*
* Unconditionally release all memory associated with a nwfilter.
@@ -928,9 +936,9 @@ virGetNWFilter(virConnectPtr conn, const char *name,
* which may also be released if its ref count hits zero.
*/
static void
-virNWFilterDispose(void *obj)
+virNWFilterFinalize(GObject *obj)
{
- virNWFilterPtr nwfilter = obj;
+ virNWFilterPtr nwfilter = VIR_NW_FILTER(obj);
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(nwfilter->uuid, uuidstr);
@@ -938,6 +946,8 @@ virNWFilterDispose(void *obj)
VIR_FREE(nwfilter->name);
virObjectUnref(nwfilter->conn);
+
+ G_OBJECT_CLASS(vir_nw_filter_parent_class)->finalize(obj);
}
diff --git a/src/datatypes.h b/src/datatypes.h
index 9dfb18147e..b51514d579 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -36,7 +36,6 @@ extern virClassPtr virInterfaceClass;
extern virClassPtr virNetworkClass;
extern virClassPtr virNetworkPortClass;
extern virClassPtr virNodeDeviceClass;
-extern virClassPtr virNWFilterClass;
extern virClassPtr virNWFilterBindingClass;
extern virClassPtr virSecretClass;
extern virClassPtr virStreamClass;
@@ -57,6 +56,9 @@ G_DECLARE_FINAL_TYPE(virDomainSnapshot,
DOMAIN_SNAPSHOT,
GObject);
+#define VIR_TYPE_NW_FILTER vir_nw_filter_get_type()
+G_DECLARE_FINAL_TYPE(virNWFilter, vir_nw_filter, VIR, NW_FILTER, GObject);
+
extern virClassPtr virAdmConnectClass;
#define VIR_TYPE_ADM_SERVER vir_adm_server_get_type()
@@ -311,8 +313,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT,
GObject);
#define virCheckNWFilterReturn(obj, retval) \
do { \
- virNWFilterPtr _nw = (obj); \
- if (!virObjectIsClass(_nw, virNWFilterClass) || \
+ virNWFilterPtr _nw = VIR_NW_FILTER(obj); \
+ if (_nw == NULL || \
!virObjectIsClass(_nw->conn, virConnectClass)) { \
virReportErrorHelper(VIR_FROM_NWFILTER, \
VIR_ERR_INVALID_NWFILTER, \
@@ -784,7 +786,7 @@ struct _virDomainSnapshot {
* Internal structure associated to a network filter
*/
struct _virNWFilter {
- virObject parent;
+ GObject parent;
virConnectPtr conn; /* pointer back to the connection */
char *name; /* the network filter external name */
unsigned char uuid[VIR_UUID_BUFLEN]; /* the network filter unique identifier */
diff --git a/src/libvirt-nwfilter.c b/src/libvirt-nwfilter.c
index d28220db8a..cd3f5759b7 100644
--- a/src/libvirt-nwfilter.c
+++ b/src/libvirt-nwfilter.c
@@ -281,7 +281,7 @@ virNWFilterFree(virNWFilterPtr nwfilter)
virCheckNWFilterReturn(nwfilter, -1);
- virObjectUnref(nwfilter);
+ g_object_unref(nwfilter);
return 0;
}
@@ -503,14 +503,13 @@ virNWFilterGetXMLDesc(virNWFilterPtr nwfilter, unsigned int flags)
int
virNWFilterRef(virNWFilterPtr nwfilter)
{
- VIR_DEBUG("nwfilter=%p refs=%d", nwfilter,
- nwfilter ? nwfilter->parent.u.s.refs : 0);
+ VIR_DEBUG("nwfilter=%p", nwfilter);
virResetLastError();
virCheckNWFilterReturn(nwfilter, -1);
- virObjectRef(nwfilter);
+ g_object_ref(nwfilter);
return 0;
}
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index be779a2d33..3080063199 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1358,6 +1358,7 @@ virCPUx86FeatureFilterSelectMSR;
# datatypes.h
vir_domain_checkpoint_get_type;
vir_domain_snapshot_get_type;
+vir_nw_filter_get_type;
virConnectClass;
virConnectCloseCallbackDataCall;
virConnectCloseCallbackDataClass;
@@ -1384,7 +1385,6 @@ virNetworkClass;
virNetworkPortClass;
virNewConnectCloseCallbackData;
virNodeDeviceClass;
-virNWFilterClass;
virSecretClass;
virStoragePoolClass;
virStorageVolClass;
diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index bca3b33e80..b51e2715ee 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -198,6 +198,7 @@ my %gobject_impl = (
virAdmServer => 1,
virDomainCheckpoint => 1,
virDomainSnapshot => 1,
+ virNWFilter => 1,
);
sub use_gobject {
--
2.26.2