mount: don't read /proc/self/cgroup many times

Signed-off-by: Andrey Vagin <avagin@openvz.org>
This commit is contained in:
Andrey Vagin 2015-09-10 11:58:08 +03:00
parent e49c1dc559
commit da2535f2d1
2 changed files with 8 additions and 3 deletions

View File

@ -98,12 +98,12 @@ type Mount struct {
Subsystems []string Subsystems []string
} }
func (m Mount) GetThisCgroupDir() (string, error) { func (m Mount) GetThisCgroupDir(cgroups map[string]string) (string, error) {
if len(m.Subsystems) == 0 { if len(m.Subsystems) == 0 {
return "", fmt.Errorf("no subsystem for mount") return "", fmt.Errorf("no subsystem for mount")
} }
return GetThisCgroupDir(m.Subsystems[0]) return getControllerPath(m.Subsystems[0], cgroups)
} }
func GetCgroupMounts() ([]Mount, error) { func GetCgroupMounts() ([]Mount, error) {

View File

@ -253,10 +253,15 @@ func getCgroupMounts(m *configs.Mount) ([]*configs.Mount, error) {
return nil, err return nil, err
} }
cgroupPaths, err := cgroups.ParseCgroupFile("/proc/self/cgroup")
if err != nil {
return nil, err
}
var binds []*configs.Mount var binds []*configs.Mount
for _, mm := range mounts { for _, mm := range mounts {
dir, err := mm.GetThisCgroupDir() dir, err := mm.GetThisCgroupDir(cgroupPaths)
if err != nil { if err != nil {
return nil, err return nil, err
} }