mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
qemu: command: Override device definition according to the namespace config
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>
This commit is contained in:
parent
e273dfc066
commit
38ab5c9ead
@ -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, ©);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
@ -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 \
|
||||
|
@ -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 \
|
||||
|
Loading…
Reference in New Issue
Block a user