Merge pull request #362 from vmarmol/cgroup

Retry getting the cgroup root at apply time.
This commit is contained in:
Mrunal Patel 2015-02-06 12:25:01 -08:00
commit 62bdfc482d
1 changed files with 22 additions and 10 deletions

View File

@ -1,11 +1,11 @@
package fs
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"sync"
"github.com/docker/libcontainer/cgroups"
)
@ -25,20 +25,31 @@ var (
)
// The absolute path to the root of the cgroup hierarchies.
var cgroupRootLock sync.Mutex
var cgroupRoot string
// TODO(vmarmol): Report error here, we'll probably need to wait for the new API.
func init() {
// Gets the cgroupRoot.
func getCgroupRoot() (string, error) {
cgroupRootLock.Lock()
defer cgroupRootLock.Unlock()
if cgroupRoot != "" {
return cgroupRoot, nil
}
// we can pick any subsystem to find the root
cpuRoot, err := cgroups.FindCgroupMountpoint("cpu")
if err != nil {
return
return "", err
}
cgroupRoot = filepath.Dir(cpuRoot)
root := filepath.Dir(cpuRoot)
if _, err := os.Stat(cgroupRoot); err != nil {
return
if _, err := os.Stat(root); err != nil {
return "", err
}
cgroupRoot = root
return cgroupRoot, nil
}
type subsystem interface {
@ -152,8 +163,9 @@ func GetPids(c *cgroups.Cgroup) ([]int, error) {
}
func getCgroupData(c *cgroups.Cgroup, pid int) (*data, error) {
if cgroupRoot == "" {
return nil, fmt.Errorf("failed to find the cgroup root")
root, err := getCgroupRoot()
if err != nil {
return nil, err
}
cgroup := c.Name
@ -162,7 +174,7 @@ func getCgroupData(c *cgroups.Cgroup, pid int) (*data, error) {
}
return &data{
root: cgroupRoot,
root: root,
cgroup: cgroup,
c: c,
pid: pid,