From a9b4e04bc413468897c3d9be8d7f8c65a2d9ca51 Mon Sep 17 00:00:00 2001 From: Periyasamy Palanisamy Date: Tue, 11 Feb 2020 15:40:48 +0100 Subject: [PATCH] Make host-device to work with virtio net device In case pciBusID contains pci address of the virtio device, then lookup the net directory under virtio directory. Issue: https://github.com/containernetworking/plugins/issues/320 Signed-off-by: Periyasamy Palanisamy --- plugins/main/host-device/host-device.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/main/host-device/host-device.go b/plugins/main/host-device/host-device.go index 799fafe0..cedae4f3 100644 --- a/plugins/main/host-device/host-device.go +++ b/plugins/main/host-device/host-device.go @@ -296,7 +296,12 @@ func getLink(devname, hwaddr, kernelpath, pciaddr string) (netlink.Link, error) } else if len(pciaddr) > 0 { netDir := filepath.Join(sysBusPCI, pciaddr, "net") if _, err := os.Lstat(netDir); err != nil { - return nil, fmt.Errorf("no net directory under pci device %s: %q", pciaddr, err) + virtioNetDir := filepath.Join(sysBusPCI, pciaddr, "virtio*", "net") + matches, err := filepath.Glob(virtioNetDir) + if matches == nil || err != nil { + return nil, fmt.Errorf("no net directory under pci device %s", pciaddr) + } + netDir = matches[0] } fInfo, err := ioutil.ReadDir(netDir) if err != nil {