The wrapper is useful for calling qemuBlockJobEventProcess with the
event details stored in disk's privateData, which is the most likely
usage of qemuBlockJobEventProcess.

Signed-off-by: Jiri Denemark <jdene...@redhat.com>
---

Notes:
    ACKed in version 1 and 2
    
    Version 3:
    - better flow in qemuBlockJobUpdate
    - document qemuBlockJobUpdate
    
    Version 2:
    - no changes
    
    ACKed in version 1 and 2
    
    Version 3:
    - better flow in qemuBlockJobUpdate
    
    Version 2:
    - no changes

 src/libvirt_private.syms |  2 ++
 src/qemu/qemu_blockjob.c | 47 +++++++++++++++++++++++++++++++++++++++--------
 src/qemu/qemu_blockjob.h |  3 +++
 3 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 62a4b4c..0c9fa06 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -265,6 +265,8 @@ virDomainDiskInsert;
 virDomainDiskInsertPreAlloced;
 virDomainDiskIoTypeFromString;
 virDomainDiskIoTypeToString;
+virDomainDiskMirrorStateTypeFromString;
+virDomainDiskMirrorStateTypeToString;
 virDomainDiskPathByName;
 virDomainDiskRemove;
 virDomainDiskRemoveByName;
diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c
index 098a43a..eb05cef 100644
--- a/src/qemu/qemu_blockjob.c
+++ b/src/qemu/qemu_blockjob.c
@@ -38,6 +38,37 @@
 
 VIR_LOG_INIT("qemu.qemu_blockjob");
 
+
+/**
+ * qemuBlockJobUpdate:
+ * @driver: qemu driver
+ * @vm: domain
+ * @disk: domain disk
+ *
+ * Update disk's mirror state in response to a block job event stored in
+ * blockJobStatus by qemuProcessHandleBlockJob event handler.
+ *
+ * Returns the block job event processed or -1 if there was no pending event.
+ */
+int
+qemuBlockJobUpdate(virQEMUDriverPtr driver,
+                   virDomainObjPtr vm,
+                   virDomainDiskDefPtr disk)
+{
+    qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
+    int status = diskPriv->blockJobStatus;
+
+    if (status != -1) {
+        qemuBlockJobEventProcess(driver, vm, disk,
+                                 diskPriv->blockJobType,
+                                 diskPriv->blockJobStatus);
+        diskPriv->blockJobStatus = -1;
+    }
+
+    return status;
+}
+
+
 /**
  * qemuBlockJobEventProcess:
  * @driver: qemu driver
@@ -49,8 +80,6 @@ VIR_LOG_INIT("qemu.qemu_blockjob");
  * Update disk's mirror state in response to a block job event
  * from QEMU. For mirror state's that must survive libvirt
  * restart, also update the domain's status XML.
- *
- * Returns 0 on success, -1 otherwise.
  */
 void
 qemuBlockJobEventProcess(virQEMUDriverPtr driver,
@@ -67,6 +96,12 @@ qemuBlockJobEventProcess(virQEMUDriverPtr driver,
     bool save = false;
     qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
 
+    VIR_DEBUG("disk=%s, mirrorState=%s, type=%d, status=%d",
+              disk->dst,
+              NULLSTR(virDomainDiskMirrorStateTypeToString(disk->mirrorState)),
+              type,
+              status);
+
     /* Have to generate two variants of the event for old vs. new
      * client callbacks */
     if (type == VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT &&
@@ -218,9 +253,7 @@ qemuBlockJobSyncEnd(virQEMUDriverPtr driver,
     if (diskPriv->blockJobSync && diskPriv->blockJobStatus != -1) {
         if (ret_status)
             *ret_status = diskPriv->blockJobStatus;
-        qemuBlockJobEventProcess(driver, vm, disk,
-                                 diskPriv->blockJobType,
-                                 diskPriv->blockJobStatus);
+        qemuBlockJobUpdate(driver, vm, disk);
         diskPriv->blockJobStatus = -1;
     }
     diskPriv->blockJobSync = false;
@@ -300,9 +333,7 @@ qemuBlockJobSyncWaitWithTimeout(virQEMUDriverPtr driver,
 
     if (ret_status)
         *ret_status = diskPriv->blockJobStatus;
-    qemuBlockJobEventProcess(driver, vm, disk,
-                             diskPriv->blockJobType,
-                             diskPriv->blockJobStatus);
+    qemuBlockJobUpdate(driver, vm, disk);
     diskPriv->blockJobStatus = -1;
 
     return 0;
diff --git a/src/qemu/qemu_blockjob.h b/src/qemu/qemu_blockjob.h
index ba372a2..81e893e 100644
--- a/src/qemu/qemu_blockjob.h
+++ b/src/qemu/qemu_blockjob.h
@@ -25,6 +25,9 @@
 # include "internal.h"
 # include "qemu_conf.h"
 
+int qemuBlockJobUpdate(virQEMUDriverPtr driver,
+                       virDomainObjPtr vm,
+                       virDomainDiskDefPtr disk);
 void qemuBlockJobEventProcess(virQEMUDriverPtr driver,
                               virDomainObjPtr vm,
                               virDomainDiskDefPtr disk,
-- 
2.4.3

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

Reply via email to