2018-02-05 16:05:59 -05:00
|
|
|
package sysinfo // import "github.com/docker/docker/pkg/sysinfo"
|
2014-01-15 17:36:13 -05:00
|
|
|
|
2015-09-08 14:40:55 -04:00
|
|
|
import "github.com/docker/docker/pkg/parsers"
|
|
|
|
|
2021-07-14 09:05:12 -04:00
|
|
|
// Opt for New().
|
|
|
|
type Opt func(info *SysInfo)
|
|
|
|
|
2015-03-26 23:05:07 -04:00
|
|
|
// SysInfo stores information about which features a kernel supports.
|
2015-05-14 12:05:14 -04:00
|
|
|
// TODO Windows: Factor out platform specific capabilities.
|
2014-01-15 17:36:13 -05:00
|
|
|
type SysInfo struct {
|
2015-07-22 06:31:34 -04:00
|
|
|
// Whether the kernel supports AppArmor or not
|
2015-06-16 22:36:20 -04:00
|
|
|
AppArmor bool
|
2016-01-11 14:44:34 -05:00
|
|
|
// Whether the kernel supports Seccomp or not
|
|
|
|
Seccomp bool
|
2015-07-22 06:31:34 -04:00
|
|
|
|
2015-08-06 18:29:10 -04:00
|
|
|
cgroupMemInfo
|
|
|
|
cgroupCPUInfo
|
|
|
|
cgroupBlkioInfo
|
|
|
|
cgroupCpusetInfo
|
2015-12-15 14:15:43 -05:00
|
|
|
cgroupPids
|
2015-07-22 06:31:34 -04:00
|
|
|
|
2018-12-14 18:07:19 -05:00
|
|
|
// Whether the kernel supports cgroup namespaces or not
|
|
|
|
CgroupNamespaces bool
|
|
|
|
|
2015-07-22 06:31:34 -04: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 13:47:43 -05:00
|
|
|
BridgeNFCallIPTablesDisabled bool
|
2015-07-22 06:31:34 -04:00
|
|
|
|
|
|
|
// Whether bridge-nf-call-ip6tables is supported or not
|
2016-02-26 13:47:43 -05:00
|
|
|
BridgeNFCallIP6TablesDisabled bool
|
2015-07-22 06:31:34 -04:00
|
|
|
|
|
|
|
// Whether the cgroup has the mountpoint of "devices" or not
|
|
|
|
CgroupDevicesEnabled bool
|
2020-03-10 08:09:25 -04:00
|
|
|
|
|
|
|
// Whether the cgroup is in unified mode (v2).
|
|
|
|
CgroupUnified bool
|
2021-07-14 08:28:52 -04:00
|
|
|
|
2021-07-14 10:24:03 -04:00
|
|
|
// Warnings contains a slice of warnings that occurred while collecting
|
|
|
|
// system information. These warnings are intended to be informational
|
|
|
|
// messages for the user, and can either be logged or returned to the
|
|
|
|
// client; they are not intended to be parsed / used for other purposes,
|
|
|
|
// and do not have a fixed format.
|
|
|
|
Warnings []string
|
|
|
|
|
2021-07-14 08:28:52 -04:00
|
|
|
// cgMounts is the list of cgroup v1 mount paths, indexed by subsystem, to
|
|
|
|
// inspect availability of subsystems.
|
|
|
|
cgMounts map[string]string
|
2021-07-14 08:52:30 -04:00
|
|
|
|
|
|
|
// cg2GroupPath is the cgroup v2 group path to inspect availability of the controllers.
|
|
|
|
cg2GroupPath string
|
2021-07-14 09:44:38 -04:00
|
|
|
|
|
|
|
// cg2Controllers is an index of available cgroup v2 controllers.
|
|
|
|
cg2Controllers map[string]struct{}
|
2015-06-16 22:36:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type cgroupMemInfo struct {
|
2015-07-22 06:31:34 -04:00
|
|
|
// Whether memory limit is supported or not
|
|
|
|
MemoryLimit bool
|
|
|
|
|
|
|
|
// Whether swap limit is supported or not
|
|
|
|
SwapLimit bool
|
|
|
|
|
2015-09-23 02:02:45 -04:00
|
|
|
// Whether soft limit is supported or not
|
|
|
|
MemoryReservation bool
|
|
|
|
|
2015-12-13 11:00:39 -05:00
|
|
|
// Whether OOM killer disable is supported or not
|
2015-07-22 06:31:34 -04:00
|
|
|
OomKillDisable bool
|
|
|
|
|
|
|
|
// Whether memory swappiness is supported or not
|
2015-07-12 03:46:33 -04:00
|
|
|
MemorySwappiness bool
|
2015-08-19 11:56:55 -04:00
|
|
|
|
2022-02-07 11:09:23 -05:00
|
|
|
// Whether kernel memory limit is supported or not. This option is used to
|
|
|
|
// detect support for kernel-memory limits on API < v1.42. Kernel memory
|
|
|
|
// limit (`kmem.limit_in_bytes`) is not supported on cgroups v2, and has been
|
|
|
|
// removed in kernel 5.4.
|
2015-08-19 11:56:55 -04:00
|
|
|
KernelMemory bool
|
2018-05-11 15:46:11 -04:00
|
|
|
|
2022-02-07 11:09:23 -05:00
|
|
|
// Whether kernel memory TCP limit is supported or not. Kernel memory TCP
|
|
|
|
// limit (`memory.kmem.tcp.limit_in_bytes`) is not supported on cgroups v2.
|
2018-05-11 15:46:11 -04:00
|
|
|
KernelMemoryTCP bool
|
2015-06-16 22:36:20 -04:00
|
|
|
}
|
|
|
|
|
2015-07-22 06:31:34 -04:00
|
|
|
type cgroupCPUInfo struct {
|
2015-08-05 10:35:18 -04:00
|
|
|
// Whether CPU shares is supported or not
|
|
|
|
CPUShares bool
|
|
|
|
|
2020-05-22 17:18:06 -04:00
|
|
|
// Whether CPU CFS (Completely Fair Scheduler) is supported
|
|
|
|
CPUCfs bool
|
2015-07-22 06:31:34 -04:00
|
|
|
|
2020-05-22 17:18:06 -04:00
|
|
|
// Whether CPU real-time scheduler is supported
|
|
|
|
CPURealtime bool
|
2014-01-15 17:36:13 -05:00
|
|
|
}
|
2015-08-05 10:35:18 -04:00
|
|
|
|
|
|
|
type cgroupBlkioInfo struct {
|
|
|
|
// Whether Block IO weight is supported or not
|
|
|
|
BlkioWeight bool
|
2015-06-11 20:34:20 -04:00
|
|
|
|
|
|
|
// Whether Block IO weight_device is supported or not
|
|
|
|
BlkioWeightDevice bool
|
2015-07-08 07:06:48 -04: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 07:06:48 -04: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 10:35:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type cgroupCpusetInfo struct {
|
|
|
|
// Whether Cpuset is supported or not
|
|
|
|
Cpuset bool
|
2015-09-08 14:40:55 -04:00
|
|
|
|
|
|
|
// Available Cpuset's cpus
|
|
|
|
Cpus string
|
|
|
|
|
|
|
|
// Available Cpuset's memory nodes
|
|
|
|
Mems string
|
|
|
|
}
|
|
|
|
|
2015-12-15 14:15:43 -05:00
|
|
|
type cgroupPids struct {
|
|
|
|
// Whether Pids Limit is supported or not
|
|
|
|
PidsLimit bool
|
|
|
|
}
|
|
|
|
|
2015-09-08 14:40:55 -04: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) {
|
2018-09-04 10:49:09 -04:00
|
|
|
parsedAvailable, err := parsers.ParseUintList(available)
|
2015-09-08 14:40:55 -04:00
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
2018-09-04 10:49:09 -04:00
|
|
|
// 8192 is the normal maximum number of CPUs in Linux, so accept numbers up to this
|
|
|
|
// or more if we actually have more CPUs.
|
|
|
|
max := 8192
|
|
|
|
for m := range parsedAvailable {
|
|
|
|
if m > max {
|
|
|
|
max = m
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parsedProvided, err := parsers.ParseUintListMaximum(provided, max)
|
2015-09-08 14:40:55 -04:00
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
for k := range parsedProvided {
|
|
|
|
if !parsedAvailable[k] {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true, nil
|
2015-08-05 10:35:18 -04:00
|
|
|
}
|