Our current monitor API forces the caller to call
migrate-set-capabilities QMP command for each capability separately,
which is quite suboptimal. Let's add a new API for setting all
capabilities at once.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/qemu/qemu_monitor.c | 19 +++++++++++
src/qemu/qemu_monitor.h | 3 ++
src/qemu/qemu_monitor_json.c | 63 ++++++++++++++++++++++++++++++++++++
src/qemu/qemu_monitor_json.h | 3 ++
4 files changed, 88 insertions(+)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 7b647525b3..7ea72af788 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3991,6 +3991,25 @@ qemuMonitorSetMigrationCapability(qemuMonitorPtr mon,
}
+int
+qemuMonitorSetMigrationCapabilities(qemuMonitorPtr mon,
+ virBitmapPtr caps,
+ virBitmapPtr states)
+{
+ char *capsStr = virBitmapFormat(caps);
+ char *statesStr = virBitmapFormat(states);
+
+ VIR_DEBUG("caps=%s, states=%s", NULLSTR(capsStr), NULLSTR(statesStr));
+
+ VIR_FREE(capsStr);
+ VIR_FREE(statesStr);
+
+ QEMU_CHECK_MONITOR_JSON(mon);
+
+ return qemuMonitorJSONSetMigrationCapabilities(mon, caps, states);
+}
+
+
/**
* qemuMonitorGetGICCapabilities:
* @mon: QEMU monitor
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index d04148e568..870aae5cbd 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -763,6 +763,9 @@ int qemuMonitorGetMigrationCapabilities(qemuMonitorPtr mon,
int qemuMonitorSetMigrationCapability(qemuMonitorPtr mon,
qemuMonitorMigrationCaps capability,
bool state);
+int qemuMonitorSetMigrationCapabilities(qemuMonitorPtr mon,
+ virBitmapPtr caps,
+ virBitmapPtr states);
int qemuMonitorGetGICCapabilities(qemuMonitorPtr mon,
virGICCapability **capabilities);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 57c2c4de0f..7ab73657a0 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6251,6 +6251,69 @@ qemuMonitorJSONSetMigrationCapability(qemuMonitorPtr mon,
}
+int
+qemuMonitorJSONSetMigrationCapabilities(qemuMonitorPtr mon,
+ virBitmapPtr caps,
+ virBitmapPtr states)
+{
+ int ret = -1;
+ qemuMonitorMigrationCaps bit;
+ virJSONValuePtr cmd = NULL;
+ virJSONValuePtr reply = NULL;
+ virJSONValuePtr cap = NULL;
+ virJSONValuePtr array;
+
+ if (!(array = virJSONValueNewArray()))
+ goto cleanup;
+
+ for (bit = 0; bit < QEMU_MONITOR_MIGRATION_CAPS_LAST; bit++) {
+ bool supported = false;
+ bool state = false;
+
+ ignore_value(virBitmapGetBit(caps, bit, &supported));
+ if (!supported)
+ continue;
+
+ ignore_value(virBitmapGetBit(states, bit, &state));
+
+ if (!(cap = virJSONValueNewObject()))
+ goto cleanup;
+
+ if (virJSONValueObjectAppendString(cap, "capability",
+ qemuMonitorMigrationCapsTypeToString(bit))
< 0)
+ goto cleanup;
+
+ if (virJSONValueObjectAppendBoolean(cap, "state", state) < 0)
+ goto cleanup;
+
+ if (virJSONValueArrayAppend(array, cap) < 0)
+ goto cleanup;
+
+ cap = NULL;
+ }
+
+ cmd = qemuMonitorJSONMakeCommand("migrate-set-capabilities",
+ "a:capabilities", &array,
+ NULL);
+ if (!cmd)
+ goto cleanup;
+
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
+
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+
+ ret = 0;
+ cleanup:
+ virJSONValueFree(array);
+ virJSONValueFree(cap);
+ virJSONValueFree(cmd);
+ virJSONValueFree(reply);
+ return ret;
+}
+
+
/**
* qemuMonitorJSONGetGICCapabilities:
* @mon: QEMU JSON monitor
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 045df4919f..76e6738f44 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -148,6 +148,9 @@ int qemuMonitorJSONGetMigrationCapabilities(qemuMonitorPtr mon,
int qemuMonitorJSONSetMigrationCapability(qemuMonitorPtr mon,
qemuMonitorMigrationCaps capability,
bool state);
+int qemuMonitorJSONSetMigrationCapabilities(qemuMonitorPtr mon,
+ virBitmapPtr caps,
+ virBitmapPtr states);
int qemuMonitorJSONGetGICCapabilities(qemuMonitorPtr mon,
virGICCapability **capabilities);
--
2.17.0