[PATCH v2 0/2] XML non-virtio video device validation

Kristina Hanicova (2): move virDomainCheckVirtioOptionsAreAbsent a few lines forward XML validate that non-virtio video devices have none virtio options src/conf/domain_validate.c | 60 ++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 28 deletions(-) -- 2.29.2

Moving this function in order to use it in the next patch before its previous declaration. Signed-off-by: Kristina Hanicova <khanicov@redhat.com> --- src/conf/domain_validate.c | 56 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index b4e09e21fe..dabdd7b8eb 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -78,6 +78,34 @@ virDomainDefVideoValidate(const virDomainDef *def) } +static int +virDomainCheckVirtioOptionsAreAbsent(virDomainVirtioOptionsPtr virtio) +{ + if (!virtio) + return 0; + + if (virtio->iommu != VIR_TRISTATE_SWITCH_ABSENT) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("iommu driver option is only supported " + "for virtio devices")); + return -1; + } + if (virtio->ats != VIR_TRISTATE_SWITCH_ABSENT) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("ats driver option is only supported " + "for virtio devices")); + return -1; + } + if (virtio->packed != VIR_TRISTATE_SWITCH_ABSENT) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("packed driver option is only supported " + "for virtio devices")); + return -1; + } + return 0; +} + + static int virDomainVideoDefValidate(const virDomainVideoDef *video, const virDomainDef *def) @@ -228,34 +256,6 @@ virSecurityDeviceLabelDefValidate(virSecurityDeviceLabelDefPtr *seclabels, } -static int -virDomainCheckVirtioOptionsAreAbsent(virDomainVirtioOptionsPtr virtio) -{ - if (!virtio) - return 0; - - if (virtio->iommu != VIR_TRISTATE_SWITCH_ABSENT) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("iommu driver option is only supported " - "for virtio devices")); - return -1; - } - if (virtio->ats != VIR_TRISTATE_SWITCH_ABSENT) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("ats driver option is only supported " - "for virtio devices")); - return -1; - } - if (virtio->packed != VIR_TRISTATE_SWITCH_ABSENT) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("packed driver option is only supported " - "for virtio devices")); - return -1; - } - return 0; -} - - static int virDomainDiskVhostUserValidate(const virDomainDiskDef *disk) { -- 2.29.2

With this, XML fails if non-virtio video devices have virtio options. Previously it didn't raise error. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1922093 Signed-off-by: Kristina Hanicova <khanicov@redhat.com> --- src/conf/domain_validate.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index dabdd7b8eb..b53f6437cc 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -179,6 +179,10 @@ virDomainVideoDefValidate(const virDomainVideoDef *video, } } + if (video->type != VIR_DOMAIN_VIDEO_TYPE_VIRTIO && + (virDomainCheckVirtioOptionsAreAbsent(video->virtio) < 0)) + return -1; + return 0; } -- 2.29.2

Sorry everyone, it should have been v1. :) On Wed, Mar 10, 2021 at 5:43 PM Kristina Hanicova <khanicov@redhat.com> wrote:
Kristina Hanicova (2): move virDomainCheckVirtioOptionsAreAbsent a few lines forward XML validate that non-virtio video devices have none virtio options
src/conf/domain_validate.c | 60 ++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 28 deletions(-)
-- 2.29.2

On 3/10/21 5:42 PM, Kristina Hanicova wrote:
Kristina Hanicova (2): move virDomainCheckVirtioOptionsAreAbsent a few lines forward XML validate that non-virtio video devices have none virtio options
src/conf/domain_validate.c | 60 ++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 28 deletions(-)
Reviewed-by: Michal Privoznik <mprivozn@redhat.com> and pushed. Michal
participants (2)
-
Kristina Hanicova
-
Michal Privoznik