[PATCH RFC 25/51] qemu: migration: Extract reporting of disk migration error

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

 



The same message is reported in 3 distinct places. Move it out into a
single function.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_migration.c | 43 ++++++++++++++++-----------------------
 1 file changed, 18 insertions(+), 25 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index bde8697ede..1ce7863460 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -463,6 +463,21 @@ qemuMigrationDstStopNBDServer(virQEMUDriverPtr driver,
 }


+static void
+qemuMigrationNBDReportMirrorError(virDomainDiskDefPtr disk,
+                                  const char *errmsg)
+{
+    if (errmsg) {
+        virReportError(VIR_ERR_OPERATION_FAILED,
+                       _("migration of disk %s failed: %s"),
+                       disk->dst, errmsg);
+    } else {
+        virReportError(VIR_ERR_OPERATION_FAILED,
+                       _("migration of disk %s failed"), disk->dst);
+    }
+}
+
+
 /**
  * qemuMigrationSrcNBDStorageCopyReady:
  * @vm: domain
@@ -492,15 +507,7 @@ qemuMigrationSrcNBDStorageCopyReady(virDomainObjPtr vm,

         status = qemuBlockJobUpdateDisk(vm, asyncJob, disk, &error);
         if (status == VIR_DOMAIN_BLOCK_JOB_FAILED) {
-            if (error) {
-                virReportError(VIR_ERR_OPERATION_FAILED,
-                               _("migration of disk %s failed: %s"),
-                               disk->dst, error);
-                VIR_FREE(error);
-            } else {
-                virReportError(VIR_ERR_OPERATION_FAILED,
-                               _("migration of disk %s failed"), disk->dst);
-            }
+            qemuMigrationNBDReportMirrorError(disk, error);
             return -1;
         }
         VIR_FREE(error);
@@ -553,14 +560,7 @@ qemuMigrationSrcNBDCopyCancelled(virDomainObjPtr vm,
         switch (status) {
         case VIR_DOMAIN_BLOCK_JOB_FAILED:
             if (check) {
-                if (error) {
-                    virReportError(VIR_ERR_OPERATION_FAILED,
-                                   _("migration of disk %s failed: %s"),
-                                   disk->dst, error);
-                } else {
-                    virReportError(VIR_ERR_OPERATION_FAILED,
-                                   _("migration of disk %s failed"), disk->dst);
-                }
+                qemuMigrationNBDReportMirrorError(disk, error);
                 failed = true;
             }
             ATTRIBUTE_FALLTHROUGH;
@@ -635,14 +635,7 @@ qemuMigrationSrcNBDCopyCancelOne(virQEMUDriverPtr driver,
     case VIR_DOMAIN_BLOCK_JOB_FAILED:
     case VIR_DOMAIN_BLOCK_JOB_CANCELED:
         if (failNoJob) {
-            if (error) {
-                virReportError(VIR_ERR_OPERATION_FAILED,
-                               _("migration of disk %s failed: %s"),
-                               disk->dst, error);
-            } else {
-                virReportError(VIR_ERR_OPERATION_FAILED,
-                               _("migration of disk %s failed"), disk->dst);
-            }
+            qemuMigrationNBDReportMirrorError(disk, error);
             goto cleanup;
         }
         ATTRIBUTE_FALLTHROUGH;
-- 
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