Skip to content

Commit

Permalink
Remount sysfs when entering again into host netns
Browse files Browse the repository at this point in the history
  • Loading branch information
jellonek committed Jul 3, 2018
1 parent 641c597 commit ecaa313
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
21 changes: 21 additions & 0 deletions pkg/nettools/nettools.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import (

"github.com/Mirantis/virtlet/pkg/cni"
"github.com/Mirantis/virtlet/pkg/network"
"github.com/Mirantis/virtlet/pkg/utils"
)

const (
Expand Down Expand Up @@ -770,6 +771,16 @@ func SetupContainerSideNetwork(info *cnicurrent.Result, nsPath string, allLinks
// Jump into host netns to get vlan id of VF using its
// master device.
if err := hostNS.Do(func(ns.NetNS) error {
// switch /sys to corresponding one in netns
// to have the correct items under /sys/class/net
if err := utils.MountSysfs(); err != nil {
return err
}
defer func() {
if err := utils.UnmountSysfs(); err != nil {
glog.V(3).Infof("Warning, error during umount of /sys: %v", err)
}
}()
var err error
vlanID, err = getVfVlanID(pciAddress)
return err
Expand All @@ -793,6 +804,16 @@ func SetupContainerSideNetwork(info *cnicurrent.Result, nsPath string, allLinks
// Jump into host netns to set mac address and vlan id
// of VF using its master device.
if err := hostNS.Do(func(ns.NetNS) error {
// switch /sys to corresponding one in netns
// to have the correct items under /sys/class/net
if err := utils.MountSysfs(); err != nil {
return err
}
defer func() {
if err := utils.UnmountSysfs(); err != nil {
glog.V(3).Infof("Warning, error during umount of /sys: %v", err)
}
}()
return setMacAndVlanOnVf(pciAddress, hwAddr, vlanID)
}); err != nil {
return nil, err
Expand Down
5 changes: 3 additions & 2 deletions pkg/tapmanager/tapfdsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/Mirantis/virtlet/pkg/dhcp"
"github.com/Mirantis/virtlet/pkg/nettools"
"github.com/Mirantis/virtlet/pkg/network"
"github.com/Mirantis/virtlet/pkg/utils"
)

const (
Expand Down Expand Up @@ -353,11 +354,11 @@ func (s *TapFDSource) setupNetNS(key string, pnd *PodNetworkDesc, initNet func(n
if err := vmNS.Do(func(hostNS ns.NetNS) error {
// switch /sys to corresponding one in netns
// to have the correct items under /sys/class/net
if err := mountSysfs(); err != nil {
if err := utils.MountSysfs(); err != nil {
return err
}
defer func() {
if err := unmountSysfs(); err != nil {
if err := utils.UnmountSysfs(); err != nil {
glog.V(3).Infof("Warning, error during umount of /sys: %v", err)
}
}()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package tapmanager
package utils

import (
"syscall"
)

func mountSysfs() error {
// MountSysfs adds new mount of sysfs on /sys to have a correct view
// in current netns on /sys/class/net
func MountSysfs() error {
return syscall.Mount("none", "/sys", "sysfs", 0, "")
}

func unmountSysfs() error {
// UnmountSysfs unmounts current fs bound to /sys
func UnmountSysfs() error {
return syscall.Unmount("/sys", syscall.MNT_DETACH)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package tapmanager
package utils

import (
"errors"
)

func mountSysfs() error {
// MountSysfs is a placeholder for unsupported systems
func MountSysfs() error {
return errors.New("not implemented")
}

func unmountSysfs() error {
// UnmountSysfs is a placeholder for unsupported systems
func UnmountSysfs() error {
return errors.New("not implemented")
}

0 comments on commit ecaa313

Please sign in to comment.