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