The function can now optionally return a bitmap describing the current state of each migration capability. Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx> --- src/qemu/qemu_capabilities.c | 2 +- src/qemu/qemu_migration_params.c | 2 +- src/qemu/qemu_monitor.c | 5 +++-- src/qemu/qemu_monitor.h | 3 ++- src/qemu/qemu_monitor_json.c | 18 +++++++++++++++++- src/qemu/qemu_monitor_json.h | 3 ++- tests/qemumonitorjsontest.c | 12 +++++++++++- 7 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 1ed4cda7f0..cd13847918 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -3347,7 +3347,7 @@ virQEMUCapsProbeQMPMigrationCapabilities(virQEMUCaps *qemuCaps, { g_auto(GStrv) caps = NULL; - if (qemuMonitorGetMigrationCapabilities(mon, &caps) < 0) + if (qemuMonitorGetMigrationCapabilities(mon, &caps, NULL) < 0) return -1; virQEMUCapsProcessStringFlags(qemuCaps, diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c index df2384b213..34416f89be 100644 --- a/src/qemu/qemu_migration_params.c +++ b/src/qemu/qemu_migration_params.c @@ -1397,7 +1397,7 @@ qemuMigrationCapsCheck(virQEMUDriver *driver, if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) return -1; - rc = qemuMonitorGetMigrationCapabilities(priv->mon, &caps); + rc = qemuMonitorGetMigrationCapabilities(priv->mon, &caps, NULL); qemuDomainObjExitMonitor(vm); if (rc < 0) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 316cff5b9b..98cf1c949e 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3636,11 +3636,12 @@ qemuMonitorGetTargetArch(qemuMonitor *mon) int qemuMonitorGetMigrationCapabilities(qemuMonitor *mon, - char ***capabilities) + char ***capabilities, + virBitmap **state) { QEMU_CHECK_MONITOR(mon); - return qemuMonitorJSONGetMigrationCapabilities(mon, capabilities); + return qemuMonitorJSONGetMigrationCapabilities(mon, capabilities, state); } diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 5c2a749282..abc29eaf4c 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -890,7 +890,8 @@ int qemuMonitorGetMigrationStats(qemuMonitor *mon, char **error); int qemuMonitorGetMigrationCapabilities(qemuMonitor *mon, - char ***capabilities); + char ***capabilities, + virBitmap **state); int qemuMonitorSetMigrationCapabilities(qemuMonitor *mon, virJSONValue **caps); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 9e611e93e8..532aad348e 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6210,12 +6210,14 @@ qemuMonitorJSONGetTargetArch(qemuMonitor *mon) int qemuMonitorJSONGetMigrationCapabilities(qemuMonitor *mon, - char ***capabilities) + char ***capabilities, + virBitmap **state) { g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; virJSONValue *caps; g_auto(GStrv) list = NULL; + g_autoptr(virBitmap) bitmap = NULL; size_t i; size_t n; @@ -6235,10 +6237,12 @@ qemuMonitorJSONGetMigrationCapabilities(qemuMonitor *mon, n = virJSONValueArraySize(caps); list = g_new0(char *, n + 1); + bitmap = virBitmapNew(n); for (i = 0; i < n; i++) { virJSONValue *cap = virJSONValueArrayGet(caps, i); const char *name; + bool enabled = false; if (!cap || virJSONValueGetType(cap) != VIR_JSON_TYPE_OBJECT) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -6252,10 +6256,22 @@ qemuMonitorJSONGetMigrationCapabilities(qemuMonitor *mon, return -1; } + if (virJSONValueObjectGetBoolean(cap, "state", &enabled) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing migration capability state")); + return -1; + } + list[i] = g_strdup(name); + + if (enabled) + ignore_value(virBitmapSetBit(bitmap, i)); } *capabilities = g_steal_pointer(&list); + if (state) + *state = g_steal_pointer(&bitmap); + return n; } diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 982fbad44e..afd100f653 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -182,7 +182,8 @@ qemuMonitorJSONGetMigrationStats(qemuMonitor *mon, int qemuMonitorJSONGetMigrationCapabilities(qemuMonitor *mon, - char ***capabilities); + char ***capabilities, + virBitmap **state); int qemuMonitorJSONSetMigrationCapabilities(qemuMonitor *mon, virJSONValue **caps); diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 99198de0ed..8ce96885e3 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2051,6 +2051,9 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationCapabilities(const void *opaque) g_auto(GStrv) caps = NULL; g_autoptr(virBitmap) bitmap = NULL; g_autoptr(virJSONValue) json = NULL; + g_autoptr(virBitmap) state = NULL; + g_autofree char *stateActual = NULL; + const char *stateExpected = "1"; const char *reply = "{" " \"return\": [" @@ -2076,7 +2079,7 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationCapabilities(const void *opaque) return -1; if (qemuMonitorGetMigrationCapabilities(qemuMonitorTestGetMonitor(test), - &caps) < 0) + &caps, &state) < 0) return -1; for (cap = 0; cap < QEMU_MIGRATION_CAP_LAST; cap++) { @@ -2100,6 +2103,13 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationCapabilities(const void *opaque) } } + stateActual = virBitmapFormat(state); + if (STRNEQ_NULLABLE(stateExpected, stateActual)) { + VIR_TEST_VERBOSE("Excepted capabilities state: '%s', got: '%s'", + NULLSTR(stateExpected), NULLSTR(stateActual)); + return -1; + } + bitmap = virBitmapNew(QEMU_MIGRATION_CAP_LAST); ignore_value(virBitmapSetBit(bitmap, QEMU_MIGRATION_CAP_XBZRLE)); if (!(json = qemuMigrationCapsToJSON(bitmap, bitmap))) -- 2.35.1