Skip to content

Commit

Permalink
namespace: do not create path using rand.
Browse files Browse the repository at this point in the history
Using random char generation at early boot may slow the process due to
low entropy.

Also from kernel 4.14.36 rand call hangs due to low-entropy. Lets
remove dependency on rand at early sandbox creation.

Fixes: kata-containers#278

Signed-off-by: Jose Carlos Venegas Munoz <jose.carlos.venegas.munoz@intel.com>
  • Loading branch information
jcvenegas committed Jun 26, 2018
1 parent f06eb20 commit 57bf4e6
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package main

import (
"crypto/rand"
"fmt"
"os"
"path/filepath"
Expand All @@ -17,7 +16,7 @@ import (
"golang.org/x/sys/unix"
)

var persistentNsDir = "/var/run"
var persistentNsDir = "/var/run/sandbox-ns"

// nsType defines a namespace type.
type nsType string
Expand Down Expand Up @@ -48,19 +47,15 @@ func getCurrentThreadNSPath(nType nsType) string {
// setupPersistentNs creates persistent namespace without switchin to it.
// Note, pid namespaces cannot be persisted.
func setupPersistentNs(namespaceType nsType) (*namespace, error) {
b := make([]byte, 8)
_, err := rand.Reader.Read(b)
if err != nil {
return nil, fmt.Errorf("failed to generate random netns name: %v", err)
}

err = os.MkdirAll(persistentNsDir, 0755)
err := os.MkdirAll(persistentNsDir, 0755)
if err != nil {
return nil, err
}

// Create an empty file at the mount point.
nsPath := filepath.Join(persistentNsDir, fmt.Sprintf("%x", b))
nsPath := filepath.Join(persistentNsDir, string(namespaceType))

mountFd, err := os.Create(nsPath)
if err != nil {
return nil, err
Expand Down

0 comments on commit 57bf4e6

Please sign in to comment.