On Thu, Oct 12, 2017 at 03:48:29PM +0200, Jiri Denemark wrote:
When migration fails, QEMU may provide a description of the error in
the reply to query-migrate QMP command. We can fetch this error and use
it instead of the generic "unexpectedly failed" message.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/qemu/qemu_driver.c | 3 ++-
src/qemu/qemu_migration.c | 36 +++++++++++++++++++++++-------------
src/qemu/qemu_migration.h | 3 ++-
src/qemu/qemu_monitor.c | 8 ++++++--
src/qemu/qemu_monitor.h | 3 ++-
src/qemu/qemu_monitor_json.c | 18 ++++++++++++++----
src/qemu/qemu_monitor_json.h | 3 ++-
tests/qemumonitorjsontest.c | 29 ++++++++++++++++++++++++++---
8 files changed, 77 insertions(+), 26 deletions(-)
[...]
diff --git a/tests/qemumonitorjsontest.c
b/tests/qemumonitorjsontest.c
index df3ef0a932..475fd270e1 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -1907,6 +1907,7 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationStats(const void
*data)
qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
int ret = -1;
qemuMonitorMigrationStats stats, expectedStats;
+ char *error = NULL;
if (!test)
return -1;
@@ -1931,21 +1932,43 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationStats(const void
*data)
" }"
" },"
" \"id\":
\"libvirt-13\""
+ "}") < 0 ||
+ qemuMonitorTestAddItem(test, "query-migrate",
+ "{"
+ " \"return\": {"
+ " \"status\":
\"failed\","
+ " \"error-desc\": \"It's
broken\""
+ " },"
+ " \"id\":
\"libvirt-14\""
"}") < 0)
goto cleanup;
- if (qemuMonitorJSONGetMigrationStats(qemuMonitorTestGetMonitor(test), &stats)
< 0)
+ if (qemuMonitorJSONGetMigrationStats(qemuMonitorTestGetMonitor(test),
+ &stats, &error) < 0)
goto cleanup;
- if (memcmp(&stats, &expectedStats, sizeof(stats)) != 0) {
+ if (memcmp(&stats, &expectedStats, sizeof(stats)) != 0 || error) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- "Invalid migration status");
+ "Invalid migration statistics");
+ goto cleanup;
+ }
Do we need to pass the "&error" for the first call of
qemuMonitorJSONGetMigrationStats() since we know the answer?
+
+ memset(&stats, 0, sizeof(stats));
+ if (qemuMonitorJSONGetMigrationStats(qemuMonitorTestGetMonitor(test),
+ &stats, &error) < 0)
+ goto cleanup;
+
+ if (stats.status != QEMU_MONITOR_MIGRATION_STATUS_ERROR ||
+ STRNEQ_NULLABLE(error, "It's broken")) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ "Invalid failed migration status");
goto cleanup;
}
ret = 0;
cleanup:
qemuMonitorTestFree(test);
+ VIR_FREE(error);
return ret;
}
Reviewed-by: Pavel Hrdina <phrdina(a)redhat.com>