github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/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 // SysInfo stores information about which features a kernel supports. 6 // TODO Windows: Factor out platform specific capabilities. 7 type SysInfo struct { 8 // Whether the kernel supports AppArmor or not 9 AppArmor bool 10 // Whether the kernel supports Seccomp or not 11 Seccomp bool 12 13 cgroupMemInfo 14 cgroupCPUInfo 15 cgroupBlkioInfo 16 cgroupCpusetInfo 17 cgroupPids 18 19 // Whether the kernel supports cgroup namespaces or not 20 CgroupNamespaces bool 21 22 // Whether IPv4 forwarding is supported or not, if this was disabled, networking will not work 23 IPv4ForwardingDisabled bool 24 25 // Whether bridge-nf-call-iptables is supported or not 26 BridgeNFCallIPTablesDisabled bool 27 28 // Whether bridge-nf-call-ip6tables is supported or not 29 BridgeNFCallIP6TablesDisabled bool 30 31 // Whether the cgroup has the mountpoint of "devices" or not 32 CgroupDevicesEnabled bool 33 34 // Whether the cgroup is in unified mode (v2). 35 CgroupUnified bool 36 } 37 38 type cgroupMemInfo struct { 39 // Whether memory limit is supported or not 40 MemoryLimit bool 41 42 // Whether swap limit is supported or not 43 SwapLimit bool 44 45 // Whether soft limit is supported or not 46 MemoryReservation bool 47 48 // Whether OOM killer disable is supported or not 49 OomKillDisable bool 50 51 // Whether memory swappiness is supported or not 52 MemorySwappiness bool 53 54 // Whether kernel memory limit is supported or not 55 KernelMemory bool 56 57 // Whether kernel memory TCP limit is supported or not 58 KernelMemoryTCP bool 59 } 60 61 type cgroupCPUInfo struct { 62 // Whether CPU shares is supported or not 63 CPUShares bool 64 65 // Whether CPU CFS(Completely Fair Scheduler) period is supported or not 66 CPUCfsPeriod bool 67 68 // Whether CPU CFS(Completely Fair Scheduler) quota is supported or not 69 CPUCfsQuota bool 70 71 // Whether CPU real-time period is supported or not 72 CPURealtimePeriod bool 73 74 // Whether CPU real-time runtime is supported or not 75 CPURealtimeRuntime bool 76 } 77 78 type cgroupBlkioInfo struct { 79 // Whether Block IO weight is supported or not 80 BlkioWeight bool 81 82 // Whether Block IO weight_device is supported or not 83 BlkioWeightDevice bool 84 85 // Whether Block IO read limit in bytes per second is supported or not 86 BlkioReadBpsDevice bool 87 88 // Whether Block IO write limit in bytes per second is supported or not 89 BlkioWriteBpsDevice bool 90 91 // Whether Block IO read limit in IO per second is supported or not 92 BlkioReadIOpsDevice bool 93 94 // Whether Block IO write limit in IO per second is supported or not 95 BlkioWriteIOpsDevice bool 96 } 97 98 type cgroupCpusetInfo struct { 99 // Whether Cpuset is supported or not 100 Cpuset bool 101 102 // Available Cpuset's cpus 103 Cpus string 104 105 // Available Cpuset's memory nodes 106 Mems string 107 } 108 109 type cgroupPids struct { 110 // Whether Pids Limit is supported or not 111 PidsLimit bool 112 } 113 114 // IsCpusetCpusAvailable returns `true` if the provided string set is contained 115 // in cgroup's cpuset.cpus set, `false` otherwise. 116 // If error is not nil a parsing error occurred. 117 func (c cgroupCpusetInfo) IsCpusetCpusAvailable(provided string) (bool, error) { 118 return isCpusetListAvailable(provided, c.Cpus) 119 } 120 121 // IsCpusetMemsAvailable returns `true` if the provided string set is contained 122 // in cgroup's cpuset.mems set, `false` otherwise. 123 // If error is not nil a parsing error occurred. 124 func (c cgroupCpusetInfo) IsCpusetMemsAvailable(provided string) (bool, error) { 125 return isCpusetListAvailable(provided, c.Mems) 126 } 127 128 func isCpusetListAvailable(provided, available string) (bool, error) { 129 parsedAvailable, err := parsers.ParseUintList(available) 130 if err != nil { 131 return false, err 132 } 133 // 8192 is the normal maximum number of CPUs in Linux, so accept numbers up to this 134 // or more if we actually have more CPUs. 135 max := 8192 136 for m := range parsedAvailable { 137 if m > max { 138 max = m 139 } 140 } 141 parsedProvided, err := parsers.ParseUintListMaximum(provided, max) 142 if err != nil { 143 return false, err 144 } 145 for k := range parsedProvided { 146 if !parsedAvailable[k] { 147 return false, nil 148 } 149 } 150 return true, nil 151 }