Browse Source

Use osl.InitOSContext appropriately

Signed-off-by: Madhu Venugopal <madhu@docker.com>
Madhu Venugopal 9 years ago
parent
commit
64edd40fcc

+ 3 - 0
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
 	}

+ 1 - 0
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

+ 3 - 0
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)

+ 0 - 3
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 {

+ 3 - 0
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
 	}

+ 1 - 0
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

+ 3 - 0
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)

+ 0 - 3
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 {