We want to have all migration capabilities parsing and formatting at one
place, i.e., in qemu_migration_params.c. The parsing is already there in
qemuMigrationCapsCheck.
Signed-off-by: Jiri Denemark
---
src/qemu/qemu_migration_params.c | 66 ++--
src/qemu/qemu_migration_paramspriv.h | 4 ++
src/qemu/qemu_monitor.c | 27 +++-
src/qemu/qemu_monitor.h | 3 +-
src/qemu/qemu_monitor_json.c | 40 ++---
src/qemu/qemu_monitor_json.h | 3 +-
tests/qemumonitorjsontest.c | 11 +++--
7 files changed, 96 insertions(+), 58 deletions(-)
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 77abc7191f..548bb1c0dd 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -591,6 +591,53 @@ qemuMigrationParamsToJSON(qemuMigrationParamsPtr migParams)
}
+virJSONValuePtr
+qemuMigrationCapsToJSON(virBitmapPtr caps,
+virBitmapPtr states)
+{
+virJSONValuePtr json = NULL;
+virJSONValuePtr cap = NULL;
+qemuMonitorMigrationCaps bit;
+const char *name;
+
+if (!(json = virJSONValueNewArray()))
+return NULL;
+
+for (bit = 0; bit < QEMU_MONITOR_MIGRATION_CAPS_LAST; bit++) {
+bool supported = false;
+bool state = false;
+
+ignore_value(virBitmapGetBit(caps, bit, ));
+if (!supported)
+continue;
+
+ignore_value(virBitmapGetBit(states, bit, ));
+
+if (!(cap = virJSONValueNewObject()))
+goto error;
+
+name = qemuMonitorMigrationCapsTypeToString(bit);
+if (virJSONValueObjectAppendString(cap, "capability", name) < 0)
+goto error;
+
+if (virJSONValueObjectAppendBoolean(cap, "state", state) < 0)
+goto error;
+
+if (virJSONValueArrayAppend(json, cap) < 0)
+goto error;
+
+cap = NULL;
+}
+
+return json;
+
+ error:
+virJSONValueFree(json);
+virJSONValueFree(cap);
+return NULL;
+}
+
+
/**
* qemuMigrationParamsApply
* @driver: qemu driver
@@ -611,6 +658,7 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver,
qemuDomainObjPrivatePtr priv = vm->privateData;
bool xbzrleCacheSize_old = false;
virJSONValuePtr params = NULL;
+virJSONValuePtr caps = NULL;
qemuMigrationParam xbzrle = QEMU_MIGRATION_PARAM_XBZRLE_CACHE_SIZE;
int ret = -1;
int rc;
@@ -618,10 +666,16 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver,
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
return -1;
-if (qemuMonitorSetMigrationCapabilities(priv->mon, priv->migrationCaps,
-migParams->caps) < 0)
+if (!(caps = qemuMigrationCapsToJSON(priv->migrationCaps,
migParams->caps)))
goto cleanup;
+if (virJSONValueArraySize(caps) > 0) {
+rc = qemuMonitorSetMigrationCapabilities(priv->mon, caps);
+caps = NULL;
+if (rc < 0)
+goto cleanup;
+}
+
/* If QEMU is too old to support xbzrle-cache-size migration parameter,
* we need to set it via migrate-set-cache-size and tell
* qemuMonitorSetMigrationParams to ignore this parameter.
@@ -974,6 +1028,7 @@ qemuMigrationCapsCheck(virQEMUDriverPtr driver,
{
qemuDomainObjPrivatePtr priv = vm->privateData;
virBitmapPtr migEvent = NULL;
+virJSONValuePtr json = NULL;
char **caps = NULL;
char **capStr;
int ret = -1;
@@ -1014,10 +1069,14 @@ qemuMigrationCapsCheck(virQEMUDriverPtr driver,
ignore_value(virBitmapSetBit(migEvent,
QEMU_MONITOR_MIGRATION_CAPS_EVENTS));
+if (!(json = qemuMigrationCapsToJSON(migEvent, migEvent)))
+goto cleanup;
+
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
goto cleanup;
-rc = qemuMonitorSetMigrationCapabilities(priv->mon, migEvent,
migEvent);
+rc = qemuMonitorSetMigrationCapabilities(priv->mon, json);
+json = NULL;
if (qemuDomainObjExitMonitor(driver, vm) < 0)
goto cleanup;
@@ -1039,6 +1098,7 @@ qemuMigrationCapsCheck(virQEMUDriverPtr driver,
ret = 0;
cleanup:
+virJSONValueFree(json);
virStringListFree(caps);
return ret;
}
diff --git a/src/qemu/qemu_migration_paramspriv.h
b/src/qemu/qemu_migration_paramspriv.h
index 350973b6f9..30773a679d 100644
--- a/src/qemu/qemu_migration_paramspriv.h
+++ b/src/qemu/qemu_migration_paramspriv.h
@@ -28,4 +28,8 @@ qemuMigrationParamsToJSON(qemuMigrationParamsPtr migParams);
qemuMigrationParamsPtr
qemuMigrationParamsFromJSON(virJSONValuePtr params);
+virJSONValuePtr
+qemuMigrationCapsToJSON(virBitmapPtr caps,
+virBitmapPtr states);
+
#endif /* __QEMU_MIGRATION_PARAMSPRIV_H__ */
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 641465f227..13d885ffc5 100644
--- a/src/qemu/qemu_monitor.c