@@ -16,7 +16,6 @@ pub const INTERFACE_NAME: &str = "eth0";
1616pub async fn configure_sriov ( num_vfs : u32 ) -> Result < ( ) , String > {
1717 let base_path = format ! ( "/sys/class/net/{INTERFACE_NAME}/device" ) ;
1818
19- // Disable driver autoprobe for new VFs to prevent mlx5_core from claiming them.
2019 let autoprobe_path = format ! ( "{base_path}/sriov_drivers_autoprobe" ) ;
2120 info ! ( "Disabling sriov_drivers_autoprobe at {autoprobe_path}" ) ;
2221 let mut autoprobe_file = OpenOptions :: new ( )
@@ -29,7 +28,6 @@ pub async fn configure_sriov(num_vfs: u32) -> Result<(), String> {
2928 . await
3029 . map_err ( |e| format ! ( "Failed to disable autoprobe: {e}" ) ) ?;
3130
32- // Reset VFs to 0 before creating new ones.
3331 let numvfs_path = format ! ( "{base_path}/sriov_numvfs" ) ;
3432 let mut numvfs_file = OpenOptions :: new ( )
3533 . write ( true )
@@ -42,15 +40,14 @@ pub async fn configure_sriov(num_vfs: u32) -> Result<(), String> {
4240 . write_all ( b"0\n " )
4341 . await
4442 . map_err ( |e| format ! ( "Failed to write 0 to sriov_numvfs: {e}" ) ) ?;
45- sleep ( Duration :: from_secs ( 1 ) ) . await ; // Give time for VFs to be removed.
43+ sleep ( Duration :: from_secs ( 1 ) ) . await ;
4644
47- // Create the new VFs.
4845 info ! ( "Creating {num_vfs} sriov virtual functions for {INTERFACE_NAME}" ) ;
4946 numvfs_file
5047 . write_all ( format ! ( "{num_vfs}\n " ) . as_bytes ( ) )
5148 . await
5249 . map_err ( |e| format ! ( "Failed to write to sriov_numvfs: {e}" ) ) ?;
53- sleep ( Duration :: from_secs ( 2 ) ) . await ; // Give time for VFs to be created.
50+ sleep ( Duration :: from_secs ( 2 ) ) . await ;
5451
5552 let device_path = read_link ( & base_path) . await . map_err ( |e| e. to_string ( ) ) ?;
5653 let pci_address = device_path
@@ -73,10 +70,8 @@ pub async fn configure_sriov(num_vfs: u32) -> Result<(), String> {
7370 . map ( format_pci_address)
7471 . collect ( ) ;
7572
76- // Bind each newly created VF to the vfio-pci driver.
7773 for vf_pci in virtual_funcs. iter ( ) {
7874 if let Err ( e) = bind_vf_to_vfio ( vf_pci) . await {
79- // With autoprobe disabled, this should be reliable. A failure is a hard error.
8075 return Err ( format ! ( "Failed to bind VF {vf_pci} to vfio-pci: {e}" ) ) ;
8176 }
8277 }
@@ -122,19 +117,13 @@ fn format_pci_address(address: (u16, u8, u8, u8)) -> String {
122117}
123118
124119async fn bind_vf_to_vfio ( pci_address : & str ) -> Result < ( ) , io:: Error > {
125- info ! ( "Binding {pci_address} to vfio-pci using driver_override" ) ;
126-
127- // Set the driver_override to vfio-pci for this specific device.
128120 let override_path = format ! ( "/sys/bus/pci/devices/{pci_address}/driver_override" ) ;
129121 let mut override_file = OpenOptions :: new ( ) . write ( true ) . open ( & override_path) . await ?;
130122 override_file. write_all ( b"vfio-pci" ) . await ?;
131- info ! ( "Set driver_override for {pci_address}" ) ;
132123
133- // Trigger the binding action. The kernel will see the override and use vfio-pci.
134124 let bind_path = "/sys/bus/pci/drivers/vfio-pci/bind" ;
135125 let mut bind_file = OpenOptions :: new ( ) . write ( true ) . open ( bind_path) . await ?;
136126 bind_file. write_all ( pci_address. as_bytes ( ) ) . await ?;
137- info ! ( "Successfully triggered bind for {pci_address}" ) ;
138127
139128 Ok ( ( ) )
140129}
0 commit comments