Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated dependency to govdpa v0.1.4 #450

Merged
merged 1 commit into from
Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/jaypipes/ghw v0.6.0
github.com/jaypipes/pcidb v0.5.0
github.com/k8snetworkplumbingwg/govdpa v0.1.3
github.com/k8snetworkplumbingwg/govdpa v0.1.4
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.1.1-0.20201119153432-9d213757d22d
github.com/onsi/ginkgo v1.14.0
github.com/onsi/gomega v1.10.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
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/govdpa v0.1.4 h1:e6mM7JFZkLVJeMQw3px96EigHAhnb4VUlqhNub/2Psk=
github.com/k8snetworkplumbingwg/govdpa v0.1.4/go.mod h1:UQR1xu7A+nnRK1dkLEi12OnNL0OiBPpIKOYDuaQQkck=
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.1.1-0.20201119153432-9d213757d22d h1:9QbZltQGRFe7temwcTDjj8rIbow48Gv6mIKOxuks+OI=
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.1.1-0.20201119153432-9d213757d22d/go.mod h1:+1DpV8uIwteAhxNO0lgRox8gHkTG6w3OeDfAlg+qqjA=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
Expand Down
22 changes: 18 additions & 4 deletions pkg/netdevice/vdpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ import (
"github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/utils"
)

// vdpaTypeToDriver translates vdpaTypes (as specified in the netDevice selectors)
// to vdpa bus drivers

/*
vdpaTypeToDriver translates vdpaTypes (as specified in the netDevice selectors)
to vdpa bus drivers
*/
var supportedVdpaTypes = map[types.VdpaType]string{
types.VdpaVirtioType: vdpa.VirtioVdpaDriver,
types.VdpaVhostType: vdpa.VhostVdpaDriver,
Expand All @@ -41,7 +42,7 @@ type vdpaDevice struct {

// GetType returns the VdpaType associated with the VdpaDevice
func (v *vdpaDevice) GetType() types.VdpaType {
currentDriver := v.GetDriver()
currentDriver := v.VdpaDevice.Driver()
for vtype, driver := range supportedVdpaTypes {
if driver == currentDriver {
return vtype
Expand All @@ -50,6 +51,19 @@ func (v *vdpaDevice) GetType() types.VdpaType {
return types.VdpaInvalidType
}

func (v *vdpaDevice) GetParent() string {
return v.VdpaDevice.Name()
}

func (v *vdpaDevice) GetPath() string {
path, err := v.ParentDevicePath()
if err != nil {
glog.Infof("%s - No path for vDPA device found: %v", v.Name(), err)
return ""
}
return path
}

// GetVdpaDevice returns a VdpaDevice from a given VF PCI address
func GetVdpaDevice(pciAddr string) types.VdpaDevice {
detailVdpaDev, err := utils.GetVdpaProvider().GetVdpaDeviceByPci(pciAddr)
Expand Down
18 changes: 17 additions & 1 deletion pkg/utils/vdpa_provider.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package utils

import (
"fmt"

"github.com/golang/glog"
vdpa "github.com/k8snetworkplumbingwg/govdpa/pkg/kvdpa"
)

Expand All @@ -25,5 +28,18 @@ func GetVdpaProvider() VdpaProvider {
}

func (defaultVdpaProvider) GetVdpaDeviceByPci(pciAddr string) (vdpa.VdpaDevice, error) {
return vdpa.GetVdpaDeviceByPci(pciAddr)
// the govdpa library requires the pci address to include the "pci/" prefix
fullPciAddr := "pci/" + pciAddr
vdpaDevices, err := vdpa.GetVdpaDevicesByPciAddress(fullPciAddr)
if err != nil {
return nil, err
}
numVdpaDevices := len(vdpaDevices)
if numVdpaDevices == 0 {
return nil, fmt.Errorf("no vdpa device associated to pciAddress %s", pciAddr)
}
if numVdpaDevices > 1 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a valid use-case?
should we always return the first one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adrian asked the same question, please check comments above. Basically, there is only one vdpa device per pci-address in SRIOV. Anyway, the govdpa interface is more general and future proof for when sub-functions will be supported.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good that we ask the same questions :P

glog.Infof("More than one vDPA device found for pciAddress %s, returning the first one", pciAddr)
}
return vdpaDevices[0], nil
lmilleri marked this conversation as resolved.
Show resolved Hide resolved
}
Loading