Skip to content

Commit

Permalink
Add dual return
Browse files Browse the repository at this point in the history
  • Loading branch information
atyronesmith committed Oct 23, 2020
1 parent bcd1c5c commit efc882e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
8 changes: 3 additions & 5 deletions pkg/resources/vfioResource.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package resources

import (
"strings"

"github.com/golang/glog"
"github.com/intel/sriov-network-device-plugin/pkg/types"
"github.com/intel/sriov-network-device-plugin/pkg/utils"
Expand Down Expand Up @@ -52,13 +50,13 @@ func (rp *vfioResource) GetDeviceSpecs(pciAddr string) []*pluginapi.DeviceSpec {
Permissions: "mrw",
})

vfioDev, err := utils.GetVFIODeviceFile(pciAddr)
vfioDevHost, vfioDevContainer, err := utils.GetVFIODeviceFile(pciAddr)
if err != nil {
glog.Errorf("GetDeviceSpecs(): error getting vfio device file for device: %s, %s", pciAddr, err.Error())
} else {
devSpecs = append(devSpecs, &pluginapi.DeviceSpec{
HostPath: vfioDev,
ContainerPath: strings.Replace(vfioDev, "noiommu-", "", 1),
HostPath: vfioDevHost,
ContainerPath: vfioDevContainer,
Permissions: "mrw",
})
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func ValidResourceName(name string) bool {
}

// GetVFIODeviceFile returns a vfio device files for vfio-pci bound PCI device's PCI address
func GetVFIODeviceFile(dev string) (devFile string, err error) {
func GetVFIODeviceFile(dev string) (devFileHost string, devFileContainer string, err error) {
// Get iommu group for this device
devPath := filepath.Join(sysBusPci, dev)
_, err = os.Lstat(devPath)
Expand Down Expand Up @@ -290,6 +290,8 @@ func GetVFIODeviceFile(dev string) (devFile string, err error) {
err = fmt.Errorf("GetVFIODeviceFile(): error reading symlink to iommu_group %v", err)
return
}
devFileContainer = filepath.Join("/dev/vfio", filepath.Base(linkName))
devFileHost = devFileContainer

// Get a file path to the iommu group name
namePath := filepath.Join(linkName, "name")
Expand All @@ -302,9 +304,9 @@ func GetVFIODeviceFile(dev string) (devFile string, err error) {
// if the iommu group name == vfio-noiommu then we are in a VM, adjust path to vfio device
if vName == "vfio-noiommu" {
linkName = filepath.Join(filepath.Dir(linkName), "noiommu-"+filepath.Base(linkName))
devFileHost = filepath.Join("/dev/vfio", filepath.Base(linkName))
}
}
devFile = filepath.Join("/dev/vfio", filepath.Base(linkName))

return
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,9 @@ var _ = Describe("In the utils package", func() {
DescribeTable("getting VFIO device file",
func(fs *FakeFilesystem, device, expected string, shouldFail bool) {
defer fs.Use()()
actual, err := GetVFIODeviceFile(device)
Expect(actual).To(Equal(expected))
//TODO: adapt test to running in a virtual environment
actualHost, _, err := GetVFIODeviceFile(device)
Expect(actualHost).To(Equal(expected))
assertShouldFail(err, shouldFail)
},
Entry("could not get directory information for device",
Expand Down

0 comments on commit efc882e

Please sign in to comment.