From c6390f2a2af85c3493b014d8d5a1bda059fcbc4c Mon Sep 17 00:00:00 2001 From: Archana Shinde Date: Wed, 6 Dec 2023 21:29:20 -0800 Subject: [PATCH] vfio: Introduce function to get vfio dev path This function will be later used to get the vfio dev path. Signed-off-by: Archana Shinde --- src/runtime/pkg/device/drivers/vfio.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/runtime/pkg/device/drivers/vfio.go b/src/runtime/pkg/device/drivers/vfio.go index e9c99b9221..f315fddaf0 100644 --- a/src/runtime/pkg/device/drivers/vfio.go +++ b/src/runtime/pkg/device/drivers/vfio.go @@ -268,6 +268,16 @@ func GetBDF(deviceSysStr string) string { return tokens[1] } +func GetVFIODevPath(bdf string) (string, error) { + // Determine the iommu group that the device belongs to. + groupPath, err := os.Readlink(fmt.Sprintf(iommuGroupPath, bdf)) + if err != nil { + return "", err + } + + return fmt.Sprintf(vfioDevPath, filepath.Base(groupPath)), nil +} + // BindDevicetoVFIO binds the device to vfio driver after unbinding from host // driver if present. // Will be called by a network interface or a generic pcie device. @@ -306,13 +316,7 @@ func BindDevicetoVFIO(bdf, hostDriver string) (string, error) { return "", err } - // Determine the iommu group that the device belongs to. - groupPath, err := os.Readlink(fmt.Sprintf(iommuGroupPath, bdf)) - if err != nil { - return "", err - } - - return fmt.Sprintf(vfioDevPath, filepath.Base(groupPath)), nil + return GetVFIODevPath(bdf) } // BindDevicetoHost unbinds the device from vfio-pci driver and binds it to the