On 23/09/2024 19:42, jspew...@iol.unh.edu wrote:
+
+    def get_vfs_on_port(self, pf_port: Port) -> list[VirtualFunction]:
+        """Get all virtual functions (VFs) that DTS is aware of on `pf_port`.
+
+        Args:
+            pf_port: The port to search for the VFs on.
+
+        Returns:
+            A list of VFs in the framework that were created/gathered from 
`pf_port`.
+        """
+        return [p for p in self.ports if isinstance(p, VirtualFunction) and 
p.pf_port == pf_port]

If the change proposed by Juraj to store VFs under the PF goes through, this could end up being simpler.

+
+    def remove_virtual_functions(self, pf_port: Port) -> None:
+        """Removes all virtual functions (VFs) created on `pf_port` by DTS.
+
+        Finds all the VFs that were created from `pf_port` and either removes 
them if they were
+        created by the DTS framework or binds them back to their os_driver if 
they were preexisting
+        on the node.
+
+        Args:
+            pf_port: Port to remove the VFs from.
+        """
+        vf_ports = self.get_vfs_on_port(pf_port)
+        if any(vf.created_by_framework for vf in vf_ports):
+            self.main_session.set_num_virtual_functions(0, pf_port)
+        else:
+            self._logger.info("Skipping removing VFs since they were not created by 
DTS.")

This will cause VFs that were created by us to not be removed. We should ensure at least these ones are cleaned up.

Reply via email to