network: Collapse log calls for endpoint Attach and Detach

Log Attach, Detach, HotAttach and HotDetach at a single
location.

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
Archana Shinde 2018-10-09 11:28:03 -07:00
parent ab15498bdf
commit b04691e229
7 changed files with 5 additions and 18 deletions

View File

@ -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
@ -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)
})
}

View File

@ -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
}
@ -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
}

View File

@ -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))
@ -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
}

View File

@ -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 {
@ -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.

View File

@ -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
@ -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
}

View File

@ -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
@ -102,8 +100,6 @@ 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)
})
@ -111,7 +107,6 @@ func (endpoint *VethEndpoint) Detach(netNsCreated bool, netNsPath string) error
// 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
@ -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 {

View File

@ -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 {
@ -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
}