From: Peter Krempa Date: Thu, 30 Sep 2021 15:55:45 +0000 (+0200) Subject: qemu: command: Introduce JSON variant of qemuBuildVirtioDevStr X-Git-Tag: v7.9.0-rc1~180 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89b5bc626a9a761563da88955de758d388dbbfd0;p=thirdparty%2Flibvirt.git qemu: command: Introduce JSON variant of qemuBuildVirtioDevStr Add a JSON variant of the generator of properties for virtio devices. 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: disable-legacy= - on/off/auto (default: "auto") disable-modern= - (default: false) iommu_platform= - on/off (default: false) ats= - on/off (default: false) packed= - on/off (default: false) Note that is an enum type without alternates in QMP so it must be represented as a string in JSON. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 551014b5b9..f1c67d1e61 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -155,6 +155,16 @@ VIR_ENUM_IMPL(qemuAudioDriver, ); +static const char * +qemuOnOffAuto(virTristateSwitch s) +{ + if (s == VIR_TRISTATE_SWITCH_ABSENT) + return NULL; + + return virTristateSwitchTypeToString(s); +} + + static int qemuBuildObjectCommandlineFromJSON(virCommand *cmd, virJSONValue *props, @@ -987,6 +997,52 @@ qemuBuildVirtioDevGetConfig(virDomainDeviceDef *device, } +/** + * qemuBuildVirtioDevProps + * @devtype: virDomainDeviceType of the device. Ex: VIR_DOMAIN_DEVICE_TYPE_RNG + * @devdata: *Def * of the device definition + * @qemuCaps: qemu capabilities + * + * Build the qemu virtio -device JSON properties name from the passed parameters. + */ +static G_GNUC_UNUSED virJSONValue * +qemuBuildVirtioDevProps(virDomainDeviceType devtype, + void *devdata, + virQEMUCaps *qemuCaps) +{ + g_autoptr(virJSONValue) props = NULL; + virDomainDeviceDef device = { .type = devtype }; + g_autofree char *model = NULL; + virTristateSwitch disableLegacy = VIR_TRISTATE_SWITCH_ABSENT; + virTristateSwitch disableModern = VIR_TRISTATE_SWITCH_ABSENT; + virDomainVirtioOptions *virtioOptions = NULL; + + virDomainDeviceSetData(&device, devdata); + + if (qemuBuildVirtioDevGetConfig(&device, qemuCaps, &model, &virtioOptions, + &disableLegacy, &disableModern) < 0) + return NULL; + + if (virJSONValueObjectCreate(&props, + "s:driver", model, + "S:disable-legacy", qemuOnOffAuto(disableLegacy), + "T:disable-modern", disableModern, + NULL) < 0) + return NULL; + + if (virtioOptions) { + if (virJSONValueObjectAdd(props, + "T:iommu_platform", virtioOptions->iommu, + "T:ats", virtioOptions->ats, + "T:packed", virtioOptions->packed, + NULL) < 0) + return NULL; + } + + return g_steal_pointer(&props); +} + + /** * qemuBuildVirtioDevStr * @buf: virBuffer * to append the built string @@ -1001,7 +1057,7 @@ qemuBuildVirtioDevGetConfig(virDomainDeviceDef *device, * * Returns: -1 on failure, 0 on success */ -static int +static G_GNUC_UNUSED int qemuBuildVirtioDevStr(virBuffer *buf, virQEMUCaps *qemuCaps, virDomainDeviceType devtype,