7a3408
From b70bc3fb7517fe18b7ef6d2c3801c3b217f977bb Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <b70bc3fb7517fe18b7ef6d2c3801c3b217f977bb@dist-git>
7a3408
From: Jiri Denemark <jdenemar@redhat.com>
7a3408
Date: Thu, 2 Jul 2015 22:32:54 +0200
7a3408
Subject: [PATCH] qemu: Don't report false error from MigrateFinish
7a3408
7a3408
virDomainMigrateFinish* APIs were unfortunately designed to return the
7a3408
pointer to the domain on destination and NULL on error. This looks OK in
7a3408
normal cases but the same API is also called when we know migration
7a3408
failed and thus we expect Finish to return NULL even if it actually did
7a3408
all it was supposed to do without any error. The call is defined to
7a3408
return nonnull domain pointer over RPC, which means returning NULL will
7a3408
always result in an error being send. If this was not in fact an error,
7a3408
the API itself wouldn't set anything to the thread local virError, which
7a3408
makes the RPC layer come up with it's own "Library function returned
7a3408
error but did not set virError" error.
7a3408
7a3408
This is quite confusing and also hard to detect by the caller. This
7a3408
patch adds a special error code which can be used to check that Finish
7a3408
successfully aborted migration.
7a3408
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
(cherry picked from commit 44c42b564dc61ddc8fdfc5b6ca4ca969bcffc7d8)
7a3408
7a3408
https://bugzilla.redhat.com/show_bug.cgi?id=1090093
7a3408
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 include/libvirt/virterror.h | 1 +
7a3408
 src/qemu/qemu_migration.c   | 6 ++++++
7a3408
 src/util/virerror.c         | 3 +++
7a3408
 3 files changed, 10 insertions(+)
7a3408
7a3408
diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h
7a3408
index 6325030..f716cb9 100644
7a3408
--- a/include/libvirt/virterror.h
7a3408
+++ b/include/libvirt/virterror.h
7a3408
@@ -307,6 +307,7 @@ typedef enum {
7a3408
     VIR_ERR_CPU_INCOMPATIBLE = 91,      /* given CPU is incompatible with host
7a3408
                                            CPU*/
7a3408
     VIR_ERR_XML_INVALID_SCHEMA = 92,    /* XML document doesn't validate against schema */
7a3408
+    VIR_ERR_MIGRATE_FINISH_OK = 93,     /* Finish API succeeded but it is expected to return NULL */
7a3408
 } virErrorNumber;
7a3408
 
7a3408
 /**
7a3408
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
7a3408
index 58874ee..a9cbada 100644
7a3408
--- a/src/qemu/qemu_migration.c
7a3408
+++ b/src/qemu/qemu_migration.c
7a3408
@@ -5751,6 +5751,12 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
7a3408
     }
7a3408
     virObjectUnref(caps);
7a3408
     virObjectUnref(cfg);
7a3408
+
7a3408
+    /* Set a special error if Finish is expected to return NULL as a result of
7a3408
+     * successful call with retcode != 0
7a3408
+     */
7a3408
+    if (retcode != 0 && !dom && !virGetLastError())
7a3408
+        virReportError(VIR_ERR_MIGRATE_FINISH_OK, NULL);
7a3408
     return dom;
7a3408
 }
7a3408
 
7a3408
diff --git a/src/util/virerror.c b/src/util/virerror.c
7a3408
index 60b2e79..6dc05f4 100644
7a3408
--- a/src/util/virerror.c
7a3408
+++ b/src/util/virerror.c
7a3408
@@ -1369,6 +1369,9 @@ virErrorMsg(virErrorNumber error, const char *info)
7a3408
             else
7a3408
                 errmsg = _("XML document failed to validate against schema: %s");
7a3408
             break;
7a3408
+        case VIR_ERR_MIGRATE_FINISH_OK:
7a3408
+            errmsg = _("migration successfully aborted");
7a3408
+            break;
7a3408
     }
7a3408
     return errmsg;
7a3408
 }
7a3408
-- 
7a3408
2.4.5
7a3408