Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

host-device: Add support for DPDK device #490

Merged
merged 3 commits into from
Jan 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions plugins/main/host-device/host-device.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const (
sysBusPCI = "/sys/bus/pci/devices"
)

// Array of different linux drivers bound to network device needed for DPDK
var userspaceDrivers = []string{"vfio-pci", "uio_pci_generic", "igb_uio"}
dcbw marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit ignorant of DPDK; is there no more generic way to detect it than a hard-coded list of names?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, this is the way to find the dpdk device as per the driver bound to it (https://doc.dpdk.org/guides/linux_gsg/linux_drivers.html)


//NetConf for host-device config, look the README to learn how to use those parameters
type NetConf struct {
types.NetConf
Expand Down Expand Up @@ -91,6 +94,16 @@ func cmdAdd(args *skel.CmdArgs) error {
}
defer containerNs.Close()

if len(cfg.PCIAddr) > 0 {
isDpdkMode, err := hasDpdkDriver(cfg.PCIAddr)
if err != nil {
return fmt.Errorf("error with host device: %v", err)
}
if isDpdkMode {
return types.PrintResult(&current.Result{}, cfg.CNIVersion)
}
}

hostDev, err := getLink(cfg.Device, cfg.HWAddr, cfg.KernelPath, cfg.PCIAddr)
if err != nil {
return fmt.Errorf("failed to find host device: %v", err)
Expand Down Expand Up @@ -168,6 +181,16 @@ func cmdDel(args *skel.CmdArgs) error {
}
defer containerNs.Close()

if len(cfg.PCIAddr) > 0 {
isDpdkMode, err := hasDpdkDriver(cfg.PCIAddr)
if err != nil {
return fmt.Errorf("error with host device: %v", err)
}
if isDpdkMode {
return nil
}
}

if err := moveLinkOut(containerNs, args.IfName); err != nil {
return err
}
Expand Down Expand Up @@ -255,6 +278,25 @@ func moveLinkOut(containerNs ns.NetNS, ifName string) error {
})
}

func hasDpdkDriver(pciaddr string) (bool, error) {
driverLink := filepath.Join(sysBusPCI, pciaddr, "driver")
driverPath, err := filepath.EvalSymlinks(driverLink)
if err != nil {
return false, err
}
driverStat, err := os.Stat(driverPath)
if err != nil {
return false, err
}
driverName := driverStat.Name()
for _, drv := range userspaceDrivers {
if driverName == drv {
return true, nil
}
}
return false, nil
}

func printLink(dev netlink.Link, cniVersion string, containerNs ns.NetNS) error {
result := current.Result{
CNIVersion: current.ImplementedSpecVersion,
Expand Down