gopkg.in/docker/docker.v23@v23.0.11/pkg/sysinfo/sysinfo.go (about) 1 package sysinfo // import "github.com/docker/docker/pkg/sysinfo" 2 3 import "github.com/docker/docker/pkg/parsers" 4 5 // Opt for New(). 6 type Opt func(info *SysInfo) 7 8 // SysInfo stores information about which features a kernel supports. 9 // TODO Windows: Factor out platform specific capabilities. 10 type SysInfo struct { 11 // Whether the kernel supports AppArmor or not 12 AppArmor bool 13 // Whether the kernel supports Seccomp or not 14 Seccomp bool 15 16 cgroupMemInfo 17 cgroupCPUInfo 18 cgroupBlkioInfo 19 cgroupCpusetInfo 20 cgroupPids 21 22 // Whether the kernel supports cgroup namespaces or not 23 CgroupNamespaces bool 24 25 // Whether IPv4 forwarding is supported or not, if this was disabled, networking will not work 26 IPv4ForwardingDisabled bool 27 28 // Whether bridge-nf-call-iptables is supported or not 29 BridgeNFCallIPTablesDisabled bool 30 31 // Whether bridge-nf-call-ip6tables is supported or not 32 BridgeNFCallIP6TablesDisabled bool 33 34 // Whether the cgroup has the mountpoint of "devices" or not 35 CgroupDevicesEnabled bool 36 37 // Whether the cgroup is in unified mode (v2). 38 CgroupUnified bool 39 40 // Warnings contains a slice of warnings that occurred while collecting 41 // system information. These warnings are intended to be informational 42 // messages for the user, and can either be logged or returned to the 43 // client; they are not intended to be parsed / used for other purposes, 44 // and do not have a fixed format. 45 Warnings []string 46 47 // cgMounts is the list of cgroup v1 mount paths, indexed by subsystem, to 48 // inspect availability of subsystems. 49 cgMounts map[string]string 50 51 // cg2GroupPath is the cgroup v2 group path to inspect availability of the controllers. 52 cg2GroupPath string 53 54 // cg2Controllers is an index of available cgroup v2 controllers. 55 cg2Controllers map[string]struct{} 56 } 57 58 type cgroupMemInfo struct { 59 // Whether memory limit is supported or not 60 MemoryLimit bool 61 62 // Whether swap limit is supported or not 63 SwapLimit bool 64 65 // Whether soft limit is supported or not 66 MemoryReservation bool 67 68 // Whether OOM killer disable is supported or not 69 OomKillDisable bool 70 71 // Whether memory swappiness is supported or not 72 MemorySwappiness bool 73 74 // Whether kernel memory limit is supported or not. This option is used to 75 // detect support for kernel-memory limits on API < v1.42. Kernel memory 76 // limit (`kmem.limit_in_bytes`) is not supported on cgroups v2, and has been 77 // removed in kernel 5.4. 78 KernelMemory bool 79 80 // Whether kernel memory TCP limit is supported or not. Kernel memory TCP 81 // limit (`memory.kmem.tcp.limit_in_bytes`) is not supported on cgroups v2. 82 KernelMemoryTCP bool 83 } 84 85 type cgroupCPUInfo struct { 86 // Whether CPU shares is supported or not 87 CPUShares bool 88 89 // Whether CPU CFS (Completely Fair Scheduler) is supported 90 CPUCfs bool 91 92 // Whether CPU real-time scheduler is supported 93 CPURealtime bool 94 } 95 96 type cgroupBlkioInfo struct { 97 // Whether Block IO weight is supported or not 98 BlkioWeight bool 99 100 // Whether Block IO weight_device is supported or not 101 BlkioWeightDevice bool 102 103 // Whether Block IO read limit in bytes per second is supported or not 104 BlkioReadBpsDevice bool 105 106 // Whether Block IO write limit in bytes per second is supported or not 107 BlkioWriteBpsDevice bool 108 109 // Whether Block IO read limit in IO per second is supported or not 110 BlkioReadIOpsDevice bool 111 112 // Whether Block IO write limit in IO per second is supported or not 113 BlkioWriteIOpsDevice bool 114 } 115 116 type cgroupCpusetInfo struct { 117 // Whether Cpuset is supported or not 118 Cpuset bool 119 120 // Available Cpuset's cpus 121 Cpus string 122 123 // Available Cpuset's memory nodes 124 Mems string 125 } 126 127 type cgroupPids struct { 128 // Whether Pids Limit is supported or not 129 PidsLimit bool 130 } 131 132 // IsCpusetCpusAvailable returns `true` if the provided string set is contained 133 // in cgroup's cpuset.cpus set, `false` otherwise. 134 // If error is not nil a parsing error occurred. 135 func (c cgroupCpusetInfo) IsCpusetCpusAvailable(provided string) (bool, error) { 136 return isCpusetListAvailable(provided, c.Cpus) 137 } 138 139 // IsCpusetMemsAvailable returns `true` if the provided string set is contained 140 // in cgroup's cpuset.mems set, `false` otherwise. 141 // If error is not nil a parsing error occurred. 142 func (c cgroupCpusetInfo) IsCpusetMemsAvailable(provided string) (bool, error) { 143 return isCpusetListAvailable(provided, c.Mems) 144 } 145 146 func isCpusetListAvailable(provided, available string) (bool, error) { 147 parsedAvailable, err := parsers.ParseUintList(available) 148 if err != nil { 149 return false, err 150 } 151 // 8192 is the normal maximum number of CPUs in Linux, so accept numbers up to this 152 // or more if we actually have more CPUs. 153 max := 8192 154 for m := range parsedAvailable { 155 if m > max { 156 max = m 157 } 158 } 159 parsedProvided, err := parsers.ParseUintListMaximum(provided, max) 160 if err != nil { 161 return false, err 162 } 163 for k := range parsedProvided { 164 if !parsedAvailable[k] { 165 return false, nil 166 } 167 } 168 return true, nil 169 }