github.com/gdevillele/moby@v1.13.0/pkg/sysinfo/sysinfo.go (about) 1 package 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 IPv4 forwarding is supported or not, if this was disabled, networking will not work 20 IPv4ForwardingDisabled bool 21 22 // Whether bridge-nf-call-iptables is supported or not 23 BridgeNFCallIPTablesDisabled bool 24 25 // Whether bridge-nf-call-ip6tables is supported or not 26 BridgeNFCallIP6TablesDisabled bool 27 28 // Whether the cgroup has the mountpoint of "devices" or not 29 CgroupDevicesEnabled bool 30 } 31 32 type cgroupMemInfo struct { 33 // Whether memory limit is supported or not 34 MemoryLimit bool 35 36 // Whether swap limit is supported or not 37 SwapLimit bool 38 39 // Whether soft limit is supported or not 40 MemoryReservation bool 41 42 // Whether OOM killer disable is supported or not 43 OomKillDisable bool 44 45 // Whether memory swappiness is supported or not 46 MemorySwappiness bool 47 48 // Whether kernel memory limit is supported or not 49 KernelMemory bool 50 } 51 52 type cgroupCPUInfo struct { 53 // Whether CPU shares is supported or not 54 CPUShares bool 55 56 // Whether CPU CFS(Completely Fair Scheduler) period is supported or not 57 CPUCfsPeriod bool 58 59 // Whether CPU CFS(Completely Fair Scheduler) quota is supported or not 60 CPUCfsQuota bool 61 62 // Whether CPU real-time period is supported or not 63 CPURealtimePeriod bool 64 65 // Whether CPU real-time runtime is supported or not 66 CPURealtimeRuntime bool 67 } 68 69 type cgroupBlkioInfo struct { 70 // Whether Block IO weight is supported or not 71 BlkioWeight bool 72 73 // Whether Block IO weight_device is supported or not 74 BlkioWeightDevice bool 75 76 // Whether Block IO read limit in bytes per second is supported or not 77 BlkioReadBpsDevice bool 78 79 // Whether Block IO write limit in bytes per second is supported or not 80 BlkioWriteBpsDevice bool 81 82 // Whether Block IO read limit in IO per second is supported or not 83 BlkioReadIOpsDevice bool 84 85 // Whether Block IO write limit in IO per second is supported or not 86 BlkioWriteIOpsDevice bool 87 } 88 89 type cgroupCpusetInfo struct { 90 // Whether Cpuset is supported or not 91 Cpuset bool 92 93 // Available Cpuset's cpus 94 Cpus string 95 96 // Available Cpuset's memory nodes 97 Mems string 98 } 99 100 type cgroupPids struct { 101 // Whether Pids Limit is supported or not 102 PidsLimit bool 103 } 104 105 // IsCpusetCpusAvailable returns `true` if the provided string set is contained 106 // in cgroup's cpuset.cpus set, `false` otherwise. 107 // If error is not nil a parsing error occurred. 108 func (c cgroupCpusetInfo) IsCpusetCpusAvailable(provided string) (bool, error) { 109 return isCpusetListAvailable(provided, c.Cpus) 110 } 111 112 // IsCpusetMemsAvailable returns `true` if the provided string set is contained 113 // in cgroup's cpuset.mems set, `false` otherwise. 114 // If error is not nil a parsing error occurred. 115 func (c cgroupCpusetInfo) IsCpusetMemsAvailable(provided string) (bool, error) { 116 return isCpusetListAvailable(provided, c.Mems) 117 } 118 119 func isCpusetListAvailable(provided, available string) (bool, error) { 120 parsedProvided, err := parsers.ParseUintList(provided) 121 if err != nil { 122 return false, err 123 } 124 parsedAvailable, err := parsers.ParseUintList(available) 125 if err != nil { 126 return false, err 127 } 128 for k := range parsedProvided { 129 if !parsedAvailable[k] { 130 return false, nil 131 } 132 } 133 return true, nil 134 } 135 136 // Returns bit count of 1, used by NumCPU 137 func popcnt(x uint64) (n byte) { 138 x -= (x >> 1) & 0x5555555555555555 139 x = (x>>2)&0x3333333333333333 + x&0x3333333333333333 140 x += x >> 4 141 x &= 0x0f0f0f0f0f0f0f0f 142 x *= 0x0101010101010101 143 return byte(x >> 56) 144 }