]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: command: Override device definition according to the namespace config
authorPeter Krempa <pkrempa@redhat.com>
Mon, 21 Mar 2022 14:17:47 +0000 (15:17 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 28 Mar 2022 11:15:25 +0000 (13:15 +0200)
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@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_command.c
tests/qemuxml2argvdata/qemu-ns.x86_64-4.0.0.args
tests/qemuxml2argvdata/qemu-ns.x86_64-latest.args

index 1f2dcdbdf6b4efffe364aea02d7bb8a7d98e0fe4..453891a725764b0546344117fcdaa78d2872e882 100644 (file)
@@ -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->nfrontend; j++) {
+            qemuDomainXmlNsOverrideProperty *prop = dev->frontend + j;
+
+            virJSONValueObjectRemoveKey(props, prop->name, NULL);
+            if (prop->json) {
+                g_autoptr(virJSONValue) copy = virJSONValueCopy(prop->json);
+
+                virJSONValueObjectAppend(props, prop->name, &copy);
+            }
+        }
+    }
+}
+
+
 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;
index 236f984a9075a69ec07375f01f5c8b5b1958c789..284f32d6a1bcfbea77beae778b044d2ac080eae1 100644 (file)
@@ -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 \
index c0bf45000f41985f0c7c8cbae3e6358f7db7ece2..c1949264f8a526b6df1fb5bab7db860774e5ec6a 100644 (file)
@@ -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 \