Skip to content

Commit

Permalink
hack for kubevirtci
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Milleri <lmilleri@redhat.com>
  • Loading branch information
lmilleri committed Dec 19, 2023
1 parent 30652a2 commit 1294fb1
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/sriovdp/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ func (rm *resourceManager) initServers() error {

for index := range rc.SelectorObjs {
devices := dp.GetDevices(rc, index)
glog.Infof("# of devices: %d", len(devices))
glog.Infof("devices: %v", devices)
partialFilteredDevices, err := dp.GetFilteredDevices(devices, rc, index)
if err != nil {
glog.Errorf("initServers(): error getting filtered devices for config %+v: %q", rc, err)
Expand Down
3 changes: 3 additions & 0 deletions pkg/netdevice/netDeviceProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,14 @@ func (np *netDeviceProvider) GetFilteredDevices(devices []types.HostDevice,
vdpaDevices := make([]types.HostDevice, 0)
for _, dev := range filteredDevice {
vdpaDev := dev.(types.PciNetDevice).GetVdpaDevice()
glog.Infof("vdpaDev: %v", vdpaDev)
if vdpaDev == nil {
continue
}
if vType := vdpaDev.GetType(); vType != types.VdpaInvalidType && vType == nf.VdpaType {
vdpaDevices = append(vdpaDevices, dev)
} else {
glog.Infof("discarded: type = ", vdpaDev.GetType())
}
}
filteredDevice = vdpaDevices
Expand Down
72 changes: 72 additions & 0 deletions pkg/utils/vdpa_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"fmt"
"strings"

"github.com/golang/glog"
vdpa "github.com/k8snetworkplumbingwg/govdpa/pkg/kvdpa"
Expand All @@ -27,7 +28,78 @@ func GetVdpaProvider() VdpaProvider {
return vdpaProvider
}

type mgmtDev struct {
busName string
devName string
}

// BusName returns the MgmtDev's bus name
func (m *mgmtDev) BusName() string {
return m.busName
}

// BusName returns the MgmtDev's device name
func (m *mgmtDev) DevName() string {
return m.devName
}

func (m *mgmtDev) Name() string {
if m.busName != "" {
return strings.Join([]string{m.busName, m.devName}, "/")

Check failure on line 48 in pkg/utils/vdpa_provider.go

View workflow job for this annotation

GitHub Actions / Golangci-lint

stringConcatSimplify: suggestion: m.busName + "/" + m.devName (gocritic)
}
return m.devName
}

type vhostVdpa struct {
name string
path string
}

// Name returns the vhost device's name
func (v *vhostVdpa) Name() string {
return v.name
}

// Name returns the vhost device's path
func (v *vhostVdpa) Path() string {
return v.path
}

type vdpaDeviceHack struct {
name string // vdpa:0000:65:00.2
busName string // optional
devName string // 0000:65:00.2
vHostName string // vhost-vdpa-0
vHostPath string // /dev/vhost-vdpa-0
}

func (v *vdpaDeviceHack) Driver() string {
return "vhost_vdpa"
}
func (v *vdpaDeviceHack) Name() string {
return v.name
}

func (v *vdpaDeviceHack) MgmtDev() vdpa.MgmtDev {
return &mgmtDev{busName: v.busName, devName: v.devName}
}
func (v *vdpaDeviceHack) VirtioNet() vdpa.VirtioNet {
return nil
}
func (v *vdpaDeviceHack) VhostVdpa() vdpa.VhostVdpa {
return &vhostVdpa{name: v.vHostName, path: v.vHostPath}
}
func (v *vdpaDeviceHack) ParentDevicePath() (string, error) {
return v.devName, nil
}

func (defaultVdpaProvider) GetVdpaDeviceByPci(pciAddr string) (vdpa.VdpaDevice, error) {
if pciAddr == "0000:65:00.2" {
return &vdpaDeviceHack{name: "vdpa:0000:65:00.2", busName: "", devName: pciAddr, vHostName: "vhost-vdpa-0", vHostPath: "/dev/vhost-vdpa-0"}, nil

Check failure on line 98 in pkg/utils/vdpa_provider.go

View workflow job for this annotation

GitHub Actions / Golangci-lint

line is 146 characters (lll)
} else if pciAddr == "0000:65:00.3" {
return &vdpaDeviceHack{name: "vdpa:0000:65:00.3", busName: "", devName: pciAddr, vHostName: "vhost-vdpa-1", vHostPath: "/dev/vhost-vdpa-1"}, nil

Check failure on line 100 in pkg/utils/vdpa_provider.go

View workflow job for this annotation

GitHub Actions / Golangci-lint

line is 146 characters (lll)
}

// the govdpa library requires the pci address to include the "pci/" prefix
fullPciAddr := "pci/" + pciAddr
vdpaDevices, err := vdpa.GetVdpaDevicesByPciAddress(fullPciAddr)
Expand Down

0 comments on commit 1294fb1

Please sign in to comment.