github.com/reds/docker@v1.11.2-rc1/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 63 type cgroupBlkioInfo struct { 64 // Whether Block IO weight is supported or not 65 BlkioWeight bool 66 67 // Whether Block IO weight_device is supported or not 68 BlkioWeightDevice bool 69 70 // Whether Block IO read limit in bytes per second is supported or not 71 BlkioReadBpsDevice bool 72 73 // Whether Block IO write limit in bytes per second is supported or not 74 BlkioWriteBpsDevice bool 75 76 // Whether Block IO read limit in IO per second is supported or not 77 BlkioReadIOpsDevice bool 78 79 // Whether Block IO write limit in IO per second is supported or not 80 BlkioWriteIOpsDevice bool 81 } 82 83 type cgroupCpusetInfo struct { 84 // Whether Cpuset is supported or not 85 Cpuset bool 86 87 // Available Cpuset's cpus 88 Cpus string 89 90 // Available Cpuset's memory nodes 91 Mems string 92 } 93 94 type cgroupPids struct { 95 // Whether Pids Limit is supported or not 96 PidsLimit bool 97 } 98 99 // IsCpusetCpusAvailable returns `true` if the provided string set is contained 100 // in cgroup's cpuset.cpus set, `false` otherwise. 101 // If error is not nil a parsing error occurred. 102 func (c cgroupCpusetInfo) IsCpusetCpusAvailable(provided string) (bool, error) { 103 return isCpusetListAvailable(provided, c.Cpus) 104 } 105 106 // IsCpusetMemsAvailable returns `true` if the provided string set is contained 107 // in cgroup's cpuset.mems set, `false` otherwise. 108 // If error is not nil a parsing error occurred. 109 func (c cgroupCpusetInfo) IsCpusetMemsAvailable(provided string) (bool, error) { 110 return isCpusetListAvailable(provided, c.Mems) 111 } 112 113 func isCpusetListAvailable(provided, available string) (bool, error) { 114 parsedProvided, err := parsers.ParseUintList(provided) 115 if err != nil { 116 return false, err 117 } 118 parsedAvailable, err := parsers.ParseUintList(available) 119 if err != nil { 120 return false, err 121 } 122 for k := range parsedProvided { 123 if !parsedAvailable[k] { 124 return false, nil 125 } 126 } 127 return true, nil 128 }