Blame SOURCES/BZ_1931355-SRIOV-wait-VF-mount-decrease.patch

a23721
From 80c97b27707b036f0a54988ade4bda3ccb342b34 Mon Sep 17 00:00:00 2001
a23721
From: Fernando Fernandez Mancera <ffmancera@riseup.net>
a23721
Date: Mon, 22 Feb 2021 12:03:11 +0100
a23721
Subject: [PATCH 1/2] SR-IOV: increase the verification timeout if SR-IOV is
a23721
 present
a23721
a23721
Certain drivers like i40e take a long time to modify the VFs in the
a23721
kernel. Nmstate is timing out on verification because of that. In order
a23721
to fix this, nmstate is incresing the verification time if SR-IOV is
a23721
present on the desired state.
a23721
a23721
Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
a23721
Signed-off-by: Gris Ge <fge@redhat.com>
a23721
---
a23721
 libnmstate/ifaces/ethernet.py |  6 ++++++
a23721
 libnmstate/netapplier.py      | 18 +++++++++++++++++-
a23721
 2 files changed, 23 insertions(+), 1 deletion(-)
a23721
a23721
diff --git a/libnmstate/ifaces/ethernet.py b/libnmstate/ifaces/ethernet.py
a23721
index 292b7bc..ca8501b 100644
a23721
--- a/libnmstate/ifaces/ethernet.py
a23721
+++ b/libnmstate/ifaces/ethernet.py
a23721
@@ -65,6 +65,12 @@ class EthernetIface(BaseIface):
a23721
     def is_peer(self):
a23721
         return self._is_peer
a23721
 
a23721
+    @property
a23721
+    def is_sriov(self):
a23721
+        return self.raw.get(Ethernet.CONFIG_SUBTREE, {}).get(
a23721
+            Ethernet.SRIOV_SUBTREE
a23721
+        )
a23721
+
a23721
     def create_sriov_vf_ifaces(self):
