Apply the user-requested changes to the device definition as requested
by the <qemu:deviceOverride> element from the custom qemu XML namespace.
Closes:
https://gitlab.com/libvirt/libvirt/-/issues/287
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_command.c | 34 ++++++++++++++++++-
.../qemu-ns.x86_64-4.0.0.args | 2 +-
.../qemu-ns.x86_64-latest.args | 2 +-
3 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 8af6179b5c..46a263cdae 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -232,14 +232,46 @@ qemuBuildNetdevCommandlineFromJSON(virCommand *cmd,
}
+static void
+qemuBuildDeviceCommandlineHandleOverrides(virJSONValue *props,
+ qemuDomainXmlNsDef *nsdef)
+{
+ const char *alias = virJSONValueObjectGetString(props, "id");
+ size_t i;
+
+ for (i = 0; i < nsdef->ndeviceOverride; i++) {
+ qemuDomainXmlNsDeviceOverride *dev = nsdef->deviceOverride + i;
+ size_t j;
+
+ if (STRNEQ(alias, dev->alias))
+ continue;
+
+ for (j = 0; j < dev->nprops; j++) {
+ qemuDomainXmlNsDeviceOverrideProperty *prop = dev->props + j;
+
+ virJSONValueObjectRemoveKey(props, prop->name, NULL);
+ if (prop->json) {
+ g_autoptr(virJSONValue) copy = virJSONValueCopy(prop->json);
+
+ virJSONValueObjectAppend(props, prop->name, ©);
+ }
+ }
+ }
+}
+
+
static int
qemuBuildDeviceCommandlineFromJSON(virCommand *cmd,
virJSONValue *props,
- const virDomainDef *def G_GNUC_UNUSED,
+ const virDomainDef *def,
virQEMUCaps *qemuCaps)
{
+ qemuDomainXmlNsDef *nsdef = def->namespaceData;
g_autofree char *arg = NULL;
+ if (nsdef && nsdef->ndeviceOverride > 0)
+ qemuBuildDeviceCommandlineHandleOverrides(props, nsdef);
+
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_JSON)) {
if (!(arg = virJSONValueToString(props, false)))
return -1;
diff --git a/tests/qemuxml2argvdata/qemu-ns.x86_64-4.0.0.args
b/tests/qemuxml2argvdata/qemu-ns.x86_64-4.0.0.args
index 236f984a90..284f32d6a1 100644
--- a/tests/qemuxml2argvdata/qemu-ns.x86_64-4.0.0.args
+++ b/tests/qemuxml2argvdata/qemu-ns.x86_64-4.0.0.args
@@ -31,7 +31,7 @@ BAR='' \
-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
-blockdev
'{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1","node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}'
\
-blockdev
'{"node-name":"libvirt-1-format","read-only":false,"driver":"raw","file":"libvirt-1-storage"}'
\
--device ide-hd,bus=ide.0,unit=0,drive=libvirt-1-format,id=ua-disk,bootindex=1 \
+-device
ide-hd,bus=ide.0,unit=0,drive=libvirt-1-format,id=ua-disk,bootindex=1,prop1=propval1,prop2=-321,prop3=123,prop4=on,prop5=off
\
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \
-unknown parameter \
-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
diff --git a/tests/qemuxml2argvdata/qemu-ns.x86_64-latest.args
b/tests/qemuxml2argvdata/qemu-ns.x86_64-latest.args
index c0bf45000f..c1949264f8 100644
--- a/tests/qemuxml2argvdata/qemu-ns.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/qemu-ns.x86_64-latest.args
@@ -33,7 +33,7 @@ BAR='' \
-device
'{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}'
\
-blockdev
'{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1","node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}'
\
-blockdev
'{"node-name":"libvirt-1-format","read-only":false,"driver":"raw","file":"libvirt-1-storage"}'
\
--device
'{"driver":"ide-hd","bus":"ide.0","unit":0,"drive":"libvirt-1-format","id":"ua-disk","bootindex":1}'
\
+-device
'{"driver":"ide-hd","bus":"ide.0","unit":0,"drive":"libvirt-1-format","id":"ua-disk","bootindex":1,"prop1":"propval1","prop2":-321,"prop3":123,"prop4":true,"prop5":false}'
\
-audiodev
'{"id":"audio1","driver":"none"}' \
-device
'{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x2"}'
\
-unknown parameter \
--
2.35.1