Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/qemu/qemu_blockjob.c | 55 ++++++++++++++++++---------------------
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, 43 insertions(+), 50 deletions(-)
diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c
index e51499532f..671bfad19b 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);
}
@@ -1743,7 +1740,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 41dfba5597..e422db80a5 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1190,7 +1190,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;
@@ -2239,7 +2239,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 ab5a7aef84..1826c4f997 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -4277,8 +4277,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 26e8d067ea..64897d0aa2 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) {
@@ -5435,7 +5427,7 @@ qemuMigrationSrcCancel(virQEMUDriverPtr driver,
storage = true;
}
- virObjectUnref(job);
+ g_clear_object(&job);
}
if (storage &&
--
2.26.2