1
0

qemuMigrationCapsToJSON: Refactor capability object formatting

Use virJSONValueObjectCreate rather than creating the object
piece-by-piece and use new accessors for bitmap to simplify the code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Peter Krempa 2020-08-24 17:00:59 +02:00
parent 433621eb48
commit 14b895ad3a

View File

@ -763,21 +763,15 @@ qemuMigrationCapsToJSON(virBitmapPtr caps,
qemuMigrationCapability bit; qemuMigrationCapability bit;
for (bit = 0; bit < QEMU_MIGRATION_CAP_LAST; bit++) { for (bit = 0; bit < QEMU_MIGRATION_CAP_LAST; bit++) {
g_autoptr(virJSONValue) cap = virJSONValueNewObject(); g_autoptr(virJSONValue) cap = NULL;
const char *name = qemuMigrationCapabilityTypeToString(bit);
bool supported = false;
bool state = false;
ignore_value(virBitmapGetBit(caps, bit, &supported)); if (!virBitmapIsBitSet(caps, bit))
if (!supported)
continue; continue;
ignore_value(virBitmapGetBit(states, bit, &state)); if (virJSONValueObjectCreate(&cap,
"s:capability", qemuMigrationCapabilityTypeToString(bit),
if (virJSONValueObjectAppendString(cap, "capability", name) < 0) "b:state", virBitmapIsBitSet(states, bit),
return NULL; NULL) < 0)
if (virJSONValueObjectAppendBoolean(cap, "state", state) < 0)
return NULL; return NULL;
if (virJSONValueArrayAppend(json, cap) < 0) if (virJSONValueArrayAppend(json, cap) < 0)