From a891afad6d7e3b09bafdccb4cc4b9fc4e577620e Mon Sep 17 00:00:00 2001 From: Fabricio Voznika Date: Fri, 28 Dec 2018 13:47:19 -0800 Subject: Simplify synchronization between runsc and sandbox process Make 'runsc create' join cgroup before creating sandbox process. This removes the need to synchronize platform creation and ensure that sandbox process is charged to the right cgroup from the start. PiperOrigin-RevId: 227166451 Change-Id: Ieb4b18e6ca0daf7b331dc897699ca419bc5ee3a2 --- runsc/test/root/cgroup_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'runsc/test/root') diff --git a/runsc/test/root/cgroup_test.go b/runsc/test/root/cgroup_test.go index fdb94ff64..0eabf9561 100644 --- a/runsc/test/root/cgroup_test.go +++ b/runsc/test/root/cgroup_test.go @@ -18,6 +18,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strconv" "strings" "testing" @@ -123,6 +124,8 @@ func TestCgroup(t *testing.T) { t.Fatalf("Docker.ID() failed: %v", err) } t.Logf("cgroup ID: %s", gid) + + // Check list of attributes defined above. for _, attr := range attrs { path := filepath.Join("/sys/fs/cgroup", attr.ctrl, "docker", gid, attr.file) out, err := ioutil.ReadFile(path) @@ -137,4 +140,33 @@ func TestCgroup(t *testing.T) { t.Errorf("arg: %q, cgroup attribute %s/%s, got: %q, want: %q", attr.arg, attr.ctrl, attr.file, got, attr.want) } } + + // Check that sandbox is inside cgroup. + controllers := []string{ + "blkio", + "cpu", + "cpuset", + "memory", + "net_cls", + "net_prio", + "devices", + "freezer", + "perf_event", + "pids", + "systemd", + } + pid, err := d.SandboxPid() + if err != nil { + t.Fatalf("SandboxPid: %v", err) + } + for _, ctrl := range controllers { + path := filepath.Join("/sys/fs/cgroup", ctrl, "docker", gid, "cgroup.procs") + out, err := ioutil.ReadFile(path) + if err != nil { + t.Fatalf("failed to read %q: %v", path, err) + } + if got := string(out); !strings.Contains(got, strconv.Itoa(pid)) { + t.Errorf("cgroup control %s processes, got: %q, want: %q", ctrl, got, pid) + } + } } -- cgit v1.2.3