Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/conf/virnwfilterbindingobjlist.c | 2 +-
src/datatypes.c | 68 +++++++++++++++++++---------
src/datatypes.h | 14 ++++--
src/libvirt-nwfilter.c | 7 ++-
src/libvirt_private.syms | 1 +
src/nwfilter/nwfilter_driver.c | 3 +-
src/rpc/gendispatch.pl | 1 +
7 files changed, 64 insertions(+), 32 deletions(-)
diff --git a/src/conf/virnwfilterbindingobjlist.c b/src/conf/virnwfilterbindingobjlist.c
index 97e4d3c49b..4f4f295b92 100644
--- a/src/conf/virnwfilterbindingobjlist.c
+++ b/src/conf/virnwfilterbindingobjlist.c
@@ -489,7 +489,7 @@ virNWFilterBindingObjListExport(virNWFilterBindingObjListPtr
bindings,
cleanup:
virObjectListFreeCount(bindingobjs, nbindings);
if (ret < 0) {
- virObjectListFreeCount(*bindinglist, nbindings);
+ virGObjectListFreeCount(*bindinglist, nbindings);
*bindinglist = NULL;
}
return ret;
diff --git a/src/datatypes.c b/src/datatypes.c
index e9f6cafd72..a562b5da5f 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -40,7 +40,6 @@ virClassPtr virInterfaceClass;
virClassPtr virNetworkClass;
virClassPtr virNetworkPortClass;
virClassPtr virNodeDeviceClass;
-virClassPtr virNWFilterBindingClass;
virClassPtr virSecretClass;
virClassPtr virStreamClass;
virClassPtr virStorageVolClass;
@@ -53,7 +52,6 @@ static void virInterfaceDispose(void *obj);
static void virNetworkDispose(void *obj);
static void virNetworkPortDispose(void *obj);
static void virNodeDeviceDispose(void *obj);
-static void virNWFilterBindingDispose(void *obj);
static void virSecretDispose(void *obj);
static void virStreamDispose(void *obj);
static void virStorageVolDispose(void *obj);
@@ -113,6 +111,24 @@ vir_nw_filter_class_init(virNWFilterClass *klass)
obj->finalize = virNWFilterFinalize;
}
+G_DEFINE_TYPE(virNWFilterBinding, vir_nw_filter_binding, G_TYPE_OBJECT);
+static void virNWFilterBindingDispose(GObject *obj);
+static void virNWFilterBindingFinalize(GObject *obj);
+
+static void
+vir_nw_filter_binding_init(virNWFilterBinding *bdg G_GNUC_UNUSED)
+{
+}
+
+static void
+vir_nw_filter_binding_class_init(virNWFilterBindingClass *klass)
+{
+ GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+ obj->dispose = virNWFilterBindingDispose;
+ obj->finalize = virNWFilterBindingFinalize;
+}
+
virClassPtr virAdmConnectClass;
virClassPtr virAdmConnectCloseCallbackDataClass;
@@ -171,7 +187,6 @@ virDataTypesOnceInit(void)
DECLARE_CLASS(virNetwork);
DECLARE_CLASS(virNetworkPort);
DECLARE_CLASS(virNodeDevice);
- DECLARE_CLASS(virNWFilterBinding);
DECLARE_CLASS(virSecret);
DECLARE_CLASS(virStream);
DECLARE_CLASS(virStorageVol);
@@ -980,7 +995,7 @@ virNWFilterFinalize(GObject *obj)
* @filtername: name of the network filter
*
* Allocates a new network filter binding object. When the object is no longer
- * needed, virObjectUnref() must be called in order to not leak data.
+ * needed, g_object_unref() must be called in order to not leak data.
*
* Returns a pointer to the network filter binding object, or NULL on error.
*/
@@ -988,16 +1003,15 @@ virNWFilterBindingPtr
virGetNWFilterBinding(virConnectPtr conn, const char *portdev,
const char *filtername)
{
- virNWFilterBindingPtr ret = NULL;
+ g_autoptr(virNWFilterBinding) ret = NULL;
if (virDataTypesInitialize() < 0)
return NULL;
- virCheckConnectGoto(conn, error);
- virCheckNonNullArgGoto(portdev, error);
+ virCheckConnectReturn(conn, NULL);
+ virCheckNonNullArgReturn(portdev, NULL);
- if (!(ret = virObjectNew(virNWFilterBindingClass)))
- goto error;
+ ret = VIR_NW_FILTER_BINDING(g_object_new(VIR_TYPE_NW_FILTER_BINDING, NULL));
ret->portdev = g_strdup(portdev);
@@ -1005,11 +1019,7 @@ virGetNWFilterBinding(virConnectPtr conn, const char *portdev,
ret->conn = virObjectRef(conn);
- return ret;
-
- error:
- virObjectUnref(ret);
- return NULL;
+ return g_steal_pointer(&ret);
}
@@ -1017,22 +1027,38 @@ virGetNWFilterBinding(virConnectPtr conn, const char *portdev,
* virNWFilterBindingDispose:
* @obj: the network filter binding to release
*
- * Unconditionally release all memory associated with a nwfilter binding.
- * The nwfilter binding object must not be used once this method returns.
+ * Unreferences the associated connection object, which may also be
+ * released if its ref count hits zero.
+ */
+static void
+virNWFilterBindingDispose(GObject *obj)
+{
+ virNWFilterBindingPtr binding = VIR_NW_FILTER_BINDING(obj);
+
+ virObjectUnref(binding->conn);
+ binding->conn = NULL;
+
+ G_OBJECT_CLASS(vir_nw_filter_binding_parent_class)->dispose(obj);
+}
+
+/**
+ * virNWFilterBindingFinalize:
+ * @obj: the network filter binding to release
*
- * It will also unreference the associated connection object,
- * which may also be released if its ref count hits zero.
+ * Unconditionally releases all memory associated with a nwfilter binding.
+ * The nwfilter binding object must not be used once this method returns.
*/
static void
-virNWFilterBindingDispose(void *obj)
+virNWFilterBindingFinalize(GObject *obj)
{
- virNWFilterBindingPtr binding = obj;
+ virNWFilterBindingPtr binding = VIR_NW_FILTER_BINDING(obj);
VIR_DEBUG("release binding %p %s", binding, binding->portdev);
VIR_FREE(binding->portdev);
VIR_FREE(binding->filtername);
- virObjectUnref(binding->conn);
+
+ G_OBJECT_CLASS(vir_nw_filter_binding_parent_class)->finalize(obj);
}
diff --git a/src/datatypes.h b/src/datatypes.h
index b51514d579..5f0ab5c84b 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 virNWFilterBindingClass;
extern virClassPtr virSecretClass;
extern virClassPtr virStreamClass;
extern virClassPtr virStorageVolClass;
@@ -59,6 +58,13 @@ G_DECLARE_FINAL_TYPE(virDomainSnapshot,
#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()
@@ -327,8 +333,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT,
GObject);
#define virCheckNWFilterBindingReturn(obj, retval) \
do { \
- virNWFilterBindingPtr _nw = (obj); \
- if (!virObjectIsClass(_nw, virNWFilterBindingClass) || \
+ virNWFilterBindingPtr _nw = VIR_NW_FILTER_BINDING(obj); \
+ if (_nw == NULL || \
!virObjectIsClass(_nw->conn, virConnectClass)) { \
virReportErrorHelper(VIR_FROM_NWFILTER, \
VIR_ERR_INVALID_NWFILTER_BINDING, \
@@ -799,7 +805,7 @@ struct _virNWFilter {
* Internal structure associated to a network filter port binding
*/
struct _virNWFilterBinding {
- virObject parent;
+ GObject parent;
virConnectPtr conn; /* pointer back to the connection */
char *portdev; /* the network filter port device name */
char *filtername; /* the network filter name */
diff --git a/src/libvirt-nwfilter.c b/src/libvirt-nwfilter.c
index cd3f5759b7..ac34d1fea0 100644
--- a/src/libvirt-nwfilter.c
+++ b/src/libvirt-nwfilter.c
@@ -621,7 +621,7 @@ virNWFilterBindingFree(virNWFilterBindingPtr binding)
virCheckNWFilterBindingReturn(binding, -1);
- virObjectUnref(binding);
+ g_object_unref(binding);
return 0;
}
@@ -819,13 +819,12 @@ virNWFilterBindingGetXMLDesc(virNWFilterBindingPtr binding, unsigned
int flags)
int
virNWFilterBindingRef(virNWFilterBindingPtr binding)
{
- VIR_DEBUG("binding=%p refs=%d", binding,
- binding ? binding->parent.u.s.refs : 0);
+ VIR_DEBUG("binding=%p", binding);
virResetLastError();
virCheckNWFilterBindingReturn(binding, -1);
- virObjectRef(binding);
+ g_object_ref(binding);
return 0;
}
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 44ffeb6abc..ba4a5f0986 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1348,6 +1348,7 @@ virCPUx86FeatureFilterSelectMSR;
# datatypes.h
vir_domain_checkpoint_get_type;
vir_domain_snapshot_get_type;
+vir_nw_filter_binding_get_type;
vir_nw_filter_get_type;
virConnectClass;
virConnectCloseCallbackDataCall;
diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index 1c407727db..cbf396342e 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -785,8 +785,7 @@ nwfilterBindingCreateXML(virConnectPtr conn,
if (virNWFilterInstantiateFilter(driver, def) < 0) {
virNWFilterBindingObjListRemove(driver->bindings, obj);
- virObjectUnref(ret);
- ret = NULL;
+ g_clear_object(&ret);
goto cleanup;
}
virNWFilterBindingObjSave(obj, driver->bindingDir);
diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index b51e2715ee..553ede5024 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -199,6 +199,7 @@ my %gobject_impl = (
virDomainCheckpoint => 1,
virDomainSnapshot => 1,
virNWFilter => 1,
+ virNWFilterBinding => 1,
);
sub use_gobject {
--
2.25.3