diff --git a/src/runtime/virtcontainers/bridgedmacvlan_endpoint.go b/src/runtime/virtcontainers/bridgedmacvlan_endpoint.go index b4c3a09ec9..f54b769007 100644 --- a/src/runtime/virtcontainers/bridgedmacvlan_endpoint.go +++ b/src/runtime/virtcontainers/bridgedmacvlan_endpoint.go @@ -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. diff --git a/src/runtime/virtcontainers/endpoint.go b/src/runtime/virtcontainers/endpoint.go index 1f422dad69..700f9157df 100644 --- a/src/runtime/virtcontainers/endpoint.go +++ b/src/runtime/virtcontainers/endpoint.go @@ -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 diff --git a/src/runtime/virtcontainers/ipvlan_endpoint.go b/src/runtime/virtcontainers/ipvlan_endpoint.go index 38e9121c31..8c6dba673e 100644 --- a/src/runtime/virtcontainers/ipvlan_endpoint.go +++ b/src/runtime/virtcontainers/ipvlan_endpoint.go @@ -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. diff --git a/src/runtime/virtcontainers/macvtap_endpoint.go b/src/runtime/virtcontainers/macvtap_endpoint.go index 3f82869766..556d4ad5be 100644 --- a/src/runtime/virtcontainers/macvtap_endpoint.go +++ b/src/runtime/virtcontainers/macvtap_endpoint.go @@ -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 } } diff --git a/src/runtime/virtcontainers/network.go b/src/runtime/virtcontainers/network.go index f848cdb92f..5553c97080 100644 --- a/src/runtime/virtcontainers/network.go +++ b/src/runtime/virtcontainers/network.go @@ -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) diff --git a/src/runtime/virtcontainers/persist/api/network.go b/src/runtime/virtcontainers/persist/api/network.go index 69610c6706..824f884539 100644 --- a/src/runtime/virtcontainers/persist/api/network.go +++ b/src/runtime/virtcontainers/persist/api/network.go @@ -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 diff --git a/src/runtime/virtcontainers/physical_endpoint.go b/src/runtime/virtcontainers/physical_endpoint.go index e778102a5b..af29aeefe1 100644 --- a/src/runtime/virtcontainers/physical_endpoint.go +++ b/src/runtime/virtcontainers/physical_endpoint.go @@ -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. diff --git a/src/runtime/virtcontainers/qemu.go b/src/runtime/virtcontainers/qemu.go index f2683f9a73..39135ae2e8 100644 --- a/src/runtime/virtcontainers/qemu.go +++ b/src/runtime/virtcontainers/qemu.go @@ -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() diff --git a/src/runtime/virtcontainers/sandbox.go b/src/runtime/virtcontainers/sandbox.go index 4d9d951556..55577d19ef 100644 --- a/src/runtime/virtcontainers/sandbox.go +++ b/src/runtime/virtcontainers/sandbox.go @@ -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) } diff --git a/src/runtime/virtcontainers/tap_endpoint.go b/src/runtime/virtcontainers/tap_endpoint.go index 583ffe9cc2..f9bb63640f 100644 --- a/src/runtime/virtcontainers/tap_endpoint.go +++ b/src/runtime/virtcontainers/tap_endpoint.go @@ -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. diff --git a/src/runtime/virtcontainers/tuntap_endpoint.go b/src/runtime/virtcontainers/tuntap_endpoint.go index 7eef86ea87..9ca7344705 100644 --- a/src/runtime/virtcontainers/tuntap_endpoint.go +++ b/src/runtime/virtcontainers/tuntap_endpoint.go @@ -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. diff --git a/src/runtime/virtcontainers/veth_endpoint.go b/src/runtime/virtcontainers/veth_endpoint.go index 371005798a..9339b48f83 100644 --- a/src/runtime/virtcontainers/veth_endpoint.go +++ b/src/runtime/virtcontainers/veth_endpoint.go @@ -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. diff --git a/src/runtime/virtcontainers/vhostuser_endpoint.go b/src/runtime/virtcontainers/vhostuser_endpoint.go index 642f06fb1d..c4ec45798c 100644 --- a/src/runtime/virtcontainers/vhostuser_endpoint.go +++ b/src/runtime/virtcontainers/vhostuser_endpoint.go @@ -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 } }