Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/libvirt_private.syms | 1 +
src/qemu/qemu_blockjob.c | 64 ++++++++++++++++-----------------------
src/qemu/qemu_domain.c | 10 +++---
src/util/virstoragefile.c | 40 ++++++++++++------------
src/util/virstoragefile.h | 6 ++--
5 files changed, 55 insertions(+), 66 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 14dace4628..8bc510c5bc 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -3092,6 +3092,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 671bfad19b..cd16b81a24 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,8 @@ qemuBlockJobDataFinalize(GObject *obj)
{
qemuBlockJobDataPtr job = QEMU_BLOCK_JOB_DATA(obj);
- virObjectUnref(job->chain);
- virObjectUnref(job->mirrorChain);
+ g_clear_object(&job->chain);
+ g_clear_object(&job->mirrorChain);
qemuBlockJobDataDisposeJobdata(job);
@@ -185,7 +185,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 +337,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 +370,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 +399,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 +688,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(©);
+ g_set_object(&persistDisk->src, copy);
}
@@ -729,8 +727,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 +737,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 +814,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 +926,7 @@ qemuBlockJobClearConfigChain(virDomainObjPtr vm,
if (!virStorageSourceIsSameLocation(disk->src, cfgdisk->src))
return;
- virObjectUnref(cfgdisk->src->backingStore);
- cfgdisk->src->backingStore = NULL;
+ g_clear_object(&cfgdisk->src->backingStore);
}
@@ -997,14 +992,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);
}
}
@@ -1171,8 +1166,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 +1177,7 @@ qemuBlockJobProcessEventCompletedCommit(virQEMUDriverPtr driver,
else
cfgdisk->src = cfgbase;
- virObjectUnref(cfgtop);
+ g_clear_object(&cfgtop);
}
}
@@ -1249,7 +1243,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 */
@@ -1265,11 +1259,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);
}
@@ -1302,8 +1294,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);
}
@@ -1321,8 +1312,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);
}
@@ -1343,8 +1333,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);
}
@@ -1394,8 +1383,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 02f0ccaa08..336a2f53c3 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1184,7 +1184,7 @@ qemuDomainDiskPrivateFinalize(GObject *obj)
{
qemuDomainDiskPrivatePtr priv = QEMU_DOMAIN_DISK(obj);
- virObjectUnref(priv->migrSource);
+ g_clear_object(&priv->migrSource);
VIR_FREE(priv->qomName);
VIR_FREE(priv->nodeCopyOnRead);
g_clear_object(&priv->blockjob);
@@ -2270,10 +2270,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;
@@ -3410,7 +3408,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 173a6a75f3..7f56a20215 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,
@@ -2654,8 +2668,7 @@ virStorageSourceBackingStoreClear(virStorageSourcePtr def)
VIR_FREE(def->backingStoreRaw);
/* recursively free backing chain */
- virObjectUnref(def->backingStore);
- def->backingStore = NULL;
+ g_clear_object(&def->backingStore);
}
@@ -2707,34 +2720,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 58e8e1d8cf..c8bab3aaf8 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 */
@@ -386,7 +386,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.26.2