[PATCH v2 36/40] 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  | 67 ++++++++++++++++++++++-----------------
 src/qemu/qemu_blockjob.h  | 15 ++++++---
 src/qemu/qemu_domain.c    |  4 +--
 src/qemu/qemu_hotplug.c   |  3 +-
 src/qemu/qemu_migration.c | 16 +++-------
 5 files changed, 55 insertions(+), 50 deletions(-)

diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c
index 2032c0c1c5..38fbba2b90 100644
--- a/src/qemu/qemu_blockjob.c
+++ b/src/qemu/qemu_blockjob.c
@@ -71,8 +71,23 @@ VIR_ENUM_IMPL(qemuBlockjob,
               "create",
               "broken");
 
-static virClassPtr qemuBlockJobDataClass;
+G_DEFINE_TYPE(qemuBlockJobData, qemu_block_job_data, G_TYPE_OBJECT);
+static void qemuBlockJobDataDispose(GObject *obj);
+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->dispose = qemuBlockJobDataDispose;
+    obj->finalize = qemuBlockJobDataFinalize;
+}
 
 static void
 qemuBlockJobDataDisposeJobdata(qemuBlockJobDataPtr job)
@@ -88,43 +103,38 @@ qemuBlockJobDataDisposeJobdata(qemuBlockJobDataPtr job)
 
 
 static void
-qemuBlockJobDataDispose(void *obj)
+qemuBlockJobDataDispose(GObject *obj)
 {
-    qemuBlockJobDataPtr job = obj;
+    qemuBlockJobDataPtr job = QEMU_BLOCK_JOB_DATA(obj);
 
     virObjectUnref(job->chain);
+    job->chain = NULL;
     virObjectUnref(job->mirrorChain);
+    job->mirrorChain = NULL;
+
+    G_OBJECT_CLASS(qemu_block_job_data_parent_class)->dispose(obj);
+}
+
+static void
+qemuBlockJobDataFinalize(GObject *obj)
+{
+    qemuBlockJobDataPtr job = QEMU_BLOCK_JOB_DATA(obj);
 
     qemuBlockJobDataDisposeJobdata(job);
 
     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 +190,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 +219,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 +436,7 @@ qemuBlockJobDiskGetJob(virDomainDiskDefPtr disk)
     if (!job)
         return NULL;
 
-    return virObjectRef(job);
+    return g_object_ref(job);
 }
 
 
@@ -466,7 +475,7 @@ qemuBlockJobStartupFinalize(virDomainObjPtr vm,
     if (job->state == QEMU_BLOCKJOB_STATE_NEW)
         qemuBlockJobUnregister(job, vm);
 
-    virObjectUnref(job);
+    g_object_unref(job);
 }
 
 
@@ -1738,7 +1747,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 c6980a53b6..99478890b6 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1166,7 +1166,7 @@ qemuDomainDiskPrivateDispose(void *obj)
     virObjectUnref(priv->migrSource);
     VIR_FREE(priv->qomName);
     VIR_FREE(priv->nodeCopyOnRead);
-    virObjectUnref(priv->blockjob);
+    g_clear_object(&priv->blockjob);
 }
 
 static virClassPtr qemuDomainStorageSourcePrivateClass;
@@ -2215,7 +2215,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 */
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 14654a17d7..98b02710d5 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -4276,8 +4276,7 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
         if (diskPriv->blockjob) {
             /* the block job keeps reference to the disk chain */
             diskPriv->blockjob->disk = NULL;
-            virObjectUnref(diskPriv->blockjob);
-            diskPriv->blockjob = NULL;
+            g_clear_object(&diskPriv->blockjob);
         } else {
             if (!(diskBackend = qemuBlockStorageSourceChainDetachPrepareBlockdev(disk->src)))
                 goto cleanup;
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index ab4ae8e150..6b668029b1 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -512,7 +512,7 @@ qemuMigrationSrcNBDStorageCopyReady(virDomainObjPtr vm,
     for (i = 0; i < vm->def->ndisks; i++) {
         virDomainDiskDefPtr disk = vm->def->disks[i];
         qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
-        qemuBlockJobDataPtr job;
+        g_autoptr(qemuBlockJobData) job = NULL;
 
         if (!diskPriv->migrating)
             continue;
@@ -526,12 +526,9 @@ qemuMigrationSrcNBDStorageCopyReady(virDomainObjPtr vm,
         qemuBlockJobUpdate(vm, job, asyncJob);
         if (job->state == VIR_DOMAIN_BLOCK_JOB_FAILED) {
             qemuMigrationNBDReportMirrorError(job, disk->dst);
-            virObjectUnref(job);
             return -1;
         }
 
-        virObjectUnref(job);
-
         if (disk->mirrorState != VIR_DOMAIN_DISK_MIRROR_STATE_READY)
             notReady++;
     }
@@ -570,7 +567,7 @@ qemuMigrationSrcNBDCopyCancelled(virDomainObjPtr vm,
     for (i = 0; i < vm->def->ndisks; i++) {
         virDomainDiskDefPtr disk = vm->def->disks[i];
         qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
-        qemuBlockJobDataPtr job;
+        g_autoptr(qemuBlockJobData) job = NULL;
 
         if (!diskPriv->migrating)
             continue;
@@ -597,8 +594,6 @@ qemuMigrationSrcNBDCopyCancelled(virDomainObjPtr vm,
 
         if (job->state == VIR_DOMAIN_BLOCK_JOB_COMPLETED)
             completed++;
-
-        virObjectUnref(job);
     }
 
     /* Updating completed block job drops the lock thus we have to recheck
@@ -704,14 +699,13 @@ qemuMigrationSrcNBDCopyCancel(virQEMUDriverPtr driver,
     for (i = 0; i < vm->def->ndisks; i++) {
         virDomainDiskDefPtr disk = vm->def->disks[i];
         qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
-        qemuBlockJobDataPtr job;
+        g_autoptr(qemuBlockJobData) job = NULL;
 
         if (!(job = qemuBlockJobDiskGetJob(disk)) ||
             !qemuBlockJobIsRunning(job))
             diskPriv->migrating = false;
 
         if (!diskPriv->migrating) {
-            virObjectUnref(job);
             continue;
         }
 
@@ -726,8 +720,6 @@ qemuMigrationSrcNBDCopyCancel(virQEMUDriverPtr driver,
             qemuBlockJobSyncEnd(vm, job, asyncJob);
             diskPriv->migrating = false;
         }
-
-        virObjectUnref(job);
     }
 
     while ((rv = qemuMigrationSrcNBDCopyCancelled(vm, asyncJob, check)) != 1) {
@@ -5437,7 +5429,7 @@ qemuMigrationSrcCancel(virQEMUDriverPtr driver,
             storage = true;
         }
 
-        virObjectUnref(job);
+        g_clear_object(&job);
     }
 
     if (storage &&
-- 
2.25.3






[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