Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/conf/virdomaincheckpointobjlist.c | 7 ++---
src/datatypes.c | 44 ++++++++++++++++-----------
src/datatypes.h | 14 ++++++---
src/libvirt-domain-checkpoint.c | 7 ++---
src/libvirt_private.syms | 2 +-
src/rpc/gendispatch.pl | 1 +
6 files changed, 44 insertions(+), 31 deletions(-)
diff --git a/src/conf/virdomaincheckpointobjlist.c
b/src/conf/virdomaincheckpointobjlist.c
index a4942ea706..2c4d484226 100644
--- a/src/conf/virdomaincheckpointobjlist.c
+++ b/src/conf/virdomaincheckpointobjlist.c
@@ -234,10 +234,7 @@ virDomainListCheckpoints(virDomainCheckpointObjListPtr checkpoints,
for (i = 0; i < count; i++)
VIR_FREE(names[i]);
VIR_FREE(names);
- if (ret < 0 && list) {
- for (i = 0; i < count; i++)
- virObjectUnref(list[i]);
- VIR_FREE(list);
- }
+ if (ret < 0)
+ virGObjectListFreeCount(list, count);
return ret;
}
diff --git a/src/datatypes.c b/src/datatypes.c
index da0a4ed19d..0f3365a10a 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -36,7 +36,6 @@ VIR_LOG_INIT("datatypes");
virClassPtr virConnectClass;
virClassPtr virConnectCloseCallbackDataClass;
virClassPtr virDomainClass;
-virClassPtr virDomainCheckpointClass;
virClassPtr virDomainSnapshotClass;
virClassPtr virInterfaceClass;
virClassPtr virNetworkClass;
@@ -52,7 +51,6 @@ virClassPtr virStoragePoolClass;
static void virConnectDispose(void *obj);
static void virConnectCloseCallbackDataDispose(void *obj);
static void virDomainDispose(void *obj);
-static void virDomainCheckpointDispose(void *obj);
static void virDomainSnapshotDispose(void *obj);
static void virInterfaceDispose(void *obj);
static void virNetworkDispose(void *obj);
@@ -65,6 +63,22 @@ static void virStreamDispose(void *obj);
static void virStorageVolDispose(void *obj);
static void virStoragePoolDispose(void *obj);
+G_DEFINE_TYPE(virDomainCheckpoint, vir_domain_checkpoint, G_TYPE_OBJECT);
+static void virDomainCheckpointFinalize(GObject *obj);
+
+static void
+vir_domain_checkpoint_init(virDomainCheckpoint *dc G_GNUC_UNUSED)
+{
+}
+
+static void
+vir_domain_checkpoint_class_init(virDomainCheckpointClass *klass)
+{
+ GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+ obj->finalize = virDomainCheckpointFinalize;
+}
+
virClassPtr virAdmConnectClass;
virClassPtr virAdmConnectCloseCallbackDataClass;
@@ -117,7 +131,6 @@ virDataTypesOnceInit(void)
DECLARE_CLASS_LOCKABLE(virConnect);
DECLARE_CLASS_LOCKABLE(virConnectCloseCallbackData);
DECLARE_CLASS(virDomain);
- DECLARE_CLASS(virDomainCheckpoint);
DECLARE_CLASS(virDomainSnapshot);
DECLARE_CLASS(virInterface);
DECLARE_CLASS(virNetwork);
@@ -984,7 +997,7 @@ virNWFilterBindingDispose(void *obj)
* @name: pointer to the domain checkpoint name
*
* Allocates a new domain checkpoint 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 domain checkpoint object, or NULL on error.
*/
@@ -992,30 +1005,25 @@ virDomainCheckpointPtr
virGetDomainCheckpoint(virDomainPtr domain,
const char *name)
{
- virDomainCheckpointPtr ret = NULL;
+ g_autoptr(virDomainCheckpoint) ret = NULL;
if (virDataTypesInitialize() < 0)
return NULL;
- virCheckDomainGoto(domain, error);
- virCheckNonNullArgGoto(name, error);
+ virCheckDomainReturn(domain, NULL);
+ virCheckNonNullArgReturn(name, NULL);
- if (!(ret = virObjectNew(virDomainCheckpointClass)))
- goto error;
+ ret = VIR_DOMAIN_CHECKPOINT(g_object_new(VIR_TYPE_DOMAIN_CHECKPOINT, NULL));
ret->name = g_strdup(name);
ret->domain = virObjectRef(domain);
- return ret;
-
- error:
- virObjectUnref(ret);
- return NULL;
+ return g_steal_pointer(&ret);
}
/**
- * virDomainCheckpointDispose:
+ * virDomainCheckpointFinalize:
* @obj: the domain checkpoint to release
*
* Unconditionally release all memory associated with a checkpoint.
@@ -1025,13 +1033,15 @@ virGetDomainCheckpoint(virDomainPtr domain,
* which may also be released if its ref count hits zero.
*/
static void
-virDomainCheckpointDispose(void *obj)
+virDomainCheckpointFinalize(GObject *obj)
{
- virDomainCheckpointPtr checkpoint = obj;
+ virDomainCheckpointPtr checkpoint = VIR_DOMAIN_CHECKPOINT(obj);
VIR_DEBUG("release checkpoint %p %s", checkpoint, checkpoint->name);
VIR_FREE(checkpoint->name);
virObjectUnref(checkpoint->domain);
+
+ G_OBJECT_CLASS(vir_domain_checkpoint_parent_class)->finalize(obj);
}
diff --git a/src/datatypes.h b/src/datatypes.h
index 482ad0274c..e6817dc43d 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -32,7 +32,6 @@
extern virClassPtr virConnectClass;
extern virClassPtr virDomainClass;
-extern virClassPtr virDomainCheckpointClass;
extern virClassPtr virDomainSnapshotClass;
extern virClassPtr virInterfaceClass;
extern virClassPtr virNetworkClass;
@@ -45,6 +44,13 @@ extern virClassPtr virStreamClass;
extern virClassPtr virStorageVolClass;
extern virClassPtr virStoragePoolClass;
+#define VIR_TYPE_DOMAIN_CHECKPOINT vir_domain_checkpoint_get_type()
+G_DECLARE_FINAL_TYPE(virDomainCheckpoint,
+ vir_domain_checkpoint,
+ VIR,
+ DOMAIN_CHECKPOINT,
+ 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 virCheckDomainCheckpointReturn(obj, retval) \
do { \
- virDomainCheckpointPtr _check = (obj); \
- if (!virObjectIsClass(_check, virDomainCheckpointClass) || \
+ virDomainCheckpointPtr _check = VIR_DOMAIN_CHECKPOINT(obj); \
+ if (_check == NULL || \
!virObjectIsClass(_check->domain, virDomainClass) || \
!virObjectIsClass(_check->domain->conn, virConnectClass)) { \
virReportErrorHelper(VIR_FROM_DOMAIN_CHECKPOINT, \
@@ -749,7 +755,7 @@ struct _virStream {
* Internal structure associated with a domain checkpoint
*/
struct _virDomainCheckpoint {
- virObject parent;
+ GObject parent;
char *name;
virDomainPtr domain;
};
diff --git a/src/libvirt-domain-checkpoint.c b/src/libvirt-domain-checkpoint.c
index 432c2d5a52..77ef434d30 100644
--- a/src/libvirt-domain-checkpoint.c
+++ b/src/libvirt-domain-checkpoint.c
@@ -535,14 +535,13 @@ virDomainCheckpointDelete(virDomainCheckpointPtr checkpoint,
int
virDomainCheckpointRef(virDomainCheckpointPtr checkpoint)
{
- VIR_DEBUG("checkpoint=%p, refs=%d", checkpoint,
- checkpoint ? checkpoint->parent.u.s.refs : 0);
+ VIR_DEBUG("checkpoint=%p", checkpoint);
virResetLastError();
virCheckDomainCheckpointReturn(checkpoint, -1);
- virObjectRef(checkpoint);
+ g_object_ref(checkpoint);
return 0;
}
@@ -565,6 +564,6 @@ virDomainCheckpointFree(virDomainCheckpointPtr checkpoint)
virCheckDomainCheckpointReturn(checkpoint, -1);
- virObjectUnref(checkpoint);
+ g_object_unref(checkpoint);
return 0;
}
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 5a83243d58..d47714f067 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1356,13 +1356,13 @@ virCPUx86FeatureFilterDropMSR;
virCPUx86FeatureFilterSelectMSR;
# datatypes.h
+vir_domain_checkpoint_get_type;
virConnectClass;
virConnectCloseCallbackDataCall;
virConnectCloseCallbackDataClass;
virConnectCloseCallbackDataGetCallback;
virConnectCloseCallbackDataRegister;
virConnectCloseCallbackDataUnregister;
-virDomainCheckpointClass;
virDomainClass;
virDomainSnapshotClass;
virGetConnect;
diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index fa5340d5e8..c8fba3dc2b 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -196,6 +196,7 @@ sub get_conn_method {
my %gobject_impl = (
virAdmClient => 1,
virAdmServer => 1,
+ virDomainCheckpoint => 1,
);
sub use_gobject {
--
2.26.2