]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: command: Introduce JSON variant of qemuBuildRomProps
authorPeter Krempa <pkrempa@redhat.com>
Fri, 1 Oct 2021 20:18:39 +0000 (22:18 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 12 Oct 2021 08:26:03 +0000 (10:26 +0200)
Add a JSON variant of the generator 'rom' properties. For convenience
both the old and new are for now marked as unused, which will be removed
once the conversion is complete.

The formatted properties have following types according to QEMU.
'virtio-blk-pci' was used as an example:
  rombar=<uint32>        -  (default: 1)
  romfile=<str>

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_command.c

index 3bacb950906973856bdd7b3d099c71ff89ab3884..cbca9d4698414c4933318f7ec4a729606c35b268 100644 (file)
@@ -1133,7 +1133,47 @@ qemuBuildVirtioDevStr(virBuffer *buf,
 }
 
 
-static int
+static int G_GNUC_UNUSED
+qemuBuildRomProps(virJSONValue *props,
+                  virDomainDeviceInfo *info)
+{
+    const char *romfile = NULL;
+    int rombar = -1;
+
+    if (info->romenabled == VIR_TRISTATE_BOOL_ABSENT &&
+        info->rombar == VIR_TRISTATE_SWITCH_ABSENT &&
+        !info->romfile)
+        return 0;
+
+    if (info->romenabled == VIR_TRISTATE_BOOL_NO) {
+        romfile = "";
+    } else {
+        romfile = info->romfile;
+
+        switch (info->rombar) {
+        case VIR_TRISTATE_SWITCH_OFF:
+            rombar = 0;
+            break;
+        case VIR_TRISTATE_SWITCH_ON:
+            rombar = 1;
+            break;
+        case VIR_TRISTATE_SWITCH_ABSENT:
+        case VIR_TRISTATE_SWITCH_LAST:
+            break;
+        }
+    }
+
+    if (virJSONValueObjectAdd(props,
+                              "k:rombar", rombar,
+                              "S:romfile", romfile,
+                              NULL) < 0)
+        return -1;
+
+    return 0;
+}
+
+
+static int G_GNUC_UNUSED
 qemuBuildRomStr(virBuffer *buf,
                 virDomainDeviceInfo *info)
 {