a23721
         return [
a23721
             EthernetIface(
a23721
diff --git a/libnmstate/netapplier.py b/libnmstate/netapplier.py
a23721
index cf208d1..3c5759b 100644
a23721
--- a/libnmstate/netapplier.py
a23721
+++ b/libnmstate/netapplier.py
a23721
@@ -24,6 +24,7 @@ import time
a23721
 
a23721
 from libnmstate import validator
a23721
 from libnmstate.error import NmstateVerificationError
a23721
+from libnmstate.schema import InterfaceType
a23721
 
a23721
 from .nmstate import create_checkpoints
a23721
 from .nmstate import destroy_checkpoints
a23721
@@ -37,6 +38,7 @@ from .version import get_version
a23721
 MAINLOOP_TIMEOUT = 35
a23721
 VERIFY_RETRY_INTERNAL = 1
a23721
 VERIFY_RETRY_TIMEOUT = 5
a23721
+VERIFY_RETRY_TIMEOUT_INCREASE = 4
a23721
 
a23721
 
a23721
 def apply(
a23721
@@ -109,7 +111,13 @@ def _apply_ifaces_state(plugins, net_state, verify_change, save_to_disk):
a23721
         plugin.apply_changes(net_state, save_to_disk)
a23721
     verified = False
a23721
     if verify_change:
a23721
-        for _ in range(VERIFY_RETRY_TIMEOUT):
a23721
+        if _net_state_contains_sriov_interface(net_state):
a23721
+            # If SR-IOV is present, the verification timeout is being increased
a23721
+            # to avoid timeouts due to slow drivers like i40e.
a23721
+            verify_retry = VERIFY_RETRY_TIMEOUT * VERIFY_RETRY_TIMEOUT_INCREASE
a23721
+        else:
a23721
+            verify_retry = VERIFY_RETRY_TIMEOUT
a23721
+        for _ in range(verify_retry):
a23721
             try:
a23721
                 _verify_change(plugins, net_state)
a23721
                 verified = True
a23721
@@ -120,6 +128,14 @@ def _apply_ifaces_state(plugins, net_state, verify_change, save_to_disk):
a23721
             _verify_change(plugins, net_state)
a23721
 
a23721
 
a23721
+def _net_state_contains_sriov_interface(net_state):
a23721
+    for iface in net_state.ifaces.all_kernel_ifaces.values():
a23721
+        if iface.type == InterfaceType.ETHERNET and iface.is_sriov:
a23721
+            return True
a23721
+
a23721
+    return False
a23721
+
a23721
+
a23721
 def _verify_change(plugins, net_state):
a23721
     current_state = show_with_plugins(plugins)
a23721
     net_state.verify(current_state)
a23721
-- 
a23721
2.27.0
a23721
a23721
a23721
From 439fe3a51a82060c5b62974c6c9fbdf403c4196b Mon Sep 17 00:00:00 2001
a23721
From: Fernando Fernandez Mancera <ffmancera@riseup.net>
a23721
Date: Mon, 22 Feb 2021 13:33:06 +0100
a23721
Subject: [PATCH 2/2] SR-IOV: fail on verification if `total_vfs` does not
a23721
 match vfs len
a23721
a23721
Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
a23721
Signed-off-by: Gris Ge <fge@redhat.com>
a23721
---
a23721
 libnmstate/ifaces/ethernet.py | 11 +++++++++++
a23721
 libnmstate/ifaces/ifaces.py   | 14 ++++++++++++++
a23721
 2 files changed, 25 insertions(+)
a23721
a23721
diff --git a/libnmstate/ifaces/ethernet.py b/libnmstate/ifaces/ethernet.py
a23721
index ca8501b..55772ce 100644
a23721
--- a/libnmstate/ifaces/ethernet.py
a23721
+++ b/libnmstate/ifaces/ethernet.py
a23721
@@ -61,6 +61,14 @@ class EthernetIface(BaseIface):
a23721
             .get(Ethernet.SRIOV.TOTAL_VFS, 0)
a23721
         )
a23721
 
a23721
+    @property
a23721
+    def sriov_vfs(self):
a23721
+        return (
a23721
+            self.raw.get(Ethernet.CONFIG_SUBTREE, {})
a23721
+            .get(Ethernet.SRIOV_SUBTREE, {})
a23721
+            .get(Ethernet.SRIOV.VFS_SUBTREE, [])
a23721
+        )
a23721
+
a23721
     @property
a23721
     def is_peer(self):
a23721
         return self._is_peer
a23721
@@ -108,6 +116,9 @@ class EthernetIface(BaseIface):
a23721
             for i in range(self.sriov_total_vfs, old_sriov_total_vfs)
a23721
         ]
a23721
 
a23721
+    def check_total_vfs_matches_vf_list(self, total_vfs):
a23721
+        return total_vfs == len(self.sriov_vfs)
a23721
+
a23721
 
a23721
 def _capitalize_sriov_vf_mac(state):
a23721
     vfs = (
a23721
diff --git a/libnmstate/ifaces/ifaces.py b/libnmstate/ifaces/ifaces.py
a23721
index 44c9e61..6c94a98 100644
a23721
--- a/libnmstate/ifaces/ifaces.py
a23721
+++ b/libnmstate/ifaces/ifaces.py
a23721
@@ -238,6 +238,8 @@ class Ifaces:
a23721
                     if new_iface.name not in self._kernel_ifaces:
a23721
                         new_iface.mark_as_desired()
a23721
                         new_ifaces.append(new_iface)
a23721
+                    else:
a23721
+                        self._kernel_ifaces[new_iface.name].mark_as_desired()
a23721
         for new_iface in new_ifaces:
a23721
             self._kernel_ifaces[new_iface.name] = new_iface
a23721
 
a23721
@@ -656,6 +658,18 @@ class Ifaces:
a23721
                                 cur_iface.state_for_verify(),
a23721
                             )
a23721
                         )
a23721
+                    elif (
a23721
+                        iface.type == InterfaceType.ETHERNET and iface.is_sriov
a23721
+                    ):
a23721
+                        if not cur_iface.check_total_vfs_matches_vf_list(
a23721
+                            iface.sriov_total_vfs
a23721
+                        ):
a23721
+                            raise NmstateVerificationError(
a23721
+                                "The NIC exceeded the waiting time for "
a23721
+                                "verification and it is failing because "
a23721
+                                "the `total_vfs` does not match the VF "
a23721
+                                "list length."
a23721
+                            )
a23721
 
a23721
     def gen_dns_metadata(self, dns_state, route_state):
a23721
         iface_metadata = dns_state.gen_metadata(self, route_state)
a23721
-- 
a23721
2.27.0
a23721