2014-01-15 22:36:13 +00:00
|
|
|
package sysinfo
|
|
|
|
|
2016-07-15 17:46:15 +00:00
|
|
|
import "github.com/containers/storage/pkg/parsers"
|
2015-09-08 18:40:55 +00:00
|
|
|
|
2015-03-27 03:05:07 +00:00
|
|
|
// SysInfo stores information about which features a kernel supports.
|
2015-05-14 16:05:14 +00:00
|
|
|
// TODO Windows: Factor out platform specific capabilities.
|
2014-01-15 22:36:13 +00:00
|
|
|
type SysInfo struct {
|
2015-07-22 10:31:34 +00:00
|
|
|
// Whether the kernel supports AppArmor or not
|
2015-06-17 02:36:20 +00:00
|
|
|
AppArmor bool
|
2016-01-11 19:44:34 +00:00
|
|
|
// Whether the kernel supports Seccomp or not
|
|
|
|
Seccomp bool
|
2015-07-22 10:31:34 +00:00
|
|
|
|
2015-08-06 22:29:10 +00:00
|
|
|
cgroupMemInfo
|
|
|
|
cgroupCPUInfo
|
|
|
|
cgroupBlkioInfo
|
|
|
|
cgroupCpusetInfo
|
2015-12-15 19:15:43 +00:00
|
|
|
cgroupPids
|
2015-07-22 10:31:34 +00:00
|
|
|
|
|
|
|
// Whether IPv4 forwarding is supported or not, if this was disabled, networking will not work
|
|
|
|
IPv4ForwardingDisabled bool
|
|
|
|
|
|
|
|
// Whether bridge-nf-call-iptables is supported or not
|
2016-02-26 18:47:43 +00:00
|
|
|
BridgeNFCallIPTablesDisabled bool
|
2015-07-22 10:31:34 +00:00
|
|
|
|
|
|
|
// Whether bridge-nf-call-ip6tables is supported or not
|
2016-02-26 18:47:43 +00:00
|
|
|
BridgeNFCallIP6TablesDisabled bool
|
2015-07-22 10:31:34 +00:00
|
|
|
|
|
|
|
// Whether the cgroup has the mountpoint of "devices" or not
|
|
|
|
CgroupDevicesEnabled bool
|
2015-06-17 02:36:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type cgroupMemInfo struct {
|
2015-07-22 10:31:34 +00:00
|
|
|
// Whether memory limit is supported or not
|
|
|
|
MemoryLimit bool
|
|
|
|
|
|
|
|
// Whether swap limit is supported or not
|
|
|
|
SwapLimit bool
|
|
|
|
|
2015-09-23 06:02:45 +00:00
|
|
|
// Whether soft limit is supported or not
|
|
|
|
MemoryReservation bool
|
|
|
|
|
2015-12-13 16:00:39 +00:00
|
|
|
// Whether OOM killer disable is supported or not
|
2015-07-22 10:31:34 +00:00
|
|
|
OomKillDisable bool
|
|
|
|
|
|
|
|
// Whether memory swappiness is supported or not
|
2015-07-12 07:46:33 +00:00
|
|
|
MemorySwappiness bool
|
2015-08-19 15:56:55 +00:00
|
|
|
|
|
|
|
// Whether kernel memory limit is supported or not
|
|
|
|
KernelMemory bool
|
2015-06-17 02:36:20 +00:00
|
|
|
}
|
|
|
|
|
2015-07-22 10:31:34 +00:00
|
|
|
type cgroupCPUInfo struct {
|
2015-08-05 14:35:18 +00:00
|
|
|
// Whether CPU shares is supported or not
|
|
|
|
CPUShares bool
|
|
|
|
|
2015-07-22 10:31:34 +00:00
|
|
|
// Whether CPU CFS(Completely Fair Scheduler) period is supported or not
|
|
|
|
CPUCfsPeriod bool
|
|
|
|
|
|
|
|
// Whether CPU CFS(Completely Fair Scheduler) quota is supported or not
|
|
|
|
CPUCfsQuota bool
|
2014-01-15 22:36:13 +00:00
|
|
|
}
|
2015-08-05 14:35:18 +00:00
|
|
|
|
|
|
|
type cgroupBlkioInfo struct {
|
|
|
|
// Whether Block IO weight is supported or not
|
|
|
|
BlkioWeight bool
|
2015-06-12 00:34:20 +00:00
|
|
|
|
|
|
|
// Whether Block IO weight_device is supported or not
|
|
|
|
BlkioWeightDevice bool
|
2015-07-08 11:06:48 +00:00
|
|
|
|
|
|
|
// Whether Block IO read limit in bytes per second is supported or not
|
|
|
|
BlkioReadBpsDevice bool
|
|
|
|
|
|
|
|
// Whether Block IO write limit in bytes per second is supported or not
|
|
|
|
BlkioWriteBpsDevice bool
|
2015-07-08 11:06:48 +00:00
|
|
|
|
|
|
|
// Whether Block IO read limit in IO per second is supported or not
|
|
|
|
BlkioReadIOpsDevice bool
|
|
|
|
|
|
|
|
// Whether Block IO write limit in IO per second is supported or not
|
|
|
|
BlkioWriteIOpsDevice bool
|
2015-08-05 14:35:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type cgroupCpusetInfo struct {
|
|
|
|
// Whether Cpuset is supported or not
|
|
|
|
Cpuset bool
|
2015-09-08 18:40:55 +00:00
|
|
|
|
|
|
|
// Available Cpuset's cpus
|
|
|
|
Cpus string
|
|
|
|
|
|
|
|
// Available Cpuset's memory nodes
|
|
|
|
Mems string
|
|
|
|
}
|
|
|
|
|
2015-12-15 19:15:43 +00:00
|
|
|
type cgroupPids struct {
|
|
|
|
// Whether Pids Limit is supported or not
|
|
|
|
PidsLimit bool
|
|
|
|
}
|
|
|
|
|
2015-09-08 18:40:55 +00:00
|
|
|
// IsCpusetCpusAvailable returns `true` if the provided string set is contained
|
|
|
|
// in cgroup's cpuset.cpus set, `false` otherwise.
|
|
|
|
// If error is not nil a parsing error occurred.
|
|
|
|
func (c cgroupCpusetInfo) IsCpusetCpusAvailable(provided string) (bool, error) {
|
|
|
|
return isCpusetListAvailable(provided, c.Cpus)
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsCpusetMemsAvailable returns `true` if the provided string set is contained
|
|
|
|
// in cgroup's cpuset.mems set, `false` otherwise.
|
|
|
|
// If error is not nil a parsing error occurred.
|
|
|
|
func (c cgroupCpusetInfo) IsCpusetMemsAvailable(provided string) (bool, error) {
|
|
|
|
return isCpusetListAvailable(provided, c.Mems)
|
|
|
|
}
|
|
|
|
|
|
|
|
func isCpusetListAvailable(provided, available string) (bool, error) {
|
|
|
|
parsedProvided, err := parsers.ParseUintList(provided)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
parsedAvailable, err := parsers.ParseUintList(available)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
for k := range parsedProvided {
|
|
|
|
if !parsedAvailable[k] {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true, nil
|
2015-08-05 14:35:18 +00:00
|
|
|
}
|
2016-06-26 05:14:09 +00:00
|
|
|
|
|
|
|
// Returns bit count of 1, used by NumCPU
|
|
|
|
func popcnt(x uint64) (n byte) {
|
|
|
|
x -= (x >> 1) & 0x5555555555555555
|
|
|
|
x = (x>>2)&0x3333333333333333 + x&0x3333333333333333
|
|
|
|
x += x >> 4
|
|
|
|
x &= 0x0f0f0f0f0f0f0f0f
|
|
|
|
x *= 0x0101010101010101
|
|
|
|
return byte(x >> 56)
|
|
|
|
}
|