github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/engine/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) is supported 66 CPUCfs bool 67 68 // Whether CPU real-time scheduler is supported 69 CPURealtime bool 70 } 71 72 type cgroupBlkioInfo struct { 73 // Whether Block IO weight is supported or not 74 BlkioWeight bool 75 76 // Whether Block IO weight_device is supported or not 77 BlkioWeightDevice bool 78 79 // Whether Block IO read limit in bytes per second is supported or not 80 BlkioReadBpsDevice bool 81 82 // Whether Block IO write limit in bytes per second is supported or not 83 BlkioWriteBpsDevice bool 84 85 // Whether Block IO read limit in IO per second is supported or not 86 BlkioReadIOpsDevice bool 87 88 // Whether Block IO write limit in IO per second is supported or not 89 BlkioWriteIOpsDevice bool 90 } 91 92 type cgroupCpusetInfo struct { 93 // Whether Cpuset is supported or not 94 Cpuset bool 95 96 // Available Cpuset's cpus 97 Cpus string 98 99 // Available Cpuset's memory nodes 100 Mems string 101 } 102 103 type cgroupPids struct { 104 // Whether Pids Limit is supported or not 105 PidsLimit bool 106 } 107 108 // IsCpusetCpusAvailable returns `true` if the provided string set is contained 109 // in cgroup's cpuset.cpus set, `false` otherwise. 110 // If error is not nil a parsing error occurred. 111 func (c cgroupCpusetInfo) IsCpusetCpusAvailable(provided string) (bool, error) { 112 return isCpusetListAvailable(provided, c.Cpus) 113 } 114 115 // IsCpusetMemsAvailable returns `true` if the provided string set is contained 116 // in cgroup's cpuset.mems set, `false` otherwise. 117 // If error is not nil a parsing error occurred. 118 func (c cgroupCpusetInfo) IsCpusetMemsAvailable(provided string) (bool, error) { 119 return isCpusetListAvailable(provided, c.Mems) 120 } 121 122 func isCpusetListAvailable(provided, available string) (bool, error) { 123 parsedAvailable, err := parsers.ParseUintList(available) 124 if err != nil { 125 return false, err 126 } 127 // 8192 is the normal maximum number of CPUs in Linux, so accept numbers up to this 128 // or more if we actually have more CPUs. 129 max := 8192 130 for m := range parsedAvailable { 131 if m > max { 132 max = m 133 } 134 } 135 parsedProvided, err := parsers.ParseUintListMaximum(provided, max) 136 if err != nil { 137 return false, err 138 } 139 for k := range parsedProvided { 140 if !parsedAvailable[k] { 141 return false, nil 142 } 143 } 144 return true, nil 145 }