Libcontainer fs.GetStats() will not look for cgroups relative to the cgroup of init process if the parent
in cgroups.Cgroup is absolute. This is required to get stats of other containers while running inside a docker container. Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)
This commit is contained in:
parent
e64f9a39c6
commit
66aee74b1e
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue