[PATCH RFC 15/51] qemu: blockjob: Turn struct qemuBlockJobData into a virObject

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Reference counting will simplify semantics of the lifecycle of the
object.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_blockjob.c | 33 ++++++++++++++++++++++++++++-----
 src/qemu/qemu_blockjob.h |  5 +++--
 src/qemu/qemu_domain.c   |  4 ++--
 3 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c
index a7cdc3c068..cf1710a0e8 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 1479c6f720..de1ad7039d 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 5a64231f95..9c3ab426bd 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1062,7 +1062,7 @@ qemuDomainDiskPrivateNew(void)
     if (!(priv = virObjectNew(qemuDomainDiskPrivateClass)))
         return NULL;

-    if (VIR_ALLOC(priv->blockjob) < 0) {
+    if (!(priv->blockjob = qemuBlockJobDataNew())) {
         virObjectUnref(priv);
         priv = NULL;
     }
@@ -1078,7 +1078,7 @@ qemuDomainDiskPrivateDispose(void *obj)
     virStorageSourceFree(priv->migrSource);
     VIR_FREE(priv->qomName);
     VIR_FREE(priv->nodeCopyOnRead);
-    qemuBlockJobDataFree(priv->blockjob);
+    virObjectUnref(priv->blockjob);
 }

 static virClassPtr qemuDomainStorageSourcePrivateClass;
-- 
2.19.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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