Skip to content

Commit

Permalink
virt-launcher, sriov: Use 'network-info' annot for network-pci mapping
Browse files Browse the repository at this point in the history
The 'network-info' annotation consist the mapping between network logical name
and underlying device PCI address, and mounted to SR-IOV VMs pods though
downward API volume.

Use 'network-info' annotation instead of the legacy 'network-pci-map' one

Signed-off-by: Or Mergi <ormergi@redhat.com>
  • Loading branch information
ormergi committed May 5, 2024
1 parent bba40f7 commit 703f725
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
5 changes: 1 addition & 4 deletions pkg/network/deviceinfo/sriov.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,4 @@

package deviceinfo

const (
SRIOVAliasPrefix = "sriov-"
NetworkPCIMapVolumePath = "network-pci-map"
)
const SRIOVAliasPrefix = "sriov-"
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func CreateHostDevices(vmi *v1.VirtualMachineInstance) ([]api.HostDevice, error)
if len(SRIOVInterfaces) == 0 {
return []api.HostDevice{}, nil
}
netStatusPath := path.Join(downwardapi.MountPath, deviceinfo.NetworkPCIMapVolumePath)
netStatusPath := path.Join(downwardapi.MountPath, downwardapi.NetworkInfoVolumePath)
pciAddressPoolWithNetworkStatus, err := newPCIAddressPoolWithNetworkStatusFromFile(netStatusPath)
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,29 @@ package sriov
import (
"encoding/json"
"fmt"

"kubevirt.io/kubevirt/pkg/network/downwardapi"
)

type PCIAddressWithNetworkStatusPool struct {
networkPCIMap map[string]string
}

// NewPCIAddressPoolWithNetworkStatus creates a PCI address pool based on the networkPciMapPath volume
func NewPCIAddressPoolWithNetworkStatus(networkPCIMapBytes []byte) (*PCIAddressWithNetworkStatusPool, error) {
func NewPCIAddressPoolWithNetworkStatus(networkInfoBytes []byte) (*PCIAddressWithNetworkStatusPool, error) {
pool := &PCIAddressWithNetworkStatusPool{}

var networkPciMap map[string]string
err := json.Unmarshal(networkPCIMapBytes, &networkPciMap)
var networkInfo downwardapi.NetworkInfo
err := json.Unmarshal(networkInfoBytes, &networkInfo)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal network-pci map %w", err)
return nil, fmt.Errorf("failed to unmarshal network-info annotation: %w", err)
}

networkPciMap := map[string]string{}
for _, iface := range networkInfo.Interfaces {
if iface.DeviceInfo != nil && iface.DeviceInfo.Pci != nil && iface.DeviceInfo.Pci.PciAddress != "" {
networkPciMap[iface.Network] = iface.DeviceInfo.Pci.PciAddress
}
}

pool.networkPCIMap = networkPciMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,17 @@ import (
var _ = Describe("SRIOV PCI address pool with network-pci-map", func() {
var emptyFileBytes []byte
emptyNetworkPCIMapBytes := []byte("{}")
networkPCIMapWithThreeNetworks := []byte(
`{"network1":"0000:04:02.5","network2":"0000:04:02.7","network3":"0000:04:02.8"}`)

networkPCIMapWithThreeNetworks := []byte(`{
"interfaces": [
{"network":"pod"},
{"network":"network1", "deviceInfo":{
"type":"pci","version":"1.0.0","pci":{"pci-address":"0000:04:02.5"}}},
{"network":"network2", "deviceInfo":{
"type":"pci","version":"1.0.0","pci":{"pci-address":"0000:04:02.7"}}},
{"network":"network3", "deviceInfo":{
"type":"pci","version":"1.0.0","pci":{"pci-address":"0000:04:02.8"}}}
]
}`)
It("should fail to create the pool when network-pci-map file is empty", func() {
pool, err := sriovhostdev.NewPCIAddressPoolWithNetworkStatus(emptyFileBytes)

Expand Down

0 comments on commit 703f725

Please sign in to comment.