}
+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, &supported));
+ if (!supported)
+ continue;
+
+ ignore_value(virBitmapGetBit(states, bit, &state));
+
+ 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
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;
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.
{
qemuDomainObjPrivatePtr priv = vm->privateData;
virBitmapPtr migEvent = NULL;
+ virJSONValuePtr json = NULL;
char **caps = NULL;
char **capStr;
int ret = -1;
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;
ret = 0;
cleanup:
+ virJSONValueFree(json);
virStringListFree(caps);
return ret;
}
qemuMigrationParamsPtr
qemuMigrationParamsFromJSON(virJSONValuePtr params);
+virJSONValuePtr
+qemuMigrationCapsToJSON(virBitmapPtr caps,
+ virBitmapPtr states);
+
#endif /* __QEMU_MIGRATION_PARAMSPRIV_H__ */
}
+/**
+ * qemuMonitorSetMigrationCapabilities:
+ * @mon: Pointer to the monitor object.
+ * @caps: Migration capabilities.
+ *
+ * The @caps object is consumed and should not be referenced by the caller
+ * after this function returns.
+ *
+ * Returns 0 on success, -1 on error.
+ */
int
qemuMonitorSetMigrationCapabilities(qemuMonitorPtr mon,
- virBitmapPtr caps,
- virBitmapPtr states)
+ virJSONValuePtr caps)
{
- 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_GOTO(mon, error);
- QEMU_CHECK_MONITOR_JSON(mon);
+ return qemuMonitorJSONSetMigrationCapabilities(mon, caps);
- return qemuMonitorJSONSetMigrationCapabilities(mon, caps, states);
+ error:
+ virJSONValueFree(caps);
+ return -1;
}
int qemuMonitorGetMigrationCapabilities(qemuMonitorPtr mon,
char ***capabilities);
int qemuMonitorSetMigrationCapabilities(qemuMonitorPtr mon,
- virBitmapPtr caps,
- virBitmapPtr states);
+ virJSONValuePtr caps);
int qemuMonitorGetGICCapabilities(qemuMonitorPtr mon,
virGICCapability **capabilities);
int
qemuMonitorJSONSetMigrationCapabilities(qemuMonitorPtr mon,
- virBitmapPtr caps,
- virBitmapPtr states)
+ virJSONValuePtr caps)
{
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,
+ "a:capabilities", &caps,
NULL);
if (!cmd)
goto cleanup;
ret = 0;
cleanup:
- virJSONValueFree(array);
- virJSONValueFree(cap);
+ virJSONValueFree(caps);
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
int qemuMonitorJSONGetMigrationCapabilities(qemuMonitorPtr mon,
char ***capabilities);
int qemuMonitorJSONSetMigrationCapabilities(qemuMonitorPtr mon,
- virBitmapPtr caps,
- virBitmapPtr states);
+ virJSONValuePtr caps);
int qemuMonitorJSONGetGICCapabilities(qemuMonitorPtr mon,
virGICCapability **capabilities);
#include "virstring.h"
#include "cpu/cpu.h"
#include "qemu/qemu_monitor.h"
+#include "qemu/qemu_migration_paramspriv.h"
#define VIR_FROM_THIS VIR_FROM_NONE
const char *cap;
char **caps = NULL;
virBitmapPtr bitmap = NULL;
+ virJSONValuePtr json = NULL;
const char *reply =
"{"
" \"return\": ["
goto cleanup;
ignore_value(virBitmapSetBit(bitmap, QEMU_MONITOR_MIGRATION_CAPS_XBZRLE));
- if (qemuMonitorJSONSetMigrationCapabilities(qemuMonitorTestGetMonitor(test),
- bitmap, bitmap) < 0)
+ if (!(json = qemuMigrationCapsToJSON(bitmap, bitmap)))
goto cleanup;
- ret = 0;
+ ret = qemuMonitorJSONSetMigrationCapabilities(qemuMonitorTestGetMonitor(test),
+ json);
+ json = NULL;
+
cleanup:
+ virJSONValueFree(json);
qemuMonitorTestFree(test);
virStringListFree(caps);
virBitmapFree(bitmap);