diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c index c7b7bfc944..ef71d8f0f9 100644 --- a/src/qemu/qemu_blockjob.c +++ b/src/qemu/qemu_blockjob.c @@ -42,14 +42,37 @@ VIR_LOG_INIT("qemu.qemu_blockjob"); -void -qemuBlockJobDataFree(qemuBlockJobDataPtr job) +static virClassPtr qemuBlockJobDataClass; + + +static void +qemuBlockJobDataDispose(void *obj) { - if (!job) - return; + qemuBlockJobDataPtr job = obj; VIR_FREE(job->errmsg); - VIR_FREE(job); +} + + +static int +qemuBlockJobDataOnceInit(void) +{ + if (!VIR_CLASS_NEW(qemuBlockJobData, virClassForObject())) + return -1; + + return 0; +} + + +VIR_ONCE_GLOBAL_INIT(qemuBlockJobData) + +qemuBlockJobDataPtr +qemuBlockJobDataNew(void) +{ + if (qemuBlockJobDataInitialize() < 0) + return NULL; + + return virObjectNew(qemuBlockJobDataClass); } diff --git a/src/qemu/qemu_blockjob.h b/src/qemu/qemu_blockjob.h index 1785414172..fc794d3d0b 100644 --- a/src/qemu/qemu_blockjob.h +++ b/src/qemu/qemu_blockjob.h @@ -30,6 +30,8 @@ typedef struct _qemuBlockJobData qemuBlockJobData; typedef qemuBlockJobData *qemuBlockJobDataPtr; struct _qemuBlockJobData { + virObject parent; + bool started; int type; int status; @@ -37,8 +39,7 @@ struct _qemuBlockJobData { bool synchronous; /* API call is waiting for this job */ }; -void -qemuBlockJobDataFree(qemuBlockJobDataPtr job); +qemuBlockJobDataPtr qemuBlockJobDataNew(void); int qemuBlockJobUpdateDisk(virDomainObjPtr vm, int asyncJob, diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index aa8fe11147..7030aa448e 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1063,7 +1063,7 @@ qemuDomainDiskPrivateNew(void) if (!(priv = virObjectNew(qemuDomainDiskPrivateClass))) return NULL; - if (VIR_ALLOC(priv->blockjob) < 0) { + if (!(priv->blockjob = qemuBlockJobDataNew())) { virObjectUnref(priv); priv = NULL; } @@ -1079,7 +1079,7 @@ qemuDomainDiskPrivateDispose(void *obj) virStorageSourceFree(priv->migrSource); VIR_FREE(priv->qomName); VIR_FREE(priv->nodeCopyOnRead); - qemuBlockJobDataFree(priv->blockjob); + virObjectUnref(priv->blockjob); } static virClassPtr qemuDomainStorageSourcePrivateClass;