mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-05-06 07:27:28 +00:00
drivers: change BindDevicetoVFIO signature
BindDevicetoVFIO now returns the vfio path to the brand new vfio device bound Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
parent
66219d164f
commit
9a9721c261
@ -9,6 +9,7 @@ package drivers
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -27,6 +28,8 @@ const (
|
|||||||
pciDriverBindPath = "/sys/bus/pci/drivers/%s/bind"
|
pciDriverBindPath = "/sys/bus/pci/drivers/%s/bind"
|
||||||
vfioNewIDPath = "/sys/bus/pci/drivers/vfio-pci/new_id"
|
vfioNewIDPath = "/sys/bus/pci/drivers/vfio-pci/new_id"
|
||||||
vfioRemoveIDPath = "/sys/bus/pci/drivers/vfio-pci/remove_id"
|
vfioRemoveIDPath = "/sys/bus/pci/drivers/vfio-pci/remove_id"
|
||||||
|
iommuGroupPath = "/sys/bus/pci/devices/%s/iommu_group"
|
||||||
|
vfioDevPath = "/dev/vfio/%s"
|
||||||
pcieRootPortPrefix = "rp"
|
pcieRootPortPrefix = "rp"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -242,7 +245,7 @@ func getSysfsDev(sysfsDevStr string) (string, error) {
|
|||||||
|
|
||||||
// BindDevicetoVFIO binds the device to vfio driver after unbinding from host.
|
// BindDevicetoVFIO binds the device to vfio driver after unbinding from host.
|
||||||
// Will be called by a network interface or a generic pcie device.
|
// Will be called by a network interface or a generic pcie device.
|
||||||
func BindDevicetoVFIO(bdf, hostDriver, vendorDeviceID string) error {
|
func BindDevicetoVFIO(bdf, hostDriver, vendorDeviceID string) (string, error) {
|
||||||
|
|
||||||
// Unbind from the host driver
|
// Unbind from the host driver
|
||||||
unbindDriverPath := fmt.Sprintf(pciDriverUnbindPath, bdf)
|
unbindDriverPath := fmt.Sprintf(pciDriverUnbindPath, bdf)
|
||||||
@ -252,7 +255,7 @@ func BindDevicetoVFIO(bdf, hostDriver, vendorDeviceID string) error {
|
|||||||
}).Info("Unbinding device from driver")
|
}).Info("Unbinding device from driver")
|
||||||
|
|
||||||
if err := utils.WriteToFile(unbindDriverPath, []byte(bdf)); err != nil {
|
if err := utils.WriteToFile(unbindDriverPath, []byte(bdf)); err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add device id to vfio driver.
|
// Add device id to vfio driver.
|
||||||
@ -262,7 +265,7 @@ func BindDevicetoVFIO(bdf, hostDriver, vendorDeviceID string) error {
|
|||||||
}).Info("Writing vendor-device-id to vfio new-id path")
|
}).Info("Writing vendor-device-id to vfio new-id path")
|
||||||
|
|
||||||
if err := utils.WriteToFile(vfioNewIDPath, []byte(vendorDeviceID)); err != nil {
|
if err := utils.WriteToFile(vfioNewIDPath, []byte(vendorDeviceID)); err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind to vfio-pci driver.
|
// Bind to vfio-pci driver.
|
||||||
@ -276,7 +279,12 @@ func BindDevicetoVFIO(bdf, hostDriver, vendorDeviceID string) error {
|
|||||||
// Device may be already bound at this time because of earlier write to new_id, ignore error
|
// Device may be already bound at this time because of earlier write to new_id, ignore error
|
||||||
utils.WriteToFile(bindDriverPath, []byte(bdf))
|
utils.WriteToFile(bindDriverPath, []byte(bdf))
|
||||||
|
|
||||||
return nil
|
groupPath, err := os.Readlink(fmt.Sprintf(iommuGroupPath, bdf))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf(vfioDevPath, filepath.Base(groupPath)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// BindDevicetoHost binds the device to the host driver driver after unbinding from vfio-pci.
|
// BindDevicetoHost binds the device to the host driver driver after unbinding from vfio-pci.
|
||||||
|
@ -202,7 +202,7 @@ func createPhysicalEndpoint(netInfo NetworkInfo) (*PhysicalEndpoint, error) {
|
|||||||
return physicalEndpoint, nil
|
return physicalEndpoint, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func bindNICToVFIO(endpoint *PhysicalEndpoint) error {
|
func bindNICToVFIO(endpoint *PhysicalEndpoint) (string, error) {
|
||||||
return drivers.BindDevicetoVFIO(endpoint.BDF, endpoint.Driver, endpoint.VendorDeviceID)
|
return drivers.BindDevicetoVFIO(endpoint.BDF, endpoint.Driver, endpoint.VendorDeviceID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user