From d41acb83c47380d8b2710a3f3dce7b65491b7e79 Mon Sep 17 00:00:00 2001 From: peri <30619230+pperiyasamy@users.noreply.github.com> Date: Wed, 20 Jan 2021 17:35:42 +0100 Subject: [PATCH] host-device: Add support for DPDK device (#490) 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 --- plugins/main/host-device/host-device.go | 42 +++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/plugins/main/host-device/host-device.go b/plugins/main/host-device/host-device.go index 5480e8b87..81acdffed 100644 --- a/plugins/main/host-device/host-device.go +++ b/plugins/main/host-device/host-device.go @@ -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 @@ -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(¤t.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) @@ -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 } @@ -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,