mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-09-09 17:24:53 +00:00
qemu: Move migration capabilities JSON formatting
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 <jdenemar@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
d384a88b30
commit
03edcd0752
@ -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, &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
|
* qemuMigrationParamsApply
|
||||||
* @driver: qemu driver
|
* @driver: qemu driver
|
||||||
@ -611,6 +658,7 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver,
|
|||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
bool xbzrleCacheSize_old = false;
|
bool xbzrleCacheSize_old = false;
|
||||||
virJSONValuePtr params = NULL;
|
virJSONValuePtr params = NULL;
|
||||||
|
virJSONValuePtr caps = NULL;
|
||||||
qemuMigrationParam xbzrle = QEMU_MIGRATION_PARAM_XBZRLE_CACHE_SIZE;
|
qemuMigrationParam xbzrle = QEMU_MIGRATION_PARAM_XBZRLE_CACHE_SIZE;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int rc;
|
int rc;
|
||||||
@ -618,10 +666,16 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver,
|
|||||||
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
|
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (qemuMonitorSetMigrationCapabilities(priv->mon, priv->migrationCaps,
|
if (!(caps = qemuMigrationCapsToJSON(priv->migrationCaps, migParams->caps)))
|
||||||
migParams->caps) < 0)
|
|
||||||
goto cleanup;
|
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,
|
/* If QEMU is too old to support xbzrle-cache-size migration parameter,
|
||||||
* we need to set it via migrate-set-cache-size and tell
|
* we need to set it via migrate-set-cache-size and tell
|
||||||
* qemuMonitorSetMigrationParams to ignore this parameter.
|
* qemuMonitorSetMigrationParams to ignore this parameter.
|
||||||
@ -974,6 +1028,7 @@ qemuMigrationCapsCheck(virQEMUDriverPtr driver,
|
|||||||
{
|
{
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
virBitmapPtr migEvent = NULL;
|
virBitmapPtr migEvent = NULL;
|
||||||
|
virJSONValuePtr json = NULL;
|
||||||
char **caps = NULL;
|
char **caps = NULL;
|
||||||
char **capStr;
|
char **capStr;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -1014,10 +1069,14 @@ qemuMigrationCapsCheck(virQEMUDriverPtr driver,
|
|||||||
|
|
||||||
ignore_value(virBitmapSetBit(migEvent, QEMU_MONITOR_MIGRATION_CAPS_EVENTS));
|
ignore_value(virBitmapSetBit(migEvent, QEMU_MONITOR_MIGRATION_CAPS_EVENTS));
|
||||||
|
|
||||||
|
if (!(json = qemuMigrationCapsToJSON(migEvent, migEvent)))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
|
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
rc = qemuMonitorSetMigrationCapabilities(priv->mon, migEvent, migEvent);
|
rc = qemuMonitorSetMigrationCapabilities(priv->mon, json);
|
||||||
|
json = NULL;
|
||||||
|
|
||||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1039,6 +1098,7 @@ qemuMigrationCapsCheck(virQEMUDriverPtr driver,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
virJSONValueFree(json);
|
||||||
virStringListFree(caps);
|
virStringListFree(caps);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -28,4 +28,8 @@ qemuMigrationParamsToJSON(qemuMigrationParamsPtr migParams);
|
|||||||
qemuMigrationParamsPtr
|
qemuMigrationParamsPtr
|
||||||
qemuMigrationParamsFromJSON(virJSONValuePtr params);
|
qemuMigrationParamsFromJSON(virJSONValuePtr params);
|
||||||
|
|
||||||
|
virJSONValuePtr
|
||||||
|
qemuMigrationCapsToJSON(virBitmapPtr caps,
|
||||||
|
virBitmapPtr states);
|
||||||
|
|
||||||
#endif /* __QEMU_MIGRATION_PARAMSPRIV_H__ */
|
#endif /* __QEMU_MIGRATION_PARAMSPRIV_H__ */
|
||||||
|
@ -3957,22 +3957,27 @@ qemuMonitorGetMigrationCapabilities(qemuMonitorPtr mon,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
int
|
||||||
qemuMonitorSetMigrationCapabilities(qemuMonitorPtr mon,
|
qemuMonitorSetMigrationCapabilities(qemuMonitorPtr mon,
|
||||||
virBitmapPtr caps,
|
virJSONValuePtr caps)
|
||||||
virBitmapPtr states)
|
|
||||||
{
|
{
|
||||||
char *capsStr = virBitmapFormat(caps);
|
QEMU_CHECK_MONITOR_JSON_GOTO(mon, error);
|
||||||
char *statesStr = virBitmapFormat(states);
|
|
||||||
|
|
||||||
VIR_DEBUG("caps=%s, states=%s", NULLSTR(capsStr), NULLSTR(statesStr));
|
return qemuMonitorJSONSetMigrationCapabilities(mon, caps);
|
||||||
|
|
||||||
VIR_FREE(capsStr);
|
error:
|
||||||
VIR_FREE(statesStr);
|
virJSONValueFree(caps);
|
||||||
|
return -1;
|
||||||
QEMU_CHECK_MONITOR_JSON(mon);
|
|
||||||
|
|
||||||
return qemuMonitorJSONSetMigrationCapabilities(mon, caps, states);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -728,8 +728,7 @@ VIR_ENUM_DECL(qemuMonitorMigrationCaps);
|
|||||||
int qemuMonitorGetMigrationCapabilities(qemuMonitorPtr mon,
|
int qemuMonitorGetMigrationCapabilities(qemuMonitorPtr mon,
|
||||||
char ***capabilities);
|
char ***capabilities);
|
||||||
int qemuMonitorSetMigrationCapabilities(qemuMonitorPtr mon,
|
int qemuMonitorSetMigrationCapabilities(qemuMonitorPtr mon,
|
||||||
virBitmapPtr caps,
|
virJSONValuePtr caps);
|
||||||
virBitmapPtr states);
|
|
||||||
|
|
||||||
int qemuMonitorGetGICCapabilities(qemuMonitorPtr mon,
|
int qemuMonitorGetGICCapabilities(qemuMonitorPtr mon,
|
||||||
virGICCapability **capabilities);
|
virGICCapability **capabilities);
|
||||||
|
@ -6111,47 +6111,14 @@ qemuMonitorJSONGetMigrationCapabilities(qemuMonitorPtr mon,
|
|||||||
|
|
||||||
int
|
int
|
||||||
qemuMonitorJSONSetMigrationCapabilities(qemuMonitorPtr mon,
|
qemuMonitorJSONSetMigrationCapabilities(qemuMonitorPtr mon,
|
||||||
virBitmapPtr caps,
|
virJSONValuePtr caps)
|
||||||
virBitmapPtr states)
|
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
qemuMonitorMigrationCaps bit;
|
|
||||||
virJSONValuePtr cmd = NULL;
|
virJSONValuePtr cmd = NULL;
|
||||||
virJSONValuePtr reply = 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",
|
cmd = qemuMonitorJSONMakeCommand("migrate-set-capabilities",
|
||||||
"a:capabilities", &array,
|
"a:capabilities", &caps,
|
||||||
NULL);
|
NULL);
|
||||||
if (!cmd)
|
if (!cmd)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -6164,8 +6131,7 @@ qemuMonitorJSONSetMigrationCapabilities(qemuMonitorPtr mon,
|
|||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
virJSONValueFree(array);
|
virJSONValueFree(caps);
|
||||||
virJSONValueFree(cap);
|
|
||||||
virJSONValueFree(cmd);
|
virJSONValueFree(cmd);
|
||||||
virJSONValueFree(reply);
|
virJSONValueFree(reply);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -146,8 +146,7 @@ int qemuMonitorJSONGetMigrationStats(qemuMonitorPtr mon,
|
|||||||
int qemuMonitorJSONGetMigrationCapabilities(qemuMonitorPtr mon,
|
int qemuMonitorJSONGetMigrationCapabilities(qemuMonitorPtr mon,
|
||||||
char ***capabilities);
|
char ***capabilities);
|
||||||
int qemuMonitorJSONSetMigrationCapabilities(qemuMonitorPtr mon,
|
int qemuMonitorJSONSetMigrationCapabilities(qemuMonitorPtr mon,
|
||||||
virBitmapPtr caps,
|
virJSONValuePtr caps);
|
||||||
virBitmapPtr states);
|
|
||||||
|
|
||||||
int qemuMonitorJSONGetGICCapabilities(qemuMonitorPtr mon,
|
int qemuMonitorJSONGetGICCapabilities(qemuMonitorPtr mon,
|
||||||
virGICCapability **capabilities);
|
virGICCapability **capabilities);
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
#include "cpu/cpu.h"
|
#include "cpu/cpu.h"
|
||||||
#include "qemu/qemu_monitor.h"
|
#include "qemu/qemu_monitor.h"
|
||||||
|
#include "qemu/qemu_migration_paramspriv.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_NONE
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||||
|
|
||||||
@ -2141,6 +2142,7 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationCapabilities(const void *data)
|
|||||||
const char *cap;
|
const char *cap;
|
||||||
char **caps = NULL;
|
char **caps = NULL;
|
||||||
virBitmapPtr bitmap = NULL;
|
virBitmapPtr bitmap = NULL;
|
||||||
|
virJSONValuePtr json = NULL;
|
||||||
const char *reply =
|
const char *reply =
|
||||||
"{"
|
"{"
|
||||||
" \"return\": ["
|
" \"return\": ["
|
||||||
@ -2176,12 +2178,15 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationCapabilities(const void *data)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ignore_value(virBitmapSetBit(bitmap, QEMU_MONITOR_MIGRATION_CAPS_XBZRLE));
|
ignore_value(virBitmapSetBit(bitmap, QEMU_MONITOR_MIGRATION_CAPS_XBZRLE));
|
||||||
if (qemuMonitorJSONSetMigrationCapabilities(qemuMonitorTestGetMonitor(test),
|
if (!(json = qemuMigrationCapsToJSON(bitmap, bitmap)))
|
||||||
bitmap, bitmap) < 0)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = 0;
|
ret = qemuMonitorJSONSetMigrationCapabilities(qemuMonitorTestGetMonitor(test),
|
||||||
|
json);
|
||||||
|
json = NULL;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
virJSONValueFree(json);
|
||||||
qemuMonitorTestFree(test);
|
qemuMonitorTestFree(test);
|
||||||
virStringListFree(caps);
|
virStringListFree(caps);
|
||||||
virBitmapFree(bitmap);
|
virBitmapFree(bitmap);
|
||||||
|
Loading…
Reference in New Issue
Block a user