[PATCH 8/8] qemu_domain: Set 'passt' net backend if 'default' is unsupported

Michal Privoznik posted 8 patches 2 months, 2 weeks ago
[PATCH 8/8] qemu_domain: Set 'passt' net backend if 'default' is unsupported
Posted by Michal Privoznik 2 months, 2 weeks ago
It may happen that QEMU is compiled without SLIRP but with
support for passt. In such case it is acceptable to alter user
provided configuration and switch backend to passt as it offers
all the features as SLIRP.

Resolves: https://issues.redhat.com/browse/RHEL-45518
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_domain.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 1a90311ca5..2134b11038 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5975,12 +5975,25 @@ qemuDomainDeviceNetDefPostParse(virDomainNetDef *net,
                                 virQEMUCaps *qemuCaps)
 {
     if (net->type == VIR_DOMAIN_NET_TYPE_VDPA &&
-        !virDomainNetGetModelString(net))
+        !virDomainNetGetModelString(net)) {
         net->model = VIR_DOMAIN_NET_MODEL_VIRTIO;
-    else if (net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV &&
+    } else if (net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV &&
         !virDomainNetGetModelString(net) &&
-        virDomainNetResolveActualType(net) != VIR_DOMAIN_NET_TYPE_HOSTDEV)
+        virDomainNetResolveActualType(net) != VIR_DOMAIN_NET_TYPE_HOSTDEV) {
         net->model = qemuDomainDefaultNetModel(def, qemuCaps);
+    }
+
+    if (net->type == VIR_DOMAIN_NET_TYPE_USER &&
+        net->backend.type == VIR_DOMAIN_NET_BACKEND_DEFAULT) {
+        virDomainCapsDeviceNet netCaps = { };
+
+        virQEMUCapsFillDomainDeviceNetCaps(qemuCaps, &netCaps);
+
+        if (!VIR_DOMAIN_CAPS_ENUM_IS_SET(netCaps.backendType, VIR_DOMAIN_NET_BACKEND_DEFAULT) &&
+            VIR_DOMAIN_CAPS_ENUM_IS_SET(netCaps.backendType, VIR_DOMAIN_NET_BACKEND_PASST)) {
+            net->backend.type = VIR_DOMAIN_NET_BACKEND_PASST;
+        }
+    }
 
     return 0;
 }
-- 
2.44.2
Re: [PATCH 8/8] qemu_domain: Set 'passt' net backend if 'default' is unsupported
Posted by Peter Krempa 2 months, 2 weeks ago
On Fri, Jun 28, 2024 at 15:12:37 +0200, Michal Privoznik wrote:
> It may happen that QEMU is compiled without SLIRP but with
> support for passt. In such case it is acceptable to alter user
> provided configuration and switch backend to passt as it offers
> all the features as SLIRP.
> 
> Resolves: https://issues.redhat.com/browse/RHEL-45518
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/qemu/qemu_domain.c | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)

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