-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jack Yu <[email protected]>
- Loading branch information
Showing
8 changed files
with
78 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ns | ||
|
||
// Join joins all the namespaces in the Joiners. | ||
func (joiners *Joiners) Join() (err error) { | ||
return nil | ||
} | ||
|
||
func Gettid() int { | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ns | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
"golang.org/x/sys/unix" | ||
|
||
"github.com/longhorn/go-common-libs/types" | ||
) | ||
|
||
// Join joins all the namespaces in the Joiners. | ||
func (joiners *Joiners) Join() (err error) { | ||
for _, joiner := range *joiners { | ||
if joiner.isJoined { | ||
logrus.Tracef("Already joined namespace: %s", joiner.namespace) | ||
continue | ||
} | ||
|
||
if joiner.namespace == types.NamespaceMnt { | ||
err := unix.Unshare(unix.CLONE_NEWNS) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to unshare namespace: %+s", joiner.namespace) | ||
} | ||
} | ||
|
||
if err := unix.Setns(joiner.fd, 0); err != nil { | ||
return errors.Wrapf(err, "failed to set namespace: %+s", joiner.namespace) | ||
} | ||
|
||
joiner.isJoined = true | ||
logrus.Tracef("Joined namespace: %v", joiner.namespace) | ||
} | ||
return nil | ||
} | ||
|
||
func Gettid() int { | ||
return unix.Gettid() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package types | ||
|
||
func (ns Namespace) Flag() uintptr { | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package types | ||
|
||
import ( | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func (ns Namespace) Flag() uintptr { | ||
switch ns { | ||
case NamespaceNet: | ||
return unix.CLONE_NEWNET | ||
default: | ||
return 0 | ||
} | ||
} |