diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 22f05222db..44da4d5642 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3960,6 +3960,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 9556a51341..0fdcada5c5 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);