Merge pull request #130 from vishh/fix_cgroup_path

Make fs.GetStats() work when used from inside a docker container.
This commit is contained in:
Victor Marmol 2014-07-29 09:21:46 -07:00
commit 5e2627e687
2 changed files with 23 additions and 0 deletions

View File

@ -150,6 +150,10 @@ func (raw *data) parent(subsystem string) (string, error) {
}
func (raw *data) path(subsystem string) (string, error) {
// If the cgroup name/path is absolute do not look relative to the cgroup of the init process.
if filepath.IsAbs(raw.cgroup) {
return filepath.Join(raw.root, subsystem, raw.cgroup), nil
}
parent, err := raw.parent(subsystem)
if err != nil {
return "", err

View File

@ -5,6 +5,8 @@ import (
"os"
"path/filepath"
"testing"
"github.com/docker/libcontainer/cgroups"
)
const (
@ -66,3 +68,20 @@ func TestGetCgroupParamsInt(t *testing.T) {
t.Fatal("Expecting error, got none")
}
}
func TestAbsolutePathHandling(t *testing.T) {
testCgroup := cgroups.Cgroup{
Name: "bar",
Parent: "/foo",
}
cgroupData := data{
root: "/sys/fs/cgroup",
cgroup: "/foo/bar",
c: &testCgroup,
pid: 1,
}
expectedPath := filepath.Join(cgroupData.root, "cpu", testCgroup.Parent, testCgroup.Name)
if path, err := cgroupData.path("cpu"); path != expectedPath || err != nil {
t.Fatalf("expected path %s but got %s %s", expectedPath, path, err)
}
}