Skip to content

Commit

Permalink
Optimizing looping over namespaces
Browse files Browse the repository at this point in the history
Signed-off-by: Harshal Patil <harshal.patil@in.ibm.com>
  • Loading branch information
Harshal Patil committed Apr 25, 2017
1 parent 94cfb79 commit 575cf7e
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1453,19 +1453,16 @@ func (c *linuxContainer) orderNamespacePaths(namespaces map[configs.NamespaceTyp
configs.NEWPID,
configs.NEWNS,
}

// Remove namespaces that we don't need to join.
var nsTypes []configs.NamespaceType
for _, ns := range order {
if c.config.Namespaces.Contains(ns) {
nsTypes = append(nsTypes, ns)

for _, ns := range order{
if !c.config.Namespaces.Contains(ns) {
continue
}
}
for _, nsType := range nsTypes {
if p, ok := namespaces[nsType]; ok && p != "" {

if p, ok := namespaces[ns]; ok && p != "" {
// check if the requested namespace is supported
if !configs.IsNamespaceSupported(nsType) {
return nil, newSystemError(fmt.Errorf("namespace %s is not supported", nsType))
if !configs.IsNamespaceSupported(ns) {
return nil, newSystemError(fmt.Errorf("namespace %s is not supported", ns))
}
// only set to join this namespace if it exists
if _, err := os.Lstat(p); err != nil {
Expand All @@ -1476,9 +1473,11 @@ func (c *linuxContainer) orderNamespacePaths(namespaces map[configs.NamespaceTyp
if strings.ContainsRune(p, ',') {
return nil, newSystemError(fmt.Errorf("invalid path %s", p))
}
paths = append(paths, fmt.Sprintf("%s:%s", configs.NsName(nsType), p))
paths = append(paths, fmt.Sprintf("%s:%s", configs.NsName(ns), p))
}

}

return paths, nil
}

Expand Down

0 comments on commit 575cf7e

Please sign in to comment.