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 <periyasamy.palanisamy@est.tech>
This commit is contained in:
parent
7dc7a002cf
commit
d41acb83c4
@ -43,6 +43,9 @@ const (
|
|||||||
sysBusPCI = "/sys/bus/pci/devices"
|
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
|
//NetConf for host-device config, look the README to learn how to use those parameters
|
||||||
type NetConf struct {
|
type NetConf struct {
|
||||||
types.NetConf
|
types.NetConf
|
||||||
@ -91,6 +94,16 @@ func cmdAdd(args *skel.CmdArgs) error {
|
|||||||
}
|
}
|
||||||
defer containerNs.Close()
|
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)
|
hostDev, err := getLink(cfg.Device, cfg.HWAddr, cfg.KernelPath, cfg.PCIAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to find host device: %v", err)
|
return fmt.Errorf("failed to find host device: %v", err)
|
||||||
@ -168,6 +181,16 @@ func cmdDel(args *skel.CmdArgs) error {
|
|||||||
}
|
}
|
||||||
defer containerNs.Close()
|
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 {
|
if err := moveLinkOut(containerNs, args.IfName); err != nil {
|
||||||
return err
|
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 {
|
func printLink(dev netlink.Link, cniVersion string, containerNs ns.NetNS) error {
|
||||||
result := current.Result{
|
result := current.Result{
|
||||||
CNIVersion: current.ImplementedSpecVersion,
|
CNIVersion: current.ImplementedSpecVersion,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user