From 78e1a4fc2eae56c6325e51a65110aa4c9a3931ce Mon Sep 17 00:00:00 2001 From: Tatsushi Inagaki Date: Mon, 29 Feb 2016 16:51:01 +0900 Subject: [PATCH] Selinux: reduce redundant parsing of mountinfo Avoid parsing the whole lines of mountinfo after the mountpoint is found. Signed-off-by: Tatsushi Inagaki --- libcontainer/selinux/selinux.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/libcontainer/selinux/selinux.go b/libcontainer/selinux/selinux.go index e28ece4a..a6cf7f20 100644 --- a/libcontainer/selinux/selinux.go +++ b/libcontainer/selinux/selinux.go @@ -16,7 +16,6 @@ import ( "sync" "syscall" - "github.com/docker/docker/pkg/mount" "github.com/opencontainers/runc/libcontainer/system" ) @@ -60,16 +59,31 @@ func getSelinuxMountPoint() string { } selinuxfs = "" - mounts, err := mount.GetMounts() + f, err := os.Open("/proc/self/mountinfo") if err != nil { return selinuxfs } - for _, mount := range mounts { - if mount.Fstype == "selinuxfs" { - selinuxfs = mount.Mountpoint - break + defer f.Close() + + scanner := bufio.NewScanner(f) + for scanner.Scan() { + txt := scanner.Text() + // Safe as mountinfo encodes mountpoints with spaces as \040. + sepIdx := strings.Index(txt, " - ") + if sepIdx == -1 { + continue } + if !strings.Contains(txt[sepIdx:], "selinuxfs") { + continue + } + fields := strings.Split(txt, " ") + if len(fields) < 5 { + continue + } + selinuxfs = fields[4] + break } + if selinuxfs != "" { var buf syscall.Statfs_t syscall.Statfs(selinuxfs, &buf)