Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
network: Use PciPath type through network handling
Browse files Browse the repository at this point in the history
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.

fixes #3002

Signed-off-by: David Gibson <[email protected]>
  • Loading branch information
dgibson committed Oct 27, 2020
1 parent bfbfab3 commit 3e58971
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 75 deletions.
15 changes: 8 additions & 7 deletions virtcontainers/bridgedmacvlan_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import (

"github.com/containernetworking/plugins/pkg/ns"
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
)

// BridgedMacvlanEndpoint represents a macvlan endpoint that is bridged to the VM
type BridgedMacvlanEndpoint struct {
NetPair NetworkInterfacePair
EndpointProperties NetworkInfo
EndpointType EndpointType
PCIAddr string
PCIPath vcTypes.PciPath
}

func createBridgedMacvlanNetworkEndpoint(idx int, ifName string, interworkingModel NetInterworkingModel) (*BridgedMacvlanEndpoint, error) {
Expand Down Expand Up @@ -67,14 +68,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.
Expand Down
5 changes: 3 additions & 2 deletions virtcontainers/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"

persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
)

// Endpoint represents a physical or virtual network interface.
Expand All @@ -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
Expand Down
15 changes: 8 additions & 7 deletions virtcontainers/ipvlan_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import (

"github.com/containernetworking/plugins/pkg/ns"
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
)

// IPVlanEndpoint represents a ipvlan endpoint that is bridged to the VM
type IPVlanEndpoint struct {
NetPair NetworkInterfacePair
EndpointProperties NetworkInfo
EndpointType EndpointType
PCIAddr string
PCIPath vcTypes.PciPath
}

func createIPVlanNetworkEndpoint(idx int, ifName string) (*IPVlanEndpoint, error) {
Expand Down Expand Up @@ -70,14 +71,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.
Expand Down
8 changes: 6 additions & 2 deletions virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2300,7 +2300,7 @@ func (k *kataAgent) convertToKataAgentInterface(iface *vcTypes.Interface) *aType
Mtu: iface.Mtu,
RawFlags: iface.RawFlags,
HwAddr: iface.HwAddr,
PciPath: iface.PciAddr,
PciPath: iface.PciPath.String(),
}
}

Expand All @@ -2311,13 +2311,17 @@ func (k *kataAgent) convertToInterfaces(aIfaces []*aTypes.Interface) ([]*vcTypes
continue
}

pcipath, err := vcTypes.PciPathFromString(aIface.PciPath)
if err != nil {
return nil, err
}
iface := &vcTypes.Interface{
Device: aIface.Device,
Name: aIface.Name,
IPAddresses: k.convertToIPAddresses(aIface.IPAddresses),
Mtu: aIface.Mtu,
HwAddr: aIface.HwAddr,
PciAddr: aIface.PciPath,
PciPath: pcipath,
}

ifaces = append(ifaces, iface)
Expand Down
19 changes: 10 additions & 9 deletions virtcontainers/macvtap_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"

persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
)

// MacvtapEndpoint represents a macvtap endpoint
Expand All @@ -18,7 +19,7 @@ type MacvtapEndpoint struct {
EndpointType EndpointType
VMFds []*os.File
VhostFds []*os.File
PCIAddr string
PCIPath vcTypes.PciPath
}

func createMacvtapNetworkEndpoint(netInfo NetworkInfo) (*MacvtapEndpoint, error) {
Expand Down Expand Up @@ -91,14 +92,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.
Expand All @@ -111,14 +112,14 @@ func (endpoint *MacvtapEndpoint) save() persistapi.NetworkEndpoint {
Type: string(endpoint.Type()),

Macvtap: &persistapi.MacvtapEndpoint{
PCIAddr: endpoint.PCIAddr,
PCIPath: endpoint.PCIPath,
},
}
}
func (endpoint *MacvtapEndpoint) load(s persistapi.NetworkEndpoint) {
endpoint.EndpointType = MacvtapEndpointType

if s.Macvtap != nil {
endpoint.PCIAddr = s.Macvtap.PCIAddr
endpoint.PCIPath = s.Macvtap.PCIPath
}
}
2 changes: 1 addition & 1 deletion virtcontainers/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ func generateVCNetworkStructures(networkNS NetworkNamespace) ([]*vcTypes.Interfa
Mtu: uint64(endpoint.Properties().Iface.MTU),
RawFlags: noarp,
HwAddr: endpoint.HardwareAddr(),
PciAddr: endpoint.PciAddr(),
PciPath: endpoint.PciPath(),
}

ifaces = append(ifaces, &ifc)
Expand Down
5 changes: 3 additions & 2 deletions virtcontainers/persist/api/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package persistapi

import (
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/vishvananda/netlink"
)

Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
15 changes: 8 additions & 7 deletions virtcontainers/physical_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/kata-containers/runtime/virtcontainers/device/drivers"
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
"github.com/kata-containers/runtime/virtcontainers/pkg/cgroups"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/safchain/ethtool"
)

Expand All @@ -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.
Expand All @@ -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.
Expand Down
8 changes: 3 additions & 5 deletions virtcontainers/pkg/types/types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Intel Corporation.
// Copyright (c) 2018 Intel Corporation.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -20,10 +20,8 @@ type Interface struct {
Mtu uint64
RawFlags uint32
HwAddr string
// pciAddr is the PCI address in the format "bridgeAddr/deviceAddr".
// Here, bridgeAddr is the address at which the bridge is attached on the root bus,
// while deviceAddr is the address at which the network device is attached on the bridge.
PciAddr string
// PCI path for the interface
PciPath PciPath
// LinkType defines the type of interface described by this structure.
// The expected values are the one that are defined by the netlink
// library, regarding each type of link. Here is a non exhaustive
Expand Down
13 changes: 11 additions & 2 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (

"github.com/kata-containers/runtime/virtcontainers/device/config"
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/pkg/uuid"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/kata-containers/runtime/virtcontainers/utils"
Expand Down Expand Up @@ -1420,8 +1421,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()
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ func (s *Sandbox) AddInterface(inf *vcTypes.Interface) (*vcTypes.Interface, erro
}

// Add network for vm
inf.PciAddr = endpoint.PciAddr()
inf.PciPath = endpoint.PciPath()
return s.agent.updateInterface(inf)
}

Expand Down
15 changes: 8 additions & 7 deletions virtcontainers/tap_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/vishvananda/netlink"

persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/pkg/uuid"
)

Expand All @@ -20,7 +21,7 @@ type TapEndpoint struct {
TapInterface TapInterface
EndpointProperties NetworkInfo
EndpointType EndpointType
PCIAddr string
PCIPath vcTypes.PciPath
}

// Properties returns the properties of the tap interface.
Expand All @@ -43,14 +44,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.
Expand Down
15 changes: 8 additions & 7 deletions virtcontainers/tuntap_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/vishvananda/netlink"

persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
)

// TuntapEndpoint represents just a tap endpoint
Expand All @@ -22,7 +23,7 @@ type TuntapEndpoint struct {
TuntapInterface TuntapInterface
EndpointProperties NetworkInfo
EndpointType EndpointType
PCIAddr string
PCIPath vcTypes.PciPath
}

// Properties returns the properties of the tap interface.
Expand All @@ -45,14 +46,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.
Expand Down
Loading

0 comments on commit 3e58971

Please sign in to comment.