[PATCH 36/36] util: convert virStorageSource 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  | 71 ++++++++++++++++++---------------------
 src/qemu/qemu_domain.c    | 13 +++----
 src/util/virstoragefile.c | 41 +++++++++++-----------
 src/util/virstoragefile.h |  6 ++--
 4 files changed, 65 insertions(+), 66 deletions(-)

diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c
index 7d6aabe554..767ac54170 100644
--- a/src/qemu/qemu_blockjob.c
+++ b/src/qemu/qemu_blockjob.c
@@ -91,10 +91,10 @@ static void
 qemuBlockJobDataDisposeJobdata(qemuBlockJobDataPtr job)
 {
     if (job->type == QEMU_BLOCKJOB_TYPE_CREATE)
-        virObjectUnref(job->data.create.src);
+        g_object_unref(job->data.create.src);
 
     if (job->type == QEMU_BLOCKJOB_TYPE_BACKUP) {
-        virObjectUnref(job->data.backup.store);
+        g_object_unref(job->data.backup.store);
         g_free(job->data.backup.bitmap);
     }
 }
@@ -105,8 +105,10 @@ qemuBlockJobDataFinalize(GObject *obj)
 {
     qemuBlockJobDataPtr job = QEMU_BLOCK_JOB_DATA(obj);
 
-    virObjectUnref(job->chain);
-    virObjectUnref(job->mirrorChain);
+    if (job->chain)
+        g_object_unref(job->chain);
+    if (job->mirrorChain)
+        g_object_unref(job->mirrorChain);
 
     qemuBlockJobDataDisposeJobdata(job);
 
@@ -185,7 +187,7 @@ qemuBlockJobRegister(qemuBlockJobDataPtr job,
 
     if (disk) {
         job->disk = disk;
-        job->chain = virObjectRef(disk->src);
+        job->chain = g_object_ref(disk->src);
         QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob = g_object_ref(job);
     }
 
@@ -337,9 +339,9 @@ qemuBlockJobNewCreate(virDomainObjPtr vm,
         return NULL;
 
     if (virStorageSourceIsBacking(chain))
-        job->chain = virObjectRef(chain);
+        job->chain = g_object_ref(chain);
 
-     job->data.create.src = virObjectRef(src);
+     job->data.create.src = g_object_ref(src);
 
     if (qemuBlockJobRegister(job, vm, NULL, true) < 0)
         return NULL;
@@ -370,7 +372,7 @@ qemuBlockJobDiskNewCopy(virDomainObjPtr vm,
     if (!(job = qemuBlockJobDataNew(QEMU_BLOCKJOB_TYPE_COPY, jobname)))
         return NULL;
 
-    job->mirrorChain = virObjectRef(mirror);
+    job->mirrorChain = g_object_ref(mirror);
 
     if (shallow && !reuse)
         job->data.copy.shallownew = true;
@@ -399,7 +401,7 @@ qemuBlockJobDiskNewBackup(virDomainObjPtr vm,
         return NULL;
 
     job->data.backup.bitmap = g_strdup(bitmap);
-    job->data.backup.store = virObjectRef(store);
+    job->data.backup.store = g_object_ref(store);
 
     /* backup jobs are usually started in bulk by transaction so the caller
      * shall save the status XML */
@@ -688,14 +690,12 @@ qemuBlockJobRewriteConfigDiskSource(virDomainObjPtr vm,
         /* discard any detected backing store */
         if (virStorageSourceIsBacking(n->backingStore) &&
             n->backingStore->detected) {
-            virObjectUnref(n->backingStore);
-            n->backingStore = NULL;
+            g_clear_object(&n->backingStore);
             break;
         }
     }
 
-    virObjectUnref(persistDisk->src);
-    persistDisk->src = g_steal_pointer(&copy);
+    g_set_object(&persistDisk->src, copy);
 }
 
 
@@ -729,8 +729,7 @@ qemuBlockJobEventProcessLegacyCompleted(virQEMUDriverPtr driver,
                      disk->dst);
         }
 
-        virObjectUnref(disk->src);
-        disk->src = disk->mirror;
+        g_set_object(&disk->src, disk->mirror);
     } else {
         if (disk->mirror) {
             virDomainLockImageDetach(driver->lockManager, vm, disk->mirror);
@@ -740,7 +739,7 @@ qemuBlockJobEventProcessLegacyCompleted(virQEMUDriverPtr driver,
              * Remove security driver metadata so that they are not leaked. */
             qemuBlockRemoveImageMetadata(driver, vm, disk->dst, disk->mirror);
 
-            virObjectUnref(disk->mirror);
+            g_object_unref(disk->mirror);
         }
 
         qemuBlockRemoveImageMetadata(driver, vm, disk->dst, disk->src);
@@ -817,8 +816,7 @@ qemuBlockJobEventProcessLegacy(virQEMUDriverPtr driver,
              * Remove security driver metadata so that they are not leaked. */
             qemuBlockRemoveImageMetadata(driver, vm, disk->dst, disk->mirror);
 
-            virObjectUnref(disk->mirror);
-            disk->mirror = NULL;
+            g_clear_object(&disk->mirror);
         }
         disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
         disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
@@ -930,8 +928,8 @@ qemuBlockJobClearConfigChain(virDomainObjPtr vm,
     if (!virStorageSourceIsSameLocation(disk->src, cfgdisk->src))
         return;
 
-    virObjectUnref(cfgdisk->src->backingStore);
-    cfgdisk->src->backingStore = NULL;
+    if (cfgdisk->src->backingStore)
+        g_clear_object(&cfgdisk->src->backingStore);
 }
 
 
@@ -997,14 +995,16 @@ qemuBlockJobProcessEventCompletedPull(virQEMUDriverPtr driver,
     if (baseparent)
         baseparent->backingStore = NULL;
     qemuBlockJobEventProcessConcludedRemoveChain(driver, vm, asyncJob, tmp);
-    virObjectUnref(tmp);
+    if (tmp)
+        g_object_unref(tmp);
 
     if (cfgdisk) {
         tmp = cfgdisk->src->backingStore;
         cfgdisk->src->backingStore = cfgbase;
         if (cfgbaseparent)
             cfgbaseparent->backingStore = NULL;
-        virObjectUnref(tmp);
+        if (tmp)
+            g_object_unref(tmp);
     }
 }
 
@@ -1171,8 +1171,7 @@ qemuBlockJobProcessEventCompletedCommit(virQEMUDriverPtr driver,
     if (job->data.commit.deleteCommittedImages)
         qemuBlockJobDeleteImages(driver, vm, job->disk, job->data.commit.top);
 
-    virObjectUnref(job->data.commit.top);
-    job->data.commit.top = NULL;
+    g_clear_object(&job->data.commit.top);
 
     if (cfgbaseparent) {
         cfgbase = cfgbaseparent->backingStore;
@@ -1183,7 +1182,8 @@ qemuBlockJobProcessEventCompletedCommit(virQEMUDriverPtr driver,
         else
             cfgdisk->src = cfgbase;
 
-        virObjectUnref(cfgtop);
+        if (cfgtop)
+            g_object_unref(cfgtop);
     }
 }
 
@@ -1249,7 +1249,8 @@ qemuBlockJobProcessEventCompletedActiveCommit(virQEMUDriverPtr driver,
         cfgbaseparent->backingStore = NULL;
         cfgdisk->src = cfgbase;
         cfgdisk->src->readonly = cfgtop->readonly;
-        virObjectUnref(cfgtop);
+        if (cfgtop)
+            g_object_unref(cfgtop);
     }
 
     /* Move security driver metadata */
@@ -1265,11 +1266,9 @@ qemuBlockJobProcessEventCompletedActiveCommit(virQEMUDriverPtr driver,
     if (job->data.commit.deleteCommittedImages)
         qemuBlockJobDeleteImages(driver, vm, job->disk, job->data.commit.top);
 
-    virObjectUnref(job->data.commit.top);
-    job->data.commit.top = NULL;
+    g_clear_object(&job->data.commit.top);
     /* the mirror element does not serve functional purpose for the commit job */
-    virObjectUnref(job->disk->mirror);
-    job->disk->mirror = NULL;
+    g_clear_object(&job->disk->mirror);
 }
 
 
@@ -1297,8 +1296,7 @@ qemuBlockJobProcessEventConcludedCopyPivot(virQEMUDriverPtr driver,
     qemuBlockJobRewriteConfigDiskSource(vm, job->disk, job->disk->mirror);
 
     qemuBlockJobEventProcessConcludedRemoveChain(driver, vm, asyncJob, job->disk->src);
-    virObjectUnref(job->disk->src);
-    job->disk->src = g_steal_pointer(&job->disk->mirror);
+    g_set_object(&job->disk->src, job->disk->mirror);
 }
 
 
@@ -1316,8 +1314,7 @@ qemuBlockJobProcessEventConcludedCopyAbort(virQEMUDriverPtr driver,
         return;
 
     qemuBlockJobEventProcessConcludedRemoveChain(driver, vm, asyncJob, job->disk->mirror);
-    virObjectUnref(job->disk->mirror);
-    job->disk->mirror = NULL;
+    g_clear_object(&job->disk->mirror);
 }
 
 
@@ -1338,8 +1335,7 @@ qemuBlockJobProcessEventFailedActiveCommit(virQEMUDriverPtr driver,
      * not leaking security driver metadata is more important. */
     qemuBlockRemoveImageMetadata(driver, vm, disk->dst, disk->mirror);
 
-    virObjectUnref(disk->mirror);
-    disk->mirror = NULL;
+    g_clear_object(&disk->mirror);
 }
 
 
@@ -1389,8 +1385,7 @@ qemuBlockJobProcessEventConcludedCreate(virQEMUDriverPtr driver,
      * it will handle further hotplug of the created volume and also that
      * the 'chain' which was registered is under their control */
     if (job->synchronous) {
-        virObjectUnref(job->chain);
-        job->chain = NULL;
+        g_clear_object(&job->chain);
         return;
     }
 
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index a12ecc0e25..7523769d9b 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1159,7 +1159,8 @@ qemuDomainDiskPrivateFinalize(GObject *obj)
 {
     qemuDomainDiskPrivatePtr priv = QEMU_DOMAIN_DISK(obj);
 
-    virObjectUnref(priv->migrSource);
+    if (priv->migrSource)
+        g_object_unref(priv->migrSource);
     VIR_FREE(priv->qomName);
     VIR_FREE(priv->nodeCopyOnRead);
     if (priv->blockjob)
@@ -2247,10 +2248,10 @@ qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr priv)
 
     virHashRemoveAll(priv->blockjobs);
 
-    virObjectUnref(priv->pflash0);
-    priv->pflash0 = NULL;
-    virObjectUnref(priv->pflash1);
-    priv->pflash1 = NULL;
+    if (priv->pflash0)
+        g_clear_object(&priv->pflash0);
+    if (priv->pflash1)
+        g_clear_object(&priv->pflash1);
 
     virDomainBackupDefFree(priv->backup);
     priv->backup = NULL;
@@ -3386,7 +3387,7 @@ qemuDomainObjPrivateXMLParseBlockjobData(virDomainObjPtr vm,
 
     if (mirror) {
         if (disk)
-            job->mirrorChain = virObjectRef(disk->mirror);
+            job->mirrorChain = g_object_ref(disk->mirror);
         else
             invalidData = true;
     }
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index ffc8bdb344..d367ebe8c3 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -45,7 +45,21 @@
 
 VIR_LOG_INIT("util.storagefile");
 
-static virClassPtr virStorageSourceClass;
+G_DEFINE_TYPE(virStorageSource, vir_storage_source, G_TYPE_OBJECT);
+static void virStorageSourceFinalize(GObject *obj);
+
+static void
+vir_storage_source_init(virStorageSource *src G_GNUC_UNUSED)
+{
+}
+
+static void
+vir_storage_source_class_init(virStorageSourceClass *klass)
+{
+    GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+    obj->finalize = virStorageSourceFinalize;
+}
 
 VIR_ENUM_IMPL(virStorage,
               VIR_STORAGE_TYPE_LAST,
@@ -2682,8 +2696,8 @@ virStorageSourceBackingStoreClear(virStorageSourcePtr def)
     VIR_FREE(def->backingStoreRaw);
 
     /* recursively free backing chain */
-    virObjectUnref(def->backingStore);
-    def->backingStore = NULL;
+    if (def->backingStore)
+        g_clear_object(&def->backingStore);
 }
 
 
@@ -2739,34 +2753,21 @@ virStorageSourceClear(virStorageSourcePtr def)
 
 
 static void
-virStorageSourceDispose(void *obj)
+virStorageSourceFinalize(GObject *obj)
 {
-    virStorageSourcePtr src = obj;
+    virStorageSourcePtr src = VIR_STORAGE_SOURCE(obj);
 
     virStorageSourceClear(src);
-}
 
-
-static int
-virStorageSourceOnceInit(void)
-{
-    if (!VIR_CLASS_NEW(virStorageSource, virClassForObject()))
-        return -1;
-
-    return 0;
+    G_OBJECT_CLASS(vir_storage_source_parent_class)->finalize(obj);
 }
 
 
-VIR_ONCE_GLOBAL_INIT(virStorageSource);
-
 
 virStorageSourcePtr
 virStorageSourceNew(void)
 {
-    if (virStorageSourceInitialize() < 0)
-        return NULL;
-
-    return virObjectNew(virStorageSourceClass);
+    return VIR_STORAGE_SOURCE(g_object_new(VIR_TYPE_STORAGE_SOURCE, NULL));
 }
 
 
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index a744bcbf5c..ce56e8e18e 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -275,7 +275,7 @@ typedef virStorageSource *virStorageSourcePtr;
  * IMPORTANT: When adding fields to this struct it's also necessary to add
  * appropriate code to the virStorageSourceCopy deep copy function */
 struct _virStorageSource {
-    virObject parent;
+    GObject parent;
 
     unsigned int id; /* backing chain identifier, 0 is unset */
     int type; /* virStorageType */
@@ -393,7 +393,9 @@ struct _virStorageSource {
     bool ssh_host_key_check_disabled;
 };
 
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageSource, virObjectUnref);
+#define VIR_TYPE_STORAGE_SOURCE vir_storage_source_get_type()
+G_DECLARE_FINAL_TYPE(virStorageSource, vir_storage_source, VIR, STORAGE_SOURCE, GObject);
+
 
 
 #ifndef DEV_BSIZE
-- 
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