Skip to content

Commit

Permalink
Merge pull request #623 from glasnostic/fix-pci
Browse files Browse the repository at this point in the history
fix device/binder can't handle correctly with network interface with `virtio-pci` driver on KVM
  • Loading branch information
gshimansky authored Jun 19, 2019
2 parents 376f7e7 + b49d4a0 commit 66385c6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion devices/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var (

var (
pathSysClassNetDeviceDriver stringBuilder = PathSysClassNet + "/%s/device/driver"
pathSysClassNetDevice stringBuilder = PathSysClassNet + "/%s/device"
pathSysClassNetDevice stringBuilder = PathSysClassNet + "/%s"
)

var (
Expand Down
26 changes: 22 additions & 4 deletions devices/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,18 @@ func FindDefaultDpdkDriver(nicName string) string {

// GetDeviceID returns the device ID of given NIC name.
func GetDeviceID(nicName string) (string, error) {
// DEV_ID=$(basename $(readlink /sys/class/net/<nicName>/device))
return readlinkBaseCmd(pathSysClassNetDevice.With(nicName))
// DEV_ID=$(basename $(readlink /sys/class/net/<nicName>))
raw, err := readlinkCmd(pathSysClassNetDevice.With(nicName))
if err != nil {
return "", err
}
// raw should be like /sys/devices/pci0002:00/0000:00:08.0/virtio2/net/ens8
raws := strings.Split(raw, "/")
if len(raws) < 5 {
return "", fmt.Errorf("path not correct")
}
return raws[4], nil

}

// IsModuleLoaded checks if the kernel has already loaded the driver or not.
Expand Down Expand Up @@ -69,12 +79,20 @@ func writeToTargetWithData(sysfs string, flag int, mode os.FileMode, data string
return nil
}

func readlinkBaseCmd(path string) (string, error) {
output, err := cmdOutputWithTimeout(defaultTimeoutLimitation, "readlink", path)
func readlinkCmd(path string) (string, error) {
output, err := cmdOutputWithTimeout(defaultTimeoutLimitation, "readlink", "-f", path)
if err != nil {
return "", fmt.Errorf("Cmd Execute readlink failed: %s", err.Error())
}
outputStr := strings.Trim(string(output), "\n")
return outputStr, nil
}

func readlinkBaseCmd(path string) (string, error) {
outputStr, err := readlinkCmd(path)
if err != nil {
return "", fmt.Errorf("Cmd Execute readlink failed: %s", err.Error())
}
result := filepath.Base(outputStr)
return result, nil
}
Expand Down

0 comments on commit 66385c6

Please sign in to comment.