[libvirt PATCH] ch: interface: correctly update nicindexes

Pavel Hrdina posted 1 patch 2 months, 3 weeks ago
src/ch/ch_interface.c | 42 ++++++++++++++++++++++++++++--------------
1 file changed, 28 insertions(+), 14 deletions(-)
[libvirt PATCH] ch: interface: correctly update nicindexes
Posted by Pavel Hrdina 2 months, 3 weeks ago
Originally nicindexes were updated only for VIR_DOMAIN_NET_TYPE_BRIDGE
and VIR_DOMAIN_NET_TYPE_DIRECT. The mentioned commit adds support for
NAT network mode and changes the code to update nicindexes for
VIR_DOMAIN_NET_TYPE_ETHERNET and VIR_DOMAIN_NET_TYPE_NETWORK as well.

It doesn't work as intended and after the change nicindexes are updated
only for VIR_DOMAIN_NET_TYPE_ETHERNET and VIR_DOMAIN_NET_TYPE_NETWORK.

Fixes: aa642090738eb276f7bd70dea97d3a4fd03d59e3
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/ch/ch_interface.c | 42 ++++++++++++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/src/ch/ch_interface.c b/src/ch/ch_interface.c
index 47b02bc322..87a95cde53 100644
--- a/src/ch/ch_interface.c
+++ b/src/ch/ch_interface.c
@@ -34,6 +34,26 @@
 
 VIR_LOG_INIT("ch.ch_interface");
 
+
+static int
+virCHInterfaceUpdateNicindexes(virDomainNetDef *net,
+                               int **nicindexes,
+                               size_t *nnicindexes)
+{
+    int nicindex = 0;
+
+    if (!nicindexes || !nnicindexes || !net->ifname)
+        return 0;
+
+    if (virNetDevGetIndex(net->ifname, &nicindex) < 0)
+        return -1;
+
+    VIR_APPEND_ELEMENT(*nicindexes, *nnicindexes, nicindex);
+
+    return 0;
+}
+
+
 /**
  * virCHConnetNetworkInterfaces:
  * @driver: pointer to ch driver object
@@ -78,6 +98,8 @@ virCHConnetNetworkInterfaces(virCHDriver *driver,
                                               net->driver.virtio.queues) < 0)
             return -1;
 
+        if (virCHInterfaceUpdateNicindexes(net, nicindexes, nnicindexes) < 0)
+            return -1;
         break;
     case VIR_DOMAIN_NET_TYPE_NETWORK:
         if (virDomainInterfaceBridgeConnect(vm, net,
@@ -88,9 +110,15 @@ virCHConnetNetworkInterfaces(virCHDriver *driver,
                                             false,
                                             NULL) < 0)
             return -1;
+
+        if (virCHInterfaceUpdateNicindexes(net, nicindexes, nnicindexes) < 0)
+            return -1;
         break;
     case VIR_DOMAIN_NET_TYPE_BRIDGE:
     case VIR_DOMAIN_NET_TYPE_DIRECT:
+        if (virCHInterfaceUpdateNicindexes(net, nicindexes, nnicindexes) < 0)
+            return -1;
+        break;
     case VIR_DOMAIN_NET_TYPE_USER:
     case VIR_DOMAIN_NET_TYPE_SERVER:
     case VIR_DOMAIN_NET_TYPE_CLIENT:
@@ -109,19 +137,5 @@ virCHConnetNetworkInterfaces(virCHDriver *driver,
         return -1;
     }
 
-    if (actualType == VIR_DOMAIN_NET_TYPE_ETHERNET ||
-        actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
-        actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
-        actualType == VIR_DOMAIN_NET_TYPE_DIRECT) {
-        if (nicindexes && nnicindexes && net->ifname) {
-            int nicindex = 0;
-
-            if (virNetDevGetIndex(net->ifname, &nicindex) < 0)
-                return -1;
-
-            VIR_APPEND_ELEMENT(*nicindexes, *nnicindexes, nicindex);
-        }
-    }
-
     return 0;
 }
-- 
2.46.0
Re: [libvirt PATCH] ch: interface: correctly update nicindexes
Posted by Michal Prívozník 2 months, 3 weeks ago
On 8/27/24 20:00, Pavel Hrdina wrote:
> Originally nicindexes were updated only for VIR_DOMAIN_NET_TYPE_BRIDGE
> and VIR_DOMAIN_NET_TYPE_DIRECT. The mentioned commit adds support for
> NAT network mode and changes the code to update nicindexes for
> VIR_DOMAIN_NET_TYPE_ETHERNET and VIR_DOMAIN_NET_TYPE_NETWORK as well.
> 
> It doesn't work as intended and after the change nicindexes are updated
> only for VIR_DOMAIN_NET_TYPE_ETHERNET and VIR_DOMAIN_NET_TYPE_NETWORK.
> 
> Fixes: aa642090738eb276f7bd70dea97d3a4fd03d59e3
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>  src/ch/ch_interface.c | 42 ++++++++++++++++++++++++++++--------------
>  1 file changed, 28 insertions(+), 14 deletions(-)
> 

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal