本文整理匯總了Golang中github.com/opencontainers/runc/libcontainer/cgroups.FindCgroupMountpoint函數的典型用法代碼示例。如果您正苦於以下問題:Golang FindCgroupMountpoint函數的具體用法?Golang FindCgroupMountpoint怎麽用?Golang FindCgroupMountpoint使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了FindCgroupMountpoint函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: checkCgroupMem
func checkCgroupMem(quiet bool) *cgroupMemInfo {
info := &cgroupMemInfo{}
mountPoint, err := cgroups.FindCgroupMountpoint("memory")
if err != nil {
if !quiet {
logrus.Warnf("Your kernel does not support cgroup memory limit: %v", err)
}
return info
}
info.MemoryLimit = true
info.SwapLimit = cgroupEnabled(mountPoint, "memory.memsw.limit_in_bytes")
if !quiet && !info.SwapLimit {
logrus.Warn("Your kernel does not support swap memory limit.")
}
info.OomKillDisable = cgroupEnabled(mountPoint, "memory.oom_control")
if !quiet && !info.OomKillDisable {
logrus.Warnf("Your kernel does not support oom control.")
}
info.MemorySwappiness = cgroupEnabled(mountPoint, "memory.swappiness")
if !quiet && !info.MemorySwappiness {
logrus.Warnf("Your kernel does not support memory swappiness.")
}
return info
}
示例2: checkCgroupCPU
func checkCgroupCPU(quiet bool) *cgroupCPUInfo {
info := &cgroupCPUInfo{}
mountPoint, err := cgroups.FindCgroupMountpoint("cpu")
if err != nil {
if !quiet {
logrus.Warn(err)
}
return info
}
info.CPUShares = cgroupEnabled(mountPoint, "cpu.shares")
if !quiet && !info.CPUShares {
logrus.Warn("Your kernel does not support cgroup cpu shares")
}
info.CPUCfsPeriod = cgroupEnabled(mountPoint, "cpu.cfs_period_us")
if !quiet && !info.CPUCfsPeriod {
logrus.Warn("Your kernel does not support cgroup cfs period")
}
info.CPUCfsQuota = cgroupEnabled(mountPoint, "cpu.cfs_quota_us")
if !quiet && !info.CPUCfsQuota {
logrus.Warn("Your kernel does not support cgroup cfs quotas")
}
return info
}
示例3: getSubsystemPath
func getSubsystemPath(c *configs.Cgroup, subsystem string) (string, error) {
mountpoint, err := cgroups.FindCgroupMountpoint(subsystem)
if err != nil {
return "", err
}
initPath, err := cgroups.GetInitCgroupDir(subsystem)
if err != nil {
return "", err
}
// if pid 1 is systemd 226 or later, it will be in init.scope, not the root
initPath = strings.TrimSuffix(filepath.Clean(initPath), "init.scope")
slice := "system.slice"
if c.Parent != "" {
slice = c.Parent
}
slice, err = ExpandSlice(slice)
if err != nil {
return "", err
}
return filepath.Join(mountpoint, initPath, slice, getUnitName(c)), nil
}
示例4: checkCgroupBlkioInfo
// checkCgroupBlkioInfo reads the blkio information from the blkio cgroup mount point.
func checkCgroupBlkioInfo(quiet bool) cgroupBlkioInfo {
mountPoint, err := cgroups.FindCgroupMountpoint("blkio")
if err != nil {
if !quiet {
logrus.Warn(err)
}
return cgroupBlkioInfo{}
}
weight := cgroupEnabled(mountPoint, "blkio.weight")
if !quiet && !weight {
logrus.Warn("Your kernel does not support cgroup blkio weight")
}
weightDevice := cgroupEnabled(mountPoint, "blkio.weight_device")
if !quiet && !weightDevice {
logrus.Warn("Your kernel does not support cgroup blkio weight_device")
}
readBpsDevice := cgroupEnabled(mountPoint, "blkio.throttle.read_bps_device")
if !quiet && !readBpsDevice {
logrus.Warn("Your kernel does not support cgroup blkio throttle.read_bps_device")
}
writeBpsDevice := cgroupEnabled(mountPoint, "blkio.throttle.write_bps_device")
if !quiet && !writeBpsDevice {
logrus.Warn("Your kernel does not support cgroup blkio throttle.write_bps_device")
}
return cgroupBlkioInfo{
BlkioWeight: weight,
BlkioWeightDevice: weightDevice,
BlkioReadBpsDevice: readBpsDevice,
BlkioWriteBpsDevice: writeBpsDevice,
}
}
示例5: New
// New returns a new SysInfo, using the filesystem to detect which features
// the kernel supports. If `quiet` is `false` warnings are printed in logs
// whenever an error occurs or misconfigurations are present.
func New(quiet bool) *SysInfo {
sysInfo := &SysInfo{}
sysInfo.cgroupMemInfo = checkCgroupMem(quiet)
sysInfo.cgroupCPUInfo = checkCgroupCPU(quiet)
sysInfo.cgroupBlkioInfo = checkCgroupBlkioInfo(quiet)
sysInfo.cgroupCpusetInfo = checkCgroupCpusetInfo(quiet)
_, err := cgroups.FindCgroupMountpoint("devices")
sysInfo.CgroupDevicesEnabled = err == nil
sysInfo.IPv4ForwardingDisabled = !readProcBool("/proc/sys/net/ipv4/ip_forward")
sysInfo.BridgeNfCallIptablesDisabled = !readProcBool("/proc/sys/net/bridge/bridge-nf-call-iptables")
sysInfo.BridgeNfCallIP6tablesDisabled = !readProcBool("/proc/sys/net/bridge/bridge-nf-call-ip6tables")
// Check if AppArmor is supported.
if _, err := os.Stat("/sys/kernel/security/apparmor"); !os.IsNotExist(err) {
sysInfo.AppArmor = true
}
// Check if Seccomp is supported, via CONFIG_SECCOMP.
if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, syscall.PR_GET_SECCOMP, 0, 0); err != syscall.EINVAL {
// Make sure the kernel has CONFIG_SECCOMP_FILTER.
if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, syscall.PR_SET_SECCOMP, SeccompModeFilter, 0); err != syscall.EINVAL {
sysInfo.Seccomp = true
}
}
return sysInfo
}
示例6: checkCgroupMem
// checkCgroupMem reads the memory information from the memory cgroup mount point.
func checkCgroupMem(quiet bool) cgroupMemInfo {
mountPoint, err := cgroups.FindCgroupMountpoint("memory")
if err != nil {
if !quiet {
logrus.Warnf("Your kernel does not support cgroup memory limit: %v", err)
}
return cgroupMemInfo{}
}
swapLimit := cgroupEnabled(mountPoint, "memory.memsw.limit_in_bytes")
if !quiet && !swapLimit {
logrus.Warn("Your kernel does not support swap memory limit.")
}
oomKillDisable := cgroupEnabled(mountPoint, "memory.oom_control")
if !quiet && !oomKillDisable {
logrus.Warnf("Your kernel does not support oom control.")
}
memorySwappiness := cgroupEnabled(mountPoint, "memory.swappiness")
if !quiet && !memorySwappiness {
logrus.Warnf("Your kernel does not support memory swappiness.")
}
return cgroupMemInfo{
MemoryLimit: true,
SwapLimit: swapLimit,
OomKillDisable: oomKillDisable,
MemorySwappiness: memorySwappiness,
}
}
示例7: checkCgroupCpusetInfo
// checkCgroupCpusetInfo reads the cpuset information from the cpuset cgroup mount point.
func checkCgroupCpusetInfo(quiet bool) cgroupCpusetInfo {
mountPoint, err := cgroups.FindCgroupMountpoint("cpuset")
if err != nil {
if !quiet {
logrus.Warn(err)
}
return cgroupCpusetInfo{}
}
cpus, err := ioutil.ReadFile(path.Join(mountPoint, "cpuset.cpus"))
if err != nil {
return cgroupCpusetInfo{}
}
mems, err := ioutil.ReadFile(path.Join(mountPoint, "cpuset.mems"))
if err != nil {
return cgroupCpusetInfo{}
}
return cgroupCpusetInfo{
Cpuset: true,
Cpus: strings.TrimSpace(string(cpus)),
Mems: strings.TrimSpace(string(mems)),
}
}
示例8: checkCgroupCPU
// checkCgroupCPU reads the cpu information from the cpu cgroup mount point.
func checkCgroupCPU(quiet bool) cgroupCPUInfo {
mountPoint, err := cgroups.FindCgroupMountpoint("cpu")
if err != nil {
if !quiet {
logrus.Warn(err)
}
return cgroupCPUInfo{}
}
cpuShares := cgroupEnabled(mountPoint, "cpu.shares")
if !quiet && !cpuShares {
logrus.Warn("Your kernel does not support cgroup cpu shares")
}
cpuCfsPeriod := cgroupEnabled(mountPoint, "cpu.cfs_period_us")
if !quiet && !cpuCfsPeriod {
logrus.Warn("Your kernel does not support cgroup cfs period")
}
cpuCfsQuota := cgroupEnabled(mountPoint, "cpu.cfs_quota_us")
if !quiet && !cpuCfsQuota {
logrus.Warn("Your kernel does not support cgroup cfs quotas")
}
return cgroupCPUInfo{
CPUShares: cpuShares,
CPUCfsPeriod: cpuCfsPeriod,
CPUCfsQuota: cpuCfsQuota,
}
}
示例9: setupCGroups
func setupCGroups(partitions map[string]int64) error {
subsystems, err := cgroups.GetAllSubsystems()
if err != nil {
return fmt.Errorf("error getting cgroup subsystems: %s", err)
} else if len(subsystems) == 0 {
return fmt.Errorf("failed to detect any cgroup subsystems")
}
for _, subsystem := range subsystems {
if _, err := cgroups.FindCgroupMountpoint(subsystem); err == nil {
// subsystem already mounted
continue
}
path := filepath.Join(cgroupRoot, subsystem)
if err := os.Mkdir(path, 0755); err != nil && !os.IsExist(err) {
return fmt.Errorf("error creating %s cgroup directory: %s", subsystem, err)
}
if err := syscall.Mount("cgroup", path, "cgroup", 0, subsystem); err != nil {
return fmt.Errorf("error mounting %s cgroup: %s", subsystem, err)
}
}
for name, shares := range partitions {
if err := createCGroupPartition(name, shares); err != nil {
return err
}
}
return nil
}
示例10: getSubsystemPath
func getSubsystemPath(subsystem string, id string) (string, error) {
var subsystemPath string
systemSlice := "system.slice"
// hack for finding proper mount point for shares
// cpu shares are part of cpu group, but openlibcontainers does not support it
if subsystem == "shares" {
subsystem = "cpu"
}
groupPath, err := cgroups.FindCgroupMountpoint(subsystem)
if err != nil {
fmt.Fprintf(os.Stderr, "[WARNING] Could not find mount point for %v\n", subsystem)
return "", err
}
if isHost(id) {
if isRunningSystemd() {
subsystemPath = filepath.Join(groupPath, systemSlice)
} else {
subsystemPath = groupPath
}
return subsystemPath, nil
}
if isFsCgroupParent(groupPath) {
// default cgroupfs parent is used for container
subsystemPath = filepath.Join(groupPath, "docker", id)
} else {
// cgroup is created under systemd.slice
subsystemPath = filepath.Join(groupPath, systemSlice, "docker-"+id+".scope")
}
return subsystemPath, nil
}
示例11: checkCgroupCpusetInfo
// checkCgroupCpusetInfo reads the cpuset information from the cpuset cgroup mount point.
func checkCgroupCpusetInfo(quiet bool) cgroupCpusetInfo {
_, err := cgroups.FindCgroupMountpoint("cpuset")
if err != nil {
if !quiet {
logrus.Warn(err)
}
return cgroupCpusetInfo{}
}
return cgroupCpusetInfo{Cpuset: true}
}
示例12: findCgroupRootAndDir
func findCgroupRootAndDir(subsystem string) (string, string, error) {
cgroupRoot, err := cgroups.FindCgroupMountpoint(subsystem)
if err != nil {
return "", "", err
}
cgroupDir, err := cgroups.GetThisCgroupDir(subsystem)
if err != nil {
return "", "", err
}
return cgroupRoot, cgroupDir, nil
}
示例13: createCgroupdir
func createCgroupdir(dir string) error {
for _, subsystem := range []string{"memory", "cpu", "cpuset", "blkio"} {
subsystemDir, err := cgroups.FindCgroupMountpoint(subsystem)
if err != nil {
return err
}
if err := os.MkdirAll(filepath.Join(subsystemDir, dir), 0700); err != nil {
return err
}
}
return nil
}
示例14: apply
func (h *cgroupfsHelper) apply(subsystem, file, data string) error {
subsystemDir, err := cgroups.FindCgroupMountpoint(subsystem)
if err != nil {
return err
}
if err := os.MkdirAll(filepath.Join(subsystemDir, h.cgroupDir), 0700); err != nil {
return err
}
if err := writeFile(filepath.Join(subsystemDir, h.cgroupDir), file, data); err != nil {
return err
}
return nil
}
示例15: checkCgroupCpusetInfo
func checkCgroupCpusetInfo(quiet bool) *cgroupCpusetInfo {
info := &cgroupCpusetInfo{}
_, err := cgroups.FindCgroupMountpoint("cpuset")
if err != nil {
if !quiet {
logrus.Warn(err)
}
return info
}
info.Cpuset = true
return info
}