[libvirt PATCH] conf: Simplify IOMMU device validation

Andrea Bolognani posted 1 patch 1 year, 8 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20220808154116.50924-1-abologna@redhat.com
src/conf/domain_validate.c | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
[libvirt PATCH] conf: Simplify IOMMU device validation
Posted by Andrea Bolognani 1 year, 8 months ago
Instead of duplicating the list of attributes that are not
allowed for some of the IOMMU models, use two separate switch
statements: one for the attributes and one for the address.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
---
 src/conf/domain_validate.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index 88205c64e0..1c78a3d31c 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -2633,6 +2633,7 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *iommu)
 {
     switch (iommu->model) {
     case VIR_DOMAIN_IOMMU_MODEL_SMMUV3:
+    case VIR_DOMAIN_IOMMU_MODEL_VIRTIO:
         if (iommu->intremap != VIR_TRISTATE_SWITCH_ABSENT ||
             iommu->caching_mode != VIR_TRISTATE_SWITCH_ABSENT ||
             iommu->eim != VIR_TRISTATE_SWITCH_ABSENT ||
@@ -2643,8 +2644,15 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *iommu)
                            virDomainIOMMUModelTypeToString(iommu->model));
             return -1;
         }
-        G_GNUC_FALLTHROUGH;
+        break;
 
+    case VIR_DOMAIN_IOMMU_MODEL_INTEL:
+    case VIR_DOMAIN_IOMMU_MODEL_LAST:
+        break;
+    }
+
+    switch (iommu->model) {
+    case VIR_DOMAIN_IOMMU_MODEL_SMMUV3:
     case VIR_DOMAIN_IOMMU_MODEL_INTEL:
         if (iommu->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
             virReportError(VIR_ERR_XML_ERROR,
@@ -2655,18 +2663,6 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *iommu)
         break;
 
     case VIR_DOMAIN_IOMMU_MODEL_VIRTIO:
-        if (iommu->intremap != VIR_TRISTATE_SWITCH_ABSENT ||
-            iommu->caching_mode != VIR_TRISTATE_SWITCH_ABSENT ||
-            iommu->eim != VIR_TRISTATE_SWITCH_ABSENT ||
-            iommu->iotlb != VIR_TRISTATE_SWITCH_ABSENT ||
-            iommu->aw_bits != 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("iommu model '%s' doesn't support additional attributes"),
-                           virDomainIOMMUModelTypeToString(iommu->model));
-            return -1;
-        }
-        break;
-
     case VIR_DOMAIN_IOMMU_MODEL_LAST:
         break;
     }
-- 
2.37.1
Re: [libvirt PATCH] conf: Simplify IOMMU device validation
Posted by Ján Tomko 1 year, 8 months ago
On a Monday in 2022, Andrea Bolognani wrote:
>Instead of duplicating the list of attributes that are not
>allowed for some of the IOMMU models, use two separate switch
>statements: one for the attributes and one for the address.
>
>Signed-off-by: Andrea Bolognani <abologna@redhat.com>
>---
> src/conf/domain_validate.c | 22 +++++++++-------------
> 1 file changed, 9 insertions(+), 13 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano
Re: [libvirt PATCH] conf: Simplify IOMMU device validation
Posted by Pavel Hrdina 1 year, 8 months ago
On Mon, Aug 08, 2022 at 05:41:16PM +0200, Andrea Bolognani wrote:
> Instead of duplicating the list of attributes that are not
> allowed for some of the IOMMU models, use two separate switch
> statements: one for the attributes and one for the address.
> 
> Signed-off-by: Andrea Bolognani <abologna@redhat.com>
> ---
>  src/conf/domain_validate.c | 22 +++++++++-------------
>  1 file changed, 9 insertions(+), 13 deletions(-)

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>