From 0f8d2b6bed46dff4a5ab772be85529af4a03a8f1 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 31 Mar 2021 12:13:48 -0700 Subject: [PATCH] libct/cg/fs2.Stat: don't look for available controllers Some controllers might still have stats available even if they are disabled (this is definitely so for cpu.stat -- see earlier commit). Some stat methods might implement sensible fallbacks (see previous commit for statPids. In the view of all that, it makes sense to not check if a particular controller is available, but rather ignore ENOENT from it. Signed-off-by: Kir Kolyshkin --- libcontainer/cgroups/fs2/fs2.go | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/libcontainer/cgroups/fs2/fs2.go b/libcontainer/cgroups/fs2/fs2.go index 030527acd..0014371b4 100644 --- a/libcontainer/cgroups/fs2/fs2.go +++ b/libcontainer/cgroups/fs2/fs2.go @@ -103,25 +103,18 @@ func (m *manager) GetStats() (*cgroups.Stats, error) { ) st := cgroups.NewStats() - if err := m.getControllers(); err != nil { - return st, err - } // pids (since kernel 4.5) if err := statPids(m.dirPath, st); err != nil { errs = append(errs, err) } // memory (since kernel 4.5) - if _, ok := m.controllers["memory"]; ok { - if err := statMemory(m.dirPath, st); err != nil { - errs = append(errs, err) - } + if err := statMemory(m.dirPath, st); err != nil && !os.IsNotExist(err) { + errs = append(errs, err) } // io (since kernel 4.5) - if _, ok := m.controllers["io"]; ok { - if err := statIo(m.dirPath, st); err != nil { - errs = append(errs, err) - } + if err := statIo(m.dirPath, st); err != nil && !os.IsNotExist(err) { + errs = append(errs, err) } // cpu (since kernel 4.15) // Note cpu.stat is available even if the controller is not enabled. @@ -129,10 +122,8 @@ func (m *manager) GetStats() (*cgroups.Stats, error) { errs = append(errs, err) } // hugetlb (since kernel 5.6) - if _, ok := m.controllers["hugetlb"]; ok { - if err := statHugeTlb(m.dirPath, st); err != nil { - errs = append(errs, err) - } + if err := statHugeTlb(m.dirPath, st); err != nil && !os.IsNotExist(err) { + errs = append(errs, err) } if len(errs) > 0 && !m.rootless { return st, errors.Errorf("error while statting cgroup v2: %+v", errs)