[PATCH 16/36] datatypes: convert virDomainSnapshot to GObject

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

 



Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx>
---
 src/conf/virdomainsnapshotobjlist.c |  6 ++--
 src/datatypes.c                     | 44 ++++++++++++++++++-----------
 src/datatypes.h                     | 13 +++++++--
 src/libvirt-domain-snapshot.c       |  7 ++---
 src/libvirt_private.syms            |  1 -
 src/qemu/qemu_driver.c              |  3 +-
 6 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/src/conf/virdomainsnapshotobjlist.c b/src/conf/virdomainsnapshotobjlist.c
index 910b0714c7..7641aa98ff 100644
--- a/src/conf/virdomainsnapshotobjlist.c
+++ b/src/conf/virdomainsnapshotobjlist.c
@@ -286,8 +286,10 @@ virDomainListSnapshots(virDomainSnapshotObjListPtr snapshots,
         VIR_FREE(names[i]);
     VIR_FREE(names);
     if (ret < 0 && list) {
-        for (i = 0; i < count; i++)
-            virObjectUnref(list[i]);
+        for (i = 0; i < count; i++) {
+            if (list[i])
+                g_object_unref(list[i]);
+        }
         VIR_FREE(list);
     }
     return ret;
diff --git a/src/datatypes.c b/src/datatypes.c
index 1e0861aa5f..fd39c96b31 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -36,7 +36,6 @@ VIR_LOG_INIT("datatypes");
 virClassPtr virConnectClass;
 virClassPtr virConnectCloseCallbackDataClass;
 virClassPtr virDomainClass;
-virClassPtr virDomainSnapshotClass;
 virClassPtr virInterfaceClass;
 virClassPtr virNetworkClass;
 virClassPtr virNetworkPortClass;
@@ -51,7 +50,6 @@ virClassPtr virStoragePoolClass;
 static void virConnectDispose(void *obj);
 static void virConnectCloseCallbackDataDispose(void *obj);
 static void virDomainDispose(void *obj);
-static void virDomainSnapshotDispose(void *obj);
 static void virInterfaceDispose(void *obj);
 static void virNetworkDispose(void *obj);
 static void virNetworkPortDispose(void *obj);
@@ -79,6 +77,22 @@ vir_domain_checkpoint_class_init(virDomainCheckpointClass *klass)
     obj->finalize = virDomainCheckpointFinalize;
 }
 
+G_DEFINE_TYPE(virDomainSnapshot, vir_domain_snapshot, G_TYPE_OBJECT);
+static void virDomainSnapshotFinalize(GObject *obj);
+
+static void
+vir_domain_snapshot_init(virDomainSnapshot *ds G_GNUC_UNUSED)
+{
+}
+
+static void
+vir_domain_snapshot_class_init(virDomainSnapshotClass *klass)
+{
+    GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+    obj->finalize = virDomainSnapshotFinalize;
+}
+
 virClassPtr virAdmConnectClass;
 virClassPtr virAdmConnectCloseCallbackDataClass;
 
@@ -131,7 +145,6 @@ virDataTypesOnceInit(void)
     DECLARE_CLASS_LOCKABLE(virConnect);
     DECLARE_CLASS_LOCKABLE(virConnectCloseCallbackData);
     DECLARE_CLASS(virDomain);
-    DECLARE_CLASS(virDomainSnapshot);
     DECLARE_CLASS(virInterface);
     DECLARE_CLASS(virNetwork);
     DECLARE_CLASS(virNetworkPort);
@@ -1051,37 +1064,32 @@ virDomainCheckpointFinalize(GObject *obj)
  * @name: pointer to the domain snapshot name
  *
  * Allocates a new domain snapshot 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 snapshot object, or NULL on error.
  */
 virDomainSnapshotPtr
 virGetDomainSnapshot(virDomainPtr domain, const char *name)
 {
-    virDomainSnapshotPtr ret = NULL;
+    g_autoptr(virDomainSnapshot) ret = NULL;
 
     if (virDataTypesInitialize() < 0)
         return NULL;
 
-    virCheckDomainGoto(domain, error);
-    virCheckNonNullArgGoto(name, error);
+    virCheckDomainReturn(domain, NULL);
+    virCheckNonNullArgReturn(name, NULL);
 
-    if (!(ret = virObjectNew(virDomainSnapshotClass)))
-        goto error;
+    ret = VIR_DOMAIN_SNAPSHOT(g_object_new(VIR_TYPE_DOMAIN_SNAPSHOT, NULL));
     ret->name = g_strdup(name);
 
     ret->domain = virObjectRef(domain);
 
-    return ret;
-
- error:
-    virObjectUnref(ret);
-    return NULL;
+    return g_steal_pointer(&ret);
 }
 
 
 /**
- * virDomainSnapshotDispose:
+ * virDomainSnapshotFinalize:
  * @obj: the domain snapshot to release
  *
  * Unconditionally release all memory associated with a snapshot.
@@ -1091,13 +1099,15 @@ virGetDomainSnapshot(virDomainPtr domain, const char *name)
  * which may also be released if its ref count hits zero.
  */
 static void
