The same message is reported in 3 distinct places. Move it out into a
single function.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
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