github.com/endocode/docker@v1.4.2-0.20160113120958-46eb4700391e/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  
    18  	// Whether IPv4 forwarding is supported or not, if this was disabled, networking will not work
    19  	IPv4ForwardingDisabled bool
    20  
    21  	// Whether bridge-nf-call-iptables is supported or not
    22  	BridgeNfCallIptablesDisabled bool
    23  
    24  	// Whether bridge-nf-call-ip6tables is supported or not
    25  	BridgeNfCallIP6tablesDisabled bool
    26  
    27  	// Whether the cgroup has the mountpoint of "devices" or not
    28  	CgroupDevicesEnabled bool
    29  }
    30  
    31  type cgroupMemInfo struct {
    32  	// Whether memory limit is supported or not
    33  	MemoryLimit bool
    34  
    35  	// Whether swap limit is supported or not
    36  	SwapLimit bool
    37  
    38  	// Whether soft limit is supported or not
    39  	MemoryReservation bool
    40  
    41  	// Whether OOM killer disable is supported or not
    42  	OomKillDisable bool
    43  
    44  	// Whether memory swappiness is supported or not
    45  	MemorySwappiness bool
    46  
    47  	// Whether kernel memory limit is supported or not
    48  	KernelMemory bool
    49  }
    50  
    51  type cgroupCPUInfo struct {
    52  	// Whether CPU shares is supported or not
    53  	CPUShares bool
    54  
    55  	// Whether CPU CFS(Completely Fair Scheduler) period is supported or not
    56  	CPUCfsPeriod bool
    57  
    58  	// Whether CPU CFS(Completely Fair Scheduler) quota is supported or not
    59  	CPUCfsQuota bool
    60  }
    61  
    62  type cgroupBlkioInfo struct {
    63  	// Whether Block IO weight is supported or not
    64  	BlkioWeight bool
    65  
    66  	// Whether Block IO weight_device is supported or not
    67  	BlkioWeightDevice bool
    68  
    69  	// Whether Block IO read limit in bytes per second is supported or not
    70  	BlkioReadBpsDevice bool
    71  
    72  	// Whether Block IO write limit in bytes per second is supported or not
    73  	BlkioWriteBpsDevice bool
    74  
    75  	// Whether Block IO read limit in IO per second is supported or not
    76  	BlkioReadIOpsDevice bool
    77  
    78  	// Whether Block IO write limit in IO per second is supported or not
    79  	BlkioWriteIOpsDevice bool
    80  }
    81  
    82  type cgroupCpusetInfo struct {
    83  	// Whether Cpuset is supported or not
    84  	Cpuset bool
    85  
    86  	// Available Cpuset's cpus
    87  	Cpus string
    88  
    89  	// Available Cpuset's memory nodes
    90  	Mems string
    91  }
    92  
    93  // IsCpusetCpusAvailable returns `true` if the provided string set is contained
    94  // in cgroup's cpuset.cpus set, `false` otherwise.
    95  // If error is not nil a parsing error occurred.
    96  func (c cgroupCpusetInfo) IsCpusetCpusAvailable(provided string) (bool, error) {
    97  	return isCpusetListAvailable(provided, c.Cpus)
    98  }
    99  
   100  // IsCpusetMemsAvailable returns `true` if the provided string set is contained
   101  // in cgroup's cpuset.mems set, `false` otherwise.
   102  // If error is not nil a parsing error occurred.
   103  func (c cgroupCpusetInfo) IsCpusetMemsAvailable(provided string) (bool, error) {
   104  	return isCpusetListAvailable(provided, c.Mems)
   105  }
   106  
   107  func isCpusetListAvailable(provided, available string) (bool, error) {
   108  	parsedProvided, err := parsers.ParseUintList(provided)
   109  	if err != nil {
   110  		return false, err
   111  	}
   112  	parsedAvailable, err := parsers.ParseUintList(available)
   113  	if err != nil {
   114  		return false, err
   115  	}
   116  	for k := range parsedProvided {
   117  		if !parsedAvailable[k] {
   118  			return false, nil
   119  		}
   120  	}
   121  	return true, nil
   122  }