Skip to content

Commit

Permalink
host-device: Add support for DPDK device (containernetworking#490)
Browse files Browse the repository at this point in the history
This commit would make host-device plugin as a placeholder
for DPDK device when applications wants to attach it with
a pod container through network attachment definition.

Signed-off-by: Periyasamy Palanisamy <[email protected]>
  • Loading branch information
pperiyasamy authored and dougbtv committed Aug 12, 2021
1 parent dbf6c66 commit 7bf2a10
Showing 1 changed file with 42 additions and 0 deletions.
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"}

//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

0 comments on commit 7bf2a10

Please sign in to comment.