Skip to content

Commit

Permalink
libcontainer/intelrdt: use moby/sys/mountinfo
Browse files Browse the repository at this point in the history
It might be a tad slower but it surely more correct and well maintained,
so it's better to use it than rely on a custom implementation which is
kind of hard to get entirely right.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Sep 29, 2020
1 parent 43d2b10 commit f1c1fdf
Showing 1 changed file with 15 additions and 33 deletions.
48 changes: 15 additions & 33 deletions libcontainer/intelrdt/intelrdt.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"
"sync"

"github.com/moby/sys/mountinfo"
"github.com/opencontainers/runc/libcontainer/configs"
)

Expand Down Expand Up @@ -241,45 +242,26 @@ func init() {

// Return the mount point path of Intel RDT "resource control" filesysem
func findIntelRdtMountpointDir() (string, error) {
f, err := os.Open("/proc/self/mountinfo")
mi, err := mountinfo.GetMounts(func(m *mountinfo.Info) (bool, bool) {
// similar to mountinfo.FstypeFilter but stops after the first match
if m.Fstype == "resctrl" {
return false, true // don't skip, stop
}
return true, false // skip, keep going
})
if err != nil {
return "", err
}
defer f.Close()

s := bufio.NewScanner(f)
for s.Scan() {
text := s.Text()
fields := strings.Split(text, " ")
// Safe as mountinfo encodes mountpoints with spaces as \040.
index := strings.Index(text, " - ")
postSeparatorFields := strings.Fields(text[index+3:])
numPostFields := len(postSeparatorFields)

// This is an error as we can't detect if the mount is for "Intel RDT"
if numPostFields == 0 {
return "", fmt.Errorf("Found no fields post '-' in %q", text)
}

if postSeparatorFields[0] == "resctrl" {
// Check that the mount is properly formatted.
if numPostFields < 3 {
return "", fmt.Errorf("Error found less than 3 fields post '-' in %q", text)
}

// Check if MBA Software Controller is enabled through mount option "-o mba_MBps"
if strings.Contains(postSeparatorFields[2], "mba_MBps") {
isMbaScEnabled = true
}

return fields[4], nil
}
if len(mi) < 1 {
return "", NewNotFoundError("Intel RDT")
}
if err := s.Err(); err != nil {
return "", err

// Check if MBA Software Controller is enabled through mount option "-o mba_MBps"
if strings.Contains(","+mi[0].VfsOpts+",", ",mba_MBps,") {
isMbaScEnabled = true
}

return "", NewNotFoundError("Intel RDT")
return mi[0].Mountpoint, nil
}

// Gets the root path of Intel RDT "resource control" filesystem
Expand Down

0 comments on commit f1c1fdf

Please sign in to comment.