diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go index ab2fbe144..22fe69e8c 100644 --- a/libcontainer/container_linux.go +++ b/libcontainer/container_linux.go @@ -655,7 +655,7 @@ func (c *linuxContainer) NotifyOOM() (<-chan struct{}, error) { } return notifyOnOOMV2(path) } - return notifyOnOOM(c.cgroupManager.GetPaths()) + return notifyOnOOM(c.cgroupManager.GetPaths()["memory"]) } func (c *linuxContainer) NotifyMemoryPressure(level PressureLevel) (<-chan struct{}, error) { @@ -663,7 +663,7 @@ func (c *linuxContainer) NotifyMemoryPressure(level PressureLevel) (<-chan struc if c.config.RootlessCgroups { logrus.Warn("getting memory pressure notifications may fail if you don't have the full access to cgroups") } - return notifyMemoryPressure(c.cgroupManager.GetPaths(), level) + return notifyMemoryPressure(c.cgroupManager.GetPaths()["memory"], level) } var criuFeatures *criurpc.CriuFeatures diff --git a/libcontainer/notify_linux.go b/libcontainer/notify_linux.go index 47a06783d..d7d1de1ba 100644 --- a/libcontainer/notify_linux.go +++ b/libcontainer/notify_linux.go @@ -3,6 +3,7 @@ package libcontainer import ( + "errors" "fmt" "io/ioutil" "os" @@ -11,8 +12,6 @@ import ( "golang.org/x/sys/unix" ) -const oomCgroupName = "memory" - type PressureLevel uint const ( @@ -66,19 +65,17 @@ func registerMemoryEvent(cgDir string, evName string, arg string) (<-chan struct // notifyOnOOM returns channel on which you can expect event about OOM, // if process died without OOM this channel will be closed. -func notifyOnOOM(paths map[string]string) (<-chan struct{}, error) { - dir := paths[oomCgroupName] +func notifyOnOOM(dir string) (<-chan struct{}, error) { if dir == "" { - return nil, fmt.Errorf("path %q missing", oomCgroupName) + return nil, errors.New("memory controller missing") } return registerMemoryEvent(dir, "memory.oom_control", "") } -func notifyMemoryPressure(paths map[string]string, level PressureLevel) (<-chan struct{}, error) { - dir := paths[oomCgroupName] +func notifyMemoryPressure(dir string, level PressureLevel) (<-chan struct{}, error) { if dir == "" { - return nil, fmt.Errorf("path %q missing", oomCgroupName) + return nil, errors.New("memory controller missing") } if level > CriticalPressure { diff --git a/libcontainer/notify_linux_test.go b/libcontainer/notify_linux_test.go index 1e15ae2c3..6f8b6d307 100644 --- a/libcontainer/notify_linux_test.go +++ b/libcontainer/notify_linux_test.go @@ -14,7 +14,7 @@ import ( "golang.org/x/sys/unix" ) -type notifyFunc func(paths map[string]string) (<-chan struct{}, error) +type notifyFunc func(path string) (<-chan struct{}, error) func testMemoryNotification(t *testing.T, evName string, notify notifyFunc, targ string) { memoryPath, err := ioutil.TempDir("", "testmemnotification-"+evName) @@ -29,10 +29,7 @@ func testMemoryNotification(t *testing.T, evName string, notify notifyFunc, targ if err := ioutil.WriteFile(eventPath, []byte{}, 0700); err != nil { t.Fatal(err) } - paths := map[string]string{ - "memory": memoryPath, - } - ch, err := notify(paths) + ch, err := notify(memoryPath) if err != nil { t.Fatal("expected no error, got:", err) } @@ -102,8 +99,8 @@ func testMemoryNotification(t *testing.T, evName string, notify notifyFunc, targ } func TestNotifyOnOOM(t *testing.T) { - f := func(paths map[string]string) (<-chan struct{}, error) { - return notifyOnOOM(paths) + f := func(path string) (<-chan struct{}, error) { + return notifyOnOOM(path) } testMemoryNotification(t, "memory.oom_control", f, "") @@ -117,8 +114,8 @@ func TestNotifyMemoryPressure(t *testing.T) { } for level, arg := range tests { - f := func(paths map[string]string) (<-chan struct{}, error) { - return notifyMemoryPressure(paths, level) + f := func(path string) (<-chan struct{}, error) { + return notifyMemoryPressure(path, level) } testMemoryNotification(t, "memory.pressure_level", f, arg)