From 64edd40fcccedaccccdc8091ad27c003786ce2b4 Mon Sep 17 00:00:00 2001 From: Madhu Venugopal Date: Thu, 10 Mar 2016 13:23:04 -0800 Subject: [PATCH] Use osl.InitOSContext appropriately Signed-off-by: Madhu Venugopal --- libnetwork/drivers/ipvlan/ipvlan_endpoint.go | 3 +++ libnetwork/drivers/ipvlan/ipvlan_joinleave.go | 1 + libnetwork/drivers/ipvlan/ipvlan_network.go | 3 +++ libnetwork/drivers/ipvlan/ipvlan_setup.go | 3 --- libnetwork/drivers/macvlan/macvlan_endpoint.go | 3 +++ libnetwork/drivers/macvlan/macvlan_joinleave.go | 1 + libnetwork/drivers/macvlan/macvlan_network.go | 3 +++ libnetwork/drivers/macvlan/macvlan_setup.go | 3 --- 8 files changed, 14 insertions(+), 6 deletions(-) diff --git a/libnetwork/drivers/ipvlan/ipvlan_endpoint.go b/libnetwork/drivers/ipvlan/ipvlan_endpoint.go index e3d724a3e5..3071162621 100644 --- a/libnetwork/drivers/ipvlan/ipvlan_endpoint.go +++ b/libnetwork/drivers/ipvlan/ipvlan_endpoint.go @@ -7,6 +7,7 @@ import ( "github.com/docker/libnetwork/driverapi" "github.com/docker/libnetwork/netlabel" "github.com/docker/libnetwork/netutils" + "github.com/docker/libnetwork/osl" "github.com/docker/libnetwork/types" "github.com/vishvananda/netlink" ) @@ -14,6 +15,7 @@ import ( // CreateEndpoint assigns the mac, ip and endpoint id for the new container func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error { + defer osl.InitOSContext()() if err := validateID(nid, eid); err != nil { return err @@ -63,6 +65,7 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, // DeleteEndpoint remove the endpoint and associated netlink interface func (d *driver) DeleteEndpoint(nid, eid string) error { + defer osl.InitOSContext()() if err := validateID(nid, eid); err != nil { return err } diff --git a/libnetwork/drivers/ipvlan/ipvlan_joinleave.go b/libnetwork/drivers/ipvlan/ipvlan_joinleave.go index ee24d37bc6..771f126d0b 100644 --- a/libnetwork/drivers/ipvlan/ipvlan_joinleave.go +++ b/libnetwork/drivers/ipvlan/ipvlan_joinleave.go @@ -121,6 +121,7 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, // Leave method is invoked when a Sandbox detaches from an endpoint. func (d *driver) Leave(nid, eid string) error { + defer osl.InitOSContext()() network, err := d.getNetwork(nid) if err != nil { return err diff --git a/libnetwork/drivers/ipvlan/ipvlan_network.go b/libnetwork/drivers/ipvlan/ipvlan_network.go index 036b37c472..60bdb0e875 100644 --- a/libnetwork/drivers/ipvlan/ipvlan_network.go +++ b/libnetwork/drivers/ipvlan/ipvlan_network.go @@ -9,11 +9,13 @@ import ( "github.com/docker/libnetwork/driverapi" "github.com/docker/libnetwork/netlabel" "github.com/docker/libnetwork/options" + "github.com/docker/libnetwork/osl" "github.com/docker/libnetwork/types" ) // CreateNetwork the network for the specified driver type func (d *driver) CreateNetwork(nid string, option map[string]interface{}, ipV4Data, ipV6Data []driverapi.IPAMData) error { + defer osl.InitOSContext()() kv, err := kernel.GetKernelVersion() if err != nil { return fmt.Errorf("Failed to check kernel version for %s driver support: %v", ipvlanType, err) @@ -119,6 +121,7 @@ func (d *driver) createNetwork(config *configuration) error { // DeleteNetwork the network for the specified driver type func (d *driver) DeleteNetwork(nid string) error { + defer osl.InitOSContext()() n := d.network(nid) if n == nil { return fmt.Errorf("network id %s not found", nid) diff --git a/libnetwork/drivers/ipvlan/ipvlan_setup.go b/libnetwork/drivers/ipvlan/ipvlan_setup.go index fb362c94ff..d8abf6d96e 100644 --- a/libnetwork/drivers/ipvlan/ipvlan_setup.go +++ b/libnetwork/drivers/ipvlan/ipvlan_setup.go @@ -9,7 +9,6 @@ import ( "strings" "github.com/Sirupsen/logrus" - "github.com/docker/libnetwork/osl" "github.com/vishvananda/netlink" ) @@ -21,8 +20,6 @@ const ( // createIPVlan Create the ipvlan slave specifying the source name func createIPVlan(containerIfName, parent, ipvlanMode string) (string, error) { - defer osl.InitOSContext()() - // Set the ipvlan mode. Default is bridge mode mode, err := setIPVlanMode(ipvlanMode) if err != nil { diff --git a/libnetwork/drivers/macvlan/macvlan_endpoint.go b/libnetwork/drivers/macvlan/macvlan_endpoint.go index 7f99092222..ee52ec54b1 100644 --- a/libnetwork/drivers/macvlan/macvlan_endpoint.go +++ b/libnetwork/drivers/macvlan/macvlan_endpoint.go @@ -7,6 +7,7 @@ import ( "github.com/docker/libnetwork/driverapi" "github.com/docker/libnetwork/netlabel" "github.com/docker/libnetwork/netutils" + "github.com/docker/libnetwork/osl" "github.com/docker/libnetwork/types" "github.com/vishvananda/netlink" ) @@ -14,6 +15,7 @@ import ( // CreateEndpoint assigns the mac, ip and endpoint id for the new container func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error { + defer osl.InitOSContext()() if err := validateID(nid, eid); err != nil { return err @@ -60,6 +62,7 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, // DeleteEndpoint remove the endpoint and associated netlink interface func (d *driver) DeleteEndpoint(nid, eid string) error { + defer osl.InitOSContext()() if err := validateID(nid, eid); err != nil { return err } diff --git a/libnetwork/drivers/macvlan/macvlan_joinleave.go b/libnetwork/drivers/macvlan/macvlan_joinleave.go index d7eeda81d1..04df3723c4 100644 --- a/libnetwork/drivers/macvlan/macvlan_joinleave.go +++ b/libnetwork/drivers/macvlan/macvlan_joinleave.go @@ -82,6 +82,7 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, // Leave method is invoked when a Sandbox detaches from an endpoint. func (d *driver) Leave(nid, eid string) error { + defer osl.InitOSContext()() network, err := d.getNetwork(nid) if err != nil { return err diff --git a/libnetwork/drivers/macvlan/macvlan_network.go b/libnetwork/drivers/macvlan/macvlan_network.go index 4fa00161d0..abaefc3059 100644 --- a/libnetwork/drivers/macvlan/macvlan_network.go +++ b/libnetwork/drivers/macvlan/macvlan_network.go @@ -9,11 +9,13 @@ import ( "github.com/docker/libnetwork/driverapi" "github.com/docker/libnetwork/netlabel" "github.com/docker/libnetwork/options" + "github.com/docker/libnetwork/osl" "github.com/docker/libnetwork/types" ) // CreateNetwork the network for the specified driver type func (d *driver) CreateNetwork(nid string, option map[string]interface{}, ipV4Data, ipV6Data []driverapi.IPAMData) error { + defer osl.InitOSContext()() kv, err := kernel.GetKernelVersion() if err != nil { return fmt.Errorf("failed to check kernel version for %s driver support: %v", macvlanType, err) @@ -123,6 +125,7 @@ func (d *driver) createNetwork(config *configuration) error { // DeleteNetwork the network for the specified driver type func (d *driver) DeleteNetwork(nid string) error { + defer osl.InitOSContext()() n := d.network(nid) if n == nil { return fmt.Errorf("network id %s not found", nid) diff --git a/libnetwork/drivers/macvlan/macvlan_setup.go b/libnetwork/drivers/macvlan/macvlan_setup.go index 9380dab504..f0b74edb53 100644 --- a/libnetwork/drivers/macvlan/macvlan_setup.go +++ b/libnetwork/drivers/macvlan/macvlan_setup.go @@ -9,7 +9,6 @@ import ( "strings" "github.com/Sirupsen/logrus" - "github.com/docker/libnetwork/osl" "github.com/vishvananda/netlink" ) @@ -21,8 +20,6 @@ const ( // Create the macvlan slave specifying the source name func createMacVlan(containerIfName, parent, macvlanMode string) (string, error) { - defer osl.InitOSContext()() - // Set the macvlan mode. Default is bridge mode mode, err := setMacVlanMode(macvlanMode) if err != nil {