-virDomainSnapshotDispose(void *obj)
+virDomainSnapshotFinalize(GObject *obj)
 {
-    virDomainSnapshotPtr snapshot = obj;
+    virDomainSnapshotPtr snapshot = VIR_DOMAIN_SNAPSHOT(obj);
     VIR_DEBUG("release snapshot %p %s", snapshot, snapshot->name);
 
     VIR_FREE(snapshot->name);
     virObjectUnref(snapshot->domain);
+
+    G_OBJECT_CLASS(vir_domain_snapshot_parent_class)->finalize(obj);
 }
 
 
diff --git a/src/datatypes.h b/src/datatypes.h
index 13ad044126..296196523b 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -32,7 +32,6 @@
 
 extern virClassPtr virConnectClass;
 extern virClassPtr virDomainClass;
-extern virClassPtr virDomainSnapshotClass;
 extern virClassPtr virInterfaceClass;
 extern virClassPtr virNetworkClass;
 extern virClassPtr virNetworkPortClass;
@@ -44,6 +43,7 @@ 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,
@@ -51,6 +51,13 @@ G_DECLARE_FINAL_TYPE(virDomainCheckpoint,
                      DOMAIN_CHECKPOINT,
                      GObject);
 
+#define VIR_TYPE_DOMAIN_SNAPSHOT vir_domain_snapshot_get_type()
+G_DECLARE_FINAL_TYPE(virDomainSnapshot,
+                     vir_domain_snapshot,
+                     VIR,
+                     DOMAIN_SNAPSHOT,
+                     GObject);
+
 extern virClassPtr virAdmConnectClass;
 
 #define VIR_TYPE_ADM_SERVER vir_adm_server_get_type()
@@ -349,7 +356,7 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT, GObject);
 #define virCheckDomainSnapshotReturn(obj, retval) \
     do { \
         virDomainSnapshotPtr _snap = (obj); \
-        if (!virObjectIsClass(_snap, virDomainSnapshotClass) || \
+        if (!G_IS_OBJECT(_snap) || !(G_OBJECT_TYPE(_snap) == VIR_TYPE_DOMAIN_SNAPSHOT) || \
             !virObjectIsClass(_snap->domain, virDomainClass) || \
             !virObjectIsClass(_snap->domain->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_DOMAIN_SNAPSHOT, \
@@ -767,7 +774,7 @@ struct _virDomainCheckpoint {
  * Internal structure associated with a domain snapshot
  */
 struct _virDomainSnapshot {
-    virObject parent;
+    GObject parent;
     char *name;
     virDomainPtr domain;
 };
diff --git a/src/libvirt-domain-snapshot.c b/src/libvirt-domain-snapshot.c
index 33593e11e9..ce870de712 100644
--- a/src/libvirt-domain-snapshot.c
+++ b/src/libvirt-domain-snapshot.c
@@ -1080,14 +1080,13 @@ virDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
 int
 virDomainSnapshotRef(virDomainSnapshotPtr snapshot)
 {
-    VIR_DEBUG("snapshot=%p, refs=%d", snapshot,
-              snapshot ? snapshot->parent.u.s.refs : 0);
+    VIR_DEBUG("snapshot=%p", snapshot);
 
     virResetLastError();
 
     virCheckDomainSnapshotReturn(snapshot, -1);
 
-    virObjectRef(snapshot);
+    g_object_ref(snapshot);
     return 0;
 }
 
@@ -1110,6 +1109,6 @@ virDomainSnapshotFree(virDomainSnapshotPtr snapshot)
 
     virCheckDomainSnapshotReturn(snapshot, -1);
 
-    virObjectUnref(snapshot);
+    g_object_unref(snapshot);
     return 0;
 }
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 008d4fa08f..7528779127 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1350,7 +1350,6 @@ virConnectCloseCallbackDataGetCallback;
 virConnectCloseCallbackDataRegister;
 virConnectCloseCallbackDataUnregister;
 virDomainClass;
-virDomainSnapshotClass;
 virGetConnect;
 virGetDomain;
 virGetDomainCheckpoint;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 73f1037e8a..864158fd9d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15853,8 +15853,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
                                             cfg->snapshotDir) < 0) {
             /* if writing of metadata fails, error out rather than trying
              * to silently carry on without completing the snapshot */
-            virObjectUnref(snapshot);
-            snapshot = NULL;
+            g_clear_object(&snapshot);
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("unable to save metadata for snapshot %s"),
                            snap->def->name);
-- 
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