Skip to content

Commit

Permalink
sriov: support virtio vdpa devices
Browse files Browse the repository at this point in the history
Add support to sriov-based virtio-vdpa devices.

When a sr-iov device has a vdpa device created, and it is bound to
virtio_vdpa driver, use the associated virtio-net device instead of the
vendor one.

In order to determine whether a device is vdpa or not as well as its
device path, use external
library github.com/k8snetworkplumbingwg/govdpa

Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
  • Loading branch information
amorenoz committed Dec 28, 2021
1 parent f546683 commit 131f732
Show file tree
Hide file tree
Showing 9 changed files with 590 additions and 0 deletions.
1 change: 1 addition & 0 deletions go-controller/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/gorilla/mux v1.8.0
github.com/juju/errors v0.0.0-20200330140219-3fe23663418f // indirect
github.com/juju/testing v0.0.0-20200706033705-4c23f9c453cd // indirect
github.com/k8snetworkplumbingwg/govdpa v0.1.3
github.com/k8snetworkplumbingwg/network-attachment-definition-client v0.0.0-20200626054723-37f83d1996bc
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/miekg/dns v1.1.31
Expand Down
2 changes: 2 additions & 0 deletions go-controller/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ github.com/juju/utils v0.0.0-20180808125547-9dfc6dbfb02b/go.mod h1:6/KLg8Wz/y2KV
github.com/juju/version v0.0.0-20161031051906-1f41e27e54f2/go.mod h1:kE8gK5X0CImdr7qpSKl3xB2PmpySSmfj7zVbkZFs81U=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/k8snetworkplumbingwg/govdpa v0.1.3 h1:FZRhTMB1e3yWwSEy+l4eS73WioyMaL+vmFZ8JNwn+Uk=
github.com/k8snetworkplumbingwg/govdpa v0.1.3/go.mod h1:Jx2rlMquENdCd8M5Oc51xHCt10bQIXTloDU8F4nS4T4=
github.com/k8snetworkplumbingwg/network-attachment-definition-client v0.0.0-20200626054723-37f83d1996bc h1:M7bj0RX9dc79YIyptmHm0tPmC/WuIbn+HVeTBDK2KZw=
github.com/k8snetworkplumbingwg/network-attachment-definition-client v0.0.0-20200626054723-37f83d1996bc/go.mod h1:+1DpV8uIwteAhxNO0lgRox8gHkTG6w3OeDfAlg+qqjA=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
Expand Down
8 changes: 8 additions & 0 deletions go-controller/pkg/cni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
utilnet "k8s.io/utils/net"

"github.com/containernetworking/cni/pkg/types/current"
"github.com/k8snetworkplumbingwg/govdpa/pkg/kvdpa"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/config"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/kube"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/types"
Expand Down Expand Up @@ -95,6 +96,13 @@ func (pr *PodRequest) checkOrUpdatePodUID(podUID string) error {

func (pr *PodRequest) getVFNetdevName() (string, error) {
// Get the vf device Name

// If a vDPA device exists, it takes preference over the vendor device, steering-wize
vdpaDevice, err := util.GetVdpaOps().GetVdpaDeviceByPci(pr.CNIConf.DeviceID)
if err == nil && vdpaDevice.GetDriver() == kvdpa.VirtioVdpaDriver {
return vdpaDevice.GetNetDev(), nil
}

vfNetdevices, err := util.GetSriovnetOps().GetNetDevicesFromPci(pr.CNIConf.DeviceID)
if err != nil {
return "", err
Expand Down
66 changes: 66 additions & 0 deletions go-controller/pkg/util/mocks/VdpaDevice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions go-controller/pkg/util/mocks/VdpaOps.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions go-controller/pkg/util/vdpa_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package util

import (
"github.com/k8snetworkplumbingwg/govdpa/pkg/kvdpa"
)

type VdpaDevice interface {
kvdpa.VdpaDevice
}

type VdpaOps interface {
GetVdpaDeviceByPci(pciAddress string) (kvdpa.VdpaDevice, error)
}

type defaultVdpaOps struct {
}

var vdpaOps VdpaOps = &defaultVdpaOps{}

// SetVdpaOpsInst method should be used by unit tests in
func SetVdpaOpsInst(mockInst VdpaOps) {
vdpaOps = mockInst
}

// GetVdpaOps will be invoked by functions in other packages that would need access to the govdpa library methods.
func GetVdpaOps() VdpaOps {
return vdpaOps
}

func (v *defaultVdpaOps) GetVdpaDeviceByPci(pciAddress string) (kvdpa.VdpaDevice, error) {
return kvdpa.GetVdpaDeviceByPci(pciAddress)
}
201 changes: 201 additions & 0 deletions go-controller/vendor/github.com/k8snetworkplumbingwg/govdpa/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 131f732

Please sign in to comment.