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

Commit

Permalink
network: Collapse log calls for endpoint Attach and Detach
Browse files Browse the repository at this point in the history
Log Attach, Detach, HotAttach and HotDetach at a single
location.

Signed-off-by: Archana Shinde <[email protected]>
  • Loading branch information
amshinde committed Oct 11, 2018
1 parent ab15498 commit b04691e
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 18 deletions.
4 changes: 0 additions & 4 deletions virtcontainers/bridgedmacvlan_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func (endpoint *BridgedMacvlanEndpoint) NetworkPair() *NetworkInterfacePair {
// Attach for virtual endpoint bridges the network pair and adds the
// tap interface of the network pair to the hypervisor.
func (endpoint *BridgedMacvlanEndpoint) Attach(h hypervisor) error {
networkLogger().Info("Attaching macvlan endpoint")
if err := xconnectVMNetwork(endpoint, true, h.hypervisorConfig().NumVCPUs, h.hypervisorConfig().DisableVhostNet); err != nil {
networkLogger().WithError(err).Error("Error bridging virtual ep")
return err
Expand All @@ -97,10 +96,7 @@ func (endpoint *BridgedMacvlanEndpoint) Detach(netNsCreated bool, netNsPath stri
return nil
}

networkLogger().Info("Detaching virtual endpoint")

return doNetNS(netNsPath, func(_ ns.NetNS) error {
//return xconnectVMNetwork(&(endpoint.NetPair), false, 0, false, endpoint.EndpointType)
return xconnectVMNetwork(endpoint, false, 0, false)
})
}
Expand Down
2 changes: 2 additions & 0 deletions virtcontainers/default_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (n *defNetwork) add(s *Sandbox) error {

err = doNetNS(s.config.NetworkConfig.NetNSPath, func(_ ns.NetNS) error {
for _, endpoint := range s.networkNS.Endpoints {
n.logger().WithField("endpoint-type", endpoint.Type()).Info("Attaching endpoint")
if err := endpoint.Attach(s.hypervisor); err != nil {
return err
}
Expand All @@ -83,6 +84,7 @@ func (n *defNetwork) remove(s *Sandbox) error {
for _, endpoint := range s.networkNS.Endpoints {
// Detach for an endpoint should enter the network namespace
// if required.
n.logger().WithField("endpoint-type", endpoint.Type()).Info("Detaching endpoint")
if err := endpoint.Detach(s.networkNS.NetNsCreated, s.networkNS.NetNsPath); err != nil {
return err
}
Expand Down
2 changes: 0 additions & 2 deletions virtcontainers/macvtap_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func (endpoint *MacvtapEndpoint) SetProperties(properties NetworkInfo) {

// Attach for macvtap endpoint passes macvtap device to the hypervisor.
func (endpoint *MacvtapEndpoint) Attach(h hypervisor) error {
networkLogger().WithField("endpoint-type", "macvtap").Info("Attaching endpoint")
var err error

endpoint.VMFds, err = createMacvtapFds(endpoint.EndpointProperties.Iface.Index, int(h.hypervisorConfig().NumVCPUs))
Expand All @@ -76,7 +75,6 @@ func (endpoint *MacvtapEndpoint) Attach(h hypervisor) error {

// Detach for macvtap endpoint does nothing.
func (endpoint *MacvtapEndpoint) Detach(netNsCreated bool, netNsPath string) error {
networkLogger().WithField("endpoint-type", "macvtap").Info("Detaching endpoint")
return nil
}

Expand Down
3 changes: 0 additions & 3 deletions virtcontainers/physical_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ func (endpoint *PhysicalEndpoint) NetworkPair() *NetworkInterfacePair {
// Attach for physical endpoint binds the physical network interface to
// vfio-pci and adds device to the hypervisor with vfio-passthrough.
func (endpoint *PhysicalEndpoint) Attach(h hypervisor) error {
networkLogger().WithField("endpoint-type", "physical").Info("Attaching endpoint")

// Unbind physical interface from host driver and bind to vfio
// so that it can be passed to qemu.
if err := bindNICToVFIO(endpoint); err != nil {
Expand All @@ -88,7 +86,6 @@ func (endpoint *PhysicalEndpoint) Detach(netNsCreated bool, netNsPath string) er
// Bind back the physical network interface to host.
// We need to do this even if a new network namespace has not
// been created by virtcontainers.
networkLogger().WithField("endpoint-type", "physical").Info("Detaching endpoint")

// We do not need to enter the network namespace to bind back the
// physical interface to host driver.
Expand Down
2 changes: 2 additions & 0 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ func (s *Sandbox) AddInterface(inf *grpc.Interface) (*grpc.Interface, error) {

endpoint.SetProperties(netInfo)
if err := doNetNS(s.networkNS.NetNsPath, func(_ ns.NetNS) error {
s.Logger().WithField("endpoint-type", endpoint.Type()).Info("Hot attaching endpoint")
return endpoint.HotAttach(s.hypervisor)
}); err != nil {
return nil, err
Expand All @@ -1136,6 +1137,7 @@ func (s *Sandbox) AddInterface(inf *grpc.Interface) (*grpc.Interface, error) {
func (s *Sandbox) RemoveInterface(inf *grpc.Interface) (*grpc.Interface, error) {
for i, endpoint := range s.networkNS.Endpoints {
if endpoint.HardwareAddr() == inf.HwAddr {
s.Logger().WithField("endpoint-type", endpoint.Type()).Info("Hot detaching endpoint")
if err := endpoint.HotDetach(s.hypervisor, s.networkNS.NetNsCreated, s.networkNS.NetNsPath); err != nil {
return inf, err
}
Expand Down
7 changes: 1 addition & 6 deletions virtcontainers/veth_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ func (endpoint *VethEndpoint) SetProperties(properties NetworkInfo) {
// Attach for veth endpoint bridges the network pair and adds the
// tap interface of the network pair to the hypervisor.
func (endpoint *VethEndpoint) Attach(h hypervisor) error {
networkLogger().WithField("endpoint-type", "virtual").Info("Attaching endpoint")

if err := xconnectVMNetwork(endpoint, true, h.hypervisorConfig().NumVCPUs, h.hypervisorConfig().DisableVhostNet); err != nil {
networkLogger().WithError(err).Error("Error bridging virtual endpoint")
return err
Expand All @@ -102,16 +100,13 @@ func (endpoint *VethEndpoint) Detach(netNsCreated bool, netNsPath string) error
return nil
}

networkLogger().WithField("endpoint-type", "virtual").Info("Detaching endpoint")

return doNetNS(netNsPath, func(_ ns.NetNS) error {
return xconnectVMNetwork(endpoint, false, 0, false)
})
}

// HotAttach for the veth endpoint uses hot plug device
func (endpoint *VethEndpoint) HotAttach(h hypervisor) error {
networkLogger().Info("Hot attaching virtual endpoint")
if err := xconnectVMNetwork(endpoint, true, h.hypervisorConfig().NumVCPUs, h.hypervisorConfig().DisableVhostNet); err != nil {
networkLogger().WithError(err).Error("Error bridging virtual ep")
return err
Expand All @@ -129,7 +124,7 @@ func (endpoint *VethEndpoint) HotDetach(h hypervisor, netNsCreated bool, netNsPa
if !netNsCreated {
return nil
}
networkLogger().Info("Hot detaching virtual endpoint")

if err := doNetNS(netNsPath, func(_ ns.NetNS) error {
return xconnectVMNetwork(endpoint, false, 0, h.hypervisorConfig().DisableVhostNet)
}); err != nil {
Expand Down
3 changes: 0 additions & 3 deletions virtcontainers/vhostuser_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ func (endpoint *VhostUserEndpoint) NetworkPair() *NetworkInterfacePair {

// Attach for vhostuser endpoint
func (endpoint *VhostUserEndpoint) Attach(h hypervisor) error {
networkLogger().WithField("endpoint-type", "vhostuser").Info("Attaching endpoint")

// Generate a unique ID to be used for hypervisor commandline fields
randBytes, err := utils.GenerateRandomBytes(8)
if err != nil {
Expand All @@ -90,7 +88,6 @@ func (endpoint *VhostUserEndpoint) Attach(h hypervisor) error {

// Detach for vhostuser endpoint
func (endpoint *VhostUserEndpoint) Detach(netNsCreated bool, netNsPath string) error {
networkLogger().WithField("endpoint-type", "vhostuser").Info("Detaching endpoint")
return nil
}

Expand Down

0 comments on commit b04691e

Please sign in to comment.