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

Add vDPA support #306

Merged
merged 7 commits into from
Mar 9, 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
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ This plugin creates device plugin endpoints based on the configurations given in
"isRdma": true
}
},
{
"resourceName": "ct6dx_vdpa_vhost",
"selectors": {
"vendors": ["15b3"],
"devices": ["101e"],
"drivers": ["mlx5_core"],
"vdpaType": "vhost"
}
},
{
"resourceName": "intel_fpga",
"deviceType": "accelerator",
Expand Down Expand Up @@ -231,8 +240,9 @@ This selector is applicable when "deviceType" is "netDevice"(note: this is defau
| "rootDevices" | N | VFs from PF matches list of PF PCI addresses | `string` list Default: `null` | "rootDevices": ["0000:86:00.0"] (See follow-up sections for some advance usage of "rootDevices") |
| "linkTypes" | N | The link type of the net device associated with the PCI device | `string` list Default: `null` | "linkTypes": ["ether"] |
| "ddpProfiles" | N | A map of device selectors | `string` list Default: `null` | "ddpProfiles": ["GTPv1-C/U IPv4/IPv6 payload"] |
| "isRdma" | N | Mount RDMA resources | `bool` values `true` or `false` Default: `false` | "isRdma": `true` |
| "isRdma" | N | Mount RDMA resources. Incompatible with vdpaType | `bool` values `true` or `false` Default: `false` | "isRdma": `true` |
| "needVhostNet"| N | Share /dev/vhost-net and /dev/net/tun | `bool` values `true` or `false` Default: `false` | "needVhostNet": `true` |
| "vdpaType" | N | The type of vDPA device (virtio, vhost). Incompatible with isRdma = true | `string` values `vhost` or `virtio` Default: `null` | "vdpaType": "vhost" |


[//]: # (The tables above generated using: https://ozh.github.io/ascii-tables/)
Expand Down
5 changes: 5 additions & 0 deletions cmd/sriovdp/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ func (rm *resourceManager) validConfigs() bool {
return false
}

// Check DeviceType-specific configuration
if !rm.deviceProviders[conf.DeviceType].ValidConfig(conf) {
return false
}

resourceNames[resourceName] = resourceName
}

Expand Down
35 changes: 32 additions & 3 deletions cmd/sriovdp/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ var _ = Describe("Resource manager", func() {
testErr = ioutil.WriteFile("/tmp/sriovdp/test_config", []byte(`{
"resourceList": [{
"resourceName": "intel_sriov_netdevice",
"isRdma": false,
"selectors": {
"isRdma": false,
"vendors": ["8086"],
"devices": ["154c", "10ed"],
"drivers": ["i40evf", "ixgbevf"]
Expand Down Expand Up @@ -162,8 +162,8 @@ var _ = Describe("Resource manager", func() {
err = ioutil.WriteFile("/tmp/sriovdp/test_config", []byte(`{
"resourceList": [{
"resourceName": "invalid-name",
"isRdma": false,
"selectors": {
"isRdma": false,
"vendors": ["8086"],
"devices": ["154c", "10ed"],
"drivers": ["i40evf", "ixgbevf"]
Expand All @@ -189,8 +189,8 @@ var _ = Describe("Resource manager", func() {
err = ioutil.WriteFile("/tmp/sriovdp/test_config", []byte(`{
"resourceList": [{
"resourceName": "duplicate",
"isRdma": true,
"selectors": {
"isRdma": true,
"vendors": ["8086"],
"devices": ["154c", "10ed"],
"drivers": ["i40evf", "ixgbevf"]
Expand All @@ -214,6 +214,35 @@ var _ = Describe("Resource manager", func() {
Expect(rm.validConfigs()).To(Equal(false))
})
})
Context("when both IsRdma and VdpaType are configured", func() {
BeforeEach(func() {
err := os.MkdirAll("/tmp/sriovdp", 0755)
if err != nil {
panic(err)
}
err = ioutil.WriteFile("/tmp/sriovdp/test_config", []byte(`{
"resourceList": [{
"resourceName": "wrong_config",
"selectors": {
"isRdma": true,
"vdpaType": "virtio",
"vendors": ["8086"],
"devices": ["154c", "10ed"],
"drivers": ["i40evf", "ixgbevf"]
}
}]
}`), 0644)
if err != nil {
panic(err)
}
_ = rm.readConfig()

})
It("should return false", func() {
defer fs.Use()()
Expect(rm.validConfigs()).To(Equal(false))
})
})
Describe("managing resources servers", func() {
Describe("initializing servers", func() {
Context("when initializing server fails", func() {
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ This page contains supplimentary documention that users may find useful for vari
* [Running RDMA application in Kubernetes](rdma/)
* [SR-IOV Network Device Plugin with DDP](ddp/)
* [Using node specific config file for running device plugin DaemonSet](config-file)
* [Using vDPA devices in Kubernetes](vdpa/)
71 changes: 71 additions & 0 deletions docs/vdpa/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Using vDPA devices in Kubernetes
adrianchiris marked this conversation as resolved.
Show resolved Hide resolved
## Introduction to vDPA
vDPA (Virtio DataPath Acceleration) is a technology that enables the acceleration
of virtIO devices while allowing the implementations of such devices
(e.g: NIC vendors) to use their own control plane.

The consumers of the virtIO devices (VMs or containers) interact with the devices
using the standard virtIO datapath and virtio-compatible control paths (virtIO, vhost).
While the data-plane is mapped directly to the accelerator device, the control-plane
gets translated by the vDPA kernel framework.

The vDPA kernel framework is composed of the vDPA bus (/sys/bus/vdpa), vDPA devices
(/sys/bus/vdpa/devices) and vDPA drivers (/sys/bus/vdpa/drivers).
Currently, two vDPA drivers are implemented:
* virtio_vdpa: Exposes the device as a virtio-net netdev
* vhost_vdpa: Exposes the device as a vhost-vdpa device. This device uses an extension
of the vhost-net protocol to allow userspace applications access the rings directly

amorenoz marked this conversation as resolved.
Show resolved Hide resolved
For more information about the vDPA framework, read the article on
[LWN.net](https://lwn.net/Articles/816063/) or the blog series written by one of the
main authors ([part 1](https://www.redhat.com/en/blog/vdpa-kernel-framework-part-1-vdpa-bus-abstracting-hardware),
[part 2](https://www.redhat.com/en/blog/vdpa-kernel-framework-part-2-vdpa-bus-drivers-kernel-subsystem-interactions),
[part3](https://www.redhat.com/en/blog/vdpa-kernel-framework-part-3-usage-vms-and-containers))

## vDPA Management
Currently, the management of vDPA devices is performed using the sysfs interface exposed
by the vDPA Framework. However, in order to decouple the management of vDPA devices from
the SR-IOV Device Plugin functionality, this low-level management is done in an external
library called [go-vdpa](https://github.com/k8snetworkplumbingwg/govdpa).

In the context of the SR-IOV Device Plugin and the SR-IOV CNI, the current plan is to
support only 1:1 mappings between SR-IOV VFs and vDPA devices despite the fact that
the vDPA Framework might support 1:N mappings.

Note that vDPA and RDMA are mutually exclusive modes.

## Tested NICs:
* Mellanox ConnectX®-6 DX

## Prerequisites
* Linux Kernel >= 5.12
* iproute >= 5.14

## vDPA device creation
Insert the vDPA kernel modules if not present:

$ modprobe vdpa
$ modprobe virtio-vdpa
$ modprobe vhost-vdpa

Create a vDPA device using the `vdpa` management tool integrated into iproute2, e.g:

$ vdpa mgmtdev show
pci/0000:65:00.2:
supported_classes net
$ vdpa dev add name vdpa2 mgmtdev pci/0000:65:00.2
$ vdpa dev list
vdpa2: type network mgmtdev pci/0000:65:00.2 vendor_id 5555 max_vqs 16 max_vq_size 256

## Bind the desired vDPA driver
The vDPA bus works similar to the pci bus. To unbind a driver from a device, run:

echo ${DEV_NAME} > /sys/bus/vdpa/devices/${DEV_NAME}/driver/unbind

To bind a driver to a device, run:

echo ${DEV_NAME} > /sys/bus/vdpa/drivers/${DRIVER_NAME}/bind

## Configure the SR-IOV Device Plugin
See the sample [configMap](configMap.yaml) for an example of how to configure a vDPA device.

30 changes: 30 additions & 0 deletions docs/vdpa/configMap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: sriovdp-config
namespace: kube-system
data:
config.json: |
{
"resourceList": [{
{
"resourceName": "vdpa_mlx_virtio",
"selectors": {
"vendors": ["15b3"],
"devices": ["101e"],
"drivers": ["mlx5_core"],
"vdpaType": "virtio"
}
},
{
"resourceName": "vdpa_mlx_vhost",
"selectors": {
"vendors": ["15b3"],
"devices": ["101e"],
"drivers": ["mlx5_core"],
"vdpaType": "vhost"
}
}
]
}

6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ 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/network-attachment-definition-client v1.1.1-0.20201119153432-9d213757d22d
github.com/onsi/ginkgo v1.12.0
github.com/onsi/gomega v1.9.0
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.0
github.com/vishvananda/netlink v1.1.1-0.20211101163509-b10eb8fe5cf6
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d // indirect
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e // indirect
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/grpc v1.28.1
k8s.io/kubelet v0.18.1
)
Expand Down
18 changes: 13 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/containernetworking/cni v0.8.1 h1:7zpDnQ3T3s4ucOuJ/ZCLrYBxzkg0AELFfII3Epo9TmI=
github.com/containernetworking/cni v0.8.1/go.mod h1:LGwApLUm2FpoOfxTDEeq8T9ipbpZ61X79hmU3w8FmsY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -106,6 +108,8 @@ github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCV
github.com/json-iterator/go v1.1.8 h1:QiWkFLKq0T7mpzwOTu6BzNDbfTE8OLrYhVKYMLF46Ok=
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
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 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 Expand Up @@ -150,6 +154,8 @@ github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZ
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/afero v1.4.1 h1:asw9sl74539yqavKaglDM5hFpdJVK0Y5Dr/JOgQ89nQ=
github.com/spf13/afero v1.4.1/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
Expand All @@ -165,6 +171,7 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
github.com/vishvananda/netlink v1.1.1-0.20210518155637-4cb3795f2ccb/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho=
github.com/vishvananda/netlink v1.1.1-0.20211101163509-b10eb8fe5cf6 h1:167a2omrzz+nN9Of6lN/0yOB9itzw+IOioRThNZ30jA=
Expand Down Expand Up @@ -204,8 +211,8 @@ golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d h1:20cMwl2fHAzkJMEA+8J4JgqBQcQGzbisXo31MIeenXI=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0=
Expand All @@ -232,16 +239,17 @@ golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
9 changes: 9 additions & 0 deletions pkg/accelerator/accelDeviceProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,12 @@ func (ap *accelDeviceProvider) GetFilteredDevices(devices []types.PciDevice, rc

return newDeviceList, nil
}

func (ap *accelDeviceProvider) ValidConfig(rc *types.ResourceConfig) bool {
_, ok := rc.SelectorObj.(*types.AccelDeviceSelectors)
if !ok {
glog.Errorf("unable to convert SelectorObj to AccelDeviceSelectors")
return false
}
return true
}
4 changes: 4 additions & 0 deletions pkg/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ func (rf *resourceFactory) GetRdmaSpec(pciAddrs string) types.RdmaSpec {
return netdevice.NewRdmaSpec(pciAddrs)
}

func (rf *resourceFactory) GetVdpaDevice(pciAddr string) types.VdpaDevice {
return netdevice.GetVdpaDevice(pciAddr)
}

// GetDeviceProvider returns an instance of DeviceProvider based on DeviceType
func (rf *resourceFactory) GetDeviceProvider(dt types.DeviceType) types.DeviceProvider {
switch dt {
Expand Down
29 changes: 29 additions & 0 deletions pkg/netdevice/netDeviceProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,38 @@ func (np *netDeviceProvider) GetFilteredDevices(devices []types.PciDevice, rc *t
filteredDevice = rdmaDevices
}

// filter for vDPA-capable devices
if nf.VdpaType != "" {
adrianchiris marked this conversation as resolved.
Show resolved Hide resolved
vdpaDevices := make([]types.PciDevice, 0)
for _, dev := range filteredDevice {
vdpaDev := dev.(types.PciNetDevice).GetVdpaDevice()
if vdpaDev == nil {
continue
}
if vType := vdpaDev.GetType(); vType != types.VdpaInvalidType && vType == nf.VdpaType {
vdpaDevices = append(vdpaDevices, dev)
}
}
filteredDevice = vdpaDevices
}

// convert to []PciNetDevice to []PciDevice
newDeviceList := make([]types.PciDevice, len(filteredDevice))
copy(newDeviceList, filteredDevice)

return newDeviceList, nil
}

// ValidConfig performs validation of NetDeviceSelectors
func (np *netDeviceProvider) ValidConfig(rc *types.ResourceConfig) bool {
nf, ok := rc.SelectorObj.(*types.NetDeviceSelectors)
if !ok {
glog.Errorf("unable to convert SelectorObj to NetDeviceSelectors")
return false
}
if nf.IsRdma && nf.VdpaType != "" {
glog.Errorf("invalid config: VdpaType and IsRdma are mutually exclusive options")
return false
}
return true
}
Loading