mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-04 11:06:21 +00:00
virtcontainers: network: Rename numCPUs to queues
The point of knowing the number of CPUs from the network perspective is to determine the number of queues that can be allocated to the network interface of the our virtual machine. Therefore, it's more logical to name it queues from a network.go perspective. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
2cb4bb9db7
commit
0bcd221fad
@ -396,7 +396,7 @@ func newNetwork(networkType NetworkModel) network {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createLink(netHandle *netlink.Handle, name string, expectedLink netlink.Link, numCPUs int) (netlink.Link, []*os.File, error) {
|
func createLink(netHandle *netlink.Handle, name string, expectedLink netlink.Link, queues int) (netlink.Link, []*os.File, error) {
|
||||||
var newLink netlink.Link
|
var newLink netlink.Link
|
||||||
var fds []*os.File
|
var fds []*os.File
|
||||||
|
|
||||||
@ -410,7 +410,7 @@ func createLink(netHandle *netlink.Handle, name string, expectedLink netlink.Lin
|
|||||||
newLink = &netlink.Tuntap{
|
newLink = &netlink.Tuntap{
|
||||||
LinkAttrs: netlink.LinkAttrs{Name: name},
|
LinkAttrs: netlink.LinkAttrs{Name: name},
|
||||||
Mode: netlink.TUNTAP_MODE_TAP,
|
Mode: netlink.TUNTAP_MODE_TAP,
|
||||||
Queues: numCPUs,
|
Queues: queues,
|
||||||
Flags: netlink.TUNTAP_MULTI_QUEUE_DEFAULTS | netlink.TUNTAP_VNET_HDR,
|
Flags: netlink.TUNTAP_MULTI_QUEUE_DEFAULTS | netlink.TUNTAP_VNET_HDR,
|
||||||
}
|
}
|
||||||
case (&netlink.Macvtap{}).Type():
|
case (&netlink.Macvtap{}).Type():
|
||||||
@ -505,7 +505,7 @@ func getLinkByName(netHandle *netlink.Handle, name string, expectedLink netlink.
|
|||||||
func xConnectVMNetwork(endpoint Endpoint, h hypervisor) error {
|
func xConnectVMNetwork(endpoint Endpoint, h hypervisor) error {
|
||||||
netPair := endpoint.NetworkPair()
|
netPair := endpoint.NetworkPair()
|
||||||
|
|
||||||
numCPUs := h.hypervisorConfig().NumVCPUs
|
queues := int(h.hypervisorConfig().NumVCPUs)
|
||||||
disableVhostNet := h.hypervisorConfig().DisableVhostNet
|
disableVhostNet := h.hypervisorConfig().DisableVhostNet
|
||||||
|
|
||||||
if netPair.NetInterworkingModel == NetXConnectDefaultModel {
|
if netPair.NetInterworkingModel == NetXConnectDefaultModel {
|
||||||
@ -514,11 +514,11 @@ func xConnectVMNetwork(endpoint Endpoint, h hypervisor) error {
|
|||||||
|
|
||||||
switch netPair.NetInterworkingModel {
|
switch netPair.NetInterworkingModel {
|
||||||
case NetXConnectBridgedModel:
|
case NetXConnectBridgedModel:
|
||||||
return bridgeNetworkPair(endpoint, numCPUs, disableVhostNet)
|
return bridgeNetworkPair(endpoint, queues, disableVhostNet)
|
||||||
case NetXConnectMacVtapModel:
|
case NetXConnectMacVtapModel:
|
||||||
return tapNetworkPair(endpoint, numCPUs, disableVhostNet)
|
return tapNetworkPair(endpoint, queues, disableVhostNet)
|
||||||
case NetXConnectTCFilterModel:
|
case NetXConnectTCFilterModel:
|
||||||
return setupTCFiltering(endpoint, numCPUs, disableVhostNet)
|
return setupTCFiltering(endpoint, queues, disableVhostNet)
|
||||||
case NetXConnectEnlightenedModel:
|
case NetXConnectEnlightenedModel:
|
||||||
return fmt.Errorf("Unsupported networking model")
|
return fmt.Errorf("Unsupported networking model")
|
||||||
default:
|
default:
|
||||||
@ -588,10 +588,10 @@ const linkRange = 0xFFFF // This will allow upto 2^16 containers
|
|||||||
const linkRetries = 128 // The numbers of time we try to find a non conflicting index
|
const linkRetries = 128 // The numbers of time we try to find a non conflicting index
|
||||||
const macvtapWorkaround = true
|
const macvtapWorkaround = true
|
||||||
|
|
||||||
func createMacVtap(netHandle *netlink.Handle, name string, link netlink.Link, numCPUs int) (taplink netlink.Link, err error) {
|
func createMacVtap(netHandle *netlink.Handle, name string, link netlink.Link, queues int) (taplink netlink.Link, err error) {
|
||||||
|
|
||||||
if !macvtapWorkaround {
|
if !macvtapWorkaround {
|
||||||
taplink, _, err = createLink(netHandle, name, link, numCPUs)
|
taplink, _, err = createLink(netHandle, name, link, queues)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -600,7 +600,7 @@ func createMacVtap(netHandle *netlink.Handle, name string, link netlink.Link, nu
|
|||||||
for i := 0; i < linkRetries; i++ {
|
for i := 0; i < linkRetries; i++ {
|
||||||
index := hostLinkOffset + (r.Int() & linkRange)
|
index := hostLinkOffset + (r.Int() & linkRange)
|
||||||
link.Attrs().Index = index
|
link.Attrs().Index = index
|
||||||
taplink, _, err = createLink(netHandle, name, link, numCPUs)
|
taplink, _, err = createLink(netHandle, name, link, queues)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -627,7 +627,7 @@ func setIPs(link netlink.Link, addrs []netlink.Addr) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func tapNetworkPair(endpoint Endpoint, numCPUs uint32, disableVhostNet bool) error {
|
func tapNetworkPair(endpoint Endpoint, queues int, disableVhostNet bool) error {
|
||||||
netHandle, err := netlink.NewHandle()
|
netHandle, err := netlink.NewHandle()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -653,7 +653,7 @@ func tapNetworkPair(endpoint Endpoint, numCPUs uint32, disableVhostNet bool) err
|
|||||||
ParentIndex: attrs.Index,
|
ParentIndex: attrs.Index,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, int(numCPUs))
|
}, queues)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Could not create TAP interface: %s", err)
|
return fmt.Errorf("Could not create TAP interface: %s", err)
|
||||||
@ -705,13 +705,13 @@ func tapNetworkPair(endpoint Endpoint, numCPUs uint32, disableVhostNet bool) err
|
|||||||
|
|
||||||
// Note: The underlying interfaces need to be up prior to fd creation.
|
// Note: The underlying interfaces need to be up prior to fd creation.
|
||||||
|
|
||||||
netPair.VMFds, err = createMacvtapFds(tapLink.Attrs().Index, int(numCPUs))
|
netPair.VMFds, err = createMacvtapFds(tapLink.Attrs().Index, queues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Could not setup macvtap fds %s: %s", netPair.TAPIface, err)
|
return fmt.Errorf("Could not setup macvtap fds %s: %s", netPair.TAPIface, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !disableVhostNet {
|
if !disableVhostNet {
|
||||||
vhostFds, err := createVhostFds(int(numCPUs))
|
vhostFds, err := createVhostFds(queues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Could not setup vhost fds %s : %s", netPair.VirtIface.Name, err)
|
return fmt.Errorf("Could not setup vhost fds %s : %s", netPair.VirtIface.Name, err)
|
||||||
}
|
}
|
||||||
@ -721,7 +721,7 @@ func tapNetworkPair(endpoint Endpoint, numCPUs uint32, disableVhostNet bool) err
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func bridgeNetworkPair(endpoint Endpoint, numCPUs uint32, disableVhostNet bool) error {
|
func bridgeNetworkPair(endpoint Endpoint, queues int, disableVhostNet bool) error {
|
||||||
netHandle, err := netlink.NewHandle()
|
netHandle, err := netlink.NewHandle()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -730,14 +730,14 @@ func bridgeNetworkPair(endpoint Endpoint, numCPUs uint32, disableVhostNet bool)
|
|||||||
|
|
||||||
netPair := endpoint.NetworkPair()
|
netPair := endpoint.NetworkPair()
|
||||||
|
|
||||||
tapLink, fds, err := createLink(netHandle, netPair.TAPIface.Name, &netlink.Tuntap{}, int(numCPUs))
|
tapLink, fds, err := createLink(netHandle, netPair.TAPIface.Name, &netlink.Tuntap{}, queues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Could not create TAP interface: %s", err)
|
return fmt.Errorf("Could not create TAP interface: %s", err)
|
||||||
}
|
}
|
||||||
netPair.VMFds = fds
|
netPair.VMFds = fds
|
||||||
|
|
||||||
if !disableVhostNet {
|
if !disableVhostNet {
|
||||||
vhostFds, err := createVhostFds(int(numCPUs))
|
vhostFds, err := createVhostFds(queues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Could not setup vhost fds %s : %s", netPair.VirtIface.Name, err)
|
return fmt.Errorf("Could not setup vhost fds %s : %s", netPair.VirtIface.Name, err)
|
||||||
}
|
}
|
||||||
@ -775,7 +775,7 @@ func bridgeNetworkPair(endpoint Endpoint, numCPUs uint32, disableVhostNet bool)
|
|||||||
}
|
}
|
||||||
|
|
||||||
mcastSnoop := false
|
mcastSnoop := false
|
||||||
bridgeLink, _, err := createLink(netHandle, netPair.Name, &netlink.Bridge{MulticastSnooping: &mcastSnoop}, int(numCPUs))
|
bridgeLink, _, err := createLink(netHandle, netPair.Name, &netlink.Bridge{MulticastSnooping: &mcastSnoop}, queues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Could not create bridge: %s", err)
|
return fmt.Errorf("Could not create bridge: %s", err)
|
||||||
}
|
}
|
||||||
@ -805,7 +805,7 @@ func bridgeNetworkPair(endpoint Endpoint, numCPUs uint32, disableVhostNet bool)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupTCFiltering(endpoint Endpoint, numCPUs uint32, disableVhostNet bool) error {
|
func setupTCFiltering(endpoint Endpoint, queues int, disableVhostNet bool) error {
|
||||||
netHandle, err := netlink.NewHandle()
|
netHandle, err := netlink.NewHandle()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -814,14 +814,14 @@ func setupTCFiltering(endpoint Endpoint, numCPUs uint32, disableVhostNet bool) e
|
|||||||
|
|
||||||
netPair := endpoint.NetworkPair()
|
netPair := endpoint.NetworkPair()
|
||||||
|
|
||||||
tapLink, fds, err := createLink(netHandle, netPair.TAPIface.Name, &netlink.Tuntap{}, int(numCPUs))
|
tapLink, fds, err := createLink(netHandle, netPair.TAPIface.Name, &netlink.Tuntap{}, queues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Could not create TAP interface: %s", err)
|
return fmt.Errorf("Could not create TAP interface: %s", err)
|
||||||
}
|
}
|
||||||
netPair.VMFds = fds
|
netPair.VMFds = fds
|
||||||
|
|
||||||
if !disableVhostNet {
|
if !disableVhostNet {
|
||||||
vhostFds, err := createVhostFds(int(numCPUs))
|
vhostFds, err := createVhostFds(queues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Could not setup vhost fds %s : %s", netPair.VirtIface.Name, err)
|
return fmt.Errorf("Could not setup vhost fds %s : %s", netPair.VirtIface.Name, err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user