[PATCH 055/103] qemu: command: Introduce JSON variant of qemuBuildRomProps

Peter Krempa pkrempa at redhat.com
Thu Oct 7 15:17:43 UTC 2021


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 at redhat.com>
---
 src/qemu/qemu_command.c | 42 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 9c8a3a85af..c9d98b8f1a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1126,7 +1126,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)
 {
-- 
2.31.1




More information about the libvir-list mailing list