[PATCH 1/2] qemuDomainGetBlockJobInfo: Move info translation into separate func

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

 



Even though we merely just pass to users whatever qemu provided
on the monitor, we still do some translation. For instance we
turn bytes into mebibytes, or fix job type if needed. However, in
the future there is more fixing to be done so this code deserves
its own function.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c | 46 ++++++++++++++++++++++++++++++----------------
 1 file changed, 30 insertions(+), 16 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 807e06d..4535eb8 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -16330,6 +16330,34 @@ qemuDomainBlockJobAbort(virDomainPtr dom,
 
 
 static int
+qemuBlockJobInfoTranslate(qemuMonitorBlockJobInfoPtr rawInfo,
+                          virDomainBlockJobInfoPtr info,
+                          virDomainDiskDefPtr disk,
+                          bool reportBytes)
+{
+    info->cur = rawInfo->cur;
+    info->end = rawInfo->end;
+
+    info->type = rawInfo->type;
+    if (info->type == VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT &&
+        disk->mirrorJob == VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT)
+        info->type = disk->mirrorJob;
+
+    if (rawInfo->bandwidth && !reportBytes)
+        rawInfo->bandwidth = VIR_DIV_UP(rawInfo->bandwidth, 1024 * 1024);
+    info->bandwidth = rawInfo->bandwidth;
+    if (info->bandwidth != rawInfo->bandwidth) {
+        virReportError(VIR_ERR_OVERFLOW,
+                       _("bandwidth %llu cannot be represented in result"),
+                       rawInfo->bandwidth);
+        return -1;
+    }
+
+    return 0;
+}
+
+
+static int
 qemuDomainGetBlockJobInfo(virDomainPtr dom,
                           const char *path,
                           virDomainBlockJobInfoPtr info,
@@ -16376,22 +16404,8 @@ qemuDomainGetBlockJobInfo(virDomainPtr dom,
     if (ret <= 0)
         goto endjob;
 
-    info->cur = rawInfo.cur;
-    info->end = rawInfo.end;
-
-    info->type = rawInfo.type;
-    if (info->type == VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT &&
-        disk->mirrorJob == VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT)
-        info->type = disk->mirrorJob;
-
-    if (rawInfo.bandwidth &&
-        !(flags & VIR_DOMAIN_BLOCK_JOB_INFO_BANDWIDTH_BYTES))
-        rawInfo.bandwidth = VIR_DIV_UP(rawInfo.bandwidth, 1024 * 1024);
-    info->bandwidth = rawInfo.bandwidth;
-    if (info->bandwidth != rawInfo.bandwidth) {
-        virReportError(VIR_ERR_OVERFLOW,
-                       _("bandwidth %llu cannot be represented in result"),
-                       rawInfo.bandwidth);
+    if (qemuBlockJobInfoTranslate(&rawInfo, info, disk,
+                                  flags & VIR_DOMAIN_BLOCK_JOB_INFO_BANDWIDTH_BYTES) < 0) {
         ret = -1;
         goto endjob;
     }
-- 
2.8.4

--
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]