Skip to content

Commit

Permalink
libct/cg/fs.getMount: reuse cgroups.GetCgroupMountinfo
Browse files Browse the repository at this point in the history
Reuse cgroups.GetCgroupMountinfo instead of parsing mountinfo directly.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Sep 23, 2020
1 parent 46cf618 commit 529dd48
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions libcontainer/cgroups/fs/cpuset.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/moby/sys/mountinfo"
"github.com/opencontainers/runc/libcontainer/cgroups"
"github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
"github.com/opencontainers/runc/libcontainer/configs"
Expand Down Expand Up @@ -47,19 +47,23 @@ func (s *CpusetGroup) GetStats(path string, stats *cgroups.Stats) error {

// Get the source mount point of directory passed in as argument.
func getMount(dir string) (string, error) {
mi, err := mountinfo.GetMounts(mountinfo.ParentsFilter(dir))
mi, err := cgroups.ReadCgroupMountinfo()
if err != nil {
return "", err
}
if len(mi) < 1 {
return "", errors.Errorf("Can't find mount point of %s", dir)
}

// find the longest mount point
// find the longest mount point which can be a parent of dir
var idx, maxlen int
for i := range mi {
if len(mi[i].Mountpoint) > maxlen {
maxlen = len(mi[i].Mountpoint)
mp := mi[i].Mountpoint
if !strings.HasPrefix(dir, mp) {
continue
}
if len(mp) > maxlen {
maxlen = len(mp)
idx = i
}
}
Expand Down

0 comments on commit 529dd48

Please sign in to comment.