[PATCH 7/8] qemu_validate: Use domaincaps to validate supported net backend type

Michal Privoznik posted 8 patches 2 months, 2 weeks ago
[PATCH 7/8] qemu_validate: Use domaincaps to validate supported net backend type
Posted by Michal Privoznik 2 months, 2 weeks ago
Now that the logic for detecting supported net backend types has
been moved to domain capabilities generation, we can just use it
when validating net backend type. Just like we do for device
models and so on.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_validate.c | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 23d642c1ce..8840306bfd 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -1705,28 +1705,18 @@ qemuValidateDomainDeviceDefNetwork(const virDomainNetDef *net,
     size_t i;
 
     if (net->type == VIR_DOMAIN_NET_TYPE_USER) {
-        switch (net->backend.type) {
-        case VIR_DOMAIN_NET_BACKEND_DEFAULT:
-            if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_NETDEV_USER)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                               _("the '%1$s' network backend is not supported with this QEMU binary"),
-                               virDomainNetBackendTypeToString(net->backend.type));
-                return -1;
-            }
-            break;
+        virDomainCapsDeviceNet netCaps = { };
 
-        case VIR_DOMAIN_NET_BACKEND_PASST:
-            if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_NETDEV_STREAM)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                               _("the '%1$s' network backend is not supported with this QEMU binary"),
-                               virDomainNetBackendTypeToString(net->backend.type));
-                return -1;
-            }
-            break;
+        virQEMUCapsFillDomainDeviceNetCaps(qemuCaps, &netCaps);
 
-        case VIR_DOMAIN_NET_BACKEND_LAST:
-            break;
+        if (!VIR_DOMAIN_CAPS_ENUM_IS_SET(netCaps.backendType,
+                                         net->backend.type)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("the '%1$s' network backend is not supported with this QEMU binary"),
+                           virDomainNetBackendTypeToString(net->backend.type));
+            return -1;
         }
+
         if (net->guestIP.nroutes) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                            _("Invalid attempt to set network interface guest-side IP route, not supported by QEMU"));
-- 
2.44.2
Re: [PATCH 7/8] qemu_validate: Use domaincaps to validate supported net backend type
Posted by Peter Krempa 2 months, 2 weeks ago
On Fri, Jun 28, 2024 at 15:12:36 +0200, Michal Privoznik wrote:
> Now that the logic for detecting supported net backend types has
> been moved to domain capabilities generation, we can just use it
> when validating net backend type. Just like we do for device
> models and so on.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/qemu/qemu_validate.c | 28 +++++++++-------------------
>  1 file changed, 9 insertions(+), 19 deletions(-)

Reviewed-by: Peter Krempa <pkrempa@redhat.com>