[PATCH 32/36] qemu: convert qemuBlockJobData to GObject

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

 



Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx>
---
 src/qemu/qemu_blockjob.c | 55 +++++++++++++++++++---------------------
 src/qemu/qemu_blockjob.h | 15 +++++++----
 src/qemu/qemu_domain.c   |  7 +++--
 3 files changed, 41 insertions(+), 36 deletions(-)

diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c
index 2032c0c1c5..7d6aabe554 100644
--- a/src/qemu/qemu_blockjob.c
+++ b/src/qemu/qemu_blockjob.c
@@ -71,8 +71,21 @@ VIR_ENUM_IMPL(qemuBlockjob,
               "create",
               "broken");
 
-static virClassPtr qemuBlockJobDataClass;
+G_DEFINE_TYPE(qemuBlockJobData, qemu_block_job_data, G_TYPE_OBJECT);
+static void qemuBlockJobDataFinalize(GObject *obj);
 
+static void
+qemu_block_job_data_init(qemuBlockJobData *job G_GNUC_UNUSED)
+{
+}
+
+static void
+qemu_block_job_data_class_init(qemuBlockJobDataClass *klass)
+{
+    GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+    obj->finalize = qemuBlockJobDataFinalize;
+}
 
 static void
 qemuBlockJobDataDisposeJobdata(qemuBlockJobDataPtr job)
@@ -88,9 +101,9 @@ qemuBlockJobDataDisposeJobdata(qemuBlockJobDataPtr job)
 
 
 static void
-qemuBlockJobDataDispose(void *obj)
+qemuBlockJobDataFinalize(GObject *obj)
 {
-    qemuBlockJobDataPtr job = obj;
+    qemuBlockJobDataPtr job = QEMU_BLOCK_JOB_DATA(obj);
 
     virObjectUnref(job->chain);
     virObjectUnref(job->mirrorChain);
@@ -99,32 +112,17 @@ qemuBlockJobDataDispose(void *obj)
 
     g_free(job->name);
     g_free(job->errmsg);
-}
 
-
-static int
-qemuBlockJobDataOnceInit(void)
-{
-    if (!VIR_CLASS_NEW(qemuBlockJobData, virClassForObject()))
-        return -1;
-
-    return 0;
+    G_OBJECT_CLASS(qemu_block_job_data_parent_class)->finalize(obj);
 }
 
 
-VIR_ONCE_GLOBAL_INIT(qemuBlockJobData);
-
 qemuBlockJobDataPtr
 qemuBlockJobDataNew(qemuBlockJobType type,
                     const char *name)
 {
-    g_autoptr(qemuBlockJobData) job = NULL;
-
-    if (qemuBlockJobDataInitialize() < 0)
-        return NULL;
-
-    if (!(job = virObjectNew(qemuBlockJobDataClass)))
-        return NULL;
+    g_autoptr(qemuBlockJobData) job =
+        QEMU_BLOCK_JOB_DATA(g_object_new(QEMU_TYPE_BLOCK_JOB_DATA, NULL));
 
     job->name = g_strdup(name);
 
@@ -180,15 +178,15 @@ qemuBlockJobRegister(qemuBlockJobDataPtr job,
         return -1;
     }
 
-    if (virHashAddEntry(priv->blockjobs, job->name, virObjectRef(job)) < 0) {
-        virObjectUnref(job);
+    if (virHashAddEntry(priv->blockjobs, job->name, g_object_ref(job)) < 0) {
+        g_object_unref(job);
         return -1;
     }
 
     if (disk) {
         job->disk = disk;
         job->chain = virObjectRef(disk->src);
-        QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob = virObjectRef(job);
+        QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob = g_object_ref(job);
     }
 
     if (savestatus)
@@ -209,8 +207,7 @@ qemuBlockJobUnregister(qemuBlockJobDataPtr job,
         diskPriv = QEMU_DOMAIN_DISK_PRIVATE(job->disk);
 
         if (job == diskPriv->blockjob) {
-            virObjectUnref(diskPriv->blockjob);
-            diskPriv->blockjob = NULL;
+            g_clear_object(&diskPriv->blockjob);
         }
 
         job->disk = NULL;
@@ -427,7 +424,7 @@ qemuBlockJobDiskGetJob(virDomainDiskDefPtr disk)
     if (!job)
         return NULL;
 
-    return virObjectRef(job);
+    return g_object_ref(job);
 }
 
 
@@ -466,7 +463,7 @@ qemuBlockJobStartupFinalize(virDomainObjPtr vm,
     if (job->state == QEMU_BLOCKJOB_STATE_NEW)
         qemuBlockJobUnregister(job, vm);
 
-    virObjectUnref(job);
+    g_object_unref(job);
 }
 
 
@@ -1738,7 +1735,7 @@ qemuBlockJobGetByDisk(virDomainDiskDefPtr disk)
     if (!job)
         return NULL;
 
-    return virObjectRef(job);
+    return g_object_ref(job);
 }
 
 
diff --git a/src/qemu/qemu_blockjob.h b/src/qemu/qemu_blockjob.h
index 19498b5bd8..fc36131c67 100644
--- a/src/qemu/qemu_blockjob.h
+++ b/src/qemu/qemu_blockjob.h
@@ -23,6 +23,7 @@
 
 #include "internal.h"
 #include "qemu_conf.h"
+#include <glib-object.h>
 
 /**
  * This enum has to map all known block job states from enum virDomainBlockJobType
@@ -119,11 +120,8 @@ struct _qemuBlockJobBackupData {
 };
 
 
-typedef struct _qemuBlockJobData qemuBlockJobData;
-typedef qemuBlockJobData *qemuBlockJobDataPtr;
-
 struct _qemuBlockJobData {
-    virObject parent;
+    GObject parent;
 
     char *name;
 
@@ -154,7 +152,14 @@ struct _qemuBlockJobData {
     bool invalidData; /* the job data (except name) is not valid */
     bool reconnected; /* internal field for tracking whether job is live after reconnect to qemu */
 };
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuBlockJobData, virObjectUnref);
+
+#define QEMU_TYPE_BLOCK_JOB_DATA qemu_block_job_data_get_type()
+G_DECLARE_FINAL_TYPE(qemuBlockJobData,
+                     qemu_block_job_data,
+                     QEMU,
+                     BLOCK_JOB_DATA,
+                     GObject);
+typedef qemuBlockJobData *qemuBlockJobDataPtr;
 
 int
 qemuBlockJobRegister(qemuBlockJobDataPtr job,
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 2506fa2eea..14b86388b0 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1165,7 +1165,10 @@ qemuDomainDiskPrivateDispose(void *obj)
     virObjectUnref(priv->migrSource);
     VIR_FREE(priv->qomName);
     VIR_FREE(priv->nodeCopyOnRead);
-    virObjectUnref(priv->blockjob);
+    if (priv->blockjob)
+        g_object_unref(priv->blockjob);
+
+    G_OBJECT_CLASS(qemu_domain_disk_private_parent_class)->finalize(obj);
 }
 
 static virClassPtr qemuDomainStorageSourcePrivateClass;
@@ -2214,7 +2217,7 @@ qemuDomainObjPrivateAlloc(void *opaque)
     if (!(priv->devs = virChrdevAlloc()))
         goto error;
 
-    if (!(priv->blockjobs = virHashCreate(5, virObjectFreeHashData)))
+    if (!(priv->blockjobs = virHashCreate(5, g_object_unref)))
         goto error;
 
     /* agent commands block by default, user can choose different behavior */
-- 
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