]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuMigrationCapsToJSON: Refactor capability object formatting
authorPeter Krempa <pkrempa@redhat.com>
Mon, 24 Aug 2020 15:00:59 +0000 (17:00 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 25 Aug 2020 06:24:34 +0000 (08:24 +0200)
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>
src/qemu/qemu_migration_params.c

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