[PATCH v2 40/40] 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/libvirt_private.syms  |  1 +
 src/qemu/qemu_blockjob.c  | 67 ++++++++++++++++-----------------------
 src/qemu/qemu_domain.c    | 11 +++----
 src/util/virstoragefile.c | 43 ++++++++++++-------------
 src/util/virstoragefile.h |  6 ++--
 5 files changed, 57 insertions(+), 71 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index d96331e633..a5dc53b4f6 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -3082,6 +3082,7 @@ virStorageGenerateQcowPassphrase;
 
 
 # util/virstoragefile.h
+vir_storage_source_get_type;
 virStorageAuthDefCopy;
 virStorageAuthDefFormat;
 virStorageAuthDefFree;
diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c
index 38fbba2b90..5aac483724 100644
--- a/src/qemu/qemu_blockjob.c
+++ b/src/qemu/qemu_blockjob.c
@@ -93,10 +93,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);
     }
 }
@@ -107,10 +107,8 @@ qemuBlockJobDataDispose(GObject *obj)
 {
     qemuBlockJobDataPtr job = QEMU_BLOCK_JOB_DATA(obj);
 
-    virObjectUnref(job->chain);
-    job->chain = NULL;
-    virObjectUnref(job->mirrorChain);
-    job->mirrorChain = NULL;
+    g_clear_object(&job->chain);
+    g_clear_object(&job->mirrorChain);
 
     G_OBJECT_CLASS(qemu_block_job_data_parent_class)->dispose(obj);
 }
@@ -197,7 +195,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);
     }
 
@@ -349,9 +347,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;
@@ -382,7 +380,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;
@@ -411,7 +409,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 */
@@ -700,14 +698,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);
 }
 
 
@@ -741,8 +737,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);
@@ -752,7 +747,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);
@@ -829,8 +824,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;
@@ -942,8 +936,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);
 }
 
 
@@ -1009,14 +1003,14 @@ qemuBlockJobProcessEventCompletedPull(virQEMUDriverPtr driver,
     if (baseparent)
         baseparent->backingStore = NULL;
     qemuBlockJobEventProcessConcludedRemoveChain(driver, vm, asyncJob, tmp);
-    virObjectUnref(tmp);
+    g_clear_object(&tmp);
 
     if (cfgdisk) {
         tmp = cfgdisk->src->backingStore;
         cfgdisk->src->backingStore = cfgbase;
         if (cfgbaseparent)
             cfgbaseparent->backingStore = NULL;
-        virObjectUnref(tmp);
+        g_clear_object(&tmp);
     }
 }
 
@@ -1183,8 +1177,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;
@@ -1195,7 +1188,7 @@ qemuBlockJobProcessEventCompletedCommit(virQEMUDriverPtr driver,
         else
             cfgdisk->src = cfgbase;
 
-        virObjectUnref(cfgtop);
+        g_clear_object(&cfgtop);
     }
 }
 
@@ -1261,7 +1254,7 @@ qemuBlockJobProcessEventCompletedActiveCommit(virQEMUDriverPtr driver,
         cfgbaseparent->backingStore = NULL;
         cfgdisk->src = cfgbase;
         cfgdisk->src->readonly = cfgtop->readonly;
-        virObjectUnref(cfgtop);
+        g_clear_object(&cfgtop);
     }
 
     /* Move security driver metadata */
@@ -1277,11 +1270,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);
 }
 
 
@@ -1309,8 +1300,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);
 }
 
 
@@ -1328,8 +1318,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);
 }
 
 
@@ -1350,8 +1339,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);
 }
 
 
@@ -1401,8 +1389,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 a61c16eb2a..be7c6837b5 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1162,8 +1162,7 @@ qemuDomainDiskPrivateDispose(GObject *obj)
 {
     qemuDomainDiskPrivatePtr priv = QEMU_DOMAIN_DISK(obj);
 
-    virObjectUnref(priv->migrSource);
-    priv->migrSource = NULL;
+    g_clear_object(&priv->migrSource);
     g_clear_object(&priv->blockjob);
 
     G_OBJECT_CLASS(qemu_domain_disk_private_parent_class)->dispose(obj);
@@ -2258,10 +2257,8 @@ qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr priv)
 
     virHashRemoveAll(priv->blockjobs);
 
-    virObjectUnref(priv->pflash0);
-    priv->pflash0 = NULL;
-    virObjectUnref(priv->pflash1);
-    priv->pflash1 = NULL;
+    g_clear_object(&priv->pflash0);
+    g_clear_object(&priv->pflash1);
 
     virDomainBackupDefFree(priv->backup);
     priv->backup = NULL;
@@ -3396,7 +3393,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 0f26a81391..baec1602b4 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,7 @@ virStorageSourceBackingStoreClear(virStorageSourcePtr def)
     VIR_FREE(def->backingStoreRaw);
 
     /* recursively free backing chain */
-    virObjectUnref(def->backingStore);
-    def->backingStore = NULL;
+    g_clear_object(&def->backingStore);
 }
 
 
@@ -2712,8 +2725,7 @@ virStorageSourceClear(virStorageSourcePtr def)
 
     virStorageSourceSliceFree(def->sliceStorage);
 
-    virObjectUnref(def->externalDataStore);
-    def->externalDataStore = NULL;
+    g_clear_object(&def->externalDataStore);
 
     virStorageNetHostDefFree(def->nhosts, def->hosts);
     virStorageAuthDefFree(def->auth);
@@ -2739,34 +2751,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.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