mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-28 19:54:35 +00:00
runtime/network: Use PciPath type through network handling
The "PCI address" returned by Endpoint::PciPath() isn't actually a PCI
address (DDDD:BB:DD.F), but rather a PCI path. Rename and use the
PciPath type to clean this up and the various parts of the network
code connected to it.
Forward port of
3e589713cf
fixes #1040
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
87c5823c4b
commit
32b40f5fe4
@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/containernetworking/plugins/pkg/ns"
|
||||
persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
)
|
||||
|
||||
// BridgedMacvlanEndpoint represents a macvlan endpoint that is bridged to the VM
|
||||
@ -17,7 +18,7 @@ type BridgedMacvlanEndpoint struct {
|
||||
NetPair NetworkInterfacePair
|
||||
EndpointProperties NetworkInfo
|
||||
EndpointType EndpointType
|
||||
PCIAddr string
|
||||
PCIPath vcTypes.PciPath
|
||||
RxRateLimiter bool
|
||||
TxRateLimiter bool
|
||||
}
|
||||
@ -69,14 +70,14 @@ func (endpoint *BridgedMacvlanEndpoint) SetProperties(properties NetworkInfo) {
|
||||
endpoint.EndpointProperties = properties
|
||||
}
|
||||
|
||||
// PciAddr returns the PCI address of the endpoint.
|
||||
func (endpoint *BridgedMacvlanEndpoint) PciAddr() string {
|
||||
return endpoint.PCIAddr
|
||||
// PciPath returns the PCI path of the endpoint.
|
||||
func (endpoint *BridgedMacvlanEndpoint) PciPath() vcTypes.PciPath {
|
||||
return endpoint.PCIPath
|
||||
}
|
||||
|
||||
// SetPciAddr sets the PCI address of the endpoint.
|
||||
func (endpoint *BridgedMacvlanEndpoint) SetPciAddr(pciAddr string) {
|
||||
endpoint.PCIAddr = pciAddr
|
||||
// SetPciPath sets the PCI path of the endpoint.
|
||||
func (endpoint *BridgedMacvlanEndpoint) SetPciPath(pciPath vcTypes.PciPath) {
|
||||
endpoint.PCIPath = pciPath
|
||||
}
|
||||
|
||||
// NetworkPair returns the network pair of the endpoint.
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
)
|
||||
|
||||
// Endpoint represents a physical or virtual network interface.
|
||||
@ -17,11 +18,11 @@ type Endpoint interface {
|
||||
Name() string
|
||||
HardwareAddr() string
|
||||
Type() EndpointType
|
||||
PciAddr() string
|
||||
PciPath() vcTypes.PciPath
|
||||
NetworkPair() *NetworkInterfacePair
|
||||
|
||||
SetProperties(NetworkInfo)
|
||||
SetPciAddr(string)
|
||||
SetPciPath(vcTypes.PciPath)
|
||||
Attach(*Sandbox) error
|
||||
Detach(netNsCreated bool, netNsPath string) error
|
||||
HotAttach(h hypervisor) error
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/containernetworking/plugins/pkg/ns"
|
||||
persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
)
|
||||
|
||||
// IPVlanEndpoint represents a ipvlan endpoint that is bridged to the VM
|
||||
@ -17,7 +18,7 @@ type IPVlanEndpoint struct {
|
||||
NetPair NetworkInterfacePair
|
||||
EndpointProperties NetworkInfo
|
||||
EndpointType EndpointType
|
||||
PCIAddr string
|
||||
PCIPath vcTypes.PciPath
|
||||
RxRateLimiter bool
|
||||
TxRateLimiter bool
|
||||
}
|
||||
@ -72,14 +73,14 @@ func (endpoint *IPVlanEndpoint) SetProperties(properties NetworkInfo) {
|
||||
endpoint.EndpointProperties = properties
|
||||
}
|
||||
|
||||
// PciAddr returns the PCI address of the endpoint.
|
||||
func (endpoint *IPVlanEndpoint) PciAddr() string {
|
||||
return endpoint.PCIAddr
|
||||
// PciPath returns the PCI path of the endpoint.
|
||||
func (endpoint *IPVlanEndpoint) PciPath() vcTypes.PciPath {
|
||||
return endpoint.PCIPath
|
||||
}
|
||||
|
||||
// SetPciAddr sets the PCI address of the endpoint.
|
||||
func (endpoint *IPVlanEndpoint) SetPciAddr(pciAddr string) {
|
||||
endpoint.PCIAddr = pciAddr
|
||||
// SetPciPath sets the PCI path of the endpoint.
|
||||
func (endpoint *IPVlanEndpoint) SetPciPath(pciPath vcTypes.PciPath) {
|
||||
endpoint.PCIPath = pciPath
|
||||
}
|
||||
|
||||
// NetworkPair returns the network pair of the endpoint.
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"os"
|
||||
|
||||
persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
)
|
||||
|
||||
// MacvtapEndpoint represents a macvtap endpoint
|
||||
@ -18,7 +19,7 @@ type MacvtapEndpoint struct {
|
||||
EndpointType EndpointType
|
||||
VMFds []*os.File
|
||||
VhostFds []*os.File
|
||||
PCIAddr string
|
||||
PCIPath vcTypes.PciPath
|
||||
RxRateLimiter bool
|
||||
TxRateLimiter bool
|
||||
}
|
||||
@ -93,14 +94,14 @@ func (endpoint *MacvtapEndpoint) HotDetach(h hypervisor, netNsCreated bool, netN
|
||||
return fmt.Errorf("MacvtapEndpoint does not support Hot detach")
|
||||
}
|
||||
|
||||
// PciAddr returns the PCI address of the endpoint.
|
||||
func (endpoint *MacvtapEndpoint) PciAddr() string {
|
||||
return endpoint.PCIAddr
|
||||
// PciPath returns the PCI path of the endpoint.
|
||||
func (endpoint *MacvtapEndpoint) PciPath() vcTypes.PciPath {
|
||||
return endpoint.PCIPath
|
||||
}
|
||||
|
||||
// SetPciAddr sets the PCI address of the endpoint.
|
||||
func (endpoint *MacvtapEndpoint) SetPciAddr(pciAddr string) {
|
||||
endpoint.PCIAddr = pciAddr
|
||||
// SetPciPath sets the PCI path of the endpoint.
|
||||
func (endpoint *MacvtapEndpoint) SetPciPath(pciPath vcTypes.PciPath) {
|
||||
endpoint.PCIPath = pciPath
|
||||
}
|
||||
|
||||
// NetworkPair returns the network pair of the endpoint.
|
||||
@ -113,7 +114,7 @@ func (endpoint *MacvtapEndpoint) save() persistapi.NetworkEndpoint {
|
||||
Type: string(endpoint.Type()),
|
||||
|
||||
Macvtap: &persistapi.MacvtapEndpoint{
|
||||
PCIAddr: endpoint.PCIAddr,
|
||||
PCIPath: endpoint.PCIPath,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -121,7 +122,7 @@ func (endpoint *MacvtapEndpoint) load(s persistapi.NetworkEndpoint) {
|
||||
endpoint.EndpointType = MacvtapEndpointType
|
||||
|
||||
if s.Macvtap != nil {
|
||||
endpoint.PCIAddr = s.Macvtap.PCIAddr
|
||||
endpoint.PCIPath = s.Macvtap.PCIPath
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -984,7 +984,7 @@ func generateVCNetworkStructures(networkNS NetworkNamespace) ([]*pbTypes.Interfa
|
||||
Mtu: uint64(endpoint.Properties().Iface.MTU),
|
||||
RawFlags: noarp,
|
||||
HwAddr: endpoint.HardwareAddr(),
|
||||
PciPath: endpoint.PciAddr(),
|
||||
PciPath: endpoint.PciPath().String(),
|
||||
}
|
||||
|
||||
ifaces = append(ifaces, &ifc)
|
||||
|
@ -7,6 +7,7 @@
|
||||
package persistapi
|
||||
|
||||
import (
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
|
||||
@ -48,7 +49,7 @@ type PhysicalEndpoint struct {
|
||||
type MacvtapEndpoint struct {
|
||||
// This is for showing information.
|
||||
// Remove this field won't impact anything.
|
||||
PCIAddr string
|
||||
PCIPath vcTypes.PciPath
|
||||
}
|
||||
|
||||
type TapEndpoint struct {
|
||||
@ -75,7 +76,7 @@ type VhostUserEndpoint struct {
|
||||
// This is for showing information.
|
||||
// Remove these fields won't impact anything.
|
||||
IfaceName string
|
||||
PCIAddr string
|
||||
PCIPath vcTypes.PciPath
|
||||
}
|
||||
|
||||
// NetworkEndpoint contains network interface information
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/cgroups"
|
||||
"github.com/safchain/ethtool"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
)
|
||||
|
||||
// PhysicalEndpoint gathers a physical network interface and its properties
|
||||
@ -28,7 +29,7 @@ type PhysicalEndpoint struct {
|
||||
BDF string
|
||||
Driver string
|
||||
VendorDeviceID string
|
||||
PCIAddr string
|
||||
PCIPath vcTypes.PciPath
|
||||
}
|
||||
|
||||
// Properties returns the properties of the physical interface.
|
||||
@ -51,14 +52,14 @@ func (endpoint *PhysicalEndpoint) Type() EndpointType {
|
||||
return endpoint.EndpointType
|
||||
}
|
||||
|
||||
// PciAddr returns the PCI address of the endpoint.
|
||||
func (endpoint *PhysicalEndpoint) PciAddr() string {
|
||||
return endpoint.PCIAddr
|
||||
// PciPath returns the PCI path of the endpoint.
|
||||
func (endpoint *PhysicalEndpoint) PciPath() vcTypes.PciPath {
|
||||
return endpoint.PCIPath
|
||||
}
|
||||
|
||||
// SetPciAddr sets the PCI address of the endpoint.
|
||||
func (endpoint *PhysicalEndpoint) SetPciAddr(pciAddr string) {
|
||||
endpoint.PCIAddr = pciAddr
|
||||
// SetPciPath sets the PCI path of the endpoint.
|
||||
func (endpoint *PhysicalEndpoint) SetPciPath(pciPath vcTypes.PciPath) {
|
||||
endpoint.PCIPath = pciPath
|
||||
}
|
||||
|
||||
// SetProperties sets the properties of the physical endpoint.
|
||||
|
@ -39,6 +39,7 @@ import (
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/uuid"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
)
|
||||
|
||||
// romFile is the file name of the ROM that can be used for virtio-pci devices.
|
||||
@ -1546,8 +1547,16 @@ func (q *qemu) hotplugNetDevice(endpoint Endpoint, op operation) (err error) {
|
||||
}
|
||||
}()
|
||||
|
||||
pciAddr := fmt.Sprintf("%02x/%s", bridge.Addr, addr)
|
||||
endpoint.SetPciAddr(pciAddr)
|
||||
bridgeSlot, err := vcTypes.PciSlotFromInt(bridge.Addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
devSlot, err := vcTypes.PciSlotFromString(addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pciPath, err := vcTypes.PciPathFromSlots(bridgeSlot, devSlot)
|
||||
endpoint.SetPciPath(pciPath)
|
||||
|
||||
var machine govmmQemu.Machine
|
||||
machine, err = q.getQemuMachine()
|
||||
|
@ -850,7 +850,7 @@ func (s *Sandbox) AddInterface(inf *pbTypes.Interface) (*pbTypes.Interface, erro
|
||||
}
|
||||
|
||||
// Add network for vm
|
||||
inf.PciPath = endpoint.PciAddr()
|
||||
inf.PciPath = endpoint.PciPath().String()
|
||||
return s.agent.updateInterface(inf)
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
|
||||
persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/uuid"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
)
|
||||
|
||||
// TapEndpoint represents just a tap endpoint
|
||||
@ -20,7 +21,7 @@ type TapEndpoint struct {
|
||||
TapInterface TapInterface
|
||||
EndpointProperties NetworkInfo
|
||||
EndpointType EndpointType
|
||||
PCIAddr string
|
||||
PCIPath vcTypes.PciPath
|
||||
RxRateLimiter bool
|
||||
TxRateLimiter bool
|
||||
}
|
||||
@ -45,14 +46,14 @@ func (endpoint *TapEndpoint) Type() EndpointType {
|
||||
return endpoint.EndpointType
|
||||
}
|
||||
|
||||
// PciAddr returns the PCI address of the endpoint.
|
||||
func (endpoint *TapEndpoint) PciAddr() string {
|
||||
return endpoint.PCIAddr
|
||||
// PciPath returns the PCI path of the endpoint.
|
||||
func (endpoint *TapEndpoint) PciPath() vcTypes.PciPath {
|
||||
return endpoint.PCIPath
|
||||
}
|
||||
|
||||
// SetPciAddr sets the PCI address of the endpoint.
|
||||
func (endpoint *TapEndpoint) SetPciAddr(pciAddr string) {
|
||||
endpoint.PCIAddr = pciAddr
|
||||
// SetPciPath sets the PCI path of the endpoint.
|
||||
func (endpoint *TapEndpoint) SetPciPath(pciPath vcTypes.PciPath) {
|
||||
endpoint.PCIPath = pciPath
|
||||
}
|
||||
|
||||
// NetworkPair returns the network pair of the endpoint.
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"github.com/vishvananda/netlink"
|
||||
|
||||
persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
)
|
||||
|
||||
// TuntapEndpoint represents just a tap endpoint
|
||||
@ -22,7 +23,7 @@ type TuntapEndpoint struct {
|
||||
TuntapInterface TuntapInterface
|
||||
EndpointProperties NetworkInfo
|
||||
EndpointType EndpointType
|
||||
PCIAddr string
|
||||
PCIPath vcTypes.PciPath
|
||||
RxRateLimiter bool
|
||||
TxRateLimiter bool
|
||||
}
|
||||
@ -47,14 +48,14 @@ func (endpoint *TuntapEndpoint) Type() EndpointType {
|
||||
return endpoint.EndpointType
|
||||
}
|
||||
|
||||
// PciAddr returns the PCI address of the endpoint.
|
||||
func (endpoint *TuntapEndpoint) PciAddr() string {
|
||||
return endpoint.PCIAddr
|
||||
// PciPath returns the PCI path of the endpoint.
|
||||
func (endpoint *TuntapEndpoint) PciPath() vcTypes.PciPath {
|
||||
return endpoint.PCIPath
|
||||
}
|
||||
|
||||
// SetPciAddr sets the PCI address of the endpoint.
|
||||
func (endpoint *TuntapEndpoint) SetPciAddr(pciAddr string) {
|
||||
endpoint.PCIAddr = pciAddr
|
||||
// SetPciPath sets the PCI path of the endpoint.
|
||||
func (endpoint *TuntapEndpoint) SetPciPath(pciPath vcTypes.PciPath) {
|
||||
endpoint.PCIPath = pciPath
|
||||
}
|
||||
|
||||
// NetworkPair returns the network pair of the endpoint.
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/containernetworking/plugins/pkg/ns"
|
||||
persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
)
|
||||
|
||||
// VethEndpoint gathers a network pair and its properties.
|
||||
@ -17,7 +18,7 @@ type VethEndpoint struct {
|
||||
NetPair NetworkInterfacePair
|
||||
EndpointProperties NetworkInfo
|
||||
EndpointType EndpointType
|
||||
PCIAddr string
|
||||
PCIPath vcTypes.PciPath
|
||||
RxRateLimiter bool
|
||||
TxRateLimiter bool
|
||||
}
|
||||
@ -67,14 +68,14 @@ func (endpoint *VethEndpoint) Type() EndpointType {
|
||||
return endpoint.EndpointType
|
||||
}
|
||||
|
||||
// PciAddr returns the PCI address of the endpoint.
|
||||
func (endpoint *VethEndpoint) PciAddr() string {
|
||||
return endpoint.PCIAddr
|
||||
// PciPath returns the PCI path of the endpoint.
|
||||
func (endpoint *VethEndpoint) PciPath() vcTypes.PciPath {
|
||||
return endpoint.PCIPath
|
||||
}
|
||||
|
||||
// SetPciAddr sets the PCI address of the endpoint.
|
||||
func (endpoint *VethEndpoint) SetPciAddr(pciAddr string) {
|
||||
endpoint.PCIAddr = pciAddr
|
||||
// SetPciPath sets the PCI path of the endpoint.
|
||||
func (endpoint *VethEndpoint) SetPciPath(pciPath vcTypes.PciPath) {
|
||||
endpoint.PCIPath = pciPath
|
||||
}
|
||||
|
||||
// NetworkPair returns the network pair of the endpoint.
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
|
||||
persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
)
|
||||
|
||||
// Long term, this should be made more configurable. For now matching path
|
||||
@ -30,7 +31,7 @@ type VhostUserEndpoint struct {
|
||||
IfaceName string
|
||||
EndpointProperties NetworkInfo
|
||||
EndpointType EndpointType
|
||||
PCIAddr string
|
||||
PCIPath vcTypes.PciPath
|
||||
}
|
||||
|
||||
// Properties returns the properties of the interface.
|
||||
@ -58,14 +59,14 @@ func (endpoint *VhostUserEndpoint) SetProperties(properties NetworkInfo) {
|
||||
endpoint.EndpointProperties = properties
|
||||
}
|
||||
|
||||
// PciAddr returns the PCI address of the endpoint.
|
||||
func (endpoint *VhostUserEndpoint) PciAddr() string {
|
||||
return endpoint.PCIAddr
|
||||
// PciPath returns the PCI path of the endpoint.
|
||||
func (endpoint *VhostUserEndpoint) PciPath() vcTypes.PciPath {
|
||||
return endpoint.PCIPath
|
||||
}
|
||||
|
||||
// SetPciAddr sets the PCI address of the endpoint.
|
||||
func (endpoint *VhostUserEndpoint) SetPciAddr(pciAddr string) {
|
||||
endpoint.PCIAddr = pciAddr
|
||||
// SetPciPath sets the PCI path of the endpoint.
|
||||
func (endpoint *VhostUserEndpoint) SetPciPath(pciPath vcTypes.PciPath) {
|
||||
endpoint.PCIPath = pciPath
|
||||
}
|
||||
|
||||
// NetworkPair returns the network pair of the endpoint.
|
||||
@ -156,7 +157,7 @@ func (endpoint *VhostUserEndpoint) save() persistapi.NetworkEndpoint {
|
||||
Type: string(endpoint.Type()),
|
||||
VhostUser: &persistapi.VhostUserEndpoint{
|
||||
IfaceName: endpoint.IfaceName,
|
||||
PCIAddr: endpoint.PCIAddr,
|
||||
PCIPath: endpoint.PCIPath,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -166,7 +167,7 @@ func (endpoint *VhostUserEndpoint) load(s persistapi.NetworkEndpoint) {
|
||||
|
||||
if s.VhostUser != nil {
|
||||
endpoint.IfaceName = s.VhostUser.IfaceName
|
||||
endpoint.PCIAddr = s.VhostUser.PCIAddr
|
||||
endpoint.PCIPath = s.VhostUser.PCIPath
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user