From c95e69007c4f0a706485b211de8c83aa746739d0 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 24 Sep 2020 19:51:03 -0700 Subject: [PATCH] libct/cg/fs*: use fscommon.OpenFile Signed-off-by: Kir Kolyshkin --- libcontainer/cgroups/fs/cpu.go | 3 +-- libcontainer/cgroups/fs/cpuacct.go | 2 +- libcontainer/cgroups/fs/memory.go | 5 ++--- libcontainer/cgroups/fs2/cpu.go | 3 +-- libcontainer/cgroups/fs2/io.go | 4 +--- libcontainer/cgroups/fs2/memory.go | 3 +-- 6 files changed, 7 insertions(+), 13 deletions(-) diff --git a/libcontainer/cgroups/fs/cpu.go b/libcontainer/cgroups/fs/cpu.go index 6fb1c2078..1d5f455d6 100644 --- a/libcontainer/cgroups/fs/cpu.go +++ b/libcontainer/cgroups/fs/cpu.go @@ -6,7 +6,6 @@ import ( "bufio" "fmt" "os" - "path/filepath" "strconv" "github.com/opencontainers/runc/libcontainer/cgroups" @@ -87,7 +86,7 @@ func (s *CpuGroup) Set(path string, cgroup *configs.Cgroup) error { } func (s *CpuGroup) GetStats(path string, stats *cgroups.Stats) error { - f, err := os.Open(filepath.Join(path, "cpu.stat")) + f, err := fscommon.OpenFile(path, "cpu.stat", os.O_RDONLY) if err != nil { if os.IsNotExist(err) { return nil diff --git a/libcontainer/cgroups/fs/cpuacct.go b/libcontainer/cgroups/fs/cpuacct.go index 9ee1119cc..129de6a01 100644 --- a/libcontainer/cgroups/fs/cpuacct.go +++ b/libcontainer/cgroups/fs/cpuacct.go @@ -135,7 +135,7 @@ func getPercpuUsageInModes(path string) ([]uint64, []uint64, error) { usageKernelMode := []uint64{} usageUserMode := []uint64{} - file, err := os.Open(filepath.Join(path, cgroupCpuacctUsageAll)) + file, err := fscommon.OpenFile(path, cgroupCpuacctUsageAll, os.O_RDONLY) if os.IsNotExist(err) { return usageKernelMode, usageUserMode, nil } else if err != nil { diff --git a/libcontainer/cgroups/fs/memory.go b/libcontainer/cgroups/fs/memory.go index 2a2f0dd6c..7fde663d9 100644 --- a/libcontainer/cgroups/fs/memory.go +++ b/libcontainer/cgroups/fs/memory.go @@ -7,7 +7,6 @@ import ( "fmt" "math" "os" - "path" "path/filepath" "strconv" "strings" @@ -160,7 +159,7 @@ func (s *MemoryGroup) Set(path string, cgroup *configs.Cgroup) error { func (s *MemoryGroup) GetStats(path string, stats *cgroups.Stats) error { // Set stats from memory.stat. - statsFile, err := os.Open(filepath.Join(path, "memory.stat")) + statsFile, err := fscommon.OpenFile(path, "memory.stat", os.O_RDONLY) if err != nil { if os.IsNotExist(err) { return nil @@ -280,7 +279,7 @@ func getMemoryData(path, name string) (cgroups.MemoryData, error) { func getPageUsageByNUMA(cgroupPath string) (cgroups.PageUsageByNUMA, error) { stats := cgroups.PageUsageByNUMA{} - file, err := os.Open(path.Join(cgroupPath, cgroupMemoryPagesByNuma)) + file, err := fscommon.OpenFile(cgroupPath, cgroupMemoryPagesByNuma, os.O_RDONLY) if os.IsNotExist(err) { return stats, nil } else if err != nil { diff --git a/libcontainer/cgroups/fs2/cpu.go b/libcontainer/cgroups/fs2/cpu.go index edf1060ec..0dffe6648 100644 --- a/libcontainer/cgroups/fs2/cpu.go +++ b/libcontainer/cgroups/fs2/cpu.go @@ -5,7 +5,6 @@ package fs2 import ( "bufio" "os" - "path/filepath" "strconv" "github.com/opencontainers/runc/libcontainer/cgroups" @@ -50,7 +49,7 @@ func setCpu(dirPath string, cgroup *configs.Cgroup) error { return nil } func statCpu(dirPath string, stats *cgroups.Stats) error { - f, err := os.Open(filepath.Join(dirPath, "cpu.stat")) + f, err := fscommon.OpenFile(dirPath, "cpu.stat", os.O_RDONLY) if err != nil { return err } diff --git a/libcontainer/cgroups/fs2/io.go b/libcontainer/cgroups/fs2/io.go index bbe3ac064..e01ea001b 100644 --- a/libcontainer/cgroups/fs2/io.go +++ b/libcontainer/cgroups/fs2/io.go @@ -5,7 +5,6 @@ package fs2 import ( "bufio" "os" - "path/filepath" "strconv" "strings" @@ -60,8 +59,7 @@ func setIo(dirPath string, cgroup *configs.Cgroup) error { func readCgroup2MapFile(dirPath string, name string) (map[string][]string, error) { ret := map[string][]string{} - p := filepath.Join(dirPath, name) - f, err := os.Open(p) + f, err := fscommon.OpenFile(dirPath, name, os.O_RDONLY) if err != nil { return nil, err } diff --git a/libcontainer/cgroups/fs2/memory.go b/libcontainer/cgroups/fs2/memory.go index 68f2546c7..1c6913bf0 100644 --- a/libcontainer/cgroups/fs2/memory.go +++ b/libcontainer/cgroups/fs2/memory.go @@ -5,7 +5,6 @@ package fs2 import ( "bufio" "os" - "path/filepath" "strconv" "github.com/opencontainers/runc/libcontainer/cgroups" @@ -75,7 +74,7 @@ func setMemory(dirPath string, cgroup *configs.Cgroup) error { func statMemory(dirPath string, stats *cgroups.Stats) error { // Set stats from memory.stat. - statsFile, err := os.Open(filepath.Join(dirPath, "memory.stat")) + statsFile, err := fscommon.OpenFile(dirPath, "memory.stat", os.O_RDONLY) if err != nil { return err }