mirror of
https://github.com/opencontainers/runc.git
synced 2025-10-05 15:37:02 +08:00
libct/cg/fs*: use fscommon.OpenFile
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/opencontainers/runc/libcontainer/cgroups"
|
"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 {
|
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 err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil
|
return nil
|
||||||
|
@@ -135,7 +135,7 @@ func getPercpuUsageInModes(path string) ([]uint64, []uint64, error) {
|
|||||||
usageKernelMode := []uint64{}
|
usageKernelMode := []uint64{}
|
||||||
usageUserMode := []uint64{}
|
usageUserMode := []uint64{}
|
||||||
|
|
||||||
file, err := os.Open(filepath.Join(path, cgroupCpuacctUsageAll))
|
file, err := fscommon.OpenFile(path, cgroupCpuacctUsageAll, os.O_RDONLY)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return usageKernelMode, usageUserMode, nil
|
return usageKernelMode, usageUserMode, nil
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
@@ -7,7 +7,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"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 {
|
func (s *MemoryGroup) GetStats(path string, stats *cgroups.Stats) error {
|
||||||
// Set stats from memory.stat.
|
// 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 err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil
|
return nil
|
||||||
@@ -280,7 +279,7 @@ func getMemoryData(path, name string) (cgroups.MemoryData, error) {
|
|||||||
func getPageUsageByNUMA(cgroupPath string) (cgroups.PageUsageByNUMA, error) {
|
func getPageUsageByNUMA(cgroupPath string) (cgroups.PageUsageByNUMA, error) {
|
||||||
stats := cgroups.PageUsageByNUMA{}
|
stats := cgroups.PageUsageByNUMA{}
|
||||||
|
|
||||||
file, err := os.Open(path.Join(cgroupPath, cgroupMemoryPagesByNuma))
|
file, err := fscommon.OpenFile(cgroupPath, cgroupMemoryPagesByNuma, os.O_RDONLY)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return stats, nil
|
return stats, nil
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
@@ -5,7 +5,6 @@ package fs2
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/opencontainers/runc/libcontainer/cgroups"
|
"github.com/opencontainers/runc/libcontainer/cgroups"
|
||||||
@@ -50,7 +49,7 @@ func setCpu(dirPath string, cgroup *configs.Cgroup) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func statCpu(dirPath string, stats *cgroups.Stats) error {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -5,7 +5,6 @@ package fs2
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -60,8 +59,7 @@ func setIo(dirPath string, cgroup *configs.Cgroup) error {
|
|||||||
|
|
||||||
func readCgroup2MapFile(dirPath string, name string) (map[string][]string, error) {
|
func readCgroup2MapFile(dirPath string, name string) (map[string][]string, error) {
|
||||||
ret := map[string][]string{}
|
ret := map[string][]string{}
|
||||||
p := filepath.Join(dirPath, name)
|
f, err := fscommon.OpenFile(dirPath, name, os.O_RDONLY)
|
||||||
f, err := os.Open(p)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@@ -5,7 +5,6 @@ package fs2
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/opencontainers/runc/libcontainer/cgroups"
|
"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 {
|
func statMemory(dirPath string, stats *cgroups.Stats) error {
|
||||||
// Set stats from memory.stat.
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user