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

Commit

Permalink
virtcontainers: network: Rename numCPUs to queues
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Sebastien Boeuf committed Dec 14, 2018
1 parent 2cb4bb9 commit 0bcd221
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions virtcontainers/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 fds []*os.File

Expand All @@ -410,7 +410,7 @@ func createLink(netHandle *netlink.Handle, name string, expectedLink netlink.Lin
newLink = &netlink.Tuntap{
LinkAttrs: netlink.LinkAttrs{Name: name},
Mode: netlink.TUNTAP_MODE_TAP,
Queues: numCPUs,
Queues: queues,
Flags: netlink.TUNTAP_MULTI_QUEUE_DEFAULTS | netlink.TUNTAP_VNET_HDR,
}
case (&netlink.Macvtap{}).Type():
Expand Down Expand Up @@ -505,7 +505,7 @@ func getLinkByName(netHandle *netlink.Handle, name string, expectedLink netlink.
func xConnectVMNetwork(endpoint Endpoint, h hypervisor) error {
netPair := endpoint.NetworkPair()

numCPUs := h.hypervisorConfig().NumVCPUs
queues := int(h.hypervisorConfig().NumVCPUs)
disableVhostNet := h.hypervisorConfig().DisableVhostNet

if netPair.NetInterworkingModel == NetXConnectDefaultModel {
Expand All @@ -514,11 +514,11 @@ func xConnectVMNetwork(endpoint Endpoint, h hypervisor) error {

switch netPair.NetInterworkingModel {
case NetXConnectBridgedModel:
return bridgeNetworkPair(endpoint, numCPUs, disableVhostNet)
return bridgeNetworkPair(endpoint, queues, disableVhostNet)
case NetXConnectMacVtapModel:
return tapNetworkPair(endpoint, numCPUs, disableVhostNet)
return tapNetworkPair(endpoint, queues, disableVhostNet)
case NetXConnectTCFilterModel:
return setupTCFiltering(endpoint, numCPUs, disableVhostNet)
return setupTCFiltering(endpoint, queues, disableVhostNet)
case NetXConnectEnlightenedModel:
return fmt.Errorf("Unsupported networking model")
default:
Expand Down Expand Up @@ -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 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 {
taplink, _, err = createLink(netHandle, name, link, numCPUs)
taplink, _, err = createLink(netHandle, name, link, queues)
return
}

Expand All @@ -600,7 +600,7 @@ func createMacVtap(netHandle *netlink.Handle, name string, link netlink.Link, nu
for i := 0; i < linkRetries; i++ {
index := hostLinkOffset + (r.Int() & linkRange)
link.Attrs().Index = index
taplink, _, err = createLink(netHandle, name, link, numCPUs)
taplink, _, err = createLink(netHandle, name, link, queues)
if err == nil {
break
}
Expand All @@ -627,7 +627,7 @@ func setIPs(link netlink.Link, addrs []netlink.Addr) error {
return nil
}

func tapNetworkPair(endpoint Endpoint, numCPUs uint32, disableVhostNet bool) error {
func tapNetworkPair(endpoint Endpoint, queues int, disableVhostNet bool) error {
netHandle, err := netlink.NewHandle()
if err != nil {
return err
Expand All @@ -653,7 +653,7 @@ func tapNetworkPair(endpoint Endpoint, numCPUs uint32, disableVhostNet bool) err
ParentIndex: attrs.Index,
},
},
}, int(numCPUs))
}, queues)

if err != nil {
return fmt.Errorf("Could not create TAP interface: %s", err)
Expand Down Expand Up @@ -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.

netPair.VMFds, err = createMacvtapFds(tapLink.Attrs().Index, int(numCPUs))
netPair.VMFds, err = createMacvtapFds(tapLink.Attrs().Index, queues)
if err != nil {
return fmt.Errorf("Could not setup macvtap fds %s: %s", netPair.TAPIface, err)
}

if !disableVhostNet {
vhostFds, err := createVhostFds(int(numCPUs))
vhostFds, err := createVhostFds(queues)
if err != nil {
return fmt.Errorf("Could not setup vhost fds %s : %s", netPair.VirtIface.Name, err)
}
Expand All @@ -721,7 +721,7 @@ func tapNetworkPair(endpoint Endpoint, numCPUs uint32, disableVhostNet bool) err
return nil
}

func bridgeNetworkPair(endpoint Endpoint, numCPUs uint32, disableVhostNet bool) error {
func bridgeNetworkPair(endpoint Endpoint, queues int, disableVhostNet bool) error {
netHandle, err := netlink.NewHandle()
if err != nil {
return err
Expand All @@ -730,14 +730,14 @@ func bridgeNetworkPair(endpoint Endpoint, numCPUs uint32, disableVhostNet bool)

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 {
return fmt.Errorf("Could not create TAP interface: %s", err)
}
netPair.VMFds = fds

if !disableVhostNet {
vhostFds, err := createVhostFds(int(numCPUs))
vhostFds, err := createVhostFds(queues)
if err != nil {
return fmt.Errorf("Could not setup vhost fds %s : %s", netPair.VirtIface.Name, err)
}
Expand Down Expand Up @@ -775,7 +775,7 @@ func bridgeNetworkPair(endpoint Endpoint, numCPUs uint32, disableVhostNet bool)
}

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 {
return fmt.Errorf("Could not create bridge: %s", err)
}
Expand Down Expand Up @@ -805,7 +805,7 @@ func bridgeNetworkPair(endpoint Endpoint, numCPUs uint32, disableVhostNet bool)
return nil
}

func setupTCFiltering(endpoint Endpoint, numCPUs uint32, disableVhostNet bool) error {
func setupTCFiltering(endpoint Endpoint, queues int, disableVhostNet bool) error {
netHandle, err := netlink.NewHandle()
if err != nil {
return err
Expand All @@ -814,14 +814,14 @@ func setupTCFiltering(endpoint Endpoint, numCPUs uint32, disableVhostNet bool) e

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 {
return fmt.Errorf("Could not create TAP interface: %s", err)
}
netPair.VMFds = fds

if !disableVhostNet {
vhostFds, err := createVhostFds(int(numCPUs))
vhostFds, err := createVhostFds(queues)
if err != nil {
return fmt.Errorf("Could not setup vhost fds %s : %s", netPair.VirtIface.Name, err)
}
Expand Down

0 comments on commit 0bcd221

Please sign in to comment.